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

Diff of /rc-scripts/src/awk/cachedepends.awk

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.7 Revision 1.15
1# Copyright 1999-2003 Gentoo Technologies, Inc. 1# Copyright 1999-2003 Gentoo Technologies, Inc.
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# Author: Martin Schlemmer <azarah@gentoo.org> 3# Author: Martin Schlemmer <azarah@gentoo.org>
4# $Header: /var/cvsroot/gentoo-src/rc-scripts/src/awk/cachedepends.awk,v 1.7 2003/01/06 21:32:44 azarah Exp $ 4# $Header: /var/cvsroot/gentoo-src/rc-scripts/src/awk/cachedepends.awk,v 1.15 2004/02/26 17:29:43 azarah Exp $
5 5
6function print_start() { 6function print_start() {
7 print "need() {" >> (DEPCACHE) 7 print "source /sbin/functions.sh" >> (SVCDIR "/depcache")
8 print "" >> (SVCDIR "/depcache")
9 print "need() {" >> (SVCDIR "/depcache")
8 print " echo \"NEED $*\"; return 0" >> (DEPCACHE) 10 print " echo \"NEED $*\"; return 0" >> (SVCDIR "/depcache")
9 print "}" >> (DEPCACHE) 11 print "}" >> (SVCDIR "/depcache")
10 print "" >> (DEPCACHE) 12 print "" >> (SVCDIR "/depcache")
11 print "use() {" >> (DEPCACHE) 13 print "use() {" >> (SVCDIR "/depcache")
12 print " echo \"USE $*\"; return 0" >> (DEPCACHE) 14 print " echo \"USE $*\"; return 0" >> (SVCDIR "/depcache")
13 print "}" >> (DEPCACHE) 15 print "}" >> (SVCDIR "/depcache")
14 print "" >> (DEPCACHE) 16 print "" >> (SVCDIR "/depcache")
15 print "before() {" >> (DEPCACHE) 17 print "before() {" >> (SVCDIR "/depcache")
16 print " echo \"BEFORE $*\"; return 0" >> (DEPCACHE) 18 print " echo \"BEFORE $*\"; return 0" >> (SVCDIR "/depcache")
17 print "}" >> (DEPCACHE) 19 print "}" >> (SVCDIR "/depcache")
18 print "" >> (DEPCACHE) 20 print "" >> (SVCDIR "/depcache")
19 print "after() {" >> (DEPCACHE) 21 print "after() {" >> (SVCDIR "/depcache")
20 print " echo \"AFTER $*\"; return 0" >> (DEPCACHE) 22 print " echo \"AFTER $*\"; return 0" >> (SVCDIR "/depcache")
21 print "}" >> (DEPCACHE) 23 print "}" >> (SVCDIR "/depcache")
22 print "" >> (DEPCACHE) 24 print "" >> (SVCDIR "/depcache")
23 print "provide() {" >> (DEPCACHE) 25 print "provide() {" >> (SVCDIR "/depcache")
24 print " echo \"PROVIDE $*\"; return 0" >> (DEPCACHE) 26 print " echo \"PROVIDE $*\"; return 0" >> (SVCDIR "/depcache")
25 print "}" >> (DEPCACHE) 27 print "}" >> (SVCDIR "/depcache")
26 print "" >> (DEPCACHE) 28 print "" >> (SVCDIR "/depcache")
29 print "parallel() {" >> (SVCDIR "/depcache")
30 print " echo \"PARALLEL $*\"; return 0" >> (SVCDIR "/depcache")
31 print "}" >> (SVCDIR "/depcache")
32 print "" >> (SVCDIR "/depcache")
27} 33}
28 34
29function print_header() { 35function print_header1(mtime) {
30 print "#*** " MYFILENAME " ***" >> (DEPCACHE) 36 print "#*** " MYFILENAME " ***" >> (SVCDIR "/depcache")
31 print "" >> (DEPCACHE) 37 print "" >> (SVCDIR "/depcache")
32 print "myservice=\"" MYFILENAME "\"" >> (DEPCACHE) 38 print "myservice=\"" MYFILENAME "\"" >> (SVCDIR "/depcache")
33 print "myservice=\"${myservice##*/}\"" >> (DEPCACHE) 39 print "myservice=\"${myservice##*/}\"" >> (SVCDIR "/depcache")
34 print "echo \"RCSCRIPT ${myservice}\"" >> (DEPCACHE) 40 print "echo \"RCSCRIPT ${myservice}\"" >> (SVCDIR "/depcache")
35 print "" >> (DEPCACHE) 41 print "" >> (SVCDIR "/depcache")
36 print "depend() {" >> (DEPCACHE) 42 print "echo \"MTIME " mtime "\"" >> (SVCDIR "/depcache")
37 print " return 0" >> (DEPCACHE) 43 print "" >> (SVCDIR "/depcache")
38 print "}" >> (DEPCACHE) 44}
39 print "" >> (DEPCACHE) 45
46function print_header2(mtime) {
47 print "(" >> (SVCDIR "/depcache")
48 print " # Get settings for rc-script ..." >> (SVCDIR "/depcache")
49 print " [ -e /etc/conf.d/basic ] && source /etc/conf.d/basic" >> (SVCDIR "/depcache")
50 print "" >> (SVCDIR "/depcache")
51 print " [ -e \"/etc/conf.d/${myservice}\" ] && source \"/etc/conf.d/${myservice}\"" >> (SVCDIR "/depcache")
52 print "" >> (SVCDIR "/depcache")
53 print " [ -e /etc/conf.d/net ] && \\" >> (SVCDIR "/depcache")
54 print " [ \"${myservice%%.*}\" = \"net\" ] && \\" >> (SVCDIR "/depcache")
55 print " [ \"${myservice##*.}\" != \"${myservice}\" ] && source /etc/conf.d/net" >> (SVCDIR "/depcache")
56 print "" >> (SVCDIR "/depcache")
57 print " [ -e /etc/rc.conf ] && source /etc/rc.conf" >> (SVCDIR "/depcache")
58 print "" >> (SVCDIR "/depcache")
59 print " depend() {" >> (SVCDIR "/depcache")
60 print " return 0" >> (SVCDIR "/depcache")
61 print " }" >> (SVCDIR "/depcache")
62 print "" >> (SVCDIR "/depcache")
40} 63}
41 64
42function print_end() { 65function print_end() {
43 print "" >> (DEPCACHE) 66 print "" >> (SVCDIR "/depcache")
44 print "depend" >> (DEPCACHE) 67 print " depend" >> (SVCDIR "/depcache")
45 print "" >> (DEPCACHE) 68 print ")" >> (SVCDIR "/depcache")
69 print "" >> (SVCDIR "/depcache")
46} 70}
47 71
48BEGIN { 72BEGIN {
49 73
50 extension("/lib/rcscripts/filefuncs.so", "dlload") 74 extension("/lib/rcscripts/filefuncs.so", "dlload")
75
76 # Get our environment variables
77 SVCDIR = ENVIRON["SVCDIR"]
78 if (SVCDIR == "") {
79 eerror("Could not get SVCDIR!")
80 exit 1
81 }
51 82
52 pipe = "ls /etc/init.d/*" 83 pipe = "ls /etc/init.d/*"
53 while ((pipe | getline tmpstring) > 0) 84 while ((pipe | getline tmpstring) > 0)
54 scripts = scripts " " tmpstring 85 scripts = scripts " " tmpstring
55 close(pipe) 86 close(pipe)
57 split(scripts, TMPRCSCRIPTS) 88 split(scripts, TMPRCSCRIPTS)
58 89
59 # Make sure that its a file we are working with, 90 # Make sure that its a file we are working with,
60 # and do not process scripts, source or backup files. 91 # and do not process scripts, source or backup files.
61 for (x in TMPRCSCRIPTS) 92 for (x in TMPRCSCRIPTS)
62 if ((isfile(TMPRCSCRIPTS[x])) && 93 if (((isfile(TMPRCSCRIPTS[x])) || (islink(TMPRCSCRIPTS[x]))) &&
63 (TMPRCSCRIPTS[x] !~ /((\.(sh|c|bak))|\~)$/)) { 94 (TMPRCSCRIPTS[x] !~ /((\.(c|bak))|\~)$/)) {
64 95
65 RCCOUNT++ 96 RCCOUNT++
66 97
67 RCSCRIPTS[RCCOUNT] = TMPRCSCRIPTS[x] 98 RCSCRIPTS[RCCOUNT] = TMPRCSCRIPTS[x]
68 } 99 }
70 if (RCCOUNT == 0) { 101 if (RCCOUNT == 0) {
71 eerror("No scripts to process!") 102 eerror("No scripts to process!")
72 exit 1 103 exit 1
73 } 104 }
74 105
75 DEPCACHE=SVCDIR "/depcache"
76
77 unlink(DEPCACHE)
78
79 print_start() 106 print_start()
80 107
81 for (count = 1;count <= RCCOUNT;count++) { 108 for (count = 1;count <= RCCOUNT;count++) {
82 109
83 MYFNR = 1 110 MYFNR = 1
84 MYFILENAME = RCSCRIPTS[count] 111 MYFILENAME = RCSCRIPTS[count]
112 STAT_DATA[1] = 1
85 113
86 while (((getline < (RCSCRIPTS[count])) > 0) && (!NEXTFILE)) { 114 while (((getline < (RCSCRIPTS[count])) > 0) && (!NEXTFILE)) {
87 115
88 # If line start with a '#' and is the first line 116 # If line start with a '#' and is the first line
89 if (($0 ~ /^[[:space:]]*#/) && (MYFNR == 1)) { 117 if (($0 ~ /^[[:space:]]*#/) && (MYFNR == 1)) {
90 118
91 # Remove any spaces and tabs 119 # Remove any spaces and tabs
92 gsub(/[[:space:]]+/, "") 120 gsub(/[[:space:]]+/, "")
93 121
94 if ($0 == "#!/sbin/runscript") { 122 if ($0 == "#!/sbin/runscript") {
123
124 if (RCSCRIPTS[count] ~ /\.sh$/) {
125
126 ewarn(RCSCRIPTS[count] " is invalid (should not end with '.sh')")
127 NEXTFILE = 1
128 continue
129 }
130
131 if (stat(MYFILENAME, STAT_DATA) != 0)
132 ewarn("Could not stat \"" MYFILENAME "\"")
95 133
96 ISRCSCRIPT = 1 134 ISRCSCRIPT = 1
97 print_header() 135 print_header1(STAT_DATA["mtime"])
98 } else { 136 } else {
99 137
100 NEXTFILE = 1 138 NEXTFILE = 1
101 continue 139 continue
102 } 140 }
103 } 141 }
104 142
105 # Filter out comments and only process if its a rcscript 143 # Filter out comments and only process if its a rcscript
106 if (($0 !~ /^[[:space:]]*#/) && (ISRCSCRIPT == 1 )) { 144 if (($0 !~ /^[[:space:]]*#/) && (ISRCSCRIPT)) {
107 145
108 # If line contain 'depend()', set GOTDEPEND to 1 146 # If line contain 'depend()', set GOTDEPEND to 1
109 if ($0 ~ /depend[[:space:]]*\(\)/) 147 if ($0 ~ /depend[[:space:]]*\(\)/) {
148
110 GOTDEPEND = 1 149 GOTDEPEND = 1
150
151 print_header2()
152 print " # Actual depend() function ..." >> (SVCDIR "/depcache")
153 }
111 154
112 # We have the depend function... 155 # We have the depend function...
113 if (GOTDEPEND == 1) { 156 if (GOTDEPEND) {
114 157
115 # Basic theory is that COUNT will be 0 when we 158 # Basic theory is that COUNT will be 0 when we
116 # have matching '{' and '}' 159 # have matching '{' and '}'
117 COUNT += gsub(/{/, "{") 160 COUNT += gsub(/{/, "{")
118 COUNT -= gsub(/}/, "}") 161 COUNT -= gsub(/}/, "}")
119 162
120 # This is just to verify that we have started with 163 # This is just to verify that we have started with
121 # the body of depend() 164 # the body of depend()
122 SBCOUNT += gsub(/{/, "{") 165 SBCOUNT += gsub(/{/, "{")
166
167 # Make sure depend() contain something, else bash
168 # errors out (empty function).
169 if ((SBCOUNT > 0) && (COUNT == 0))
170 print " \treturn 0" >> (SVCDIR "/depcache")
123 171
124 # Print the depend() function 172 # Print the depend() function
125 print >> (DEPCACHE) 173 print " " $0 >> (SVCDIR "/depcache")
126 174
127 # If COUNT=0, and SBCOUNT>0, it means we have read 175 # If COUNT=0, and SBCOUNT>0, it means we have read
128 # all matching '{' and '}' for depend(), so stop. 176 # all matching '{' and '}' for depend(), so stop.
129 if ((SBCOUNT > 0) && (COUNT == 0)) { 177 if ((SBCOUNT > 0) && (COUNT == 0)) {
130 178
131 GOTDEPEND = 0 179 GOTDEPEND = 0
132 ISRCSCRIPT = 0
133 COUNT = 0 180 COUNT = 0
134 SBCOUNT = 0 181 SBCOUNT = 0
182 ISRCSCRIPT = 0
135 183
136 print_end() 184 print_end()
137 185
138 NEXTFILE = 1 186 NEXTFILE = 1
139 continue 187 continue
140 } 188 }
141 } 189 }
142 } 190 }
147 close(RCSCRIPTS[count]) 195 close(RCSCRIPTS[count])
148 196
149 NEXTFILE = 0 197 NEXTFILE = 0
150 198
151 } 199 }
152
153 close (DEPCACHE)
154} 200}
155 201
156 202
157# vim:ts=4 203# vim:ts=4

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.15

  ViewVC Help
Powered by ViewVC 1.1.20