1 /*****************************************************************************\
3 * | || | ___ | |_ _ __ | | _ _ __ _ |_ ) *
4 * | __ |/ _ \| _|| '_ \| || || |/ _` | / / *
5 * |_||_|\___/ \__|| .__/|_| \_,_|\__, |/___| *
7 \*****************************************************************************/
19 #include <sys/types.h>
23 #include <linux/types.h>
24 #include <linux/input.h>
26 #include "../mem_utils.h"
27 #include "../parser_utils.h"
28 #include "../filemap_utils.h"
30 #define JUMP_TO_NEXT { free(line); free(module); continue; }
32 #define PRINT_WILDCARD(prefix, format, variable, any) \
34 fprintf(fp, prefix "*"); \
36 fprintf(fp, prefix format, variable);
38 #define PRINT_WILDCARD_COND(prefix, format, variable, condition) \
40 fprintf(fp, prefix format, variable); \
42 fprintf(fp, prefix "*");
44 #define SET_OFFSET(offset, token, prefix, prefix_len) \
45 offset = strncmp(token, prefix, prefix_len) ? 0 : prefix_len;
47 #ifndef KEY_MIN_INTERESTING
48 #define KEY_MIN_INTERESTING KEY_MUTE
51 /* Some kernel headers appear to define it even without __KERNEL__ */
53 #define BITS_PER_LONG (sizeof(long) * 8)
56 #define NBITS(x) ((x / BITS_PER_LONG) + 1)
59 #define TEST_INPUT_BIT(i,bm) (bm[i / BITS_PER_LONG] & (((unsigned long)1) << (i%BITS_PER_LONG)))
61 void module_tr(char *modname
) {
64 for (ptr
= modname
; *ptr
!= '\0'; ptr
++) {
70 int hexchar_to_int(char c
) {
72 if (c
>= 'a' && c
<= 'f') {
74 } else if (c
>= '0' && c
<= '9') {
81 void alias_from_pcimap(FILE *fp
, char *prefix
) {
82 struct filemap_t pcimap
;
83 char *line
, *nline
, *nptr
;
88 unsigned long vendor
, device
, sub_vendor
, sub_device
, class_type
, class_mask
;
90 filename
= xmalloc(strlen(prefix
) + strlen("modules.pcimap") + 2);
91 strcpy(filename
, prefix
);
92 strcat(filename
, "/modules.pcimap");
94 if (map_file(filename
, &pcimap
)) {
101 while ((line
= dup_line(nptr
, &nptr
)) != NULL
) {
104 module
= dup_token(nline
, &nline
, isspace
);
105 if (!module
|| module
[0] == '#')
108 token
= dup_token(nline
, &nline
, isspace
);
111 vendor
= strtoul(token
, NULL
, 0);
114 token
= dup_token(nline
, &nline
, isspace
);
117 device
= strtoul(token
, NULL
, 0);
120 token
= dup_token(nline
, &nline
, isspace
);
123 sub_vendor
= strtoul(token
, NULL
, 0);
126 token
= dup_token(nline
, &nline
, isspace
);
129 sub_device
= strtoul(token
, NULL
, 0);
132 token
= dup_token(nline
, &nline
, isspace
);
135 class_type
= strtoul(token
, NULL
, 0);
138 token
= dup_token(nline
, &nline
, isspace
);
141 class_mask
= strtoul(token
, NULL
, 0);
144 fprintf(fp
, "alias pci:");
146 PRINT_WILDCARD("v", "%08lX", vendor
, 0xffffffff);
147 PRINT_WILDCARD("d", "%08lX", device
, 0xffffffff);
148 PRINT_WILDCARD("sv", "%08lX", sub_vendor
, 0xffffffff);
149 PRINT_WILDCARD("sd", "%08lX", sub_device
, 0xffffffff);
151 /* FIXME ! USE PRINT_WIL*/
152 PRINT_WILDCARD_COND("bc", "%02X",
153 (unsigned int)((class_type
& 0x00ff0000 & class_mask
) >> 16),
154 class_mask
& 0x00ff0000);
156 PRINT_WILDCARD_COND("sc", "%02X",
157 (unsigned int)((class_type
& 0x0000ff00 & class_mask
) >> 8),
158 class_mask
& 0x00ff0000);
160 PRINT_WILDCARD_COND("i", "%02X",
161 (unsigned int)((class_type
& 0x000000ff & class_mask
)),
162 class_mask
& 0x00ff0000);
165 fprintf(fp
, " %s\n", module
);
175 /* Yes, this -is- ugly. */
176 void alias_from_usbmap_print_pattern(FILE *fp
,
177 unsigned long mflags
, unsigned long ven
,
178 unsigned long pro
, unsigned long bcdl
, unsigned long bcdh
,
179 unsigned long bdc
, unsigned long bdsc
, unsigned long bdp
,
180 unsigned long bic
, unsigned long bisc
, unsigned long bip
,
181 int len
, unsigned long left
, int ndigits
,
184 fprintf(fp
, "alias usb:");
186 PRINT_WILDCARD_COND("v", "%04lX", ven
, mflags
& 0x0001);
187 PRINT_WILDCARD_COND("p", "%04lX", pro
, mflags
& 0x0002);
191 if (mflags
& 0x000C) {
193 fprintf(fp
, "%.*lX", ndigits
- 1, left
);
195 if (bcdl
== 0 && bcdh
== 0xf)
196 fprintf(fp
, "*"), ndigits
= len
;
197 else if (bcdl
== bcdh
)
198 fprintf(fp
, "%lX", bcdl
);
199 else if (bcdl
/ 10 != bcdh
/ 10)
200 fprintf(fp
, "[%lX-%X%X-%lX]", bcdl
, 9, 10, bcdh
);
202 fprintf(fp
, "[%lX-%lX]", bcdl
, bcdh
);
210 PRINT_WILDCARD_COND("dc", "%02lX", bdc
, mflags
& 0x0010);
211 PRINT_WILDCARD_COND("dsc", "%02lX", bdsc
, mflags
& 0x0020);
212 PRINT_WILDCARD_COND("dp", "%02lX", bdp
, mflags
& 0x0040);
214 PRINT_WILDCARD_COND("ic", "%02lX", bic
, mflags
& 0x0080);
215 PRINT_WILDCARD_COND("isc", "%02lX", bisc
, mflags
& 0x0100);
216 PRINT_WILDCARD_COND("ip", "%02lX", bip
, mflags
& 0x0200);
218 fprintf(fp
, " %s\n", module
);
221 void alias_from_usbmap(FILE *fp
, char *prefix
) {
222 struct filemap_t usbmap
;
223 char *line
, *nline
, *nptr
;
228 unsigned long match_flags
;
229 unsigned long vendor
, product
;
230 unsigned long bcddev_lo
, bcddev_hi
; /* some devices violate bcd */
231 unsigned long bdevclass
, bdevsubclass
, bdevproto
;
232 unsigned long bifclass
, bifsubclass
, bifproto
;
234 unsigned long cmin
, cmax
;
237 filename
= xmalloc(strlen(prefix
) + strlen("modules.usbmap") + 2);
238 strcpy(filename
, prefix
);
239 strcat(filename
, "/modules.usbmap");
241 if (map_file(filename
, &usbmap
)) {
248 while ((line
= dup_line(nptr
, &nptr
)) != NULL
) {
251 module
= dup_token(nline
, &nline
, isspace
);
252 if (!module
|| module
[0] == '#')
255 token
= dup_token(nline
, &nline
, isspace
);
258 match_flags
= strtoul(token
, NULL
, 0);
261 token
= dup_token(nline
, &nline
, isspace
);
264 vendor
= strtoul(token
, NULL
, 0);
267 token
= dup_token(nline
, &nline
, isspace
);
270 product
= strtoul(token
, NULL
, 0);
273 token
= dup_token(nline
, &nline
, isspace
);
276 bcddev_lo
= strtoul(token
, NULL
, 0);
279 token
= dup_token(nline
, &nline
, isspace
);
282 bcddev_hi
= strtoul(token
, NULL
, 0);
285 token
= dup_token(nline
, &nline
, isspace
);
288 bdevclass
= strtoul(token
, NULL
, 0);
291 token
= dup_token(nline
, &nline
, isspace
);
294 bdevsubclass
= strtoul(token
, NULL
, 0);
297 token
= dup_token(nline
, &nline
, isspace
);
300 bdevproto
= strtoul(token
, NULL
, 0);
303 token
= dup_token(nline
, &nline
, isspace
);
306 bifclass
= strtoul(token
, NULL
, 0);
309 token
= dup_token(nline
, &nline
, isspace
);
312 bifsubclass
= strtoul(token
, NULL
, 0);
315 token
= dup_token(nline
, &nline
, isspace
);
318 bifproto
= strtoul(token
, NULL
, 0);
323 for (len
= ndigits
= 4; bcddev_lo
<= bcddev_hi
; ndigits
--) {
324 cmin
= bcddev_lo
& 0xf;
325 cmax
= bcddev_hi
& 0xf;
330 if (bcddev_lo
== bcddev_hi
|| ndigits
== 0) {
331 alias_from_usbmap_print_pattern(fp
,
332 match_flags
, vendor
, product
,
334 bdevclass
, bdevsubclass
, bdevproto
,
335 bifclass
, bifsubclass
, bifproto
,
336 len
, bcddev_lo
, ndigits
,
342 alias_from_usbmap_print_pattern(fp
,
343 match_flags
, vendor
, product
,
345 bdevclass
, bdevsubclass
, bdevproto
,
346 bifclass
, bifsubclass
, bifproto
,
347 len
, bcddev_lo
++, ndigits
,
352 alias_from_usbmap_print_pattern(fp
,
353 match_flags
, vendor
, product
,
355 bdevclass
, bdevsubclass
, bdevproto
,
356 bifclass
, bifsubclass
, bifproto
,
357 len
, bcddev_hi
--, ndigits
,
370 void alias_from_ieee1394map(FILE *fp
, char *prefix
) {
371 struct filemap_t ieee1394map
;
372 char *line
, *nline
, *nptr
;
377 unsigned long match_flags
, vendor
, product
, specifier
, version
;
379 filename
= xmalloc(strlen(prefix
) + strlen("modules.ieee1394map") + 2);
380 strcpy(filename
, prefix
);
381 strcat(filename
, "/modules.ieee1394map");
383 if (map_file(filename
, &ieee1394map
)) {
388 nptr
= ieee1394map
.map
;
390 while ((line
= dup_line(nptr
, &nptr
)) != NULL
) {
393 module
= dup_token(nline
, &nline
, isspace
);
394 if (!module
|| module
[0] == '#')
397 token
= dup_token(nline
, &nline
, isspace
);
400 match_flags
= strtoul(token
, NULL
, 0);
403 token
= dup_token(nline
, &nline
, isspace
);
406 vendor
= strtoul(token
, NULL
, 0);
409 token
= dup_token(nline
, &nline
, isspace
);
412 product
= strtoul(token
, NULL
, 0);
415 token
= dup_token(nline
, &nline
, isspace
);
418 specifier
= strtoul(token
, NULL
, 0);
421 token
= dup_token(nline
, &nline
, isspace
);
424 version
= strtoul(token
, NULL
, 0);
427 fprintf(fp
, "alias ieee1394:");
429 PRINT_WILDCARD_COND("ven", "%08lX", vendor
, match_flags
& 0x01);
430 PRINT_WILDCARD_COND("mo", "%08lX", product
, match_flags
& 0x02);
431 PRINT_WILDCARD_COND("sp", "%08lX", specifier
, match_flags
& 0x04);
432 PRINT_WILDCARD_COND("ver", "%08lX", version
, match_flags
& 0x08);
433 if (match_flags
& 0x08)
437 fprintf(fp
, " %s\n", module
);
443 unmap_file(&ieee1394map
);
447 void alias_from_isapnpmap(FILE *fp
, char *prefix
) {
448 struct filemap_t isapnpmap
;
449 char *line
, *nline
, *nptr
;
456 unsigned char vendor_sig
[3], vendor
[2], function
[2];
457 unsigned char card_vendor_sig
[3], card_vendor
[2], card_device
[2];
459 filename
= xmalloc(strlen(prefix
) + strlen("modules.isapnpmap") + 2);
460 strcpy(filename
, prefix
);
461 strcat(filename
, "/modules.isapnpmap");
463 if (map_file(filename
, &isapnpmap
)) {
468 nptr
= isapnpmap
.map
;
470 while ((line
= dup_line(nptr
, &nptr
)) != NULL
) {
473 module
= dup_token(nline
, &nline
, isspace
);
474 if (!module
|| module
[0] == '#')
477 token
= dup_token(nline
, &nline
, isspace
);
481 SET_OFFSET(offset
, token
, "0x", 2);
482 card_vendor
[1] = hexchar_to_int(token
[offset
]) * 16 + hexchar_to_int(token
[offset
+ 1]);
483 card_vendor
[0] = hexchar_to_int(token
[offset
+ 2]) * 16 + hexchar_to_int(token
[offset
+ 3]);
486 token
= dup_token(nline
, &nline
, isspace
);
490 SET_OFFSET(offset
, token
, "0x", 2);
491 card_device
[1] = hexchar_to_int(token
[offset
]) * 16 + hexchar_to_int(token
[offset
+ 1]);
492 card_device
[0] = hexchar_to_int(token
[offset
+ 2]) * 16 + hexchar_to_int(token
[offset
+ 3]);
495 /* jump driverdata */
496 token
= dup_token(nline
, &nline
, isspace
);
501 token
= dup_token(nline
, &nline
, isspace
);
505 SET_OFFSET(offset
, token
, "0x", 2);
506 vendor
[1] = hexchar_to_int(token
[offset
]) * 16 + hexchar_to_int(token
[offset
+ 1]);
507 vendor
[0] = hexchar_to_int(token
[offset
+ 2]) * 16 + hexchar_to_int(token
[offset
+ 3]);
509 vendor_sig
[0] = ((vendor
[0] >> 2) & 0x1f) + ('A' - 1);
510 vendor_sig
[1] = (((vendor
[0] & 3) << 3) | (vendor
[1] >> 5)) + ('A' - 1);
511 vendor_sig
[2] = (vendor
[1] & 0x1f) + ('A' - 1);
515 token
= dup_token(nline
, &nline
, isspace
);
519 SET_OFFSET(offset
, token
, "0x", 2);
520 function
[1] = hexchar_to_int(token
[offset
]) * 16 + hexchar_to_int(token
[offset
+ 1]);
521 function
[0] = hexchar_to_int(token
[offset
+ 2]) * 16 + hexchar_to_int(token
[offset
+ 3]);
525 fprintf(fp
, "alias pnp:");
526 if (memcmp("\xff\xff", card_vendor
, 2) && memcmp("\xff\xff", card_device
, 2)) {
527 card_vendor_sig
[0] = ((card_vendor
[0] >> 2) & 0x1f) + ('A' - 1);
528 card_vendor_sig
[1] = (((card_vendor
[0] & 3) << 3) | (card_vendor
[1] >> 5)) + ('A' - 1);
529 card_vendor_sig
[2] = (card_vendor
[1] & 0x1f) + ('A' - 1);
531 fprintf(fp
, "c%c%c%c%02x%02x", card_vendor_sig
[0], card_vendor_sig
[1], card_vendor_sig
[2], card_device
[0], card_device
[1]);
534 fprintf(fp
, "d%c%c%c%02x%02x", vendor_sig
[0], vendor_sig
[1], vendor_sig
[2], function
[0], function
[1]);
535 while ((token
= dup_token(nline
, &nline
, isspace
)) != NULL
) {
539 SET_OFFSET(offset
, token
, "0x", 2);
540 vendor
[1] = hexchar_to_int(token
[offset
]) * 16 + hexchar_to_int(token
[offset
+ 1]);
541 vendor
[0] = hexchar_to_int(token
[offset
+ 2]) * 16 + hexchar_to_int(token
[offset
+ 3]);
543 vendor_sig
[0] = ((vendor
[0] >> 2) & 0x1f) + ('A' - 1);
544 vendor_sig
[1] = (((vendor
[0] & 3) << 3) | (vendor
[1] >> 5)) + ('A' - 1);
545 vendor_sig
[2] = (vendor
[1] & 0x1f) + ('A' - 1);
549 token
= dup_token(nline
, &nline
, isspace
);
553 SET_OFFSET(offset
, token
, "0x", 2);
554 function
[1] = hexchar_to_int(token
[offset
]) * 16 + hexchar_to_int(token
[offset
+ 1]);
555 function
[0] = hexchar_to_int(token
[offset
+ 2]) * 16 + hexchar_to_int(token
[offset
+ 3]);
559 fprintf(fp
, "d%c%c%c%02x%02x", vendor_sig
[0], vendor_sig
[1], vendor_sig
[2], function
[0], function
[1]);
563 fprintf(fp
, "* %s\n", module
);
569 unmap_file(&isapnpmap
);
573 void alias_from_seriomap(FILE *fp
, char *prefix
) {
574 struct filemap_t seriomap
;
575 char *line
, *nline
, *nptr
;
580 unsigned char type
, extra
, id
, proto
;
582 filename
= xmalloc(strlen(prefix
) + strlen("modules.seriomap") + 2);
583 strcpy(filename
, prefix
);
584 strcat(filename
, "/modules.seriomap");
586 if (map_file(filename
, &seriomap
)) {
593 while ((line
= dup_line(nptr
, &nptr
)) != NULL
) {
596 module
= dup_token(nline
, &nline
, isspace
);
597 if (!module
|| module
[0] == '#')
600 token
= dup_token(nline
, &nline
, isspace
);
603 type
= strtoul(token
, NULL
, 16);
606 token
= dup_token(nline
, &nline
, isspace
);
609 extra
= strtoul(token
, NULL
, 16);
612 token
= dup_token(nline
, &nline
, isspace
);
615 id
= strtoul(token
, NULL
, 16);
618 token
= dup_token(nline
, &nline
, isspace
);
621 proto
= strtoul(token
, NULL
, 16);
624 fprintf(fp
, "alias serio:");
625 PRINT_WILDCARD("ty", "%02X", type
, 0xff);
626 PRINT_WILDCARD("pr", "%02X", proto
, 0xff);
627 PRINT_WILDCARD("id", "%02X", id
, 0xff);
628 PRINT_WILDCARD("ex", "%02X", extra
, 0xff);
629 fprintf(fp
, " %s\n", module
);
635 unmap_file(&seriomap
);
639 inline int iscolon(int c
) {
643 char *bitmap_to_bitstring(char name
, unsigned long *bm
, unsigned int min_bit
, unsigned int max_bit
)
646 unsigned int i
, len
= 0, size
= 16, srv
;
650 len
+= snprintf(rv
+ len
, size
- len
, "%c*", name
);
652 for (i
= min_bit
; i
< max_bit
; i
++) {
653 if (TEST_INPUT_BIT(i
, bm
)) {
654 while ((srv
= snprintf(rv
+ len
, size
- len
, "%X,", i
)) >= (size
- len
)) {
656 rv
= xrealloc(rv
, size
);
662 /* read: if (we had any match) { */
664 while ((srv
= snprintf(rv
+ len
, size
- len
, "*")) >= (size
- len
)) {
666 rv
= xrealloc(rv
, size
);
673 void string_to_bitmap(char *input
, unsigned long *bitmap
, int bm_len
) {
677 ptr
= input
+ strlen(input
);
679 while ((token
= dup_token_r(ptr
, input
, &ptr
, iscolon
)) != NULL
) {
680 bitmap
[i
] = strtoul(token
, NULL
, 16);
689 #define GET_BITMAP(mapkey, bitmap, name, min) \
690 token = dup_token(nline, &nline, isspace); \
693 if (TEST_INPUT_BIT(EV_ ## mapkey, ev_bits)) { \
697 string_to_bitmap(token, bitmap ## _bits, NBITS(mapkey ## _MAX)); \
699 bitmap = bitmap_to_bitstring(name, bitmap ## _bits, min, mapkey ## _MAX); \
702 void alias_from_inputmap(FILE *fp
, char *prefix
) {
703 struct filemap_t inputmap
;
704 char *line
, *nline
, *nptr
;
705 char *token
, *sw_token
;
711 char *ev
, *key
, *rel
, *abs
, *sw
, *msc
, *led
, *snd
, *ff
;
713 unsigned long bustype
, vendor
, product
, version
;
714 unsigned long ev_bits
[NBITS(EV_MAX
)];
715 unsigned long key_bits
[NBITS(KEY_MAX
)];
716 unsigned long rel_bits
[NBITS(REL_MAX
)];
717 unsigned long abs_bits
[NBITS(ABS_MAX
)];
718 unsigned long msc_bits
[NBITS(MSC_MAX
)];
719 unsigned long led_bits
[NBITS(LED_MAX
)];
720 unsigned long snd_bits
[NBITS(SND_MAX
)];
721 unsigned long ff_bits
[NBITS(FF_MAX
)];
722 #if defined(SW_MAX) && defined(EV_SW)
723 unsigned long sw_bits
[NBITS(SW_MAX
)];
726 memset(ev_bits
, 0, NBITS(EV_MAX
) * sizeof(long));
727 memset(key_bits
, 0, NBITS(KEY_MAX
) * sizeof(long));
728 memset(rel_bits
, 0, NBITS(REL_MAX
) * sizeof(long));
729 memset(abs_bits
, 0, NBITS(ABS_MAX
) * sizeof(long));
730 memset(msc_bits
, 0, NBITS(MSC_MAX
) * sizeof(long));
731 memset(led_bits
, 0, NBITS(LED_MAX
) * sizeof(long));
732 memset(snd_bits
, 0, NBITS(SND_MAX
) * sizeof(long));
733 memset(ff_bits
, 0, NBITS(FF_MAX
) * sizeof(long));
734 #if defined(SW_MAX) && defined(EV_SW)
735 memset(sw_bits
, 0, NBITS(SW_MAX
) * sizeof(long));
738 filename
= xmalloc(strlen(prefix
) + strlen("modules.inputmap") + 2);
739 strcpy(filename
, prefix
);
740 strcat(filename
, "/modules.inputmap");
742 if (map_file(filename
, &inputmap
)) {
749 while ((line
= dup_line(nptr
, &nptr
)) != NULL
) {
752 module
= dup_token(nline
, &nline
, isspace
);
753 if (!module
|| module
[0] == '#')
757 token
= dup_token(nline
, &nline
, isspace
);
762 token
= dup_token(nline
, &nline
, isspace
);
765 bustype
= strtoul(token
, NULL
, 0);
768 token
= dup_token(nline
, &nline
, isspace
);
771 vendor
= strtoul(token
, NULL
, 0);
774 token
= dup_token(nline
, &nline
, isspace
);
777 product
= strtoul(token
, NULL
, 0);
780 token
= dup_token(nline
, &nline
, isspace
);
783 version
= strtoul(token
, NULL
, 0);
786 token
= dup_token(nline
, &nline
, isspace
);
790 string_to_bitmap(token
, ev_bits
, NBITS(EV_MAX
));
791 ev
= bitmap_to_bitstring('e', ev_bits
, 0, EV_MAX
);
794 GET_BITMAP(KEY
, key
, 'k', KEY_MIN_INTERESTING
);
795 GET_BITMAP(REL
, rel
, 'r', 0);
796 GET_BITMAP(ABS
, abs
, 'a', 0);
797 GET_BITMAP(MSC
, msc
, 'm', 0);
798 GET_BITMAP(LED
, led
, 'l', 0);
799 GET_BITMAP(SND
, snd
, 's', 0);
800 GET_BITMAP(FF
, ff
, 'f', 0);
804 token
= dup_token(nline
, &nline
, isspace
);
809 token
= dup_token(nline
, &nline
, isspace
);
810 new_format
= token
? 1 : 0;
813 #if defined(SW_MAX) && defined(EV_SW)
816 GET_BITMAP(SW
, sw
, 'w', 0);
824 fprintf(fp
, "alias input:");
826 PRINT_WILDCARD("b", "%04lX", bustype
, 0x0);
827 PRINT_WILDCARD("v", "%04lX", vendor
, 0x0);
828 PRINT_WILDCARD("p", "%04lX", product
, 0x0);
829 PRINT_WILDCARD("e", "%04lX", version
, 0x0);
832 fprintf(fp
, "%s%s%s%s%s%s%s%s%s",
833 ev
, key
, rel
, abs
, msc
, led
, snd
, ff
, sw
);
835 fprintf(fp
, " %s\n", module
);
851 unmap_file(&inputmap
);
855 void alias_from_ccwmap(FILE *fp
, char *prefix
) {
856 struct filemap_t ccwmap
;
857 char *line
, *nline
, *nptr
;
862 unsigned long match_flags
, cu_type
, cu_model
, dev_type
, dev_model
;
864 filename
= xmalloc(strlen(prefix
) + strlen("modules.ccwmap") + 2);
865 strcpy(filename
, prefix
);
866 strcat(filename
, "/modules.ccwmap");
868 if (map_file(filename
, &ccwmap
)) {
875 while ((line
= dup_line(nptr
, &nptr
)) != NULL
) {
878 module
= dup_token(nline
, &nline
, isspace
);
879 if (!module
|| module
[0] == '#')
882 token
= dup_token(nline
, &nline
, isspace
);
885 match_flags
= strtoul(token
, NULL
, 0);
888 token
= dup_token(nline
, &nline
, isspace
);
891 cu_type
= strtoul(token
, NULL
, 0);
894 token
= dup_token(nline
, &nline
, isspace
);
897 cu_model
= strtoul(token
, NULL
, 0);
900 token
= dup_token(nline
, &nline
, isspace
);
903 dev_type
= strtoul(token
, NULL
, 0);
906 token
= dup_token(nline
, &nline
, isspace
);
909 dev_model
= strtoul(token
, NULL
, 0);
912 fprintf(fp
, "alias ccw:");
913 PRINT_WILDCARD_COND("t", "%04lX", cu_type
, match_flags
& 0x01);
914 PRINT_WILDCARD_COND("m", "%02lX", cu_model
, match_flags
& 0x02);
915 PRINT_WILDCARD_COND("dt", "%04lX", dev_type
, match_flags
& 0x04);
916 PRINT_WILDCARD_COND("dm", "%02lX", dev_model
, match_flags
& 0x08);
917 if (match_flags
& 0x08)
919 fprintf(fp
, " %s\n", module
);
929 void alias_from_ofmap(FILE *fp
, char *prefix
) {
930 struct filemap_t ofmap
;
931 char *line
, *nline
, *nptr
;
936 char *name
, *type
, *compatible
;
938 filename
= xmalloc(strlen(prefix
) + strlen("modules.ofmap") + 2);
939 strcpy(filename
, prefix
);
940 strcat(filename
, "/modules.ofmap");
942 if (map_file(filename
, &ofmap
)) {
949 while ((line
= dup_line(nptr
, &nptr
)) != NULL
) {
952 module
= dup_token(nline
, &nline
, isspace
);
953 if (!module
|| module
[0] == '#')
956 token
= dup_token(nline
, &nline
, isspace
);
961 token
= dup_token(nline
, &nline
, isspace
);
968 token
= dup_token(nline
, &nline
, isspace
);
976 fprintf(fp
, "alias of:");
977 fprintf(fp
, "N%sT%sC%s", name
, type
, compatible
);
978 fprintf(fp
, " %s\n", module
);
992 int main(int argc
, char *argv
[]) {
997 for (i
= 1; i
< argc
; i
++) {
998 if (!strcmp(argv
[i
], "--output") && i
< argc
- 1 && !fp
) {
1000 if (!strcmp(argv
[i
], "-")) {
1003 fp
= fopen(argv
[i
], "wb");
1005 fprintf(stderr
, "Unable to open output file.\n");
1009 } else if (!strcmp(argv
[i
], "--prefix") && i
< argc
- 1 && !prefix
) {
1020 alias_from_ofmap(fp
, prefix
);
1021 alias_from_ieee1394map(fp
, prefix
);
1022 alias_from_ccwmap(fp
, prefix
);
1023 alias_from_seriomap(fp
, prefix
);
1024 alias_from_ieee1394map(fp
, prefix
);
1025 alias_from_pcimap(fp
, prefix
);
1026 alias_from_isapnpmap(fp
, prefix
);
1027 alias_from_usbmap(fp
, prefix
);
1028 alias_from_inputmap(fp
, prefix
);