- fix: extra newline in many error messages (#23947).
[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 "rpmbuild.h"
8 #include "debug.h"
9
10 int parseBuildInstallClean(Spec spec, rpmParseState parsePart)
11 {
12     int nextPart, rc;
13     StringBuf *sbp = NULL;
14     const char *name = NULL;
15
16     if (parsePart == PART_BUILD) {
17         sbp = &(spec->build);
18         name = "%build";
19     } else if (parsePart == PART_INSTALL) {
20         sbp = &(spec->install);
21         name = "%install";
22     } else if (parsePart == PART_CLEAN) {
23         sbp = &(spec->clean);
24         name = "%clean";
25     }
26     
27     if (*sbp != NULL) {
28         rpmError(RPMERR_BADSPEC, _("line %d: second %s\n"),
29                 spec->lineNum, name);
30         return RPMERR_BADSPEC;
31     }
32     
33     *sbp = newStringBuf();
34
35     /* There are no options to %build, %install, or %clean */
36     if ((rc = readLine(spec, STRIP_NOTHING)) > 0)
37         return PART_NONE;
38     if (rc)
39         return rc;
40     
41     while (! (nextPart = isPart(spec->line))) {
42         appendStringBuf(*sbp, spec->line);
43         if ((rc = readLine(spec, STRIP_NOTHING)) > 0)
44             return PART_NONE;
45         if (rc)
46             return rc;
47     }
48
49     return nextPart;
50 }