aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/mk/file.c
blob: 2533343fd8ddabab29e513918c7f0e53bb0c3c35 (plain)
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
#include	"mk.h"

/* table-driven version in bootes dump of 12/31/96 */

long
mtime(char *name)
{
	return mkmtime(name);
}

long
timeof(char *name, int force)
{
	Symtab *sym;
	long t;

	if(utfrune(name, '('))
		return atimeof(force, name);	/* archive */

	if(force)
		return mtime(name);


	sym = symlook(name, S_TIME, 0);
	if (sym)
		return (long) sym->value;		/* uggh */

	t = mtime(name);
	if(t == 0)
		return 0;

	symlook(name, S_TIME, (void*)t);		/* install time in cache */
	return t;
}

void
touch(char *name)
{
	Bprint(&bout, "touch(%s)\n", name);
	if(nflag)
		return;

	if(utfrune(name, '('))
		atouch(name);		/* archive */
	else if(chgtime(name) < 0) {
		fprint(2, "%s: %r\n", name);
		Exit();
	}
}

void
delete(char *name)
{
	if(utfrune(name, '(') == 0) {		/* file */
		if(remove(name) < 0)
			fprint(2, "remove %s: %r\n", name);
	} else
		fprint(2, "hoon off; mk can'tdelete archive members\n");
}

void
timeinit(char *s)
{
	long t;
	char *cp;
	Rune r;
	int c, n;

	t = time(0);
	while (*s) {
		cp = s;
		do{
			n = chartorune(&r, s);
			if (r == ' ' || r == ',' || r == '\n')
				break;
			s += n;
		} while(*s);
		c = *s;
		*s = 0;
		symlook(strdup(cp), S_TIME, (void *)t)->value = (void *)t;
		if (c)
			*s++ = c;
		while(*s){
			n = chartorune(&r, s);
			if(r != ' ' && r != ',' && r != '\n')
				break;
			s += n;
		}
	}
}