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