diff options
author | jbj <devnull@localhost> | 2002-10-14 14:52:45 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2002-10-14 14:52:45 +0000 |
commit | a0bdebee4dad4cae17a8585cf9be74fb7093a3c5 (patch) | |
tree | c901b42ba16683908e0ee12c3c7495913453892f /build/argv.c | |
parent | 627873989525aa2c713a1a755d82b3ad79575d8e (diff) | |
download | librpm-tizen-a0bdebee4dad4cae17a8585cf9be74fb7093a3c5.tar.gz librpm-tizen-a0bdebee4dad4cae17a8585cf9be74fb7093a3c5.tar.bz2 librpm-tizen-a0bdebee4dad4cae17a8585cf9be74fb7093a3c5.zip |
Spin mostly complete file classifier off to rpmfc.[ch].
CVS patchset: 5773
CVS date: 2002/10/14 14:52:45
Diffstat (limited to 'build/argv.c')
-rw-r--r-- | build/argv.c | 75 |
1 files changed, 64 insertions, 11 deletions
diff --git a/build/argv.c b/build/argv.c index 3a84b76e4..01af214ab 100644 --- a/build/argv.c +++ b/build/argv.c @@ -33,16 +33,27 @@ void argvPrint(const char * msg, ARGV_t argv, FILE * fp) } -int argvFree(/*@only@*/ /*@null@*/ ARGV_t argv) +ARGI_t argiFree(ARGI_t argi) +{ + if (argi) { + argi->nvals = 0; + argi->vals = _free(argi->vals); + } + argi = _free(argi); + return NULL; +} + +ARGV_t argvFree(/*@only@*/ /*@null@*/ ARGV_t argv) { ARGV_t av; - if ((av = argv)) { - while (*av) - *av = _free(*av); - argv = _free(argv); - } - return 0; +/*@-branchstate@*/ + if (argv) + for (av = argv; *av; av++) + *av = _free(*av); +/*@=branchstate@*/ + argv = _free(argv); + return NULL; } int argvCount(/*@null@*/ const ARGV_t argv) @@ -57,22 +68,64 @@ int argvCount(/*@null@*/ const ARGV_t argv) int argvCmp(const void * a, const void * b) { /*@-boundsread@*/ - ARG_t astr = *(ARGV_t)a; - ARG_t bstr = *(ARGV_t)b; + ARGstr_t astr = *(ARGV_t)a; + ARGstr_t bstr = *(ARGV_t)b; /*@=boundsread@*/ return strcmp(astr, bstr); } int argvSort(ARGV_t argv, int (*compar)(const void *, const void *)) { + if (compar == NULL) + compar = argvCmp; qsort(argv, argvCount(argv), sizeof(*argv), compar); return 0; } -ARGV_t argvSearch(ARGV_t argv, ARG_t s, +ARGV_t argvSearch(ARGV_t argv, ARGstr_t val, int (*compar)(const void *, const void *)) { - return bsearch(&s, argv, argvCount(argv), sizeof(*argv), compar); + if (argv == NULL) + return NULL; + if (compar == NULL) + compar = argvCmp; + return bsearch(&val, argv, argvCount(argv), sizeof(*argv), compar); +} + +int argiAdd(/*@out@*/ ARGI_t * argip, unsigned ix, int val) +{ + ARGI_t argi; + + if (argip == NULL) + return -1; + if (*argip == NULL) + *argip = xcalloc(1, sizeof(**argip)); + argi = *argip; + if (ix >= argi->nvals) { + argi->vals = xrealloc(argi->vals, (ix + 1) * sizeof(*argi->vals)); + memset(argi->vals + argi->nvals, 0, + (ix - argi->nvals) * sizeof(*argi->vals)); + argi->nvals = ix + 1; + } + argi->vals[ix] = val; + return 0; +} + +int argvAdd(/*@out@*/ ARGV_t * argvp, ARGstr_t val) +{ + ARGV_t argv; + int argc; + + if (argvp == NULL) + return -1; + argc = argvCount(*argvp); +/*@-unqualifiedtrans@*/ + *argvp = xrealloc(*argvp, (argc + 1 + 1) * sizeof(**argvp)); +/*@=unqualifiedtrans@*/ + argv = *argvp; + argv[argc++] = xstrdup(val); + argv[argc ] = NULL; + return 0; } int argvAppend(/*@out@*/ ARGV_t * argvp, const ARGV_t av) |