r6308@lvps87-230-33-50: verhaegs | 2007-12-03 22:24:30 +0100
[AROS.git] / test / consolemodes.c
blob5fb5d0c655a0fcccc1805fe75a7e3af4ac1546da
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 struct IOFileSys iofs;
14 struct FileHandle *fh;
16 in = Input();
17 out = Output();
19 SetMode(in, 0);
21 Printf("in normal (cooked) mode\n");
22 Printf("type something: ");
23 Flush(out);
25 FGets(out, something, 64);
26 *(strchr(something, '\n')) = '\0';
28 Printf("you typed: %s\n", something);
30 SetMode(in, 1);
32 Printf("in raw mode\n");
33 Printf("type something: ");
34 Flush(out);
36 something[63] = '\0';
37 i = 0;
38 while (i < 63) {
39 WaitForChar(in, 0);
40 Read(in, &(something[i]), 1);
41 if (something[i] == 0x0d) {
42 something[i] = '\0';
43 break;
45 if (! isprint(something[i]))
46 continue;
47 i++;
50 Printf("\nyou typed: %s\n", something);
52 fh = (struct FileHandle *) in;
54 iofs.IOFS.io_Message.mn_Node.ln_Type = NT_REPLYMSG;
55 iofs.IOFS.io_Message.mn_ReplyPort = &(((struct Process *) FindTask(NULL))->pr_MsgPort);
56 iofs.IOFS.io_Message.mn_Length = sizeof(struct IOFileSys);
58 iofs.IOFS.io_Device = fh->fh_Device;
59 iofs.IOFS.io_Unit = fh->fh_Unit;
60 iofs.IOFS.io_Command = FSA_CONSOLE_MODE;
61 iofs.IOFS.io_Flags = 0;
63 iofs.io_Union.io_CONSOLE_MODE.io_ConsoleMode = FCM_NOECHO;
65 DoIO(&(iofs.IOFS));
67 Printf("in cooked mode with no echoing\n");
68 Printf("type something: ");
69 Flush(out);
71 FGets(out, something, 64);
72 *(strchr(something, '\n')) = '\0';
74 Printf("you typed: %s\n", something);
76 SetMode(in, 0);
78 Printf("restored normal (cooked) mode\n");
80 return 0;