Make parseBuildInstallClean() return PART_ERROR on errors, streamline exits
[platform/upstream/rpm.git] / build / parseBuildInstallClean.c
1 /** \ingroup rpmbuild
2  * \file build/parseBuildInstallClean.c
3  *  Parse %build/%install/%clean section from spec file.
4  */
5 #include "system.h"
6
7 #include <rpm/rpmbuild.h>
8 #include <rpm/rpmlog.h>
9 #include "debug.h"
10
11
12 int parseBuildInstallClean(rpmSpec spec, rpmParseState parsePart)
13 {
14     int nextPart, rc, res = PART_ERROR;
15     StringBuf *sbp = NULL;
16     const char *name = NULL;
17
18     if (parsePart == PART_BUILD) {
19         sbp = &(spec->build);
20         name = "%build";
21     } else if (parsePart == PART_INSTALL) {
22         sbp = &(spec->install);
23         name = "%install";
24     } else if (parsePart == PART_CHECK) {
25         sbp = &(spec->check);
26         name = "%check";
27     } else if (parsePart == PART_CLEAN) {
28         sbp = &(spec->clean);
29         name = "%clean";
30     }
31     
32     if (*sbp != NULL) {
33         rpmlog(RPMLOG_ERR, _("line %d: second %s\n"),
34                 spec->lineNum, name);
35         goto exit;
36     }
37     
38     *sbp = newStringBuf();
39
40     /* There are no options to %build, %install, %check, or %clean */
41     if ((rc = readLine(spec, STRIP_NOTHING)) > 0) {
42         res = PART_NONE;
43         goto exit;
44     } else if (rc < 0) {
45         goto exit;
46     }
47     
48     while (! (nextPart = isPart(spec->line))) {
49         appendStringBuf(*sbp, spec->line);
50         if ((rc = readLine(spec, STRIP_NOTHING)) > 0) {
51             nextPart = PART_NONE;
52             break;
53         } else if (rc < 0) {
54             goto exit;
55         }
56     }
57     res = nextPart;
58     
59 exit:
60
61     return res;
62 }