summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjbj <devnull@localhost>2002-10-13 14:39:21 +0000
committerjbj <devnull@localhost>2002-10-13 14:39:21 +0000
commit627873989525aa2c713a1a755d82b3ad79575d8e (patch)
treef00d5737d57e2af5ac497bba739301e4be6c9ea1
parent097ff145c9571f7ace5427f2409ef3804c95a131 (diff)
downloadrpm-627873989525aa2c713a1a755d82b3ad79575d8e.tar.gz
rpm-627873989525aa2c713a1a755d82b3ad79575d8e.tar.bz2
rpm-627873989525aa2c713a1a755d82b3ad79575d8e.zip
Add argv.[ch].
CVS patchset: 5772 CVS date: 2002/10/13 14:39:21
-rw-r--r--build/.cvsignore1
-rw-r--r--build/Makefile.am4
-rw-r--r--build/argv.c125
-rw-r--r--build/argv.h83
-rw-r--r--build/files.c14
-rw-r--r--build/tfr.c139
6 files changed, 223 insertions, 143 deletions
diff --git a/build/.cvsignore b/build/.cvsignore
index c64b470d2..c5d69b0b4 100644
--- a/build/.cvsignore
+++ b/build/.cvsignore
@@ -6,3 +6,4 @@ Makefile.in
*.la
*.lcd
*.lo
+tfr
diff --git a/build/Makefile.am b/build/Makefile.am
index c106ee735..3ed2f50b7 100644
--- a/build/Makefile.am
+++ b/build/Makefile.am
@@ -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
diff --git a/build/argv.c b/build/argv.c
new file mode 100644
index 000000000..3a84b76e4
--- /dev/null
+++ b/build/argv.c
@@ -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@*/
diff --git a/build/argv.h b/build/argv.h
new file mode 100644
index 000000000..ae986f30e
--- /dev/null
+++ b/build/argv.h
@@ -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_ */
diff --git a/build/files.c b/build/files.c
index 72e547103..d176b6843 100644
--- a/build/files.c
+++ b/build/files.c
@@ -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;
diff --git a/build/tfr.c b/build/tfr.c
index 85151ffc2..46c7623bd 100644
--- a/build/tfr.c
+++ b/build/tfr.c
@@ -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;