Changeset d0dcfa80 in mainline


Ignore:
Timestamp:
2011-02-23T21:56:22Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b1c6e58
Parents:
b84e114
Message:

Refactoring of usbinfo application (strings)

File:
1 edited

Legend:

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

    rb84e114 rd0dcfa80  
    151151
    152152        /*
    153          * Dump all strings in English (0x0409).
     153         * Dump all strings in all available langages;
    154154         */
    155         uint16_t lang = 0x0409;
    156         /*
    157          * Up to 3 string in device descriptor, 1 for configuration and
    158          * one for each interface.
    159          */
    160         size_t max_idx = 3 + 1 + config_descriptor.interface_count;
    161         size_t idx;
    162         for (idx = 1; idx <= max_idx; idx++) {
    163                 uint8_t *string;
    164                 size_t string_size;
    165                 rc = usb_request_get_descriptor_alloc(&ctrl_pipe,
    166                     USB_REQUEST_TYPE_STANDARD, USB_DESCTYPE_STRING,
    167                     idx, uint16_host2usb(lang),
    168                     (void **) &string, &string_size);
    169                 if (rc == EINTR) {
    170                         /* Invalid index, skip silently. */
    171                         continue;
     155        for (i = 0; i < langs_count; i++) {
     156                l18_win_locales_t lang = langs[i];
     157
     158                printf("  String for language 0x%04x:\n", (int) lang);
     159
     160                /*
     161                 * Try all indexes - we will see what pops-up ;-).
     162                 * However, to speed things up, we will stop after
     163                 * encountering several broken (or nonexistent ones)
     164                 * descriptors in line.
     165                 */
     166                size_t idx;
     167                size_t failed_count = 0;
     168                for (idx = 1; idx < 0xFF; idx++) {
     169                        char *string;
     170                        rc = usb_request_get_string(&ctrl_pipe, idx, lang,
     171                            &string);
     172                        if (rc != EOK) {
     173                                failed_count++;
     174                                if (failed_count > 3) {
     175                                        break;
     176                                }
     177                                continue;
     178                        }
     179                        printf("    String #%zu: \"%s\"\n", idx, string);
     180                        free(string);
     181                        failed_count = 0; /* Reset failed counter. */
    172182                }
    173                 if (rc != EOK) {
    174                         fprintf(stderr,
    175                             NAME ": failed to fetch string #%zu " \
    176                             "(lang 0x%04x): %s.\n",
    177                             idx, (int) lang, str_error(rc));
    178                         continue;
    179                 }
    180                 /*
    181                 printf("String #%zu (language 0x%04x):\n", idx, (int) lang);
    182                 dump_buffer(NULL, 0,
    183                     string, string_size);
    184                 */
    185                 if (string_size <= 2) {
    186                         fprintf(stderr,
    187                             NAME ": no string for index #%zu.\n", idx);
    188                         free(string);
    189                         continue;
    190                 }
    191                 string_size -= 2;
     183        }
    192184
    193                 size_t string_char_count = string_size / 2;
    194                 wchar_t *string_chars = malloc(sizeof(wchar_t) * (string_char_count + 1));
    195                 assert(string_chars != NULL);
    196                 for (i = 0; i < string_char_count; i++) {
    197                         uint16_t uni_char = (string[2 + 2 * i + 1] << 8)
    198                             + string[2 + 2 * i];
    199                         string_chars[i] = uni_char;
    200                 }
    201                 string_chars[string_char_count] = 0;
    202                 free(string);
    203 
    204                 char *str = wstr_to_astr(string_chars);
    205                 assert(str != NULL);
    206                 free(string_chars);
    207 
    208                 printf("String #%zu (language 0x%04x): \"%s\"\n",
    209                     idx, (int) lang, str);
    210                 free(str);
    211         }
    212185
    213186skip_strings:
Note: See TracChangeset for help on using the changeset viewer.