42260
|
1 /* Give this program DOC-mm.nn.oo as standard input and it outputs to
|
36226
|
2 standard output a file of texinfo input containing the doc strings.
|
42439
|
3
|
36226
|
4 Copyright (C) 1989, 1992, 1994, 1996, 1999, 2000, 2001
|
|
5 Free Software Foundation Inc.
|
|
6
|
|
7 This file is part of GNU Emacs.
|
|
8
|
|
9 GNU Emacs is free software; you can redistribute it and/or modify
|
|
10 it under the terms of the GNU General Public License as published by
|
|
11 the Free Software Foundation; either version 2, or (at your option)
|
|
12 any later version.
|
|
13
|
|
14 GNU Emacs is distributed in the hope that it will be useful,
|
|
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 GNU General Public License for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
42258
|
20 along with GNU Emacs; see the file COPYING. If not, write to the
|
64083
|
21 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
22 Boston, MA 02110-1301, USA.
|
42258
|
23
|
36226
|
24 This version sorts the output by function name. */
|
29
|
25
|
42412
|
26 #ifdef HAVE_CONFIG_H
|
|
27 #include <config.h>
|
|
28 #endif
|
|
29
|
29
|
30 #include <stdio.h>
|
|
31 #include <ctype.h>
|
31884
|
32 #ifndef HAVE_STDLIB_H /* config.h includes stdlib. */
|
29
|
33 extern char *malloc ();
|
31884
|
34 #endif
|
29
|
35
|
|
36 #define NUL '\0'
|
|
37 #define MARKER '\037'
|
|
38
|
|
39 #define DEBUG 0
|
|
40
|
|
41 typedef struct line LINE;
|
|
42
|
|
43 struct line
|
|
44 {
|
|
45 LINE *next; /* ptr to next or NULL */
|
|
46 char *line; /* text of the line */
|
|
47 };
|
|
48
|
|
49 typedef struct docstr DOCSTR;
|
|
50
|
|
51 struct docstr /* Allocated thing for an entry. */
|
|
52 {
|
|
53 DOCSTR *next; /* next in the chain */
|
|
54 char *name; /* name of the function or var */
|
|
55 LINE *first; /* first line of doc text. */
|
|
56 char type; /* 'F' for function, 'V' for variable */
|
|
57 };
|
|
58
|
|
59
|
|
60 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
|
|
61
|
9491
|
62 void
|
29
|
63 error (s1, s2)
|
|
64 char *s1, *s2;
|
|
65 {
|
|
66 fprintf (stderr, "sorted-doc: ");
|
|
67 fprintf (stderr, s1, s2);
|
|
68 fprintf (stderr, "\n");
|
|
69 }
|
|
70
|
9491
|
71 /* Print error message and exit. */
|
|
72
|
|
73 void
|
|
74 fatal (s1, s2)
|
|
75 char *s1, *s2;
|
|
76 {
|
|
77 error (s1, s2);
|
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
diff
changeset
|
78 exit (EXIT_FAILURE);
|
9491
|
79 }
|
|
80
|
29
|
81 /* Like malloc but get fatal error if memory is exhausted. */
|
|
82
|
|
83 char *
|
|
84 xmalloc (size)
|
|
85 int size;
|
|
86 {
|
|
87 char *result = malloc ((unsigned)size);
|
|
88 if (result == NULL)
|
|
89 fatal ("%s", "virtual memory exhausted");
|
|
90 return result;
|
|
91 }
|
|
92
|
|
93 char *
|
9491
|
94 xstrdup (str)
|
29
|
95 char * str;
|
|
96 {
|
|
97 char *buf = xmalloc (strlen (str) + 1);
|
|
98 (void) strcpy (buf, str);
|
|
99 return (buf);
|
|
100 }
|
|
101
|
|
102 /* Comparison function for qsort to call. */
|
|
103
|
|
104 int
|
|
105 cmpdoc (a, b)
|
|
106 DOCSTR **a;
|
|
107 DOCSTR **b;
|
|
108 {
|
|
109 register int val = strcmp ((*a)->name, (*b)->name);
|
|
110 if (val) return val;
|
|
111 return (*a)->type - (*b)->type;
|
|
112 }
|
|
113
|
|
114
|
|
115 enum state
|
|
116 {
|
|
117 WAITING, BEG_NAME, NAME_GET, BEG_DESC, DESC_GET
|
|
118 };
|
|
119
|
|
120 char *states[] =
|
|
121 {
|
|
122 "WAITING", "BEG_NAME", "NAME_GET", "BEG_DESC", "DESC_GET"
|
|
123 };
|
42439
|
124
|
9491
|
125 int
|
29
|
126 main ()
|
|
127 {
|
|
128 register DOCSTR *dp = NULL; /* allocated DOCSTR */
|
|
129 register LINE *lp = NULL; /* allocated line */
|
|
130 register char *bp; /* ptr inside line buffer */
|
|
131 register enum state state = WAITING; /* state at start */
|
|
132 int cnt = 0; /* number of DOCSTRs read */
|
|
133
|
|
134 DOCSTR *docs; /* chain of allocated DOCSTRS */
|
|
135 char buf[512]; /* line buffer */
|
42439
|
136
|
29
|
137 while (1) /* process one char at a time */
|
|
138 {
|
|
139 /* this char from the DOCSTR file */
|
|
140 register int ch = getchar ();
|
|
141
|
|
142 /* Beginnings */
|
|
143
|
|
144 if (state == WAITING)
|
|
145 {
|
|
146 if (ch == MARKER)
|
|
147 state = BEG_NAME;
|
|
148 }
|
|
149 else if (state == BEG_NAME)
|
|
150 {
|
|
151 cnt++;
|
|
152 if (dp == NULL) /* first dp allocated */
|
|
153 {
|
|
154 docs = dp = (DOCSTR*) xmalloc (sizeof (DOCSTR));
|
|
155 }
|
|
156 else /* all the rest */
|
|
157 {
|
|
158 dp->next = (DOCSTR*) xmalloc (sizeof (DOCSTR));
|
|
159 dp = dp->next;
|
|
160 }
|
|
161 lp = NULL;
|
|
162 dp->next = NULL;
|
|
163 bp = buf;
|
|
164 state = NAME_GET;
|
|
165 /* Record whether function or variable. */
|
|
166 dp->type = ch;
|
|
167 ch = getchar ();
|
|
168 }
|
|
169 else if (state == BEG_DESC)
|
|
170 {
|
|
171 if (lp == NULL) /* first line for dp */
|
|
172 {
|
|
173 dp->first = lp = (LINE*)xmalloc (sizeof (LINE));
|
|
174 }
|
|
175 else /* continuing lines */
|
|
176 {
|
|
177 lp->next = (LINE*)xmalloc (sizeof (LINE));
|
|
178 lp = lp->next;
|
|
179 }
|
|
180 lp->next = NULL;
|
|
181 bp = buf;
|
|
182 state = DESC_GET;
|
|
183 }
|
42439
|
184
|
29
|
185 /* process gets */
|
|
186
|
|
187 if (state == NAME_GET || state == DESC_GET)
|
|
188 {
|
|
189 if (ch != MARKER && ch != '\n' && ch != EOF)
|
|
190 {
|
|
191 *bp++ = ch;
|
|
192 }
|
|
193 else /* saving and changing state */
|
|
194 {
|
|
195 *bp = NUL;
|
9491
|
196 bp = xstrdup (buf);
|
29
|
197
|
|
198 if (state == NAME_GET)
|
|
199 dp->name = bp;
|
|
200 else
|
|
201 lp->line = bp;
|
|
202
|
|
203 bp = buf;
|
|
204 state = (ch == MARKER) ? BEG_NAME : BEG_DESC;
|
|
205 }
|
|
206 } /* NAME_GET || DESC_GET */
|
|
207 if (ch == EOF)
|
|
208 break;
|
|
209 }
|
|
210
|
|
211 {
|
|
212 DOCSTR **array;
|
|
213 register int i; /* counter */
|
|
214
|
|
215 /* build array of ptrs to DOCSTRs */
|
|
216
|
|
217 array = (DOCSTR**)xmalloc (cnt * sizeof (*array));
|
|
218 for (dp = docs, i = 0; dp != NULL ; dp = dp->next)
|
|
219 array[i++] = dp;
|
|
220
|
|
221 /* sort the array by name; within each name, by type */
|
|
222
|
|
223 qsort ((char*)array, cnt, sizeof (DOCSTR*), cmpdoc);
|
|
224
|
|
225 /* write the output header */
|
|
226
|
|
227 printf ("\\input texinfo @c -*-texinfo-*-\n");
|
|
228 printf ("@setfilename ../info/summary\n");
|
|
229 printf ("@settitle Command Summary for GNU Emacs\n");
|
24533
|
230 printf ("@finalout\n");
|
29
|
231 printf ("@unnumbered Command Summary for GNU Emacs\n");
|
|
232 printf ("@table @asis\n");
|
1175
|
233 printf ("\n");
|
24533
|
234 printf ("@iftex\n");
|
|
235 printf ("@global@let@ITEM@item\n");
|
1175
|
236 printf ("@def@item{@filbreak@vskip5pt@ITEM}\n");
|
|
237 printf ("@font@tensy cmsy10 scaled @magstephalf\n");
|
|
238 printf ("@font@teni cmmi10 scaled @magstephalf\n");
|
|
239 printf ("@def\\{{@tensy@char110}}\n"); /* this backslash goes with cmr10 */
|
|
240 printf ("@def|{{@tensy@char106}}\n");
|
|
241 printf ("@def@{{{@tensy@char102}}\n");
|
|
242 printf ("@def@}{{@tensy@char103}}\n");
|
|
243 printf ("@def<{{@teni@char62}}\n");
|
|
244 printf ("@def>{{@teni@char60}}\n");
|
|
245 printf ("@chardef@@64\n");
|
|
246 printf ("@catcode43=12\n");
|
|
247 printf ("@tableindent-0.2in\n");
|
24533
|
248 printf ("@end iftex\n");
|
29
|
249
|
|
250 /* print each function from the array */
|
|
251
|
|
252 for (i = 0; i < cnt; i++)
|
|
253 {
|
|
254 printf ("\n@item %s @code{%s}\n@display\n",
|
|
255 array[i]->type == 'F' ? "Function" : "Variable",
|
|
256 array[i]->name);
|
|
257
|
|
258 for (lp = array[i]->first; lp != NULL ; lp = lp->next)
|
|
259 {
|
|
260 for (bp = lp->line; *bp; bp++)
|
|
261 {
|
|
262 /* the characters "@{}" need special treatment */
|
|
263 if (*bp == '@' || *bp == '{' || *bp == '}')
|
|
264 {
|
|
265 putchar('@');
|
|
266 }
|
|
267 putchar(*bp);
|
|
268 }
|
|
269 putchar ('\n');
|
|
270 }
|
|
271 printf("@end display\n");
|
24533
|
272 /* Try to avoid a save size overflow in the TeX output
|
|
273 routine. */
|
|
274 if (i%100 == 0 && i > 0 && i != cnt)
|
|
275 printf("\n@end table\n@table @asis\n");
|
29
|
276 }
|
|
277
|
|
278 printf ("@end table\n");
|
|
279 printf ("@bye\n");
|
|
280 }
|
|
281
|
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
diff
changeset
|
282 return EXIT_SUCCESS;
|
29
|
283 }
|
52401
|
284
|
|
285 /* arch-tag: ce28f204-1e70-4b34-8210-3d54a5662071
|
|
286 (do not change this comment) */
|
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
diff
changeset
|
287
|
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
diff
changeset
|
288 /* sorted-doc.c ends here */
|