Changeset a458bc9 in mainline


Ignore:
Timestamp:
2011-03-17T23:22:25Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8865087
Parents:
2d6787b
Message:

usbinfo refactoring - command line switches

Location:
uspace/app/usbinfo
Files:
2 edited

Legend:

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

    r2d6787b ra458bc9  
    154154static const char *short_options = "himts";
    155155
     156static usbinfo_action_t actions[] = {
     157        {
     158                .opt = 'i',
     159                .action = dump_short_device_identification,
     160                .active = false
     161        },
     162        {
     163                .opt = 'm',
     164                .action = dump_device_match_ids,
     165                .active = false
     166        },
     167        {
     168                .opt = 't',
     169                .action = dump_descriptor_tree_brief,
     170                .active = false
     171        },
     172        {
     173                .opt = 's',
     174                .action = dump_strings,
     175                .active = false
     176        },
     177        {
     178                .opt = 0
     179        }
     180};
     181
    156182int main(int argc, char *argv[])
    157183{
     
    160186                return -1;
    161187        }
    162 
    163         bool action_print_short_identification = false;
    164         bool action_print_match_ids = false;
    165         bool action_print_descriptor_tree = false;
    166         bool action_print_strings = false;
    167188
    168189        /*
     
    183204                                print_usage(argv[0]);
    184205                                return 0;
    185                         case 'i':
    186                                 action_print_short_identification = true;
     206                        default: {
     207                                int idx = 0;
     208                                while (actions[idx].opt != 0) {
     209                                        if (actions[idx].opt == opt) {
     210                                                actions[idx].active = true;
     211                                                break;
     212                                        }
     213                                        idx++;
     214                                }
    187215                                break;
    188                         case 'm':
    189                                 action_print_match_ids = true;
    190                                 break;
    191                         case 't':
    192                                 action_print_descriptor_tree = true;
    193                                 break;
    194                         case 's':
    195                                 action_print_strings = true;
    196                                 break;
    197                         default:
    198                                 assert(false && "unreachable code");
    199                                 break;
     216                        }
    200217                }
    201218        } while (opt > 0);
    202219
    203220        /* Set the default action. */
    204         if (!action_print_match_ids
    205             && !action_print_short_identification
    206             && !action_print_strings
    207             && !action_print_descriptor_tree) {
    208                 action_print_short_identification = true;
     221        int idx = 0;
     222        bool something_active = false;
     223        while (actions[idx].opt != 0) {
     224                if (actions[idx].active) {
     225                        something_active = true;
     226                        break;
     227                }
     228                idx++;
     229        }
     230        if (!something_active) {
     231                actions[0].active = true;
    209232        }
    210233
     
    237260                printf("%s\n", devpath);
    238261
    239                 if (action_print_short_identification) {
    240                         dump_short_device_identification(dev);
    241                 }
    242                 if (action_print_match_ids) {
    243                         dump_device_match_ids(dev);
    244                 }
    245                 if (action_print_descriptor_tree) {
    246                         dump_descriptor_tree_brief(dev);
    247                 }
    248                 if (action_print_strings) {
    249                         dump_strings(dev);
     262                int action = 0;
     263                while (actions[action].opt != 0) {
     264                        if (actions[action].active) {
     265                                actions[action].action(dev);
     266                        }
     267                        action++;
    250268                }
    251269
  • uspace/app/usbinfo/usbinfo.h

    r2d6787b ra458bc9  
    5151} usbinfo_device_t;
    5252
     53typedef struct {
     54        int opt;
     55        void (*action)(usbinfo_device_t *dev);
     56        bool active;
     57} usbinfo_action_t;
     58
     59
    5360#define NAME "usbinfo"
    5461
Note: See TracChangeset for help on using the changeset viewer.