diff options
author | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-06 11:47:08 +0100 |
---|---|---|
committer | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-06 11:47:08 +0100 |
commit | 45d86e65aeff97a16e1bbac6a1d36e5a5c999ff5 (patch) | |
tree | 145e098aaa7d85dbd1f5070443ac606bda42124d /eurephiadm | |
parent | f97bef1166744117de2e2a73606e17dd92c46945 (diff) | |
download | eurephia-45d86e65aeff97a16e1bbac6a1d36e5a5c999ff5.tar.gz eurephia-45d86e65aeff97a16e1bbac6a1d36e5a5c999ff5.tar.xz eurephia-45d86e65aeff97a16e1bbac6a1d36e5a5c999ff5.zip |
Added new function for copying char ** (arrays)
Diffstat (limited to 'eurephiadm')
-rw-r--r-- | eurephiadm/argparser.c | 19 | ||||
-rw-r--r-- | eurephiadm/argparser.h | 1 |
2 files changed, 20 insertions, 0 deletions
diff --git a/eurephiadm/argparser.c b/eurephiadm/argparser.c index 6272c77..5fb387e 100644 --- a/eurephiadm/argparser.c +++ b/eurephiadm/argparser.c @@ -19,6 +19,7 @@ */ #include <stdio.h> +#include <stdlib.h> #include <string.h> #define ARGPARSER_C @@ -49,3 +50,21 @@ int _eurephia_getopt(const char *module, int curarg, int argc, char **argv, e_op fprintf(stderr, "%s: ERROR :: Unknown argument '%s'\n", module, arg); return -1; } + + +// This function will take (argc,argv) and copy pointers over to (**outargv), starting from +// the index given in stidx (start index). The outargv array must have been allocated first +// by calloc(sizeof(char *), elmnts). The outsize must not exceed the number of elements you +// have allocated space for. The function returns number of elements copied (the new argc, kind of) +// +size_t eurephia_arraycp(int stidx, int inargc, char **inargv, char **outargv, size_t outsize) { + int i, outargc; + + outargc = 0; + for( i = stidx; ((i < inargc) && (outargc < outsize)); i++ ) { + fprintf(stderr, "(%i, %i) '%s'\n", i, outargc, inargv[i]); + outargv[outargc++] = inargv[i]; + } + + return outargc; +} diff --git a/eurephiadm/argparser.h b/eurephiadm/argparser.h index d0076f8..842e14a 100644 --- a/eurephiadm/argparser.h +++ b/eurephiadm/argparser.h @@ -40,4 +40,5 @@ extern char *optargs[MAX_ARGUMENTS]; int _eurephia_getopt(const char *module, int curarg, int argc, char **argv, e_options *argopts); #define eurephia_getopt(ca, ac, av, opts) _eurephia_getopt(MODULE, ca, ac, av, opts) +size_t eurephia_arraycp(int stidx, int inargc, char **inargv, char **outargv, size_t outsize); #endif |