]>
cvs.zerfleddert.de Git - usb-driver/blob - config.c
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
;
35 for (i
=0; i
<sizeof(pp_config
)/sizeof(struct parport_config
); i
++) {
37 pp_config
[i
].ppbase
= i
*0x10;
38 pp_config
[i
].real
= 1;
39 pp_config
[i
].open
= parport_open
;
40 pp_config
[i
].close
= parport_close
;
41 pp_config
[i
].transfer
= parport_transfer
;
44 snprintf(buf
, sizeof(buf
), "%s/.libusb-driverrc", getenv("HOME"));
46 cfg
= fopen(buf
, "r");
51 pbuf
= fgets(buf
, sizeof(buf
), cfg
);
59 if (len
> 0 && buf
[len
-1] == '\n') {
63 if (len
> 0 && buf
[len
-1] == '\r') {
68 for (i
= 0; i
< len
; i
++) {
69 if (buf
[i
] != ' ' && buf
[i
] != '\t')
73 if (buf
[i
] == '#' || buf
[i
] == ';' || buf
[i
] == '\0')
76 if (!strncasecmp(buf
+i
, "LPT", 3)) {
77 unsigned char equal_seen
= 0;
81 for (; i
< len
; i
++) {
82 if (buf
[i
] == ' ' || buf
[i
] == '\t' || buf
[i
] == '=') {
98 num
= strtol(pbuf
, NULL
, 10);
105 for (; (i
< len
) && (!equal_seen
) ; i
++) {
110 } else if (buf
[i
] != ' ' && buf
[i
] != '\t') {
120 for (; i
< len
; i
++) {
121 if (buf
[i
] != ' ' && buf
[i
] != '\t')
125 if (strncasecmp(buf
+i
, "FTDI:", 5)) {
133 for (; i
< len
; i
++) {
146 vid
= strtol(pbuf
, NULL
, 16);
155 for (; i
< len
; i
++) {
156 if (buf
[i
] == ' ' || buf
[i
] == '\t' || buf
[i
] == ':')
161 pid
= strtol(pbuf
, NULL
, 16);
169 if (pbuf
[0] == ':') {
170 iface
= atoi(pbuf
+ 1);
173 pp_config
[num
].real
= 0;
174 pp_config
[num
].usb_vid
= vid
;
175 pp_config
[num
].usb_pid
= pid
;
176 pp_config
[num
].usb_iface
= iface
;
177 pp_config
[num
].open
= jtagkey_open
;
178 pp_config
[num
].close
= jtagkey_close
;
179 pp_config
[num
].transfer
= jtagkey_transfer
;
185 fprintf(stderr
,"libusb-driver not compiled with FTDI2232-support, config file ignored!\n");
191 struct parport_config
*config_get(int num
) {
192 struct parport_config
*ret
= NULL
;
197 for (i
=0; i
<sizeof(pp_config
)/sizeof(struct parport_config
); i
++) {
198 if (pp_config
[i
].num
== num
) {
199 ret
= &(pp_config
[i
]);
207 unsigned char config_is_real_pport(int num
) {
213 for (i
=0; i
<sizeof(pp_config
)/sizeof(struct parport_config
); i
++) {
214 if (pp_config
[i
].num
== num
) {
215 ret
= pp_config
[i
].real
;
223 unsigned short config_usb_vid(int num
) {
224 unsigned short ret
= 0x00;
229 for (i
=0; i
<sizeof(pp_config
)/sizeof(struct parport_config
); i
++) {
230 if (pp_config
[i
].num
== num
) {
231 ret
= pp_config
[i
].usb_vid
;
239 unsigned short config_usb_pid(int num
) {
240 unsigned short ret
= 0x00;
245 for (i
=0; i
<sizeof(pp_config
)/sizeof(struct parport_config
); i
++) {
246 if (pp_config
[i
].num
== num
) {
247 ret
= pp_config
[i
].usb_pid
;
255 unsigned short config_usb_iface(int num
) {
256 unsigned short ret
= 0x00;
261 for (i
=0; i
<sizeof(pp_config
)/sizeof(struct parport_config
); i
++) {
262 if (pp_config
[i
].num
== num
) {
263 ret
= pp_config
[i
].usb_iface
;