1
|
|
-#include <regex.h>
|
2
|
|
-#include <stdio.h>
|
3
|
|
-#include <stdlib.h>
|
4
|
|
-#include <string.h>
|
5
|
|
-
|
6
|
|
-struct Err {
|
7
|
|
- char *name;
|
8
|
|
- int num;
|
9
|
|
-#if 0
|
10
|
|
- char *descr;
|
11
|
|
-#endif
|
12
|
|
-} err[256];
|
13
|
|
-
|
14
|
|
-int nerr = 0;
|
15
|
|
-
|
16
|
|
-regex_t reg;
|
17
|
|
-
|
18
|
|
-void match(const char *line) {
|
19
|
|
- regmatch_t match[3];
|
20
|
|
- regoff_t len;
|
21
|
|
-
|
22
|
|
- if (regexec(®, line, 3, match, 0) == REG_NOMATCH)
|
23
|
|
- return;
|
24
|
|
-
|
25
|
|
- len = match[1].rm_eo - match[1].rm_so;
|
26
|
|
- err[nerr].name = malloc(len + 1);
|
27
|
|
- sprintf(err[nerr].name, "%.*s", len, line + match[1].rm_so);
|
28
|
|
-
|
29
|
|
- err[nerr].num = atoi(line + match[2].rm_so);
|
30
|
|
-
|
31
|
|
-#if 0
|
32
|
|
- err[nerr].descr = strerror(err[nerr].num);
|
33
|
|
-#endif
|
34
|
|
-
|
35
|
|
- nerr++;
|
36
|
|
-}
|
37
|
|
-
|
38
|
|
-int cmp(const void *a, const void *b) {
|
39
|
|
- return ((struct Err *)a)->num - ((struct Err *)b)->num;
|
40
|
|
-}
|
41
|
|
-
|
42
|
|
-int main(int argc, char **argv)
|
43
|
|
-{
|
44
|
|
- int i;
|
45
|
|
- FILE *fp;
|
46
|
|
- char line[1024];
|
47
|
|
-
|
48
|
|
- regcomp(®, "^#define[ \t]*(E[A-Z0-9]+)[ \t]*([0-9]+)", REG_EXTENDED);
|
49
|
|
-
|
50
|
|
- for (i = 1; i < argc; i++) {
|
51
|
|
- if ((fp = fopen(argv[i], "r")) == NULL) {
|
52
|
|
- perror("fopen");
|
53
|
|
- exit(1);
|
54
|
|
- }
|
55
|
|
- while (fgets(line, sizeof(line), fp) != NULL)
|
56
|
|
- match(line);
|
57
|
|
- fclose(fp);
|
58
|
|
- }
|
59
|
|
-
|
60
|
|
- qsort(err, nerr, sizeof(*err), cmp);
|
61
|
|
-
|
62
|
|
- /*
|
63
|
|
- * Print out CMUCL-style file header
|
64
|
|
- */
|
65
|
|
- puts(";;; -*- Package: UNIX -*-\n\
|
66
|
|
-;;;\n\
|
67
|
|
-;;; **********************************************************************\n\
|
68
|
|
-;;; This code was written as part of the CMU Common Lisp project at\n\
|
69
|
|
-;;; Carnegie Mellon University, and has been placed in the public domain.\n\
|
70
|
|
-;;;\n\
|
71
|
|
-(ext:file-comment\n\
|
72
|
|
- \"$Header: src/code/unix-errno.lisp $\")\n\
|
73
|
|
-;;;\n\
|
74
|
|
-;;; **********************************************************************\n\
|
75
|
|
-;;;\n\
|
76
|
|
-;;; This file contains the values of the UNIX errno values.\n\
|
77
|
|
-;;;\n \
|
78
|
|
-;;; DO NOT EDIT! This is auto-generated from create-errno.\n\
|
79
|
|
-;;;\n");
|
80
|
|
-
|
81
|
|
- puts("(in-package \"UNIX\")\n");
|
82
|
|
- for (i = 0; i < nerr; i++) {
|
83
|
|
-#if 0
|
84
|
|
- printf("(def-unix-error %s %d \"%s\")\n", err[i].name, err[i].num, err[i].descr);
|
85
|
|
-#else
|
86
|
|
- printf("(def-unix-error %s %d)\n", err[i].name, err[i].num);
|
87
|
|
-#endif
|
88
|
|
- }
|
89
|
|
-
|
90
|
|
- return 0;
|
91
|
|
-} |