#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
*/
}
}
+/* 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
* 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
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);
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);
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;
#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
/* 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__