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.
5 This version sorts the output by function name.
8 /* Synched up with: FSF 19.28. */
10 #include <../src/config.h>
14 #if __STDC__ || defined(STDC_HEADERS)
15 # include <stdlib.h> /* for qsort() and malloc() */
17 static void *xmalloc (int);
22 extern char *malloc ();
23 static void *xmalloc ();
34 typedef struct line LINE;
38 LINE *next; /* ptr to next or NULL */
39 char *line; /* text of the line */
42 typedef struct docstr DOCSTR;
44 struct docstr /* Allocated thing for an entry. */
46 DOCSTR *next; /* next in the chain */
47 char *name; /* name of the function or var */
48 LINE *first; /* first line of doc text. */
49 char type; /* 'F' for function, 'V' for variable */
53 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
56 error (char *s1, char *s2)
58 fprintf (stderr, "sorted-doc: ");
59 fprintf (stderr, s1, s2);
60 fprintf (stderr, "\n");
63 /* Print error message and exit. */
66 fatal (char *s1, char *s2)
72 /* Like malloc but get fatal error if memory is exhausted. */
77 char *result = malloc ((unsigned)size);
79 fatal ("%s", "virtual memory exhausted");
86 char *buf = xmalloc (strlen (str) + 1);
87 (void) strcpy (buf, str);
91 /* Comparison function for qsort to call. */
94 cmpdoc (DOCSTR **a, DOCSTR **b)
96 register int val = strcmp ((*a)->name, (*b)->name);
98 return (*a)->type - (*b)->type;
104 WAITING, BEG_NAME, NAME_GET, BEG_DESC, DESC_GET
107 CONST char *states[] =
109 "WAITING", "BEG_NAME", "NAME_GET", "BEG_DESC", "DESC_GET"
113 main (int argc, char *argv[])
115 register DOCSTR *dp = NULL; /* allocated DOCSTR */
116 register LINE *lp = NULL; /* allocated line */
117 register char *bp = 0; /* ptr inside line buffer */
118 /* int notfirst = 0; / * set after read something */
119 register enum state state = WAITING; /* state at start */
120 int cnt = 0; /* number of DOCSTRs read */
122 DOCSTR *docs = 0; /* chain of allocated DOCSTRS */
123 char buf[512]; /* line buffer */
125 while (1) /* process one char at a time */
127 /* this char from the DOCSTR file */
128 register int ch = getchar ();
132 if (state == WAITING)
137 else if (state == BEG_NAME)
140 if (dp == NULL) /* first dp allocated */
142 docs = dp = (DOCSTR*) xmalloc (sizeof (DOCSTR));
144 else /* all the rest */
146 dp->next = (DOCSTR*) xmalloc (sizeof (DOCSTR));
153 /* Record whether function or variable. */
157 else if (state == BEG_DESC)
159 if (lp == NULL) /* first line for dp */
161 dp->first = lp = (LINE*)xmalloc (sizeof (LINE));
163 else /* continuing lines */
165 lp->next = (LINE*)xmalloc (sizeof (LINE));
175 if (state == NAME_GET || state == DESC_GET)
177 if (ch != MARKER && ch != '\n' && ch != EOF)
181 else /* saving and changing state */
186 if (state == NAME_GET)
192 state = (ch == MARKER) ? BEG_NAME : BEG_DESC;
194 } /* NAME_GET || DESC_GET */
201 register int i; /* counter */
203 /* build array of ptrs to DOCSTRs */
205 array = (DOCSTR**)xmalloc (cnt * sizeof (*array));
206 for (dp = docs, i = 0; dp != NULL ; dp = dp->next)
209 /* sort the array by name; within each name, by type */
211 qsort ((char*)array, cnt, sizeof (DOCSTR*),
212 /* was cast to (int (*)(CONST void *, CONST void *))
213 but that loses on HP because CONST_IS_LOSING. */
214 /* This one loses too: (int (*)()) */
215 /* Ok, so let's try const instead of CONST. Fuck me!!! */
216 (int (*)(const void *, const void *))
219 /* write the output header */
221 printf ("\\input texinfo @c -*-texinfo-*-\n");
222 printf ("@setfilename ../info/summary\n");
223 printf ("@settitle Command Summary for GNU Emacs\n");
224 printf ("@unnumbered Command Summary for GNU Emacs\n");
225 printf ("@table @asis\n");
228 printf ("@global@let@ITEM=@item\n");
229 printf ("@def@item{@filbreak@vskip5pt@ITEM}\n");
230 printf ("@font@tensy cmsy10 scaled @magstephalf\n");
231 printf ("@font@teni cmmi10 scaled @magstephalf\n");
232 printf ("@def\\{{@tensy@char110}}\n"); /* this backslash goes with cmr10 */
233 printf ("@def|{{@tensy@char106}}\n");
234 printf ("@def@{{{@tensy@char102}}\n");
235 printf ("@def@}{{@tensy@char103}}\n");
236 printf ("@def<{{@teni@char62}}\n");
237 printf ("@def>{{@teni@char60}}\n");
238 printf ("@chardef@@64\n");
239 printf ("@catcode43=12\n");
240 printf ("@tableindent-0.2in\n");
241 printf ("@end iftex\n");
243 /* print each function from the array */
245 for (i = 0; i < cnt; i++)
247 printf ("\n@item %s @code{%s}\n@display\n",
248 array[i]->type == 'F' ? "Function" : "Variable",
251 for (lp = array[i]->first; lp != NULL ; lp = lp->next)
253 for (bp = lp->line; *bp; bp++)
255 /* the characters "@{}" need special treatment */
256 if (*bp == '@' || *bp == '{' || *bp == '}')
264 printf("@end display\n");
265 if ( i%200 == 0 && i != 0 ) printf("@end table\n\n@table @asis\n");
268 printf ("@end table\n");