summaryrefslogtreecommitdiff
path: root/rpmio
diff options
context:
space:
mode:
authorjbj <devnull@localhost>1999-11-26 16:19:30 +0000
committerjbj <devnull@localhost>1999-11-26 16:19:30 +0000
commitc8406c80d2a9670df64f1ab7e38d90626cad906f (patch)
tree73cd94dccefe9e495fa59f775b6e931e4867e984 /rpmio
parent2a423cf9398d597b1320e95e864909e292f9c82f (diff)
downloadrpm-c8406c80d2a9670df64f1ab7e38d90626cad906f.tar.gz
rpm-c8406c80d2a9670df64f1ab7e38d90626cad906f.tar.bz2
rpm-c8406c80d2a9670df64f1ab7e38d90626cad906f.zip
lib/macro.c: Create rpmCleanPath().
build/misc.c: Delete cleanFileName(). CVS patchset: 3435 CVS date: 1999/11/26 16:19:30
Diffstat (limited to 'rpmio')
-rw-r--r--rpmio/macro.c94
-rw-r--r--rpmio/rpmmacro.h28
2 files changed, 68 insertions, 54 deletions
diff --git a/rpmio/macro.c b/rpmio/macro.c
index bf8a5a412..0323f2873 100644
--- a/rpmio/macro.c
+++ b/rpmio/macro.c
@@ -132,7 +132,7 @@ sortMacroTable(MacroContext *mc)
}
void
-dumpMacroTable(MacroContext *mc, FILE *f)
+dumpMacroTable(MacroContext * mc, FILE * fp)
{
int i;
int nempty = 0;
@@ -140,10 +140,10 @@ dumpMacroTable(MacroContext *mc, FILE *f)
if (mc == NULL)
mc = &globalMacroContext;
- if (f == NULL)
- f = stderr;
+ if (fp == NULL)
+ fp = stderr;
- fprintf(f, "========================\n");
+ fprintf(fp, "========================\n");
for (i = 0; i < mc->firstFree; i++) {
MacroEntry *me;
if ((me = mc->macroTable[i]) == NULL) {
@@ -151,16 +151,16 @@ dumpMacroTable(MacroContext *mc, FILE *f)
nempty++;
continue;
}
- fprintf(f, "%3d%c %s", me->level,
+ fprintf(fp, "%3d%c %s", me->level,
(me->used > 0 ? '=' : ':'), me->name);
if (me->opts && *me->opts)
- fprintf(f, "(%s)", me->opts);
+ fprintf(fp, "(%s)", me->opts);
if (me->body && *me->body)
- fprintf(f, "\t%s", me->body);
- fprintf(f, "\n");
+ fprintf(fp, "\t%s", me->body);
+ fprintf(fp, "\n");
nactive++;
}
- fprintf(f, _("======================== active %d empty %d\n"),
+ fprintf(fp, _("======================== active %d empty %d\n"),
nactive, nempty);
}
@@ -1462,32 +1462,14 @@ rpmExpandNumeric(const char *arg)
return rc;
}
-/* Return concatenated and expanded path with multiple /'s removed */
-const char *
-rpmGetPath(const char *path, ...)
+const char *rpmCleanPath(char * path)
{
- char buf[BUFSIZ], *t, *te, *se;
const char *s;
- va_list ap;
-
- if (path == NULL)
- return xstrdup("");
+ char *se, *t, *te;
- t = buf;
- te = stpcpy(t, path);
- *te = '\0';
-
- va_start(ap, path);
- while ((s = va_arg(ap, const char *)) != NULL) {
- te = stpcpy(te, s);
- *te = '\0';
- }
- va_end(ap);
- expandMacros(NULL, NULL, buf, sizeof(buf));
-
- s = t = te = buf;
+ s = t = te = path;
while (*s) {
-/*fprintf(stderr, "*** got \"%.*s\"\trest \"%s\"\n", (t-buf), buf, s); */
+/*fprintf(stderr, "*** got \"%.*s\"\trest \"%s\"\n", (t-path), path, s); */
switch(*s) {
case ':': /* handle url's */
if (s[1] == '/' && s[2] == '/') {
@@ -1501,37 +1483,37 @@ rpmGetPath(const char *path, ...)
;
if (se < t && *se == '/') {
te = se;
-/*fprintf(stderr, "*** next pdir \"%.*s\"\n", (te-buf), buf); */
+/*fprintf(stderr, "*** next pdir \"%.*s\"\n", (te-path), path); */
}
while (s[1] == '/')
s++;
- while (t > buf && t[-1] == '/')
+ while (t > path && t[-1] == '/')
t--;
break;
case '.':
/* Leading .. is special */
- if (t == buf && s[1] == '.') {
+ if (t == path && s[1] == '.') {
*t++ = *s++;
break;
}
/* Single . is special */
- if (t == buf && s[1] == '\0') {
+ if (t == path && s[1] == '\0') {
break;
}
/* Trim leading ./ , embedded ./ , trailing /. */
- if ((t == buf || t[-1] == '/') && (s[1] == '/' || s[1] == '\0')) {
+ if ((t == path || t[-1] == '/') && (s[1] == '/' || s[1] == '\0')) {
/*fprintf(stderr, "*** Trim leading ./ , embedded ./ , trailing /.\n"); */
s++;
continue;
}
/* Trim embedded /../ and trailing /.. */
- if (t > buf && t[-1] == '/' && s[1] == '.' && (s[2] == '/' || s[2] == '\0')) {
+ if (t > path && t[-1] == '/' && s[1] == '.' && (s[2] == '/' || s[2] == '\0')) {
t = te;
/* Move parent dir forward */
- if (te > buf)
- for (--te; te > buf && *te != '/'; te--)
+ if (te > path)
+ for (--te; te > path && *te != '/'; te--)
;
-/*fprintf(stderr, "*** prev pdir \"%.*s\"\n", (te-buf), buf); */
+/*fprintf(stderr, "*** prev pdir \"%.*s\"\n", (te-path), path); */
s++;
s++;
continue;
@@ -1542,12 +1524,40 @@ rpmGetPath(const char *path, ...)
}
*t++ = *s++;
}
+
/* Trim trailing / (but leave single / alone) */
- if (t > &buf[1] && t[-1] == '/')
+ if (t > &path[1] && t[-1] == '/')
t--;
*t = '\0';
- return xstrdup(buf);
+ return path;
+}
+
+/* Return concatenated and expanded canonical path. */
+const char *
+rpmGetPath(const char *path, ...)
+{
+ char buf[BUFSIZ];
+ const char * s;
+ char * t, * te;
+ va_list ap;
+
+ if (path == NULL)
+ return xstrdup("");
+
+ t = buf;
+ te = stpcpy(t, path);
+ *te = '\0';
+
+ va_start(ap, path);
+ while ((s = va_arg(ap, const char *)) != NULL) {
+ te = stpcpy(te, s);
+ *te = '\0';
+ }
+ va_end(ap);
+ expandMacros(NULL, NULL, buf, sizeof(buf));
+
+ return xstrdup( rpmCleanPath(buf) );
}
/* Merge 3 args into path, any or all of which may be a url. */
diff --git a/rpmio/rpmmacro.h b/rpmio/rpmmacro.h
index a1d038666..9ad1e5ded 100644
--- a/rpmio/rpmmacro.h
+++ b/rpmio/rpmmacro.h
@@ -33,28 +33,32 @@ typedef /*@abstract@*/ struct MacroContext {
extern "C" {
#endif
-void dumpMacroTable (MacroContext *mc, FILE *f);
+void dumpMacroTable (MacroContext * mc, FILE * fp);
/* XXX this is used only in build/expression.c and will go away. */
const char *getMacroBody (MacroContext *mc, const char *name);
-int expandMacros (void *spec, MacroContext *mc, char *sbuf, size_t sbuflen);
-void addMacro (MacroContext *mc, const char *n, const char *o, const char *b, int depth);
-void delMacro (MacroContext *mc, const char *n);
+int expandMacros (void * spec, MacroContext * mc, char * sbuf,
+ size_t sbuflen);
+void addMacro (MacroContext * mc, const char * n, const char * o,
+ const char * b, int depth);
+void delMacro (MacroContext * mc, const char * n);
-int rpmDefineMacro (MacroContext *mc, const char *macro, int level);
-void initMacros (MacroContext *mc, const char *macrofile);
-void freeMacros (MacroContext *mc);
+int rpmDefineMacro (MacroContext * mc, const char * macro, int level);
+void initMacros (MacroContext * mc, const char * macrofile);
+void freeMacros (MacroContext * mc);
#define COMPRESSED_NOT 0
#define COMPRESSED_OTHER 1
#define COMPRESSED_BZIP2 2
-int isCompressed (const char *file, int *compressed);
+int isCompressed (const char * file, int * compressed);
-char * rpmExpand (const char *arg, ...);
-const char *rpmGetPath (const char *path, ...);
-const char *rpmGenPath (const char *root, const char *mdir, const char *file);
-int rpmExpandNumeric (const char *arg);
+char * rpmExpand (const char * arg, ...);
+const char *rpmCleanPath(char * path);
+const char *rpmGetPath (const char * path, ...);
+const char *rpmGenPath (const char * root, const char * mdir,
+ const char * file);
+int rpmExpandNumeric (const char * arg);
#ifdef __cplusplus
}