From 30b7779eb2696f56263ec38a19cce37e4ce809da Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Fri, 7 May 2010 05:54:09 +0000 Subject: enum-ised mdoc_argv() return (better return-value safety). --- libmdoc.h | 15 +++++++++------ mdoc_argv.c | 4 ++-- mdoc_macro.c | 46 +++++++++++++++++++++++++--------------------- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/libmdoc.h b/libmdoc.h index d2b7d3e1..f6b4d135 100644 --- a/libmdoc.h +++ b/libmdoc.h @@ -1,4 +1,4 @@ -/* $Id: libmdoc.h,v 1.36 2010/05/07 05:48:29 kristaps Exp $ */ +/* $Id: libmdoc.h,v 1.37 2010/05/07 05:54:09 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -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 62c44c59..d45ba999 100644 --- a/mdoc_argv.c +++ b/mdoc_argv.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_argv.c,v 1.39 2010/05/07 05:48:29 kristaps Exp $ */ +/* $Id: mdoc_argv.c,v 1.40 2010/05/07 05:54:09 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -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 46ac95f7..89240740 100644 --- a/mdoc_macro.c +++ b/mdoc_macro.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_macro.c,v 1.55 2010/05/07 05:48:29 kristaps Exp $ */ +/* $Id: mdoc_macro.c,v 1.56 2010/05/07 05:54:09 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -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); -- cgit v1.2.3