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 pushback
*pushback
; /* pushed-back input characters */
66 int npushback
, pushbacksize
;
68 int reportcols
; /* report column numbers in errors */
69 macrostack
*stack
; /* macro expansions in force */
70 int defcharset
, charset
; /* character sets for input files */
71 charset_state csstate
;
72 wchar_t wc
[16]; /* wide chars from input conversion */
73 int nwc
, wcpos
; /* size of, and position in, wc[] */
74 char *pushback_chars
; /* used to save input-encoding data */
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 char *origkeyword
; /* same again in original charset */
86 word
*words
; /* list of words in paragraph */
87 int aux
; /* number, in a numbered paragraph
90 word
*kwtext
; /* chapter/section indication */
91 word
*kwtext2
; /* numeric-only form of kwtext */
94 paragraph
*parent
, *child
, *sibling
; /* for hierarchy navigation */
96 void *private_data
; /* for temp use in backends */
99 para_IM
, /* index merge */
100 para_BR
, /* bibliography rewrite */
101 para_Rule
, /* random horizontal rule */
104 para_UnnumberedChapter
,
108 para_Biblio
, /* causes no output unless turned ... */
109 para_BiblioCited
, /* ... into this paragraph type */
119 para_Config
, /* configuration directive */
120 para_LcontPush
, /* begin continuation of list item */
121 para_LcontPop
, /* end continuation of list item */
122 para_QuotePush
, /* begin block quote */
123 para_QuotePop
, /* end block quote */
125 * Back ends may define their own paragraph types beyond here,
126 * in case they need to use them internally.
128 para_NotParaType
/* placeholder value */
132 * Data structure to hold an individual word
138 int breaks
; /* can a line break after it? */
142 void *private_data
; /* for temp use in backends */
145 /* ORDERING CONSTRAINT: these normal-word types ... */
148 word_Code
, /* monospaced; `quoted' in text */
149 word_WeakCode
, /* monospaced, normal in text */
150 /* ... must be in the same order as these space types ... */
151 word_WhiteSpace
, /* text is NULL or ignorable */
152 word_EmphSpace
, /* WhiteSpace when emphasised */
153 word_CodeSpace
, /* WhiteSpace when code */
154 word_WkCodeSpace
, /* WhiteSpace when weak code */
155 /* ... and must be in the same order as these quote types ... */
156 word_Quote
, /* text is NULL or ignorable */
157 word_EmphQuote
, /* Quote when emphasised */
158 word_CodeQuote
, /* (can't happen) */
159 word_WkCodeQuote
, /* (can't happen) */
160 /* END ORDERING CONSTRAINT */
161 word_internal_endattrs
,
162 word_UpperXref
, /* \K */
163 word_LowerXref
, /* \k */
164 word_XrefEnd
, /* (invisible; no text) */
165 word_IndexRef
, /* (always an invisible one) */
166 word_HyperLink
, /* (invisible) */
167 word_HyperEnd
, /* (also invisible; no text) */
169 * Back ends may define their own word types beyond here, in
170 * case they need to use them internally.
172 word_NotWordType
/* placeholder value */
174 /* aux values for attributed words */
176 attr_Only
= 0x0000, /* a lone word with the attribute */
177 attr_First
= 0x0001, /* the first of a series */
178 attr_Last
= 0x0002, /* the last of a series */
179 attr_Always
= 0x0003, /* any other part of a series */
182 /* aux values for quote-type words */
185 quote_Close
= 0x0020,
188 #define isvis(x) ( ( (x) >= word_Normal && (x) <= word_LowerXref ) )
189 #define isattr(x) ( ( (x) > word_Normal && (x) < word_WhiteSpace ) || \
190 ( (x) > word_WhiteSpace && (x) < word_internal_endattrs ) )
191 #define sameattr(x,y) ( (((x)-(y)) & 3) == 0 )
192 #define towordstyle(x) ( word_Normal + ((x) & 3) )
193 #define tospacestyle(x) ( word_WhiteSpace + ((x) & 3) )
194 #define toquotestyle(x) ( word_Quote + ((x) & 3) )
195 #define removeattr(x) ( word_Normal + ((x) &~ 3) )
197 #define attraux(x) ( (x) & attr_mask )
198 #define quoteaux(x) ( (x) & quote_mask )
203 void fatal(int code
, ...) NORETURN
;
204 void error(int code
, ...);
206 err_nomemory
, /* out of memory */
207 err_optnoarg
, /* option `-%s' requires an argument */
208 err_nosuchopt
, /* unrecognised option `-%s' */
209 err_cmdcharset
, /* unrecognised charset %s (cmdline) */
210 err_futileopt
, /* futile option `-%s'%s */
211 err_noinput
, /* no input files */
212 err_cantopen
, /* unable to open input file `%s' */
213 err_nodata
, /* no data in input files */
214 err_brokencodepara
, /* line in codepara didn't begin `\c' */
215 err_kwunclosed
, /* expected `}' after keyword */
216 err_kwillegal
, /* paragraph type expects no keyword */
217 err_kwexpected
, /* paragraph type expects a keyword */
218 err_kwtoomany
, /* paragraph type expects only 1 */
219 err_bodyillegal
, /* paragraph type expects only kws! */
220 err_badparatype
, /* invalid command at start of para */
221 err_badmidcmd
, /* invalid command in mid-para */
222 err_unexbrace
, /* unexpected brace */
223 err_explbr
, /* expected `{' after command */
224 err_commenteof
, /* EOF inside braced comment */
225 err_kwexprbr
, /* expected `}' after cross-ref */
226 err_codequote
, /* \q within \c is not supported */
227 err_missingrbrace
, /* unclosed braces at end of para */
228 err_missingrbrace2
, /* unclosed braces at end of file */
229 err_nestedstyles
, /* unable to nest text styles */
230 err_nestedindex
, /* unable to nest `\i' thingys */
231 err_indexcase
, /* two \i differing only in case */
232 err_nosuchkw
, /* unresolved cross-reference */
233 err_multiBR
, /* multiple \BRs on same keyword */
234 err_nosuchidxtag
, /* \IM on unknown index tag (warning) */
235 err_cantopenw
, /* can't open output file for write */
236 err_macroexists
, /* this macro already exists */
237 err_sectjump
, /* jump a heading level, eg \C -> \S */
238 err_winhelp_ctxclash
, /* WinHelp context ID hash clash */
239 err_multikw
, /* keyword clash in sections */
240 err_misplacedlcont
, /* \lcont not after a list item */
241 err_sectmarkerinblock
, /* section marker appeared in block */
242 err_cfginsufarg
, /* \cfg{%s} insufficient args (<%d) */
243 err_infonodechar
, /* colon/comma in node name in info */
244 err_text_codeline
, /* \c line too long in text backend */
245 err_htmlver
, /* unrecognised HTML version keyword */
246 err_charset
, /* unrecognised character set name */
247 err_nofont
, /* unrecognised font name */
248 err_afmeof
, /* eof in AFM file */
249 err_afmkey
, /* missing expected keyword in AFM */
250 err_afmvers
, /* unsupported AFM version */
251 err_afmval
, /* missing value(s) for AFM key */
252 err_pfeof
, /* eof in Type 1 font file */
253 err_pfhead
, /* bad Type 1 header line */
254 err_pfbad
, /* otherwise invalide Type 1 font */
255 err_pfnoafm
, /* Type 1 font but no AFM */
256 err_chmnames
, /* need both or neither of hhp+chm */
257 err_sfntnotable
, /* required sfnt table missing */
258 err_sfntnopsname
, /* sfnt has no PostScript name */
259 err_sfntbadtable
, /* sfnt table not valid */
260 err_sfntnounicmap
, /* sfnt has no UCS-2 cmap */
261 err_sfnttablevers
, /* sfnt table version unknown */
262 err_sfntbadhdr
, /* sfnt has bad header */
263 err_sfntbadglyph
, /* sfnt cmap references bad glyph */
264 err_whatever
/* random error of another type */
271 void *smalloc(char *file
, int line
, int size
);
272 void *srealloc(char *file
, int line
, void *p
, int size
);
273 void sfree(char *file
, int line
, void *p
);
274 #define smalloc(x) smalloc(__FILE__, __LINE__, x)
275 #define srealloc(x, y) srealloc(__FILE__, __LINE__, x, y)
276 #define sfree(x) sfree(__FILE__, __LINE__, x)
278 void *smalloc(int size
);
279 void *srealloc(void *p
, int size
);
282 void free_word_list(word
*w
);
283 void free_para_list(paragraph
*p
);
284 word
*dup_word_list(word
*w
);
285 char *dupstr(char const *s
);
287 #define snew(type) ( (type *) smalloc (sizeof (type)) )
288 #define snewn(number, type) ( (type *) smalloc ((number) * sizeof (type)) )
289 #define sresize(array, number, type) \
290 ( (type *) srealloc ((array), (number) * sizeof (type)) )
291 #define lenof(array) ( sizeof(array) / sizeof(*(array)) )
296 wchar_t *ustrdup(wchar_t const *s
);
297 char *ustrtoa(wchar_t const *s
, char *outbuf
, int size
, int charset
);
298 char *ustrtoa_careful(wchar_t const *s
, char *outbuf
, int size
, int charset
);
299 wchar_t *ustrfroma(char const *s
, wchar_t *outbuf
, int size
, int charset
);
300 char *utoa_dup(wchar_t const *s
, int charset
);
301 char *utoa_dup_len(wchar_t const *s
, int charset
, int *len
);
302 char *utoa_careful_dup(wchar_t const *s
, int charset
);
303 wchar_t *ufroma_dup(char const *s
, int charset
);
304 char *utoa_locale_dup(wchar_t const *s
);
305 wchar_t *ufroma_locale_dup(char const *s
);
306 int ustrlen(wchar_t const *s
);
307 wchar_t *uadv(wchar_t *s
);
308 wchar_t *ustrcpy(wchar_t *dest
, wchar_t const *source
);
309 wchar_t *ustrncpy(wchar_t *dest
, wchar_t const *source
, int n
);
310 wchar_t utolower(wchar_t);
311 int uisalpha(wchar_t);
312 int ustrcmp(wchar_t *lhs
, wchar_t *rhs
);
313 int ustricmp(wchar_t const *lhs
, wchar_t const *rhs
);
314 int ustrnicmp(wchar_t const *lhs
, wchar_t const *rhs
, int maxlen
);
315 int utoi(wchar_t const *);
316 double utof(wchar_t const *);
317 int utob(wchar_t const *);
318 int uisdigit(wchar_t);
319 wchar_t *ustrlow(wchar_t *s
);
320 wchar_t *ustrftime(const wchar_t *wfmt
, const struct tm
*timespec
);
321 int cvt_ok(int charset
, const wchar_t *s
);
322 int charset_from_ustr(filepos
*fpos
, const wchar_t *name
);
327 int strwid(char const *s
, int charset
);
328 int ustrwid(wchar_t const *s
, int charset
);
335 void showversion(void);
336 void listcharsets(void);
346 extern const char *const version
;
353 typedef struct stackTag
*stack
;
355 void stk_free(stack
);
356 void stk_push(stack
, void *);
357 void *stk_pop(stack
);
358 void *stk_top(stack
);
360 typedef struct tagRdstring rdstring
;
365 typedef struct tagRdstringc rdstringc
;
366 struct tagRdstringc
{
370 extern const rdstring empty_rdstring
;
371 extern const rdstringc empty_rdstringc
;
372 void rdadd(rdstring
*rs
, wchar_t c
);
373 void rdadds(rdstring
*rs
, wchar_t const *p
);
374 wchar_t *rdtrim(rdstring
*rs
);
375 void rdaddc(rdstringc
*rs
, char c
);
376 void rdaddsc(rdstringc
*rs
, char const *p
);
377 void rdaddsn(rdstringc
*rc
, char const *p
, int len
);
378 char *rdtrimc(rdstringc
*rs
);
380 int compare_wordlists(word
*a
, word
*b
);
382 void mark_attr_ends(word
*words
);
384 typedef struct tagWrappedLine wrappedline
;
385 struct tagWrappedLine
{
387 word
*begin
, *end
; /* first & last words of line */
388 int nspaces
; /* number of whitespaces in line */
389 int shortfall
; /* how much shorter than max width */
391 wrappedline
*wrap_para(word
*, int, int, int (*)(void *, word
*), void *, int);
392 void wrap_free(wrappedline
*);
393 void cmdline_cfg_add(paragraph
*cfg
, char *string
);
394 paragraph
*cmdline_cfg_new(void);
395 paragraph
*cmdline_cfg_simple(char *string
, ...);
400 paragraph
*read_input(input
*in
, indexdata
*idx
);
405 void read_afm_file(input
*in
);
410 void read_pfa_file(input
*in
);
411 void read_pfb_file(input
*in
);
416 void read_sfnt_file(input
*in
);
421 struct keywordlist_Tag
{
424 tree234
*keys
; /* sorted by `key' field */
425 word
**looseends
; /* non-keyword list element numbers */
430 wchar_t *key
; /* the keyword itself */
431 word
*text
; /* "Chapter 2", "Appendix Q"... */
432 /* (NB: filepos are not set) */
433 paragraph
*para
; /* the paragraph referenced */
435 keyword
*kw_lookup(keywordlist
*, wchar_t *);
436 keywordlist
*get_keywords(paragraph
*);
437 void free_keywords(keywordlist
*);
438 void subst_keywords(paragraph
*, keywordlist
*);
445 * Data structure to hold both sides of the index.
447 struct indexdata_Tag
{
448 tree234
*tags
; /* holds type `indextag' */
449 tree234
*entries
; /* holds type `indexentry' */
453 * Data structure to hold an index tag (LHS of index).
455 struct indextag_Tag
{
458 filepos implicit_fpos
;
459 word
**explicit_texts
;
460 filepos
*explicit_fpos
;
461 int nexplicit
, explicit_size
;
463 indexentry
**refs
; /* array of entries referenced by tag */
467 * Data structure to hold an index entry (RHS of index).
469 struct indexentry_Tag
{
471 void *backend_data
; /* private to back end */
475 indexdata
*make_index(void);
476 void cleanup_index(indexdata
*);
477 /* index_merge takes responsibility for freeing arg 3 iff implicit; never
478 * takes responsibility for arg 2 */
479 void index_merge(indexdata
*, int is_explicit
, wchar_t *, word
*, filepos
*);
480 void build_index(indexdata
*);
481 void index_debug(indexdata
*);
482 indextag
*index_findtag(indexdata
*idx
, wchar_t *name
);
487 numberstate
*number_init(void);
488 void number_cfg(numberstate
*, paragraph
*);
489 word
*number_mktext(numberstate
*, paragraph
*, wchar_t *, int *, int *);
490 void number_free(numberstate
*);
495 void gen_citations(paragraph
*, keywordlist
*);
500 void text_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
501 paragraph
*text_config_filename(char *filename
);
506 void html_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
507 paragraph
*html_config_filename(char *filename
);
512 void whlp_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
513 paragraph
*whlp_config_filename(char *filename
);
518 void man_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
519 paragraph
*man_config_filename(char *filename
);
524 void info_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
525 paragraph
*info_config_filename(char *filename
);
530 void *paper_pre_backend(paragraph
*, keywordlist
*, indexdata
*);
531 void listfonts(void);
536 void ps_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
537 paragraph
*ps_config_filename(char *filename
);
542 void pdf_backend(paragraph
*, keywordlist
*, indexdata
*, void *);
543 paragraph
*pdf_config_filename(char *filename
);