version 1.37, 2009/03/06 14:13:47 |
version 1.59, 2009/06/16 19:45:51 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se> |
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the |
* purpose with or without fee is hereby granted, provided that the above |
* above copyright notice and this permission notice appear in all |
* copyright notice and this permission notice appear in all copies. |
* copies. |
|
* |
* |
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
* PERFORMANCE OF THIS SOFTWARE. |
|
*/ |
*/ |
#ifndef MDOC_H |
#ifndef MDOC_H |
#define MDOC_H |
#define MDOC_H |
|
|
|
#include <time.h> |
|
|
/* |
/* |
* This library implements a validating scanner/parser for ``mdoc'' roff |
* This library implements a validating scanner/parser for ``mdoc'' roff |
* macro documents, a.k.a. BSD manual page documents. The mdoc.c file |
* macro documents, a.k.a. BSD manual page documents. The mdoc.c file |
|
|
|
|
/* What follows is a list of ALL possible macros. */ |
/* What follows is a list of ALL possible macros. */ |
|
|
#define MDOC___ 0 |
#define MDOC_Ap 0 |
#define MDOC_Dd 1 |
#define MDOC_Dd 1 |
#define MDOC_Dt 2 |
#define MDOC_Dt 2 |
#define MDOC_Os 3 |
#define MDOC_Os 3 |
|
|
#define MDOC_Fr 104 |
#define MDOC_Fr 104 |
#define MDOC_Ud 105 |
#define MDOC_Ud 105 |
#define MDOC_Lb 106 |
#define MDOC_Lb 106 |
#define MDOC_MAX 107 |
#define MDOC_Lp 107 |
|
#define MDOC_Lk 108 |
|
#define MDOC_Mt 109 |
|
#define MDOC_Brq 110 |
|
#define MDOC_Bro 111 |
|
#define MDOC_Brc 112 |
|
#define MDOC__C 113 |
|
#define MDOC_Es 114 |
|
#define MDOC_En 115 |
|
#define MDOC_Dx 116 |
|
#define MDOC__Q 117 |
|
#define MDOC_MAX 118 |
|
|
/* What follows is a list of ALL possible macro arguments. */ |
/* What follows is a list of ALL possible macro arguments. */ |
|
|
|
|
#define MDOC_Words 22 |
#define MDOC_Words 22 |
#define MDOC_Emphasis 23 |
#define MDOC_Emphasis 23 |
#define MDOC_Symbolic 24 |
#define MDOC_Symbolic 24 |
#define MDOC_ARG_MAX 25 |
#define MDOC_Nested 25 |
|
#define MDOC_ARG_MAX 26 |
|
|
/* Warnings are either syntax or groff-compatibility. */ |
/* Warnings are either syntax or groff-compatibility. */ |
enum mdoc_warn { |
enum mdoc_warn { |
Line 173 enum mdoc_warn { |
|
Line 185 enum mdoc_warn { |
|
WARN_COMPAT |
WARN_COMPAT |
}; |
}; |
|
|
/* An argument to a macro (multiple values = `It -column'). */ |
|
struct mdoc_arg { |
|
int arg; |
|
int line; |
|
int pos; |
|
size_t sz; |
|
char **value; |
|
}; |
|
|
|
/* Type of a syntax node. */ |
/* Type of a syntax node. */ |
enum mdoc_type { |
enum mdoc_type { |
MDOC_TEXT, |
MDOC_TEXT, |
Line 229 struct mdoc_meta { |
|
Line 232 struct mdoc_meta { |
|
char *name; |
char *name; |
}; |
}; |
|
|
/* Text-only node. */ |
/* An argument to a macro (multiple values = `It -column'). */ |
struct mdoc_text { |
struct mdoc_argv { |
char *string; |
int arg; |
|
int line; |
|
int pos; |
|
size_t sz; |
|
char **value; |
}; |
}; |
|
|
/* Block (scoped) node. */ |
struct mdoc_arg { |
struct mdoc_block { |
|
size_t argc; |
size_t argc; |
struct mdoc_arg *argv; |
struct mdoc_argv *argv; |
struct mdoc_node *head; |
unsigned int refcnt; |
struct mdoc_node *body; |
|
struct mdoc_node *tail; |
|
}; |
}; |
|
|
/* In-line element node. */ |
|
struct mdoc_elem { |
|
size_t argc; |
|
struct mdoc_arg *argv; |
|
}; |
|
|
|
/* Typed nodes of an AST node. */ |
|
union mdoc_data { |
|
struct mdoc_text text; |
|
struct mdoc_elem elem; |
|
struct mdoc_block block; |
|
}; |
|
|
|
/* Node in AST. */ |
/* Node in AST. */ |
struct mdoc_node { |
struct mdoc_node { |
struct mdoc_node *parent; |
struct mdoc_node *parent; |
Line 269 struct mdoc_node { |
|
Line 260 struct mdoc_node { |
|
#define MDOC_VALID (1 << 0) |
#define MDOC_VALID (1 << 0) |
#define MDOC_ACTED (1 << 1) |
#define MDOC_ACTED (1 << 1) |
enum mdoc_type type; |
enum mdoc_type type; |
union mdoc_data data; |
|
enum mdoc_sec sec; |
enum mdoc_sec sec; |
|
|
|
/* FIXME: union/struct this with #defines. */ |
|
struct mdoc_arg *args; /* BLOCK/ELEM */ |
|
struct mdoc_node *head; /* BLOCK */ |
|
struct mdoc_node *body; /* BLOCK */ |
|
struct mdoc_node *tail; /* BLOCK */ |
|
char *string; /* TEXT */ |
}; |
}; |
|
|
|
#define MDOC_IGN_SCOPE (1 << 0) /* Ignore scope violations. */ |
|
#define MDOC_IGN_ESCAPE (1 << 1) /* Ignore bad escape sequences. */ |
|
#define MDOC_IGN_MACRO (1 << 2) /* Ignore unknown macros. */ |
|
#define MDOC_IGN_CHARS (1 << 3) /* Ignore disallowed chars. */ |
|
|
/* Call-backs for parse messages. */ |
/* Call-backs for parse messages. */ |
struct mdoc_cb { |
struct mdoc_cb { |
void (*mdoc_msg)(void *, int, int, const char *); |
|
int (*mdoc_err)(void *, int, int, const char *); |
int (*mdoc_err)(void *, int, int, const char *); |
int (*mdoc_warn)(void *, int, int, |
int (*mdoc_warn)(void *, int, int, |
enum mdoc_warn, const char *); |
enum mdoc_warn, const char *); |
|
|
void mdoc_free(struct mdoc *); |
void mdoc_free(struct mdoc *); |
|
|
/* Allocate a new parser instance. */ |
/* Allocate a new parser instance. */ |
struct mdoc *mdoc_alloc(void *data, const struct mdoc_cb *); |
struct mdoc *mdoc_alloc(void *, int, const struct mdoc_cb *); |
|
|
|
/* Gets system ready for another parse. */ |
|
int mdoc_reset(struct mdoc *); |
|
|
/* Parse a single line in a stream (boolean retval). */ |
/* Parse a single line in a stream (boolean retval). */ |
int mdoc_parseln(struct mdoc *, int, char *buf); |
int mdoc_parseln(struct mdoc *, int, char *buf); |
|
|
Line 314 int mdoc_endparse(struct mdoc *); |
|
Line 318 int mdoc_endparse(struct mdoc *); |
|
const char *mdoc_a2att(const char *); |
const char *mdoc_a2att(const char *); |
const char *mdoc_a2lib(const char *); |
const char *mdoc_a2lib(const char *); |
const char *mdoc_a2st(const char *); |
const char *mdoc_a2st(const char *); |
|
|
int mdoc_isdelim(const char *); |
|
|
|
__END_DECLS |
__END_DECLS |
|
|