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, 2007, 2008, 2009 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 3 of the License, or
12 (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>. */
23 /* This version sorts the output by function name. */
32 #include <fcntl.h> /* for O_BINARY */
33 #include <io.h> /* for setmode */
35 #ifndef HAVE_STDLIB_H /* config.h includes stdlib. */
36 #ifndef WINDOWSNT /* src/s/ms-w32.h includes stdlib.h */
37 extern char *malloc ();
46 typedef struct line LINE
;
50 LINE
*next
; /* ptr to next or NULL */
51 char *line
; /* text of the line */
54 typedef struct docstr DOCSTR
;
56 struct docstr
/* Allocated thing for an entry. */
58 DOCSTR
*next
; /* next in the chain */
59 char *name
; /* name of the function or var */
60 LINE
*first
; /* first line of doc text. */
61 char type
; /* 'F' for function, 'V' for variable */
65 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
71 fprintf (stderr
, "sorted-doc: ");
72 fprintf (stderr
, s1
, s2
);
73 fprintf (stderr
, "\n");
76 /* Print error message and exit. */
86 /* Like malloc but get fatal error if memory is exhausted. */
92 char *result
= malloc ((unsigned)size
);
94 fatal ("%s", "virtual memory exhausted");
102 char *buf
= xmalloc (strlen (str
) + 1);
103 (void) strcpy (buf
, str
);
107 /* Comparison function for qsort to call. */
114 register int val
= strcmp ((*a
)->name
, (*b
)->name
);
116 return (*a
)->type
- (*b
)->type
;
122 WAITING
, BEG_NAME
, NAME_GET
, BEG_DESC
, DESC_GET
127 "WAITING", "BEG_NAME", "NAME_GET", "BEG_DESC", "DESC_GET"
133 register DOCSTR
*dp
= NULL
; /* allocated DOCSTR */
134 register LINE
*lp
= NULL
; /* allocated line */
135 register char *bp
; /* ptr inside line buffer */
136 register enum state state
= WAITING
; /* state at start */
137 int cnt
= 0; /* number of DOCSTRs read */
139 DOCSTR
*docs
= NULL
; /* chain of allocated DOCSTRS */
140 char buf
[512]; /* line buffer */
143 /* DOC is a binary file. */
144 if (!isatty (fileno (stdin
)))
145 setmode (fileno (stdin
), O_BINARY
);
150 while (1) /* process one char at a time */
152 /* this char from the DOCSTR file */
153 register int ch
= getchar ();
157 if (state
== WAITING
)
162 else if (state
== BEG_NAME
)
165 if (dp
== NULL
) /* first dp allocated */
167 docs
= dp
= (DOCSTR
*) xmalloc (sizeof (DOCSTR
));
169 else /* all the rest */
171 dp
->next
= (DOCSTR
*) xmalloc (sizeof (DOCSTR
));
178 /* Record whether function or variable. */
182 else if (state
== BEG_DESC
)
184 if (lp
== NULL
) /* first line for dp */
186 dp
->first
= lp
= (LINE
*)xmalloc (sizeof (LINE
));
188 else /* continuing lines */
190 lp
->next
= (LINE
*)xmalloc (sizeof (LINE
));
200 if (state
== NAME_GET
|| state
== DESC_GET
)
202 if (ch
!= MARKER
&& ch
!= '\n' && ch
!= EOF
)
206 else /* saving and changing state */
211 if (state
== NAME_GET
)
217 state
= (ch
== MARKER
) ? BEG_NAME
: BEG_DESC
;
219 } /* NAME_GET || DESC_GET */
226 register int i
; /* counter */
228 /* build array of ptrs to DOCSTRs */
230 array
= (DOCSTR
**)xmalloc (cnt
* sizeof (*array
));
231 for (dp
= docs
, i
= 0; dp
!= NULL
; dp
= dp
->next
)
234 /* sort the array by name; within each name, by type */
236 qsort ((char*)array
, cnt
, sizeof (DOCSTR
*), cmpdoc
);
238 /* write the output header */
240 printf ("\\input texinfo @c -*-texinfo-*-\n");
241 printf ("@setfilename ../info/summary\n");
242 printf ("@settitle Command Summary for GNU Emacs\n");
243 printf ("@finalout\n");
244 printf ("@unnumbered Command Summary for GNU Emacs\n");
245 printf ("@table @asis\n");
248 printf ("@global@let@ITEM@item\n");
249 printf ("@def@item{@filbreak@vskip5pt@ITEM}\n");
250 printf ("@font@tensy cmsy10 scaled @magstephalf\n");
251 printf ("@font@teni cmmi10 scaled @magstephalf\n");
252 printf ("@def\\{{@tensy@char110}}\n"); /* this backslash goes with cmr10 */
253 printf ("@def|{{@tensy@char106}}\n");
254 printf ("@def@{{{@tensy@char102}}\n");
255 printf ("@def@}{{@tensy@char103}}\n");
256 printf ("@def<{{@teni@char62}}\n");
257 printf ("@def>{{@teni@char60}}\n");
258 printf ("@chardef@@64\n");
259 printf ("@catcode43=12\n");
260 printf ("@tableindent-0.2in\n");
261 printf ("@end iftex\n");
263 /* print each function from the array */
265 for (i
= 0; i
< cnt
; i
++)
267 printf ("\n@item %s @code{%s}\n@display\n",
268 array
[i
]->type
== 'F' ? "Function" : "Variable",
271 for (lp
= array
[i
]->first
; lp
!= NULL
; lp
= lp
->next
)
273 for (bp
= lp
->line
; *bp
; bp
++)
275 /* the characters "@{}" need special treatment */
276 if (*bp
== '@' || *bp
== '{' || *bp
== '}')
284 printf("@end display\n");
285 /* Try to avoid a save size overflow in the TeX output
287 if (i
%100 == 0 && i
> 0 && i
!= cnt
)
288 printf("\n@end table\n@table @asis\n");
291 printf ("@end table\n");
298 /* arch-tag: ce28f204-1e70-4b34-8210-3d54a5662071
299 (do not change this comment) */
301 /* sorted-doc.c ends here */