1. creating functions restoreFirstChar(), copyNextLineFromOFI() and copyNextLineFinish() out of copyNextLine() 2. creating function readLineFromOFI() out of readLine() diff -r 72d1c4be6809 build/parseSpec.c --- build/parseSpec.c Tue Dec 18 13:42:42 2007 +0200 +++ build/parseSpec.c Thu Dec 20 21:35:36 2007 +0100 @@ -114,18 +114,21 @@ static void forceIncludeFile(rpmSpec spe spec->fileStack = ofi; } -/** - */ -static int copyNextLine(rpmSpec spec, OFI_t *ofi, int strip) +static int restoreFirstChar(rpmSpec spec) { - char *last; - char ch; - /* Restore 1st char in (possible) next line */ if (spec->nextline != NULL && spec->nextpeekc != '\0') { *spec->nextline = spec->nextpeekc; spec->nextpeekc = '\0'; + return 1; } + return 0; +} + +static int copyNextLineFromOFI(rpmSpec spec, OFI_t *ofi) +{ + char ch; + /* Expand next line from file into line buffer */ if (!(spec->nextline && *spec->nextline)) { int pc = 0, bc = 0, nc = 0; @@ -181,6 +184,13 @@ static int copyNextLine(rpmSpec spec, OF } spec->nextline = spec->lbuf; } + return 0; +} + +static void copyNextLineFinish(rpmSpec spec, int strip) +{ + char *last; + char ch; /* Find next line in expanded line buffer */ spec->line = last = spec->nextline; @@ -202,18 +212,24 @@ static int copyNextLine(rpmSpec spec, OF if (strip & STRIP_TRAILINGSPACE) *last = '\0'; +} + +/** + */ +static int copyNextLine(rpmSpec spec, OFI_t *ofi, int strip) +{ + restoreFirstChar(spec); + + int rc = copyNextLineFromOFI(spec, ofi); + if (rc != 0) return rc; + + copyNextLineFinish(spec, strip); return 0; } -int readLine(rpmSpec spec, int strip) +static int readLineFromOFI(rpmSpec spec, OFI_t *ofi) { - char *s; - int match; - struct ReadLevelEntry *rl; - OFI_t *ofi = spec->fileStack; - int rc; - retry: /* Make sure the current file is open */ if (ofi->fd == NULL) { @@ -264,7 +280,21 @@ retry: sl->sl_lines[sl->sl_nlines++] = xstrdup(ofi->readBuf); } } - + return 0; +} + +int readLine(rpmSpec spec, int strip) +{ + char *s; + int match; + struct ReadLevelEntry *rl; + OFI_t *ofi = spec->fileStack; + int rc; + + retry: + if ((rc = readLineFromOFI(spec, ofi)) != 0) + return rc; + /* Copy next file line into the spec line buffer */ if ((rc = copyNextLine(spec, ofi, strip)) != 0) { if (rc == RPMRC_FAIL)