aboutsummaryrefslogtreecommitdiff
path: root/mpiosh
diff options
context:
space:
mode:
authorcrunchy <crunchy>2002-10-12 18:31:45 +0000
committercrunchy <crunchy>2002-10-12 18:31:45 +0000
commitde0ca5908fbdfdd14d48ae733b39a323336b62df (patch)
tree6bef384b848c5b0f886f9ad868b2925e494ddbf4 /mpiosh
parent1f791c254d58441a745681b76c925c534e2b3638 (diff)
downloadmpiosh-de0ca5908fbdfdd14d48ae733b39a323336b62df.tar.gz
mpiosh-de0ca5908fbdfdd14d48ae733b39a323336b62df.tar.bz2
mpiosh-de0ca5908fbdfdd14d48ae733b39a323336b62df.zip
add completion for files on the mpio memory cards
Diffstat (limited to 'mpiosh')
-rw-r--r--mpiosh/Makefile.am4
-rw-r--r--mpiosh/callback.c14
-rw-r--r--mpiosh/command.c212
-rw-r--r--mpiosh/command.h38
-rw-r--r--mpiosh/mpiosh.c361
-rw-r--r--mpiosh/mpiosh.h26
-rw-r--r--mpiosh/readline.c148
-rw-r--r--mpiosh/readline.h45
8 files changed, 517 insertions, 331 deletions
diff --git a/mpiosh/Makefile.am b/mpiosh/Makefile.am
index bb38b8a..db79d0f 100644
--- a/mpiosh/Makefile.am
+++ b/mpiosh/Makefile.am
@@ -2,7 +2,7 @@ INCLUDES=-I..
bin_PROGRAMS=mpiosh
-mpiosh_SOURCES=mpiosh.c callback.c
+mpiosh_SOURCES=mpiosh.c callback.c readline.c command.c
mpiosh_LDADD=../libmpio/libmpio.la -lreadline -lncurses
-noinst_HEADERS=mpiosh.h callback.h \ No newline at end of file
+noinst_HEADERS=mpiosh.h callback.h readline.h command.h \ No newline at end of file
diff --git a/mpiosh/callback.c b/mpiosh/callback.c
index e4c64ab..5d85781 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.20 2002/09/28 00:32:41 germeier Exp $
+ * $Id: callback.c,v 1.21 2002/10/12 18:31:45 crunchy Exp $
*
* Copyright (C) 2001 Andreas Büsching <crunchy@tzi.de>
*
@@ -31,6 +31,8 @@
#include <unistd.h>
#include "mpiosh.h"
+#include "command.h"
+
#include "libmpio/debug.h"
/* commands */
@@ -99,7 +101,7 @@ mpiosh_cmd_help(char *args[])
else
printf("\n");
if (cmd->info)
- printf(" %s\n", cmd->info);
+ printf("%s\n", cmd->info);
else
printf("\n");
}
@@ -281,8 +283,7 @@ void
mpiosh_cmd_mget(char *args[])
{
BYTE * p;
- int size, i = 0;
- int error;
+ int i = 0, error;
regex_t regex;
BYTE fname[100];
BYTE errortext[100];
@@ -368,14 +369,11 @@ void
mpiosh_cmd_mput(char *args[])
{
char dir_buf[NAME_MAX];
- int size, j, i = 0;
+ int size, j, i = 0, error, written = 0;
struct dirent ** dentry, **run;
struct stat st;
regex_t regex;
- int error;
BYTE errortext[100];
- int fsize;
- int written = 0;
MPIOSH_CHECK_CONNECTION_CLOSED;
MPIOSH_CHECK_ARG;
diff --git a/mpiosh/command.c b/mpiosh/command.c
new file mode 100644
index 0000000..7000e24
--- /dev/null
+++ b/mpiosh/command.c
@@ -0,0 +1,212 @@
+/* command.c
+ *
+ * Author: Andreas Buesching <crunchy@tzi.de>
+ *
+ * $Id: command.c,v 1.1 2002/10/12 18:31:45 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 "command.h"
+
+char **
+mpiosh_command_split_line(char *line)
+{
+ char **cmds, *cmd;
+ int count = 1;
+ char *help, *copy = strdup(line);
+
+ help = copy;
+
+ while (*help)
+ if ((*help++ == ';') && (*(help) != '\0')) count++;
+ cmds = malloc(sizeof(char *) * (count + 1));
+
+ cmd = help = copy, count = 0;
+ while (*cmd == ' ') cmd++;
+ while (help) {
+ if (*help == '"') {
+ help++;
+ while (*help != '\0' && *help != '"') help++;
+ }
+
+ if (*help == '\0') break;
+ if (*help == ';') {
+ *help++ = '\0';
+ if (*help == '\0') break;
+ cmds[count++] = strdup(cmd);
+ while (*help == ' ') help++;
+ cmd = help;
+ }
+ help++;
+ }
+ if (cmd != '\0') {
+ cmds[count++] = strdup(cmd);
+ }
+
+ cmds[count] = NULL;
+ free(copy);
+
+ return cmds;
+}
+
+mpiosh_cmd_t *
+mpiosh_command_find(char *line)
+{
+ mpiosh_cmd_t *cmd = commands;
+
+ while (cmd->cmd) {
+ if (strstr(line, cmd->cmd) == line) {
+ if (line[strlen(cmd->cmd)] == ' ' ||
+ line[strlen(cmd->cmd)] == '\0')
+ return cmd;
+ }
+ cmd++;
+ }
+
+ return NULL;
+}
+
+void
+mpiosh_command_regex_fix(char *argv[])
+{
+ char **walk = argv;
+ char *new_pos, *help;
+ char buffer[512];
+
+ while (*walk) {
+ memset(buffer, '\0', 512);
+ help = *walk;
+ new_pos = buffer;
+ *new_pos++ = '^';
+ while (*help != '\0') {
+ if (*help == '*' && ((help == *walk) || (*(help - 1) != '.'))) {
+ *new_pos++ = '.';
+ *new_pos = *help;
+ } else if ((*help == '.') && (*(help + 1) != '*')) {
+ *new_pos++ = '\\';
+ *new_pos = *help;
+ } else if (*help == '?' && ((help == *walk) || (*(help - 1) != '\\'))) {
+ *new_pos = '.';
+ } else {
+ *new_pos = *help;
+ }
+
+ help++, new_pos++;
+ }
+ *new_pos = '$';
+ free(*walk);
+ *walk = strdup(buffer);
+
+ walk++;
+ }
+}
+
+char **
+mpiosh_command_get_args(char *line)
+{
+ char **args;
+ char *arg_start, *copy, *help, *prev;
+ int count = 0, i = 0, go = 1, in_quote = 0;
+
+ copy = strdup(line);
+ arg_start = strchr(copy, ' ');
+
+ if (arg_start == NULL) {
+ args = malloc(sizeof(char *));
+ args[0] = NULL;
+ return args;
+ }
+
+ while (*arg_start == ' ') arg_start++;
+
+ help = arg_start;
+ while (help <= (copy + strlen(copy))) {
+ if (*help == '"') {
+ help++;count++;
+
+ while (*help != '\0' && *help != '"')
+ help++;
+ help++;
+ while (*help == ' ') help++;
+ if (*help == '\0') break;
+ in_quote = 1;
+ } else if (((help > arg_start) && (*help == '\0')) ||
+ (*help == ' ' && (*(help + 1) != '\0') && (*(help + 1) != ' '))) {
+ count++;
+ in_quote = 0;
+ help++;
+ } else
+ help++;
+ }
+
+ args = malloc(sizeof(char *) * (count + 1));
+
+ help = prev = arg_start;
+ in_quote = 0;
+ while (go) {
+ if (*help == '"') in_quote = !in_quote, help++;
+ if (((*help == ' ') && !in_quote) || (in_quote && *help == '"') ||
+ (*help == '\0')) {
+ if (*help == '\0') {
+ go = 0;
+ if (*prev == '\0') break;
+ }
+
+ if (*prev == '"') {
+ if (*(help - 1) == '"')
+ *(help - 1) = '\0';
+ else
+ *help = '\0';
+
+ args[i++] = strdup(prev + 1);
+ } else {
+ *help = '\0';
+ args[i++] = strdup(prev);
+ }
+
+ if (go) {
+ help++;
+ if (in_quote) {
+ while (*help != '"') help++;
+ help++;
+ in_quote = 0;
+ } else
+ while (*help == ' ') help++;
+ prev = help;
+ }
+ } else
+ help++;
+ }
+ args[i] = NULL;
+
+ free(copy);
+
+ return args;
+}
+
+void
+mpiosh_command_free_args(char **args)
+{
+ char **arg = args;
+
+ while (*arg) free(*arg++);
+
+ free(args);
+}
+
+/* end of command.c */
diff --git a/mpiosh/command.h b/mpiosh/command.h
new file mode 100644
index 0000000..1374385
--- /dev/null
+++ b/mpiosh/command.h
@@ -0,0 +1,38 @@
+/* command.h
+ *
+ * Author: Andreas Buesching <crunchy@tzi.de>
+ *
+ * $Id: command.h,v 1.1 2002/10/12 18:31:45 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_COMMAND_HH
+#define MPIOSH_COMMAND_HH
+
+#include "mpiosh.h"
+
+/* command(-line) functions */
+mpiosh_cmd_t *mpiosh_command_find(char *line);
+char **mpiosh_command_split_line(char *line);
+char **mpiosh_command_get_args(char *line);
+void mpiosh_command_regex_fix(char *argv[]);
+void mpiosh_command_free_args(char **args);
+
+#endif
+
+/* end of command.h */
diff --git a/mpiosh/mpiosh.c b/mpiosh/mpiosh.c
index 508bf3d..ff6b9d8 100644
--- a/mpiosh/mpiosh.c
+++ b/mpiosh/mpiosh.c
@@ -2,7 +2,7 @@
/*
*
- * $Id: mpiosh.c,v 1.18 2002/09/23 22:38:03 germeier Exp $
+ * $Id: mpiosh.c,v 1.19 2002/10/12 18:31:45 crunchy Exp $
*
* Author: Andreas Büsching <crunchy@tzi.de>
*
@@ -26,17 +26,15 @@
* */
#include <signal.h>
-#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
-#include <readline/readline.h>
-#include <readline/history.h>
-
#include "libmpio/debug.h"
#include "libmpio/mpio.h"
#include "callback.h"
+#include "command.h"
+#include "readline.h"
#include "mpiosh.h"
/* structure containing current state */
@@ -52,132 +50,87 @@ 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 },
+ " modify debugging options",
+ mpiosh_cmd_debug, NULL },
{ "ver", NULL,
- "version of mpio package",
- mpiosh_cmd_version },
+ " version of mpio package",
+ mpiosh_cmd_version, NULL },
{ "help", "[<command>]",
- "show information about known commands or just about <command>",
- mpiosh_cmd_help },
+ " show information about known commands or just about <command>",
+ mpiosh_cmd_help, NULL },
{ "dir", NULL,
- "list content of current memory card",
- mpiosh_cmd_dir },
+ " list content of current memory card",
+ mpiosh_cmd_dir, NULL },
{ "info", NULL,
- "show information about MPIO player",
- mpiosh_cmd_info },
+ " show information about MPIO player",
+ mpiosh_cmd_info, NULL },
{ "mem", "[i|e]",
- "set current memory card. 'i' selects the internal and 'e' "
- "selects the external memory card (smart media card)",
- mpiosh_cmd_mem },
+ " 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 },
+ " open connect to MPIO player",
+ mpiosh_cmd_open, NULL },
{ "close", NULL,
- "close connect to MPIO player",
- mpiosh_cmd_close },
+ " close connect to MPIO player",
+ mpiosh_cmd_close, NULL },
{ "quit", " or exit",
"exit mpiosh and close the device",
- mpiosh_cmd_quit },
+ mpiosh_cmd_quit, NULL },
{ "exit", NULL, NULL, mpiosh_cmd_quit },
{ "get", "<filename>",
"read <filename> from memory card",
- mpiosh_cmd_get },
+ mpiosh_cmd_get, mpiosh_readline_comp_mpio_file },
{ "mget", "<regexp>",
- "read all files matching the regular expression "
- "from the selected memory card",
- mpiosh_cmd_mget },
+ " 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 },
+ " write <filename> to memory card",
+ mpiosh_cmd_put, mpiosh_readline_comp_mpio_file },
{ "mput", "<regexp>",
- "write all local files matching the regular expression "
- "to the selected memory card",
- mpiosh_cmd_mput },
+ " 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 },
+ " deletes <filename> from memory card",
+ mpiosh_cmd_del, mpiosh_readline_comp_mpio_file },
{ "mdel", "<regexp>",
- "deletes all files matching the regular expression "
- "from the selected memory card",
- mpiosh_cmd_mdel },
+ " 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 },
+ " 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 },
+ " display amount of available bytes of current memory card",
+ mpiosh_cmd_free, NULL },
{ "format", NULL,
- "format current memory card",
- mpiosh_cmd_format },
+ " 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 },
+ " list local directory",
+ mpiosh_cmd_ldir, NULL },
{ "lpwd", NULL,
- "print current working directory",
- mpiosh_cmd_lpwd },
+ " print current working directory",
+ mpiosh_cmd_lpwd, NULL },
{ "lcd", NULL,
- "change the current working directory",
- mpiosh_cmd_lcd },
+ " change the current working directory",
+ mpiosh_cmd_lcd, NULL },
{ "lmkdir", NULL,
- "create a local directory",
- mpiosh_cmd_lmkdir },
+ " create a local directory",
+ mpiosh_cmd_lmkdir, NULL },
{ "dump_memory", NULL,
- "dump FAT, directory, spare area and the first 0x100 of the selected memory card",
- mpiosh_cmd_dump_mem },
- { NULL, NULL, 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 }
};
-/* readline extensaions */
-void
-mpiosh_readline_init(void)
-{
- rl_readline_name = "mpio";
- rl_catch_signals = 0;
- rl_filename_quote_characters = " ";
- rl_attempted_completion_function = mpiosh_readline_completion;
- rl_event_hook = mpiosh_readline_cancel;
-}
-
-char *
-mpiosh_readline_comp_cmd(const char *text, int state)
-{
- static mpiosh_cmd_t *cmd = NULL;
- char *cmd_text = NULL;
-
- if (state == 0) {
- cmd = commands;
- }
-
- while (cmd->cmd) {
- if ((*text == '\0') || (strstr(cmd->cmd, text) == cmd->cmd)) {
- cmd_text = strdup(cmd->cmd);
- cmd++;
- break;
- }
- cmd++;
- }
-
- return cmd_text;
-}
-
-char **
-mpiosh_readline_completion(const char *text, int start, int end)
-{
- char **matches = (char**)NULL;
-
- UNUSED(end);
-
- if (start == 0)
- matches = rl_completion_matches(text, mpiosh_readline_comp_cmd);
-
- return matches;
-}
-
-/* helper functions */
+/* mpiosh core functions */
void
mpiosh_init(void)
{
@@ -186,200 +139,6 @@ mpiosh_init(void)
mpiosh.prompt = PROMPT_INT;
}
-char **
-mpiosh_command_split_line(char *line)
-{
- char **cmds, *cmd;
- int count = 1;
- char *help, *copy = strdup(line);
-
- help = copy;
-
- while (*help)
- if ((*help++ == ';') && (*(help) != '\0')) count++;
- cmds = malloc(sizeof(char *) * (count + 1));
-
- cmd = help = copy, count = 0;
- while (*cmd == ' ') cmd++;
- while (help) {
- if (*help == '"') {
- help++;
- while (*help != '\0' && *help != '"') help++;
- }
-
- if (*help == '\0') break;
- if (*help == ';') {
- *help++ = '\0';
- if (*help == '\0') break;
- cmds[count++] = strdup(cmd);
- while (*help == ' ') help++;
- cmd = help;
- }
- help++;
- }
- if (cmd != '\0') {
- cmds[count++] = strdup(cmd);
- }
-
- cmds[count] = NULL;
- free(copy);
-
- return cmds;
-}
-
-mpiosh_cmd_t *
-mpiosh_command_find(char *line)
-{
- mpiosh_cmd_t *cmd = commands;
-
- while (cmd->cmd) {
- if (strstr(line, cmd->cmd) == line) {
- if (line[strlen(cmd->cmd)] == ' ' ||
- line[strlen(cmd->cmd)] == '\0')
- return cmd;
- }
- cmd++;
- }
-
- return NULL;
-}
-
-void
-mpiosh_command_regex_fix(char *argv[])
-{
- char **walk = argv;
- char *new_pos, *help;
- char buffer[512];
-
- while (*walk) {
- memset(buffer, '\0', 512);
- help = *walk;
- new_pos = buffer;
- *new_pos++ = '^';
- while (*help != '\0') {
- if (*help == '*' && ((help == *walk) || (*(help - 1) != '.'))) {
- *new_pos++ = '.';
- *new_pos = *help;
- } else if ((*help == '.') && (*(help + 1) != '*')) {
- *new_pos++ = '\\';
- *new_pos = *help;
- } else if (*help == '?' && ((help == *walk) || (*(help - 1) != '\\'))) {
- *new_pos = '.';
- } else {
- *new_pos = *help;
- }
-
- help++, new_pos++;
- }
- *new_pos = '$';
- free(*walk);
- *walk = strdup(buffer);
-
- walk++;
- }
-}
-
-char **
-mpiosh_command_get_args(char *line)
-{
- char **args;
- char *arg_start, *copy, *help, *prev;
- int count = 0, i = 0, go = 1, in_quote = 0;
-
- copy = strdup(line);
- arg_start = strchr(copy, ' ');
-
- if (arg_start == NULL) {
- args = malloc(sizeof(char *));
- args[0] = NULL;
- return args;
- }
-
- while (*arg_start == ' ') arg_start++;
-
- help = arg_start;
- while (help <= (copy + strlen(copy))) {
- if (*help == '"') {
- help++;count++;
-
- while (*help != '\0' && *help != '"')
- help++;
- help++;
- while (*help == ' ') help++;
- if (*help == '\0') break;
- in_quote = 1;
- } else if (((help > arg_start) && (*help == '\0')) ||
- (*help == ' ' && (*(help + 1) != '\0') && (*(help + 1) != ' '))) {
- count++;
- in_quote = 0;
- help++;
- } else
- help++;
- }
-
- args = malloc(sizeof(char *) * (count + 1));
-
- help = prev = arg_start;
- in_quote = 0;
- while (go) {
- if (*help == '"') in_quote = !in_quote, help++;
- if (((*help == ' ') && !in_quote) || (in_quote && *help == '"') ||
- (*help == '\0')) {
- if (*help == '\0') {
- go = 0;
- if (*prev == '\0') break;
- }
-
- if (*prev == '"') {
- if (*(help - 1) == '"')
- *(help - 1) = '\0';
- else
- *help = '\0';
-
- args[i++] = strdup(prev + 1);
- } else {
- *help = '\0';
- args[i++] = strdup(prev);
- }
-
- if (go) {
- help++;
- if (in_quote) {
- while (*help != '"') help++;
- help++;
- in_quote = 0;
- } else
- while (*help == ' ') help++;
- prev = help;
- }
- } else
- help++;
- }
- args[i] = NULL;
-
- free(copy);
-
- return args;
-}
-
-void
-mpiosh_command_free_args(char **args)
-{
- char **arg = args;
-
- while (*arg) free(*arg++);
-
- free(args);
-}
-
-int
-mpiosh_readline_cancel(void)
-{
- if (mpiosh_cancel) rl_done = 1;
-
- return 0;
-}
-
void
mpiosh_signal_handler(int signal)
{
@@ -387,11 +146,6 @@ mpiosh_signal_handler(int signal)
mpiosh_cancel_ack = 0;
}
-void
-mpiosh_noredisplay(void)
-{
-}
-
int
main(int argc, char *argv[]) {
char * line;
@@ -430,8 +184,7 @@ main(int argc, char *argv[]) {
if (!isatty(fileno(stdin))) {
interactive = 0;
mpiosh.prompt = NULL;
- rl_redisplay_function = mpiosh_noredisplay;
- rl_event_hook = NULL;
+ mpiosh_readline_pipe();
}
if (!mpiosh.dev && interactive) {
@@ -462,10 +215,10 @@ main(int argc, char *argv[]) {
help = args;
if (!interactive) debug("running... '%s'\n", *walk);
- cmd->func(args);
+ cmd->cmd_func(args);
mpiosh_command_free_args(args);
} else
- printf("unknown command: '%s'\n", *walk);
+ fprintf(stderr, "unknown command: '%s'\n", *walk);
/* if ((idx = history_search(line, -1)) != -1) */
/* history_set_pos(idx); */
diff --git a/mpiosh/mpiosh.h b/mpiosh/mpiosh.h
index ba7079b..5bb76da 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.6 2002/09/21 22:17:15 germeier Exp $
+ * $Id: mpiosh.h,v 1.7 2002/10/12 18:31:45 crunchy Exp $
*
* Copyright (C) 2002 Andreas Büsching <crunchy@tzi.de>
*
@@ -24,7 +24,11 @@
#ifndef _MPIOSH_H_
#define _MPIOSH_H_
-typedef void(*cmd_callback)(char *args[]);
+#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;
@@ -36,25 +40,13 @@ typedef struct {
char * cmd;
char * args;
char * info;
- cmd_callback func;
+ mpiosh_cmd_callback_t cmd_func;
+ mpiosh_comp_callback_t comp_func;
} mpiosh_cmd_t;
-/* signal handler */
+/* mpiosh core functions */
void mpiosh_signal_handler(int signal);
-
-/* readline extensions */
-void mpiosh_readline_init(void);
-char **mpiosh_readline_completion(const char *text, int start, int end);
-char *mpiosh_readline_comp_cmd(const char *text, int state);
-int mpiosh_readline_cancel(void);
-
-/* helper functions */
void mpiosh_init(void);
-mpiosh_cmd_t *mpiosh_command_find(char *line);
-char **mpiosh_command_split_line(char *line);
-char **mpiosh_command_get_args(char *line);
-void mpiosh_command_regex_fix(char *argv[]);
-void mpiosh_command_free_args(char **args);
/* global structures */
extern mpiosh_t mpiosh;
diff --git a/mpiosh/readline.c b/mpiosh/readline.c
new file mode 100644
index 0000000..0b8731d
--- /dev/null
+++ b/mpiosh/readline.c
@@ -0,0 +1,148 @@
+/* readline.c
+ *
+ * Author: Andreas Büsching <crunchy@tzi.de>
+ *
+ * $Id: readline.c,v 1.1 2002/10/12 18:31:45 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 "readline.h"
+
+#include "command.h"
+#include "mpiosh.h"
+
+/* readline extensions */
+void
+mpiosh_readline_init(void)
+{
+ rl_readline_name = "mpio";
+ rl_catch_signals = 0;
+ rl_completer_quote_characters = "\"\'";
+ rl_filename_quote_characters = " \"\' ";
+ rl_attempted_completion_function = mpiosh_readline_completion;
+ rl_event_hook = mpiosh_readline_cancel;
+}
+
+char *
+mpiosh_readline_comp_cmd(const char *text, int state)
+{
+ static mpiosh_cmd_t *cmd = NULL;
+ char *cmd_text = NULL;
+
+ if (state == 0) {
+ cmd = commands;
+ }
+
+ while (cmd->cmd) {
+ if ((*text == '\0') || (strstr(cmd->cmd, text) == cmd->cmd)) {
+ cmd_text = strdup(cmd->cmd);
+ cmd++;
+ break;
+ }
+ cmd++;
+ }
+
+ return cmd_text;
+}
+
+char *
+mpiosh_readline_comp_mpio_file(const char *text, int state)
+{
+ static BYTE *p;
+ char *arg = NULL;
+ BYTE month, day, hour, minute;
+ char fname[100];
+ WORD year;
+ DWORD fsize;
+
+ if (state == 0) p = mpio_directory_open(mpiosh.dev, mpiosh.card);
+
+ while ((p != NULL) && (arg == NULL)) {
+ memset(fname, '\0', 100);
+
+ mpio_dentry_get(mpiosh.dev, mpiosh.card, p,
+ fname, 100,
+ &year, &month, &day,
+ &hour, &minute, &fsize);
+
+ if (strstr(fname, text) == fname) {
+ arg = strdup(fname);
+ if (strchr(arg, ' ')) {
+ rl_filename_completion_desired = 1;
+ rl_filename_quoting_desired = 1;
+ }
+ }
+
+ p = mpio_dentry_next(mpiosh.dev, mpiosh.card, p);
+ }
+
+
+ return arg;
+}
+
+char **
+mpiosh_readline_completion(const char *text, int start, int end)
+{
+ char **matches = (char**)NULL;
+
+ UNUSED(end);
+
+ if (start == 0) /* command completion */
+ matches = rl_completion_matches(text, mpiosh_readline_comp_cmd);
+ else {
+ mpiosh_cmd_t *scmd;
+ char *cmd, *help= rl_line_buffer;
+
+ while (*help != ' ') help++;
+ cmd = malloc(help - rl_line_buffer + 1);
+ strncpy(cmd, rl_line_buffer, help - rl_line_buffer + 1);
+ cmd[help - rl_line_buffer] = '\0';
+
+ if ((scmd = mpiosh_command_find(cmd))) {
+ if (scmd->comp_func) {
+ matches = rl_completion_matches(text, scmd->comp_func);
+ }
+ }
+
+ free(cmd);
+ }
+
+ return matches;
+}
+
+int
+mpiosh_readline_cancel(void)
+{
+ if (mpiosh_cancel) rl_done = 1;
+
+ return 0;
+}
+
+void
+mpiosh_readline_noredisplay(void)
+{
+}
+
+void
+mpiosh_readline_pipe(void)
+{
+ rl_redisplay_function = mpiosh_readline_noredisplay;
+ rl_event_hook = NULL;
+}
+
+/* end of readline.c */
diff --git a/mpiosh/readline.h b/mpiosh/readline.h
new file mode 100644
index 0000000..4c04f64
--- /dev/null
+++ b/mpiosh/readline.h
@@ -0,0 +1,45 @@
+/* readline.h
+ *
+ * Author: Andreas Büsching <crunchy@tzi.de>
+ *
+ * $Id: readline.h,v 1.1 2002/10/12 18:31:45 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_READLINE_HH
+#define MPIOSH_READLINE_HH
+
+#include <stdio.h>
+
+#include <readline/readline.h>
+#include <readline/history.h>
+
+/* readline extensions */
+void mpiosh_readline_init(void);
+char **mpiosh_readline_completion(const char *text, int start, int end);
+
+void mpiosh_readline_noredisplay(void);
+void mpiosh_readline_pipe(void);
+int mpiosh_readline_cancel(void);
+
+char *mpiosh_readline_comp_cmd(const char *text, int state);
+char *mpiosh_readline_comp_mpio_file(const char *text, int state);
+
+#endif
+
+/* end of readline.h */