summaryrefslogtreecommitdiffstats
path: root/mdoc_term.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-07-14 15:49:44 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-07-14 15:49:44 +0000
commit367d592b85f82bddefeeedb9dcacf312e9e4ac87 (patch)
treebc9ffe5fc9854dad13f8dc6c54c34c525eef7954 /mdoc_term.c
parent1aeffd06ef23e334ada54a5997652946127819de (diff)
downloadmandoc-367d592b85f82bddefeeedb9dcacf312e9e4ac87.tar.gz
Cleaned up arg_width and arg_column functions.
Added XXn and XXm support to -offset (not documented in mdoc.samples, but used in mdoc.samples!). Lint warnings fixed.
Diffstat (limited to 'mdoc_term.c')
-rw-r--r--mdoc_term.c43
1 files changed, 27 insertions, 16 deletions
diff --git a/mdoc_term.c b/mdoc_term.c
index 8e37cbc1..a23bb33a 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -517,28 +517,26 @@ print_head(struct termp *p, const struct mdoc_meta *meta)
static size_t
arg_width(const struct mdoc_argv *arg, int pos)
{
- size_t v;
int i, len;
+ const char *p;
assert(pos < (int)arg->sz && pos >= 0);
assert(arg->value[pos]);
- if (0 == (len = (int)strlen(arg->value[pos])))
+ p = arg->value[pos];
+
+ if (0 == (len = (int)strlen(p)))
return(0);
for (i = 0; i < len - 1; i++)
- if ( ! isdigit((u_char)arg->value[pos][i]))
+ if ( ! isdigit((u_char)p[i]))
break;
- if (i == len - 1) {
- if ('n' == arg->value[pos][len - 1] ||
- 'm' == arg->value[pos][len - 1]) {
- v = (size_t)atoi(arg->value[pos]);
- return(v + 2);
- }
+ if (i == len - 1)
+ if ('n' == p[len - 1] || 'm' == p[len - 1])
+ return((size_t)atoi(p) + 2);
- }
- return(strlen(arg->value[pos]) + 2);
+ return((size_t)len + 2);
}
@@ -586,18 +584,31 @@ arg_listtype(const struct mdoc_node *n)
static size_t
arg_offset(const struct mdoc_argv *arg)
{
+ int len, i;
+ const char *p;
assert(*arg->value);
- if (0 == strcmp(*arg->value, "left"))
+ p = *arg->value;
+
+ if (0 == strcmp(p, "left"))
return(0);
- if (0 == strcmp(*arg->value, "indent"))
+ if (0 == strcmp(p, "indent"))
return(INDENT + 1);
- if (0 == strcmp(*arg->value, "indent-two"))
+ if (0 == strcmp(p, "indent-two"))
return((INDENT + 1) * 2);
- /* FIXME: needs to support field-widths (10n, etc.). */
+ if (0 == (len = (int)strlen(p)))
+ return(0);
+
+ for (i = 0; i < len - 1; i++)
+ if ( ! isdigit((u_char)p[i]))
+ break;
+
+ if (i == len - 1)
+ if ('n' == p[len - 1] || 'm' == p[len - 1])
+ return((size_t)atoi(p));
- return(strlen(*arg->value));
+ return((size_t)len);
}