aboutsummaryrefslogtreecommitdiff
path: root/sys/tty/ttydevnm.x
blob: 76996d69a63208667b3fd296a012d1aa7131e346 (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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<ctype.h>

# TTYDEVNAME -- Extract the logical device name from a full device specification
# of the form  "node ! logical_device ? physical_device".  The node prefix, if
# given, specifies the node from which the device is to be accessed (via the
# network), and the physical device field contains particulars about the
# physical device to be accessed.  Only the logical device field, used to index
# the termcap file, is of any interest to TTY.  The logical device name
# consists of chars chosen from the set [a-zA-Z0-9_+-].

procedure ttydevname (device, ldevice, maxch)

char	device[ARB]		# full device specification
char	ldevice[maxch]		# logical device name
int	maxch

pointer	sp, nodename
int	ip, op, ch
int	ki_extnode()

begin
	call smark (sp)
	call salloc (nodename, SZ_FNAME, TY_CHAR)

	ip = ki_extnode (device, Memc[nodename], maxch, op) + 1

	for (op=1;  device[ip] != EOS;  ip=ip+1) {
	    ch = device[ip]
	    if (!(IS_ALNUM(ch) || ch == '_' || ch == '+' || ch == '-')) {
		ldevice[op] = EOS
		break
	    } else {
		ldevice[op] = ch
		op = op + 1
	    }
	}

	call sfree (sp)
end