X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/b30c4e8f1aef96f6fdc93da9f125545f5f74d06e..52ef24e4020adcb773adcb0d82b1c2c385610461:/avr/cmd_attach.c?ds=sidebyside diff --git a/avr/cmd_attach.c b/avr/cmd_attach.c index e9b5ccd..651404f 100644 --- a/avr/cmd_attach.c +++ b/avr/cmd_attach.c @@ -8,43 +8,13 @@ * attach channels to devices */ -#include "common.h" -#include -#include +#include "cmd_attach.h" #include "command.h" #include "z180-serv.h" #include "getopt-min.h" -static const FLASH char * const FLASH rc_messages[] = { - FSTR("OK"), - FSTR("Unknown error"), - FSTR("Disk number out of range 0..7"), - FSTR("Disk allready attached"), - FSTR("Disk not attached"), - FSTR("File not found"), - FSTR("Not enough memory"), - FSTR("Error opening file"), - FSTR("File allready attached to other drive"), - }; - -static -void printerror(int rc, uint8_t unit, char *fn) -{ - if (rc < 0 || (unsigned) rc >= ARRAY_SIZE(rc_messages)) - rc = 1; - -#if GCC_BUG_61443 - printf_P(PSTR("Attachment of '%s' to dsk%d failed: "), fn, unit); - my_puts_P(rc_messages[rc]); - my_puts_P(PSTR("!\n")); -#else - printf_P(PSTR("Attachment of '%s' to dsk%d failed: %S!\n"), - fn, unit, rc_messages[rc]); -#endif -} - /* * attach [[options] [unit [diskfile]]] * @@ -58,9 +28,9 @@ void printerror(int rc, uint8_t unit, char *fn) * */ -command_ret_t do_attach(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +command_ret_t do_attach(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]) { - uint8_t unit; + uint8_t unit = 0; char *filename = NULL; bool detach = false; bool detach_all = false; @@ -79,9 +49,6 @@ command_ret_t do_attach(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ return CMD_RET_SUCCESS; } - /* reset getopt() */ - optind = 0; - int opt; while ((opt = getopt(argc, argv, PSTR("darwo:"))) != -1) { switch (opt) { @@ -136,8 +103,7 @@ command_ret_t do_attach(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ strncmp_P(argv[optind], PSTR("dsk"), 3) || (unit = argv[optind][3] - '0') >= CONFIG_CPM_MAX_DRIVE)) { - printf_P(PSTR("Unknown device: '%s'\n"), argv[optind]); - return CMD_RET_FAILURE; + cmd_error(CMD_RET_FAILURE, 0, PSTR("Invalid device: '%s'"), argv[optind]); } if (detach) { @@ -154,7 +120,7 @@ command_ret_t do_attach(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ res = drv_attach(unit, filename, options); if (res) - printerror(res, unit, filename); + cmd_error(CMD_RET_FAILURE, res, PSTR("Attachment of '%s' to dsk%d failed"), filename, unit); - return res ? CMD_RET_FAILURE : CMD_RET_SUCCESS; + return CMD_RET_SUCCESS; }