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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (show annotations) (download)
Wed May 21 08:00:55 2003 UTC (17 years, 1 month ago) by azarah
Branch: MAIN
Changes since 1.10: +6 -1 lines
bugfixes

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

  ViewVC Help
Powered by ViewVC 1.1.20