Mercurial > emacs
annotate lib-src/sorted-doc.c @ 42297:c4f9d48801a8
Explain using a before-string to put something in the margin.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 24 Dec 2001 16:29:42 +0000 |
parents | 661375cd8c4c |
children | 83c1951257f1 |
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. |
29 | 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 |
21 Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 Boston, MA 02111-1307, USA. | |
23 | |
36226 | 24 This version sorts the output by function name. */ |
29 | 25 |
31884 | 26 #include "config.h" |
29 | 27 #include <stdio.h> |
28 #include <ctype.h> | |
31884 | 29 #ifndef HAVE_STDLIB_H /* config.h includes stdlib. */ |
29 | 30 extern char *malloc (); |
31884 | 31 #endif |
29 | 32 |
33 #define NUL '\0' | |
34 #define MARKER '\037' | |
35 | |
36 #define DEBUG 0 | |
37 | |
38 typedef struct line LINE; | |
39 | |
40 struct line | |
41 { | |
42 LINE *next; /* ptr to next or NULL */ | |
43 char *line; /* text of the line */ | |
44 }; | |
45 | |
46 typedef struct docstr DOCSTR; | |
47 | |
48 struct docstr /* Allocated thing for an entry. */ | |
49 { | |
50 DOCSTR *next; /* next in the chain */ | |
51 char *name; /* name of the function or var */ | |
52 LINE *first; /* first line of doc text. */ | |
53 char type; /* 'F' for function, 'V' for variable */ | |
54 }; | |
55 | |
56 | |
57 /* Print error message. `s1' is printf control string, `s2' is arg for it. */ | |
58 | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
59 void |
29 | 60 error (s1, s2) |
61 char *s1, *s2; | |
62 { | |
63 fprintf (stderr, "sorted-doc: "); | |
64 fprintf (stderr, s1, s2); | |
65 fprintf (stderr, "\n"); | |
66 } | |
67 | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
68 /* Print error message and exit. */ |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
69 |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
70 void |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
71 fatal (s1, s2) |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
72 char *s1, *s2; |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
73 { |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
74 error (s1, s2); |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
75 exit (1); |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
76 } |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
77 |
29 | 78 /* Like malloc but get fatal error if memory is exhausted. */ |
79 | |
80 char * | |
81 xmalloc (size) | |
82 int size; | |
83 { | |
84 char *result = malloc ((unsigned)size); | |
85 if (result == NULL) | |
86 fatal ("%s", "virtual memory exhausted"); | |
87 return result; | |
88 } | |
89 | |
90 char * | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
91 xstrdup (str) |
29 | 92 char * str; |
93 { | |
94 char *buf = xmalloc (strlen (str) + 1); | |
95 (void) strcpy (buf, str); | |
96 return (buf); | |
97 } | |
98 | |
99 /* Comparison function for qsort to call. */ | |
100 | |
101 int | |
102 cmpdoc (a, b) | |
103 DOCSTR **a; | |
104 DOCSTR **b; | |
105 { | |
106 register int val = strcmp ((*a)->name, (*b)->name); | |
107 if (val) return val; | |
108 return (*a)->type - (*b)->type; | |
109 } | |
110 | |
111 | |
112 enum state | |
113 { | |
114 WAITING, BEG_NAME, NAME_GET, BEG_DESC, DESC_GET | |
115 }; | |
116 | |
117 char *states[] = | |
118 { | |
119 "WAITING", "BEG_NAME", "NAME_GET", "BEG_DESC", "DESC_GET" | |
120 }; | |
121 | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
122 int |
29 | 123 main () |
124 { | |
125 register DOCSTR *dp = NULL; /* allocated DOCSTR */ | |
126 register LINE *lp = NULL; /* allocated line */ | |
127 register char *bp; /* ptr inside line buffer */ | |
128 register enum state state = WAITING; /* state at start */ | |
129 int cnt = 0; /* number of DOCSTRs read */ | |
130 | |
131 DOCSTR *docs; /* chain of allocated DOCSTRS */ | |
132 char buf[512]; /* line buffer */ | |
133 | |
134 while (1) /* process one char at a time */ | |
135 { | |
136 /* this char from the DOCSTR file */ | |
137 register int ch = getchar (); | |
138 | |
139 /* Beginnings */ | |
140 | |
141 if (state == WAITING) | |
142 { | |
143 if (ch == MARKER) | |
144 state = BEG_NAME; | |
145 } | |
146 else if (state == BEG_NAME) | |
147 { | |
148 cnt++; | |
149 if (dp == NULL) /* first dp allocated */ | |
150 { | |
151 docs = dp = (DOCSTR*) xmalloc (sizeof (DOCSTR)); | |
152 } | |
153 else /* all the rest */ | |
154 { | |
155 dp->next = (DOCSTR*) xmalloc (sizeof (DOCSTR)); | |
156 dp = dp->next; | |
157 } | |
158 lp = NULL; | |
159 dp->next = NULL; | |
160 bp = buf; | |
161 state = NAME_GET; | |
162 /* Record whether function or variable. */ | |
163 dp->type = ch; | |
164 ch = getchar (); | |
165 } | |
166 else if (state == BEG_DESC) | |
167 { | |
168 if (lp == NULL) /* first line for dp */ | |
169 { | |
170 dp->first = lp = (LINE*)xmalloc (sizeof (LINE)); | |
171 } | |
172 else /* continuing lines */ | |
173 { | |
174 lp->next = (LINE*)xmalloc (sizeof (LINE)); | |
175 lp = lp->next; | |
176 } | |
177 lp->next = NULL; | |
178 bp = buf; | |
179 state = DESC_GET; | |
180 } | |
181 | |
182 /* process gets */ | |
183 | |
184 if (state == NAME_GET || state == DESC_GET) | |
185 { | |
186 if (ch != MARKER && ch != '\n' && ch != EOF) | |
187 { | |
188 *bp++ = ch; | |
189 } | |
190 else /* saving and changing state */ | |
191 { | |
192 *bp = NUL; | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
193 bp = xstrdup (buf); |
29 | 194 |
195 if (state == NAME_GET) | |
196 dp->name = bp; | |
197 else | |
198 lp->line = bp; | |
199 | |
200 bp = buf; | |
201 state = (ch == MARKER) ? BEG_NAME : BEG_DESC; | |
202 } | |
203 } /* NAME_GET || DESC_GET */ | |
204 if (ch == EOF) | |
205 break; | |
206 } | |
207 | |
208 { | |
209 DOCSTR **array; | |
210 register int i; /* counter */ | |
211 | |
212 /* build array of ptrs to DOCSTRs */ | |
213 | |
214 array = (DOCSTR**)xmalloc (cnt * sizeof (*array)); | |
215 for (dp = docs, i = 0; dp != NULL ; dp = dp->next) | |
216 array[i++] = dp; | |
217 | |
218 /* sort the array by name; within each name, by type */ | |
219 | |
220 qsort ((char*)array, cnt, sizeof (DOCSTR*), cmpdoc); | |
221 | |
222 /* write the output header */ | |
223 | |
224 printf ("\\input texinfo @c -*-texinfo-*-\n"); | |
225 printf ("@setfilename ../info/summary\n"); | |
226 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
|
227 printf ("@finalout\n"); |
29 | 228 printf ("@unnumbered Command Summary for GNU Emacs\n"); |
229 printf ("@table @asis\n"); | |
1175 | 230 printf ("\n"); |
24533
32a7344ac2e7
(main): Split up tables. Modify the preamble
Dave Love <fx@gnu.org>
parents:
15719
diff
changeset
|
231 printf ("@iftex\n"); |
32a7344ac2e7
(main): Split up tables. Modify the preamble
Dave Love <fx@gnu.org>
parents:
15719
diff
changeset
|
232 printf ("@global@let@ITEM@item\n"); |
1175 | 233 printf ("@def@item{@filbreak@vskip5pt@ITEM}\n"); |
234 printf ("@font@tensy cmsy10 scaled @magstephalf\n"); | |
235 printf ("@font@teni cmmi10 scaled @magstephalf\n"); | |
236 printf ("@def\\{{@tensy@char110}}\n"); /* this backslash goes with cmr10 */ | |
237 printf ("@def|{{@tensy@char106}}\n"); | |
238 printf ("@def@{{{@tensy@char102}}\n"); | |
239 printf ("@def@}{{@tensy@char103}}\n"); | |
240 printf ("@def<{{@teni@char62}}\n"); | |
241 printf ("@def>{{@teni@char60}}\n"); | |
242 printf ("@chardef@@64\n"); | |
243 printf ("@catcode43=12\n"); | |
244 printf ("@tableindent-0.2in\n"); | |
24533
32a7344ac2e7
(main): Split up tables. Modify the preamble
Dave Love <fx@gnu.org>
parents:
15719
diff
changeset
|
245 printf ("@end iftex\n"); |
29 | 246 |
247 /* print each function from the array */ | |
248 | |
249 for (i = 0; i < cnt; i++) | |
250 { | |
251 printf ("\n@item %s @code{%s}\n@display\n", | |
252 array[i]->type == 'F' ? "Function" : "Variable", | |
253 array[i]->name); | |
254 | |
255 for (lp = array[i]->first; lp != NULL ; lp = lp->next) | |
256 { | |
257 for (bp = lp->line; *bp; bp++) | |
258 { | |
259 /* the characters "@{}" need special treatment */ | |
260 if (*bp == '@' || *bp == '{' || *bp == '}') | |
261 { | |
262 putchar('@'); | |
263 } | |
264 putchar(*bp); | |
265 } | |
266 putchar ('\n'); | |
267 } | |
268 printf("@end display\n"); | |
24533
32a7344ac2e7
(main): Split up tables. Modify the preamble
Dave Love <fx@gnu.org>
parents:
15719
diff
changeset
|
269 /* 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
|
270 routine. */ |
32a7344ac2e7
(main): Split up tables. Modify the preamble
Dave Love <fx@gnu.org>
parents:
15719
diff
changeset
|
271 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
|
272 printf("\n@end table\n@table @asis\n"); |
29 | 273 } |
274 | |
275 printf ("@end table\n"); | |
276 printf ("@bye\n"); | |
277 } | |
278 | |
279 return 0; | |
280 } |