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

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

  ViewVC Help
Powered by ViewVC 1.1.20