#!/usr/bin/perl # #BBS2ANSI v1.0 - 06/20/1999 #By Leonard Richardson leonardr@ucla.edu # #BBS2ANSI converts Wildcat!-style .BBS display screens to ANSI display #screens. It handles color codes and will fill in BBS status codes #with operator-provided information. It produces files that are valid #ANSI, but probably not as compact as they could be. Since I wrote #this as a frontend to iCE's convansi program, I am not terribly #concerned about this. # #This code is licensed under the terms of the GNU General Public #License, version 2, or, at your option, any later version. #If ignore_blink is set, then BBS2ANSI will throw away all blink #information in the BBS file when converting. This is useful when #using convansi, which treats blinking incorrectly. $ignore_blink = 1; ######################################################################## #Here is ANSI color information. $ESCAPE = "["; $ANSI_BOLD = 1; $ANSI_NORMAL = 0; $ANSI_BLINK = 5; $ANSI_FG_BLACK = 30; $ANSI_FG_RED=31; $ANSI_FG_GREEN=32; $ANSI_FG_YELLOW=33; $ANSI_FG_BLUE=34; $ANSI_FG_MAGENTA=35; $ANSI_FG_CYAN=36; $ANSI_FG_WHITE=37; $ANSI_BG_BLACK=40; $ANSI_BG_RED=41; $ANSI_BG_GREEN=42; $ANSI_BG_YELLOW=43; $ANSI_BG_BLUE=44; $ANSI_BG_MAGENTA=45; $ANSI_BG_CYAN=46; $ANSI_BG_WHITE=47; #Arrays are arranged in ANSI color order: #0 black #1 blue #2 green #3 cyan #4 red #5 magenta #6 yellow #7 white @ansi_bg_colors = ( $ANSI_BG_BLACK, $ANSI_BG_BLUE, $ANSI_BG_GREEN, $ANSI_BG_CYAN, $ANSI_BG_RED, $ANSI_BG_MAGENTA, $ANSI_BG_YELLOW, $ANSI_BG_WHITE ); @ansi_fg_colors = ( $ANSI_FG_BLACK, $ANSI_FG_BLUE, $ANSI_FG_GREEN, $ANSI_FG_CYAN, $ANSI_FG_RED, $ANSI_FG_MAGENTA, $ANSI_FG_YELLOW, $ANSI_FG_WHITE ); ######################################################################## #Wildcat! has several special codes which fill in user information. #This associative array allows you to specify sample information to be #filled in when one of those codes is seen. # $SKIP = "SKIP"; %bbs_codes = ( "bbs" => "Da Warren BBS & Grill", "tuser" => "1024", "tcalls" => "29401", "tfile" => "1402", "first" => "Joe", "last" => "User", "user" => "JOE USER", "laston" => "Sammy Laston", "bdate" => "06/22/93", "phone" => "(805) 555-1212", "downs" => "42", "ups" => "69", "left" => "36", "date" => "06/22/96", "time" => "12:36 PM", "bell" => $SKIP, #There must be an escape sequence to ring the bell, but I can't find it. "cls" => $SKIP, "pause" => $SKIP, "enter" => $SKIP, "nopause" => $SKIP, "nostop" => $SKIP, ); ############################################################ foreach $file (@ARGV) { $blinking = 0; $new_file = "$file.ans"; $new_file =~ s/(.*)\.bbs/$1/; print "$file => $new_file\n"; open BBS, $file; open ANSI, ">$new_file"; while() { s/\@(.)(.)\@/convert_color_code(hex($1),hex($2))/ge; s/\@(\w+)\@/substitute_bbs_code($1)/ge; print ANSI $_; } close BBS; close ANSI; } sub substitute_bbs_code { ($code) = @_; $code = lc($code); if ($bbs_codes{$code} eq "") { print "ERROR: Can't substitute $code in $file. Ignoring.\n"; return $code; } elsif ($bbs_codes{$code} ne $SKIP) { return $bbs_codes{$code}; } } sub convert_color_code { ($backcolor, $forecolor) = @_; $ansi_code = $ESCAPE; if (high_bit_set($forecolor)) { $ansi_code .= "$ANSI_BOLD;"; $forecolor = mask_high_bit($forecolor); } else { $ansi_code .= "$ANSI_NORMAL;"; } if (high_bit_set($backcolor)) { if (!$ignore_blink) { $blinking = 1; $ansi_code .= "$ANSI_BLINK;"; } $backcolor = mask_high_bit($backcolor); } elsif ($blinking) { $blinking = 0; $ansi_code .= "$ANSI_NORMAL;"; } $new_bg = $ansi_bg_colors[$backcolor]; $new_fg = $ansi_fg_colors[$forecolor]; $ansi_code .= $new_bg . ";"; $ansi_code .= $new_fg . "m"; return $ansi_code; } sub high_bit_set { ($code) = @_; return ($code >= 8); } sub mask_high_bit { ($code) = @_; return ($code - 8); }