| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
#ifdef HAVE_CONFIG_H |
|---|
| 27 |
#include <config.h> |
|---|
| 28 |
#endif |
|---|
| 29 |
|
|---|
| 30 |
#include <stdio.h> |
|---|
| 31 |
#include <ctype.h> |
|---|
| 32 |
#ifdef DOS_NT |
|---|
| 33 |
#include <fcntl.h> |
|---|
| 34 |
#include <io.h> |
|---|
| 35 |
#endif |
|---|
| 36 |
#ifndef HAVE_STDLIB_H |
|---|
| 37 |
#ifndef WINDOWSNT |
|---|
| 38 |
extern char *malloc (); |
|---|
| 39 |
#endif |
|---|
| 40 |
#endif |
|---|
| 41 |
|
|---|
| 42 |
#define NUL '\0' |
|---|
| 43 |
#define MARKER '\037' |
|---|
| 44 |
|
|---|
| 45 |
#define DEBUG 0 |
|---|
| 46 |
|
|---|
| 47 |
typedef struct line LINE; |
|---|
| 48 |
|
|---|
| 49 |
struct line |
|---|
| 50 |
{ |
|---|
| 51 |
LINE *next; |
|---|
| 52 |
char *line; |
|---|
| 53 |
}; |
|---|
| 54 |
|
|---|
| 55 |
typedef struct docstr DOCSTR; |
|---|
| 56 |
|
|---|
| 57 |
struct docstr |
|---|
| 58 |
{ |
|---|
| 59 |
DOCSTR *next; |
|---|
| 60 |
char *name; |
|---|
| 61 |
LINE *first; |
|---|
| 62 |
char type; |
|---|
| 63 |
}; |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
void |
|---|
| 69 |
error (s1, s2) |
|---|
| 70 |
char *s1, *s2; |
|---|
| 71 |
{ |
|---|
| 72 |
fprintf (stderr, "sorted-doc: "); |
|---|
| 73 |
fprintf (stderr, s1, s2); |
|---|
| 74 |
fprintf (stderr, "\n"); |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
void |
|---|
| 80 |
fatal (s1, s2) |
|---|
| 81 |
char *s1, *s2; |
|---|
| 82 |
{ |
|---|
| 83 |
error (s1, s2); |
|---|
| 84 |
exit (EXIT_FAILURE); |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
char * |
|---|
| 90 |
xmalloc (size) |
|---|
| 91 |
int size; |
|---|
| 92 |
{ |
|---|
| 93 |
char *result = malloc ((unsigned)size); |
|---|
| 94 |
if (result == NULL) |
|---|
| 95 |
fatal ("%s", "virtual memory exhausted"); |
|---|
| 96 |
return result; |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
char * |
|---|
| 100 |
xstrdup (str) |
|---|
| 101 |
char * str; |
|---|
| 102 |
{ |
|---|
| 103 |
char *buf = xmalloc (strlen (str) + 1); |
|---|
| 104 |
(void) strcpy (buf, str); |
|---|
| 105 |
return (buf); |
|---|
| 106 |
} |
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
int |
|---|
| 111 |
cmpdoc (a, b) |
|---|
| 112 |
DOCSTR **a; |
|---|
| 113 |
DOCSTR **b; |
|---|
| 114 |
{ |
|---|
| 115 |
register int val = strcmp ((*a)->name, (*b)->name); |
|---|
| 116 |
if (val) return val; |
|---|
| 117 |
return (*a)->type - (*b)->type; |
|---|
| 118 |
} |
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
enum state |
|---|
| 122 |
{ |
|---|
| 123 |
WAITING, BEG_NAME, NAME_GET, BEG_DESC, DESC_GET |
|---|
| 124 |
}; |
|---|
| 125 |
|
|---|
| 126 |
char *states[] = |
|---|
| 127 |
{ |
|---|
| 128 |
"WAITING", "BEG_NAME", "NAME_GET", "BEG_DESC", "DESC_GET" |
|---|
| 129 |
}; |
|---|
| 130 |
|
|---|
| 131 |
int |
|---|
| 132 |
main () |
|---|
| 133 |
{ |
|---|
| 134 |
register DOCSTR *dp = NULL; |
|---|
| 135 |
register LINE *lp = NULL; |
|---|
| 136 |
register char *bp; |
|---|
| 137 |
register enum state state = WAITING; |
|---|
| 138 |
int cnt = 0; |
|---|
| 139 |
|
|---|
| 140 |
DOCSTR *docs = NULL; |
|---|
| 141 |
char buf[512]; |
|---|
| 142 |
|
|---|
| 143 |
#ifdef DOS_NT |
|---|
| 144 |
|
|---|
| 145 |
if (!isatty (fileno (stdin))) |
|---|
| 146 |
setmode (fileno (stdin), O_BINARY); |
|---|
| 147 |
#endif |
|---|
| 148 |
|
|---|
| 149 |
bp = buf; |
|---|
| 150 |
|
|---|
| 151 |
while (1) |
|---|
| 152 |
{ |
|---|
| 153 |
|
|---|
| 154 |
register int ch = getchar (); |
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
if (state == WAITING) |
|---|
| 159 |
{ |
|---|
| 160 |
if (ch == MARKER) |
|---|
| 161 |
state = BEG_NAME; |
|---|
| 162 |
} |
|---|
| 163 |
else if (state == BEG_NAME) |
|---|
| 164 |
{ |
|---|
| 165 |
cnt++; |
|---|
| 166 |
if (dp == NULL) |
|---|
| 167 |
{ |
|---|
| 168 |
docs = dp = (DOCSTR*) xmalloc (sizeof (DOCSTR)); |
|---|
| 169 |
} |
|---|
| 170 |
else |
|---|
| 171 |
{ |
|---|
| 172 |
dp->next = (DOCSTR*) xmalloc (sizeof (DOCSTR)); |
|---|
| 173 |
dp = dp->next; |
|---|
| 174 |
} |
|---|
| 175 |
lp = NULL; |
|---|
| 176 |
dp->next = NULL; |
|---|
| 177 |
bp = buf; |
|---|
| 178 |
state = NAME_GET; |
|---|
| 179 |
|
|---|
| 180 |
dp->type = ch; |
|---|
| 181 |
ch = getchar (); |
|---|
| 182 |
} |
|---|
| 183 |
else if (state == BEG_DESC) |
|---|
| 184 |
{ |
|---|
| 185 |
if (lp == NULL) |
|---|
| 186 |
{ |
|---|
| 187 |
dp->first = lp = (LINE*)xmalloc (sizeof (LINE)); |
|---|
| 188 |
} |
|---|
| 189 |
else |
|---|
| 190 |
{ |
|---|
| 191 |
lp->next = (LINE*)xmalloc (sizeof (LINE)); |
|---|
| 192 |
lp = lp->next; |
|---|
| 193 |
} |
|---|
| 194 |
lp->next = NULL; |
|---|
| 195 |
bp = buf; |
|---|
| 196 |
state = DESC_GET; |
|---|
| 197 |
} |
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
if (state == NAME_GET || state == DESC_GET) |
|---|
| 202 |
{ |
|---|
| 203 |
if (ch != MARKER && ch != '\n' && ch != EOF) |
|---|
| 204 |
{ |
|---|
| 205 |
*bp++ = ch; |
|---|
| 206 |
} |
|---|
| 207 |
else |
|---|
| 208 |
{ |
|---|
| 209 |
*bp = NUL; |
|---|
| 210 |
bp = xstrdup (buf); |
|---|
| 211 |
|
|---|
| 212 |
if (state == NAME_GET) |
|---|
| 213 |
dp->name = bp; |
|---|
| 214 |
else |
|---|
| 215 |
lp->line = bp; |
|---|
| 216 |
|
|---|
| 217 |
bp = buf; |
|---|
| 218 |
state = (ch == MARKER) ? BEG_NAME : BEG_DESC; |
|---|
| 219 |
} |
|---|
| 220 |
} |
|---|
| 221 |
if (ch == EOF) |
|---|
| 222 |
break; |
|---|
| 223 |
} |
|---|
| 224 |
|
|---|
| 225 |
{ |
|---|
| 226 |
DOCSTR **array; |
|---|
| 227 |
register int i; |
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 |
array = (DOCSTR**)xmalloc (cnt * sizeof (*array)); |
|---|
| 232 |
for (dp = docs, i = 0; dp != NULL ; dp = dp->next) |
|---|
| 233 |
array[i++] = dp; |
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 |
qsort ((char*)array, cnt, sizeof (DOCSTR*), cmpdoc); |
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 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"); |
|---|
| 247 |
printf ("\n"); |
|---|
| 248 |
printf ("@iftex\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"); |
|---|
| 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"); |
|---|
| 263 |
|
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 |
for (i = 0; i < cnt; i++) |
|---|
| 267 |
{ |
|---|
| 268 |
printf ("\n@item %s @code{%s}\n@display\n", |
|---|
| 269 |
array[i]->type == 'F' ? "Function" : "Variable", |
|---|
| 270 |
array[i]->name); |
|---|
| 271 |
|
|---|
| 272 |
for (lp = array[i]->first; lp != NULL ; lp = lp->next) |
|---|
| 273 |
{ |
|---|
| 274 |
for (bp = lp->line; *bp; bp++) |
|---|
| 275 |
{ |
|---|
| 276 |
|
|---|
| 277 |
if (*bp == '@' || *bp == '{' || *bp == '}') |
|---|
| 278 |
{ |
|---|
| 279 |
putchar('@'); |
|---|
| 280 |
} |
|---|
| 281 |
putchar(*bp); |
|---|
| 282 |
} |
|---|
| 283 |
putchar ('\n'); |
|---|
| 284 |
} |
|---|
| 285 |
printf("@end display\n"); |
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
if (i%100 == 0 && i > 0 && i != cnt) |
|---|
| 289 |
printf("\n@end table\n@table @asis\n"); |
|---|
| 290 |
} |
|---|
| 291 |
|
|---|
| 292 |
printf ("@end table\n"); |
|---|
| 293 |
printf ("@bye\n"); |
|---|
| 294 |
} |
|---|
| 295 |
|
|---|
| 296 |
return EXIT_SUCCESS; |
|---|
| 297 |
} |
|---|
| 298 |
|
|---|
| 299 |
|
|---|
| 300 |
|
|---|
| 301 |
|
|---|
| 302 |
|
|---|