FreeCalypso > hg > fc-usbser-tools
diff cp2102/read_eeprom_main.c @ 98:1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Thu, 28 Sep 2023 04:45:13 +0000 |
| parents | 8d35346f1d46 |
| children |
line wrap: on
line diff
--- a/cp2102/read_eeprom_main.c Thu Sep 28 03:26:11 2023 +0000 +++ b/cp2102/read_eeprom_main.c Thu Sep 28 04:45:13 2023 +0000 @@ -18,6 +18,32 @@ extern struct usb_device *find_cp2102_device(); u_char eeprom[SIZE_EEPROM]; +char *device_selector, *outfilename; + +process_cmdline(argc, argv) + char **argv; +{ + int c; + extern int optind; + extern char *optarg; + + while ((c = getopt(argc, argv, "d:")) != EOF) { + switch (c) { + case 'd': + device_selector = optarg; + continue; + default: + usage: + fprintf(stderr, + "usage: %s [-d device-selector] output-hex-file\n", + argv[0]); + exit(1); + } + } + if (argc != optind + 1) + goto usage; + outfilename = argv[optind]; +} main(argc, argv) char **argv; @@ -26,12 +52,8 @@ usb_dev_handle *usbh; FILE *outf; - if (argc != 3) { - fprintf(stderr, "usage: %s device-selector output-hex-file\n", - argv[0]); - exit(1); - } - dev = find_cp2102_device(argv[1]); + process_cmdline(argc, argv); + dev = find_cp2102_device(device_selector); usbh = usb_open(dev); if (!usbh) { fprintf(stderr, "error: usb_open() failed\n"); @@ -39,9 +61,9 @@ } read_eeprom(usbh); usb_close(usbh); - outf = fopen(argv[2], "w"); + outf = fopen(outfilename, "w"); if (!outf) { - perror(argv[2]); + perror(outfilename); exit(1); } intel_hex_out(eeprom, outf);
