aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrunchy <crunchy>2002-09-13 19:06:29 +0000
committercrunchy <crunchy>2002-09-13 19:06:29 +0000
commitc74b3cb41e5498ed863325fa060f5a1f2d1902d0 (patch)
tree6a2e57ad570fcda24fc938f22ccad0c25442a47f
parent0dd441fe0f1942a3bd8e21339f331c63ed9e7ecf (diff)
downloadmpiosh-c74b3cb41e5498ed863325fa060f5a1f2d1902d0.tar.gz
mpiosh-c74b3cb41e5498ed863325fa060f5a1f2d1902d0.tar.bz2
mpiosh-c74b3cb41e5498ed863325fa060f5a1f2d1902d0.zip
extended handling of SIGINT; support for stdin being a tty
-rw-r--r--ChangeLog5
-rw-r--r--mpiosh/callback.c30
-rw-r--r--mpiosh/mpiosh.c21
3 files changed, 31 insertions, 25 deletions
diff --git a/ChangeLog b/ChangeLog
index a9e74ce..028a672 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,11 @@
2002-09-13 Andreas Buesching <crunchy@tzi.de>
+ * mpiosh/callback.c (mpiosh_callback_mget, mpiosh_callback_mput)
+ (mpiosh_callback_mdel): handling of user interrupt
+
+ * mpiosh/mpiosh.c: handling for stdin being a tty
+
* mpiosh/callback.c (mpiosh_callback_get, mpiosh_callback_put)
(mpiosh_callback_del): using mpiosh_cancel to abort operation
diff --git a/mpiosh/callback.c b/mpiosh/callback.c
index 020b03f..deaec72 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.3 2002/09/13 15:20:25 crunchy Exp $
+ * $Id: callback.c,v 1.4 2002/09/13 19:06:30 crunchy Exp $
*
* Copyright (C) 2001 Andreas Büsching <crunchy@tzi.de>
*
@@ -222,12 +222,7 @@ 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
+ return mpiosh_cancel; // continue
}
void
@@ -274,6 +269,7 @@ mpiosh_cmd_mget(char *args[])
printf("getting '%s' ... \n", fname);
size = mpio_file_get(mpiosh.dev, mpiosh.card,
fname, mpiosh_callback_put);
+ if (mpiosh_cancel) break;
printf("\n");
} else {
regerror(error, &regex, errortext, 100);
@@ -285,6 +281,8 @@ mpiosh_cmd_mget(char *args[])
}
i++;
}
+
+ regfree(&regex);
}
BYTE
@@ -293,12 +291,7 @@ 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
+ return mpiosh_cancel; // continue
}
void
@@ -343,6 +336,7 @@ mpiosh_cmd_mput(char *args[])
printf("putting '%s' ... \n", (*run)->d_name);
fsize = mpio_file_put(mpiosh.dev, mpiosh.card,
(*run)->d_name, mpiosh_callback_put);
+ if (mpiosh_cancel) break;
printf("\n");
written=1; /* we did write something, so do mpio_sync afterwards */
} else {
@@ -357,6 +351,7 @@ mpiosh_cmd_mput(char *args[])
}
i++;
}
+ regfree(&regex);
if (written)
mpio_sync(mpiosh.dev, mpiosh.card);
}
@@ -367,12 +362,7 @@ 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
+ return mpiosh_cancel; // continue
}
void
@@ -421,6 +411,7 @@ mpiosh_cmd_mdel(char *args[])
printf("deleting '%s' ... \n", fname);
size = mpio_file_del(mpiosh.dev, mpiosh.card,
fname, mpiosh_callback_del);
+ if (mpiosh_cancel) break;
printf("\n");
deleted=1;
/* if we delete a file, start again from the beginning,
@@ -436,6 +427,7 @@ mpiosh_cmd_mdel(char *args[])
}
i++;
}
+ regfree(&regex);
if (deleted)
mpio_sync(mpiosh.dev, mpiosh.card);
}
diff --git a/mpiosh/mpiosh.c b/mpiosh/mpiosh.c
index 2db4e16..3bcf6d4 100644
--- a/mpiosh/mpiosh.c
+++ b/mpiosh/mpiosh.c
@@ -2,7 +2,7 @@
/*
*
- * $Id: mpiosh.c,v 1.3 2002/09/13 15:20:25 crunchy Exp $
+ * $Id: mpiosh.c,v 1.4 2002/09/13 19:06:30 crunchy Exp $
*
* Author: Andreas Büsching <crunchy@tzi.de>
*
@@ -346,6 +346,7 @@ main(int argc, char *argv[]) {
char ** cmds, **walk;
mpiosh_cmd_t * cmd;
struct sigaction sigc;
+ int interactive = 1;
UNUSED(argc);
UNUSED(argv);
@@ -371,18 +372,23 @@ main(int argc, char *argv[]) {
mpiosh_init();
mpiosh.dev = mpio_init();
- if (!mpiosh.dev) {
- printf("could not find MPIO player.\n");
- }
-
if (mpiosh.card == MPIO_INTERNAL_MEM)
mpiosh.prompt = PROMPT_INT;
else
mpiosh.prompt = PROMPT_EXT;
+ if (!isatty(fileno(stdin))) {
+ interactive = 0;
+ mpiosh.prompt = NULL;
+ }
+
+ if (!mpiosh.dev && interactive) {
+ printf("could not find MPIO player.\n");
+ }
+
while ((line = readline(mpiosh.prompt))) {
if (*line == '\0') continue;
-
+
cmds = mpiosh_command_split(line);
if (cmds[0][0] == '\0') {
@@ -411,6 +417,9 @@ main(int argc, char *argv[]) {
walk++;
}
free(cmds);
+
+ /* reset abort state */
+ mpiosh_cancel = 0;
}
mpiosh_cmd_quit(NULL);