From 619beb63a1748cd9ece96260bfb2e9484e52cb67 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sat, 9 May 2009 16:07:05 +0200 Subject: Cleanup Remove unused files, move mpiosh to src, ... --- CMakeLists.txt | 4 +- ChangeLog | 962 --------------------------------- INSTALL | 291 ---------- NEWS | 0 README | 79 +-- TODO | 47 -- contrib/mpioshrc | 7 + debian/README | 6 - debian/changelog | 5 - debian/control | 21 - debian/copyright | 24 - debian/docs | 5 - debian/libmpio-dev.install | 1 - debian/libmpio.install | 2 - debian/mpio-tools.install | 3 - debian/postinst | 42 -- debian/rules | 6 - etc/mpioshrc | 7 - hotplug/libmpio.in | 20 - hotplug/libmpio.usermap | 5 - libmpio/CMakeLists.txt | 10 +- libmpio/src/CMakeLists.txt | 9 + mkmpiodev | 24 - mpio.spec.in | 65 --- mpiosh/.gitignore | 2 - mpiosh/CMakeLists.txt | 15 - mpiosh/callback.c | 1273 -------------------------------------------- mpiosh/callback.h | 101 ---- mpiosh/cfg.c | 238 --------- mpiosh/cfg.h | 56 -- mpiosh/cfgio.c | 654 ----------------------- mpiosh/cfgio.h | 453 ---------------- mpiosh/command.c | 222 -------- mpiosh/command.h | 38 -- mpiosh/config.h.in | 9 - mpiosh/global.c | 159 ------ mpiosh/global.h | 68 --- mpiosh/mpiosh.c | 163 ------ mpiosh/mpiosh.h | 37 -- mpiosh/readline.c | 212 -------- mpiosh/readline.h | 47 -- src/.gitignore | 2 + src/CMakeLists.txt | 10 + src/callback.c | 1273 ++++++++++++++++++++++++++++++++++++++++++++ src/callback.h | 101 ++++ src/cfg.c | 238 +++++++++ src/cfg.h | 56 ++ src/cfgio.c | 654 +++++++++++++++++++++++ src/cfgio.h | 453 ++++++++++++++++ src/command.c | 222 ++++++++ src/command.h | 38 ++ src/config.h.in | 9 + src/global.c | 159 ++++++ src/global.h | 68 +++ src/mpiosh.c | 163 ++++++ src/mpiosh.h | 37 ++ src/readline.c | 212 ++++++++ src/readline.h | 47 ++ 58 files changed, 3762 insertions(+), 5372 deletions(-) delete mode 100644 ChangeLog delete mode 100644 INSTALL delete mode 100644 NEWS delete mode 100644 TODO create mode 100644 contrib/mpioshrc delete mode 100644 debian/README delete mode 100644 debian/changelog delete mode 100644 debian/control delete mode 100644 debian/copyright delete mode 100644 debian/docs delete mode 100644 debian/libmpio-dev.install delete mode 100644 debian/libmpio.install delete mode 100644 debian/mpio-tools.install delete mode 100644 debian/postinst delete mode 100755 debian/rules delete mode 100644 etc/mpioshrc delete mode 100755 hotplug/libmpio.in delete mode 100644 hotplug/libmpio.usermap create mode 100644 libmpio/src/CMakeLists.txt delete mode 100755 mkmpiodev delete mode 100644 mpio.spec.in delete mode 100644 mpiosh/.gitignore delete mode 100644 mpiosh/CMakeLists.txt delete mode 100644 mpiosh/callback.c delete mode 100644 mpiosh/callback.h delete mode 100644 mpiosh/cfg.c delete mode 100644 mpiosh/cfg.h delete mode 100644 mpiosh/cfgio.c delete mode 100644 mpiosh/cfgio.h delete mode 100644 mpiosh/command.c delete mode 100644 mpiosh/command.h delete mode 100644 mpiosh/config.h.in delete mode 100644 mpiosh/global.c delete mode 100644 mpiosh/global.h delete mode 100644 mpiosh/mpiosh.c delete mode 100644 mpiosh/mpiosh.h delete mode 100644 mpiosh/readline.c delete mode 100644 mpiosh/readline.h create mode 100644 src/.gitignore create mode 100644 src/CMakeLists.txt create mode 100644 src/callback.c create mode 100644 src/callback.h create mode 100644 src/cfg.c create mode 100644 src/cfg.h create mode 100644 src/cfgio.c create mode 100644 src/cfgio.h create mode 100644 src/command.c create mode 100644 src/command.h create mode 100644 src/config.h.in create mode 100644 src/global.c create mode 100644 src/global.h create mode 100644 src/mpiosh.c create mode 100644 src/mpiosh.h create mode 100644 src/readline.c create mode 100644 src/readline.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4149b10..193fa63 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required (VERSION 2.4) -set (PACKAGE mpiotools) +set (PACKAGE mpiosh) project (${PACKAGE} C) add_subdirectory (libmpio) -add_subdirectory (mpiosh) +add_subdirectory (src) diff --git a/ChangeLog b/ChangeLog deleted file mode 100644 index d841fe1..0000000 --- a/ChangeLog +++ /dev/null @@ -1,962 +0,0 @@ -2006-01-21 Markus Germeier - * changed version to 0.7.1-pre3 - * (hopefully) fixed signedness hell, - should fix problems with 64 bit machines - -2006-01-20 Markus Germeier - * fixed mpio.spec.in - -2005-04-20 Markus Germeier - * configure.in: - fix version check for libusb, use black list instead - -2004-05-31 Markus Germeier - * libmpio/src/mpio.c (mpio_init_external): - fixed stupid bugs - -2004-05-30 Markus Germeier - * added Roberts MMC code (step 1) - * fixed a FAT bug he found on the way - * Thanks and kudos to Robert! - -2004-05-30 Markus Germeier - * changed version to 0.7.1-pre2 - -2004-04-24 Markus Germeier - * further open/close fixes - -2004-04-23 Markus Germeier - * libmpio/src/mpio.c (mpio_close): - - fixed a stupid bug while closing the device - * don't dump core if internal memory is not available - -2004-04-23 Markus Germeier - * remove all files from CVS which can be automagically - generated by the build environment - -> this should fix the missing ".so" problem - and all other "inter-version" problems - (at least so I hope ;-) - -2004-04-19 Markus Germeier - * added hotplug infrastructure to the project - - defaults to root:root 0666 - - change with --with-{user,group,perm}= - - minor clean ups - * changed version to 0.7.1-pre1 - -2004-04-19 Markus Germeier - * libmpio/src/smartmedia.c: - libmpio/src/io.c: - fixed debug outputs and copyright notice - * removed "#ifdef HAVE_USB"s - libusb is mandatory now! - * added "#ifdef USE_KMODULE" - * removed noisy and misleading debug messages - -2004-03-25 Markus Germeier - * Don't BuildRequire libusb-devel because - it does not exist on SuSE 9.0 - -2004-03-24 Markus Germeier - * dummy entry! fixed CVS syncmail - * check latest Changelog entries! - -2004-03-24 Markus Germeier - * small build environment updates - * updated mpio.spec.in file - -2004-03-21 Markus Germeier - * fixed build environment - * kernel module is (finally) deprecated - * may be enabled "--with-kernel-module" - -2004-02-08 Markus Germeier - * added support for the new 128MB internal chip - reported by Karin. Thanks! - -2004-01-13 Markus Germeier - * Added FY200 informations which is reported to work - external memory is supposed to work with these changes - -2004-01-12 Markus Germeier - * libmpio/src/smartmedia.c (mpio_id2mem): - updated chip IDs which were reported quite some time ago - (sorry for the delay!) still very unsure what they are - -2003-10-19 Markus Germeier - * added some missing #ifdef HAVE_USB - to libmpio/src/io.c - -2003-10-19 Markus Germeier - * added support for the new internal chips - found in the new FL100 player - (this is supposed to mainly work, but - still has some issues) - * added support for libusb if the kernel - module is not available - (this needs root privilidges for the moment :-( ) - -2003-09-23 Markus Germeier - * libmpio/src/io.c (model2externalmem): added FY100 and VP-01 to - the list, the external memory of these is now supported. - (Thanks to John for providing the information!) - * libmpio/src/mpio.c (mpio_init_external): - minor change to possibly support card 16MB and below - -2003-09-22 Markus Germeier - * added Johns patch to support the VirginPulse - VP-01 player. (Thanks!) - * small fixes to John patch - * assumed the upcoming VP-02 is a FL100 clone - so updated the code accordingly - * small and dirty hack for '.' in firmware - release numbers - -2003-08-01 Markus Germeier - - * configure.in: bumped version to 0.7.0 - * today is "release day"! :-) - -2003-07-27 Andreas Buesching - - * mpiosh/callback.c (mpiosh_cmd_cd): checking argument. - NULL is replaced with "." - -2003-07-24 Markus Germeier - * detect new SmartMedia chips and report them - * added version to mpio_smartmedia_t - * libmpio/src/smartmedia.c (mpio_id2version): - added function - * spare area read of new chips should work now - * bumped version to 0.7.0RC2 - -2003-07-17 Markus Germeier - * libmpio/src/smartmedia.c (mpio_id2mem): - added non-standard SmartMedia chip ID, as reported by Andreas - -2003-07-15 Markus Germeier - * libmpio/src/directory.c (mpio_dentry_get_real): - follow up fix for the broken internal FAT fix - added FTYPE_BROKEN - * libmpio/src/directory.c (mpio_directory_make): - another follow up fix for the broken internal FAT fix - -2003-07-14 Markus Germeier - * libmpio/src/directory.c (mpio_dentry_get_startcluster): - fixed a bug Yury stumbled across - -2003-07-07 Markus Germeier - * libmpio/src/directory.c (mpio_dentry_filename_write): - fixed one of my "famous" 8.3 filename handling "fixes" :-( - -2003-07-01 Markus Germeier - * mpiosh/callback.c(mpiosh_ftyp2ascii): added function - * mpiosh/callback.c(mpiosh_cmd_dir): - * libmpio/src/directory.c (mpio_dentry_get_real): - return/display file type/tag for files from internal memory - (as requested by Markus) - -2003-06-27 Andreas Buesching - - * mpiosh/callback.c (mpiosh_cmd_backup): using the resolved backup - directory name as argument for mpio_file_get_as - (mpiosh_cmd_restore): same as above s/get/put/ - - * mpiosh/config.c (mpiosh_config_check_backup_dir): changed return - type to char *. returning the resolved backip directory name - -2003-06-27 Andreas Buesching - - * mpiosh/global.c: add CONFIG_BACKUP defining a user backup - directory. - (commands): add backup and restore command - - * libmpio/src/mpio.c (mpio_file_get_real): fix a bug. Unlink the - external file (not the internal) before writing it (is it really - necessary?). - - * mpiosh/callback.c (mpiosh_cmd_config): deactivated. - (mpiosh_cmd_backup): new function, which creates a backup of all - existing config files. - (mpiosh_cmd_restore): new function, which restores a backup. - - * mpiosh/config.c (mpiosh_config_check_backup_dir): new function - to check for the backup directory ~/.mpio/backup/. Optionally it - can be created. - -2003-06-26 Markus Germeier - * libmpio/src/mpio.c (mpio_file_exists): - added helper function - * mpiosh/callback.c (mpiosh_cmd_font_upload): - * libmpio/defs.h (MPIO_FONT_FON): added support for - font file - * mpiosh/callback.c (mpiosh_cmd_format): - restore font file if it existed before a format - -2003-06-18 Markus Germeier - * libmpio/Makefile.am (AM_LDFLAGS): - added variable to support API versioninging of libmpio - * missing: updated script - -2003-06-14 Markus Germeier - * libmpio/src/directory.c (mpio_dentry_filename_write): - added/fixed vfat 8.3 checksum to make "real" vfat - drivers happy - * configure.in: increased version to 0.7.0RC1 for upcoming - release - -2003-06-12 Markus Germeier - * libmpio/src/id3.c (mpio_id3_do): fixed debug output - * libmpio/src/ecc.c: fixed debug output - * libmpio/src/directory.c (mpio_dentry_get_startcluster): - fixed ugly bug which broke reading/deleting of files on - external memory (D'oh!) - -2003-06-06 Markus Germeier - * libmpio/src/io.c (model2externalmem): added model - FD100 for external memory support. - reported by Thorsten to work this way - -2003-05-19 Markus Germeier - * libmpio/src/mpio.c (mpio_file_put_real): - fixed strncat bug found by Sergey. Thanks! - -2003-04-30 Markus Germeier - * libmpio/src/ecc.c: cleaned up ECC code - -2003-04-29 Markus Germeier - * libmpio/src/ecc.c (mpio_ecc_256_check): - fix level for debug messages - -2003-04-27 Markus Germeier - * libmpio: fixed some C code "things" found with - "paranoia" CFLAGS settings - * libmpio: changed license from GPL to LGPL - -2003-04-21 Markus Germeier - - * libmpio/id3.c (mpio_id3_copy_tag): - remove trailing spaces as suggested by Thomas - * kernel/Makefile.am: - removed unnecessary -I$(INCLUDE) as spotted by Yury - -2003-04-20 Markus Germeier - - * libmpio/directory.c (mpio_dentry_filename_write): - split this function from mpio_dentry_put to make a rename easier - * libmpio/mpio.c (mpio_file_rename): - libmpio/directory.c (mpio_dentry_rename): - new functions - -2003-04-19 Markus Germeier - - * libmpio/id3.h: - libmpio/id3.c: added files to support ID3 rewriting - * libmpio/mpio.c (mpio_file_put_real): - add support for ID3 rewriting - * mplib/src/mplib_s.c: - small changes for MPIO use - * mpiosh/callback.c (mpiosh_cmd_id3, mpiosh_cmd_id3_format): - added function for commands "id3" and "id3_format" - * mpiosh/config.c (mpiosh_config_read): - add new config file options: - id3_rewriting [on|off] - id3_format - -2003-04-18 Markus Germeier - * integration of mplib 1.0.1 in source tree - * update build environment to use mplib if not - disabled manually - -2003-04-18 Markus Germeier - - * mpiosh/callback.c (mpiosh_cmd_health): - libmpio/mpio.c (mpio_health): new functions to report - health status of SmartMedia cards. - -2003-04-12 Markus Germeier - * small error messages changes - -2003-04-11 Markus Germeier - - * libmpio/directory.c (mpio_directory_make): - libmpio/mpio.c (mpio_file_put_real): - fix timestamp generation as suggested by Sebastian. Thanks! - (mpio_directory_is_empty,mpio_dentry_is_dir): - added functions - (mpio_dentry_put): another 8.3 generation fix, - special treatment for "MPIO RECORD" dir. - * mpiosh/callback.c (mpiosh_cmd_format): - mkdir "MPIO RECORD" dir if it existed before the format - -2003-04-07 Markus Germeier - * Mega-Update all over the place - initial support for directories - [BEWARE: this might have broken some things!!!] - -2003-04-06 Markus Germeier - - * libmpio/directory.c (mpio_dentry_put): Another 8.3 filename fix - This time: try to get the extension right for filenames with - more than one '.' - -2003-03-26 Markus Germeier - - * libmpio/mpio.c (mpio_file_put_real): - libmpio/fat.c (mpio_fatentry_new, mpio_fatentry_read): - Small fixes which try to support changes in internal FAT - structure (Not Tested!) - -2003-03-22 Markus Germeier - - * kernel/mpio.c (probe_mpio, write_mpio, read_mpio): - automagically find USB bulk endpoints and use them - -2003-03-15 Markus Germeier - - * libmpio/mpio.c (mpio_init_internal): detect up to four - internal memory chips - * libmpio/fat.c (mpio_fatentry_hw2entry, mpio_fatentry_entry2hw): - libmpio/io.c (mpio_io_block_delete_phys, mpio_io_spare_read): - changes to support four internal chips - -2003-03-14 Andreas Buesching - - * mpio.spec.in: - add mpio.h and defs.h to the rpm. - creating a devel rpm would be oversized - -2003-03-14 Markus Germeier - - * libmpio/directory.c (mpio_dentry_put): - fixed missing first char issue - -2003-03-13 Markus Germeier - - * trying to fix iconv UNICODE conversions on BIG_ENDIAN - machines (not sure about that one!) - -2003-03-11 Markus Germeier - - * libmpio/mpio.c (mpio_init): added code the recognize new MPIO - models (FD100/FL100/FY100), no idea how to handle them, yet! - -2003-03-08 Markus Germeier - - * mpio.spec.in, etc/Makefile.am: fixed packaging problems - * libmpio/mpio.c (mpio_init): re-added memset, this time at the - correct location - * mpiosh/callback.c (mpiosh_cmd_mem): removes warning messages - (this should hopefully work now ;-) - (mpiosh_cmd_dump): fixed core dump in "dump" command - -2003-02-21 - - * libmpio/directory.h, libmpio/directory.c, libmpio/mpio.h, - libmpio/mpio.c: add patch from Sebastian Kloska - . containing possibility to chage name of - destination when copying files, moving files and reordering files - in directory - -2002-12-06 - - * kernel/mpio.c: 2.4.20 does not contain the typedef purb_t - anymore. Replaced it with 'struct urb *' - -2002-11-18 Andreas Buesching - - * configure.in: add a check for readline header files - -2002-11-14 Andreas Buesching - - * tools/mpiologo.c: renamed logotool.c to mpiologo.c - - * mpio.spec.in (): another way to add the kernel module to - the file list; add mpiologo to file list - - -2002-11-13 Markus Germeier - - * mpiosh/callback.c (mpiosh_cmd_format): backup and restore - config files (probably not complete yet!) - * libmpio/defs.h (MPIO_CHARSET): - * libmpio/directory.c (mpio_dentry_put, mpio_dentry_get_real): - use ISO-8859-15 instead of ASCII as default charset encoding - (much nicer now!) - * libmpio/directory.c (mpio_charset_get, mpio_charset_set): - added functions to allow changing of charset - * mpiosh/config.c: read charset from config file - * libmpio/fat.c (mpio_fatentry_read): - fixed problem with CONFIG.DAT that only the first block - was read. (what was I thinking there??) - -2002-11-04 Andreas Buesching - - * mpiosh/callback.c (mpiosh_cmd_quit): writing configuration - including history und freeing config reader - - * mpiosh/global.c: modified filename for history - "~/.mpio/history" - - * mpiosh/config.c (mpiosh_config_new): reading history file - (mpiosh_config_write): saving current history - -2002-11-02 Yuji Touya - - * tools/logotool.c: add a tool to extract/change logo animation - data in config.dat file, and sample animation data. - -2002-11-01 Yuji Touya - - * kernel/mpio.c: Add usbdevfs filesystem support - -2002-10-29 Andreas Buesching - - * mpiosh/mpiosh.c (mpiosh_init): uses the new configuration file - support to initialise the shell - - * etc/mpio/mpioshrc: add a sample configuration file will be - install as a global configuration file in - @sysconfdir@/mpio/mpioshrc - - * mpiosh/cfgio.c, mpiosh/cfgio.c, mpiosh/config.c, - mpiosh/config.h: added these new files to support global and user - configuration files. - -2002-10-27 Markus Germeier - - * libmpio/mpio.{c,h}: split mpio_file_{get,put} into several - functions, to allow reading and writing files from/to memory - (needed for handling of config files) - * mpiosh/callback.c (mpiosh_cmd_channel): added function/command - channel to handle the radio channel of the *-Plus models - * libmpio/directory.c (mpio_dentry_put): - another fix for the 8.3 handling needed for the config file - (one day this will be bug free ...) - * mpiosh/callback.c (mpiosh_cmd_config): implement the function - * libmpio/directory.c (mpio_dentry_find_name_8_3): - another fix for the 8.3 handling needed for the config file - (GRR, one day ...) - * libmpio/mpio.c (mpio_get_model): added function - * mpiosh/callback.c (mpiosh_cmd_switch): implement the function - * libmpio/mpio.c (mpio_file_switch): added function - * mpiosh/callback.c (mpiosh_cmd_mget): added error message - * libmpio/mpio.c (mpio_file_put_real): - updates to support reading files into memory - -2002-10-26 Markus Germeier - - * libmpio/mpio.c (mpio_close): fixed segv - * libmpio/*.h: - make libmpio header files C++ compliant - -2002-10-23 Markus Germeier - - * libmpio/io.c (mpio_io_spare_read): fixed init progress counter - for models with two internal chips - -2002-10-18 Andreas Buesching - - * mpiosh/global.c (commands): add config command with no - functionality at the moment - (commands): removed completion for mpio files on the put command - -2002-10-14 Andreas Buesching - - * mpiosh/global.c (commands): reactivated switch command without - any functionality at the moment - -2002-10-18 Markus Germeier - - * libmpio/directory.c (mpio_dentry_get_real): - another fix for the 8.3 handling needed for the config file - -2002-10-13 Markus Germeier - - * mpiosh/callback.c (mpiosh_cmd_dump): fixed compile and - logic error due to now "missing" mpiosh_cmd_get - -2002-10-13 Andreas Buesching - - * mpiosh/callback.c: removed the callback functions of get, put - and del. This work is done by mget, mput and mdel now. - - * mpiosh/readline.c (mpiosh_readline_comp_mpio_file): fixed a - crash which ocurrs when there is no connection to the player - opened. Also stop readline from using default filename completion - in the case of not returning any results. - -2002-10-13 Markus Germeier - - * all operations on external memory should work now! - * libmpio/ecc.c (mpio_ecc_256_check): - 1 Bit errors are now automagically corrected - -2002-10-13 Markus Germeier - - * libmpio/mpio.c (mpio_init): fixed segv when external memory - was selected - * formatting of external memory is now completly supported - (untested ATM) - -2002-10-12 Andreas Buesching - - * configure.in: changed version to 0.6.0 for the next release; - add check for a usable path to the kernel header files - - * mpiosh/global.c (commands): removed commands 'put', 'get', 'del' - and 'exit' and add these to the alias lists of 'mput', 'mget', - 'mdel' and 'quit'. Also add some more aliases to some other - commands - - * mpiosh/readline.c (mpiosh_readline_comp_cmd): add aliases to - completion list - - * mpiosh/global.c (commands): use command completion for 'help' - arguments - - * mpiosh/global.h: add alias list to command struct - - * mpiosh/global.c: new file containing global symbols as the - command list - - * mpiosh/callback.c: fix compiler warnings - - * libmpio/mpio.c (mpio_memory_format): fixed compiler warning - - * mpiosh/readline.c: new file containing all stuff around the - readline library - (mpiosh_readline_comp_mpio_file): doing completion on files of the - current mpio memory card - (mpiosh_readline_init): inserted bug fix for the completion - quoting from Mathieu - -2002-10-05 Markus Germeier - * big changes to IO layer and updates to formating/writing - for external memory - * BEWARE: writing to external mem still does not work - and I might have damaged the internal support! - -2002-10-05 Markus Germeier - - * libmpio/cis.c: generate new CIS block for formatting - -2002-09-30 Markus Germeier - - * libmpio/mpio.c (mpio_init): fixed identification of - newer firmwares (e.g. DMG+) "MPIOxy" vs. "MPIO-xy" - thanks to mathieu for reporting this one. - -2002-09-28 Markus Germeier - - * kernel/Makefile.am (distclean): added target distclean - -2002-09-28 Markus Germeier - * a lot of changes! - * reading from external memory should work now correctly - * BEWARE: all write operations are still broken on external mem! - -2002-09-24 Markus Germeier - * libmpio/directory.c (mpio_dentry_put): fixed 8.3 handling - to allow correct writing of CONFIG.DAT - (mpio_dentry_find_name_8_3): fixed handling of given filename - * libmpio/mpio.c (mpio_file_del, mpio_file_get): - system files (like sysdum?.du?) can now be read and deleted - (mpio_file_put): use mpio_filetype_t to tag files which are - written to the internal memory (it is now possible to write - config files back to the player) - -2002-09-24 Markus Germeier - * a lot of little changes and updates - * mpiosh/callback.c (mpiosh_cmd_dump_mem): - renamed function from debug_memory to dump_memory - (mpiosh_callback_init): display progress of internal and - external memory - * libmpio/mpio.c (mpio_check_filename): added function - to check for string zero termination (more to check??) - (mpio_memory_dump): dump all relevant memory areas - (mpio_init): read spare area for external memory - * libmpio/defs.h: added mpio_callback_t, mpio_callback_init_t - and mpio_filename_t - -2002-09-22 Andreas Buesching - - * configure.in (SPEC_PATH): needed for the spec file to find the - kernel module - -2002-09-22 Markus Germeier - * mpiosh/callback.c (mpiosh_cmd_mdel): - fixed logical error in abort handling which corrupted - FAT and directory - (mpiosh_cmd_mget): call the correct callback function - (mpiosh_callback_put): introduced mpiosh_cancel_ack - to fix annoying displays in case of an abort - (mpiosh_cmd_mput): don't break mput if an FILE_EXITS - is encountered - -2002-09-21 Andreas Buesching - - * mpio.spec.in (CFLAGS): add 'depmod -a' call to post install - instructions - - * kernel/Makefile.am: add target clean and fixed the install - target to not strip the kernel module - -2002-09-21 Yuji Touya - - * README: Add a few lines about Hot plug for 2.4.x - -2002-09-20 Markus Germeier - - * libmpio/mpio.c (mpio_init): - added code to identify DMG+ (assumed, but should be correct) - - * mpiosh/callback.c (mpiosh_cmd_format, mpiosh_cmd_mem): - added warning messages for the upcoming release. - (mpiosh_cmd_get, mpiosh_cmd_put): added missing printf - -2002-09-20 Andreas Buesching - - * mpiosh/mpiosh.c (mpiosh_command_regex_fix): bug fix for .* - do not quote the '.' if next character is a '*' - - * libmpio/mpio.c (mpio_strerror): fixed stupid bug no - 23.423.543.453.453 (time to go to bed) - -2002-09-19 Andreas Buesching - - * libmpio/mpio.c (mpio_strerror): fixed a strange bug with the - argument name. Never call an argument errno?!? - -2002-09-19 Markus Germeier - - * mpiosh/callback.c (mpiosh_cmd_dump, mpiosh_cmd_mget) - (mpiosh_cmd_mdel, mpiosh_cmd_mput): fixed handling of an abort - * libmpio/mpio.c (MPIO_ERR_RETURN): fixed buggy define - - -2002-09-19 Andreas Buesching - - * mpiosh/mpiosh.c (mpiosh_command_regex_fix): hopefully fixed a - bug (Sorry Markus) - - * mpiosh/callback.c (mpiosh_cmd_mput): using new error handling - functions - - * libmpio/mpio.c (mpio_errno, mpio_strerror, mpio_perror): - add functions for error handling - (mpio_file_get, mpio_file_put, mpio_file_del): using error - handling functions - - -2002-09-19 Markus Germeier - - * libmpio/mpio.c (mpio_init_internal): - added code to check if the internal memory is available - (don't ask! :-) - (mpio_sync): check if selected memory is available - * mpiosh/callback.c (mpiosh_cmd_mem): - fixed external mem check - - -2002-09-18 Markus Germeier - - * mpiosh/callback.c (mpiosh_cmd_mem): - external memory is only selectable if it is available - * libmpio/mpio.c (mpio_init): added progress callback - for init - * mpiosh/callback.c (mpiosh_callback_init): - added function - * libmpio/io.c (cluster2block, cluster2blockaddress): - removed wrong block mapping - (current mapping should work with complete error - free SM cards _only_) - - -2002-09-18 Andreas Buesching - - * libmpio/mpio.c (mpio_file_get, mpio_file_put, mpio_file_del): - using new error codes - - * libmpio/defs.h (MPIO_ERR_*): added definitions for possible - errors codes - - * libmpio/mpio.c (mpio_model_name): moved model array from def.h; - removed some compiler warnings (unused variables, missing return - codes) - - * mpiosh/mpiosh.c (mpiosh_command_regex_fix): extented conditions - to not replace sequences like ".*" by "\\..*" - -2002-09-16 Andreas Buesching - - * kernel/Makefile.am (install-strip): defined to avoid stripping - of the kernel module - -2002-09-16 Yuji Touya - - * kernel/mpio.c: changed include file to resolve symbols - * kernel/mpio.c (read_mpio): changed maxretry value - * libmpio/io.c (model2externalmem): fixed function - * libmpio/defs.h: added command, filetype and comments - * README: modified "getting started" - -2002-09-15 Andreas Buesching - - * mpiosh/callback.c (mpiosh_cmd_ldir): checking more return values - to avoid segmentation faults. - - * mpiosh/mpiosh.c: removed all references to the not implemented - switch command (just for the next release) - - * configure.in (MODULE_PATH): checking for the right module - directory and use it to install the mpio module - - * kernel/Makefile.am (install): the kernel module is now installed - into the determinated module directory of the current kernel - version. - - * mpio.spec.in: created rpm spec file for creating binary and - source rpm packages - -2002-09-15 Markus Germeier - - * mpiosh/callback.c (mpiosh_cmd_debug_mem): added function - call "debug_memory" in mpiosh - * libmpio/io.c (model2externalmem): added function - (mpio_io_set_cmdpacket): use model2externalmem - * libmpio/mpio.c (mpio_init): added code to identify different - models - (mpio_memory_debug): added function for debugging purposes - -2002-09-15 Andreas Buesching - - * mpiosh/mpiosh.c: add a debug message, displaying the executed - command in script mode - (mpiosh_command_regex_fix): better mapping for shell regular - expressions (hopefully) - -2002-09-15 Markus Germeier - - * libmpio/directory.c: add debug informations, - (mpio_dentry_get): fixed a off-by-one error - - * libmpio/mpio.h: add mpio_mem_t to dentry functions - to enable further debugging - -2002-09-14 Andreas Buesching - - * mpiosh/mpiosh.c: does not hang anymore after reading commands - from a pipe - - * mpiosh/callback.c (mpiosh_callback_mget, mpiosh_callback_mput) - (mpiosh_callback_mdel): calling new function mpiosh_command_regex_fix - - * mpiosh/mpiosh.c: fixed output of none interactive mode - (mpiosh_signal_handler, mpiosh_readline_cancel) - (mpiosh_noredisplay): functions added to get a expected handling - of C-c (SIGINT) - (mpiosh_command_regex_fix): add function. tries to map regular - expressions to shell expressions. mapping '*' -> ".*" and '.' -> "\." - -2002-09-13 Markus Germeier - - * libmpio/mpio.c (mpio_file_put): fixed abort handling - -2002-09-13 Andreas Buesching - - * 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 - - * mpiosh/mpiosh.c: changed handling of SIGINT. The global variable - mpiosh_cancel indicates the interrupt. - - * mpiosh/callback.c (mpiosh_cmd_help): add support for - arguments. just prints help about specified commands. - - * mpiosh/mpiosh.c: add new command lpwd - -2002-09-13 Markus Germeier - - * mpiosh/callback.c (mpiosh_cmd_put, mpiosh_cmd_del) - (mpiosh_cmd_mdel, mpiosh_cmd_mput): use mpio_sync - - * libmpio/mpio.c (mpio_file_get, mpio_file_put) - (mpio_memory_format, mpio_file_del): add code to handle abort - "signal" from user interface - (mpio_sync): added function - -2002-09-12 Andreas Buesching - - * mpiosh/mpiosh.c (mpiosh_command_split): - function added to support command sequences separated by ';' - changed mpiosh_cmd_t structure, containing help string and - argument information - - * mpiosh/callback.h, mpiosh/callback.c (): - new files containing callback functions of shell commands - (MPIOSH_CHECK_CONNECTION_OPEN, MPIOSH_CHECK_CONNECTION_CLOSED) - (MPIOSH_CHECK_ARG): macros for checking status of connection to - player - -2002-09-11 Markus Germeier - - * libmpio/mpio.c (mpio_file_put,mpio_file_get): - set timestamps on files correct - * libmpio/directory.c (mpio_dentry_put): - write correct 8.3 filenames into directory - (mpio_dentry_put): - fixed handling of time stamps with a "little" help - from the current mtools distribution - (date_dos2unix): added function, copied from the linux - kernel - (mpio_dentry_get_time): added function, uses (date_dos2unix) - -2002-09-11 Markus Germeier - - * mpio_tool/mpiosh.c (mpiosh_cmd_mdel): added command mdel - -2002-09-11 Markus Germeier - - * libmpio/mpio.c (mpio_file_put): - finished support for writing to internal memory - + changes to fat.c and io.c - -2002-09-11 Markus Germeier - - * libmpio/io.c (cluster2blockaddress): added function - (mpio_io_block_write, mpio_io_sector_write): - fixed block address in spare area - (mpio_io_block_read): - check block address and give debug output if address differs - -2002-09-11 Markus Germeier - - * libmpio/mpio.c (mpio_file_put): (+ various files) - updated writing support to support mpio_fatentry_t - -2002-09-10 Markus Germeier - - * libmpio/io.c (mpio_io_block_write): - write FAT entry for internal mem - * libmpio/fat.c (mpio_fat_internal_find_fileindex): added function - -2002-09-10 Markus Germeier - - * libmpio/mpio.c (mpio_memory_format): - formatting works for internal and external memory now - BEWARE: No config files are written, you might ruin your - player!!! - * libmpio/mpio.c (mpio_file_del): - deleting works for internal and external memory now (BEWARE !!!) - * support for deleting/formatting added to various parts of - fat.c and io.c - -2002-09-10 Markus Germeier - - * libmpio/fat.c (mpio_fatentry_set_free) - (mpio_fatentry_set_defect): added functions - * libmpio/io.c (mpio_io_block_delete): - return negative status value in case of error - * libmpio/mpio.c (mpio_memory_format): - mark block/cluster defect in FAT if an error occurs during format - * libmpio/mpio.c (mpio_file_del): - changed function to support new mpio_fatentry_t - -2002-09-09 Markus Germeier - - * libmpio/io.c (fatentry2hw): added function - (mpio_io_block_read, mpio_io_block_delete): - use fatentry2hw - -2002-09-09 Markus Germeier - - * libmpio/mpio.c (mpio_memory_format): - updated code to format external SmartMedia cards - * libmpio/fat.c (mpio_fatentry_plus_plus, mpio_bootblocks_read): - fixed max_cluster issues - -2002-09-09 Markus Germeier - - * libmpio/io.c (cluster2block): - fixed cluster to block mapping for 32MB SmartMedia cards - * libmpio/io.c (mpio_io_block_read, mpio_io_sector_read): - added debug output in case of ECC error - * libmpio/mpio.c (mpio_memory_free): - fixed segmentation violation if no SM card is inserted - * libmpio/mpio.c (mpio_get_info): - *really* fixed the problem if no SM card is inserted - -2002-09-09 Markus Germeier - - * mpio_tool/mpiosh.c: - (mpiosh_cmd_mput): - (mpiosh_cmd_mget): - make info texts consistent with get and put - * libmpio/mpio.c (mpio_init_internal): - fixed max_clusters for internal memory with more - then one chip - * libmpio/fat.c (mpio_fatentry_hw2entry): added function - * libmpio/fat.c (mpio_fatentry_entry2hw): added function - * libmpio/fat.c: - fixed support for MPIOs with more than one internal chip - (hopefully, someone please test this) - -2002-09-08 Markus Germeier - - * mpio_tool/mpiosh.c: - (mpiosh_cmd_mput): fixed regex handling - (mpiosh_cmd_mget): fixed regex handling - * regex for mput/mget does now work but uses "hard" - regular expressions instead of shell-like regex, e.g.: - "^0.*\.mp3$" ("hard" regular expression) - "0*.mp3" (shell-like) - -2002-09-04 Andreas Buesching - - * mpio_tool/mpiosh.c (mpiosh_cmd_mput): - added command mput. The arguments can be extended regular - expressions. UNTESTED! - (mpiosh_cmd_ldir): removed compiler warnings - (mpiosh_cmd_mget): added command mget. The arguments can be - extended regular expressions. UNTESTED! - (mpiosh_cmd_help): updated help text - -2002-09-03 Markus Germeier - - * first part of "design" fixes - * libmpio: - - introduced mpio_fatentry_t - - reading support changed to mpio_fatentry_t - - writing and deleting deactivated - (this simply can't work right now) - -2002-09-03 Yuji Touya - - * add mkmpiodev script to create device file - * README: add explanation to get started - -2002-09-03 Markus Germeier - - * libmpio/*: various "little" code cleanups - -2002-09-01 Andreas Buesching - - * mpio_tool/mpiosh.c: add commands lcd and ldir - (mpiosh_cmd_dump): fixed a stupid bug - (mpiosh_cmd_ldir): implemented the command ldir - (mpiosh_cmd_lcd): implemented the command lcd - -2002-08-22 Andreas Buesching - * README: fixed soome types and add a warning - * AUTHORS: add salmoon to the list - -2002-08-05 Andreas Buesching - - * autogen.sh: add script to build configure script - diff --git a/INSTALL b/INSTALL deleted file mode 100644 index 8b82ade..0000000 --- a/INSTALL +++ /dev/null @@ -1,291 +0,0 @@ -Installation Instructions -************************* - -Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, -2006, 2007, 2008 Free Software Foundation, Inc. - - This file is free documentation; the Free Software Foundation gives -unlimited permission to copy, distribute and modify it. - -Basic Installation -================== - - Briefly, the shell commands `./configure; make; make install' should -configure, build, and install this package. The following -more-detailed instructions are generic; see the `README' file for -instructions specific to this package. - - The `configure' shell script attempts to guess correct values for -various system-dependent variables used during compilation. It uses -those values to create a `Makefile' in each directory of the package. -It may also create one or more `.h' files containing system-dependent -definitions. Finally, it creates a shell script `config.status' that -you can run in the future to recreate the current configuration, and a -file `config.log' containing compiler output (useful mainly for -debugging `configure'). - - It can also use an optional file (typically called `config.cache' -and enabled with `--cache-file=config.cache' or simply `-C') that saves -the results of its tests to speed up reconfiguring. Caching is -disabled by default to prevent problems with accidental use of stale -cache files. - - If you need to do unusual things to compile the package, please try -to figure out how `configure' could check whether to do them, and mail -diffs or instructions to the address given in the `README' so they can -be considered for the next release. If you are using the cache, and at -some point `config.cache' contains results you don't want to keep, you -may remove or edit it. - - The file `configure.ac' (or `configure.in') is used to create -`configure' by a program called `autoconf'. You need `configure.ac' if -you want to change it or regenerate `configure' using a newer version -of `autoconf'. - -The simplest way to compile this package is: - - 1. `cd' to the directory containing the package's source code and type - `./configure' to configure the package for your system. - - Running `configure' might take a while. While running, it prints - some messages telling which features it is checking for. - - 2. Type `make' to compile the package. - - 3. Optionally, type `make check' to run any self-tests that come with - the package. - - 4. Type `make install' to install the programs and any data files and - documentation. - - 5. You can remove the program binaries and object files from the - source code directory by typing `make clean'. To also remove the - files that `configure' created (so you can compile the package for - a different kind of computer), type `make distclean'. There is - also a `make maintainer-clean' target, but that is intended mainly - for the package's developers. If you use it, you may have to get - all sorts of other programs in order to regenerate files that came - with the distribution. - - 6. Often, you can also type `make uninstall' to remove the installed - files again. - -Compilers and Options -===================== - - Some systems require unusual options for compilation or linking that -the `configure' script does not know about. Run `./configure --help' -for details on some of the pertinent environment variables. - - You can give `configure' initial values for configuration parameters -by setting variables in the command line or in the environment. Here -is an example: - - ./configure CC=c99 CFLAGS=-g LIBS=-lposix - - *Note Defining Variables::, for more details. - -Compiling For Multiple Architectures -==================================== - - You can compile the package for more than one kind of computer at the -same time, by placing the object files for each architecture in their -own directory. To do this, you can use GNU `make'. `cd' to the -directory where you want the object files and executables to go and run -the `configure' script. `configure' automatically checks for the -source code in the directory that `configure' is in and in `..'. - - With a non-GNU `make', it is safer to compile the package for one -architecture at a time in the source code directory. After you have -installed the package for one architecture, use `make distclean' before -reconfiguring for another architecture. - - On MacOS X 10.5 and later systems, you can create libraries and -executables that work on multiple system types--known as "fat" or -"universal" binaries--by specifying multiple `-arch' options to the -compiler but only a single `-arch' option to the preprocessor. Like -this: - - ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ - CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ - CPP="gcc -E" CXXCPP="g++ -E" - - This is not guaranteed to produce working output in all cases, you -may have to build one architecture at a time and combine the results -using the `lipo' tool if you have problems. - -Installation Names -================== - - By default, `make install' installs the package's commands under -`/usr/local/bin', include files under `/usr/local/include', etc. You -can specify an installation prefix other than `/usr/local' by giving -`configure' the option `--prefix=PREFIX'. - - You can specify separate installation prefixes for -architecture-specific files and architecture-independent files. If you -pass the option `--exec-prefix=PREFIX' to `configure', the package uses -PREFIX as the prefix for installing programs and libraries. -Documentation and other data files still use the regular prefix. - - In addition, if you use an unusual directory layout you can give -options like `--bindir=DIR' to specify different values for particular -kinds of files. Run `configure --help' for a list of the directories -you can set and what kinds of files go in them. - - If the package supports it, you can cause programs to be installed -with an extra prefix or suffix on their names by giving `configure' the -option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. - -Optional Features -================= - - Some packages pay attention to `--enable-FEATURE' options to -`configure', where FEATURE indicates an optional part of the package. -They may also pay attention to `--with-PACKAGE' options, where PACKAGE -is something like `gnu-as' or `x' (for the X Window System). The -`README' should mention any `--enable-' and `--with-' options that the -package recognizes. - - For packages that use the X Window System, `configure' can usually -find the X include and library files automatically, but if it doesn't, -you can use the `configure' options `--x-includes=DIR' and -`--x-libraries=DIR' to specify their locations. - -Particular systems -================== - - On HP-UX, the default C compiler is not ANSI C compatible. If GNU -CC is not installed, it is recommended to use the following options in -order to use an ANSI C compiler: - - ./configure CC="cc -Ae" - -and if that doesn't work, install pre-built binaries of GCC for HP-UX. - - On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot -parse its `' header file. The option `-nodtk' can be used as -a workaround. If GNU CC is not installed, it is therefore recommended -to try - - ./configure CC="cc" - -and if that doesn't work, try - - ./configure CC="cc -nodtk" - -Specifying the System Type -========================== - - There may be some features `configure' cannot figure out -automatically, but needs to determine by the type of machine the package -will run on. Usually, assuming the package is built to be run on the -_same_ architectures, `configure' can figure that out, but if it prints -a message saying it cannot guess the machine type, give it the -`--build=TYPE' option. TYPE can either be a short name for the system -type, such as `sun4', or a canonical name which has the form: - - CPU-COMPANY-SYSTEM - -where SYSTEM can have one of these forms: - - OS KERNEL-OS - - See the file `config.sub' for the possible values of each field. If -`config.sub' isn't included in this package, then this package doesn't -need to know the machine type. - - If you are _building_ compiler tools for cross-compiling, you should -use the option `--target=TYPE' to select the type of system they will -produce code for. - - If you want to _use_ a cross compiler, that generates code for a -platform different from the build platform, you should specify the -"host" platform (i.e., that on which the generated programs will -eventually be run) with `--host=TYPE'. - -Sharing Defaults -================ - - If you want to set default values for `configure' scripts to share, -you can create a site shell script called `config.site' that gives -default values for variables like `CC', `cache_file', and `prefix'. -`configure' looks for `PREFIX/share/config.site' if it exists, then -`PREFIX/etc/config.site' if it exists. Or, you can set the -`CONFIG_SITE' environment variable to the location of the site script. -A warning: not all `configure' scripts look for a site script. - -Defining Variables -================== - - Variables not defined in a site shell script can be set in the -environment passed to `configure'. However, some packages may run -configure again during the build, and the customized values of these -variables may be lost. In order to avoid this problem, you should set -them in the `configure' command line, using `VAR=value'. For example: - - ./configure CC=/usr/local2/bin/gcc - -causes the specified `gcc' to be used as the C compiler (unless it is -overridden in the site shell script). - -Unfortunately, this technique does not work for `CONFIG_SHELL' due to -an Autoconf bug. Until the bug is fixed you can use this workaround: - - CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash - -`configure' Invocation -====================== - - `configure' recognizes the following options to control how it -operates. - -`--help' -`-h' - Print a summary of all of the options to `configure', and exit. - -`--help=short' -`--help=recursive' - Print a summary of the options unique to this package's - `configure', and exit. The `short' variant lists options used - only in the top level, while the `recursive' variant lists options - also present in any nested packages. - -`--version' -`-V' - Print the version of Autoconf used to generate the `configure' - script, and exit. - -`--cache-file=FILE' - Enable the cache: use and save the results of the tests in FILE, - traditionally `config.cache'. FILE defaults to `/dev/null' to - disable caching. - -`--config-cache' -`-C' - Alias for `--cache-file=config.cache'. - -`--quiet' -`--silent' -`-q' - Do not print messages saying which checks are being made. To - suppress all normal output, redirect it to `/dev/null' (any error - messages will still be shown). - -`--srcdir=DIR' - Look for the package's source code in directory DIR. Usually - `configure' can determine that directory automatically. - -`--prefix=DIR' - Use DIR as the installation prefix. *Note Installation Names:: - for more details, including other options available for fine-tuning - the installation locations. - -`--no-create' -`-n' - Run the configure checks, but stop before creating any output - files. - -`configure' also accepts some other, not widely useful, options. Run -`configure --help' for more details. - diff --git a/NEWS b/NEWS deleted file mode 100644 index e69de29..0000000 diff --git a/README b/README index 1ec91ff..e622094 100644 --- a/README +++ b/README @@ -1,79 +1,2 @@ -- How can I get started with this software? - -You should create device file for MPIO. Be root and type following: - - /usr/local/sbin/mkmpiodev - -Once you create it, you do not need to run this script again. -Next, the driver module has to be loaded before playing. - - /sbin/depmod -a - /sbin/modprobe mpio - -Connect your MPIO to PC by USB cable. You can run mpiosh shell now. -When you want to stop playing, disconnect MPIO and type: - - /sbin/modprobe -r mpio - -*Hotplug for kernel 2.4.x - - If the Hot plugging tool (like Murasaki) is installed on your -system, the driver module will be loaded/unloaded automatically -when MPIO player is connected/disconnected to your PC. And you -do not need to run modprobe anymore. - -- Is there any risk to use this software with my MPIO mp3 player? - -We do not really know that, but we do not garantee for anything. If -you use this software and your MPIO mp3 player turns into a useless -brick it is your own fault. If you use any other device with this -library it would be a wonder if does _not_ turn it into a brick. So if -you do not like your mp3 player just use this software ;-) - -- I downloaded a current CVS snapshot but there is no configure script, only - a configure.in ! What do I have to do?? - -configure and a few other files are automagically created using the -tools aclocal, autoconf and automake. Execute the script "autogen.sh" -and you should be ready to go. (Of course, you need to have the -mentioned tools installed ;-) - -- How to help us finding bugs and learning more about different models - of the MPIO mp3 players? - -The mpiosh shell is at the moment the only user interface to access -the functionality of libmpio. Because this software is definitly not -ready yet (pre alpha) and we need a lot of more information about -different models of the MPIO mp3 players we add special debugging -functionality to the shell to help users to support our work. - -To help us understanding your bug reports we need a lot of information -about the data which is exchanged between your MPIO mp3 player and our -library. To get this information we added a special 'debug' command to -the mpio-shell (mpiosh). To activate the debug ouput type the following -command: - - mpio debug on - -to see more detailed debug output the level can be changed using the -'level' option like this: - - mpio debug level 5 - -This sets the highest debug level available. To make it easier to send us -the output you can redirect the debug output to a file like this: - - mpio debug file /tmp/mpio-5.debug - -If you would like to help us finding bugs and learning more about the -protocol of the MPIO players use this debugging support and send the log -files to one of the developers or the mailing-list at sourceforge - -Thanks for you help. - -your MPIO-Team - - - - +This is a fork of http://mpio.sourceforge.net/ diff --git a/TODO b/TODO deleted file mode 100644 index 13ee468..0000000 --- a/TODO +++ /dev/null @@ -1,47 +0,0 @@ -$Id: TODO,v 1.19 2003/04/06 23:09:19 germeier Exp $ - -* Kernel Module - - the MPIO can no multitasking, so: - allow only *one* process to use the device - [did always work, my mistake] - -* libmpio - - find FAT entry dynamic [DONE] - - finish API - - implement dir functions [DONE] - - implement ECC code (we want a GPL code for this) [DONE] - - use ECC code for every read/write operation!! [DONE] - - implement reading of files [DONE] - - implement writing of files [partially done] - * writing to internal memory [DONE] - * resolve remainig block addressing issues in spare area [DONE] - * fix 8.3 filenames [DONE] - * fix timestamps of files [DONE] - - implement deleting of files [DONE] - - If everything is done: - - implement formating of external memory [DONE] - * write code to fix defective CIS (??), MBR, PBR [DONE] - - implement formating of internal memory (BEWARE !!!!) - [DONE: BEWARE no config files are written!!!!] - - written config files file setting/permissions seem not - to be right for the newer players (CONFIG.DAT appears as - a playable track) - -* mpio_tool [is deprecated, use mpiosh] - -* mpiosh - - more completion functions - + command completion [DONE] - + correct completion of filenames (quoting) [DONE] - + command option completion [partly DONE] - - handle regexps in command arguments [DONE] - - use indices for files as possible arguments for put/get - - use shell-like regular expressions [DONE] - - command separator like ';' [DONE] - - using stdin for reading command sequences [DONE] - - fill: uses current local directory to fill the current memory card - + options: random, best(?) - - configuration files [almost DONE] - - save command history [DONE] - diff --git a/contrib/mpioshrc b/contrib/mpioshrc new file mode 100644 index 0000000..d599aed --- /dev/null +++ b/contrib/mpioshrc @@ -0,0 +1,7 @@ +[mpiosh] +default_mem=internal +prompt_int=mpio  +prompt_ext=mpio  +charset=ISO-8859-15 +id3_rewriting=off +id3_format=%p - %t diff --git a/debian/README b/debian/README deleted file mode 100644 index e04899b..0000000 --- a/debian/README +++ /dev/null @@ -1,6 +0,0 @@ -The Debian Package mpio ----------------------------- - -Comments regarding the Package - -Andreas Büsching , Sat, 1 Apr 2006 19:40:10 +0200 diff --git a/debian/changelog b/debian/changelog deleted file mode 100644 index da87b83..0000000 --- a/debian/changelog +++ /dev/null @@ -1,5 +0,0 @@ -mpio (0.7.1-1) unstable; urgency=low - - * Initial Release. - - -- Andreas Büsching Mon, 3 Apr 2006 23:15:38 +0200 diff --git a/debian/control b/debian/control deleted file mode 100644 index 1dfcd1c..0000000 --- a/debian/control +++ /dev/null @@ -1,21 +0,0 @@ -Source: mpio -Section: misc -Priority: optional -Maintainer: Andreas Büsching -Build-Depends: debhelper (>= 4.0.0), autotools-dev, cdbs, libusb-dev, libreadline5-dev -Standards-Version: 3.6.2 - -Package: libmpio -Architecture: any -Depends: ${shlibs:Depends}, libusb-0.1-4 -Description: provides access to MPIO MP3 players - -Package: libmpio-dev -Architecture: all -Depends: ${shlibs:Depends} -Description: Development files for the MPIO library - -Package: mpio-tools -Architecture: any -Depends: ${shlibs:Depends}, libmpio, libreadline5 -Description: MPIO Shell and MPIO Logo diff --git a/debian/copyright b/debian/copyright deleted file mode 100644 index 0ba1c99..0000000 --- a/debian/copyright +++ /dev/null @@ -1,24 +0,0 @@ -This is mpio, written and maintained by - Markus Germeier - Andreas Buesching - -Copyright (C) 2006 - -License: - - 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 package; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -On Debian systems, the complete text of the GNU General -Public License can be found in `/usr/share/common-licenses/GPL'. diff --git a/debian/docs b/debian/docs deleted file mode 100644 index ed91ff0..0000000 --- a/debian/docs +++ /dev/null @@ -1,5 +0,0 @@ -NEWS -README -TODO -COPYING -AUTHORS diff --git a/debian/libmpio-dev.install b/debian/libmpio-dev.install deleted file mode 100644 index f616c9a..0000000 --- a/debian/libmpio-dev.install +++ /dev/null @@ -1 +0,0 @@ -debian/tmp/usr/include/mpio/* diff --git a/debian/libmpio.install b/debian/libmpio.install deleted file mode 100644 index dd9256f..0000000 --- a/debian/libmpio.install +++ /dev/null @@ -1,2 +0,0 @@ -debian/tmp/usr/lib/libmpio* -debian/tmp/etc/hotplug/usb/* diff --git a/debian/mpio-tools.install b/debian/mpio-tools.install deleted file mode 100644 index 38676ab..0000000 --- a/debian/mpio-tools.install +++ /dev/null @@ -1,3 +0,0 @@ -debian/tmp/usr/bin/* -debian/tmp/etc/mpio/* - diff --git a/debian/postinst b/debian/postinst deleted file mode 100644 index 7f8c955..0000000 --- a/debian/postinst +++ /dev/null @@ -1,42 +0,0 @@ -#! /bin/sh -# postinst script for gex -# -# see: dh_installdeb(1) - -set -e - -# summary of how this script can be called: -# * `configure' -# * `abort-upgrade' -# * `abort-remove' `in-favour' -# -# * `abort-deconfigure' `in-favour' -# `removing' -# -# for details, see http://www.debian.org/doc/debian-policy/ or -# the debian-policy package -# - -case "$1" in - configure) - - ;; - - abort-upgrade|abort-remove|abort-deconfigure) - - ;; - - *) - echo "postinst called with unknown argument \`$1'" >&2 - exit 1 - ;; -esac - -# dh_installdeb will replace this with shell code automatically -# generated by other debhelper scripts. - -#DEBHELPER# - -exit 0 - - diff --git a/debian/rules b/debian/rules deleted file mode 100755 index fef39cd..0000000 --- a/debian/rules +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/make -f - -include /usr/share/cdbs/1/class/autotools.mk -include /usr/share/cdbs/1/rules/simple-patchsys.mk -include /usr/share/cdbs/1/rules/debhelper.mk - diff --git a/etc/mpioshrc b/etc/mpioshrc deleted file mode 100644 index d599aed..0000000 --- a/etc/mpioshrc +++ /dev/null @@ -1,7 +0,0 @@ -[mpiosh] -default_mem=internal -prompt_int=mpio  -prompt_ext=mpio  -charset=ISO-8859-15 -id3_rewriting=off -id3_format=%p - %t diff --git a/hotplug/libmpio.in b/hotplug/libmpio.in deleted file mode 100755 index 27c5370..0000000 --- a/hotplug/libmpio.in +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -# -# /etc/hotplug/usb/libmpio -# -# Fix permissions on device file, so -# "normal" users can access the MPIO player - -MPIO_USER=@MPIOUSER@ -MPIO_GROUP=@MPIOGROUP@ -MPIO_PERM=@MPIOPERM@ - -if [ "$ACTION" = "add" ] && - [ "$TYPE" = "usb" ] && - [ -f "${DEVICE}" ] -then - chmod 0000 "$DEVICE" - chown $MPIO_USER "$DEVICE" - chgrp $MPIO_GROUP "$DEVICE" - chmod $MPIO_PERM "$DEVICE" -fi diff --git a/hotplug/libmpio.usermap b/hotplug/libmpio.usermap deleted file mode 100644 index a73ca0e..0000000 --- a/hotplug/libmpio.usermap +++ /dev/null @@ -1,5 +0,0 @@ -# usb module match_flags idVendor idProduct bcdDevice_lo bcdDevice_hi bDeviceClass bDeviceSubClass bDeviceProtocol bInterfaceClass bInterfaceSubClass bInterfaceProtocol driver_info -# all MPIO players: -libmpio 0x0003 0x2735 0x0001 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000 -# Virgin Pulse branded MPIO players: -libmpio 0x0003 0x2735 0x0071 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000 diff --git a/libmpio/CMakeLists.txt b/libmpio/CMakeLists.txt index ce48530..fb590ef 100644 --- a/libmpio/CMakeLists.txt +++ b/libmpio/CMakeLists.txt @@ -3,12 +3,4 @@ cmake_minimum_required (VERSION 2.4) set (PACKAGE libmpio) project (${PACKAGE} C) -set (CMAKE_C_FLAGS -Wall) - -include_directories (${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/mplib) - -add_library (mpio STATIC src/mpio.c src/io.c src/debug.c src/smartmedia.c - src/mmc.c src/directory.c src/fat.c src/ecc.c src/cis.c) - -target_link_libraries (mpio -lusb) +add_subdirectory (src) diff --git a/libmpio/src/CMakeLists.txt b/libmpio/src/CMakeLists.txt new file mode 100644 index 0000000..0422cb7 --- /dev/null +++ b/libmpio/src/CMakeLists.txt @@ -0,0 +1,9 @@ +set (CMAKE_C_FLAGS -Wall) + +include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../) + +add_library (mpio STATIC mpio.c io.c debug.c smartmedia.c mmc.c directory.c + fat.c ecc.c cis.c) + +target_link_libraries (mpio -lusb) + diff --git a/mkmpiodev b/mkmpiodev deleted file mode 100755 index bbe6995..0000000 --- a/mkmpiodev +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -#------------------------------ -# Create device file for MPIO -#------------------------------ - -DEVFILE=/dev/usb/mpio -MAJOR=180 -MINOR=70 -PERM=666 -OWNER=root.root - -if test -c $DEVFILE; then - echo -n "Removing $DEVFILE ... " - rm -f $DEVFILE - echo "done" -fi - -if test "$1" != "-r"; then - echo -n "Creating $DEVFILE ... " - mknod -m $PERM $DEVFILE c $MAJOR $MINOR - chown $OWNER $DEVFILE - echo "done" -fi - diff --git a/mpio.spec.in b/mpio.spec.in deleted file mode 100644 index 43bd5cd..0000000 --- a/mpio.spec.in +++ /dev/null @@ -1,65 +0,0 @@ -# -*- rpm-spec -*- -%define version @VERSION@ -%define release @RELEASE@ -%define name mpio -%define prefix /usr -%define sysconfdir %prefix/etc - -Version: %version -Summary: MPIO - providing access to MPIO mp3 players -Name: %name -Release: %release -License: GPL -Group: Applications/MultiMedia -Source: http://download.sourceforge.net/mpio/mpio-@VERSION@.tar.gz -Prefix: %prefix -Buildroot: /var/tmp/mpio-@VERSION@-buildroot/ -Packager: Andreas Büsching -Requires: libusb >= 0.1.7, readline >= 4.3, ncurses >= 5.0 -BuildRequires: readline-devel >= 4.3 -BuildRequires: ncurses-devel >= 5.0 - -%description -This is a project for using Digitalway/Adtec digital audio player MPIO -(DMG, DMK, DME, DMB, FD 100, FL100, FY100, FY200) under Linux. It uses -libusb and provides a userspace library and at the moment one tool to -access the MPIO player. - -%prep -%setup -CFLAGS="$RPM_OPT_FLAGS" ./configure --prefix=%prefix -sysconfdir=%sysconfdir - -%build -make - -%install -rm -rf $RPM_BUILD_ROOT -KVERSION=`uname -r` - -echo "%defattr(755,root,root)" > /tmp/mpio-files.lst -echo "%prefix/bin/mpiosh" >> /tmp/mpio-files.lst -echo "%prefix/bin/mpiologo" >> /tmp/mpio-files.lst -echo "%prefix/lib/libmpio*" >> /tmp/mpio-files.lst -echo "%defattr(700,root,root)" >> /tmp/mpio-files.lst -echo "%defattr(644,root,root)" >> /tmp/mpio-files.lst -echo "%sysconfdir/mpio/mpioshrc" >> /tmp/mpio-files.lst -echo "%prefix/include/mpio/mpio.h" >> /tmp/mpio-files.lst -echo "%prefix/include/mpio/defs.h" >> /tmp/mpio-files.lst -echo "/etc/hotplug/usb/libmpio.usermap" >> /tmp/mpio-files.lst -echo "%defattr(755,root,root)" >> /tmp/mpio-files.lst -echo "/etc/hotplug/usb/libmpio" >> /tmp/mpio-files.lst - -make DESTDIR=$RPM_BUILD_ROOT install - -%post -ldconfig - -%files -f /tmp/mpio-files.lst - -%doc COPYING ChangeLog INSTALL NEWS -%doc README TODO - -%clean -rm -rf $RPM_BUILD_ROOT -rm -f /tmp/mpio-files.lst - diff --git a/mpiosh/.gitignore b/mpiosh/.gitignore deleted file mode 100644 index 2e3941e..0000000 --- a/mpiosh/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -mpiosh -config.h diff --git a/mpiosh/CMakeLists.txt b/mpiosh/CMakeLists.txt deleted file mode 100644 index efff2c7..0000000 --- a/mpiosh/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -cmake_minimum_required (VERSION 2.4) - -set (PACKAGE mpiosh) -project (${PACKAGE} C) - -set (CMAKE_C_FLAGS -Wall) - -configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.h.in - ${CMAKE_CURRENT_BINARY_DIR}/config.h) - -include_directories (${CMAKE_CURRENT_SOURCE_DIR}/..) - -add_executable (mpiosh mpiosh.c callback.c readline.c command.c global.c - cfgio.c cfg.c) -target_link_libraries (mpiosh mpio -lreadline -lncurses) diff --git a/mpiosh/callback.c b/mpiosh/callback.c deleted file mode 100644 index e98a334..0000000 --- a/mpiosh/callback.c +++ /dev/null @@ -1,1273 +0,0 @@ -/* callback.c - * - * Author: Andreas Büsching - * - * $Id: callback.c,v 1.49 2006/01/21 18:33:20 germeier Exp $ - * - * Copyright (C) 2001 Andreas Büsching - * - * 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 "callback.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "mpiosh.h" -#include "command.h" -#include "cfg.h" - -#include "libmpio/debug.h" - -/* helper */ -BYTE -mpiosh_ftype2ascii(BYTE ftype) { - switch(ftype) - { - case FTYPE_CONF: - case FTYPE_FONT: - case FTYPE_OTHER: - case FTYPE_MEMO: - case FTYPE_WAV: - case FTYPE_ENTRY: - case FTYPE_DIR: - case FTYPE_PLAIN: - return ftype; - case FTYPE_DIR_RECURSION: - return 'r'; - case FTYPE_CHAN: - return 'c'; - case FTYPE_MUSIC: - return '-'; - default: - return '?'; - } - return '?'; -} - - -/* 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] \n"); - } - } else { - fprintf(stderr, "error: no arguments given\n"); - printf("debug [level|file|on|off] \n"); - } -} - -void -mpiosh_cmd_version(char *args[]) -{ - UNUSED(args); - - printf("MPIO shell %s\n\n", VERSION); -} - -void -mpiosh_cmd_help(char *args[]) -{ - struct mpiosh_cmd_t *cmd = commands; - int ignore; - - while (cmd->cmd) { - 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->aliases) { - char **go = cmd->aliases; - printf(" alias:\n "); - while(*go) printf(( *(go+1) ? "%s" : "%s, "), *go++); - printf("\n"); - } - - if (cmd->info) - printf(" description:\n%s\n", cmd->info); - else - printf("\n"); - } - cmd++; - } -} - -void -mpiosh_cmd_dir(char *args[]) -{ - BYTE *p; - BYTE month, day, hour, minute, type; - CHAR fname[100]; - WORD year; - DWORD fsize; - - UNUSED(args); - - MPIOSH_CHECK_CONNECTION_CLOSED; - - p = mpio_directory_open(mpiosh.dev, mpiosh.card); - while (p != NULL) { - memset(fname, '\0', 100); - - mpio_dentry_get(mpiosh.dev, mpiosh.card, p, - fname, 100, - &year, &month, &day, - &hour, &minute, &fsize, - &type); - - printf ("%02d.%02d.%04d %02d:%02d %9d %c %s\n", - day, month, year, hour, minute, fsize, - mpiosh_ftype2ascii(type), fname); - - p = mpio_dentry_next(mpiosh.dev, mpiosh.card, p); - } -} - -void -mpiosh_cmd_pwd(char *args[]) -{ - CHAR pwd[INFO_LINE]; - - UNUSED(args); - - MPIOSH_CHECK_CONNECTION_CLOSED; - - mpio_directory_pwd(mpiosh.dev, mpiosh.card, pwd); - printf ("%s\n", pwd); - -} - -void -mpiosh_cmd_mkdir(char *args[]) -{ - CHAR pwd[INFO_LINE]; - BYTE r; - - MPIOSH_CHECK_CONNECTION_CLOSED; - - r=mpio_directory_make(mpiosh.dev, mpiosh.card, args[0]); - if (r != MPIO_OK) - { - mpio_perror("ERROR"); - } - mpio_sync(mpiosh.dev, mpiosh.card); - -} - -void -mpiosh_cmd_cd(char *args[]) -{ - CHAR pwd[INFO_LINE]; - BYTE r; - - MPIOSH_CHECK_CONNECTION_CLOSED; - - if ( args[ 0 ] != NULL ) - r=mpio_directory_cd(mpiosh.dev, mpiosh.card, args[0]); - else - r=mpio_directory_cd(mpiosh.dev, mpiosh.card, "."); - - if (r != MPIO_OK) - { - mpio_perror("ERROR"); - } - - mpio_directory_pwd(mpiosh.dev, mpiosh.card, pwd); - printf ("directory is now: %s\n", pwd); - -} - -void -mpiosh_cmd_info(char *args[]) -{ - mpio_info_t info; - - UNUSED(args); - - MPIOSH_CHECK_CONNECTION_CLOSED; - - 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("model : %s\n", info.model); - printf("memory\n"); - printf(" internal: %s\n", info.mem_internal); - printf(" external: %s\n", info.mem_external); -} - -void -mpiosh_cmd_mem(char *args[]) -{ - DWORD free; - - MPIOSH_CHECK_CONNECTION_CLOSED; - MPIOSH_CHECK_ARG; - - if (!strcmp(args[0], "e")) { - if (mpio_memory_free(mpiosh.dev, MPIO_EXTERNAL_MEM, &free)) { - mpiosh.card = MPIO_EXTERNAL_MEM; - mpiosh.prompt = PROMPT_EXT; - printf("external memory card is selected\n"); - } else { - printf("no external memory card is available\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[]) -{ - MPIOSH_CHECK_CONNECTION_OPEN; - - UNUSED(args); - - mpiosh.dev = mpio_init(mpiosh_callback_init); - - printf("\n"); - - if (mpiosh.dev == NULL) { - mpio_perror("ERROR"); - printf("could not open connection MPIO player\n"); - } - else - printf("connection to MPIO player is opened\n"); - - if ((mpiosh.dev) && (mpiosh.config->charset)) - mpio_charset_set(mpiosh.dev, mpiosh.config->charset); -} - -void -mpiosh_cmd_close(char *args[]) -{ - MPIOSH_CHECK_CONNECTION_CLOSED; - - 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); - - if (mpiosh.config) { - mpiosh_config_write(mpiosh.config); - mpiosh_config_free(mpiosh.config); - } - - exit(0); -} - -BYTE -mpiosh_callback_init(mpio_mem_t mem, int read, int total) -{ - switch(mem) - { - case MPIO_INTERNAL_MEM: - printf("\rinternal memory: " ); - break; - case MPIO_EXTERNAL_MEM: - printf("\rexternal memory: " ); - break; - default: - printf("\runknown memory: " ); - } - - printf("initialized %.2f %% ", ((double) read / total) * 100.0 ); - fflush(stdout); - - return mpiosh_cancel; // continue -} - -BYTE -mpiosh_callback_get(int read, int total) -{ - printf("\rretrieved %.2f %%", ((double) read / total) * 100.0 ); - fflush(stdout); - - if (mpiosh_cancel) - debug ("user cancelled operation\n"); - - return mpiosh_cancel; // continue -} - -/* void */ -/* mpiosh_cmd_get(char *args[]) */ -/* { */ -/* MPIOSH_CHECK_CONNECTION_CLOSED; */ -/* MPIOSH_CHECK_ARG; */ - -/* if (mpio_file_get(mpiosh.dev, mpiosh.card, args[0], */ -/* mpiosh_callback_get) == -1) { */ -/* mpio_perror("error"); */ -/* } */ -/* printf("\n"); */ -/* } */ - -void -mpiosh_cmd_mget(char *args[]) -{ - BYTE * p; - int i = 0, error, ret; - regex_t regex; - CHAR fname[100]; - CHAR errortext[100]; - BYTE month, day, hour, minute, type; - WORD year; - DWORD fsize; - int found; - - MPIOSH_CHECK_CONNECTION_CLOSED; - MPIOSH_CHECK_ARG; - - mpiosh_command_regex_fix(args); - - while (args[i] != NULL) { - if ((error = regcomp(®ex, args[i], REG_NOSUB))) { - regerror(error, ®ex, errortext, 100); - debugn (2, "error in regular expression: %s (%s)\n", args[i], errortext); - } else { - found = 0; - p = mpio_directory_open(mpiosh.dev, mpiosh.card); - while (p != NULL) { - memset(fname, '\0', 100); - mpio_dentry_get(mpiosh.dev, mpiosh.card, p, fname, 100, - &year, &month, &day, &hour, &minute, &fsize, &type); - - if (!(error = regexec(®ex, fname, 0, NULL, 0))) { - found = 1; - printf("getting '%s' ... \n", fname); - if ((mpio_file_get(mpiosh.dev, mpiosh.card, - fname, mpiosh_callback_get)) == -1) { - if ((ret=mpio_errno()) == MPIO_ERR_USER_CANCEL) { - debug("cancelled operation\n"); - mpio_perror("error"); - break; - } - mpio_error_set(ret); - mpio_perror("error"); - } - printf("\n"); - if (mpiosh_cancel) { - debug("operation cancelled by user\n"); - break; - } - } else { - regerror(error, ®ex, errortext, 100); - debugn (2, "file does not match: %s (%s)\n", fname, errortext); - } - - p = mpio_dentry_next(mpiosh.dev, mpiosh.card, p); - } - } - if (!found) - printf("file not found! (%s)\n", args[i]); - i++; - } - - - regfree(®ex); -} - -BYTE -mpiosh_callback_put(int read, int total) -{ - printf("\rwrote %.2f %%", ((double) read / total) * 100.0 ); - fflush(stdout); - - if ((mpiosh_cancel) && (!mpiosh_cancel_ack)) { - debug ("user cancelled operation\n"); - mpiosh_cancel_ack = 1; - } - - return mpiosh_cancel; // continue -} - -/* void */ -/* mpiosh_cmd_put(char *args[]) */ -/* { */ -/* int size; */ - -/* MPIOSH_CHECK_CONNECTION_CLOSED; */ -/* MPIOSH_CHECK_ARG; */ - -/* if ((size = mpio_file_put(mpiosh.dev, mpiosh.card, args[0], FTYPE_MUSIC, */ -/* mpiosh_callback_put)) == -1) { */ -/* mpio_perror("error"); */ -/* } else { */ -/* mpio_sync(mpiosh.dev, mpiosh.card); */ -/* } */ -/* printf("\n"); */ -/* } */ - -void -mpiosh_cmd_mput(char *args[]) -{ - char dir_buf[NAME_MAX]; - int size, j, i = 0, error, written = 0; - struct dirent ** dentry, **run; - struct stat st; - regex_t regex; - CHAR errortext[100]; - - MPIOSH_CHECK_CONNECTION_CLOSED; - MPIOSH_CHECK_ARG; - - mpiosh_command_regex_fix(args); - getcwd(dir_buf, NAME_MAX); - while (args[i] != NULL) { - if ((error = regcomp(®ex, args[i], REG_NOSUB))) { - regerror(error, ®ex, errortext, 100); - debugn (2, "error in regular expression: %s (%s)\n", args[i], errortext); - } else { - if ((size = scandir(dir_buf, &dentry, NULL, alphasort)) != -1) { - run = dentry; - for (j = 0; ((j < size) && (!mpiosh_cancel)); j++, run++) { - if (stat((*run)->d_name, &st) == -1) { - free(*run); - continue; - } else { - if (!S_ISREG(st.st_mode)) { - debugn(2, "not a regular file: '%s'\n", (*run)->d_name); - free(*run); - continue; - } - } - - if (!(error = regexec(®ex, (*run)->d_name, 0, NULL, 0))) { - printf("putting '%s' ... \n", (*run)->d_name); - if (mpio_file_put(mpiosh.dev, mpiosh.card, (*run)->d_name, - FTYPE_MUSIC, mpiosh_callback_put) == -1) { - mpio_perror("error"); - /* an existing file is no reason for a complete abort!! */ - if (mpio_errno() == MPIO_ERR_FILE_EXISTS) - continue; - break; - } - written = 1; /* we did write something, so do mpio_sync afterwards */ - - printf("\n"); - } else { - regerror(error, ®ex, errortext, 100); - debugn(2, "file does not match: %s (%s)\n", - (*run)->d_name, errortext); - } - free(*run); - } - free(dentry); - } - } - i++; - } - regfree(®ex); - if (mpiosh_cancel) - debug("operation cancelled by user\n"); - - if (written) { - mpio_sync(mpiosh.dev, mpiosh.card); - } else { - printf("file not found!\n"); - } -} - -BYTE -mpiosh_callback_del(int read, int total) -{ - printf("\rdeleted %.2f %%", ((double) read / total) * 100.0 ); - fflush(stdout); - - if (mpiosh_cancel) - debug ("user cancelled operation\n"); - - return mpiosh_cancel; // continue -} - -/* void */ -/* mpiosh_cmd_del(char *args[]) */ -/* { */ -/* int size; */ - -/* MPIOSH_CHECK_CONNECTION_CLOSED; */ -/* MPIOSH_CHECK_ARG; */ - -/* size = mpio_file_del(mpiosh.dev, mpiosh.card, args[0], mpiosh_callback_del); */ -/* mpio_sync(mpiosh.dev, mpiosh.card); */ - -/* printf("\n"); */ -/* } */ - -void -mpiosh_cmd_mdel(char *args[]) -{ - BYTE * p; - int i = 0; - int error; - regex_t regex; - int r; - CHAR fname[100]; - CHAR errortext[100]; - BYTE month, day, hour, minute, type; - WORD year; - DWORD fsize; - int deleted = 0; - - MPIOSH_CHECK_CONNECTION_CLOSED; - MPIOSH_CHECK_ARG; - - mpiosh_command_regex_fix(args); - while (args[i] != NULL) { - if ((error = regcomp(®ex, args[i], REG_NOSUB))) { - regerror(error, ®ex, errortext, 100); - debugn (2, "error in regular expression: %s (%s)\n", args[i], errortext); - } else { - p = mpio_directory_open(mpiosh.dev, mpiosh.card); - while ((p != NULL) && (!mpiosh_cancel)) { - memset(fname, '\0', 100); - mpio_dentry_get(mpiosh.dev, mpiosh.card, p, fname, 100, - &year, &month, &day, &hour, &minute, &fsize, &type); - - if ((!(error = regexec(®ex, fname, 0, NULL, 0))) && - (strcmp(fname, "..")) && (strcmp(fname, "."))) - { - /* this line has to be above the del, or we won't write - * the FAT and directory in case of an abort!!! - */ - deleted=1; - printf("deleting '%s' ... \n", fname); - r = mpio_file_del(mpiosh.dev, mpiosh.card, - fname, mpiosh_callback_del); - printf("\n"); - if (mpiosh_cancel) break; - /* if we delete a file, start again from the beginning, - because the directory has changed !! */ - if (r != MPIO_OK) - { - mpio_perror("ERROR"); - p = mpio_dentry_next(mpiosh.dev, mpiosh.card, p); - break; - } - p = mpio_directory_open(mpiosh.dev, mpiosh.card); - } else { - regerror(error, ®ex, errortext, 100); - debugn (2, "file does not match: %s (%s)\n", fname, errortext); - p = mpio_dentry_next(mpiosh.dev, mpiosh.card, p); - } - - } - } - i++; - } - regfree(®ex); - if (deleted) { - mpio_sync(mpiosh.dev, mpiosh.card); - } else { - printf("file not found!\n"); - } -} - - -void -mpiosh_cmd_dump(char *args[]) -{ - BYTE *p; - BYTE month, day, hour, minute, type; - CHAR fname[256]; - char *arg[2]; - WORD year; - DWORD fsize; - - MPIOSH_CHECK_CONNECTION_CLOSED; - - UNUSED(args); - - arg[1] = NULL; - - p = mpio_directory_open(mpiosh.dev, mpiosh.card); - while ((p != NULL) && (!mpiosh_cancel)) { - arg[0] = fname; /* is this a memory leak?? -mager */ - memset(fname, '\0', 256); - - mpio_dentry_get(mpiosh.dev, mpiosh.card, p, - fname, 256, - &year, &month, &day, - &hour, &minute, &fsize, &type); - - mpiosh_cmd_mget(arg); - - p = mpio_dentry_next(mpiosh.dev, mpiosh.card, p); - } -} - -void -mpiosh_cmd_free(char *args[]) -{ - DWORD free; - int kbytes; - - MPIOSH_CHECK_CONNECTION_CLOSED; - - 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]; - CHAR *config, *fmconfig, *rconfig, *fontconfig; - int csize, fmsize, rsize, fontsize; - - MPIOSH_CHECK_CONNECTION_CLOSED; - - 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 (mpiosh.card == MPIO_INTERNAL_MEM) { - printf("read config files from player\n"); - - /* save config files and write them back after formatting */ - config = NULL; - fmconfig = NULL; - rconfig = NULL; - fontconfig = NULL; - - csize = mpio_file_get_to_memory(mpiosh.dev, MPIO_INTERNAL_MEM, - MPIO_CONFIG_FILE, NULL, &config); - fmsize = mpio_file_get_to_memory(mpiosh.dev, MPIO_INTERNAL_MEM, - MPIO_CHANNEL_FILE, NULL, &fmconfig); - rsize = mpio_file_get_to_memory(mpiosh.dev, MPIO_INTERNAL_MEM, - MPIO_MPIO_RECORD, NULL, &rconfig); - fontsize = mpio_file_get_to_memory(mpiosh.dev, MPIO_INTERNAL_MEM, - MPIO_FONT_FON, NULL, &fontconfig); - } - - printf("formatting memory...\n"); - - if (mpio_memory_format(mpiosh.dev, mpiosh.card, - mpiosh_callback_format) == -1) - printf("\nfailed\n"); - else { - printf("\n"); - - if (mpiosh.card == MPIO_INTERNAL_MEM) { - printf("restoring saved config files\n"); - /* restore everything we saved */ - if (config) - if (mpio_file_put_from_memory(mpiosh.dev, MPIO_INTERNAL_MEM, - MPIO_CONFIG_FILE, FTYPE_CONF, - NULL, config, csize)==-1) - mpio_perror("error"); - if (fmconfig) - if (mpio_file_put_from_memory(mpiosh.dev, MPIO_INTERNAL_MEM, - MPIO_CHANNEL_FILE, FTYPE_CHAN, - NULL, fmconfig, fmsize)==-1) - mpio_perror("error"); - if (rconfig) - if (mpio_directory_make(mpiosh.dev, MPIO_INTERNAL_MEM, - MPIO_MPIO_RECORD)!=MPIO_OK) - mpio_perror("error"); - if (fontconfig) - if (mpio_file_put_from_memory(mpiosh.dev, MPIO_INTERNAL_MEM, - MPIO_FONT_FON, FTYPE_FONT, - NULL, fontconfig, fontsize)==-1) - mpio_perror("error"); - - if (config || fmconfig || rconfig || fontconfig) - mpio_sync(mpiosh.dev, MPIO_INTERNAL_MEM); - if (config) - free(config); - if (fmconfig) - free(fmconfig); - if (rconfig) - free(rconfig); - if (fontconfig) - free(fontconfig); - } - - } - mpiosh_cmd_health(NULL); - } -} - -void -mpiosh_cmd_switch(char *args[]) -{ - MPIOSH_CHECK_CONNECTION_CLOSED; - - if(args[0] && args[1] && !args[2]) { - if ((mpio_file_switch(mpiosh.dev, mpiosh.card, - args[0], args[1])) == -1) { - mpio_perror("error"); - } else { - mpio_sync(mpiosh.dev, mpiosh.card); - } - - } else { - fprintf(stderr, "error: wrong number of arguments given\n"); - printf("switch \n"); - } - -} - -void -mpiosh_cmd_rename(char *args[]) -{ - MPIOSH_CHECK_CONNECTION_CLOSED; - - if(args[0] && args[1] && !args[2]) { - if ((mpio_file_rename(mpiosh.dev, mpiosh.card, - args[0], args[1])) == -1) { - mpio_perror("error"); - } else { - mpio_sync(mpiosh.dev, mpiosh.card); - } - - } else { - fprintf(stderr, "error: wrong number of arguments given\n"); - printf("rename \n"); - } -} - -void -mpiosh_cmd_dump_mem(char *args[]) -{ - - MPIOSH_CHECK_CONNECTION_CLOSED; - - UNUSED(args); - - mpio_memory_dump(mpiosh.dev, mpiosh.card); - -} - -void -mpiosh_cmd_health(char *args[]) -{ - mpio_health_t health; - int i, lost, r; - - UNUSED(args); - - MPIOSH_CHECK_CONNECTION_CLOSED; - - if ((r=mpio_health(mpiosh.dev, mpiosh.card, &health)) != MPIO_OK) { - printf("error: %s\n", mpio_strerror(r)); - return; - } - - if (mpiosh.card == MPIO_INTERNAL_MEM) { - lost=0; - printf("health status of internal memory:\n"); - printf("=================================\n"); - printf("%d chip%c (total/spare/broken)\n", - health.num, ((health.num==1)?' ':'s')); - for(i=0; id_name, &st) == -1) { - perror("stat"); - } else { - rights[0] = *("?pc?dnb?-?l?s???" + (st.st_mode >> 12 & 0xf)); - for (j = 0; j < 9; j++) { - if (st.st_mode & 1 << (8 - j)) - rights[j + 1] = "rwxrwxrwx"[j]; - else - rights[j + 1] = '-'; - } - - pwd = getpwuid(st.st_uid); - grp = getgrgid(st.st_gid); - strftime(time, 12, "%b %2d", localtime(&(st.st_mtime))); - if (pwd && grp) { - printf("%s %8s %8s %8d %10s %s\n", - rights, pwd->pw_name, grp->gr_name, (int)st.st_size, - time, (*run)->d_name); - } else if (pwd) { - printf("%s %8s %8d %8d %10s %s\n", - rights, pwd->pw_name, st.st_gid, (int)st.st_size, - time, (*run)->d_name); - } else if (grp) { - printf("%s %8d %8s %8d %10s %s\n", - rights, st.st_uid, grp->gr_name, (int)st.st_size, - time, (*run)->d_name); - } else { - printf("%s %8d %8d %8d %10s %s\n", - rights, st.st_uid, st.st_gid, (int)st.st_size, - time, (*run)->d_name); - } - } - free(*run); - } - free(dentry); - } else { - perror("scandir"); - } - } -} - -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[]) -{ - MPIOSH_CHECK_ARG; - - if (chdir(args[0])) { - perror ("error"); - } -} - -void -mpiosh_cmd_lmkdir(char *args[]) -{ - MPIOSH_CHECK_ARG; - - if (mkdir(args[0], 0777)) { - perror("error"); - } -} - -void -mpiosh_cmd_font_upload(char *args[]) -{ - BYTE * p; - int size; - - MPIOSH_CHECK_CONNECTION_CLOSED; - MPIOSH_CHECK_ARG; - - /* check if fonts file already exists */ - p = mpio_file_exists(mpiosh.dev, MPIO_INTERNAL_MEM, - MPIO_FONT_FON); - if (p) { - printf("Fontsfile already exists. Please delete it first!\n"); - return; - } - - printf("writing new font file ...\n"); - if (mpio_file_put_as(mpiosh.dev, MPIO_INTERNAL_MEM, - args[0], MPIO_FONT_FON, - FTYPE_FONT, mpiosh_callback_put)==-1) - mpio_perror("error"); - - printf("\n"); - mpio_sync(mpiosh.dev, MPIO_INTERNAL_MEM); - -} - - -/* end of callback.c */ diff --git a/mpiosh/callback.h b/mpiosh/callback.h deleted file mode 100644 index 00ffb86..0000000 --- a/mpiosh/callback.h +++ /dev/null @@ -1,101 +0,0 @@ -/* callback.h - * - * Author: Andreas Büsching - * - * $Id: callback.h,v 1.13 2003/06/27 12:21:21 crunchy Exp $ - * - * Copyright (C) 2001 Andreas Büsching - * - * 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 CALLBACK_HH -#define CALLBACK_HH - -#include "libmpio/mpio.h" - -/* mpio 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_pwd(char *args[]); -void mpiosh_cmd_mkdir(char *args[]); -void mpiosh_cmd_cd(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_mget(char *args[]); -void mpiosh_cmd_put(char *args[]); -void mpiosh_cmd_mput(char *args[]); -void mpiosh_cmd_del(char *args[]); -void mpiosh_cmd_mdel(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[]); -void mpiosh_cmd_rename(char *args[]); -void mpiosh_cmd_dump_mem(char *args[]); -void mpiosh_cmd_health(char *args[]); -void mpiosh_cmd_backup(char *args[]); -void mpiosh_cmd_restore(char *args[]); -#if 0 -void mpiosh_cmd_config(char *args[]); -#endif -void mpiosh_cmd_channel(char *args[]); -void mpiosh_cmd_id3(char *args[]); -void mpiosh_cmd_id3_format(char *args[]); -void mpiosh_cmd_font_upload(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[]); - -/* progress callbacks */ -BYTE mpiosh_callback_init(mpio_mem_t, int read, int total); -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); - -/* check situation */ - -#define MPIOSH_CHECK_CONNECTION_OPEN \ - if (mpiosh.dev != NULL) { \ - printf("connection to MPIO player is open\n"); \ - return; \ - } - -#define MPIOSH_CHECK_CONNECTION_CLOSED \ - if (mpiosh.dev == NULL) { \ - printf("connection to MPIO player is closed\n"); \ - return; \ - } - -#define MPIOSH_CHECK_ARG \ - if (args[0] == NULL) { \ - printf("error: no argument given\n"); \ - return; \ - } - - -#endif - -/* end of callback.h */ diff --git a/mpiosh/cfg.c b/mpiosh/cfg.c deleted file mode 100644 index f8c672f..0000000 --- a/mpiosh/cfg.c +++ /dev/null @@ -1,238 +0,0 @@ -/* config.c - * - * Author: Andreas Buesching - * - * $Id: config.c,v 1.7 2003/06/27 13:40:23 crunchy Exp $ - * - * Copyright (C) 2001 Andreas Büsching - * - * 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 "cfg.h" -#include "global.h" - -#include -#include -#include - -struct mpiosh_config_t * -mpiosh_config_new(void) -{ - struct mpiosh_config_t * cfg = malloc(sizeof(struct mpiosh_config_t)); - char *filename, *tmp; - struct stat st; - - cfg->prompt_int = cfg->prompt_ext = NULL; - cfg->default_mem = MPIO_INTERNAL_MEM; - - filename = malloc(strlen(CONFIG_GLOBAL) + strlen(CONFIG_FILE) + 1); - filename[0] = '\0'; - strcat(filename, CONFIG_GLOBAL); - strcat(filename, CONFIG_FILE); - tmp = cfg_resolve_path(filename); - - if (stat(tmp, &st) != -1) - cfg->handle_global = - cfg_handle_new_with_filename(tmp, 1); - else - cfg->handle_global = 0; - - free(tmp), free(filename); - filename = malloc(strlen(CONFIG_USER) + strlen(CONFIG_FILE) + 1); - filename[0] = '\0'; - strcat(filename, CONFIG_USER); - strcat(filename, CONFIG_FILE); - tmp = cfg_resolve_path(filename); - - if (stat(tmp, &st) != -1) - cfg->handle_user = - cfg_handle_new_with_filename(tmp, 1); - else - cfg->handle_user = - cfg_handle_new_with_filename(tmp, 0); - - free(tmp), free(filename); - - /* initialise history */ - using_history(); - - filename = malloc(strlen(CONFIG_USER) + strlen(CONFIG_HISTORY) + 1); - filename[0] = '\0'; - strcat(filename, CONFIG_USER); - strcat(filename, CONFIG_HISTORY); - tmp = cfg_resolve_path(filename); - - read_history(tmp); - free(tmp), free(filename); - - return cfg; -} - -const char * -mpiosh_config_read_key(struct mpiosh_config_t *config, const char *group, - const char *key) -{ - char *value = NULL; - - if (config->handle_user) - value = (char *)cfg_key_get_value(config->handle_user, - group, key); - else if (config->handle_global) - value = (char *)cfg_key_get_value(config->handle_global, - group, key); - - return value; -} - -void -mpiosh_config_free(struct mpiosh_config_t *config) -{ - if (config->handle_global) - cfg_close(config->handle_global); - - cfg_close(config->handle_user); - free(config->prompt_int); - free(config->prompt_ext); - free(config); -} - -int -mpiosh_config_read(struct mpiosh_config_t *config) -{ - if (config) { - const char *value; - - value = mpiosh_config_read_key(config, "mpiosh", "prompt_int"); - if (value) { - config->prompt_int = strdup(value); - } else { - config->prompt_int = strdup(PROMPT_INT); - } - - value = mpiosh_config_read_key(config, "mpiosh", "prompt_ext"); - if (value) { - config->prompt_ext = strdup(value); - } else { - config->prompt_ext = strdup(PROMPT_EXT); - } - - value = mpiosh_config_read_key(config, "mpiosh", "default_mem"); - if (value) { - if (!strcmp("internal", value)) { - config->default_mem = MPIO_INTERNAL_MEM; - } else if (!strcmp("external", value)) { - config->default_mem = MPIO_EXTERNAL_MEM; - } - } - - value = mpiosh_config_read_key(config, "mpiosh", "charset"); - if (value) { - config->charset = strdup(value); - } else { - config->charset = NULL; - } - - value = mpiosh_config_read_key(config, "mpiosh", "id3_rewriting"); - if (value) { - if (!strcmp("on", value)) { - config->id3_rewriting = 1; - } else { - config->id3_rewriting = 0; - } - } - - value = mpiosh_config_read_key(config, "mpiosh", "id3_format"); - if (value) { - config->id3_format = strdup(value); - } else { - config->id3_format = strdup(MPIO_ID3_FORMAT); - } - - } - - return 1; -} - -char * -mpiosh_config_check_backup_dir( struct mpiosh_config_t *config, int create ) -{ - DIR *dir; - char *path = cfg_resolve_path( CONFIG_BACKUP ); - char *ret = path; - - if ( ( dir = opendir( path ) ) == NULL ) - if ( create ) { - if ( mkdir(path, 0777 ) ) - ret = NULL; - } else - ret = NULL; - else - closedir(dir); - - return ret; -} - -int -mpiosh_config_write( struct mpiosh_config_t *config ) -{ - DIR *dir; - char *path = cfg_resolve_path(CONFIG_USER); - - if ((dir = opendir(path)) == NULL) - mkdir(path, 0777); - else - closedir(dir); - - free(path); - - if (config->handle_user) { - char *tmp, *filename; - - cfg_key_set_value(config->handle_user, - "mpiosh", "prompt_int", config->prompt_int); - cfg_key_set_value(config->handle_user, - "mpiosh", "prompt_ext", config->prompt_ext); - if (config->default_mem == MPIO_EXTERNAL_MEM) - cfg_key_set_value(config->handle_user, - "mpiosh", "default_mem", "external"); - else - cfg_key_set_value(config->handle_user, - "mpiosh", "default_mem", "internal"); - cfg_key_set_value(config->handle_user, - "mpiosh", "id3_rewriting", - (config->id3_rewriting?"on":"off")); - cfg_key_set_value(config->handle_user, - "mpiosh", "id3_format", config->id3_format); - - cfg_save(config->handle_user, 0); - - /* save history */ - filename = malloc(strlen(CONFIG_USER) + strlen(CONFIG_HISTORY) + 1); - filename[0] = '\0'; - strcat(filename, CONFIG_USER); - strcat(filename, CONFIG_HISTORY); - tmp = cfg_resolve_path(filename); - - printf("writing history to file %s\n", filename); - write_history(tmp); - free(tmp), free(filename); - } - - return 1; -} - - -/* end of config.c */ diff --git a/mpiosh/cfg.h b/mpiosh/cfg.h deleted file mode 100644 index 4157bd6..0000000 --- a/mpiosh/cfg.h +++ /dev/null @@ -1,56 +0,0 @@ -/* config.h - * - * Author: Andreas Buesching - * - * $Id: config.h,v 1.5 2003/06/27 13:40:23 crunchy Exp $ - * - * Copyright (C) 2001 Andreas Büsching - * - * 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_CONFIG_HH -#define MPIOSH_CONFIG_HH - -#include "cfgio.h" - -struct mpiosh_config_t { - CfgHandle *handle_global; - CfgHandle *handle_user; - - char *prompt_int; - char *prompt_ext; - char *charset; - unsigned default_mem; - - unsigned id3_rewriting; - char *id3_format; -}; - -struct mpiosh_config_t *mpiosh_config_new(void); -void mpiosh_config_free(struct mpiosh_config_t *config); - -const char *mpiosh_config_read_key(struct mpiosh_config_t *config, - const char *group, const char *key); -int mpiosh_config_read(struct mpiosh_config_t *config); -int mpiosh_config_write(struct mpiosh_config_t *config); - -char * mpiosh_config_check_backup_dir( struct mpiosh_config_t *config, - int create ); - -#endif - -/* end of config.h */ - diff --git a/mpiosh/cfgio.c b/mpiosh/cfgio.c deleted file mode 100644 index b8a1829..0000000 --- a/mpiosh/cfgio.c +++ /dev/null @@ -1,654 +0,0 @@ -#include "cfgio.h" - -#include -#include - -/*************************************************** - * help!!! functions - ***************************************************/ - -char * -cfg_resolve_path(const char *filename) -{ - char *fn = NULL; - - if (filename[0] != '~') return strdup(filename); - - if (filename[1] == '/' ) { - /* own home directory */ - char *home; - if ((home = getenv ("HOME")) == NULL) { - fn = strdup(filename); - } else { - fn = (char *)malloc(strlen(home) + strlen(filename+1) + 1); - sprintf(fn, "%s%s", home,filename+1); - } - } else { - /* other home directory */ - struct passwd *pw; - char *dir = strchr(filename, '/'); - size_t len = (size_t)(dir - filename-1); - char user[len]; - strncpy(user, filename+1, len); - user[len] = '\0'; - - if (!(pw = getpwnam(user))) { - fn = strdup(filename); - } else { - fn = (char *) malloc(strlen(pw->pw_dir) + strlen(dir) + 1); - sprintf (fn, "%s%s",pw->pw_dir, dir); - } - } - - return fn; -} - -/*************************************************** - * open functions - ***************************************************/ -int cfg_save(CfgHandle *h, int cl){ - if (h && h->file) { - FILE *f = h->file; - CfgGroup *group; - group = h->first; - - while (group) { - CfgKey *key; - fprintf(f, "[%s]\n", group->name); - key = group->first; - while (key) { - fprintf(f, "%s=%s\n", key->name, key->value ? key->value : ""); - key = key->next; - } - fprintf(f, "\n"); - group = group->next; - } - if (cl) return cfg_close(h); - return 0; - } - return -1; -} - -int cfg_save_as(CfgHandle *h, const char* filename, int err, int cl){ - if (h && filename) { - int res; - res = cfg_handle_change_filename(h, filename); - if (res) return res; - res = cfg_open(h, err, "w+"); - if (res) return res; - return cfg_save(h,cl); - } - return -1; -} - - -int cfg_read(CfgHandle *h, int cl){ - if (h && h->file){ - char *gname = NULL; - FILE* file = h->file; - int offset; - char *line = (char*)malloc(_CFG_MAX_LINE_SIZE); - while ((line = fgets(line, _CFG_MAX_LINE_SIZE, file)) != NULL) { - for (offset = strlen(line); offset > 0 && isspace(line[offset-1]); line[--offset] = '\0'); - for (offset = 0;isspace(line[offset]); offset++); - switch (line[offset]) { - case '#': - case '\0': break; - case '[': - free (gname); - gname = strdup(line+offset+1); - gname[strlen(gname)-1] = '\0'; - cfg_group_new(h, gname); - break; - default: { - char *k, *v, *vo, *p; - size_t len; - int i; - p = strchr(line+offset, '='); - if (p) { - len = (size_t)(p - (line+offset) + 1); - k = (char*)malloc(len); - k = strncpy(k, line+offset, len); - k[len-1] = '\0'; - for (i = strlen(k); i > 0 && isspace(k[i-1]); k[--i] = '\0'); - v = (char*)malloc(strlen(p+1)+1); - /* v = (char*)malloc(strlen(p+1)); */ - v = strcpy(v, p+1); - for (vo = v; isspace(vo[0]); vo++); - /* for (vo = v+1; isspace(vo[0]); vo++); */ - cfg_key_new_with_value(h, gname, k, vo); - free (v); - } else { - len = (size_t)(strlen(line) - offset + 1); - k = (char*)malloc(len); - k = strncpy(k, line+offset, len); - k[len-1] = '\0'; - vo = NULL; - cfg_key_new_with_value(h, gname, k, vo); - } - - free (k); - } - } - } - free (line); - free (gname); - if (cl) return cfg_close(h); - return 0; - } - return -1; -} - - -int cfg_open_file(CfgHandle* h, const char* filename, int reportErrors, const char* mode){ - if ((h->file = fopen (filename, mode)) != NULL) { - return 0; - } else { - if (reportErrors) { - fprintf (stderr, "Can't open configuration file \"%s\": %s\n", - filename, strerror (errno)); - } - return -1; - } -} - -char * -cfg_find_file(char **files, char **pathes) -{ - /* e.g.: - char *files[] = { ".blarc", "blarc", "bla", NULL }; - char *pathes[] = { "/", "/usr/etc/", "/etc/", NULL }; */ - char **file, **path = pathes; - char *options_file = NULL, *help = NULL; - struct stat s; - - while (*path) { - file = files; - while(*file) { - free(options_file); - options_file = (char *)malloc(sizeof(char) * ( - strlen(*path) + - strlen(*file) + 1)); - sprintf(options_file, "%s%s", *path, *file); - help = cfg_resolve_path(options_file); - if (!stat(help, &s)) { - free(options_file); - return help; - } - free(help); - file++; - } - path++; - } - free(options_file); - - return NULL; -} - -int -cfg_open_user_file(CfgHandle *h, const char* filename, - int reportErrors, const char* mode) -{ - char *fn = cfg_resolve_path(filename); - int ret = cfg_open_file(h, fn, reportErrors, mode); - - free(fn); - - return ret; -} - -int cfg_open(CfgHandle* h, int reportErrors, const char* mode){ - int res; - const char *filename; - if (!h || !h->filename || !mode) return -1; - filename = h->filename; - if (filename[0] == '~') { - /* Absolute Path of a Users HomeDir */ - res = cfg_open_user_file (h, filename, reportErrors, mode); - } else if (filename[0] == '/') { - /* Absolute pathname: try it - there are no alternatives */ - res = cfg_open_file (h, filename, reportErrors, mode); - } else { - /* Relative pathname: try current directory first */ - res = cfg_open_file (h, filename, 0, mode); - } - return res; -} - -int cfg_open_read (CfgHandle *handle, const char* filename, int err, int cl){ - if (handle && filename) { - int res; - res = cfg_handle_change_filename(handle, filename); - if (res) return res; - res = cfg_open(handle, err, "r"); - if (res) return res; - return cfg_read(handle,cl); - } - else return -1; -} - -int cfg_close (CfgHandle* h){ - if (!h || !h->file) return -1; - fclose (h->file); - h->file = NULL; - return 0; -} - - -/*************************************************** - * commons - ***************************************************/ - -CfgGroup* cfg_find_group(CfgHandle* h, const char* g){ - CfgGroup *tmp; - if (h == NULL || g == NULL) return NULL; - tmp = h->first; - while (tmp && strcmp(tmp->name, g) != 0) tmp = tmp->next; - return tmp; -} - -CfgKey* cfg_find_key(CfgGroup* g, const char* key){ - CfgKey* tmp; - if (g == NULL || key == NULL) return NULL; - tmp = g->first; - while (tmp && strcmp(tmp->name, key) != 0) tmp = tmp->next; - return tmp; -} - -/*************************************************** - * cfg_handle_... - ***************************************************/ - -CfgHandle* cfg_handle_new_with_filename (const char* filename, int read){ - CfgHandle* h; - h = (CfgHandle*)malloc(sizeof(CfgHandle)); - if (!h) return NULL; - - h->filename = filename ? strdup(filename) : NULL; - h->file = NULL; - h->first = h->last = NULL; - - if (read) { - int r = cfg_open_read(h, filename, 0, 1); - if (r != 0) { - cfg_handle_free(h); - return NULL; - } - } - - return h; -} - -CfgHandle* cfg_handle_new (){ - return cfg_handle_new_with_filename(NULL,0); -} - - -int cfg_handle_change_filename(CfgHandle *h, const char* filename){ - if (h && filename) { - if (h->file) return -2; - free (h->filename); - h->filename = strdup(filename); - return 0; - } - else return -1; -} - - -int cfg_handle_add_group(CfgHandle* h, CfgGroup* g){ - if (h && g) { - CfgGroup* last = h->last; - if (last) { - last->next = g; - g->prev = last; - } else { - h->first = g; - } - h->last = g; - g->pp = h; - return 0; - } - else - return -1; -} - -void cfg_handle_free (CfgHandle* h){ - CfgGroup *ga, *gb; - CfgKey *ka, *kb; - if (!h) return; - ga = h->first; - if (h->file) fclose (h->file); - while (ga){ - gb = ga->next; - ka = ga->first; - while (ka) { - kb = ka->next; - free (ka->name); - free (ka->value); - free (ka); - ka = kb; - } - free (ga->name); - free (ga); - ga = gb; - } - free (h); -} - - -/*************************************************** - * cfg_group_... - ***************************************************/ - -int cfg_group_exist(CfgHandle* h, const char* name){ - if (h == NULL || name == NULL) - return -1; - else { - CfgGroup* tmp = h->first; - while (tmp && strcmp(tmp->name,name) != 0 ) - tmp = tmp->next; - if (tmp != NULL) return -1; - } - return 0; -} - -int cfg_group_new (CfgHandle* handle, const char* name){ - if (cfg_find_group(handle, name) == NULL) { - CfgGroup* g = (CfgGroup*)malloc(sizeof(CfgGroup)); - if (!g) return -1; - g->name = strdup(name); - g->prev = NULL; - g->next = NULL; - g->first = NULL; - g->last = NULL; - g->pp = NULL; - return cfg_handle_add_group(handle, g); - } else - return -1; -} - -int cfg_group_add_key(CfgGroup* g, CfgKey* k){ - if (g && k) { - CfgKey* last = g->last; - if (last) { - last->next = k; - k->prev = last; - } else { - g->first = k; - } - - g->last = k; - k->pp = g; - return 0; - } else - return -1; -} - -void cfg_group_free(CfgHandle* h, const char* name){ - if (h && name) { - CfgGroup *tmp, *prev, *next; - CfgKey *a, *b; - tmp = cfg_find_group(h, name); - if (!tmp) return; - - a = tmp->first; - while (a) { - b = a->next; - free (a->name); - free (a->value); - free (a); - a = b; - } - - prev = tmp->prev; - next = tmp->next; - - free (tmp->name); - if (prev) { - prev->next = next; - } else { - tmp->pp->first= next; - } - - if (next) { - next->prev = prev; - } else { - tmp->pp->last = prev; - } - - free(tmp); - } -} - -/*************************************************** - * cfg_key_... - ***************************************************/ - -int -cfg_key_new (CfgHandle* h, const char* g, const char* key) -{ - CfgGroup *group; - if ((group = cfg_find_group(h, g)) == NULL) return -1; - // if (cfg_find_key(group, key) != NULL) return -1; - if (h && g && key) { - CfgKey* k = (CfgKey*)malloc(sizeof(CfgKey)); - if (!k) return -1; - k->name = strdup(key); - k->value = NULL; - k->prev = NULL; - k->next = NULL; - k->pp = NULL; - return cfg_group_add_key(group, k); - } else - return -1; -} - -int -cfg_key_new_with_value(CfgHandle* h, const char* g, const char* key, - const char* value) -{ - if (cfg_key_new (h, g, key) == 0) { - CfgKey* tmp = cfg_find_group(h, g)->last; - if (!tmp) return -1; - tmp->value = ((value == NULL) ? NULL : strdup(value)); - return 0; - } else - return -1; -} - -int -cfg_key_set_value(CfgHandle* h, const char* g, const char* key, - const char* value) -{ - if (h && g && key && value) { - CfgKey* tmp = cfg_find_key(cfg_find_group(h,g), key); - if (!tmp) return -1; - free (tmp->value); - tmp->value = ((value == NULL) ? NULL : strdup(value)); - return 0; - } else return -1; -} - -int -cfg_key_set_uint_value (CfgHandle *h, const char* g, const char* key, - unsigned int value) -{ - char dest[30]; - sprintf(dest,"%ud", value); - return cfg_key_set_value(h, g, key, dest); -} - -int -cfg_key_set_int_value (CfgHandle *h, const char* g, const char* key, - int value) -{ - char dest[30]; - sprintf(dest,"%d", value); - return cfg_key_set_value(h, g, key, dest); -} - -int -cfg_key_set_double_value (CfgHandle *h, const char* g, const char* key, - double value) -{ - char dest[30]; - sprintf(dest,"%e",value); - return cfg_key_set_value(h, g, key, dest); -} - -int -cfg_key_set_float_value (CfgHandle *h, const char* g, const char* key, - float value) -{ - char dest[30]; - sprintf(dest,"%f",value); - return cfg_key_set_value(h, g, key, dest); -} - -int -cfg_key_set_bool_value (CfgHandle *h, const char* g, const char* key, - bool value) -{ - char dest[2]; - sprintf(dest, "%1d", value); - return cfg_key_set_value(h, g, key, dest); -} - -int -cfg_key_set_char_value (CfgHandle *h, const char* g, const char* key, - char value) -{ - char dest[2]; - sprintf(dest, "%c",value); - return cfg_key_set_value(h, g, key, dest); -} - -const char* -cfg_key_get_value(CfgHandle* h, const char* g, const char* key) -{ - if (h && g && key) { - CfgKey* tmp = cfg_find_key(cfg_find_group(h,g), key); - if (!tmp) return NULL; - return tmp->value; - } else - return NULL; -} - -int -cfg_key_get_value_as_bool(CfgHandle* h, const char* g, const char* key, - bool* res){ - char *endptr; - const char *nptr = cfg_key_get_value(h, g, key); - if (!nptr) return -1; - if (!strcasecmp(nptr, "yes") || !strcasecmp(nptr, "true")) - *res = TRUE; - else - *res = FALSE; - - return (int)*endptr; -} - -int -cfg_key_get_value_as_uint(CfgHandle* h, const char* g, const char* key, - unsigned int* res){ - char *endptr; - const char *nptr = cfg_key_get_value(h, g, key); - if (!nptr) return -1; - *res = (unsigned int)strtoul(nptr, &endptr, 10); - return (int)*endptr; -} - -int -cfg_key_get_value_as_int(CfgHandle* h, const char* g, const char* key, - int* res) -{ - char *endptr; - const char *nptr = cfg_key_get_value(h, g, key); - if (!nptr) return -1; - *res = (int)strtol(nptr, &endptr, 10); - return (int)*endptr; -} - -int -cfg_key_get_value_as_ushort(CfgHandle* h, const char* g, const char* key, - unsigned short* res) -{ - char *endptr; - const char *nptr = cfg_key_get_value(h, g, key); - if (!nptr) return -1; - *res = (unsigned short)strtoul(nptr, &endptr, 10); - return (int)*endptr; -} - -int -cfg_key_get_value_as_short(CfgHandle* h, const char* g, const char* key, - short* res) -{ - char *endptr; - const char *nptr = cfg_key_get_value(h, g, key); - if (!nptr) return -1; - *res = (short)strtol(nptr, &endptr, 10); - return (int)*endptr; -} - -int -cfg_key_get_value_as_double(CfgHandle* h, const char* g, const char* key, - double* res) -{ - char *endptr; - const char *nptr = cfg_key_get_value(h, g, key); - if (!nptr) return -1; - *res = (double)strtod(nptr, &endptr); - return (int)*endptr; -} - -int -cfg_key_get_value_as_float(CfgHandle* h, const char* g, const char* key, - float* res) -{ - char *endptr; - const char *nptr = cfg_key_get_value(h, g, key); - if (!nptr) return -1; - *res = (float)strtod(nptr, &endptr); - return (int)*endptr; -} - -void -cfg_key_free (CfgHandle* h, const char* g, const char* key) -{ - if (h && g && key) { - CfgKey *tmp, *prev, *next; - tmp = cfg_find_key(cfg_find_group(h,g), key); - if (!tmp) return; - prev = tmp->prev; - next = tmp->next; - - free (tmp->name); - free (tmp->value); - - if (prev) { - prev->next = next; - } else { - tmp->pp->first = next; - } - - if (next) { - next->prev = prev; - } else { - tmp->pp->last = prev; - } - - free (tmp); - } -} - -void -cfg_key_for_each (CfgHandle* h, const char* grp, cfg_key_func func) -{ - CfgGroup *tmp = cfg_find_group(h,grp); - - if (tmp && func) { - CfgKey *k = tmp->first; - while(k) func(k), k = k->next; - } -} diff --git a/mpiosh/cfgio.h b/mpiosh/cfgio.h deleted file mode 100644 index d58cd3f..0000000 --- a/mpiosh/cfgio.h +++ /dev/null @@ -1,453 +0,0 @@ -/* configreader and -writer - * - * Source in ANSI C, except function strdup - * needs _BSD_SOURCE or _SVID_SOURCE defined, if compiled ANSI - * Thomas Buntrock (bunti@tzi.de) - * - * Comments in configfile are allowed, but ONLY at the BEGINNING of a line - * When reading a config then writing the same, all comments will be removed - * - * The groupname MUST be put exactly between two square braces, e.g. [Name]. - * Any Spaces in between are interpreted as part of the name. - * - * Keys and their value are separated by "=". Leading and following spaces - * are removed. - * Spaces right before and after the "=" are removed. Spaces in the value - * will remain. - * Keys without value are accepted, BUT the "=" is MANDATORY. - * - * A config line MUST NOT be longer than _CFG_MAX_LINE_SIZE (default: 256) - * - */ - -#ifndef _CFG_IO_H -#define _CFG_IO_H - -#include -#include -#include -#include -#include -#include -#include - -#define _CFG_MAX_LINE_SIZE 256 - -/* define bool */ -#ifndef TRUE -#define TRUE 1 -#define FALSE 0 -#endif - -typedef unsigned char bool; - -struct _CFG_Key { - char *name; - char *value; - struct _CFG_Key* prev; - struct _CFG_Key* next; - struct _CFG_Group* pp; -}; - -struct _CFG_Group { - char *name; - struct _CFG_Group* prev; - struct _CFG_Group* next; - struct _CFG_Key* first; - struct _CFG_Key* last; - struct _CFG_Handle* pp; -}; - -struct _CFG_Handle { - FILE *file; - char *filename; - struct _CFG_Group *first; - struct _CFG_Group *last; -}; - - -typedef struct _CFG_Key CfgKey; -typedef struct _CFG_Group CfgGroup; -typedef struct _CFG_Handle CfgHandle; -typedef int (*cfg_key_func)(CfgKey *key); - -char *cfg_resolve_path(const char *filename); - -/* - * files: a list of files - * e.g. char *files[] = { ".blarc", ".bla", "blarc", NULL }; - * - * paths: a list of paths - * e.g. char *paths[] = { "~/", "/etc/" "etc/", NULL}; - * - * select the first path and iterates through the files, - * then select the next path... - * - * returns the first match of: path/file - */ -char *cfg_find_file (char **files, char **paths); - -/* - * Save the config - * - * close: close the file after saving - * - * returns 0 on success or -1 on failure - */ -int cfg_save (CfgHandle *handle, int close); - -/* - * Save the config with another filename - * - * handle : the config handle - * filename : the new filename - * reportErrors: 0 does not report errors the stderr - * close : close the file after saving - * - * returns 0 on success or -1 on failure - */ -int cfg_save_as (CfgHandle *handle, const char* filename, - int reportErrors, int close); -/* - * Read config file - * requires the Handle to be associated to a file and being opened - * - * handle: the config handle - * close : close the file after reading - * - * returns 0 on success or -1 on failure - */ -int cfg_read (CfgHandle *handle, int close); - -/* - * Open a file to read or save - * - * handle : the config handle - * reportErrors: write errors to stderr - * mode : the mode the file should be opened with (man 3 fopen) - * - * returns 0 on success or -1 on failure - */ -int cfg_open (CfgHandle *handle, int reportErrors, - const char* mode); -/* - * Open a file in read mode - * - * handle : the config handle - * filename : the filename of the config file - * reportErrors: write errors to stderr - * close : close the file after reading - * - * returns 0 on success or -1 on failure - */ -int cfg_open_read (CfgHandle *handle, const char* filename, - int reportErrors, int close); -/* - * Close the file - * - * h: the config handle - * - * returns 0 on success or -1 if the handle was NULL or the was already closed - */ -int cfg_close (CfgHandle *h); - -/* - * Create a new empty file handle - * - * returns the pointer to the new handle - */ -CfgHandle* cfg_handle_new (); - -/* - * Create a new filehandle - * - * filename: the filename of the configfile - * read : read the config file - * - * returns the pointer to the new handle - */ -CfgHandle* cfg_handle_new_with_filename (const char* filename, int read); - -/* - * Change the filename of the config file - * only the internal filename ist changed, to apply on disk you need to call - * cfg_save - * - * filename: new filename - * - * returns 0 on success or -1 on failure - */ -int cfg_handle_change_filename (CfgHandle *h, const char* filename); - -/* - * Delete the handle - * An opened file will be closed - * - * h: the config handle - */ -void cfg_handle_free (CfgHandle* h); - -/* - * Create a new group within the config - * - * handle: the config handle - * name : name of the group - * - * returns 0 on success or -1 on failure - */ -int cfg_group_new (CfgHandle* handle, const char* name); - -/* - * Delete a group within the config - * All keys within this group will be delete as well - * - * handle: the config handle - * name : the name of the group - */ -void cfg_group_free (CfgHandle* handle, const char* name); - -/* - * returns a handle to the group g if found. - * - * handle: the config handle - * name : the name of the group to search for - */ -CfgGroup* cfg_find_group(CfgHandle* h, const char* g); - -/* - * Create a new key within a group within the config - * - * h : the config handle - * g : name of the group - * key: name of the key - * - * returns 0 on success or -1 on failure - */ -int cfg_key_new (CfgHandle* h, const char* g, const char* key); - -/* - * Create a new key within the group within the config and set its value - * - * h : the config handle - * g : name of the group - * key : name of the key - * value: value for the key - * - * returns 0 on success or -1 on failure - */ -int cfg_key_new_with_value (CfgHandle* h, const char* g, const char* key, - const char* value); - -/* - * Set the value for a specific key within a group of the config - * - * h : the config handle - * g : name of the group - * key : name of the key - * value: value for the key - * - * returns 0 on success or -1 on failure - */ -int cfg_key_set_value (CfgHandle* h, const char* g, const char* key, - const char* value); - -/* - * Set the value for a specific key within a group of the config - * - * h : the config handle - * g : name of the group - * key : name of the key - * value: value for the key - * - * returns 0 on success or -1 on failure - */ -int cfg_key_set_uint_value (CfgHandle *h, const char* g, const char* key, - unsigned int value); - -/* - * Set the value for a specific key within a group of the config - * - * h : the config handle - * g : name of the group - * key : name of the key - * value: value for the key - * - * returns 0 on success or -1 on failure - */ -int cfg_key_set_int_value (CfgHandle *h, const char* g, const char* key, - int value); - -/* - * Set the value for a specific key within a group of the config - * - * h : the config handle - * g : name of the group - * key : name of the key - * value: value for the key - * - * returns 0 on success or -1 on failure - */ -int cfg_key_set_double_value (CfgHandle *h, const char* g, const char* key, - double value); - -/* - * Set the value for a specific key within a group of the config - * - * h : the config handle - * g : name of the group - * key : name of the key - * value: value for the key - * - * returns 0 on success or -1 on failure - */ -int cfg_key_set_float_value (CfgHandle *h, const char* g, const char* key, - float value); - -/* - * Set the value for a specific key within a group of the config - * - * h : the config handle - * g : name of the group - * key : name of the key - * value: value for the key - * - * returns 0 on success or -1 on failure - */ -int cfg_key_set_bool_value (CfgHandle *h, const char* g, const char* key, - bool value); - -/* - * Set the value for a specific key within a group of the config - * - * h : the config handle - * g : name of the group - * key : name of the key - * value: value for the key - * - * returns 0 on success or -1 on failure - */ -int cfg_key_set_char_value (CfgHandle *h, const char* g, const char* key, - char value); - -/* - * Delete a key of a group within the config - * - * h : the config handle - * g : name of the group - * key : name of the key - */ -void cfg_key_free (CfgHandle* h, const char* g, const char* key); - -/* - * Get the value of a key within a group of the config - * - * h : the config handle - * g : name of the group - * key: name of the key - * res: the result will be stored in this variable - * - * returns 0 on success or -1 on failure - */ -int cfg_key_get_value_as_bool (CfgHandle* h, const char* g, const char* key, - bool *res); - -/* - * Get the value of a key within a group of the config - * - * h : the config handle - * g : name of the group - * key: name of the key - * res: the result will be stored in this variable - * - * returns 0 on success or -1 on failure - */ -int cfg_key_get_value_as_uint (CfgHandle* h, const char* g, const char* key, - unsigned int *res); - -/* - * Get the value of a key within a group of the config - * - * h : the config handle - * g : name of the group - * key: name of the key - * res: the result will be stored in this variable - * - * returns 0 on success or -1 on failure - */ -int cfg_key_get_value_as_int (CfgHandle* h, const char* g, const char* key, - int *res); - -/* - * Get the value of a key within a group of the config - * - * h : the config handle - * g : name of the group - * key: name of the key - * res: the result will be stored in this variable - * - * returns 0 on success or -1 on failure - */ -int cfg_key_get_value_as_ushort (CfgHandle* h, const char* g, const char* key, - unsigned short *res); - -/* - * Get the value of a key within a group of the config - * - * h : the config handle - * g : name of the group - * key: name of the key - * res: the result will be stored in this variable - * - * returns 0 on success or -1 on failure - */ -int cfg_key_get_value_as_short (CfgHandle* h, const char* g, const char* key, - short *res); - -/* - * Get the value of a key within a group of the config - * - * h : the config handle - * g : name of the group - * key: name of the key - * res: the result will be stored in this variable - * - * returns 0 on success or -1 on failure - */ -int cfg_key_get_value_as_double (CfgHandle* h, const char* g, const char* key, - double *res); - -/* - * Get the value of a key within a group of the config - * - * h : the config handle - * g : name of the group - * key: name of the key - * res: the result will be stored in this variable - * - * returns 0 on success or -1 on failure - */ -int cfg_key_get_value_as_float (CfgHandle* h, const char* g, const char* key, - float *res); - -/* - * Get the value of a key within a group of the config - * - * h : the config handle - * g : name of the group - * key: name of the key - * - * returns the value of the key or NULL if empty - */ -const char* cfg_key_get_value (CfgHandle* h, const char* g, const char* key); - -/* - * iterators through key value pairs of a group - * - * h : the config handle - * grp : name of the group - * func: pointer to the function to call with each element - * - * returns the value of the key or NULL if empty - */ -void cfg_key_for_each (CfgHandle* h, const char* grp, cfg_key_func func); -#endif /* _CFG_IO_H */ diff --git a/mpiosh/command.c b/mpiosh/command.c deleted file mode 100644 index 9c42a8c..0000000 --- a/mpiosh/command.c +++ /dev/null @@ -1,222 +0,0 @@ -/* command.c - * - * Author: Andreas Buesching - * - * $Id: command.c,v 1.3 2002/10/29 20:03:35 crunchy Exp $ - * - * Copyright (C) 2001 Andreas Büsching - * - * 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; -} - -struct mpiosh_cmd_t * -mpiosh_command_find(char *line) -{ - struct 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; - } else if (cmd->aliases) { - char **go = cmd->aliases; - while (*go) { - if ((strstr(line, *go) == line) && - ((line[strlen(*go)] == ' ') || (line[strlen(*go)] == '\0'))) { - return cmd; - } - go++; - } - } - - 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 deleted file mode 100644 index 34dbc9b..0000000 --- a/mpiosh/command.h +++ /dev/null @@ -1,38 +0,0 @@ -/* command.h - * - * Author: Andreas Buesching - * - * $Id: command.h,v 1.2 2002/10/29 20:03:35 crunchy Exp $ - * - * Copyright (C) 2001 Andreas Büsching - * - * 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 */ -struct 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/config.h.in b/mpiosh/config.h.in deleted file mode 100644 index bb60f14..0000000 --- a/mpiosh/config.h.in +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _CONFIG_H -#define _CONFIG_H - -/* package name */ -#define PACKAGE "${PACKAGE}" -#define VERSION "0.7.1-pre3" -#define SYSCONFDIR "/etc" - -#endif /* _CONFIG_H */ diff --git a/mpiosh/global.c b/mpiosh/global.c deleted file mode 100644 index 04fd9e7..0000000 --- a/mpiosh/global.c +++ /dev/null @@ -1,159 +0,0 @@ -/* global.c - containing global symbols for mpiosh - * - * Author: Andreas Buesching - * - * $Id: global.c,v 1.14 2003/06/27 12:21:21 crunchy Exp $ - * - * Copyright (C) 2001 Andreas Büsching - * - * 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 "callback.h" -#include "global.h" -#include "readline.h" -#include "cfg.h" - -/* structure containing current state */ -struct mpiosh_t mpiosh; -struct mpiosh_config_t config; - -/* flag indicating a user-interrupt of the current command */ -int mpiosh_cancel = 0; -int mpiosh_cancel_ack = 0; - -/* configuration filenames */ -const char *CONFIG_GLOBAL = SYSCONFDIR "/mpio/"; -const char *CONFIG_USER = "~/.mpio/"; -const char *CONFIG_BACKUP = "~/.mpio/backup/"; -const char *CONFIG_FILE = "mpioshrc"; -const char *CONFIG_HISTORY = "history"; - -/* prompt strings */ -const char *PROMPT_INT = "\033[;1mmpio \033[m "; -const char *PROMPT_EXT = "\033[;1mmpio \033[m "; - -struct mpiosh_cmd_t commands[] = { - { "debug", NULL , "[level|file|on|off] ", - " modify debugging options", - mpiosh_cmd_debug, NULL }, - { "ver", NULL, NULL, - " version of mpio package", - mpiosh_cmd_version, NULL }, - { "help", (char *[]){ "?", NULL }, "[]", - " show information about known commands or just about ", - mpiosh_cmd_help, mpiosh_readline_comp_cmd }, - { "dir", (char *[]){ "ls", "ll", NULL }, NULL, - " list content of current memory card", - mpiosh_cmd_dir, NULL }, - { "pwd", NULL, NULL, - " print the current working directory", - mpiosh_cmd_pwd, NULL }, - { "mkdir", (char *[]){ "md", NULL }, "", - " make a new directory", - mpiosh_cmd_mkdir, mpiosh_readline_comp_mpio_file }, - { "cd", NULL, "", - " change the current working directory", - mpiosh_cmd_cd, mpiosh_readline_comp_mpio_file }, - { "info", NULL, NULL, - " show information about MPIO player", - mpiosh_cmd_info, NULL }, - { "mem", NULL, "[i|e]", - " 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, NULL, - " open connect to MPIO player", - mpiosh_cmd_open, NULL }, - { "close", NULL, NULL, - " close connect to MPIO player", - mpiosh_cmd_close, NULL }, - { "quit", (char *[]){ "exit", NULL }, NULL, - " exit mpiosh and close the device", - mpiosh_cmd_quit, NULL }, - { "mget", (char *[]){ "get", NULL }, "list of filenames and ", - " read all files matching the regular expression\n" - " from the selected memory card", - mpiosh_cmd_mget, mpiosh_readline_comp_mpio_file }, - { "mput", (char *[]){ "put", NULL }, "list of filenames and ", - " write all local files matching the regular expression\n" - " to the selected memory card", - mpiosh_cmd_mput, NULL }, - { "mdel", (char *[]){ "rm", "del", NULL }, "", - " deletes all files matching the regular expression\n" - " from the selected memory card", - mpiosh_cmd_mdel, mpiosh_readline_comp_mpio_file }, - { "dump", NULL, NULL, - " get all files of current memory card", - mpiosh_cmd_dump, NULL }, - { "free", NULL, NULL, - " display amount of available bytes of current memory card", - mpiosh_cmd_free, NULL }, - { "format", NULL, NULL, - " format current memory card", - mpiosh_cmd_format, NULL }, - { "switch", NULL, " ", - " switches the order of two files", - mpiosh_cmd_switch, mpiosh_readline_comp_mpio_file }, - { "rename", (char *[]){ "ren", NULL }, " ", - " renames a file on the current memory card", - mpiosh_cmd_rename, mpiosh_readline_comp_mpio_file }, - { "ldir", (char *[]){ "lls", NULL }, NULL, - " list local directory", - mpiosh_cmd_ldir, NULL }, - { "lpwd", NULL, NULL, - " print current working directory", - mpiosh_cmd_lpwd, NULL }, - { "lcd", NULL, NULL, - " change the current working directory", - mpiosh_cmd_lcd, NULL }, - { "lmkdir", NULL, NULL, - " create a local directory", - mpiosh_cmd_lmkdir, NULL }, - { "health", NULL, NULL, - " show the health status from the selected memory", - mpiosh_cmd_health, NULL }, - { "font_upload", NULL, "[]", - " upload the give fontfile to the internal memory", - mpiosh_cmd_font_upload, NULL }, - { "dump_memory", NULL, NULL, - " dump FAT, directory, spare area and the first 0x100 of the\n" - " selected memory card", - mpiosh_cmd_dump_mem, NULL }, - { "backup", NULL, NULL, - " create a backup of all known configuration files.", - mpiosh_cmd_backup, NULL }, - { "restore", NULL, NULL, - " restore an existing backup of all known configuration files.", - mpiosh_cmd_restore, NULL }, -#if 0 - /* deactivated for the 0.6.0 release because the code is incomplete! -mager */ - { "config", (char *[]) { "conf", NULL }, "[read|write|show]", - " give access to the configuration file of the MPIO player\n" - " read read the configuration file and dump it on the local disc\n" - " write write the configuration back to the MPIO player\n" - " show show the current configuration", - mpiosh_cmd_config, mpiosh_readline_comp_config }, - { "channel", (char *[]) { "channels", "chan", NULL }, "[read|write|show]", - " give access to the radio channel file of the MPIO player\n" - " read read the channel file and dump it on the local disc\n" - " write write the channel file back to the MPIO player\n" - " show show the current channel configuration", - mpiosh_cmd_channel, mpiosh_readline_comp_config }, -#endif - { NULL, NULL, NULL, NULL, NULL, NULL } -}; - -/* end of global.c */ diff --git a/mpiosh/global.h b/mpiosh/global.h deleted file mode 100644 index 1e52491..0000000 --- a/mpiosh/global.h +++ /dev/null @@ -1,68 +0,0 @@ -/* global.h - * - * Author: Andreas Buesching - * - * $Id: global.h,v 1.3 2003/06/27 12:21:22 crunchy Exp $ - * - * Copyright (C) 2001-2003 Andreas Büsching - * - * 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_GLOBAL_HH -#define MPIOSH_GLOBAL_HH - -#include "libmpio/mpio.h" - -#include "config.h" - -/* type definitions */ -typedef void(*mpiosh_cmd_callback_t)(char *args[]); -typedef char *(*mpiosh_comp_callback_t)(const char *text, int state); - -struct mpiosh_t { - mpio_t * dev; - mpio_mem_t card; - const char * prompt; - struct mpiosh_config_t *config; -}; - -struct mpiosh_cmd_t { - char *cmd; - char **aliases; - char *args; - char *info; - mpiosh_cmd_callback_t cmd_func; - mpiosh_comp_callback_t comp_func; -}; - -/* global structures */ -extern struct mpiosh_t mpiosh; -extern struct mpiosh_cmd_t commands[]; -extern int mpiosh_cancel; -extern int mpiosh_cancel_ack; - -extern const char *CONFIG_GLOBAL; -extern const char *CONFIG_USER; -extern const char *CONFIG_BACKUP; -extern const char *CONFIG_FILE; -extern const char *CONFIG_HISTORY; - -extern const char *PROMPT_INT; -extern const char *PROMPT_EXT; - -#endif - -/* end of global.h */ diff --git a/mpiosh/mpiosh.c b/mpiosh/mpiosh.c deleted file mode 100644 index e74278d..0000000 --- a/mpiosh/mpiosh.c +++ /dev/null @@ -1,163 +0,0 @@ -/* -*- linux-c -*- */ - -/* - * - * $Id: mpiosh.c,v 1.27 2003/08/25 19:38:57 crunchy Exp $ - * - * Author: Andreas Büsching - * - * 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 -#include -#include -#include - -#include "libmpio/debug.h" -#include "libmpio/mpio.h" - -#include "callback.h" -#include "command.h" -#include "cfg.h" -#include "readline.h" -#include "mpiosh.h" - -/* mpiosh core functions */ -void -mpiosh_init(void) -{ - /* set state */ - mpiosh.dev = NULL; - mpiosh.config = NULL; - mpiosh.prompt = NULL; - - /* read configuration */ - mpiosh.config = mpiosh_config_new(); - if (mpiosh.config) - mpiosh_config_read(mpiosh.config); - - mpiosh.card = mpiosh.config->default_mem; - if (mpiosh.config->default_mem == MPIO_EXTERNAL_MEM) - mpiosh.prompt = mpiosh.config->prompt_ext; - else - mpiosh.prompt = mpiosh.config->prompt_int; - - /* inital mpio library */ - mpiosh.dev = mpio_init(mpiosh_callback_init); - - printf("\n"); - - if ((mpiosh.dev) && (mpiosh.config->charset)) - mpio_charset_set(mpiosh.dev, mpiosh.config->charset); -} - -void -mpiosh_signal_handler(int signal) -{ - mpiosh_cancel = 1; - mpiosh_cancel_ack = 0; -} - -int -main(int argc, char *argv[]) { - char *line; - char **cmds, **walk; - struct mpiosh_cmd_t *cmd; - struct sigaction sigc; - int interactive = 1; - - UNUSED(argc); - UNUSED(argv); - - setenv("mpio_debug", "", 0); - setenv("mpio_color", "", 0); - - /* no unwanted interruption anymore */ - sigc.sa_handler = mpiosh_signal_handler; - sigc.sa_flags = SA_NOMASK; - - sigaction(SIGINT, &sigc, NULL); - - /* init readline and history */ - mpiosh_readline_init(); - debug_init(); - mpiosh_init(); - - if (!isatty(fileno(stdin))) { - interactive = 0; - mpiosh.prompt = NULL; - mpiosh_readline_pipe(); - } - - if( !isatty(fileno(stdout)) ) { - setvbuf( stdout, NULL, _IOLBF, 256 ); - } - - if (!mpiosh.dev && interactive) { - printf("ERROR: %s\n", mpio_strerror(mpio_errno())); - printf("could not find MPIO player.\n"); - } - - while ((line = readline(mpiosh.prompt))) { - if ((*line == '\0') || mpiosh_cancel) { - rl_clear_pending_input (); - mpiosh_cancel = 0; - mpiosh_cancel_ack = 0; - continue; - } - - cmds = mpiosh_command_split_line(line); - - if (cmds[0][0] == '\0') { - free(cmds); - continue; - } - - walk = cmds; - while (*walk) { - cmd = mpiosh_command_find(*walk); - - if (cmd) { - char ** help, **args = mpiosh_command_get_args(*walk); - help = args; - - if (!interactive) debug("running... '%s'\n", *walk); - cmd->cmd_func(args); - mpiosh_command_free_args(args); - } else - fprintf(stderr, "unknown command: '%s'\n", *walk); - -/* if ((idx = history_search(line, -1)) != -1) */ -/* history_set_pos(idx); */ -/* else */ - add_history(line); - free(*walk); - walk++; - } - free(cmds); - - /* reset abort state */ - mpiosh_cancel = 0; - } - - mpiosh_cmd_quit(NULL); - - return 0; -} diff --git a/mpiosh/mpiosh.h b/mpiosh/mpiosh.h deleted file mode 100644 index 8291178..0000000 --- a/mpiosh/mpiosh.h +++ /dev/null @@ -1,37 +0,0 @@ -/* mpiosh.h - * - * Author: Andreas Büsching - * - * $Id: mpiosh.h,v 1.8 2002/10/12 20:06:22 crunchy Exp $ - * - * Copyright (C) 2002 Andreas Büsching - * - * 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_ - -#include "libmpio/debug.h" - -#include "global.h" - -/* mpiosh core functions */ -void mpiosh_signal_handler(int signal); -void mpiosh_init(void); - -#endif // _MPIOSH_H_ - -/* end of mpiosh.h */ diff --git a/mpiosh/readline.c b/mpiosh/readline.c deleted file mode 100644 index afc78c0..0000000 --- a/mpiosh/readline.c +++ /dev/null @@ -1,212 +0,0 @@ -/* readline.c - * - * Author: Andreas Büsching - * - * $Id: readline.c,v 1.7 2003/04/23 08:34:16 crunchy Exp $ - * - * Copyright (C) 2001 Andreas Büsching - * - * 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_onoff(const char *text, int state) -{ - static const char * states[] = { "on", "off", NULL }; - static const char ** st = states; - const char * ret = NULL; - - if (state == 0) { - st = states; - } - - while (*st) { - if (!strncmp(text, *st, strlen(text))) { - ret = *st; - st++; - break; - } - st++; - } - - return (ret ? strdup(ret) : NULL); -} - -char * -mpiosh_readline_comp_cmd(const char *text, int state) -{ - static struct mpiosh_cmd_t *cmd = NULL; - static char **alias = NULL; - char *cmd_text = NULL; - - if (state == 0) { - cmd = commands; - } - - while (cmd->cmd) { - if (!alias) { - if ((*text == '\0') || (strstr(cmd->cmd, text) == cmd->cmd)) { - cmd_text = strdup(cmd->cmd); - if (cmd->aliases) alias = cmd->aliases; - else cmd++; - break; - } - if (cmd->aliases) alias = cmd->aliases; - else cmd++; - } else { - int break_it = 0; - - while (*alias) { - if (strstr(*alias, text) == *alias) { - cmd_text = strdup(*alias); - alias++; - break_it = 1; - break; - } - alias++; - } - if (break_it) break; - if (*alias == NULL) cmd++, alias = NULL; - } - } - - 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, type; - char fname[100]; - WORD year; - DWORD fsize; - - if (mpiosh.dev == NULL) { - rl_attempted_completion_over = 1; - return NULL; - } - - 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, &type); - - 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_comp_config(const char *text, int state) -{ - static char *args[] = { "put", "write", "show", NULL }; - static char **arg = NULL; - char *res = NULL; - - if (state == 0) arg = args; - if (*arg && (strstr(*arg, text) == *arg)) { - res = strdup(*arg); - arg++; - } - - return res; -} - - -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 { - struct 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 deleted file mode 100644 index a0bb08a..0000000 --- a/mpiosh/readline.h +++ /dev/null @@ -1,47 +0,0 @@ -/* readline.h - * - * Author: Andreas Büsching - * - * $Id: readline.h,v 1.3 2003/04/23 08:34:16 crunchy Exp $ - * - * Copyright (C) 2001 Andreas Büsching - * - * 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 - -#include -#include - -/* 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_onoff(const char *text, int state); -char *mpiosh_readline_comp_mpio_file(const char *text, int state); -char *mpiosh_readline_comp_config(const char *text, int state); - -#endif - -/* end of readline.h */ diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..2e3941e --- /dev/null +++ b/src/.gitignore @@ -0,0 +1,2 @@ +mpiosh +config.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..7132b28 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,10 @@ +set (CMAKE_C_FLAGS -Wall) + +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/config.h) + +include_directories (${CMAKE_CURRENT_SOURCE_DIR}/..) + +add_executable (mpiosh mpiosh.c callback.c readline.c command.c global.c + cfgio.c cfg.c) +target_link_libraries (mpiosh mpio -lreadline -lncurses) diff --git a/src/callback.c b/src/callback.c new file mode 100644 index 0000000..e98a334 --- /dev/null +++ b/src/callback.c @@ -0,0 +1,1273 @@ +/* callback.c + * + * Author: Andreas Büsching + * + * $Id: callback.c,v 1.49 2006/01/21 18:33:20 germeier Exp $ + * + * Copyright (C) 2001 Andreas Büsching + * + * 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 "callback.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mpiosh.h" +#include "command.h" +#include "cfg.h" + +#include "libmpio/debug.h" + +/* helper */ +BYTE +mpiosh_ftype2ascii(BYTE ftype) { + switch(ftype) + { + case FTYPE_CONF: + case FTYPE_FONT: + case FTYPE_OTHER: + case FTYPE_MEMO: + case FTYPE_WAV: + case FTYPE_ENTRY: + case FTYPE_DIR: + case FTYPE_PLAIN: + return ftype; + case FTYPE_DIR_RECURSION: + return 'r'; + case FTYPE_CHAN: + return 'c'; + case FTYPE_MUSIC: + return '-'; + default: + return '?'; + } + return '?'; +} + + +/* 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] \n"); + } + } else { + fprintf(stderr, "error: no arguments given\n"); + printf("debug [level|file|on|off] \n"); + } +} + +void +mpiosh_cmd_version(char *args[]) +{ + UNUSED(args); + + printf("MPIO shell %s\n\n", VERSION); +} + +void +mpiosh_cmd_help(char *args[]) +{ + struct mpiosh_cmd_t *cmd = commands; + int ignore; + + while (cmd->cmd) { + 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->aliases) { + char **go = cmd->aliases; + printf(" alias:\n "); + while(*go) printf(( *(go+1) ? "%s" : "%s, "), *go++); + printf("\n"); + } + + if (cmd->info) + printf(" description:\n%s\n", cmd->info); + else + printf("\n"); + } + cmd++; + } +} + +void +mpiosh_cmd_dir(char *args[]) +{ + BYTE *p; + BYTE month, day, hour, minute, type; + CHAR fname[100]; + WORD year; + DWORD fsize; + + UNUSED(args); + + MPIOSH_CHECK_CONNECTION_CLOSED; + + p = mpio_directory_open(mpiosh.dev, mpiosh.card); + while (p != NULL) { + memset(fname, '\0', 100); + + mpio_dentry_get(mpiosh.dev, mpiosh.card, p, + fname, 100, + &year, &month, &day, + &hour, &minute, &fsize, + &type); + + printf ("%02d.%02d.%04d %02d:%02d %9d %c %s\n", + day, month, year, hour, minute, fsize, + mpiosh_ftype2ascii(type), fname); + + p = mpio_dentry_next(mpiosh.dev, mpiosh.card, p); + } +} + +void +mpiosh_cmd_pwd(char *args[]) +{ + CHAR pwd[INFO_LINE]; + + UNUSED(args); + + MPIOSH_CHECK_CONNECTION_CLOSED; + + mpio_directory_pwd(mpiosh.dev, mpiosh.card, pwd); + printf ("%s\n", pwd); + +} + +void +mpiosh_cmd_mkdir(char *args[]) +{ + CHAR pwd[INFO_LINE]; + BYTE r; + + MPIOSH_CHECK_CONNECTION_CLOSED; + + r=mpio_directory_make(mpiosh.dev, mpiosh.card, args[0]); + if (r != MPIO_OK) + { + mpio_perror("ERROR"); + } + mpio_sync(mpiosh.dev, mpiosh.card); + +} + +void +mpiosh_cmd_cd(char *args[]) +{ + CHAR pwd[INFO_LINE]; + BYTE r; + + MPIOSH_CHECK_CONNECTION_CLOSED; + + if ( args[ 0 ] != NULL ) + r=mpio_directory_cd(mpiosh.dev, mpiosh.card, args[0]); + else + r=mpio_directory_cd(mpiosh.dev, mpiosh.card, "."); + + if (r != MPIO_OK) + { + mpio_perror("ERROR"); + } + + mpio_directory_pwd(mpiosh.dev, mpiosh.card, pwd); + printf ("directory is now: %s\n", pwd); + +} + +void +mpiosh_cmd_info(char *args[]) +{ + mpio_info_t info; + + UNUSED(args); + + MPIOSH_CHECK_CONNECTION_CLOSED; + + 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("model : %s\n", info.model); + printf("memory\n"); + printf(" internal: %s\n", info.mem_internal); + printf(" external: %s\n", info.mem_external); +} + +void +mpiosh_cmd_mem(char *args[]) +{ + DWORD free; + + MPIOSH_CHECK_CONNECTION_CLOSED; + MPIOSH_CHECK_ARG; + + if (!strcmp(args[0], "e")) { + if (mpio_memory_free(mpiosh.dev, MPIO_EXTERNAL_MEM, &free)) { + mpiosh.card = MPIO_EXTERNAL_MEM; + mpiosh.prompt = PROMPT_EXT; + printf("external memory card is selected\n"); + } else { + printf("no external memory card is available\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[]) +{ + MPIOSH_CHECK_CONNECTION_OPEN; + + UNUSED(args); + + mpiosh.dev = mpio_init(mpiosh_callback_init); + + printf("\n"); + + if (mpiosh.dev == NULL) { + mpio_perror("ERROR"); + printf("could not open connection MPIO player\n"); + } + else + printf("connection to MPIO player is opened\n"); + + if ((mpiosh.dev) && (mpiosh.config->charset)) + mpio_charset_set(mpiosh.dev, mpiosh.config->charset); +} + +void +mpiosh_cmd_close(char *args[]) +{ + MPIOSH_CHECK_CONNECTION_CLOSED; + + 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); + + if (mpiosh.config) { + mpiosh_config_write(mpiosh.config); + mpiosh_config_free(mpiosh.config); + } + + exit(0); +} + +BYTE +mpiosh_callback_init(mpio_mem_t mem, int read, int total) +{ + switch(mem) + { + case MPIO_INTERNAL_MEM: + printf("\rinternal memory: " ); + break; + case MPIO_EXTERNAL_MEM: + printf("\rexternal memory: " ); + break; + default: + printf("\runknown memory: " ); + } + + printf("initialized %.2f %% ", ((double) read / total) * 100.0 ); + fflush(stdout); + + return mpiosh_cancel; // continue +} + +BYTE +mpiosh_callback_get(int read, int total) +{ + printf("\rretrieved %.2f %%", ((double) read / total) * 100.0 ); + fflush(stdout); + + if (mpiosh_cancel) + debug ("user cancelled operation\n"); + + return mpiosh_cancel; // continue +} + +/* void */ +/* mpiosh_cmd_get(char *args[]) */ +/* { */ +/* MPIOSH_CHECK_CONNECTION_CLOSED; */ +/* MPIOSH_CHECK_ARG; */ + +/* if (mpio_file_get(mpiosh.dev, mpiosh.card, args[0], */ +/* mpiosh_callback_get) == -1) { */ +/* mpio_perror("error"); */ +/* } */ +/* printf("\n"); */ +/* } */ + +void +mpiosh_cmd_mget(char *args[]) +{ + BYTE * p; + int i = 0, error, ret; + regex_t regex; + CHAR fname[100]; + CHAR errortext[100]; + BYTE month, day, hour, minute, type; + WORD year; + DWORD fsize; + int found; + + MPIOSH_CHECK_CONNECTION_CLOSED; + MPIOSH_CHECK_ARG; + + mpiosh_command_regex_fix(args); + + while (args[i] != NULL) { + if ((error = regcomp(®ex, args[i], REG_NOSUB))) { + regerror(error, ®ex, errortext, 100); + debugn (2, "error in regular expression: %s (%s)\n", args[i], errortext); + } else { + found = 0; + p = mpio_directory_open(mpiosh.dev, mpiosh.card); + while (p != NULL) { + memset(fname, '\0', 100); + mpio_dentry_get(mpiosh.dev, mpiosh.card, p, fname, 100, + &year, &month, &day, &hour, &minute, &fsize, &type); + + if (!(error = regexec(®ex, fname, 0, NULL, 0))) { + found = 1; + printf("getting '%s' ... \n", fname); + if ((mpio_file_get(mpiosh.dev, mpiosh.card, + fname, mpiosh_callback_get)) == -1) { + if ((ret=mpio_errno()) == MPIO_ERR_USER_CANCEL) { + debug("cancelled operation\n"); + mpio_perror("error"); + break; + } + mpio_error_set(ret); + mpio_perror("error"); + } + printf("\n"); + if (mpiosh_cancel) { + debug("operation cancelled by user\n"); + break; + } + } else { + regerror(error, ®ex, errortext, 100); + debugn (2, "file does not match: %s (%s)\n", fname, errortext); + } + + p = mpio_dentry_next(mpiosh.dev, mpiosh.card, p); + } + } + if (!found) + printf("file not found! (%s)\n", args[i]); + i++; + } + + + regfree(®ex); +} + +BYTE +mpiosh_callback_put(int read, int total) +{ + printf("\rwrote %.2f %%", ((double) read / total) * 100.0 ); + fflush(stdout); + + if ((mpiosh_cancel) && (!mpiosh_cancel_ack)) { + debug ("user cancelled operation\n"); + mpiosh_cancel_ack = 1; + } + + return mpiosh_cancel; // continue +} + +/* void */ +/* mpiosh_cmd_put(char *args[]) */ +/* { */ +/* int size; */ + +/* MPIOSH_CHECK_CONNECTION_CLOSED; */ +/* MPIOSH_CHECK_ARG; */ + +/* if ((size = mpio_file_put(mpiosh.dev, mpiosh.card, args[0], FTYPE_MUSIC, */ +/* mpiosh_callback_put)) == -1) { */ +/* mpio_perror("error"); */ +/* } else { */ +/* mpio_sync(mpiosh.dev, mpiosh.card); */ +/* } */ +/* printf("\n"); */ +/* } */ + +void +mpiosh_cmd_mput(char *args[]) +{ + char dir_buf[NAME_MAX]; + int size, j, i = 0, error, written = 0; + struct dirent ** dentry, **run; + struct stat st; + regex_t regex; + CHAR errortext[100]; + + MPIOSH_CHECK_CONNECTION_CLOSED; + MPIOSH_CHECK_ARG; + + mpiosh_command_regex_fix(args); + getcwd(dir_buf, NAME_MAX); + while (args[i] != NULL) { + if ((error = regcomp(®ex, args[i], REG_NOSUB))) { + regerror(error, ®ex, errortext, 100); + debugn (2, "error in regular expression: %s (%s)\n", args[i], errortext); + } else { + if ((size = scandir(dir_buf, &dentry, NULL, alphasort)) != -1) { + run = dentry; + for (j = 0; ((j < size) && (!mpiosh_cancel)); j++, run++) { + if (stat((*run)->d_name, &st) == -1) { + free(*run); + continue; + } else { + if (!S_ISREG(st.st_mode)) { + debugn(2, "not a regular file: '%s'\n", (*run)->d_name); + free(*run); + continue; + } + } + + if (!(error = regexec(®ex, (*run)->d_name, 0, NULL, 0))) { + printf("putting '%s' ... \n", (*run)->d_name); + if (mpio_file_put(mpiosh.dev, mpiosh.card, (*run)->d_name, + FTYPE_MUSIC, mpiosh_callback_put) == -1) { + mpio_perror("error"); + /* an existing file is no reason for a complete abort!! */ + if (mpio_errno() == MPIO_ERR_FILE_EXISTS) + continue; + break; + } + written = 1; /* we did write something, so do mpio_sync afterwards */ + + printf("\n"); + } else { + regerror(error, ®ex, errortext, 100); + debugn(2, "file does not match: %s (%s)\n", + (*run)->d_name, errortext); + } + free(*run); + } + free(dentry); + } + } + i++; + } + regfree(®ex); + if (mpiosh_cancel) + debug("operation cancelled by user\n"); + + if (written) { + mpio_sync(mpiosh.dev, mpiosh.card); + } else { + printf("file not found!\n"); + } +} + +BYTE +mpiosh_callback_del(int read, int total) +{ + printf("\rdeleted %.2f %%", ((double) read / total) * 100.0 ); + fflush(stdout); + + if (mpiosh_cancel) + debug ("user cancelled operation\n"); + + return mpiosh_cancel; // continue +} + +/* void */ +/* mpiosh_cmd_del(char *args[]) */ +/* { */ +/* int size; */ + +/* MPIOSH_CHECK_CONNECTION_CLOSED; */ +/* MPIOSH_CHECK_ARG; */ + +/* size = mpio_file_del(mpiosh.dev, mpiosh.card, args[0], mpiosh_callback_del); */ +/* mpio_sync(mpiosh.dev, mpiosh.card); */ + +/* printf("\n"); */ +/* } */ + +void +mpiosh_cmd_mdel(char *args[]) +{ + BYTE * p; + int i = 0; + int error; + regex_t regex; + int r; + CHAR fname[100]; + CHAR errortext[100]; + BYTE month, day, hour, minute, type; + WORD year; + DWORD fsize; + int deleted = 0; + + MPIOSH_CHECK_CONNECTION_CLOSED; + MPIOSH_CHECK_ARG; + + mpiosh_command_regex_fix(args); + while (args[i] != NULL) { + if ((error = regcomp(®ex, args[i], REG_NOSUB))) { + regerror(error, ®ex, errortext, 100); + debugn (2, "error in regular expression: %s (%s)\n", args[i], errortext); + } else { + p = mpio_directory_open(mpiosh.dev, mpiosh.card); + while ((p != NULL) && (!mpiosh_cancel)) { + memset(fname, '\0', 100); + mpio_dentry_get(mpiosh.dev, mpiosh.card, p, fname, 100, + &year, &month, &day, &hour, &minute, &fsize, &type); + + if ((!(error = regexec(®ex, fname, 0, NULL, 0))) && + (strcmp(fname, "..")) && (strcmp(fname, "."))) + { + /* this line has to be above the del, or we won't write + * the FAT and directory in case of an abort!!! + */ + deleted=1; + printf("deleting '%s' ... \n", fname); + r = mpio_file_del(mpiosh.dev, mpiosh.card, + fname, mpiosh_callback_del); + printf("\n"); + if (mpiosh_cancel) break; + /* if we delete a file, start again from the beginning, + because the directory has changed !! */ + if (r != MPIO_OK) + { + mpio_perror("ERROR"); + p = mpio_dentry_next(mpiosh.dev, mpiosh.card, p); + break; + } + p = mpio_directory_open(mpiosh.dev, mpiosh.card); + } else { + regerror(error, ®ex, errortext, 100); + debugn (2, "file does not match: %s (%s)\n", fname, errortext); + p = mpio_dentry_next(mpiosh.dev, mpiosh.card, p); + } + + } + } + i++; + } + regfree(®ex); + if (deleted) { + mpio_sync(mpiosh.dev, mpiosh.card); + } else { + printf("file not found!\n"); + } +} + + +void +mpiosh_cmd_dump(char *args[]) +{ + BYTE *p; + BYTE month, day, hour, minute, type; + CHAR fname[256]; + char *arg[2]; + WORD year; + DWORD fsize; + + MPIOSH_CHECK_CONNECTION_CLOSED; + + UNUSED(args); + + arg[1] = NULL; + + p = mpio_directory_open(mpiosh.dev, mpiosh.card); + while ((p != NULL) && (!mpiosh_cancel)) { + arg[0] = fname; /* is this a memory leak?? -mager */ + memset(fname, '\0', 256); + + mpio_dentry_get(mpiosh.dev, mpiosh.card, p, + fname, 256, + &year, &month, &day, + &hour, &minute, &fsize, &type); + + mpiosh_cmd_mget(arg); + + p = mpio_dentry_next(mpiosh.dev, mpiosh.card, p); + } +} + +void +mpiosh_cmd_free(char *args[]) +{ + DWORD free; + int kbytes; + + MPIOSH_CHECK_CONNECTION_CLOSED; + + 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]; + CHAR *config, *fmconfig, *rconfig, *fontconfig; + int csize, fmsize, rsize, fontsize; + + MPIOSH_CHECK_CONNECTION_CLOSED; + + 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 (mpiosh.card == MPIO_INTERNAL_MEM) { + printf("read config files from player\n"); + + /* save config files and write them back after formatting */ + config = NULL; + fmconfig = NULL; + rconfig = NULL; + fontconfig = NULL; + + csize = mpio_file_get_to_memory(mpiosh.dev, MPIO_INTERNAL_MEM, + MPIO_CONFIG_FILE, NULL, &config); + fmsize = mpio_file_get_to_memory(mpiosh.dev, MPIO_INTERNAL_MEM, + MPIO_CHANNEL_FILE, NULL, &fmconfig); + rsize = mpio_file_get_to_memory(mpiosh.dev, MPIO_INTERNAL_MEM, + MPIO_MPIO_RECORD, NULL, &rconfig); + fontsize = mpio_file_get_to_memory(mpiosh.dev, MPIO_INTERNAL_MEM, + MPIO_FONT_FON, NULL, &fontconfig); + } + + printf("formatting memory...\n"); + + if (mpio_memory_format(mpiosh.dev, mpiosh.card, + mpiosh_callback_format) == -1) + printf("\nfailed\n"); + else { + printf("\n"); + + if (mpiosh.card == MPIO_INTERNAL_MEM) { + printf("restoring saved config files\n"); + /* restore everything we saved */ + if (config) + if (mpio_file_put_from_memory(mpiosh.dev, MPIO_INTERNAL_MEM, + MPIO_CONFIG_FILE, FTYPE_CONF, + NULL, config, csize)==-1) + mpio_perror("error"); + if (fmconfig) + if (mpio_file_put_from_memory(mpiosh.dev, MPIO_INTERNAL_MEM, + MPIO_CHANNEL_FILE, FTYPE_CHAN, + NULL, fmconfig, fmsize)==-1) + mpio_perror("error"); + if (rconfig) + if (mpio_directory_make(mpiosh.dev, MPIO_INTERNAL_MEM, + MPIO_MPIO_RECORD)!=MPIO_OK) + mpio_perror("error"); + if (fontconfig) + if (mpio_file_put_from_memory(mpiosh.dev, MPIO_INTERNAL_MEM, + MPIO_FONT_FON, FTYPE_FONT, + NULL, fontconfig, fontsize)==-1) + mpio_perror("error"); + + if (config || fmconfig || rconfig || fontconfig) + mpio_sync(mpiosh.dev, MPIO_INTERNAL_MEM); + if (config) + free(config); + if (fmconfig) + free(fmconfig); + if (rconfig) + free(rconfig); + if (fontconfig) + free(fontconfig); + } + + } + mpiosh_cmd_health(NULL); + } +} + +void +mpiosh_cmd_switch(char *args[]) +{ + MPIOSH_CHECK_CONNECTION_CLOSED; + + if(args[0] && args[1] && !args[2]) { + if ((mpio_file_switch(mpiosh.dev, mpiosh.card, + args[0], args[1])) == -1) { + mpio_perror("error"); + } else { + mpio_sync(mpiosh.dev, mpiosh.card); + } + + } else { + fprintf(stderr, "error: wrong number of arguments given\n"); + printf("switch \n"); + } + +} + +void +mpiosh_cmd_rename(char *args[]) +{ + MPIOSH_CHECK_CONNECTION_CLOSED; + + if(args[0] && args[1] && !args[2]) { + if ((mpio_file_rename(mpiosh.dev, mpiosh.card, + args[0], args[1])) == -1) { + mpio_perror("error"); + } else { + mpio_sync(mpiosh.dev, mpiosh.card); + } + + } else { + fprintf(stderr, "error: wrong number of arguments given\n"); + printf("rename \n"); + } +} + +void +mpiosh_cmd_dump_mem(char *args[]) +{ + + MPIOSH_CHECK_CONNECTION_CLOSED; + + UNUSED(args); + + mpio_memory_dump(mpiosh.dev, mpiosh.card); + +} + +void +mpiosh_cmd_health(char *args[]) +{ + mpio_health_t health; + int i, lost, r; + + UNUSED(args); + + MPIOSH_CHECK_CONNECTION_CLOSED; + + if ((r=mpio_health(mpiosh.dev, mpiosh.card, &health)) != MPIO_OK) { + printf("error: %s\n", mpio_strerror(r)); + return; + } + + if (mpiosh.card == MPIO_INTERNAL_MEM) { + lost=0; + printf("health status of internal memory:\n"); + printf("=================================\n"); + printf("%d chip%c (total/spare/broken)\n", + health.num, ((health.num==1)?' ':'s')); + for(i=0; id_name, &st) == -1) { + perror("stat"); + } else { + rights[0] = *("?pc?dnb?-?l?s???" + (st.st_mode >> 12 & 0xf)); + for (j = 0; j < 9; j++) { + if (st.st_mode & 1 << (8 - j)) + rights[j + 1] = "rwxrwxrwx"[j]; + else + rights[j + 1] = '-'; + } + + pwd = getpwuid(st.st_uid); + grp = getgrgid(st.st_gid); + strftime(time, 12, "%b %2d", localtime(&(st.st_mtime))); + if (pwd && grp) { + printf("%s %8s %8s %8d %10s %s\n", + rights, pwd->pw_name, grp->gr_name, (int)st.st_size, + time, (*run)->d_name); + } else if (pwd) { + printf("%s %8s %8d %8d %10s %s\n", + rights, pwd->pw_name, st.st_gid, (int)st.st_size, + time, (*run)->d_name); + } else if (grp) { + printf("%s %8d %8s %8d %10s %s\n", + rights, st.st_uid, grp->gr_name, (int)st.st_size, + time, (*run)->d_name); + } else { + printf("%s %8d %8d %8d %10s %s\n", + rights, st.st_uid, st.st_gid, (int)st.st_size, + time, (*run)->d_name); + } + } + free(*run); + } + free(dentry); + } else { + perror("scandir"); + } + } +} + +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[]) +{ + MPIOSH_CHECK_ARG; + + if (chdir(args[0])) { + perror ("error"); + } +} + +void +mpiosh_cmd_lmkdir(char *args[]) +{ + MPIOSH_CHECK_ARG; + + if (mkdir(args[0], 0777)) { + perror("error"); + } +} + +void +mpiosh_cmd_font_upload(char *args[]) +{ + BYTE * p; + int size; + + MPIOSH_CHECK_CONNECTION_CLOSED; + MPIOSH_CHECK_ARG; + + /* check if fonts file already exists */ + p = mpio_file_exists(mpiosh.dev, MPIO_INTERNAL_MEM, + MPIO_FONT_FON); + if (p) { + printf("Fontsfile already exists. Please delete it first!\n"); + return; + } + + printf("writing new font file ...\n"); + if (mpio_file_put_as(mpiosh.dev, MPIO_INTERNAL_MEM, + args[0], MPIO_FONT_FON, + FTYPE_FONT, mpiosh_callback_put)==-1) + mpio_perror("error"); + + printf("\n"); + mpio_sync(mpiosh.dev, MPIO_INTERNAL_MEM); + +} + + +/* end of callback.c */ diff --git a/src/callback.h b/src/callback.h new file mode 100644 index 0000000..00ffb86 --- /dev/null +++ b/src/callback.h @@ -0,0 +1,101 @@ +/* callback.h + * + * Author: Andreas Büsching + * + * $Id: callback.h,v 1.13 2003/06/27 12:21:21 crunchy Exp $ + * + * Copyright (C) 2001 Andreas Büsching + * + * 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 CALLBACK_HH +#define CALLBACK_HH + +#include "libmpio/mpio.h" + +/* mpio 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_pwd(char *args[]); +void mpiosh_cmd_mkdir(char *args[]); +void mpiosh_cmd_cd(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_mget(char *args[]); +void mpiosh_cmd_put(char *args[]); +void mpiosh_cmd_mput(char *args[]); +void mpiosh_cmd_del(char *args[]); +void mpiosh_cmd_mdel(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[]); +void mpiosh_cmd_rename(char *args[]); +void mpiosh_cmd_dump_mem(char *args[]); +void mpiosh_cmd_health(char *args[]); +void mpiosh_cmd_backup(char *args[]); +void mpiosh_cmd_restore(char *args[]); +#if 0 +void mpiosh_cmd_config(char *args[]); +#endif +void mpiosh_cmd_channel(char *args[]); +void mpiosh_cmd_id3(char *args[]); +void mpiosh_cmd_id3_format(char *args[]); +void mpiosh_cmd_font_upload(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[]); + +/* progress callbacks */ +BYTE mpiosh_callback_init(mpio_mem_t, int read, int total); +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); + +/* check situation */ + +#define MPIOSH_CHECK_CONNECTION_OPEN \ + if (mpiosh.dev != NULL) { \ + printf("connection to MPIO player is open\n"); \ + return; \ + } + +#define MPIOSH_CHECK_CONNECTION_CLOSED \ + if (mpiosh.dev == NULL) { \ + printf("connection to MPIO player is closed\n"); \ + return; \ + } + +#define MPIOSH_CHECK_ARG \ + if (args[0] == NULL) { \ + printf("error: no argument given\n"); \ + return; \ + } + + +#endif + +/* end of callback.h */ diff --git a/src/cfg.c b/src/cfg.c new file mode 100644 index 0000000..f8c672f --- /dev/null +++ b/src/cfg.c @@ -0,0 +1,238 @@ +/* config.c + * + * Author: Andreas Buesching + * + * $Id: config.c,v 1.7 2003/06/27 13:40:23 crunchy Exp $ + * + * Copyright (C) 2001 Andreas Büsching + * + * 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 "cfg.h" +#include "global.h" + +#include +#include +#include + +struct mpiosh_config_t * +mpiosh_config_new(void) +{ + struct mpiosh_config_t * cfg = malloc(sizeof(struct mpiosh_config_t)); + char *filename, *tmp; + struct stat st; + + cfg->prompt_int = cfg->prompt_ext = NULL; + cfg->default_mem = MPIO_INTERNAL_MEM; + + filename = malloc(strlen(CONFIG_GLOBAL) + strlen(CONFIG_FILE) + 1); + filename[0] = '\0'; + strcat(filename, CONFIG_GLOBAL); + strcat(filename, CONFIG_FILE); + tmp = cfg_resolve_path(filename); + + if (stat(tmp, &st) != -1) + cfg->handle_global = + cfg_handle_new_with_filename(tmp, 1); + else + cfg->handle_global = 0; + + free(tmp), free(filename); + filename = malloc(strlen(CONFIG_USER) + strlen(CONFIG_FILE) + 1); + filename[0] = '\0'; + strcat(filename, CONFIG_USER); + strcat(filename, CONFIG_FILE); + tmp = cfg_resolve_path(filename); + + if (stat(tmp, &st) != -1) + cfg->handle_user = + cfg_handle_new_with_filename(tmp, 1); + else + cfg->handle_user = + cfg_handle_new_with_filename(tmp, 0); + + free(tmp), free(filename); + + /* initialise history */ + using_history(); + + filename = malloc(strlen(CONFIG_USER) + strlen(CONFIG_HISTORY) + 1); + filename[0] = '\0'; + strcat(filename, CONFIG_USER); + strcat(filename, CONFIG_HISTORY); + tmp = cfg_resolve_path(filename); + + read_history(tmp); + free(tmp), free(filename); + + return cfg; +} + +const char * +mpiosh_config_read_key(struct mpiosh_config_t *config, const char *group, + const char *key) +{ + char *value = NULL; + + if (config->handle_user) + value = (char *)cfg_key_get_value(config->handle_user, + group, key); + else if (config->handle_global) + value = (char *)cfg_key_get_value(config->handle_global, + group, key); + + return value; +} + +void +mpiosh_config_free(struct mpiosh_config_t *config) +{ + if (config->handle_global) + cfg_close(config->handle_global); + + cfg_close(config->handle_user); + free(config->prompt_int); + free(config->prompt_ext); + free(config); +} + +int +mpiosh_config_read(struct mpiosh_config_t *config) +{ + if (config) { + const char *value; + + value = mpiosh_config_read_key(config, "mpiosh", "prompt_int"); + if (value) { + config->prompt_int = strdup(value); + } else { + config->prompt_int = strdup(PROMPT_INT); + } + + value = mpiosh_config_read_key(config, "mpiosh", "prompt_ext"); + if (value) { + config->prompt_ext = strdup(value); + } else { + config->prompt_ext = strdup(PROMPT_EXT); + } + + value = mpiosh_config_read_key(config, "mpiosh", "default_mem"); + if (value) { + if (!strcmp("internal", value)) { + config->default_mem = MPIO_INTERNAL_MEM; + } else if (!strcmp("external", value)) { + config->default_mem = MPIO_EXTERNAL_MEM; + } + } + + value = mpiosh_config_read_key(config, "mpiosh", "charset"); + if (value) { + config->charset = strdup(value); + } else { + config->charset = NULL; + } + + value = mpiosh_config_read_key(config, "mpiosh", "id3_rewriting"); + if (value) { + if (!strcmp("on", value)) { + config->id3_rewriting = 1; + } else { + config->id3_rewriting = 0; + } + } + + value = mpiosh_config_read_key(config, "mpiosh", "id3_format"); + if (value) { + config->id3_format = strdup(value); + } else { + config->id3_format = strdup(MPIO_ID3_FORMAT); + } + + } + + return 1; +} + +char * +mpiosh_config_check_backup_dir( struct mpiosh_config_t *config, int create ) +{ + DIR *dir; + char *path = cfg_resolve_path( CONFIG_BACKUP ); + char *ret = path; + + if ( ( dir = opendir( path ) ) == NULL ) + if ( create ) { + if ( mkdir(path, 0777 ) ) + ret = NULL; + } else + ret = NULL; + else + closedir(dir); + + return ret; +} + +int +mpiosh_config_write( struct mpiosh_config_t *config ) +{ + DIR *dir; + char *path = cfg_resolve_path(CONFIG_USER); + + if ((dir = opendir(path)) == NULL) + mkdir(path, 0777); + else + closedir(dir); + + free(path); + + if (config->handle_user) { + char *tmp, *filename; + + cfg_key_set_value(config->handle_user, + "mpiosh", "prompt_int", config->prompt_int); + cfg_key_set_value(config->handle_user, + "mpiosh", "prompt_ext", config->prompt_ext); + if (config->default_mem == MPIO_EXTERNAL_MEM) + cfg_key_set_value(config->handle_user, + "mpiosh", "default_mem", "external"); + else + cfg_key_set_value(config->handle_user, + "mpiosh", "default_mem", "internal"); + cfg_key_set_value(config->handle_user, + "mpiosh", "id3_rewriting", + (config->id3_rewriting?"on":"off")); + cfg_key_set_value(config->handle_user, + "mpiosh", "id3_format", config->id3_format); + + cfg_save(config->handle_user, 0); + + /* save history */ + filename = malloc(strlen(CONFIG_USER) + strlen(CONFIG_HISTORY) + 1); + filename[0] = '\0'; + strcat(filename, CONFIG_USER); + strcat(filename, CONFIG_HISTORY); + tmp = cfg_resolve_path(filename); + + printf("writing history to file %s\n", filename); + write_history(tmp); + free(tmp), free(filename); + } + + return 1; +} + + +/* end of config.c */ diff --git a/src/cfg.h b/src/cfg.h new file mode 100644 index 0000000..4157bd6 --- /dev/null +++ b/src/cfg.h @@ -0,0 +1,56 @@ +/* config.h + * + * Author: Andreas Buesching + * + * $Id: config.h,v 1.5 2003/06/27 13:40:23 crunchy Exp $ + * + * Copyright (C) 2001 Andreas Büsching + * + * 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_CONFIG_HH +#define MPIOSH_CONFIG_HH + +#include "cfgio.h" + +struct mpiosh_config_t { + CfgHandle *handle_global; + CfgHandle *handle_user; + + char *prompt_int; + char *prompt_ext; + char *charset; + unsigned default_mem; + + unsigned id3_rewriting; + char *id3_format; +}; + +struct mpiosh_config_t *mpiosh_config_new(void); +void mpiosh_config_free(struct mpiosh_config_t *config); + +const char *mpiosh_config_read_key(struct mpiosh_config_t *config, + const char *group, const char *key); +int mpiosh_config_read(struct mpiosh_config_t *config); +int mpiosh_config_write(struct mpiosh_config_t *config); + +char * mpiosh_config_check_backup_dir( struct mpiosh_config_t *config, + int create ); + +#endif + +/* end of config.h */ + diff --git a/src/cfgio.c b/src/cfgio.c new file mode 100644 index 0000000..b8a1829 --- /dev/null +++ b/src/cfgio.c @@ -0,0 +1,654 @@ +#include "cfgio.h" + +#include +#include + +/*************************************************** + * help!!! functions + ***************************************************/ + +char * +cfg_resolve_path(const char *filename) +{ + char *fn = NULL; + + if (filename[0] != '~') return strdup(filename); + + if (filename[1] == '/' ) { + /* own home directory */ + char *home; + if ((home = getenv ("HOME")) == NULL) { + fn = strdup(filename); + } else { + fn = (char *)malloc(strlen(home) + strlen(filename+1) + 1); + sprintf(fn, "%s%s", home,filename+1); + } + } else { + /* other home directory */ + struct passwd *pw; + char *dir = strchr(filename, '/'); + size_t len = (size_t)(dir - filename-1); + char user[len]; + strncpy(user, filename+1, len); + user[len] = '\0'; + + if (!(pw = getpwnam(user))) { + fn = strdup(filename); + } else { + fn = (char *) malloc(strlen(pw->pw_dir) + strlen(dir) + 1); + sprintf (fn, "%s%s",pw->pw_dir, dir); + } + } + + return fn; +} + +/*************************************************** + * open functions + ***************************************************/ +int cfg_save(CfgHandle *h, int cl){ + if (h && h->file) { + FILE *f = h->file; + CfgGroup *group; + group = h->first; + + while (group) { + CfgKey *key; + fprintf(f, "[%s]\n", group->name); + key = group->first; + while (key) { + fprintf(f, "%s=%s\n", key->name, key->value ? key->value : ""); + key = key->next; + } + fprintf(f, "\n"); + group = group->next; + } + if (cl) return cfg_close(h); + return 0; + } + return -1; +} + +int cfg_save_as(CfgHandle *h, const char* filename, int err, int cl){ + if (h && filename) { + int res; + res = cfg_handle_change_filename(h, filename); + if (res) return res; + res = cfg_open(h, err, "w+"); + if (res) return res; + return cfg_save(h,cl); + } + return -1; +} + + +int cfg_read(CfgHandle *h, int cl){ + if (h && h->file){ + char *gname = NULL; + FILE* file = h->file; + int offset; + char *line = (char*)malloc(_CFG_MAX_LINE_SIZE); + while ((line = fgets(line, _CFG_MAX_LINE_SIZE, file)) != NULL) { + for (offset = strlen(line); offset > 0 && isspace(line[offset-1]); line[--offset] = '\0'); + for (offset = 0;isspace(line[offset]); offset++); + switch (line[offset]) { + case '#': + case '\0': break; + case '[': + free (gname); + gname = strdup(line+offset+1); + gname[strlen(gname)-1] = '\0'; + cfg_group_new(h, gname); + break; + default: { + char *k, *v, *vo, *p; + size_t len; + int i; + p = strchr(line+offset, '='); + if (p) { + len = (size_t)(p - (line+offset) + 1); + k = (char*)malloc(len); + k = strncpy(k, line+offset, len); + k[len-1] = '\0'; + for (i = strlen(k); i > 0 && isspace(k[i-1]); k[--i] = '\0'); + v = (char*)malloc(strlen(p+1)+1); + /* v = (char*)malloc(strlen(p+1)); */ + v = strcpy(v, p+1); + for (vo = v; isspace(vo[0]); vo++); + /* for (vo = v+1; isspace(vo[0]); vo++); */ + cfg_key_new_with_value(h, gname, k, vo); + free (v); + } else { + len = (size_t)(strlen(line) - offset + 1); + k = (char*)malloc(len); + k = strncpy(k, line+offset, len); + k[len-1] = '\0'; + vo = NULL; + cfg_key_new_with_value(h, gname, k, vo); + } + + free (k); + } + } + } + free (line); + free (gname); + if (cl) return cfg_close(h); + return 0; + } + return -1; +} + + +int cfg_open_file(CfgHandle* h, const char* filename, int reportErrors, const char* mode){ + if ((h->file = fopen (filename, mode)) != NULL) { + return 0; + } else { + if (reportErrors) { + fprintf (stderr, "Can't open configuration file \"%s\": %s\n", + filename, strerror (errno)); + } + return -1; + } +} + +char * +cfg_find_file(char **files, char **pathes) +{ + /* e.g.: + char *files[] = { ".blarc", "blarc", "bla", NULL }; + char *pathes[] = { "/", "/usr/etc/", "/etc/", NULL }; */ + char **file, **path = pathes; + char *options_file = NULL, *help = NULL; + struct stat s; + + while (*path) { + file = files; + while(*file) { + free(options_file); + options_file = (char *)malloc(sizeof(char) * ( + strlen(*path) + + strlen(*file) + 1)); + sprintf(options_file, "%s%s", *path, *file); + help = cfg_resolve_path(options_file); + if (!stat(help, &s)) { + free(options_file); + return help; + } + free(help); + file++; + } + path++; + } + free(options_file); + + return NULL; +} + +int +cfg_open_user_file(CfgHandle *h, const char* filename, + int reportErrors, const char* mode) +{ + char *fn = cfg_resolve_path(filename); + int ret = cfg_open_file(h, fn, reportErrors, mode); + + free(fn); + + return ret; +} + +int cfg_open(CfgHandle* h, int reportErrors, const char* mode){ + int res; + const char *filename; + if (!h || !h->filename || !mode) return -1; + filename = h->filename; + if (filename[0] == '~') { + /* Absolute Path of a Users HomeDir */ + res = cfg_open_user_file (h, filename, reportErrors, mode); + } else if (filename[0] == '/') { + /* Absolute pathname: try it - there are no alternatives */ + res = cfg_open_file (h, filename, reportErrors, mode); + } else { + /* Relative pathname: try current directory first */ + res = cfg_open_file (h, filename, 0, mode); + } + return res; +} + +int cfg_open_read (CfgHandle *handle, const char* filename, int err, int cl){ + if (handle && filename) { + int res; + res = cfg_handle_change_filename(handle, filename); + if (res) return res; + res = cfg_open(handle, err, "r"); + if (res) return res; + return cfg_read(handle,cl); + } + else return -1; +} + +int cfg_close (CfgHandle* h){ + if (!h || !h->file) return -1; + fclose (h->file); + h->file = NULL; + return 0; +} + + +/*************************************************** + * commons + ***************************************************/ + +CfgGroup* cfg_find_group(CfgHandle* h, const char* g){ + CfgGroup *tmp; + if (h == NULL || g == NULL) return NULL; + tmp = h->first; + while (tmp && strcmp(tmp->name, g) != 0) tmp = tmp->next; + return tmp; +} + +CfgKey* cfg_find_key(CfgGroup* g, const char* key){ + CfgKey* tmp; + if (g == NULL || key == NULL) return NULL; + tmp = g->first; + while (tmp && strcmp(tmp->name, key) != 0) tmp = tmp->next; + return tmp; +} + +/*************************************************** + * cfg_handle_... + ***************************************************/ + +CfgHandle* cfg_handle_new_with_filename (const char* filename, int read){ + CfgHandle* h; + h = (CfgHandle*)malloc(sizeof(CfgHandle)); + if (!h) return NULL; + + h->filename = filename ? strdup(filename) : NULL; + h->file = NULL; + h->first = h->last = NULL; + + if (read) { + int r = cfg_open_read(h, filename, 0, 1); + if (r != 0) { + cfg_handle_free(h); + return NULL; + } + } + + return h; +} + +CfgHandle* cfg_handle_new (){ + return cfg_handle_new_with_filename(NULL,0); +} + + +int cfg_handle_change_filename(CfgHandle *h, const char* filename){ + if (h && filename) { + if (h->file) return -2; + free (h->filename); + h->filename = strdup(filename); + return 0; + } + else return -1; +} + + +int cfg_handle_add_group(CfgHandle* h, CfgGroup* g){ + if (h && g) { + CfgGroup* last = h->last; + if (last) { + last->next = g; + g->prev = last; + } else { + h->first = g; + } + h->last = g; + g->pp = h; + return 0; + } + else + return -1; +} + +void cfg_handle_free (CfgHandle* h){ + CfgGroup *ga, *gb; + CfgKey *ka, *kb; + if (!h) return; + ga = h->first; + if (h->file) fclose (h->file); + while (ga){ + gb = ga->next; + ka = ga->first; + while (ka) { + kb = ka->next; + free (ka->name); + free (ka->value); + free (ka); + ka = kb; + } + free (ga->name); + free (ga); + ga = gb; + } + free (h); +} + + +/*************************************************** + * cfg_group_... + ***************************************************/ + +int cfg_group_exist(CfgHandle* h, const char* name){ + if (h == NULL || name == NULL) + return -1; + else { + CfgGroup* tmp = h->first; + while (tmp && strcmp(tmp->name,name) != 0 ) + tmp = tmp->next; + if (tmp != NULL) return -1; + } + return 0; +} + +int cfg_group_new (CfgHandle* handle, const char* name){ + if (cfg_find_group(handle, name) == NULL) { + CfgGroup* g = (CfgGroup*)malloc(sizeof(CfgGroup)); + if (!g) return -1; + g->name = strdup(name); + g->prev = NULL; + g->next = NULL; + g->first = NULL; + g->last = NULL; + g->pp = NULL; + return cfg_handle_add_group(handle, g); + } else + return -1; +} + +int cfg_group_add_key(CfgGroup* g, CfgKey* k){ + if (g && k) { + CfgKey* last = g->last; + if (last) { + last->next = k; + k->prev = last; + } else { + g->first = k; + } + + g->last = k; + k->pp = g; + return 0; + } else + return -1; +} + +void cfg_group_free(CfgHandle* h, const char* name){ + if (h && name) { + CfgGroup *tmp, *prev, *next; + CfgKey *a, *b; + tmp = cfg_find_group(h, name); + if (!tmp) return; + + a = tmp->first; + while (a) { + b = a->next; + free (a->name); + free (a->value); + free (a); + a = b; + } + + prev = tmp->prev; + next = tmp->next; + + free (tmp->name); + if (prev) { + prev->next = next; + } else { + tmp->pp->first= next; + } + + if (next) { + next->prev = prev; + } else { + tmp->pp->last = prev; + } + + free(tmp); + } +} + +/*************************************************** + * cfg_key_... + ***************************************************/ + +int +cfg_key_new (CfgHandle* h, const char* g, const char* key) +{ + CfgGroup *group; + if ((group = cfg_find_group(h, g)) == NULL) return -1; + // if (cfg_find_key(group, key) != NULL) return -1; + if (h && g && key) { + CfgKey* k = (CfgKey*)malloc(sizeof(CfgKey)); + if (!k) return -1; + k->name = strdup(key); + k->value = NULL; + k->prev = NULL; + k->next = NULL; + k->pp = NULL; + return cfg_group_add_key(group, k); + } else + return -1; +} + +int +cfg_key_new_with_value(CfgHandle* h, const char* g, const char* key, + const char* value) +{ + if (cfg_key_new (h, g, key) == 0) { + CfgKey* tmp = cfg_find_group(h, g)->last; + if (!tmp) return -1; + tmp->value = ((value == NULL) ? NULL : strdup(value)); + return 0; + } else + return -1; +} + +int +cfg_key_set_value(CfgHandle* h, const char* g, const char* key, + const char* value) +{ + if (h && g && key && value) { + CfgKey* tmp = cfg_find_key(cfg_find_group(h,g), key); + if (!tmp) return -1; + free (tmp->value); + tmp->value = ((value == NULL) ? NULL : strdup(value)); + return 0; + } else return -1; +} + +int +cfg_key_set_uint_value (CfgHandle *h, const char* g, const char* key, + unsigned int value) +{ + char dest[30]; + sprintf(dest,"%ud", value); + return cfg_key_set_value(h, g, key, dest); +} + +int +cfg_key_set_int_value (CfgHandle *h, const char* g, const char* key, + int value) +{ + char dest[30]; + sprintf(dest,"%d", value); + return cfg_key_set_value(h, g, key, dest); +} + +int +cfg_key_set_double_value (CfgHandle *h, const char* g, const char* key, + double value) +{ + char dest[30]; + sprintf(dest,"%e",value); + return cfg_key_set_value(h, g, key, dest); +} + +int +cfg_key_set_float_value (CfgHandle *h, const char* g, const char* key, + float value) +{ + char dest[30]; + sprintf(dest,"%f",value); + return cfg_key_set_value(h, g, key, dest); +} + +int +cfg_key_set_bool_value (CfgHandle *h, const char* g, const char* key, + bool value) +{ + char dest[2]; + sprintf(dest, "%1d", value); + return cfg_key_set_value(h, g, key, dest); +} + +int +cfg_key_set_char_value (CfgHandle *h, const char* g, const char* key, + char value) +{ + char dest[2]; + sprintf(dest, "%c",value); + return cfg_key_set_value(h, g, key, dest); +} + +const char* +cfg_key_get_value(CfgHandle* h, const char* g, const char* key) +{ + if (h && g && key) { + CfgKey* tmp = cfg_find_key(cfg_find_group(h,g), key); + if (!tmp) return NULL; + return tmp->value; + } else + return NULL; +} + +int +cfg_key_get_value_as_bool(CfgHandle* h, const char* g, const char* key, + bool* res){ + char *endptr; + const char *nptr = cfg_key_get_value(h, g, key); + if (!nptr) return -1; + if (!strcasecmp(nptr, "yes") || !strcasecmp(nptr, "true")) + *res = TRUE; + else + *res = FALSE; + + return (int)*endptr; +} + +int +cfg_key_get_value_as_uint(CfgHandle* h, const char* g, const char* key, + unsigned int* res){ + char *endptr; + const char *nptr = cfg_key_get_value(h, g, key); + if (!nptr) return -1; + *res = (unsigned int)strtoul(nptr, &endptr, 10); + return (int)*endptr; +} + +int +cfg_key_get_value_as_int(CfgHandle* h, const char* g, const char* key, + int* res) +{ + char *endptr; + const char *nptr = cfg_key_get_value(h, g, key); + if (!nptr) return -1; + *res = (int)strtol(nptr, &endptr, 10); + return (int)*endptr; +} + +int +cfg_key_get_value_as_ushort(CfgHandle* h, const char* g, const char* key, + unsigned short* res) +{ + char *endptr; + const char *nptr = cfg_key_get_value(h, g, key); + if (!nptr) return -1; + *res = (unsigned short)strtoul(nptr, &endptr, 10); + return (int)*endptr; +} + +int +cfg_key_get_value_as_short(CfgHandle* h, const char* g, const char* key, + short* res) +{ + char *endptr; + const char *nptr = cfg_key_get_value(h, g, key); + if (!nptr) return -1; + *res = (short)strtol(nptr, &endptr, 10); + return (int)*endptr; +} + +int +cfg_key_get_value_as_double(CfgHandle* h, const char* g, const char* key, + double* res) +{ + char *endptr; + const char *nptr = cfg_key_get_value(h, g, key); + if (!nptr) return -1; + *res = (double)strtod(nptr, &endptr); + return (int)*endptr; +} + +int +cfg_key_get_value_as_float(CfgHandle* h, const char* g, const char* key, + float* res) +{ + char *endptr; + const char *nptr = cfg_key_get_value(h, g, key); + if (!nptr) return -1; + *res = (float)strtod(nptr, &endptr); + return (int)*endptr; +} + +void +cfg_key_free (CfgHandle* h, const char* g, const char* key) +{ + if (h && g && key) { + CfgKey *tmp, *prev, *next; + tmp = cfg_find_key(cfg_find_group(h,g), key); + if (!tmp) return; + prev = tmp->prev; + next = tmp->next; + + free (tmp->name); + free (tmp->value); + + if (prev) { + prev->next = next; + } else { + tmp->pp->first = next; + } + + if (next) { + next->prev = prev; + } else { + tmp->pp->last = prev; + } + + free (tmp); + } +} + +void +cfg_key_for_each (CfgHandle* h, const char* grp, cfg_key_func func) +{ + CfgGroup *tmp = cfg_find_group(h,grp); + + if (tmp && func) { + CfgKey *k = tmp->first; + while(k) func(k), k = k->next; + } +} diff --git a/src/cfgio.h b/src/cfgio.h new file mode 100644 index 0000000..d58cd3f --- /dev/null +++ b/src/cfgio.h @@ -0,0 +1,453 @@ +/* configreader and -writer + * + * Source in ANSI C, except function strdup + * needs _BSD_SOURCE or _SVID_SOURCE defined, if compiled ANSI + * Thomas Buntrock (bunti@tzi.de) + * + * Comments in configfile are allowed, but ONLY at the BEGINNING of a line + * When reading a config then writing the same, all comments will be removed + * + * The groupname MUST be put exactly between two square braces, e.g. [Name]. + * Any Spaces in between are interpreted as part of the name. + * + * Keys and their value are separated by "=". Leading and following spaces + * are removed. + * Spaces right before and after the "=" are removed. Spaces in the value + * will remain. + * Keys without value are accepted, BUT the "=" is MANDATORY. + * + * A config line MUST NOT be longer than _CFG_MAX_LINE_SIZE (default: 256) + * + */ + +#ifndef _CFG_IO_H +#define _CFG_IO_H + +#include +#include +#include +#include +#include +#include +#include + +#define _CFG_MAX_LINE_SIZE 256 + +/* define bool */ +#ifndef TRUE +#define TRUE 1 +#define FALSE 0 +#endif + +typedef unsigned char bool; + +struct _CFG_Key { + char *name; + char *value; + struct _CFG_Key* prev; + struct _CFG_Key* next; + struct _CFG_Group* pp; +}; + +struct _CFG_Group { + char *name; + struct _CFG_Group* prev; + struct _CFG_Group* next; + struct _CFG_Key* first; + struct _CFG_Key* last; + struct _CFG_Handle* pp; +}; + +struct _CFG_Handle { + FILE *file; + char *filename; + struct _CFG_Group *first; + struct _CFG_Group *last; +}; + + +typedef struct _CFG_Key CfgKey; +typedef struct _CFG_Group CfgGroup; +typedef struct _CFG_Handle CfgHandle; +typedef int (*cfg_key_func)(CfgKey *key); + +char *cfg_resolve_path(const char *filename); + +/* + * files: a list of files + * e.g. char *files[] = { ".blarc", ".bla", "blarc", NULL }; + * + * paths: a list of paths + * e.g. char *paths[] = { "~/", "/etc/" "etc/", NULL}; + * + * select the first path and iterates through the files, + * then select the next path... + * + * returns the first match of: path/file + */ +char *cfg_find_file (char **files, char **paths); + +/* + * Save the config + * + * close: close the file after saving + * + * returns 0 on success or -1 on failure + */ +int cfg_save (CfgHandle *handle, int close); + +/* + * Save the config with another filename + * + * handle : the config handle + * filename : the new filename + * reportErrors: 0 does not report errors the stderr + * close : close the file after saving + * + * returns 0 on success or -1 on failure + */ +int cfg_save_as (CfgHandle *handle, const char* filename, + int reportErrors, int close); +/* + * Read config file + * requires the Handle to be associated to a file and being opened + * + * handle: the config handle + * close : close the file after reading + * + * returns 0 on success or -1 on failure + */ +int cfg_read (CfgHandle *handle, int close); + +/* + * Open a file to read or save + * + * handle : the config handle + * reportErrors: write errors to stderr + * mode : the mode the file should be opened with (man 3 fopen) + * + * returns 0 on success or -1 on failure + */ +int cfg_open (CfgHandle *handle, int reportErrors, + const char* mode); +/* + * Open a file in read mode + * + * handle : the config handle + * filename : the filename of the config file + * reportErrors: write errors to stderr + * close : close the file after reading + * + * returns 0 on success or -1 on failure + */ +int cfg_open_read (CfgHandle *handle, const char* filename, + int reportErrors, int close); +/* + * Close the file + * + * h: the config handle + * + * returns 0 on success or -1 if the handle was NULL or the was already closed + */ +int cfg_close (CfgHandle *h); + +/* + * Create a new empty file handle + * + * returns the pointer to the new handle + */ +CfgHandle* cfg_handle_new (); + +/* + * Create a new filehandle + * + * filename: the filename of the configfile + * read : read the config file + * + * returns the pointer to the new handle + */ +CfgHandle* cfg_handle_new_with_filename (const char* filename, int read); + +/* + * Change the filename of the config file + * only the internal filename ist changed, to apply on disk you need to call + * cfg_save + * + * filename: new filename + * + * returns 0 on success or -1 on failure + */ +int cfg_handle_change_filename (CfgHandle *h, const char* filename); + +/* + * Delete the handle + * An opened file will be closed + * + * h: the config handle + */ +void cfg_handle_free (CfgHandle* h); + +/* + * Create a new group within the config + * + * handle: the config handle + * name : name of the group + * + * returns 0 on success or -1 on failure + */ +int cfg_group_new (CfgHandle* handle, const char* name); + +/* + * Delete a group within the config + * All keys within this group will be delete as well + * + * handle: the config handle + * name : the name of the group + */ +void cfg_group_free (CfgHandle* handle, const char* name); + +/* + * returns a handle to the group g if found. + * + * handle: the config handle + * name : the name of the group to search for + */ +CfgGroup* cfg_find_group(CfgHandle* h, const char* g); + +/* + * Create a new key within a group within the config + * + * h : the config handle + * g : name of the group + * key: name of the key + * + * returns 0 on success or -1 on failure + */ +int cfg_key_new (CfgHandle* h, const char* g, const char* key); + +/* + * Create a new key within the group within the config and set its value + * + * h : the config handle + * g : name of the group + * key : name of the key + * value: value for the key + * + * returns 0 on success or -1 on failure + */ +int cfg_key_new_with_value (CfgHandle* h, const char* g, const char* key, + const char* value); + +/* + * Set the value for a specific key within a group of the config + * + * h : the config handle + * g : name of the group + * key : name of the key + * value: value for the key + * + * returns 0 on success or -1 on failure + */ +int cfg_key_set_value (CfgHandle* h, const char* g, const char* key, + const char* value); + +/* + * Set the value for a specific key within a group of the config + * + * h : the config handle + * g : name of the group + * key : name of the key + * value: value for the key + * + * returns 0 on success or -1 on failure + */ +int cfg_key_set_uint_value (CfgHandle *h, const char* g, const char* key, + unsigned int value); + +/* + * Set the value for a specific key within a group of the config + * + * h : the config handle + * g : name of the group + * key : name of the key + * value: value for the key + * + * returns 0 on success or -1 on failure + */ +int cfg_key_set_int_value (CfgHandle *h, const char* g, const char* key, + int value); + +/* + * Set the value for a specific key within a group of the config + * + * h : the config handle + * g : name of the group + * key : name of the key + * value: value for the key + * + * returns 0 on success or -1 on failure + */ +int cfg_key_set_double_value (CfgHandle *h, const char* g, const char* key, + double value); + +/* + * Set the value for a specific key within a group of the config + * + * h : the config handle + * g : name of the group + * key : name of the key + * value: value for the key + * + * returns 0 on success or -1 on failure + */ +int cfg_key_set_float_value (CfgHandle *h, const char* g, const char* key, + float value); + +/* + * Set the value for a specific key within a group of the config + * + * h : the config handle + * g : name of the group + * key : name of the key + * value: value for the key + * + * returns 0 on success or -1 on failure + */ +int cfg_key_set_bool_value (CfgHandle *h, const char* g, const char* key, + bool value); + +/* + * Set the value for a specific key within a group of the config + * + * h : the config handle + * g : name of the group + * key : name of the key + * value: value for the key + * + * returns 0 on success or -1 on failure + */ +int cfg_key_set_char_value (CfgHandle *h, const char* g, const char* key, + char value); + +/* + * Delete a key of a group within the config + * + * h : the config handle + * g : name of the group + * key : name of the key + */ +void cfg_key_free (CfgHandle* h, const char* g, const char* key); + +/* + * Get the value of a key within a group of the config + * + * h : the config handle + * g : name of the group + * key: name of the key + * res: the result will be stored in this variable + * + * returns 0 on success or -1 on failure + */ +int cfg_key_get_value_as_bool (CfgHandle* h, const char* g, const char* key, + bool *res); + +/* + * Get the value of a key within a group of the config + * + * h : the config handle + * g : name of the group + * key: name of the key + * res: the result will be stored in this variable + * + * returns 0 on success or -1 on failure + */ +int cfg_key_get_value_as_uint (CfgHandle* h, const char* g, const char* key, + unsigned int *res); + +/* + * Get the value of a key within a group of the config + * + * h : the config handle + * g : name of the group + * key: name of the key + * res: the result will be stored in this variable + * + * returns 0 on success or -1 on failure + */ +int cfg_key_get_value_as_int (CfgHandle* h, const char* g, const char* key, + int *res); + +/* + * Get the value of a key within a group of the config + * + * h : the config handle + * g : name of the group + * key: name of the key + * res: the result will be stored in this variable + * + * returns 0 on success or -1 on failure + */ +int cfg_key_get_value_as_ushort (CfgHandle* h, const char* g, const char* key, + unsigned short *res); + +/* + * Get the value of a key within a group of the config + * + * h : the config handle + * g : name of the group + * key: name of the key + * res: the result will be stored in this variable + * + * returns 0 on success or -1 on failure + */ +int cfg_key_get_value_as_short (CfgHandle* h, const char* g, const char* key, + short *res); + +/* + * Get the value of a key within a group of the config + * + * h : the config handle + * g : name of the group + * key: name of the key + * res: the result will be stored in this variable + * + * returns 0 on success or -1 on failure + */ +int cfg_key_get_value_as_double (CfgHandle* h, const char* g, const char* key, + double *res); + +/* + * Get the value of a key within a group of the config + * + * h : the config handle + * g : name of the group + * key: name of the key + * res: the result will be stored in this variable + * + * returns 0 on success or -1 on failure + */ +int cfg_key_get_value_as_float (CfgHandle* h, const char* g, const char* key, + float *res); + +/* + * Get the value of a key within a group of the config + * + * h : the config handle + * g : name of the group + * key: name of the key + * + * returns the value of the key or NULL if empty + */ +const char* cfg_key_get_value (CfgHandle* h, const char* g, const char* key); + +/* + * iterators through key value pairs of a group + * + * h : the config handle + * grp : name of the group + * func: pointer to the function to call with each element + * + * returns the value of the key or NULL if empty + */ +void cfg_key_for_each (CfgHandle* h, const char* grp, cfg_key_func func); +#endif /* _CFG_IO_H */ diff --git a/src/command.c b/src/command.c new file mode 100644 index 0000000..9c42a8c --- /dev/null +++ b/src/command.c @@ -0,0 +1,222 @@ +/* command.c + * + * Author: Andreas Buesching + * + * $Id: command.c,v 1.3 2002/10/29 20:03:35 crunchy Exp $ + * + * Copyright (C) 2001 Andreas Büsching + * + * 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; +} + +struct mpiosh_cmd_t * +mpiosh_command_find(char *line) +{ + struct 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; + } else if (cmd->aliases) { + char **go = cmd->aliases; + while (*go) { + if ((strstr(line, *go) == line) && + ((line[strlen(*go)] == ' ') || (line[strlen(*go)] == '\0'))) { + return cmd; + } + go++; + } + } + + 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/src/command.h b/src/command.h new file mode 100644 index 0000000..34dbc9b --- /dev/null +++ b/src/command.h @@ -0,0 +1,38 @@ +/* command.h + * + * Author: Andreas Buesching + * + * $Id: command.h,v 1.2 2002/10/29 20:03:35 crunchy Exp $ + * + * Copyright (C) 2001 Andreas Büsching + * + * 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 */ +struct 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/src/config.h.in b/src/config.h.in new file mode 100644 index 0000000..bb60f14 --- /dev/null +++ b/src/config.h.in @@ -0,0 +1,9 @@ +#ifndef _CONFIG_H +#define _CONFIG_H + +/* package name */ +#define PACKAGE "${PACKAGE}" +#define VERSION "0.7.1-pre3" +#define SYSCONFDIR "/etc" + +#endif /* _CONFIG_H */ diff --git a/src/global.c b/src/global.c new file mode 100644 index 0000000..04fd9e7 --- /dev/null +++ b/src/global.c @@ -0,0 +1,159 @@ +/* global.c - containing global symbols for mpiosh + * + * Author: Andreas Buesching + * + * $Id: global.c,v 1.14 2003/06/27 12:21:21 crunchy Exp $ + * + * Copyright (C) 2001 Andreas Büsching + * + * 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 "callback.h" +#include "global.h" +#include "readline.h" +#include "cfg.h" + +/* structure containing current state */ +struct mpiosh_t mpiosh; +struct mpiosh_config_t config; + +/* flag indicating a user-interrupt of the current command */ +int mpiosh_cancel = 0; +int mpiosh_cancel_ack = 0; + +/* configuration filenames */ +const char *CONFIG_GLOBAL = SYSCONFDIR "/mpio/"; +const char *CONFIG_USER = "~/.mpio/"; +const char *CONFIG_BACKUP = "~/.mpio/backup/"; +const char *CONFIG_FILE = "mpioshrc"; +const char *CONFIG_HISTORY = "history"; + +/* prompt strings */ +const char *PROMPT_INT = "\033[;1mmpio \033[m "; +const char *PROMPT_EXT = "\033[;1mmpio \033[m "; + +struct mpiosh_cmd_t commands[] = { + { "debug", NULL , "[level|file|on|off] ", + " modify debugging options", + mpiosh_cmd_debug, NULL }, + { "ver", NULL, NULL, + " version of mpio package", + mpiosh_cmd_version, NULL }, + { "help", (char *[]){ "?", NULL }, "[]", + " show information about known commands or just about ", + mpiosh_cmd_help, mpiosh_readline_comp_cmd }, + { "dir", (char *[]){ "ls", "ll", NULL }, NULL, + " list content of current memory card", + mpiosh_cmd_dir, NULL }, + { "pwd", NULL, NULL, + " print the current working directory", + mpiosh_cmd_pwd, NULL }, + { "mkdir", (char *[]){ "md", NULL }, "", + " make a new directory", + mpiosh_cmd_mkdir, mpiosh_readline_comp_mpio_file }, + { "cd", NULL, "", + " change the current working directory", + mpiosh_cmd_cd, mpiosh_readline_comp_mpio_file }, + { "info", NULL, NULL, + " show information about MPIO player", + mpiosh_cmd_info, NULL }, + { "mem", NULL, "[i|e]", + " 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, NULL, + " open connect to MPIO player", + mpiosh_cmd_open, NULL }, + { "close", NULL, NULL, + " close connect to MPIO player", + mpiosh_cmd_close, NULL }, + { "quit", (char *[]){ "exit", NULL }, NULL, + " exit mpiosh and close the device", + mpiosh_cmd_quit, NULL }, + { "mget", (char *[]){ "get", NULL }, "list of filenames and ", + " read all files matching the regular expression\n" + " from the selected memory card", + mpiosh_cmd_mget, mpiosh_readline_comp_mpio_file }, + { "mput", (char *[]){ "put", NULL }, "list of filenames and ", + " write all local files matching the regular expression\n" + " to the selected memory card", + mpiosh_cmd_mput, NULL }, + { "mdel", (char *[]){ "rm", "del", NULL }, "", + " deletes all files matching the regular expression\n" + " from the selected memory card", + mpiosh_cmd_mdel, mpiosh_readline_comp_mpio_file }, + { "dump", NULL, NULL, + " get all files of current memory card", + mpiosh_cmd_dump, NULL }, + { "free", NULL, NULL, + " display amount of available bytes of current memory card", + mpiosh_cmd_free, NULL }, + { "format", NULL, NULL, + " format current memory card", + mpiosh_cmd_format, NULL }, + { "switch", NULL, " ", + " switches the order of two files", + mpiosh_cmd_switch, mpiosh_readline_comp_mpio_file }, + { "rename", (char *[]){ "ren", NULL }, " ", + " renames a file on the current memory card", + mpiosh_cmd_rename, mpiosh_readline_comp_mpio_file }, + { "ldir", (char *[]){ "lls", NULL }, NULL, + " list local directory", + mpiosh_cmd_ldir, NULL }, + { "lpwd", NULL, NULL, + " print current working directory", + mpiosh_cmd_lpwd, NULL }, + { "lcd", NULL, NULL, + " change the current working directory", + mpiosh_cmd_lcd, NULL }, + { "lmkdir", NULL, NULL, + " create a local directory", + mpiosh_cmd_lmkdir, NULL }, + { "health", NULL, NULL, + " show the health status from the selected memory", + mpiosh_cmd_health, NULL }, + { "font_upload", NULL, "[]", + " upload the give fontfile to the internal memory", + mpiosh_cmd_font_upload, NULL }, + { "dump_memory", NULL, NULL, + " dump FAT, directory, spare area and the first 0x100 of the\n" + " selected memory card", + mpiosh_cmd_dump_mem, NULL }, + { "backup", NULL, NULL, + " create a backup of all known configuration files.", + mpiosh_cmd_backup, NULL }, + { "restore", NULL, NULL, + " restore an existing backup of all known configuration files.", + mpiosh_cmd_restore, NULL }, +#if 0 + /* deactivated for the 0.6.0 release because the code is incomplete! -mager */ + { "config", (char *[]) { "conf", NULL }, "[read|write|show]", + " give access to the configuration file of the MPIO player\n" + " read read the configuration file and dump it on the local disc\n" + " write write the configuration back to the MPIO player\n" + " show show the current configuration", + mpiosh_cmd_config, mpiosh_readline_comp_config }, + { "channel", (char *[]) { "channels", "chan", NULL }, "[read|write|show]", + " give access to the radio channel file of the MPIO player\n" + " read read the channel file and dump it on the local disc\n" + " write write the channel file back to the MPIO player\n" + " show show the current channel configuration", + mpiosh_cmd_channel, mpiosh_readline_comp_config }, +#endif + { NULL, NULL, NULL, NULL, NULL, NULL } +}; + +/* end of global.c */ diff --git a/src/global.h b/src/global.h new file mode 100644 index 0000000..1e52491 --- /dev/null +++ b/src/global.h @@ -0,0 +1,68 @@ +/* global.h + * + * Author: Andreas Buesching + * + * $Id: global.h,v 1.3 2003/06/27 12:21:22 crunchy Exp $ + * + * Copyright (C) 2001-2003 Andreas Büsching + * + * 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_GLOBAL_HH +#define MPIOSH_GLOBAL_HH + +#include "libmpio/mpio.h" + +#include "config.h" + +/* type definitions */ +typedef void(*mpiosh_cmd_callback_t)(char *args[]); +typedef char *(*mpiosh_comp_callback_t)(const char *text, int state); + +struct mpiosh_t { + mpio_t * dev; + mpio_mem_t card; + const char * prompt; + struct mpiosh_config_t *config; +}; + +struct mpiosh_cmd_t { + char *cmd; + char **aliases; + char *args; + char *info; + mpiosh_cmd_callback_t cmd_func; + mpiosh_comp_callback_t comp_func; +}; + +/* global structures */ +extern struct mpiosh_t mpiosh; +extern struct mpiosh_cmd_t commands[]; +extern int mpiosh_cancel; +extern int mpiosh_cancel_ack; + +extern const char *CONFIG_GLOBAL; +extern const char *CONFIG_USER; +extern const char *CONFIG_BACKUP; +extern const char *CONFIG_FILE; +extern const char *CONFIG_HISTORY; + +extern const char *PROMPT_INT; +extern const char *PROMPT_EXT; + +#endif + +/* end of global.h */ diff --git a/src/mpiosh.c b/src/mpiosh.c new file mode 100644 index 0000000..e74278d --- /dev/null +++ b/src/mpiosh.c @@ -0,0 +1,163 @@ +/* -*- linux-c -*- */ + +/* + * + * $Id: mpiosh.c,v 1.27 2003/08/25 19:38:57 crunchy Exp $ + * + * Author: Andreas Büsching + * + * 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 +#include +#include +#include + +#include "libmpio/debug.h" +#include "libmpio/mpio.h" + +#include "callback.h" +#include "command.h" +#include "cfg.h" +#include "readline.h" +#include "mpiosh.h" + +/* mpiosh core functions */ +void +mpiosh_init(void) +{ + /* set state */ + mpiosh.dev = NULL; + mpiosh.config = NULL; + mpiosh.prompt = NULL; + + /* read configuration */ + mpiosh.config = mpiosh_config_new(); + if (mpiosh.config) + mpiosh_config_read(mpiosh.config); + + mpiosh.card = mpiosh.config->default_mem; + if (mpiosh.config->default_mem == MPIO_EXTERNAL_MEM) + mpiosh.prompt = mpiosh.config->prompt_ext; + else + mpiosh.prompt = mpiosh.config->prompt_int; + + /* inital mpio library */ + mpiosh.dev = mpio_init(mpiosh_callback_init); + + printf("\n"); + + if ((mpiosh.dev) && (mpiosh.config->charset)) + mpio_charset_set(mpiosh.dev, mpiosh.config->charset); +} + +void +mpiosh_signal_handler(int signal) +{ + mpiosh_cancel = 1; + mpiosh_cancel_ack = 0; +} + +int +main(int argc, char *argv[]) { + char *line; + char **cmds, **walk; + struct mpiosh_cmd_t *cmd; + struct sigaction sigc; + int interactive = 1; + + UNUSED(argc); + UNUSED(argv); + + setenv("mpio_debug", "", 0); + setenv("mpio_color", "", 0); + + /* no unwanted interruption anymore */ + sigc.sa_handler = mpiosh_signal_handler; + sigc.sa_flags = SA_NOMASK; + + sigaction(SIGINT, &sigc, NULL); + + /* init readline and history */ + mpiosh_readline_init(); + debug_init(); + mpiosh_init(); + + if (!isatty(fileno(stdin))) { + interactive = 0; + mpiosh.prompt = NULL; + mpiosh_readline_pipe(); + } + + if( !isatty(fileno(stdout)) ) { + setvbuf( stdout, NULL, _IOLBF, 256 ); + } + + if (!mpiosh.dev && interactive) { + printf("ERROR: %s\n", mpio_strerror(mpio_errno())); + printf("could not find MPIO player.\n"); + } + + while ((line = readline(mpiosh.prompt))) { + if ((*line == '\0') || mpiosh_cancel) { + rl_clear_pending_input (); + mpiosh_cancel = 0; + mpiosh_cancel_ack = 0; + continue; + } + + cmds = mpiosh_command_split_line(line); + + if (cmds[0][0] == '\0') { + free(cmds); + continue; + } + + walk = cmds; + while (*walk) { + cmd = mpiosh_command_find(*walk); + + if (cmd) { + char ** help, **args = mpiosh_command_get_args(*walk); + help = args; + + if (!interactive) debug("running... '%s'\n", *walk); + cmd->cmd_func(args); + mpiosh_command_free_args(args); + } else + fprintf(stderr, "unknown command: '%s'\n", *walk); + +/* if ((idx = history_search(line, -1)) != -1) */ +/* history_set_pos(idx); */ +/* else */ + add_history(line); + free(*walk); + walk++; + } + free(cmds); + + /* reset abort state */ + mpiosh_cancel = 0; + } + + mpiosh_cmd_quit(NULL); + + return 0; +} diff --git a/src/mpiosh.h b/src/mpiosh.h new file mode 100644 index 0000000..8291178 --- /dev/null +++ b/src/mpiosh.h @@ -0,0 +1,37 @@ +/* mpiosh.h + * + * Author: Andreas Büsching + * + * $Id: mpiosh.h,v 1.8 2002/10/12 20:06:22 crunchy Exp $ + * + * Copyright (C) 2002 Andreas Büsching + * + * 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_ + +#include "libmpio/debug.h" + +#include "global.h" + +/* mpiosh core functions */ +void mpiosh_signal_handler(int signal); +void mpiosh_init(void); + +#endif // _MPIOSH_H_ + +/* end of mpiosh.h */ diff --git a/src/readline.c b/src/readline.c new file mode 100644 index 0000000..afc78c0 --- /dev/null +++ b/src/readline.c @@ -0,0 +1,212 @@ +/* readline.c + * + * Author: Andreas Büsching + * + * $Id: readline.c,v 1.7 2003/04/23 08:34:16 crunchy Exp $ + * + * Copyright (C) 2001 Andreas Büsching + * + * 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_onoff(const char *text, int state) +{ + static const char * states[] = { "on", "off", NULL }; + static const char ** st = states; + const char * ret = NULL; + + if (state == 0) { + st = states; + } + + while (*st) { + if (!strncmp(text, *st, strlen(text))) { + ret = *st; + st++; + break; + } + st++; + } + + return (ret ? strdup(ret) : NULL); +} + +char * +mpiosh_readline_comp_cmd(const char *text, int state) +{ + static struct mpiosh_cmd_t *cmd = NULL; + static char **alias = NULL; + char *cmd_text = NULL; + + if (state == 0) { + cmd = commands; + } + + while (cmd->cmd) { + if (!alias) { + if ((*text == '\0') || (strstr(cmd->cmd, text) == cmd->cmd)) { + cmd_text = strdup(cmd->cmd); + if (cmd->aliases) alias = cmd->aliases; + else cmd++; + break; + } + if (cmd->aliases) alias = cmd->aliases; + else cmd++; + } else { + int break_it = 0; + + while (*alias) { + if (strstr(*alias, text) == *alias) { + cmd_text = strdup(*alias); + alias++; + break_it = 1; + break; + } + alias++; + } + if (break_it) break; + if (*alias == NULL) cmd++, alias = NULL; + } + } + + 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, type; + char fname[100]; + WORD year; + DWORD fsize; + + if (mpiosh.dev == NULL) { + rl_attempted_completion_over = 1; + return NULL; + } + + 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, &type); + + 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_comp_config(const char *text, int state) +{ + static char *args[] = { "put", "write", "show", NULL }; + static char **arg = NULL; + char *res = NULL; + + if (state == 0) arg = args; + if (*arg && (strstr(*arg, text) == *arg)) { + res = strdup(*arg); + arg++; + } + + return res; +} + + +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 { + struct 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/src/readline.h b/src/readline.h new file mode 100644 index 0000000..a0bb08a --- /dev/null +++ b/src/readline.h @@ -0,0 +1,47 @@ +/* readline.h + * + * Author: Andreas Büsching + * + * $Id: readline.h,v 1.3 2003/04/23 08:34:16 crunchy Exp $ + * + * Copyright (C) 2001 Andreas Büsching + * + * 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 + +#include +#include + +/* 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_onoff(const char *text, int state); +char *mpiosh_readline_comp_mpio_file(const char *text, int state); +char *mpiosh_readline_comp_config(const char *text, int state); + +#endif + +/* end of readline.h */ -- cgit v1.2.3