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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header$
function einfo(string)
{
printf(" %s %s%s", "\033[32;01m*\033[0m", string, "\n")
}
function ewarn(string)
{
printf(" %s %s%s" , "\033[33;01m*\033[0m", string, "\n")
}
function eerror(string)
{
printf(" %s %s%s" , "\033[31;01m*\033[0m", string, "\n")
}
function isfile(pathname, x, ret, data)
{
ret = 0
data[1] = 1
if (pathname == "")
return 0
ret = stat(pathname, data)
if (ret < 0)
return 0
for (i in data) {
if (i == "type")
if (data[i] == "file")
ret = 1
}
return ret
}
function islink(pathname, x, ret, data)
{
ret = 0
data[1] = 1
if (pathname == "")
return 0
ret = stat(pathname, data)
if (ret < 0)
return 0
for (i in data) {
if (i == "type")
if (data[i] == "symlink")
ret = 1
}
return ret
}
function isdir(pathname, x, ret, data)
{
ret = 0
data[1] = 1
if (pathname == "")
return 0
ret = stat(pathname, data)
if (ret < 0)
return 0
for (i in data) {
if (i == "type")
if (data[i] == "directory")
ret = 1
}
return ret
}
function mktree(pathname, mode, x, max, ret, data, pathnodes, tmppath)
{
ret = 0
data[1] = 1
pathnodes[1] = 1
if (pathname == "")
return 0
if (pathname ~ /^\//)
tmppath = ""
else
tmppath = "."
split(pathname, pathnodes, "/")
for (x in pathnodes)
max++
# We cannot use 'for (x in pathnodes)', as gawk likes to
# sort the order indexes are processed ...
for (x = 1;x <= max;x++) {
if (pathnodes[x] == "")
continue
tmppath = tmppath "/" pathnodes[x]
ret = stat(tmppath, data)
if (ret < 0)
if (mkdir(tmppath, mode) < 0)
return 0
}
return 1
}
# symlink() wrapper that normalize return codes ...
function dosymlink(oldpath, newpath, ret)
{
ret = 0
ret = symlink(oldpath, newpath)
if (ret < 0)
return 0
else
return 1
}
# system() wrapper that normalize return codes ...
function dosystem(command, ret)
{
ret = 0
ret = system(command)
if (ret == 0)
return 1
else
return 0
}
# assert --- assert that a condition is true. Otherwise exit.
# This is from the gawk info manual.
function assert(condition, string)
{
if (! condition) {
printf("%s:%d: assertion failed: %s\n",
FILENAME, FNR, string) > "/dev/stderr"
_assert_exit = 1
exit 1
}
}
# vim:ts=4
|