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 numberstate_Tag numberstate
;
39 typedef struct indexdata_Tag indexdata
;
40 typedef struct indextag_Tag indextag
;
41 typedef struct indexentry_Tag indexentry
;
42 typedef struct macrostack_Tag macrostack
;
45 * Data structure to hold a file name and index, a line and a
46 * column number, for reporting errors
54 * Data structure to hold all the file names etc for input
56 typedef struct pushback_Tag
{
61 char **filenames
; /* complete list of input files */
62 int nfiles
; /* how many in the list */
63 FILE *currfp
; /* the currently open one */
64 int currindex
; /* which one is that in the list */
65 int wantclose
; /* does the current file want closing */
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[] */
75 char *pushback_chars
; /* used to save input-encoding data */
79 * Data structure to hold the input form of the source, ie a linked
82 struct paragraph_Tag
{
85 wchar_t *keyword
; /* for most special paragraphs */
86 char *origkeyword
; /* same again in original charset */
87 word
*words
; /* list of words in paragraph */
88 int aux
; /* number, in a numbered paragraph
91 word
*kwtext
; /* chapter/section indication */
92 word
*kwtext2
; /* numeric-only form of kwtext */
95 paragraph
*parent
, *child
, *sibling
; /* for hierarchy navigation */
97 void *private_data
; /* for temp use in backends */
100 para_IM
, /* index merge */
101 para_BR
, /* bibliography rewrite */
102 para_Rule
, /* random horizontal rule */
105 para_UnnumberedChapter
,
109 para_Biblio
, /* causes no output unless turned ... */
110 para_BiblioCited
, /* ... into this paragraph type */
120 para_Config
, /* configuration directive */
121 para_LcontPush
, /* begin continuation of list item */
122 para_LcontPop
, /* end continuation of list item */
123 para_QuotePush
, /* begin block quote */
124 para_QuotePop
, /* end block quote */
126 * Back ends may define their own paragraph types beyond here,
127 * in case they need to use them internally.
129 para_NotParaType
/* placeholder value */
133 * Data structure to hold an individual word
139 int breaks
; /* can a line break after it? */
143 void *private_data
; /* for temp use in backends */
146 /* ORDERING CONSTRAINT: these normal-word types ... */
149 word_Code
, /* monospaced; `quoted' in text */
150 word_WeakCode
, /* monospaced, normal in text */
151 /* ... must be in the same order as these space types ... */
152 word_WhiteSpace
, /* text is NULL or ignorable */
153 word_EmphSpace
, /* WhiteSpace when emphasised */
154 word_CodeSpace
, /* WhiteSpace when code */
155 word_WkCodeSpace
, /* WhiteSpace when weak code */
156 /* ... and must be in the same order as these quote types ... */
157 word_Quote
, /* text is NULL or ignorable */
158 word_EmphQuote
, /* Quote when emphasised */
159 word_CodeQuote
, /* (can't happen) */
160 word_WkCodeQuote
, /* (can't happen) */
161 /* END ORDERING CONSTRAINT */
162 word_internal_endattrs
,
163 word_UpperXref
, /* \K */
164 word_LowerXref
, /* \k */
165 word_XrefEnd
, /* (invisible; no text) */
166 word_IndexRef
, /* (always an invisible one) */
167 word_HyperLink
, /* (invisible) */
168 word_HyperEnd
, /* (also invisible; no text) */
170 * Back ends may define their own word types beyond here, in
171 * case they need to use them internally.
173 word_NotWordType
/* placeholder value */
175 /* aux values for attributed words */
177 attr_Only
= 0x0000, /* a lone word with the attribute */
178 attr_First
= 0x0001, /* the first of a series */
179 attr_Last
= 0x0002, /* the last of a series */
180 attr_Always
= 0x0003, /* any other part of a series */
183 /* aux values for quote-type words */
186 quote_Close
= 0x0020,
189 #define isvis(x) ( ( (x) >= word_Normal && (x) <= word_LowerXref ) )
190 #define isattr(x) ( ( (x) > word_Normal && (x) < word_WhiteSpace ) || \
191 ( (x) > word_WhiteSpace && (x) < word_internal_endattrs ) )
192 #define sameattr(x,y) ( (((x)-(y)) & 3) == 0 )
193 #define towordstyle(x) ( word_Normal + ((x) & 3) )
194 #define tospacestyle(x) ( word_WhiteSpace + ((x) & 3) )
195 #define toquotestyle(x) ( word_Quote + ((x) & 3) )
196 #define removeattr(x) ( word_Normal + ((x) &~ 3) )
198 #define attraux(x) ( (x) & attr_mask )
199 #define quoteaux(x) ( (x) & quote_mask )
205 void fatalerr_nomemory(void) NORETURN
;
206 /* option `-%s' requires an argument */
207 void err_optnoarg(const char *sp
);
208 /* unrecognised option `-%s' */
209 void err_nosuchopt(const char *sp
);
210 /* unrecognised charset %s (cmdline) */
211 void err_cmdcharset(const char *sp
);
212 /* futile option `-%s'%s */
213 void err_futileopt(const char *sp
, const char *sp2
);
215 void err_noinput(void);
216 /* unable to open input file `%s' */
217 void err_cantopen(const char *sp
);
218 /* no data in input files */
219 void err_nodata(void);
220 /* line in codepara didn't begin `\c' */
221 void err_brokencodepara(const filepos
*fpos
);
222 /* expected `}' after keyword */
223 void err_kwunclosed(const filepos
*fpos
);
224 /* paragraph type expects no keyword */
225 void err_kwexpected(const filepos
*fpos
);
226 /* paragraph type expects a keyword */
227 void err_kwillegal(const filepos
*fpos
);
228 /* paragraph type expects only 1 */
229 void err_kwtoomany(const filepos
*fpos
);
230 /* paragraph type expects only kws! */
231 void err_bodyillegal(const filepos
*fpos
);
232 /* invalid command at start of para */
233 void err_badparatype(const wchar_t *wsp
, const filepos
*fpos
);
234 /* invalid command in mid-para */
235 void err_badmidcmd(const wchar_t *wsp
, const filepos
*fpos
);
236 /* unexpected brace */
237 void err_unexbrace(const filepos
*fpos
);
238 /* expected `{' after command */
239 void err_explbr(const filepos
*fpos
);
240 /* EOF inside braced comment */
241 void err_commenteof(const filepos
*fpos
);
242 /* expected `}' after cross-ref */
243 void err_kwexprbr(const filepos
*fpos
);
244 /* \q within \c is not supported */
245 void err_codequote(const filepos
*fpos
);
246 /* unclosed braces at end of para */
247 void err_missingrbrace(const filepos
*fpos
);
248 /* unclosed braces at end of file */
249 void err_missingrbrace2(const filepos
*fpos
);
250 /* unable to nest text styles */
251 void err_nestedstyles(const filepos
*fpos
);
252 /* unable to nest `\i' thingys */
253 void err_nestedindex(const filepos
*fpos
);
254 /* two \i differing only in case */
255 void err_indexcase(const filepos
*fpos
, const wchar_t *wsp
,
256 const filepos
*fpos2
, const wchar_t *wsp2
);
257 /* unresolved cross-reference */
258 void err_nosuchkw(const filepos
*fpos
, const wchar_t *wsp
);
259 /* multiple \BRs on same keyword */
260 void err_multiBR(const filepos
*fpos
, const wchar_t *wsp
);
261 /* \IM on unknown index tag (warning) */
262 void err_nosuchidxtag(const filepos
*fpos
, const wchar_t *wsp
);
263 /* can't open output file for write */
264 void err_cantopenw(const char *sp
);
265 /* this macro already exists */
266 void err_macroexists(const filepos
*fpos
, const wchar_t *wsp
);
267 /* jump a heading level, eg \C -> \S */
268 void err_sectjump(const filepos
*fpos
);
269 /* WinHelp context ID hash clash */
270 void err_winhelp_ctxclash(const filepos
*fpos
, const char *sp
, const char *sp2
);
271 /* keyword clash in sections */
272 void err_multikw(const filepos
*fpos
, const filepos
*fpos2
, const wchar_t *wsp
);
273 /* \lcont not after a list item */
274 void err_misplacedlcont(const filepos
*fpos
);
275 /* section marker appeared in block */
276 void err_sectmarkerinblock(const filepos
*fpos
, const char *sp
);
277 /* \cfg{%s} insufficient args (<%d) */
278 void err_cfginsufarg(const filepos
*fpos
, const char *sp
, int i
);
279 /* colon/comma in node name in info */
280 void err_infonodechar(const filepos
*fpos
, char c
) /* fpos might be NULL */;
281 /* \c line too long in text backend */
282 void err_text_codeline(const filepos
*fpos
, int i
, int j
);
283 /* unrecognised HTML version keyword */
284 void err_htmlver(const filepos
*fpos
, const wchar_t *wsp
);
285 /* unrecognised character set name */
286 void err_charset(const filepos
*fpos
, const wchar_t *wsp
);
287 /* unrecognised font name */
288 void err_nofont(const filepos
*fpos
, const wchar_t *wsp
);
289 /* eof in AFM file */
290 void err_afmeof(const filepos
*fpos
);
291 /* missing expected keyword in AFM */
292 void err_afmkey(const filepos
*fpos
, const char *sp
);
293 /* unsupported AFM version */
294 void err_afmvers(const filepos
*fpos
);
295 /* missing value(s) for AFM key */
296 void err_afmval(const filepos
*fpos
, const char *sp
, int i
);
297 /* eof in Type 1 font file */
298 void err_pfeof(const filepos
*fpos
);
299 /* bad Type 1 header line */
300 void err_pfhead(const filepos
*fpos
);
301 /* otherwise invalide Type 1 font */
302 void err_pfbad(const filepos
*fpos
);
303 /* Type 1 font but no AFM */
304 void err_pfnoafm(const filepos
*fpos
, const char *sp
);
305 /* need both or neither of hhp+chm */
306 void err_chmnames(void);
307 /* required sfnt table missing */
308 void err_sfntnotable(const filepos
*fpos
, const char *sp
);
309 /* sfnt has no PostScript name */
310 void err_sfntnopsname(const filepos
*fpos
);
311 /* sfnt table not valid */
312 void err_sfntbadtable(const filepos
*fpos
, const char *sp
);
313 /* sfnt has no UCS-2 cmap */
314 void err_sfntnounicmap(const filepos
*fpos
);
315 /* sfnt table version unknown */
316 void err_sfnttablevers(const filepos
*fpos
, const char *sp
);
317 /* sfnt has bad header */
318 void err_sfntbadhdr(const filepos
*fpos
);
319 /* sfnt cmap references bad glyph */
320 void err_sfntbadglyph(const filepos
*fpos
, unsigned wc
);
326 void *smalloc(char *file
, int line
, int size
);
327 void *srealloc(char *file
, int line
, void *p
, int size
);
328 void sfree(char *file
, int line
, void *p
);
329 #define smalloc(x) smalloc(__FILE__, __LINE__, x)
330 #define srealloc(x, y) srealloc(__FILE__, __LINE__, x, y)
331 #define sfree(x) sfree(__FILE__, __LINE__, x)
333 void *smalloc(int size
);
334 void *srealloc(void *p
, int size
);
337 void free_word_list(word
*w
);
338 void free_para_list(paragraph
*p
);
339 word
*dup_word_list(word
*w
);
340 char *dupstr(char const *s
);
342 #define snew(type) ( (type *) smalloc (sizeof (type)) )
343 #define snewn(number, type) ( (type *) smalloc ((number) * sizeof (type)) )
344 #define sresize(array, number, type) \
345 ( (type *) srealloc ((array), (number) * sizeof (type)) )
346 #define lenof(array) ( sizeof(array) / sizeof(*(array)) )
351 wchar_t *ustrdup(wchar_t const *s
);
352 char *ustrtoa(wchar_t const *s
, char *outbuf
, int size
, int charset
);
353 char *ustrtoa_careful(wchar_t const *s
, char *outbuf
, int size
, int charset
);
354 wchar_t *ustrfroma(char const *s
, wchar_t *outbuf
, int size
, int charset
);
355 char *utoa_dup(wchar_t const *s
, int charset
);
356 char *utoa_dup_len(wchar_t const *s
, int charset
, int *len
);
357 char *utoa_careful_dup(wchar_t const *s
, int charset
);
358 wchar_t *ufroma_dup(char const *s
, int charset
);
359 char *utoa_locale_dup(wchar_t const *s
);
360 wchar_t *ufroma_locale_dup(char const *s
);
361 int ustrlen(wchar_t const *s
);
362 wchar_t *uadv(wchar_t *s
);
363 wchar_t *ustrcpy(wchar_t *dest
, wchar_t const *source
);
364 wchar_t *ustrncpy(wchar_t *dest
, wchar_t const *source
, int n
);
365 wchar_t utolower(wchar_t);
366 int uisalpha(wchar_t);
367 int ustrcmp(wchar_t *lhs
, wchar_t *rhs
);
368 int ustricmp(wchar_t const *lhs
, wchar_t const *rhs
);
369 int ustrnicmp(wchar_t const *lhs
, wchar_t const *rhs
, int maxlen
);
370 int utoi(wchar_t const *);
371 double utof(wchar_t const *);
372 int utob(wchar_t const *);
373 int uisdigit(wchar_t);
374 wchar_t *ustrlow(wchar_t *s
);
375 wchar_t *ustrftime(const wchar_t *wfmt
, const struct tm
*timespec
);
376 int cvt_ok(int charset
, const wchar_t *s
);
377 int charset_from_ustr(filepos
*fpos
, const wchar_t *name
);
382 int strwid(char const *s
, int charset
);
383 int ustrwid(wchar_t const *s
, int charset
);
390 void showversion(void);
391 void listcharsets(void);
401 extern const char *const version
;
408 typedef struct stackTag
*stack
;
410 void stk_free(stack
);
411 void stk_push(stack
, void *);
412 void *stk_pop(stack
);
413 void *stk_top(stack
);
415 typedef struct tagRdstring rdstring
;
420 typedef struct tagRdstringc rdstringc
;
421 struct tagRdstringc
{
425 extern const rdstring empty_rdstring
;
426 extern const rdstringc empty_rdstringc
;
427 void rdadd(rdstring
*rs
, wchar_t c
);
428 void rdadds(rdstring
*rs
, wchar_t const *p
);
429 wchar_t *rdtrim(rdstring
*rs
);
430 void rdaddc(rdstringc
*rs
, char c
);
431 void rdaddsc(rdstringc
*rs
, char const *p
);
432 void rdaddsn(rdstringc
*rc
, char const *p
, int len
);
433 char *rdtrimc(rdstringc
*rs
);
435 int compare_wordlists(word
*a
, word
*b
);
437 void mark_attr_ends(word
*words
);
439 typedef struct tagWrappedLine wrappedline
;
440 struct tagWrappedLine
{
442 word
*begin
, *end
; /* first & last words of line */
443 int nspaces
; /* number of whitespaces in line */
444 int shortfall
; /* how much shorter than max width */
446 wrappedline
*wrap_para(word
*, int, int, int (*)(void *, word
*), void *, int);
447 void wrap_free(wrappedline
*);
448 void cmdline_cfg_add(paragraph
*cfg
, char *string
);
449 paragraph
*cmdline_cfg_new(void);
450 paragraph
*cmdline_cfg_simple(char *string
, ...);
455 paragraph
*read_input(input
*in
, indexdata
*idx
);
460 void read_afm_file(input
*in
);
465 void read_pfa_file(input
*in
);
466 void read_pfb_file(input
*in
);
471 void read_sfnt_file(input
*in
);
476 struct keywordlist_Tag
{
479 tree234
*keys
; /* sorted by `key' field */
480 word
**looseends
; /* non-keyword list element numbers */
485 wchar_t *key
; /* the keyword itself */
486 word
*text
; /* "Chapter 2", "Appendix Q"... */
487 /* (NB: filepos are not set) */
488 paragraph
*para
; /* the paragraph referenced */
490 keyword
*kw_lookup(keywordlist
*, wchar_t *);
491 keywordlist
*get_keywords(paragraph
*);
492 void free_keywords(keywordlist
*);
493 void subst_keywords(paragraph
*, keywordlist
*);
500 * Data structure to hold both sides of the index.
502 struct indexdata_Tag
{
503 tree234
*tags
; /* holds type `indextag' */
504 tree234
*entries
; /* holds type `indexentry' */
508 * Data structure to hold an index tag (LHS of index).
510 struct indextag_Tag
{
513 filepos implicit_fpos
;
514 word
**explicit_texts
;
515 filepos
*explicit_fpos
;
516 int nexplicit
, explicit_size
;
518 indexentry
**refs
; /* array of entries referenced by tag */
522 * Data structure to hold an index entry (RHS of index).
524 struct indexentry_Tag
{
526 void *backend_data
; /* private to back end */
530 indexdata
*make_index(void);
531 void cleanup_index(indexdata
*);
532 /* index_merge takes responsibility for freeing arg 3 iff implicit; never
533 * takes responsibility for arg 2 */
534 void index_merge(indexdata
*, int is_explicit
, wchar_t *, word
*, filepos
*);
535 void build_index(indexdata
*);
536 void index_debug(indexdata
*);
537 indextag
*index_findtag(indexdata
*idx
, wchar_t *name
);
542 numberstate
*number_init(void);
543 void number_cfg(numberstate
*, paragraph
*);
544 word
*number_mktext(numberstate
*, paragraph
*, wchar_t *, int *, int *);
545 void number_free(numberstate
*);
550 void gen_citations(paragraph
*, keywordlist
*);
555 void text_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
556 paragraph
*text_config_filename(char *filename
);
561 void html_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
562 paragraph
*html_config_filename(char *filename
);
567 void whlp_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
568 paragraph
*whlp_config_filename(char *filename
);
573 void man_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
574 paragraph
*man_config_filename(char *filename
);
579 void info_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
580 paragraph
*info_config_filename(char *filename
);
585 void *paper_pre_backend(paragraph
*, keywordlist
*, indexdata
*);
586 void listfonts(void);
591 void ps_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
592 paragraph
*ps_config_filename(char *filename
);
597 void pdf_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
598 paragraph
*pdf_config_filename(char *filename
);