=================================================================== RCS file: /cvs/mandoc/out.c,v retrieving revision 1.1 retrieving revision 1.4 diff -u -p -r1.1 -r1.4 --- mandoc/out.c 2009/09/21 00:39:02 1.1 +++ mandoc/out.c 2009/10/09 06:54:11 1.4 @@ -1,4 +1,4 @@ -/* $Id: out.c,v 1.1 2009/09/21 00:39:02 kristaps Exp $ */ +/* $Id: out.c,v 1.4 2009/10/09 06:54:11 kristaps Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons * @@ -16,98 +16,111 @@ */ #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], hasd; int i; + enum roffscale unit; - assert(MDOC_BLOCK == n->type && MDOC_Bl == n->tok); - assert(n->args); + i = hasd = 0; - 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; + switch (*src) { + case ('+'): + src++; + break; + case ('-'): + buf[i++] = *src++; + break; + default: + break; + } + + while (i < BUFSIZ) { + if ( ! isdigit((u_char)*src)) { + if ('.' != *src) + break; + else if (hasd) + break; + else + hasd = 1; } + buf[i++] = *src++; + } - 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); + buf[i] = '\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); + if ((dst->scale = atof(buf)) < 0) + dst->scale = 0; + dst->unit = unit; + dst->pt = hasd; - 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); + return(1); } -