[CCID3]: Sending time: update to ktime_t
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / zorro / gen-devlist.c
blob16fe206f9998bc1d8631646ccad12e0782286032
1 /*
2 * Generate devlist.h from the Zorro ID file.
4 * (c) 2000 Geert Uytterhoeven <geert@linux-m68k.org>
6 * Based on the PCI version:
8 * (c) 1999--2000 Martin Mares <mj@ucw.cz>
9 */
11 #include <stdio.h>
12 #include <string.h>
14 #define MAX_NAME_SIZE 63
16 static void
17 pq(FILE *f, const char *c)
19 while (*c) {
20 if (*c == '"')
21 fprintf(f, "\\\"");
22 else
23 fputc(*c, f);
24 c++;
28 int
29 main(void)
31 char line[1024], *c, *bra, manuf[8];
32 int manufs = 0;
33 int mode = 0;
34 int lino = 0;
35 int manuf_len = 0;
36 FILE *devf;
38 devf = fopen("devlist.h", "w");
39 if (!devf) {
40 fprintf(stderr, "Cannot create output file!\n");
41 return 1;
44 while (fgets(line, sizeof(line)-1, stdin)) {
45 lino++;
46 if ((c = strchr(line, '\n')))
47 *c = 0;
48 if (!line[0] || line[0] == '#')
49 continue;
50 if (line[0] == '\t') {
51 switch (mode) {
52 case 1:
53 if (strlen(line) > 5 && line[5] == ' ') {
54 c = line + 5;
55 while (*c == ' ')
56 *c++ = 0;
57 if (manuf_len + strlen(c) + 1 > MAX_NAME_SIZE) {
58 /* Too long, try cutting off long description */
59 bra = strchr(c, '[');
60 if (bra && bra > c && bra[-1] == ' ')
61 bra[-1] = 0;
62 if (manuf_len + strlen(c) + 1 > MAX_NAME_SIZE) {
63 fprintf(stderr, "Line %d: Product name too long\n", lino);
64 return 1;
67 fprintf(devf, "\tPRODUCT(%s,%s,\"", manuf, line+1);
68 pq(devf, c);
69 fputs("\")\n", devf);
70 } else goto err;
71 break;
72 default:
73 goto err;
75 } else if (strlen(line) > 4 && line[4] == ' ') {
76 c = line + 4;
77 while (*c == ' ')
78 *c++ = 0;
79 if (manufs)
80 fputs("ENDMANUF()\n\n", devf);
81 manufs++;
82 strcpy(manuf, line);
83 manuf_len = strlen(c);
84 if (manuf_len + 24 > MAX_NAME_SIZE) {
85 fprintf(stderr, "Line %d: manufacturer name too long\n", lino);
86 return 1;
88 fprintf(devf, "MANUF(%s,\"", manuf);
89 pq(devf, c);
90 fputs("\")\n", devf);
91 mode = 1;
92 } else {
93 err:
94 fprintf(stderr, "Line %d: Syntax error in mode %d: %s\n", lino, mode, line);
95 return 1;
98 fputs("ENDMANUF()\n\
99 \n\
100 #undef MANUF\n\
101 #undef PRODUCT\n\
102 #undef ENDMANUF\n", devf);
104 fclose(devf);
106 return 0;