3 # Wouter Teepe (wouter@teepe.com)
5 # A simple configure script to fix the ri_once issue
8 ############################################################
12 # sets the xterm color (only used when $debug=1)
17 } else {if ($t == 1) {
18 print "\e[0m\e[31;43m";
19 } else {if ($t == 2) {
20 print "\e[0m\e[30;42m";
21 } else {if ($t == 3) {
22 print "\e[0m\e[33;41m";
26 # prints arg1 with color arg2 (only used when $debug=1)
31 $pos = index($line, "\n");
38 $str = substr($line, 0, $pos);
41 $line = substr($line, $pos+1);
47 # print arg1 to term or $out
56 # parse php code fore include's and require's
59 while ($phpcode ne "") {
60 $inc = index($phpcode, 'include');
61 $req = index($phpcode, 'require');
62 if (($req == -1) or (($inc != -1) and ($inc < $req))) {
68 &myprint
(substr($phpcode, 0, $index), 1);
70 $r = ord(substr($phpcode, $index-1, 1));
75 if ((($r >= 125) and ($r <= 255)) or ($r == ord("_")) or
76 (($r >= ord("A")) and ($r <= ord("Z"))) or
77 (($r >= ord("a")) and ($r <= ord("z"))) or
78 (($r >= ord("1")) and ($r <= ord("9")))) {
82 $o = index($phpcode, '(', $index);
84 $p = substr($phpcode, $index+7);
86 $p = substr($phpcode, $index+7, $o-$index-7);
88 if (!($p =~ /^\s*$/)) {
94 &myprint
('/* \'_once\' Added by ri_once */ ', 3);
96 &myprint
(substr($phpcode, $index, 7), 1);
100 $lastbyte = ord('e');
101 $phpcode = substr($phpcode, $index+7);
103 &myprint
($phpcode, 1);
109 # parse php block for comments and strings
111 while ($htmlcomment ne "") {
112 $len = length($htmlcomment);
113 $doublequote = index($htmlcomment, '"');
114 $singlequote = index($htmlcomment, "'");
115 $pound = index($htmlcomment, '#');
116 $slashslash = index($htmlcomment, '//');
117 $slashstar = index($htmlcomment, '/*');
118 if ($doublequote == -1) { $doublequote = $len; }
119 if ($singlequote == -1) { $singlequote = $len; }
120 if ($pound == -1) { $pound = $len; }
121 if ($slashslash == -1) { $slashslash = $len; }
122 if ($slashstar == -1) { $slashstar = $len; }
124 $pos = $doublequote; $end = '"'; $sl = 1; $el = 1;
125 if ($pos > $singlequote) { $pos = $singlequote; $end = "'"; }
126 if ($pos > $pound) { $pos = $pound; $end = "\n"; }
127 if ($pos > $slashslash) { $pos = $slashslash; $end = "\n"; $sl = 2; }
128 if ($pos > $slashstar) { $pos = $slashstar; $end = '*/'; $sl = 2; $el = 2; }
131 $phpcode = substr($htmlcomment, 0, $pos);
132 $rest = substr($htmlcomment, $pos);
133 $eoc = index($rest, $end, $sl);
134 if (($end = '"') or ($end = "'")) {
135 while (($eoc > 0) and (substr($rest, $eoc-1, 1) eq '\\')) {
136 $eoc = index($rest, $end, $eoc+1);
139 if ($eoc == -1) { $eoc = length($rest); }
140 $phpcomment = substr($rest, 0, $eoc+$el);
141 $htmlcomment = substr($rest, $eoc+$el);
143 &myprint
($phpcomment, 2);
145 $phpcode = $htmlcomment;
152 # parse html file for php blocks
154 while ($text ne '') {
155 $index = index($text, '<?');
157 $html = substr($text, 0, $index+2);
158 $text = substr($text, $index+2);
160 $index = index($text, '?>');
161 if ($index == -1) { $index = length($text); }
162 $htmlcomment = substr($text, 0, $index);
163 $text = substr($text, $index);
164 $type = substr($htmlcomment, 0, 3);
165 if (uc($type) eq "PHP") {
167 $htmlcomment = substr($htmlcomment, 3);
168 } else { if (substr($htmlcomment, 0, 1) eq '=') {
170 &myprint
('php /* \'=\' Modified to \'php blah echo\'by ri_once */ echo ', 3);
171 $htmlcomment = substr($htmlcomment, 1);
174 &myprint
('php /* \'php\' Added by ri_once */', 3);
188 open (FILE
, '<'.$file);
194 while ($line = <FILE
>) {
205 $out = "<?php /* Modified at $mod places by ri_once */ ?>\n" . $out;
206 # $mode = (stat($file))[2];
207 rename($file, $file.'.before_ri_once');
208 open (FILE
, '>'.$file);
211 # chmod($stats[2], $file);
216 # process a directory recursively
225 opendir(DIR
, $dirname) or die "can't opendir $dirname: $!";
227 while (defined($file = readdir(DIR
))) {
228 @files[$i++] = $file;
231 while (defined($file = @files[$i++])) {
232 next if $file =~ /^\.\.?$/;
233 $full = $dirname.'/'.$file;
234 # print "found: $full\n";
236 # print "doing dir: $full\n";
238 } else { if ($file =~ /.*\.php$/) {
239 # print "doing file: $full\n";