summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2010-10-23 15:49:31 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2010-10-23 15:49:31 +0000
commitd7ce593667f61f889486dd1115b40c8fed241df2 (patch)
treec467561acf2fb17c5389cf4b55518111784637fc /usr.bin/mandoc
parent8e12f85560fc6cbe21ee1d99ef2a764d08702ed2 (diff)
sync comments to bsd.lv; no functional change
Diffstat (limited to 'usr.bin/mandoc')
-rw-r--r--usr.bin/mandoc/man.h66
-rw-r--r--usr.bin/mandoc/mandoc.h57
-rw-r--r--usr.bin/mandoc/mdoc.h150
3 files changed, 175 insertions, 98 deletions
diff --git a/usr.bin/mandoc/man.h b/usr.bin/mandoc/man.h
index a838c82f907..9bf9556f8c4 100644
--- a/usr.bin/mandoc/man.h
+++ b/usr.bin/mandoc/man.h
@@ -1,4 +1,4 @@
-/* $Id: man.h,v 1.27 2010/10/15 20:45:03 schwarze Exp $ */
+/* $Id: man.h,v 1.28 2010/10/23 15:49:30 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -17,8 +17,9 @@
#ifndef MAN_H
#define MAN_H
-#include <time.h>
-
+/*
+ * What follows is a list of ALL possible macros.
+ */
enum mant {
MAN_br = 0,
MAN_TH,
@@ -62,6 +63,9 @@ enum mant {
MAN_MAX
};
+/*
+ * Type of a syntax node.
+ */
enum man_type {
MAN_TEXT,
MAN_ELEM,
@@ -71,37 +75,49 @@ enum man_type {
MAN_BODY
};
+/*
+ * Information from prologue.
+ */
struct man_meta {
- char *msec;
- time_t date;
- char *rawdate;
- char *vol;
- char *title;
- char *source;
+ char *msec; /* `TH' section (1, 3p, etc.) */
+ time_t date; /* `TH' normalised date */
+ char *rawdate; /* raw `TH' date */
+ char *vol; /* `TH' volume */
+ char *title; /* `TH' title (e.g., FOO) */
+ char *source; /* `TH' source (e.g., GNU) */
};
+union man_data {
+ struct tbl *TS;
+};
+
+/*
+ * Single node in tree-linked AST.
+ */
struct man_node {
- struct man_node *parent;
- struct man_node *child;
- struct man_node *next;
- struct man_node *prev;
- int nchild;
+ struct man_node *parent; /* parent AST node */
+ struct man_node *child; /* first child AST node */
+ struct man_node *next; /* sibling AST node */
+ struct man_node *prev; /* prior sibling AST node */
+ int nchild; /* number children */
int line;
int pos;
- enum mant tok;
+ enum mant tok; /* tok or MAN__MAX if none */
int flags;
-#define MAN_VALID (1 << 0)
-#define MAN_ACTED (1 << 1)
-#define MAN_EOS (1 << 2)
- enum man_type type;
- char *string;
- struct man_node *head;
- struct man_node *body;
- union {
- struct tbl *TS;
- } data;
+#define MAN_VALID (1 << 0) /* has been validated */
+#define MAN_ACTED (1 << 1) /* has been acted upon */
+#define MAN_EOS (1 << 2) /* at sentence boundary */
+ enum man_type type; /* AST node type */
+ char *string; /* TEXT node argument */
+ struct man_node *head; /* BLOCK node HEAD ptr */
+ struct man_node *body; /* BLOCK node BODY ptr */
+ union man_data data;
};
+/*
+ * Names of macros. Index is enum mant. Indexing into this returns
+ * the normalised name, e.g., man_macronames[MAN_SH] -> "SH".
+ */
extern const char *const *man_macronames;
__BEGIN_DECLS
diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h
index db0bc1beedd..996cd1e03c9 100644
--- a/usr.bin/mandoc/mandoc.h
+++ b/usr.bin/mandoc/mandoc.h
@@ -1,4 +1,4 @@
-/* $Id: mandoc.h,v 1.15 2010/10/16 20:49:37 schwarze Exp $ */
+/* $Id: mandoc.h,v 1.16 2010/10/23 15:49:30 schwarze Exp $ */
/*
* Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -17,31 +17,34 @@
#ifndef MANDOC_H
#define MANDOC_H
-/*
- * This contains declarations that are available system-wide.
- */
-
#define ASCII_NBRSP 31 /* non-breaking space */
#define ASCII_HYPH 30 /* breakable hyphen */
-__BEGIN_DECLS
-
+/*
+ * Status level. This refers to both internal status (i.e., whilst
+ * running, when warnings/errors are reported) and an indicator of a
+ * threshold of when to halt (when said internal state exceeds the
+ * threshold).
+ */
enum mandoclevel {
MANDOCLEVEL_OK = 0,
MANDOCLEVEL_RESERVED,
- MANDOCLEVEL_WARNING,
- MANDOCLEVEL_ERROR,
- MANDOCLEVEL_FATAL,
- MANDOCLEVEL_BADARG,
- MANDOCLEVEL_SYSERR,
+ MANDOCLEVEL_WARNING, /* warnings: syntax, whitespace, etc. */
+ MANDOCLEVEL_ERROR, /* input has been thrown away */
+ MANDOCLEVEL_FATAL, /* input is borked */
+ MANDOCLEVEL_BADARG, /* bad argument in invocation */
+ MANDOCLEVEL_SYSERR, /* system error */
MANDOCLEVEL_MAX
};
+/*
+ * All possible things that can go wrong within a parse, be it libroff,
+ * libmdoc, or libman.
+ */
enum mandocerr {
MANDOCERR_OK,
- MANDOCERR_WARNING, /* ===== end of warnings ===== */
-
+ MANDOCERR_WARNING, /* ===== start of warnings ===== */
MANDOCERR_UPPERCASE, /* text should be uppercase */
MANDOCERR_SECOOO, /* sections out of conventional order */
MANDOCERR_SECREP, /* section name repeats */
@@ -64,8 +67,7 @@ enum mandocerr {
MANDOCERR_EOLNSPACE, /* end of line whitespace */
MANDOCERR_SCOPENEST, /* blocks badly nested */
- MANDOCERR_ERROR, /* ===== end of errors ===== */
-
+ MANDOCERR_ERROR, /* ===== start of errors ===== */
MANDOCERR_NAMESECFIRST, /* NAME section must come first */
MANDOCERR_BADBOOL, /* bad Boolean value */
MANDOCERR_CHILD, /* child violates parent syntax */
@@ -102,8 +104,7 @@ enum mandocerr {
MANDOCERR_IGNPAR, /* paragraph macro ignored */
MANDOCERR_TBL, /* tbl(1) error */
- MANDOCERR_FATAL, /* ===== end of fatal errors ===== */
-
+ MANDOCERR_FATAL, /* ===== start of fatal errors ===== */
MANDOCERR_COLUMNS, /* column syntax is inconsistent */
/* FIXME: this should be a MANDOCERR_ERROR */
MANDOCERR_NESTEDDISP, /* displays may not be nested */
@@ -118,16 +119,26 @@ enum mandocerr {
MANDOCERR_NODOCPROLOG, /* no document prologue */
MANDOCERR_UTSNAME, /* utsname system call failed */
MANDOCERR_MEM, /* static buffer exhausted */
-
MANDOCERR_MAX
};
+/*
+ * Available registers (set in libroff, accessed elsewhere).
+ */
enum regs {
- REG_nS = 0, /* register: nS */
+ REG_nS = 0,
REG__MAX
};
/*
+ * A register (struct reg) can consist of many types: this consists of
+ * normalised types from the original string form.
+ */
+union regval {
+ unsigned u; /* unsigned integer */
+};
+
+/*
* A single register entity. If "set" is zero, the value of the
* register should be the default one, which is per-register. It's
* assumed that callers know which type in "v" corresponds to which
@@ -135,9 +146,7 @@ enum regs {
*/
struct reg {
int set; /* whether set or not */
- union {
- unsigned u; /* unsigned integer */
- } v;
+ union regval v; /* parsed data */
};
/*
@@ -149,6 +158,8 @@ struct regset {
struct reg regs[REG__MAX];
};
+__BEGIN_DECLS
+
/*
* Callback function for warnings, errors, and fatal errors as they
* occur in the compilers libroff, libmdoc, and libman.
diff --git a/usr.bin/mandoc/mdoc.h b/usr.bin/mandoc/mdoc.h
index 99727fdbe50..7cbf86df49f 100644
--- a/usr.bin/mandoc/mdoc.h
+++ b/usr.bin/mandoc/mdoc.h
@@ -1,4 +1,4 @@
-/* $Id: mdoc.h,v 1.34 2010/10/16 13:38:29 schwarze Exp $ */
+/* $Id: mdoc.h,v 1.35 2010/10/23 15:49:30 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -17,16 +17,9 @@
#ifndef MDOC_H
#define MDOC_H
-/*
- * This library implements a validating scanner/parser for ``mdoc'' roff
- * macro documents, a.k.a. BSD manual page documents. The mdoc.c file
- * drives the parser, while macro.c describes the macro ontologies.
- * validate.c pre- and post-validates parsed macros, and action.c
- * performs actions on parsed and validated macros.
+/*
+ * What follows is a list of ALL possible macros.
*/
-
-/* What follows is a list of ALL possible macros. */
-
enum mdoct {
MDOC_Ap = 0,
MDOC_Dd,
@@ -155,8 +148,9 @@ enum mdoct {
MDOC_MAX
};
-/* What follows is a list of ALL possible macro arguments. */
-
+/*
+ * What follows is a list of ALL possible macro arguments.
+ */
enum mdocargt {
MDOC_Split,
MDOC_Nosplit,
@@ -188,7 +182,9 @@ enum mdocargt {
MDOC_ARG_MAX
};
-/* Type of a syntax node. */
+/*
+ * Type of a syntax node.
+ */
enum mdoc_type {
MDOC_TEXT,
MDOC_ELEM,
@@ -199,9 +195,12 @@ enum mdoc_type {
MDOC_ROOT
};
-/* Section (named/unnamed) of `Sh'. */
+/*
+ * Section (named/unnamed) of `Sh'. Note that these appear in the
+ * conventional order imposed by mdoc.7.
+ */
enum mdoc_sec {
- SEC_NONE, /* No section, yet. */
+ SEC_NONE = 0, /* No section, yet. */
SEC_NAME,
SEC_LIBRARY,
SEC_SYNOPSIS,
@@ -222,42 +221,58 @@ enum mdoc_sec {
SEC_CAVEATS,
SEC_BUGS,
SEC_SECURITY,
- SEC_CUSTOM, /* User-defined. */
+ SEC_CUSTOM, /* User-defined. */
SEC__MAX
};
-/* Information from prologue. */
+/*
+ * Information from prologue.
+ */
struct mdoc_meta {
- char *msec;
- char *vol;
- char *arch;
- time_t date;
- char *title;
- char *os;
- char *name;
+ char *msec; /* `Dt' section (1, 3p, etc.) */
+ char *vol; /* `Dt' volume (implied) */
+ char *arch; /* `Dt' arch (i386, etc.) */
+ time_t date; /* `Dd' normalised date */
+ char *title; /* `Dt' title (FOO, etc.) */
+ char *os; /* `Os' system (OpenBSD, etc.) */
+ char *name; /* leading `Nm' name */
};
-/* An argument to a macro (multiple values = `It -column'). */
+/*
+ * An argument to a macro (multiple values = `-column xxx yyy').
+ */
struct mdoc_argv {
- enum mdocargt arg;
+ enum mdocargt arg; /* type of argument */
int line;
int pos;
- size_t sz;
- char **value;
+ size_t sz; /* elements in "value" */
+ char **value; /* argument strings */
};
+/*
+ * Reference-counted macro arguments. These are refcounted because
+ * blocks have multiple instances of the same arguments spread across
+ * the HEAD, BODY, TAIL, and BLOCK node types.
+ */
struct mdoc_arg {
size_t argc;
struct mdoc_argv *argv;
unsigned int refcnt;
};
+/*
+ * Indicates that a BODY's formatting has ended, but the scope is still
+ * open. Used for syntax-broken blocks.
+ */
enum mdoc_endbody {
ENDBODY_NOT = 0,
- ENDBODY_SPACE,
- ENDBODY_NOSPACE
+ ENDBODY_SPACE, /* is broken: append a space */
+ ENDBODY_NOSPACE /* is broken: don't append a space */
};
+/*
+ * Normalised `Bl' list type.
+ */
enum mdoc_list {
LIST__NONE = 0,
LIST_bullet,
@@ -273,6 +288,9 @@ enum mdoc_list {
LIST_tag
};
+/*
+ * Normalised `Bd' display type.
+ */
enum mdoc_disp {
DISP__NONE = 0,
DISP_centred,
@@ -282,12 +300,18 @@ enum mdoc_disp {
DISP_literal
};
+/*
+ * Normalised `An' splitting argument.
+ */
enum mdoc_auth {
AUTH__NONE = 0,
AUTH_split,
AUTH_nosplit
};
+/*
+ * Normalised `Bf' font type.
+ */
enum mdoc_font {
FONT__NONE = 0,
FONT_Em,
@@ -295,12 +319,18 @@ enum mdoc_font {
FONT_Sy
};
+/*
+ * Normalised arguments for `Bd'.
+ */
struct mdoc_bd {
const char *offs; /* -offset */
enum mdoc_disp type; /* -ragged, etc. */
int comp; /* -compact */
};
+/*
+ * Normalised arguments for `Bl'.
+ */
struct mdoc_bl {
const char *width; /* -width */
const char *offs; /* -offset */
@@ -310,15 +340,36 @@ struct mdoc_bl {
const char **cols; /* -column val ptr */
};
+/*
+ * Normalised arguments for `Bf'.
+ */
struct mdoc_bf {
enum mdoc_font font; /* font */
};
+/*
+ * Normalised arguments for `An'.
+ */
struct mdoc_an {
enum mdoc_auth auth; /* -split, etc. */
};
-/* Node in AST. */
+/*
+ * Consists of normalised node arguments. These should be used instead
+ * of iterating through the mdoc_arg pointers of a node: defaults are
+ * provided, etc.
+ */
+union mdoc_data {
+ struct mdoc_an An;
+ struct mdoc_bd *Bd;
+ struct mdoc_bf *Bf;
+ struct mdoc_bl *Bl;
+ struct tbl *TS;
+};
+
+/*
+ * Single node in tree-linked AST.
+ */
struct mdoc_node {
struct mdoc_node *parent; /* parent AST node */
struct mdoc_node *child; /* first child AST node */
@@ -338,34 +389,33 @@ struct mdoc_node {
enum mdoc_type type; /* AST node type */
enum mdoc_sec sec; /* current named section */
/* FIXME: these can be union'd to shave a few bytes. */
- struct mdoc_arg *args; /* BLOCK/ELEM */
- struct mdoc_node *pending; /* BLOCK */
- struct mdoc_node *head; /* BLOCK */
- struct mdoc_node *body; /* BLOCK */
- struct mdoc_node *tail; /* BLOCK */
- char *string; /* TEXT */
- enum mdoc_endbody end; /* BODY */
-
- union {
- struct mdoc_an An;
- struct mdoc_bd *Bd;
- struct mdoc_bf *Bf;
- struct mdoc_bl *Bl;
- struct tbl *TS;
- } data;
+ struct mdoc_arg *args; /* BLOCK/ELEM */
+ struct mdoc_node *pending; /* BLOCK */
+ struct mdoc_node *head; /* BLOCK */
+ struct mdoc_node *body; /* BLOCK */
+ struct mdoc_node *tail; /* BLOCK */
+ char *string; /* TEXT */
+ enum mdoc_endbody end; /* BODY */
+ union mdoc_data data;
};
-/* See mdoc.3 for documentation. */
-
+/*
+ * Names of macros. Index is enum mdoct. Indexing into this returns
+ * the normalised name, e.g., mdoc_macronames[MDOC_Sh] -> "Sh".
+ */
extern const char *const *mdoc_macronames;
+
+/*
+ * Names of macro args. Index is enum mdocargt. Indexing into this
+ * returns the normalised name, e.g., mdoc_argnames[MDOC_File] ->
+ * "file".
+ */
extern const char *const *mdoc_argnames;
__BEGIN_DECLS
struct mdoc;
-/* See mdoc.3 for documentation. */
-
void mdoc_free(struct mdoc *);
struct mdoc *mdoc_alloc(struct regset *, void *, mandocmsg);
void mdoc_reset(struct mdoc *);