summaryrefslogtreecommitdiff
path: root/build
diff options
context:
space:
mode:
Diffstat (limited to 'build')
-rw-r--r--build/parseSpec.c90
-rw-r--r--build/rpmspec.h12
-rw-r--r--build/spec.c4
3 files changed, 63 insertions, 43 deletions
diff --git a/build/parseSpec.c b/build/parseSpec.c
index 73e542614..72464d6bc 100644
--- a/build/parseSpec.c
+++ b/build/parseSpec.c
@@ -92,7 +92,7 @@ void handleComments(char *s)
static void forceIncludeFile(Spec spec, const char * fileName)
{
- struct OpenFileInfo * ofi;
+ OFI_t * ofi;
ofi = newOpenFileInfo();
ofi->fileName = strdup(fileName);
@@ -100,21 +100,61 @@ static void forceIncludeFile(Spec spec, const char * fileName)
spec->fileStack = ofi;
}
+static int copyNextLine(Spec spec, OFI_t *ofi, int strip)
+{
+ char *last;
+ char ch;
+
+ /* Expand next line from file into line buffer */
+ if (!(spec->nextline && *spec->nextline)) {
+ char *from, *to;
+ to = last = spec->nextline = spec->lbuf;
+ from = ofi->readPtr;
+ while ((ch = *from) && ch != '\n')
+ *to++ = *from++;
+ *to++ = '\0';
+ ofi->readPtr = from;
+
+ if (expandMacros(spec, spec->macros, spec->lbuf, sizeof(spec->lbuf))) {
+ rpmError(RPMERR_BADSPEC, _("line %d: %s"), spec->lineNum, spec->lbuf);
+ return RPMERR_BADSPEC;
+ }
+ }
+
+ /* Find next line in expanded line buffer */
+ spec->line = spec->nextline;
+ while ((ch = *spec->nextline) && ch != '\n') {
+ spec->nextline++;
+ if (!isspace(ch))
+ last = spec->nextline;
+ }
+ if (ch == '\n')
+ *spec->nextline++ = '\0';
+
+ if (strip & STRIP_COMMENTS)
+ handleComments(spec->line);
+
+ if (strip & STRIP_TRAILINGSPACE)
+ *last = '\0';
+
+ return 0;
+}
+
/* returns 0 - success */
/* 1 - EOF */
/* <0 - error */
int readLine(Spec spec, int strip)
{
- char *from, *to, *last, *s, *arch, *os;
+ char *s, *arch, *os;
int match;
- char ch;
struct ReadLevelEntry *rl;
- struct OpenFileInfo *ofi = spec->fileStack;
+ OFI_t *ofi = spec->fileStack;
+ int rc;
- /* Make sure the current file is open */
retry:
- if (!ofi->file) {
+ /* Make sure the current file is open */
+ if (ofi->file == NULL) {
if (!(ofi->file = fopen(ofi->fileName, "r"))) {
rpmError(RPMERR_BADSPEC, _("Unable to open: %s\n"),
ofi->fileName);
@@ -124,7 +164,7 @@ retry:
}
/* Make sure we have something in the read buffer */
- if (!ofi->readPtr || ! *(ofi->readPtr)) {
+ if (!(ofi->readPtr && *(ofi->readPtr))) {
if (!fgets(ofi->readBuf, BUFSIZ, ofi->file)) {
/* EOF */
if (spec->readStack->next) {
@@ -158,42 +198,18 @@ retry:
}
sl->sl_lines[sl->sl_nlines++] = strdup(ofi->readBuf);
}
- /*rpmMessage(RPMMESS_DEBUG, "LINE: %s", spec->readBuf);*/
- }
-
- /* Copy a single line to the line buffer */
- from = ofi->readPtr;
- to = last = spec->line;
- ch = ' ';
- while (*from && ch != '\n') {
- ch = *to++ = *from++;
- if (!isspace(ch)) {
- last = to;
- }
}
- *to = '\0';
- ofi->readPtr = from;
- if (strip & STRIP_COMMENTS) {
- handleComments(spec->line);
- }
-
- if (strip & STRIP_TRAILINGSPACE) {
- *last = '\0';
- }
-
- if (spec->readStack->reading) {
- if (expandMacros(spec, spec->macros, spec->line, sizeof(spec->line))) {
- rpmError(RPMERR_BADSPEC, _("line %d: %s"), spec->lineNum, spec->line);
- return RPMERR_BADSPEC;
- }
- }
-
rpmGetArchInfo(&arch, NULL);
rpmGetOsInfo(&os, NULL);
+ /* Copy next file line into the spec line buffer */
+ if ((rc = copyNextLine(spec, ofi, strip)) != 0)
+ return rc;
+
s = spec->line;
SKIPSPACE(s);
+
match = -1;
if (! strncmp("%ifarch", s, 7)) {
s += 7;
@@ -281,7 +297,7 @@ retry:
void closeSpec(Spec spec)
{
- struct OpenFileInfo *ofi;
+ OFI_t *ofi;
while (spec->fileStack) {
ofi = spec->fileStack;
diff --git a/build/rpmspec.h b/build/rpmspec.h
index fb7e4a811..208c3a897 100644
--- a/build/rpmspec.h
+++ b/build/rpmspec.h
@@ -37,19 +37,19 @@ struct Source {
/*@owned@*/ struct Source *next;
};
-struct ReadLevelEntry {
+typedef struct ReadLevelEntry {
int reading;
/*@dependent@*/ struct ReadLevelEntry *next;
-};
+} RLE_t;
-struct OpenFileInfo {
+typedef struct OpenFileInfo {
/*@only@*/ char *fileName;
/*@dependent@*/ FILE *file;
int lineNum;
char readBuf[BUFSIZ];
/*@dependent@*/ char *readPtr;
/*@owned@*/ struct OpenFileInfo *next;
-};
+} OFI_t;
struct spectag {
int t_tag;
@@ -80,7 +80,9 @@ struct SpecStruct {
struct spectags *st;
/*@owned@*/ struct OpenFileInfo *fileStack;
- char line[BUFSIZ];
+ char lbuf[BUFSIZ];
+ char *line;
+ char *nextline;
int lineNum;
/*@only@*/ struct ReadLevelEntry *readStack;
diff --git a/build/spec.c b/build/spec.c
index 76c803eb2..fa77546ea 100644
--- a/build/spec.c
+++ b/build/spec.c
@@ -404,7 +404,9 @@ Spec newSpec(void)
spec->st = newSt();
spec->fileStack = NULL;
- spec->line[0] = '\0';
+ spec->lbuf[0] = '\0';
+ spec->line = spec->lbuf;
+ spec->nextline = NULL;
spec->lineNum = 0;
spec->readStack = malloc(sizeof(struct ReadLevelEntry));
spec->readStack->next = NULL;