Changeset 4e7637a in mainline
- Timestamp:
- 2012-05-13T09:30:03Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f8dbc12
- Parents:
- 32d96e1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/loc/loc.c
r32d96e1 r4e7637a 43 43 #define NAME "loc" 44 44 45 int main(int argc, char *argv[]) 45 static int show_cat(const char *cat_name, category_id_t cat_id) 46 { 47 service_id_t *svc_ids; 48 size_t svc_cnt; 49 char *svc_name; 50 int rc; 51 size_t j; 52 53 printf("%s (%" PRIun "):\n", cat_name, cat_id); 54 55 rc = loc_category_get_svcs(cat_id, &svc_ids, &svc_cnt); 56 if (rc != EOK) { 57 printf(NAME ": Failed getting list of services in " 58 "category %s, skipping.\n", cat_name); 59 return rc; 60 } 61 62 for (j = 0; j < svc_cnt; j++) { 63 rc = loc_service_get_name(svc_ids[j], &svc_name); 64 if (rc != EOK) { 65 printf(NAME ": Unknown service name (SID %" 66 PRIun ").\n", svc_ids[j]); 67 continue; 68 } 69 printf("\t%s (%" PRIun ")\n", svc_name, svc_ids[j]); 70 free(svc_name); 71 } 72 73 free(svc_ids); 74 return EOK; 75 } 76 77 static int list_svcs_by_cat(void) 46 78 { 47 79 category_id_t *cat_ids; 48 80 size_t cat_cnt; 49 service_id_t *svc_ids;50 size_t svc_cnt;51 81 52 size_t i , j;82 size_t i; 53 83 char *cat_name; 54 char *svc_name;55 84 int rc; 56 85 … … 58 87 if (rc != EOK) { 59 88 printf(NAME ": Error getting list of categories.\n"); 60 return 1;89 return rc; 61 90 } 62 91 … … 68 97 if (cat_name == NULL) { 69 98 printf(NAME ": Error allocating memory.\n"); 70 return 1; 99 free(cat_ids); 100 return rc; 71 101 } 72 102 73 printf("%s (%" PRIun "):\n", cat_name, cat_ids[i]); 103 rc = show_cat(cat_name, cat_ids[i]); 104 (void) rc; 74 105 75 rc = loc_category_get_svcs(cat_ids[i], &svc_ids, &svc_cnt);76 if (rc != EOK) {77 printf(NAME ": Failed getting list of services in "78 "category %s, skipping.\n", cat_name);79 free(cat_name);80 continue;81 }82 83 for (j = 0; j < svc_cnt; j++) {84 rc = loc_service_get_name(svc_ids[j], &svc_name);85 if (rc != EOK) {86 printf(NAME ": Unknown service name (SID %"87 PRIun ").\n", svc_ids[j]);88 continue;89 }90 printf("\t%s (%" PRIun ")\n", svc_name, svc_ids[j]);91 free(svc_name);92 }93 94 free(svc_ids);95 106 free(cat_name); 96 107 } 97 108 98 109 free(cat_ids); 110 return EOK; 111 } 112 113 static void print_syntax(void) 114 { 115 printf("syntax:\n" 116 "\t" NAME " List categories and services " 117 "they contain\n" 118 "\t" NAME " show-cat <category> List services in category\n"); 119 } 120 121 int main(int argc, char *argv[]) 122 { 123 int rc; 124 char *cmd; 125 char *cat_name; 126 category_id_t cat_id; 127 128 if (argc <= 1) { 129 rc = list_svcs_by_cat(); 130 if (rc != EOK) 131 return 1; 132 return 0; 133 } 134 135 cmd = argv[1]; 136 if (str_cmp(cmd, "show-cat") == 0) { 137 if (argc < 3) { 138 printf("Argument missing.\n"); 139 print_syntax(); 140 return 1; 141 } 142 143 cat_name = argv[2]; 144 rc = loc_category_get_id(cat_name, &cat_id, 0); 145 if (rc != EOK) { 146 printf("Error looking up category '%s'.\n", cat_name); 147 return 1; 148 } 149 150 rc = show_cat(cat_name, cat_id); 151 if (rc != EOK) 152 return 1; 153 } else { 154 printf("Invalid command '%s'\n", cmd); 155 print_syntax(); 156 return 1; 157 } 158 99 159 return 0; 100 160 }
Note:
See TracChangeset
for help on using the changeset viewer.