Merge "allow rpm to custom systemd installation" into tizen
[platform/upstream/rpm.git] / build / parseDescription.c
1 /** \ingroup rpmbuild
2  * \file build/parseDescription.c
3  *  Parse %description section from spec file.
4  */
5
6 #include "system.h"
7
8 #include <rpm/header.h>
9 #include <rpm/rpmlog.h>
10 #include "build/rpmbuild_internal.h"
11 #include "debug.h"
12
13 int parseDescription(rpmSpec spec)
14 {
15     int nextPart = PART_ERROR;  /* assume error */
16     StringBuf sb = NULL;
17     int flag = PART_SUBNAME;
18     Package pkg;
19     int rc, argc;
20     int arg;
21     const char **argv = NULL;
22     const char *name = NULL;
23     const char *lang = RPMBUILD_DEFAULT_LANG;
24     poptContext optCon = NULL;
25     struct poptOption optionsTable[] = {
26         { NULL, 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL},
27         { NULL, 'l', POPT_ARG_STRING, &lang, 'l', NULL, NULL},
28         { 0, 0, 0, 0, 0, NULL, NULL}
29     };
30
31     if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
32         rpmlog(RPMLOG_ERR, _("line %d: Error parsing %%description: %s\n"),
33                  spec->lineNum, poptStrerror(rc));
34         return PART_ERROR;
35     }
36
37     optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
38     while ((arg = poptGetNextOpt(optCon)) > 0) {
39         if (arg == 'n') {
40             flag = PART_NAME;
41         }
42     }
43
44     if (arg < -1) {
45         rpmlog(RPMLOG_ERR, _("line %d: Bad option %s: %s\n"),
46                  spec->lineNum,
47                  poptBadOption(optCon, POPT_BADOPTION_NOALIAS), 
48                  spec->line);
49         goto exit;
50     }
51
52     if (poptPeekArg(optCon)) {
53         if (name == NULL)
54             name = poptGetArg(optCon);
55         if (poptPeekArg(optCon)) {
56             rpmlog(RPMLOG_ERR, _("line %d: Too many names: %s\n"),
57                      spec->lineNum,
58                      spec->line);
59             goto exit;
60         }
61     }
62
63     if (lookupPackage(spec, name, flag, &pkg)) {
64         rpmlog(RPMLOG_ERR, _("line %d: Package does not exist: %s\n"),
65                  spec->lineNum, spec->line);
66         goto exit;
67     }
68
69
70     /******************/
71
72 #if 0    
73     if (headerIsEntry(pkg->header, RPMTAG_DESCRIPTION)) {
74         rpmlog(RPMLOG_ERR, _("line %d: Second description\n"),
75                 spec->lineNum);
76         goto exit;
77     }
78 #endif
79
80     sb = newStringBuf();
81
82     if ((rc = readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
83         nextPart = PART_NONE;
84     } else if (rc < 0) {
85             nextPart = PART_ERROR;
86             goto exit;
87     } else {
88         while (! (nextPart = isPart(spec->line))) {
89             appendLineStringBuf(sb, spec->line);
90             if ((rc =
91                 readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
92                 nextPart = PART_NONE;
93                 break;
94             } else if (rc < 0) {
95                 nextPart = PART_ERROR;
96                 goto exit;
97             }
98         }
99     }
100     
101     stripTrailingBlanksStringBuf(sb);
102     if (!((spec->flags & RPMSPEC_NOLANG) && !rstreq(lang, RPMBUILD_DEFAULT_LANG))) {
103         (void) headerAddI18NString(pkg->header, RPMTAG_DESCRIPTION,
104                         getStringBuf(sb), lang);
105     }
106     
107      
108 exit:
109     freeStringBuf(sb);
110     free(argv);
111     poptFreeContext(optCon);
112     return nextPart;
113 }