-
Notifications
You must be signed in to change notification settings - Fork 5
/
tpreds.pl
151 lines (122 loc) · 4.04 KB
/
tpreds.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/****************************************************************/
/* This module includes some routines which are used in nearly */
/* all menu and screen tools. */
/****************************************************************/
/****************************************************************/
/* repeat */
/****************************************************************/
% repeat.
% repeat:-repeat.
/****************************************************************/
/* miscellaneous */
/****************************************************************/
maxlen([H|T],MAX,MAX1) :-
str_len(H,LENGTH),
LENGTH>MAX,!,
maxlen(T,LENGTH,MAX1).
maxlen([_|T],MAX,MAX1) :- maxlen(T,MAX,MAX1).
maxlen([],LENGTH,LENGTH).
listlen([],0).
listlen([_|T],N):-
listlen(T,X),
N is X+1.
writelist(_,_,[]).
writelist(LI,ANTKOL,[H|T]):-
field_str(LI,0,ANTKOL,H),
LI1 is LI+1,
writelist(LI1,ANTKOL,T).
min(X,Y,X):-X=<Y,!.
min(_,X,X).
max(X,Y,X):-X>=Y,!.
max(_,X,X).
reverseattr(A1,A2):-
bitand(A1,$07,H11),
bitleft(H11,4,H12),
bitand(A1,$70,H21),
bitright(H21,4,H22),
bitand(A1,$08,H31),
A2 is H12+H22+H31.
/****************************************************************/
/* Find letter selection in a list of strings */
/* Look initially for first uppercase letter. */
/* Then try with first letter of each string. */
/****************************************************************/
/*
upc(CHAR,CH):-
CHAR>='a',CHAR=<'z',!,
char_int(CHAR,CI), CI1 is CI-32, char_int(CH,CI1).
upc(CH,CH).
lowc(CHAR,CH):-
CHAR>='A',CHAR=<'Z',!,
char_int(CHAR,CI), CI1 is CI+32, char_int(CH,CI1).
lowc(CH,CH).
try_upper(CHAR,STRING):-
frontchar(STRING,CH,_),
CH>='A',CH=<'Z',!,
CH=CHAR.
try_upper(CHAR,STRING):-
frontchar(STRING,_,REST),
try_upper(CHAR,REST).
tryfirstupper(CHAR,[W|_],N,N) :-
try_upper(CHAR,W),!.
tryfirstupper(CHAR,[_|T],N1,N2) :-
N3 is N1+1,
tryfirstupper(CHAR,T,N3,N2).
tryfirstletter(CHAR,[W|_],N,N) :-
frontchar(W,CHAR,_),!.
tryfirstletter(CHAR,[_|T],N1,N2) :-
N3 is N1+1,
tryfirstletter(CHAR,T,N3,N2).
tryletter(CHAR,LIST,SELECTION):-
upc(CHAR,CH),tryfirstupper(CH,LIST,0,SELECTION),!.
tryletter(CHAR,LIST,SELECTION):-
lowc(CHAR,CH),tryfirstletter(CH,LIST,0,SELECTION).
*/
/*****************************************************************/
/* adjustwindow takes a windowstart and a windowsize and adjusts */
/* the windowstart so the window can be placed on the screen. */
/* adjframe looks at the frameattribute: if it is different from */
/* zero, two is added to the size of the window */
/****************************************************************/
adjustwindow(LI,KOL,DLI,DKOL,ALI,AKOL):-
LI<25-DLI,KOL<80-DKOL,!,ALI=LI,AKOL=KOL.
adjustwindow(LI,_,DLI,DKOL,ALI,AKOL):-
LI<25-DLI,!,ALI=LI,AKOL is 80-DKOL.
adjustwindow(_,KOL,DLI,DKOL,ALI,AKOL):-
KOL<80-DKOL,!,ALI is 25-DLI, AKOL=KOL.
adjustwindow(_,_,DLI,DKOL,ALI,AKOL):-
ALI is 25-DLI, AKOL is 80-DKOL.
adjframe(0,R,C,R,C):-!.
adjframe(_,R1,C1,R2,C2):-R2 is R1+2, C2 is C1+2.
/****************************************************************/
/* Readkey */
/* Returns a symbolic key from the KEY domain */
/****************************************************************/
readkey(KEY):-readchar(T),char_int(T,VAL),readkey1(KEY,T,VAL).
readkey1(KEY,_,0):-!,readchar(T),char_int(T,VAL),readkey2(KEY,VAL).
readkey1(cr,_,13):-!.
readkey1(esc,_,27):-!.
readkey1(break,_,3):-!.
readkey1(tab,_,9):-!.
readkey1(bdel,_,8):-!.
readkey1(ctrlbdel,_,127):-!.
readkey1(char(T),T,_) .
readkey2(btab,15):-!.
readkey2(del,83):-!.
readkey2(ins,82):-!.
readkey2(up,72):-!.
readkey2(down,80):-!.
readkey2(left,75):-!.
readkey2(right,77):-!.
readkey2(pgup,73):-!.
readkey2(pgdn,81):-!.
readkey2(end,79):-!.
readkey2(home,71):-!.
readkey2(ctrlleft,115):-!.
readkey2(ctrlright,116):-!.
readkey2(ctrlend,117):-!.
readkey2(ctrlpgdn,118):-!.
readkey2(ctrlhome,119):-!.
readkey2(ctrlpgup,132):-!.
readkey2(fkey(N),VAL):- VAL>58, VAL<70, N is VAL-58, !.
readkey2(otherspec,_).