Changeset 97c7682 in mainline for uspace/app/loc/loc.c


Ignore:
Timestamp:
2012-07-14T11:18:40Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
804d9b6
Parents:
0747468 (diff), f0348c8 (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.

Text conflict in boot/arch/arm32/Makefile.inc:

Trivial conflict around ifeq condition.

Text conflict in kernel/arch/arm32/include/mm/page.h:

Added defines and set_pt_levelx_present function.
COnflict looked horrible because of the armv4/v7 split.

File:
1 moved

Legend:

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

    r0747468 r97c7682  
    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        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
     92static int list_svcs_by_cat(void)
    4693{
    4794        category_id_t *cat_ids;
    4895        size_t cat_cnt;
    49         service_id_t *svc_ids;
    50         size_t svc_cnt;
    5196
    52         size_t i, j;
     97        size_t i;
    5398        char *cat_name;
    54         char *svc_name;
    5599        int rc;
    56100
     
    58102        if (rc != EOK) {
    59103                printf(NAME ": Error getting list of categories.\n");
    60                 return 1;
     104                return rc;
    61105        }
    62106
     
    68112                if (cat_name == NULL) {
    69113                        printf(NAME ": Error allocating memory.\n");
    70                         return 1;
     114                        free(cat_ids);
     115                        return rc;
    71116                }
    72117
    73                 printf("%s (%" PRIun "):\n", cat_name, cat_ids[i]);
     118                rc = show_cat(cat_name, cat_ids[i]);
     119                (void) rc;
    74120
    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);
    95121                free(cat_name);
    96122        }
    97123
    98124        free(cat_ids);
     125        return EOK;
     126}
     127
     128static 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
     136int 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
    99174        return 0;
    100175}
Note: See TracChangeset for help on using the changeset viewer.