summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile10
-rw-r--r--arch.c3
-rw-r--r--att.c3
-rw-r--r--chars.c1
-rw-r--r--eqn.c1
-rw-r--r--html.c1
-rw-r--r--lib.c3
-rw-r--r--main.c1
-rw-r--r--man.c1
-rw-r--r--man_hash.c1
-rw-r--r--man_validate.c1
-rw-r--r--mandoc.380
-rw-r--r--mandoc.c69
-rw-r--r--mandoc.h7
-rw-r--r--mandocdb.c1
-rw-r--r--manpath.c2
-rw-r--r--mansearch.c1
-rw-r--r--mdoc.c1
-rw-r--r--mdoc_argv.c1
-rw-r--r--mdoc_hash.c1
-rw-r--r--mdoc_man.c5
-rw-r--r--mdoc_validate.c1
-rw-r--r--msec.c1
-rw-r--r--out.c1
-rw-r--r--read.c1
-rw-r--r--roff.c1
-rw-r--r--st.c3
-rw-r--r--tbl.c1
-rw-r--r--tbl_data.c1
-rw-r--r--tbl_layout.c2
-rw-r--r--term.c2
-rw-r--r--term_ascii.c2
-rw-r--r--term_ps.c1
-rw-r--r--vol.c3
34 files changed, 88 insertions, 126 deletions
diff --git a/Makefile b/Makefile
index e29946e6..6338839b 100644
--- a/Makefile
+++ b/Makefile
@@ -124,6 +124,8 @@ SRCS = Makefile \
mandoc.3 \
mandoc.c \
mandoc.h \
+ mandoc_aux.c \
+ mandoc_aux.h \
mandoc_char.7 \
mandocdb.8 \
mandocdb.c \
@@ -201,6 +203,7 @@ LIBMANDOC_OBJS = $(LIBMAN_OBJS) \
$(LIBROFF_OBJS) \
chars.o \
mandoc.o \
+ mandoc_aux.o \
msec.o \
read.o
@@ -225,7 +228,7 @@ vol.o: vol.in
$(LIBMAN_OBJS): libman.h
$(LIBMDOC_OBJS): libmdoc.h
$(LIBROFF_OBJS): libroff.h
-$(LIBMANDOC_OBJS): mandoc.h mdoc.h man.h libmandoc.h config.h
+$(LIBMANDOC_OBJS): mandoc.h mandoc_aux.h mdoc.h man.h libmandoc.h config.h
$(COMPAT_OBJS): config.h compat_ohash.h
MANDOC_HTML_OBJS = eqn_html.o \
@@ -252,10 +255,11 @@ MANDOC_OBJS = $(MANDOC_HTML_OBJS) \
main.o \
out.o \
tree.o
-$(MANDOC_OBJS): main.h mandoc.h mdoc.h man.h config.h out.h
+$(MANDOC_OBJS): main.h mandoc.h mandoc_aux.h mdoc.h man.h config.h out.h
MANDOCDB_OBJS = mandocdb.o mansearch_const.o manpath.o
-$(MANDOCDB_OBJS): mansearch.h mandoc.h mdoc.h man.h config.h manpath.h
+$(MANDOCDB_OBJS): mansearch.h mandoc.h mandoc_aux.h \
+ mdoc.h man.h config.h manpath.h
PRECONV_OBJS = preconv.o
$(PRECONV_OBJS): config.h
diff --git a/arch.c b/arch.c
index 6e6d5dac..37590774 100644
--- a/arch.c
+++ b/arch.c
@@ -18,12 +18,9 @@
#include "config.h"
#endif
-#include <stdlib.h>
#include <string.h>
-#include <time.h>
#include "mdoc.h"
-#include "mandoc.h"
#include "libmdoc.h"
#define LINE(x, y) \
diff --git a/att.c b/att.c
index 6e5c9de5..05320d74 100644
--- a/att.c
+++ b/att.c
@@ -18,12 +18,9 @@
#include "config.h"
#endif
-#include <stdlib.h>
#include <string.h>
-#include <time.h>
#include "mdoc.h"
-#include "mandoc.h"
#include "libmdoc.h"
#define LINE(x, y) \
diff --git a/chars.c b/chars.c
index 6370b219..9ca0d571 100644
--- a/chars.c
+++ b/chars.c
@@ -25,6 +25,7 @@
#include <string.h>
#include "mandoc.h"
+#include "mandoc_aux.h"
#include "libmandoc.h"
#define PRINT_HI 126
diff --git a/eqn.c b/eqn.c
index 2ff91b7a..045ec460 100644
--- a/eqn.c
+++ b/eqn.c
@@ -26,6 +26,7 @@
#include <time.h>
#include "mandoc.h"
+#include "mandoc_aux.h"
#include "libmandoc.h"
#include "libroff.h"
diff --git a/html.c b/html.c
index 17976fd4..0d24e197 100644
--- a/html.c
+++ b/html.c
@@ -31,6 +31,7 @@
#include <unistd.h>
#include "mandoc.h"
+#include "mandoc_aux.h"
#include "libmandoc.h"
#include "out.h"
#include "html.h"
diff --git a/lib.c b/lib.c
index 9bafccbf..5fdf7e8c 100644
--- a/lib.c
+++ b/lib.c
@@ -18,12 +18,9 @@
#include "config.h"
#endif
-#include <stdlib.h>
#include <string.h>
-#include <time.h>
#include "mdoc.h"
-#include "mandoc.h"
#include "libmdoc.h"
#define LINE(x, y) \
diff --git a/main.c b/main.c
index 738f0972..ff76f340 100644
--- a/main.c
+++ b/main.c
@@ -28,6 +28,7 @@
#include <unistd.h>
#include "mandoc.h"
+#include "mandoc_aux.h"
#include "main.h"
#include "mdoc.h"
#include "man.h"
diff --git a/man.c b/man.c
index 2de652e9..b456829b 100644
--- a/man.c
+++ b/man.c
@@ -30,6 +30,7 @@
#include "man.h"
#include "mandoc.h"
+#include "mandoc_aux.h"
#include "libman.h"
#include "libmandoc.h"
diff --git a/man_hash.c b/man_hash.c
index 95e7c790..0f8dd3e4 100644
--- a/man_hash.c
+++ b/man_hash.c
@@ -23,7 +23,6 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <stdlib.h>
#include <string.h>
#include "man.h"
diff --git a/man_validate.c b/man_validate.c
index 8ab5c2c5..43f0b691 100644
--- a/man_validate.c
+++ b/man_validate.c
@@ -32,6 +32,7 @@
#include "man.h"
#include "mandoc.h"
+#include "mandoc_aux.h"
#include "libman.h"
#include "libmandoc.h"
diff --git a/mandoc.3 b/mandoc.3
index 6cb5bbb3..f110a805 100644
--- a/mandoc.3
+++ b/mandoc.3
@@ -20,7 +20,12 @@
.Os
.Sh NAME
.Nm mandoc ,
+.Nm mandoc_calloc ,
.Nm mandoc_escape ,
+.Nm mandoc_malloc ,
+.Nm mandoc_realloc ,
+.Nm mandoc_strdup ,
+.Nm mandoc_strndup ,
.Nm man_meta ,
.Nm man_mparse ,
.Nm man_node ,
@@ -45,28 +50,30 @@
.Sh LIBRARY
.Lb libmandoc
.Sh SYNOPSIS
-.In man.h
-.In mdoc.h
.In mandoc.h
+.Fd "#define ASCII_NBRSP"
+.Fd "#define ASCII_HYPH"
+.Fd "#define ASCII_BREAK"
+.Ft "void *"
+.Fo mandoc_calloc
+.Fa "size_t nmemb"
+.Fa "size_t size"
+.Fc
.Ft "enum mandoc_esc"
.Fo mandoc_escape
.Fa "const char **end"
.Fa "const char **start"
.Fa "int *sz"
.Fc
-.Ft "const struct man_meta *"
-.Fo man_meta
-.Fa "const struct man *man"
-.Fc
-.Ft "const struct mparse *"
-.Fo man_mparse
-.Fa "const struct man *man"
-.Fc
-.Ft "const struct man_node *"
-.Fo man_node
-.Fa "const struct man *man"
-.Fc
+.Ft "void *"
+.Fn mandoc_malloc "size_t size"
.Ft "struct mchars *"
+.Fo mandoc_realloc
+.Fa "void *ptr"
+.Fa "size_t size"
+.Fc
+.Ft "char *"
+.Fn mandoc_strdup
.Fn mchars_alloc "void"
.Ft void
.Fn mchars_free "struct mchars *p"
@@ -87,14 +94,6 @@
.Fa "const char *cp"
.Fa "size_t sz"
.Fc
-.Ft "const struct mdoc_meta *"
-.Fo mdoc_meta
-.Fa "const struct mdoc *mdoc"
-.Fc
-.Ft "const struct mdoc_node *"
-.Fo mdoc_node
-.Fa "const struct mdoc *mdoc"
-.Fc
.Ft void
.Fo mparse_alloc
.Fa "enum mparset inttype"
@@ -104,6 +103,15 @@
.Fa "int quick"
.Fc
.Ft void
+.Fo (*mandocmsg)
+.Fa "enum mandocerr errtype"
+.Fa "enum mandoclevel level"
+.Fa "const char *file"
+.Fa "int line"
+.Fa "int col"
+.Fa "const char *msg"
+.Fc
+.Ft void
.Fo mparse_free
.Fa "struct mparse *parse"
.Fc
@@ -139,11 +147,33 @@
.Fo mparse_strlevel
.Fa "enum mandoclevel"
.Fc
-.Vt extern const char * const * man_macronames;
+.In mandoc.h
+.In mdoc.h
+.Ft "const struct mdoc_meta *"
+.Fo mdoc_meta
+.Fa "const struct mdoc *mdoc"
+.Fc
+.Ft "const struct mdoc_node *"
+.Fo mdoc_node
+.Fa "const struct mdoc *mdoc"
+.Fc
.Vt extern const char * const * mdoc_argnames;
.Vt extern const char * const * mdoc_macronames;
-.Fd "#define ASCII_NBRSP"
-.Fd "#define ASCII_HYPH"
+.In mandoc.h
+.In man.h
+.Ft "const struct man_meta *"
+.Fo man_meta
+.Fa "const struct man *man"
+.Fc
+.Ft "const struct mparse *"
+.Fo man_mparse
+.Fa "const struct man *man"
+.Fc
+.Ft "const struct man_node *"
+.Fo man_node
+.Fa "const struct man *man"
+.Fc
+.Vt extern const char * const * man_macronames;
.Sh DESCRIPTION
The
.Nm mandoc
diff --git a/mandoc.c b/mandoc.c
index 5f002bf5..c709f23b 100644
--- a/mandoc.c
+++ b/mandoc.c
@@ -31,6 +31,7 @@
#include <time.h>
#include "mandoc.h"
+#include "mandoc_aux.h"
#include "libmandoc.h"
#define DATESIZE 32
@@ -353,74 +354,6 @@ mandoc_escape(const char **end, const char **start, int *sz)
return(gly);
}
-void *
-mandoc_calloc(size_t num, size_t size)
-{
- void *ptr;
-
- ptr = calloc(num, size);
- if (NULL == ptr) {
- perror(NULL);
- exit((int)MANDOCLEVEL_SYSERR);
- }
-
- return(ptr);
-}
-
-
-void *
-mandoc_malloc(size_t size)
-{
- void *ptr;
-
- ptr = malloc(size);
- if (NULL == ptr) {
- perror(NULL);
- exit((int)MANDOCLEVEL_SYSERR);
- }
-
- return(ptr);
-}
-
-
-void *
-mandoc_realloc(void *ptr, size_t size)
-{
-
- ptr = realloc(ptr, size);
- if (NULL == ptr) {
- perror(NULL);
- exit((int)MANDOCLEVEL_SYSERR);
- }
-
- return(ptr);
-}
-
-char *
-mandoc_strndup(const char *ptr, size_t sz)
-{
- char *p;
-
- p = mandoc_malloc(sz + 1);
- memcpy(p, ptr, sz);
- p[(int)sz] = '\0';
- return(p);
-}
-
-char *
-mandoc_strdup(const char *ptr)
-{
- char *p;
-
- p = strdup(ptr);
- if (NULL == p) {
- perror(NULL);
- exit((int)MANDOCLEVEL_SYSERR);
- }
-
- return(p);
-}
-
/*
* Parse a quoted or unquoted roff-style request or macro argument.
* Return a pointer to the parsed argument, which is either the original
diff --git a/mandoc.h b/mandoc.h
index 02070c5c..b5df7f95 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -1,7 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -405,12 +405,7 @@ struct man;
__BEGIN_DECLS
-void *mandoc_calloc(size_t, size_t);
enum mandoc_esc mandoc_escape(const char **, const char **, int *);
-void *mandoc_malloc(size_t);
-void *mandoc_realloc(void *, size_t);
-char *mandoc_strdup(const char *);
-char *mandoc_strndup(const char *, size_t);
struct mchars *mchars_alloc(void);
void mchars_free(struct mchars *);
char mchars_num2char(const char *, size_t);
diff --git a/mandocdb.c b/mandocdb.c
index 2c75eb64..4a8af53d 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -46,6 +46,7 @@
#include "mdoc.h"
#include "man.h"
#include "mandoc.h"
+#include "mandoc_aux.h"
#include "manpath.h"
#include "mansearch.h"
diff --git a/manpath.c b/manpath.c
index 9496d8f9..5138c045 100644
--- a/manpath.c
+++ b/manpath.c
@@ -26,7 +26,7 @@
#include <stdlib.h>
#include <string.h>
-#include "mandoc.h"
+#include "mandoc_aux.h"
#include "manpath.h"
#define MAN_CONF_FILE "/etc/man.conf"
diff --git a/mansearch.c b/mansearch.c
index 562ca636..9caf434e 100644
--- a/mansearch.c
+++ b/mansearch.c
@@ -39,6 +39,7 @@
#include <sqlite3.h>
#include "mandoc.h"
+#include "mandoc_aux.h"
#include "manpath.h"
#include "mansearch.h"
diff --git a/mdoc.c b/mdoc.c
index 6ae1631c..2f1a14d0 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -30,6 +30,7 @@
#include "mdoc.h"
#include "mandoc.h"
+#include "mandoc_aux.h"
#include "libmdoc.h"
#include "libmandoc.h"
diff --git a/mdoc_argv.c b/mdoc_argv.c
index d0da16d3..a7e609b1 100644
--- a/mdoc_argv.c
+++ b/mdoc_argv.c
@@ -28,6 +28,7 @@
#include "mdoc.h"
#include "mandoc.h"
+#include "mandoc_aux.h"
#include "libmdoc.h"
#include "libmandoc.h"
diff --git a/mdoc_hash.c b/mdoc_hash.c
index 9aad261a..da9a9836 100644
--- a/mdoc_hash.c
+++ b/mdoc_hash.c
@@ -28,7 +28,6 @@
#include <string.h>
#include "mdoc.h"
-#include "mandoc.h"
#include "libmdoc.h"
static unsigned char table[27 * 12];
diff --git a/mdoc_man.c b/mdoc_man.c
index d1d203e8..a6a9fa05 100644
--- a/mdoc_man.c
+++ b/mdoc_man.c
@@ -23,6 +23,7 @@
#include <string.h>
#include "mandoc.h"
+#include "mandoc_aux.h"
#include "out.h"
#include "man.h"
#include "mdoc.h"
@@ -461,7 +462,7 @@ print_offs(const char *v)
/*
* Set up the indentation for a list item; used from pre_it().
*/
-void
+static void
print_width(const char *v, const struct mdoc_node *child, size_t defsz)
{
char buf[24];
@@ -513,7 +514,7 @@ print_width(const char *v, const struct mdoc_node *child, size_t defsz)
TPremain = remain;
}
-void
+static void
print_count(int *count)
{
char buf[12];
diff --git a/mdoc_validate.c b/mdoc_validate.c
index fd0db4b6..972c5ab8 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -36,6 +36,7 @@
#include "mdoc.h"
#include "mandoc.h"
+#include "mandoc_aux.h"
#include "libmdoc.h"
#include "libmandoc.h"
diff --git a/msec.c b/msec.c
index 14b52c00..a51737be 100644
--- a/msec.c
+++ b/msec.c
@@ -18,7 +18,6 @@
#include "config.h"
#endif
-#include <stdlib.h>
#include <string.h>
#include "mandoc.h"
diff --git a/out.c b/out.c
index 866e05b3..672e8727 100644
--- a/out.c
+++ b/out.c
@@ -28,6 +28,7 @@
#include <string.h>
#include <time.h>
+#include "mandoc_aux.h"
#include "mandoc.h"
#include "out.h"
diff --git a/read.c b/read.c
index f325b148..98c245a0 100644
--- a/read.c
+++ b/read.c
@@ -37,6 +37,7 @@
#include <unistd.h>
#include "mandoc.h"
+#include "mandoc_aux.h"
#include "libmandoc.h"
#include "mdoc.h"
#include "man.h"
diff --git a/roff.c b/roff.c
index b6ad9d20..ee025cbb 100644
--- a/roff.c
+++ b/roff.c
@@ -26,6 +26,7 @@
#include <string.h>
#include "mandoc.h"
+#include "mandoc_aux.h"
#include "libroff.h"
#include "libmandoc.h"
diff --git a/st.c b/st.c
index 04631627..4a1bd1ac 100644
--- a/st.c
+++ b/st.c
@@ -18,12 +18,9 @@
#include "config.h"
#endif
-#include <stdlib.h>
#include <string.h>
-#include <time.h>
#include "mdoc.h"
-#include "mandoc.h"
#include "libmdoc.h"
#define LINE(x, y) \
diff --git a/tbl.c b/tbl.c
index 25f65738..74776dab 100644
--- a/tbl.c
+++ b/tbl.c
@@ -26,6 +26,7 @@
#include <time.h>
#include "mandoc.h"
+#include "mandoc_aux.h"
#include "libmandoc.h"
#include "libroff.h"
diff --git a/tbl_data.c b/tbl_data.c
index c2b31a58..f52a9a65 100644
--- a/tbl_data.c
+++ b/tbl_data.c
@@ -26,6 +26,7 @@
#include <time.h>
#include "mandoc.h"
+#include "mandoc_aux.h"
#include "libmandoc.h"
#include "libroff.h"
diff --git a/tbl_layout.c b/tbl_layout.c
index 618be8c6..835ea613 100644
--- a/tbl_layout.c
+++ b/tbl_layout.c
@@ -19,13 +19,13 @@
#include "config.h"
#endif
-#include <assert.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "mandoc.h"
+#include "mandoc_aux.h"
#include "libmandoc.h"
#include "libroff.h"
diff --git a/term.c b/term.c
index 97efc3ee..39dbf2e1 100644
--- a/term.c
+++ b/term.c
@@ -23,12 +23,12 @@
#include <assert.h>
#include <ctype.h>
-#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mandoc.h"
+#include "mandoc_aux.h"
#include "out.h"
#include "term.h"
#include "main.h"
diff --git a/term_ascii.c b/term_ascii.c
index b2e88b9c..3fccc675 100644
--- a/term_ascii.c
+++ b/term_ascii.c
@@ -20,7 +20,6 @@
#include <sys/types.h>
-#include <assert.h>
#ifdef USE_WCHAR
# include <locale.h>
#endif
@@ -33,6 +32,7 @@
#endif
#include "mandoc.h"
+#include "mandoc_aux.h"
#include "out.h"
#include "term.h"
#include "main.h"
diff --git a/term_ps.c b/term_ps.c
index 0a2e00b3..7ab58682 100644
--- a/term_ps.c
+++ b/term_ps.c
@@ -30,6 +30,7 @@
#include <unistd.h>
#include "mandoc.h"
+#include "mandoc_aux.h"
#include "out.h"
#include "main.h"
#include "term.h"
diff --git a/vol.c b/vol.c
index 5de4c8c6..b855df2e 100644
--- a/vol.c
+++ b/vol.c
@@ -18,12 +18,9 @@
#include "config.h"
#endif
-#include <stdlib.h>
#include <string.h>
-#include <time.h>
#include "mdoc.h"
-#include "mandoc.h"
#include "libmdoc.h"
#define LINE(x, y) \