Changeset 72cf064 in mainline for uspace/app/sportdmp/sportdmp.c


Ignore:
Timestamp:
2012-08-13T17:17:04Z (12 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
33fee91
Parents:
f4a8734 (diff), 4820360 (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 edited

Legend:

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

    rf4a8734 r72cf064  
    3737static void syntax_print(void)
    3838{
    39         fprintf(stderr, "Usage: sportdmp <baud> <device_service>\n");
     39        fprintf(stderr, "Usage: sportdmp [--baud=<baud>] [device_service]\n");
    4040}
    4141
    4242int main(int argc, char **argv)
    4343{
    44         const char* svc_path = "devices/\\hw\\pci0\\00:01.0\\com1\\a";
    4544        sysarg_t baud = 9600;
     45        service_id_t svc_id;
    4646       
    47         if (argc > 1) {
     47        int arg = 1;
     48        int rc;
     49               
     50        if (argc > arg && str_test_prefix(argv[arg], "--baud=")) {
     51                size_t arg_offset = str_lsize(argv[arg], 7);
     52                char* arg_str = argv[arg] + arg_offset;
     53                if (str_length(arg_str) == 0) {
     54                        fprintf(stderr, "--baud requires an argument\n");
     55                        syntax_print();
     56                        return 1;
     57                }
    4858                char *endptr;
    49                 baud = strtol(argv[1], &endptr, 10);
     59                baud = strtol(arg_str, &endptr, 10);
    5060                if (*endptr != '\0') {
    5161                        fprintf(stderr, "Invalid value for baud\n");
     
    5363                        return 1;
    5464                }
     65                arg++;
    5566        }
    5667       
    57         if (argc > 2) {
    58                 svc_path = argv[2];
     68        if (argc > arg) {
     69                rc = loc_service_get_id(argv[arg], &svc_id, 0);
     70                if (rc != EOK) {
     71                        fprintf(stderr, "Cannot find device service %s\n",
     72                            argv[arg]);
     73                        return 1;
     74                }
     75                arg++;
     76        }
     77        else {
     78                category_id_t serial_cat_id;
     79               
     80                rc = loc_category_get_id("serial", &serial_cat_id, 0);
     81                if (rc != EOK) {
     82                        fprintf(stderr, "Failed getting id of category "
     83                            "'serial'\n");
     84                        return 1;
     85                }
     86               
     87                service_id_t *svc_ids;
     88                size_t svc_count;
     89               
     90                rc = loc_category_get_svcs(serial_cat_id, &svc_ids, &svc_count);                if (rc != EOK) {
     91                        fprintf(stderr, "Failed getting list of services\n");
     92                        return 1;
     93                }
     94               
     95                if (svc_count == 0) {
     96                        fprintf(stderr, "No service in category 'serial'\n");
     97                        free(svc_ids);
     98                        return 1;
     99                }
     100               
     101                svc_id = svc_ids[0];
     102                free(svc_ids);
    59103        }
    60104       
    61         if (argc > 3) {
     105        if (argc > arg) {
     106                fprintf(stderr, "Too many arguments\n");
    62107                syntax_print();
    63108                return 1;
    64109        }
    65110       
    66         service_id_t svc_id;
    67         int rc = loc_service_get_id(svc_path, &svc_id, IPC_FLAG_BLOCKING);
    68         if (rc != EOK) {
    69                 fprintf(stderr, "Cannot find device service %s\n", svc_path);
    70                 return 1;
    71         }
    72111       
    73112        async_sess_t *sess = loc_service_connect(EXCHANGE_SERIALIZE, svc_id,
    74113            IPC_FLAG_BLOCKING);
    75114        if (!sess) {
    76                 fprintf(stderr, "Failed connecting to service %s\n", svc_path);
     115                fprintf(stderr, "Failed connecting to service\n");
    77116        }
    78117       
Note: See TracChangeset for help on using the changeset viewer.