From 6dd2081f944069b723714e5662c20a208f61ea1a Mon Sep 17 00:00:00 2001 From: crunchy Date: Wed, 4 Sep 2002 07:55:08 +0000 Subject: added mput, mget (UNTESTED) and removed compiler warnings --- mpio_tool/mpiosh.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++--- mpio_tool/mpiosh.h | 4 ++- 2 files changed, 99 insertions(+), 5 deletions(-) (limited to 'mpio_tool') diff --git a/mpio_tool/mpiosh.c b/mpio_tool/mpiosh.c index f424509..29f92d5 100644 --- a/mpio_tool/mpiosh.c +++ b/mpio_tool/mpiosh.c @@ -2,7 +2,7 @@ /* * - * $Id: mpiosh.c,v 1.3 2002/09/01 18:27:49 crunchy Exp $ + * $Id: mpiosh.c,v 1.4 2002/09/04 07:55:08 crunchy Exp $ * * Author: Andreas Büsching * @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -56,7 +57,9 @@ static mpiosh_cmd_t commands[] = { { "quit", mpiosh_cmd_quit, NO }, { "exit", mpiosh_cmd_quit, NO }, { "get", mpiosh_cmd_get, YES }, + { "mget", mpiosh_cmd_mget, YES }, { "put", mpiosh_cmd_put, YES }, + { "mput", mpiosh_cmd_mput, YES }, { "del", mpiosh_cmd_del, YES }, { "dump", mpiosh_cmd_dump, NO }, { "free", mpiosh_cmd_free, NO }, @@ -302,8 +305,14 @@ mpiosh_cmd_help(char *args[]) " display amount of available bytes of current memory card\n"); printf("put \n" " write to memory card\n"); + printf("mput \n" + " write all local files matching the regular expression\n" + " to the selected memory card\n"); printf("get \n" " read from memory card\n"); + printf("mput \n" + " read all files matching the regular expression\n" + " from the selected memory card\n"); printf("del \n" " deletes from memory card\n"); printf("exit, quit\n" @@ -471,6 +480,49 @@ mpiosh_cmd_get(char *args[]) printf("\n"); } +void +mpiosh_cmd_mget(char *args[]) +{ + BYTE * p; + int size, i = 0; + regex_t regex; + BYTE fname[100]; + BYTE month, day, hour, minute; + WORD year; + DWORD fsize; + + if (mpiosh.dev == NULL) { + printf("connection to MPIO player already closed\n"); + return; + } + + if (args[0] == NULL) { + printf("error: no argument given\n"); + return; + } + + while (args[i] != NULL) { + if (regcomp(®ex, args[i], REG_EXTENDED | REG_ICASE)) { + fprintf(stderr, "error in regular expression: %s\n", args[i]); + continue; + } + + p = mpio_directory_open(mpiosh.dev, mpiosh.card); + while (p != NULL) { + memset(fname, '\0', 100); + mpio_dentry_get(mpiosh.dev, p, fname, 100, + &year, &month, &day, &hour, &minute, &fsize); + + if (!regexec(®ex, fname, 0, NULL, 0)) { + size = mpio_file_get(mpiosh.dev, mpiosh.card, + fname, mpiosh_callback_put); + } + p = mpio_dentry_next(mpiosh.dev, p); + } + i++; + } +} + BYTE mpiosh_callback_put(int read, int total) { @@ -499,6 +551,46 @@ mpiosh_cmd_put(char *args[]) printf("\n"); } +void +mpiosh_cmd_mput(char *args[]) +{ + char dir_buf[NAME_MAX]; + int size, j, i = 0; + struct dirent ** dentry, **run; + + regex_t regex; + if (mpiosh.dev == NULL) { + printf("connection to MPIO player already closed\n"); + return; + } + + if (args[0] == NULL) { + printf("error: no argument given\n"); + return; + } + + getcwd(dir_buf, NAME_MAX); + while (args[i] != NULL) { + if (regcomp(®ex, args[i], REG_EXTENDED | REG_ICASE)) { + fprintf(stderr, "error in regular expression: %s\n", args[i]); + continue; + } + + if ((size = scandir(dir_buf, &dentry, NULL, alphasort)) != -1) { + run = dentry; + for (j = 0; j < size; j++, run++) { + if (!regexec(®ex, (*run)->d_name, 0, NULL, 0)) { + size = mpio_file_put(mpiosh.dev, mpiosh.card, + (*run)->d_name, mpiosh_callback_put); + } + free(*run); + } + free(dentry); + } + i++; + } +} + BYTE mpiosh_callback_del(int read, int total) { @@ -637,7 +729,7 @@ mpiosh_cmd_ldir(char *args[]) getcwd(dir_buf, NAME_MAX); if (dir_buf != '\0') { if ((count = scandir(dir_buf, &dentry, NULL, alphasort)) != -1) { - int j, i, len = 0; + int j, i; struct stat st; struct passwd * pwd; struct group * grp; @@ -660,8 +752,8 @@ mpiosh_cmd_ldir(char *args[]) pwd = getpwuid(st.st_uid); grp = getgrgid(st.st_gid); strftime(time, 12, "%b %2d", localtime(&(st.st_mtime))); - printf("%s %08s %08s %8d %10s %s\n", - rights, pwd->pw_name, grp->gr_name, st.st_size, + printf("%s %8s %8s %8d %10s %s\n", + rights, pwd->pw_name, grp->gr_name, (int)st.st_size, time, (*run)->d_name); free(*run); diff --git a/mpio_tool/mpiosh.h b/mpio_tool/mpiosh.h index c3d550a..9f9b297 100644 --- a/mpio_tool/mpiosh.h +++ b/mpio_tool/mpiosh.h @@ -2,7 +2,7 @@ * * Author: Andreas Büsching * - * $Id: mpiosh.h,v 1.3 2002/09/01 18:27:49 crunchy Exp $ + * $Id: mpiosh.h,v 1.4 2002/09/04 07:55:08 crunchy Exp $ * * Copyright (C) 2002 Andreas Büsching * @@ -72,7 +72,9 @@ void mpiosh_cmd_open(char *args[]); void mpiosh_cmd_close(char *args[]); void mpiosh_cmd_quit(char *args[]); void mpiosh_cmd_get(char *args[]); +void mpiosh_cmd_mget(char *args[]); void mpiosh_cmd_put(char *args[]); +void mpiosh_cmd_mput(char *args[]); void mpiosh_cmd_del(char *args[]); void mpiosh_cmd_dump(char *args[]); void mpiosh_cmd_free(char *args[]); -- cgit v1.2.3