1 /* Give this program DOC-mm.nn.oo as standard input and it outputs to
2 standard output a file of texinfo input containing the doc strings.
4 Copyright (C) 1989, 1992, 1994, 1996, 1999, 2000, 2001, 2002, 2003,
5 2004, 2005, 2006 Free Software Foundation, Inc.
7 This file is part of GNU Emacs.
9 GNU Emacs is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GNU Emacs is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU Emacs; see the file COPYING. If not, write to the
21 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA.
24 This version sorts the output by function name. */
33 #include <fcntl.h> /* for O_BINARY */
34 #include <io.h> /* for setmode */
36 #ifndef HAVE_STDLIB_H /* config.h includes stdlib. */
37 #ifndef WINDOWSNT /* src/s/ms-w32.h includes stdlib.h */
38 extern char *malloc ();
47 typedef struct line LINE
;
51 LINE
*next
; /* ptr to next or NULL */
52 char *line
; /* text of the line */
55 typedef struct docstr DOCSTR
;
57 struct docstr
/* Allocated thing for an entry. */
59 DOCSTR
*next
; /* next in the chain */
60 char *name
; /* name of the function or var */
61 LINE
*first
; /* first line of doc text. */
62 char type
; /* 'F' for function, 'V' for variable */
66 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
72 fprintf (stderr
, "sorted-doc: ");
73 fprintf (stderr
, s1
, s2
);
74 fprintf (stderr
, "\n");
77 /* Print error message and exit. */
87 /* Like malloc but get fatal error if memory is exhausted. */
93 char *result
= malloc ((unsigned)size
);
95 fatal ("%s", "virtual memory exhausted");
103 char *buf
= xmalloc (strlen (str
) + 1);
104 (void) strcpy (buf
, str
);
108 /* Comparison function for qsort to call. */
115 register int val
= strcmp ((*a
)->name
, (*b
)->name
);
117 return (*a
)->type
- (*b
)->type
;
123 WAITING
, BEG_NAME
, NAME_GET
, BEG_DESC
, DESC_GET
128 "WAITING", "BEG_NAME", "NAME_GET", "BEG_DESC", "DESC_GET"
134 register DOCSTR
*dp
= NULL
; /* allocated DOCSTR */
135 register LINE
*lp
= NULL
; /* allocated line */
136 register char *bp
; /* ptr inside line buffer */
137 register enum state state
= WAITING
; /* state at start */
138 int cnt
= 0; /* number of DOCSTRs read */
140 DOCSTR
*docs
= NULL
; /* chain of allocated DOCSTRS */
141 char buf
[512]; /* line buffer */
144 /* DOC is a binary file. */
145 if (!isatty (fileno (stdin
)))
146 setmode (fileno (stdin
), O_BINARY
);
151 while (1) /* process one char at a time */
153 /* this char from the DOCSTR file */
154 register int ch
= getchar ();
158 if (state
== WAITING
)
163 else if (state
== BEG_NAME
)
166 if (dp
== NULL
) /* first dp allocated */
168 docs
= dp
= (DOCSTR
*) xmalloc (sizeof (DOCSTR
));
170 else /* all the rest */
172 dp
->next
= (DOCSTR
*) xmalloc (sizeof (DOCSTR
));
179 /* Record whether function or variable. */
183 else if (state
== BEG_DESC
)
185 if (lp
== NULL
) /* first line for dp */
187 dp
->first
= lp
= (LINE
*)xmalloc (sizeof (LINE
));
189 else /* continuing lines */
191 lp
->next
= (LINE
*)xmalloc (sizeof (LINE
));
201 if (state
== NAME_GET
|| state
== DESC_GET
)
203 if (ch
!= MARKER
&& ch
!= '\n' && ch
!= EOF
)
207 else /* saving and changing state */
212 if (state
== NAME_GET
)
218 state
= (ch
== MARKER
) ? BEG_NAME
: BEG_DESC
;
220 } /* NAME_GET || DESC_GET */
227 register int i
; /* counter */
229 /* build array of ptrs to DOCSTRs */
231 array
= (DOCSTR
**)xmalloc (cnt
* sizeof (*array
));
232 for (dp
= docs
, i
= 0; dp
!= NULL
; dp
= dp
->next
)
235 /* sort the array by name; within each name, by type */
237 qsort ((char*)array
, cnt
, sizeof (DOCSTR
*), cmpdoc
);
239 /* write the output header */
241 printf ("\\input texinfo @c -*-texinfo-*-\n");
242 printf ("@setfilename ../info/summary\n");
243 printf ("@settitle Command Summary for GNU Emacs\n");
244 printf ("@finalout\n");
245 printf ("@unnumbered Command Summary for GNU Emacs\n");
246 printf ("@table @asis\n");
249 printf ("@global@let@ITEM@item\n");
250 printf ("@def@item{@filbreak@vskip5pt@ITEM}\n");
251 printf ("@font@tensy cmsy10 scaled @magstephalf\n");
252 printf ("@font@teni cmmi10 scaled @magstephalf\n");
253 printf ("@def\\{{@tensy@char110}}\n"); /* this backslash goes with cmr10 */
254 printf ("@def|{{@tensy@char106}}\n");
255 printf ("@def@{{{@tensy@char102}}\n");
256 printf ("@def@}{{@tensy@char103}}\n");
257 printf ("@def<{{@teni@char62}}\n");
258 printf ("@def>{{@teni@char60}}\n");
259 printf ("@chardef@@64\n");
260 printf ("@catcode43=12\n");
261 printf ("@tableindent-0.2in\n");
262 printf ("@end iftex\n");
264 /* print each function from the array */
266 for (i
= 0; i
< cnt
; i
++)
268 printf ("\n@item %s @code{%s}\n@display\n",
269 array
[i
]->type
== 'F' ? "Function" : "Variable",
272 for (lp
= array
[i
]->first
; lp
!= NULL
; lp
= lp
->next
)
274 for (bp
= lp
->line
; *bp
; bp
++)
276 /* the characters "@{}" need special treatment */
277 if (*bp
== '@' || *bp
== '{' || *bp
== '}')
285 printf("@end display\n");
286 /* Try to avoid a save size overflow in the TeX output
288 if (i
%100 == 0 && i
> 0 && i
!= cnt
)
289 printf("\n@end table\n@table @asis\n");
292 printf ("@end table\n");
299 /* arch-tag: ce28f204-1e70-4b34-8210-3d54a5662071
300 (do not change this comment) */
302 /* sorted-doc.c ends here */