diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-09-24 13:03:32 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-09-24 13:03:32 +0000 |
commit | 81c9a3f1c3d4a64b4404c010ceda364c2afd9e7c (patch) | |
tree | 3a29277c304a82861246c998d6b623a5a624e7f5 | |
parent | 0371d94639d271317d0697e7eefe5cb79df85fb7 (diff) | |
download | mandoc-81c9a3f1c3d4a64b4404c010ceda364c2afd9e7c.tar.gz |
-offset string can now be blank (supplied with 6n as stipulated by mdoc.samples).
-rw-r--r-- | mdoc_action.c | 59 | ||||
-rw-r--r-- | mdoc_argv.c | 8 |
2 files changed, 54 insertions, 13 deletions
diff --git a/mdoc_action.c b/mdoc_action.c index 8a58bcc8..fb780d37 100644 --- a/mdoc_action.c +++ b/mdoc_action.c @@ -51,7 +51,9 @@ static int post_std(POST_ARGS); static int post_tilde(POST_ARGS); static int pre_bd(PRE_ARGS); +static int pre_bl(PRE_ARGS); static int pre_dl(PRE_ARGS); +static int pre_offset(PRE_ARGS); static const struct actions mdoc_actions[MDOC_MAX] = { { NULL, NULL }, /* Ap */ @@ -65,7 +67,7 @@ static const struct actions mdoc_actions[MDOC_MAX] = { { pre_dl, post_display }, /* Dl */ { pre_bd, post_display }, /* Bd */ { NULL, NULL }, /* Ed */ - { NULL, post_bl }, /* Bl */ + { pre_bl, post_bl }, /* Bl */ { NULL, NULL }, /* El */ { NULL, NULL }, /* It */ { NULL, NULL }, /* Ad */ @@ -825,28 +827,63 @@ pre_dl(PRE_ARGS) static int +pre_offset(PRE_ARGS) +{ + int i; + + /* + * Make sure that an empty offset produces an 8n length space as + * stipulated by mdoc.samples. + */ + + assert(n->args); + for (i = 0; i < (int)n->args->argc; i++) { + if (MDOC_Offset != n->args->argv[i].arg) + continue; + if (n->args->argv[i].sz) + break; + assert(1 == n->args->refcnt); + /* If no value set, length of <string>. */ + n->args->argv[i].value = + calloc(1, sizeof(char *)); + if (NULL == n->args->argv[i].value) + return(mdoc_nerr(m, n, EMALLOC)); + n->args->argv[i].sz++; + n->args->argv[i].value[0] = strdup("8n"); + if (NULL == n->args->argv[i].value[0]) + return(mdoc_nerr(m, n, EMALLOC)); + break; + } + + return(1); +} + + +static int +pre_bl(PRE_ARGS) +{ + + return(MDOC_BLOCK == n->type ? pre_offset(m, n) : 1); +} + + +static int pre_bd(PRE_ARGS) { int i; + if (MDOC_BLOCK == n->type) + return(pre_offset(m, n)); if (MDOC_BODY != n->type) return(1); /* Enter literal context if `Bd -literal' or `-unfilled'. */ - /* - * TODO: `-offset' without an argument should be the width of - * the literal "<string>". - */ - for (n = n->parent, i = 0; i < (int)n->args->argc; i++) if (MDOC_Literal == n->args->argv[i].arg) - break; + m->flags |= MDOC_LITERAL; else if (MDOC_Unfilled == n->args->argv[i].arg) - break; - - if (i < (int)n->args->argc) - m->flags |= MDOC_LITERAL; + m->flags |= MDOC_LITERAL; return(1); } diff --git a/mdoc_argv.c b/mdoc_argv.c index 20a9dc5e..e0919c7a 100644 --- a/mdoc_argv.c +++ b/mdoc_argv.c @@ -60,7 +60,7 @@ static int mdoc_argvflags[MDOC_ARG_MAX] = { ARGV_NONE, /* MDOC_Unfilled */ ARGV_NONE, /* MDOC_Literal */ ARGV_NONE, /* MDOC_File */ - ARGV_SINGLE, /* MDOC_Offset */ + ARGV_OPT_SINGLE, /* MDOC_Offset */ ARGV_NONE, /* MDOC_Bullet */ ARGV_NONE, /* MDOC_Dash */ ARGV_NONE, /* MDOC_Hyphen */ @@ -309,9 +309,13 @@ mdoc_argv_free(struct mdoc_arg *p) for (i = 0; i < (int)p->argc; i++) { if (0 == p->argv[i].sz) continue; + if (NULL == p->argv[i].value) + continue; + /* LINTED */ for (j = 0; j < (int)p->argv[i].sz; j++) - free(p->argv[i].value[j]); + if (p->argv[i].value[j]) + free(p->argv[i].value[j]); free(p->argv[i].value); } |