backport
[AROS.git] / test / consolemodes.c
blob8abb970314a95362d603313a9990e1fbdb7927af
1 #include <exec/types.h>
2 #include <proto/exec.h>
3 #include <proto/dos.h>
4 #include <dos/filesystem.h>
5 #include <string.h>
6 #include <stdlib.h>
7 #include <ctype.h>
9 int main(int argc, char **argv) {
10 BPTR in, out;
11 TEXT something[64];
12 int i;
13 #ifndef AROS_DOS_PACKETS
14 struct IOFileSys iofs;
15 struct FileHandle *fh;
16 #endif
18 in = Input();
19 out = Output();
21 SetMode(in, 0);
23 Printf("in normal (cooked) mode\n");
24 Printf("type something: ");
25 Flush(out);
27 FGets(out, something, 64);
28 *(strchr(something, '\n')) = '\0';
30 Printf("you typed: %s\n", something);
32 SetMode(in, 1);
34 Printf("in raw mode\n");
35 Printf("type something: ");
36 Flush(out);
38 something[63] = '\0';
39 i = 0;
40 while (i < 63) {
41 WaitForChar(in, 0);
42 Read(in, &(something[i]), 1);
43 if (something[i] == 0x0d) {
44 something[i] = '\0';
45 break;
47 if (! isprint(something[i]))
48 continue;
49 i++;
52 Printf("\nyou typed: %s\n", something);
54 #ifdef AROS_DOS_PACKETS
55 /* TODO: Switch to cooked mode */
56 #else
57 fh = (struct FileHandle *) in;
59 iofs.IOFS.io_Message.mn_Node.ln_Type = NT_REPLYMSG;
60 iofs.IOFS.io_Message.mn_ReplyPort = &(((struct Process *) FindTask(NULL))->pr_MsgPort);
61 iofs.IOFS.io_Message.mn_Length = sizeof(struct IOFileSys);
63 iofs.IOFS.io_Device = fh->fh_Device;
64 iofs.IOFS.io_Unit = fh->fh_Unit;
65 iofs.IOFS.io_Command = FSA_CONSOLE_MODE;
66 iofs.IOFS.io_Flags = 0;
68 iofs.io_Union.io_CONSOLE_MODE.io_ConsoleMode = FCM_NOECHO;
70 DoIO(&(iofs.IOFS));
71 #endif
73 Printf("in cooked mode with no echoing\n");
74 Printf("type something: ");
75 Flush(out);
77 FGets(out, something, 64);
78 *(strchr(something, '\n')) = '\0';
80 Printf("you typed: %s\n", something);
82 SetMode(in, 0);
84 Printf("restored normal (cooked) mode\n");
86 return 0;