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