/[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.2 - (hide annotations) (download)
Sun Nov 17 19:33:01 2002 UTC (17 years, 7 months ago) by azarah
Branch: MAIN
Changes since 1.1: +7 -1 lines
some sanity checks

1 azarah 1.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 azarah 1.2 # $Header: /home/cvsroot/gentoo-src/rc-scripts/src/awk/cachedepends.awk,v 1.1 2002/11/17 17:11:09 azarah Exp $
5 azarah 1.1
6     BEGIN {
7    
8     extension("/lib/rcscripts/filefuncs.so", "dlload")
9    
10     DEPCACHE=SVCDIR "/depcache"
11    
12     unlink(DEPCACHE)
13    
14     print_start()
15     }
16    
17     function print_start() {
18     print "need() {" >> (DEPCACHE)
19     print " echo \"NEED $*\"; return 0" >> (DEPCACHE)
20     print "}" >> (DEPCACHE)
21     print "" >> (DEPCACHE)
22     print "use() {" >> (DEPCACHE)
23     print " echo \"USE $*\"; return 0" >> (DEPCACHE)
24     print "}" >> (DEPCACHE)
25     print "" >> (DEPCACHE)
26     print "before() {" >> (DEPCACHE)
27     print " echo \"BEFORE $*\"; return 0" >> (DEPCACHE)
28     print "}" >> (DEPCACHE)
29     print "" >> (DEPCACHE)
30     print "after() {" >> (DEPCACHE)
31     print " echo \"AFTER $*\"; return 0" >> (DEPCACHE)
32     print "}" >> (DEPCACHE)
33     print "" >> (DEPCACHE)
34     print "provide() {" >> (DEPCACHE)
35     print " echo \"PROVIDE $*\"; return 0" >> (DEPCACHE)
36     print "}" >> (DEPCACHE)
37     print "" >> (DEPCACHE)
38     }
39    
40     function print_header() {
41     print "#*** " FILENAME " ***" >> (DEPCACHE)
42     print "" >> (DEPCACHE)
43     print "myservice=\"" FILENAME "\"" >> (DEPCACHE)
44     print "myservice=\"${myservice##*/}\"" >> (DEPCACHE)
45     print "echo \"RCSCRIPT ${myservice}\"" >> (DEPCACHE)
46     print "" >> (DEPCACHE)
47     print "depend() {" >> (DEPCACHE)
48     print " return 0" >> (DEPCACHE)
49     print "}" >> (DEPCACHE)
50     print "" >> (DEPCACHE)
51     }
52    
53     function print_end() {
54     print "" >> (DEPCACHE)
55     print "depend" >> (DEPCACHE)
56     print "" >> (DEPCACHE)
57     }
58    
59     {
60     # If line start with a '#' and is the first line
61     if (($0 ~ /^[[:space:]]*#/) && (FNR == 1)) {
62    
63     # Remove any spaces and tabs
64     gsub(/[[:space:]]+/, "")
65    
66     if ($0 == "#!/sbin/runscript") {
67     ISRCSCRIPT = 1
68    
69     print_header()
70     } else
71     nextfile
72 azarah 1.2
73     # Do not process scripts, source or backup files
74     if (FILENAME ~ /((\.(sh|c|bak))|\~)$/)
75     nextfile
76 azarah 1.1 }
77    
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 azarah 1.2
111     nextfile
112 azarah 1.1 }
113     }
114     }
115     }
116    
117     END {
118     close (DEPCACHE)
119     }
120    

  ViewVC Help
Powered by ViewVC 1.1.20