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
|
include "../curses.h"
include "promptfn.h"
# PROMPTFN -- Function that processes the prompt input
procedure promptfn (win, ch, maxch, str, data, done)
int win # i: Window descriptor
int ch # i: Keyboard character
int maxch # i: Maximum line length
char str[ARB] # io: String containing line
pointer data # io: Line data structure
bool done # o: Flag indicating line is done
#--
int nrows, ncols, ic, jc, nc
int strlen()
begin
# Check for carriage return
if (ch == '\r') {
done = true
return
} else {
done = false
}
# Initialize data structure on first pass through
if (PR_START(data) == YES) {
call wdimen (win, nrows, ncols)
if (nrows == 1)
call werase (win)
PR_START(data) = NO
PR_ROW(data) = min (2, nrows)
PR_COL(data) = 1
}
if (ch < K_BASE) {
ic = PR_COL(data)
if (str[ic] == EOS) {
if (ic <= maxch) {
str[ic] = ch
str[ic+1] = EOS
call waddstr (win, str[ic])
}
} else {
nc = strlen (str)
if (nc < maxch) {
do jc = nc+1, ic, -1
str[jc+1] = str[jc]
str[ic] = ch
call winsch (win, str[ic])
}
}
PR_COL(data) = PR_COL(data) + 1
} else {
ic = PR_COL(data)
switch (ch) {
case K_RIGHT: # Move right one column
if (str[ic] != EOS) {
PR_COL(data) = PR_COL(data) + 1
call wmove (win, PR_ROW(data), PR_COL(data))
}
case K_LEFT: # Move left one column
if (ic != 1) {
PR_COL(data) = PR_COL(data) - 1
call wmove (win, PR_ROW(data), PR_COL(data))
}
case K_BOL: # Move to first column in line
if (ic > 1) {
PR_COL(data) = 1
call wmove (win, PR_ROW(data), PR_COL(data))
}
case K_EOL: # Move to last column in line
if (str[ic] != EOS) {
PR_COL(data) = strlen (str) + 1
call wmove (win, PR_ROW(data), PR_COL(data))
}
case K_DEL: # Delete character underneath cursor
if (str[ic] != EOS) {
while (str[ic] != EOS) {
str[ic] = str[ic+1]
ic = ic + 1
}
call wdelch (win)
}
case K_BS: # Delete character to left of cursor
if (ic > 1) {
PR_COL(data) = PR_COL(data) - 1
ic = ic - 1
while (str[ic] != EOS) {
str[ic] = str[ic+1]
ic = ic + 1
}
call wmove (win, PR_ROW(data), PR_COL(data))
call wdelch (win)
}
case K_DWORD: # Delete entire line
if (str[1] != EOS) {
PR_COL(data) = 1
for (ic = 1; str[ic] != EOS; ic = ic + 1)
str[ic] = ' '
call addstr (win, str)
str[1] = EOS
}
case K_HELP: # Display help screen
call fm_help
case K_PAINT: # Redraw the screen
call clearok (STDSCR, true)
call wrefresh (STDSCR)
call wmove (win, PR_ROW(data), PR_COL(data))
default:
call ps_beep
}
}
end
|