2 * main.c: command line parsing and top level
9 static void dbg_prtsource(paragraph
*sourceform
);
10 static void dbg_prtwordlist(int level
, word
*w
);
11 static void dbg_prtkws(keywordlist
*kws
);
13 int main(int argc
, char **argv
) {
23 * Set up initial (default) parameters.
25 infiles
= mknewa(char *, argc
);
38 * Parse command line arguments.
55 opt
= p
++; /* opt will have _one_ leading - */
56 while (*p
&& *p
!= '=')
57 p
++; /* find end of option */
63 if (!strcmp(opt
, "-help")) {
66 } else if (!strcmp(opt
, "-version")) {
69 } else if (!strcmp(opt
, "-licence") ||
70 !strcmp(opt
, "-license")) {
73 } else if (!strcmp(opt
, "-output")) {
75 errs
= TRUE
, error(err_optnoarg
, opt
);
78 } else if (!strcmp(opt
, "-precise")) {
81 errs
= TRUE
, error(err_nosuchopt
, opt
);
92 * Option requiring no parameter.
117 * Option requiring parameter.
126 errs
= TRUE
, error(err_optnoarg
, opt
);
129 * Now c is the option and p is the parameter.
136 p
= NULL
; /* prevent continued processing */
140 * Unrecognised option.
146 errs
= TRUE
, error(err_nosuchopt
, opt
);
152 * A non-option argument.
154 infiles
[nfiles
++] = p
;
174 paragraph
*sourceform
, *p
;
176 keywordlist
*keywords
;
178 in
.filenames
= infiles
;
182 in
.npushback
= in
.pushbacksize
= 0;
184 in
.reportcols
= reportcols
;
189 sourceform
= read_input(&in
, idx
);
195 mark_attr_ends(sourceform
);
199 keywords
= get_keywords(sourceform
);
202 gen_citations(sourceform
, keywords
);
203 subst_keywords(sourceform
, keywords
);
205 for (p
= sourceform
; p
; p
= p
->next
)
206 if (p
->type
== para_IM
)
207 index_merge(idx
, TRUE
, p
->keyword
, p
->words
);
213 dbg_prtkws(keywords
);
214 dbg_prtsource(sourceform
);
217 text_backend(sourceform
, keywords
, idx
);
218 xhtml_backend(sourceform
, keywords
, idx
);
219 whlp_backend(sourceform
, keywords
, idx
);
220 man_backend(sourceform
, keywords
, idx
);
222 free_para_list(sourceform
);
223 free_keywords(keywords
);
230 static void dbg_prtsource(paragraph
*sourceform
) {
232 * Output source form in debugging format.
236 for (p
= sourceform
; p
; p
= p
->next
) {
238 printf("para %d ", p
->type
);
250 printf("(no keyword)");
252 dbg_prtwordlist(1, p
->words
);
257 static void dbg_prtkws(keywordlist
*kws
) {
259 * Output keywords in debugging format.
265 for (i
= 0; (kw
= index234(kws
->keys
, i
)) != NULL
; i
++) {
278 dbg_prtwordlist(1, kw
->text
);
283 static void dbg_prtwordlist(int level
, word
*w
) {
284 for (; w
; w
= w
->next
) {
286 printf("%*sword %d ", level
*4, "", w
->type
);
289 for (wp
= w
->text
; *wp
; wp
++)
295 printf(" alt = {\n");
296 dbg_prtwordlist(level
+1, w
->alt
);
297 printf("%*s}", level
*4, "");