Add argv.[ch].

CVS patchset: 5772
CVS date: 2002/10/13 14:39:21
This commit is contained in:
jbj 2002-10-13 14:39:21 +00:00
parent 097ff145c9
commit 6278739895
6 changed files with 223 additions and 143 deletions

View File

@ -6,3 +6,4 @@ Makefile.in
*.la
*.lcd
*.lo
tfr

View File

@ -26,11 +26,11 @@ tfr_LDADD = \
pkgincdir = $(pkgincludedir)
pkginc_HEADERS = rpmbuild.h rpmspec.h
noinst_HEADERS = buildio.h
noinst_HEADERS = argv.h buildio.h
lib_LTLIBRARIES = librpmbuild.la
librpmbuild_la_SOURCES = \
build.c expression.c files.c misc.c names.c pack.c \
argv.c build.c expression.c files.c misc.c names.c pack.c \
parseBuildInstallClean.c parseChangelog.c parseDescription.c \
parseFiles.c parsePreamble.c parsePrep.c parseReqs.c parseScript.c \
parseSpec.c poptBT.c reqprov.c spec.c

125
build/argv.c Normal file
View File

@ -0,0 +1,125 @@
#include "system.h"
#include <argv.h>
#include "debug.h"
/*@-bounds@*/
/**
* Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
* @param p memory to free
* @return NULL always
*/
/*@unused@*/ static inline /*@null@*/
void * _free(/*@only@*/ /*@null@*/ /*@out@*/ const void * p)
/*@modifies p @*/
{
if (p != NULL) free((void *)p);
return NULL;
}
void argvPrint(const char * msg, ARGV_t argv, FILE * fp)
{
ARGV_t av;
int ac;
if (fp == NULL) fp = stderr;
if (msg)
fprintf(fp, "===================================== %s\n", msg);
for (ac = 0, av = argv; *av; av++, ac++)
fprintf(fp, "%5d: %s\n", ac, *av);
}
int argvFree(/*@only@*/ /*@null@*/ ARGV_t argv)
{
ARGV_t av;
if ((av = argv)) {
while (*av)
*av = _free(*av);
argv = _free(argv);
}
return 0;
}
int argvCount(/*@null@*/ const ARGV_t argv)
{
int argc = 0;
if (argv)
while (argv[argc] != NULL)
argc++;
return argc;
}
int argvCmp(const void * a, const void * b)
{
/*@-boundsread@*/
ARG_t astr = *(ARGV_t)a;
ARG_t bstr = *(ARGV_t)b;
/*@=boundsread@*/
return strcmp(astr, bstr);
}
int argvSort(ARGV_t argv, int (*compar)(const void *, const void *))
{
qsort(argv, argvCount(argv), sizeof(*argv), compar);
return 0;
}
ARGV_t argvSearch(ARGV_t argv, ARG_t s,
int (*compar)(const void *, const void *))
{
return bsearch(&s, argv, argvCount(argv), sizeof(*argv), compar);
}
int argvAppend(/*@out@*/ ARGV_t * argvp, const ARGV_t av)
{
ARGV_t argv = *argvp;
int argc = argvCount(argv);
int ac = argvCount(av);
int i;
argv = xrealloc(argv, (argc + ac + 1) * sizeof(*argv));
for (i = 0; i < ac; i++)
argv[argc + i] = xstrdup(av[i]);
argv[argc + ac] = NULL;
*argvp = argv;
return 0;
}
int argvSplit(ARGV_t * argvp, const char * str, const char * seps)
{
char * dest = alloca(strlen(str) + 1);
ARGV_t argv;
int argc = 1;
const char * s;
char * t;
int c;
for (argc = 1, s = str, t = dest; (c = *s); s++, t++) {
if (strchr(seps, c)) {
argc++;
c = '\0';
}
*t = c;
}
*t = '\0';
argv = xmalloc( (argc + 1) * sizeof(*argv));
for (c = 0, s = dest; s < t; s+= strlen(s) + 1) {
if (*s == '\0')
continue;
argv[c] = xstrdup(s);
c++;
}
argv[c] = NULL;
*argvp = argv;
/*@-nullstate@*/
return 0;
/*@=nullstate@*/
}
/*@=bounds@*/

83
build/argv.h Normal file
View File

@ -0,0 +1,83 @@
#ifndef _H_ARGV_
#define _H_ARGV_
/** \ingroup rpmbuild
* \file build/argv.h
*/
typedef const char * ARG_t;
typedef ARG_t * ARGV_t;
#ifdef __cplusplus
extern "C" {
#endif
/**
* Print argv array elements.
* @param msg output message prefix (or NULL)
* @param argv argv array
* @param fp output file handle (NULL uses stderr)
*/
void argvPrint(const char * msg, ARGV_t argv, FILE * fp)
/*@globals fileSystem @*/
/*@modifies *fp, fileSystem @*/;
/**
* Destroy an argv array.
* @param argv argv array
*/
int argvFree(/*@only@*/ /*@null@*/ ARGV_t argv)
/*@modifies argv @*/;
/**
* Return no. of elements in argv array.
* @param argv argv array
*/
int argvCount(/*@null@*/ const ARGV_t argv)
/*@*/;
/**
* Compare argv arrays (qsort/bsearch).
* @param a 1st instance address
* @param b 2nd instance address
* @return result of comparison
*/
int argvCmp(const void * a, const void * b)
/*@*/;
/**
* Sort an argv array.
* @param argv argv array
*/
int argvSort(ARGV_t argv, int (*compar)(const void *, const void *))
/*@modifies *argv @*/;
/**
* Find an element in an argv array.
* @param argv argv array
*/
/*@dependent@*/ /*@null@*/
ARGV_t argvSearch(ARGV_t argv, ARG_t s,
int (*compar)(const void *, const void *))
/*@*/;
/**
* Append one argv array to another.
* @retval *argvp argv array
* @param av argv array to append
*/
int argvAppend(/*@out@*/ ARGV_t * argvp, const ARGV_t av)
/*@modifies *argvp @*/;
/**
* Splint a string into an argv array.
* @retval *argvp argv array
*/
int argvSplit(ARGV_t * argvp, const char * str, const char * seps)
/*@modifies *argvp @*/;
#ifdef __cplusplus
}
#endif
#endif /* _H_ARGV_ */

View File

@ -100,7 +100,7 @@ typedef struct AttrRec_s {
/**
*/
/*@unchecked@*/
static int multiLibNo = 0; /* MULTILIB */
static unsigned multiLibNo = 0; /* MULTILIB */
/**
*/
@ -1248,7 +1248,7 @@ static void genCpioListAndHeader(/*@partial@*/ FileList fl,
* Create union bit mask of all files in the package.
*/
if (flp->flags & RPMFILE_MULTILIB_MASK) {
int mlno;
unsigned mlno;
mlno = (flp->flags & RPMFILE_MULTILIB_MASK);
mlno >>= RPMFILE_MULTILIB_SHIFT;
multiLibMask |= (1u << mlno);
@ -1722,8 +1722,8 @@ static int addFile(FileList fl, const char * diskURL,
/* If coloring and still white, apply regex to path. */
if (multiLibNo
&& !(flp->flags & RPMFILE_MULTILIB_MASK)
&& !parseForRegexMultiLib(fileURL)) {
&& !(flp->flags & RPMFILE_MULTILIB_MASK)
&& !parseForRegexMultiLib(fileURL)) {
flp->flags |= RPMFILE_MULTILIB(multiLibNo);
}
@ -2881,8 +2881,10 @@ exit:
/*@-incondefs@*/
int processBinaryFiles(Spec spec, int installSpecialDoc, int test)
/*@globals check_fileList, check_fileListLen @*/
/*@modifies check_fileList, check_fileListLen @*/
/*@globals check_fileList, check_fileListLen,
multiLibNo, multiLib_oneshot @*/
/*@modifies check_fileList, check_fileListLen,
multiLibNo, multiLib_oneshot @*/
{
HGE_t hge = (HGE_t)headerGetEntryMinMemory;
Package pkg;

View File

@ -1,141 +1,10 @@
#include "system.h"
#include <rpmbuild.h>
#include <argv.h>
#include "debug.h"
/**
*/
static int argvFree(/*@only@*/ /*@null@*/ const char ** argv)
/*@modifies argv @*/
{
const char ** av;
if ((av = argv)) {
while (*av)
*av = _free(*av);
argv = _free(argv);
}
return 0;
}
/**
*/
static void argvPrint(const char * msg, const char ** argv, FILE * fp)
/*@*/
{
const char ** av;
int ac;
if (fp == NULL) fp = stderr;
if (msg)
fprintf(fp, "===================================== %s\n", msg);
for (ac = 0, av = argv; *av; av++, ac++)
fprintf(fp, "%5d: %s\n", ac, *av);
}
/**
*/
static int argvCount(/*@null@*/ const char ** argv)
/*@*/
{
int argc = 0;
if (argv)
while (argv[argc] != NULL)
argc++;
return argc;
}
/**
* Compare argv arrays (qsort/bsearch).
* @param a 1st instance address
* @param b 2nd instance address
* @return result of comparison
*/
static int argvCmp(const void * a, const void * b)
/*@*/
{
/*@-boundsread@*/
const char * astr = *(const char **)a;
const char * bstr = *(const char **)b;
/*@=boundsread@*/
return strcmp(astr, bstr);
}
/**
*/
static int argvSort(const char ** argv,
int (*compar)(const void *, const void *))
/*@*/
{
qsort(argv, argvCount(argv), sizeof(*argv), compar);
return 0;
}
/**
*/
static const char ** argvSearch(const char ** argv, const char * s,
int (*compar)(const void *, const void *))
/*@*/
{
return bsearch(&s, argv, argvCount(argv), sizeof(*argv), compar);
}
/**
*/
static int argvAppend(/*@out@*/ const char *** argvp, const char ** av)
/*@*/
{
const char ** argv = *argvp;
int argc = argvCount(argv);
int ac = argvCount(av);
int i;
argv = xrealloc(argv, (argc + ac + 1) * sizeof(*argv));
for (i = 0; i < ac; i++)
argv[argc + i] = xstrdup(av[i]);
argv[argc + ac] = NULL;
*argvp = argv;
return 0;
}
/**
*/
static int argvSplit(const char *** argvp, const char * str, const char * seps)
/*@*/
{
char * dest = alloca(strlen(str) + 1);
const char ** argv;
int argc = 1;
const char * s;
char * t;
int c;
for (argc = 1, s = str, t = dest; (c = *s); s++, t++) {
if (strchr(seps, c)) {
argc++;
c = '\0';
}
*t = c;
}
*t = '\0';
argv = xmalloc( (argc + 1) * sizeof(*argv));
for (c = 0, s = dest; s < t; s+= strlen(s) + 1) {
if (*s == '\0')
continue;
argv[c] = xstrdup(s);
c++;
}
argv[c] = NULL;
*argvp = argv;
return 0;
}
static struct poptOption optionsTable[] = {
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
@ -152,10 +21,10 @@ main(int argc, char *const argv[])
{
poptContext optCon;
StringBuf sb;
const char ** pav;
ARGV_t pav;
int pac = 0;
const char ** xav;
const char ** av = NULL;
ARGV_t xav;
ARGV_t av = NULL;
int ac = 0;
const char * s;
int ec = 1;