/[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 - (hide 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 azarah 1.7 # Copyright 1999-2003 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.11 # $Header: /home/cvsroot/gentoo-src/rc-scripts/src/awk/cachedepends.awk,v 1.10 2003/05/11 23:32:47 azarah Exp $
5 azarah 1.1
6     function print_start() {
7 azarah 1.10 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 azarah 1.1 }
34    
35 azarah 1.8 function print_header1() {
36 azarah 1.10 print "#*** " MYFILENAME " ***"
37     print ""
38     print "myservice=\"" MYFILENAME "\""
39     print "myservice=\"${myservice##*/}\""
40     print "echo \"RCSCRIPT ${myservice}\""
41     print ""
42 azarah 1.8 }
43    
44     function print_header2() {
45 azarah 1.10 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 azarah 1.1 }
62    
63     function print_end() {
64 azarah 1.10 print ""
65     print " depend"
66     print ")"
67     print ""
68 azarah 1.1 }
69    
70 azarah 1.3 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 azarah 1.5
92     if (RCCOUNT == 0) {
93     eerror("No scripts to process!")
94     exit 1
95     }
96 azarah 1.3
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 azarah 1.1
109 azarah 1.3 # Remove any spaces and tabs
110     gsub(/[[:space:]]+/, "")
111 azarah 1.1
112 azarah 1.3 if ($0 == "#!/sbin/runscript") {
113    
114     ISRCSCRIPT = 1
115 azarah 1.8 print_header1()
116 azarah 1.3 } else {
117    
118     NEXTFILE = 1
119     continue
120     }
121     }
122 azarah 1.1
123 azarah 1.3 # Filter out comments and only process if its a rcscript
124 azarah 1.9 if (($0 !~ /^[[:space:]]*#/) && (ISRCSCRIPT)) {
125 azarah 1.1
126 azarah 1.3 # If line contain 'depend()', set GOTDEPEND to 1
127 azarah 1.8 if ($0 ~ /depend[[:space:]]*\(\)/) {
128    
129 azarah 1.3 GOTDEPEND = 1
130 azarah 1.8
131     print_header2()
132 azarah 1.10 print " # Actual depend() function ..."
133 azarah 1.8 }
134 azarah 1.1
135 azarah 1.3 # We have the depend function...
136 azarah 1.9 if (GOTDEPEND) {
137 azarah 1.1
138 azarah 1.3 # Basic theory is that COUNT will be 0 when we
139     # have matching '{' and '}'
140     COUNT += gsub(/{/, "{")
141     COUNT -= gsub(/}/, "}")
142 azarah 1.1
143 azarah 1.3 # This is just to verify that we have started with
144     # the body of depend()
145     SBCOUNT += gsub(/{/, "{")
146 azarah 1.11
147     # Make sure depend() contain something, else bash
148     # errors out (empty function).
149     if ((SBCOUNT > 0) && (COUNT == 0))
150     print " \treturn 0"
151 azarah 1.1
152 azarah 1.3 # Print the depend() function
153 azarah 1.10 print " " $0
154 azarah 1.1
155 azarah 1.3 # 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 azarah 1.8 ISRCSCRIPT = 0
163 azarah 1.3
164     print_end()
165 azarah 1.8
166 azarah 1.3 NEXTFILE = 1
167     continue
168     }
169     }
170     }
171    
172     MYFNR++
173     }
174    
175     close(RCSCRIPTS[count])
176 azarah 1.1
177 azarah 1.3 NEXTFILE = 0
178 azarah 1.2
179 azarah 1.1 }
180     }
181    
182 azarah 1.3
183     # vim:ts=4

  ViewVC Help
Powered by ViewVC 1.1.20