* attach channels to devices
*/
-#include "common.h"
-#include <string.h>
-#include <stdbool.h>
+#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]]]
*
*
*/
-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;
return CMD_RET_SUCCESS;
}
- /* reset getopt() */
- optind = 0;
-
int opt;
while ((opt = getopt(argc, argv, PSTR("darwo:"))) != -1) {
switch (opt) {
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) {
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;
}