rpm  5.4.14
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;
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 !defined(RPM_VENDOR_MANDRIVA) && !defined(RPM_VENDOR_PLD) /* mdvbz#62979 */
96  if (spec->packages->header != pkg->header) {
97  he->tag = RPMTAG_DESCRIPTION;
98  xx = headerGet(pkg->header, he, 0);
99  he->p.ptr = _free(he->p.ptr);
100  if (xx && he->t == RPM_STRING_TYPE)
101  xx = headerDel(pkg->header, he, 0);
102  }
103 #endif
104 
105  t = stashSt(spec, pkg->header, RPMTAG_DESCRIPTION, lang);
106 
107  iob = rpmiobNew(0);
108 
109  if ((rc = readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
110  nextPart = PART_NONE;
111  goto exit;
112  }
113  if (rc < 0) {
114  nextPart = (rpmParseState) RPMRC_FAIL;
115  goto exit;
116  }
117 
118  while ((nextPart = isPart(spec)) == PART_NONE) {
119  iob = rpmiobAppend(iob, spec->line, 1);
120  if (t) t->t_nlines++;
121  if ((rc = readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
122  nextPart = PART_NONE;
123  break;
124  }
125  if (rc) {
126  nextPart = (rpmParseState) RPMRC_FAIL;
127  goto exit;
128  }
129  }
130 
131  iob = rpmiobRTrim(iob);
132  if (!(noLang && strcmp(lang, RPMBUILD_DEFAULT_LANG))) {
133 #if defined(SUPPORT_I18NSTRING_TYPE)
134  const char * s = rpmiobStr(iob);
135  (void) headerAddI18NString(pkg->header, RPMTAG_DESCRIPTION, s, lang);
136 #else
138  he->tag = RPMTAG_DESCRIPTION;
139  he->t = RPM_STRING_TYPE;
140  he->p.str = rpmiobStr(iob);
141  he->c = 1;
142  xx = headerPut(pkg->header, he, 0);
143  }
144 #endif
145  }
146 
147 exit:
148  iob = rpmiobFree(iob);
149  argv = _free(argv);
150  optCon = poptFreeContext(optCon);
151  return nextPart;
152 }
rpmTagType t
Definition: rpmtag.h:502
rpmiob rpmiobRTrim(rpmiob iob)
Trim trailing white space.
Definition: rpmiob.c:67
const char * str
Definition: rpmtag.h:73
int xx
Definition: spec.c:744
rpmTag tag
Definition: rpmtag.h:501
static struct poptOption optionsTable[]
rpmlog(RPMLOG_ERR,"%s\n", buf)
return se
Definition: macro.c:897
int rc
Definition: poptALL.c:670
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
rpmiob rpmiobFree(rpmiob iob)
Destroy a I/O buffer instance.
rpmiob rpmiobAppend(rpmiob iob, const char *s, size_t nl)
Append string to I/O buffer.
Definition: rpmiob.c:77
spectag stashSt(Spec spec, Header h, rpmTag tag, const char *lang)
stashSt.
argv
Definition: rpmmtree.c:3679
struct rpmiob_s * rpmiob
Definition: rpmiotypes.h:60
char * alloca()
Yet Another syslog(3) API clone.
goto exit
Definition: db3.c:1903
memset(_r, 0, sizeof(*_r))
Header header
Definition: rpmspec.h:217
int headerDel(Header h, HE_t he, unsigned int flags)
Remove tag container from header.
Definition: header.c:2312
void * ptr
Definition: rpmtag.h:67
rpmParseState isPart(Spec spec)
Check line for section separator, return next parser state.
Definition: parseSpec.c:64
char * line
Definition: rpmspec.h:138
#define PART_SUBNAME
Definition: rpmbuild.h:49
rpmTagData p
Definition: rpmtag.h:504
struct _HE_s * HE_t
Destroy an extension cache.
Definition: rpmtag.h:59
int headerGet(Header h, HE_t he, unsigned int flags)
Retrieve extension or tag value from a header.
Definition: header.c:2230
int headerPut(Header h, HE_t he, unsigned int flags)
Add or append tag container to header.
Definition: header.c:2293
rpmTagCount c
Definition: rpmtag.h:505
static const char * lang
The structure used to store values parsed from a spec file.
Definition: rpmspec.h:113
rpmiob rpmiobNew(size_t len)
Create an I/O buffer.
Definition: rpmiob.c:44
optCon
Definition: poptALL.c:604
char * rpmiobStr(rpmiob iob)
Return I/O buffer (as string).
Definition: rpmiob.c:112
Package packages
Definition: rpmspec.h:204
Definition: rpmtag.h:500
return strcmp(ame->name, bme->name)
const char * s
Definition: poptALL.c:734
char * t
Definition: rpmds.c:2716
This is the only module users of librpmbuild should need to include.
int parseDescription(Spec spec)
Parse %description section of a spec file.
int noLang
Definition: poptBT.c:57
int t_nlines
Definition: rpmspec.h:85
enum rpmParseState_e rpmParseState
int lineNum
Definition: rpmspec.h:139
return NULL
Definition: poptALL.c:613
static void
Print copy of spec file, filling in Group/Description/Summary from specspo.
Definition: spec.c:737
static const char * name
#define _(Text)
Definition: system.h:29
The structure used to store values for a package.
Definition: rpmspec.h:214
poptContext
Definition: poptALL.c:525
#define RPMBUILD_DEFAULT_LANG
Definition: rpmspec.h:40
int readLine(Spec spec, rpmStripFlags strip)
Read next line from spec file.
Definition: parseSpec.c:351
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
Definition: rpmiotypes.h:647
Spec spec
Definition: spec-py.c:121