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