| 1 | /* $Id: man.h,v 1.23 2009/10/30 05:58:37 kristaps Exp $ */ |
| 2 | /* |
| 3 | * Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se> |
| 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 above |
| 7 | * copyright notice and this permission notice appear in all copies. |
| 8 | * |
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 | */ |
| 17 | #ifndef MAN_H |
| 18 | #define MAN_H |
| 19 | |
| 20 | #include <time.h> |
| 21 | |
| 22 | #define MAN_br 0 |
| 23 | #define MAN_TH 1 |
| 24 | #define MAN_SH 2 |
| 25 | #define MAN_SS 3 |
| 26 | #define MAN_TP 4 |
| 27 | #define MAN_LP 5 |
| 28 | #define MAN_PP 6 |
| 29 | #define MAN_P 7 |
| 30 | #define MAN_IP 8 |
| 31 | #define MAN_HP 9 |
| 32 | #define MAN_SM 10 |
| 33 | #define MAN_SB 11 |
| 34 | #define MAN_BI 12 |
| 35 | #define MAN_IB 13 |
| 36 | #define MAN_BR 14 |
| 37 | #define MAN_RB 15 |
| 38 | #define MAN_R 16 |
| 39 | #define MAN_B 17 |
| 40 | #define MAN_I 18 |
| 41 | #define MAN_IR 19 |
| 42 | #define MAN_RI 20 |
| 43 | #define MAN_na 21 |
| 44 | #define MAN_i 22 |
| 45 | #define MAN_sp 23 |
| 46 | #define MAN_nf 24 |
| 47 | #define MAN_fi 25 |
| 48 | #define MAN_r 26 |
| 49 | #define MAN_RE 27 |
| 50 | #define MAN_RS 28 |
| 51 | #define MAN_DT 29 |
| 52 | #define MAN_UC 30 |
| 53 | #define MAN_PD 31 |
| 54 | #define MAN_MAX 32 |
| 55 | |
| 56 | enum man_type { |
| 57 | MAN_TEXT, |
| 58 | MAN_ELEM, |
| 59 | MAN_ROOT, |
| 60 | MAN_BLOCK, |
| 61 | MAN_HEAD, |
| 62 | MAN_BODY |
| 63 | }; |
| 64 | |
| 65 | struct man_meta { |
| 66 | int msec; |
| 67 | time_t date; |
| 68 | char *vol; |
| 69 | char *title; |
| 70 | char *source; |
| 71 | }; |
| 72 | |
| 73 | struct man_node { |
| 74 | struct man_node *parent; |
| 75 | struct man_node *child; |
| 76 | struct man_node *next; |
| 77 | struct man_node *prev; |
| 78 | int nchild; |
| 79 | int line; |
| 80 | int pos; |
| 81 | int tok; |
| 82 | int flags; |
| 83 | #define MAN_VALID (1 << 0) |
| 84 | #define MAN_ACTED (1 << 1) |
| 85 | enum man_type type; |
| 86 | char *string; |
| 87 | struct man_node *head; |
| 88 | struct man_node *body; |
| 89 | }; |
| 90 | |
| 91 | #define MAN_IGN_MACRO (1 << 0) |
| 92 | #define MAN_IGN_CHARS (1 << 1) |
| 93 | #define MAN_IGN_ESCAPE (1 << 2) |
| 94 | |
| 95 | extern const char *const *man_macronames; |
| 96 | |
| 97 | struct man_cb { |
| 98 | int (*man_warn)(void *, int, int, const char *); |
| 99 | int (*man_err)(void *, int, int, const char *); |
| 100 | }; |
| 101 | |
| 102 | __BEGIN_DECLS |
| 103 | |
| 104 | struct man; |
| 105 | |
| 106 | void man_free(struct man *); |
| 107 | struct man *man_alloc(void *, int, const struct man_cb *); |
| 108 | void man_reset(struct man *); |
| 109 | int man_parseln(struct man *, int, char *buf); |
| 110 | int man_endparse(struct man *); |
| 111 | |
| 112 | const struct man_node *man_node(const struct man *); |
| 113 | const struct man_meta *man_meta(const struct man *); |
| 114 | |
| 115 | __END_DECLS |
| 116 | |
| 117 | #endif /*!MAN_H*/ |