rpm  5.4.15
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 
117 #if defined(RPM_VENDOR_MANDRIVA)
118  /* if no %clean section, add implicit */
119  rc = (nextPart == PART_NONE && spec->clean == NULL) ? PART_CLEAN : nextPart;
120 #else
121  rc = nextPart;
122 #endif
123 
124 exit:
125  argv = _free(argv);
126  optCon = poptFreeContext(optCon);
127 
128  return rc;
129 }
rpmParseState isPart(Spec spec)
Check line for section separator, return next parser state.
Definition: parseSpec.c:64
rpmiob clean
Definition: rpmspec.h:194
rpmiob fileList
Definition: rpmspec.h:253
char * rpmGetPath(const char *path,...)
Return (malloc'ed) expanded, canonicalized, file path.
Definition: macro.c:3443
const char * fileFile
Definition: rpmspec.h:251
rpmRC lookupPackage(Spec spec, const char *name, int flag, Package *pkg)
Find sub-package control structure by name.
Definition: spec.c:78
#define PART_NAME
Definition: rpmbuild.h:50
static void rpmlog(int code, const char *fmt,...)
Definition: rpmlog.h:299
rpmiob rpmiobAppend(rpmiob iob, const char *s, size_t nl)
Append string to I/O buffer.
Definition: rpmiob.c:77
int readLine(Spec spec, rpmStripFlags strip)
Read next line from spec file.
Definition: parseSpec.c:351
Yet Another syslog(3) API clone.
char * line
Definition: rpmspec.h:138
#define PART_SUBNAME
Definition: rpmbuild.h:49
static const char * file
Definition: parseFiles.c:20
static const char * name
Definition: parseFiles.c:18
The structure used to store values parsed from a spec file.
Definition: rpmspec.h:113
int parseFiles(Spec spec)
Parse %files section of a spec file.
Definition: parseFiles.c:28
const char const char int arg
Definition: mongo.h:777
rpmiob rpmiobNew(size_t len)
Create an I/O buffer.
Definition: rpmiob.c:44
This is the only module users of librpmbuild should need to include.
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
Definition: rpmiotypes.h:756
enum rpmParseState_e rpmParseState
int lineNum
Definition: rpmspec.h:139
#define _(Text)
Definition: system.h:29
The structure used to store values for a package.
Definition: rpmspec.h:214
static struct poptOption optionsTable[]
Definition: parseFiles.c:22