/[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.5 - (show annotations) (download)
Mon Nov 18 15:15:08 2002 UTC (17 years, 7 months ago) by azarah
Branch: MAIN
Changes since 1.4: +6 -1 lines
add some checks

1 # Copyright 1999-2002 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.4 2002/11/18 13:07:02 azarah Exp $
5
6 function print_start() {
7 print "need() {" >> (DEPCACHE)
8 print " echo \"NEED $*\"; return 0" >> (DEPCACHE)
9 print "}" >> (DEPCACHE)
10 print "" >> (DEPCACHE)
11 print "use() {" >> (DEPCACHE)
12 print " echo \"USE $*\"; return 0" >> (DEPCACHE)
13 print "}" >> (DEPCACHE)
14 print "" >> (DEPCACHE)
15 print "before() {" >> (DEPCACHE)
16 print " echo \"BEFORE $*\"; return 0" >> (DEPCACHE)
17 print "}" >> (DEPCACHE)
18 print "" >> (DEPCACHE)
19 print "after() {" >> (DEPCACHE)
20 print " echo \"AFTER $*\"; return 0" >> (DEPCACHE)
21 print "}" >> (DEPCACHE)
22 print "" >> (DEPCACHE)
23 print "provide() {" >> (DEPCACHE)
24 print " echo \"PROVIDE $*\"; return 0" >> (DEPCACHE)
25 print "}" >> (DEPCACHE)
26 print "" >> (DEPCACHE)
27 }
28
29 function print_header() {
30 print "#*** " MYFILENAME " ***" >> (DEPCACHE)
31 print "" >> (DEPCACHE)
32 print "myservice=\"" MYFILENAME "\"" >> (DEPCACHE)
33 print "myservice=\"${myservice##*/}\"" >> (DEPCACHE)
34 print "echo \"RCSCRIPT ${myservice}\"" >> (DEPCACHE)
35 print "" >> (DEPCACHE)
36 print "depend() {" >> (DEPCACHE)
37 print " return 0" >> (DEPCACHE)
38 print "}" >> (DEPCACHE)
39 print "" >> (DEPCACHE)
40 }
41
42 function print_end() {
43 print "" >> (DEPCACHE)
44 print "depend" >> (DEPCACHE)
45 print "" >> (DEPCACHE)
46 }
47
48 BEGIN {
49
50 extension("/lib/rcscripts/filefuncs.so", "dlload")
51
52 pipe = "ls /etc/init.d/*"
53 while ((pipe | getline tmpstring) > 0)
54 scripts = scripts " " tmpstring
55 close(pipe)
56
57 split(scripts, TMPRCSCRIPTS)
58
59 # Make sure that its a file we are working with,
60 # and do not process scripts, source or backup files.
61 for (x in TMPRCSCRIPTS)
62 if ((isfile(TMPRCSCRIPTS[x])) &&
63 (TMPRCSCRIPTS[x] !~ /((\.(sh|c|bak))|\~)$/)) {
64
65 RCCOUNT++
66
67 RCSCRIPTS[RCCOUNT] = TMPRCSCRIPTS[x]
68 }
69
70 if (RCCOUNT == 0) {
71 eerror("No scripts to process!")
72 exit 1
73 }
74
75 DEPCACHE=SVCDIR "/depcache"
76
77 unlink(DEPCACHE)
78
79 print_start()
80
81 for (count = 1;count <= RCCOUNT;count++) {
82
83 MYFNR = 1
84 MYFILENAME = RCSCRIPTS[count]
85
86 while (((getline < (RCSCRIPTS[count])) > 0) && (!NEXTFILE)) {
87
88 # If line start with a '#' and is the first line
89 if (($0 ~ /^[[:space:]]*#/) && (MYFNR == 1)) {
90
91 # Remove any spaces and tabs
92 gsub(/[[:space:]]+/, "")
93
94 if ($0 == "#!/sbin/runscript") {
95
96 ISRCSCRIPT = 1
97 print_header()
98 } else {
99
100 NEXTFILE = 1
101 continue
102 }
103 }
104
105 # Filter out comments and only process if its a rcscript
106 if (($0 !~ /[[:space:]]*#/) && (ISRCSCRIPT == 1 )) {
107
108 # If line contain 'depend()', set GOTDEPEND to 1
109 if ($0 ~ /depend[[:space:]]*\(\)/)
110 GOTDEPEND = 1
111
112 # We have the depend function...
113 if (GOTDEPEND == 1) {
114
115 # Basic theory is that COUNT will be 0 when we
116 # have matching '{' and '}'
117 COUNT += gsub(/{/, "{")
118 COUNT -= gsub(/}/, "}")
119
120 # This is just to verify that we have started with
121 # the body of depend()
122 SBCOUNT += gsub(/{/, "{")
123
124 # Print the depend() function
125 print >> (DEPCACHE)
126
127 # If COUNT=0, and SBCOUNT>0, it means we have read
128 # all matching '{' and '}' for depend(), so stop.
129 if ((SBCOUNT > 0) && (COUNT == 0)) {
130
131 GOTDEPEND = 0
132 ISRCSCRIPT = 0
133 COUNT = 0
134 SBCOUNT = 0
135
136 print_end()
137
138 NEXTFILE = 1
139 continue
140 }
141 }
142 }
143
144 MYFNR++
145 }
146
147 close(RCSCRIPTS[count])
148
149 NEXTFILE = 0
150
151 }
152
153 close (DEPCACHE)
154 }
155
156
157 # vim:ts=4

  ViewVC Help
Powered by ViewVC 1.1.20