=================================================================== RCS file: /cvs/texi2mdoc/extern.h,v retrieving revision 1.13 retrieving revision 1.28 diff -u -p -r1.13 -r1.28 --- texi2mdoc/extern.h 2015/02/24 20:34:43 1.13 +++ texi2mdoc/extern.h 2015/03/12 04:24:19 1.28 @@ -1,4 +1,4 @@ -/* $Id: extern.h,v 1.13 2015/02/24 20:34:43 kristaps Exp $ */ +/* $Id: extern.h,v 1.28 2015/03/12 04:24:19 kristaps Exp $ */ /* * Copyright (c) 2015 Kristaps Dzonsons * @@ -17,6 +17,23 @@ #ifndef EXTERN_H #define EXTERN_H +#if !defined(__BEGIN_DECLS) +# ifdef __cplusplus +# define __BEGIN_DECLS extern "C" { +# else +# define __BEGIN_DECLS +# endif +#endif +#if !defined(__END_DECLS) +# ifdef __cplusplus +# define __END_DECLS } +# else +# define __END_DECLS +# endif +#endif + +#define HAVE_INDEX 1 + /* * This defines each one of the Texinfo commands that we understand. * Obviously this only refers to native commands; overriden names are a @@ -40,6 +57,7 @@ enum texicmd { TEXICMD_AT, TEXICMD_AUTHOR, TEXICMD_B, + TEXICMD_BACKSLASH, TEXICMD_BANG, TEXICMD_BULLET, TEXICMD_BYE, @@ -95,6 +113,7 @@ enum texicmd { TEXICMD_DMN, TEXICMD_DOCUMENTDESCRPITION, TEXICMD_DOCUMENTENCODING, + TEXICMD_DOCUMENTLANGUAGE, TEXICMD_DOTACCENT, TEXICMD_DOTLESS, TEXICMD_DOTS, @@ -114,7 +133,11 @@ enum texicmd { TEXICMD_FILE, TEXICMD_FINALOUT, TEXICMD_FINDEX, + TEXICMD_FLUSHLEFT, + TEXICMD_FLUSHRIGHT, + TEXICMD_FIRSTPARAGRAPHINDENT, TEXICMD_FOOTNOTE, + TEXICMD_FOOTNOTESTYLE, TEXICMD_FTABLE, TEXICMD_FORMAT, TEXICMD_GEQ, @@ -151,6 +174,7 @@ enum texicmd { TEXICMD_IMAGE, TEXICMD_INCLUDE, TEXICMD_INDENTBLOCK, + TEXICMD_INDICATEURL, TEXICMD_INFOREF, TEXICMD_INSERTCOPYING, TEXICMD_ITEM, @@ -253,6 +277,7 @@ enum texicmd { TEXICMD_TITLEFONT, TEXICMD_TITLEPAGE, TEXICMD_TOP, + TEXICMD_TPINDEX, TEXICMD_U, TEXICMD_UBARACCENT, TEXICMD_UDOTACCENT, @@ -271,6 +296,7 @@ enum texicmd { TEXICMD_VERBATIM, TEXICMD_VERBATIMINCLUDE, TEXICMD_VINDEX, + TEXICMD_VRINDEX, TEXICMD_VSKIP, TEXICMD_VTABLE, TEXICMD_W, @@ -292,8 +318,11 @@ struct texifile { const char *name; /* name of the file */ size_t line; /* current line (from zero) */ size_t col; /* current column in line (from zero) */ - char *map; /* mmap'd file OR allocated buffer */ - size_t mapsz; /* size of mmap */ + char *map; /* allocated file buffer */ + size_t mapsz; /* size of map */ + size_t mapmaxsz; /* full size of map */ + size_t insplice; /* how many bytes left in splice */ + size_t depth; /* pasted macro recursive depth */ }; struct texi; @@ -301,8 +330,7 @@ struct texi; /* * Callback for functions implementing texi commands. */ -typedef void (*texicmdfp)(struct texi *, - enum texicmd, const char *, size_t, size_t *); +typedef void (*texicmdfp)(struct texi *, enum texicmd, size_t *); /* * Describes Texinfo commands, whether native or overriden. @@ -345,38 +373,73 @@ struct teximacro { }; /* + * A term is a word in an index. + * For example "@cindex foo" adds the term "foo" to the "cp" index. + * This occurs within a chapter ("nodes" in struct texi) + */ +struct texiterm { + char *term; + size_t chapter; +}; + +/* + * Index tables. + * These have a two or three letter name (usually) and any number of + * terms that are associated with it. + */ +struct texidex { + char *name; + struct texiterm *index; + size_t indexsz; +}; + +/* * The main parse structure. * This keeps any necessary information handy. */ struct texi { + const char *chapters; /* are we splitting chapters */ + size_t chapnum; /* current chapter node */ + char **dirs; /* texi directories */ + size_t dirsz; /* number of texi directories */ + FILE *outfile; /* current output stream */ + /* + * Run-time parameters. + */ struct texifile files[64]; /* stack of open files */ size_t filepos; /* number of open files */ const char *valstack[64]; /* stack of opened values */ size_t valstackpos; /* position in valstack */ - size_t outcol; /* column in output line */ - char **dirs; /* texi directories */ - size_t dirsz; /* number of texi directories */ char *title; /* title of document */ char *subtitle; /* subtitle of document */ int secoffs; /* see sectioner() */ - char **indexs; /* @defindex indices */ + struct texidex *indexs; /* index entries */ size_t indexsz; /* entries in indexs */ struct texivalue *vals; /* @value entries */ size_t valsz; /* entries in vals */ struct teximacro *macros; /* @macro entries */ size_t macrosz; /* entries in macros */ + char *copying; /* the @copying block */ + size_t copyingsz; /* length of @copying */ + char **nodes; + size_t nodesz; /* * The following control what we output to the screen. * The complexity is required to accomodate for mdoc(7). */ enum texilist list; /* current list (set recursively) */ int outmacro; /* if >0, output is in line macro */ + size_t outcol; /* column in output line */ int seenws; /* ws has been seen (and ignored) */ int seenvs; /* newline has been Pp'd */ int ign; /* if >0, don't print anything */ int literal; /* if >0, literal context */ + int uppercase; /* if >0, uppercase */ }; +#define BUF(_p) ((_p)->files[(_p)->filepos - 1].map) +#define BUFSZ(_p) ((_p)->files[(_p)->filepos - 1].mapsz) + #define isws(_x) \ (' ' == (_x) || '\t' == (_x)) #define ismspace(_x) \ @@ -384,28 +447,28 @@ struct texi { __BEGIN_DECLS -void advance(struct texi *, const char *, size_t *); -size_t advanceeoln(struct texi *, const char *, size_t, size_t *, int); -void advanceto(struct texi *, const char *, size_t *, size_t); +void advance(struct texi *, size_t *); +size_t advanceeoln(struct texi *, size_t *, int); +void advanceto(struct texi *, size_t *, size_t); -char **argparse(struct texi *, const char *, size_t, size_t *, size_t *, size_t); +char **argparse(struct texi *, size_t *, size_t *, size_t); -int parsearg(struct texi *, const char *, size_t, size_t *, size_t); -void parsebracket(struct texi *, const char *, size_t, size_t *); +int parsearg(struct texi *, size_t *, size_t); +void parsebracket(struct texi *, size_t *, int); void parsestdin(struct texi *); void parsefile(struct texi *, const char *, int); -int parselinearg(struct texi *, const char *, size_t, size_t *); -void parseeof(struct texi *, const char *, size_t); -void parsemembuf(struct texi *, const char *, size_t); -void parseeoln(struct texi *, const char *, size_t, size_t *); -void parsesingle(struct texi *, const char *, size_t, size_t *); -void parseto(struct texi *, const char *, size_t, size_t *, const char *); +int parselinearg(struct texi *, size_t *); +void parseeoln(struct texi *, size_t *); +void parseto(struct texi *, size_t *, const char *); void texiabort(struct texi *, const char *) __attribute__((noreturn)); enum texicmd - texicmd(struct texi *, const char *, size_t, size_t, - size_t *, struct teximacro **); + texicmd(const struct texi *, size_t, size_t *, struct teximacro **); +enum texicmd + peekcmd(const struct texi *, size_t); +enum texicmd + peeklinecmd(const struct texi *, size_t); void texierr(struct texi *, const char *, ...) __attribute__((format(printf, 2, 3))) __attribute__((noreturn)); @@ -414,20 +477,26 @@ void texifilepop(struct texi *); void teximacro(struct texi *, const char *); void teximacroclose(struct texi *); void teximacroopen(struct texi *, const char *); -void texipunctuate(struct texi *, const char *, size_t, size_t *); -void texiputbuf(struct texi *p, const char *, size_t, size_t); +void teximdocopen(struct texi *, size_t *); +void teximdocclose(struct texi *, int); +void texindex(struct texi *, const char *, + size_t, const char *, size_t); +void texindex_add(struct texi *, const char *, size_t); +void texipunctuate(struct texi *, size_t *); +void texiputbuf(struct texi *p, size_t, size_t); void texiputchar(struct texi *p, char); void texiputchars(struct texi *, const char *); void texivspace(struct texi *); void texiwarn(const struct texi *, const char *, ...) __attribute__((format(printf, 2, 3))); +void texisplice(struct texi *, const char *, size_t, size_t); void valueadd(struct texi *, char *, char *); const char * - valueblookup(struct texi *, const char *, size_t, size_t *); -void valuelclear(struct texi *, const char *, size_t, size_t *); + valueblookup(struct texi *, size_t *); +void valuelclear(struct texi *, size_t *); const char * - valuellookup(struct texi *, const char *, size_t, size_t *); + valuellookup(struct texi *, size_t *); extern const struct texitok *const texitoks;