aboutsummaryrefslogtreecommitdiffstats
path: root/com32/rosh
diff options
context:
space:
mode:
authorGene Cumm <gene.cumm@gmail.com>2010-10-09 11:28:48 -0400
committerGene Cumm <gene.cumm@gmail.com>2010-10-09 11:28:48 -0400
commit9ca018b331ccda7043b5c8b179849bc0d35949a1 (patch)
tree6cabda6d4500275e0202b3b47e4edb8c040011c1 /com32/rosh
parent0b2566e9aebbde9b16bb2fff6c0312e5cd403df0 (diff)
downloadsyslinux-9ca018b331ccda7043b5c8b179849bc0d35949a1.tar.gz
syslinux-9ca018b331ccda7043b5c8b179849bc0d35949a1.tar.xz
syslinux-9ca018b331ccda7043b5c8b179849bc0d35949a1.zip
rosh: Fix rosh_ls(); fix FTBFS on rosh_more(); add ROSH_DEBUG2_ARGV_V macro
Diffstat (limited to 'com32/rosh')
-rw-r--r--com32/rosh/rosh.c32
-rw-r--r--com32/rosh/rosh.h6
2 files changed, 31 insertions, 7 deletions
diff --git a/com32/rosh/rosh.c b/com32/rosh/rosh.c
index 476dfd2a..b22a42c2 100644
--- a/com32/rosh/rosh.c
+++ b/com32/rosh/rosh.c
@@ -41,7 +41,7 @@
#define APP_NAME "rosh"
#define APP_AUTHOR "Gene Cumm"
#define APP_YEAR "2010"
-#define APP_VER "beta-b085"
+#define APP_VER "beta-b087"
/* Print version information to stdout
*/
@@ -240,6 +240,14 @@ void rosh_pr_argv_v(int argc, char *argv[])
}
}
+/* Reset the getopt() environment
+ */
+void rosh_getopt_reset(void)
+{
+ optind = 0;
+ optopt = 0;
+}
+
/* Display help
* type Help type
* cmdstr Command for which help is requested
@@ -495,30 +503,40 @@ void rosh_echo(const char *cmdstr)
* argv Argument values
* optarr option array to populate
*/
-void rosh_ls_arg_opt(int argc, char *argv[], int *optarr)
+void rosh_ls_arg_opt(int argc, char *argv[], int optarr[])
{
int rv = 0;
optarr[0] = -1;
optarr[1] = -1;
optarr[2] = -1;
+ rosh_getopt_reset();
while (rv != -1) {
+ ROSH_DEBUG2("getopt optind=%d rv=%d\n", optind, rv);
rv = getopt(argc, argv, rosh_ls_opt_str);
switch (rv) {
case 'l':
+ case 0:
optarr[0] = 1;
break;
case 'F':
+ case 1:
optarr[1] = 1;
break;
case 'i':
+ case 2:
optarr[2] = 1;
break;
case '?':
+ case -1:
default:
+ ROSH_DEBUG2("getopt optind=%d rv=%d\n", optind, rv);
break;
}
}
+ ROSH_DEBUG2(" end getopt optind=%d rv=%d\n", optind, rv);
+ ROSH_DEBUG2("\tIn rosh_ls_arg_opt() opt[0]=%d\topt[1]=%d\topt[2]=%d\n", optarr[0], optarr[1],
+ optarr[2]);
} /* rosh_ls_arg_opt */
/* Retrieve the size of a file argument
@@ -865,11 +883,13 @@ void rosh_ls(int argc, char *argv[])
int i;
rosh_ls_arg_opt(argc, argv, optarr);
+ ROSH_DEBUG2("In ls()\n");
+ ROSH_DEBUG2_ARGV_V(argc, argv);
#ifdef DO_DEBUG
optarr[0] = 2;
#endif /* DO_DEBUG */
- ROSH_DEBUG(" argc=%d; optind=%d\n", argc, optind);
- if (optind > argc)
+ ROSH_DEBUG2(" argc=%d; optind=%d\n", argc, optind);
+ if (optind >= argc)
rosh_ls_arg(".", optarr);
for (i = optind; i < argc; i++) {
rosh_ls_arg(argv[i], optarr);
@@ -993,7 +1013,7 @@ void rosh_more(int argc, char *argv[])
char *scrbuf;
int ret;
- ROSH_DEBUG("CMD: '%s'\n", cmdstr);
+ ROSH_DEBUG_ARGV_V(argc, argv);
ret = getscreensize(1, &rows, &cols);
if (ret) {
ROSH_DEBUG("getscreensize() fail(%d); fall back\n", ret);
@@ -1192,7 +1212,7 @@ char rosh_command(int argc, char *argv[], const char *ipwdstr)
case 's':
case 'S':
if (strncasecmp("ls", argv[0], tlen) == 0)
- rosh_ls(argc - 1, &argv[1]);
+ rosh_ls(argc, argv);
else
rosh_help(1, NULL);
break;
diff --git a/com32/rosh/rosh.h b/com32/rosh/rosh.h
index 0127df7a..cabf556a 100644
--- a/com32/rosh/rosh.h
+++ b/com32/rosh/rosh.h
@@ -36,13 +36,14 @@
#include <sys/stat.h> /* fstat() */
#include <fcntl.h> /* open(); open mode macros */
#include <dirent.h> /* fdopendir() opendir() readdir() closedir() DIR */
-#include <unistd.h> /* getcwd() */
+#include <unistd.h> /* getcwd() getopt() */
#include <errno.h> /* errno; error macros */
#include <netinet/in.h> /* For htonl/ntohl/htons/ntohs */
#include <ctype.h> /* isspace() */
#include <getkey.h>
#include <consoles.h> /* console_ansi_raw() console_ansi_std() */
+// #include <getopt.h> /* getopt_long() */
#ifdef DO_DEBUG
# define ROSH_DEBUG printf
@@ -50,14 +51,17 @@
/* define ROSH_DEBUG(f, ...) printf (f, ## __VA_ARGS__) */
# ifdef DO_DEBUG2
# define ROSH_DEBUG2 printf
+# define ROSH_DEBUG2_ARGV_V rosh_pr_argv_v
# else /* DO_DEBUG2 */
/* This forces a format argument into the function call */
# define ROSH_DEBUG2(f, ...) ((void)0)
+# define ROSH_DEBUG2_ARGV_V(argc, argv) ((void)0)
# endif /* DO_DEBUG2 */
#else /* DO_DEBUG */
# define ROSH_DEBUG(f, ...) ((void)0)
# define ROSH_DEBUG_ARGV_V(argc, argv) ((void)0)
# define ROSH_DEBUG2(f, ...) ((void)0)
+# define ROSH_DEBUG2_ARGV_V(argc, argv) ((void)0)
#endif /* DO_DEBUG */
#ifdef __COM32__