2017-01-21 13:01:39 +00:00
|
|
|
/* $Id: html.c,v 1.200 2017/01/21 02:29:57 schwarze Exp $ */
|
2012-10-18 09:55:16 +00:00
|
|
|
/*
|
2014-12-02 07:34:06 +00:00
|
|
|
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
|
2017-01-21 13:01:39 +00:00
|
|
|
* Copyright (c) 2011-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
|
2012-10-18 09:55:16 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
2016-01-15 23:08:59 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
|
2012-10-18 09:55:16 +00:00
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
2016-01-15 23:08:59 +00:00
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
2012-10-18 09:55:16 +00:00
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "mandoc.h"
|
2014-11-22 18:08:25 +00:00
|
|
|
#include "mandoc_aux.h"
|
2012-10-18 09:55:16 +00:00
|
|
|
#include "out.h"
|
|
|
|
#include "html.h"
|
2016-01-15 23:08:59 +00:00
|
|
|
#include "manconf.h"
|
2012-10-18 09:55:16 +00:00
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
struct htmldata {
|
|
|
|
const char *name;
|
|
|
|
int flags;
|
2017-01-21 13:01:39 +00:00
|
|
|
#define HTML_NOSTACK (1 << 0)
|
|
|
|
#define HTML_AUTOCLOSE (1 << 1)
|
|
|
|
#define HTML_NLBEFORE (1 << 2)
|
|
|
|
#define HTML_NLBEGIN (1 << 3)
|
|
|
|
#define HTML_NLEND (1 << 4)
|
|
|
|
#define HTML_NLAFTER (1 << 5)
|
|
|
|
#define HTML_NLAROUND (HTML_NLBEFORE | HTML_NLAFTER)
|
|
|
|
#define HTML_NLINSIDE (HTML_NLBEGIN | HTML_NLEND)
|
|
|
|
#define HTML_NLALL (HTML_NLAROUND | HTML_NLINSIDE)
|
|
|
|
#define HTML_INDENT (1 << 6)
|
|
|
|
#define HTML_NOINDENT (1 << 7)
|
2012-10-18 09:55:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct htmldata htmltags[TAG_MAX] = {
|
2017-01-21 13:01:39 +00:00
|
|
|
{"html", HTML_NLALL},
|
|
|
|
{"head", HTML_NLALL | HTML_INDENT},
|
|
|
|
{"body", HTML_NLALL},
|
|
|
|
{"meta", HTML_NOSTACK | HTML_AUTOCLOSE | HTML_NLALL},
|
|
|
|
{"title", HTML_NLAROUND},
|
|
|
|
{"div", HTML_NLAROUND},
|
|
|
|
{"h1", HTML_NLAROUND},
|
|
|
|
{"h2", HTML_NLAROUND},
|
|
|
|
{"span", 0},
|
|
|
|
{"link", HTML_NOSTACK | HTML_AUTOCLOSE | HTML_NLALL},
|
|
|
|
{"br", HTML_NOSTACK | HTML_AUTOCLOSE | HTML_NLALL},
|
|
|
|
{"a", 0},
|
|
|
|
{"table", HTML_NLALL | HTML_INDENT},
|
|
|
|
{"tbody", HTML_NLALL | HTML_INDENT},
|
|
|
|
{"col", HTML_NOSTACK | HTML_AUTOCLOSE | HTML_NLALL},
|
|
|
|
{"tr", HTML_NLALL | HTML_INDENT},
|
|
|
|
{"td", HTML_NLAROUND},
|
|
|
|
{"li", HTML_NLAROUND | HTML_INDENT},
|
|
|
|
{"ul", HTML_NLALL | HTML_INDENT},
|
|
|
|
{"ol", HTML_NLALL | HTML_INDENT},
|
|
|
|
{"dl", HTML_NLALL | HTML_INDENT},
|
|
|
|
{"dt", HTML_NLAROUND},
|
|
|
|
{"dd", HTML_NLAROUND | HTML_INDENT},
|
|
|
|
{"pre", HTML_NLALL | HTML_NOINDENT},
|
|
|
|
{"b", 0},
|
|
|
|
{"i", 0},
|
|
|
|
{"code", 0},
|
|
|
|
{"small", 0},
|
|
|
|
{"style", HTML_NLALL | HTML_INDENT},
|
|
|
|
{"math", HTML_NLALL | HTML_INDENT},
|
|
|
|
{"mrow", 0},
|
|
|
|
{"mi", 0},
|
|
|
|
{"mo", 0},
|
|
|
|
{"msup", 0},
|
|
|
|
{"msub", 0},
|
|
|
|
{"msubsup", 0},
|
|
|
|
{"mfrac", 0},
|
|
|
|
{"msqrt", 0},
|
|
|
|
{"mfenced", 0},
|
|
|
|
{"mtable", 0},
|
|
|
|
{"mtr", 0},
|
|
|
|
{"mtd", 0},
|
|
|
|
{"munderover", 0},
|
|
|
|
{"munder", 0},
|
|
|
|
{"mover", 0},
|
2012-10-18 09:55:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *const roffscales[SCALE_MAX] = {
|
|
|
|
"cm", /* SCALE_CM */
|
|
|
|
"in", /* SCALE_IN */
|
|
|
|
"pc", /* SCALE_PC */
|
|
|
|
"pt", /* SCALE_PT */
|
|
|
|
"em", /* SCALE_EM */
|
|
|
|
"em", /* SCALE_MM */
|
|
|
|
"ex", /* SCALE_EN */
|
|
|
|
"ex", /* SCALE_BU */
|
|
|
|
"em", /* SCALE_VS */
|
|
|
|
"ex", /* SCALE_FS */
|
|
|
|
};
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
static void a2width(const char *, struct roffsu *);
|
|
|
|
static void print_byte(struct html *, char);
|
|
|
|
static void print_endline(struct html *);
|
|
|
|
static void print_endword(struct html *);
|
|
|
|
static void print_indent(struct html *);
|
|
|
|
static void print_word(struct html *, const char *);
|
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
static void print_ctag(struct html *, struct tag *);
|
2017-01-21 13:01:39 +00:00
|
|
|
static int print_escape(struct html *, char);
|
|
|
|
static int print_encode(struct html *, const char *, const char *, int);
|
|
|
|
static void print_href(struct html *, const char *, const char *, int);
|
2012-10-18 09:55:16 +00:00
|
|
|
static void print_metaf(struct html *, enum mandoc_esc);
|
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
void *
|
2016-01-15 23:08:59 +00:00
|
|
|
html_alloc(const struct manoutput *outopts)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
|
|
|
struct html *h;
|
|
|
|
|
|
|
|
h = mandoc_calloc(1, sizeof(struct html));
|
|
|
|
|
|
|
|
h->tags.head = NULL;
|
2016-01-15 23:08:59 +00:00
|
|
|
h->style = outopts->style;
|
|
|
|
h->base_man = outopts->man;
|
|
|
|
h->base_includes = outopts->includes;
|
|
|
|
if (outopts->fragment)
|
|
|
|
h->oflags |= HTML_FRAGMENT;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
return h;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
html_free(void *p)
|
|
|
|
{
|
|
|
|
struct tag *tag;
|
|
|
|
struct html *h;
|
|
|
|
|
|
|
|
h = (struct html *)p;
|
|
|
|
|
|
|
|
while ((tag = h->tags.head) != NULL) {
|
2014-11-22 18:08:25 +00:00
|
|
|
h->tags.head = tag->next;
|
2012-10-18 09:55:16 +00:00
|
|
|
free(tag);
|
|
|
|
}
|
2014-11-22 18:08:25 +00:00
|
|
|
|
2012-10-18 09:55:16 +00:00
|
|
|
free(h);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_gen_head(struct html *h)
|
|
|
|
{
|
2014-12-02 07:34:06 +00:00
|
|
|
struct tag *t;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
print_otag(h, TAG_META, "?", "charset", "utf-8");
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
/*
|
|
|
|
* Print a default style-sheet.
|
|
|
|
*/
|
2017-01-21 13:01:39 +00:00
|
|
|
|
|
|
|
t = print_otag(h, TAG_STYLE, "");
|
|
|
|
print_text(h, "table.head, table.foot { width: 100%; }");
|
|
|
|
print_endline(h);
|
|
|
|
print_text(h, "td.head-rtitle, td.foot-os { text-align: right; }");
|
|
|
|
print_endline(h);
|
|
|
|
print_text(h, "td.head-vol { text-align: center; }");
|
|
|
|
print_endline(h);
|
|
|
|
print_text(h, "div.Pp { margin: 1ex 0ex; }");
|
2014-12-02 07:34:06 +00:00
|
|
|
print_tagq(h, t);
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
if (h->style)
|
|
|
|
print_otag(h, TAG_LINK, "?h??", "rel", "stylesheet",
|
|
|
|
h->style, "type", "text/css", "media", "all");
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_metaf(struct html *h, enum mandoc_esc deco)
|
|
|
|
{
|
|
|
|
enum htmlfont font;
|
|
|
|
|
|
|
|
switch (deco) {
|
2014-11-22 18:08:25 +00:00
|
|
|
case ESCAPE_FONTPREV:
|
2012-10-18 09:55:16 +00:00
|
|
|
font = h->metal;
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case ESCAPE_FONTITALIC:
|
2012-10-18 09:55:16 +00:00
|
|
|
font = HTMLFONT_ITALIC;
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case ESCAPE_FONTBOLD:
|
2012-10-18 09:55:16 +00:00
|
|
|
font = HTMLFONT_BOLD;
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case ESCAPE_FONTBI:
|
2014-01-31 19:59:03 +00:00
|
|
|
font = HTMLFONT_BI;
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case ESCAPE_FONT:
|
|
|
|
case ESCAPE_FONTROMAN:
|
2012-10-18 09:55:16 +00:00
|
|
|
font = HTMLFONT_NONE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (h->metaf) {
|
|
|
|
print_tagq(h, h->metaf);
|
|
|
|
h->metaf = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
h->metal = h->metac;
|
|
|
|
h->metac = font;
|
|
|
|
|
2014-01-31 19:59:03 +00:00
|
|
|
switch (font) {
|
2014-11-22 18:08:25 +00:00
|
|
|
case HTMLFONT_ITALIC:
|
2017-01-21 13:01:39 +00:00
|
|
|
h->metaf = print_otag(h, TAG_I, "");
|
2014-01-31 19:59:03 +00:00
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case HTMLFONT_BOLD:
|
2017-01-21 13:01:39 +00:00
|
|
|
h->metaf = print_otag(h, TAG_B, "");
|
2014-01-31 19:59:03 +00:00
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case HTMLFONT_BI:
|
2017-01-21 13:01:39 +00:00
|
|
|
h->metaf = print_otag(h, TAG_B, "");
|
|
|
|
print_otag(h, TAG_I, "");
|
2014-01-31 19:59:03 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
html_strlen(const char *cp)
|
|
|
|
{
|
2014-01-31 19:59:03 +00:00
|
|
|
size_t rsz;
|
|
|
|
int skip, sz;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Account for escaped sequences within string length
|
|
|
|
* calculations. This follows the logic in term_strlen() as we
|
|
|
|
* must calculate the width of produced strings.
|
|
|
|
* Assume that characters are always width of "1". This is
|
|
|
|
* hacky, but it gets the job done for approximation of widths.
|
|
|
|
*/
|
|
|
|
|
|
|
|
sz = 0;
|
2014-01-31 19:59:03 +00:00
|
|
|
skip = 0;
|
|
|
|
while (1) {
|
|
|
|
rsz = strcspn(cp, "\\");
|
|
|
|
if (rsz) {
|
|
|
|
cp += rsz;
|
|
|
|
if (skip) {
|
|
|
|
skip = 0;
|
|
|
|
rsz--;
|
|
|
|
}
|
|
|
|
sz += rsz;
|
|
|
|
}
|
|
|
|
if ('\0' == *cp)
|
|
|
|
break;
|
|
|
|
cp++;
|
|
|
|
switch (mandoc_escape(&cp, NULL, NULL)) {
|
2014-11-22 18:08:25 +00:00
|
|
|
case ESCAPE_ERROR:
|
2016-01-15 23:08:59 +00:00
|
|
|
return sz;
|
2014-11-22 18:08:25 +00:00
|
|
|
case ESCAPE_UNICODE:
|
|
|
|
case ESCAPE_NUMBERED:
|
|
|
|
case ESCAPE_SPECIAL:
|
2015-03-02 16:45:41 +00:00
|
|
|
case ESCAPE_OVERSTRIKE:
|
2014-01-31 19:59:03 +00:00
|
|
|
if (skip)
|
|
|
|
skip = 0;
|
|
|
|
else
|
|
|
|
sz++;
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case ESCAPE_SKIPCHAR:
|
2014-01-31 19:59:03 +00:00
|
|
|
skip = 1;
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-01-15 23:08:59 +00:00
|
|
|
return sz;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
static int
|
2017-01-21 13:01:39 +00:00
|
|
|
print_escape(struct html *h, char c)
|
2014-11-22 18:08:25 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case '<':
|
2017-01-21 13:01:39 +00:00
|
|
|
print_word(h, "<");
|
2014-11-22 18:08:25 +00:00
|
|
|
break;
|
|
|
|
case '>':
|
2017-01-21 13:01:39 +00:00
|
|
|
print_word(h, ">");
|
2014-11-22 18:08:25 +00:00
|
|
|
break;
|
|
|
|
case '&':
|
2017-01-21 13:01:39 +00:00
|
|
|
print_word(h, "&");
|
2014-11-22 18:08:25 +00:00
|
|
|
break;
|
|
|
|
case '"':
|
2017-01-21 13:01:39 +00:00
|
|
|
print_word(h, """);
|
2014-11-22 18:08:25 +00:00
|
|
|
break;
|
|
|
|
case ASCII_NBRSP:
|
2017-01-21 13:01:39 +00:00
|
|
|
print_word(h, " ");
|
2014-11-22 18:08:25 +00:00
|
|
|
break;
|
|
|
|
case ASCII_HYPH:
|
2017-01-21 13:01:39 +00:00
|
|
|
print_byte(h, '-');
|
2016-01-15 23:08:59 +00:00
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case ASCII_BREAK:
|
|
|
|
break;
|
|
|
|
default:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 0;
|
2014-11-22 18:08:25 +00:00
|
|
|
}
|
2016-01-15 23:08:59 +00:00
|
|
|
return 1;
|
2014-11-22 18:08:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-18 09:55:16 +00:00
|
|
|
static int
|
2017-01-21 13:01:39 +00:00
|
|
|
print_encode(struct html *h, const char *p, const char *pend, int norecurse)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
2017-01-21 13:01:39 +00:00
|
|
|
char numbuf[16];
|
2012-10-18 09:55:16 +00:00
|
|
|
size_t sz;
|
|
|
|
int c, len, nospace;
|
|
|
|
const char *seq;
|
|
|
|
enum mandoc_esc esc;
|
2014-11-22 18:08:25 +00:00
|
|
|
static const char rejs[9] = { '\\', '<', '>', '&', '"',
|
|
|
|
ASCII_NBRSP, ASCII_HYPH, ASCII_BREAK, '\0' };
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
if (pend == NULL)
|
|
|
|
pend = strchr(p, '\0');
|
|
|
|
|
2012-10-18 09:55:16 +00:00
|
|
|
nospace = 0;
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
while (p < pend) {
|
2014-01-31 19:59:03 +00:00
|
|
|
if (HTML_SKIPCHAR & h->flags && '\\' != *p) {
|
|
|
|
h->flags &= ~HTML_SKIPCHAR;
|
|
|
|
p++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
for (sz = strcspn(p, rejs); sz-- && p < pend; p++)
|
|
|
|
if (*p == ' ')
|
|
|
|
print_endword(h);
|
|
|
|
else
|
|
|
|
print_byte(h, *p);
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
if (p >= pend)
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
if (print_escape(h, *p++))
|
2012-10-18 09:55:16 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
esc = mandoc_escape(&p, &seq, &len);
|
|
|
|
if (ESCAPE_ERROR == esc)
|
|
|
|
break;
|
|
|
|
|
2014-01-31 19:59:03 +00:00
|
|
|
switch (esc) {
|
2014-11-22 18:08:25 +00:00
|
|
|
case ESCAPE_FONT:
|
|
|
|
case ESCAPE_FONTPREV:
|
|
|
|
case ESCAPE_FONTBOLD:
|
|
|
|
case ESCAPE_FONTITALIC:
|
|
|
|
case ESCAPE_FONTBI:
|
|
|
|
case ESCAPE_FONTROMAN:
|
2014-01-31 19:59:03 +00:00
|
|
|
if (0 == norecurse)
|
|
|
|
print_metaf(h, esc);
|
|
|
|
continue;
|
2014-11-22 18:08:25 +00:00
|
|
|
case ESCAPE_SKIPCHAR:
|
2014-01-31 19:59:03 +00:00
|
|
|
h->flags |= HTML_SKIPCHAR;
|
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (h->flags & HTML_SKIPCHAR) {
|
|
|
|
h->flags &= ~HTML_SKIPCHAR;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-10-18 09:55:16 +00:00
|
|
|
switch (esc) {
|
2014-11-22 18:08:25 +00:00
|
|
|
case ESCAPE_UNICODE:
|
|
|
|
/* Skip past "u" header. */
|
2012-10-18 09:55:16 +00:00
|
|
|
c = mchars_num2uc(seq + 1, len - 1);
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case ESCAPE_NUMBERED:
|
2012-10-18 09:55:16 +00:00
|
|
|
c = mchars_num2char(seq, len);
|
2014-12-02 07:34:06 +00:00
|
|
|
if (c < 0)
|
|
|
|
continue;
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case ESCAPE_SPECIAL:
|
2016-01-15 23:08:59 +00:00
|
|
|
c = mchars_spec2cp(seq, len);
|
2014-12-02 07:34:06 +00:00
|
|
|
if (c <= 0)
|
|
|
|
continue;
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case ESCAPE_NOSPACE:
|
2012-10-18 09:55:16 +00:00
|
|
|
if ('\0' == *p)
|
|
|
|
nospace = 1;
|
2014-12-02 07:34:06 +00:00
|
|
|
continue;
|
2015-03-02 16:45:41 +00:00
|
|
|
case ESCAPE_OVERSTRIKE:
|
|
|
|
if (len == 0)
|
|
|
|
continue;
|
|
|
|
c = seq[len - 1];
|
|
|
|
break;
|
2012-10-18 09:55:16 +00:00
|
|
|
default:
|
2014-12-02 07:34:06 +00:00
|
|
|
continue;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
2014-12-02 07:34:06 +00:00
|
|
|
if ((c < 0x20 && c != 0x09) ||
|
|
|
|
(c > 0x7E && c < 0xA0))
|
|
|
|
c = 0xFFFD;
|
2017-01-21 13:01:39 +00:00
|
|
|
if (c > 0x7E) {
|
|
|
|
(void)snprintf(numbuf, sizeof(numbuf), "&#%d;", c);
|
|
|
|
print_word(h, numbuf);
|
|
|
|
} else if (print_escape(h, c) == 0)
|
|
|
|
print_byte(h, c);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
return nospace;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-01-21 13:01:39 +00:00
|
|
|
print_href(struct html *h, const char *name, const char *sec, int man)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
2017-01-21 13:01:39 +00:00
|
|
|
const char *p, *pp;
|
|
|
|
|
|
|
|
pp = man ? h->base_man : h->base_includes;
|
|
|
|
while ((p = strchr(pp, '%')) != NULL) {
|
|
|
|
print_encode(h, pp, p, 1);
|
|
|
|
if (man && p[1] == 'S') {
|
|
|
|
if (sec == NULL)
|
|
|
|
print_byte(h, '1');
|
|
|
|
else
|
|
|
|
print_encode(h, sec, NULL, 1);
|
|
|
|
} else if ((man && p[1] == 'N') ||
|
|
|
|
(man == 0 && p[1] == 'I'))
|
|
|
|
print_encode(h, name, NULL, 1);
|
|
|
|
else
|
|
|
|
print_encode(h, p, p + 2, 1);
|
|
|
|
pp = p + 2;
|
|
|
|
}
|
|
|
|
if (*pp != '\0')
|
|
|
|
print_encode(h, pp, NULL, 1);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct tag *
|
2017-01-21 13:01:39 +00:00
|
|
|
print_otag(struct html *h, enum htmltag tag, const char *fmt, ...)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
2017-01-21 13:01:39 +00:00
|
|
|
va_list ap;
|
|
|
|
struct roffsu mysu, *su;
|
|
|
|
char numbuf[16];
|
2012-10-18 09:55:16 +00:00
|
|
|
struct tag *t;
|
2017-01-21 13:01:39 +00:00
|
|
|
const char *attr;
|
|
|
|
char *s;
|
|
|
|
double v;
|
|
|
|
int i, have_style, tflags;
|
|
|
|
|
|
|
|
tflags = htmltags[tag].flags;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
/* Push this tags onto the stack of open scopes. */
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
if ((tflags & HTML_NOSTACK) == 0) {
|
2012-10-18 09:55:16 +00:00
|
|
|
t = mandoc_malloc(sizeof(struct tag));
|
|
|
|
t->tag = tag;
|
|
|
|
t->next = h->tags.head;
|
|
|
|
h->tags.head = t;
|
|
|
|
} else
|
|
|
|
t = NULL;
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
if (tflags & HTML_NLBEFORE)
|
|
|
|
print_endline(h);
|
|
|
|
if (h->col == 0)
|
|
|
|
print_indent(h);
|
|
|
|
else if ((h->flags & HTML_NOSPACE) == 0) {
|
|
|
|
if (h->flags & HTML_KEEP)
|
|
|
|
print_word(h, " ");
|
|
|
|
else {
|
|
|
|
if (h->flags & HTML_PREKEEP)
|
|
|
|
h->flags |= HTML_KEEP;
|
|
|
|
print_endword(h);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
2017-01-21 13:01:39 +00:00
|
|
|
}
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
if ( ! (h->flags & HTML_NONOSPACE))
|
|
|
|
h->flags &= ~HTML_NOSPACE;
|
|
|
|
else
|
|
|
|
h->flags |= HTML_NOSPACE;
|
|
|
|
|
|
|
|
/* Print out the tag name and attributes. */
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
print_byte(h, '<');
|
|
|
|
print_word(h, htmltags[tag].name);
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
|
|
|
|
have_style = 0;
|
|
|
|
while (*fmt != '\0') {
|
|
|
|
if (*fmt == 's') {
|
|
|
|
print_word(h, " style=\"");
|
|
|
|
have_style = 1;
|
|
|
|
fmt++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
s = va_arg(ap, char *);
|
|
|
|
switch (*fmt++) {
|
|
|
|
case 'c':
|
|
|
|
attr = "class";
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
attr = "href";
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
attr = "id";
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
attr = s;
|
|
|
|
s = va_arg(ap, char *);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
print_byte(h, ' ');
|
|
|
|
print_word(h, attr);
|
|
|
|
print_byte(h, '=');
|
|
|
|
print_byte(h, '"');
|
|
|
|
switch (*fmt) {
|
|
|
|
case 'M':
|
|
|
|
print_href(h, s, va_arg(ap, char *), 1);
|
|
|
|
fmt++;
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
print_href(h, s, NULL, 0);
|
|
|
|
fmt++;
|
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
print_byte(h, '#');
|
|
|
|
fmt++;
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
default:
|
|
|
|
print_encode(h, s, NULL, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
print_byte(h, '"');
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print out styles. */
|
|
|
|
|
|
|
|
s = NULL;
|
|
|
|
su = &mysu;
|
|
|
|
while (*fmt != '\0') {
|
|
|
|
|
|
|
|
/* First letter: input argument type. */
|
|
|
|
|
|
|
|
switch (*fmt++) {
|
|
|
|
case 'h':
|
|
|
|
i = va_arg(ap, int);
|
|
|
|
SCALE_HS_INIT(su, i);
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
s = va_arg(ap, char *);
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
su = va_arg(ap, struct roffsu *);
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
i = va_arg(ap, int);
|
|
|
|
SCALE_VS_INIT(su, i);
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
s = va_arg(ap, char *);
|
|
|
|
a2width(s, su);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Second letter: style name. */
|
|
|
|
|
|
|
|
switch (*fmt++) {
|
|
|
|
case 'b':
|
|
|
|
attr = "margin-bottom";
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
attr = "height";
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
attr = "text-indent";
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
attr = "margin-left";
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
attr = "margin-top";
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
attr = "width";
|
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
attr = "min-width";
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
print_word(h, s);
|
|
|
|
print_byte(h, ':');
|
|
|
|
print_byte(h, ' ');
|
|
|
|
print_word(h, va_arg(ap, char *));
|
|
|
|
print_byte(h, ';');
|
|
|
|
if (*fmt != '\0')
|
|
|
|
print_byte(h, ' ');
|
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
v = su->scale;
|
|
|
|
if (su->unit == SCALE_MM && (v /= 100.0) == 0.0)
|
|
|
|
v = 1.0;
|
|
|
|
else if (su->unit == SCALE_BU)
|
|
|
|
v /= 24.0;
|
|
|
|
print_word(h, attr);
|
|
|
|
print_byte(h, ':');
|
|
|
|
print_byte(h, ' ');
|
|
|
|
(void)snprintf(numbuf, sizeof(numbuf), "%.2f", v);
|
|
|
|
print_word(h, numbuf);
|
|
|
|
print_word(h, roffscales[su->unit]);
|
|
|
|
print_byte(h, ';');
|
|
|
|
if (*fmt != '\0')
|
|
|
|
print_byte(h, ' ');
|
|
|
|
}
|
|
|
|
if (have_style)
|
|
|
|
print_byte(h, '"');
|
|
|
|
|
|
|
|
va_end(ap);
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
/* Accommodate for "well-formed" singleton escaping. */
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
if (HTML_AUTOCLOSE & htmltags[tag].flags)
|
2017-01-21 13:01:39 +00:00
|
|
|
print_byte(h, '/');
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
print_byte(h, '>');
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
if (tflags & HTML_NLBEGIN)
|
|
|
|
print_endline(h);
|
|
|
|
else
|
|
|
|
h->flags |= HTML_NOSPACE;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
if (tflags & HTML_INDENT)
|
|
|
|
h->indent++;
|
|
|
|
if (tflags & HTML_NOINDENT)
|
|
|
|
h->noindent++;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
return t;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-03-02 16:45:41 +00:00
|
|
|
print_ctag(struct html *h, struct tag *tag)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
2017-01-21 13:01:39 +00:00
|
|
|
int tflags;
|
2014-11-22 18:08:25 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
/*
|
|
|
|
* Remember to close out and nullify the current
|
|
|
|
* meta-font and table, if applicable.
|
|
|
|
*/
|
|
|
|
if (tag == h->metaf)
|
|
|
|
h->metaf = NULL;
|
|
|
|
if (tag == h->tblt)
|
|
|
|
h->tblt = NULL;
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
tflags = htmltags[tag->tag].flags;
|
|
|
|
|
|
|
|
if (tflags & HTML_INDENT)
|
|
|
|
h->indent--;
|
|
|
|
if (tflags & HTML_NOINDENT)
|
|
|
|
h->noindent--;
|
|
|
|
if (tflags & HTML_NLEND)
|
|
|
|
print_endline(h);
|
|
|
|
print_indent(h);
|
|
|
|
print_byte(h, '<');
|
|
|
|
print_byte(h, '/');
|
|
|
|
print_word(h, htmltags[tag->tag].name);
|
|
|
|
print_byte(h, '>');
|
|
|
|
if (tflags & HTML_NLAFTER)
|
|
|
|
print_endline(h);
|
2015-03-02 16:45:41 +00:00
|
|
|
|
|
|
|
h->tags.head = tag->next;
|
|
|
|
free(tag);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_gen_decls(struct html *h)
|
|
|
|
{
|
2017-01-21 13:01:39 +00:00
|
|
|
print_word(h, "<!DOCTYPE html>");
|
|
|
|
print_endline(h);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_text(struct html *h, const char *word)
|
|
|
|
{
|
2017-01-21 13:01:39 +00:00
|
|
|
if (h->col && (h->flags & HTML_NOSPACE) == 0) {
|
2012-10-18 09:55:16 +00:00
|
|
|
if ( ! (HTML_KEEP & h->flags)) {
|
|
|
|
if (HTML_PREKEEP & h->flags)
|
|
|
|
h->flags |= HTML_KEEP;
|
2017-01-21 13:01:39 +00:00
|
|
|
print_endword(h);
|
2012-10-18 09:55:16 +00:00
|
|
|
} else
|
2017-01-21 13:01:39 +00:00
|
|
|
print_word(h, " ");
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(NULL == h->metaf);
|
2014-01-31 19:59:03 +00:00
|
|
|
switch (h->metac) {
|
2014-11-22 18:08:25 +00:00
|
|
|
case HTMLFONT_ITALIC:
|
2017-01-21 13:01:39 +00:00
|
|
|
h->metaf = print_otag(h, TAG_I, "");
|
2014-01-31 19:59:03 +00:00
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case HTMLFONT_BOLD:
|
2017-01-21 13:01:39 +00:00
|
|
|
h->metaf = print_otag(h, TAG_B, "");
|
2014-01-31 19:59:03 +00:00
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case HTMLFONT_BI:
|
2017-01-21 13:01:39 +00:00
|
|
|
h->metaf = print_otag(h, TAG_B, "");
|
|
|
|
print_otag(h, TAG_I, "");
|
2014-01-31 19:59:03 +00:00
|
|
|
break;
|
|
|
|
default:
|
2017-01-21 13:01:39 +00:00
|
|
|
print_indent(h);
|
2014-01-31 19:59:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
assert(word);
|
2017-01-21 13:01:39 +00:00
|
|
|
if ( ! print_encode(h, word, NULL, 0)) {
|
2012-10-18 09:55:16 +00:00
|
|
|
if ( ! (h->flags & HTML_NONOSPACE))
|
|
|
|
h->flags &= ~HTML_NOSPACE;
|
2014-12-25 21:33:25 +00:00
|
|
|
h->flags &= ~HTML_NONEWLINE;
|
2012-10-18 09:55:16 +00:00
|
|
|
} else
|
2014-12-25 21:33:25 +00:00
|
|
|
h->flags |= HTML_NOSPACE | HTML_NONEWLINE;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
if (h->metaf) {
|
|
|
|
print_tagq(h, h->metaf);
|
|
|
|
h->metaf = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
h->flags &= ~HTML_IGNDELIM;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_tagq(struct html *h, const struct tag *until)
|
|
|
|
{
|
|
|
|
struct tag *tag;
|
|
|
|
|
|
|
|
while ((tag = h->tags.head) != NULL) {
|
2015-03-02 16:45:41 +00:00
|
|
|
print_ctag(h, tag);
|
2012-10-18 09:55:16 +00:00
|
|
|
if (until && tag == until)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_stagq(struct html *h, const struct tag *suntil)
|
|
|
|
{
|
|
|
|
struct tag *tag;
|
|
|
|
|
|
|
|
while ((tag = h->tags.head) != NULL) {
|
|
|
|
if (suntil && tag == suntil)
|
|
|
|
return;
|
2015-03-02 16:45:41 +00:00
|
|
|
print_ctag(h, tag);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
void
|
|
|
|
print_paragraph(struct html *h)
|
|
|
|
{
|
|
|
|
struct tag *t;
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
t = print_otag(h, TAG_DIV, "c", "Pp");
|
2014-12-02 07:34:06 +00:00
|
|
|
print_tagq(h, t);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* Low level output functions.
|
|
|
|
* They implement line breaking using a short static buffer.
|
|
|
|
***********************************************************************/
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
/*
|
|
|
|
* Buffer one HTML output byte.
|
|
|
|
* If the buffer is full, flush and deactivate it and start a new line.
|
|
|
|
* If the buffer is inactive, print directly.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
print_byte(struct html *h, char c)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
2017-01-21 13:01:39 +00:00
|
|
|
if ((h->flags & HTML_BUFFER) == 0) {
|
|
|
|
putchar(c);
|
|
|
|
h->col++;
|
|
|
|
return;
|
|
|
|
}
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
if (h->col + h->bufcol < sizeof(h->buf)) {
|
|
|
|
h->buf[h->bufcol++] = c;
|
|
|
|
return;
|
|
|
|
}
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
putchar('\n');
|
|
|
|
h->col = 0;
|
|
|
|
print_indent(h);
|
|
|
|
putchar(' ');
|
|
|
|
putchar(' ');
|
|
|
|
fwrite(h->buf, h->bufcol, 1, stdout);
|
|
|
|
putchar(c);
|
|
|
|
h->col = (h->indent + 1) * 2 + h->bufcol + 1;
|
|
|
|
h->bufcol = 0;
|
|
|
|
h->flags &= ~HTML_BUFFER;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
/*
|
|
|
|
* If something was printed on the current output line, end it.
|
|
|
|
* Not to be called right after print_indent().
|
|
|
|
*/
|
2012-10-18 09:55:16 +00:00
|
|
|
static void
|
2017-01-21 13:01:39 +00:00
|
|
|
print_endline(struct html *h)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
2017-01-21 13:01:39 +00:00
|
|
|
if (h->col == 0)
|
|
|
|
return;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
if (h->bufcol) {
|
|
|
|
putchar(' ');
|
|
|
|
fwrite(h->buf, h->bufcol, 1, stdout);
|
|
|
|
h->bufcol = 0;
|
|
|
|
}
|
|
|
|
putchar('\n');
|
|
|
|
h->col = 0;
|
|
|
|
h->flags |= HTML_NOSPACE;
|
|
|
|
h->flags &= ~HTML_BUFFER;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
/*
|
|
|
|
* Flush the HTML output buffer.
|
|
|
|
* If it is inactive, activate it.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
print_endword(struct html *h)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
2017-01-21 13:01:39 +00:00
|
|
|
if (h->noindent) {
|
|
|
|
print_byte(h, ' ');
|
|
|
|
return;
|
|
|
|
}
|
2014-11-22 18:08:25 +00:00
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
if ((h->flags & HTML_BUFFER) == 0) {
|
|
|
|
h->col++;
|
|
|
|
h->flags |= HTML_BUFFER;
|
|
|
|
} else if (h->bufcol) {
|
|
|
|
putchar(' ');
|
|
|
|
fwrite(h->buf, h->bufcol, 1, stdout);
|
|
|
|
h->col += h->bufcol + 1;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
2017-01-21 13:01:39 +00:00
|
|
|
h->bufcol = 0;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
/*
|
|
|
|
* If at the beginning of a new output line,
|
|
|
|
* perform indentation and mark the line as containing output.
|
|
|
|
* Make sure to really produce some output right afterwards,
|
|
|
|
* but do not use print_otag() for producing it.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
print_indent(struct html *h)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
2017-01-21 13:01:39 +00:00
|
|
|
size_t i;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
if (h->col)
|
|
|
|
return;
|
2014-11-22 18:08:25 +00:00
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
if (h->noindent == 0) {
|
|
|
|
h->col = h->indent * 2;
|
|
|
|
for (i = 0; i < h->col; i++)
|
|
|
|
putchar(' ');
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
2017-01-21 13:01:39 +00:00
|
|
|
h->flags &= ~HTML_NOSPACE;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
/*
|
|
|
|
* Print or buffer some characters
|
|
|
|
* depending on the current HTML output buffer state.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
print_word(struct html *h, const char *cp)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
2017-01-21 13:01:39 +00:00
|
|
|
while (*cp != '\0')
|
|
|
|
print_byte(h, *cp++);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
/*
|
|
|
|
* Calculate the scaling unit passed in a `-width' argument. This uses
|
|
|
|
* either a native scaling unit (e.g., 1i, 2m) or the string length of
|
|
|
|
* the value.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
a2width(const char *p, struct roffsu *su)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
2017-01-21 13:01:39 +00:00
|
|
|
if (a2roffsu(p, su, SCALE_MAX) < 2) {
|
|
|
|
su->unit = SCALE_EN;
|
|
|
|
su->scale = html_strlen(p);
|
|
|
|
} else if (su->scale < 0.0)
|
|
|
|
su->scale = 0.0;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|