Changeset a458bc9 in mainline
- Timestamp:
- 2011-03-17T23:22:25Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8865087
- Parents:
- 2d6787b
- Location:
- uspace/app/usbinfo
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/usbinfo/main.c
r2d6787b ra458bc9 154 154 static const char *short_options = "himts"; 155 155 156 static 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 156 182 int main(int argc, char *argv[]) 157 183 { … … 160 186 return -1; 161 187 } 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;167 188 168 189 /* … … 183 204 print_usage(argv[0]); 184 205 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 } 187 215 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 } 200 217 } 201 218 } while (opt > 0); 202 219 203 220 /* 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; 209 232 } 210 233 … … 237 260 printf("%s\n", devpath); 238 261 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++; 250 268 } 251 269 -
uspace/app/usbinfo/usbinfo.h
r2d6787b ra458bc9 51 51 } usbinfo_device_t; 52 52 53 typedef struct { 54 int opt; 55 void (*action)(usbinfo_device_t *dev); 56 bool active; 57 } usbinfo_action_t; 58 59 53 60 #define NAME "usbinfo" 54 61
Note:
See TracChangeset
for help on using the changeset viewer.