Imported Upstream version 0.1beta
[debian/yforth] / udio.c
1 /* yForth? - Written by Luca Padovani (C) 1996/97
2  * ------------------------------------------------------------------------
3  * This software is FreeWare as long as it comes with this header in each
4  * source file, anyway you can use it or any part of it whatever
5  * you want. It comes without any warranty, so use it at your own risk.
6  * ------------------------------------------------------------------------
7  * Module name: udio.c
8  * Abstract:    User Device Input/Output functions. Here are enclosed all
9  *              non-portable functions.
10  */
11
12 #include "yforth.h"
13 #ifdef HAVE_CONIO
14 #       include <conio.h>
15 #elifdef HAVE_CURSES
16 #       include <curses.h>
17 #endif
18 #include "udio.h"
19
20 /* d_clrscr: clear the screen */
21 void d_clrscr() {
22 #ifdef HAVE_CONIO
23         clrscr();
24 #elifdef HAVE_CURSES
25         clear();
26 #endif
27 }
28
29 /* d_clreol: clear to end of line */
30 void d_clreol() {
31 #ifdef HAVE_CONIO
32         clreol();
33 #elifdef HAVE_CURSES
34         clrtoeol();
35 #endif
36 }
37
38 /* d_setattr: set default attributes */
39 void d_setaddr(Cell attr) {
40 #ifdef HAVE_CONIO
41         textattr(attr);
42 #elifdef HAVE_CURSES
43 #endif
44 }
45
46 /* d_getattr: get default attributes */
47 Cell d_getattr() {
48 #ifdef HAVE_CONIO
49         struct text_info ti;
50         gettextinfo(&ti);
51         return (ti.attribute);
52 #elifdef HAVE_CURSES
53 #endif
54 }
55
56 /* d_gotoxy: move the cursor to the location (x, y) of the screen */
57 void d_gotoxy(Cell x, Cell y) {
58 #ifdef HAVE_CONIO
59         gotoxy(x, y);
60 #elifdef HAVE_CURSES
61         move(y, x);
62 #endif
63 }
64
65 /* d_wherex: current column position of the cursor */
66 Cell d_wherex() {
67 #ifdef HAVE_CONIO
68         return (wherex());
69 #elifdef HAVE_CURSES
70         int x, y;
71         getyx(stdscr, y, x);
72         return ((Cell) x);
73 #endif
74 }
75
76 /* d_wherey: current row position of the cursor */
77 Cell d_wherey() {
78 #ifdef HAVE_CONIO
79         return (wherey());
80 #elifdef HAVE_CURSES
81         int x, y;
82         getyx(stdscr, y, x);
83         return ((Cell) y);
84 #endif
85 }
86
87 /* d_getch: read a characted from the input device without displaying it and
88  * return as soon as the character is enteres (i.e. no wait for Carriage 
89  * Return
90  */
91 Char d_getch() {
92 #ifdef HAVE_CONIO
93         return (getch());
94 #elifdef HAVE_CURSES
95         return (getch());
96 #endif 
97 }
98
99 /* d_kbhit: return True if a character is available */
100 Cell d_kbhit() {
101 #ifdef HAVE_CONIO
102         return (kbhit());
103 #elifdef HAVE_CURSES
104         return (1);
105 #endif 
106 }
107
108 /* d_open: Initialize the Input/Output device */
109 void d_open() {
110 #ifdef HAVE_CURSES
111         initscr();
112         cbreak();
113         noecho();
114         nonl();
115         /* intrflush(stdscr, FALSE); */
116         /* keypad(stdscr, TRUE); */
117 #endif
118
119
120 /* d_close: make some work when program finish to restore Input/Output device */
121 void d_close() {
122 #ifdef HAVE_CURSES
123         endwin();
124 #endif
125 }
126
127
128
129
130
131
132
133
134