2 * Generate devlist.h and classlist.h from the PCI ID file.
4 * (c) 1999--2002 Martin Mares <mj@ucw.cz>
10 #define MAX_NAME_SIZE 200
13 pq(FILE *f, const char *c, int len)
16 while (*c && i != len) {
21 if (*c == '?' && c[1] == '?') {
34 char line[1024], *c, *bra, vend[8];
41 devf = fopen("devlist.h", "w");
42 clsf = fopen("classlist.h", "w");
44 fprintf(stderr, "Cannot create output file!\n");
48 while (fgets(line, sizeof(line)-1, stdin)) {
50 if ((c = strchr(line, '\n')))
52 if (!line[0] || line[0] == '#')
55 if (line[0] == 'C' && strlen(line) > 4 && line[4] == ' ') {
62 else if (line[0] == '\t') {
67 if (strlen(line) > 5 && line[5] == ' ') {
71 if (vendor_len + strlen(c) + 1 > MAX_NAME_SIZE) {
72 /* Too long, try cutting off long description */
74 if (bra && bra > c && bra[-1] == ' ')
76 if (vendor_len + strlen(c) + 1 > MAX_NAME_SIZE) {
77 fprintf(stderr, "Line %d: Device name too long. Name truncated.\n", lino);
78 fprintf(stderr, "%s\n", c);
82 fprintf(devf, "\tDEVICE(%s,%s,\"", vend, line+1);
83 pq(devf, c, MAX_NAME_SIZE - vendor_len - 1);
88 if (strlen(line) > 3 && line[3] == ' ') {
92 fprintf(clsf, "CLASS(%s%s, \"%s\")\n", vend, line+1, c);
98 } else if (strlen(line) > 4 && line[4] == ' ') {
103 fputs("ENDVENDOR()\n\n", devf);
106 vendor_len = strlen(c);
107 if (vendor_len + 24 > MAX_NAME_SIZE) {
108 fprintf(stderr, "Line %d: Vendor name too long\n", lino);
111 fprintf(devf, "VENDOR(%s,\"", vend);
113 fputs("\")\n", devf);
117 fprintf(stderr, "Line %d: Syntax error in mode %d: %s\n", lino, mode, line);
121 fputs("ENDVENDOR()\n\
125 #undef ENDVENDOR\n", devf);
126 fputs("\n#undef CLASS\n", clsf);