Linux Audio

Check our new training course

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