Annotation of mandoc/libmdoc.h, Revision 1.1
1.1 ! kristaps 1: /* $Id: private.h,v 1.91 2009/03/21 13:09:29 kristaps Exp $ */
! 2: /*
! 3: * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
! 4: *
! 5: * Permission to use, copy, modify, and distribute this software for any
! 6: * purpose with or without fee is hereby granted, provided that the
! 7: * above copyright notice and this permission notice appear in all
! 8: * copies.
! 9: *
! 10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
! 11: * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
! 12: * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
! 13: * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
! 14: * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
! 15: * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
! 16: * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
! 17: * PERFORMANCE OF THIS SOFTWARE.
! 18: */
! 19: #ifndef LIBMDOC_H
! 20: #define LIBMDOC_H
! 21:
! 22: #include "mdoc.h"
! 23:
! 24: enum mdoc_next {
! 25: MDOC_NEXT_SIBLING = 0,
! 26: MDOC_NEXT_CHILD
! 27: };
! 28:
! 29: struct mdoc {
! 30: void *data;
! 31: struct mdoc_cb cb;
! 32: void *htab;
! 33: int flags;
! 34: #define MDOC_HALT (1 << 0)
! 35: #define MDOC_LITERAL (1 << 1)
! 36: int pflags;
! 37: enum mdoc_next next;
! 38: struct mdoc_node *last;
! 39: struct mdoc_node *first;
! 40: struct mdoc_meta meta;
! 41: enum mdoc_sec lastnamed;
! 42: enum mdoc_sec lastsec;
! 43: };
! 44:
! 45:
! 46: #define MACRO_PROT_ARGS struct mdoc *mdoc, int tok, int line, \
! 47: int ppos, int *pos, char *buf
! 48:
! 49: struct mdoc_macro {
! 50: int (*fp)(MACRO_PROT_ARGS);
! 51: int flags;
! 52: #define MDOC_CALLABLE (1 << 0)
! 53: #define MDOC_PARSED (1 << 1)
! 54: #define MDOC_EXPLICIT (1 << 2)
! 55: #define MDOC_PROLOGUE (1 << 3)
! 56: #define MDOC_IGNDELIM (1 << 4)
! 57: /* Reserved words in arguments treated as text. */
! 58: };
! 59:
! 60: #define mdoc_nwarn(mdoc, node, type, fmt, ...) \
! 61: mdoc_vwarn((mdoc), (node)->line, \
! 62: (node)->pos, (type), (fmt), ##__VA_ARGS__)
! 63:
! 64: #define mdoc_nerr(mdoc, node, fmt, ...) \
! 65: mdoc_verr((mdoc), (node)->line, \
! 66: (node)->pos, (fmt), ##__VA_ARGS__)
! 67:
! 68: #define mdoc_warn(mdoc, type, fmt, ...) \
! 69: mdoc_vwarn((mdoc), (mdoc)->last->line, \
! 70: (mdoc)->last->pos, (type), (fmt), ##__VA_ARGS__)
! 71:
! 72: #define mdoc_err(mdoc, fmt, ...) \
! 73: mdoc_verr((mdoc), (mdoc)->last->line, \
! 74: (mdoc)->last->pos, (fmt), ##__VA_ARGS__)
! 75:
! 76: #define mdoc_msg(mdoc, fmt, ...) \
! 77: mdoc_vmsg((mdoc), (mdoc)->last->line, \
! 78: (mdoc)->last->pos, (fmt), ##__VA_ARGS__)
! 79:
! 80: #define mdoc_pmsg(mdoc, line, pos, fmt, ...) \
! 81: mdoc_vmsg((mdoc), (line), \
! 82: (pos), (fmt), ##__VA_ARGS__)
! 83:
! 84: #define mdoc_pwarn(mdoc, line, pos, type, fmt, ...) \
! 85: mdoc_vwarn((mdoc), (line), \
! 86: (pos), (type), (fmt), ##__VA_ARGS__)
! 87:
! 88: #define mdoc_perr(mdoc, line, pos, fmt, ...) \
! 89: mdoc_verr((mdoc), (line), \
! 90: (pos), (fmt), ##__VA_ARGS__)
! 91:
! 92: extern const struct mdoc_macro *const mdoc_macros;
! 93:
! 94: __BEGIN_DECLS
! 95:
! 96: int mdoc_vwarn(struct mdoc *, int, int,
! 97: enum mdoc_warn, const char *, ...);
! 98: void mdoc_vmsg(struct mdoc *, int, int,
! 99: const char *, ...);
! 100: int mdoc_verr(struct mdoc *, int, int,
! 101: const char *, ...);
! 102: int mdoc_macro(MACRO_PROT_ARGS);
! 103: int mdoc_word_alloc(struct mdoc *,
! 104: int, int, const char *);
! 105: int mdoc_elem_alloc(struct mdoc *, int, int,
! 106: int, struct mdoc_arg *);
! 107: int mdoc_block_alloc(struct mdoc *, int, int,
! 108: int, struct mdoc_arg *);
! 109: int mdoc_head_alloc(struct mdoc *, int, int, int);
! 110: int mdoc_tail_alloc(struct mdoc *, int, int, int);
! 111: int mdoc_body_alloc(struct mdoc *, int, int, int);
! 112: void mdoc_node_free(struct mdoc_node *);
! 113: void mdoc_node_freelist(struct mdoc_node *);
! 114: void *mdoc_tokhash_alloc(void);
! 115: int mdoc_tokhash_find(const void *, const char *);
! 116: void mdoc_tokhash_free(void *);
! 117: int mdoc_iscdelim(char);
! 118: int mdoc_isdelim(const char *);
! 119: size_t mdoc_isescape(const char *);
! 120: enum mdoc_sec mdoc_atosec(const char *);
! 121: time_t mdoc_atotime(const char *);
! 122:
! 123: size_t mdoc_macro2len(int);
! 124: const char *mdoc_a2arch(const char *);
! 125: const char *mdoc_a2vol(const char *);
! 126: const char *mdoc_a2msec(const char *);
! 127: int mdoc_valid_pre(struct mdoc *,
! 128: const struct mdoc_node *);
! 129: int mdoc_valid_post(struct mdoc *);
! 130: int mdoc_action_pre(struct mdoc *,
! 131: const struct mdoc_node *);
! 132: int mdoc_action_post(struct mdoc *);
! 133: int mdoc_argv(struct mdoc *, int, int,
! 134: struct mdoc_arg **, int *, char *);
! 135: #define ARGV_ERROR (-1)
! 136: #define ARGV_EOLN (0)
! 137: #define ARGV_ARG (1)
! 138: #define ARGV_WORD (2)
! 139: void mdoc_argv_free(struct mdoc_arg *);
! 140: int mdoc_args(struct mdoc *, int,
! 141: int *, char *, int, char **);
! 142: #define ARGS_ERROR (-1)
! 143: #define ARGS_EOLN (0)
! 144: #define ARGS_WORD (1)
! 145: #define ARGS_PUNCT (2)
! 146: #define ARGS_QWORD (3)
! 147: #define ARGS_PHRASE (4)
! 148:
! 149: /* FIXME: get rid of these. */
! 150: int xstrlcpys(char *, const struct mdoc_node *, size_t);
! 151: int xstrlcat(char *, const char *, size_t);
! 152: int xstrlcpy(char *, const char *, size_t);
! 153: int xstrcmp(const char *, const char *);
! 154: void *xrealloc(void *, size_t);
! 155: char *xstrdup(const char *);
! 156: int macro_end(struct mdoc *);
! 157:
! 158: __END_DECLS
! 159:
! 160: #endif /*!LIBMDOC_H*/
CVSweb