Initial release of Maemo 5 port of gnuplot
[gnuplot] / docs / doc2hlp.c
1 #ifndef lint
2 static char *RCSid() { return RCSid("$Id: doc2hlp.c,v 1.16 2005/06/03 05:11:55 sfeam Exp $"); }
3 #endif
4
5 /* GNUPLOT - doc2hlp.c */
6
7 /*[
8  * Copyright 1986 - 1993, 1998, 2004   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  * doc2hlp.c  -- program to convert Gnuplot .DOC format to
39  * VMS help (.HLP) format.
40  *
41  * This involves stripping all lines with a leading ?,
42  * @, #, or %.
43  * Modified by Russell Lang from hlp2ms.c by Thomas Williams
44  *
45  * usage:  doc2hlp [file.doc [file.hlp]]
46  *
47  * Original version by David Kotz used the following one line script!
48  * sed '/^[?@#%]/d' file.doc > file.hlp
49  */
50
51 #ifdef HAVE_CONFIG_H
52 # include "config.h"
53 #endif
54
55 #include "syscfg.h"
56 #include "stdfn.h"
57 #include "doc2x.h"
58
59 extern TBOOLEAN single_top_level;
60
61 void convert __PROTO((FILE *, FILE *));
62 void process_line __PROTO((char *, FILE *));
63
64 int
65 main (int argc, char **argv)
66 {
67     FILE *infile;
68     FILE *outfile;
69
70     infile = stdin;
71     outfile = stdout;
72
73     single_top_level = TRUE;
74
75     if (argc > 3) {
76         fprintf(stderr, "Usage: %s [infile [outfile]]\n", argv[0]);
77         exit(EXIT_FAILURE);
78     }
79     if (argc >= 2) {
80         if ((infile = fopen(argv[1], "r")) == (FILE *) NULL) {
81             fprintf(stderr, "%s: Can't open %s for reading\n",
82                     argv[0], argv[1]);
83             exit(EXIT_FAILURE);
84         }
85     }
86     if (argc == 3) {
87         if ((outfile = fopen(argv[2], "w")) == (FILE *) NULL) {
88             fprintf(stderr, "%s: Can't open %s for writing\n",
89                     argv[0], argv[2]);
90             exit(EXIT_FAILURE);
91         }
92     }
93
94     convert(infile, outfile);
95
96     return EXIT_SUCCESS;
97 }
98
99
100 void
101 convert (FILE *inf, FILE *outf)
102 {
103     static char line[MAX_LINE_LEN+1];
104
105     while (get_line(line, sizeof(line), inf))
106         process_line(line, outf);
107 }
108
109
110 void
111 process_line (char *line, FILE *b)
112 {
113     static int line_count = 0;
114
115     line_count++;
116
117     switch (line[0]) {          /* control character */
118     case '?':{                  /* interactive help entry */
119             break;              /* ignore */
120         }
121     case '@':{                  /* start/end table */
122             break;              /* ignore */
123         }
124     case '=':                   /* latex index entry */
125     case '#':{                  /* latex table entry */
126             break;              /* ignore */
127         }
128     case '%':{                  /* troff table entry */
129             break;              /* ignore */
130         }
131     case '^':{                  /* html entry */
132             break;              /* ignore */
133         }
134     case '\n':                  /* empty text line */
135     case ' ':{                  /* normal text line */
136             (void) fputs(line, b);
137             break;
138         }
139     default:{
140             if (isdigit((int)line[0])) { /* start of section */
141                 (void) fputs(line, b);
142             } else
143                 fprintf(stderr, "unknown control code '%c' in column 1, line %d\n",
144                         line[0], line_count);
145             break;
146         }
147     }
148 }