Mercurial > emacs
annotate lib-src/sorted-doc.c @ 15701:5db02009315e libc-1-93 libc-960716 libc-960717 libc-960718 libc-960719 libc-960720 libc-960721 libc-960722 libc-960723 libc-960724 libc-960725 libc-960726 libc-960727 libc-960728 libc-960729 libc-960730 libc-960731 libc-960801 libc-960802 libc-960803 libc-960804 libc-960805 libc-960806 libc-960807 libc-960808 libc-960809 libc-960810 libc-960811 libc-960812 libc-960813 libc-960814 libc-960815 libc-960816 libc-960817 libc-960818 libc-960819 libc-960820 libc-960821 libc-960822 libc-960823 libc-960824 libc-960825 libc-960826 libc-960827 libc-960828 libc-960829 libc-960830 libc-960831 libc-960901 libc-960902 libc-960903 libc-960904 libc-960905 libc-960906 libc-960907 libc-960908 libc-960909 libc-960910 libc-960911 libc-960912 release-0-0 release-0-1
Fix previous change. Use sed's y command instead.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Tue, 16 Jul 1996 04:47:46 +0000 |
parents | b0652f55a85d |
children | fdac027af4e1 |
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 | |
15681
b0652f55a85d
[__GNU_LIBRARY__]: Use <string.h>.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
11 #ifdef __GNU_LIBRARY__ |
b0652f55a85d
[__GNU_LIBRARY__]: Use <string.h>.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
12 # include <string.h> |
b0652f55a85d
[__GNU_LIBRARY__]: Use <string.h>.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
13 #endif |
b0652f55a85d
[__GNU_LIBRARY__]: Use <string.h>.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
14 |
29 | 15 extern char *malloc (); |
16 char *xmalloc (); | |
17 | |
18 #define NUL '\0' | |
19 #define MARKER '\037' | |
20 | |
21 #define DEBUG 0 | |
22 | |
23 typedef struct line LINE; | |
24 | |
25 struct line | |
26 { | |
27 LINE *next; /* ptr to next or NULL */ | |
28 char *line; /* text of the line */ | |
29 }; | |
30 | |
31 typedef struct docstr DOCSTR; | |
32 | |
33 struct docstr /* Allocated thing for an entry. */ | |
34 { | |
35 DOCSTR *next; /* next in the chain */ | |
36 char *name; /* name of the function or var */ | |
37 LINE *first; /* first line of doc text. */ | |
38 char type; /* 'F' for function, 'V' for variable */ | |
39 }; | |
40 | |
41 | |
42 /* Print error message. `s1' is printf control string, `s2' is arg for it. */ | |
43 | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
44 void |
29 | 45 error (s1, s2) |
46 char *s1, *s2; | |
47 { | |
48 fprintf (stderr, "sorted-doc: "); | |
49 fprintf (stderr, s1, s2); | |
50 fprintf (stderr, "\n"); | |
51 } | |
52 | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
53 /* Print error message and exit. */ |
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 void |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
56 fatal (s1, s2) |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
57 char *s1, *s2; |
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 error (s1, s2); |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
60 exit (1); |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
61 } |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
62 |
29 | 63 /* Like malloc but get fatal error if memory is exhausted. */ |
64 | |
65 char * | |
66 xmalloc (size) | |
67 int size; | |
68 { | |
69 char *result = malloc ((unsigned)size); | |
70 if (result == NULL) | |
71 fatal ("%s", "virtual memory exhausted"); | |
72 return result; | |
73 } | |
74 | |
75 char * | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
76 xstrdup (str) |
29 | 77 char * str; |
78 { | |
79 char *buf = xmalloc (strlen (str) + 1); | |
80 (void) strcpy (buf, str); | |
81 return (buf); | |
82 } | |
83 | |
84 /* Comparison function for qsort to call. */ | |
85 | |
86 int | |
87 cmpdoc (a, b) | |
88 DOCSTR **a; | |
89 DOCSTR **b; | |
90 { | |
91 register int val = strcmp ((*a)->name, (*b)->name); | |
92 if (val) return val; | |
93 return (*a)->type - (*b)->type; | |
94 } | |
95 | |
96 | |
97 enum state | |
98 { | |
99 WAITING, BEG_NAME, NAME_GET, BEG_DESC, DESC_GET | |
100 }; | |
101 | |
102 char *states[] = | |
103 { | |
104 "WAITING", "BEG_NAME", "NAME_GET", "BEG_DESC", "DESC_GET" | |
105 }; | |
106 | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
107 int |
29 | 108 main () |
109 { | |
110 register DOCSTR *dp = NULL; /* allocated DOCSTR */ | |
111 register LINE *lp = NULL; /* allocated line */ | |
112 register char *bp; /* ptr inside line buffer */ | |
113 register enum state state = WAITING; /* state at start */ | |
114 int cnt = 0; /* number of DOCSTRs read */ | |
115 | |
116 DOCSTR *docs; /* chain of allocated DOCSTRS */ | |
117 char buf[512]; /* line buffer */ | |
118 | |
119 while (1) /* process one char at a time */ | |
120 { | |
121 /* this char from the DOCSTR file */ | |
122 register int ch = getchar (); | |
123 | |
124 /* Beginnings */ | |
125 | |
126 if (state == WAITING) | |
127 { | |
128 if (ch == MARKER) | |
129 state = BEG_NAME; | |
130 } | |
131 else if (state == BEG_NAME) | |
132 { | |
133 cnt++; | |
134 if (dp == NULL) /* first dp allocated */ | |
135 { | |
136 docs = dp = (DOCSTR*) xmalloc (sizeof (DOCSTR)); | |
137 } | |
138 else /* all the rest */ | |
139 { | |
140 dp->next = (DOCSTR*) xmalloc (sizeof (DOCSTR)); | |
141 dp = dp->next; | |
142 } | |
143 lp = NULL; | |
144 dp->next = NULL; | |
145 bp = buf; | |
146 state = NAME_GET; | |
147 /* Record whether function or variable. */ | |
148 dp->type = ch; | |
149 ch = getchar (); | |
150 } | |
151 else if (state == BEG_DESC) | |
152 { | |
153 if (lp == NULL) /* first line for dp */ | |
154 { | |
155 dp->first = lp = (LINE*)xmalloc (sizeof (LINE)); | |
156 } | |
157 else /* continuing lines */ | |
158 { | |
159 lp->next = (LINE*)xmalloc (sizeof (LINE)); | |
160 lp = lp->next; | |
161 } | |
162 lp->next = NULL; | |
163 bp = buf; | |
164 state = DESC_GET; | |
165 } | |
166 | |
167 /* process gets */ | |
168 | |
169 if (state == NAME_GET || state == DESC_GET) | |
170 { | |
171 if (ch != MARKER && ch != '\n' && ch != EOF) | |
172 { | |
173 *bp++ = ch; | |
174 } | |
175 else /* saving and changing state */ | |
176 { | |
177 *bp = NUL; | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
1175
diff
changeset
|
178 bp = xstrdup (buf); |
29 | 179 |
180 if (state == NAME_GET) | |
181 dp->name = bp; | |
182 else | |
183 lp->line = bp; | |
184 | |
185 bp = buf; | |
186 state = (ch == MARKER) ? BEG_NAME : BEG_DESC; | |
187 } | |
188 } /* NAME_GET || DESC_GET */ | |
189 if (ch == EOF) | |
190 break; | |
191 } | |
192 | |
193 { | |
194 DOCSTR **array; | |
195 register int i; /* counter */ | |
196 | |
197 /* build array of ptrs to DOCSTRs */ | |
198 | |
199 array = (DOCSTR**)xmalloc (cnt * sizeof (*array)); | |
200 for (dp = docs, i = 0; dp != NULL ; dp = dp->next) | |
201 array[i++] = dp; | |
202 | |
203 /* sort the array by name; within each name, by type */ | |
204 | |
205 qsort ((char*)array, cnt, sizeof (DOCSTR*), cmpdoc); | |
206 | |
207 /* write the output header */ | |
208 | |
209 printf ("\\input texinfo @c -*-texinfo-*-\n"); | |
210 printf ("@setfilename ../info/summary\n"); | |
211 printf ("@settitle Command Summary for GNU Emacs\n"); | |
212 printf ("@unnumbered Command Summary for GNU Emacs\n"); | |
213 printf ("@table @asis\n"); | |
1175 | 214 printf ("\n"); |
215 printf ("@let@ITEM@item\n"); | |
216 printf ("@def@item{@filbreak@vskip5pt@ITEM}\n"); | |
217 printf ("@font@tensy cmsy10 scaled @magstephalf\n"); | |
218 printf ("@font@teni cmmi10 scaled @magstephalf\n"); | |
219 printf ("@def\\{{@tensy@char110}}\n"); /* this backslash goes with cmr10 */ | |
220 printf ("@def|{{@tensy@char106}}\n"); | |
221 printf ("@def@{{{@tensy@char102}}\n"); | |
222 printf ("@def@}{{@tensy@char103}}\n"); | |
223 printf ("@def<{{@teni@char62}}\n"); | |
224 printf ("@def>{{@teni@char60}}\n"); | |
225 printf ("@chardef@@64\n"); | |
226 printf ("@catcode43=12\n"); | |
227 printf ("@tableindent-0.2in\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"); | |
251 } | |
252 | |
253 printf ("@end table\n"); | |
254 printf ("@bye\n"); | |
255 } | |
256 | |
257 return 0; | |
258 } |