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
*);
17 paragraph
*(*filename
)(char *filename
);
20 {"text", text_backend
, text_config_filename
, 0x0001},
21 {"xhtml", xhtml_backend
, xhtml_config_filename
, 0x0002},
22 {"html", xhtml_backend
, xhtml_config_filename
, 0x0002},
23 {"hlp", whlp_backend
, whlp_config_filename
, 0x0004},
24 {"whlp", whlp_backend
, whlp_config_filename
, 0x0004},
25 {"winhelp", whlp_backend
, whlp_config_filename
, 0x0004},
26 {"man", man_backend
, man_config_filename
, 0x0008},
29 int main(int argc
, char **argv
) {
38 paragraph
*cfg
, *cfg_tail
;
41 * Set up initial (default) parameters.
43 infiles
= mknewa(char *, argc
);
49 cfg
= cfg_tail
= NULL
;
57 * Parse command line arguments.
74 opt
= p
++; /* opt will have _one_ leading - */
75 while (*p
&& *p
!= '=')
76 p
++; /* find end of option */
83 assert(opt
[0] == '-');
84 for (k
= 0; k
< (int)lenof(backends
); k
++)
85 if (!strcmp(opt
+1, backends
[k
].name
)) {
86 backendbits
|= backends
[k
].bitfield
;
88 paragraph
*p
= backends
[k
].filename(val
);
100 if (k
< (int)lenof(backends
)) {
102 } else if (!strcmp(opt
, "-help")) {
105 } else if (!strcmp(opt
, "-version")) {
108 } else if (!strcmp(opt
, "-licence") ||
109 !strcmp(opt
, "-license")) {
112 } else if (!strcmp(opt
, "-precise")) {
115 errs
= TRUE
, error(err_nosuchopt
, opt
);
126 * Option requiring no parameter.
151 * Option requiring parameter.
160 errs
= TRUE
, error(err_optnoarg
, opt
);
163 * Now c is the option and p is the parameter.
168 * -C means we split our argument up into
169 * colon-separated chunks and assemble them
170 * into a config paragraph.
178 keywords
= mknewa(wchar_t, 2+strlen(p
));
187 if (*q
== '\\' && q
[1])
189 /* FIXME: lacks charset flexibility */
196 para
= mknew(paragraph
);
197 memset(para
, 0, sizeof(*para
));
198 para
->type
= para_Config
;
199 para
->keyword
= keywords
;
201 para
->fpos
.filename
= "<command line>";
202 para
->fpos
.line
= para
->fpos
.col
= -1;
205 cfg_tail
->next
= para
;
212 p
= NULL
; /* prevent continued processing */
216 * Unrecognised option.
222 errs
= TRUE
, error(err_nosuchopt
, opt
);
228 * A non-option argument.
230 infiles
[nfiles
++] = p
;
250 paragraph
*sourceform
, *p
;
252 keywordlist
*keywords
;
254 in
.filenames
= infiles
;
258 in
.npushback
= in
.pushbacksize
= 0;
260 in
.reportcols
= reportcols
;
265 sourceform
= read_input(&in
, idx
);
270 * Append the config directives acquired from the command
277 while (end
&& end
->next
)
286 mark_attr_ends(sourceform
);
290 keywords
= get_keywords(sourceform
);
293 gen_citations(sourceform
, keywords
);
294 subst_keywords(sourceform
, keywords
);
296 for (p
= sourceform
; p
; p
= p
->next
)
297 if (p
->type
== para_IM
)
298 index_merge(idx
, TRUE
, p
->keyword
, p
->words
);
304 dbg_prtkws(keywords
);
305 dbg_prtsource(sourceform
);
309 * Run the selected set of backends.
311 for (k
= b
= 0; k
< (int)lenof(backends
); k
++)
312 if (b
!= backends
[k
].bitfield
) {
313 b
= backends
[k
].bitfield
;
314 if (backendbits
== 0 || (backendbits
& b
))
315 backends
[k
].func(sourceform
, keywords
, idx
);
318 free_para_list(sourceform
);
319 free_keywords(keywords
);
326 static void dbg_prtsource(paragraph
*sourceform
) {
328 * Output source form in debugging format.
332 for (p
= sourceform
; p
; p
= p
->next
) {
334 printf("para %d ", p
->type
);
346 printf("(no keyword)");
348 dbg_prtwordlist(1, p
->words
);
353 static void dbg_prtkws(keywordlist
*kws
) {
355 * Output keywords in debugging format.
361 for (i
= 0; (kw
= index234(kws
->keys
, i
)) != NULL
; i
++) {
374 dbg_prtwordlist(1, kw
->text
);
379 static void dbg_prtwordlist(int level
, word
*w
) {
380 for (; w
; w
= w
->next
) {
382 printf("%*sword %d ", level
*4, "", w
->type
);
385 for (wp
= w
->text
; *wp
; wp
++)
391 printf(" alt = {\n");
392 dbg_prtwordlist(level
+1, w
->alt
);
393 printf("%*s}", level
*4, "");