fixes, fully translated tomato, with english dictionary and Polish translation
[tomato.git] / release / src / router / busybox / util-linux / lsusb.c
blob6f9b54daad7c5c42e6b48ca64e9b50aeae174215
1 /* vi: set sw=4 ts=4: */
2 /*
3 * lsusb implementation for busybox
5 * Copyright (C) 2009 Malek Degachi <malek-degachi@laposte.net>
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8 */
9 #include "libbb.h"
11 static int FAST_FUNC fileAction(
12 const char *fileName,
13 struct stat *statbuf UNUSED_PARAM,
14 void *userData UNUSED_PARAM,
15 int depth UNUSED_PARAM)
17 parser_t *parser;
18 char *tokens[4];
19 char *busnum = NULL, *devnum = NULL;
20 int product_vid = 0, product_did = 0;
21 char *uevent_filename = concat_path_file(fileName, "/uevent");
23 parser = config_open2(uevent_filename, fopen_for_read);
24 free(uevent_filename);
26 while (config_read(parser, tokens, 4, 2, "\\/=", PARSE_NORMAL)) {
27 if ((parser->lineno == 1) && strcmp(tokens[0], "DEVTYPE") == 0) {
28 break;
31 if (strcmp(tokens[0], "PRODUCT") == 0) {
32 product_vid = xstrtou(tokens[1], 16);
33 product_did = xstrtou(tokens[2], 16);
34 continue;
37 if (strcmp(tokens[0], "BUSNUM") == 0) {
38 busnum = xstrdup(tokens[1]);
39 continue;
42 if (strcmp(tokens[0], "DEVNUM") == 0) {
43 devnum = xstrdup(tokens[1]);
44 continue;
47 config_close(parser);
49 if (busnum) {
50 printf("Bus %s Device %s: ID %04x:%04x\n", busnum, devnum, product_vid, product_did);
51 free(busnum);
52 free(devnum);
55 return TRUE;
58 int lsusb_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
59 int lsusb_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
61 /* no options, no getopt */
63 recursive_action("/sys/bus/usb/devices",
64 ACTION_RECURSE,
65 fileAction,
66 NULL, /* dirAction */
67 NULL, /* userData */
68 0 /* depth */);
70 return EXIT_SUCCESS;