Make parseScript() return PART_ERROR on errors
authorPanu Matilainen <pmatilai@redhat.com>
Mon, 5 May 2008 07:56:55 +0000 (10:56 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Mon, 5 May 2008 07:56:55 +0000 (10:56 +0300)
- streamline exists by assuming failure

build/parseScript.c

index 82eaa4d..3e73b52 100644 (file)
@@ -88,6 +88,7 @@ int parseScript(rpmSpec spec, int parsePart)
     int index;
     char reqargs[BUFSIZ];
 
+    int res = PART_ERROR; /* assume failure */
     int rc, argc;
     int arg;
     const char **argv = NULL;
@@ -177,7 +178,7 @@ int parseScript(rpmSpec spec, int parsePart)
        if (!p) {
            rpmlog(RPMLOG_ERR, _("line %d: triggers must have --: %s\n"),
                     spec->lineNum, spec->line);
-           return RPMRC_FAIL;
+           return PART_ERROR;
        }
 
        *p = '\0';
@@ -187,7 +188,7 @@ int parseScript(rpmSpec spec, int parsePart)
     if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
        rpmlog(RPMLOG_ERR, _("line %d: Error parsing %s: %s\n"),
                 spec->lineNum, partname, poptStrerror(rc));
-       return RPMRC_FAIL;
+       return PART_ERROR;
     }
     
     optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
@@ -199,14 +200,12 @@ int parseScript(rpmSpec spec, int parsePart)
                    rpmlog(RPMLOG_ERR,
                             _("line %d: internal script must end "
                             "with \'>\': %s\n"), spec->lineNum, prog);
-                   rc = RPMRC_FAIL;
                    goto exit;
                }
            } else if (prog[0] != '/') {
                rpmlog(RPMLOG_ERR,
                         _("line %d: script program must begin "
                         "with \'/\': %s\n"), spec->lineNum, prog);
-               rc = RPMRC_FAIL;
                goto exit;
            }
            break;
@@ -221,7 +220,6 @@ int parseScript(rpmSpec spec, int parsePart)
                 spec->lineNum,
                 poptBadOption(optCon, POPT_BADOPTION_NOALIAS), 
                 spec->line);
-       rc = RPMRC_FAIL;
        goto exit;
     }
 
@@ -232,7 +230,6 @@ int parseScript(rpmSpec spec, int parsePart)
            rpmlog(RPMLOG_ERR, _("line %d: Too many names: %s\n"),
                     spec->lineNum,
                     spec->line);
-           rc = RPMRC_FAIL;
            goto exit;
        }
     }
@@ -240,7 +237,6 @@ int parseScript(rpmSpec spec, int parsePart)
     if (lookupPackage(spec, name, flag, &pkg)) {
        rpmlog(RPMLOG_ERR, _("line %d: Package does not exist: %s\n"),
                 spec->lineNum, spec->line);
-       rc = RPMRC_FAIL;
        goto exit;
     }
 
@@ -248,7 +244,6 @@ int parseScript(rpmSpec spec, int parsePart)
        if (headerIsEntry(pkg->header, progtag)) {
            rpmlog(RPMLOG_ERR, _("line %d: Second %s\n"),
                     spec->lineNum, partname);
-           rc = RPMRC_FAIL;
            goto exit;
        }
     }
@@ -256,24 +251,23 @@ int parseScript(rpmSpec spec, int parsePart)
     if ((rc = poptParseArgvString(prog, &progArgc, &progArgv))) {
        rpmlog(RPMLOG_ERR, _("line %d: Error parsing %s: %s\n"),
                 spec->lineNum, partname, poptStrerror(rc));
-       rc = RPMRC_FAIL;
        goto exit;
     }
 
     sb = newStringBuf();
     if ((rc = readLine(spec, STRIP_NOTHING)) > 0) {
        nextPart = PART_NONE;
+    } else if (rc < 0) {
+       goto exit;
     } else {
-       if (rc)
-           goto exit;
        while (! (nextPart = isPart(spec->line))) {
            appendStringBuf(sb, spec->line);
            if ((rc = readLine(spec, STRIP_NOTHING)) > 0) {
                nextPart = PART_NONE;
                break;
-           }
-           if (rc)
+           } else if (rc < 0) {
                goto exit;
+           }
        }
     }
     stripTrailingBlanksStringBuf(sb);
@@ -283,7 +277,6 @@ int parseScript(rpmSpec spec, int parsePart)
     if (!strcmp(progArgv[0], "<lua>")) {
        rpmlua lua = NULL; /* Global state. */
        if (rpmluaCheckScript(lua, p, partname) != RPMRC_OK) {
-           rc = RPMRC_FAIL;
            goto exit;
        }
        (void) rpmlibNeedsFeature(pkg->header,
@@ -294,7 +287,6 @@ int parseScript(rpmSpec spec, int parsePart)
        rpmlog(RPMLOG_ERR,
                 _("line %d: unsupported internal script: %s\n"),
                 spec->lineNum, progArgv[0]);
-       rc = RPMRC_FAIL;
        goto exit;
     } else {
         (void) addReqProv(spec, pkg->header, RPMTAG_REQUIRENAME,
@@ -350,7 +342,7 @@ int parseScript(rpmSpec spec, int parsePart)
            }
        }
     }
-    rc = nextPart;
+    res = nextPart;
     
 exit:
     sb = freeStringBuf(sb);
@@ -358,5 +350,5 @@ exit:
     argv = _free(argv);
     optCon = poptFreeContext(optCon);
     
-    return rc;
+    return res;
 }