rosh: change rosh_cd() to use argc/argv
authorGene Cumm <gene.cumm@gmail.com>
Fri, 1 Oct 2010 03:03:35 +0000 (23:03 -0400)
committerGene Cumm <gene.cumm@gmail.com>
Sat, 9 Oct 2010 11:33:07 +0000 (07:33 -0400)
com32/rosh/rosh.c
com32/rosh/rosh.h

index 97be4fc..0d51f22 100644 (file)
@@ -41,7 +41,7 @@
 #define APP_NAME       "rosh"
 #define APP_AUTHOR     "Gene Cumm"
 #define APP_YEAR       "2010"
-#define APP_VER                "beta-b071"
+#define APP_VER                "beta-b072"
 
 void rosh_version(int vtype)
 {
@@ -221,6 +221,9 @@ void rosh_help(int type, const char *cmdstr)
            puts(rosh_help_str2);
        } else {
            switch (istr[0]) {
+           case 'c':
+               puts(rosh_help_cd_str);
+               break;
            case 'l':
                puts(rosh_help_ls_str);
                break;
@@ -407,26 +410,21 @@ void rosh_cat(const char *cmdstr)
 }                              /* rosh_cat */
 
 /* Change PWD (Present Working Directory)
- *     cmdstr  command string to process
+ *     argc    Argument count
+ *     argv    Argument values
  *     ipwdstr Initial PWD
  */
-void rosh_cd(const char *cmdstr, const char *ipwdstr)
+void rosh_cd(int argc, char *argv[], const char *ipwdstr)
 {
-    int rv;
-    char filestr[ROSH_PATH_SZ];
-    int cmdpos;
-    ROSH_DEBUG("CMD: '%s'\n", cmdstr);
-    /* Initialization */
-    filestr[0] = 0;
-    cmdpos = 0;
-    rv = 0;
-    /* skip the first word */
-    cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
-    cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
-    if (strlen(filestr) != 0)
-       rv = chdir(filestr);
-    else
+    int rv = 0;
+    ROSH_DEBUG("CMD: \n");
+    ROSH_DEBUG_ARGV(argc, argv);
+    if (argc == 2)
+       rv = chdir(argv[1]);
+    else if (argc == 1)
        rv = chdir(ipwdstr);
+    else
+       rosh_help(2, argv[0]);
     if (rv != 0) {
        rosh_error(errno, "cd", filestr);
        errno = 0;
@@ -1147,7 +1145,7 @@ char rosh_command(const char *cmdstr, const char *ipwdstr)
        case 'd':
        case 'D':
            if (strncasecmp("cd", argv[0], tlen) == 0)
-               rosh_cd(cmdstr, ipwdstr);
+               rosh_cd(argc, argv, ipwdstr);
            else
                rosh_help(1, NULL);
            break;
index 118c531..907df1e 100644 (file)
@@ -46,6 +46,7 @@
 
 #ifdef DO_DEBUG
 # define ROSH_DEBUG    printf
+# define ROSH_DEBUG_ARGV       rosh_pr_argv
 /* define ROSH_DEBUG(f, ...)   printf (f, ## __VA_ARGS__) */
 # ifdef DO_DEBUG2
 #  define ROSH_DEBUG2  printf
@@ -55,6 +56,7 @@
 # endif        /* DO_DEBUG2 */
 #else /* DO_DEBUG */
 # define ROSH_DEBUG(f, ...)    ((void)0)
+# define ROSH_DEBUG_ARGV(int argc, char *argv[])       ((void)0)
 # define ROSH_DEBUG2(f, ...)   ((void)0)
 #endif /* DO_DEBUG */
 
@@ -235,6 +237,10 @@ const char rosh_beta_str[] =
 const char rosh_cd_norun_str[] =
     " -- cd (Change Directory) not implemented for use with run and exit.\n";
 
+const char rosh_help_cd_str[] = "cd    Change directory\n\
+   with no argument, return to original directory from entry to rosh\n\
+   with one argument, change to that directory";
+
 const char rosh_help_ls_str[] = "ls    List contents of current directory\n\
   -l  Long format\n\
   -i  Inode; print Inode of file\n\