2 static char *RCSid() { return RCSid("$Id: doc2ms.c,v 1.18 2005/06/03 05:11:55 sfeam Exp $"); }
5 /* GNUPLOT - doc2ms.c */
8 * Copyright 1986 - 1993, 1998, 2004 Thomas Williams, Colin Kelley
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.
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,
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
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.
33 * This software is provided "as is" without express or implied warranty
34 * to the extent permitted by applicable law.
38 * doc2ms.c -- program to convert Gnuplot .DOC format to *roff -ms document
39 * From hlp2ms by Thomas Williams
41 * Modified by Russell Lang, 2nd October 1989
42 * to make vms help level 1 and 2 create the same ms section level.
44 * Modified to become doc2ms by David Kotz (David.Kotz@Dartmouth.edu) 12/89
45 * Added table and backquote support.
47 * usage: doc2ms [file.doc [file.ms]]
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
52 * typical usage for GNUPLOT:
54 * doc2ms gnuplot.doc | tbl | eqn | troff -ms
58 * doc2ms gnuplot.doc | groff -ms -et >gnuplot.ps
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 *));
79 static TBOOLEAN intable = FALSE;
82 main (int argc, char **argv)
89 fprintf(stderr, "Usage: %s [infile [outfile]]\n", argv[0]);
93 if ((infile = fopen(argv[1], "r")) == (FILE *) NULL) {
94 fprintf(stderr, "%s: Can't open %s for reading\n",
100 if ((outfile = fopen(argv[2], "w")) == (FILE *) NULL) {
101 fprintf(stderr, "%s: Can't open %s for writing\n",
107 convert(infile, outfile);
116 /* in nroff, increase line length by 8 and don't adjust lines */
117 (void) fputs(".if n \\{.nr LL +8m\n.na \\}\n\
122 .ta 1.5i 3.0i 4.5i 6.0i 7.5i\n\
123 \\&\n.sp 3\n.PP\n", b);
125 /* following line commented out by rjl
126 (void) fputs(".so intro\n",b);
132 convert( FILE *a, FILE *b)
134 static char line[MAX_LINE_LEN+1];
136 while (get_line(line, sizeof(line), a)) {
137 process_line(line, b);
142 process_line( char *line, FILE *b)
144 switch (line[0]) { /* control character */
145 case '?':{ /* interactive help entry */
148 case '@':{ /* start/end table */
150 (void) fputs(".TE\n.KE\n", b);
151 (void) fputs(".EQ\ndelim off\n.EN\n\n", b);
154 (void) fputs("\n.EQ\ndelim $$\n.EN\n", b);
155 (void) fputs(".KS\n.TS\ncenter box tab (@) ;\n", b);
156 /* moved to gnuplot.doc by RCC
157 (void) fputs("c c l .\n", b);
161 /* ignore rest of line */
164 case '^':{ /* html table entry */
167 case '=': /* latex index entry */
168 case '#':{ /* latex table entry */
171 case '%':{ /* troff table entry */
173 (void) fputs(line + 1, b); /* copy directly */
175 fprintf(stderr, "error: %% line found outside of table\n");
178 case '\n': /* empty text line */
179 case ' ':{ /* normal text line */
181 break; /* ignore while in table */
186 putms_verb(line + 1, b);
195 case '.':{ /* hide leading . from ms */
202 putms(line, b); /* handle totally blank line */
212 if (isdigit((int)line[0])) { /* start of section */
213 if (!intable) /* ignore while in table */
216 fprintf(stderr, "unknown control code '%c' in column 1\n",
224 /* process a line with a digit control char */
225 /* starts a new [sub]section */
228 section( char *line, FILE *b)
230 static char string[MAX_LINE_LEN+1];
235 (void) sscanf(line, "%d %[^\n]s", &sh_i, string);
237 (void) fprintf(b, ".sp %d\n", (sh_i == 1) ? LINE_SKIP : LINE_SKIP - 1);
241 if (old != 1) /* this line added by rjl */
242 (void) fputs(".RS\n.IP\n", b);
243 while (++old < sh_i);
244 } else if (sh_i < old) {
246 if (sh_i != 1) /* this line added by rjl */
247 (void) fputs(".RE\n.br\n", b);
248 while (--old > sh_i);
250 /* added by dfk to capitalize section headers */
251 if (islower((int)string[0]))
252 string[0] = toupper(string[0]);
254 /* next 3 lines added by rjl */
256 (void) fprintf(b, ".NH %d\n%s\n.sp 1\n.LP\n", sh_i - 1, string);
258 (void) fprintf(b, ".NH %d\n%s\n.sp 1\n.LP\n", sh_i, string);
261 (void) fputs(".XS\n", b);
262 (void) fputs(string, b);
263 (void) fputs("\n.XE\n", b);
267 putms( char *s, FILE *file)
269 static TBOOLEAN inquote = FALSE;
273 case '`':{ /* backquote -> boldface */
283 case '\\':{ /* backslash */
287 case '\'':{ /* single quote */
301 * convert a verbatim line to troff input style, i.e. convert "\" to "\\"
302 * (added by Alexander Lehmann 01/30/93)
306 putms_verb( char *s, FILE *file)
317 /* spit out table of contents */