Changeset 6843a9c in mainline for uspace/app/loc/loc.c
- Timestamp:
- 2012-06-29T13:02:14Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 722912e
- Parents:
- ba72f2b (diff), 0bbd13e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/loc/loc.c
rba72f2b r6843a9c 27 27 */ 28 28 29 /** @addtogroup loc info29 /** @addtogroup loc 30 30 * @{ 31 31 */ 32 /** @file loc info.c Print information from location service.32 /** @file loc.c Print information from location service. 33 33 */ 34 34 … … 41 41 #include <sys/typefmt.h> 42 42 43 #define NAME "loc info"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 char *server_name; 51 int rc; 52 size_t j; 53 54 printf("%s:\n", cat_name); 55 56 rc = loc_category_get_svcs(cat_id, &svc_ids, &svc_cnt); 57 if (rc != EOK) { 58 printf(NAME ": Failed getting list of services in " 59 "category %s, skipping.\n", cat_name); 60 return rc; 61 } 62 63 for (j = 0; j < svc_cnt; j++) { 64 rc = loc_service_get_name(svc_ids[j], &svc_name); 65 if (rc != EOK) { 66 printf(NAME ": Unknown service name (SID %" 67 PRIun ").\n", svc_ids[j]); 68 continue; 69 } 70 71 rc = loc_service_get_server_name(svc_ids[j], &server_name); 72 if (rc != EOK && rc != EINVAL) { 73 free(svc_name); 74 printf(NAME ": Unknown service name (SID %" 75 PRIun ").\n", svc_ids[j]); 76 continue; 77 } 78 79 if (rc == EOK) 80 printf("\t%s : %s\n", svc_name, server_name); 81 else 82 printf("\t%s\n", svc_name); 83 84 free(svc_name); 85 free(server_name); 86 } 87 88 free(svc_ids); 89 return EOK; 90 } 91 92 static int list_svcs_by_cat(void) 46 93 { 47 94 category_id_t *cat_ids; 48 95 size_t cat_cnt; 49 service_id_t *svc_ids;50 size_t svc_cnt;51 96 52 size_t i , j;97 size_t i; 53 98 char *cat_name; 54 char *svc_name;55 99 int rc; 56 100 … … 58 102 if (rc != EOK) { 59 103 printf(NAME ": Error getting list of categories.\n"); 60 return 1;104 return rc; 61 105 } 62 106 … … 68 112 if (cat_name == NULL) { 69 113 printf(NAME ": Error allocating memory.\n"); 70 return 1; 114 free(cat_ids); 115 return rc; 71 116 } 72 117 73 printf("%s (%" PRIun "):\n", cat_name, cat_ids[i]); 118 rc = show_cat(cat_name, cat_ids[i]); 119 (void) rc; 74 120 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 }92 93 free(svc_ids);94 121 free(cat_name); 95 122 } 96 123 97 124 free(cat_ids); 125 return EOK; 126 } 127 128 static void print_syntax(void) 129 { 130 printf("syntax:\n" 131 "\t" NAME " List categories and services " 132 "they contain\n" 133 "\t" NAME " show-cat <category> List services in category\n"); 134 } 135 136 int main(int argc, char *argv[]) 137 { 138 int rc; 139 char *cmd; 140 char *cat_name; 141 category_id_t cat_id; 142 143 if (argc <= 1) { 144 rc = list_svcs_by_cat(); 145 if (rc != EOK) 146 return 1; 147 return 0; 148 } 149 150 cmd = argv[1]; 151 if (str_cmp(cmd, "show-cat") == 0) { 152 if (argc < 3) { 153 printf("Argument missing.\n"); 154 print_syntax(); 155 return 1; 156 } 157 158 cat_name = argv[2]; 159 rc = loc_category_get_id(cat_name, &cat_id, 0); 160 if (rc != EOK) { 161 printf("Error looking up category '%s'.\n", cat_name); 162 return 1; 163 } 164 165 rc = show_cat(cat_name, cat_id); 166 if (rc != EOK) 167 return 1; 168 } else { 169 printf("Invalid command '%s'\n", cmd); 170 print_syntax(); 171 return 1; 172 } 173 98 174 return 0; 99 175 }
Note:
See TracChangeset
for help on using the changeset viewer.