=================================================================== RCS file: /cvs/mandoc/libmdoc.h,v retrieving revision 1.1 retrieving revision 1.23 diff -u -p -r1.1 -r1.23 --- mandoc/libmdoc.h 2009/03/23 14:22:11 1.1 +++ mandoc/libmdoc.h 2009/08/18 14:27:16 1.23 @@ -1,20 +1,18 @@ -/* $Id: libmdoc.h,v 1.1 2009/03/23 14:22:11 kristaps Exp $ */ +/* $Id: libmdoc.h,v 1.23 2009/08/18 14:27:16 kristaps Exp $ */ /* - * Copyright (c) 2008, 2009 Kristaps Dzonsons + * Copyright (c) 2008, 2009 Kristaps Dzonsons * * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the - * above copyright notice and this permission notice appear in all - * copies. + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE - * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef LIBMDOC_H #define LIBMDOC_H @@ -31,8 +29,9 @@ struct mdoc { struct mdoc_cb cb; void *htab; int flags; -#define MDOC_HALT (1 << 0) -#define MDOC_LITERAL (1 << 1) +#define MDOC_HALT (1 << 0) /* Error in parse. Halt. */ +#define MDOC_LITERAL (1 << 1) /* In a literal scope. */ +#define MDOC_PBODY (1 << 2) /* In the document body. */ int pflags; enum mdoc_next next; struct mdoc_node *last; @@ -42,6 +41,60 @@ struct mdoc { enum mdoc_sec lastsec; }; +enum merr { + ETAILWS = 0, + EQUOTPARM, + EQUOTTERM, + EMALLOC, + EARGVAL, + EBODYPROL, + EPROLBODY, + ETEXTPROL, + ENOBLANK, + ETOOLONG, + EESCAPE, + EPRINT, + ENODAT, + ENOPROLOGUE, + ELINE, + EATT, + ENAME, + ELISTTYPE, + EDISPTYPE, + EMULTIDISP, + EMULTILIST, + ESECNAME, + ENAMESECINC, + EARGREP, + EBOOL, + ECOLMIS, + ENESTDISP, + EMISSWIDTH, + EWRONGMSEC, + ESECOOO, + ESECREP, + EBADSTAND, + ENOMULTILINE, + EMULTILINE, + ENOLINE, + EPROLOOO, + EPROLREP, + EBADMSEC, + EBADSEC, + EFONT, + EBADDATE, + ENUMFMT, + ENOWIDTH, + EUTSNAME, + EOBS, + EIMPBRK, + EIGNE, + EOPEN, + EQUOTPHR, + ENOCTX, + ELIB, + MERRMAX +}; #define MACRO_PROT_ARGS struct mdoc *mdoc, int tok, int line, \ int ppos, int *pos, char *buf @@ -57,48 +110,23 @@ struct mdoc_macro { /* Reserved words in arguments treated as text. */ }; -#define mdoc_nwarn(mdoc, node, type, fmt, ...) \ - mdoc_vwarn((mdoc), (node)->line, \ - (node)->pos, (type), (fmt), ##__VA_ARGS__) - -#define mdoc_nerr(mdoc, node, fmt, ...) \ - mdoc_verr((mdoc), (node)->line, \ - (node)->pos, (fmt), ##__VA_ARGS__) - -#define mdoc_warn(mdoc, type, fmt, ...) \ - mdoc_vwarn((mdoc), (mdoc)->last->line, \ - (mdoc)->last->pos, (type), (fmt), ##__VA_ARGS__) - -#define mdoc_err(mdoc, fmt, ...) \ - mdoc_verr((mdoc), (mdoc)->last->line, \ - (mdoc)->last->pos, (fmt), ##__VA_ARGS__) - -#define mdoc_msg(mdoc, fmt, ...) \ - mdoc_vmsg((mdoc), (mdoc)->last->line, \ - (mdoc)->last->pos, (fmt), ##__VA_ARGS__) - -#define mdoc_pmsg(mdoc, line, pos, fmt, ...) \ - mdoc_vmsg((mdoc), (line), \ - (pos), (fmt), ##__VA_ARGS__) - -#define mdoc_pwarn(mdoc, line, pos, type, fmt, ...) \ - mdoc_vwarn((mdoc), (line), \ - (pos), (type), (fmt), ##__VA_ARGS__) - -#define mdoc_perr(mdoc, line, pos, fmt, ...) \ - mdoc_verr((mdoc), (line), \ - (pos), (fmt), ##__VA_ARGS__) - extern const struct mdoc_macro *const mdoc_macros; __BEGIN_DECLS -int mdoc_vwarn(struct mdoc *, int, int, - enum mdoc_warn, const char *, ...); -void mdoc_vmsg(struct mdoc *, int, int, - const char *, ...); -int mdoc_verr(struct mdoc *, int, int, - const char *, ...); +#define mdoc_perr(m, l, p, t) \ + mdoc_err((m), (l), (p), 1, (t)) +#define mdoc_pwarn(m, l, p, t) \ + mdoc_err((m), (l), (p), 0, (t)) +#define mdoc_nerr(m, n, t) \ + mdoc_err((m), (n)->line, (n)->pos, 1, (t)) +#define mdoc_nwarn(m, n, t) \ + mdoc_err((m), (n)->line, (n)->pos, 0, (t)) + +int mdoc_err(struct mdoc *, int, int, int, enum merr); +int mdoc_verr(struct mdoc *, int, int, const char *, ...); +int mdoc_vwarn(struct mdoc *, int, int, const char *, ...); + int mdoc_macro(MACRO_PROT_ARGS); int mdoc_word_alloc(struct mdoc *, int, int, const char *); @@ -111,9 +139,9 @@ int mdoc_tail_alloc(struct mdoc *, int, int, int); int mdoc_body_alloc(struct mdoc *, int, int, int); void mdoc_node_free(struct mdoc_node *); void mdoc_node_freelist(struct mdoc_node *); -void *mdoc_tokhash_alloc(void); -int mdoc_tokhash_find(const void *, const char *); -void mdoc_tokhash_free(void *); +void *mdoc_hash_alloc(void); +int mdoc_hash_find(const void *, const char *); +void mdoc_hash_free(void *); int mdoc_iscdelim(char); int mdoc_isdelim(const char *); size_t mdoc_isescape(const char *); @@ -121,6 +149,9 @@ enum mdoc_sec mdoc_atosec(const char *); time_t mdoc_atotime(const char *); size_t mdoc_macro2len(int); +const char *mdoc_a2att(const char *); +const char *mdoc_a2lib(const char *); +const char *mdoc_a2st(const char *); const char *mdoc_a2arch(const char *); const char *mdoc_a2vol(const char *); const char *mdoc_a2msec(const char *); @@ -139,6 +170,8 @@ int mdoc_argv(struct mdoc *, int, int, void mdoc_argv_free(struct mdoc_arg *); int mdoc_args(struct mdoc *, int, int *, char *, int, char **); +int mdoc_zargs(struct mdoc *, int, + int *, char *, char **); #define ARGS_ERROR (-1) #define ARGS_EOLN (0) #define ARGS_WORD (1) @@ -146,14 +179,7 @@ int mdoc_args(struct mdoc *, int, #define ARGS_QWORD (3) #define ARGS_PHRASE (4) -/* FIXME: get rid of these. */ -int xstrlcpys(char *, const struct mdoc_node *, size_t); -int xstrlcat(char *, const char *, size_t); -int xstrlcpy(char *, const char *, size_t); -int xstrcmp(const char *, const char *); -void *xrealloc(void *, size_t); -char *xstrdup(const char *); -int macro_end(struct mdoc *); +int mdoc_macroend(struct mdoc *); __END_DECLS