Debian Codegraph @

terps/advsys/advtrm.c

raw symbols SCIP
1
2 /* advtrm.c - terminal i/o routines */
3 /*
4 Copyright (c) 1986, by David Michael Betz
5 All rights reserved
6 */
7
8 #include "header.h"
9
10 /* useful definitions */
11 #define TRUE 1
12 #define FALSE 0
13 #define EOS '\0'
14 #define LINEMAX 200
15 #define WORDMAX 100
16
17 /* global variables */
18 char line[LINEMAX+1];
19
20 /* local variables */
21 static int col,maxcol,row,maxrow;
22 static int scnt,wcnt;
23 static char word[WORDMAX+1],*wptr;
24 static FILE *logfp = NULL;
25
26 /* forward declarations */
27 char *trm_line(char *line);
28
29 /* trm_init - initialize the terminal module */
30 void trm_init(int rows, int cols, char *name)
31 {
32 /* initialize the terminal i/o variables */
33 maxcol = cols-1; col = 0;
34 maxrow = rows-1; row = 0;
35 wptr = word; wcnt = 0;
36 scnt = 0;
37
38 }
39
40 /* trm_done - finish terminal i/o */
41 void trm_done()
42 {
43 /* Do nothing now */
44 }
45
46 /* trm_get - get a line */
47 char *trm_get(char *line)
48 {
49 return (trm_line(line));
50 }
51
52 /* trm_str - output a string */
53 void trm_str(char *str)
54 {
55 glk_put_string(str);
56 }
57
58 /* trm_xstr - output a string without logging or word wrap */
59 void trm_xstr(char *str)
60 {
61 glk_put_string(str);
62 }
63
64 /* trm_chr - output a character */
65 void trm_chr(int ch)
66 {
67 if (ch == '\t')
68 glk_put_string(" ");
69 else
70 glk_put_char(ch);
71 }
72
73 /* trm_word - output the current word */
74 void trm_word()
75 {
76 /* Do nothing */
77 }
78
79 /* trm_eol - end the current line */
80 void trm_eol()
81 {
82 glk_put_char('\n');
83
84 }
85
86 /* trm_wait - wait for the user to type return */
87 void trm_wait()
88 {
89 /* Do nothing. GLK does waiting for us */
90 }
91
92 /* trm_line - get an input line */
93 char *trm_line(char *line)
94 {
95 event_t event;
96
97 glk_request_line_event(window, line, LINEMAX, 0);
98 do {
99 glk_select(&event);
100 } while (event.type != evtype_LineInput);
101
102 /* Null terminate it */
103 line[event.val1] = 0;
104
105 return line;
106 }
107