2 * main.c: command line parsing and top level
10 static void dbg_prtsource(paragraph
*sourceform
);
11 static void dbg_prtwordlist(int level
, word
*w
);
12 static void dbg_prtkws(keywordlist
*kws
);
14 static const struct backend
{
16 void (*func
)(paragraph
*, keywordlist
*, indexdata
*);
19 {"text", text_backend
, 0x0001},
20 {"xhtml", xhtml_backend
, 0x0002},
21 {"html", xhtml_backend
, 0x0002},
22 {"hlp", whlp_backend
, 0x0004},
23 {"whlp", whlp_backend
, 0x0004},
24 {"winhelp", whlp_backend
, 0x0004},
25 {"man", man_backend
, 0x0008},
28 int main(int argc
, char **argv
) {
39 * Set up initial (default) parameters.
41 infiles
= mknewa(char *, argc
);
54 * Parse command line arguments.
71 opt
= p
++; /* opt will have _one_ leading - */
72 while (*p
&& *p
!= '=')
73 p
++; /* find end of option */
80 assert(opt
[0] == '-');
81 for (k
= 0; k
< (int)lenof(backends
); k
++)
82 if (!strcmp(opt
+1, backends
[k
].name
)) {
83 backendbits
|= backends
[k
].bitfield
;
86 if (k
< (int)lenof(backends
)) {
88 } else if (!strcmp(opt
, "-help")) {
91 } else if (!strcmp(opt
, "-version")) {
94 } else if (!strcmp(opt
, "-licence") ||
95 !strcmp(opt
, "-license")) {
98 } else if (!strcmp(opt
, "-precise")) {
101 errs
= TRUE
, error(err_nosuchopt
, opt
);
112 * Option requiring no parameter.
138 * Option requiring parameter.
147 errs
= TRUE
, error(err_optnoarg
, opt
);
150 * Now c is the option and p is the parameter.
157 p
= NULL
; /* prevent continued processing */
162 * Unrecognised option.
168 errs
= TRUE
, error(err_nosuchopt
, opt
);
174 * A non-option argument.
176 infiles
[nfiles
++] = p
;
196 paragraph
*sourceform
, *p
;
198 keywordlist
*keywords
;
200 in
.filenames
= infiles
;
204 in
.npushback
= in
.pushbacksize
= 0;
206 in
.reportcols
= reportcols
;
211 sourceform
= read_input(&in
, idx
);
217 mark_attr_ends(sourceform
);
221 keywords
= get_keywords(sourceform
);
224 gen_citations(sourceform
, keywords
);
225 subst_keywords(sourceform
, keywords
);
227 for (p
= sourceform
; p
; p
= p
->next
)
228 if (p
->type
== para_IM
)
229 index_merge(idx
, TRUE
, p
->keyword
, p
->words
);
235 dbg_prtkws(keywords
);
236 dbg_prtsource(sourceform
);
240 * Run the selected set of backends.
242 for (k
= b
= 0; k
< (int)lenof(backends
); k
++)
243 if (b
!= backends
[k
].bitfield
) {
244 b
= backends
[k
].bitfield
;
245 if (backendbits
== 0 || (backendbits
& b
))
246 backends
[k
].func(sourceform
, keywords
, idx
);
249 free_para_list(sourceform
);
250 free_keywords(keywords
);
257 static void dbg_prtsource(paragraph
*sourceform
) {
259 * Output source form in debugging format.
263 for (p
= sourceform
; p
; p
= p
->next
) {
265 printf("para %d ", p
->type
);
277 printf("(no keyword)");
279 dbg_prtwordlist(1, p
->words
);
284 static void dbg_prtkws(keywordlist
*kws
) {
286 * Output keywords in debugging format.
292 for (i
= 0; (kw
= index234(kws
->keys
, i
)) != NULL
; i
++) {
305 dbg_prtwordlist(1, kw
->text
);
310 static void dbg_prtwordlist(int level
, word
*w
) {
311 for (; w
; w
= w
->next
) {
313 printf("%*sword %d ", level
*4, "", w
->type
);
316 for (wp
= w
->text
; *wp
; wp
++)
322 printf(" alt = {\n");
323 dbg_prtwordlist(level
+1, w
->alt
);
324 printf("%*s}", level
*4, "");