/[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.6 - (hide annotations) (download)
Mon Nov 25 22:24:08 2002 UTC (17 years, 7 months ago) by azarah
Branch: MAIN
Changes since 1.5: +2 -2 lines
import Adelie Cluster stuff

1 azarah 1.1 # Copyright 1999-2002 Gentoo Technologies, Inc.
2 azarah 1.4 # Distributed under the terms of the GNU General Public License v2
3 azarah 1.1 # Author: Martin Schlemmer <azarah@gentoo.org>
4 azarah 1.6 # $Header: /home/cvsroot/gentoo-src/rc-scripts/src/awk/cachedepends.awk,v 1.5 2002/11/18 15:15:08 azarah Exp $
5 azarah 1.1
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 azarah 1.3 print "#*** " MYFILENAME " ***" >> (DEPCACHE)
31 azarah 1.1 print "" >> (DEPCACHE)
32 azarah 1.3 print "myservice=\"" MYFILENAME "\"" >> (DEPCACHE)
33 azarah 1.1 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 azarah 1.3 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 azarah 1.5
70     if (RCCOUNT == 0) {
71     eerror("No scripts to process!")
72     exit 1
73     }
74 azarah 1.3
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 azarah 1.1
91 azarah 1.3 # Remove any spaces and tabs
92     gsub(/[[:space:]]+/, "")
93 azarah 1.1
94 azarah 1.3 if ($0 == "#!/sbin/runscript") {
95    
96     ISRCSCRIPT = 1
97     print_header()
98     } else {
99    
100     NEXTFILE = 1
101     continue
102     }
103     }
104 azarah 1.1
105 azarah 1.3 # Filter out comments and only process if its a rcscript
106 azarah 1.6 if (($0 !~ /^[[:space:]]*#/) && (ISRCSCRIPT == 1 )) {
107 azarah 1.1
108 azarah 1.3 # If line contain 'depend()', set GOTDEPEND to 1
109     if ($0 ~ /depend[[:space:]]*\(\)/)
110     GOTDEPEND = 1
111 azarah 1.1
112 azarah 1.3 # We have the depend function...
113     if (GOTDEPEND == 1) {
114 azarah 1.1
115 azarah 1.3 # Basic theory is that COUNT will be 0 when we
116     # have matching '{' and '}'
117     COUNT += gsub(/{/, "{")
118     COUNT -= gsub(/}/, "}")
119 azarah 1.1
120 azarah 1.3 # This is just to verify that we have started with
121     # the body of depend()
122     SBCOUNT += gsub(/{/, "{")
123 azarah 1.1
124 azarah 1.3 # Print the depend() function
125     print >> (DEPCACHE)
126 azarah 1.1
127 azarah 1.3 # 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 azarah 1.1
149 azarah 1.3 NEXTFILE = 0
150 azarah 1.2
151 azarah 1.1 }
152    
153     close (DEPCACHE)
154     }
155    
156 azarah 1.3
157     # vim:ts=4

  ViewVC Help
Powered by ViewVC 1.1.20