1 #ifndef HALIBUT_HALIBUT_H
2 #define HALIBUT_HALIBUT_H
12 #define NORETURN __attribute__((__noreturn__))
14 #define NORETURN /* nothing */
24 /* For suppressing unused-parameter warnings */
25 #define IGNORE(x) ( (x) = (x) )
30 * FIXME: Charset temporary workarounds
32 #define CS_FIXME CS_ISO8859_1
33 #define CS_LOCAL CS_ISO8859_1
38 typedef struct input_Tag input
;
39 typedef struct filepos_Tag filepos
;
40 typedef struct paragraph_Tag paragraph
;
41 typedef struct word_Tag word
;
42 typedef struct keywordlist_Tag keywordlist
;
43 typedef struct keyword_Tag keyword
;
44 typedef struct userstyle_Tag userstyle
;
45 typedef struct numberstate_Tag numberstate
;
46 typedef struct indexdata_Tag indexdata
;
47 typedef struct indextag_Tag indextag
;
48 typedef struct indexentry_Tag indexentry
;
49 typedef struct macrostack_Tag macrostack
;
52 * Data structure to hold a file name and index, a line and a
53 * column number, for reporting errors
61 * Data structure to hold all the file names etc for input
63 typedef struct pushback_Tag
{
68 char **filenames
; /* complete list of input files */
69 int nfiles
; /* how many in the list */
70 FILE *currfp
; /* the currently open one */
71 int currindex
; /* which one is that in the list */
72 pushback
*pushback
; /* pushed-back input characters */
73 int npushback
, pushbacksize
;
75 int reportcols
; /* report column numbers in errors */
76 macrostack
*stack
; /* macro expansions in force */
77 int defcharset
, charset
; /* character sets for input files */
78 charset_state csstate
;
79 wchar_t wc
[16]; /* wide chars from input conversion */
80 int nwc
, wcpos
; /* size of, and position in, wc[] */
81 char *pushback_chars
; /* used to save input-encoding data */
85 * Data structure to hold the input form of the source, ie a linked
88 struct paragraph_Tag
{
91 wchar_t *keyword
; /* for most special paragraphs */
92 char *origkeyword
; /* same again in original charset */
93 word
*words
; /* list of words in paragraph */
94 int aux
; /* number, in a numbered paragraph
97 word
*kwtext
; /* chapter/section indication */
98 word
*kwtext2
; /* numeric-only form of kwtext */
101 paragraph
*parent
, *child
, *sibling
; /* for hierarchy navigation */
103 void *private_data
; /* for temp use in backends */
106 para_IM
, /* index merge */
107 para_BR
, /* bibliography rewrite */
108 para_Rule
, /* random horizontal rule */
111 para_UnnumberedChapter
,
115 para_Biblio
, /* causes no output unless turned ... */
116 para_BiblioCited
, /* ... into this paragraph type */
126 para_Config
, /* configuration directive */
127 para_LcontPush
, /* begin continuation of list item */
128 para_LcontPop
, /* end continuation of list item */
129 para_QuotePush
, /* begin block quote */
130 para_QuotePop
, /* end block quote */
132 * Back ends may define their own paragraph types beyond here,
133 * in case they need to use them internally.
135 para_NotParaType
/* placeholder value */
139 * Data structure to hold an individual word
145 int breaks
; /* can a line break after it? */
149 void *private_data
; /* for temp use in backends */
152 /* ORDERING CONSTRAINT: these normal-word types ... */
155 word_Code
, /* monospaced; `quoted' in text */
156 word_WeakCode
, /* monospaced, normal in text */
157 /* ... must be in the same order as these space types ... */
158 word_WhiteSpace
, /* text is NULL or ignorable */
159 word_EmphSpace
, /* WhiteSpace when emphasised */
160 word_CodeSpace
, /* WhiteSpace when code */
161 word_WkCodeSpace
, /* WhiteSpace when weak code */
162 /* ... and must be in the same order as these quote types ... */
163 word_Quote
, /* text is NULL or ignorable */
164 word_EmphQuote
, /* Quote when emphasised */
165 word_CodeQuote
, /* (can't happen) */
166 word_WkCodeQuote
, /* (can't happen) */
167 /* END ORDERING CONSTRAINT */
168 word_internal_endattrs
,
169 word_UpperXref
, /* \K */
170 word_LowerXref
, /* \k */
171 word_XrefEnd
, /* (invisible; no text) */
172 word_IndexRef
, /* (always an invisible one) */
173 word_HyperLink
, /* (invisible) */
174 word_HyperEnd
, /* (also invisible; no text) */
176 * Back ends may define their own word types beyond here, in
177 * case they need to use them internally.
179 word_NotWordType
/* placeholder value */
181 /* aux values for attributed words */
183 attr_Only
= 0x0000, /* a lone word with the attribute */
184 attr_First
= 0x0001, /* the first of a series */
185 attr_Last
= 0x0002, /* the last of a series */
186 attr_Always
= 0x0003, /* any other part of a series */
189 /* aux values for quote-type words */
192 quote_Close
= 0x0020,
195 #define isattr(x) ( ( (x) > word_Normal && (x) < word_WhiteSpace ) || \
196 ( (x) > word_WhiteSpace && (x) < word_internal_endattrs ) )
197 #define sameattr(x,y) ( (((x)-(y)) & 3) == 0 )
198 #define towordstyle(x) ( word_Normal + ((x) & 3) )
199 #define tospacestyle(x) ( word_WhiteSpace + ((x) & 3) )
200 #define toquotestyle(x) ( word_Quote + ((x) & 3) )
201 #define removeattr(x) ( word_Normal + ((x) &~ 3) )
203 #define attraux(x) ( (x) & attr_mask )
204 #define quoteaux(x) ( (x) & quote_mask )
209 void fatal(int code
, ...) NORETURN
;
210 void error(int code
, ...);
212 err_nomemory
, /* out of memory */
213 err_optnoarg
, /* option `-%s' requires an argument */
214 err_nosuchopt
, /* unrecognised option `-%s' */
215 err_noinput
, /* no input files */
216 err_cantopen
, /* unable to open input file `%s' */
217 err_nodata
, /* no data in input files */
218 err_brokencodepara
, /* line in codepara didn't begin `\c' */
219 err_kwunclosed
, /* expected `}' after keyword */
220 err_kwillegal
, /* paragraph type expects no keyword */
221 err_kwexpected
, /* paragraph type expects a keyword */
222 err_kwtoomany
, /* paragraph type expects only 1 */
223 err_bodyillegal
, /* paragraph type expects only kws! */
224 err_badparatype
, /* invalid command at start of para */
225 err_badmidcmd
, /* invalid command in mid-para */
226 err_unexbrace
, /* unexpected brace */
227 err_explbr
, /* expected `{' after command */
228 err_commenteof
, /* EOF inside braced comment */
229 err_kwexprbr
, /* expected `}' after cross-ref */
230 err_missingrbrace
, /* unclosed braces at end of para */
231 err_missingrbrace2
, /* unclosed braces at end of file */
232 err_nestedstyles
, /* unable to nest text styles */
233 err_nestedindex
, /* unable to nest `\i' thingys */
234 err_nosuchkw
, /* unresolved cross-reference */
235 err_multiBR
, /* multiple \BRs on same keyword */
236 err_nosuchidxtag
, /* \IM on unknown index tag (warning) */
237 err_cantopenw
, /* can't open output file for write */
238 err_macroexists
, /* this macro already exists */
239 err_sectjump
, /* jump a heading level, eg \C -> \S */
240 err_winhelp_ctxclash
, /* WinHelp context ID hash clash */
241 err_multikw
, /* keyword clash in sections */
242 err_misplacedlcont
, /* \lcont not after a list item */
243 err_sectmarkerinblock
, /* section marker appeared in block */
244 err_infodirentry
, /* \cfg{info-dir-entry} missing param */
245 err_infonodechar
, /* colon/comma in node name in info */
246 err_whatever
/* random error of another type */
253 void *smalloc(char *file
, int line
, int size
);
254 void *srealloc(char *file
, int line
, void *p
, int size
);
255 void sfree(char *file
, int line
, void *p
);
256 #define smalloc(x) smalloc(__FILE__, __LINE__, x)
257 #define srealloc(x, y) srealloc(__FILE__, __LINE__, x, y)
258 #define sfree(x) sfree(__FILE__, __LINE__, x)
260 void *smalloc(int size
);
261 void *srealloc(void *p
, int size
);
264 void free_word_list(word
*w
);
265 void free_para_list(paragraph
*p
);
266 word
*dup_word_list(word
*w
);
267 char *dupstr(char *s
);
269 #define mknew(type) ( (type *) smalloc (sizeof (type)) )
270 #define mknewa(type, number) ( (type *) smalloc ((number) * sizeof (type)) )
271 #define resize(array, len) ( srealloc ((array), (len) * sizeof (*(array))) )
272 #define lenof(array) ( sizeof(array) / sizeof(*(array)) )
277 wchar_t *ustrdup(wchar_t const *s
);
278 char *ustrtoa(wchar_t const *s
, char *outbuf
, int size
, int charset
);
279 char *ustrtoa_careful(wchar_t const *s
, char *outbuf
, int size
, int charset
);
280 wchar_t *ustrfroma(char const *s
, wchar_t *outbuf
, int size
, int charset
);
281 char *utoa_dup(wchar_t const *s
, int charset
);
282 char *utoa_dup_len(wchar_t const *s
, int charset
, int *len
);
283 char *utoa_careful_dup(wchar_t const *s
, int charset
);
284 wchar_t *ufroma_dup(char const *s
, int charset
);
285 int ustrlen(wchar_t const *s
);
286 wchar_t *uadv(wchar_t *s
);
287 wchar_t *ustrcpy(wchar_t *dest
, wchar_t const *source
);
288 wchar_t utolower(wchar_t);
289 int uisalpha(wchar_t);
290 int ustrcmp(wchar_t *lhs
, wchar_t *rhs
);
291 int ustricmp(wchar_t *lhs
, wchar_t *rhs
);
294 int uisdigit(wchar_t);
295 wchar_t *ustrlow(wchar_t *s
);
296 wchar_t *ustrftime(wchar_t *fmt
, struct tm
*timespec
);
303 void showversion(void);
313 const char *const version
;
320 typedef struct stackTag
*stack
;
322 void stk_free(stack
);
323 void stk_push(stack
, void *);
324 void *stk_pop(stack
);
325 void *stk_top(stack
);
327 typedef struct tagRdstring rdstring
;
332 typedef struct tagRdstringc rdstringc
;
333 struct tagRdstringc
{
337 extern const rdstring empty_rdstring
;
338 extern const rdstringc empty_rdstringc
;
339 void rdadd(rdstring
*rs
, wchar_t c
);
340 void rdadds(rdstring
*rs
, wchar_t const *p
);
341 wchar_t *rdtrim(rdstring
*rs
);
342 void rdaddc(rdstringc
*rs
, char c
);
343 void rdaddsc(rdstringc
*rs
, char const *p
);
344 char *rdtrimc(rdstringc
*rs
);
346 int compare_wordlists(word
*a
, word
*b
);
348 void mark_attr_ends(paragraph
*sourceform
);
350 typedef struct tagWrappedLine wrappedline
;
351 struct tagWrappedLine
{
353 word
*begin
, *end
; /* first & last words of line */
354 int nspaces
; /* number of whitespaces in line */
355 int shortfall
; /* how much shorter than max width */
357 wrappedline
*wrap_para(word
*, int, int, int (*)(void *, word
*), void *, int);
358 void wrap_free(wrappedline
*);
359 void cmdline_cfg_add(paragraph
*cfg
, char *string
);
360 paragraph
*cmdline_cfg_new(void);
361 paragraph
*cmdline_cfg_simple(char *string
, ...);
366 paragraph
*read_input(input
*in
, indexdata
*idx
);
371 struct keywordlist_Tag
{
374 tree234
*keys
; /* sorted by `key' field */
375 word
**looseends
; /* non-keyword list element numbers */
380 wchar_t *key
; /* the keyword itself */
381 word
*text
; /* "Chapter 2", "Appendix Q"... */
382 /* (NB: filepos are not set) */
383 paragraph
*para
; /* the paragraph referenced */
385 keyword
*kw_lookup(keywordlist
*, wchar_t *);
386 keywordlist
*get_keywords(paragraph
*);
387 void free_keywords(keywordlist
*);
388 void subst_keywords(paragraph
*, keywordlist
*);
395 * Data structure to hold both sides of the index.
397 struct indexdata_Tag
{
398 tree234
*tags
; /* holds type `indextag' */
399 tree234
*entries
; /* holds type `indexentry' */
403 * Data structure to hold an index tag (LHS of index).
405 struct indextag_Tag
{
408 filepos implicit_fpos
;
409 word
**explicit_texts
;
410 filepos
*explicit_fpos
;
411 int nexplicit
, explicit_size
;
413 indexentry
**refs
; /* array of entries referenced by tag */
417 * Data structure to hold an index entry (RHS of index).
419 struct indexentry_Tag
{
421 void *backend_data
; /* private to back end */
425 indexdata
*make_index(void);
426 void cleanup_index(indexdata
*);
427 /* index_merge takes responsibility for freeing arg 3 iff implicit; never
428 * takes responsibility for arg 2 */
429 void index_merge(indexdata
*, int is_explicit
, wchar_t *, word
*, filepos
*);
430 void build_index(indexdata
*);
431 void index_debug(indexdata
*);
432 indextag
*index_findtag(indexdata
*idx
, wchar_t *name
);
437 numberstate
*number_init(void);
438 void number_cfg(numberstate
*, paragraph
*);
439 word
*number_mktext(numberstate
*, paragraph
*, wchar_t *, int *, int *);
440 void number_free(numberstate
*);
445 void gen_citations(paragraph
*, keywordlist
*);
450 struct userstyle_Tag
{
456 void text_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
457 paragraph
*text_config_filename(char *filename
);
462 void xhtml_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
463 paragraph
*xhtml_config_filename(char *filename
);
468 void whlp_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
469 paragraph
*whlp_config_filename(char *filename
);
474 void man_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
475 paragraph
*man_config_filename(char *filename
);
480 void info_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
481 paragraph
*info_config_filename(char *filename
);
486 void *paper_pre_backend(paragraph
*, keywordlist
*, indexdata
*);
491 void ps_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
492 paragraph
*ps_config_filename(char *filename
);
497 void pdf_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
498 paragraph
*pdf_config_filename(char *filename
);