Changeset 0b749a3 in mainline for uspace/app/getterm/getterm.c


Ignore:
Timestamp:
2010-11-22T15:39:53Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0eddb76, aae339e9
Parents:
9a1d8ab (diff), 8cd1aa5e (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 development/ changes

File:
1 edited

Legend:

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

    r9a1d8ab r0b749a3  
    4141#include <task.h>
    4242#include <str_error.h>
     43#include <errno.h>
    4344#include "version.h"
     45#include "welcome.h"
    4446
    4547#define APP_NAME  "getterm"
     
    4749static void usage(void)
    4850{
    49         printf("Usage: %s <terminal> <path>\n", APP_NAME);
     51        printf("Usage: %s <terminal> [-w] <command> [<arguments...>]\n", APP_NAME);
    5052}
    5153
     
    7274}
    7375
    74 static task_id_t spawn(const char *fname)
    75 {
    76         const char *args[2];
    77        
    78         args[0] = fname;
    79         args[1] = NULL;
    80        
    81         int err;
    82         task_id_t id = task_spawn(fname, args, &err);
    83        
    84         if (id == 0)
    85                 printf("%s: Error spawning %s (%s)\n", APP_NAME, fname,
    86                     str_error(err));
    87        
    88         return id;
    89 }
    90 
    9176int main(int argc, char *argv[])
    9277{
    93         if (argc < 3) {
     78        int rc;
     79        task_exit_t texit;
     80        int retval;
     81        task_id_t id;
     82        char *fname, *term;
     83        char **cmd_args;
     84        bool print_wmsg;
     85
     86        argv++;
     87        argc--;
     88        if (argc < 1) {
    9489                usage();
    9590                return -1;
    9691        }
     92
     93        if (str_cmp(*argv, "-w") == 0) {
     94                print_wmsg = true;
     95                argv++;
     96                argc--;
     97        } else {
     98                print_wmsg = false;
     99        }
     100
     101        if (argc < 2) {
     102                usage();
     103                return -1;
     104        }
     105
     106        term = *argv++;
     107        fname = *argv;
     108        cmd_args = argv;
    97109       
    98         reopen(&stdin, 0, argv[1], O_RDONLY, "r");
    99         reopen(&stdout, 1, argv[1], O_WRONLY, "w");
    100         reopen(&stderr, 2, argv[1], O_WRONLY, "w");
     110        reopen(&stdin, 0, term, O_RDONLY, "r");
     111        reopen(&stdout, 1, term, O_WRONLY, "w");
     112        reopen(&stderr, 2, term, O_WRONLY, "w");
    101113       
    102114        /*
     
    115127                return -4;
    116128       
    117         version_print(argv[1]);
    118         task_id_t id = spawn(argv[2]);
    119        
    120         if (id != 0) {
    121                 task_exit_t texit;
    122                 int retval;
    123                 task_wait(id, &texit, &retval);
    124                
    125                 return 0;
     129        version_print(term);
     130        if (print_wmsg)
     131                welcome_msg_print();
     132
     133        rc = task_spawnv(&id, fname, (const char * const *) cmd_args);
     134        if (rc != EOK) {
     135                printf("%s: Error spawning %s (%s)\n", APP_NAME, fname,
     136                    str_error(rc));
     137                return -5;
    126138        }
    127        
    128         return -5;
     139
     140        rc = task_wait(id, &texit, &retval);
     141        if (rc != EOK) {
     142                printf("%s: Error waiting for %s (%s)\n", APP_NAME, fname,
     143                    str_error(rc));
     144                return -6;
     145        }
     146
     147        return 0;
    129148}
    130149
Note: See TracChangeset for help on using the changeset viewer.