1 /* GNUPLOT - doc2hlp.c */
2 
3 /*[
4  * Copyright 1986 - 1993, 1998, 2004   Thomas Williams, Colin Kelley
5  *
6  * Permission to use, copy, and distribute this software and its
7  * documentation for any purpose with or without fee is hereby granted,
8  * provided that the above copyright notice appear in all copies and
9  * that both that copyright notice and this permission notice appear
10  * in supporting documentation.
11  *
12  * Permission to modify the software is granted, but not the right to
13  * distribute the complete modified source code.  Modifications are to
14  * be distributed as patches to the released version.  Permission to
15  * distribute binaries produced by compiling modified sources is granted,
16  * provided you
17  *   1. distribute the corresponding source modifications from the
18  *    released version in the form of a patch file along with the binaries,
19  *   2. add special version identification to distinguish your version
20  *    in addition to the base release version number,
21  *   3. provide your name and address as the primary contact for the
22  *    support of your modified version, and
23  *   4. retain our contact information in regard to use of the base
24  *    software.
25  * Permission to distribute the released version of the source code along
26  * with corresponding source modifications in the form of a patch file is
27  * granted with same provisions 2 through 4 for binary distributions.
28  *
29  * This software is provided "as is" without express or implied warranty
30  * to the extent permitted by applicable law.
31 ]*/
32 
33 /*
34  * doc2hlp.c  -- program to convert Gnuplot .DOC format to
35  * VMS help (.HLP) format.
36  *
37  * This involves stripping all lines with a leading ?,
38  * @, #, or %.
39  * Modified by Russell Lang from hlp2ms.c by Thomas Williams
40  *
41  * usage:  doc2hlp [file.doc [file.hlp]]
42  *
43  * Original version by David Kotz used the following one line script!
44  * sed '/^[?@#%]/d' file.doc > file.hlp
45  */
46 
47 #ifdef HAVE_CONFIG_H
48 # include "config.h"
49 #endif
50 
51 #include "syscfg.h"
52 #include "stdfn.h"
53 #include "doc2x.h"
54 
55 extern TBOOLEAN single_top_level;
56 
57 void convert(FILE *, FILE *);
58 void process_line(char *, FILE *);
59 
60 int
main(int argc,char ** argv)61 main (int argc, char **argv)
62 {
63     FILE *infile;
64     FILE *outfile;
65 
66     infile = stdin;
67     outfile = stdout;
68 
69     single_top_level = TRUE;
70 
71     if (argc > 3) {
72 	fprintf(stderr, "Usage: %s [infile [outfile]]\n", argv[0]);
73 	exit(EXIT_FAILURE);
74     }
75     if (argc >= 2) {
76 	if ((infile = fopen(argv[1], "r")) == (FILE *) NULL) {
77 	    fprintf(stderr, "%s: Can't open %s for reading\n",
78 		    argv[0], argv[1]);
79 	    exit(EXIT_FAILURE);
80 	}
81     }
82     if (argc == 3) {
83 	if ((outfile = fopen(argv[2], "w")) == (FILE *) NULL) {
84 	    fprintf(stderr, "%s: Can't open %s for writing\n",
85 		    argv[0], argv[2]);
86 	    exit(EXIT_FAILURE);
87 	}
88     }
89 
90     convert(infile, outfile);
91 
92     return EXIT_SUCCESS;
93 }
94 
95 
96 void
convert(FILE * inf,FILE * outf)97 convert (FILE *inf, FILE *outf)
98 {
99     static char line[MAX_LINE_LEN+1];
100 
101     while (get_line(line, sizeof(line), inf))
102         process_line(line, outf);
103 }
104 
105 
106 void
process_line(char * line,FILE * b)107 process_line (char *line, FILE *b)
108 {
109     static int line_count = 0;
110 
111     line_count++;
112 
113     switch (line[0]) {		/* control character */
114     case '?':{			/* interactive help entry */
115 	    break;		/* ignore */
116 	}
117     case '@':{			/* start/end table */
118 	    break;		/* ignore */
119 	}
120     case '=':			/* latex index entry */
121     case 'F':			/* latex embedded figure */
122     case '#':{			/* latex table entry */
123 	    break;		/* ignore */
124 	}
125     case '%':{			/* troff table entry */
126 	    break;		/* ignore */
127 	}
128     case '^':{			/* html entry */
129 	    break;		/* ignore */
130 	}
131     case '\n':			/* empty text line */
132     case ' ':{			/* normal text line */
133 	    (void) fputs(line, b);
134 	    break;
135 	}
136     default:{
137 	    if (isdigit((int)line[0])) { /* start of section */
138 		(void) fputs(line, b);
139 	    } else
140 		fprintf(stderr, "unknown control code '%c' in column 1, line %d\n",
141 			line[0], line_count);
142 	    break;
143 	}
144     }
145 }
146