git @ Cat's Eye Technologies Corona-Realm-of-Magic / e682157
We don't really need these here... catseye 9 years ago
2 changed file(s) with 0 addition(s) and 214 deletion(s). Raw diff Collapse all Expand all
+0
-12
src/util/test.pl less more
0 while(1)
1 {
2 $d1 = int(rand(1)*9)+1;
3 $d2 = int(rand(1)*3)+1;
4 $b = ($d1 >= $d2);
5 $m++;
6 $s++ if $b;
7 $a = sprintf("%5.3f", $s/$m);
8 print "$d1 >= $d2 ? $b ! $m/$s = $a\n";
9 exit 0 if $m > 10000;
10 }
11
+0
-202
src/util/yaeolc.pl less more
0 #!/usr/local/bin/perl -w
1
2 # yaeolc.pl - Yet Another End Of Line Converter
3 # v2000.07.18 Chris Pressey, Cat's Eye Technologies
4
5 # Copyright (c)2000, Cat's Eye Technologies.
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 #
12 # Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 #
15 # Redistributions in binary form must reproduce the above copyright
16 # notice, this list of conditions and the following disclaimer in
17 # the documentation and/or other materials provided with the
18 # distribution.
19 #
20 # Neither name of Cat's Eye Technologies nor the names of its
21 # contributors may be used to endorse or promote products derived
22 # from this software without specific prior written permission.
23 #
24 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
25 # CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
26 # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 # DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
29 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
30 # OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
32 # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
33 # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
34 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 # POSSIBILITY OF SUCH DAMAGE.
37
38 # Why yaeolc.pl?
39 # - Need script to massage Befunge source files to sensible EOLs.
40 # - Need conversion for mounting MS-DOS partition under FreeBSD/Linux.
41 # - For both of these tasks it is extremely useful to have a script
42 # which just "readjusts" all text files in the current directory
43 # to the EOL convention which makes the most sense locally.
44
45 # How yaeolc.pl differs from other utilities like it:
46 # - if no file names are given, converts every file in the current dir
47 # - recurses into directories if -r switch is given
48 # - auto-detects file types - will not convert files which look like
49 # binary or directory files unless they're explicitly forced with -f
50 # - always converts files to what it considers the current native EOL
51 # - -crcrlf looks for and xlates the mangled marker 'CR CR LF' => EOL
52
53 # usage: [perl] yaeolc[.pl] [-f] [-q] [-r] [-crcrlf] {files}
54
55 # history:
56 # v0.7 Jul 17 2000 - hacked together in primary form.
57 # v2000.07.18 - added recursive operation into subdirs.
58 # - improved (GNUified) switches somewhat.
59
60 ### GLOBALS ###
61
62 my $switch = '';
63 my $force = 0;
64 my $crcrlf = 0;
65 my $quiet = 0;
66 my $recur = 0;
67
68 my $file = '';
69 my $count = 0;
70
71 ### SUBS ###
72
73 sub convert
74 {
75 my $file = shift;
76 my @char = ();
77 my $q; my $i;
78 open FILE, $file;
79 binmode FILE;
80 while (read(FILE, $q, 1))
81 {
82 push @char, ord($q);
83 }
84 close FILE;
85
86 $i = 0;
87 while ($i <= $#char)
88 {
89 if($char[$i] == 13) # Mac or MS-DOS EOL
90 {
91 if($char[$i+1] == 10) # MS-DOS EOL
92 {
93 $char[$i] = -2; $i++;
94 } else # Mac or Mangled EOL
95 {
96 if($char[$i+1] == 13 and $char[$i+2] == 10 and $crcrlf)
97 { # Mangled EOL
98 $char[$i] = -3; $i += 2;
99 } else # Mac EOL
100 {
101 $char[$i] = -1;
102 }
103 }
104 } elsif($char[$i] == 10) # Unix EOL
105 {
106 $char[$i] = -1;
107 }
108 $i++;
109 }
110
111 open FILE, ">$file"; # overwrite file
112 while (defined($q = shift @char))
113 {
114 if ($q < 0)
115 {
116 print FILE "\n";
117 if ($q == -2)
118 {
119 $q = shift @char; # ignore second char in EOL
120 }
121 elsif ($q == -3)
122 {
123 $q = shift @char; # ignore second and third chars
124 $q = shift @char;
125 }
126 } else
127 {
128 print FILE chr($q);
129 }
130 }
131 close FILE;
132 }
133
134 sub convertdir
135 {
136 my $dir = shift;
137 my $fh = shift;
138 my $file;
139 print "Processing directory: $dir\n";
140 opendir $fh, $dir;
141 while (defined($file = readdir $fh))
142 {
143 next if $file eq '..' or $file eq '.';
144 if (-d "$dir/$file")
145 {
146 convertdir("$dir/$file", "_$fh") if $recur;
147 next;
148 }
149 if(not -T "$dir/$file")
150 {
151 print "* $dir/$file does not look like a text file\n" if not $quiet;
152 next if not $force;
153 }
154 print "Converting $dir/$file...\n" if not $quiet;
155 convert "$dir/$file"; $count++;
156 }
157 closedir $fh;
158 }
159
160 ### MAIN ###
161
162 while (defined($ARGV[0]) and $ARGV[0] =~ /^\-\-?(\w+?)$/)
163 {
164 $switch = $1; shift @ARGV;
165 if ($switch eq 'f' or $switch eq 'force') { $force = 1 }
166 elsif ($switch eq 'q' or $switch eq 'quiet') { $quiet = 1 }
167 elsif ($switch eq 'r' or $switch eq 'recurse') { $recur = 1 }
168 elsif ($switch eq 'crcrlf') { $crcrlf = 1 }
169 else
170 {
171 die "Usage: [perl] yaeolc[.pl] [-q] [-f] [-r] [-crcrlf] {files}\n";
172 }
173 }
174
175 print "yaeolc.pl v2000.07.18 Chris Pressey, Cat's Eye Technologies\n" if not $quiet;
176
177 if (defined $ARGV[0])
178 {
179 while (defined $ARGV[0])
180 {
181 $file = shift @ARGV;
182 if (-d $file)
183 {
184 convertdir($file, 'DIR') if $recur;
185 next;
186 }
187 if(not -T $file)
188 {
189 print "* $file does not look like a text file\n" if not $quiet;
190 next if not $force;
191 }
192 print "Converting $file...\n" if not $quiet;
193 convert $file; $count++;
194 }
195 } else
196 {
197 convertdir('.', 'DIR');
198 }
199 print "Done processing, $count files converted.\n" if not $quiet;
200
201 ### END ###