aboutsummaryrefslogtreecommitdiff
path: root/pkg/utilities/nttools/tedit/display/screen/kconvert.x
blob: 11e283fa2fd95f833e85ad41e55a3a9b9fbbbb97 (plain) (blame)
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
include	<ctype.h>

# K_CONVERT -- Convert a string with coded escape sequences to the real thing
#
# B.Simon	23-Jan-89	Original

procedure k_convert (escstr, escseq, maxch)

char	escstr[ARB]	# i: Escape sequence string
char	escseq[ARB]	# o: Escape key sequence
int	maxch		# i: Declared length of key sequence
#--
int	ic, jc, index, num

string	echars  "befnrt"
string	ecodes  "\010\033\f\n\r\t"

int	stridx()

begin
	ic = 1
	for (jc = 1; jc <= maxch; jc = jc + 1) {

	    # Exit when all characters in escape string have been processed

	    if (escstr[ic] == EOS)
		break

	    # Convert escape sequence

	    if (escstr[ic] == '\\') {
		ic = ic + 1
		index = stridx (escstr[ic], echars)
		if (index > 0) {
		    escseq[jc] = ecodes[index]
		} else if (IS_DIGIT(escstr[ic])) {
		    for (num = 0; IS_DIGIT(escstr[ic]); ic = ic + 1)
			num = 8 * num + TO_DIGIT(escstr[ic])
		    ic = ic - 1
		    escseq[jc] = num
		} else {
		    escseq[jc] = escstr[ic]
		}

	    # Convert control sequence

	    } else if (escstr[ic] == '^') {
		ic = ic + 1
		escseq[jc] = mod (int(escstr[ic]), 32)

	    # Copy ordinary character

	    } else {
		escseq[jc] = escstr[ic]
	    }

	    ic = ic + 1
	}

	escseq[jc] = EOS
end