/[gentoo-src]/rc-scripts/src/awk/functions.awk
Gentoo

Contents of /rc-scripts/src/awk/functions.awk

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (show annotations) (download)
Mon Aug 23 06:39:42 2004 UTC (15 years, 9 months ago) by vapier
Branch: MAIN
CVS Tags: HEAD
Branch point for: bsd-porting, rc-scripts-1_6
Changes since 1.7: +2 -2 lines
fix copyright lines

1 # Copyright 1999-2004 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /home/cvsroot/gentoo-src/rc-scripts/src/awk/functions.awk,v 1.7 2004/04/21 17:09:18 vapier Exp $
4
5 function einfo(string)
6 {
7 printf(" %s %s%s", "\033[32;01m*\033[0m", string, "\n")
8 }
9
10 function ewarn(string)
11 {
12 printf(" %s %s%s" , "\033[33;01m*\033[0m", string, "\n")
13 }
14
15 function eerror(string)
16 {
17 printf(" %s %s%s" , "\033[31;01m*\033[0m", string, "\n")
18 }
19
20 function isfile(pathname, x, ret, data)
21 {
22 ret = 0
23 data[1] = 1
24
25 if (pathname == "")
26 return 0
27
28 ret = stat(pathname, data)
29 if (ret < 0)
30 return 0
31
32 for (i in data) {
33 if (i == "type")
34 if (data[i] == "file")
35 ret = 1
36 }
37
38 return ret
39 }
40
41 function islink(pathname, x, ret, data)
42 {
43 ret = 0
44 data[1] = 1
45
46 if (pathname == "")
47 return 0
48
49 ret = stat(pathname, data)
50 if (ret < 0)
51 return 0
52
53 for (i in data) {
54 if (i == "type")
55 if (data[i] == "symlink")
56 ret = 1
57 }
58
59 return ret
60 }
61
62 function isdir(pathname, x, ret, data)
63 {
64 ret = 0
65 data[1] = 1
66
67 if (pathname == "")
68 return 0
69
70 ret = stat(pathname, data)
71 if (ret < 0)
72 return 0
73
74 for (i in data) {
75 if (i == "type")
76 if (data[i] == "directory")
77 ret = 1
78 }
79
80 return ret
81 }
82
83 function mktree(pathname, mode, x, max, ret, data, pathnodes, tmppath)
84 {
85 ret = 0
86 data[1] = 1
87 pathnodes[1] = 1
88
89 if (pathname == "")
90 return 0
91
92 if (pathname ~ /^\//)
93 tmppath = ""
94 else
95 tmppath = "."
96
97 split(pathname, pathnodes, "/")
98
99 for (x in pathnodes)
100 max++
101
102 # We cannot use 'for (x in pathnodes)', as gawk likes to
103 # sort the order indexes are processed ...
104 for (x = 1;x <= max;x++) {
105 if (pathnodes[x] == "")
106 continue
107
108 tmppath = tmppath "/" pathnodes[x]
109
110 ret = stat(tmppath, data)
111 if (ret < 0)
112 if (mkdir(tmppath, mode) < 0)
113 return 0
114 }
115
116 return 1
117 }
118
119 # symlink() wrapper that normalize return codes ...
120 function dosymlink(oldpath, newpath, ret)
121 {
122 ret = 0
123
124 ret = symlink(oldpath, newpath)
125 if (ret < 0)
126 return 0
127 else
128 return 1
129 }
130
131 # system() wrapper that normalize return codes ...
132 function dosystem(command, ret)
133 {
134 ret = 0
135
136 ret = system(command)
137 if (ret == 0)
138 return 1
139 else
140 return 0
141 }
142
143 # assert --- assert that a condition is true. Otherwise exit.
144 # This is from the gawk info manual.
145 function assert(condition, string)
146 {
147 if (! condition) {
148 printf("%s:%d: assertion failed: %s\n",
149 FILENAME, FNR, string) > "/dev/stderr"
150 _assert_exit = 1
151 exit 1
152 }
153 }
154
155
156 # vim:ts=4

  ViewVC Help
Powered by ViewVC 1.1.20