/[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.4 - (hide annotations) (download)
Mon Nov 18 13:07:02 2002 UTC (17 years, 9 months ago) by azarah
Branch: MAIN
Changes since 1.3: +2 -2 lines
change license

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.4 # $Header: /home/cvsroot/gentoo-src/rc-scripts/src/awk/cachedepends.awk,v 1.3 2002/11/18 09:02:26 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    
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    
83     # If line start with a '#' and is the first line
84     if (($0 ~ /^[[:space:]]*#/) && (MYFNR == 1)) {
85 azarah 1.1
86 azarah 1.3 # Remove any spaces and tabs
87     gsub(/[[:space:]]+/, "")
88 azarah 1.1
89 azarah 1.3 if ($0 == "#!/sbin/runscript") {
90    
91     ISRCSCRIPT = 1
92     print_header()
93     } else {
94    
95     NEXTFILE = 1
96     continue
97     }
98     }
99 azarah 1.1
100 azarah 1.3 # Filter out comments and only process if its a rcscript
101     if (($0 !~ /[[:space:]]*#/) && (ISRCSCRIPT == 1 )) {
102 azarah 1.1
103 azarah 1.3 # If line contain 'depend()', set GOTDEPEND to 1
104     if ($0 ~ /depend[[:space:]]*\(\)/)
105     GOTDEPEND = 1
106 azarah 1.1
107 azarah 1.3 # We have the depend function...
108     if (GOTDEPEND == 1) {
109 azarah 1.1
110 azarah 1.3 # Basic theory is that COUNT will be 0 when we
111     # have matching '{' and '}'
112     COUNT += gsub(/{/, "{")
113     COUNT -= gsub(/}/, "}")
114 azarah 1.1
115 azarah 1.3 # This is just to verify that we have started with
116     # the body of depend()
117     SBCOUNT += gsub(/{/, "{")
118 azarah 1.1
119 azarah 1.3 # Print the depend() function
120     print >> (DEPCACHE)
121 azarah 1.1
122 azarah 1.3 # 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 azarah 1.1
144 azarah 1.3 NEXTFILE = 0
145 azarah 1.2
146 azarah 1.1 }
147    
148     close (DEPCACHE)
149     }
150    
151 azarah 1.3
152     # vim:ts=4

  ViewVC Help
Powered by ViewVC 1.1.20