aboutsummaryrefslogtreecommitdiff
path: root/mpio_tool
diff options
context:
space:
mode:
authorsalmoon <salmoon>2002-08-28 16:10:44 +0000
committersalmoon <salmoon>2002-08-28 16:10:44 +0000
commit0d8d92cf4631f4a0a88fe04817d375f9e73408e4 (patch)
tree66c43b0aec21aaa2ea6643fe38b71fac12b91fe4 /mpio_tool
downloadmpiosh-0d8d92cf4631f4a0a88fe04817d375f9e73408e4.tar.gz
mpiosh-0d8d92cf4631f4a0a88fe04817d375f9e73408e4.tar.bz2
mpiosh-0d8d92cf4631f4a0a88fe04817d375f9e73408e4.zip
Initial revision
Diffstat (limited to 'mpio_tool')
-rw-r--r--mpio_tool/Makefile.am11
-rw-r--r--mpio_tool/Makefile.in340
-rw-r--r--mpio_tool/mpio_tool.c133
-rw-r--r--mpio_tool/mpiosh.c667
-rw-r--r--mpio_tool/mpiosh.h90
5 files changed, 1241 insertions, 0 deletions
diff --git a/mpio_tool/Makefile.am b/mpio_tool/Makefile.am
new file mode 100644
index 0000000..d57d84a
--- /dev/null
+++ b/mpio_tool/Makefile.am
@@ -0,0 +1,11 @@
+INCLUDES=-I..
+
+bin_PROGRAMS=mpio_tool mpiosh
+
+mpio_tool_SOURCES=mpio_tool.c
+mpio_tool_LDADD=../libmpio/libmpio.la
+
+mpiosh_SOURCES=mpiosh.c
+mpiosh_LDADD=../libmpio/libmpio.la -lreadline -lncurses
+
+noinst_HEADERS=mpiosh.h \ No newline at end of file
diff --git a/mpio_tool/Makefile.in b/mpio_tool/Makefile.in
new file mode 100644
index 0000000..2586bc4
--- /dev/null
+++ b/mpio_tool/Makefile.in
@@ -0,0 +1,340 @@
+# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
+
+# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+
+SHELL = @SHELL@
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+
+bindir = @bindir@
+sbindir = @sbindir@
+libexecdir = @libexecdir@
+datadir = @datadir@
+sysconfdir = @sysconfdir@
+sharedstatedir = @sharedstatedir@
+localstatedir = @localstatedir@
+libdir = @libdir@
+infodir = @infodir@
+mandir = @mandir@
+includedir = @includedir@
+oldincludedir = /usr/include
+
+DESTDIR =
+
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+
+top_builddir = ..
+
+ACLOCAL = @ACLOCAL@
+AUTOCONF = @AUTOCONF@
+AUTOMAKE = @AUTOMAKE@
+AUTOHEADER = @AUTOHEADER@
+
+INSTALL = @INSTALL@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+transform = @program_transform_name@
+
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_alias = @build_alias@
+build_triplet = @build@
+host_alias = @host_alias@
+host_triplet = @host@
+target_alias = @target_alias@
+target_triplet = @target@
+AS = @AS@
+CC = @CC@
+DLLTOOL = @DLLTOOL@
+ECHO = @ECHO@
+EXEEXT = @EXEEXT@
+HAVE_GETOPT_H = @HAVE_GETOPT_H@
+LIBTOOL = @LIBTOOL@
+LN_S = @LN_S@
+MAKEINFO = @MAKEINFO@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+RANLIB = @RANLIB@
+STRIP = @STRIP@
+VERSION = @VERSION@
+
+INCLUDES = -I..
+
+bin_PROGRAMS = mpio_tool mpiosh
+
+mpio_tool_SOURCES = mpio_tool.c
+mpio_tool_LDADD = ../libmpio/libmpio.la
+
+mpiosh_SOURCES = mpiosh.c
+mpiosh_LDADD = ../libmpio/libmpio.la -lreadline -lncurses
+
+noinst_HEADERS = mpiosh.h
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_CLEAN_FILES =
+bin_PROGRAMS = mpio_tool$(EXEEXT) mpiosh$(EXEEXT)
+PROGRAMS = $(bin_PROGRAMS)
+
+
+DEFS = @DEFS@ -I. -I$(srcdir)
+CPPFLAGS = @CPPFLAGS@
+LDFLAGS = @LDFLAGS@
+LIBS = @LIBS@
+mpio_tool_OBJECTS = mpio_tool.$(OBJEXT)
+mpio_tool_DEPENDENCIES = ../libmpio/libmpio.la
+mpio_tool_LDFLAGS =
+mpiosh_OBJECTS = mpiosh.$(OBJEXT)
+mpiosh_DEPENDENCIES = ../libmpio/libmpio.la
+mpiosh_LDFLAGS =
+CFLAGS = @CFLAGS@
+COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
+HEADERS = $(noinst_HEADERS)
+
+DIST_COMMON = Makefile.am Makefile.in
+
+
+DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
+
+TAR = gtar
+GZIP_ENV = --best
+SOURCES = $(mpio_tool_SOURCES) $(mpiosh_SOURCES)
+OBJECTS = $(mpio_tool_OBJECTS) $(mpiosh_OBJECTS)
+
+all: all-redirect
+.SUFFIXES:
+.SUFFIXES: .S .c .lo .o .obj .s
+$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
+ cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps mpio_tool/Makefile
+
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ cd $(top_builddir) \
+ && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
+
+
+mostlyclean-binPROGRAMS:
+
+clean-binPROGRAMS:
+ -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
+
+distclean-binPROGRAMS:
+
+maintainer-clean-binPROGRAMS:
+
+install-binPROGRAMS: $(bin_PROGRAMS)
+ @$(NORMAL_INSTALL)
+ $(mkinstalldirs) $(DESTDIR)$(bindir)
+ @list='$(bin_PROGRAMS)'; for p in $$list; do \
+ if test -f $$p; then \
+ echo " $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \
+ $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \
+ else :; fi; \
+ done
+
+uninstall-binPROGRAMS:
+ @$(NORMAL_UNINSTALL)
+ list='$(bin_PROGRAMS)'; for p in $$list; do \
+ rm -f $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \
+ done
+
+.c.o:
+ $(COMPILE) -c $<
+
+# FIXME: We should only use cygpath when building on Windows,
+# and only if it is available.
+.c.obj:
+ $(COMPILE) -c `cygpath -w $<`
+
+.s.o:
+ $(COMPILE) -c $<
+
+.S.o:
+ $(COMPILE) -c $<
+
+mostlyclean-compile:
+ -rm -f *.o core *.core
+ -rm -f *.$(OBJEXT)
+
+clean-compile:
+
+distclean-compile:
+ -rm -f *.tab.c
+
+maintainer-clean-compile:
+
+.c.lo:
+ $(LIBTOOL) --mode=compile $(COMPILE) -c $<
+
+.s.lo:
+ $(LIBTOOL) --mode=compile $(COMPILE) -c $<
+
+.S.lo:
+ $(LIBTOOL) --mode=compile $(COMPILE) -c $<
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+distclean-libtool:
+
+maintainer-clean-libtool:
+
+mpio_tool$(EXEEXT): $(mpio_tool_OBJECTS) $(mpio_tool_DEPENDENCIES)
+ @rm -f mpio_tool$(EXEEXT)
+ $(LINK) $(mpio_tool_LDFLAGS) $(mpio_tool_OBJECTS) $(mpio_tool_LDADD) $(LIBS)
+
+mpiosh$(EXEEXT): $(mpiosh_OBJECTS) $(mpiosh_DEPENDENCIES)
+ @rm -f mpiosh$(EXEEXT)
+ $(LINK) $(mpiosh_LDFLAGS) $(mpiosh_OBJECTS) $(mpiosh_LDADD) $(LIBS)
+
+tags: TAGS
+
+ID: $(HEADERS) $(SOURCES) $(LISP)
+ list='$(SOURCES) $(HEADERS)'; \
+ unique=`for i in $$list; do echo $$i; done | \
+ awk ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ here=`pwd` && cd $(srcdir) \
+ && mkid -f$$here/ID $$unique $(LISP)
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS)'; \
+ unique=`for i in $$list; do echo $$i; done | \
+ awk ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
+ || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
+
+mostlyclean-tags:
+
+clean-tags:
+
+distclean-tags:
+ -rm -f TAGS ID
+
+maintainer-clean-tags:
+
+distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
+
+subdir = mpio_tool
+
+distdir: $(DISTFILES)
+ @for file in $(DISTFILES); do \
+ d=$(srcdir); \
+ if test -d $$d/$$file; then \
+ cp -pr $$d/$$file $(distdir)/$$file; \
+ else \
+ test -f $(distdir)/$$file \
+ || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
+ || cp -p $$d/$$file $(distdir)/$$file || :; \
+ fi; \
+ done
+mpio_tool.o: mpio_tool.c ../libmpio/mpio.h ../libmpio/defs.h \
+ ../libmpio/debug.h
+mpiosh.o: mpiosh.c ../libmpio/debug.h ../libmpio/mpio.h \
+ ../libmpio/defs.h mpiosh.h
+
+info-am:
+info: info-am
+dvi-am:
+dvi: dvi-am
+check-am: all-am
+check: check-am
+installcheck-am:
+installcheck: installcheck-am
+install-exec-am: install-binPROGRAMS
+install-exec: install-exec-am
+
+install-data-am:
+install-data: install-data-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+install: install-am
+uninstall-am: uninstall-binPROGRAMS
+uninstall: uninstall-am
+all-am: Makefile $(PROGRAMS) $(HEADERS)
+all-redirect: all-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
+installdirs:
+ $(mkinstalldirs) $(DESTDIR)$(bindir)
+
+
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -rm -f Makefile $(CONFIG_CLEAN_FILES)
+ -rm -f config.cache config.log stamp-h stamp-h[0-9]*
+
+maintainer-clean-generic:
+mostlyclean-am: mostlyclean-binPROGRAMS mostlyclean-compile \
+ mostlyclean-libtool mostlyclean-tags \
+ mostlyclean-generic
+
+mostlyclean: mostlyclean-am
+
+clean-am: clean-binPROGRAMS clean-compile clean-libtool clean-tags \
+ clean-generic mostlyclean-am
+
+clean: clean-am
+
+distclean-am: distclean-binPROGRAMS distclean-compile distclean-libtool \
+ distclean-tags distclean-generic clean-am
+ -rm -f libtool
+
+distclean: distclean-am
+
+maintainer-clean-am: maintainer-clean-binPROGRAMS \
+ maintainer-clean-compile maintainer-clean-libtool \
+ maintainer-clean-tags maintainer-clean-generic \
+ distclean-am
+ @echo "This command is intended for maintainers to use;"
+ @echo "it deletes files that may require special tools to rebuild."
+
+maintainer-clean: maintainer-clean-am
+
+.PHONY: mostlyclean-binPROGRAMS distclean-binPROGRAMS clean-binPROGRAMS \
+maintainer-clean-binPROGRAMS uninstall-binPROGRAMS install-binPROGRAMS \
+mostlyclean-compile distclean-compile clean-compile \
+maintainer-clean-compile mostlyclean-libtool distclean-libtool \
+clean-libtool maintainer-clean-libtool tags mostlyclean-tags \
+distclean-tags clean-tags maintainer-clean-tags distdir info-am info \
+dvi-am dvi check check-am installcheck-am installcheck install-exec-am \
+install-exec install-data-am install-data install-am install \
+uninstall-am uninstall all-redirect all-am all installdirs \
+mostlyclean-generic distclean-generic clean-generic \
+maintainer-clean-generic clean mostlyclean distclean maintainer-clean
+
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/mpio_tool/mpio_tool.c b/mpio_tool/mpio_tool.c
new file mode 100644
index 0000000..c76bfa0
--- /dev/null
+++ b/mpio_tool/mpio_tool.c
@@ -0,0 +1,133 @@
+/* -*- linux-c -*- */
+
+/*
+ *
+ * $Id: mpio_tool.c,v 1.1 2002/08/28 16:10:51 salmoon Exp $
+ *
+ * Test tool for USB MPIO-*
+ *
+ * Markus Germeier (mager@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 of the
+ * License, 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+
+#include "libmpio/mpio.h"
+#include "libmpio/debug.h"
+
+#define FOOBAR (64*1024*1024)
+
+BYTE buffer[FOOBAR];
+BYTE *p, *q;
+
+mpio_t *test;
+
+BYTE callback(int, int);
+
+BYTE callback(int part, int total)
+{
+ UNUSED(part);
+ UNUSED(total);
+
+/* printf("a: %d\n", a); */
+ return 0;
+
+}
+
+
+
+int
+main(int argc, char *argv[]) {
+ int debug=1;
+ int size;
+ int free, mem;
+
+ WORD year;
+ BYTE month, day, hour, minute;
+ DWORD fsize;
+ BYTE fname[100];
+
+ size=0;
+
+ if (argc == 2) {
+ debug=atoi(argv[1]);
+ }
+
+
+ test = mpio_init();
+
+ if (!test) {
+ printf ("Error initializing MPIO library\n");
+ exit(1);
+ }
+
+ /* do stuff */
+
+ mem=mpio_memory_free(test, MPIO_INTERNAL_MEM, &free);
+ printf("\nInternal Memory (size: %dKB / avail: %dKB):\n", mem/1000, free);
+ p=mpio_directory_open(test, MPIO_INTERNAL_MEM);
+ while (p!=NULL) {
+
+ mpio_dentry_get(test, p,
+ fname, 100,
+ &year, &month, &day,
+ &hour, &minute, &fsize);
+
+ printf ("%02d.%02d.%04d %02d:%02d %9d - %s\n",
+ day, month, year, hour, minute, fsize, fname);
+
+ p=mpio_dentry_next(test, p);
+ }
+
+ if ((mem=mpio_memory_free(test, MPIO_EXTERNAL_MEM, &free))!=0) {
+
+ printf("\nExternal Memory (size: %dKB / avail: %dKB):\n", mem/1000, free);
+ p=mpio_directory_open(test, MPIO_EXTERNAL_MEM);
+ while (p!=NULL) {
+
+ mpio_dentry_get(test, p,
+ fname, 100,
+ &year, &month, &day,
+ &hour, &minute, &fsize);
+
+ printf ("%02d.%02d.%04d %02d:%02d %9d - %s\n",
+ day, month, year, hour, minute, fsize, fname);
+
+ p=mpio_dentry_next(test, p);
+ }
+ }else {
+ printf("\nNo external Memory available!\n");
+ }
+
+
+/* mpio_file_get(test, MPIO_EXTERNAL_MEM, "Alanis_Morissette_01_21_Things_simplemp3s.mp3", callback); */
+
+
+ mpio_close(test);
+
+ exit(0);
+}
+
+
diff --git a/mpio_tool/mpiosh.c b/mpio_tool/mpiosh.c
new file mode 100644
index 0000000..82709e5
--- /dev/null
+++ b/mpio_tool/mpiosh.c
@@ -0,0 +1,667 @@
+/* -*- linux-c -*- */
+
+/*
+ *
+ * $Id: mpiosh.c,v 1.1 2002/08/28 16:10:51 salmoon Exp $
+ *
+ * Author: Andreas Büsching <crunchy@tzi.de>
+ *
+ * mpiosh - user interface of the mpio library, providing access to
+ * some model of the MPIO mp3 players.
+ *
+ * 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 of the
+ * License, 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * */
+
+#include <signal.h>
+#include <stdio.h>
+
+#include <readline/readline.h>
+#include <readline/history.h>
+
+#include "libmpio/debug.h"
+#include "libmpio/mpio.h"
+
+#include "mpiosh.h"
+
+static mpiosh_t mpiosh;
+
+static mpiosh_cmd_t commands[] = {
+ { "debug", mpiosh_cmd_debug, YES },
+ { "ver", mpiosh_cmd_version, NO },
+ { "help", mpiosh_cmd_help, NO },
+ { "dir", mpiosh_cmd_dir, NO },
+ { "info", mpiosh_cmd_info, NO },
+ { "mem", mpiosh_cmd_mem, YES },
+ { "open", mpiosh_cmd_open, NO },
+ { "close", mpiosh_cmd_close, NO },
+ { "quit", mpiosh_cmd_quit, NO },
+ { "exit", mpiosh_cmd_quit, NO },
+ { "get", mpiosh_cmd_get, YES },
+ { "put", mpiosh_cmd_put, YES },
+ { "del", mpiosh_cmd_del, YES },
+ { "dump", mpiosh_cmd_dump, NO },
+ { "free", mpiosh_cmd_free, NO },
+ { "format", mpiosh_cmd_format, NO },
+ { "switch", mpiosh_cmd_switch, YES },
+ { NULL, NULL, NO }
+};
+
+/* readline extensaions */
+void
+mpiosh_readline_init(void)
+{
+ rl_readline_name = "mpio";
+ rl_attempted_completion_function = mpiosh_readline_completion;
+}
+
+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 = completion_matches(text, mpiosh_readline_comp_cmd);
+ else {
+
+ }
+
+ return matches;
+}
+
+/* helper functions */
+void
+mpiosh_init(void)
+{
+ mpiosh.dev = NULL;
+ mpiosh.card = MPIO_INTERNAL_MEM;
+ mpiosh.prompt = PROMPT_INT;
+}
+
+
+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;
+}
+
+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);
+}
+
+/* commands */
+void
+mpiosh_cmd_debug(char *args[])
+{
+ if (args[0] != NULL) {
+ if (!strcmp(args[0], "level")) {
+ debug_level(strtol(args[1], NULL, 0));
+ } else if (!strcmp(args[0], "file")) {
+ debug_file(args[1]);
+ } else if (!strcmp(args[0], "on")) {
+ if (debug_level_get() == -1)
+ debug_level(1);
+ else
+ fprintf(stderr, "debug already activated for level %d\n",
+ debug_level_get());
+ } else if (!strcmp(args[0], "off")) {
+ if (debug_level_get() == -1)
+ fprintf(stderr, "debug already deactivated\n");
+ else
+ debug_level(-1);
+ } else {
+ fprintf(stderr, "unknown debug command\n");
+ printf("debug [level|file|on|off] <value>\n");
+ }
+ } else {
+ fprintf(stderr, "error: no arguments given\n");
+ printf("debug [level|file|on|off] <value>\n");
+ }
+}
+
+void
+mpiosh_cmd_version(char *args[])
+{
+ UNUSED(args);
+
+ printf("MPIO shell %s\n\n", VERSION);
+}
+
+void
+mpiosh_cmd_help(char *args[])
+{
+ UNUSED(args);
+
+ printf("debug[level|file|on|off] <value>\n"
+ " modify debugging options\n");
+ printf("ver\n"
+ " version of mpio package\n");
+ printf("help\n"
+ " show known commands\n");
+ printf("info\n"
+ " show information about MPIO player\n");
+ printf("open\n"
+ " open connect to MPIO player\n");
+ printf("close\n"
+ " close connect to MPIO player\n");
+ printf("dev [i|e]\n"
+ " set current memory card. 'i' selects the internal and 'e'\n"
+ " selects the external memory card (smart media card)\n");
+ printf("dir\n"
+ " list content of current memory card\n");
+ printf("format\n"
+ " format current memory card\n");
+ printf("dump\n"
+ " get all files of current memory card\n");
+ printf("free\n"
+ " display amount of available bytes of current memory card\n");
+ printf("put <filename>\n"
+ " write <filename> to memory card\n");
+ printf("get <filename>\n"
+ " read <filename> from memory card\n");
+ printf("del <filename>\n"
+ " deletes <filename> from memory card\n");
+}
+
+void
+mpiosh_cmd_dir(char *args[])
+{
+ BYTE *p;
+ BYTE month, day, hour, minute;
+ BYTE fname[100];
+ WORD year;
+ DWORD fsize;
+
+ UNUSED(args);
+
+ if (mpiosh.dev == NULL) {
+ printf("open connection first!\n");
+ return;
+ }
+
+ 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);
+
+ printf ("%02d.%02d.%04d %02d:%02d %9d - %s\n",
+ day, month, year, hour, minute, fsize, fname);
+
+ p = mpio_dentry_next(mpiosh.dev, p);
+ }
+}
+
+void
+mpiosh_cmd_info(char *args[])
+{
+ mpio_info_t info;
+
+ UNUSED(args);
+
+ if (mpiosh.dev == NULL) {
+ printf("open connection first!\n");
+ return;
+ }
+
+ mpio_get_info(mpiosh.dev, &info);
+
+ printf("firmware %s\n", info.firmware_id);
+ printf(" version : %s\n", info.firmware_version);
+ printf(" date : %s\n", info.firmware_date);
+ printf("memory\n");
+ printf(" internal: %s\n", info.firmware_mem_internal);
+ printf(" external: %s\n", info.firmware_mem_external);
+}
+
+void
+mpiosh_cmd_mem(char *args[])
+{
+ if (mpiosh.dev == NULL) {
+ printf("open connection first!\n");
+ return;
+ }
+
+ if (args[0] == NULL) {
+ printf("error: no argument given.\n");
+ return;
+ }
+
+ if (!strcmp(args[0], "e")) {
+ mpiosh.card = MPIO_EXTERNAL_MEM;
+ mpiosh.prompt = PROMPT_EXT;
+ printf("external memory card is selected\n");
+ } else if (!strcmp(args[0], "i")) {
+ mpiosh.card = MPIO_INTERNAL_MEM;
+ mpiosh.prompt = PROMPT_INT;
+ printf("internal memory card is selected\n");
+ } else {
+ printf("can not select memory card '%s'\n", args[0]);
+ }
+}
+
+void
+mpiosh_cmd_open(char *args[])
+{
+ if (mpiosh.dev) {
+ printf("connection to MPIO player already opened\n");
+ return;
+ }
+
+ UNUSED(args);
+
+ mpiosh.dev = mpio_init();
+
+ if (mpiosh.dev == NULL)
+ printf("error: could not open connection MPIO player\n");
+ else
+ printf("connection to MPIO player is opened\n");
+}
+
+void
+mpiosh_cmd_close(char *args[])
+{
+ if (mpiosh.dev == NULL) {
+ printf("connection to MPIO player already closed\n");
+ return;
+ }
+
+ UNUSED(args);
+
+ mpio_close(mpiosh.dev);
+ mpiosh.dev = NULL;
+
+ printf("connection to MPIO player is closed\n");
+}
+
+void
+mpiosh_cmd_quit(char *args[])
+{
+ if (mpiosh.dev) {
+ printf("\nclosing connection to MPIO player\nHave a nice day\n");
+ mpio_close(mpiosh.dev);
+ }
+
+ UNUSED(args);
+
+ exit(0);
+}
+
+BYTE
+mpiosh_callback_get(int read, int total)
+{
+ printf("\rretrieved %.2f %%", ((double) read / total) * 100.0 );
+ fflush(stdout);
+ return 0; // continue
+}
+
+void
+mpiosh_cmd_get(char *args[])
+{
+ int size;
+
+ if (mpiosh.dev == NULL) {
+ printf("connection to MPIO player already closed\n");
+ return;
+ }
+
+ if (args[0] == NULL) {
+ printf("error: no argument given\n");
+ return;
+ }
+
+ size = mpio_file_get(mpiosh.dev, mpiosh.card, args[0], mpiosh_callback_get);
+
+ printf("\n");
+}
+
+BYTE
+mpiosh_callback_put(int read, int total)
+{
+ printf("\rwrote %.2f %%", ((double) read / total) * 100.0 );
+ fflush(stdout);
+ return 0; // continue
+}
+
+void
+mpiosh_cmd_put(char *args[])
+{
+ int size;
+
+ if (mpiosh.dev == NULL) {
+ printf("connection to MPIO player already closed\n");
+ return;
+ }
+
+ if (args[0] == NULL) {
+ printf("error: no argument given\n");
+ return;
+ }
+
+ size = mpio_file_put(mpiosh.dev, mpiosh.card, args[0], mpiosh_callback_put);
+
+ printf("\n");
+}
+
+BYTE
+mpiosh_callback_del(int read, int total)
+{
+ printf("\rdeleted %.2f %%", ((double) read / total) * 100.0 );
+ fflush(stdout);
+ return 0; // continue
+}
+
+void
+mpiosh_cmd_del(char *args[])
+{
+ int size;
+
+ if (mpiosh.dev == NULL) {
+ printf("connection to MPIO player already closed\n");
+ return;
+ }
+
+ if (args[0] == NULL) {
+ printf("error: no argument given\n");
+ return;
+ }
+
+ size = mpio_file_del(mpiosh.dev, mpiosh.card, args[0], mpiosh_callback_del);
+
+ printf("\n");
+}
+
+
+void
+mpiosh_cmd_dump(char *args[])
+{
+ BYTE *p;
+ BYTE month, day, hour, minute;
+ BYTE fname[100];
+ char *arg[2];
+ WORD year;
+ DWORD fsize;
+
+ if (mpiosh.dev == NULL) {
+ printf("open connection first!\n");
+ return;
+ }
+
+ UNUSED(args);
+
+ args[0] = fname;
+ args[1] = NULL;
+
+ 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);
+
+ printf("getting '%s' ... ", arg[0]);
+ mpiosh_cmd_get(arg);
+
+ p = mpio_dentry_next(mpiosh.dev, p);
+ }
+}
+
+void
+mpiosh_cmd_free(char *args[])
+{
+ int free, kbytes;
+
+ if (mpiosh.dev == NULL) {
+ printf("open connection first!\n");
+ return;
+ }
+
+ UNUSED(args);
+
+ kbytes = mpio_memory_free(mpiosh.dev, mpiosh.card, &free);
+
+ printf("%d KB of %d KB are available\n", free, kbytes);
+}
+
+BYTE
+mpiosh_callback_format(int read, int total)
+{
+ printf("\rformatted %.2f %%", ((double) read / total) * 100.0 );
+ fflush(stdout);
+ return 0; // continue
+}
+
+void
+mpiosh_cmd_format(char *args[])
+{
+ char answer[512];
+
+ if (mpiosh.dev == NULL) {
+ printf("open connection first!\n");
+ return;
+ }
+
+ UNUSED(args);
+
+ printf("This will destroy all tracks saved on the memory card. "
+ "Are you sure (y/n)? ");
+
+ fgets(answer, 511, stdin);
+
+ if (answer[0] == 'y' || answer[0] == 'Y') {
+ if (mpio_memory_format(mpiosh.dev, mpiosh.card,
+ mpiosh_callback_format) == -1)
+ printf("\nfailed\n");
+ else
+ printf("\n");
+ }
+}
+
+void
+mpiosh_cmd_switch(char *args[])
+{
+ if (mpiosh.dev == NULL) {
+ printf("open connection first!\n");
+ return;
+ }
+
+ UNUSED(args);
+}
+
+int
+main(int argc, char *argv[]) {
+ char * line;
+ mpiosh_cmd_t *cmd;
+
+ UNUSED(argc);
+ UNUSED(argv);
+
+ setenv("mpio_debug", "", 0);
+ setenv("mpio_color", "", 0);
+
+ /* no unwanted interruption anymore */
+ signal(SIGINT, SIG_IGN);
+
+ /* init readline and history */
+ rl_readline_name = "mpio";
+ using_history();
+
+ debug_init();
+ mpiosh_readline_init();
+
+ 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;
+
+ while ((line = readline(mpiosh.prompt))) {
+ if (*line == '\0') continue;
+
+ cmd = mpiosh_command_find(line);
+
+ if (cmd) {
+ char ** help, **args = mpiosh_command_get_args(line);
+ help = args;
+
+ cmd->func(args);
+ mpiosh_command_free_args(args);
+ } else
+ printf("unknown command: %s\n", line);
+
+ add_history(line);
+ }
+
+ mpiosh_cmd_quit(NULL);
+
+ return 0;
+}
+
+
diff --git a/mpio_tool/mpiosh.h b/mpio_tool/mpiosh.h
new file mode 100644
index 0000000..18e2feb
--- /dev/null
+++ b/mpio_tool/mpiosh.h
@@ -0,0 +1,90 @@
+/* mpiosh.h
+ *
+ * Author: Andreas Büsching <crunchy@tzi.de>
+ *
+ * $Id: mpiosh.h,v 1.1 2002/08/28 16:10:52 salmoon Exp $
+ *
+ * Copyright (C) 2002 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_H_
+#define _MPIOSH_H_
+
+#if !defined TRUE
+# define TRUE 1
+#endif
+
+#if !defined FALSE
+# define FALSE 1
+#endif
+
+typedef void(*cmd_callback)(char *args[]);
+typedef enum { NO, YES } bool;
+
+typedef struct {
+ mpio_t * dev;
+ mpio_mem_t card;
+ const char * prompt;
+} mpiosh_t;
+
+typedef struct {
+ char * cmd;
+ cmd_callback func;
+ bool args;
+} mpiosh_cmd_t;
+
+const char* PROMPT_INT = "\033[;1mmpio <i>\033[m ";
+const char* PROMPT_EXT = "\033[;1mmpio <e>\033[m ";
+
+/* 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);
+
+/* helper functions */
+void mpiosh_init(void);
+mpiosh_cmd_t *mpiosh_command_find(char *line);
+char **mpiosh_command_get_args(char *line);
+void mpiosh_command_free_args(char **args);
+
+/* command callbacks */
+void mpiosh_cmd_debug(char *args[]);
+void mpiosh_cmd_version(char *args[]);
+void mpiosh_cmd_help(char *args[]);
+void mpiosh_cmd_dir(char *args[]);
+void mpiosh_cmd_info(char *args[]);
+void mpiosh_cmd_mem(char *args[]);
+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_put(char *args[]);
+void mpiosh_cmd_del(char *args[]);
+void mpiosh_cmd_dump(char *args[]);
+void mpiosh_cmd_free(char *args[]);
+void mpiosh_cmd_format(char *args[]);
+void mpiosh_cmd_switch(char *args[]);
+
+/* progress callbacks */
+BYTE mpiosh_callback_get(int read, int total);
+BYTE mpiosh_callback_put(int read, int total);
+BYTE mpiosh_callback_del(int read, int total);
+BYTE mpiosh_callback_format(int read, int total);
+
+#endif // _MPIOSH_H_
+
+/* end of mpiosh.h */