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

include	<ctype.h>
include	<knet.h>

# FDIRNAME -- Return the concatenatable directory prefix for the named
# directory.  If no vfn is given (null string), a path to the current
# directory is returned.

procedure fdirname (vfn, path, maxch)

char	vfn[ARB]		# VFN of directory
char	path[ARB]		# unpacked path to directory
int	maxch

int	len1, len2, ch
int	gstrcpy()

begin
	if (vfn[1] == EOS) {
	    # Null vfn; return current directory.
	    call strcpy ("./", path, maxch)
	    return
	}

	# Do we have an OS directory reference?
	call zfxdir (vfn, path, maxch, len2)
	ch = path[len2]
	if (len2 > 0 && !(IS_ALNUM(ch) || ch == '_'))
	    return

	# Do we have an "ldir$" or "subdir/"?  If so, quit, else if the last
	# char is a normal identifier class filename char, assume that we have
	# a VFN and add the / delimiter.  This technique is not infallible,
	# and a better solution would be to have ZFXDIR or FDIRNAME itself
	# execute on the remote node.

	len1 = gstrcpy (vfn, path, maxch)
	ch = path[len1]
	if (ch == '$' || ch == '/')
	    return

	# Must be a subdirectory of the form "subdir".  Add the /.
	path[len1+1] = '/'
	path[len1+2] = EOS
end