~ubuntu-branches/ubuntu/natty/9base/natty

« back to all changes in this revision

Viewing changes to mk/file.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-11-07 12:25:14 UTC
  • mto: (6.2.3 squeeze)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20091107122514-7fngaksi3zra1vt4
Tags: upstream-4
ImportĀ upstreamĀ versionĀ 4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include        "mk.h"
 
2
 
 
3
/* table-driven version in bootes dump of 12/31/96 */
 
4
 
 
5
long
 
6
mtime(char *name)
 
7
{
 
8
        return mkmtime(name);
 
9
}
 
10
 
 
11
long
 
12
timeof(char *name, int force)
 
13
{
 
14
        Symtab *sym;
 
15
        long t;
 
16
 
 
17
        if(utfrune(name, '('))
 
18
                return atimeof(force, name);    /* archive */
 
19
 
 
20
        if(force)
 
21
                return mtime(name);
 
22
 
 
23
 
 
24
        sym = symlook(name, S_TIME, 0);
 
25
        if (sym)
 
26
                return sym->u.value;
 
27
 
 
28
        t = mtime(name);
 
29
        if(t == 0)
 
30
                return 0;
 
31
 
 
32
        symlook(name, S_TIME, (void*)t);                /* install time in cache */
 
33
        return t;
 
34
}
 
35
 
 
36
void
 
37
touch(char *name)
 
38
{
 
39
        Bprint(&bout, "touch(%s)\n", name);
 
40
        if(nflag)
 
41
                return;
 
42
 
 
43
        if(utfrune(name, '('))
 
44
                atouch(name);           /* archive */
 
45
        else if(chgtime(name) < 0) {
 
46
                fprint(2, "%s: %r\n", name);
 
47
                Exit();
 
48
        }
 
49
}
 
50
 
 
51
void
 
52
delete(char *name)
 
53
{
 
54
        if(utfrune(name, '(') == 0) {           /* file */
 
55
                if(remove(name) < 0)
 
56
                        fprint(2, "remove %s: %r\n", name);
 
57
        } else
 
58
                fprint(2, "hoon off; mk can'tdelete archive members\n");
 
59
}
 
60
 
 
61
void
 
62
timeinit(char *s)
 
63
{
 
64
        long t;
 
65
        char *cp;
 
66
        Rune r;
 
67
        int c, n;
 
68
 
 
69
        t = time(0);
 
70
        while (*s) {
 
71
                cp = s;
 
72
                do{
 
73
                        n = chartorune(&r, s);
 
74
                        if (r == ' ' || r == ',' || r == '\n')
 
75
                                break;
 
76
                        s += n;
 
77
                } while(*s);
 
78
                c = *s;
 
79
                *s = 0;
 
80
                symlook(strdup(cp), S_TIME, (void *)t)->u.value = t;
 
81
                if (c)
 
82
                        *s++ = c;
 
83
                while(*s){
 
84
                        n = chartorune(&r, s);
 
85
                        if(r != ' ' && r != ',' && r != '\n')
 
86
                                break;
 
87
                        s += n;
 
88
                }
 
89
        }
 
90
}