From 690c9e245e451dfd9723fd2dd86bac999228b4c9 Mon Sep 17 00:00:00 2001 From: crunchy Date: Fri, 13 Sep 2002 15:20:23 +0000 Subject: better signal handling, new command lpwd --- mpiosh/callback.c | 69 +++++++++++++++++++++++++++++++++++++++++++++---------- mpiosh/callback.h | 3 ++- mpiosh/mpiosh.c | 34 +++++++++++++++++++++------ mpiosh/mpiosh.h | 8 +++++-- 4 files changed, 92 insertions(+), 22 deletions(-) (limited to 'mpiosh') diff --git a/mpiosh/callback.c b/mpiosh/callback.c index b84dea1..020b03f 100644 --- a/mpiosh/callback.c +++ b/mpiosh/callback.c @@ -2,7 +2,7 @@ * * Author: Andreas Büsching * - * $Id: callback.c,v 1.2 2002/09/13 13:07:06 germeier Exp $ + * $Id: callback.c,v 1.3 2002/09/13 15:20:25 crunchy Exp $ * * Copyright (C) 2001 Andreas Büsching * @@ -76,19 +76,34 @@ void mpiosh_cmd_help(char *args[]) { mpiosh_cmd_t *cmd = commands; + int ignore; - UNUSED(args); - while (cmd->cmd) { - printf("%s", cmd->cmd); - if (cmd->args) - printf(" %s\n", cmd->args); - else - printf("\n"); - if (cmd->info) - printf(" %s\n", cmd->info); - else - printf("\n"); + if (args[0] != NULL) { + char ** walk = args; + ignore = 1; + + while(*walk) { + if (!strcmp(*walk, cmd->cmd)) { + ignore = 0; + break; + } + walk++; + } + } else + ignore = 0; + + if (!ignore) { + printf("%s", cmd->cmd); + if (cmd->args) + printf(" %s\n", cmd->args); + else + printf("\n"); + if (cmd->info) + printf(" %s\n", cmd->info); + else + printf("\n"); + } cmd++; } } @@ -206,6 +221,12 @@ mpiosh_callback_get(int read, int total) { printf("\rretrieved %.2f %%", ((double) read / total) * 100.0 ); fflush(stdout); + + if (mpiosh_cancel) { + mpiosh_cancel = 0; + return 1; + } + return 0; // continue } @@ -271,6 +292,12 @@ mpiosh_callback_put(int read, int total) { printf("\rwrote %.2f %%", ((double) read / total) * 100.0 ); fflush(stdout); + + if (mpiosh_cancel) { + mpiosh_cancel = 0; + return 1; + } + return 0; // continue } @@ -339,6 +366,12 @@ mpiosh_callback_del(int read, int total) { printf("\rdeleted %.2f %%", ((double) read / total) * 100.0 ); fflush(stdout); + + if (mpiosh_cancel) { + mpiosh_cancel = 0; + return 1; + } + return 0; // continue } @@ -539,6 +572,18 @@ mpiosh_cmd_ldir(char *args[]) } } +void +mpiosh_cmd_lpwd(char *args[]) +{ + char dir_buf[NAME_MAX]; + + UNUSED(args); + + getcwd(dir_buf, NAME_MAX); + + printf("%s\n", dir_buf); +} + void mpiosh_cmd_lcd(char *args[]) { diff --git a/mpiosh/callback.h b/mpiosh/callback.h index 4a0f79e..622ab00 100644 --- a/mpiosh/callback.h +++ b/mpiosh/callback.h @@ -2,7 +2,7 @@ * * Author: Andreas Büsching * - * $Id: callback.h,v 1.1 2002/09/13 06:59:38 crunchy Exp $ + * $Id: callback.h,v 1.2 2002/09/13 15:20:25 crunchy Exp $ * * Copyright (C) 2001 Andreas Büsching * @@ -49,6 +49,7 @@ void mpiosh_cmd_switch(char *args[]); /* local command callbacks */ void mpiosh_cmd_ldir(char *args[]); +void mpiosh_cmd_lpwd(char *args[]); void mpiosh_cmd_lcd(char *args[]); void mpiosh_cmd_lmkdir(char *args[]); diff --git a/mpiosh/mpiosh.c b/mpiosh/mpiosh.c index 3b725d0..2db4e16 100644 --- a/mpiosh/mpiosh.c +++ b/mpiosh/mpiosh.c @@ -2,7 +2,7 @@ /* * - * $Id: mpiosh.c,v 1.2 2002/09/13 07:00:46 crunchy Exp $ + * $Id: mpiosh.c,v 1.3 2002/09/13 15:20:25 crunchy Exp $ * * Author: Andreas Büsching * @@ -39,8 +39,13 @@ #include "callback.h" #include "mpiosh.h" +/* structure containing current state */ mpiosh_t mpiosh; +/* flag indicating a user-interrupt of the current command */ +int mpiosh_cancel = 0; + +/* prompt strings */ const char *PROMPT_INT = "\033[;1mmpio \033[m "; const char *PROMPT_EXT = "\033[;1mmpio \033[m "; @@ -51,8 +56,8 @@ mpiosh_cmd_t commands[] = { { "ver", NULL, "version of mpio package", mpiosh_cmd_version }, - { "help", NULL, - "show known commands", + { "help", "[]", + "show information about known commands or just about ", mpiosh_cmd_help }, { "dir", NULL, "list content of current memory card", @@ -110,6 +115,9 @@ mpiosh_cmd_t commands[] = { { "ldir", NULL, "list local directory", mpiosh_cmd_ldir }, + { "lpwd", NULL, + "print current working directory", + mpiosh_cmd_lpwd }, { "lcd", NULL, "change the current working directory", mpiosh_cmd_lcd }, @@ -325,12 +333,19 @@ mpiosh_command_free_args(char **args) free(args); } +void +mpiosh_signal_handler(int signal) +{ + debug("user abort!\n"); + mpiosh_cancel = 1; +} int main(int argc, char *argv[]) { - char * line; - char ** cmds, **walk; - mpiosh_cmd_t *cmd; + char * line; + char ** cmds, **walk; + mpiosh_cmd_t * cmd; + struct sigaction sigc; UNUSED(argc); UNUSED(argv); @@ -339,7 +354,12 @@ main(int argc, char *argv[]) { setenv("mpio_color", "", 0); /* no unwanted interruption anymore */ - signal(SIGINT, SIG_IGN); + sigc.sa_handler = mpiosh_signal_handler; + sigc.sa_flags = SA_NOMASK; + + sigaction(SIGINT, &sigc, NULL); + +/* signal(SIGINT, SIG_IGN); */ /* init readline and history */ rl_readline_name = "mpio"; diff --git a/mpiosh/mpiosh.h b/mpiosh/mpiosh.h index a26c911..c6e8755 100644 --- a/mpiosh/mpiosh.h +++ b/mpiosh/mpiosh.h @@ -2,7 +2,7 @@ * * Author: Andreas Büsching * - * $Id: mpiosh.h,v 1.2 2002/09/13 07:00:46 crunchy Exp $ + * $Id: mpiosh.h,v 1.3 2002/09/13 15:20:25 crunchy Exp $ * * Copyright (C) 2002 Andreas Büsching * @@ -39,6 +39,9 @@ typedef struct { cmd_callback func; } mpiosh_cmd_t; +/* signal handler */ +void mpiosh_signal_handler(int signal); + /* readline extensions */ void mpiosh_readline_init(void); char **mpiosh_readline_completion(const char *text, int start, int end); @@ -51,9 +54,10 @@ char **mpiosh_command_split(char *line); char **mpiosh_command_get_args(char *line); void mpiosh_command_free_args(char **args); -/* global structure for device information */ +/* global structures */ extern mpiosh_t mpiosh; extern mpiosh_cmd_t commands[]; +extern int mpiosh_cancel; extern const char *PROMPT_INT; extern const char *PROMPT_EXT; -- cgit v1.2.3