rpm  4.5
parseDescription.c
Go to the documentation of this file.
1 
6 #include "system.h"
7 
8 #include "rpmbuild.h"
9 #include "debug.h"
10 
11 /*@-exportheadervar@*/
12 /*@unchecked@*/
13 extern int noLang;
14 /*@=exportheadervar@*/
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 *lang = NULL;
21 
22 /*@unchecked@*/
23  static struct poptOption optionsTable[] = {
24  { NULL, 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL},
25  { NULL, 'l', POPT_ARG_STRING, &lang, 'l', NULL, NULL},
26  { 0, 0, 0, 0, 0, NULL, NULL}
27  };
28 
30  /*@globals name, lang @*/
31  /*@modifies name, lang @*/
32 {
33  int nextPart = RPMERR_BADSPEC; /* assume error */
34  StringBuf sb;
35  int flag = PART_SUBNAME;
36  Package pkg;
37  int rc, argc;
38  int arg;
39  const char **argv = NULL;
40  poptContext optCon = NULL;
41  spectag t = NULL;
42 
43  name = NULL;
45 
46  if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
47  rpmError(RPMERR_BADSPEC, _("line %d: Error parsing %%description: %s\n"),
48  spec->lineNum, poptStrerror(rc));
49  return RPMERR_BADSPEC;
50  }
51 
52  optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
53  while ((arg = poptGetNextOpt(optCon)) > 0) {
54  if (arg == 'n') {
55  flag = PART_NAME;
56  }
57  }
58 
59  if (arg < -1) {
60  rpmError(RPMERR_BADSPEC, _("line %d: Bad option %s: %s\n"),
61  spec->lineNum,
62  poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
63  spec->line);
64  goto exit;
65  }
66 
67  if (poptPeekArg(optCon)) {
68  if (name == NULL)
69  name = poptGetArg(optCon);
70  if (poptPeekArg(optCon)) {
71  rpmError(RPMERR_BADSPEC, _("line %d: Too many names: %s\n"),
72  spec->lineNum,
73  spec->line);
74  goto exit;
75  }
76  }
77 
78  if (lookupPackage(spec, name, flag, &pkg)) {
79  rpmError(RPMERR_BADSPEC, _("line %d: Package does not exist: %s\n"),
80  spec->lineNum, spec->line);
81  goto exit;
82  }
83 
84 
85  /******************/
86 
87 #if 0
89  rpmError(RPMERR_BADSPEC, _("line %d: Second description\n"),
90  spec->lineNum);
91  goto exit;
92  }
93 #endif
94 
95  t = stashSt(spec, pkg->header, RPMTAG_DESCRIPTION, lang);
96 
97  sb = newStringBuf();
98 
99  if ((rc = readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
100  nextPart = PART_NONE;
101  } else {
102  if (rc) {
103  nextPart = RPMERR_BADSPEC;
104  goto exit;
105  }
106  while (! (nextPart = isPart(spec->line))) {
107  appendLineStringBuf(sb, spec->line);
108  if (t) t->t_nlines++;
109  if ((rc =
111  nextPart = PART_NONE;
112  break;
113  }
114  if (rc) {
115  nextPart = RPMERR_BADSPEC;
116  goto exit;
117  }
118  }
119  }
120 
122  if (!(noLang && strcmp(lang, RPMBUILD_DEFAULT_LANG))) {
124  getStringBuf(sb), lang);
125  }
126 
127  sb = freeStringBuf(sb);
128 
129 exit:
130  argv = _free(argv);
131  optCon = poptFreeContext(optCon);
132  return nextPart;
133 }