1cd2cd8fed/*
2cd2cd8fed |	new_curse.c
3cd2cd8fed |
4cd2cd8fed |	A subset of curses developed for use with ae.
5cd2cd8fed |
6cd2cd8fed |	written by Hugh Mahon
7cd2cd8fed |
8c24192eed |      Copyright (c) 1986, 1987, 1988, 1991, 1992, 1993, 1994, 1995, 2009 Hugh Mahon
9c24192eed |      All rights reserved.
10c24192eed |
11c24192eed |      Redistribution and use in source and binary forms, with or without
12c24192eed |      modification, are permitted provided that the following conditions
13c24192eed |      are met:
14c24192eed |
15c24192eed |          * Redistributions of source code must retain the above copyright
16c24192eed |            notice, this list of conditions and the following disclaimer.
17c24192eed |          * Redistributions in binary form must reproduce the above
18c24192eed |            copyright notice, this list of conditions and the following
19c24192eed |            disclaimer in the documentation and/or other materials provided
20c24192eed |            with the distribution.
21c24192eed |
22c24192eed |      THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23c24192eed |      "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24c24192eed |      LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25c24192eed |      FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26c24192eed |      COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27c24192eed |      INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28c24192eed |      BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29c24192eed |      LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30c24192eed |      CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31c24192eed |      LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32c24192eed |      ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33c24192eed |      POSSIBILITY OF SUCH DAMAGE.
34cd2cd8fed |
35c24192eed |
36cd2cd8fed |	All are rights reserved.
37cd2cd8fed |
38d2f3627ed |	$Header: /home/hugh/sources/old_ae/RCS/new_curse.c,v 1.54 2002/09/21 00:47:14 hugh Exp $
39cd2cd8fed |
40cd2cd8fed */
41cd2cd8fed
42c24192eedchar *copyright_message[] = { "Copyright (c) 1986, 1987, 1988, 1991, 1992, 1993, 1994, 1995, 2009 Hugh Mahon",
43cd2cd8fed				"All rights are reserved."};
44cd2cd8fed
45d2f3627edchar * new_curse_name= "@(#) new_curse.c $Revision: 1.54 $";
46cd2cd8fed
47cd2cd8fed#include "new_curse.h"
48cd2cd8fed#include <signal.h>
49cd2cd8fed#include <fcntl.h>
50cd2cd8fed
51cd2cd8fed#ifdef SYS5
52cd2cd8fed#include <string.h>
53cd2cd8fed#else
54cd2cd8fed#include <strings.h>
55cd2cd8fed#endif
56cd2cd8fed
57cd2cd8fed#ifdef BSD_SELECT
58cd2cd8fed#include <sys/types.h>
59cd2cd8fed#include <sys/time.h>
60cd2cd8fed
61cd2cd8fed#ifdef SLCT_HDR
62cd2cd8fed#include <sys/select.h>  /* on AIX */
63cd2cd8fed#endif /* SLCT_HDR */
64cd2cd8fed
65cd2cd8fed#endif /* BSD_SELECT */
66cd2cd8fed
67cd2cd8fed#ifdef HAS_STDLIB
68cd2cd8fed#include <stdlib.h>
69cd2cd8fed#endif
70cd2cd8fed
71cd2cd8fed#if defined(__STDC__)
72cd2cd8fed#include <stdarg.h>
73cd2cd8fed#else
74cd2cd8fed#include <varargs.h>
75cd2cd8fed#endif
76cd2cd8fed
77cd2cd8fed#ifdef HAS_UNISTD
78cd2cd8fed#include <unistd.h>
79cd2cd8fed#endif
80cd2cd8fed
81cd2cd8fed#ifdef HAS_SYS_IOCTL
82cd2cd8fed#include <sys/ioctl.h>
83cd2cd8fed#endif
84cd2cd8fed
85cd2cd8fed
86cd2cd8fedWINDOW *curscr;
87cd2cd8fedstatic WINDOW *virtual_scr;
88cd2cd8fedWINDOW *stdscr;
89cd2cd8fedWINDOW *last_window_refreshed;
90cd2cd8fed
91cd2cd8fed#ifdef TIOCGWINSZ
92cd2cd8fed	struct winsize ws;
93cd2cd8fed#endif
94cd2cd8fed
95cd2cd8fed#define min(a, b)	(a < b ? a : b)
96cd2cd8fed#define highbitset(a)	((a) & 0x80)
97cd2cd8fed
98cd2cd8fed#ifndef CAP
99cd2cd8fed#define String_Out(table, stack, place) Info_Out(table, stack, place)
100cd2cd8fed#else
101cd2cd8fed#define String_Out(table, stack, place) Cap_Out(table, stack, place)
102cd2cd8fed#endif
103cd2cd8fed
104cd2cd8fed#define bw__ 0	/* booleans	*/
105cd2cd8fed#define am__ 1
106cd2cd8fed#define xb__ 2
107cd2cd8fed#define xs__ 3	/* hp glitch (standout not erased by overwrite)	*/
108cd2cd8fed#define xn__ 4
109cd2cd8fed#define eo__ 5
110cd2cd8fed#define gn__ 6	/* generic type terminal	*/
111cd2cd8fed#define hc__ 7	/* hardcopy terminal		*/
112cd2cd8fed#define km__ 8
113cd2cd8fed#define hs__ 9
114cd2cd8fed#define in__ 10
115cd2cd8fed#define da__ 11
116cd2cd8fed#define db__ 12
117cd2cd8fed#define mi__ 13	/* safe to move during insert mode	*/
118cd2cd8fed#define ms__ 14	/* safe to move during standout mode	*/
119cd2cd8fed#define os__ 15
120cd2cd8fed#define es__ 16
121cd2cd8fed#define xt__ 17
122cd2cd8fed#define hz__ 18	/* hazeltine glitch	*/
123cd2cd8fed#define ul__ 19
124cd2cd8fed#define xo__ 20
125cd2cd8fed#define chts__ 21
126cd2cd8fed#define nxon__ 22
127cd2cd8fed#define nrrmc__ 23
128cd2cd8fed#define npc__ 24
129cd2cd8fed#define mc5i__ 25
130cd2cd8fed
131cd2cd8fed#define co__ 0	/* number of columns	*/	/* numbers		*/
132cd2cd8fed#define it__ 1	/* spaces per tab	*/
133cd2cd8fed#define li__ 2	/* number of lines	*/
134cd2cd8fed#define lm__ 3
135cd2cd8fed#define sg__ 4	/* magic cookie glitch	*/
136cd2cd8fed#define pb__ 5
137cd2cd8fed#define vt__ 6
138cd2cd8fed#define ws__ 7
139cd2cd8fed
140cd2cd8fed#define cols__ 0
141cd2cd8fed#define lines__ 2
142cd2cd8fed#define xmc__ 4
143cd2cd8fed#define vt__ 6
144cd2cd8fed#define wsl__ 7
145cd2cd8fed#define nlab__ 8
146cd2cd8fed#define lh__ 9
147cd2cd8fed#define lw__ 10
148cd2cd8fed
149cd2cd8fed#define bt__ 0	/* back tab		*/	/* strings	*/
150cd2cd8fed#define bl__ 1	/* bell			*/
151cd2cd8fed#define cr__ 2	/* carriage return	*/
152cd2cd8fed#define cs__ 3	/* change scroll region	*/
153cd2cd8fed#define ct__ 4	/* clear all tab stops	*/
154cd2cd8fed#define cl__ 5	/* clear screen and home cursor	*/
155cd2cd8fed#define ce__ 6	/* clear to end of line	*/
156cd2cd8fed#define cd__ 7	/* clear to end of display	*/
157cd2cd8fed#define ch__ 8	/* set cursor column	*/
158cd2cd8fed#define CC__ 9	/* term, settable cmd char in 	*/
159cd2cd8fed#define cm__ 10	/* screen rel cursor motion, row, column	*/
160cd2cd8fed#define do__ 11	/* down one line	*/
161cd2cd8fed#define ho__ 12	/* home cursor	*/
162cd2cd8fed#define vi__ 13	/* make cursor invisible	*/
163cd2cd8fed#define le__ 14	/* move cursor left one space	*/
164cd2cd8fed#define CM__ 15	/* memory rel cursor addressing	*/
165cd2cd8fed#define ve__ 16	/* make cursor appear normal	*/
166cd2cd8fed#define nd__ 17	/* non-destructive space (cursor right)	*/
167cd2cd8fed#define ll__ 18	/* last line, first col	*/
168cd2cd8fed#define up__ 19	/* cursor up		*/
169cd2cd8fed#define vs__ 20
170cd2cd8fed#define dc__ 21	/* delete character	*/
171cd2cd8fed#define dl__ 22	/* delete line		*/
172cd2cd8fed#define ds__ 23
173cd2cd8fed#define hd__ 24
174cd2cd8fed#define as__ 25
175cd2cd8fed#define mb__ 26
176cd2cd8fed#define md__ 27	/* turn on bold		*/
177cd2cd8fed#define ti__ 28
178cd2cd8fed#define dm__ 29	/* turn on delete mode	*/
179cd2cd8fed#define mh__ 30	/* half bright mode	*/
180cd2cd8fed#define im__ 31	/* insert mode		*/
181cd2cd8fed#define mk__ 32
182cd2cd8fed#define mp__ 33
183cd2cd8fed#define mr__ 34
184cd2cd8fed#define so__ 35	/* enter standout mode	*/
185cd2cd8fed#define us__ 36
186cd2cd8fed#define ec__ 37
187cd2cd8fed#define ae__ 38
188cd2cd8fed#define me__ 39
189cd2cd8fed#define te__ 40
190cd2cd8fed#define ed__ 41
191cd2cd8fed#define ei__ 42	/* exit insert mode	*/
192cd2cd8fed#define se__ 43	/* exit standout mode	*/
193cd2cd8fed#define ue__ 44
194cd2cd8fed#define vb__ 45
195cd2cd8fed#define ff__ 46
196cd2cd8fed#define fs__ 47
197cd2cd8fed#define i1__ 48
198cd2cd8fed#define i2__ 49
199cd2cd8fed#define i3__ 50
200cd2cd8fed#define if__ 51
201cd2cd8fed#define ic__ 52
202cd2cd8fed#define al__ 53
203cd2cd8fed#define ip__ 54
204cd2cd8fed#define kb__ 55		/* backspace key	*/
205cd2cd8fed#define ka__ 56
206cd2cd8fed#define kC__ 57
207cd2cd8fed#define kt__ 58
208cd2cd8fed#define kD__ 59
209cd2cd8fed#define kL__ 60
210cd2cd8fed#define kd__ 61
211cd2cd8fed#define kM__ 62
212cd2cd8fed#define kE__ 63
213cd2cd8fed#define kS__ 64
214cd2cd8fed#define k0__ 65
215cd2cd8fed#define k1__ 66
216cd2cd8fed#define kf10__ 67
217cd2cd8fed#define k2__ 68
218cd2cd8fed#define k3__ 69
219cd2cd8fed#define k4__ 70
220cd2cd8fed#define k5__ 71
221cd2cd8fed#define k6__ 72
222cd2cd8fed#define k7__ 73
223cd2cd8fed#define k8__ 74
224cd2cd8fed#define k9__ 75
225cd2cd8fed#define kh__ 76
226cd2cd8fed#define kI__ 77
227cd2cd8fed#define kA__ 78
228cd2cd8fed#define kl__ 79
229cd2cd8fed#define kH__ 80
230cd2cd8fed#define kN__ 81
231cd2cd8fed#define kP__ 82
232cd2cd8fed#define kr__ 83
233cd2cd8fed#define kF__ 84
234cd2cd8fed#define kR__ 85
235cd2cd8fed#define kT__ 86
236cd2cd8fed#define ku__ 87	/* key up	*/
237cd2cd8fed#define ke__ 88
238cd2cd8fed#define ks__ 89
239cd2cd8fed#define l0__ 90
240cd2cd8fed#define l1__ 91
241cd2cd8fed#define la__ 92
242cd2cd8fed#define l2__ 93
243cd2cd8fed#define l3__ 94
244cd2cd8fed#define l4__ 95
245cd2cd8fed#define l5__ 96
246cd2cd8fed#define l6__ 97
247cd2cd8fed#define l7__ 98
248cd2cd8fed#define l8__ 99
249cd2cd8fed#define l9__ 100
250cd2cd8fed#define mo__ 101
251cd2cd8fed#define mm__ 102
252cd2cd8fed#define nw__ 103
253cd2cd8fed#define pc__ 104
254cd2cd8fed#define DC__ 105
255cd2cd8fed#define DL__ 106
256cd2cd8fed#define DO__ 107
257cd2cd8fed#define IC__ 118
258cd2cd8fed#define SF__ 109
259cd2cd8fed#define AL__ 110
260cd2cd8fed#define LE__ 111
261cd2cd8fed#define RI__ 112
262cd2cd8fed#define SR__ 113
263cd2cd8fed#define UP__ 114
264cd2cd8fed#define pk__ 115
265cd2cd8fed#define pl__ 116
266cd2cd8fed#define px__ 117
267cd2cd8fed#define ps__ 118
268cd2cd8fed#define pf__ 119
269cd2cd8fed#define po__ 120
270cd2cd8fed#define rp__ 121
271cd2cd8fed#define r1__ 122
272cd2cd8fed#define r2__ 123
273cd2cd8fed#define r3__ 124
274cd2cd8fed#define rf__ 125
275cd2cd8fed#define rc__ 126
276cd2cd8fed#define cv__ 127
277cd2cd8fed#define sc__ 128
278cd2cd8fed#define sf__ 129
279cd2cd8fed#define sr__ 130
280cd2cd8fed#define sa__ 131	/* sgr	*/
281cd2cd8fed#define st__ 132
282cd2cd8fed#define wi__ 133
283cd2cd8fed#define ta__ 134
284cd2cd8fed#define ts__ 135
285cd2cd8fed#define uc__ 136
286cd2cd8fed#define hu__ 137
287cd2cd8fed#define iP__ 138
288cd2cd8fed#define K1__ 139
289cd2cd8fed#define K2__ 140
290cd2cd8fed#define K3__ 141
291cd2cd8fed#define K4__ 142
292cd2cd8fed#define K5__ 143
293cd2cd8fed#define pO__ 144
294cd2cd8fed#define ml__ 145
295cd2cd8fed#define mu__ 146
296cd2cd8fed#define rmp__ 145
297cd2cd8fed#define acsc__ 146
298cd2cd8fed#define pln__ 147
299cd2cd8fed#define kcbt__ 148
300cd2cd8fed#define smxon__ 149
301cd2cd8fed#define rmxon__ 150
302cd2cd8fed#define smam__ 151
303cd2cd8fed#define rmam__ 152
304cd2cd8fed#define xonc__ 153
305cd2cd8fed#define xoffc__ 154
306cd2cd8fed#define enacs__ 155
307cd2cd8fed#define smln__ 156
308cd2cd8fed#define rmln__ 157
309cd2cd8fed#define kbeg__ 158
310cd2cd8fed#define kcan__ 159
311cd2cd8fed#define kclo__ 160
312cd2cd8fed#define kcmd__ 161
313cd2cd8fed#define kcpy__ 162
314cd2cd8fed#define kcrt__ 163
315cd2cd8fed#define kend__ 164
316cd2cd8fed#define kent__ 165
317cd2cd8fed#define kext__ 166
318cd2cd8fed#define kfnd__ 167
319cd2cd8fed#define khlp__ 168
320cd2cd8fed#define kmrk__ 169
321cd2cd8fed#define kmsg__ 170
322cd2cd8fed#define kmov__ 171
323cd2cd8fed#define knxt__ 172
324cd2cd8fed#define kopn__ 173
325cd2cd8fed#define kopt__ 174
326cd2cd8fed#define kprv__ 175
327cd2cd8fed#define kprt__ 176
328cd2cd8fed#define krdo__ 177
329cd2cd8fed#define kref__ 178
330cd2cd8fed#define krfr__ 179
331cd2cd8fed#define krpl__ 180
332cd2cd8fed#define krst__ 181
333cd2cd8fed#define kres__ 182
334cd2cd8fed#define ksav__ 183
335cd2cd8fed#define kspd__ 184
336cd2cd8fed#define kund__ 185
337cd2cd8fed#define kBEG__ 186
338cd2cd8fed#define kCAN__ 187
339cd2cd8fed#define kCMD__ 188
340cd2cd8fed#define kCPY__ 189
341cd2cd8fed#define kCRT__ 190
342cd2cd8fed#define kDC__ 191
343cd2cd8fed#define kDL__ 192
344cd2cd8fed#define kslt__ 193
345cd2cd8fed#define kEND__ 194
346cd2cd8fed#define kEOL__ 195
347cd2cd8fed#define kEXT__ 196
348cd2cd8fed#define kFND__ 197
349cd2cd8fed#define kHLP__ 198
350cd2cd8fed#define kHOM__ 199
351cd2cd8fed#define kIC__ 200
352cd2cd8fed#define kLFT__ 201
353cd2cd8fed#define kMSG__ 202
354cd2cd8fed#define kMOV__ 203
355cd2cd8fed#define kNXT__ 204
356cd2cd8fed#define kOPT__ 205
357cd2cd8fed#define kPRV__ 206
358cd2cd8fed#define kPRT__ 207
359cd2cd8fed#define kRDO__ 208
360cd2cd8fed#define kRPL__ 209
361cd2cd8fed#define kRIT__ 210
362cd2cd8fed#define kRES__ 211
363cd2cd8fed#define kSAV__ 212
364cd2cd8fed#define kSPD__ 213
365cd2cd8fed#define kUND__ 214
366cd2cd8fed#define rfi__ 215
367cd2cd8fed#define kf11__ 216
368cd2cd8fed#define kf12__ 217
369cd2cd8fed#define kf13__ 218
370cd2cd8fed#define kf14__ 219
371cd2cd8fed#define kf15__ 220
372cd2cd8fed#define kf16__ 221
373cd2cd8fed#define kf17__ 222
374cd2cd8fed#define kf18__ 223
375cd2cd8fed#define kf19__ 224
376cd2cd8fed#define kf20__ 225
377cd2cd8fed#define kf21__ 226
378cd2cd8fed#define kf22__ 227
379cd2cd8fed#define kf23__ 228
380cd2cd8fed#define kf24__ 229
381cd2cd8fed#define kf25__ 230
382cd2cd8fed#define kf26__ 231
383cd2cd8fed#define kf27__ 232
384cd2cd8fed#define kf28__ 233
385cd2cd8fed#define kf29__ 234
386cd2cd8fed#define kf30__ 235
387cd2cd8fed#define kf31__ 236
388cd2cd8fed#define kf32__ 237
389cd2cd8fed#define kf33__ 238
390cd2cd8fed#define kf34__ 239
391cd2cd8fed#define kf35__ 240
392cd2cd8fed#define kf36__ 241
393cd2cd8fed#define kf37__ 242
394cd2cd8fed#define kf38__ 243
395cd2cd8fed#define kf39__ 244
396cd2cd8fed#define kf40__ 245
397cd2cd8fed#define kf41__ 246
398cd2cd8fed#define kf42__ 247
399cd2cd8fed#define kf43__ 248
400cd2cd8fed#define kf44__ 249
401cd2cd8fed#define kf45__ 250
402cd2cd8fed#define kf46__ 251
403cd2cd8fed#define kf47__ 252
404cd2cd8fed#define kf48__ 253
405cd2cd8fed#define kf49__ 254
406cd2cd8fed#define kf50__ 255
407cd2cd8fed#define kf51__ 256
408cd2cd8fed#define kf52__ 257
409cd2cd8fed#define kf53__ 258
410cd2cd8fed#define kf54__ 259
411cd2cd8fed#define kf55__ 260
412cd2cd8fed#define kf56__ 261
413cd2cd8fed#define kf57__ 262
414cd2cd8fed#define kf58__ 263
415cd2cd8fed#define kf59__ 264
416cd2cd8fed#define kf60__ 265
417cd2cd8fed#define kf61__ 266
418cd2cd8fed#define kf62__ 267
419cd2cd8fed#define kf63__ 268
420cd2cd8fed#define el1__ 269
421cd2cd8fed#define mgc__ 270
422cd2cd8fed#define smgl__ 271
423cd2cd8fed#define smgr__ 272
424cd2cd8fed
425cd2cd8fed#ifdef CAP
426cd2cd8fedchar *Boolean_names[] = {
427cd2cd8fed"bw", "am", "xb", "xs", "xn", "eo", "gn", "hc", "km", "hs", "in", "da", "db",
428cd2cd8fed"mi", "ms", "os", "es", "xt", "hz", "ul", "xo", "HC", "nx", "NR", "NP", "5i"
429cd2cd8fed};
430cd2cd8fed
431cd2cd8fedchar *Number_names[] = {
432cd2cd8fed"co#", "it#", "li#", "lm#", "sg#", "pb#", "vt#", "ws#", "Nl#", "lh#", "lw#"
433cd2cd8fed};
434cd2cd8fed
435cd2cd8fedchar *String_names[] = {
436cd2cd8fed"bt=", "bl=", "cr=", "cs=", "ct=", "cl=", "ce=", "cd=", "ch=", "CC=", "cm=",
437cd2cd8fed"do=", "ho=", "vi=", "le=", "CM=", "ve=", "nd=", "ll=", "up=", "vs=", "dc=",
438cd2cd8fed"dl=", "ds=", "hd=", "as=", "mb=", "md=", "ti=", "dm=", "mh=", "im=", "mk=",
439cd2cd8fed"mp=", "mr=", "so=", "us=", "ec=", "ae=", "me=", "te=", "ed=", "ei=", "se=",
440cd2cd8fed"ue=", "vb=", "ff=", "fs=", "i1=", "i2=", "i3=", "if=", "ic=", "al=", "ip=",
441cd2cd8fed"kb=", "ka=", "kC=", "kt=", "kD=", "kL=", "kd=", "kM=", "kE=", "kS=", "k0=",
442cd2cd8fed"k1=", "k;=", "k2=", "k3=", "k4=", "k5=", "k6=", "k7=", "k8=", "k9=", "kh=",
443cd2cd8fed"kI=", "kA=", "kl=", "kH=", "kN=", "kP=", "kr=", "kF=", "kR=", "kT=", "ku=",
444cd2cd8fed"ke=", "ks=", "l0=", "l1=", "la=", "l2=", "l3=", "l4=", "l5=", "l6=", "l7=",
445cd2cd8fed"l8=", "l9=", "mo=", "mm=", "nw=", "pc=", "DC=", "DL=", "DO=", "IC=", "SF=",
446cd2cd8fed"AL=", "LE=", "RI=", "SR=", "UP=", "pk=", "pl=", "px=", "ps=", "pf=", "po=",
447cd2cd8fed"rp=", "r1=", "r2=", "r3=", "rf=", "rc=", "cv=", "sc=", "sf=", "sr=", "sa=",
448cd2cd8fed"st=", "wi=", "ta=", "ts=", "uc=", "hu=", "iP=", "K1=", "K3=", "K2=", "K4=",
449cd2cd8fed"K5=", "pO=", "rP=", "ac=", "pn=", "kB=", "SX=", "RX=", "SA=", "RA=", "XN=",
450cd2cd8fed"XF=", "eA=", "LO=", "LF=", "@1=", "@2=", "@3=", "@4=", "@5=", "@6=", "@7=",
451cd2cd8fed"@8=", "@9=", "@0=", "%1=", "%2=", "%3=", "%4=", "%5=", "%6=", "%7=", "%8=",
452cd2cd8fed"%9=", "%0=", "&1=", "&2=", "&3=", "&4=", "&5=", "&6=", "&7=", "&8=", "&9=",
453cd2cd8fed"&0=", "*1=", "*2=", "*3=", "*4=", "*5=", "*6=", "*7=", "*8=", "*9=", "*0=",
454cd2cd8fed"#1=", "#2=", "#3=", "#4=", "%a=", "%b=", "%c=", "%d=", "%e=", "%f=", "%g=",
455cd2cd8fed"%h=", "%i=", "%j=", "!1=", "!2=", "!3=", "RF=", "F1=", "F2=", "F3=", "F4=",
456cd2cd8fed"F5=", "F6=", "F7=", "F8=", "F9=", "FA=", "FB=", "FC=", "FD=", "FE=", "FF=",
457cd2cd8fed"FG=", "FH=", "FI=", "FJ=", "FK=", "FL=", "FM=", "FN=", "FO=", "FP=", "FQ=",
458cd2cd8fed"FR=", "FS=", "FT=", "FU=", "FV=", "FW=", "FX=", "FY=", "FZ=", "Fa=", "Fb=",
459cd2cd8fed"Fc=", "Fd=", "Fe=", "Ff=", "Fg=", "Fh=", "Fi=", "Fj=", "Fk=", "Fl=", "Fm=",
460cd2cd8fed"Fn=", "Fo=", "Fp=", "Fq=", "Fr=", "cb=", "MC=", "ML=", "MR="
461cd2cd8fed};
462cd2cd8fed#endif
463cd2cd8fed
464cd2cd8fedchar *new_curse = "October 1987";
465cd2cd8fed
466cd2cd8fedchar in_buff[100];	/* buffer for ungetch			*/
467cd2cd8fedint bufp;		/* next free position in in_buff	*/
468cd2cd8fed
469cd2cd8fedchar *TERMINAL_TYPE = NULL; /* terminal type to be gotten from environment	*/
470cd2cd8fedint CFOUND = FALSE;
471cd2cd8fedint Data_Line_len = 0;
472cd2cd8fedint Max_Key_len;	/* max length of a sequence sent by a key	*/
473cd2cd8fedchar *Data_Line = NULL;
474cd2cd8fedchar *TERM_PATH = NULL;
475cd2cd8fedchar *TERM_data_ptr = NULL;
476cd2cd8fedchar *Term_File_name = NULL;	/* name of file containing terminal description	*/
477cd2cd8fedFILE *TFP;		/* file pointer to file with terminal des.	*/
478cd2cd8fedint Fildes;		/* file descriptor for terminfo file		*/
479cd2cd8fedint STAND = FALSE;	/* is standout mode activated?			*/
480cd2cd8fedint TERM_INFO = FALSE;	/* is terminfo being used (TRUE), or termcap (FALSE) */
481cd2cd8fedint Time_Out;	/* set when time elapsed while trying to read function key */
482cd2cd8fedint Curr_x;		/* current x position on screen			*/
483cd2cd8fedint Curr_y;		/* current y position on the screen		*/
484cd2cd8fedint LINES;
485cd2cd8fedint COLS;
486cd2cd8fedint Move_It;		/* flag to move cursor if magic cookie glitch	*/
487cd2cd8fedint initialized = FALSE;	/* tells whether new_curse is initialized	*/
488cd2cd8fedfloat speed;
489cd2cd8fedfloat chars_per_millisecond;
490cd2cd8fedint Repaint_screen;	/* if an operation to change screen impossible, repaint screen	*/
491cd2cd8fedint Intr;		/* storeage for interrupt character		*/
492cd2cd8fedint Parity;		/* 0 = no parity, 1 = odd parity, 2 = even parity */
493cd2cd8fedint Noblock;		/* for BSD systems				*/
494cd2cd8fedint Num_bits;	/* number of bits per character	*/
495cd2cd8fedint Flip_Bytes;	/* some systems have byte order reversed	*/
496cd2cd8fedint interrupt_flag = FALSE;	/* set true if SIGWINCH received	*/
497cd2cd8fed
498cd2cd8fed#ifndef CAP
499cd2cd8fedchar *Strings;
500cd2cd8fed#endif
501cd2cd8fed
502adbe69bed#if !defined(TERMCAP)
503adbe69bed#define TERMCAP "/etc/termcap"
504adbe69bed#endif
505adbe69bed
506cd2cd8fedstruct KEYS {
507cd2cd8fed	int length;	/* length of string sent by key			*/
508cd2cd8fed	char *string;	/* string sent by key				*/
509cd2cd8fed	int value;	/* CURSES value of key (9-bit)			*/
510cd2cd8fed	};
511cd2cd8fed
512cd2cd8fedstruct KEY_STACK {
513cd2cd8fed	struct KEYS *element;
514cd2cd8fed	struct KEY_STACK *next;
515cd2cd8fed	};
516cd2cd8fed
517cd2cd8fedstruct KEY_STACK *KEY_TOS = NULL;
518cd2cd8fedstruct KEY_STACK *KEY_POINT;
519cd2cd8fed
520cd2cd8fed/*
521cd2cd8fed |
522cd2cd8fed |	Not all systems have good terminal information, so we will define
523cd2cd8fed |	keyboard information here for the most widely used terminal type,
524cd2cd8fed |	the VT100.
525cd2cd8fed |
526cd2cd8fed */
527cd2cd8fed
528cd2cd8fedstruct KEYS vt100[] =
529cd2cd8fed	{
530cd2cd8fed		{ 3, "\033[A", 0403 },	/* key up 	*/
531cd2cd8fed		{ 3, "\033[C", 0405 },	/* key right	*/
532cd2cd8fed		{ 3, "\033[D", 0404 },	/* key left	*/
533cd2cd8fed
534cd2cd8fed		{ 4, "\033[6~", 0522 },	/* key next page	*/
535cd2cd8fed		{ 4, "\033[5~", 0523 },	/* key prev page	*/
536cd2cd8fed		{ 3, "\033[[", 0550 },	/* key end	*/
537cd2cd8fed		{ 3, "\033[@", 0406 },	/* key home	*/
538cd2cd8fed		{ 4, "\033[2~", 0513 },	/* key insert char	*/
539cd2cd8fed
540cd2cd8fed		{ 3, "\033[y", 0410 },	/* key F0	*/
541cd2cd8fed		{ 3, "\033[P", 0411 },	/* key F1	*/
542cd2cd8fed		{ 3, "\033[Q", 0412 },	/* key F2	*/
543cd2cd8fed		{ 3, "\033[R", 0413 },	/* key F3	*/
544cd2cd8fed		{ 3, "\033[S", 0414 },	/* key F4	*/
545cd2cd8fed		{ 3, "\033[t", 0415 },	/* key F5	*/
546cd2cd8fed		{ 3, "\033[u", 0416 },	/* key F6	*/
547cd2cd8fed		{ 3, "\033[v", 0417 },	/* key F7	*/
548cd2cd8fed		{ 3, "\033[l", 0420 },	/* key F8	*/
549cd2cd8fed		{ 3, "\033[w", 0421 },	/* key F9	*/
550cd2cd8fed		{ 3, "\033[x", 0422 },	/* key F10	*/
551cd2cd8fed
552cd2cd8fed		{ 5, "\033[10~", 0410 },	/* key F0	*/
553cd2cd8fed		{ 5, "\033[11~", 0411 },	/* key F1	*/
554cd2cd8fed		{ 5, "\033[12~", 0412 },	/* key F2	*/
555cd2cd8fed		{ 5, "\033[13~", 0413 },	/* key F3	*/
556cd2cd8fed		{ 5, "\033[14~", 0414 },	/* key F4	*/
557cd2cd8fed		{ 5, "\033[15~", 0415 },	/* key F5	*/
558cd2cd8fed		{ 5, "\033[17~", 0416 },	/* key F6	*/
559cd2cd8fed		{ 5, "\033[18~", 0417 },	/* key F7	*/
560cd2cd8fed		{ 5, "\033[19~", 0420 },	/* key F8	*/
561cd2cd8fed		{ 5, "\033[20~", 0421 },	/* key F9	*/
562cd2cd8fed		{ 5, "\033[21~", 0422 },	/* key F10	*/
563cd2cd8fed		{ 5, "\033[23~", 0423 },	/* key F11	*/
564cd2cd8fed		{ 5, "\033[24~", 0424 },	/* key F12	*/
565cd2cd8fed		{ 3, "\033[q", 0534 },	/* ka1 upper-left of keypad	*/
566cd2cd8fed		{ 3, "\033[s", 0535 },	/* ka3 upper-right of keypad	*/
567cd2cd8fed		{ 3, "\033[r", 0536 },	/* kb2 center of keypad	*/
568cd2cd8fed 		{ 3, "\033[p", 0537 },	/* kc1 lower-left of keypad	*/
569cd2cd8fed		{ 3, "\033[n", 0540 },	/* kc3 lower-right of keypad	*/
570cd2cd8fed
571cd2cd8fed		/*
572cd2cd8fed		 |	The following are the same keys as above, but with
573cd2cd8fed		 |	a different character following the escape char.
574cd2cd8fed		 */
575cd2cd8fed
576cd2cd8fed		{ 3, "\033OA", 0403 },	/* key up 	*/
577cd2cd8fed		{ 3, "\033OC", 0405 },	/* key right	*/
578cd2cd8fed		{ 3, "\033OD", 0404 },	/* key left	*/
579cd2cd8fed		{ 3, "\033OB", 0402 },	/* key down	*/
580cd2cd8fed		{ 4, "\033O6~", 0522 },	/* key next page	*/
581cd2cd8fed		{ 4, "\033O5~", 0523 },	/* key prev page	*/
582cd2cd8fed		{ 3, "\033O[", 0550 },	/* key end	*/
583cd2cd8fed		{ 3, "\033O@", 0406 },	/* key home	*/
584cd2cd8fed		{ 4, "\033O2~", 0513 },	/* key insert char	*/
585cd2cd8fed
586cd2cd8fed		{ 3, "\033Oy", 0410 },	/* key F0	*/
587cd2cd8fed		{ 3, "\033OP", 0411 },	/* key F1	*/
588cd2cd8fed		{ 3, "\033OQ", 0412 },	/* key F2	*/
589cd2cd8fed		{ 3, "\033OR", 0413 },	/* key F3	*/
590cd2cd8fed		{ 3, "\033OS", 0414 },	/* key F4	*/
591cd2cd8fed		{ 3, "\033Ot", 0415 },	/* key F5	*/
592cd2cd8fed		{ 3, "\033Ou", 0416 },	/* key F6	*/
593cd2cd8fed		{ 3, "\033Ov", 0417 },	/* key F7	*/
594cd2cd8fed		{ 3, "\033Ol", 0420 },	/* key F8	*/
595cd2cd8fed		{ 3, "\033Ow", 0421 },	/* key F9	*/
596cd2cd8fed		{ 3, "\033Ox", 0422 },	/* key F10	*/
597cd2cd8fed
598cd2cd8fed		{ 5, "\033O10~", 0410 },	/* key F0	*/
599cd2cd8fed		{ 5, "\033O11~", 0411 },	/* key F1	*/
600cd2cd8fed		{ 5, "\033O12~", 0412 },	/* key F2	*/
601cd2cd8fed		{ 5, "\033O13~", 0413 },	/* key F3	*/
602cd2cd8fed		{ 5, "\033O14~", 0414 },	/* key F4	*/
603cd2cd8fed		{ 5, "\033O15~", 0415 },	/* key F5	*/
604cd2cd8fed		{ 5, "\033O17~", 0416 },	/* key F6	*/
605cd2cd8fed		{ 5, "\033O18~", 0417 },	/* key F7	*/
606cd2cd8fed		{ 5, "\033O19~", 0420 },	/* key F8	*/
607cd2cd8fed		{ 5, "\033O20~", 0421 },	/* key F9	*/
608cd2cd8fed		{ 5, "\033O21~", 0422 },	/* key F10	*/
609cd2cd8fed		{ 5, "\033O23~", 0423 },	/* key F11	*/
610cd2cd8fed		{ 5, "\033O24~", 0424 },	/* key F12	*/
611cd2cd8fed		{ 3, "\033Oq", 0534 },	/* ka1 upper-left of keypad	*/
612cd2cd8fed		{ 3, "\033Os", 0535 },	/* ka3 upper-right of keypad	*/
613cd2cd8fed		{ 3, "\033Or", 0536 },	/* kb2 center of keypad	*/
614cd2cd8fed 		{ 3, "\033Op", 0537 },	/* kc1 lower-left of keypad	*/
615cd2cd8fed		{ 3, "\033On", 0540 },	/* kc3 lower-right of keypad	*/
616cd2cd8fed
617cd2cd8fed		{ 0, "", 0 }	/* end	*/
618cd2cd8fed	};
619cd2cd8fed
620cd2cd8fedstruct Parameters {
621cd2cd8fed	int value;
622cd2cd8fed	struct Parameters *next;
623cd2cd8fed	};
624cd2cd8fed
625cd2cd8fedint Key_vals[] = {
626cd2cd8fed	0407, 0526, 0515, 0525, 0512, 0510, 0402, 0514, 0517, 0516, 0410, 0411,
627cd2cd8fed	0422, 0412, 0413, 0414, 0415, 0416, 0417, 0420, 0421, 0406, 0513, 0511,
628cd2cd8fed	0404, 0533, 0522, 0523, 0405, 0520, 0521, 0524, 0403,
629cd2cd8fed	0534, 0535, 0536, 0537, 0540, 0541, 0542, 0543, 0544, 0545, 0546, 0547,
630cd2cd8fed	0550, 0527, 0551, 0552, 0553, 0554, 0555, 0556, 0557, 0560, 0561, 0562,
631cd2cd8fed	0532, 0563, 0564, 0565, 0566, 0567, 0570, 0571, 0627, 0630, 0572, 0573,
632cd2cd8fed	0574, 0575, 0576, 0577, 0600, 0601, 0602, 0603, 0604, 0605, 0606, 0607,
633cd2cd8fed	0610, 0611, 0612, 0613, 0614, 0615, 0616, 0617, 0620, 0621, 0622, 0623,
634cd2cd8fed	0624, 0625, 0626, 0423, 0424, 0425, 0426, 0427, 0430, 0431,
635cd2cd8fed	0432, 0433, 0434, 0435, 0436, 0437, 0440, 0441, 0442, 0443, 0444, 0445,
636cd2cd8fed	0446, 0447, 0450, 0451, 0452, 0453, 0454, 0455, 0456, 0457, 0460, 0461,
637cd2cd8fed	0462, 0463, 0464, 0465, 0466, 0467, 0470, 0471, 0472, 0473, 0474, 0475,
638cd2cd8fed	0476, 0477, 0500, 0501, 0502, 0503, 0504, 0505, 0506, 0507
639cd2cd8fed};
640cd2cd8fed
641cd2cd8fedint attributes_set[9];
642cd2cd8fed
643cd2cd8fedstatic int nc_attributes = 0;	/* global attributes for new_curse to observe */
644cd2cd8fed
645cd2cd8fed#ifdef SYS5
646cd2cd8fedstruct termio Terminal;
647cd2cd8fedstruct termio Saved_tty;
648cd2cd8fed#else
649cd2cd8fedstruct sgttyb Terminal;
650cd2cd8fedstruct sgttyb Saved_tty;
651cd2cd8fed#endif
652cd2cd8fed
653cd2cd8fedchar *tc_;
654cd2cd8fed
655cd2cd8fedint Booleans[128];
656cd2cd8fedint Numbers[128];
657cd2cd8fedchar *String_table[1024];
658cd2cd8fed
659cd2cd8fedint *virtual_lines;
660cd2cd8fed
661cd2cd8fedstatic char nc_scrolling_ability = FALSE;
662cd2cd8fed
663d2f3627edchar *terminfo_path[] = {
664d2f3627ed        "/usr/lib/terminfo",
665d2f3627ed        "/usr/share/lib/terminfo",
666d2f3627ed        "/usr/share/terminfo",
667d2f3627ed        NULL
668d2f3627ed        };
669d2f3627ed
670cd2cd8fed#ifdef CAP
671cd2cd8fed
672cd2cd8fed#if defined(__STDC__) || defined(__cplusplus)
673cd2cd8fed#define P_(s) s
674cd2cd8fed#else
675cd2cd8fed#define P_(s) ()
676cd2cd8fed#endif /* __STDC__ */
677cd2cd8fed
678cd2cd8fedint tc_Get_int P_((int));
679cd2cd8fedvoid CAP_PARSE P_((void));
680cd2cd8fedvoid Find_term P_((void));
681cd2cd8fed
682cd2cd8fed#undef P_
683cd2cd8fed
684cd2cd8fed#endif /* CAP */
685cd2cd8fed
686cd2cd8fed
687cd2cd8fed#ifndef __STDC__
688cd2cd8fed#ifndef HAS_STDLIB
689cd2cd8fedextern char *fgets();
690cd2cd8fedextern char *malloc();
691cd2cd8fedextern char *getenv();
692cd2cd8fedFILE *fopen();			/* declaration for open function	*/
693cd2cd8fed#endif /* HAS_STDLIB */
694cd2cd8fed#endif /* __STDC__ */
695cd2cd8fed
696cd2cd8fed#ifdef SIGWINCH
697cd2cd8fed
698cd2cd8fed/*
699cd2cd8fed |	Copy the contents of one window to another.
700cd2cd8fed */
701cd2cd8fed
702cd2cd8fedvoid
703cd2cd8fedcopy_window(origin, destination)
704cd2cd8fedWINDOW *origin, *destination;
705cd2cd8fed{
706cd2cd8fed	int row, column;
707cd2cd8fed	struct _line *orig, *dest;
708cd2cd8fed
709cd2cd8fed	orig = origin->first_line;
710cd2cd8fed	dest = destination->first_line;
711cd2cd8fed
712cd2cd8fed	for (row = 0;
713cd2cd8fed		row < (min(origin->Num_lines, destination->Num_lines));
714cd2cd8fed			row++)
715cd2cd8fed	{
716cd2cd8fed		for (column = 0;
717cd2cd8fed		    column < (min(origin->Num_cols, destination->Num_cols));
718cd2cd8fed			column++)
719cd2cd8fed		{
720cd2cd8fed			dest->row[column] = orig->row[column];
721cd2cd8fed			dest->attributes[column] = orig->attributes[column];
722cd2cd8fed		}
723cd2cd8fed		dest->changed = orig->changed;
724cd2cd8fed		dest->scroll = orig->scroll;
725cd2cd8fed		dest->last_char = min(orig->last_char, destination->Num_cols);
726cd2cd8fed		orig = orig->next_screen;
727cd2cd8fed		dest = dest->next_screen;
728cd2cd8fed	}
729cd2cd8fed	destination->LX = min((destination->Num_cols - 1), origin->LX);
730cd2cd8fed	destination->LY = min((destination->Num_lines - 1), origin->LY);
731cd2cd8fed	destination->Attrib = origin->Attrib;
732cd2cd8fed	destination->scroll_up = origin->scroll_up;
733cd2cd8fed	destination->scroll_down = origin->scroll_down;
734cd2cd8fed	destination->SCROLL_CLEAR = origin->SCROLL_CLEAR;
735cd2cd8fed}
736cd2cd8fed
737cd2cd8fedvoid
738cd2cd8fedreinitscr(foo)
739cd2cd8fedint foo;
740cd2cd8fed{
741cd2cd8fed	WINDOW *local_virt;
742cd2cd8fed	WINDOW *local_std;
743cd2cd8fed	WINDOW *local_cur;
744cd2cd8fed
745cd2cd8fed	signal(SIGWINCH, reinitscr);
746cd2cd8fed#ifdef TIOCGWINSZ
747cd2cd8fed	if (ioctl(0, TIOCGWINSZ, &ws) >= 0)
748cd2cd8fed	{
749cd2cd8fed		if (ws.ws_row == LINES && ws.ws_col == COLS)
750cd2cd8fed			return;
751cd2cd8fed		if (ws.ws_row > 0)
752cd2cd8fed			LINES = ws.ws_row;
753cd2cd8fed		if (ws.ws_col > 0)
754cd2cd8fed			COLS = ws.ws_col;
755cd2cd8fed	}
756cd2cd8fed#endif /* TIOCGWINSZ */
757cd2cd8fed	local_virt = newwin(LINES, COLS, 0, 0);
758cd2cd8fed	local_std = newwin(LINES, COLS, 0, 0);
759cd2cd8fed	local_cur = newwin(LINES, COLS, 0, 0);
760cd2cd8fed	copy_window(virtual_scr, local_virt);
761cd2cd8fed	copy_window(stdscr, local_std);
762cd2cd8fed	copy_window(curscr, local_cur);
763cd2cd8fed	delwin(virtual_scr);
764cd2cd8fed	delwin(stdscr);
765cd2cd8fed	delwin(curscr);
766cd2cd8fed	virtual_scr = local_virt;
767cd2cd8fed	stdscr = local_std;
768cd2cd8fed	curscr = local_cur;
769cd2cd8fed	free(virtual_lines);
770cd2cd8fed	virtual_lines = (int *) malloc(LINES * (sizeof(int)));
771cd2cd8fed	interrupt_flag = TRUE;
772cd2cd8fed}
773cd2cd8fed#endif /* SIGWINCH */
774cd2cd8fed
775cd2cd8fedvoid
776cd2cd8fedinitscr()		/* initialize terminal for operations	*/
777cd2cd8fed{
778cd2cd8fed	int value;
779d2f3627ed	int counter;
780cd2cd8fed	char *lines_string;
781cd2cd8fed	char *columns_string;
782cd2cd8fed#ifdef CAP
783cd2cd8fed	char *pointer;
784cd2cd8fed#endif /* CAP */
785cd2cd8fed
786cd2cd8fed#ifdef DIAG
787cd2cd8fedprintf("starting initscr \n");fflush(stdout);
788cd2cd8fed#endif
789cd2cd8fed	if (initialized)
790cd2cd8fed		return;
791cd2cd8fed#ifdef BSD_SELECT
792cd2cd8fed	setbuf(stdin, NULL);
793cd2cd8fed#endif /* BSD_SELECT */
794cd2cd8fed	Flip_Bytes = FALSE;
795cd2cd8fed	Parity = 0;
796cd2cd8fed	Time_Out = FALSE;
797cd2cd8fed	bufp = 0;
798cd2cd8fed	Move_It = FALSE;
799cd2cd8fed	Noblock = FALSE;
800cd2cd8fed#ifdef SYS5
801cd2cd8fed	value = ioctl(0, TCGETA, &Terminal);
802cd2cd8fed	if (Terminal.c_cflag & PARENB)
803cd2cd8fed	{
804cd2cd8fed		if (Terminal.c_cflag & PARENB)
805cd2cd8fed			Parity = 1;
806cd2cd8fed		else
807cd2cd8fed			Parity = 2;
808cd2cd8fed	}
809cd2cd8fed	if ((Terminal.c_cflag & CS8) == CS8)
810cd2cd8fed	{
811cd2cd8fed		Num_bits = 8;
812cd2cd8fed	}
813cd2cd8fed	else if ((Terminal.c_cflag & CS7) == CS7)
814cd2cd8fed		Num_bits = 7;
815cd2cd8fed	else if ((Terminal.c_cflag & CS6) == CS6)
816cd2cd8fed		Num_bits = 6;
817cd2cd8fed	else
818cd2cd8fed		Num_bits = 5;
819cd2cd8fed	value = Terminal.c_cflag & 037;
820cd2cd8fed	switch (value) {
821cd2cd8fed	case 01:	speed = 50.0;
822cd2cd8fed		break;
823cd2cd8fed	case 02:	speed = 75.0;
824cd2cd8fed		break;
825cd2cd8fed	case 03:	speed = 110.0;
826cd2cd8fed		break;
827cd2cd8fed	case 04:	speed = 134.5;
828cd2cd8fed		break;
829cd2cd8fed	case 05:	speed = 150.0;
830cd2cd8fed		break;
831cd2cd8fed	case 06:	speed = 200.0;
832cd2cd8fed		break;
833cd2cd8fed	case 07:	speed = 300.0;
834cd2cd8fed		break;
835cd2cd8fed	case 010:	speed = 600.0;
836cd2cd8fed		break;
837cd2cd8fed	case 011:	speed = 900.0;
838cd2cd8fed		break;
839cd2cd8fed	case 012:	speed = 1200.0;
840cd2cd8fed		break;
841cd2cd8fed	case 013:	speed = 1800.0;
842cd2cd8fed		break;
843cd2cd8fed	case 014:	speed = 2400.0;
844cd2cd8fed		break;
845cd2cd8fed	case 015:	speed = 3600.0;
846cd2cd8fed		break;
847cd2cd8fed	case 016:	speed = 4800.0;
848cd2cd8fed		break;
849cd2cd8fed	case 017:	speed = 7200.0;
850cd2cd8fed		break;
851cd2cd8fed	case 020:	speed = 9600.0;
852cd2cd8fed		break;
853cd2cd8fed	case 021:	speed = 19200.0;
854cd2cd8fed		break;
855cd2cd8fed	case 022:	speed = 38400.0;
856cd2cd8fed		break;
857cd2cd8fed	default:	speed = 0.0;
858cd2cd8fed	}
859cd2cd8fed#else
860cd2cd8fed	value = ioctl(0, TIOCGETP, &Terminal);
861cd2cd8fed	if (Terminal.sg_flags & EVENP)
862cd2cd8fed		Parity = 2;
863cd2cd8fed	else if (Terminal.sg_flags & ODDP)
864cd2cd8fed		Parity = 1;
865cd2cd8fed	value = Terminal.sg_ospeed;
866cd2cd8fed	switch (value) {
867cd2cd8fed	case 01:	speed = 50.0;
868cd2cd8fed		break;
869cd2cd8fed	case 02:	speed = 75.0;
870cd2cd8fed		break;
871cd2cd8fed	case 03:	speed = 110.0;
872cd2cd8fed		break;
873cd2cd8fed	case 04:	speed = 134.5;
874cd2cd8fed		break;
875cd2cd8fed	case 05:	speed = 150.0;
876cd2cd8fed		break;
877cd2cd8fed	case 06:	speed = 200.0;
878cd2cd8fed		break;
879cd2cd8fed	case 07:	speed = 300.0;
880cd2cd8fed		break;
881cd2cd8fed	case 010:	speed = 600.0;
882cd2cd8fed		break;
883cd2cd8fed	case 011:	speed = 1200.0;
884cd2cd8fed		break;
885cd2cd8fed	case 012:	speed = 1800.0;
886cd2cd8fed		break;
887cd2cd8fed	case 013:	speed = 2400.0;
888cd2cd8fed		break;
889cd2cd8fed	case 014:	speed = 4800.0;
890cd2cd8fed		break;
891cd2cd8fed	case 015:	speed = 9600.0;
892cd2cd8fed		break;
893cd2cd8fed	default:	speed = 0.0;
894cd2cd8fed	}
895cd2cd8fed#endif
896cd2cd8fed	chars_per_millisecond = (0.001 * speed) / 8.0;
897cd2cd8fed	TERMINAL_TYPE = getenv("TERM");
898cd2cd8fed	if (TERMINAL_TYPE == NULL)
899cd2cd8fed	{
900cd2cd8fed		printf("unknown terminal type\n");
901cd2cd8fed		exit(0);
902cd2cd8fed	}
903cd2cd8fed#ifndef CAP
904cd2cd8fed	Fildes = -1;
905cd2cd8fed	TERM_PATH = getenv("TERMINFO");
906cd2cd8fed	if (TERM_PATH != NULL)
907cd2cd8fed	{
908cd2cd8fed		Data_Line_len = 23 + strlen(TERM_PATH) + strlen(TERMINAL_TYPE);
909cd2cd8fed		Term_File_name = malloc(Data_Line_len);
910cd2cd8fed		sprintf(Term_File_name, "%s/%c/%s", TERM_PATH, *TERMINAL_TYPE, TERMINAL_TYPE);
911cd2cd8fed		Fildes = open(Term_File_name, O_RDONLY);
912d2f3627ed		if (Fildes == -1)
913d2f3627ed		{
914d2f3627ed        		sprintf(Term_File_name, "%s/%x/%s", TERM_PATH, *TERMINAL_TYPE, TERMINAL_TYPE);
915d2f3627ed        		Fildes = open(Term_File_name, O_RDONLY);
916d2f3627ed		}
917cd2cd8fed	}
918d2f3627ed	counter = 0;
919d2f3627ed	while ((Fildes == -1) && (terminfo_path[counter] != NULL))
920cd2cd8fed	{
921d2f3627ed		TERM_PATH = terminfo_path[counter];
922cd2cd8fed		Data_Line_len = 23 + strlen(TERM_PATH) + strlen(TERMINAL_TYPE);
923cd2cd8fed		Term_File_name = malloc(Data_Line_len);
924cd2cd8fed		sprintf(Term_File_name, "%s/%c/%s", TERM_PATH, *TERMINAL_TYPE, TERMINAL_TYPE);
925cd2cd8fed		Fildes = open(Term_File_name, O_RDONLY);
926d2f3627ed		if (Fildes == -1)
927d2f3627ed		{
928d2f3627ed        		sprintf(Term_File_name, "%s/%x/%s", TERM_PATH, *TERMINAL_TYPE, TERMINAL_TYPE);
929d2f3627ed        		Fildes = open(Term_File_name, O_RDONLY);
930d2f3627ed		}
931d2f3627ed		counter++;
932cd2cd8fed	}
933cd2cd8fed	if (Fildes == -1)
934cd2cd8fed	{
935cd2cd8fed		free(Term_File_name);
936cd2cd8fed		Term_File_name = NULL;
937cd2cd8fed	}
938cd2cd8fed	else
939cd2cd8fed		TERM_INFO = INFO_PARSE();
940cd2cd8fed#else
941cd2cd8fed	/*
942cd2cd8fed	 |	termcap information can be in the TERMCAP env variable, if so
943cd2cd8fed	 |	use that, otherwise check the /etc/termcap file
944cd2cd8fed	 */
945cd2cd8fed	if ((pointer = Term_File_name = getenv("TERMCAP")) != NULL)
946cd2cd8fed	{
947cd2cd8fed		if (*Term_File_name != '/')
948adbe69bed			Term_File_name = TERMCAP;
949cd2cd8fed	}
950cd2cd8fed	else
951cd2cd8fed	{
952adbe69bed		Term_File_name = TERMCAP;
953cd2cd8fed	}
954cd2cd8fed	if ((TFP = fopen(Term_File_name, "r")) == NULL)
955cd2cd8fed	{
956adbe69bed		printf("unable to open %s file \n", TERMCAP);
957cd2cd8fed		exit(0);
958cd2cd8fed	}
959cd2cd8fed 	for (value = 0; value < 1024; value++)
960cd2cd8fed		String_table[value] = NULL;
961cd2cd8fed	for (value = 0; value < 128; value++)
962cd2cd8fed		Booleans[value] = 0;
963cd2cd8fed	for (value = 0; value < 128; value++)
964cd2cd8fed		Numbers[value] = 0;
965cd2cd8fed	Data_Line = malloc(512);
966cd2cd8fed	if (pointer && *pointer != '/')
967cd2cd8fed	{
968cd2cd8fed		TERM_data_ptr = pointer;
969cd2cd8fed		CAP_PARSE();
970cd2cd8fed	}
971cd2cd8fed	else
972cd2cd8fed	{
973cd2cd8fed		Find_term();
974cd2cd8fed		CAP_PARSE();
975cd2cd8fed	}
976cd2cd8fed#endif
977cd2cd8fed	if (String_table[pc__] == NULL)
978cd2cd8fed		String_table[pc__] = "\0";
979cd2cd8fed	if ((String_table[cm__] == NULL) || (Booleans[hc__]))
980cd2cd8fed	{
981cd2cd8fed		fprintf(stderr, "sorry, unable to use this terminal type for screen editing\n");
982cd2cd8fed		exit(0);
983cd2cd8fed	}
984cd2cd8fed	Key_Get();
985cd2cd8fed	keys_vt100();
986cd2cd8fed	LINES = Numbers[li__];
987cd2cd8fed	COLS = Numbers[co__];
988cd2cd8fed	if ((lines_string = getenv("LINES")) != NULL)
989cd2cd8fed	{
990cd2cd8fed		value = atoi(lines_string);
991cd2cd8fed		if (value > 0)
992cd2cd8fed			LINES = value;
993cd2cd8fed	}
994cd2cd8fed	if ((columns_string = getenv("COLUMNS")) != NULL)
995cd2cd8fed	{
996cd2cd8fed		value = atoi(columns_string);
997cd2cd8fed		if (value > 0)
998cd2cd8fed			COLS = value;
999cd2cd8fed	}
1000cd2cd8fed#ifdef TIOCGWINSZ
1001cd2cd8fed	/*
1002cd2cd8fed	 |	get the window size
1003cd2cd8fed	 */
1004cd2cd8fed	if (ioctl(0, TIOCGWINSZ, &ws) >= 0)
1005cd2cd8fed	{
1006cd2cd8fed		if (ws.ws_row > 0)
1007cd2cd8fed			LINES = ws.ws_row;
1008cd2cd8fed		if (ws.ws_col > 0)
1009cd2cd8fed			COLS = ws.ws_col;
1010cd2cd8fed	}
1011cd2cd8fed#endif
1012cd2cd8fed	virtual_scr = newwin(LINES, COLS, 0, 0);
1013cd2cd8fed	stdscr = newwin(LINES, COLS, 0, 0);
1014cd2cd8fed	curscr = newwin(LINES, COLS, 0, 0);
1015cd2cd8fed	wmove(stdscr, 0, 0);
1016cd2cd8fed	werase(stdscr);
1017cd2cd8fed	Repaint_screen = TRUE;
1018cd2cd8fed	initialized = TRUE;
1019cd2cd8fed	virtual_lines = (int *) malloc(LINES * (sizeof(int)));
1020cd2cd8fed
1021cd2cd8fed#ifdef SIGWINCH
1022cd2cd8fed	/*
1023cd2cd8fed	 |	reset size of windows and LINES and COLS if term window
1024cd2cd8fed	 |	changes size
1025cd2cd8fed	 */
1026cd2cd8fed	signal(SIGWINCH, reinitscr);
1027cd2cd8fed#endif /* SIGWINCH */
1028cd2cd8fed
1029cd2cd8fed	/*
1030cd2cd8fed	 |	check if scrolling is available
1031cd2cd8fed	 */
1032cd2cd8fed
1033cd2cd8fed	nc_scrolling_ability = ((String_table[al__] != NULL) &&
1034cd2cd8fed				(String_table[dl__])) || ((String_table[cs__])
1035cd2cd8fed				&& (String_table[sr__]));
1036cd2cd8fed
1037cd2cd8fed}
1038cd2cd8fed
1039cd2cd8fed#ifndef CAP
1040cd2cd8fedint
1041cd2cd8fedGet_int()		/* get a two-byte integer from the terminfo file */
1042cd2cd8fed{
1043cd2cd8fed	int High_byte;
1044cd2cd8fed	int Low_byte;
1045cd2cd8fed	int temp;
1046cd2cd8fed
1047cd2cd8fed	Low_byte = *((unsigned char *) TERM_data_ptr++);
1048cd2cd8fed	High_byte = *((unsigned char *) TERM_data_ptr++);
1049cd2cd8fed	if (Flip_Bytes)
1050cd2cd8fed	{
1051cd2cd8fed		temp = Low_byte;
1052cd2cd8fed		Low_byte = High_byte;
1053cd2cd8fed		High_byte = temp;
1054cd2cd8fed	}
1055cd2cd8fed	if ((High_byte == 255) && (Low_byte == 255))
1056cd2cd8fed		return (-1);
1057cd2cd8fed	else
1058cd2cd8fed		return(Low_byte + (High_byte * 256));
1059cd2cd8fed}
1060cd2cd8fed
1061cd2cd8fedint
1062cd2cd8fedINFO_PARSE()		/* parse off the data in the terminfo data file	*/
1063cd2cd8fed{
1064cd2cd8fed	int offset;
1065cd2cd8fed	int magic_number = 0;
1066cd2cd8fed	int counter = 0;
1067cd2cd8fed	int Num_names = 0;
1068cd2cd8fed	int Num_bools = 0;
1069cd2cd8fed	int Num_ints = 0;
1070cd2cd8fed	int Num_strings = 0;
1071cd2cd8fed	int string_table_len = 0;
1072cd2cd8fed	char *temp_ptr;
1073cd2cd8fed
1074cd2cd8fed	TERM_data_ptr = Data_Line = malloc((10240 * (sizeof(char))));
1075cd2cd8fed	Data_Line_len = read(Fildes, Data_Line, 10240);
1076cd2cd8fed	if ((Data_Line_len >= 10240) || (Data_Line_len < 0))
1077cd2cd8fed		return(0);
1078cd2cd8fed	/*
1079cd2cd8fed	 |	get magic number
1080cd2cd8fed	 */
1081cd2cd8fed	magic_number = Get_int();
1082cd2cd8fed	/*
1083cd2cd8fed	 |	if magic number not right, reverse byte order and check again
1084cd2cd8fed	 */
1085cd2cd8fed	if (magic_number != 282)
1086cd2cd8fed	{
1087cd2cd8fed		Flip_Bytes = TRUE;
1088cd2cd8fed		TERM_data_ptr--;
1089cd2cd8fed		TERM_data_ptr--;
1090cd2cd8fed		magic_number = Get_int();
1091cd2cd8fed		if (magic_number != 282)
1092cd2cd8fed			return(0);
1093cd2cd8fed	}
1094cd2cd8fed	/*
1095cd2cd8fed	 |	get the number of each type in the terminfo data file
1096cd2cd8fed	 */
1097cd2cd8fed	Num_names = Get_int();
1098cd2cd8fed	Num_bools = Get_int();
1099cd2cd8fed	Num_ints = Get_int();
1100cd2cd8fed	Num_strings = Get_int();
1101cd2cd8fed	string_table_len = Get_int();
1102cd2cd8fed	Strings = malloc(string_table_len);
1103cd2cd8fed	while (Num_names > 0)
1104cd2cd8fed	{
1105cd2cd8fed		TERM_data_ptr++;
1106cd2cd8fed		Num_names--;
1107cd2cd8fed	}
1108cd2cd8fed	counter = 0;
1109cd2cd8fed	while (Num_bools)
1110cd2cd8fed	{
1111cd2cd8fed		Num_bools--;
1112cd2cd8fed		Booleans[counter++] = *TERM_data_ptr++;
1113cd2cd8fed	}
1114c24192eed	if ((unsigned long)TERM_data_ptr & 1)	/* force alignment	*/
1115cd2cd8fed		TERM_data_ptr++;
1116cd2cd8fed	counter = 0;
1117cd2cd8fed	while (Num_ints)
1118cd2cd8fed	{
1119cd2cd8fed		Num_ints--;
1120cd2cd8fed		Numbers[counter] = Get_int();
1121cd2cd8fed		counter++;
1122cd2cd8fed	}
1123cd2cd8fed	temp_ptr = TERM_data_ptr + Num_strings + Num_strings;
1124cd2cd8fed	memcpy(Strings, temp_ptr, string_table_len);
1125cd2cd8fed	counter = bt__;
1126cd2cd8fed	while (Num_strings)
1127cd2cd8fed	{
1128cd2cd8fed		Num_strings--;
1129cd2cd8fed		if ((offset=Get_int()) != -1)
1130cd2cd8fed		{
1131cd2cd8fed			if (String_table[counter] == NULL)
1132cd2cd8fed				String_table[counter] = Strings + offset;
1133cd2cd8fed		}
1134cd2cd8fed		else
1135cd2cd8fed			String_table[counter] = NULL;
1136cd2cd8fed		counter++;
1137cd2cd8fed	}
1138cd2cd8fed	close(Fildes);
1139cd2cd8fed	free(Data_Line);
1140cd2cd8fed	return(TRUE);
1141cd2cd8fed}
1142cd2cd8fed#endif		/* ifndef CAP	*/
1143cd2cd8fed
1144cd2cd8fedint
1145cd2cd8fedAtoI()		/* convert ascii text to integers	*/
1146cd2cd8fed{
1147cd2cd8fed	int Temp;
1148cd2cd8fed
1149cd2cd8fed	Temp = 0;
1150cd2cd8fed	while ((*TERM_data_ptr >= '0') && (*TERM_data_ptr <= '9'))
1151cd2cd8fed	{
1152cd2cd8fed		Temp = (Temp * 10) + (*TERM_data_ptr - '0');
1153cd2cd8fed		TERM_data_ptr++;
1154cd2cd8fed	}
1155cd2cd8fed	return(Temp);
1156cd2cd8fed}
1157cd2cd8fed
1158cd2cd8fedvoid
1159cd2cd8fedKey_Get()		/* create linked list with all key sequences obtained from terminal database	*/
1160cd2cd8fed{
1161cd2cd8fed	int Counter;
1162cd2cd8fed	int Klen;
1163cd2cd8fed	int key_def;
1164cd2cd8fed	struct KEY_STACK *Spoint;
1165cd2cd8fed
1166cd2cd8fed	Max_Key_len = 0;
1167cd2cd8fed	Counter = 0;
1168cd2cd8fed	key_def = kb__;
1169cd2cd8fed	while (key_def <= kf63__)
1170cd2cd8fed	{
1171cd2cd8fed		if (key_def == ke__)
1172cd2cd8fed			key_def = K1__;
1173cd2cd8fed		else if (key_def == (K5__ + 1))
1174cd2cd8fed			key_def = kcbt__;
1175cd2cd8fed		else if (key_def == (kcbt__ + 1))
1176cd2cd8fed			key_def = kbeg__;
1177cd2cd8fed		else if (key_def == (kUND__ + 1))
1178cd2cd8fed			key_def = kf11__;
1179cd2cd8fed		if (String_table[key_def] != NULL)
1180cd2cd8fed		{
1181cd2cd8fed			if (KEY_TOS == NULL)
1182cd2cd8fed				Spoint = KEY_TOS = (struct KEY_STACK *) malloc(sizeof(struct KEY_STACK));
1183cd2cd8fed			else
1184cd2cd8fed			{
1185cd2cd8fed				Spoint = KEY_TOS;
1186cd2cd8fed				while (Spoint->next != NULL)
1187cd2cd8fed					Spoint = Spoint->next;
1188cd2cd8fed				Spoint->next = (struct KEY_STACK *) malloc(sizeof(struct KEY_STACK));
1189cd2cd8fed				Spoint = Spoint->next;
1190cd2cd8fed			}
1191cd2cd8fed			Spoint->next = NULL;
1192cd2cd8fed			Spoint->element = (struct KEYS *) malloc(sizeof(struct KEYS));
1193cd2cd8fed			Spoint->element->string = String_table[key_def];
1194cd2cd8fed			Spoint->element->length = strlen(String_table[key_def]);
1195cd2cd8fed			Spoint->element->value = Key_vals[Counter];
1196cd2cd8fed			Klen = strlen(Spoint->element->string);
1197cd2cd8fed			if (Klen > Max_Key_len)
1198cd2cd8fed				Max_Key_len = Klen;
1199cd2cd8fed			/*
1200cd2cd8fed			 |  Some terminal types accept keystrokes of the form
1201cd2cd8fed			 |  \E[A and \EOA, substituting '[' for 'O'.  Make a
1202cd2cd8fed			 |  duplicate of such key strings (since the
1203cd2cd8fed			 |  database will only have one version) so new_curse
1204cd2cd8fed			 |  can understand both.
1205cd2cd8fed			 */
1206cd2cd8fed			if ((Spoint->element->length > 1) &&
1207cd2cd8fed			    ((String_table[key_def][1] == '[') ||
1208cd2cd8fed			     (String_table[key_def][1] == 'O')))
1209cd2cd8fed			{
1210cd2cd8fed				Spoint->next = (struct KEY_STACK *) malloc(sizeof(struct KEY_STACK));
1211cd2cd8fed				Spoint = Spoint->next;
1212cd2cd8fed				Spoint->next = NULL;
1213cd2cd8fed				Spoint->element = (struct KEYS *) malloc(sizeof(struct KEYS));
1214cd2cd8fed				Spoint->element->length = strlen(String_table[key_def]);
1215cd2cd8fed				Spoint->element->string = malloc(Spoint->element->length + 1);
1216cd2cd8fed				strcpy(Spoint->element->string, String_table[key_def]);
1217cd2cd8fed				Spoint->element->value = Key_vals[Counter];
1218cd2cd8fed				Klen = strlen(Spoint->element->string);
1219cd2cd8fed				if (Klen > Max_Key_len)
1220cd2cd8fed					Max_Key_len = Klen;
1221cd2cd8fed
1222cd2cd8fed				if (String_table[key_def][1] == '[')
1223cd2cd8fed					Spoint->element->string[1] = 'O';
1224cd2cd8fed				else
1225cd2cd8fed					Spoint->element->string[1] = '[';
1226cd2cd8fed			}
1227cd2cd8fed		}
1228cd2cd8fed		key_def++;
1229cd2cd8fed		Counter++;
1230cd2cd8fed	}
1231cd2cd8fed}
1232cd2cd8fed
1233cd2cd8fed/*
1234cd2cd8fed |	insert information about keys for a vt100 terminal
1235cd2cd8fed */
1236cd2cd8fed
1237cd2cd8fedvoid
1238cd2cd8fedkeys_vt100()
1239cd2cd8fed{
1240cd2cd8fed	int counter;
1241cd2cd8fed	int Klen;
1242cd2cd8fed	struct KEY_STACK *Spoint;
1243cd2cd8fed
1244cd2cd8fed	Spoint = KEY_TOS;
1245cd2cd8fed	while (Spoint->next != NULL)
1246cd2cd8fed		Spoint = Spoint->next;
1247cd2cd8fed	for (counter = 0; vt100[counter].length != 0; counter++)
1248cd2cd8fed	{
1249cd2cd8fed		Spoint->next = (struct KEY_STACK *) malloc(sizeof(struct KEY_STACK));
1250cd2cd8fed		Spoint = Spoint->next;
1251cd2cd8fed		Spoint->next = NULL;
1252cd2cd8fed		Spoint->element = &vt100[counter];
1253cd2cd8fed		Klen = strlen(Spoint->element->string);
1254cd2cd8fed		if (Klen > Max_Key_len)
1255cd2cd8fed			Max_Key_len = Klen;
1256cd2cd8fed	}
1257cd2cd8fed}
1258cd2cd8fed
1259cd2cd8fed#ifdef CAP
1260cd2cd8fedchar *
1261cd2cd8fedString_Get(param)		/* read the string */
1262cd2cd8fedchar *param;
1263cd2cd8fed{
1264cd2cd8fed	char *String;
1265cd2cd8fed	char *Temp;
1266cd2cd8fed	int Counter;
1267cd2cd8fed
1268cd2cd8fed	if (param == NULL)
1269cd2cd8fed	{
1270cd2cd8fed		while (*TERM_data_ptr != '=')
1271cd2cd8fed			TERM_data_ptr++;
1272cd2cd8fed		Temp = ++TERM_data_ptr;
1273cd2cd8fed		Counter = 1;
1274cd2cd8fed		while ((*Temp != ':') && (*Temp != (char)NULL))
1275cd2cd8fed		{
1276cd2cd8fed			Counter++;
1277cd2cd8fed			Temp++;
1278cd2cd8fed		}
1279cd2cd8fed		if (Counter == 1)	/* no data */
1280cd2cd8fed			return(NULL);
1281cd2cd8fed		String = Temp = malloc(Counter);
1282cd2cd8fed		while ((*TERM_data_ptr != ':') && (*TERM_data_ptr != (char)NULL))
1283cd2cd8fed		{
1284cd2cd8fed			if (*TERM_data_ptr == '\\')
1285cd2cd8fed			{
1286cd2cd8fed				TERM_data_ptr++;
1287cd2cd8fed				if (*TERM_data_ptr == 'n')
1288cd2cd8fed					*Temp = '\n';
1289cd2cd8fed				else if (*TERM_data_ptr == 't')
1290cd2cd8fed					*Temp = '\t';
1291cd2cd8fed				else if (*TERM_data_ptr == 'b')
1292cd2cd8fed					*Temp = '\b';
1293cd2cd8fed				else if (*TERM_data_ptr == 'r')
1294cd2cd8fed					*Temp = '\r';
1295cd2cd8fed				else if (*TERM_data_ptr == 'f')
1296cd2cd8fed					*Temp = '\f';
1297cd2cd8fed				else if ((*TERM_data_ptr == 'e') || (*TERM_data_ptr == 'E'))
1298cd2cd8fed					*Temp = '\033';		/* escape */
1299cd2cd8fed				else if (*TERM_data_ptr == '\\')
1300cd2cd8fed					*Temp = '\\';
1301cd2cd8fed				else if (*TERM_data_ptr == '\'')
1302cd2cd8fed					*Temp = '\'';
1303cd2cd8fed				else if ((*TERM_data_ptr >= '0') && (*TERM_data_ptr <= '9'))
1304cd2cd8fed				{
1305cd2cd8fed					Counter = 0;
1306cd2cd8fed					while ((*TERM_data_ptr >= '0') && (*TERM_data_ptr <= '9'))
1307cd2cd8fed					{
1308cd2cd8fed						Counter = (8 * Counter) + (*TERM_data_ptr - '0');
1309cd2cd8fed						TERM_data_ptr++;  /* ? */
1310cd2cd8fed					}
1311cd2cd8fed					*Temp = Counter;
1312cd2cd8fed					TERM_data_ptr--;
1313cd2cd8fed				}
1314cd2cd8fed				TERM_data_ptr++;
1315cd2cd8fed				Temp++;
1316cd2cd8fed			}
1317cd2cd8fed			else if (*TERM_data_ptr == '^')
1318cd2cd8fed			{
1319cd2cd8fed				TERM_data_ptr++;
1320cd2cd8fed				if ((*TERM_data_ptr >= '@') && (*TERM_data_ptr <= '_'))
1321cd2cd8fed					*Temp = *TERM_data_ptr - '@';
1322cd2cd8fed				else if (*TERM_data_ptr == '?')
1323cd2cd8fed					*Temp = 127;
1324cd2cd8fed				TERM_data_ptr++;
1325cd2cd8fed				Temp++;
1326cd2cd8fed			}
1327cd2cd8fed			else
1328cd2cd8fed				*Temp++ = *TERM_data_ptr++;
1329cd2cd8fed		}
1330cd2cd8fed		*Temp = (char)NULL;
1331cd2cd8fed		param = String;
1332cd2cd8fed	}
1333cd2cd8fed	else
1334cd2cd8fed	{
1335cd2cd8fed		while ((*TERM_data_ptr != (char)NULL) && (*TERM_data_ptr != ':'))
1336cd2cd8fed			TERM_data_ptr++;
1337cd2cd8fed	}
1338cd2cd8fed	return(param);
1339cd2cd8fed}
1340cd2cd8fed
1341cd2cd8fedint
1342cd2cd8fedtc_Get_int(param)		/* read the integer			*/
1343cd2cd8fedint param;
1344cd2cd8fed{
1345cd2cd8fed	int Itemp;
1346cd2cd8fed
1347cd2cd8fed	if (param == 0)
1348cd2cd8fed	{
1349cd2cd8fed		while ((*TERM_data_ptr != (char)NULL) && (*TERM_data_ptr != '#'))
1350cd2cd8fed			TERM_data_ptr++;
1351cd2cd8fed		TERM_data_ptr++;
1352cd2cd8fed		Itemp = AtoI();
1353cd2cd8fed		param = Itemp;
1354cd2cd8fed	}
1355cd2cd8fed	else
1356cd2cd8fed	{
1357cd2cd8fed		while (*TERM_data_ptr != ':')
1358cd2cd8fed			TERM_data_ptr++;
1359cd2cd8fed	}
1360cd2cd8fed	return(param);
1361cd2cd8fed}
1362cd2cd8fed
1363cd2cd8fedvoid
1364cd2cd8fedFind_term()		/* find terminal description in termcap file	*/
1365cd2cd8fed{
1366cd2cd8fed	char *Name;
1367cd2cd8fed	char *Ftemp;
1368cd2cd8fed
1369d2f3627ed	Ftemp = Name = malloc(strlen(TERMINAL_TYPE) + 2);
1370cd2cd8fed	strcpy(Name, TERMINAL_TYPE);
1371cd2cd8fed	while (*Ftemp != (char)NULL)
1372cd2cd8fed		Ftemp++;
1373cd2cd8fed	*Ftemp++ = '|';
1374cd2cd8fed	*Ftemp = (char)NULL;
1375cd2cd8fed	CFOUND = FALSE;
1376cd2cd8fed	Data_Line_len = strlen(TERMINAL_TYPE) + 1;
1377cd2cd8fed	while ((!CFOUND) && ((TERM_data_ptr=fgets(Data_Line, 512, TFP)) != NULL))
1378cd2cd8fed	{
1379cd2cd8fed		if ((*TERM_data_ptr != ' ') && (*TERM_data_ptr != '\t') && (*TERM_data_ptr != '#'))
1380cd2cd8fed		{
1381cd2cd8fed			while ((!CFOUND) && (*TERM_data_ptr != (char)NULL))
1382cd2cd8fed			{
1383cd2cd8fed				CFOUND = !strncmp(TERM_data_ptr, Name, Data_Line_len);
1384cd2cd8fed				while ((*TERM_data_ptr != (char)NULL) && (*TERM_data_ptr != '|') && (*TERM_data_ptr != '#') && (*TERM_data_ptr != ':'))
1385cd2cd8fed					TERM_data_ptr++;
1386cd2cd8fed				if (*TERM_data_ptr == '|')
1387cd2cd8fed					TERM_data_ptr++;
1388cd2cd8fed				else if (!CFOUND)
1389cd2cd8fed					*TERM_data_ptr = (char)NULL;
1390cd2cd8fed			}
1391cd2cd8fed		}
1392cd2cd8fed	}
1393cd2cd8fed	if (!CFOUND)
1394cd2cd8fed	{
1395cd2cd8fed		printf("terminal type %s not found\n", TERMINAL_TYPE);
1396cd2cd8fed		exit(0);
1397cd2cd8fed	}
1398cd2cd8fed}
1399cd2cd8fed
1400cd2cd8fedvoid
1401cd2cd8fedCAP_PARSE()		/* parse off the data in the termcap data file	*/
1402cd2cd8fed{
1403cd2cd8fed	int offset;
1404cd2cd8fed	int found;
1405cd2cd8fed
1406cd2cd8fed	do
1407cd2cd8fed	{
1408cd2cd8fed		while (*TERM_data_ptr != (char)NULL)
1409cd2cd8fed		{
1410cd2cd8fed			for (found = FALSE, offset = 0; (!found) && (offset < 26); offset++)
1411cd2cd8fed			{
1412cd2cd8fed				if (!strncmp(TERM_data_ptr, Boolean_names[offset], 2))
1413cd2cd8fed				{
1414cd2cd8fed					found = TRUE;
1415cd2cd8fed					Booleans[offset] = TRUE;
1416cd2cd8fed				}
1417cd2cd8fed			}
1418cd2cd8fed			if (!found)
1419cd2cd8fed			{
1420cd2cd8fed				for (found = FALSE, offset = 0; (!found) && (offset < lw__); offset++)
1421cd2cd8fed				{
1422cd2cd8fed					if (!strncmp(TERM_data_ptr, Number_names[offset], 3))
1423cd2cd8fed					{
1424cd2cd8fed						found = TRUE;
1425cd2cd8fed						Numbers[offset] = tc_Get_int(Numbers[offset]);
1426cd2cd8fed					}
1427cd2cd8fed				}
1428cd2cd8fed			}
1429cd2cd8fed			if (!found)
1430cd2cd8fed			{
1431cd2cd8fed				for (found = FALSE, offset = 0; (!found) && (offset < smgr__); offset++)
1432cd2cd8fed				{
1433cd2cd8fed					if (!strncmp(TERM_data_ptr, String_names[offset], 3))
1434cd2cd8fed					{
1435cd2cd8fed						found = TRUE;
1436cd2cd8fed						String_table[offset] = String_Get(String_table[offset]);
1437cd2cd8fed					}
1438cd2cd8fed				}
1439cd2cd8fed			}
1440cd2cd8fed
1441cd2cd8fed			if (!strncmp(TERM_data_ptr, "tc=", 3))
1442cd2cd8fed				tc_ = String_Get(NULL);
1443cd2cd8fed			while ((*TERM_data_ptr != ':') && (*TERM_data_ptr != (char)NULL))
1444cd2cd8fed				TERM_data_ptr++;
1445cd2cd8fed			if (*TERM_data_ptr == ':')
1446cd2cd8fed				TERM_data_ptr++;
1447cd2cd8fed		}
1448cd2cd8fed	} while (((TERM_data_ptr = fgets(Data_Line, 512, TFP)) != NULL) && ((*TERM_data_ptr == ' ') || (*TERM_data_ptr == '\t')));
1449cd2cd8fed	if (tc_ != NULL)
1450cd2cd8fed	{
1451cd2cd8fed		TERMINAL_TYPE = tc_;
1452cd2cd8fed		rewind(TFP);
1453cd2cd8fed		Find_term();
1454cd2cd8fed		tc_ = NULL;
1455cd2cd8fed		CAP_PARSE();
1456cd2cd8fed	}
1457cd2cd8fed	else
1458cd2cd8fed		fclose(TFP);
1459cd2cd8fed}
1460cd2cd8fed#endif		/* ifdef CAP	*/
1461cd2cd8fed
1462cd2cd8fedstruct _line *
1463cd2cd8fedScreenalloc(columns)
1464cd2cd8fedint columns;
1465cd2cd8fed{
1466cd2cd8fed	int i;
1467cd2cd8fed	struct _line *tmp;
1468cd2cd8fed
1469cd2cd8fed	tmp = (struct _line *) malloc(sizeof (struct _line));
1470cd2cd8fed	tmp->row = malloc(columns + 1);
1471cd2cd8fed	tmp->attributes = malloc(columns + 1);
1472cd2cd8fed	tmp->prev_screen = NULL;
1473cd2cd8fed	tmp->next_screen = NULL;
1474cd2cd8fed	for (i = 0; i < columns; i++)
1475cd2cd8fed	{
1476cd2cd8fed		tmp->row[i] = ' ';
1477c24192eed		tmp->attributes[i] = '\0';
1478cd2cd8fed	}
1479cd2cd8fed	tmp->scroll = tmp->changed = FALSE;
1480c24192eed	tmp->row[0] = '\0';
1481c24192eed	tmp->attributes[0] = '\0';
1482c24192eed	tmp->row[columns] = '\0';
1483c24192eed	tmp->attributes[columns] = '\0';
1484cd2cd8fed	tmp->last_char = 0;
1485cd2cd8fed	return(tmp);
1486cd2cd8fed}
1487cd2cd8fed
1488cd2cd8fedWINDOW *newwin(lines, cols, start_l, start_c)
1489cd2cd8fedint lines, cols;	/* number of lines and columns to be in window	*/
1490cd2cd8fedint start_l, start_c;	/* starting line and column to be inwindow	*/
1491cd2cd8fed{
1492cd2cd8fed	WINDOW *Ntemp;
1493cd2cd8fed	struct _line *temp_screen;
1494cd2cd8fed	int i;
1495cd2cd8fed
1496cd2cd8fed	Ntemp = (WINDOW *) malloc(sizeof(WINDOW));
1497cd2cd8fed	Ntemp->SR = start_l;
1498cd2cd8fed	Ntemp->SC = start_c;
1499cd2cd8fed	Ntemp->Num_lines = lines;
1500cd2cd8fed	Ntemp->Num_cols = cols;
1501cd2cd8fed	Ntemp->LX = 0;
1502cd2cd8fed	Ntemp->LY = 0;
1503cd2cd8fed	Ntemp->scroll_down = Ntemp->scroll_up = 0;
1504cd2cd8fed	Ntemp->SCROLL_CLEAR = FALSE;
1505cd2cd8fed	Ntemp->Attrib = FALSE;
1506cd2cd8fed	Ntemp->first_line = temp_screen = Screenalloc(cols);
1507cd2cd8fed	Ntemp->first_line->number = 0;
1508cd2cd8fed	Ntemp->line_array = (struct _line **) malloc(LINES * sizeof(struct _line *));
1509cd2cd8fed
1510cd2cd8fed	Ntemp->line_array[0] = Ntemp->first_line;
1511cd2cd8fed
1512cd2cd8fed	for (i = 1; i < lines; i++)
1513cd2cd8fed	{
1514cd2cd8fed		temp_screen->next_screen = Screenalloc(cols);
1515cd2cd8fed		temp_screen->next_screen->number = i;
1516cd2cd8fed		temp_screen->next_screen->prev_screen = temp_screen;
1517cd2cd8fed		temp_screen = temp_screen->next_screen;
1518cd2cd8fed		Ntemp->line_array[i] = temp_screen;
1519cd2cd8fed	}
1520cd2cd8fed	Ntemp->first_line->prev_screen = NULL;
1521cd2cd8fed	temp_screen->next_screen = NULL;
1522cd2cd8fed	return(Ntemp);
1523cd2cd8fed}
1524cd2cd8fed
1525cd2cd8fed#ifdef CAP
1526cd2cd8fedvoid
1527cd2cd8fedCap_Out(string, p_list, place)	/* interpret the output string if necessary */
1528cd2cd8fedchar *string;
1529cd2cd8fedint p_list[];			/* stack of values	*/
1530cd2cd8fedint place;			/* place keeper of top of stack	*/
1531cd2cd8fed{
1532cd2cd8fed	char *Otemp;		/* temporary string pointer to parse output */
1533cd2cd8fed	int delay;
1534cd2cd8fed	int p1, p2, temp;
1535cd2cd8fed	float chars;
1536cd2cd8fed
1537cd2cd8fed	if (string == NULL)
1538cd2cd8fed		return;
1539cd2cd8fed
1540cd2cd8fed	if (p_list != NULL)
1541cd2cd8fed	{
1542cd2cd8fed		p1 = p_list[--place];
1543cd2cd8fed		p2 = p_list[--place];
1544cd2cd8fed	}
1545cd2cd8fed	delay = 0;
1546cd2cd8fed	Otemp = string;
1547cd2cd8fed	if ((*Otemp >= '0') && (*Otemp <= '9'))
1548cd2cd8fed	{
1549cd2cd8fed		delay = atoi(Otemp);
1550cd2cd8fed		while ((*Otemp >= '0') && (*Otemp <= '9'))
1551cd2cd8fed			Otemp++;
1552cd2cd8fed		if (*Otemp == '*')
1553cd2cd8fed			Otemp++;
1554cd2cd8fed	}
1555cd2cd8fed	while (*Otemp != (char)NULL)
1556cd2cd8fed	{
1557cd2cd8fed		if (*Otemp == '%')
1558cd2cd8fed		{
1559cd2cd8fed			Otemp++;
1560cd2cd8fed			if ((*Otemp == 'd') || (*Otemp == '2') || (*Otemp == '3') || (*Otemp == '.') || (*Otemp == '+'))
1561cd2cd8fed			{
1562cd2cd8fed				if (*Otemp == 'd')
1563cd2cd8fed				 	printf("%d", p1);
1564cd2cd8fed				else if (*Otemp == '2')
1565cd2cd8fed					printf("%02d", p1);
1566cd2cd8fed				else if (*Otemp == '3')
1567cd2cd8fed					printf("%03d", p1);
1568cd2cd8fed				else if (*Otemp == '+')
1569cd2cd8fed				{
1570cd2cd8fed					Otemp++;
1571cd2cd8fed					p1 += *Otemp;
1572cd2cd8fed					putchar(p1);
1573cd2cd8fed				}
1574cd2cd8fed				else if (*Otemp == '.')
1575cd2cd8fed					putchar(p1);
1576cd2cd8fed				p1 = p2;
1577cd2cd8fed				p2 = 0;
1578cd2cd8fed			}
1579cd2cd8fed			else if (*Otemp == '>')
1580cd2cd8fed			{
1581cd2cd8fed				Otemp++;
1582cd2cd8fed				if (p1 > *Otemp)
1583cd2cd8fed				{
1584cd2cd8fed					Otemp++;
1585cd2cd8fed					p1 += *Otemp;
1586cd2cd8fed				}
1587cd2cd8fed				else
1588cd2cd8fed					Otemp++;
1589cd2cd8fed			}
1590cd2cd8fed			else if (*Otemp == 'r')
1591cd2cd8fed			{
1592cd2cd8fed				temp = p1;
1593cd2cd8fed				p1 = p2;
1594cd2cd8fed				p2 = temp;
1595cd2cd8fed			}
1596cd2cd8fed			else if (*Otemp == 'i')
1597cd2cd8fed			{
1598cd2cd8fed				p1++;
1599cd2cd8fed				p2++;
1600cd2cd8fed			}
1601cd2cd8fed			else if (*Otemp == '%')
1602cd2cd8fed				putchar(*Otemp);
1603cd2cd8fed			else if (*Otemp == 'n')
1604cd2cd8fed			{
1605cd2cd8fed				p1 ^= 0140;
1606cd2cd8fed				p2 ^= 0140;
1607cd2cd8fed			}
1608cd2cd8fed			else if (*Otemp == 'B')
1609cd2cd8fed			{
1610cd2cd8fed				p1 = (16 * (p1/10)) + (p1 % 10);
1611cd2cd8fed				p2 = (16 * (p2/10)) + (p2 % 10);
1612cd2cd8fed			}
1613cd2cd8fed			else if (*Otemp == 'D')
1614cd2cd8fed			{
1615cd2cd8fed				p1 = (p1 - 2 * (p1 % 16));
1616cd2cd8fed				p2 = (p2 - 2 * (p2 % 16));
1617cd2cd8fed			}
1618cd2cd8fed		}
1619cd2cd8fed		else
1620cd2cd8fed			putchar (*Otemp);
1621cd2cd8fed		Otemp++;
1622cd2cd8fed	}
1623cd2cd8fed	if (delay != 0)
1624cd2cd8fed	{
1625cd2cd8fed		chars = delay * chars_per_millisecond;
1626cd2cd8fed		delay = chars;
1627cd2cd8fed		if ((chars - delay) > 0.0)
1628cd2cd8fed			delay++;
1629cd2cd8fed		for (; delay > 0; delay--)
1630cd2cd8fed			putchar(*String_table[pc__]);
1631cd2cd8fed	}
1632cd2cd8fed	fflush(stdout);
1633cd2cd8fed}
1634cd2cd8fed
1635cd2cd8fed#else
1636cd2cd8fed
1637cd2cd8fed	char *Otemp;		/* temporary string pointer to parse output */
1638cd2cd8fed	float chars;
1639cd2cd8fed	int p[10];
1640cd2cd8fed	int variable[27];
1641cd2cd8fed
1642cd2cd8fedint
1643cd2cd8fedOperation(Temp_Stack, place)	/* handle conditional operations	*/
1644cd2cd8fedint Temp_Stack[];
1645cd2cd8fedint place;
1646cd2cd8fed{
1647cd2cd8fed	int temp;
1648cd2cd8fed
1649cd2cd8fed	if (*Otemp == 'd')
1650cd2cd8fed	{
1651cd2cd8fed		Otemp++;
1652cd2cd8fed		temp = Temp_Stack[--place];
1653cd2cd8fed	 	printf("%d", temp);
1654cd2cd8fed	}
1655cd2cd8fed	else if (!strncmp(Otemp, "2d", 2))
1656cd2cd8fed	{
1657cd2cd8fed		temp = Temp_Stack[--place];
1658cd2cd8fed		printf("%2d", temp);
1659cd2cd8fed		Otemp++;
1660cd2cd8fed		Otemp++;
1661cd2cd8fed	}
1662cd2cd8fed	else if (!strncmp(Otemp, "3d", 2))
1663cd2cd8fed	{
1664cd2cd8fed		temp = Temp_Stack[--place];
1665cd2cd8fed		printf("%0d", temp);
1666cd2cd8fed		Otemp++;
1667cd2cd8fed		Otemp++;
1668cd2cd8fed	}
1669cd2cd8fed	else if (!strncmp(Otemp, "02d", 3))
1670cd2cd8fed	{
1671cd2cd8fed		temp = Temp_Stack[--place];
1672cd2cd8fed		printf("%02d", temp);
1673cd2cd8fed		Otemp++;
1674cd2cd8fed		Otemp++;
1675cd2cd8fed		Otemp++;
1676cd2cd8fed	}
1677cd2cd8fed	else if (!strncmp(Otemp, "03d", 3))
1678cd2cd8fed	{
1679cd2cd8fed		temp = Temp_Stack[--place];
1680cd2cd8fed		printf("%03d", temp);
1681cd2cd8fed		Otemp++;
1682cd2cd8fed		Otemp++;
1683cd2cd8fed		Otemp++;
1684cd2cd8fed	}
1685cd2cd8fed	else if (*Otemp == '+')
1686cd2cd8fed	{
1687cd2cd8fed		Otemp++;
1688cd2cd8fed		temp = Temp_Stack[--place];
1689cd2cd8fed		temp += Temp_Stack[--place];
1690cd2cd8fed		Temp_Stack[place++] = temp;
1691cd2cd8fed	}
1692cd2cd8fed	else if (*Otemp == '-')
1693cd2cd8fed	{
1694cd2cd8fed		Otemp++;
1695cd2cd8fed		temp = Temp_Stack[--place];
1696cd2cd8fed		temp -= Temp_Stack[--place];
1697cd2cd8fed		Temp_Stack[place++] = temp;
1698cd2cd8fed	}
1699cd2cd8fed	else if (*Otemp == '*')
1700cd2cd8fed	{
1701cd2cd8fed		Otemp++;
1702cd2cd8fed		temp = Temp_Stack[--place];
1703cd2cd8fed		temp *= Temp_Stack[--place];
1704cd2cd8fed		Temp_Stack[place++] = temp;
1705cd2cd8fed	}
1706cd2cd8fed	else if (*Otemp == '/')
1707cd2cd8fed	{
1708cd2cd8fed		Otemp++;
1709cd2cd8fed		temp = Temp_Stack[--place];
1710cd2cd8fed		temp /= Temp_Stack[--place];
1711cd2cd8fed		Temp_Stack[place++] = temp;
1712cd2cd8fed	}
1713cd2cd8fed	else if (*Otemp == 'm')
1714cd2cd8fed	{
1715cd2cd8fed		Otemp++;
1716cd2cd8fed		temp = Temp_Stack[--place];
1717cd2cd8fed		temp %= Temp_Stack[--place];
1718cd2cd8fed		Temp_Stack[place++] = temp;
1719cd2cd8fed	}
1720cd2cd8fed	else if (*Otemp == '&')
1721cd2cd8fed	{
1722cd2cd8fed		Otemp++;
1723cd2cd8fed		temp = Temp_Stack[--place];
1724cd2cd8fed		temp &= Temp_Stack[--place];
1725cd2cd8fed		Temp_Stack[place++] = temp;
1726cd2cd8fed	}
1727cd2cd8fed	else if (*Otemp == '|')
1728cd2cd8fed	{
1729cd2cd8fed		Otemp++;
1730cd2cd8fed		temp = Temp_Stack[--place];
1731cd2cd8fed		temp |= Temp_Stack[--place];
1732cd2cd8fed		Temp_Stack[place++] = temp;
1733cd2cd8fed	}
1734cd2cd8fed	else if (*Otemp == '^')
1735cd2cd8fed	{
1736cd2cd8fed		Otemp++;
1737cd2cd8fed		temp = Temp_Stack[--place];
1738cd2cd8fed		temp ^= Temp_Stack[--place];
1739cd2cd8fed		Temp_Stack[place++] = temp;
1740cd2cd8fed	}
1741cd2cd8fed	else if (*Otemp == '=')
1742cd2cd8fed	{
1743cd2cd8fed		Otemp++;
1744cd2cd8fed		temp = Temp_Stack[--place];
1745cd2cd8fed		temp = (temp == Temp_Stack[--place]);
1746cd2cd8fed		Temp_Stack[place++] = temp;
1747cd2cd8fed	}
1748cd2cd8fed	else if (*Otemp == '>')
1749cd2cd8fed	{
1750cd2cd8fed		Otemp++;
1751cd2cd8fed		temp = Temp_Stack[--place];
1752cd2cd8fed		temp = temp > Temp_Stack[--place];
1753cd2cd8fed		Temp_Stack[place++] = temp;
1754cd2cd8fed	}
1755cd2cd8fed	else if (*Otemp == '<')
1756cd2cd8fed	{
1757cd2cd8fed		Otemp++;
1758cd2cd8fed		temp = Temp_Stack[--place];
1759cd2cd8fed		temp = temp < Temp_Stack[--place];
1760cd2cd8fed		Temp_Stack[place++] = temp;
1761cd2cd8fed	}
1762cd2cd8fed	else if (*Otemp == 'c')
1763cd2cd8fed	{
1764cd2cd8fed		Otemp++;
1765cd2cd8fed		putchar(Temp_Stack[--place]);
1766cd2cd8fed	}
1767cd2cd8fed	else if (*Otemp == 'i')
1768cd2cd8fed	{
1769cd2cd8fed		Otemp++;
1770cd2cd8fed		p[1]++;
1771cd2cd8fed		p[2]++;
1772cd2cd8fed	}
1773cd2cd8fed	else if (*Otemp == '%')
1774cd2cd8fed	{
1775cd2cd8fed		putchar(*Otemp);
1776cd2cd8fed		Otemp++;
1777cd2cd8fed	}
1778cd2cd8fed	else if (*Otemp == '!')
1779cd2cd8fed	{
1780cd2cd8fed		temp = ! Temp_Stack[--place];
1781cd2cd8fed		Temp_Stack[place++] = temp;
1782cd2cd8fed		Otemp++;
1783cd2cd8fed	}
1784cd2cd8fed	else if (*Otemp == '~')
1785cd2cd8fed	{
1786cd2cd8fed		temp = ~Temp_Stack[--place];
1787cd2cd8fed		Temp_Stack[place++] = temp;
1788cd2cd8fed		Otemp++;
1789cd2cd8fed	}
1790cd2cd8fed	else if (*Otemp == 'p')
1791cd2cd8fed	{
1792cd2cd8fed		Otemp++;
1793cd2cd8fed		Temp_Stack[place++] = p[*Otemp - '0'];
1794cd2cd8fed		Otemp++;
1795cd2cd8fed	}
1796cd2cd8fed	else if (*Otemp == 'P')
1797cd2cd8fed	{
1798cd2cd8fed		Otemp++;
1799cd2cd8fed		Temp_Stack[place++] = variable[*Otemp - 'a'];
1800cd2cd8fed		Otemp++;
1801cd2cd8fed	}
1802cd2cd8fed	else if (*Otemp == 'g')
1803cd2cd8fed	{
1804cd2cd8fed		Otemp++;
1805cd2cd8fed		variable[*Otemp - 'a'] = Temp_Stack[--place];
1806cd2cd8fed		Otemp++;
1807cd2cd8fed	}
1808cd2cd8fed	else if (*Otemp == '\'')
1809cd2cd8fed	{
1810cd2cd8fed		Otemp++;
1811cd2cd8fed		Temp_Stack[place++] = *Otemp;
1812cd2cd8fed		Otemp++;
1813cd2cd8fed		Otemp++;
1814cd2cd8fed	}
1815cd2cd8fed	else if (*Otemp == '{')
1816cd2cd8fed	{
1817cd2cd8fed		Otemp++;
1818cd2cd8fed		temp = atoi(Otemp);
1819cd2cd8fed		Temp_Stack[place++] = temp;
1820cd2cd8fed		while (*Otemp != '}')
1821cd2cd8fed			Otemp++;
1822cd2cd8fed		Otemp++;
1823cd2cd8fed	}
1824cd2cd8fed	return(place);
1825cd2cd8fed}
1826cd2cd8fed
1827cd2cd8fedvoid
1828cd2cd8fedInfo_Out(string, p_list, place)	/* interpret the output string if necessary */
1829cd2cd8fedchar *string;
1830cd2cd8fedint p_list[];
1831cd2cd8fedint place;
1832cd2cd8fed{
1833cd2cd8fed	char *tchar;
1834cd2cd8fed	int delay;
1835cd2cd8fed	int temp;
1836cd2cd8fed	int Cond_FLAG;
1837cd2cd8fed	int EVAL;
1838cd2cd8fed	int Cond_Stack[128];
1839cd2cd8fed	int Cond_place;
1840cd2cd8fed	int Stack[128];
1841cd2cd8fed	int Top_of_stack;
1842cd2cd8fed
1843cd2cd8fed	if (string == NULL)
1844cd2cd8fed		return;
1845cd2cd8fed
1846cd2cd8fed	Cond_FLAG = FALSE;
1847cd2cd8fed	Cond_place = 0;
1848cd2cd8fed	Top_of_stack = 0;
1849cd2cd8fed	p[0] = 0;
1850cd2cd8fed	p[1] = 0;
1851cd2cd8fed	p[2] = 0;
1852cd2cd8fed	p[3] = 0;
1853cd2cd8fed	p[4] = 0;
1854cd2cd8fed	p[5] = 0;
1855cd2cd8fed	p[6] = 0;
1856cd2cd8fed	p[7] = 0;
1857cd2cd8fed	p[8] = 0;
1858cd2cd8fed	p[9] = 0;
1859cd2cd8fed	if (p_list != NULL)
1860cd2cd8fed	{
1861cd2cd8fed		for (temp = 1; (place != 0); temp++)
1862cd2cd8fed		{
1863cd2cd8fed			p[temp] = p_list[--place];
1864cd2cd8fed		}
1865cd2cd8fed	}
1866cd2cd8fed	delay = 0;
1867cd2cd8fed	Otemp = string;
1868c24192eed	while (*Otemp != '\0')
1869cd2cd8fed	{
1870cd2cd8fed		if (*Otemp == '%')
1871cd2cd8fed		{
1872cd2cd8fed			Otemp++;
1873cd2cd8fed			if ((*Otemp == '?') || (*Otemp == 't') || (*Otemp == 'e') || (*Otemp == ';'))
1874cd2cd8fed			{
1875cd2cd8fed				if (*Otemp == '?')
1876cd2cd8fed				{
1877cd2cd8fed					Otemp++;
1878cd2cd8fed					Cond_FLAG = TRUE;
1879cd2cd8fed					EVAL = TRUE;
1880cd2cd8fed					while (EVAL)
1881cd2cd8fed					{
1882cd2cd8fed						/*
1883cd2cd8fed						 |  find the end of the
1884cd2cd8fed						 |  conditional statement
1885cd2cd8fed						 */
1886c24192eed						while ((strncmp(Otemp, "%t", 2)) && (*Otemp != '\0'))
1887cd2cd8fed						{
1888cd2cd8fed							/*
1889cd2cd8fed							 |  move past '%'
1890cd2cd8fed							 */
1891cd2cd8fed							Otemp++;
1892cd2cd8fed							Cond_place = Operation(Cond_Stack, Cond_place);
1893cd2cd8fed						}
1894cd2cd8fed
1895cd2cd8fed						/*
1896cd2cd8fed						 |  if condition is true
1897cd2cd8fed						 */
1898cd2cd8fed						if ((Cond_place > 0) && (Cond_Stack[Cond_place-1]))
1899cd2cd8fed						{
1900cd2cd8fed							/*
1901cd2cd8fed							 |  end conditional
1902cd2cd8fed							 |  parsing
1903cd2cd8fed							 */
1904cd2cd8fed							EVAL = FALSE;
1905cd2cd8fed							Otemp++;
1906cd2cd8fed							Otemp++;
1907cd2cd8fed						}
1908cd2cd8fed						else	/* condition is false */
1909cd2cd8fed						{
1910cd2cd8fed							/*
1911cd2cd8fed							 |  find 'else' or end
1912cd2cd8fed							 |  of if statement
1913cd2cd8fed							 */
1914c24192eed							while ((strncmp(Otemp, "%e", 2)) && (strncmp(Otemp, "%;", 2)) && (*Otemp != '\0'))
1915cd2cd8fed								Otemp++;
1916cd2cd8fed							/*
1917cd2cd8fed							 |  if an 'else' found
1918cd2cd8fed							 */
1919c24192eed							if ((*Otemp != '\0') && (!strncmp(Otemp, "%e", 2)))
1920cd2cd8fed							{
1921cd2cd8fed								Otemp++;
1922cd2cd8fed								Otemp++;
1923cd2cd8fed								tchar = Otemp;
1924cd2cd8fed								/*
1925cd2cd8fed								 |  check for 'then' part
1926cd2cd8fed								 */
1927c24192eed								while ((*tchar != '\0') && (strncmp(tchar, "%t", 2)) && (strncmp(tchar, "%;", 2)))
1928cd2cd8fed									tchar++;
1929cd2cd8fed								/*
1930cd2cd8fed								 |  if end of string
1931cd2cd8fed								 */
1932c24192eed								if (*tchar == '\0')
1933cd2cd8fed								{
1934cd2cd8fed									EVAL = FALSE;
1935cd2cd8fed									Cond_FLAG = FALSE;
1936cd2cd8fed									Otemp = tchar;
1937cd2cd8fed								}
1938cd2cd8fed								/*
1939cd2cd8fed								 |  if end of if found,
1940cd2cd8fed								 |  set up to parse
1941cd2cd8fed								 |  info
1942cd2cd8fed								 */
1943cd2cd8fed								else if (!strncmp(tchar, "%;", 2))
1944cd2cd8fed									EVAL = FALSE;
1945cd2cd8fed								/*
1946cd2cd8fed								 |  otherwise, check
1947cd2cd8fed								 |  conditional in
1948cd2cd8fed								 |  'else'
1949cd2cd8fed								 */
1950cd2cd8fed							}
1951cd2cd8fed							/*
1952cd2cd8fed							 |  if end of if found,
1953cd2cd8fed							 |  get out of if
1954cd2cd8fed							 |  statement
1955cd2cd8fed							 */
1956c24192eed							else if ((*Otemp != '\0') && (!strncmp(Otemp, "%;", 2)))
1957cd2cd8fed							{
1958cd2cd8fed								EVAL = FALSE;
1959cd2cd8fed								Otemp++;
1960cd2cd8fed								Otemp++;
1961cd2cd8fed							}
1962cd2cd8fed							else /* Otemp == NULL */
1963cd2cd8fed							{
1964cd2cd8fed								EVAL = FALSE;
1965cd2cd8fed								Cond_FLAG = FALSE;
1966cd2cd8fed							}
1967cd2cd8fed						}
1968cd2cd8fed					}
1969cd2cd8fed				}
1970cd2cd8fed				else
1971cd2cd8fed				{
1972cd2cd8fed					Otemp++;
1973cd2cd8fed					Cond_FLAG = FALSE;
1974cd2cd8fed					if (*Otemp != ';')
1975cd2cd8fed					{
1976c24192eed						while ((*Otemp != '\0') && (strncmp(Otemp, "%;", 2)))
1977cd2cd8fed							Otemp++;
1978c24192eed						if (*Otemp != '\0')
1979cd2cd8fed						{
1980cd2cd8fed							Otemp++;
1981cd2cd8fed							Otemp++;
1982cd2cd8fed						}
1983cd2cd8fed					}
1984cd2cd8fed					else
1985cd2cd8fed						Otemp++;
1986cd2cd8fed				}
1987cd2cd8fed			}
1988cd2cd8fed			else
1989cd2cd8fed			{
1990cd2cd8fed				Top_of_stack = Operation(Stack, Top_of_stack);
1991cd2cd8fed			}
1992cd2cd8fed		}
1993cd2cd8fed		else if (!strncmp(Otemp, "$<", 2))
1994cd2cd8fed		{
1995cd2cd8fed			Otemp++;
1996cd2cd8fed			Otemp++;
1997cd2cd8fed			delay = atoi(Otemp);
1998cd2cd8fed			while (*Otemp != '>')
1999cd2cd8fed				Otemp++;
2000cd2cd8fed			Otemp++;
2001cd2cd8fed			chars = delay * chars_per_millisecond;
2002cd2cd8fed			delay = chars;
2003cd2cd8fed			if ((chars - delay) > 0.0)
2004cd2cd8fed				delay++;
2005cd2cd8fed			if (String_table[pc__] == NULL)
2006cd2cd8fed				temp = 0;
2007cd2cd8fed			else
2008cd2cd8fed				temp = *String_table[pc__];
2009cd2cd8fed			for (; delay > 0; delay--)
2010cd2cd8fed				putc(temp, stdout);
2011cd2cd8fed		}
2012cd2cd8fed		else
2013cd2cd8fed		{
2014cd2cd8fed			putchar(*Otemp);
2015cd2cd8fed			Otemp++;
2016cd2cd8fed		}
2017cd2cd8fed	}
2018cd2cd8fed	fflush(stdout);
2019cd2cd8fed}
2020cd2cd8fed#endif
2021cd2cd8fed
2022cd2cd8fedvoid
2023cd2cd8fedwmove(window, row, column)	/* move cursor to indicated position in window */
2024cd2cd8fedWINDOW *window;
2025cd2cd8fedint row, column;
2026cd2cd8fed{
2027cd2cd8fed	if ((row < window->Num_lines) && (column < window->Num_cols))
2028cd2cd8fed	{
2029cd2cd8fed		window->LX = column;
2030cd2cd8fed		window->LY = row;
2031cd2cd8fed	}
2032cd2cd8fed}
2033cd2cd8fed
2034cd2cd8fedvoid
2035cd2cd8fedclear_line(line, column, cols)
2036cd2cd8fedstruct _line *line;
2037cd2cd8fedint column;
2038cd2cd8fedint cols;
2039cd2cd8fed{
2040cd2cd8fed	int j;
2041cd2cd8fed
2042cd2cd8fed	if (column > line->last_char)
2043cd2cd8fed	{
2044cd2cd8fed		for (j = line->last_char; j < column; j++)
2045cd2cd8fed		{
2046cd2cd8fed			line->row[j] = ' ';
2047c24192eed			line->attributes[j] = '\0';
2048cd2cd8fed		}
2049cd2cd8fed	}
2050cd2cd8fed	line->last_char = column;
2051c24192eed	line->row[column] = '\0';
2052c24192eed	line->attributes[column] = '\0';
2053cd2cd8fed	line->changed = TRUE;
2054cd2cd8fed}
2055cd2cd8fed
2056cd2cd8fedvoid
2057cd2cd8fedwerase(window)			/* clear the specified window		*/
2058cd2cd8fedWINDOW *window;
2059cd2cd8fed{
2060cd2cd8fed	int i;
2061cd2cd8fed	struct _line *tmp;
2062cd2cd8fed
2063cd2cd8fed	window->SCROLL_CLEAR = CLEAR;
2064cd2cd8fed	window->scroll_up = window->scroll_down = 0;
2065cd2cd8fed	for (i = 0, tmp = window->first_line; i < window->Num_lines; i++, tmp = tmp->next_screen)
2066cd2cd8fed		clear_line(tmp, 0, window->Num_cols);
2067cd2cd8fed}
2068cd2cd8fed
2069cd2cd8fedvoid
2070cd2cd8fedwclrtoeol(window)	/* erase from current cursor position to end of line */
2071cd2cd8fedWINDOW *window;
2072cd2cd8fed{
2073cd2cd8fed	int column, row;
2074cd2cd8fed	struct _line *tmp;
2075cd2cd8fed
2076cd2cd8fed	window->SCROLL_CLEAR = CHANGE;
2077cd2cd8fed	column = window->LX;
2078cd2cd8fed	row = window->LY;
2079cd2cd8fed	for (row = 0, tmp = window->first_line; row < window->LY; row++)
2080cd2cd8fed		tmp = tmp->next_screen;
2081cd2cd8fed	clear_line(tmp, column, window->Num_cols);
2082cd2cd8fed}
2083cd2cd8fed
2084cd2cd8fedvoid
2085cd2cd8fedwrefresh(window)		/* flush all previous output		*/
2086cd2cd8fedWINDOW *window;
2087cd2cd8fed{
2088cd2cd8fed	wnoutrefresh(window);
2089cd2cd8fed#ifdef DIAG
2090cd2cd8fed{
2091cd2cd8fed	struct _line *temp;
2092cd2cd8fed	int value;
2093cd2cd8fed	fprintf(stderr, "columns=%d, lines=%d, SC=%d, SR=%d\n",window->Num_cols, window->Num_lines, window->SC, window->SR);
2094cd2cd8fed	for (value = 0, temp = window->first_line; value < window->Num_lines; value++, temp = temp->next_screen)
2095cd2cd8fed	{
2096cd2cd8fed		if (temp->number == -1)
2097cd2cd8fed			fprintf(stderr, "line moved ");
2098cd2cd8fed		if (temp->scroll)
2099cd2cd8fed			fprintf(stderr, "scroll_x is set:  ");
2100cd2cd8fed		fprintf(stderr, "lc%d=%s|\n", temp->last_char, temp->row);
2101cd2cd8fed	}
2102cd2cd8fed	fprintf(stderr, "+-------------------- virtual screen ----------------------------------------+\n");
2103cd2cd8fed	fprintf(stderr, "columns=%d, lines=%d \n",virtual_scr->Num_cols, virtual_scr->Num_lines);
2104cd2cd8fed	for (value = 0, temp = virtual_scr->first_line; value < virtual_scr->Num_lines; value++, temp = temp->next_screen)
2105cd2cd8fed	{
2106cd2cd8fed		if (temp->number == -1)
2107cd2cd8fed			fprintf(stderr, "line moved ");
2108cd2cd8fed		if (temp->scroll)
2109cd2cd8fed			fprintf(stderr, "scroll_x is set:  ");
2110cd2cd8fed		fprintf(stderr, "lc%d=%s|\n", temp->last_char, temp->row);
2111cd2cd8fed	}
2112cd2cd8fed	fprintf(stderr, "columns=%d, lines=%d \n",curscr->Num_cols, curscr->Num_lines);
2113cd2cd8fed	for (value = 0, temp = curscr->first_line; value < curscr->Num_lines; value++, temp = temp->next_screen)
2114cd2cd8fed		fprintf(stderr, "line=%s|\n", temp->row);
2115cd2cd8fed}
2116cd2cd8fed#endif
2117cd2cd8fed	doupdate();
2118cd2cd8fed	virtual_scr->SCROLL_CLEAR = FALSE;
2119cd2cd8fed	virtual_scr->scroll_down = virtual_scr->scroll_up = 0;
2120cd2cd8fed	fflush(stdout);
2121cd2cd8fed}
2122cd2cd8fed
2123cd2cd8fedvoid
2124cd2cd8fedtouchwin(window)
2125cd2cd8fedWINDOW *window;
2126cd2cd8fed{
2127cd2cd8fed	struct _line *user_line;
2128cd2cd8fed	int line_counter = 0;
2129cd2cd8fed
2130cd2cd8fed	for (line_counter = 0, user_line = window->first_line;
2131cd2cd8fed		line_counter < window->Num_lines; line_counter++)
2132cd2cd8fed	{
2133cd2cd8fed		user_line->changed = TRUE;
2134cd2cd8fed	}
2135cd2cd8fed	window->SCROLL_CLEAR = TRUE;
2136cd2cd8fed}
2137cd2cd8fed
2138cd2cd8fedvoid
2139cd2cd8fedwnoutrefresh(window)
2140cd2cd8fedWINDOW *window;
2141cd2cd8fed{
2142cd2cd8fed	struct _line *user_line;
2143cd2cd8fed	struct _line *virtual_line;
2144cd2cd8fed	int line_counter = 0;
2145cd2cd8fed	int user_col = 0;
2146cd2cd8fed	int virt_col = 0;
2147cd2cd8fed
2148cd2cd8fed	if (window->SR >= virtual_scr->Num_lines)
2149cd2cd8fed		return;
2150cd2cd8fed	user_line = window->first_line;
2151cd2cd8fed	virtual_line = virtual_scr->first_line;
2152cd2cd8fed	virtual_scr->SCROLL_CLEAR = window->SCROLL_CLEAR;
2153cd2cd8fed	virtual_scr->LX = window->LX + window->SC;
2154cd2cd8fed	virtual_scr->LY = window->LY + window->SR;
2155cd2cd8fed	virtual_scr->scroll_up = window->scroll_up;
2156cd2cd8fed	virtual_scr->scroll_down = window->scroll_down;
2157cd2cd8fed	if ((last_window_refreshed == window) && (!window->SCROLL_CLEAR))
2158cd2cd8fed		return;
2159cd2cd8fed	for (line_counter = 0; line_counter < window->SR; line_counter++)
2160cd2cd8fed	{
2161cd2cd8fed		virtual_line = virtual_line->next_screen;
2162cd2cd8fed	}
2163cd2cd8fed	for (line_counter = 0; (line_counter < window->Num_lines)
2164cd2cd8fed		&& ((line_counter + window->SR) < virtual_scr->Num_lines);
2165cd2cd8fed			line_counter++)
2166cd2cd8fed	{
2167cd2cd8fed		if ((last_window_refreshed != window) || (user_line->changed) || ((SCROLL | CLEAR) & window->SCROLL_CLEAR))
2168cd2cd8fed		{
2169cd2cd8fed			for (user_col = 0, virt_col = window->SC;
2170cd2cd8fed				(virt_col < virtual_scr->Num_cols)
2171cd2cd8fed				  && (user_col < user_line->last_char);
2172cd2cd8fed				  	virt_col++, user_col++)
2173cd2cd8fed			{
2174cd2cd8fed				virtual_line->row[virt_col] = user_line->row[user_col];
2175cd2cd8fed				virtual_line->attributes[virt_col] = user_line->attributes[user_col];
2176cd2cd8fed			}
2177cd2cd8fed			for (user_col = user_line->last_char,
2178cd2cd8fed			     virt_col = window->SC + user_line->last_char;
2179cd2cd8fed				(virt_col < virtual_scr->Num_cols)
2180cd2cd8fed				  && (user_col < window->Num_cols);
2181cd2cd8fed				  	virt_col++, user_col++)
2182cd2cd8fed			{
2183cd2cd8fed				virtual_line->row[virt_col] = ' ';
2184c24192eed				virtual_line->attributes[virt_col] = '\0';
2185cd2cd8fed			}
2186cd2cd8fed		}
2187cd2cd8fed		if (virtual_scr->Num_cols != window->Num_cols)
2188cd2cd8fed		{
2189cd2cd8fed			if (virtual_line->last_char < (user_line->last_char + window->SC))
2190cd2cd8fed			{
2191c24192eed				if (virtual_line->row[virtual_line->last_char] == '\0')
2192cd2cd8fed					virtual_line->row[virtual_line->last_char] = ' ';
2193cd2cd8fed				virtual_line->last_char =
2194cd2cd8fed					min(virtual_scr->Num_cols,
2195cd2cd8fed					  (user_line->last_char + window->SC));
2196cd2cd8fed			}
2197cd2cd8fed		}
2198cd2cd8fed		else
2199cd2cd8fed			virtual_line->last_char = user_line->last_char;
2200c24192eed		virtual_line->row[virtual_line->last_char] = '\0';
2201cd2cd8fed		virtual_line->changed = user_line->changed;
2202cd2cd8fed		virtual_line = virtual_line->next_screen;
2203cd2cd8fed		user_line = user_line->next_screen;
2204cd2cd8fed	}
2205cd2cd8fed	window->SCROLL_CLEAR = FALSE;
2206cd2cd8fed	window->scroll_up = window->scroll_down = 0;
2207cd2cd8fed	last_window_refreshed = window;
2208cd2cd8fed}
2209cd2cd8fed
2210cd2cd8fedvoid
2211cd2cd8fedflushinp()			/* flush input				*/
2212cd2cd8fed{
2213cd2cd8fed}
2214cd2cd8fed
2215cd2cd8fedvoid
2216cd2cd8fedungetch(c)			/* push a character back on input	*/
2217cd2cd8fedint c;
2218cd2cd8fed{
2219cd2cd8fed	if (bufp < 100)
2220cd2cd8fed		in_buff[bufp++] = c;
2221cd2cd8fed}
2222cd2cd8fed
2223cd2cd8fed#ifdef BSD_SELECT
2224cd2cd8fedint
2225cd2cd8fedtimed_getchar()
2226cd2cd8fed{
2227cd2cd8fed	struct timeval tv;
2228cd2cd8fed	fd_set fds;
2229cd2cd8fed	int ret_val;
2230cd2cd8fed	int nfds = 1;
2231cd2cd8fed	char temp;
2232cd2cd8fed
2233cd2cd8fed	FD_ZERO(&fds);
2234cd2cd8fed	tv.tv_sec = 0;
2235cd2cd8fed	tv.tv_usec = 500000;  /* half a second */
2236cd2cd8fed	FD_SET(0, &fds);
2237cd2cd8fed	Time_Out = FALSE; /* just in case */
2238cd2cd8fed
2239cd2cd8fed	ret_val = select(nfds, &fds, 0, 0, &tv);
2240cd2cd8fed
2241cd2cd8fed	/*
2242cd2cd8fed	 |	if ret_val is less than zero, there was no input
2243cd2cd8fed	 |	otherwise, get a character and return it
2244cd2cd8fed	 */
2245cd2cd8fed
2246cd2cd8fed	if (ret_val <= 0)
2247cd2cd8fed	{
2248cd2cd8fed		Time_Out = TRUE;
2249cd2cd8fed		return(-1);
2250cd2cd8fed	}
2251cd2cd8fed
2252cd2cd8fed	return(read(0, &temp, 1)? temp : -1);
2253cd2cd8fed}
2254cd2cd8fed#endif
2255cd2cd8fed
2256cd2cd8fedint
2257cd2cd8fedwgetch(window)			/* get character from specified window	*/
2258cd2cd8fedWINDOW *window;
2259cd2cd8fed{
2260cd2cd8fed	int in_value;
2261cd2cd8fed	char temp;
2262cd2cd8fed#ifndef SYS5
2263cd2cd8fed	int old_arg;
2264cd2cd8fed#endif /* SYS5 */
2265cd2cd8fed
2266cd2cd8fed#ifdef BSD_SELECT
2267cd2cd8fed	if (Noblock)
2268cd2cd8fed		in_value = ((bufp > 0) ? in_buff[--bufp] : timed_getchar());
2269cd2cd8fed	else
2270cd2cd8fed		in_value = ((bufp > 0) ? in_buff[--bufp] : read(0, &temp, 1)? temp : -1);
2271cd2cd8fed#else /* BSD_SELECT */
2272cd2cd8fed#ifdef SYS5
2273cd2cd8fed	in_value = ((bufp > 0) ? in_buff[--bufp] :
2274cd2cd8fed					(read(0, &temp, 1)> 0) ? temp : -1);
2275cd2cd8fed#else /* SYS5 */
2276cd2cd8fed	if (Noblock)
2277cd2cd8fed	{
2278cd2cd8fed		Time_Out = FALSE;
2279cd2cd8fed		old_arg = fcntl(0, F_GETFL, 0);
2280cd2cd8fed		in_value = fcntl(0, F_SETFL, old_arg | FNDELAY);
2281cd2cd8fed	}
2282cd2cd8fed	in_value = ((bufp > 0) ? in_buff[--bufp] : read(0, &temp, 1)? temp : -1);
2283cd2cd8fed	if (Noblock)
2284cd2cd8fed	{
2285cd2cd8fed		fcntl(0, F_SETFL, old_arg);
2286cd2cd8fed		if (Time_Out)
2287cd2cd8fed			in_value = -1;
2288cd2cd8fed	}
2289cd2cd8fed#endif /* SYS5 */
2290cd2cd8fed#endif /* BSD_SELECT */
2291cd2cd8fed
2292cd2cd8fed	if (in_value != -1)
2293cd2cd8fed	{
2294cd2cd8fed		in_value &= 0xff;
2295cd2cd8fed		if ((Parity) && (Num_bits < 8))
2296cd2cd8fed				/* strip eighth bit if parity in use */
2297cd2cd8fed		in_value &= 0177;
2298cd2cd8fed	}
2299cd2cd8fed	else if (interrupt_flag)
2300cd2cd8fed	{
2301cd2cd8fed		interrupt_flag = FALSE;
2302cd2cd8fed		in_value = wgetch(window);
2303cd2cd8fed	}
2304cd2cd8fed
2305cd2cd8fed	if ((in_value == '\033') || (in_value == '\037'))/* escape character */
2306cd2cd8fed		in_value = Get_key(in_value);
2307cd2cd8fed	return(in_value);
2308cd2cd8fed}
2309cd2cd8fed
2310cd2cd8fed#ifndef BSD_SELECT
2311cd2cd8fedvoid
2312cd2cd8fedClear(arg)		/* notify that time out has occurred	*/
2313cd2cd8fedint arg;
2314cd2cd8fed{
2315cd2cd8fed	Time_Out = TRUE;
2316cd2cd8fed#ifdef DEBUG
2317cd2cd8fedfprintf(stderr, "inside Clear()\n");
2318cd2cd8fedfflush(stderr);
2319cd2cd8fed#endif /* DEBUG */
2320cd2cd8fed}
2321cd2cd8fed#endif /* BSD_SELECT */
2322cd2cd8fed
2323cd2cd8fedint
2324cd2cd8fedGet_key(first_char)			/* try to decode key sequence	*/
2325cd2cd8fedint first_char;				/* first character of sequence	*/
2326cd2cd8fed{
2327cd2cd8fed	int in_char;
2328cd2cd8fed	int Count;
2329cd2cd8fed	char string[128];
2330cd2cd8fed	char *Gtemp;
2331cd2cd8fed	int Found;
2332cd2cd8fed#ifdef SYS5
2333cd2cd8fed	struct termio Gterminal;
2334cd2cd8fed#else
2335cd2cd8fed	struct sgttyb Gterminal;
2336cd2cd8fed#endif
2337cd2cd8fed	struct KEY_STACK *St_point;
2338cd2cd8fed#if (!defined( BSD_SELECT)) || (!defined(SYS5))
2339cd2cd8fed	int value;
2340cd2cd8fed#endif /* BSD_SELECT */
2341cd2cd8fed
2342cd2cd8fed	Count = 0;
2343cd2cd8fed	Gtemp = string;
2344cd2cd8fed	string[Count++] = first_char;
2345c24192eed	string[Count] = '\0';
2346cd2cd8fed	Time_Out = FALSE;
2347cd2cd8fed#ifndef BSD_SELECT
2348cd2cd8fed	signal(SIGALRM, Clear);
2349cd2cd8fed	value = alarm(1);
2350cd2cd8fed#endif /* BSD_SELECT */
2351cd2cd8fed	Noblock = TRUE;
2352cd2cd8fed#ifdef SYS5
2353cd2cd8fed	Gterminal.c_cc[VTIME] = 0;		/* timeout value	*/
2354cd2cd8fed	Gterminal.c_lflag &= ~ICANON;	/* disable canonical operation	*/
2355cd2cd8fed	Gterminal.c_lflag &= ~ECHO;		/* disable echo		*/
2356cd2cd8fed#endif
2357cd2cd8fed	Count = 1;
2358cd2cd8fed	Found = FALSE;
2359cd2cd8fed	while ((Count < Max_Key_len) && (!Time_Out) && (!Found))
2360cd2cd8fed	{
2361cd2cd8fed		in_char = wgetch(stdscr);
2362cd2cd8fed#ifdef DEBUG
2363cd2cd8fedfprintf(stderr, "back in GetKey()\n");
2364cd2cd8fedfflush(stderr);
2365cd2cd8fed#endif /* DEBUG */
2366cd2cd8fed		if (in_char != -1)
2367cd2cd8fed		{
2368cd2cd8fed			string[Count++] = in_char;
2369c24192eed			string[Count] = '\0';
2370cd2cd8fed			St_point = KEY_TOS;
2371cd2cd8fed			while ((St_point != NULL) && (!Found))
2372cd2cd8fed			{
2373cd2cd8fed				if (!strcmp(string, St_point->element->string))
2374cd2cd8fed					Found = TRUE;
2375cd2cd8fed				else
2376cd2cd8fed					St_point = St_point->next;
2377cd2cd8fed			}
2378cd2cd8fed		}
2379cd2cd8fed	}
2380cd2cd8fed#ifndef BSD_SELECT
2381cd2cd8fed	if (!Time_Out)
2382cd2cd8fed		value = alarm(0);
2383cd2cd8fed#endif /* BSD_SELECT */
2384cd2cd8fed#ifdef SYS5
2385cd2cd8fed/*	value = ioctl(0, TCSETA, &Terminal);*/
2386cd2cd8fed#else
2387cd2cd8fed	value = ioctl(0, TIOCSETP, &Terminal);
2388cd2cd8fed/*	value = fcntl(0, F_SETFL, old_arg);*/
2389cd2cd8fed#endif
2390cd2cd8fed	Noblock = FALSE;
2391cd2cd8fed	if (Found)
2392cd2cd8fed	{
2393cd2cd8fed		return(St_point->element->value);
2394cd2cd8fed	}
2395cd2cd8fed	else
2396cd2cd8fed	{
2397cd2cd8fed		while (Count > 1)
2398cd2cd8fed		{
2399cd2cd8fed			if ((string[--Count] != -1) &&
2400cd2cd8fed					((unsigned char) (string[Count]) != 255))
2401cd2cd8fed			{
2402cd2cd8fed#ifdef DIAG
2403cd2cd8fedfprintf(stderr, "ungetting character %d\n", string[Count]);fflush(stdout);
2404cd2cd8fed#endif
2405cd2cd8fed				ungetch(string[Count]);
2406cd2cd8fed			}
2407cd2cd8fed		}
2408cd2cd8fed		return(first_char);
2409cd2cd8fed	}
2410cd2cd8fed}
2411cd2cd8fed
2412cd2cd8fedvoid
2413cd2cd8fedwaddch(window, c)	/* output the character in the specified window	*/
2414cd2cd8fedWINDOW *window;
2415cd2cd8fedint c;
2416cd2cd8fed{
2417cd2cd8fed	int column, j;
2418cd2cd8fed	int shift;	/* number of spaces to shift if a tab		*/
2419cd2cd8fed	struct _line *tmpline;
2420cd2cd8fed
2421cd2cd8fed#ifdef DIAG
2422cd2cd8fed/*printf("starting waddch \n");fflush(stdout);*/
2423cd2cd8fed#endif
2424cd2cd8fed	column = window->LX;
2425cd2cd8fed	if (c == '\t')
2426cd2cd8fed	{
2427cd2cd8fed		shift = (column + 1) % 8;
2428cd2cd8fed		if (shift == 0)
2429cd2cd8fed			shift++;
2430cd2cd8fed		else
2431cd2cd8fed			shift = 9 - shift;
2432cd2cd8fed		while (shift > 0)
2433cd2cd8fed		{
2434cd2cd8fed			shift--;
2435cd2cd8fed			waddch(window, ' ');
2436cd2cd8fed		}
2437cd2cd8fed	}
2438cd2cd8fed	else if ((column < window->Num_cols) && (window->LY < window->Num_lines))
2439cd2cd8fed	{
2440cd2cd8fed		if ((c == '~') && (Booleans[hz__]))
2441cd2cd8fed			c = '@';
2442cd2cd8fed
2443cd2cd8fed		if (( c != '\b') && (c != '\n') && (c != '\r'))
2444cd2cd8fed		{
2445cd2cd8fed			tmpline = window->line_array[window->LY];
2446cd2cd8fed			tmpline->row[column] = c;
2447cd2cd8fed			tmpline->attributes[column] = window->Attrib;
2448cd2cd8fed			tmpline->changed = TRUE;
2449cd2cd8fed			if (column >= tmpline->last_char)
2450cd2cd8fed			{
2451cd2cd8fed				if (column > tmpline->last_char)
2452cd2cd8fed					for (j = tmpline->last_char; j < column; j++)
2453cd2cd8fed					{
2454cd2cd8fed						tmpline->row[j] = ' ';
2455c24192eed						tmpline->attributes[j] = '\0';
2456cd2cd8fed					}
2457c24192eed				tmpline->row[column + 1] = '\0';
2458c24192eed				tmpline->attributes[column + 1] = '\0';
2459cd2cd8fed				tmpline->last_char = column + 1;
2460cd2cd8fed			}
2461cd2cd8fed		}
2462cd2cd8fed		if (c == '\n')
2463cd2cd8fed		{
2464cd2cd8fed			wclrtoeol(window);
2465cd2cd8fed			window->LX = window->Num_cols;
2466cd2cd8fed		}
2467cd2cd8fed		else if (c == '\r')
2468cd2cd8fed			window->LX = 0;
2469cd2cd8fed		else if (c == '\b')
2470cd2cd8fed			window->LX--;
2471cd2cd8fed		else
2472cd2cd8fed			window->LX++;
2473cd2cd8fed	}
2474cd2cd8fed	if (window->LX >= window->Num_cols)
2475cd2cd8fed	{
2476cd2cd8fed		window->LX = 0;
2477cd2cd8fed		window->LY++;
2478cd2cd8fed		if (window->LY >= window->Num_lines)
2479cd2cd8fed		{
2480cd2cd8fed			window->LY = window->Num_lines - 1;
2481cd2cd8fed/*			window->LY = row;
2482cd2cd8fed			wmove(window, 0, 0);
2483cd2cd8fed			wdeleteln(window);
2484cd2cd8fed			wmove(window, row, 0);*/
2485cd2cd8fed		}
2486cd2cd8fed	}
2487cd2cd8fed	window->SCROLL_CLEAR = CHANGE;
2488cd2cd8fed}
2489cd2cd8fed
2490cd2cd8fedvoid
2491cd2cd8fedwinsertln(window)	/* insert a blank line into the specified window */
2492cd2cd8fedWINDOW *window;
2493cd2cd8fed{
2494cd2cd8fed	int row, column;
2495cd2cd8fed	struct _line *tmp;
2496cd2cd8fed	struct _line *tmp1;
2497cd2cd8fed
2498cd2cd8fed	window->scroll_down += 1;
2499cd2cd8fed	window->SCROLL_CLEAR = SCROLL;
2500cd2cd8fed	column = window->LX;
2501cd2cd8fed	row = window->LY;
2502cd2cd8fed	for (row = 0, tmp = window->first_line; (row < window->Num_lines) && (tmp->next_screen != NULL); row++)
2503cd2cd8fed		tmp = tmp->next_screen;
2504cd2cd8fed	if (tmp->prev_screen != NULL)
2505cd2cd8fed		tmp->prev_screen->next_screen = NULL;
2506cd2cd8fed	tmp1 = tmp;
2507cd2cd8fed	clear_line(tmp1, 0, window->Num_cols);
2508cd2cd8fed	tmp1->number = -1;
2509cd2cd8fed	for (row = 0, tmp = window->first_line; (row < window->LY) && (tmp->next_screen != NULL); row++)
2510cd2cd8fed		tmp = tmp->next_screen;
2511cd2cd8fed	if ((window->LY == (window->Num_lines - 1)) && (window->Num_lines > 1))
2512cd2cd8fed	{
2513cd2cd8fed		tmp1->next_screen = tmp->next_screen;
2514cd2cd8fed		tmp->next_screen = tmp1;
2515cd2cd8fed		tmp->changed = TRUE;
2516cd2cd8fed		tmp->next_screen->prev_screen = tmp;
2517cd2cd8fed	}
2518cd2cd8fed	else if (window->Num_lines > 1)
2519cd2cd8fed	{
2520cd2cd8fed		if (tmp->prev_screen != NULL)
2521cd2cd8fed			tmp->prev_screen->next_screen = tmp1;
2522cd2cd8fed		tmp1->prev_screen = tmp->prev_screen;
2523cd2cd8fed		tmp->prev_screen = tmp1;
2524cd2cd8fed		tmp1->next_screen = tmp;
2525cd2cd8fed		tmp->changed = TRUE;
2526cd2cd8fed		tmp->scroll = DOWN;
2527cd2cd8fed	}
2528cd2cd8fed	if (window->LY == 0)
2529cd2cd8fed		window->first_line = tmp1;
2530cd2cd8fed
2531cd2cd8fed	for (row = 0, tmp1 = window->first_line;
2532cd2cd8fed		row < window->Num_lines; row++)
2533cd2cd8fed	{
2534cd2cd8fed		window->line_array[row] = tmp1;
2535cd2cd8fed		tmp1 = tmp1->next_screen;
2536cd2cd8fed	}
2537cd2cd8fed}
2538cd2cd8fed
2539cd2cd8fedvoid
2540cd2cd8fedwdeleteln(window)	/* delete a line in the specified window */
2541cd2cd8fedWINDOW *window;
2542cd2cd8fed{
2543cd2cd8fed	int row, column;
2544cd2cd8fed	struct _line *tmp;
2545cd2cd8fed	struct _line  *tmpline;
2546cd2cd8fed
2547cd2cd8fed	if (window->Num_lines > 1)
2548cd2cd8fed	{
2549cd2cd8fed		window->scroll_up += 1;
2550cd2cd8fed		window->SCROLL_CLEAR = SCROLL;
2551cd2cd8fed		column = window->LX;
2552cd2cd8fed		row = window->LY;
2553cd2cd8fed		for (row = 0, tmp = window->first_line; row < window->LY; row++)
2554cd2cd8fed			tmp = tmp->next_screen;
2555cd2cd8fed		if (window->LY == 0)
2556cd2cd8fed			window->first_line = tmp->next_screen;
2557cd2cd8fed		if (tmp->prev_screen != NULL)
2558cd2cd8fed			tmp->prev_screen->next_screen = tmp->next_screen;
2559cd2cd8fed		if (tmp->next_screen != NULL)
2560cd2cd8fed		{
2561cd2cd8fed			tmp->next_screen->changed = TRUE;
2562cd2cd8fed			tmp->next_screen->scroll = UP;
2563cd2cd8fed			tmp->next_screen->prev_screen = tmp->prev_screen;
2564cd2cd8fed		}
2565cd2cd8fed		tmpline = tmp;
2566cd2cd8fed		clear_line(tmpline, 0, window->Num_cols);
2567cd2cd8fed		tmpline->number = -1;
2568cd2cd8fed		for (row = 0, tmp = window->first_line; tmp->next_screen != NULL; row++)
2569cd2cd8fed			tmp = tmp->next_screen;
2570cd2cd8fed		if (tmp != NULL)
2571cd2cd8fed		{
2572cd2cd8fed			tmp->next_screen = tmpline;
2573cd2cd8fed			tmp->next_screen->prev_screen = tmp;
2574cd2cd8fed			tmp->changed = TRUE;
2575cd2cd8fed			tmp = tmp->next_screen;
2576cd2cd8fed		}
2577cd2cd8fed		else
2578cd2cd8fed			tmp = tmpline;
2579cd2cd8fed		tmp->next_screen = NULL;
2580cd2cd8fed
2581cd2cd8fed		for (row = 0, tmp = window->first_line; row < window->Num_lines; row++)
2582cd2cd8fed		{
2583cd2cd8fed			window->line_array[row] = tmp;
2584cd2cd8fed			tmp = tmp->next_screen;
2585cd2cd8fed		}
2586cd2cd8fed	}
2587cd2cd8fed	else
2588cd2cd8fed	{
2589cd2cd8fed		clear_line(window->first_line, 0, window->Num_cols);
2590cd2cd8fed	}
2591cd2cd8fed}
2592cd2cd8fed
2593cd2cd8fedvoid
2594cd2cd8fedwclrtobot(window)	/* delete from current position to end of the window */
2595cd2cd8fedWINDOW *window;
2596cd2cd8fed{
2597cd2cd8fed	int row, column;
2598cd2cd8fed	struct _line *tmp;
2599cd2cd8fed
2600cd2cd8fed	window->SCROLL_CLEAR |= CLEAR;
2601cd2cd8fed	column = window->LX;
2602cd2cd8fed	row = window->LY;
2603cd2cd8fed	for (row = 0, tmp = window->first_line; row < window->LY; row++)
2604cd2cd8fed		tmp = tmp->next_screen;
2605cd2cd8fed	clear_line(tmp, column, window->Num_cols);
2606cd2cd8fed	for (row = (window->LY + 1); row < window->Num_lines; row++)
2607cd2cd8fed	{
2608cd2cd8fed		tmp = tmp->next_screen;
2609cd2cd8fed		clear_line(tmp, 0, window->Num_cols);
2610cd2cd8fed	}
2611cd2cd8fed	wmove(window, row, column);
2612cd2cd8fed}
2613cd2cd8fed
2614cd2cd8fedvoid
2615cd2cd8fedwstandout(window)	/* begin standout mode in window	*/
2616cd2cd8fedWINDOW *window;
2617cd2cd8fed{
2618cd2cd8fed	if (Numbers[sg__] < 1)	/* if not magic cookie glitch	*/
2619cd2cd8fed		window->Attrib |= A_STANDOUT;
2620cd2cd8fed}
2621cd2cd8fed
2622cd2cd8fedvoid
2623cd2cd8fedwstandend(window)	/* end standout mode in window	*/
2624cd2cd8fedWINDOW *window;
2625cd2cd8fed{
2626cd2cd8fed	window->Attrib &= ~A_STANDOUT;
2627cd2cd8fed}
2628cd2cd8fed
2629cd2cd8fedvoid
2630cd2cd8fedwaddstr(window, string)	/* write 'string' in window	*/
2631cd2cd8fedWINDOW *window;
2632cd2cd8fedchar *string;
2633cd2cd8fed{
2634cd2cd8fed	char *wstring;
2635cd2cd8fed
2636c24192eed	for (wstring = string; *wstring != '\0'; wstring++)
2637cd2cd8fed		waddch(window, *wstring);
2638cd2cd8fed}
2639cd2cd8fed
2640cd2cd8fedvoid
2641cd2cd8fedclearok(window, flag)	/* erase screen and redraw at next refresh	*/
2642cd2cd8fedWINDOW *window;
2643cd2cd8fedint flag;
2644cd2cd8fed{
2645cd2cd8fed	Repaint_screen = TRUE;
2646cd2cd8fed}
2647cd2cd8fed
2648cd2cd8fed
2649cd2cd8fedvoid
2650cd2cd8fedecho()			/* turn on echoing				*/
2651cd2cd8fed{
2652cd2cd8fed	int value;
2653cd2cd8fed
2654cd2cd8fed#ifdef SYS5
2655cd2cd8fed	Terminal.c_lflag |= ECHO;		/* enable echo		*/
2656cd2cd8fed	value = ioctl(0, TCSETA, &Terminal);	/* set characteristics	*/
2657cd2cd8fed#else
2658cd2cd8fed	Terminal.sg_flags |= ECHO;		/* enable echo		*/
2659cd2cd8fed	value = ioctl(0, TIOCSETP, &Terminal);	/* set characteristics	*/
2660cd2cd8fed#endif
2661cd2cd8fed}
2662cd2cd8fed
2663cd2cd8fedvoid
2664cd2cd8fednoecho()		/* turn off echoing				*/
2665cd2cd8fed{
2666cd2cd8fed	int value;
2667cd2cd8fed
2668cd2cd8fed#ifdef SYS5
2669cd2cd8fed	Terminal.c_lflag &= ~ECHO;		/* disable echo		*/
2670cd2cd8fed	value = ioctl(0, TCSETA, &Terminal);	/* set characteristics	*/
2671cd2cd8fed#else
2672cd2cd8fed	Terminal.sg_flags &= ~ECHO;		/* disable echo		*/
2673cd2cd8fed	value = ioctl(0, TIOCSETP, &Terminal);	/* set characteristics	*/
2674cd2cd8fed#endif
2675cd2cd8fed}
2676cd2cd8fed
2677cd2cd8fedvoid
2678cd2cd8fedraw()			/* set to read characters immediately		*/
2679cd2cd8fed{
2680cd2cd8fed	int value;
2681cd2cd8fed
2682cd2cd8fed#ifdef SYS5
2683cd2cd8fed	Intr = Terminal.c_cc[VINTR];	/* get the interrupt character	*/
2684cd2cd8fed	Terminal.c_lflag &= ~ICANON;	/* disable canonical operation	*/
2685cd2cd8fed	Terminal.c_lflag &= ~ISIG;	/* disable signal checking	*/
2686cd2cd8fed#ifdef FLUSHO
2687cd2cd8fed	Terminal.c_lflag &= ~FLUSHO;
2688cd2cd8fed#endif
2689cd2cd8fed#ifdef PENDIN
2690cd2cd8fed	Terminal.c_lflag &= ~PENDIN;
2691cd2cd8fed#endif
2692cd2cd8fed#ifdef IEXTEN
2693cd2cd8fed	Terminal.c_lflag &= ~IEXTEN;
2694cd2cd8fed#endif
2695cd2cd8fed	Terminal.c_cc[VMIN] = 1;		/* minimum of one character */
2696cd2cd8fed	Terminal.c_cc[VTIME] = 0;		/* timeout value	*/
2697cd2cd8fed	Terminal.c_cc[VINTR] = 0;		/* eliminate interrupt	*/
2698cd2cd8fed	value = ioctl(0, TCSETA, &Terminal);	/* set characteristics	*/
2699cd2cd8fed#else
2700cd2cd8fed	Terminal.sg_flags |= RAW;	/* enable raw mode		*/
2701cd2cd8fed	value = ioctl(0, TIOCSETP, &Terminal);	/* set characteristics	*/
2702cd2cd8fed#endif
2703cd2cd8fed}
2704cd2cd8fed
2705cd2cd8fedvoid
2706cd2cd8fednoraw()			/* set to normal character read mode		*/
2707cd2cd8fed{
2708cd2cd8fed	int value;
2709cd2cd8fed
2710cd2cd8fed#ifdef SYS5
2711cd2cd8fed	Terminal.c_lflag |= ICANON;	/* enable canonical operation	*/
2712cd2cd8fed	Terminal.c_lflag |= ISIG;	/* enable signal checking	*/
2713cd2cd8fed	Terminal.c_cc[VEOF] = 4;		/* EOF character = 4	*/
2714c24192eed	Terminal.c_cc[VEOL] = '\0';	/* EOL = 0		*/
2715cd2cd8fed	Terminal.c_cc[VINTR] = Intr;		/* reset interrupt char	*/
2716cd2cd8fed	value = ioctl(0, TCSETA, &Terminal);	/* set characteristics	*/
2717cd2cd8fed#else
2718cd2cd8fed	Terminal.sg_flags &= ~RAW;	/* disable raw mode		*/
2719cd2cd8fed	value = ioctl(0, TIOCSETP, &Terminal);	/* set characteristics	*/
2720cd2cd8fed/*	old_arg = fcntl(0, F_GETFL, 0);
2721cd2cd8fed	value = fcntl(0, F_SETFL, old_arg & ~FNDELAY);*/
2722cd2cd8fed#endif
2723cd2cd8fed}
2724cd2cd8fed
2725cd2cd8fedvoid
2726cd2cd8fednl()
2727cd2cd8fed{
2728cd2cd8fed	int value;
2729cd2cd8fed
2730cd2cd8fed#ifdef SYS5
2731cd2cd8fed	Terminal.c_iflag |= ICRNL;	/* enable carriage-return to line-feed mapping	*/
2732cd2cd8fed	value = ioctl(0, TCSETA, &Terminal);	/* set characteristics	*/
2733cd2cd8fed#endif
2734cd2cd8fed}
2735cd2cd8fed
2736cd2cd8fedvoid
2737cd2cd8fednonl()
2738cd2cd8fed{
2739cd2cd8fed	int value;
2740cd2cd8fed
2741cd2cd8fed#ifdef SYS5
2742cd2cd8fed	Terminal.c_iflag &= ~ICRNL;	/* disable carriage-return to line-feed mapping	*/
2743cd2cd8fed	Terminal.c_iflag &= ~IGNCR;	/* do not ignore carriage-return	*/
2744cd2cd8fed	value = ioctl(0, TCSETA, &Terminal);	/* set characteristics	*/
2745cd2cd8fed#endif
2746cd2cd8fed}
2747cd2cd8fed
2748cd2cd8fedvoid
2749cd2cd8fedsaveterm()
2750cd2cd8fed{
2751cd2cd8fed}
2752cd2cd8fed
2753cd2cd8fedvoid
2754cd2cd8fedfixterm()
2755cd2cd8fed{
2756cd2cd8fed}
2757cd2cd8fed
2758cd2cd8fedvoid
2759cd2cd8fedresetterm()
2760cd2cd8fed{
2761cd2cd8fed}
2762cd2cd8fed
2763cd2cd8fedvoid
2764cd2cd8fednodelay(window, flag)
2765cd2cd8fedWINDOW *window;
2766cd2cd8fedint flag;
2767cd2cd8fed{
2768cd2cd8fed}
2769cd2cd8fed
2770cd2cd8fedvoid
2771cd2cd8fedidlok(window, flag)
2772cd2cd8fedWINDOW *window;
2773cd2cd8fedint flag;
2774cd2cd8fed{
2775cd2cd8fed}
2776cd2cd8fed
2777cd2cd8fedvoid
2778cd2cd8fedkeypad(window, flag)
2779cd2cd8fedWINDOW *window;
2780cd2cd8fedint flag;
2781cd2cd8fed{
2782cd2cd8fed	if (flag)
2783cd2cd8fed		String_Out(String_table[ks__], NULL, 0);
2784cd2cd8fed	else
2785cd2cd8fed		String_Out(String_table[ke__], NULL, 0);
2786cd2cd8fed}
2787cd2cd8fed
2788cd2cd8fedvoid
2789cd2cd8fedsavetty()		/* save current tty stats			*/
2790cd2cd8fed{
2791cd2cd8fed	int value;
2792cd2cd8fed
2793cd2cd8fed#ifdef SYS5
2794cd2cd8fed	value = ioctl(0, TCGETA, &Saved_tty);	/* set characteristics	*/
2795cd2cd8fed#else
2796cd2cd8fed	value = ioctl(0, TIOCGETP, &Saved_tty);	/* set characteristics	*/
2797cd2cd8fed#endif
2798cd2cd8fed}
2799cd2cd8fed
2800cd2cd8fedvoid
2801cd2cd8fedresetty()		/* restore previous tty stats			*/
2802cd2cd8fed{
2803cd2cd8fed	int value;
2804cd2cd8fed
2805cd2cd8fed#ifdef SYS5
2806cd2cd8fed	value = ioctl(0, TCSETA, &Saved_tty);	/* set characteristics	*/
2807cd2cd8fed#else
2808cd2cd8fed	value = ioctl(0, TIOCSETP, &Saved_tty);	/* set characteristics	*/
2809cd2cd8fed#endif
2810cd2cd8fed}
2811cd2cd8fed
2812cd2cd8fedvoid
2813cd2cd8fedendwin()		/* end windows					*/
2814cd2cd8fed{
2815cd2cd8fed	keypad(stdscr, FALSE);
2816cd2cd8fed	initialized = FALSE;
2817cd2cd8fed	delwin(curscr);
2818cd2cd8fed	delwin(virtual_scr);
2819cd2cd8fed	delwin(stdscr);
2820cd2cd8fed#ifndef SYS5
2821cd2cd8fed{
2822cd2cd8fed	int old_arg, value;
2823cd2cd8fed/*	old_arg = fcntl(0, F_GETFL, 0);
2824cd2cd8fed	value = fcntl(0, F_SETFL, old_arg & ~FNDELAY);*/
2825cd2cd8fed}
2826cd2cd8fed#endif
2827cd2cd8fed}
2828cd2cd8fed
2829cd2cd8fedvoid
2830cd2cd8feddelwin(window)		/* delete the window structure			*/
2831cd2cd8fedWINDOW *window;
2832cd2cd8fed{
2833cd2cd8fed	int i;
2834cd2cd8fed
2835cd2cd8fed	for (i = 1; (i < window->Num_lines) && (window->first_line->next_screen != NULL); i++)
2836cd2cd8fed	{
2837cd2cd8fed		window->first_line = window->first_line->next_screen;
2838cd2cd8fed		free(window->first_line->prev_screen->row);
2839cd2cd8fed		free(window->first_line->prev_screen->attributes);
2840cd2cd8fed		free(window->first_line->prev_screen);
2841cd2cd8fed	}
2842cd2cd8f