From 5ed685425eb21ffb7609bd42dc87c8cdbcc0a725 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Tue, 24 Aug 2010 12:35:59 +0300 Subject: [PATCH] Eliminate addSource() from librpmbuild API - Nothing outside parsePreamble.c needs, bury it there and make static --- build/parsePreamble.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++ build/rpmspec.h | 9 ---- build/spec.c | 122 ------------------------------------------------- 3 files changed, 123 insertions(+), 131 deletions(-) diff --git a/build/parsePreamble.c b/build/parsePreamble.c index 207b27b..1de8016 100644 --- a/build/parsePreamble.c +++ b/build/parsePreamble.c @@ -11,6 +11,7 @@ #include #include #include +#include "rpmio/rpmlua.h" #include "debug.h" #define SKIPSPACE(s) { while (*(s) && risspace(*(s))) (s)++; } @@ -167,6 +168,128 @@ static int parseNoSource(rpmSpec spec, const char * field, rpmTag tag) return 0; } +static int addSource(rpmSpec spec, Package pkg, const char *field, rpmTag tag) +{ + struct Source *p; + int flag = 0; + const char *name = NULL; + char *nump; + char *fieldp = NULL; + char *buf = NULL; + uint32_t num = 0; + + switch (tag) { + case RPMTAG_SOURCE: + flag = RPMBUILD_ISSOURCE; + name = "source"; + fieldp = spec->line + 6; + break; + case RPMTAG_PATCH: + flag = RPMBUILD_ISPATCH; + name = "patch"; + fieldp = spec->line + 5; + break; + case RPMTAG_ICON: + flag = RPMBUILD_ISICON; + fieldp = NULL; + break; + default: + return -1; + break; + } + + /* Get the number */ + if (tag != RPMTAG_ICON) { + /* We already know that a ':' exists, and that there */ + /* are no spaces before it. */ + /* This also now allows for spaces and tabs between */ + /* the number and the ':' */ + char ch; + char *fieldp_backup = fieldp; + + while ((*fieldp != ':') && (*fieldp != ' ') && (*fieldp != '\t')) { + fieldp++; + } + ch = *fieldp; + *fieldp = '\0'; + + nump = fieldp_backup; + SKIPSPACE(nump); + if (nump == NULL || *nump == '\0') { + num = flag == RPMBUILD_ISSOURCE ? 0 : INT_MAX; + } else { + if (parseUnsignedNum(fieldp_backup, &num)) { + rpmlog(RPMLOG_ERR, _("line %d: Bad %s number: %s\n"), + spec->lineNum, name, spec->line); + *fieldp = ch; + return RPMRC_FAIL; + } + } + *fieldp = ch; + } + + /* Check whether tags of the same number haven't already been defined */ + for (p = spec->sources; p != NULL; p = p->next) { + if ( p->num != num ) continue; + if ((tag == RPMTAG_SOURCE && p->flags == RPMBUILD_ISSOURCE) || + (tag == RPMTAG_PATCH && p->flags == RPMBUILD_ISPATCH)) { + rpmlog(RPMLOG_ERR, _("%s %d defined multiple times\n"), name, num); + return RPMRC_FAIL; + } + } + + /* Create the entry and link it in */ + p = xmalloc(sizeof(*p)); + p->num = num; + p->fullSource = xstrdup(field); + p->flags = flag; + p->source = strrchr(p->fullSource, '/'); + if (p->source) { + p->source++; + } else { + p->source = p->fullSource; + } + + if (tag != RPMTAG_ICON) { + p->next = spec->sources; + spec->sources = p; + } else { + p->next = pkg->icon; + pkg->icon = p; + } + + spec->numSources++; + + if (tag != RPMTAG_ICON) { + char *body = rpmGetPath("%{_sourcedir}/", p->source, NULL); + + rasprintf(&buf, "%s%d", + (flag & RPMBUILD_ISPATCH) ? "PATCH" : "SOURCE", num); + addMacro(spec->macros, buf, NULL, body, RMIL_SPEC); + free(buf); + rasprintf(&buf, "%sURL%d", + (flag & RPMBUILD_ISPATCH) ? "PATCH" : "SOURCE", num); + addMacro(spec->macros, buf, NULL, p->fullSource, RMIL_SPEC); + free(buf); +#ifdef WITH_LUA + if (!spec->recursing) { + rpmlua lua = NULL; /* global state */ + const char * what = (flag & RPMBUILD_ISPATCH) ? "patches" : "sources"; + rpmluaPushTable(lua, what); + rpmluav var = rpmluavNew(); + rpmluavSetListMode(var, 1); + rpmluavSetValue(var, RPMLUAV_STRING, body); + rpmluaSetVar(lua, var); + var = rpmluavFree(var); + rpmluaPop(lua); + } +#endif + body = _free(body); + } + + return 0; +} + typedef const struct tokenBits_s { const char * name; rpmsenseFlags bits; diff --git a/build/rpmspec.h b/build/rpmspec.h index 7948831..ef68c79 100644 --- a/build/rpmspec.h +++ b/build/rpmspec.h @@ -210,15 +210,6 @@ struct OpenFileInfo * newOpenFileInfo(void); */ spectag stashSt(rpmSpec spec, Header h, rpmTag tag, const char * lang); -/** \ingroup rpmbuild - * addSource. - * @param spec spec file control structure - * @param pkg package control - * @param field field to parse - * @param tag tag - */ -int addSource(rpmSpec spec, Package pkg, const char * field, rpmTag tag); - #ifdef __cplusplus } #endif diff --git a/build/spec.c b/build/spec.c index d07dbd2..aee609b 100644 --- a/build/spec.c +++ b/build/spec.c @@ -183,128 +183,6 @@ Package freePackages(Package packages) return NULL; } -int addSource(rpmSpec spec, Package pkg, const char *field, rpmTag tag) -{ - struct Source *p; - int flag = 0; - const char *name = NULL; - char *nump; - char *fieldp = NULL; - char *buf = NULL; - uint32_t num = 0; - - switch (tag) { - case RPMTAG_SOURCE: - flag = RPMBUILD_ISSOURCE; - name = "source"; - fieldp = spec->line + 6; - break; - case RPMTAG_PATCH: - flag = RPMBUILD_ISPATCH; - name = "patch"; - fieldp = spec->line + 5; - break; - case RPMTAG_ICON: - flag = RPMBUILD_ISICON; - fieldp = NULL; - break; - default: - return -1; - break; - } - - /* Get the number */ - if (tag != RPMTAG_ICON) { - /* We already know that a ':' exists, and that there */ - /* are no spaces before it. */ - /* This also now allows for spaces and tabs between */ - /* the number and the ':' */ - char ch; - char *fieldp_backup = fieldp; - - while ((*fieldp != ':') && (*fieldp != ' ') && (*fieldp != '\t')) { - fieldp++; - } - ch = *fieldp; - *fieldp = '\0'; - - nump = fieldp_backup; - SKIPSPACE(nump); - if (nump == NULL || *nump == '\0') { - num = flag == RPMBUILD_ISSOURCE ? 0 : INT_MAX; - } else { - if (parseUnsignedNum(fieldp_backup, &num)) { - rpmlog(RPMLOG_ERR, _("line %d: Bad %s number: %s\n"), - spec->lineNum, name, spec->line); - *fieldp = ch; - return RPMRC_FAIL; - } - } - *fieldp = ch; - } - - /* Check whether tags of the same number haven't already been defined */ - for (p = spec->sources; p != NULL; p = p->next) { - if ( p->num != num ) continue; - if ((tag == RPMTAG_SOURCE && p->flags == RPMBUILD_ISSOURCE) || - (tag == RPMTAG_PATCH && p->flags == RPMBUILD_ISPATCH)) { - rpmlog(RPMLOG_ERR, _("%s %d defined multiple times\n"), name, num); - return RPMRC_FAIL; - } - } - - /* Create the entry and link it in */ - p = xmalloc(sizeof(*p)); - p->num = num; - p->fullSource = xstrdup(field); - p->flags = flag; - p->source = strrchr(p->fullSource, '/'); - if (p->source) { - p->source++; - } else { - p->source = p->fullSource; - } - - if (tag != RPMTAG_ICON) { - p->next = spec->sources; - spec->sources = p; - } else { - p->next = pkg->icon; - pkg->icon = p; - } - - spec->numSources++; - - if (tag != RPMTAG_ICON) { - char *body = rpmGetPath("%{_sourcedir}/", p->source, NULL); - - rasprintf(&buf, "%s%d", - (flag & RPMBUILD_ISPATCH) ? "PATCH" : "SOURCE", num); - addMacro(spec->macros, buf, NULL, body, RMIL_SPEC); - free(buf); - rasprintf(&buf, "%sURL%d", - (flag & RPMBUILD_ISPATCH) ? "PATCH" : "SOURCE", num); - addMacro(spec->macros, buf, NULL, p->fullSource, RMIL_SPEC); - free(buf); -#ifdef WITH_LUA - if (!spec->recursing) { - rpmlua lua = NULL; /* global state */ - const char * what = (flag & RPMBUILD_ISPATCH) ? "patches" : "sources"; - rpmluaPushTable(lua, what); - rpmluav var = rpmluavNew(); - rpmluavSetListMode(var, 1); - rpmluavSetValue(var, RPMLUAV_STRING, body); - rpmluaSetVar(lua, var); - var = rpmluavFree(var); - rpmluaPop(lua); - } -#endif - body = _free(body); - } - - return 0; -} - /** */ static inline speclines freeSl(speclines sl) -- 2.7.4