Realize the remaining bits of direct rpmdb interface are dead too
[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     } else {
31         goto exit; /* programmer error */
32     }
33     
34     if (*sbp != NULL) {
35         rpmlog(RPMLOG_ERR, _("line %d: second %s\n"),
36                 spec->lineNum, name);
37         goto exit;
38     }
39     
40     *sbp = newStringBuf();
41
42     /* There are no options to %build, %install, %check, or %clean */
43     if ((rc = readLine(spec, STRIP_NOTHING)) > 0) {
44         res = PART_NONE;
45         goto exit;
46     } else if (rc < 0) {
47         goto exit;
48     }
49     
50     while (! (nextPart = isPart(spec->line))) {
51         appendStringBuf(*sbp, spec->line);
52         if ((rc = readLine(spec, STRIP_NOTHING)) > 0) {
53             nextPart = PART_NONE;
54             break;
55         } else if (rc < 0) {
56             goto exit;
57         }
58     }
59     res = nextPart;
60     
61 exit:
62
63     return res;
64 }