]>
git.zerfleddert.de Git - usb-driver/blob - config.c
a39902e99e8a04f683f398266f0cc13ffddc94e8
5 #include "usb-driver.h"
14 #define PARSEERROR fprintf(stderr,"LIBUSB-DRIVER WARNING: Invalid config statement at line %d\n", line)
16 static struct parport_config pp_config
[4];
18 static void read_config() {
20 static int config_read
= 0;
25 unsigned short vid
, pid
;
34 for (i
=0; i
<sizeof(pp_config
)/sizeof(struct parport_config
); i
++) {
36 pp_config
[i
].ppbase
= i
*0x10;
37 pp_config
[i
].real
= 1;
38 pp_config
[i
].open
= parport_open
;
39 pp_config
[i
].close
= parport_close
;
40 pp_config
[i
].transfer
= parport_transfer
;
43 snprintf(buf
, sizeof(buf
), "%s/.libusb-driverrc", getenv("HOME"));
45 cfg
= fopen(buf
, "r");
50 pbuf
= fgets(buf
, sizeof(buf
), cfg
);
58 if (len
> 0 && buf
[len
-1] == '\n') {
62 if (len
> 0 && buf
[len
-1] == '\r') {
67 for (i
= 0; i
< len
; i
++) {
68 if (buf
[i
] != ' ' && buf
[i
] != '\t')
72 if (buf
[i
] == '#' || buf
[i
] == ';' || buf
[i
] == '\0')
75 if (!strncasecmp(buf
+i
, "LPT", 3)) {
76 unsigned char equal_seen
= 0;
80 for (; i
< len
; i
++) {
81 if (buf
[i
] == ' ' || buf
[i
] == '\t' || buf
[i
] == '=') {
97 num
= strtol(pbuf
, NULL
, 10);
104 for (; (i
< len
) && (!equal_seen
) ; i
++) {
109 } else if (buf
[i
] != ' ' && buf
[i
] != '\t') {
119 for (; i
< len
; i
++) {
120 if (buf
[i
] != ' ' && buf
[i
] != '\t')
124 if (strncasecmp(buf
+i
, "FTDI:", 5)) {
132 for (; i
< len
; i
++) {
145 vid
= strtol(pbuf
, NULL
, 16);
154 for (; i
< len
; i
++) {
155 if (buf
[i
] == ' ' || buf
[i
] == '\t')
160 pid
= strtol(pbuf
, NULL
, 16);
166 pp_config
[num
].real
= 0;
167 pp_config
[num
].usb_vid
= vid
;
168 pp_config
[num
].usb_pid
= pid
;
169 pp_config
[num
].open
= jtagkey_open
;
170 pp_config
[num
].close
= jtagkey_close
;
171 pp_config
[num
].transfer
= jtagkey_transfer
;
177 fprintf(stderr
,"libusb-driver not compiled with FTDI2232-support, config file ignored!\n");
183 struct parport_config
*config_get(int num
) {
184 struct parport_config
*ret
= NULL
;
189 for (i
=0; i
<sizeof(pp_config
)/sizeof(struct parport_config
); i
++) {
190 if (pp_config
[i
].num
== num
) {
191 ret
= &(pp_config
[i
]);
199 unsigned char config_is_real_pport(int num
) {
205 for (i
=0; i
<sizeof(pp_config
)/sizeof(struct parport_config
); i
++) {
206 if (pp_config
[i
].num
== num
) {
207 ret
= pp_config
[i
].real
;
215 unsigned short config_usb_vid(int num
) {
216 unsigned short ret
= 0x00;
221 for (i
=0; i
<sizeof(pp_config
)/sizeof(struct parport_config
); i
++) {
222 if (pp_config
[i
].num
== num
) {
223 ret
= pp_config
[i
].usb_vid
;
231 unsigned short config_usb_pid(int num
) {
232 unsigned short ret
= 0x00;
237 for (i
=0; i
<sizeof(pp_config
)/sizeof(struct parport_config
); i
++) {
238 if (pp_config
[i
].num
== num
) {
239 ret
= pp_config
[i
].usb_pid
;