Documentation sugar.
[platform/upstream/rpm.git] / build / parseFiles.c
1 /** \file build/parseFiles.c
2  *  Parse %files section from spec file.
3  */
4
5 #include "system.h"
6
7 #include "rpmbuild.h"
8
9 /* These have to be global scope to make up for *stupid* compilers */
10     /*@observer@*/ /*@null@*/ static const char *name = NULL;
11     /*@observer@*/ /*@null@*/ static const char *file = NULL;
12     static struct poptOption optionsTable[] = {
13         { NULL, 'n', POPT_ARG_STRING, &name, 'n',       NULL, NULL},
14         { NULL, 'f', POPT_ARG_STRING, &file, 'f',       NULL, NULL},
15         { 0, 0, 0, 0, 0,        NULL, NULL}
16     };
17
18 /** */
19 int parseFiles(Spec spec)
20 {
21     int nextPart;
22     Package pkg;
23     int rc, argc;
24     int arg;
25     const char **argv = NULL;
26     int flag = PART_SUBNAME;
27     poptContext optCon = NULL;
28
29     name = file = NULL;
30
31     if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
32         rpmError(RPMERR_BADSPEC, _("line %d: Error parsing %%files: %s"),
33                  spec->lineNum, poptStrerror(rc));
34         return RPMERR_BADSPEC;
35     }
36
37     optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
38     while ((arg = poptGetNextOpt(optCon)) > 0) {
39         if (arg == 'n') {
40             flag = PART_NAME;
41         }
42     }
43
44     if (arg < -1) {
45         rpmError(RPMERR_BADSPEC, _("line %d: Bad option %s: %s"),
46                  spec->lineNum,
47                  poptBadOption(optCon, POPT_BADOPTION_NOALIAS), 
48                  spec->line);
49         FREE(argv);
50         poptFreeContext(optCon);
51         return RPMERR_BADSPEC;
52     }
53
54     if (poptPeekArg(optCon)) {
55         if (name == NULL)
56             name = poptGetArg(optCon);
57         if (poptPeekArg(optCon)) {
58             rpmError(RPMERR_BADSPEC, _("line %d: Too many names: %s"),
59                      spec->lineNum,
60                      spec->line);
61             FREE(argv);
62             poptFreeContext(optCon);
63             return RPMERR_BADSPEC;
64         }
65     }
66
67     if (lookupPackage(spec, name, flag, &pkg)) {
68         rpmError(RPMERR_BADSPEC, _("line %d: Package does not exist: %s"),
69                  spec->lineNum, spec->line);
70         FREE(argv);
71         poptFreeContext(optCon);
72         return RPMERR_BADSPEC;
73     }
74
75     if (pkg->fileList != NULL) {
76         rpmError(RPMERR_BADSPEC, _("line %d: Second %%files list"),
77                  spec->lineNum);
78         FREE(argv);
79         poptFreeContext(optCon);
80         return RPMERR_BADSPEC;
81     }
82
83     if (file) {
84         pkg->fileFile = xstrdup(file);
85     }
86     pkg->fileList = newStringBuf();
87     
88     if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
89         nextPart = PART_NONE;
90     } else {
91         if (rc) {
92             return rc;
93         }
94         while (! (nextPart = isPart(spec->line))) {
95             appendStringBuf(pkg->fileList, spec->line);
96             if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
97                 nextPart = PART_NONE;
98                 break;
99             }
100             if (rc) {
101                 return rc;
102             }
103         }
104     }
105
106     FREE(argv);
107     poptFreeContext(optCon);
108         
109     return nextPart;
110 }