Annotation of mandoc/out.c, Revision 1.3
1.3 ! kristaps 1: /* $Id: html.c,v 1.57 2009/10/04 09:02:40 kristaps Exp $ */
1.1 kristaps 2: /*
3: * Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
4: *
5: * Permission to use, copy, modify, and distribute this software for any
6: * purpose with or without fee is hereby granted, provided that the above
7: * copyright notice and this permission notice appear in all copies.
8: *
9: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16: */
17: #include <sys/types.h>
18:
19: #include <ctype.h>
1.3 ! kristaps 20: #include <stdio.h>
1.1 kristaps 21: #include <stdlib.h>
22:
23: #include "out.h"
24:
1.3 ! kristaps 25:
! 26: /*
! 27: * Convert a `scaling unit' to a consistent form, or fail. Scaling
! 28: * units are documented in groff.7, which stipulates the following:
! 29: *
! 30: * (1) A scaling unit is a signed/unsigned integer/float with or
! 31: * without a unit.
! 32: *
! 33: * (2) The following units exist:
! 34: * c Centimeter
! 35: * i Inch
! 36: * P Pica = 1/6 inch
! 37: * p Point = 1/72 inch
! 38: * m Em = the font size in points (width of letter m)
! 39: * M 100th of an Em
! 40: * n En = Em/2
! 41: * u Basic unit for actual output device
! 42: * v Vertical line space in basic units scaled point =
! 43: * 1/sizescale of a point (defined in font DESC file)
! 44: * f Scale by 65536.
! 45: */
1.1 kristaps 46: int
1.3 ! kristaps 47: a2roffsu(const char *src, struct roffsu *dst)
1.1 kristaps 48: {
1.3 ! kristaps 49: char buf[BUFSIZ], *p;
1.1 kristaps 50: int i;
1.3 ! kristaps 51: enum roffscale unit;
1.1 kristaps 52:
1.3 ! kristaps 53: for (p = buf, i = 0; i < BUFSIZ && isdigit((u_char)*src); i++)
! 54: *p++ = *src++;
1.1 kristaps 55:
1.3 ! kristaps 56: if (BUFSIZ == i || (*src && *(src + 1)))
1.1 kristaps 57: return(0);
58:
1.3 ! kristaps 59: *p = '\0';
1.1 kristaps 60:
1.3 ! kristaps 61: switch (*src) {
! 62: case ('c'):
! 63: unit = SCALE_CM;
! 64: break;
! 65: case ('i'):
! 66: unit = SCALE_IN;
! 67: break;
! 68: case ('P'):
! 69: unit = SCALE_PC;
! 70: break;
! 71: case ('p'):
! 72: unit = SCALE_PT;
! 73: break;
! 74: case ('f'):
! 75: unit = SCALE_FS;
! 76: break;
! 77: case ('v'):
! 78: unit = SCALE_VS;
! 79: break;
! 80: case ('m'):
! 81: unit = SCALE_EM;
! 82: break;
! 83: case ('\0'):
! 84: /* FALLTHROUGH */
! 85: case ('u'):
! 86: unit = SCALE_BU;
! 87: break;
! 88: case ('M'):
! 89: unit = SCALE_MM;
! 90: break;
! 91: case ('n'):
! 92: unit = SCALE_EN;
! 93: break;
! 94: default:
1.1 kristaps 95: return(0);
1.3 ! kristaps 96: }
1.1 kristaps 97:
1.3 ! kristaps 98: if ((dst->scale = atoi(buf)) < 0)
! 99: dst->scale = 0;
! 100: dst->unit = unit;
! 101: return(1);
1.1 kristaps 102: }
CVSweb