annotate lib-src/sorted-doc.c @ 5406:061f4f90f874

Convert lib-src/ to GPLv3.
author Mike Sperber <sperber@deinprogramm.de>
date Mon, 18 Oct 2010 14:02:19 +0200
parents ecf1ebac70d8
children 1f0b15040456
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
1 /* Give this program DOC-mm.nn.oo as standard input and it outputs to
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
2 standard output a file of texinfo input containing the doc strings.
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
3
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
4 Copyright (C) 1989, 1992, 1994, 1996, 1999, 2000, 2001, 2002, 2003,
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
5 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
6
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
7 This file is part of XEmacs.
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
8
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
9 XEmacs is free software: you can redistribute it and/or modify
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
10 it under the terms of the GNU General Public License as published by
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
11 the Free Software Foundation, either version 3 of the License, or
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
12 (at your option) any later version.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
14 XEmacs is distributed in the hope that it will be useful,
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
17 GNU General Public License for more details.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
19 You should have received a copy of the GNU General Public License
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
20 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
21
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
22
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
23 /* This version sorts the output by function name. */
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
24
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
25 #ifdef HAVE_CONFIG_H
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
26 #include <config.h>
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
27 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 #include <stdio.h>
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
30 #include <stdlib.h>
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
31 #include <string.h>
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 #include <ctype.h>
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
33 #ifdef DOS_NT
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
34 #include <fcntl.h> /* for O_BINARY */
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
35 #include <io.h> /* for setmode */
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
36 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 #define NUL '\0'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 #define MARKER '\037'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 #define DEBUG 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
43 typedef struct line LINE;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
45 struct line
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 LINE *next; /* ptr to next or NULL */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 char *line; /* text of the line */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 typedef struct docstr DOCSTR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 struct docstr /* Allocated thing for an entry. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 DOCSTR *next; /* next in the chain */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 char *name; /* name of the function or var */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 LINE *first; /* first line of doc text. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 char type; /* 'F' for function, 'V' for variable */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
61 void error (char *s1, char *s2);
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
62 void fatal (char *s1, char *s2);
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
63 char *xmalloc (int size);
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
64 char *xstrdup (char *str);
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
65 int cmpdoc (DOCSTR **a, DOCSTR **b);
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
66
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
67 typedef int (*sort_function_t)(const void *, const void *);
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
68
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
72 void
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 error (char *s1, char *s2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 fprintf (stderr, "sorted-doc: ");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 fprintf (stderr, s1, s2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 fprintf (stderr, "\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 /* Print error message and exit. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
82 void
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 fatal (char *s1, char *s2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 error (s1, s2);
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
86 exit (EXIT_FAILURE);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 /* Like malloc but get fatal error if memory is exhausted. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
91 char *
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
92 xmalloc (int size)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 {
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
94 char *result = malloc ((unsigned)size);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 if (result == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 fatal ("%s", "virtual memory exhausted");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
100 char *
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
101 xstrdup (char *str)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 {
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
103 char *buf = xmalloc (strlen (str) + 1);
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
104 (void) strcpy (buf, str);
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
105 return (buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 /* Comparison function for qsort to call. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
110 int
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 cmpdoc (DOCSTR **a, DOCSTR **b)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 register int val = strcmp ((*a)->name, (*b)->name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 if (val) return val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 return (*a)->type - (*b)->type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 enum state
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 WAITING, BEG_NAME, NAME_GET, BEG_DESC, DESC_GET
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
124 char *states[] =
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 "WAITING", "BEG_NAME", "NAME_GET", "BEG_DESC", "DESC_GET"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 };
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
128
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 int
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
130 main (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 register DOCSTR *dp = NULL; /* allocated DOCSTR */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 register LINE *lp = NULL; /* allocated line */
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
134 register char *bp; /* ptr inside line buffer */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 register enum state state = WAITING; /* state at start */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 int cnt = 0; /* number of DOCSTRs read */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
138 DOCSTR *docs = NULL; /* chain of allocated DOCSTRS */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 char buf[512]; /* line buffer */
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
140
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
141 #ifdef DOS_NT
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
142 /* DOC is a binary file. */
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
143 if (!isatty (fileno (stdin)))
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
144 setmode (fileno (stdin), O_BINARY);
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
145 #endif
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
146
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
147 bp = buf;
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
148
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 while (1) /* process one char at a time */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 /* this char from the DOCSTR file */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 register int ch = getchar ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 /* Beginnings */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 if (state == WAITING)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 if (ch == MARKER)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 state = BEG_NAME;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 else if (state == BEG_NAME)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 cnt++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 if (dp == NULL) /* first dp allocated */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 docs = dp = (DOCSTR*) xmalloc (sizeof (DOCSTR));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 else /* all the rest */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 dp->next = (DOCSTR*) xmalloc (sizeof (DOCSTR));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 dp = dp->next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 lp = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 dp->next = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 bp = buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 state = NAME_GET;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 /* Record whether function or variable. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 dp->type = ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 ch = getchar ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 else if (state == BEG_DESC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 if (lp == NULL) /* first line for dp */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 dp->first = lp = (LINE*)xmalloc (sizeof (LINE));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 else /* continuing lines */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 lp->next = (LINE*)xmalloc (sizeof (LINE));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 lp = lp->next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 lp->next = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 bp = buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 state = DESC_GET;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 }
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
196
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 /* process gets */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 if (state == NAME_GET || state == DESC_GET)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 if (ch != MARKER && ch != '\n' && ch != EOF)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 *bp++ = ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 else /* saving and changing state */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 *bp = NUL;
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
208 bp = xstrdup (buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 if (state == NAME_GET)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 dp->name = bp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 lp->line = bp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 bp = buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 state = (ch == MARKER) ? BEG_NAME : BEG_DESC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 } /* NAME_GET || DESC_GET */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 if (ch == EOF)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 DOCSTR **array;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 register int i; /* counter */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 /* build array of ptrs to DOCSTRs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 array = (DOCSTR**)xmalloc (cnt * sizeof (*array));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 for (dp = docs, i = 0; dp != NULL ; dp = dp->next)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 array[i++] = dp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 /* sort the array by name; within each name, by type */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
235 qsort ((char*)array, cnt, sizeof (DOCSTR*), (sort_function_t)cmpdoc);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 /* write the output header */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 printf ("\\input texinfo @c -*-texinfo-*-\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 printf ("@setfilename ../info/summary\n");
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 442
diff changeset
241 printf ("@settitle Command Summary for XEmacs\n");
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
242 printf ("@finalout\n");
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 442
diff changeset
243 printf ("@unnumbered Command Summary for XEmacs\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 printf ("@table @asis\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 printf ("\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 printf ("@iftex\n");
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
247 printf ("@global@let@ITEM@item\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 printf ("@def@item{@filbreak@vskip5pt@ITEM}\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 printf ("@font@tensy cmsy10 scaled @magstephalf\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 printf ("@font@teni cmmi10 scaled @magstephalf\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 printf ("@def\\{{@tensy@char110}}\n"); /* this backslash goes with cmr10 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 printf ("@def|{{@tensy@char106}}\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 printf ("@def@{{{@tensy@char102}}\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 printf ("@def@}{{@tensy@char103}}\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 printf ("@def<{{@teni@char62}}\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 printf ("@def>{{@teni@char60}}\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 printf ("@chardef@@64\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 printf ("@catcode43=12\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 printf ("@tableindent-0.2in\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 printf ("@end iftex\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 /* print each function from the array */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 for (i = 0; i < cnt; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 printf ("\n@item %s @code{%s}\n@display\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 array[i]->type == 'F' ? "Function" : "Variable",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 array[i]->name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 for (lp = array[i]->first; lp != NULL ; lp = lp->next)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 for (bp = lp->line; *bp; bp++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 /* the characters "@{}" need special treatment */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 if (*bp == '@' || *bp == '{' || *bp == '}')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 putchar('@');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 putchar(*bp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 putchar ('\n');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 printf("@end display\n");
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
284 /* Try to avoid a save size overflow in the TeX output
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
285 routine. */
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
286 if (i%100 == 0 && i > 0 && i != cnt)
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
287 printf("\n@end table\n@table @asis\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 printf ("@end table\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 printf ("@bye\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
294 return EXIT_SUCCESS;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 }
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
296
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 2367
diff changeset
297 /* sorted-doc.c ends here */