]>
cloudbase.mooo.com Git - z180-stamp.git/blob - avr/cmd_attach.c
e1a3b2c9052467403a6c0990c36eb146c357f461
2 * (C) Copyright 2016 Leo C. <erbl259-lmu@yahoo.de>
4 * SPDX-License-Identifier: GPL-2.0
8 * attach chanels to devices
16 #include "z180-serv.h"
17 #include "getopt-min.h"
18 //#include "print-utils.h"
19 //#include "con-utils.h"
25 static const FLASH
char * const FLASH rc_messages
[] = {
27 FSTR("Unknown error"),
28 FSTR("Disk number out of range 0..7"),
29 FSTR("Disk allready attached"),
30 FSTR("Disk not attached"),
31 FSTR("File not found"),
32 FSTR("Not enough memory"),
33 FSTR("Error opening file"),
34 FSTR("File allready attached to other drive"),
38 void printerror(int rc
, uint8_t unit
, char *fn
)
40 if (rc
< 0 || (unsigned) rc
>= ARRAY_SIZE(rc_messages
))
44 printf_P(PSTR("rc=%u FR_"), rc
);
45 my_puts_P(rc_names
[rc
]);
46 my_puts_P(PSTR("\n"));
48 printf_P(PSTR("Attachment of '%s' to dsk%d failed: %S!\n"),
49 fn
, unit
, rc_messages
[rc
]);
54 * attach [[options] [unit [diskfile]]]
59 * attach -o reattach unit
60 * attach -o reattach unit diskfile
62 * attach unit diskfile
66 command_ret_t
do_attach(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
69 char *filename
= NULL
;
71 drv_opt_t options
= 0;
74 (void) cmdtp
; (void) flag
;
77 if (argv
[0][0] == 'd')
78 /* we are called as 'detach' */
84 return CMD_RET_SUCCESS
;
91 while ((opt
= getopt(argc
, argv
, PSTR("drwo:"))) != -1) {
97 options
|= DRV_OPT_RO
;
100 options
&= ~DRV_OPT_RO
;
104 static const FLASH
char delim
[] = {", "};
105 char *p
= strtok_P(optarg
, delim
);
107 if (!strcmp_P(p
, PSTR("ro")))
108 options
|= DRV_OPT_RO
;
109 else if (!strcmp_P(p
, PSTR("rw")))
110 options
&= ~DRV_OPT_RO
;
111 else if (!strcmp_P(p
, PSTR("debug")))
112 options
|= DRV_OPT_DEBUG
;
113 else if (!strcmp_P(p
, PSTR("nodebug")))
114 options
&= ~DRV_OPT_DEBUG
;
115 else if (!strcmp_P(p
, PSTR("reattach")))
116 options
|= DRV_OPT_REATTATCH
;
118 return CMD_RET_USAGE
;
120 p
= strtok_P(NULL
, delim
);
125 return CMD_RET_USAGE
;
129 /* remaining arguments */
131 if ( !((detach
&& argc
== 1) ||
132 ((options
& DRV_OPT_REATTATCH
) && argc
== 1) ||
134 return CMD_RET_USAGE
;
136 if ((strlen(argv
[optind
]) != 4) ||
137 strncmp_P(argv
[optind
], PSTR("dsk"), 3) ||
138 (unit
= argv
[optind
][3] - '0') >= CONFIG_CPM_MAX_DRIVE
) {
140 printf_P(PSTR("Unknown device: '%s'\n"), argv
[optind
]);
141 return CMD_RET_FAILURE
;
145 res
= drv_detach(unit
);
146 return CMD_RET_SUCCESS
;
150 filename
= argv
[++optind
];
152 res
= drv_attach(unit
, filename
, options
);
154 printerror(res
, unit
, filename
);
156 return res
? CMD_RET_FAILURE
: CMD_RET_SUCCESS
;