summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-05-07 05:54:09 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-05-07 05:54:09 +0000
commitaffb60f9d063ad854386b239fbe7688abd4cdeac (patch)
tree6787d7d3eff3b1e51d83ef8d9de8317ad3c6a7e6
parent820ec2c8803594c2404d9f5cd0d1d07f90621538 (diff)
downloadmandoc-affb60f9d063ad854386b239fbe7688abd4cdeac.tar.gz
enum-ised mdoc_argv() return (better return-value safety).
-rw-r--r--libmdoc.h13
-rw-r--r--mdoc_argv.c2
-rw-r--r--mdoc_macro.c44
3 files changed, 33 insertions, 26 deletions
diff --git a/libmdoc.h b/libmdoc.h
index 2211c9fd..ede159f6 100644
--- a/libmdoc.h
+++ b/libmdoc.h
@@ -120,6 +120,13 @@ enum margserr {
ARGS_PHRASE
};
+enum margverr {
+ ARGV_ERROR,
+ ARGV_EOLN,
+ ARGV_ARG,
+ ARGV_WORD
+};
+
extern const struct mdoc_macro *const mdoc_macros;
__BEGIN_DECLS
@@ -169,12 +176,8 @@ int mdoc_valid_post(struct mdoc *);
int mdoc_action_pre(struct mdoc *,
const struct mdoc_node *);
int mdoc_action_post(struct mdoc *);
-int mdoc_argv(struct mdoc *, int, enum mdoct,
+enum margverr mdoc_argv(struct mdoc *, int, enum mdoct,
struct mdoc_arg **, int *, char *);
-#define ARGV_ERROR (-1)
-#define ARGV_EOLN (0)
-#define ARGV_ARG (1)
-#define ARGV_WORD (2)
void mdoc_argv_free(struct mdoc_arg *);
void mdoc_argn_free(struct mdoc_arg *, int);
enum margserr mdoc_args(struct mdoc *, int,
diff --git a/mdoc_argv.c b/mdoc_argv.c
index 1828ec15..08de1bf0 100644
--- a/mdoc_argv.c
+++ b/mdoc_argv.c
@@ -217,7 +217,7 @@ static int mdoc_argflags[MDOC_MAX] = {
* [value0...], which may either have a single mandatory value, at least
* one mandatory value, an optional single value, or no value.
*/
-int
+enum margverr
mdoc_argv(struct mdoc *m, int line, enum mdoct tok,
struct mdoc_arg **v, int *pos, char *buf)
{
diff --git a/mdoc_macro.c b/mdoc_macro.c
index 390cdf32..eef40906 100644
--- a/mdoc_macro.c
+++ b/mdoc_macro.c
@@ -732,7 +732,8 @@ blk_exp_close(MACRO_PROT_ARGS)
static int
in_line(MACRO_PROT_ARGS)
{
- int la, lastpunct, c, cnt, d, nc;
+ int la, lastpunct, cnt, d, nc;
+ enum margverr av;
enum mdoct ntok;
enum margserr ac;
struct mdoc_arg *arg;
@@ -764,15 +765,15 @@ in_line(MACRO_PROT_ARGS)
for (arg = NULL;; ) {
la = *pos;
- c = mdoc_argv(m, line, tok, &arg, pos, buf);
+ av = mdoc_argv(m, line, tok, &arg, pos, buf);
- if (ARGV_WORD == c) {
+ if (ARGV_WORD == av) {
*pos = la;
break;
}
- if (ARGV_EOLN == c)
+ if (ARGV_EOLN == av)
break;
- if (ARGV_ARG == c)
+ if (ARGV_ARG == av)
continue;
mdoc_argv_free(arg);
@@ -883,7 +884,7 @@ in_line(MACRO_PROT_ARGS)
static int
blk_full(MACRO_PROT_ARGS)
{
- int c, la;
+ int la;
struct mdoc_arg *arg;
struct mdoc_node *head; /* save of head macro */
struct mdoc_node *body; /* save of body macro */
@@ -892,6 +893,7 @@ blk_full(MACRO_PROT_ARGS)
#endif
enum mdoct ntok;
enum margserr ac;
+ enum margverr av;
char *p;
/* Close out prior implicit scope. */
@@ -914,16 +916,16 @@ blk_full(MACRO_PROT_ARGS)
for (arg = NULL;; ) {
la = *pos;
- c = mdoc_argv(m, line, tok, &arg, pos, buf);
+ av = mdoc_argv(m, line, tok, &arg, pos, buf);
- if (ARGV_WORD == c) {
+ if (ARGV_WORD == av) {
*pos = la;
break;
}
- if (ARGV_EOLN == c)
+ if (ARGV_EOLN == av)
break;
- if (ARGV_ARG == c)
+ if (ARGV_ARG == av)
continue;
mdoc_argv_free(arg);
@@ -1269,8 +1271,9 @@ blk_part_exp(MACRO_PROT_ARGS)
static int
in_line_argn(MACRO_PROT_ARGS)
{
- int la, flushed, j, c, maxargs;
+ int la, flushed, j, maxargs;
enum margserr ac;
+ enum margverr av;
struct mdoc_arg *arg;
char *p;
enum mdoct ntok;
@@ -1303,16 +1306,16 @@ in_line_argn(MACRO_PROT_ARGS)
for (arg = NULL; ; ) {
la = *pos;
- c = mdoc_argv(m, line, tok, &arg, pos, buf);
+ av = mdoc_argv(m, line, tok, &arg, pos, buf);
- if (ARGV_WORD == c) {
+ if (ARGV_WORD == av) {
*pos = la;
break;
}
- if (ARGV_EOLN == c)
+ if (ARGV_EOLN == av)
break;
- if (ARGV_ARG == c)
+ if (ARGV_ARG == av)
continue;
mdoc_argv_free(arg);
@@ -1404,8 +1407,9 @@ in_line_argn(MACRO_PROT_ARGS)
static int
in_line_eoln(MACRO_PROT_ARGS)
{
- int c, la;
+ int la;
enum margserr ac;
+ enum margverr av;
struct mdoc_arg *arg;
char *p;
enum mdoct ntok;
@@ -1416,15 +1420,15 @@ in_line_eoln(MACRO_PROT_ARGS)
for (arg = NULL; ; ) {
la = *pos;
- c = mdoc_argv(m, line, tok, &arg, pos, buf);
+ av = mdoc_argv(m, line, tok, &arg, pos, buf);
- if (ARGV_WORD == c) {
+ if (ARGV_WORD == av) {
*pos = la;
break;
}
- if (ARGV_EOLN == c)
+ if (ARGV_EOLN == av)
break;
- if (ARGV_ARG == c)
+ if (ARGV_ARG == av)
continue;
mdoc_argv_free(arg);