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.
11 #ifndef HAVE_STDLIB_H /* config.h includes stdlib. */
12 extern char *malloc ();
20 typedef struct line LINE
;
24 LINE
*next
; /* ptr to next or NULL */
25 char *line
; /* text of the line */
28 typedef struct docstr DOCSTR
;
30 struct docstr
/* Allocated thing for an entry. */
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 */
39 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
45 fprintf (stderr
, "sorted-doc: ");
46 fprintf (stderr
, s1
, s2
);
47 fprintf (stderr
, "\n");
50 /* Print error message and exit. */
60 /* Like malloc but get fatal error if memory is exhausted. */
66 char *result
= malloc ((unsigned)size
);
68 fatal ("%s", "virtual memory exhausted");
76 char *buf
= xmalloc (strlen (str
) + 1);
77 (void) strcpy (buf
, str
);
81 /* Comparison function for qsort to call. */
88 register int val
= strcmp ((*a
)->name
, (*b
)->name
);
90 return (*a
)->type
- (*b
)->type
;
96 WAITING
, BEG_NAME
, NAME_GET
, BEG_DESC
, DESC_GET
101 "WAITING", "BEG_NAME", "NAME_GET", "BEG_DESC", "DESC_GET"
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 */
113 DOCSTR
*docs
; /* chain of allocated DOCSTRS */
114 char buf
[512]; /* line buffer */
116 while (1) /* process one char at a time */
118 /* this char from the DOCSTR file */
119 register int ch
= getchar ();
123 if (state
== WAITING
)
128 else if (state
== BEG_NAME
)
131 if (dp
== NULL
) /* first dp allocated */
133 docs
= dp
= (DOCSTR
*) xmalloc (sizeof (DOCSTR
));
135 else /* all the rest */
137 dp
->next
= (DOCSTR
*) xmalloc (sizeof (DOCSTR
));
144 /* Record whether function or variable. */
148 else if (state
== BEG_DESC
)
150 if (lp
== NULL
) /* first line for dp */
152 dp
->first
= lp
= (LINE
*)xmalloc (sizeof (LINE
));
154 else /* continuing lines */
156 lp
->next
= (LINE
*)xmalloc (sizeof (LINE
));
166 if (state
== NAME_GET
|| state
== DESC_GET
)
168 if (ch
!= MARKER
&& ch
!= '\n' && ch
!= EOF
)
172 else /* saving and changing state */
177 if (state
== NAME_GET
)
183 state
= (ch
== MARKER
) ? BEG_NAME
: BEG_DESC
;
185 } /* NAME_GET || DESC_GET */
192 register int i
; /* counter */
194 /* build array of ptrs to DOCSTRs */
196 array
= (DOCSTR
**)xmalloc (cnt
* sizeof (*array
));
197 for (dp
= docs
, i
= 0; dp
!= NULL
; dp
= dp
->next
)
200 /* sort the array by name; within each name, by type */
202 qsort ((char*)array
, cnt
, sizeof (DOCSTR
*), cmpdoc
);
204 /* write the output header */
206 printf ("\\input texinfo @c -*-texinfo-*-\n");
207 printf ("@setfilename ../info/summary\n");
208 printf ("@settitle Command Summary for GNU Emacs\n");
209 printf ("@finalout\n");
210 printf ("@unnumbered Command Summary for GNU Emacs\n");
211 printf ("@table @asis\n");
214 printf ("@global@let@ITEM@item\n");
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");
227 printf ("@end iftex\n");
229 /* print each function from the array */
231 for (i
= 0; i
< cnt
; i
++)
233 printf ("\n@item %s @code{%s}\n@display\n",
234 array
[i
]->type
== 'F' ? "Function" : "Variable",
237 for (lp
= array
[i
]->first
; lp
!= NULL
; lp
= lp
->next
)
239 for (bp
= lp
->line
; *bp
; bp
++)
241 /* the characters "@{}" need special treatment */
242 if (*bp
== '@' || *bp
== '{' || *bp
== '}')
250 printf("@end display\n");
251 /* Try to avoid a save size overflow in the TeX output
253 if (i
%100 == 0 && i
> 0 && i
!= cnt
)
254 printf("\n@end table\n@table @asis\n");
257 printf ("@end table\n");