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 and exit. */
47 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
52 fprintf (stderr
, "sorted-doc: ");
53 fprintf (stderr
, s1
, s2
);
54 fprintf (stderr
, "\n");
57 /* Like malloc but get fatal error if memory is exhausted. */
63 char *result
= malloc ((unsigned)size
);
65 fatal ("%s", "virtual memory exhausted");
73 char *buf
= xmalloc (strlen (str
) + 1);
74 (void) strcpy (buf
, str
);
78 /* Comparison function for qsort to call. */
85 register int val
= strcmp ((*a
)->name
, (*b
)->name
);
87 return (*a
)->type
- (*b
)->type
;
93 WAITING
, BEG_NAME
, NAME_GET
, BEG_DESC
, DESC_GET
98 "WAITING", "BEG_NAME", "NAME_GET", "BEG_DESC", "DESC_GET"
103 register DOCSTR
*dp
= NULL
; /* allocated DOCSTR */
104 register LINE
*lp
= NULL
; /* allocated line */
105 register char *bp
; /* ptr inside line buffer */
106 int notfirst
= 0; /* set after read something */
107 register enum state state
= WAITING
; /* state at start */
108 int cnt
= 0; /* number of DOCSTRs read */
110 DOCSTR
*docs
; /* chain of allocated DOCSTRS */
111 char buf
[512]; /* line buffer */
113 while (1) /* process one char at a time */
115 /* this char from the DOCSTR file */
116 register int ch
= getchar ();
120 if (state
== WAITING
)
125 else if (state
== BEG_NAME
)
128 if (dp
== NULL
) /* first dp allocated */
130 docs
= dp
= (DOCSTR
*) xmalloc (sizeof (DOCSTR
));
132 else /* all the rest */
134 dp
->next
= (DOCSTR
*) xmalloc (sizeof (DOCSTR
));
141 /* Record whether function or variable. */
145 else if (state
== BEG_DESC
)
147 if (lp
== NULL
) /* first line for dp */
149 dp
->first
= lp
= (LINE
*)xmalloc (sizeof (LINE
));
151 else /* continuing lines */
153 lp
->next
= (LINE
*)xmalloc (sizeof (LINE
));
163 if (state
== NAME_GET
|| state
== DESC_GET
)
165 if (ch
!= MARKER
&& ch
!= '\n' && ch
!= EOF
)
169 else /* saving and changing state */
174 if (state
== NAME_GET
)
180 state
= (ch
== MARKER
) ? BEG_NAME
: BEG_DESC
;
182 } /* NAME_GET || DESC_GET */
189 register int i
; /* counter */
191 /* build array of ptrs to DOCSTRs */
193 array
= (DOCSTR
**)xmalloc (cnt
* sizeof (*array
));
194 for (dp
= docs
, i
= 0; dp
!= NULL
; dp
= dp
->next
)
197 /* sort the array by name; within each name, by type */
199 qsort ((char*)array
, cnt
, sizeof (DOCSTR
*), cmpdoc
);
201 /* write the output header */
203 printf ("\\input texinfo @c -*-texinfo-*-\n");
204 printf ("@setfilename ../info/summary\n");
205 printf ("@settitle Command Summary for GNU Emacs\n");
206 printf ("@unnumbered Command Summary for GNU Emacs\n");
207 printf ("@table @asis\n");
209 printf ("@let@ITEM@item\n");
210 printf ("@def@item{@filbreak@vskip5pt@ITEM}\n");
211 printf ("@font@tensy cmsy10 scaled @magstephalf\n");
212 printf ("@font@teni cmmi10 scaled @magstephalf\n");
213 printf ("@def\\{{@tensy@char110}}\n"); /* this backslash goes with cmr10 */
214 printf ("@def|{{@tensy@char106}}\n");
215 printf ("@def@{{{@tensy@char102}}\n");
216 printf ("@def@}{{@tensy@char103}}\n");
217 printf ("@def<{{@teni@char62}}\n");
218 printf ("@def>{{@teni@char60}}\n");
219 printf ("@chardef@@64\n");
220 printf ("@catcode43=12\n");
221 printf ("@tableindent-0.2in\n");
223 /* print each function from the array */
225 for (i
= 0; i
< cnt
; i
++)
227 printf ("\n@item %s @code{%s}\n@display\n",
228 array
[i
]->type
== 'F' ? "Function" : "Variable",
231 for (lp
= array
[i
]->first
; lp
!= NULL
; lp
= lp
->next
)
233 for (bp
= lp
->line
; *bp
; bp
++)
235 /* the characters "@{}" need special treatment */
236 if (*bp
== '@' || *bp
== '{' || *bp
== '}')
244 printf("@end display\n");
247 printf ("@end table\n");