/[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.12 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.12 2003/07/16 18:27:55 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 "source /sbin/functions.sh" 7 print "source /sbin/functions.sh" >> (SVCDIR "/depcache")
8 print "" 8 print "" >> (SVCDIR "/depcache")
9 print "need() {" 9 print "need() {" >> (SVCDIR "/depcache")
10 print " echo \"NEED $*\"; return 0" 10 print " echo \"NEED $*\"; return 0" >> (SVCDIR "/depcache")
11 print "}" 11 print "}" >> (SVCDIR "/depcache")
12 print "" 12 print "" >> (SVCDIR "/depcache")
13 print "use() {" 13 print "use() {" >> (SVCDIR "/depcache")
14 print " echo \"USE $*\"; return 0" 14 print " echo \"USE $*\"; return 0" >> (SVCDIR "/depcache")
15 print "}" 15 print "}" >> (SVCDIR "/depcache")
16 print "" 16 print "" >> (SVCDIR "/depcache")
17 print "before() {" 17 print "before() {" >> (SVCDIR "/depcache")
18 print " echo \"BEFORE $*\"; return 0" 18 print " echo \"BEFORE $*\"; return 0" >> (SVCDIR "/depcache")
19 print "}" 19 print "}" >> (SVCDIR "/depcache")
20 print "" 20 print "" >> (SVCDIR "/depcache")
21 print "after() {" 21 print "after() {" >> (SVCDIR "/depcache")
22 print " echo \"AFTER $*\"; return 0" 22 print " echo \"AFTER $*\"; return 0" >> (SVCDIR "/depcache")
23 print "}" 23 print "}" >> (SVCDIR "/depcache")
24 print "" 24 print "" >> (SVCDIR "/depcache")
25 print "provide() {" 25 print "provide() {" >> (SVCDIR "/depcache")
26 print " echo \"PROVIDE $*\"; return 0" 26 print " echo \"PROVIDE $*\"; return 0" >> (SVCDIR "/depcache")
27 print "}" 27 print "}" >> (SVCDIR "/depcache")
28 print "" 28 print "" >> (SVCDIR "/depcache")
29 print "parallel() {" 29 print "parallel() {" >> (SVCDIR "/depcache")
30 print " echo \"PARALLEL $*\"; return 0" 30 print " echo \"PARALLEL $*\"; return 0" >> (SVCDIR "/depcache")
31 print "}" 31 print "}" >> (SVCDIR "/depcache")
32 print "" 32 print "" >> (SVCDIR "/depcache")
33} 33}
34 34
35function print_header1() { 35function print_header1(mtime) {
36 print "#*** " MYFILENAME " ***" 36 print "#*** " MYFILENAME " ***" >> (SVCDIR "/depcache")
37 print "" 37 print "" >> (SVCDIR "/depcache")
38 print "myservice=\"" MYFILENAME "\"" 38 print "myservice=\"" MYFILENAME "\"" >> (SVCDIR "/depcache")
39 print "myservice=\"${myservice##*/}\"" 39 print "myservice=\"${myservice##*/}\"" >> (SVCDIR "/depcache")
40 print "echo \"RCSCRIPT ${myservice}\"" 40 print "echo \"RCSCRIPT ${myservice}\"" >> (SVCDIR "/depcache")
41 print "" 41 print "" >> (SVCDIR "/depcache")
42 print "echo \"MTIME " mtime "\"" >> (SVCDIR "/depcache")
43 print "" >> (SVCDIR "/depcache")
42} 44}
43 45
44function print_header2() { 46function print_header2(mtime) {
45 print "(" 47 print "(" >> (SVCDIR "/depcache")
46 print " # Get settings for rc-script ..." 48 print " # Get settings for rc-script ..." >> (SVCDIR "/depcache")
47 print " [ -e /etc/conf.d/basic ] && source /etc/conf.d/basic" 49 print " [ -e /etc/conf.d/basic ] && source /etc/conf.d/basic" >> (SVCDIR "/depcache")
48 print "" 50 print "" >> (SVCDIR "/depcache")
49 print " [ -e \"/etc/conf.d/${myservice}\" ] && source \"/etc/conf.d/${myservice}\"" 51 print " [ -e \"/etc/conf.d/${myservice}\" ] && source \"/etc/conf.d/${myservice}\"" >> (SVCDIR "/depcache")
50 print "" 52 print "" >> (SVCDIR "/depcache")
51 print " [ -e /etc/conf.d/net ] && \\" 53 print " [ -e /etc/conf.d/net ] && \\" >> (SVCDIR "/depcache")
52 print " [ \"${myservice%%.*}\" = \"net\" ] && \\" 54 print " [ \"${myservice%%.*}\" = \"net\" ] && \\" >> (SVCDIR "/depcache")
53 print " [ \"${myservice##*.}\" != \"${myservice}\" ] && source /etc/conf.d/net" 55 print " [ \"${myservice##*.}\" != \"${myservice}\" ] && source /etc/conf.d/net" >> (SVCDIR "/depcache")
54 print "" 56 print "" >> (SVCDIR "/depcache")
55 print " [ -e /etc/rc.conf ] && source /etc/rc.conf" 57 print " [ -e /etc/rc.conf ] && source /etc/rc.conf" >> (SVCDIR "/depcache")
56 print "" 58 print "" >> (SVCDIR "/depcache")
57 print " depend() {" 59 print " depend() {" >> (SVCDIR "/depcache")
58 print " return 0" 60 print " return 0" >> (SVCDIR "/depcache")
59 print " }" 61 print " }" >> (SVCDIR "/depcache")
60 print "" 62 print "" >> (SVCDIR "/depcache")
61} 63}
62 64
63function print_end() { 65function print_end() {
64 print "" 66 print "" >> (SVCDIR "/depcache")
65 print " depend" 67 print " depend" >> (SVCDIR "/depcache")
66 print ")" 68 print ")" >> (SVCDIR "/depcache")
67 print "" 69 print "" >> (SVCDIR "/depcache")
68} 70}
69 71
70BEGIN { 72BEGIN {
71 73
72 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 }
73 82
74 pipe = "ls /etc/init.d/*" 83 pipe = "ls /etc/init.d/*"
75 while ((pipe | getline tmpstring) > 0) 84 while ((pipe | getline tmpstring) > 0)
76 scripts = scripts " " tmpstring 85 scripts = scripts " " tmpstring
77 close(pipe) 86 close(pipe)
80 89
81 # Make sure that its a file we are working with, 90 # Make sure that its a file we are working with,
82 # and do not process scripts, source or backup files. 91 # and do not process scripts, source or backup files.
83 for (x in TMPRCSCRIPTS) 92 for (x in TMPRCSCRIPTS)
84 if (((isfile(TMPRCSCRIPTS[x])) || (islink(TMPRCSCRIPTS[x]))) && 93 if (((isfile(TMPRCSCRIPTS[x])) || (islink(TMPRCSCRIPTS[x]))) &&
85 (TMPRCSCRIPTS[x] !~ /((\.(sh|c|bak))|\~)$/)) { 94 (TMPRCSCRIPTS[x] !~ /((\.(c|bak))|\~)$/)) {
86 95
87 RCCOUNT++ 96 RCCOUNT++
88 97
89 RCSCRIPTS[RCCOUNT] = TMPRCSCRIPTS[x] 98 RCSCRIPTS[RCCOUNT] = TMPRCSCRIPTS[x]
90 } 99 }
98 107
99 for (count = 1;count <= RCCOUNT;count++) { 108 for (count = 1;count <= RCCOUNT;count++) {
100 109
101 MYFNR = 1 110 MYFNR = 1
102 MYFILENAME = RCSCRIPTS[count] 111 MYFILENAME = RCSCRIPTS[count]
112 STAT_DATA[1] = 1
103 113
104 while (((getline < (RCSCRIPTS[count])) > 0) && (!NEXTFILE)) { 114 while (((getline < (RCSCRIPTS[count])) > 0) && (!NEXTFILE)) {
105 115
106 # If line start with a '#' and is the first line 116 # If line start with a '#' and is the first line
107 if (($0 ~ /^[[:space:]]*#/) && (MYFNR == 1)) { 117 if (($0 ~ /^[[:space:]]*#/) && (MYFNR == 1)) {
108 118
109 # Remove any spaces and tabs 119 # Remove any spaces and tabs
110 gsub(/[[:space:]]+/, "") 120 gsub(/[[:space:]]+/, "")
111 121
112 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 "\"")
113 133
114 ISRCSCRIPT = 1 134 ISRCSCRIPT = 1
115 print_header1() 135 print_header1(STAT_DATA["mtime"])
116 } else { 136 } else {
117 137
118 NEXTFILE = 1 138 NEXTFILE = 1
119 continue 139 continue
120 } 140 }
127 if ($0 ~ /depend[[:space:]]*\(\)/) { 147 if ($0 ~ /depend[[:space:]]*\(\)/) {
128 148
129 GOTDEPEND = 1 149 GOTDEPEND = 1
130 150
131 print_header2() 151 print_header2()
132 print " # Actual depend() function ..." 152 print " # Actual depend() function ..." >> (SVCDIR "/depcache")
133 } 153 }
134 154
135 # We have the depend function... 155 # We have the depend function...
136 if (GOTDEPEND) { 156 if (GOTDEPEND) {
137 157
145 SBCOUNT += gsub(/{/, "{") 165 SBCOUNT += gsub(/{/, "{")
146 166
147 # Make sure depend() contain something, else bash 167 # Make sure depend() contain something, else bash
148 # errors out (empty function). 168 # errors out (empty function).
149 if ((SBCOUNT > 0) && (COUNT == 0)) 169 if ((SBCOUNT > 0) && (COUNT == 0))
150 print " \treturn 0" 170 print " \treturn 0" >> (SVCDIR "/depcache")
151 171
152 # Print the depend() function 172 # Print the depend() function
153 print " " $0 173 print " " $0 >> (SVCDIR "/depcache")
154 174
155 # If COUNT=0, and SBCOUNT>0, it means we have read 175 # If COUNT=0, and SBCOUNT>0, it means we have read
156 # all matching '{' and '}' for depend(), so stop. 176 # all matching '{' and '}' for depend(), so stop.
157 if ((SBCOUNT > 0) && (COUNT == 0)) { 177 if ((SBCOUNT > 0) && (COUNT == 0)) {
158 178

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

  ViewVC Help
Powered by ViewVC 1.1.20