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) )
32 typedef struct input_Tag input
;
33 typedef struct filepos_Tag filepos
;
34 typedef struct paragraph_Tag paragraph
;
35 typedef struct word_Tag word
;
36 typedef struct keywordlist_Tag keywordlist
;
37 typedef struct keyword_Tag keyword
;
38 typedef struct userstyle_Tag userstyle
;
39 typedef struct numberstate_Tag numberstate
;
40 typedef struct indexdata_Tag indexdata
;
41 typedef struct indextag_Tag indextag
;
42 typedef struct indexentry_Tag indexentry
;
43 typedef struct macrostack_Tag macrostack
;
46 * Data structure to hold a file name and index, a line and a
47 * column number, for reporting errors
55 * Data structure to hold all the file names etc for input
57 typedef struct pushback_Tag
{
62 char **filenames
; /* complete list of input files */
63 int nfiles
; /* how many in the list */
64 FILE *currfp
; /* the currently open one */
65 int currindex
; /* which one is that in the list */
66 pushback
*pushback
; /* pushed-back input characters */
67 int npushback
, pushbacksize
;
69 int reportcols
; /* report column numbers in errors */
70 macrostack
*stack
; /* macro expansions in force */
71 int defcharset
, charset
; /* character sets for input files */
72 charset_state csstate
;
73 wchar_t wc
[16]; /* wide chars from input conversion */
74 int nwc
, wcpos
; /* size of, and position in, wc[] */
78 * Data structure to hold the input form of the source, ie a linked
81 struct paragraph_Tag
{
84 wchar_t *keyword
; /* for most special paragraphs */
85 word
*words
; /* list of words in paragraph */
86 int aux
; /* number, in a numbered paragraph
89 word
*kwtext
; /* chapter/section indication */
90 word
*kwtext2
; /* numeric-only form of kwtext */
93 paragraph
*parent
, *child
, *sibling
; /* for hierarchy navigation */
95 void *private_data
; /* for temp use in backends */
98 para_IM
, /* index merge */
99 para_BR
, /* bibliography rewrite */
100 para_Rule
, /* random horizontal rule */
103 para_UnnumberedChapter
,
107 para_Biblio
, /* causes no output unless turned ... */
108 para_BiblioCited
, /* ... into this paragraph type */
118 para_Config
, /* configuration directive */
119 para_LcontPush
, /* begin continuation of list item */
120 para_LcontPop
, /* end continuation of list item */
121 para_QuotePush
, /* begin block quote */
122 para_QuotePop
, /* end block quote */
124 * Back ends may define their own paragraph types beyond here,
125 * in case they need to use them internally.
127 para_NotParaType
/* placeholder value */
131 * Data structure to hold an individual word
137 int breaks
; /* can a line break after it? */
141 void *private_data
; /* for temp use in backends */
144 /* ORDERING CONSTRAINT: these normal-word types ... */
147 word_Code
, /* monospaced; `quoted' in text */
148 word_WeakCode
, /* monospaced, normal in text */
149 /* ... must be in the same order as these space types ... */
150 word_WhiteSpace
, /* text is NULL or ignorable */
151 word_EmphSpace
, /* WhiteSpace when emphasised */
152 word_CodeSpace
, /* WhiteSpace when code */
153 word_WkCodeSpace
, /* WhiteSpace when weak code */
154 /* ... and must be in the same order as these quote types ... */
155 word_Quote
, /* text is NULL or ignorable */
156 word_EmphQuote
, /* Quote when emphasised */
157 word_CodeQuote
, /* (can't happen) */
158 word_WkCodeQuote
, /* (can't happen) */
159 /* END ORDERING CONSTRAINT */
160 word_internal_endattrs
,
161 word_UpperXref
, /* \K */
162 word_LowerXref
, /* \k */
163 word_XrefEnd
, /* (invisible; no text) */
164 word_IndexRef
, /* (always an invisible one) */
165 word_HyperLink
, /* (invisible) */
166 word_HyperEnd
, /* (also invisible; no text) */
168 * Back ends may define their own word types beyond here, in
169 * case they need to use them internally.
171 word_NotWordType
/* placeholder value */
173 /* aux values for attributed words */
175 attr_Only
= 0x0000, /* a lone word with the attribute */
176 attr_First
= 0x0001, /* the first of a series */
177 attr_Last
= 0x0002, /* the last of a series */
178 attr_Always
= 0x0003, /* any other part of a series */
181 /* aux values for quote-type words */
184 quote_Close
= 0x0020,
187 #define isattr(x) ( ( (x) > word_Normal && (x) < word_WhiteSpace ) || \
188 ( (x) > word_WhiteSpace && (x) < word_internal_endattrs ) )
189 #define sameattr(x,y) ( (((x)-(y)) & 3) == 0 )
190 #define towordstyle(x) ( word_Normal + ((x) & 3) )
191 #define tospacestyle(x) ( word_WhiteSpace + ((x) & 3) )
192 #define toquotestyle(x) ( word_Quote + ((x) & 3) )
193 #define removeattr(x) ( word_Normal + ((x) &~ 3) )
195 #define attraux(x) ( (x) & attr_mask )
196 #define quoteaux(x) ( (x) & quote_mask )
201 void fatal(int code
, ...) NORETURN
;
202 void error(int code
, ...);
204 err_nomemory
, /* out of memory */
205 err_optnoarg
, /* option `-%s' requires an argument */
206 err_nosuchopt
, /* unrecognised option `-%s' */
207 err_noinput
, /* no input files */
208 err_cantopen
, /* unable to open input file `%s' */
209 err_nodata
, /* no data in input files */
210 err_brokencodepara
, /* line in codepara didn't begin `\c' */
211 err_kwunclosed
, /* expected `}' after keyword */
212 err_kwillegal
, /* paragraph type expects no keyword */
213 err_kwexpected
, /* paragraph type expects a keyword */
214 err_kwtoomany
, /* paragraph type expects only 1 */
215 err_bodyillegal
, /* paragraph type expects only kws! */
216 err_badparatype
, /* invalid command at start of para */
217 err_badmidcmd
, /* invalid command in mid-para */
218 err_unexbrace
, /* unexpected brace */
219 err_explbr
, /* expected `{' after command */
220 err_commenteof
, /* EOF inside braced comment */
221 err_kwexprbr
, /* expected `}' after cross-ref */
222 err_missingrbrace
, /* unclosed braces at end of para */
223 err_missingrbrace2
, /* unclosed braces at end of file */
224 err_nestedstyles
, /* unable to nest text styles */
225 err_nestedindex
, /* unable to nest `\i' thingys */
226 err_nosuchkw
, /* unresolved cross-reference */
227 err_multiBR
, /* multiple \BRs on same keyword */
228 err_nosuchidxtag
, /* \IM on unknown index tag (warning) */
229 err_cantopenw
, /* can't open output file for write */
230 err_macroexists
, /* this macro already exists */
231 err_sectjump
, /* jump a heading level, eg \C -> \S */
232 err_winhelp_ctxclash
, /* WinHelp context ID hash clash */
233 err_multikw
, /* keyword clash in sections */
234 err_misplacedlcont
, /* \lcont not after a list item */
235 err_sectmarkerinblock
, /* section marker appeared in block */
236 err_infodirentry
, /* \cfg{info-dir-entry} missing param */
237 err_infonodechar
, /* colon/comma in node name in info */
238 err_whatever
/* random error of another type */
245 void *smalloc(char *file
, int line
, int size
);
246 void *srealloc(char *file
, int line
, void *p
, int size
);
247 void sfree(char *file
, int line
, void *p
);
248 #define smalloc(x) smalloc(__FILE__, __LINE__, x)
249 #define srealloc(x, y) srealloc(__FILE__, __LINE__, x, y)
250 #define sfree(x) sfree(__FILE__, __LINE__, x)
252 void *smalloc(int size
);
253 void *srealloc(void *p
, int size
);
256 void free_word_list(word
*w
);
257 void free_para_list(paragraph
*p
);
258 word
*dup_word_list(word
*w
);
259 char *dupstr(char *s
);
261 #define mknew(type) ( (type *) smalloc (sizeof (type)) )
262 #define mknewa(type, number) ( (type *) smalloc ((number) * sizeof (type)) )
263 #define resize(array, len) ( srealloc ((array), (len) * sizeof (*(array))) )
264 #define lenof(array) ( sizeof(array) / sizeof(*(array)) )
269 wchar_t *ustrdup(wchar_t *s
);
270 char *ustrtoa(wchar_t *s
, char *outbuf
, int size
);
271 wchar_t *ustrfroma(char *s
, wchar_t *outbuf
, int size
);
272 char *utoa_dup(wchar_t *s
);
273 wchar_t *ufroma_dup(char *s
);
274 int ustrlen(wchar_t const *s
);
275 wchar_t *uadv(wchar_t *s
);
276 wchar_t *ustrcpy(wchar_t *dest
, wchar_t const *source
);
277 wchar_t utolower(wchar_t);
278 int uisalpha(wchar_t);
279 int ustrcmp(wchar_t *lhs
, wchar_t *rhs
);
280 int ustricmp(wchar_t *lhs
, wchar_t *rhs
);
283 int uisdigit(wchar_t);
284 wchar_t *ustrlow(wchar_t *s
);
285 wchar_t *ustrftime(wchar_t *fmt
, struct tm
*timespec
);
292 void showversion(void);
302 const char *const version
;
307 typedef struct stackTag
*stack
;
309 void stk_free(stack
);
310 void stk_push(stack
, void *);
311 void *stk_pop(stack
);
312 void *stk_top(stack
);
314 typedef struct tagRdstring rdstring
;
319 typedef struct tagRdstringc rdstringc
;
320 struct tagRdstringc
{
324 extern const rdstring empty_rdstring
;
325 extern const rdstringc empty_rdstringc
;
326 void rdadd(rdstring
*rs
, wchar_t c
);
327 void rdadds(rdstring
*rs
, wchar_t const *p
);
328 wchar_t *rdtrim(rdstring
*rs
);
329 void rdaddc(rdstringc
*rs
, char c
);
330 void rdaddsc(rdstringc
*rs
, char const *p
);
331 char *rdtrimc(rdstringc
*rs
);
333 int compare_wordlists(word
*a
, word
*b
);
335 void mark_attr_ends(paragraph
*sourceform
);
337 typedef struct tagWrappedLine wrappedline
;
338 struct tagWrappedLine
{
340 word
*begin
, *end
; /* first & last words of line */
341 int nspaces
; /* number of whitespaces in line */
342 int shortfall
; /* how much shorter than max width */
344 wrappedline
*wrap_para(word
*, int, int, int (*)(void *, word
*), void *, int);
345 void wrap_free(wrappedline
*);
350 paragraph
*read_input(input
*in
, indexdata
*idx
);
355 struct keywordlist_Tag
{
358 tree234
*keys
; /* sorted by `key' field */
359 word
**looseends
; /* non-keyword list element numbers */
364 wchar_t *key
; /* the keyword itself */
365 word
*text
; /* "Chapter 2", "Appendix Q"... */
366 /* (NB: filepos are not set) */
367 paragraph
*para
; /* the paragraph referenced */
369 keyword
*kw_lookup(keywordlist
*, wchar_t *);
370 keywordlist
*get_keywords(paragraph
*);
371 void free_keywords(keywordlist
*);
372 void subst_keywords(paragraph
*, keywordlist
*);
379 * Data structure to hold both sides of the index.
381 struct indexdata_Tag
{
382 tree234
*tags
; /* holds type `indextag' */
383 tree234
*entries
; /* holds type `indexentry' */
387 * Data structure to hold an index tag (LHS of index).
389 struct indextag_Tag
{
392 filepos implicit_fpos
;
393 word
**explicit_texts
;
394 filepos
*explicit_fpos
;
395 int nexplicit
, explicit_size
;
397 indexentry
**refs
; /* array of entries referenced by tag */
401 * Data structure to hold an index entry (RHS of index).
403 struct indexentry_Tag
{
405 void *backend_data
; /* private to back end */
409 indexdata
*make_index(void);
410 void cleanup_index(indexdata
*);
411 /* index_merge takes responsibility for freeing arg 3 iff implicit; never
412 * takes responsibility for arg 2 */
413 void index_merge(indexdata
*, int is_explicit
, wchar_t *, word
*, filepos
*);
414 void build_index(indexdata
*);
415 void index_debug(indexdata
*);
416 indextag
*index_findtag(indexdata
*idx
, wchar_t *name
);
421 numberstate
*number_init(void);
422 void number_cfg(numberstate
*, paragraph
*);
423 word
*number_mktext(numberstate
*, paragraph
*, wchar_t *, int *, int *);
424 void number_free(numberstate
*);
429 void gen_citations(paragraph
*, keywordlist
*);
434 struct userstyle_Tag
{
440 void text_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
441 paragraph
*text_config_filename(char *filename
);
446 void xhtml_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
447 paragraph
*xhtml_config_filename(char *filename
);
452 void whlp_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
453 paragraph
*whlp_config_filename(char *filename
);
458 void man_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
459 paragraph
*man_config_filename(char *filename
);
464 void info_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
465 paragraph
*info_config_filename(char *filename
);
470 void *paper_pre_backend(paragraph
*, keywordlist
*, indexdata
*);
475 void ps_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
476 paragraph
*ps_config_filename(char *filename
);
481 void pdf_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
482 paragraph
*pdf_config_filename(char *filename
);