Home | History | Annotate | Line # | Download | only in dist
libmdoc.h revision 1.1.1.3
      1  1.1.1.3  joerg /*	$Vendor-Id: libmdoc.h,v 1.31 2010/03/31 07:13:53 kristaps Exp $ */
      2      1.1  joerg /*
      3      1.1  joerg  * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps (at) kth.se>
      4      1.1  joerg  *
      5      1.1  joerg  * Permission to use, copy, modify, and distribute this software for any
      6      1.1  joerg  * purpose with or without fee is hereby granted, provided that the above
      7      1.1  joerg  * copyright notice and this permission notice appear in all copies.
      8      1.1  joerg  *
      9      1.1  joerg  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     10      1.1  joerg  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     11      1.1  joerg  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     12      1.1  joerg  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     13      1.1  joerg  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     14      1.1  joerg  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     15      1.1  joerg  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     16      1.1  joerg  */
     17      1.1  joerg #ifndef LIBMDOC_H
     18      1.1  joerg #define LIBMDOC_H
     19      1.1  joerg 
     20      1.1  joerg #include "mdoc.h"
     21      1.1  joerg 
     22      1.1  joerg enum	mdoc_next {
     23      1.1  joerg 	MDOC_NEXT_SIBLING = 0,
     24      1.1  joerg 	MDOC_NEXT_CHILD
     25      1.1  joerg };
     26      1.1  joerg 
     27      1.1  joerg struct	mdoc {
     28      1.1  joerg 	void		 *data;
     29      1.1  joerg 	struct mdoc_cb	  cb;
     30      1.1  joerg 	int		  flags;
     31      1.1  joerg #define	MDOC_HALT	 (1 << 0)	/* Error in parse. Halt. */
     32      1.1  joerg #define	MDOC_LITERAL	 (1 << 1)	/* In a literal scope. */
     33      1.1  joerg #define	MDOC_PBODY	 (1 << 2)	/* In the document body. */
     34      1.1  joerg 	int		  pflags;
     35      1.1  joerg 	enum mdoc_next	  next;
     36      1.1  joerg 	struct mdoc_node *last;
     37      1.1  joerg 	struct mdoc_node *first;
     38      1.1  joerg 	struct mdoc_meta  meta;
     39      1.1  joerg 	enum mdoc_sec	  lastnamed;
     40      1.1  joerg 	enum mdoc_sec	  lastsec;
     41      1.1  joerg };
     42      1.1  joerg 
     43      1.1  joerg enum	merr {
     44      1.1  joerg 	ETAILWS = 0,
     45      1.1  joerg 	EQUOTPARM,
     46      1.1  joerg 	EQUOTTERM,
     47      1.1  joerg 	EARGVAL,
     48      1.1  joerg 	EBODYPROL,
     49      1.1  joerg 	EPROLBODY,
     50      1.1  joerg 	ETEXTPROL,
     51      1.1  joerg 	ENOBLANK,
     52      1.1  joerg 	ETOOLONG,
     53      1.1  joerg 	EESCAPE,
     54      1.1  joerg 	EPRINT,
     55      1.1  joerg 	ENODAT,
     56      1.1  joerg 	ENOPROLOGUE,
     57      1.1  joerg 	ELINE,
     58      1.1  joerg 	EATT,
     59      1.1  joerg 	ENAME,
     60      1.1  joerg 	ELISTTYPE,
     61      1.1  joerg 	EDISPTYPE,
     62      1.1  joerg 	EMULTIDISP,
     63      1.1  joerg 	EMULTILIST,
     64      1.1  joerg 	ESECNAME,
     65      1.1  joerg 	ENAMESECINC,
     66      1.1  joerg 	EARGREP,
     67      1.1  joerg 	EBOOL,
     68      1.1  joerg 	ECOLMIS,
     69      1.1  joerg 	ENESTDISP,
     70      1.1  joerg 	EMISSWIDTH,
     71      1.1  joerg 	EWRONGMSEC,
     72      1.1  joerg 	ESECOOO,
     73      1.1  joerg 	ESECREP,
     74      1.1  joerg 	EBADSTAND,
     75      1.1  joerg 	ENOMULTILINE,
     76      1.1  joerg 	EMULTILINE,
     77      1.1  joerg 	ENOLINE,
     78      1.1  joerg 	EPROLOOO,
     79      1.1  joerg 	EPROLREP,
     80      1.1  joerg 	EBADMSEC,
     81      1.1  joerg 	EBADSEC,
     82      1.1  joerg 	EFONT,
     83      1.1  joerg 	EBADDATE,
     84      1.1  joerg 	ENUMFMT,
     85      1.1  joerg 	ENOWIDTH,
     86      1.1  joerg 	EUTSNAME,
     87      1.1  joerg 	EOBS,
     88      1.1  joerg 	EIMPBRK,
     89      1.1  joerg 	EIGNE,
     90      1.1  joerg 	EOPEN,
     91      1.1  joerg 	EQUOTPHR,
     92      1.1  joerg 	ENOCTX,
     93      1.1  joerg 	ELIB,
     94      1.1  joerg 	EBADCHILD,
     95      1.1  joerg 	ENOTYPE,
     96      1.1  joerg 	MERRMAX
     97      1.1  joerg };
     98      1.1  joerg 
     99  1.1.1.3  joerg #define	MACRO_PROT_ARGS	struct mdoc *m, enum mdoct tok, \
    100  1.1.1.3  joerg 			int line, int ppos, int *pos, char *buf
    101      1.1  joerg 
    102      1.1  joerg struct	mdoc_macro {
    103      1.1  joerg 	int		(*fp)(MACRO_PROT_ARGS);
    104      1.1  joerg 	int		  flags;
    105      1.1  joerg #define	MDOC_CALLABLE	 (1 << 0)
    106      1.1  joerg #define	MDOC_PARSED	 (1 << 1)
    107      1.1  joerg #define	MDOC_EXPLICIT	 (1 << 2)
    108      1.1  joerg #define	MDOC_PROLOGUE	 (1 << 3)
    109      1.1  joerg #define	MDOC_IGNDELIM	 (1 << 4)
    110      1.1  joerg 	/* Reserved words in arguments treated as text. */
    111      1.1  joerg };
    112      1.1  joerg 
    113      1.1  joerg extern	const struct mdoc_macro *const mdoc_macros;
    114      1.1  joerg 
    115      1.1  joerg __BEGIN_DECLS
    116      1.1  joerg 
    117      1.1  joerg #define		  mdoc_perr(m, l, p, t) \
    118      1.1  joerg 		  mdoc_err((m), (l), (p), 1, (t))
    119      1.1  joerg #define		  mdoc_pwarn(m, l, p, t) \
    120      1.1  joerg 		  mdoc_err((m), (l), (p), 0, (t))
    121      1.1  joerg #define		  mdoc_nerr(m, n, t) \
    122      1.1  joerg 		  mdoc_err((m), (n)->line, (n)->pos, 1, (t))
    123      1.1  joerg #define		  mdoc_nwarn(m, n, t) \
    124      1.1  joerg 		  mdoc_err((m), (n)->line, (n)->pos, 0, (t))
    125      1.1  joerg 
    126      1.1  joerg int		  mdoc_err(struct mdoc *, int, int, int, enum merr);
    127      1.1  joerg int		  mdoc_verr(struct mdoc *, int, int, const char *, ...);
    128      1.1  joerg int		  mdoc_vwarn(struct mdoc *, int, int, const char *, ...);
    129      1.1  joerg 
    130      1.1  joerg int		  mdoc_macro(MACRO_PROT_ARGS);
    131      1.1  joerg int		  mdoc_word_alloc(struct mdoc *,
    132      1.1  joerg 			int, int, const char *);
    133      1.1  joerg int		  mdoc_elem_alloc(struct mdoc *, int, int,
    134  1.1.1.3  joerg 			enum mdoct, struct mdoc_arg *);
    135      1.1  joerg int		  mdoc_block_alloc(struct mdoc *, int, int,
    136  1.1.1.3  joerg 			enum mdoct, struct mdoc_arg *);
    137  1.1.1.3  joerg int		  mdoc_head_alloc(struct mdoc *, int, int, enum mdoct);
    138  1.1.1.3  joerg int		  mdoc_tail_alloc(struct mdoc *, int, int, enum mdoct);
    139  1.1.1.3  joerg int		  mdoc_body_alloc(struct mdoc *, int, int, enum mdoct);
    140      1.1  joerg void		  mdoc_node_free(struct mdoc_node *);
    141      1.1  joerg void		  mdoc_node_freelist(struct mdoc_node *);
    142      1.1  joerg void		  mdoc_hash_init(void);
    143  1.1.1.3  joerg enum mdoct	  mdoc_hash_find(const char *);
    144      1.1  joerg int		  mdoc_iscdelim(char);
    145      1.1  joerg int		  mdoc_isdelim(const char *);
    146      1.1  joerg size_t		  mdoc_isescape(const char *);
    147      1.1  joerg enum	mdoc_sec  mdoc_atosec(const char *);
    148      1.1  joerg time_t		  mdoc_atotime(const char *);
    149      1.1  joerg 
    150      1.1  joerg size_t		  mdoc_macro2len(int);
    151      1.1  joerg const char	 *mdoc_a2att(const char *);
    152      1.1  joerg const char	 *mdoc_a2lib(const char *);
    153      1.1  joerg const char	 *mdoc_a2st(const char *);
    154      1.1  joerg const char	 *mdoc_a2arch(const char *);
    155      1.1  joerg const char	 *mdoc_a2vol(const char *);
    156      1.1  joerg const char	 *mdoc_a2msec(const char *);
    157      1.1  joerg int		  mdoc_valid_pre(struct mdoc *,
    158      1.1  joerg 			const struct mdoc_node *);
    159      1.1  joerg int		  mdoc_valid_post(struct mdoc *);
    160      1.1  joerg int		  mdoc_action_pre(struct mdoc *,
    161      1.1  joerg 			const struct mdoc_node *);
    162      1.1  joerg int		  mdoc_action_post(struct mdoc *);
    163  1.1.1.3  joerg int		  mdoc_argv(struct mdoc *, int, enum mdoct,
    164      1.1  joerg 			struct mdoc_arg **, int *, char *);
    165      1.1  joerg #define	ARGV_ERROR	(-1)
    166      1.1  joerg #define	ARGV_EOLN	(0)
    167      1.1  joerg #define	ARGV_ARG	(1)
    168      1.1  joerg #define	ARGV_WORD	(2)
    169      1.1  joerg void		  mdoc_argv_free(struct mdoc_arg *);
    170      1.1  joerg int		  mdoc_args(struct mdoc *, int,
    171  1.1.1.3  joerg 			int *, char *, enum mdoct, char **);
    172      1.1  joerg int		  mdoc_zargs(struct mdoc *, int,
    173      1.1  joerg 			int *, char *, int, char **);
    174      1.1  joerg #define	ARGS_DELIM	(1 << 1)	/* See args(). */
    175      1.1  joerg #define	ARGS_TABSEP	(1 << 2)	/* See args(). */
    176      1.1  joerg #define	ARGS_NOWARN	(1 << 3)	/* See args(). */
    177      1.1  joerg #define	ARGS_ERROR	(-1)
    178      1.1  joerg #define	ARGS_EOLN	(0)
    179      1.1  joerg #define	ARGS_WORD	(1)
    180      1.1  joerg #define	ARGS_PUNCT	(2)
    181      1.1  joerg #define	ARGS_QWORD	(3)
    182      1.1  joerg #define	ARGS_PHRASE	(4)
    183      1.1  joerg int		  mdoc_macroend(struct mdoc *);
    184      1.1  joerg 
    185      1.1  joerg __END_DECLS
    186      1.1  joerg 
    187      1.1  joerg #endif /*!LIBMDOC_H*/
    188