diff options
-rw-r--r-- | Makefile | 18 | ||||
-rw-r--r-- | macro.c | 93 | ||||
-rw-r--r-- | mdoc.h | 92 | ||||
-rw-r--r-- | private.h | 9 | ||||
-rw-r--r-- | strings.c | 66 |
5 files changed, 200 insertions, 78 deletions
@@ -2,15 +2,15 @@ VERSION = 1.1.0 CFLAGS += -W -Wall -Wno-unused-parameter -g -LNS = macro.ln mdoc.ln mdocml.ln hash.ln +LNS = macro.ln mdoc.ln mdocml.ln hash.ln strings.ln LLNS = llib-llibmdoc.ln llib-lmdocml.ln LIBS = libmdoc.a -OBJS = macro.o mdoc.o mdocml.o hash.o +OBJS = macro.o mdoc.o mdocml.o hash.o strings.o -SRCS = macro.c mdoc.c mdocml.c hash.c +SRCS = macro.c mdoc.c mdocml.c hash.c strings.c HEADS = mdoc.h @@ -28,8 +28,8 @@ mdocml: mdocml.o libmdoc.a clean: rm -f $(CLEAN) -llib-llibmdoc.ln: macro.ln mdoc.ln hash.ln - $(LINT) $(LINTFLAGS) -Clibmdoc mdoc.ln macro.ln hash.ln +llib-llibmdoc.ln: macro.ln mdoc.ln hash.ln strings.ln + $(LINT) $(LINTFLAGS) -Clibmdoc mdoc.ln macro.ln hash.ln strings.ln llib-lmdocml.ln: mdocml.ln llib-llibmdoc.ln $(LINT) $(LINTFLAGS) -Cmdocml mdocml.ln llib-llibmdoc.ln @@ -38,6 +38,10 @@ macro.ln: macro.c private.h macro.o: macro.c private.h +strings.ln: strings.c private.h + +strings.o: strings.c private.h + hash.ln: hash.c private.h hash.o: hash.c private.h @@ -52,6 +56,6 @@ mdocml.o: mdocml.c mdoc.h private.h: mdoc.h -libmdoc.a: macro.o mdoc.o hash.o - $(AR) rs $@ macro.o mdoc.o hash.o +libmdoc.a: macro.o mdoc.o hash.o strings.o + $(AR) rs $@ macro.o mdoc.o hash.o strings.o @@ -29,54 +29,11 @@ static int append_text(struct mdoc *, int, int, int, char *[]); static int append_scoped(struct mdoc *, int, int, int, char *[]); -static int isdelim(const char *); static int args_next(struct mdoc *, int, int *, char *, char **); static int -isdelim(const char *p) -{ - - if (0 == *p) - return(0); - if (0 != *(p + 1)) - return(0); - - switch (*p) { - case('{'): - /* FALLTHROUGH */ - case('.'): - /* FALLTHROUGH */ - case(','): - /* FALLTHROUGH */ - case(';'): - /* FALLTHROUGH */ - case(':'): - /* FALLTHROUGH */ - case('?'): - /* FALLTHROUGH */ - case('!'): - /* FALLTHROUGH */ - case('('): - /* FALLTHROUGH */ - case(')'): - /* FALLTHROUGH */ - case('['): - /* FALLTHROUGH */ - case(']'): - /* FALLTHROUGH */ - case('}'): - return(1); - default: - break; - } - - return(0); -} - - -static int args_next(struct mdoc *mdoc, int tok, int *pos, char *buf, char **v) { @@ -125,6 +82,18 @@ append_scoped(struct mdoc *mdoc, int tok, int pos, int sz, char *args[]) { + switch (tok) { + /* ======= ADD MORE MACRO CHECKS BELOW. ======= */ + case (MDOC_Sh): + break; + case (MDOC_Ss): + break; + /* ======= ADD MORE MACRO CHECKS ABOVE. ======= */ + default: + abort(); + /* NOTREACHED */ + } + assert(sz >= 0); args[sz] = NULL; mdoc_block_alloc(mdoc, pos, tok, 0, NULL); @@ -143,8 +112,7 @@ append_text(struct mdoc *mdoc, int tok, args[sz] = NULL; switch (tok) { - /* ======= ADD MORE MACRO ARGUMENT-LIMITS BELOW. ======= */ - + /* ======= ADD MORE MACRO CHECKS BELOW. ======= */ case (MDOC_Ft): /* FALLTHROUGH */ case (MDOC_Li): @@ -154,21 +122,17 @@ append_text(struct mdoc *mdoc, int tok, case (MDOC_Pa): /* FALLTHROUGH */ case (MDOC_Tn): - if (0 == sz && ! mdoc_warn(mdoc, tok, pos, WARN_ARGS_GE1)) + if (0 < sz) + break; + if ( ! mdoc_warn(mdoc, tok, pos, WARN_ARGS_GE1)) return(0); - mdoc_elem_alloc(mdoc, pos, tok, 0, - NULL, (size_t)sz, _CC(args)); - return(1); - + break; case (MDOC_Ar): /* FALLTHROUGH */ case (MDOC_Cm): /* FALLTHROUGH */ case (MDOC_Fl): - mdoc_elem_alloc(mdoc, pos, tok, 0, - NULL, (size_t)sz, _CC(args)); - return(1); - + break; case (MDOC_Ad): /* FALLTHROUGH */ case (MDOC_Em): @@ -186,19 +150,18 @@ append_text(struct mdoc *mdoc, int tok, case (MDOC_Va): /* FALLTHROUGH */ case (MDOC_Vt): - if (0 == sz) - return(mdoc_err(mdoc, tok, pos, ERR_ARGS_GE1)); - mdoc_elem_alloc(mdoc, pos, tok, 0, - NULL, (size_t)sz, _CC(args)); - return(1); - - /* ======= ADD MORE MACRO ARGUMENT-LIMITS ABOVE. ======= */ + if (0 < sz) + break; + return(mdoc_err(mdoc, tok, pos, ERR_ARGS_GE1)); + /* ======= ADD MORE MACRO CHECKS ABOVE. ======= */ default: - break; + abort(); + /* NOTREACHED */ } - abort(); - /* NOTREACHED */ + mdoc_elem_alloc(mdoc, pos, tok, 0, + NULL, (size_t)sz, _CC(args)); + return(1); } @@ -235,7 +198,7 @@ again: /* Word found. */ - if ( ! isdelim(args[j])) { + if ( ! mdoc_isdelim(args[j])) { j++; goto again; } @@ -220,6 +220,97 @@ enum mdoc_type { MDOC_BLOCK }; +enum mdoc_msec { + MSEC_1, + MSEC_2, + MSEC_3, + MSEC_3f, + MSEC_3p, + MSEC_4, + MSEC_5, + MSEC_6, + MSEC_7, + MSEC_8, + MSEC_9, + MSEC_X11, + MSEC_X11R6, + MSEC_local, + MSEC_n, + MSEC_unass, + MSEC_draft, + MSEC_paper, + MSEC_NONE +}; + +enum mdoc_sec { + SEC_PROLOGUE, + SEC_NAME, + SEC_SYNOPSIS, + SEC_DESCRIPTION, + SEC_RETURN_VALUES, + SEC_ENVIRONMENT, + SEC_FILES, + SEC_EXAMPLES, + SEC_DIAGNOSTICS, + SEC_ERRORS, + SEC_SEE_ALSO, + SEC_STANDARDS, + SEC_HISTORY, + SEC_AUTHORS, + SEC_CAVEATS, + SEC_BUGS, + SEC_CUSTOM +}; + +enum mdoc_vol { + VOL_AMD, + VOL_IND, + VOL_KM, + VOL_LOCAL, + VOL_PRM, + VOL_PS1, + VOL_SMM, + VOL_URM, + VOL_USD, + VOL_DEFAULT +}; + +enum mdoc_arch { + ARCH_alpha, + ARCH_amd64, + ARCH_amiga, + ARCH_arc, + ARCH_armish, + ARCH_aviion, + ARCH_hp300, + ARCH_hppa, + ARCH_hppa64, + ARCH_i386, + ARCH_landisk, + ARCH_luna88k, + ARCH_mac68k, + ARCH_macppc, + ARCH_mvme68k, + ARCH_mvme88k, + ARCH_mvmeppc, + ARCH_pmax, + ARCH_sgi, + ARCH_socppc, + ARCH_sparc, + ARCH_sparc64, + ARCH_sun3, + ARCH_vax, + ARCH_zaurus, + ARCH_DEFAULT +}; + +struct mdoc_meta { + enum mdoc_msec msec; + enum mdoc_vol vol; + enum mdoc_arch arch; + struct tm tm; +}; + struct mdoc_text { char *string; }; @@ -280,7 +371,6 @@ struct mdoc; void mdoc_free(struct mdoc *); struct mdoc *mdoc_alloc(void *data, const struct mdoc_cb *); int mdoc_parseln(struct mdoc *, char *buf); - const struct mdoc_node *mdoc_result(struct mdoc *); @@ -27,6 +27,9 @@ struct mdoc { void *htab; struct mdoc_node *last; struct mdoc_node *first; + + enum mdoc_sec sec_lastn; + enum mdoc_sec sec_last; }; struct mdoc_macro { @@ -43,10 +46,8 @@ __BEGIN_DECLS int mdoc_err(struct mdoc *, int, int, enum mdoc_err); int mdoc_warn(struct mdoc *, int, int, enum mdoc_warn); void mdoc_msg(struct mdoc *, int, const char *, ...); - int mdoc_macro(struct mdoc *, int, int, int *, char *); int mdoc_find(const struct mdoc *, const char *); - void mdoc_word_alloc(struct mdoc *, int, const char *); void mdoc_elem_alloc(struct mdoc *, int, int, size_t, const struct mdoc_arg *, @@ -56,15 +57,13 @@ void mdoc_block_alloc(struct mdoc *, int, int, void mdoc_head_alloc(struct mdoc *, int, int, size_t, const char **); void mdoc_body_alloc(struct mdoc *, int, int); - void mdoc_node_free(struct mdoc_node *); - void mdoc_sibling(struct mdoc *, int, struct mdoc_node **, struct mdoc_node **, struct mdoc_node *); - void *mdoc_hash_alloc(void); int mdoc_hash_find(const void *, const char *); void mdoc_hash_free(void *); +int mdoc_isdelim(const char *); __END_DECLS diff --git a/strings.c b/strings.c new file mode 100644 index 00000000..786ae88b --- /dev/null +++ b/strings.c @@ -0,0 +1,66 @@ +/* $Id$ */ +/* + * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se> + * + * 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. + * + * 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. + */ +#include <assert.h> +#include <ctype.h> +#include <stdlib.h> +#include <stdio.h> + +#include "private.h" + +int +mdoc_isdelim(const char *p) +{ + + if (0 == *p) + return(0); + if (0 != *(p + 1)) + return(0); + + switch (*p) { + case('{'): + /* FALLTHROUGH */ + case('.'): + /* FALLTHROUGH */ + case(','): + /* FALLTHROUGH */ + case(';'): + /* FALLTHROUGH */ + case(':'): + /* FALLTHROUGH */ + case('?'): + /* FALLTHROUGH */ + case('!'): + /* FALLTHROUGH */ + case('('): + /* FALLTHROUGH */ + case(')'): + /* FALLTHROUGH */ + case('['): + /* FALLTHROUGH */ + case(']'): + /* FALLTHROUGH */ + case('}'): + return(1); + default: + break; + } + + return(0); +} + |