rpm  5.4.10
parseDescription.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 /*@-exportheadervar@*/
15 /*@unchecked@*/
16 extern int noLang;
17 /*@=exportheadervar@*/
18 
19 /* These have to be global scope to make up for *stupid* compilers */
20 /*@unchecked@*/
21  /*@observer@*/ /*@null@*/ static const char *name = NULL;
22 /*@unchecked@*/
23  /*@observer@*/ /*@null@*/ static const char *lang = NULL;
24 
25 /*@unchecked@*/
26  static struct poptOption optionsTable[] = {
27  { NULL, 'n', POPT_ARG_STRING, &name, 0, NULL, NULL},
28  { NULL, 'l', POPT_ARG_STRING, &lang, 0, NULL, NULL},
29  { 0, 0, 0, 0, 0, NULL, NULL}
30  };
31 
33  /*@globals name, lang @*/
34  /*@modifies name, lang @*/
35 {
36  HE_t he = (HE_t) memset(alloca(sizeof(*he)), 0, sizeof(*he));
37  rpmParseState nextPart = (rpmParseState) RPMRC_FAIL; /* assume error */
38  rpmiob iob = NULL;
39  int flag = PART_SUBNAME;
40  Package pkg;
41  int rc, argc;
42  int arg;
43  const char **argv = NULL;
44  poptContext optCon = NULL;
45  spectag t = NULL;
46  int xx;
47 
48  { char * se = strchr(spec->line, '#');
49  if (se) {
50  *se = '\0';
51  while (--se >= spec->line && strchr(" \t\n\r", *se) != NULL)
52  *se = '\0';
53  }
54  }
55 
56  if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
57  rpmlog(RPMLOG_ERR, _("line %d: Error parsing %%description: %s\n"),
58  spec->lineNum, poptStrerror(rc));
59  goto exit;
60  }
61 
62  name = NULL;
64  optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
65  while ((arg = poptGetNextOpt(optCon)) > 0)
66  {;}
67  if (name != NULL)
68  flag = PART_NAME;
69 
70  if (arg < -1) {
71  rpmlog(RPMLOG_ERR, _("line %d: Bad option %s: %s\n"),
72  spec->lineNum,
73  poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
74  spec->line);
75  goto exit;
76  }
77 
78  if (poptPeekArg(optCon)) {
79  if (name == NULL)
80  name = poptGetArg(optCon);
81  if (poptPeekArg(optCon)) {
82  rpmlog(RPMLOG_ERR, _("line %d: Too many names: %s\n"),
83  spec->lineNum, spec->line);
84  goto exit;
85  }
86  }
87 
88  if (lookupPackage(spec, name, flag, &pkg) != RPMRC_OK) {
89  rpmlog(RPMLOG_ERR, _("line %d: Package does not exist: %s\n"),
90  spec->lineNum, spec->line);
91  goto exit;
92  }
93 
94  /* Lose the inheirited %description (if present). */
95  if (spec->packages->header != pkg->header) {
96  he->tag = RPMTAG_DESCRIPTION;
97  xx = headerGet(pkg->header, he, 0);
98  he->p.ptr = _free(he->p.ptr);
99  if (xx && he->t == RPM_STRING_TYPE)
100  xx = headerDel(pkg->header, he, 0);
101  }
102 
103  t = stashSt(spec, pkg->header, RPMTAG_DESCRIPTION, lang);
104 
105  iob = rpmiobNew(0);
106 
107  if ((rc = readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
108  nextPart = PART_NONE;
109  goto exit;
110  }
111  if (rc < 0) {
112  nextPart = (rpmParseState) RPMRC_FAIL;
113  goto exit;
114  }
115 
116  while ((nextPart = isPart(spec)) == PART_NONE) {
117  iob = rpmiobAppend(iob, spec->line, 1);
118  if (t) t->t_nlines++;
119  if ((rc = readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
120  nextPart = PART_NONE;
121  break;
122  }
123  if (rc) {
124  nextPart = (rpmParseState) RPMRC_FAIL;
125  goto exit;
126  }
127  }
128 
129  iob = rpmiobRTrim(iob);
130  if (!(noLang && strcmp(lang, RPMBUILD_DEFAULT_LANG))) {
131 #if defined(SUPPORT_I18NSTRING_TYPE)
132  const char * s = rpmiobStr(iob);
133  (void) headerAddI18NString(pkg->header, RPMTAG_DESCRIPTION, s, lang);
134 #else
135  if (!strcmp(lang, RPMBUILD_DEFAULT_LANG)) {
136  he->tag = RPMTAG_DESCRIPTION;
137  he->t = RPM_STRING_TYPE;
138  he->p.str = rpmiobStr(iob);
139  he->c = 1;
140  xx = headerPut(pkg->header, he, 0);
141  }
142 #endif
143  }
144 
145 exit:
146  iob = rpmiobFree(iob);
147  argv = _free(argv);
148  optCon = poptFreeContext(optCon);
149  return nextPart;
150 }
rpmTagType t
Definition: rpmtag.h:505
rpmiob rpmiobRTrim(rpmiob iob)
Trim trailing white space.
Definition: rpmiob.c:67
const char * str
Definition: rpmtag.h:72
rpmTag tag
Definition: rpmtag.h:504
rpmParseState isPart(Spec spec)
Check line for section separator, return next parser state.
Definition: parseSpec.c:68
static struct poptOption optionsTable[]
int parseDescription(Spec spec)
Parse %description section of a spec file.
int headerGet(Header h, HE_t he, unsigned int flags)
Retrieve extension or tag value from a header.
Definition: header.c:2222
int headerPut(Header h, HE_t he, unsigned int flags)
Add or append tag container to header.
Definition: header.c:2285
rpmRC lookupPackage(Spec spec, const char *name, int flag, Package *pkg)
Find sub-package control structure by name.
Definition: spec.c:82
#define PART_NAME
Definition: rpmbuild.h:49
int headerDel(Header h, HE_t he, unsigned int flags)
Remove tag container from header.
Definition: header.c:2304
rpmiob rpmiobFree(rpmiob iob)
Destroy a I/O buffer instance.
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:78
int readLine(Spec spec, rpmStripFlags strip)
Read next line from spec file.
Definition: parseSpec.c:353
char * alloca()
Yet Another syslog(3) API clone.
Header header
Definition: rpmspec.h:210
struct _HE_s * HE_t
Definition: rpmtag.h:58
void * ptr
Definition: rpmtag.h:66
char * line
Definition: rpmspec.h:133
#define PART_SUBNAME
Definition: rpmbuild.h:48
rpmTagData p
Definition: rpmtag.h:507
rpmTagCount c
Definition: rpmtag.h:508
static const char * lang
The structure used to store values parsed from a spec file.
Definition: rpmspec.h:108
spectag stashSt(Spec spec, Header h, rpmTag tag, const char *lang)
stashSt.
rpmiob rpmiobNew(size_t len)
Create an I/O buffer.
Definition: rpmiob.c:44
char * rpmiobStr(rpmiob iob)
Return I/O buffer (as string).
Definition: rpmiob.c:113
Package packages
Definition: rpmspec.h:197
Definition: rpmtag.h:503
This is the only module users of librpmbuild should need to include.
int noLang
Definition: poptBT.c:57
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
Definition: rpmiotypes.h:647
struct rpmiob_s * rpmiob
Definition: rpmiotypes.h:57
int t_nlines
Definition: rpmspec.h:80
enum rpmParseState_e rpmParseState
int lineNum
Definition: rpmspec.h:134
static const char * name
#define _(Text)
Definition: system.h:30
The structure used to store values for a package.
Definition: rpmspec.h:207
#define RPMBUILD_DEFAULT_LANG
Definition: rpmspec.h:35