Initial release of Maemo 5 port of gnuplot
[gnuplot] / docs / checkdoc.c
1 #ifndef lint
2 static char *RCSid() { return RCSid("$Id: checkdoc.c,v 1.14 2005/06/28 22:37:31 sfeam Exp $"); }
3 #endif
4
5 /* GNUPLOT - checkdoc.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  * checkdoc -- check a doc file for correctness of first column.
39  *
40  * Prints out lines that have an illegal first character.
41  * First character must be space, digit, or ?, @, #, %,
42  * or line must be empty.
43  *
44  * usage: checkdoc [docfile]
45  * Modified by Russell Lang from hlp2ms.c by Thomas Williams
46  *
47  * Original version by David Kotz used the following one line script!
48  * sed -e '/^$/d' -e '/^[ 0-9?@#%]/d' gnuplot.doc
49  *
50  */
51
52 #ifdef HAVE_CONFIG_H
53 # include "config.h"
54 #endif
55
56 #include "syscfg.h"
57 #include "stdfn.h"
58 #include "doc2x.h"
59
60 void convert __PROTO((FILE *, FILE *));
61 void process_line __PROTO((char *, FILE *));
62
63 int
64 main (int argc, char **argv)
65 {
66     FILE *infile;
67     infile = stdin;
68
69     if (argc > 2) {
70         fprintf(stderr, "Usage: %s [infile]\n", argv[0]);
71         exit(EXIT_FAILURE);
72     }
73     if (argc == 2)
74         if ((infile = fopen(argv[1], "r")) == (FILE *) NULL) {
75             fprintf(stderr, "%s: Can't open %s for reading\n",
76                     argv[0], argv[1]);
77             exit(EXIT_FAILURE);
78         }
79     convert(infile, stdout);
80     return EXIT_SUCCESS;
81 }
82
83 void
84 convert(FILE *a, FILE *b)
85 {
86     static char line[MAX_LINE_LEN+1];
87
88     while (get_line(line, sizeof(line), a)) {
89         process_line(line, b);
90     }
91 }
92
93 void
94 process_line(char *line, FILE *b)
95 {
96     /* check matching backticks within a paragraph */
97
98     static int count = 0;
99
100     if (line[0] == ' ') {
101         char *p = line;
102
103         /* skip/count leading spaces */
104
105         while (*++p == ' ');
106
107         if (*p == '\n') {
108             /* it is not clear if this is an error, but it is an
109              * inconsistency, so flag it
110              */
111             fprintf(b, "spaces-only line %s:%d\n", termdoc_filename, termdoc_lineno);
112         } else {
113             /* accumulate count of backticks. Do not check odd-ness
114              * until end of paragraph (non-space in column 1)
115              */
116             for (; *p; ++p)
117                 if (*p == '`')
118                     ++count;
119         }
120     } else {
121         if (count & 1) {
122             fprintf(b,
123                     "mismatching backticks before %s:%d\n",
124                     termdoc_filename, termdoc_lineno);
125         }
126         count = 0;
127     }
128
129     if (strchr(line, '\t'))
130         fprintf(b, "tab character in line %s:%d\n", termdoc_filename, termdoc_lineno);
131
132     switch (line[0]) {          /* control character */
133     case '?':{                  /* interactive help entry */
134             break;              /* ignore */
135         }
136     case '<':{                  /* term docs */
137             break;              /* ignore */
138         }
139     case '@':{                  /* start/end table */
140             break;              /* ignore */
141         }
142     case '#':{                  /* latex table entry */
143             break;              /* ignore */
144         }
145     case '%':{                  /* troff table entry */
146             break;              /* ignore */
147         }
148     case '^':{                  /* html entry */
149             break;              /* ignore */
150         }
151     case '=':{                  /* index entry */
152             break;              /* ignore */
153         }
154     case '\n':                  /* empty text line */
155     case ' ':{                  /* normal text line */
156             break;
157         }
158     default:{
159             if (isdigit((int)line[0])) {        /* start of section */
160                 /* ignore */
161             } else
162                 /* output bad line */
163                 fprintf(b, "%s:%d:%s", termdoc_filename, termdoc_lineno, line);
164             break;
165         }
166     }
167 }