Mercurial > emacs
annotate lib-src/sorted-doc.c @ 81805:05153ccde019
Load cl-loaddefs.el quietly.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Tue, 10 Jul 2007 21:01:20 +0000 |
parents | 3d45362f1d38 |
children | 1f2482de3237 95d0cdf160ea |
rev | line source |
---|---|
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
d8a417105504
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
42412
diff
changeset
|
3 |
64769
6358e3c6075c
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64083
diff
changeset
|
4 Copyright (C) 1989, 1992, 1994, 1996, 1999, 2000, 2001, 2002, 2003, |
75348 | 5 2004, 2005, 2006, 2007 Free Software Foundation, Inc. |
36226 | 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> | |
71192
fa429804cb96
[DOS_NT] <top level>: Include fcntl.h and io.h.
Eli Zaretskii <eliz@gnu.org>
parents:
70285
diff
changeset
|
32 #ifdef DOS_NT |
fa429804cb96
[DOS_NT] <top level>: Include fcntl.h and io.h.
Eli Zaretskii <eliz@gnu.org>
parents:
70285
diff
changeset
|
33 #include <fcntl.h> /* for O_BINARY */ |
fa429804cb96
[DOS_NT] <top level>: Include fcntl.h and io.h.
Eli Zaretskii <eliz@gnu.org>
parents:
70285
diff
changeset
|
34 #include <io.h> /* for setmode */ |
fa429804cb96
[DOS_NT] <top level>: Include fcntl.h and io.h.
Eli Zaretskii <eliz@gnu.org>
parents:
70285
diff
changeset
|
35 #endif |
31884 | 36 #ifndef HAVE_STDLIB_H /* config.h includes stdlib. */ |
71192
fa429804cb96
[DOS_NT] <top level>: Include fcntl.h and io.h.
Eli Zaretskii <eliz@gnu.org>
parents:
70285
diff
changeset
|
37 #ifndef WINDOWSNT /* src/s/ms-w32.h includes stdlib.h */ |
29 | 38 extern char *malloc (); |
31884 | 39 #endif |
71192
fa429804cb96
[DOS_NT] <top level>: Include fcntl.h and io.h.
Eli Zaretskii <eliz@gnu.org>
parents:
70285
diff
changeset
|
40 #endif |
29 | 41 |
42 #define NUL '\0' | |
43 #define MARKER '\037' | |
44 | |
45 #define DEBUG 0 | |
46 | |
47 typedef struct line LINE; | |
48 | |
49 struct line | |
50 { | |
51 LINE *next; /* ptr to next or NULL */ | |
52 char *line; /* text of the line */ | |
53 }; | |
54 | |
55 typedef struct docstr DOCSTR; | |
56 | |
57 struct docstr /* Allocated thing for an entry. */ | |
58 { | |
59 DOCSTR *next; /* next in the chain */ | |
60 char *name; /* name of the function or var */ | |
61 LINE *first; /* first line of doc text. */ | |
62 char type; /* 'F' for function, 'V' for variable */ | |
63 }; | |
64 | |
65 | |
66 /* Print error message. `s1' is printf control string, `s2' is arg for it. */ | |
67 | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
68 void |
29 | 69 error (s1, s2) |
70 char *s1, *s2; | |
71 { | |
72 fprintf (stderr, "sorted-doc: "); | |
73 fprintf (stderr, s1, s2); | |
74 fprintf (stderr, "\n"); | |
75 } | |
76 | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
77 /* Print error message and exit. */ |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
78 |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
79 void |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
80 fatal (s1, s2) |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
81 char *s1, *s2; |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
82 { |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
83 error (s1, s2); |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
84 exit (EXIT_FAILURE); |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
85 } |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
86 |
29 | 87 /* Like malloc but get fatal error if memory is exhausted. */ |
88 | |
89 char * | |
90 xmalloc (size) | |
91 int size; | |
92 { | |
93 char *result = malloc ((unsigned)size); | |
94 if (result == NULL) | |
95 fatal ("%s", "virtual memory exhausted"); | |
96 return result; | |
97 } | |
98 | |
99 char * | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
100 xstrdup (str) |
29 | 101 char * str; |
102 { | |
103 char *buf = xmalloc (strlen (str) + 1); | |
104 (void) strcpy (buf, str); | |
105 return (buf); | |
106 } | |
107 | |
108 /* Comparison function for qsort to call. */ | |
109 | |
110 int | |
111 cmpdoc (a, b) | |
112 DOCSTR **a; | |
113 DOCSTR **b; | |
114 { | |
115 register int val = strcmp ((*a)->name, (*b)->name); | |
116 if (val) return val; | |
117 return (*a)->type - (*b)->type; | |
118 } | |
119 | |
120 | |
121 enum state | |
122 { | |
123 WAITING, BEG_NAME, NAME_GET, BEG_DESC, DESC_GET | |
124 }; | |
125 | |
126 char *states[] = | |
127 { | |
128 "WAITING", "BEG_NAME", "NAME_GET", "BEG_DESC", "DESC_GET" | |
129 }; | |
42439
d8a417105504
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
42412
diff
changeset
|
130 |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
131 int |
29 | 132 main () |
133 { | |
134 register DOCSTR *dp = NULL; /* allocated DOCSTR */ | |
135 register LINE *lp = NULL; /* allocated line */ | |
136 register char *bp; /* ptr inside line buffer */ | |
137 register enum state state = WAITING; /* state at start */ | |
138 int cnt = 0; /* number of DOCSTRs read */ | |
139 | |
70285
0f15a453179c
(main): Initialize docs to NULL.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
68647
diff
changeset
|
140 DOCSTR *docs = NULL; /* chain of allocated DOCSTRS */ |
29 | 141 char buf[512]; /* line buffer */ |
42439
d8a417105504
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
42412
diff
changeset
|
142 |
71192
fa429804cb96
[DOS_NT] <top level>: Include fcntl.h and io.h.
Eli Zaretskii <eliz@gnu.org>
parents:
70285
diff
changeset
|
143 #ifdef DOS_NT |
fa429804cb96
[DOS_NT] <top level>: Include fcntl.h and io.h.
Eli Zaretskii <eliz@gnu.org>
parents:
70285
diff
changeset
|
144 /* DOC is a binary file. */ |
fa429804cb96
[DOS_NT] <top level>: Include fcntl.h and io.h.
Eli Zaretskii <eliz@gnu.org>
parents:
70285
diff
changeset
|
145 if (!isatty (fileno (stdin))) |
fa429804cb96
[DOS_NT] <top level>: Include fcntl.h and io.h.
Eli Zaretskii <eliz@gnu.org>
parents:
70285
diff
changeset
|
146 setmode (fileno (stdin), O_BINARY); |
fa429804cb96
[DOS_NT] <top level>: Include fcntl.h and io.h.
Eli Zaretskii <eliz@gnu.org>
parents:
70285
diff
changeset
|
147 #endif |
fa429804cb96
[DOS_NT] <top level>: Include fcntl.h and io.h.
Eli Zaretskii <eliz@gnu.org>
parents:
70285
diff
changeset
|
148 |
71194
036770549c03
(main): Initialize bp, to avoid compiler warnings
Eli Zaretskii <eliz@gnu.org>
parents:
71192
diff
changeset
|
149 bp = buf; |
036770549c03
(main): Initialize bp, to avoid compiler warnings
Eli Zaretskii <eliz@gnu.org>
parents:
71192
diff
changeset
|
150 |
29 | 151 while (1) /* process one char at a time */ |
152 { | |
153 /* this char from the DOCSTR file */ | |
154 register int ch = getchar (); | |
155 | |
156 /* Beginnings */ | |
157 | |
158 if (state == WAITING) | |
159 { | |
160 if (ch == MARKER) | |
161 state = BEG_NAME; | |
162 } | |
163 else if (state == BEG_NAME) | |
164 { | |
165 cnt++; | |
166 if (dp == NULL) /* first dp allocated */ | |
167 { | |
168 docs = dp = (DOCSTR*) xmalloc (sizeof (DOCSTR)); | |
169 } | |
170 else /* all the rest */ | |
171 { | |
172 dp->next = (DOCSTR*) xmalloc (sizeof (DOCSTR)); | |
173 dp = dp->next; | |
174 } | |
175 lp = NULL; | |
176 dp->next = NULL; | |
177 bp = buf; | |
178 state = NAME_GET; | |
179 /* Record whether function or variable. */ | |
180 dp->type = ch; | |
181 ch = getchar (); | |
182 } | |
183 else if (state == BEG_DESC) | |
184 { | |
185 if (lp == NULL) /* first line for dp */ | |
186 { | |
187 dp->first = lp = (LINE*)xmalloc (sizeof (LINE)); | |
188 } | |
189 else /* continuing lines */ | |
190 { | |
191 lp->next = (LINE*)xmalloc (sizeof (LINE)); | |
192 lp = lp->next; | |
193 } | |
194 lp->next = NULL; | |
195 bp = buf; | |
196 state = DESC_GET; | |
197 } | |
42439
d8a417105504
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
42412
diff
changeset
|
198 |
29 | 199 /* process gets */ |
200 | |
201 if (state == NAME_GET || state == DESC_GET) | |
202 { | |
203 if (ch != MARKER && ch != '\n' && ch != EOF) | |
204 { | |
205 *bp++ = ch; | |
206 } | |
207 else /* saving and changing state */ | |
208 { | |
209 *bp = NUL; | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
210 bp = xstrdup (buf); |
29 | 211 |
212 if (state == NAME_GET) | |
213 dp->name = bp; | |
214 else | |
215 lp->line = bp; | |
216 | |
217 bp = buf; | |
218 state = (ch == MARKER) ? BEG_NAME : BEG_DESC; | |
219 } | |
220 } /* NAME_GET || DESC_GET */ | |
221 if (ch == EOF) | |
222 break; | |
223 } | |
224 | |
225 { | |
226 DOCSTR **array; | |
227 register int i; /* counter */ | |
228 | |
229 /* build array of ptrs to DOCSTRs */ | |
230 | |
231 array = (DOCSTR**)xmalloc (cnt * sizeof (*array)); | |
232 for (dp = docs, i = 0; dp != NULL ; dp = dp->next) | |
233 array[i++] = dp; | |
234 | |
235 /* sort the array by name; within each name, by type */ | |
236 | |
237 qsort ((char*)array, cnt, sizeof (DOCSTR*), cmpdoc); | |
238 | |
239 /* write the output header */ | |
240 | |
241 printf ("\\input texinfo @c -*-texinfo-*-\n"); | |
242 printf ("@setfilename ../info/summary\n"); | |
243 printf ("@settitle Command Summary for GNU Emacs\n"); | |
24533
32a7344ac2e7
(main): Split up tables. Modify the preamble
Dave Love <fx@gnu.org>
parents:
15719
diff
changeset
|
244 printf ("@finalout\n"); |
29 | 245 printf ("@unnumbered Command Summary for GNU Emacs\n"); |
246 printf ("@table @asis\n"); | |
1175 | 247 printf ("\n"); |
24533
32a7344ac2e7
(main): Split up tables. Modify the preamble
Dave Love <fx@gnu.org>
parents:
15719
diff
changeset
|
248 printf ("@iftex\n"); |
32a7344ac2e7
(main): Split up tables. Modify the preamble
Dave Love <fx@gnu.org>
parents:
15719
diff
changeset
|
249 printf ("@global@let@ITEM@item\n"); |
1175 | 250 printf ("@def@item{@filbreak@vskip5pt@ITEM}\n"); |
251 printf ("@font@tensy cmsy10 scaled @magstephalf\n"); | |
252 printf ("@font@teni cmmi10 scaled @magstephalf\n"); | |
253 printf ("@def\\{{@tensy@char110}}\n"); /* this backslash goes with cmr10 */ | |
254 printf ("@def|{{@tensy@char106}}\n"); | |
255 printf ("@def@{{{@tensy@char102}}\n"); | |
256 printf ("@def@}{{@tensy@char103}}\n"); | |
257 printf ("@def<{{@teni@char62}}\n"); | |
258 printf ("@def>{{@teni@char60}}\n"); | |
259 printf ("@chardef@@64\n"); | |
260 printf ("@catcode43=12\n"); | |
261 printf ("@tableindent-0.2in\n"); | |
24533
32a7344ac2e7
(main): Split up tables. Modify the preamble
Dave Love <fx@gnu.org>
parents:
15719
diff
changeset
|
262 printf ("@end iftex\n"); |
29 | 263 |
264 /* print each function from the array */ | |
265 | |
266 for (i = 0; i < cnt; i++) | |
267 { | |
268 printf ("\n@item %s @code{%s}\n@display\n", | |
269 array[i]->type == 'F' ? "Function" : "Variable", | |
270 array[i]->name); | |
271 | |
272 for (lp = array[i]->first; lp != NULL ; lp = lp->next) | |
273 { | |
274 for (bp = lp->line; *bp; bp++) | |
275 { | |
276 /* the characters "@{}" need special treatment */ | |
277 if (*bp == '@' || *bp == '{' || *bp == '}') | |
278 { | |
279 putchar('@'); | |
280 } | |
281 putchar(*bp); | |
282 } | |
283 putchar ('\n'); | |
284 } | |
285 printf("@end display\n"); | |
24533
32a7344ac2e7
(main): Split up tables. Modify the preamble
Dave Love <fx@gnu.org>
parents:
15719
diff
changeset
|
286 /* Try to avoid a save size overflow in the TeX output |
32a7344ac2e7
(main): Split up tables. Modify the preamble
Dave Love <fx@gnu.org>
parents:
15719
diff
changeset
|
287 routine. */ |
32a7344ac2e7
(main): Split up tables. Modify the preamble
Dave Love <fx@gnu.org>
parents:
15719
diff
changeset
|
288 if (i%100 == 0 && i > 0 && i != cnt) |
32a7344ac2e7
(main): Split up tables. Modify the preamble
Dave Love <fx@gnu.org>
parents:
15719
diff
changeset
|
289 printf("\n@end table\n@table @asis\n"); |
29 | 290 } |
291 | |
292 printf ("@end table\n"); | |
293 printf ("@bye\n"); | |
294 } | |
295 | |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
296 return EXIT_SUCCESS; |
29 | 297 } |
52401 | 298 |
299 /* arch-tag: ce28f204-1e70-4b34-8210-3d54a5662071 | |
300 (do not change this comment) */ | |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
301 |
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
302 /* sorted-doc.c ends here */ |