1 /********************************************************************/
2 /* */
3 /* s7 Seed7 interpreter */
4 /* Copyright (C) 1990 - 2000 Thomas Mertes */
5 /* */
6 /* This program is free software; you can redistribute it and/or */
7 /* modify it under the terms of the GNU General Public License as */
8 /* published by the Free Software Foundation; either version 2 of */
9 /* the License, or (at your option) any later version. */
10 /* */
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. */
15 /* */
16 /* You should have received a copy of the GNU General Public */
17 /* License along with this program; if not, write to the */
18 /* Free Software Foundation, Inc., 51 Franklin Street, */
19 /* Fifth Floor, Boston, MA 02110-1301, USA. */
20 /* */
21 /* Module: Library */
22 /* File: seed7/src/kbdlib.c */
23 /* Changes: 1992, 1993, 1994 Thomas Mertes */
24 /* Content: All primitive actions to do keyboard input. */
25 /* */
26 /********************************************************************/
27
28 #include "version.h"
29
30 #include "stdlib.h"
31 #include "stdio.h"
32 #include "string.h"
33
34 #include "common.h"
35 #include "data.h"
36 #include "heaputl.h"
37 #include "flistutl.h"
38 #include "syvarutl.h"
39 #include "striutl.h"
40 #include "objutl.h"
41 #include "runerr.h"
42 #include "kbd_rtl.h"
43 #include "kbd_drv.h"
44 #include "con_drv.h"
45
46 #undef EXTERN
47 #define EXTERN
48 #include "kbdlib.h"
49
50
51
52 /**
53 * Read a char from keyboard, but don't wait if no key was pressed.
54 * @return the char read from the console keyboard file, or
55 * KEY_NONE if no char is available.
56 */
kbd_busy_getc(listType arguments)57 objectType kbd_busy_getc (listType arguments)
58
59 { /* kbd_busy_getc */
60 if (kbdKeyPressed()) {
61 return bld_char_temp(kbdGetc());
62 } else {
63 return bld_char_temp((charType) K_NONE);
64 } /* if */
65 } /* kbd_busy_getc */
66
67
68
69 /**
70 * Read a character from the console keyboard file.
71 * @return the character read.
72 */
kbd_getc(listType arguments)73 objectType kbd_getc (listType arguments)
74
75 { /* kbd_getc */
76 return bld_char_temp(kbdGetc());
77 } /* kbd_getc */
78
79
80
81 /**
82 * Read a string with maximum length from the console keyboard file.
83 * @return the string read.
84 */
kbd_gets(listType arguments)85 objectType kbd_gets (listType arguments)
86
87 { /* kbd_gets */
88 isit_int(arg_2(arguments));
89 return bld_stri_temp(
90 kbdGets(take_int(arg_2(arguments))));
91 } /* kbd_gets */
92
93
94
95 /**
96 * Determine if at least one character can be read without waiting.
97 * @return TRUE if a character is available at the console keyboard file
98 * FALSE otherwise.
99 */
kbd_keypressed(listType arguments)100 objectType kbd_keypressed (listType arguments)
101
102 { /* kbd_keypressed */
103 if (kbdKeyPressed()) {
104 return SYS_TRUE_OBJECT;
105 } else {
106 return SYS_FALSE_OBJECT;
107 } /* if */
108 } /* kbd_keypressed */
109
110
111
112 /**
113 * Read a line from the console keyboard file.
114 * The function accepts lines ending with "\n", "\r\n" or EOF.
115 * The line ending characters are not copied into the string.
116 * That means that the "\r" of a "\r\n" sequence is silently removed.
117 * When the function is left terminationChar/arg_2 contains '\n' or EOF.
118 * @return the line read.
119 */
kbd_line_read(listType arguments)120 objectType kbd_line_read (listType arguments)
121
122 {
123 objectType ch_variable;
124
125 /* kbd_line_read */
126 ch_variable = arg_2(arguments);
127 isit_char(ch_variable);
128 is_variable(ch_variable);
129 return bld_stri_temp(
130 kbdLineRead(&ch_variable->value.charValue));
131 } /* kbd_line_read */
132
133
134
kbd_raw_getc(listType arguments)135 objectType kbd_raw_getc (listType arguments)
136
137 { /* kbd_raw_read */
138 return bld_char_temp(kbdRawGetc());
139 } /* kbd_raw_read */
140
141
142
143 /**
144 * Read a word from the console keyboard file.
145 * Before reading the word it skips spaces and tabs. The function
146 * accepts words ending with " ", "\t", "\n", "\r\n" or EOF.
147 * The word ending characters are not copied into the string.
148 * That means that the "\r" of a "\r\n" sequence is silently removed.
149 * When the function is left terminationChar/arg_2 contains ' ',
150 * '\t', '\n' or EOF.
151 * @return the word read.
152 */
kbd_word_read(listType arguments)153 objectType kbd_word_read (listType arguments)
154
155 {
156 objectType ch_variable;
157
158 /* kbd_word_read */
159 ch_variable = arg_2(arguments);
160 isit_char(ch_variable);
161 is_variable(ch_variable);
162 return bld_stri_temp(
163 kbdWordRead(&ch_variable->value.charValue));
164 } /* kbd_word_read */
165