=================================================================== RCS file: /cvs/mandoc/out.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -p -r1.2 -r1.3 --- mandoc/out.c 2009/09/21 13:06:13 1.2 +++ mandoc/out.c 2009/10/07 12:35:24 1.3 @@ -1,4 +1,4 @@ -/* $Id: out.c,v 1.2 2009/09/21 13:06:13 kristaps dead $ */ +/* $Id: out.c,v 1.3 2009/10/07 12:35:24 kristaps Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons * @@ -16,98 +16,87 @@ */ #include -#include #include +#include #include -#include -#include "mdoc.h" -#include "man.h" #include "out.h" + +/* + * Convert a `scaling unit' to a consistent form, or fail. Scaling + * units are documented in groff.7, which stipulates the following: + * + * (1) A scaling unit is a signed/unsigned integer/float with or + * without a unit. + * + * (2) The following units exist: + * c Centimeter + * i Inch + * P Pica = 1/6 inch + * p Point = 1/72 inch + * m Em = the font size in points (width of letter m) + * M 100th of an Em + * n En = Em/2 + * u Basic unit for actual output device + * v Vertical line space in basic units scaled point = + * 1/sizescale of a point (defined in font DESC file) + * f Scale by 65536. + */ int -out_a2list(const struct mdoc_node *n) +a2roffsu(const char *src, struct roffsu *dst) { + char buf[BUFSIZ], *p; int i; + enum roffscale unit; - assert(MDOC_BLOCK == n->type && MDOC_Bl == n->tok); - assert(n->args); + for (p = buf, i = 0; i < BUFSIZ && isdigit((u_char)*src); i++) + *p++ = *src++; - for (i = 0; i < (int)n->args->argc; i++) - switch (n->args->argv[i].arg) { - case (MDOC_Enum): - /* FALLTHROUGH */ - case (MDOC_Dash): - /* FALLTHROUGH */ - case (MDOC_Hyphen): - /* FALLTHROUGH */ - case (MDOC_Bullet): - /* FALLTHROUGH */ - case (MDOC_Tag): - /* FALLTHROUGH */ - case (MDOC_Hang): - /* FALLTHROUGH */ - case (MDOC_Inset): - /* FALLTHROUGH */ - case (MDOC_Diag): - /* FALLTHROUGH */ - case (MDOC_Item): - /* FALLTHROUGH */ - case (MDOC_Column): - /* FALLTHROUGH */ - case (MDOC_Ohang): - return(n->args->argv[i].arg); - default: - break; - } - - abort(); - /* NOTREACHED */ -} - - -int -out_a2width(const char *p) -{ - int i, len; - - if (0 == (len = (int)strlen(p))) + if (BUFSIZ == i || (*src && *(src + 1))) 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(atoi(p) + 2); + *p = '\0'; - return(len + 2); -} - - -int -out_a2offs(const char *p, int indent) -{ - int len, i; - - if (0 == strcmp(p, "left")) + switch (*src) { + case ('c'): + unit = SCALE_CM; + break; + case ('i'): + unit = SCALE_IN; + break; + case ('P'): + unit = SCALE_PC; + break; + case ('p'): + unit = SCALE_PT; + break; + case ('f'): + unit = SCALE_FS; + break; + case ('v'): + unit = SCALE_VS; + break; + case ('m'): + unit = SCALE_EM; + break; + case ('\0'): + /* FALLTHROUGH */ + case ('u'): + unit = SCALE_BU; + break; + case ('M'): + unit = SCALE_MM; + break; + case ('n'): + unit = SCALE_EN; + break; + default: return(0); - if (0 == strcmp(p, "indent")) - return(indent + 1); - if (0 == strcmp(p, "indent-two")) - return((indent + 1) * 2); + } - 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(atoi(p)); - - return(len); + if ((dst->scale = atoi(buf)) < 0) + dst->scale = 0; + dst->unit = unit; + return(1); } -