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