r99: *** empty log message ***
[ctsim.git] / libctsupport / consoleio.cpp
1 /*****************************************************************************
2 **  This is part of the CTSim program
3 **  Copyright (C) 1983-2000 Kevin Rosenberg
4 **
5 **  $Id: consoleio.cpp,v 1.1 2000/06/19 02:58:08 kevin Exp $
6 **
7 **  This program is free software; you can redistribute it and/or modify
8 **  it under the terms of the GNU General Public License (version 2) as
9 **  published by the Free Software Foundation.
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 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
19 ******************************************************************************/
20
21 #include <stdio.h>
22 #include <string.h>
23 #include "cio.h"
24 #include "kstddef.h"
25 #include "cio.h"
26
27
28
29 /* NAME
30  *   cio_put_c                          Put a character on screen
31  *
32  * SYNOPSIS
33  *   cio_put_c (c)
34  *   char c                             Character to write
35  *
36  * NOTES
37  *   Color of character is determined by the global variable, crtv.text_attr.
38  *
39  * SIDE EFFECTS
40  *   Cursor is advanced by one.  If necessary, the cursor will wrap around
41  *   and maybe the screen will scroll
42  */
43
44 void 
45 cio_put_c (int c)
46 {
47     fputc(c, stdout);
48 }
49
50
51
52 /* NAME
53  *    cio_put_cc                        Put a char on screen count times
54  *
55  * SYNOPSIS
56  *    cio_put_cc (c, count)
57  *    char c                            Character to write
58  *    int count                         Number of characters to write
59  */
60
61 void 
62 cio_put_cc (int c, int count)
63 {
64     for (int i = 0; i < count; i++)
65         cio_put_c (c);
66 }
67
68
69 void 
70 cio_put_str (const char *str)
71 {
72     fputs (str, stdout);
73 }
74
75
76
77 /* NAME
78  *   kb_getc                    Get a character from the keyboard
79  *
80  * SYNOPSIS
81  *   key = kb_getc()
82  *
83  * DESCRIPTION
84  *      1. This routine returns an EXTENTED ASCII code,
85  *         the extended codes have a low byte of 0 and a distinctive
86  *         high byte, such as 0x2D00 and 0x3200
87  *      2. This routine waits until a key has been typed
88  *      2. The keystroke will not be echoed.
89  */
90
91 unsigned int cio_kb_getc(void)
92 {
93     return fgetc(stdin);
94 }
95
96 void 
97 cio_kb_ungetc (unsigned int c)
98 {
99     ungetc(c, stdin);
100 }
101
102 /* NAME
103  *    kb_gets                           Get a string from the keyboard
104  *
105  * SYNOPSIS
106  *    str = kb_gets (str, maxlen)
107  *    char *str                         Space to store input string
108  *    int maxlen                        Maximum number of characters to read
109  *                                      (Not including EOS)
110  * NOTES
111  *    Backspace - erases character to the right
112  *    Escape    - erases to beginning of line
113  *    Return    - ends string (no not cause a linefeed)
114  */
115
116 char *
117 cio_kb_gets (char *str, int maxlen)
118 {
119     return fgets(str, maxlen, stdin);
120 }
121
122 /* NAME
123  *   kb_waitc                   Wait for a character from the keyboard
124  *
125  * SYNOPSIS
126  *   key = kb_waitc (astr, estr, beep)
127  *   int key                    Keystroke entered
128  *   char *astr                 String of valid ascii characters
129  *   bool beep                  If TRUE, beep when user hits invalid key
130  *
131  */
132
133
134 unsigned int
135 cio_kb_waitc (const char *astr, int beep_on_error)
136 {
137   unsigned int c;
138   do {
139     c = cio_kb_getc ();
140     if (strchr (astr, c) != NULL)
141         break;
142     if (beep_on_error)
143       cio_beep();
144   } while (1);
145   
146   return (c);
147 }
148
149