aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog15
-rw-r--r--mpiosh/Makefile.am4
-rw-r--r--mpiosh/callback.c11
-rw-r--r--mpiosh/command.c12
-rw-r--r--mpiosh/global.c111
-rw-r--r--mpiosh/global.h59
-rw-r--r--mpiosh/mpiosh.c95
-rw-r--r--mpiosh/mpiosh.h31
-rw-r--r--mpiosh/readline.c34
9 files changed, 238 insertions, 134 deletions
diff --git a/ChangeLog b/ChangeLog
index 875bae7..8d56685 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
2002-10-12 Andreas Buesching <crunchy@tzi.de>
+ * mpiosh/global.c (commands): removed commands 'put', 'get' and
+ 'del' and add these to the alias lists of 'mput', 'mget' and
+ 'mdel'. Also add some more alias to some other commands
+
+ * mpiosh/readline.c (mpiosh_readline_comp_cmd): add aliases to
+ completion list
+
+ * mpiosh/global.c (commands): use command completion for 'help'
+ arguments
+
+ * mpiosh/global.h: add alias list to command struct
+
+ * mpiosh/global.c: new file containing global symbols as the
+ command list
+
* mpiosh/callback.c: fix compiler warnings
* libmpio/mpio.c (mpio_memory_format): fixed compiler warning
diff --git a/mpiosh/Makefile.am b/mpiosh/Makefile.am
index db79d0f..d6586a8 100644
--- a/mpiosh/Makefile.am
+++ b/mpiosh/Makefile.am
@@ -2,7 +2,7 @@ INCLUDES=-I..
bin_PROGRAMS=mpiosh
-mpiosh_SOURCES=mpiosh.c callback.c readline.c command.c
+mpiosh_SOURCES=mpiosh.c callback.c readline.c command.c global.c
mpiosh_LDADD=../libmpio/libmpio.la -lreadline -lncurses
-noinst_HEADERS=mpiosh.h callback.h readline.h command.h \ No newline at end of file
+noinst_HEADERS=mpiosh.h callback.h readline.h command.h global.h \ No newline at end of file
diff --git a/mpiosh/callback.c b/mpiosh/callback.c
index 5d85781..65cfa49 100644
--- a/mpiosh/callback.c
+++ b/mpiosh/callback.c
@@ -2,7 +2,7 @@
*
* Author: Andreas Büsching <crunchy@tzi.de>
*
- * $Id: callback.c,v 1.21 2002/10/12 18:31:45 crunchy Exp $
+ * $Id: callback.c,v 1.22 2002/10/12 20:06:22 crunchy Exp $
*
* Copyright (C) 2001 Andreas Büsching <crunchy@tzi.de>
*
@@ -100,8 +100,15 @@ mpiosh_cmd_help(char *args[])
printf(" %s\n", cmd->args);
else
printf("\n");
+ if (cmd->aliases) {
+ char **go = cmd->aliases;
+ printf(" alias:\n ");
+ while(*go) printf(( *(go+1) ? "%s" : "%s, "), *go++);
+ printf("\n");
+ }
+
if (cmd->info)
- printf("%s\n", cmd->info);
+ printf(" description:\n%s\n", cmd->info);
else
printf("\n");
}
diff --git a/mpiosh/command.c b/mpiosh/command.c
index 7000e24..338ee8d 100644
--- a/mpiosh/command.c
+++ b/mpiosh/command.c
@@ -2,7 +2,7 @@
*
* Author: Andreas Buesching <crunchy@tzi.de>
*
- * $Id: command.c,v 1.1 2002/10/12 18:31:45 crunchy Exp $
+ * $Id: command.c,v 1.2 2002/10/12 20:06:22 crunchy Exp $
*
* Copyright (C) 2001 Andreas Büsching <crunchy@tzi.de>
*
@@ -74,7 +74,17 @@ mpiosh_command_find(char *line)
if (line[strlen(cmd->cmd)] == ' ' ||
line[strlen(cmd->cmd)] == '\0')
return cmd;
+ } else if (cmd->aliases) {
+ char **go = cmd->aliases;
+ while (*go) {
+ if ((strstr(line, *go) == line) &&
+ ((line[strlen(*go)] == ' ') || (line[strlen(*go)] == '\0'))) {
+ return cmd;
+ }
+ go++;
+ }
}
+
cmd++;
}
diff --git a/mpiosh/global.c b/mpiosh/global.c
new file mode 100644
index 0000000..832ac8b
--- /dev/null
+++ b/mpiosh/global.c
@@ -0,0 +1,111 @@
+/* global.c - containing global symbols for mpiosh
+ *
+ * Author: Andreas Buesching <crunchy@tzi.de>
+ *
+ * $Id: global.c,v 1.1 2002/10/12 20:06:22 crunchy Exp $
+ *
+ * Copyright (C) 2001 Andreas Büsching <crunchy@tzi.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "callback.h"
+#include "global.h"
+#include "readline.h"
+
+/* structure containing current state */
+mpiosh_t mpiosh;
+
+/* flag indicating a user-interrupt of the current command */
+int mpiosh_cancel = 0;
+int mpiosh_cancel_ack = 0;
+
+/* prompt strings */
+const char *PROMPT_INT = "\033[;1mmpio <i>\033[m ";
+const char *PROMPT_EXT = "\033[;1mmpio <e>\033[m ";
+
+mpiosh_cmd_t commands[] = {
+ { "debug", NULL , "[level|file|on|off] <value>",
+ " modify debugging options",
+ mpiosh_cmd_debug, NULL },
+ { "ver", NULL, NULL,
+ " version of mpio package",
+ mpiosh_cmd_version, NULL },
+ { "help", NULL, "[<command>]",
+ " show information about known commands or just about <command>",
+ mpiosh_cmd_help, mpiosh_readline_comp_cmd },
+ { "dir", (char *[]){ "ls", "ll", NULL }, NULL,
+ " list content of current memory card",
+ mpiosh_cmd_dir, NULL },
+ { "info", NULL, NULL,
+ " show information about MPIO player",
+ mpiosh_cmd_info, NULL },
+ { "mem", NULL, "[i|e]",
+ " set current memory card. 'i' selects the internal and 'e'\n"
+ " selects the external memory card (smart media card)",
+ mpiosh_cmd_mem, NULL },
+ { "open", NULL, NULL,
+ " open connect to MPIO player",
+ mpiosh_cmd_open, NULL },
+ { "close", NULL, NULL,
+ " close connect to MPIO player",
+ mpiosh_cmd_close, NULL },
+ { "quit", (char *[]){ "exit", NULL }, NULL,
+ " exit mpiosh and close the device",
+ mpiosh_cmd_quit, NULL },
+ { "mget", (char *[]){ "get", NULL }, "list of filenames and <regexp>",
+ " read all files matching the regular expression\n"
+ " from the selected memory card",
+ mpiosh_cmd_mget, mpiosh_readline_comp_mpio_file },
+ { "mput", (char *[]){ "put", NULL }, "list of filenames and <regexp>",
+ " write all local files matching the regular expression\n"
+ " to the selected memory card",
+ mpiosh_cmd_mput, mpiosh_readline_comp_mpio_file },
+ { "mdel", (char *[]){ "rm", "del", NULL }, "<regexp>",
+ " deletes all files matching the regular expression\n"
+ " from the selected memory card",
+ mpiosh_cmd_mdel, mpiosh_readline_comp_mpio_file },
+ { "dump", NULL, NULL,
+ " get all files of current memory card",
+ mpiosh_cmd_dump, NULL },
+ { "free", NULL, NULL,
+ " display amount of available bytes of current memory card",
+ mpiosh_cmd_free, NULL },
+ { "format", NULL, NULL,
+ " format current memory card",
+ mpiosh_cmd_format, NULL },
+/* { "switch", "<file1> <file2>", */
+/* "switches the order of two files", */
+/* mpiosh_cmd_switch }, */
+ { "ldir", (char *[]){ "lls", NULL }, NULL,
+ " list local directory",
+ mpiosh_cmd_ldir, NULL },
+ { "lpwd", NULL, NULL,
+ " print current working directory",
+ mpiosh_cmd_lpwd, NULL },
+ { "lcd", NULL, NULL,
+ " change the current working directory",
+ mpiosh_cmd_lcd, NULL },
+ { "lmkdir", NULL, NULL,
+ " create a local directory",
+ mpiosh_cmd_lmkdir, NULL },
+ { "dump_memory", NULL, NULL,
+ " dump FAT, directory, spare area and the first 0x100 of the\n"
+ " selected memory card",
+ mpiosh_cmd_dump_mem, NULL },
+ { NULL, NULL, NULL, NULL, NULL, NULL }
+};
+
+/* end of global.c */
diff --git a/mpiosh/global.h b/mpiosh/global.h
new file mode 100644
index 0000000..4800d68
--- /dev/null
+++ b/mpiosh/global.h
@@ -0,0 +1,59 @@
+/* global.h
+ *
+ * Author: Andreas Buesching <crunchy@tzi.de>
+ *
+ * $Id: global.h,v 1.1 2002/10/12 20:06:22 crunchy Exp $
+ *
+ * Copyright (C) 2001 Andreas Büsching <crunchy@tzi.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef MPIOSH_GLOBAL_HH
+#define MPIOSH_GLOBAL_HH
+
+#include "libmpio/mpio.h"
+
+/* type definitions */
+typedef void(*mpiosh_cmd_callback_t)(char *args[]);
+typedef char *(*mpiosh_comp_callback_t)(const char *text, int state);
+
+typedef struct {
+ mpio_t * dev;
+ mpio_mem_t card;
+ const char * prompt;
+} mpiosh_t;
+
+typedef struct {
+ char * cmd;
+ char ** aliases;
+ char * args;
+ char * info;
+ mpiosh_cmd_callback_t cmd_func;
+ mpiosh_comp_callback_t comp_func;
+} mpiosh_cmd_t;
+
+/* global structures */
+extern mpiosh_t mpiosh;
+extern mpiosh_cmd_t commands[];
+extern int mpiosh_cancel;
+extern int mpiosh_cancel_ack;
+
+extern const char *PROMPT_INT;
+extern const char *PROMPT_EXT;
+
+#endif
+
+/* end of global.h */
diff --git a/mpiosh/mpiosh.c b/mpiosh/mpiosh.c
index ff6b9d8..f5896a5 100644
--- a/mpiosh/mpiosh.c
+++ b/mpiosh/mpiosh.c
@@ -2,7 +2,7 @@
/*
*
- * $Id: mpiosh.c,v 1.19 2002/10/12 18:31:45 crunchy Exp $
+ * $Id: mpiosh.c,v 1.20 2002/10/12 20:06:22 crunchy Exp $
*
* Author: Andreas Büsching <crunchy@tzi.de>
*
@@ -37,99 +37,6 @@
#include "readline.h"
#include "mpiosh.h"
-/* structure containing current state */
-mpiosh_t mpiosh;
-
-/* flag indicating a user-interrupt of the current command */
-int mpiosh_cancel = 0;
-int mpiosh_cancel_ack = 0;
-
-/* prompt strings */
-const char *PROMPT_INT = "\033[;1mmpio <i>\033[m ";
-const char *PROMPT_EXT = "\033[;1mmpio <e>\033[m ";
-
-mpiosh_cmd_t commands[] = {
- { "debug", "[level|file|on|off] <value>",
- " modify debugging options",
- mpiosh_cmd_debug, NULL },
- { "ver", NULL,
- " version of mpio package",
- mpiosh_cmd_version, NULL },
- { "help", "[<command>]",
- " show information about known commands or just about <command>",
- mpiosh_cmd_help, NULL },
- { "dir", NULL,
- " list content of current memory card",
- mpiosh_cmd_dir, NULL },
- { "info", NULL,
- " show information about MPIO player",
- mpiosh_cmd_info, NULL },
- { "mem", "[i|e]",
- " set current memory card. 'i' selects the internal and 'e'\n"
- " selects the external memory card (smart media card)",
- mpiosh_cmd_mem, NULL },
- { "open", NULL,
- " open connect to MPIO player",
- mpiosh_cmd_open, NULL },
- { "close", NULL,
- " close connect to MPIO player",
- mpiosh_cmd_close, NULL },
- { "quit", " or exit",
- "exit mpiosh and close the device",
- mpiosh_cmd_quit, NULL },
- { "exit", NULL, NULL, mpiosh_cmd_quit },
- { "get", "<filename>",
- "read <filename> from memory card",
- mpiosh_cmd_get, mpiosh_readline_comp_mpio_file },
- { "mget", "<regexp>",
- " read all files matching the regular expression\n"
- " from the selected memory card",
- mpiosh_cmd_mget, mpiosh_readline_comp_mpio_file },
- { "put", "<filename>",
- " write <filename> to memory card",
- mpiosh_cmd_put, mpiosh_readline_comp_mpio_file },
- { "mput", "<regexp>",
- " write all local files matching the regular expression\n"
- " to the selected memory card",
- mpiosh_cmd_mput, mpiosh_readline_comp_mpio_file },
- { "del", "<filename>",
- " deletes <filename> from memory card",
- mpiosh_cmd_del, mpiosh_readline_comp_mpio_file },
- { "mdel", "<regexp>",
- " deletes all files matching the regular expression\n"
- " from the selected memory card",
- mpiosh_cmd_mdel, mpiosh_readline_comp_mpio_file },
- { "dump", NULL,
- " get all files of current memory card",
- mpiosh_cmd_dump, NULL },
- { "free", NULL,
- " display amount of available bytes of current memory card",
- mpiosh_cmd_free, NULL },
- { "format", NULL,
- " format current memory card",
- mpiosh_cmd_format, NULL },
-/* { "switch", "<file1> <file2>", */
-/* "switches the order of two files", */
-/* mpiosh_cmd_switch }, */
- { "ldir", NULL,
- " list local directory",
- mpiosh_cmd_ldir, NULL },
- { "lpwd", NULL,
- " print current working directory",
- mpiosh_cmd_lpwd, NULL },
- { "lcd", NULL,
- " change the current working directory",
- mpiosh_cmd_lcd, NULL },
- { "lmkdir", NULL,
- " create a local directory",
- mpiosh_cmd_lmkdir, NULL },
- { "dump_memory", NULL,
- " dump FAT, directory, spare area and the first 0x100 of the\n"
- " selected memory card",
- mpiosh_cmd_dump_mem, NULL },
- { NULL, NULL, NULL, NULL, NULL }
-};
-
/* mpiosh core functions */
void
mpiosh_init(void)
diff --git a/mpiosh/mpiosh.h b/mpiosh/mpiosh.h
index 5bb76da..8291178 100644
--- a/mpiosh/mpiosh.h
+++ b/mpiosh/mpiosh.h
@@ -2,7 +2,7 @@
*
* Author: Andreas Büsching <crunchy@tzi.de>
*
- * $Id: mpiosh.h,v 1.7 2002/10/12 18:31:45 crunchy Exp $
+ * $Id: mpiosh.h,v 1.8 2002/10/12 20:06:22 crunchy Exp $
*
* Copyright (C) 2002 Andreas Büsching <crunchy@tzi.de>
*
@@ -24,39 +24,14 @@
#ifndef _MPIOSH_H_
#define _MPIOSH_H_
-#include "libmpio/mpio.h"
#include "libmpio/debug.h"
-typedef void(*mpiosh_cmd_callback_t)(char *args[]);
-typedef char *(*mpiosh_comp_callback_t)(const char *text, int state);
-
-typedef struct {
- mpio_t * dev;
- mpio_mem_t card;
- const char * prompt;
-} mpiosh_t;
-
-typedef struct {
- char * cmd;
- char * args;
- char * info;
- mpiosh_cmd_callback_t cmd_func;
- mpiosh_comp_callback_t comp_func;
-} mpiosh_cmd_t;
-
+#include "global.h"
+
/* mpiosh core functions */
void mpiosh_signal_handler(int signal);
void mpiosh_init(void);
-/* global structures */
-extern mpiosh_t mpiosh;
-extern mpiosh_cmd_t commands[];
-extern int mpiosh_cancel;
-extern int mpiosh_cancel_ack;
-
-extern const char *PROMPT_INT;
-extern const char *PROMPT_EXT;
-
#endif // _MPIOSH_H_
/* end of mpiosh.h */
diff --git a/mpiosh/readline.c b/mpiosh/readline.c
index 0b8731d..5427b9f 100644
--- a/mpiosh/readline.c
+++ b/mpiosh/readline.c
@@ -2,7 +2,7 @@
*
* Author: Andreas Büsching <crunchy@tzi.de>
*
- * $Id: readline.c,v 1.1 2002/10/12 18:31:45 crunchy Exp $
+ * $Id: readline.c,v 1.2 2002/10/12 20:06:22 crunchy Exp $
*
* Copyright (C) 2001 Andreas Büsching <crunchy@tzi.de>
*
@@ -41,7 +41,9 @@ mpiosh_readline_init(void)
char *
mpiosh_readline_comp_cmd(const char *text, int state)
{
- static mpiosh_cmd_t *cmd = NULL;
+ static mpiosh_cmd_t * cmd = NULL;
+ static char ** alias = NULL;
+
char *cmd_text = NULL;
if (state == 0) {
@@ -49,12 +51,30 @@ mpiosh_readline_comp_cmd(const char *text, int state)
}
while (cmd->cmd) {
- if ((*text == '\0') || (strstr(cmd->cmd, text) == cmd->cmd)) {
- cmd_text = strdup(cmd->cmd);
- cmd++;
- break;
+ if (!alias) {
+ if ((*text == '\0') || (strstr(cmd->cmd, text) == cmd->cmd)) {
+ cmd_text = strdup(cmd->cmd);
+ if (cmd->aliases) alias = cmd->aliases;
+ else cmd++;
+ break;
+ }
+ if (cmd->aliases) alias = cmd->aliases;
+ else cmd++;
+ } else {
+ int break_it = 0;
+
+ while (*alias) {
+ if (strstr(*alias, text) == *alias) {
+ cmd_text = strdup(*alias);
+ alias++;
+ break_it = 1;
+ break;
+ }
+ alias++;
+ }
+ if (break_it) break;
+ if (*alias == NULL) cmd++, alias = NULL;
}
- cmd++;
}
return cmd_text;