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
) {
37 paragraph
*cfg
, *cfg_tail
;
40 * Set up initial (default) parameters.
42 infiles
= mknewa(char *, argc
);
48 cfg
= cfg_tail
= NULL
;
56 * Parse command line arguments.
73 opt
= p
++; /* opt will have _one_ leading - */
74 while (*p
&& *p
!= '=')
75 p
++; /* find end of option */
82 assert(opt
[0] == '-');
83 for (k
= 0; k
< (int)lenof(backends
); k
++)
84 if (!strcmp(opt
+1, backends
[k
].name
)) {
85 backendbits
|= backends
[k
].bitfield
;
88 if (k
< (int)lenof(backends
)) {
90 } else if (!strcmp(opt
, "-help")) {
93 } else if (!strcmp(opt
, "-version")) {
96 } else if (!strcmp(opt
, "-licence") ||
97 !strcmp(opt
, "-license")) {
100 } else if (!strcmp(opt
, "-precise")) {
103 errs
= TRUE
, error(err_nosuchopt
, opt
);
114 * Option requiring no parameter.
139 * Option requiring parameter.
148 errs
= TRUE
, error(err_optnoarg
, opt
);
151 * Now c is the option and p is the parameter.
156 * -C means we split our argument up into
157 * colon-separated chunks and assemble them
158 * into a config paragraph.
166 keywords
= mknewa(wchar_t, 2+strlen(p
));
175 if (*q
== '\\' && q
[1])
177 /* FIXME: lacks charset flexibility */
184 para
= mknew(paragraph
);
185 memset(para
, 0, sizeof(*para
));
186 para
->type
= para_Config
;
187 para
->keyword
= keywords
;
189 para
->fpos
.filename
= "<command line>";
190 para
->fpos
.line
= para
->fpos
.col
= -1;
193 cfg_tail
->next
= para
;
200 p
= NULL
; /* prevent continued processing */
204 * Unrecognised option.
210 errs
= TRUE
, error(err_nosuchopt
, opt
);
216 * A non-option argument.
218 infiles
[nfiles
++] = p
;
238 paragraph
*sourceform
, *p
;
240 keywordlist
*keywords
;
242 in
.filenames
= infiles
;
246 in
.npushback
= in
.pushbacksize
= 0;
248 in
.reportcols
= reportcols
;
253 sourceform
= read_input(&in
, idx
);
258 * Append the config directives acquired from the command
265 while (end
&& end
->next
)
274 mark_attr_ends(sourceform
);
278 keywords
= get_keywords(sourceform
);
281 gen_citations(sourceform
, keywords
);
282 subst_keywords(sourceform
, keywords
);
284 for (p
= sourceform
; p
; p
= p
->next
)
285 if (p
->type
== para_IM
)
286 index_merge(idx
, TRUE
, p
->keyword
, p
->words
);
292 dbg_prtkws(keywords
);
293 dbg_prtsource(sourceform
);
297 * Run the selected set of backends.
299 for (k
= b
= 0; k
< (int)lenof(backends
); k
++)
300 if (b
!= backends
[k
].bitfield
) {
301 b
= backends
[k
].bitfield
;
302 if (backendbits
== 0 || (backendbits
& b
))
303 backends
[k
].func(sourceform
, keywords
, idx
);
306 free_para_list(sourceform
);
307 free_keywords(keywords
);
314 static void dbg_prtsource(paragraph
*sourceform
) {
316 * Output source form in debugging format.
320 for (p
= sourceform
; p
; p
= p
->next
) {
322 printf("para %d ", p
->type
);
334 printf("(no keyword)");
336 dbg_prtwordlist(1, p
->words
);
341 static void dbg_prtkws(keywordlist
*kws
) {
343 * Output keywords in debugging format.
349 for (i
= 0; (kw
= index234(kws
->keys
, i
)) != NULL
; i
++) {
362 dbg_prtwordlist(1, kw
->text
);
367 static void dbg_prtwordlist(int level
, word
*w
) {
368 for (; w
; w
= w
->next
) {
370 printf("%*sword %d ", level
*4, "", w
->type
);
373 for (wp
= w
->text
; *wp
; wp
++)
379 printf(" alt = {\n");
380 dbg_prtwordlist(level
+1, w
->alt
);
381 printf("%*s}", level
*4, "");