aboutsummaryrefslogtreecommitdiff
path: root/sys/mtio/mtparse.x
blob: 27622280e7ff10f774bd0bef348df921a8aa3785 (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
121
122
123
124
125
126
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<config.h>
include	<syserr.h>
include	<ctype.h>
include	"mtio.h"

# MTPARSE -- Decode a virtual magtape file specification, returning the device
# name, file and record to which the drive is to be positioned, and any special
# device attributes (these will override the device defaults).  The file and
# record fields are returned as ERR if missing.  Only the drive name field is
# required.
# 
# Magtape device syntax:
#
#	[node!] mtX [ '[' file[.record] [:attr-list] ']' ]
#
# for example,
#
#	mtexb1[4:nb:se@:ts=1200:so=/dev/ttya8]
#
# The "mt" prefix is required for the object to be considered a magtape
# device reference.  The device name returned is "mtX" as shown above; there
# must be an entry for device mtX in the tapecap file in DEV.
#
# The file and record numbers are optional.  Files and records are numbered
# starting with 1.  A sequence such as "mtX[eot]" will cause the tape to be
# positioned to end of tape.  "mtX[0]" causes the tape to be opened at the
# current position, i.e., without being moved.
#
# The optional attr-list field consists of a sequence of colon-delimited
# tapecap fields.  These will override any values given in the tapecap
# entry for the device.  The syntax for attr-list is the same as in tapecap.

procedure mtparse (mtname, device, sz_device, file, record, attrl, sz_attrl)

char	mtname[ARB]		#I device specification
char	device[ARB]		#O device name as in tapecap
int	sz_device		#I max chars in device name
int	file			#O file number or -1
int	record			#O record number or -1
char	attrl[ARB]		#O attribute list
int	sz_attrl		#I max char in attribute list

char	eotstr[3]
int	ip, op, nchars, ival
int	ctoi(), strncmp(), ki_extnode()
bool	streq()
define	bad_ 91

begin
	# Extract the node name, if any, from the mtname.
	ip = ki_extnode (mtname, device, sz_device, nchars) + 1
	op = nchars + 1

	# Verify that this is a magtape device specification.
	if (strncmp (mtname[ip], "mt", 2) != 0)
	    goto bad_

	# Extract the device name field.
	while (mtname[ip] != EOS && mtname[ip] != '[') {
	    device[op] = mtname[ip]
	    op = min (sz_device, op + 1)
	    ip = ip + 1
	}
	device[op] = EOS

	file = ERR
	record = ERR
	attrl[1] = EOS

	# Process the [...] part of the device specification.
	if (mtname[ip] == '[') {
	    ip = ip + 1

	    # Get the file number.
	    if (ctoi (mtname, ip, ival) > 0) {
		file = ival
		if (file < 0)
		    goto bad_
	    } else if (IS_ALPHA(mtname[ip])) {
		call strcpy (mtname[ip], eotstr, 3)
		call strlwr (eotstr)
		if (streq (eotstr, "eot")) {
		    file = EOT
		    ip = ip + 3
		} else
		    goto bad_
	    }

	    # Get the record number.
	    if (mtname[ip] == '.' || mtname[ip] == ',') {
		ip = ip + 1
		if (mtname[ip] == ']')
		    record = ERR
		else if (ctoi (mtname, ip, ival) > 0) {
		    record = ival
		    if (record < 0)
			goto bad_
		}
	    }

	    # Get the device attribute list.
	    op = 1
	    if (mtname[ip] == ':') {
		attrl[op] = mtname[ip]
		op = max(1, min(sz_attrl, op + 1))
		ip = ip + 1

		while (mtname[ip] != EOS && mtname[ip] != ']') {
		    attrl[op] = mtname[ip]
		    op = max(1, min(sz_attrl, op + 1))
		    ip = ip + 1
		}
	    }
	    attrl[op] = EOS

	    # Check for the ']' terminator.
	    if (mtname[ip] != ']')
		goto bad_
	}

	return
bad_
	call syserrs (SYS_MTFILSPEC, mtname)
end