aboutsummaryrefslogtreecommitdiff
path: root/sys/ki/zzdebug.x
blob: 550fcc3f7a5fc70322e0ee368d22438212bff8d5 (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
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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

task	rexec	= t_rexec,
	rtype	= t_rtype,
	rread	= t_rread,
	encode	= t_encode

define	SZ_BUF		4096


# REXEC -- Execute a command on a remote node and print the resultant output on
# the standard output.  Used to test the kernel server driver.

procedure t_rexec()

char	server[SZ_LINE]
char	buf[SZ_BUF]
int	chan, nbytes, status

begin
	call clgstr ("server", server, SZ_LINE)
	call strpak (server, server, SZ_LINE)

	call zopnks (server, READ_WRITE, chan)
	if (chan == ERR)
	    call error (1, "cannot connect to remote server process")

	repeat {
	    call zardks (chan, buf, SZ_BUF, 0)
	    call zawtks (chan, nbytes)

	    if (nbytes > 0) {
		call chrupk (buf, 1, buf, 1, nbytes)
		call write (STDOUT, buf, nbytes)
		call flush (STDOUT)
	    }
	} until (nbytes <= 0)

	call zclsks (chan, status)
	if (status == ERR)
	    call error (1, "error disconnecting server process")
end


# RTYPE -- Type a text file possibly resident on a remote node.

procedure t_rtype()

char	fname[SZ_FNAME]
char	lbuf[SZ_LINE]
int	fd
int	open(), getline()

begin
	call clgstr ("file", fname, SZ_FNAME)
	fd = open (fname, READ_ONLY, TEXT_FILE)

	while (getline (fd, lbuf) != EOF) {
	    call putline (STDOUT, lbuf)
	    call flush (STDOUT)
	}

	call close (fd)
end


# RREAD -- Read a binary file.

procedure t_rread()

char	fname[SZ_FNAME]
char	dbuf[SZ_BUF]
int	fd
long	nchars, totchars
int	open(), read()

begin
	call clgstr ("file", fname, SZ_FNAME)
	fd = open (fname, READ_ONLY, BINARY_FILE)

	totchars = 0

	repeat {
	    nchars = read (fd, dbuf, SZ_BUF)
	    if (nchars > 0)
		totchars = totchars + nchars
	} until (nchars == EOF)

	call close (fd)

	call printf ("read %d chars\n")
	    call pargi (totchars)
end


# ENCODE -- Test the kiencode/decode routines.

procedure t_encode()

int	v, ip
char	xnum[8]
int	ki_decode(), clgeti()

begin
	repeat {
	    v = clgeti ("value")
	    call ki_encode (v, xnum, 8)
	    call chrpak (xnum, 1, xnum, 1, 8)
	    call chrupk (xnum, 1, xnum, 1, 8)

	    call printf ("\t")
	    for (ip=1;  ip <= 8;  ip=ip+1) {
		call printf ("%3d ")
		    call pargc (xnum[ip])
	    }

	    call printf (" --> %d\n")
		call pargi (ki_decode (xnum, 8))
	}
end