Changeset eb083ad in mainline for uspace/app/loc/loc.c


Ignore:
Timestamp:
2012-05-17T21:09:06Z (12 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8fde078
Parents:
a8b8086 (diff), 3e67ab1 (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.
Message:

merge mainline changes

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/app/loc/loc.c

    ra8b8086 reb083ad  
    2727 */
    2828
    29 /** @addtogroup locinfo
     29/** @addtogroup loc
    3030 * @{
    3131 */
    32 /** @file locinfo.c Print information from location service.
     32/** @file loc.c Print information from location service.
    3333 */
    3434
     
    4141#include <sys/typefmt.h>
    4242
    43 #define NAME "locinfo"
     43#define NAME "loc"
    4444
    45 int main(int argc, char *argv[])
     45static 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
     77static int list_svcs_by_cat(void)
    4678{
    4779        category_id_t *cat_ids;
    4880        size_t cat_cnt;
    49         service_id_t *svc_ids;
    50         size_t svc_cnt;
    5181
    52         size_t i, j;
     82        size_t i;
    5383        char *cat_name;
    54         char *svc_name;
    5584        int rc;
    5685
     
    5887        if (rc != EOK) {
    5988                printf(NAME ": Error getting list of categories.\n");
    60                 return 1;
     89                return rc;
    6190        }
    6291
     
    6897                if (cat_name == NULL) {
    6998                        printf(NAME ": Error allocating memory.\n");
    70                         return 1;
     99                        free(cat_ids);
     100                        return rc;
    71101                }
    72102
    73                 printf("%s (%" PRIun "):\n", cat_name, cat_ids[i]);
     103                rc = show_cat(cat_name, cat_ids[i]);
     104                (void) rc;
    74105
    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);
    95106                free(cat_name);
    96107        }
    97108
    98109        free(cat_ids);
     110        return EOK;
     111}
     112
     113static 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
     121int 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
    99159        return 0;
    100160}
Note: See TracChangeset for help on using the changeset viewer.