aboutsummaryrefslogtreecommitdiff
path: root/pkg/system/t_fcache.x
blob: 236c33c4744953fdf55259a07c3bccee6f8a9c34 (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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<error.h>

define	FC_CMDS	"|init|purge|destroy|list|lookup|access|add|delete|wait|help|"

define	FC_INIT		1
define	FC_PURGE	2
define	FC_DESTROY	3
define	FC_LIST		4
define	FC_LOOKUP	5
define	FC_ACCESS	6
define	FC_ADD		7
define	FC_DELETE	8
define	FC_WAIT		9
define	FC_HELP		10


# FCACHE -- Task interface to the file cache.

procedure t_fcache ()

char	cmd[SZ_FNAME], cache[SZ_FNAME], fname[SZ_FNAME]
char	pattern[SZ_FNAME], src[SZ_FNAME], cname[SZ_FNAME], extn[SZ_FNAME]
bool	verbose, in_src, exists
int	age

int	strdic(), clgeti(), envgeti()
bool	clgetb(), fcaccess()

begin
	# Get the common parameters.
	call clgstr ("cmd", cmd, SZ_FNAME)
	call clgstr ("cache", cache, SZ_FNAME)
	verbose = clgetb ("verbose")

	# Process the requested command.
	switch (strdic (cmd, cmd, SZ_FNAME, FC_CMDS)) {
	case FC_INIT:
	    call clgstr ("pattern", pattern, SZ_FNAME)
	    call fcinit (cache, pattern)

	case FC_PURGE:
	    age = clgeti ("age")
	    if (age < 0)
		age = envgeti ("cache_age")
	    call fcpurge (cache, verbose, age)

	case FC_DESTROY:
	    call fcdestroy (cache, verbose)

	case FC_LIST:
	    call fclist (cache, verbose, STDOUT)

	case FC_LOOKUP:
	    call clgstr ("src", src, SZ_FNAME)
	    if (src[1] != EOS) {
	        call fclookup (cache, src, fname, extn, SZ_FNAME)
	        if (verbose) {
		    call printf ("%s\n")
		        call pargstr (fname)
	        }
	        call clpstr ("fname", fname)
	        call clpstr ("extn", extn)
	    } else {
	        call clgstr ("fname", fname, SZ_FNAME)
	        call clgstr ("extn", extn, SZ_FNAME)
	        call fclookup (cache, src, fname, extn, SZ_FNAME)
		if (verbose) {
		    call printf ("%s\n")
		        call pargstr (src)
		}
	        call clpstr ("src", src)
	    }

	case FC_ACCESS:
	    call clgstr ("src", src, SZ_FNAME)
	    call clgstr ("extn", extn, SZ_FNAME)

	    exists =  fcaccess (cache, src, extn)
	    call printf ("%b\n")
	        call pargb (exists)

	case FC_ADD:
	    call clgstr ("src", src, SZ_FNAME)
	    call clgstr ("extn", extn, SZ_FNAME)
	    call fcadd (cache, src, extn, cname, SZ_FNAME)
	    if (verbose) {
		call eprintf ("%s\n")
		    call pargstr (cname)
	    }
	    call clpstr ("fname", cname)
	    if (clgetb ("wait"))
	        call fcwait (cache, cname)

	case FC_DELETE:
	    call clgstr ("src", src, SZ_FNAME)
	    if (src[1] != EOS) {
		# Delete by src string.
	        call fclookup (cache, src, fname, extn, SZ_FNAME)
	        call fcdelete (cache, fname)
	    } else {
		# Delete by cached filename.
	        call clgstr ("fname", fname, SZ_FNAME)
	        call fcdelete (cache, fname)
	    }

	case FC_WAIT:
	    call clgstr ("src", src, SZ_FNAME)
	    call fcwait (cache, src)

	case FC_HELP:

	default:
	    call eprintf ("Unknown command '%s'\n")
		call pargstr (cmd)
	}
end