+static int
+post_bl_tagwidth(struct mdoc *mdoc)
+{
+ struct mdoc_node *n;
+ int sz;
+ char buf[32];
+
+ /*
+ * If -tag has been specified and -width has not been, then try
+ * to intuit our width from the first body element.
+ */
+
+ if (NULL == (n = mdoc->last->body->child))
+ return(1);
+
+ /*
+ * Use the text width, if a text node, or the default macro
+ * width if a macro.
+ */
+
+ if ((n = n->head->child)) {
+ if (MDOC_TEXT != n->type) {
+ if (0 == (sz = (int)mdoc_macro2len(n->tok)))
+ sz = -1;
+ } else
+ sz = (int)strlen(n->string) + 1;
+ } else
+ sz = -1;
+
+ if (-1 == sz) {
+ if ( ! mwarn(mdoc, WNOWIDTH))
+ return(0);
+ sz = 10;
+ }
+
+ (void)snprintf(buf, sizeof(buf), "%dn", sz);
+
+ /*
+ * We have to dynamically add this to the macro's argument list.
+ * We're guaranteed that a MDOC_Width doesn't already exist.
+ */
+
+ if (NULL == mdoc->last->args) {
+ mdoc->last->args = xcalloc
+ (1, sizeof(struct mdoc_arg));
+ mdoc->last->args->refcnt = 1;
+ }
+
+ n = mdoc->last;
+ sz = (int)n->args->argc;
+
+ (n->args->argc)++;
+
+ n->args->argv = xrealloc(n->args->argv,
+ n->args->argc * sizeof(struct mdoc_arg));
+
+ n->args->argv[sz - 1].arg = MDOC_Width;
+ n->args->argv[sz - 1].line = mdoc->last->line;
+ n->args->argv[sz - 1].pos = mdoc->last->pos;
+ n->args->argv[sz - 1].sz = 1;
+ n->args->argv[sz - 1].value = xcalloc(1, sizeof(char *));
+ n->args->argv[sz - 1].value[0] = xstrdup(buf);
+
+ mdoc_msg(mdoc, "adding %s argument: %s",
+ mdoc_argnames[MDOC_Width], buf);
+