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 extern char *malloc ();
19 typedef struct line LINE
;
23 LINE
*next
; /* ptr to next or NULL */
24 char *line
; /* text of the line */
27 typedef struct docstr DOCSTR
;
29 struct docstr
/* Allocated thing for an entry. */
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 */
38 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
44 fprintf (stderr
, "sorted-doc: ");
45 fprintf (stderr
, s1
, s2
);
46 fprintf (stderr
, "\n");
49 /* Print error message and exit. */
59 /* Like malloc but get fatal error if memory is exhausted. */
65 char *result
= malloc ((unsigned)size
);
67 fatal ("%s", "virtual memory exhausted");
75 char *buf
= xmalloc (strlen (str
) + 1);
76 (void) strcpy (buf
, str
);
80 /* Comparison function for qsort to call. */
87 register int val
= strcmp ((*a
)->name
, (*b
)->name
);
89 return (*a
)->type
- (*b
)->type
;
95 WAITING
, BEG_NAME
, NAME_GET
, BEG_DESC
, DESC_GET
100 "WAITING", "BEG_NAME", "NAME_GET", "BEG_DESC", "DESC_GET"
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 */
112 DOCSTR
*docs
; /* chain of allocated DOCSTRS */
113 char buf
[512]; /* line buffer */
115 while (1) /* process one char at a time */
117 /* this char from the DOCSTR file */
118 register int ch
= getchar ();
122 if (state
== WAITING
)
127 else if (state
== BEG_NAME
)
130 if (dp
== NULL
) /* first dp allocated */
132 docs
= dp
= (DOCSTR
*) xmalloc (sizeof (DOCSTR
));
134 else /* all the rest */
136 dp
->next
= (DOCSTR
*) xmalloc (sizeof (DOCSTR
));
143 /* Record whether function or variable. */
147 else if (state
== BEG_DESC
)
149 if (lp
== NULL
) /* first line for dp */
151 dp
->first
= lp
= (LINE
*)xmalloc (sizeof (LINE
));
153 else /* continuing lines */
155 lp
->next
= (LINE
*)xmalloc (sizeof (LINE
));
165 if (state
== NAME_GET
|| state
== DESC_GET
)
167 if (ch
!= MARKER
&& ch
!= '\n' && ch
!= EOF
)
171 else /* saving and changing state */
176 if (state
== NAME_GET
)
182 state
= (ch
== MARKER
) ? BEG_NAME
: BEG_DESC
;
184 } /* NAME_GET || DESC_GET */
191 register int i
; /* counter */
193 /* build array of ptrs to DOCSTRs */
195 array
= (DOCSTR
**)xmalloc (cnt
* sizeof (*array
));
196 for (dp
= docs
, i
= 0; dp
!= NULL
; dp
= dp
->next
)
199 /* sort the array by name; within each name, by type */
201 qsort ((char*)array
, cnt
, sizeof (DOCSTR
*), cmpdoc
);
203 /* write the output header */
205 printf ("\\input texinfo @c -*-texinfo-*-\n");
206 printf ("@setfilename ../info/summary\n");
207 printf ("@settitle Command Summary for GNU Emacs\n");
208 printf ("@unnumbered Command Summary for GNU Emacs\n");
209 printf ("@table @asis\n");
211 printf ("@let@ITEM@item\n");
212 printf ("@def@item{@filbreak@vskip5pt@ITEM}\n");
213 printf ("@font@tensy cmsy10 scaled @magstephalf\n");
214 printf ("@font@teni cmmi10 scaled @magstephalf\n");
215 printf ("@def\\{{@tensy@char110}}\n"); /* this backslash goes with cmr10 */
216 printf ("@def|{{@tensy@char106}}\n");
217 printf ("@def@{{{@tensy@char102}}\n");
218 printf ("@def@}{{@tensy@char103}}\n");
219 printf ("@def<{{@teni@char62}}\n");
220 printf ("@def>{{@teni@char60}}\n");
221 printf ("@chardef@@64\n");
222 printf ("@catcode43=12\n");
223 printf ("@tableindent-0.2in\n");
225 /* print each function from the array */
227 for (i
= 0; i
< cnt
; i
++)
229 printf ("\n@item %s @code{%s}\n@display\n",
230 array
[i
]->type
== 'F' ? "Function" : "Variable",
233 for (lp
= array
[i
]->first
; lp
!= NULL
; lp
= lp
->next
)
235 for (bp
= lp
->line
; *bp
; bp
++)
237 /* the characters "@{}" need special treatment */
238 if (*bp
== '@' || *bp
== '{' || *bp
== '}')
246 printf("@end display\n");
249 printf ("@end table\n");