Changeset 81ca204 in mainline for uspace/app/usbinfo/main.c


Ignore:
Timestamp:
2011-03-16T10:27:58Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e160da4d
Parents:
3100ebe
Message:

Add command-line switches to usbinfo

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/usbinfo/main.c

    r3100ebe r81ca204  
    130130}
    131131
     132static struct option long_options[] = {
     133        {"help", no_argument, NULL, 'h'},
     134        {"identification", no_argument, NULL, 'i'},
     135        {"match-ids", no_argument, NULL, 'm'},
     136        {0, 0, NULL, 0}
     137};
     138static const char *short_options = "him";
     139
    132140int main(int argc, char *argv[])
    133141{
     
    137145        }
    138146
     147        bool action_print_short_identification = false;
     148        bool action_print_match_ids = false;
     149
    139150        /*
    140151         * Process command-line options. They determine what shall be
    141152         * done with the device.
    142153         */
    143 
    144         /* TODO */
     154        int opt;
     155        do {
     156                opt = getopt_long(argc, argv,
     157                    short_options, long_options, NULL);
     158                switch (opt) {
     159                        case -1:
     160                                break;
     161                        case '?':
     162                                print_usage(argv[0]);
     163                                return 1;
     164                        case 'h':
     165                                print_usage(argv[0]);
     166                                return 0;
     167                        case 'i':
     168                                action_print_short_identification = true;
     169                                break;
     170                        case 'm':
     171                                action_print_match_ids = true;
     172                                break;
     173                        default:
     174                                break;
     175                }
     176        } while (opt > 0);
     177
     178        /* Set the default action. */
     179        if (!action_print_match_ids && !action_print_short_identification) {
     180                action_print_short_identification = true;
     181        }
    145182
    146183        /*
     
    149186         */
    150187        int i;
    151         for (i = 1; i < argc; i++) {
     188        for (i = optind; i < argc; i++) {
    152189                char *devpath = argv[i];
    153190
     
    170207
    171208                /* Run actions the user specified. */
    172                 /* TODO */
    173 
    174 
    175209                printf("%s\n", devpath);
    176                 dump_short_device_identification(dev);
    177                 dump_device_match_ids(dev);
     210
     211                if (action_print_short_identification) {
     212                        dump_short_device_identification(dev);
     213                }
     214                if (action_print_match_ids) {
     215                        dump_device_match_ids(dev);
     216                }
    178217
    179218                /* Destroy the control pipe (close the session etc.). */
Note: See TracChangeset for help on using the changeset viewer.