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