Added a test for MUIA_Listview_SelectChange.
[AROS.git] / workbench / system / BHFormat / cli.c
blob02de167be11d9889856cb9bbb08c4122120465d0
1 /*
2 * Format -- disk formatting and file-system creation program
3 * Copyright (C) 1999 Ben Hutchings <womble@zzumbouk.demon.co.uk>
4 * Copyright (C) 2008 Pavel Fedin <sonic_amiga@rambler.ru>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <dos/dos.h>
23 #include <dos/dosasl.h> /* for ERROR_BREAK definition */
24 #include <dos/dosextens.h>
25 #include <dos/filehandler.h>
26 #include <dos/rdargs.h>
27 #include <proto/dos.h>
28 #include <proto/exec.h>
30 #include "format.h"
31 #include "locale.h"
33 BPTR bpfhStdErr;
35 static struct {
36 char *pszDevice;
37 char *pszName;
38 IPTR bOFS;
39 IPTR bFFS;
40 IPTR bIntl;
41 IPTR bNoIntl;
42 #ifndef __AROS__
43 IPTR bDirCache;
44 IPTR bNoDirCache;
45 #endif
46 IPTR bNoIcons;
47 IPTR bDiskIcon;
48 IPTR bQuick;
49 IPTR bNoVerify;
50 char *pszType;
51 char *pszFlags;
52 } args;
54 #ifdef __AROS__
55 #define ARGS_TEMPLATE "DEVICE=DRIVE/K/A,NAME/K/A,OFS/S,FFS/S," \
56 "INTL=INTERNATIONAL/S,NOINTL=NOINTERNATIONAL/S," \
57 "NOICONS/S,DISKICON/S," \
58 "QUICK/S,NOVERIFY/S,TYPE=DOSTYPE/K,FLAGS/K"
59 #else
60 #define ARGS_TEMPLATE "DEVICE=DRIVE/K/A,NAME/K/A,OFS/S,FFS/S," \
61 "INTL=INTERNATIONAL/S,NOINTL=NOINTERNATIONAL/S," \
62 "DIRCACHE/S,NODIRCACHE/S,NOICONS/S,DISKICON/S," \
63 "QUICK/S,NOVERIFY/S,TYPE=DOSTYPE/K,FLAGS/K"
64 #endif
66 int rcCliMain(void)
68 struct RDArgs * prda;
69 BOOL bCloseStdErr = FALSE;
70 LONG rc = RETURN_FAIL;
71 BPTR bpfhStdIn, bpfhStdOut;
72 BOOL DirCache = FALSE;
73 BOOL NoDirCache = TRUE;
74 char ch;
76 prda = ReadArgs(ARGS_TEMPLATE, (IPTR *)&args, 0 );
77 if( prda == 0 )
79 PrintFault( IoErr(), 0 );
80 return RETURN_ERROR;
84 struct Process * pprSelf = (struct Process *)FindTask(0);
85 bpfhStdIn = pprSelf->pr_CIS;
86 bpfhStdOut = pprSelf->pr_COS;
87 bpfhStdErr = pprSelf->pr_CES;
88 /* CES is allowed to be 0; in that case the best behaviour is to
89 try opening the console, or as a last resort sending errors to
90 COS instead */
91 if( bpfhStdErr == 0 )
93 if( (bpfhStdErr = Open( "*", MODE_NEWFILE )) == 0 )
94 bpfhStdErr = bpfhStdOut;
95 else
96 bCloseStdErr = TRUE;
100 if( !bSetSzDosDeviceFromSz(args.pszDevice)
101 || !bSetSzVolumeFromSz(args.pszName)
102 || (args.pszType && !bSetFstFromSz(args.pszType))
103 || (args.pszFlags && !bSetDevfFromSz(args.pszFlags))
104 || !bGetDosDevice(NULL, 0) )
106 rc = RETURN_ERROR;
107 goto cleanup;
110 /* Get confirmation before we start the process */
111 *pchDosDeviceColon = 0;
112 Printf( _(MSG_INSERT_DISK),
113 (IPTR)szDosDevice );
114 Flush(bpfhStdOut);
115 SetMode( bpfhStdIn, 1 ); /* raw input */
117 LONG cch;
118 do {
119 cch = Read( bpfhStdIn, &ch, 1 );
120 D(Printf("Character code: %lu\n", ch));
121 } while( cch == 1 && ch != 3 && ch != 13 );
123 SetMode( bpfhStdIn, 0 ); /* cooked input */
124 PutStr("\n");
125 if (ch == 3)
127 PrintFault( ERROR_BREAK, 0 );
128 goto cleanup;
130 PutStr("\n");
132 /* Do (low-level) format unless the "QUICK" switch was used */
133 BOOL formatOk = TRUE;
134 if(!args.bQuick)
136 ULONG icyl;
138 if(!bGetExecDevice(!args.bNoVerify))
139 goto cleanup;
141 PutStr("\033[0 p"); /* turn cursor off */
142 /* TODO: arrange for cursor to be turned back on in case of error */
144 for( icyl = LowCyl;
145 icyl <= HighCyl;
146 ++icyl )
148 /* Allow the user to break */
149 if(CheckSignal(SIGBREAKF_CTRL_C))
151 PutStr("\033[ p\n");
152 D(Printf("Cancelled by user\n"));
153 PrintFault( ERROR_BREAK, 0 );
154 formatOk = FALSE;
155 break;
158 Printf( _(MSG_FORMATTING), icyl, HighCyl-icyl );
159 D(PutStr("\n"));
160 Flush(bpfhStdOut);
161 if(!bFormatCylinder(icyl))
163 formatOk = FALSE;
164 break;
167 if(!args.bNoVerify)
169 PutStr( _(MSG_VERIFYING) );
170 D(PutStr("\n"));
171 Flush(bpfhStdOut);
172 if(!bVerifyCylinder(icyl))
174 formatOk = FALSE;
175 break;
180 PutStr("\033[ p\n"); /* turn cursor on and go to next line */
183 FreeExecDevice();
185 if(formatOk)
187 PutStr( _(MSG_INITIALIZING) );
189 #ifndef __AROS__
190 DirCache = args.bDirCache;
191 NoDirCache = args.bNoDirCache;
192 #endif
193 if( bMakeFileSys( args.bFFS, args.bOFS, args.bIntl, args.bNoIntl,
194 DirCache, NoDirCache )
195 && (args.bNoIcons || bMakeFiles(args.bDiskIcon)) )
196 rc = RETURN_OK;
199 cleanup:
200 if(bCloseStdErr)
201 (void) Close(bpfhStdErr);
202 FreeArgs(prda);
204 return rc;