Changeset aad3587 in mainline


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

String printing back in usbinfo

Location:
uspace/app/usbinfo
Files:
3 edited

Legend:

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

    r7b13d8e raad3587  
    200200}
    201201
     202void dump_strings(usbinfo_device_t *dev)
     203{
     204        /* Get supported languages. */
     205        l18_win_locales_t *langs;
     206        size_t langs_count;
     207        int rc = usb_request_get_supported_languages(&dev->ctrl_pipe,
     208            &langs, &langs_count);
     209        if (rc != EOK) {
     210                fprintf(stderr,
     211                    NAME ": failed to get list of supported languages: %s.\n",
     212                    str_error(rc));
     213                return;
     214        }
     215
     216        printf("%sString languages (%zu):", get_indent(0), langs_count);
     217        size_t i;
     218        for (i = 0; i < langs_count; i++) {
     219                printf(" 0x%04x", (int) langs[i]);
     220        }
     221        printf(".\n");
     222
     223        /* Get all strings and dump them. */
     224        for (i = 0; i < langs_count; i++) {
     225                l18_win_locales_t lang = langs[i];
     226
     227                printf("%sStrings for language 0x%04x:\n", get_indent(0),
     228                    (int) lang);
     229                /*
     230                 * Try only the first 15 strings
     231                 * (typically, device will not have much more anyway).
     232                 */
     233                size_t idx;
     234                for (idx = 1; idx < 0x0F; idx++) {
     235                        char *string;
     236                        rc = usb_request_get_string(&dev->ctrl_pipe, idx, lang,
     237                            &string);
     238                        if (rc != EOK) {
     239                                continue;
     240                        }
     241                        printf("%sString #%zu: \"%s\"\n", get_indent(1),
     242                            idx, string);
     243                        free(string);
     244                }
     245        }
     246}
     247
    202248int dump_device(devman_handle_t hc_handle, usb_address_t address)
    203249{
  • uspace/app/usbinfo/main.c

    r7b13d8e raad3587  
    134134        _OPTION("-m --match-ids", "Print match ids generated for the device.");
    135135        _OPTION("-t --descriptor-tree", "Print descriptor tree.");
     136        _OPTION("-s --strings", "Try to print all string descriptors.");
    136137
    137138        printf("\n");
     
    148149        {"match-ids", no_argument, NULL, 'm'},
    149150        {"descriptor-tree", no_argument, NULL, 't'},
     151        {"strings", no_argument, NULL, 's'},
    150152        {0, 0, NULL, 0}
    151153};
    152 static const char *short_options = "himt";
     154static const char *short_options = "himts";
    153155
    154156int main(int argc, char *argv[])
     
    162164        bool action_print_match_ids = false;
    163165        bool action_print_descriptor_tree = false;
     166        bool action_print_strings = false;
    164167
    165168        /*
     
    189192                                action_print_descriptor_tree = true;
    190193                                break;
     194                        case 's':
     195                                action_print_strings = true;
     196                                break;
    191197                        default:
    192198                                assert(false && "unreachable code");
     
    198204        if (!action_print_match_ids
    199205            && !action_print_short_identification
     206            && !action_print_strings
    200207            && !action_print_descriptor_tree) {
    201208                action_print_short_identification = true;
     
    239246                        dump_descriptor_tree_brief(dev);
    240247                }
     248                if (action_print_strings) {
     249                        dump_strings(dev);
     250                }
    241251
    242252                /* Destroy the control pipe (close the session etc.). */
  • uspace/app/usbinfo/usbinfo.h

    r7b13d8e raad3587  
    7676void dump_device_match_ids(usbinfo_device_t *);
    7777void dump_descriptor_tree_brief(usbinfo_device_t *);
     78void dump_strings(usbinfo_device_t *);
    7879
    7980
Note: See TracChangeset for help on using the changeset viewer.