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