summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--mdoc_term.c43
-rw-r--r--term.c2
2 files changed, 28 insertions, 17 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);
}
diff --git a/term.c b/term.c
index a9f92429..1835544c 100644
--- a/term.c
+++ b/term.c
@@ -315,7 +315,7 @@ term_flushln(struct termp *p)
putchar(' ');
}
if (TERMP_HANG & p->flags)
- sv = vis - maxvis;
+ sv = (int)(vis - maxvis);
p->col = 0;
return;
}