| 1 | ############################################################################### | ||
| 2 | package Acme::Buckaroo; | ||
| 3 | ############################################################################### | ||
| 4 | # | ||
| 5 | # Acme::Buckaroo.pm | ||
| 6 | # | ||
| 7 | ############################################################################### | ||
| 8 | # | ||
| 9 | # Author: Kevin J. Rice | ||
| 10 | # Buffalo Grove, IL | ||
| 11 | # http://www.JustAnyone.com | ||
| 12 | # | ||
| 13 | ############################################################################### | ||
| 14 | # | ||
| 15 | # NOTE: For Module Comments, see bottom of this file for POD documentation. | ||
| 16 | # | ||
| 17 | # Version Information: | ||
| 18 | # | ||
| 19 | # 1.01 Kevin J. Rice June 11th, 2002 | ||
| 20 | # Submitted to CPAN. | ||
| 21 | # 1.02 Kevin J. Rice June 13th, 2002 | ||
| 22 | # Fixed "bug" in POD documentation, in response to bug #741 in the | ||
| 23 | # cpan but tracking database (see http://rt.cpan.org) | ||
| 24 | # | ||
| 25 | ############################################################################### | ||
| 26 | |||
| 27 | use 5.006; | ||
| 28 | use strict; | ||
| 29 | use warnings; | ||
| 30 | |||
| 31 | require Exporter; | ||
| 32 | |||
| 33 | our @ISA = qw(Exporter); | ||
| 34 | our %EXPORT_TAGS = ( 'all' => [ ] ); | ||
| 35 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | ||
| 36 | our @EXPORT = (); | ||
| 37 | our $VERSION = '1.02'; | ||
| 38 | |||
| 39 | ############################################################################### | ||
| 40 | # IF YOU WANT TO TURN ON DEBUG MODE | ||
| 41 | # (and thus see lots of logging lines that explain how things are happening | ||
| 42 | # as they happen), set debug_mode = 1. | ||
| 43 | # If you do, you'll need either: | ||
| 44 | # (1) Perl 5.6 (to get Data::Dumper by default), or | ||
| 45 | # (2) to have Data::Dumper already installed. | ||
| 46 | # Data::Dumper is a very, very handy module, but it wasn't in the default Perl | ||
| 47 | # installation until (I think) Perl 5.6. Perl 5.005 usually don't have it. | ||
| 48 | # Look on CPAN.ORG for Data::Dumper if you don't have it. | ||
| 49 | ############################################################################### | ||
| 50 | my $debug_mode = 0; | ||
| 51 | print("starting script...\n") if $debug_mode; | ||
| 52 | |||
| 53 | if ($debug_mode) | ||
| 54 | { | ||
| 55 | use Data::Dumper; | ||
| 56 | } | ||
| 57 | else | ||
| 58 | { | ||
| 59 | # sub Dumper { return(""); } | ||
| 60 | } | ||
| 61 | |||
| 62 | my $header = "Buckaroo Banzai Across The Eigth Dimension " x 2 . "\n"; | ||
| 63 | |||
| 64 | ############################################################################### | ||
| 65 | # this translation array is just for fun, but also for debugging so you can see | ||
| 66 | # how characters are encoded as they are encoded. | ||
| 67 | # | ||
| 68 | # If you try a new encoding method, use this one and you'll be able to see if | ||
| 69 | # characters are encoded and decoded correctly. | ||
| 70 | |||
| 71 | my @xlate_array1 = (qw( | ||
| 72 | 000q 001q 002q 003q 004q 005q 006q 007q 008q 009q | ||
| 73 | 010q 011q 012q 013q 014q 015q 016q 017q 018q 019q | ||
| 74 | 020q 021q 022q 023q 024q 025q 026q 027q 028q 029q | ||
| 75 | 030q 031q 032q 033q 034q 035q 036q 037q 038q 039q | ||
| 76 | 040q 041q 042q 043q 044q 045q 046q 047q 048q 049q | ||
| 77 | 050q 051q 052q 053q 054q 055q 056q 057q 058q 059q | ||
| 78 | 060q 061q 062q 063q 064q 065q 066q 067q 068q 069q | ||
| 79 | 070q 071q 072q 073q 074q 075q 076q 077q 078q 079q | ||
| 80 | 080q 081q 082q 083q 084q 085q 086q 087q 088q 089q | ||
| 81 | 090q 091q 092q 093q 094q 095q 096q 097q 098q 099q | ||
| 82 | 100q 101q 102q 103q 104q 105q 106q 107q 108q 109q | ||
| 83 | 110q 111q 112q 113q 114q 115q 116q 117q 118q 119q | ||
| 84 | 120q 121q 122q 123q 124q 125q 126q 127q 128q 129q | ||
| 85 | 130q 131q 132q 133q 134q 135q 136q 137q 138q 139q | ||
| 86 | 140q 141q 142q 143q 144q 145q 146q 147q 148q 149q | ||
| 87 | 150q 151q 152q 153q 154q 155q 156q 157q 158q 159q | ||
| 88 | 160q 161q 162q 163q 164q 165q 166q 167q 168q 169q | ||
| 89 | 170q 171q 172q 173q 174q 175q 176q 177q 178q 179q | ||
| 90 | 180q 181q 182q 183q 184q 185q 186q 187q 188q 189q | ||
| 91 | 190q 191q 192q 193q 194q 195q 196q 197q 198q 199q | ||
| 92 | 200q 201q 202q 203q 204q 205q 206q 207q 208q 209q | ||
| 93 | 210q 211q 212q 213q 214q 215q 216q 217q 218q 219q | ||
| 94 | 220q 221q 222q 223q 224q 225q 226q 227q 228q 229q | ||
| 95 | 230q 231q 232q 233q 234q 235q 236q 237q 238q 239q | ||
| 96 | 240q 241q 242q 243q 244q 245q 246q 247q 248q 249q | ||
| 97 | 250q 251q 252q 253q 254q )); | ||
| 98 | |||
| 99 | my @xlate_array = ( | ||
| 100 | "Aggie Guerard Rodgers", "Alan Howarth", "Alan Oliney", "Alexandra Leviloff", "Anne Thompson", "Anthony Milch", | ||
| 101 | "Arne Schulze", "Artie Duncan", "Arties Artery", "Baby Bang", "Bari Dreiband-Burman", "Beverly Bernacki", | ||
| 102 | "Bill Cobb", "Bill Henderson", "Billy Travers", "Billy Vera", "Black Lectroid", "Blue Blazer Irregulars", | ||
| 103 | "Bodifications", "Bones Howe", "Brian Ralph", "Bruce McBroom", "Bryan Denegal", "Dan Hedaya", "Dan Lupovitz", | ||
| 104 | "Dan Roth", "David Blitstein", "David E. Campbell", "David Gross", "David P. Newell", "David R. Hardberger", | ||
| 105 | "David Schwartz", "Buckaroo Banzai", "Defense Sec. McKinley", "Penny Priddy", "Dry LA aqueduct", | ||
| 106 | "Eighth dimension", "Ellen Barkin", "Future Begins Tomorrow", "Girl Named John", "Hanoi Xan", | ||
| 107 | "Hong Kong Cavaliers", "Hydraulic Watermelon", "Jeff Goldblum", "John Balook", "John Bigboote", | ||
| 108 | "John Lithgow", "John Smallberries", "John Ya Ya", "Lectoid", "Monkey Boy", "Neurosurgeon", | ||
| 109 | "NoNoNo Dont Tugonthat", "Nomatterwhereyougo thereyouare", "Nuclear Physicst", "Oscillation Overthruster", | ||
| 110 | "Perfect Tommy", "Peter Weller", "Pinky Carruthers", "Planet 10", "President Widmark", "Prof Toichi Hikita", | ||
| 111 | "Rawhide", "Red Lectroids", "Reno Nevada", "Sandra Banzai", "Scooter Lindley", "Sidney Zwibel", "Smolensk USSR", | ||
| 112 | "Thermopod", "Truncheon Bomber", "W.D. Richter", "Yakov Smirnoff", "Yoyodyne Propulsion Systems", "Carl Lumbly", | ||
| 113 | "Cash for lithium", "Casper Lindley", "Cheryl Bloch", "Chris Casady", "Chris Collins", "Christopher Keith", | ||
| 114 | "Christopher Lloyd", "Chuck Cooper", "Clancy Brown", "Colette Emanuel", "Comic Book Hero", "Crying of Lot 49", | ||
| 115 | "Damon Hines", "Dena Fischer", "Dennis E. Jones", "Dennis Schultz", "Duck Hunter Bubba", "Duck Hunter Burt", | ||
| 116 | "Earl Mac Rauch", "Doctor Emilio Lizardo", "Tom Cranham", "Ron Gress", "New Jersey", "Sam Minsky", | ||
| 117 | "Doreen A. Dixon", "Eddie Marks", "Edward Morey", "Eric Guaglione", "Erik L. Nelson", "Francine Lembi", | ||
| 118 | "Frank James Sparks", "Fred Iguchi", "Fred J. Koenekamp", "Gary Bisig", "Gary Daigler", "Gary Hellerstein", | ||
| 119 | "Gary Hymes", "General Catburd", "George Bowers", "George Stokes", "Gerald Peterson", "Glenn Campbell", | ||
| 120 | "Gordon Ecker Jr.", "Greenlite", "Greg Mires", "Gregg C. Rudloff", "Gregory Jein", "Grovers Mills", "H. Bud Otto", | ||
| 121 | "Henry Millar", "Hoyt Yeatman", "J. Michael Riva", "Jacqueline Zietlow", "James Belohovek", "James Hagedorn", | ||
| 122 | "James Keane", "James M. McCann", "James Rosin", "James Saito", "Jamie Lee Curtis", "Jane Marla Robbins", | ||
| 123 | "Jane Schwartz Jaffe", "Jerry Lewis hope2carrion", "Jerry Segal", "Jessie Lawrence Ferguson", "Joan Rowe", | ||
| 124 | "John Bracken", "John David Ashton", "John Emdall", "John Gant", "John Gomez", "John Murray", "John O'Connor", | ||
| 125 | "John Parker", "John Roesch", "John Scheele", "John T. Reitz", "John T. VanVliet", "John Valuk", "John Vigran", | ||
| 126 | "John Walter Davis", "Jonathan Banks", "Judi Rosner", "Judith Herman", "Justin De Rosa", "Kathryn Newbrough Sommer", | ||
| 127 | "Katterli Frauenfelder", "Keith Shartle", "Kenneth Karman", "Kenneth Magee", "Kent Perkins", "Kevin Rodney Sullivan", | ||
| 128 | "Kolodny Brothers", "Larry Fallick", "Laura Harrington", "Layne Bourgoyne", "Leonard Gaines", "Leslie Ekker", | ||
| 129 | "Lewis Smith", "Linda DeScenna", "Linda Fleisher", "Linda Henrikson", "Lord John Whorfin", "M. James Arnett", | ||
| 130 | "Mariclare Costello", "Mark Freund", "Mark Homer", "Mark Stetson", "Masado Banzai", "Matt Clark", "Matthew Mires", | ||
| 131 | "Mic Rodgers", "Michael Bigelow", "Michael Boddicker", "Michael Evje", "Michael G. Nathanson", "Michael Hosch", | ||
| 132 | "Michael L. Fink", "Michael Neale", "Michael Runyard", "Michael Santoro", "Mike De Luna", "Mister Wizard", | ||
| 133 | "Mrs. E. Johnson", "Neil Canton", "Peggy Priddy", "Pepe Serna", "Peter Kuran", "Phone Phreakers", "R.J. Robertson", | ||
| 134 | "Radar Blazer", "Radford Polinsky", "Raye Birk", "Reed Morgan", "Richard Carter", "Richard L. Thompson", | ||
| 135 | "Richard Marks", "Rick Heinrichs", "Rick Taylor", "Robert Gray", "Robert Hummer", "Robert Ito", | ||
| 136 | "Robert Michael Steloff", "Robert Wilcox", "Roberto Terminelli", "Robin Dean Leyden", "Rocco Gioffre", | ||
| 137 | "Rock star", "Ronald Lacey", "Rosalind Cash", "Rug Sucker", "Sal Orefice", "Samurai", "Scott Beattie", | ||
| 138 | "Scott Squires", "Selma Brown", "Senator Cunningham", "Sherman Labby", "Sidney Beckerman", "Stephen Dane", | ||
| 139 | "Stephen Robinette", "Steve Burg", "Steve Grumette", "Steve Hellerstein", "Steve LaPorte", "Terry Liebling", | ||
| 140 | "Thomas Hollister", "Thomas Pynchon", "Thomas R. Polizzi", "Tom Southwell", "Tommy J. Huff", "Tony Rivetti", | ||
| 141 | "Vincent Schiavelli", "Virginia L. Randolph", "Wayne Fitzgerald", "William G. Clevenger", | ||
| 142 | "William L. Hayward", "William Reilly", "William Traylor"); | ||
| 143 | |||
| 144 | # global variables. Don't use these at home, boys and girls! | ||
| 145 | # semi-seriously, I should put these into a calling function, but it's such a bother. | ||
| 146 | |||
| 147 | my %xlate_2_hash = (); | ||
| 148 | my %xlate_from_hash = (); | ||
| 149 | |||
| 150 | |||
| 151 | ############################################################################### | ||
| 152 | |||
| 153 | sub translate | ||
| 154 | { | ||
| 155 | # receives the string of the entire perl script after 'use Acme::Buckaroo'. | ||
| 156 | |||
| 157 | my $in_string = shift; | ||
| 158 | |||
| 159 | my $out = ""; | ||
| 160 | $out = Dumper($in_string); | ||
| 161 | print("Instring=>>$out<<\n") if $debug_mode; | ||
| 162 | |||
| 163 | my @in_array = split(//, $in_string); | ||
| 164 | $out = Dumper(@in_array); | ||
| 165 | print("in_array=>>$out<<\n") if $debug_mode; | ||
| 166 | |||
| 167 | my $i = 0; | ||
| 168 | my @temparray = (); | ||
| 169 | foreach my $thischar (@in_array) | ||
| 170 | { | ||
| 171 | # translate each character into it's ascii value. | ||
| 172 | my $num = unpack("c", $thischar); | ||
| 173 | # change that ascii value into a string from the array... | ||
| 174 | my $newchar = $xlate_array[$num]; | ||
| 175 | print("char=>>$thischar<<, num=>>$num<<, newchar=>>$newchar<<\n") if $debug_mode; | ||
| 176 | print("char=>>%s<<, num=>>%s<<, newchar=>>%s<<\n", $thischar, $num, $newchar) if $debug_mode; | ||
| 177 | push(@temparray, "$newchar"); | ||
| 178 | $i++; | ||
| 179 | if ($i > 3) | ||
| 180 | { | ||
| 181 | push(@temparray, "\n"); | ||
| 182 | $i = 0; | ||
| 183 | } | ||
| 184 | } | ||
| 185 | |||
| 186 | my $out_string = $header . join("\t", @temparray) . "\n"; | ||
| 187 | print("out_string=>>$out_string<<\n") if $debug_mode; | ||
| 188 | return $out_string; | ||
| 189 | |||
| 190 | } | ||
| 191 | |||
| 192 | ################################################################################ | ||
| 193 | # Normalize is called to convert the text to perl again from the encoded version. | ||
| 194 | # | ||
| 195 | |||
| 196 | sub normalize | ||
| 197 | { | ||
| 198 | my $in_string = shift;; | ||
| 199 | |||
| 200 | $in_string =~ s/^$header//g; | ||
| 201 | |||
| 202 | print("normalize, got in_string>>$in_string<<\n") if $debug_mode; | ||
| 203 | |||
| 204 | my %revhash = (); | ||
| 205 | my $counter = 0; | ||
| 206 | foreach my $this_elem (@xlate_array) | ||
| 207 | { | ||
| 208 | $revhash{$this_elem} = $counter++; | ||
| 209 | } | ||
| 210 | |||
| 211 | $in_string =~ s/\t\n/\t/g; | ||
| 212 | $in_string =~ s/\t+/\t/g; | ||
| 213 | my @in_array = split(/[\t]/, $in_string); | ||
| 214 | my $in_array_dump = Dumper(@in_array); | ||
| 215 | print("in_array_dump=>>$in_array_dump<<\n") if $debug_mode; | ||
| 216 | |||
| 217 | my @translate_array = (); | ||
| 218 | my $this_elem = ""; | ||
| 219 | $counter = 1; | ||
| 220 | foreach $this_elem (@in_array) | ||
| 221 | { | ||
| 222 | if (!($this_elem)) { print("Found undefined elem, counter=$counter.\n"); $counter++; next; } | ||
| 223 | my $ascii_num = $xlate_2_hash{$this_elem} || 0; | ||
| 224 | my $to_char = pack("c", $ascii_num); | ||
| 225 | printf("Normalized >>%s<<, ascii_num=>>%s<<, char=>>%s<<, counter=>>%s<<\n", $this_elem, $ascii_num, $to_char, $counter) if $debug_mode; | ||
| 226 | push(@translate_array, $to_char); | ||
| 227 | $counter++; | ||
| 228 | } | ||
| 229 | |||
| 230 | my $outtext = join('', @translate_array); | ||
| 231 | print("Converted back to text=>>$outtext<<\n") if $debug_mode; | ||
| 232 | |||
| 233 | return("$outtext"); | ||
| 234 | |||
| 235 | } | ||
| 236 | |||
| 237 | ############################################################################### | ||
| 238 | |||
| 239 | sub has_wordchars | ||
| 240 | { | ||
| 241 | |||
| 242 | my $in_string = shift; | ||
| 243 | my $retval = 0; | ||
| 244 | |||
| 245 | print("In has_wordchars\n") if $debug_mode; | ||
| 246 | |||
| 247 | if ($in_string =~ /\s/) | ||
| 248 | { | ||
| 249 | return $in_string; | ||
| 250 | } | ||
| 251 | else | ||
| 252 | { | ||
| 253 | return 0; | ||
| 254 | } | ||
| 255 | } | ||
| 256 | |||
| 257 | ############################################################################### | ||
| 258 | |||
| 259 | sub starts_with_header | ||
| 260 | { | ||
| 261 | |||
| 262 | my $in_string = shift; | ||
| 263 | my $retval = 0; | ||
| 264 | |||
| 265 | print("In starts_with_header\n") if $debug_mode; | ||
| 266 | |||
| 267 | if ($in_string =~ /^$header/) | ||
| 268 | { | ||
| 269 | return $in_string; | ||
| 270 | } | ||
| 271 | else | ||
| 272 | { | ||
| 273 | return 0; | ||
| 274 | } | ||
| 275 | |||
| 276 | } | ||
| 277 | |||
| 278 | ############################################################################### | ||
| 279 | |||
| 280 | sub import | ||
| 281 | { | ||
| 282 | |||
| 283 | my $first = shift; # name of module, in this case "Buckaroo.pm" | ||
| 284 | my $source_filename = $0; # name of file called from (if test.pl does a 'use Acme::Buckaroo;' then this will be "test.pl") | ||
| 285 | |||
| 286 | print("Starting \"Buckaroo\" process...\n") if $debug_mode; | ||
| 287 | |||
| 288 | # set up some hashes to go to/from encoding scheme. | ||
| 289 | my $i = 0; | ||
| 290 | foreach my $this_elem (@xlate_array) | ||
| 291 | { | ||
| 292 | $xlate_2_hash{$this_elem} = $i; | ||
| 293 | $xlate_from_hash{$i} = $this_elem; | ||
| 294 | $i++; | ||
| 295 | } | ||
| 296 | |||
| 297 | if (!(open(FILE_HANDLE, "<$source_filename"))) | ||
| 298 | { | ||
| 299 | print("Can't Buckaroo again on '$0'\n"); | ||
| 300 | exit; | ||
| 301 | } | ||
| 302 | else | ||
| 303 | { | ||
| 304 | #comment this out if you don't care. | ||
| 305 | print("Past open... ") if $debug_mode; | ||
| 306 | } | ||
| 307 | |||
| 308 | #read entire file in as a string. | ||
| 309 | my @file_array = <FILE_HANDLE>; | ||
| 310 | my $file_array_dump = Dumper(@file_array); | ||
| 311 | print("file_array_dump=>>$file_array_dump<<") if $debug_mode; | ||
| 312 | |||
| 313 | my $file_string = join("", @file_array); | ||
| 314 | |||
| 315 | # elim anything before the 'use Acme::Buckaroo; line. | ||
| 316 | $file_string =~ s/use\s*Acme::Buckaroo\s*;\s*\n//; | ||
| 317 | |||
| 318 | print("Filestring=>>$file_string<<\n") if $debug_mode; | ||
| 319 | |||
| 320 | # no clue why we do this. Anyone know? | ||
| 321 | #local $SIG{__WARN__} = \&has_wordchars; | ||
| 322 | |||
| 323 | if ( (has_wordchars($file_string) ) && | ||
| 324 | (!(starts_with_header($file_string))) ) | ||
| 325 | { | ||
| 326 | if (!(open(FILE_HANDLE, ">$0"))) | ||
| 327 | { | ||
| 328 | print("Cannot Buckaroo '$0'\n"); | ||
| 329 | exit; | ||
| 330 | } | ||
| 331 | print("past open2...") if $debug_mode; | ||
| 332 | print(FILE_HANDLE "use Acme::Buckaroo;\n"); | ||
| 333 | my $result = translate($file_string); | ||
| 334 | print(FILE_HANDLE $result); | ||
| 335 | print("Done \"Buckaroo-ing!\n"); | ||
| 336 | } | ||
| 337 | else | ||
| 338 | { | ||
| 339 | print("normalizing...\n") if $debug_mode; | ||
| 340 | my $out_string = normalize($file_string); | ||
| 341 | print("out_string=>>$out_string<<\n") if $debug_mode; | ||
| 342 | my $outval = eval($out_string); | ||
| 343 | print("Outval returned: $outval\n") if $debug_mode; | ||
| 344 | if ($@) | ||
| 345 | { | ||
| 346 | print("Perl Error returned: $@\n"); | ||
| 347 | } | ||
| 348 | print("No eval error returned.\n") if $debug_mode; | ||
| 349 | } | ||
| 350 | |||
| 351 | print("Finishing...\n") if $debug_mode; | ||
| 352 | |||
| 353 | exit; | ||
| 354 | |||
| 355 | } | ||
| 356 | |||
| 357 | ############################################################################### | ||
| 358 | |||
| 359 | 1; | ||
| 360 | |||
| 361 | ############################################################################### | ||
| 362 | |||
| 363 | __END__ |