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
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
# PATHNAMES -- Convert one or more filenames into OS pathnames. If the input
# is redirected, filenames are read from the standard input. Otherwise,
# a file name template is expanded and used as the list of filenames to be
# transformed. If called without any arguments, return the pathname of the
# current working directory.
procedure t_pathnames()
int list
pointer sp, fname, osfname
bool streq(), clgetb()
int clgeti(), clpopni(), clpopnu(), clgfil(), fscan()
begin
call smark (sp)
call salloc (fname, SZ_LINE, TY_CHAR)
call salloc (osfname, SZ_LINE, TY_CHAR)
# If no arguments, return the pathame of the current
# directory: do not prompt for the template.
if (clgeti ("$nargs") == 0) {
call fpathname ("", Memc[osfname], SZ_LINE)
call printf ("%s\n")
call pargstr (Memc[osfname])
call sfree (sp)
return
}
# Expand template, output pathname of each file therein.
if (clgetb ("sort"))
list = clpopni ("template")
else
list = clpopnu ("template")
while (clgfil (list, Memc[fname], SZ_FNAME) != EOF) {
if (streq (Memc[fname], "STDIN")) {
while (fscan (STDIN) != EOF) {
call gargstr (Memc[fname], SZ_LINE)
call fpathname (Memc[fname], Memc[osfname], SZ_LINE)
call printf ("%s\n")
call pargstr (Memc[osfname])
}
} else {
call fpathname (Memc[fname], Memc[osfname], SZ_LINE)
call printf ("%s\n")
call pargstr (Memc[osfname])
}
}
call clpcls (list)
call sfree (sp)
end
|