2 static char *RCSid() { return RCSid("$Id: doc2rnh.c,v 1.16 2005/06/03 05:11:55 sfeam Exp $"); }
5 /* GNUPLOT - doc2rnh.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 * doc2rnh.c -- program to convert Gnuplot .DOC format to
39 * Digital Standard Runoff for VMS HELP files
40 * (gnuplot.doc, including the terminal documentation
41 * is no longer formated for VMS HELP by default)
43 * From hlp2ms by Thomas Williams
45 * Modified by Russell Lang, 2nd October 1989
46 * to make vms help level 1 and 2 create the same ms section level.
48 * Modified to become doc2ms by David Kotz (David.Kotz@Dartmouth.edu) 12/89
49 * Added table and backquote support.
51 * Adapted from doc2ms.c (the unix 'runoff' text-processor)
54 * right margin is adjusted two spaces for each level to compensate
55 * for the indentation by VMS HELP
57 * the page width can be adjusted by changing the value of DSR_RM
58 * usage: $ MCR []doc2rnh gnuplot.doc gnuplot.rnh
59 * $ RUNOFF gnuplot.rnh
72 extern TBOOLEAN single_top_level;
77 void init __PROTO((FILE *));
78 void convert __PROTO((FILE *, FILE *));
79 void process_line __PROTO((char *, FILE *));
80 void section __PROTO((char *, FILE *));
81 void putrnh __PROTO((char *, FILE *));
82 void putrnh_ __PROTO((char *, FILE *));
83 void finish __PROTO((FILE *));
85 static TBOOLEAN intable = FALSE;
86 static TBOOLEAN rnh_table = FALSE;
87 static TBOOLEAN initial_entry = FALSE;
90 main (int argc, char **argv)
97 single_top_level = TRUE;
100 fprintf(stderr, "Usage: %s [infile [outfile]]\n", argv[0]);
104 if ((infile = fopen(argv[1], "r")) == (FILE *) NULL) {
105 fprintf(stderr, "%s: Can't open %s for reading\n",
111 if ((outfile = fopen(argv[2], "w")) == (FILE *) NULL) {
112 fprintf(stderr, "%s: Can't open %s for writing\n",
118 convert(infile, outfile);
138 convert(FILE *a, FILE *b)
140 static char line[MAX_LINE_LEN+1];
142 while (get_line(line, sizeof(line), a)) {
143 process_line(line, b);
148 process_line(char *line, FILE *b)
150 switch (line[0]) { /* control character */
151 case '?':{ /* interactive help entry */
154 case '@':{ /* start/end table */
156 (void) fputs(".end literal\n", b);
160 /* (void) fputs(".literal\n",b); */
163 initial_entry = TRUE;
165 /* ignore rest of line */
168 case '^':{ /* html table entry */
171 case '=': /* latex index entry */
172 case '#':{ /* latex table entry */
175 case '%':{ /* troff table entry */
179 /* 'C' is taken care of by termdoc.c */
180 case 'C':{ /* new Comment designator */
184 case '\n': /* empty text line */
185 case ' ':{ /* normal text line */
187 /* most tables are simple; no flags means no protected characters
188 * other than period (command indicator) in first column
190 * However, for ease of maintainence, two tables have sublevels
191 * and descriptions, corresponding to the printed table entries,
192 * encapsulated by the table markers. Therefore we need to
195 * Doc2hlp just ignores the table headings and treats
196 * lower levels irrespectively, but we need to break
197 * the level designators out of the table format.
199 * The first entry in a table will have either
200 * - a level number in the first column => remainder of text in
202 * - spaces in the first two columns => rest of text is literal
203 * to be placed in table format
207 /* use the "cleartext" table or other text in tables */
209 /* if (intable) { */ /* its already literal */
210 if (rnh_table) { /* its a literal */
216 if ((intable) && (initial_entry)) {
218 initial_entry = FALSE;
219 fputs(".literal\n", b);
224 fputs(".literal\n", b);
226 fputs(".end literal\n", b);
231 * "." in first column is the DSR command character;
232 * therefore, include the preceeding " "
240 fputs(".skip\n", b); /* totally blank line */
250 if (isdigit((int) line[0])) { /* start of section */
252 /* some HELP text is surrounded by table flags */
253 /* doc2rnh will ignore the flags */
257 initial_entry = FALSE;
263 fprintf(stderr, "unknown control code '%c' in column 1\n",
271 /* process a line with a digit control char */
272 /* starts a new [sub]section */
273 /* We want to retain section number, so its simpler than w/ TeX or roff */
276 section(char *line, FILE *b)
281 (void) sscanf(line,"%d",&sh_i);
283 * check to make sure this works with terminals also
289 if (old != 1) /* this line added by rjl */
290 (void) fputs(".rm-2\n", b);
291 while (++old < sh_i);
292 } else if (sh_i < old) {
294 if (sh_i != 1) /* this line added by rjl */
295 (void) fputs(".rm+2\n", b);
296 while (--old > sh_i);
298 /* added by dfk to capitalize section headers */
299 /* Header name starts at [2] */
300 /* omit for online documentation
301 * if (islower(line[2]))
302 * line[2] = toupper(line[2]);
306 (void) fputs(".indent -1;\n", b);
307 (void) putrnh_(line, b);
308 (void) fputs(".br;\n", b);
312 * dummy function in case we need to convert some characters in
313 * output string ala doc2tex and doc2ms
317 putrnh(char *s, FILE *file)
319 (void) fputs(s, file);
323 * LBR$OUTPUT_HELP treats spaces and "/"s as list separators for topics,
324 * but they are used in gnuplot.doc for the printed docs; convert to
325 * "_" and "|" Modeled after section heading conversions in doc2tex
331 putrnh_(char *s, FILE *file)
333 int i, s_len, last_chr;
335 last_chr = s_len = strlen(s);
337 for (i = s_len - 1; i > 2; i--) { /* any trailing spaces to drop? */
344 for (i = 0; i <= last_chr; i++) {
348 (void) fputc('_', file);
351 (void) fputc('|', file);
354 (void) fputc(s[i], file);
357 (void) fputc(s[i], file);