^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * names.c -- USB name database manipulation routines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 1999, 2000 Thomas Sailer (sailer@ife.ee.ethz.ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2005 Takahiro Hirofuchi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * - names_deinit() is added.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <sys/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <sys/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <dirent.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "names.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "usbip_common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct vendor {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct vendor *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) u_int16_t vendorid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) char name[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct product {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct product *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) u_int16_t vendorid, productid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) char name[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct class {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct class *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) u_int8_t classid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) char name[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct subclass {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct subclass *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) u_int8_t classid, subclassid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) char name[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct protocol {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct protocol *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) u_int8_t classid, subclassid, protocolid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) char name[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct genericstrtable {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) struct genericstrtable *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) unsigned int num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) char name[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define HASH1 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define HASH2 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define HASHSZ 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static unsigned int hashnum(unsigned int num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) unsigned int mask1 = HASH1 << 27, mask2 = HASH2 << 27;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) for (; mask1 >= HASH1; mask1 >>= 1, mask2 >>= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (num & mask1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) num ^= mask2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) return num & (HASHSZ-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) static struct vendor *vendors[HASHSZ] = { NULL, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static struct product *products[HASHSZ] = { NULL, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static struct class *classes[HASHSZ] = { NULL, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static struct subclass *subclasses[HASHSZ] = { NULL, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static struct protocol *protocols[HASHSZ] = { NULL, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) const char *names_vendor(u_int16_t vendorid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct vendor *v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) v = vendors[hashnum(vendorid)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) for (; v; v = v->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (v->vendorid == vendorid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return v->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) const char *names_product(u_int16_t vendorid, u_int16_t productid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct product *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) p = products[hashnum((vendorid << 16) | productid)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) for (; p; p = p->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (p->vendorid == vendorid && p->productid == productid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return p->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) const char *names_class(u_int8_t classid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct class *c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) c = classes[hashnum(classid)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) for (; c; c = c->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (c->classid == classid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) return c->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) const char *names_subclass(u_int8_t classid, u_int8_t subclassid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct subclass *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) s = subclasses[hashnum((classid << 8) | subclassid)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) for (; s; s = s->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) if (s->classid == classid && s->subclassid == subclassid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return s->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) const char *names_protocol(u_int8_t classid, u_int8_t subclassid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) u_int8_t protocolid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct protocol *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) p = protocols[hashnum((classid << 16) | (subclassid << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) | protocolid)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) for (; p; p = p->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (p->classid == classid && p->subclassid == subclassid &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) p->protocolid == protocolid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return p->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /* add a cleanup function by takahiro */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct pool {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct pool *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) void *mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static struct pool *pool_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static void *my_malloc(size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct pool *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) p = calloc(1, sizeof(struct pool));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) p->mem = calloc(1, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (!p->mem) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) free(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) p->next = pool_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) pool_head = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) return p->mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) void names_free(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct pool *pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (!pool_head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) for (pool = pool_head; pool != NULL; ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct pool *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (pool->mem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) free(pool->mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) tmp = pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) pool = pool->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) free(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static int new_vendor(const char *name, u_int16_t vendorid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct vendor *v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) unsigned int h = hashnum(vendorid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) v = vendors[h];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) for (; v; v = v->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (v->vendorid == vendorid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) v = my_malloc(sizeof(struct vendor) + strlen(name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (!v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) strcpy(v->name, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) v->vendorid = vendorid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) v->next = vendors[h];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) vendors[h] = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static int new_product(const char *name, u_int16_t vendorid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) u_int16_t productid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct product *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) unsigned int h = hashnum((vendorid << 16) | productid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) p = products[h];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) for (; p; p = p->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (p->vendorid == vendorid && p->productid == productid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) p = my_malloc(sizeof(struct product) + strlen(name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) strcpy(p->name, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) p->vendorid = vendorid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) p->productid = productid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) p->next = products[h];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) products[h] = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static int new_class(const char *name, u_int8_t classid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct class *c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) unsigned int h = hashnum(classid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) c = classes[h];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) for (; c; c = c->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (c->classid == classid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) c = my_malloc(sizeof(struct class) + strlen(name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (!c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) strcpy(c->name, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) c->classid = classid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) c->next = classes[h];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) classes[h] = c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static int new_subclass(const char *name, u_int8_t classid, u_int8_t subclassid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct subclass *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) unsigned int h = hashnum((classid << 8) | subclassid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) s = subclasses[h];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) for (; s; s = s->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (s->classid == classid && s->subclassid == subclassid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) s = my_malloc(sizeof(struct subclass) + strlen(name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (!s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) strcpy(s->name, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) s->classid = classid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) s->subclassid = subclassid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) s->next = subclasses[h];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) subclasses[h] = s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static int new_protocol(const char *name, u_int8_t classid, u_int8_t subclassid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) u_int8_t protocolid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) struct protocol *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) unsigned int h = hashnum((classid << 16) | (subclassid << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) | protocolid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) p = protocols[h];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) for (; p; p = p->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (p->classid == classid && p->subclassid == subclassid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) && p->protocolid == protocolid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) p = my_malloc(sizeof(struct protocol) + strlen(name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) strcpy(p->name, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) p->classid = classid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) p->subclassid = subclassid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) p->protocolid = protocolid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) p->next = protocols[h];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) protocols[h] = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) static void parse(FILE *f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) char buf[512], *cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) unsigned int linectr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) int lastvendor = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) int lastclass = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) int lastsubclass = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) int lasthut = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) int lastlang = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) unsigned int u;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) while (fgets(buf, sizeof(buf), f)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) linectr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) /* remove line ends */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) cp = strchr(buf, '\r');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) if (cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) *cp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) cp = strchr(buf, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) *cp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (buf[0] == '#' || !buf[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) cp = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) if (buf[0] == 'P' && buf[1] == 'H' && buf[2] == 'Y' &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) buf[3] == 'S' && buf[4] == 'D' &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) buf[5] == 'E' && buf[6] == 'S' && /*isspace(buf[7])*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) buf[7] == ' ') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) if (buf[0] == 'P' && buf[1] == 'H' &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) buf[2] == 'Y' && /*isspace(buf[3])*/ buf[3] == ' ') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) if (buf[0] == 'B' && buf[1] == 'I' && buf[2] == 'A' &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) buf[3] == 'S' && /*isspace(buf[4])*/ buf[4] == ' ') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) if (buf[0] == 'L' && /*isspace(buf[1])*/ buf[1] == ' ') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) lasthut = lastclass = lastvendor = lastsubclass = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * set 1 as pseudo-id to indicate that the parser is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * in a `L' section.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) lastlang = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) if (buf[0] == 'C' && /*isspace(buf[1])*/ buf[1] == ' ') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) /* class spec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) cp = buf+2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) while (isspace(*cp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) cp++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) if (!isxdigit(*cp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) err("Invalid class spec at line %u", linectr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) u = strtoul(cp, &cp, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) while (isspace(*cp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) cp++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) if (!*cp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) err("Invalid class spec at line %u", linectr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) if (new_class(cp, u))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) err("Duplicate class spec at line %u class %04x %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) linectr, u, cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) dbg("line %5u class %02x %s", linectr, u, cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) lasthut = lastlang = lastvendor = lastsubclass = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) lastclass = u;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) if (buf[0] == 'A' && buf[1] == 'T' && isspace(buf[2])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) /* audio terminal type spec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) if (buf[0] == 'H' && buf[1] == 'C' && buf[2] == 'C'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) && isspace(buf[3])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) /* HID Descriptor bCountryCode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) if (isxdigit(*cp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) /* vendor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) u = strtoul(cp, &cp, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) while (isspace(*cp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) cp++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) if (!*cp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) err("Invalid vendor spec at line %u", linectr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (new_vendor(cp, u))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) err("Duplicate vendor spec at line %u vendor %04x %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) linectr, u, cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) dbg("line %5u vendor %04x %s", linectr, u, cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) lastvendor = u;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) lasthut = lastlang = lastclass = lastsubclass = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) if (buf[0] == '\t' && isxdigit(buf[1])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) /* product or subclass spec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) u = strtoul(buf+1, &cp, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) while (isspace(*cp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) cp++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (!*cp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) err("Invalid product/subclass spec at line %u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) linectr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) if (lastvendor != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) if (new_product(cp, lastvendor, u))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) err("Duplicate product spec at line %u product %04x:%04x %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) linectr, lastvendor, u, cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) dbg("line %5u product %04x:%04x %s", linectr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) lastvendor, u, cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (lastclass != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if (new_subclass(cp, lastclass, u))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) err("Duplicate subclass spec at line %u class %02x:%02x %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) linectr, lastclass, u, cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) dbg("line %5u subclass %02x:%02x %s", linectr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) lastclass, u, cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) lastsubclass = u;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) if (lasthut != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) /* do not store hut */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) if (lastlang != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) /* do not store langid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) err("Product/Subclass spec without prior Vendor/Class spec at line %u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) linectr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) if (buf[0] == '\t' && buf[1] == '\t' && isxdigit(buf[2])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) /* protocol spec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) u = strtoul(buf+2, &cp, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) while (isspace(*cp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) cp++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) if (!*cp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) err("Invalid protocol spec at line %u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) linectr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) if (lastclass != -1 && lastsubclass != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) if (new_protocol(cp, lastclass, lastsubclass,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) u))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) err("Duplicate protocol spec at line %u class %02x:%02x:%02x %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) linectr, lastclass, lastsubclass,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) u, cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) dbg("line %5u protocol %02x:%02x:%02x %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) linectr, lastclass, lastsubclass, u, cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) err("Protocol spec without prior Class and Subclass spec at line %u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) linectr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) if (buf[0] == 'H' && buf[1] == 'I' &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) buf[2] == 'D' && /*isspace(buf[3])*/ buf[3] == ' ') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) if (buf[0] == 'H' && buf[1] == 'U' &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) buf[2] == 'T' && /*isspace(buf[3])*/ buf[3] == ' ') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) lastlang = lastclass = lastvendor = lastsubclass = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) * set 1 as pseudo-id to indicate that the parser is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) * in a `HUT' section.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) lasthut = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) if (buf[0] == 'R' && buf[1] == ' ')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) if (buf[0] == 'V' && buf[1] == 'T')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) err("Unknown line at line %u", linectr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) int names_init(char *n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) FILE *f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) f = fopen(n, "r");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) if (!f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) return errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) parse(f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) fclose(f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) }