Mercurial > hg > xemacs-beta
annotate lib-src/sorted-doc.c @ 5726:179f4a9201b5
Merge.
author | Mike Sperber <sperber@deinprogramm.de> |
---|---|
date | Tue, 05 Mar 2013 08:55:56 +0100 |
parents | 1f0b15040456 |
children |
rev | line source |
---|---|
5406
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
1 /* Give this program DOC-mm.nn.oo as standard input and it outputs to |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
2 standard output a file of texinfo input containing the doc strings. |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
3 |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
4 Copyright (C) 1989, 1992, 1994, 1996, 1999, 2000, 2001, 2002, 2003, |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
5 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
6 |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
7 This file is part of XEmacs. |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
8 |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
9 XEmacs is free software: you can redistribute it and/or modify |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
10 it under the terms of the GNU General Public License as published by |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
11 the Free Software Foundation, either version 3 of the License, or |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
12 (at your option) any later version. |
428 | 13 |
5406
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
14 XEmacs is distributed in the hope that it will be useful, |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
15 but WITHOUT ANY WARRANTY; without even the implied warranty of |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
17 GNU General Public License for more details. |
428 | 18 |
5406
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
19 You should have received a copy of the GNU General Public License |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
20 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
21 |
5491 | 22 /* Synced up with: GNU 23.1.92. */ |
23 /* Synced by: Ben Wing, 2-17-10. */ | |
5406
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
24 |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
25 /* This version sorts the output by function name. */ |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
26 |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
27 #ifdef HAVE_CONFIG_H |
438 | 28 #include <config.h> |
5406
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
29 #endif |
428 | 30 |
31 #include <stdio.h> | |
32 #include <ctype.h> | |
440 | 33 #include <stdlib.h> /* for qsort() and malloc() */ |
5406
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
34 #include <string.h> |
440 | 35 static void *xmalloc (size_t); |
5491 | 36 #ifdef WIN32_NATIVE |
5406
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
37 #include <fcntl.h> /* for O_BINARY */ |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
38 #include <io.h> /* for setmode */ |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
39 #endif |
428 | 40 |
41 #define NUL '\0' | |
42 #define MARKER '\037' | |
43 | |
44 #define DEBUG 0 | |
45 | |
440 | 46 typedef struct LINE LINE; |
428 | 47 |
440 | 48 struct LINE |
428 | 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 | |
67 static void | |
68 error (char *s1, char *s2) | |
69 { | |
70 fprintf (stderr, "sorted-doc: "); | |
71 fprintf (stderr, s1, s2); | |
72 fprintf (stderr, "\n"); | |
73 } | |
74 | |
75 /* Print error message and exit. */ | |
76 | |
77 static void | |
78 fatal (char *s1, char *s2) | |
79 { | |
80 error (s1, s2); | |
5406
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
81 exit (EXIT_FAILURE); |
428 | 82 } |
83 | |
84 /* Like malloc but get fatal error if memory is exhausted. */ | |
85 | |
86 static void * | |
440 | 87 xmalloc (size_t size) |
428 | 88 { |
440 | 89 void *result = malloc (size); |
428 | 90 if (result == NULL) |
91 fatal ("%s", "virtual memory exhausted"); | |
92 return result; | |
93 } | |
94 | |
95 static char * | |
5406
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
96 xstrdup (char *str) |
428 | 97 { |
5406
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
98 char *buf = xmalloc (strlen (str) + 1); |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
99 (void) strcpy (buf, str); |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
100 return (buf); |
428 | 101 } |
102 | |
103 /* Comparison function for qsort to call. */ | |
104 | |
105 static int | |
106 cmpdoc (DOCSTR **a, DOCSTR **b) | |
107 { | |
108 register int val = strcmp ((*a)->name, (*b)->name); | |
109 if (val) return val; | |
110 return (*a)->type - (*b)->type; | |
111 } | |
112 | |
113 | |
114 enum state | |
115 { | |
116 WAITING, BEG_NAME, NAME_GET, BEG_DESC, DESC_GET | |
117 }; | |
118 | |
442 | 119 const char *states[] = |
428 | 120 { |
121 "WAITING", "BEG_NAME", "NAME_GET", "BEG_DESC", "DESC_GET" | |
122 }; | |
123 | |
124 int | |
2367 | 125 main (int argc, char **argv) |
428 | 126 { |
127 register DOCSTR *dp = NULL; /* allocated DOCSTR */ | |
128 register LINE *lp = NULL; /* allocated line */ | |
129 register char *bp = 0; /* ptr inside line buffer */ | |
130 register enum state state = WAITING; /* state at start */ | |
131 int cnt = 0; /* number of DOCSTRs read */ | |
132 | |
5406
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
133 DOCSTR *docs = NULL; /* chain of allocated DOCSTRS */ |
428 | 134 char buf[512]; /* line buffer */ |
5406
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
135 |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
136 #ifdef DOS_NT |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
137 /* DOC is a binary file. */ |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
138 if (!isatty (fileno (stdin))) |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
139 setmode (fileno (stdin), O_BINARY); |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
140 #endif |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
141 |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
142 bp = buf; |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
143 |
428 | 144 while (1) /* process one char at a time */ |
145 { | |
146 /* this char from the DOCSTR file */ | |
147 register int ch = getchar (); | |
148 | |
149 /* Beginnings */ | |
150 | |
151 if (state == WAITING) | |
152 { | |
153 if (ch == MARKER) | |
154 state = BEG_NAME; | |
155 } | |
156 else if (state == BEG_NAME) | |
157 { | |
158 cnt++; | |
159 if (dp == NULL) /* first dp allocated */ | |
160 { | |
161 docs = dp = (DOCSTR*) xmalloc (sizeof (DOCSTR)); | |
162 } | |
163 else /* all the rest */ | |
164 { | |
165 dp->next = (DOCSTR*) xmalloc (sizeof (DOCSTR)); | |
166 dp = dp->next; | |
167 } | |
168 lp = NULL; | |
169 dp->next = NULL; | |
170 bp = buf; | |
171 state = NAME_GET; | |
172 /* Record whether function or variable. */ | |
173 dp->type = ch; | |
174 ch = getchar (); | |
175 } | |
176 else if (state == BEG_DESC) | |
177 { | |
178 if (lp == NULL) /* first line for dp */ | |
179 { | |
180 dp->first = lp = (LINE*)xmalloc (sizeof (LINE)); | |
181 } | |
182 else /* continuing lines */ | |
183 { | |
184 lp->next = (LINE*)xmalloc (sizeof (LINE)); | |
185 lp = lp->next; | |
186 } | |
187 lp->next = NULL; | |
188 bp = buf; | |
189 state = DESC_GET; | |
190 } | |
5406
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
191 |
428 | 192 /* process gets */ |
193 | |
194 if (state == NAME_GET || state == DESC_GET) | |
195 { | |
196 if (ch != MARKER && ch != '\n' && ch != EOF) | |
197 { | |
198 *bp++ = ch; | |
199 } | |
200 else /* saving and changing state */ | |
201 { | |
202 *bp = NUL; | |
5406
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
203 bp = xstrdup (buf); |
428 | 204 |
205 if (state == NAME_GET) | |
206 dp->name = bp; | |
207 else | |
208 lp->line = bp; | |
209 | |
210 bp = buf; | |
211 state = (ch == MARKER) ? BEG_NAME : BEG_DESC; | |
212 } | |
213 } /* NAME_GET || DESC_GET */ | |
214 if (ch == EOF) | |
215 break; | |
216 } | |
217 | |
218 { | |
219 DOCSTR **array; | |
220 register int i; /* counter */ | |
221 | |
222 /* build array of ptrs to DOCSTRs */ | |
223 | |
224 array = (DOCSTR**)xmalloc (cnt * sizeof (*array)); | |
225 for (dp = docs, i = 0; dp != NULL ; dp = dp->next) | |
226 array[i++] = dp; | |
227 | |
228 /* sort the array by name; within each name, by type */ | |
229 | |
230 qsort ((char*)array, cnt, sizeof (DOCSTR*), | |
442 | 231 (int (*)(const void *, const void *)) cmpdoc); |
428 | 232 |
233 /* write the output header */ | |
234 | |
235 printf ("\\input texinfo @c -*-texinfo-*-\n"); | |
236 printf ("@setfilename ../info/summary\n"); | |
613 | 237 printf ("@settitle Command Summary for XEmacs\n"); |
5406
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
238 printf ("@finalout\n"); |
613 | 239 printf ("@unnumbered Command Summary for XEmacs\n"); |
428 | 240 printf ("@table @asis\n"); |
241 printf ("\n"); | |
242 printf ("@iftex\n"); | |
5491 | 243 /* #### XEmacs note: FSF 23.1.92 is missing the = sign below. |
244 Which is correct? */ | |
428 | 245 printf ("@global@let@ITEM=@item\n"); |
246 printf ("@def@item{@filbreak@vskip5pt@ITEM}\n"); | |
247 printf ("@font@tensy cmsy10 scaled @magstephalf\n"); | |
248 printf ("@font@teni cmmi10 scaled @magstephalf\n"); | |
249 printf ("@def\\{{@tensy@char110}}\n"); /* this backslash goes with cmr10 */ | |
250 printf ("@def|{{@tensy@char106}}\n"); | |
251 printf ("@def@{{{@tensy@char102}}\n"); | |
252 printf ("@def@}{{@tensy@char103}}\n"); | |
253 printf ("@def<{{@teni@char62}}\n"); | |
254 printf ("@def>{{@teni@char60}}\n"); | |
255 printf ("@chardef@@64\n"); | |
256 printf ("@catcode43=12\n"); | |
257 printf ("@tableindent-0.2in\n"); | |
258 printf ("@end iftex\n"); | |
259 | |
260 /* print each function from the array */ | |
261 | |
262 for (i = 0; i < cnt; i++) | |
263 { | |
264 printf ("\n@item %s @code{%s}\n@display\n", | |
265 array[i]->type == 'F' ? "Function" : "Variable", | |
266 array[i]->name); | |
267 | |
268 for (lp = array[i]->first; lp != NULL ; lp = lp->next) | |
269 { | |
270 for (bp = lp->line; *bp; bp++) | |
271 { | |
272 /* the characters "@{}" need special treatment */ | |
273 if (*bp == '@' || *bp == '{' || *bp == '}') | |
274 { | |
275 putchar('@'); | |
276 } | |
277 putchar(*bp); | |
278 } | |
279 putchar ('\n'); | |
280 } | |
281 printf("@end display\n"); | |
5406
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
282 /* Try to avoid a save size overflow in the TeX output |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
283 routine. */ |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
284 if (i%100 == 0 && i > 0 && i != cnt) |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
285 printf("\n@end table\n@table @asis\n"); |
428 | 286 } |
287 | |
288 printf ("@end table\n"); | |
289 printf ("@bye\n"); | |
290 } | |
291 | |
5406
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
292 return EXIT_SUCCESS; |
428 | 293 } |
5406
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
294 |
5491 | 295 /* arch-tag: ce28f204-1e70-4b34-8210-3d54a5662071 |
296 (do not change this comment) */ | |
297 | |
5406
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
298 /* sorted-doc.c ends here */ |