/[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.3 Revision 1.15
1# Copyright 1999-2002 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.3 2002/11/18 09:02:26 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 }
69 100
70 DEPCACHE=SVCDIR "/depcache" 101 if (RCCOUNT == 0) {
71 102 eerror("No scripts to process!")
72 unlink(DEPCACHE) 103 exit 1
104 }
73 105
74 print_start() 106 print_start()
75 107
76 for (count = 1;count <= RCCOUNT;count++) { 108 for (count = 1;count <= RCCOUNT;count++) {
77 109
78 MYFNR = 1 110 MYFNR = 1
79 MYFILENAME = RCSCRIPTS[count] 111 MYFILENAME = RCSCRIPTS[count]
112 STAT_DATA[1] = 1
80 113
81 while (((getline < (RCSCRIPTS[count])) > 0) && (!NEXTFILE)) { 114 while (((getline < (RCSCRIPTS[count])) > 0) && (!NEXTFILE)) {
82 115
83 # If line start with a '#' and is the first line 116 # If line start with a '#' and is the first line
84 if (($0 ~ /^[[:space:]]*#/) && (MYFNR == 1)) { 117 if (($0 ~ /^[[:space:]]*#/) && (MYFNR == 1)) {
85 118
86 # Remove any spaces and tabs 119 # Remove any spaces and tabs
87 gsub(/[[:space:]]+/, "") 120 gsub(/[[:space:]]+/, "")
88 121
89 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 "\"")
90 133
91 ISRCSCRIPT = 1 134 ISRCSCRIPT = 1
92 print_header() 135 print_header1(STAT_DATA["mtime"])
93 } else { 136 } else {
94 137
95 NEXTFILE = 1 138 NEXTFILE = 1
96 continue 139 continue
97 } 140 }
98 } 141 }
99 142
100 # Filter out comments and only process if its a rcscript 143 # Filter out comments and only process if its a rcscript
101 if (($0 !~ /[[:space:]]*#/) && (ISRCSCRIPT == 1 )) { 144 if (($0 !~ /^[[:space:]]*#/) && (ISRCSCRIPT)) {
102 145
103 # If line contain 'depend()', set GOTDEPEND to 1 146 # If line contain 'depend()', set GOTDEPEND to 1
104 if ($0 ~ /depend[[:space:]]*\(\)/) 147 if ($0 ~ /depend[[:space:]]*\(\)/) {
148
105 GOTDEPEND = 1 149 GOTDEPEND = 1
150
151 print_header2()
152 print " # Actual depend() function ..." >> (SVCDIR "/depcache")
153 }
106 154
107 # We have the depend function... 155 # We have the depend function...
108 if (GOTDEPEND == 1) { 156 if (GOTDEPEND) {
109 157
110 # Basic theory is that COUNT will be 0 when we 158 # Basic theory is that COUNT will be 0 when we
111 # have matching '{' and '}' 159 # have matching '{' and '}'
112 COUNT += gsub(/{/, "{") 160 COUNT += gsub(/{/, "{")
113 COUNT -= gsub(/}/, "}") 161 COUNT -= gsub(/}/, "}")
114 162
115 # This is just to verify that we have started with 163 # This is just to verify that we have started with
116 # the body of depend() 164 # the body of depend()
117 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")
118 171
119 # Print the depend() function 172 # Print the depend() function
120 print >> (DEPCACHE) 173 print " " $0 >> (SVCDIR "/depcache")
121 174
122 # If COUNT=0, and SBCOUNT>0, it means we have read 175 # If COUNT=0, and SBCOUNT>0, it means we have read
123 # all matching '{' and '}' for depend(), so stop. 176 # all matching '{' and '}' for depend(), so stop.
124 if ((SBCOUNT > 0) && (COUNT == 0)) { 177 if ((SBCOUNT > 0) && (COUNT == 0)) {
125 178
126 GOTDEPEND = 0 179 GOTDEPEND = 0
127 ISRCSCRIPT = 0
128 COUNT = 0 180 COUNT = 0
129 SBCOUNT = 0 181 SBCOUNT = 0
182 ISRCSCRIPT = 0
130 183
131 print_end() 184 print_end()
132 185
133 NEXTFILE = 1 186 NEXTFILE = 1
134 continue 187 continue
135 } 188 }
136 } 189 }
137 } 190 }
142 close(RCSCRIPTS[count]) 195 close(RCSCRIPTS[count])
143 196
144 NEXTFILE = 0 197 NEXTFILE = 0
145 198
146 } 199 }
147
148 close (DEPCACHE)
149} 200}
150 201
151 202
152# vim:ts=4 203# vim:ts=4

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

  ViewVC Help
Powered by ViewVC 1.1.20