Annotation of OpenXM_contrib/gnuplot/docs/doc2ms.c, Revision 1.1.1.2
1.1 maekawa 1: #ifndef lint
1.1.1.2 ! maekawa 2: static char *RCSid = "$Id: doc2ms.c,v 1.9 1998/10/19 13:17:49 lhecking Exp $";
1.1 maekawa 3: #endif
4:
5: /* GNUPLOT - doc2ms.c */
6:
7: /*[
8: * Copyright 1986 - 1993, 1998 Thomas Williams, Colin Kelley
9: *
10: * Permission to use, copy, and distribute this software and its
11: * documentation for any purpose with or without fee is hereby granted,
12: * provided that the above copyright notice appear in all copies and
13: * that both that copyright notice and this permission notice appear
14: * in supporting documentation.
15: *
16: * Permission to modify the software is granted, but not the right to
17: * distribute the complete modified source code. Modifications are to
18: * be distributed as patches to the released version. Permission to
19: * distribute binaries produced by compiling modified sources is granted,
20: * provided you
21: * 1. distribute the corresponding source modifications from the
22: * released version in the form of a patch file along with the binaries,
23: * 2. add special version identification to distinguish your version
24: * in addition to the base release version number,
25: * 3. provide your name and address as the primary contact for the
26: * support of your modified version, and
27: * 4. retain our contact information in regard to use of the base
28: * software.
29: * Permission to distribute the released version of the source code along
30: * with corresponding source modifications in the form of a patch file is
31: * granted with same provisions 2 through 4 for binary distributions.
32: *
33: * This software is provided "as is" without express or implied warranty
34: * to the extent permitted by applicable law.
35: ]*/
36:
37: /*
38: * doc2ms.c -- program to convert Gnuplot .DOC format to *roff -ms document
39: * From hlp2ms by Thomas Williams
40: *
41: * Modified by Russell Lang, 2nd October 1989
42: * to make vms help level 1 and 2 create the same ms section level.
43: *
44: * Modified to become doc2ms by David Kotz (David.Kotz@Dartmouth.edu) 12/89
45: * Added table and backquote support.
46: *
47: * usage: doc2ms [file.doc [file.ms]]
48: *
49: * where file.doc is a VMS .DOC file, and file.ms will be a [nt]roff
50: * document suitable for printing with nroff -ms or troff -ms
51: *
52: * typical usage for GNUPLOT:
53: *
54: * doc2ms gnuplot.doc | tbl | eqn | troff -ms
55: *
56: * or
57: *
58: * doc2ms gnuplot.doc | groff -ms -et >gnuplot.ps
59: */
60:
61: #ifdef HAVE_CONFIG_H
62: # include "config.h"
63: #endif
64:
65: #include "ansichek.h"
66: #include "stdfn.h"
67: #include "doc2x.h"
68:
69: #define LINE_SKIP 3
70:
71: void init __PROTO((FILE *));
72: void convert __PROTO((FILE *, FILE *));
73: void process_line __PROTO((char *, FILE *));
74: void section __PROTO((char *, FILE *));
75: void putms __PROTO((char *, FILE *));
76: void putms_verb __PROTO((char *, FILE *));
77: void finish __PROTO((FILE *));
78:
79: static boolean intable = FALSE;
80:
81: int main(argc, argv)
82: int argc;
83: char **argv;
84: {
85: FILE *infile;
86: FILE *outfile;
87: infile = stdin;
88: outfile = stdout;
89: if (argc > 3) {
90: fprintf(stderr, "Usage: %s [infile [outfile]]\n", argv[0]);
91: exit(EXIT_FAILURE);
92: }
93: if (argc >= 2) {
94: if ((infile = fopen(argv[1], "r")) == (FILE *) NULL) {
95: fprintf(stderr, "%s: Can't open %s for reading\n",
96: argv[0], argv[1]);
97: exit(EXIT_FAILURE);
98: }
99: }
100: if (argc == 3) {
101: if ((outfile = fopen(argv[2], "w")) == (FILE *) NULL) {
102: fprintf(stderr, "%s: Can't open %s for writing\n",
103: argv[0], argv[2]);
104: exit(EXIT_FAILURE);
105: }
106: }
107: init(outfile);
108: convert(infile, outfile);
109: finish(outfile);
110: exit(EXIT_SUCCESS);
111: }
112:
113:
114: void init(b)
115: FILE *b;
116: {
117: /* in nroff, increase line length by 8 and don't adjust lines */
118: (void) fputs(".if n \\{.nr LL +8m\n.na \\}\n\
119: .nr PO +0.3i\n\
120: .so titlepag.ms\n\
121: .pn 1\n\
122: .bp\n\
123: .ta 1.5i 3.0i 4.5i 6.0i 7.5i\n\
124: \\&\n.sp 3\n.PP\n", b);
125:
126: /* following line commented out by rjl
127: (void) fputs(".so intro\n",b);
128: */
129: }
130:
131:
132: void convert(a, b)
133: FILE *a, *b;
134: {
135: static char line[MAX_LINE_LEN+1];
136:
137: while (get_line(line, sizeof(line), a)) {
138: process_line(line, b);
139: }
140: }
141:
142: void process_line(line, b)
143: char *line;
144: FILE *b;
145: {
146: switch (line[0]) { /* control character */
147: case '?':{ /* interactive help entry */
148: break; /* ignore */
149: }
150: case '@':{ /* start/end table */
151: if (intable) {
152: (void) fputs(".TE\n.KE\n", b);
153: (void) fputs(".EQ\ndelim off\n.EN\n\n", b);
154: intable = FALSE;
155: } else {
156: (void) fputs("\n.EQ\ndelim $$\n.EN\n", b);
157: (void) fputs(".KS\n.TS\ncenter box tab (@) ;\n", b);
158: /* moved to gnuplot.doc by RCC
159: (void) fputs("c c l .\n", b);
160: */
161: intable = TRUE;
162: }
163: /* ignore rest of line */
164: break;
165: }
166: case '^':{ /* html table entry */
167: break; /* ignore */
168: }
169: case '#':{ /* latex table entry */
170: break; /* ignore */
171: }
172: case '%':{ /* troff table entry */
173: if (intable)
174: (void) fputs(line + 1, b); /* copy directly */
175: else
176: fprintf(stderr, "error: %% line found outside of table\n");
177: break;
178: }
179: case '\n': /* empty text line */
180: case ' ':{ /* normal text line */
181: if (intable)
182: break; /* ignore while in table */
183: switch (line[1]) {
184: case ' ':{
185: /* verbatim mode */
186: fputs(".br\n", b);
187: putms_verb(line + 1, b);
188: fputs(".br\n", b);
189: break;
190: }
191: case '\'':{
192: fputs("\\&", b);
193: putms(line + 1, b);
194: break;
195: }
196: case '.':{ /* hide leading . from ms */
197: fputs("\\&", b);
198: putms(line + 1, b);
199: break;
200: }
201: default:{
202: if (line[0] == '\n')
203: putms(line, b); /* handle totally blank line */
204: else
205: putms(line + 1, b);
206: break;
207: }
208: break;
209: }
210: break;
211: }
212: default:{
213: if (isdigit((int)line[0])) { /* start of section */
214: if (!intable) /* ignore while in table */
215: section(line, b);
216: } else
217: fprintf(stderr, "unknown control code '%c' in column 1\n",
218: line[0]);
219: break;
220: }
221: }
222: }
223:
224:
225: /* process a line with a digit control char */
226: /* starts a new [sub]section */
227:
228: void section(line, b)
229: char *line;
230: FILE *b;
231: {
232: static char string[MAX_LINE_LEN+1];
233: int sh_i;
234: static int old = 1;
235:
236:
237: (void) sscanf(line, "%d %[^\n]s", &sh_i, string);
238:
239: (void) fprintf(b, ".sp %d\n", (sh_i == 1) ? LINE_SKIP : LINE_SKIP - 1);
240:
241: if (sh_i > old) {
242: do
243: if (old != 1) /* this line added by rjl */
244: (void) fputs(".RS\n.IP\n", b);
245: while (++old < sh_i);
246: } else if (sh_i < old) {
247: do
248: if (sh_i != 1) /* this line added by rjl */
249: (void) fputs(".RE\n.br\n", b);
250: while (--old > sh_i);
251: }
252: /* added by dfk to capitalize section headers */
253: if (islower((int)string[0]))
254: string[0] = toupper(string[0]);
255:
256: /* next 3 lines added by rjl */
257: if (sh_i != 1)
258: (void) fprintf(b, ".NH %d\n%s\n.sp 1\n.LP\n", sh_i - 1, string);
259: else
260: (void) fprintf(b, ".NH %d\n%s\n.sp 1\n.LP\n", sh_i, string);
261: old = sh_i;
262:
263: (void) fputs(".XS\n", b);
264: (void) fputs(string, b);
265: (void) fputs("\n.XE\n", b);
266: }
267:
268: void putms(s, file)
269: char *s;
270: FILE *file;
271: {
272: static boolean inquote = FALSE;
273:
274: while (*s != NUL) {
275: switch (*s) {
276: case '`':{ /* backquote -> boldface */
277: if (inquote) {
278: fputs("\\fR", file);
279: inquote = FALSE;
280: } else {
281: fputs("\\fB", file);
282: inquote = TRUE;
283: }
284: break;
285: }
286: case '\\':{ /* backslash */
287: fputs("\\\\", file);
288: break;
289: }
290: case '\'':{ /* single quote */
291: fputs("\\&'", file);
292: break;
293: }
294: default:{
295: fputc(*s, file);
296: break;
297: }
298: }
299: s++;
300: }
301: }
302:
303: /*
304: * convert a verbatim line to troff input style, i.e. convert "\" to "\\"
305: * (added by Alexander Lehmann 01/30/93)
306: */
307:
308: void putms_verb(s, file)
309: char *s;
310: FILE *file;
311: {
312: while (*s != '\0') {
313: if (*s == '\\') {
314: fputc('\\', file);
315: }
316: fputc(*s, file);
317: s++;
318: }
319: }
320:
321: void finish(b) /* spit out table of contents */
322: FILE *b;
323: {
324: (void) fputs(".pn 1\n", b);
325: (void) fputs(".ds RH %\n", b);
326: (void) fputs(".af % i\n", b);
327: (void) fputs(".bp\n.PX\n", b);
328: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>