Annotation of mandoc/out.c, Revision 1.4
1.4 ! kristaps 1: /* $Id: out.c,v 1.3 2009/10/07 12:35:24 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.4 ! kristaps 49: char buf[BUFSIZ], hasd;
1.1 kristaps 50: int i;
1.3 kristaps 51: enum roffscale unit;
1.1 kristaps 52:
1.4 ! kristaps 53: i = hasd = 0;
! 54:
! 55: switch (*src) {
! 56: case ('+'):
! 57: src++;
! 58: break;
! 59: case ('-'):
! 60: buf[i++] = *src++;
! 61: break;
! 62: default:
! 63: break;
! 64: }
! 65:
! 66: while (i < BUFSIZ) {
! 67: if ( ! isdigit((u_char)*src)) {
! 68: if ('.' != *src)
! 69: break;
! 70: else if (hasd)
! 71: break;
! 72: else
! 73: hasd = 1;
! 74: }
! 75: buf[i++] = *src++;
! 76: }
1.1 kristaps 77:
1.3 kristaps 78: if (BUFSIZ == i || (*src && *(src + 1)))
1.1 kristaps 79: return(0);
80:
1.4 ! kristaps 81: buf[i] = '\0';
1.1 kristaps 82:
1.3 kristaps 83: switch (*src) {
84: case ('c'):
85: unit = SCALE_CM;
86: break;
87: case ('i'):
88: unit = SCALE_IN;
89: break;
90: case ('P'):
91: unit = SCALE_PC;
92: break;
93: case ('p'):
94: unit = SCALE_PT;
95: break;
96: case ('f'):
97: unit = SCALE_FS;
98: break;
99: case ('v'):
100: unit = SCALE_VS;
101: break;
102: case ('m'):
103: unit = SCALE_EM;
104: break;
105: case ('\0'):
106: /* FALLTHROUGH */
107: case ('u'):
108: unit = SCALE_BU;
109: break;
110: case ('M'):
111: unit = SCALE_MM;
112: break;
113: case ('n'):
114: unit = SCALE_EN;
115: break;
116: default:
1.1 kristaps 117: return(0);
1.3 kristaps 118: }
1.1 kristaps 119:
1.4 ! kristaps 120: if ((dst->scale = atof(buf)) < 0)
1.3 kristaps 121: dst->scale = 0;
122: dst->unit = unit;
1.4 ! kristaps 123: dst->pt = hasd;
! 124:
1.3 kristaps 125: return(1);
1.1 kristaps 126: }
CVSweb