rpm 5.2.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

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
32 int parseDescription(Spec spec)
33 /*@globals name, lang @*/
34 /*@modifies name, lang @*/
35 {
36 rpmParseState nextPart = (rpmParseState) RPMRC_FAIL; /* assume error */
37 rpmiob iob;
38 int flag = PART_SUBNAME;
39 Package pkg;
40 int rc, argc;
41 int arg;
42 const char **argv = NULL;
43 poptContext optCon = NULL;
44 spectag t = NULL;
45
46 { char * se = strchr(spec->line, '#');
47 if (se) {
48 *se = '\0';
49 while (--se >= spec->line && strchr(" \t\n\r", *se) != NULL)
50 *se = '\0';
51 }
52 }
53
54 if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
55 rpmlog(RPMLOG_ERR, _("line %d: Error parsing %%description: %s\n"),
56 spec->lineNum, poptStrerror(rc));
57 return RPMRC_FAIL;
58 }
59
60 name = NULL;
61 lang = RPMBUILD_DEFAULT_LANG;
62 optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
63 while ((arg = poptGetNextOpt(optCon)) > 0)
64 {;}
65 if (name != NULL)
66 flag = PART_NAME;
67
68 if (arg < -1) {
69 rpmlog(RPMLOG_ERR, _("line %d: Bad option %s: %s\n"),
70 spec->lineNum,
71 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
72 spec->line);
73 goto exit;
74 }
75
76 if (poptPeekArg(optCon)) {
77 if (name == NULL)
78 name = poptGetArg(optCon);
79 if (poptPeekArg(optCon)) {
80 rpmlog(RPMLOG_ERR, _("line %d: Too many names: %s\n"),
81 spec->lineNum, spec->line);
82 goto exit;
83 }
84 }
85
86 if (lookupPackage(spec, name, flag, &pkg) != RPMRC_OK) {
87 rpmlog(RPMLOG_ERR, _("line %d: Package does not exist: %s\n"),
88 spec->lineNum, spec->line);
89 goto exit;
90 }
91
92 /* Lose the inheirited %description (if present). */
93 { HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
94 int xx;
95 he->tag = RPMTAG_DESCRIPTION;
96 xx = headerGet(pkg->header, he, 0);
97 he->p.ptr = _free(he->p.ptr);
98 if (xx && he->t == RPM_STRING_TYPE)
99 xx = headerDel(pkg->header, he, 0);
100 }
101
102 t = stashSt(spec, pkg->header, RPMTAG_DESCRIPTION, lang);
103
104 iob = rpmiobNew(0);
105
106 if ((rc = readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
107 nextPart = PART_NONE;
108 } else {
109 if (rc) {
110 nextPart = (rpmParseState) RPMRC_FAIL;
111 goto exit;
112 }
113 while ((nextPart = isPart(spec)) == PART_NONE) {
114 iob = rpmiobAppend(iob, spec->line, 1);
115 if (t) t->t_nlines++;
116 if ((rc =
117 readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
118 nextPart = PART_NONE;
119 break;
120 }
121 if (rc) {
122 nextPart = (rpmParseState) RPMRC_FAIL;
123 goto exit;
124 }
125 }
126 }
127
128 iob = rpmiobRTrim(iob);
129 if (!(noLang && strcmp(lang, RPMBUILD_DEFAULT_LANG))) {
130 (void) headerAddI18NString(pkg->header, RPMTAG_DESCRIPTION,
131 rpmiobStr(iob), lang);
132 }
133
134 iob = rpmiobFree(iob);
135
136 exit:
137 argv = _free(argv);
138 optCon = poptFreeContext(optCon);
139 return nextPart;
140 }