Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » Finished MUD Scripts
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Mon Jul 01, 2002 1:06 am   

ANSI to HTML converter
 
This scripts converts a file with ANSI control codes into an HTML file. It is not really fast, but I'll keep looking into what optimizations can be made and will continue making updates to the script here.

Usage is:
ansiToHtml inputFile outputFile [defCol] [defBgCol]

where inptuFile and outFile are the names of the files (within the zMUD directory) to be read from and written to respectively. defCol is the default text color and defBgCol is the default background color. Both of these are optional and default to a value of 1 and 16 respectively. Their values must be between 1 and 16. For more information on the numbering of colors you can use:
ansiToHtmlColors

Anyway, here it is (instead of copying directly into the command line, this script should be placed in a text file and the imported from inside zMUD):

#CLASS {Converter}
#ALIAS ansiToHtml {
#VARIABLE textCol %if( %3, %3, 1)
#VARIABLE backCol %if( %4, %4, 16)
#IF ((%null( %1)) or (%null( %2))) {
#SAY No output or input file.
#ABORT 1
}
#IF ((@textCol > 16) or (@textCol < 1) or (@backCol > 16) or (@backCol < 1)) {
#SAY Color invalid.
#ABORT 1
}
#VARIABLE progress 0
#VARIABLE open ""
#VARIABLE bright 0
#VARIABLE invert 0
#VARIABLE filesize 0
#FILE 1 %1
#GAG
#VARIABLE filesize %filesize( 1)
#FILE 2 %2
#GAG
#SAY Converting %1 from ANSI to HTML. - %secs
#VARIABLE progress 0
#GAUGE conv Converting... @progress 100 90 "" "blue" "green"
#WRITE 2 "<HTML>"
#VARIABLE color @textCol
#VARIABLE bgcolor @backCol
#WRITE 2 %concat( "<BODY TEXT=#", %item( @colors, @textCol), " STYLE='background-color:#", %item( @colors, @backCol), ";'>")
#WRITE 2 "<PRE>"
#LOOP @filesize {
#VARIABLE line %read( 1)
#VARIABLE newline ""
#VARIABLE pos 1
#VARIABLE substr @line
#WHILE (%pos( %char( 27), @substr)) {
#VARIABLE newline %concat( @newline, %copy( @line, @pos, %pos( %char( 27), @substr) - 1))
#ADD pos %pos( %char( 27), @substr))
#VARIABLE char %copy( @line, @pos, 1)
#VARIABLE sequence @char
#WHILE (!%ismember( @char, @endCodes)) {
#ADD pos 1
#VARIABLE char %copy( @line, @pos, 1)
#VARIABLE sequence %concat( @sequence, @char)
}
#IF (@char = "m") {
#VARIABLE sequence %replace( @sequence, ";", "|")
#VARIABLE sequence %leftback( @sequence, 1)
#VARIABLE sequence %right( @sequence, 1)
#FORALL @sequence {#IF (%ismember( %i, @validCodes)) {#EXECUTE %concat( "code", %i)}}
}
#ADD pos 1
#VARIABLE substr %copy( @line, @pos, %len( @line) - @pos + 1)
}
#VARIABLE newline %concat( @newline, @substr)
#WRITE 2 {@newline}
#VARIABLE progress %eval( (%i * 100) / @filesize)
}
#UNBUTTON conv
#GAG
#FORALL @open {#WRITE 2 "</SPAN>"}
#WRITE 2 "</PRE>"
#WRITE 2 "</BODY>"
#WRITE 2 "</HTML>"
#SAY %1 converted from ANSI to HTML - %secs
#SAY Output file - %2
#CLOSE 2
#GAG
#CLOSE 1
#GAG
}
#ALIAS ansiToHtmlColors {
#SHOW Valid colors are:
#SHOW 1 - %ansi( 0)black
#SHOW 2 - %ansi( 4)red
#SHOW 3 - %ansi( 2)green
#SHOW 4 - %ansi( 6)yellow
#SHOW 5 - %ansi( 1)blue
#SHOW 6 - %ansi( 5)magenta
#SHOW 7 - %ansi( 3)cyan
#SHOW 8 - %ansi( 7)white
#SHOW 9 - %ansi( 8)bright black
#SHOW 10 - %ansi( 12)bright red
#SHOW 11 - %ansi( 10)bright green
#SHOW 12 - %ansi( 14)bright yellow
#SHOW 13 - %ansi( 9)bright blue
#SHOW 14 - %ansi( 13)bright magenta
#SHOW 15 - %ansi( 11)bright cyan
#SHOW 16 - %ansi( 15)bright white
}
#ALIAS setbgcol {
#IF (%ismember( "5", @open)) {
#VARIABLE reopen ""
#LOOP %ismember( "5", @open),%numitems( @open) {
#VARIABLE newline %concat( @newline, "</SPAN>")
#ADDITEM reopen %item( @open, %i)
}
#DELNITEM reopen 1
#DELNITEM open %ismember( "5", @open)
reopen @reopen
}
#VARIABLE newline %concat( @newline, "<SPAN STYLE='background-color:#", %item( @colors, @bgcolor), ";'>")
#ADDITEM open 5
}
#ALIAS setcol {
#IF (%ismember( "4", @open)) {
#VARIABLE reopen ""
#LOOP %ismember( "4", @open),%numitems( @open) {
#VARIABLE newline %concat( @newline, "</SPAN>")
#ADDITEM reopen %item( @open, %i)
}
#DELNITEM reopen 1
#DELNITEM open %ismember( "4", @open)
reopen @reopen
}
#VARIABLE newline %concat( @newline, "<SPAN STYLE='color:#", %item( @colors, @color), ";'>")
#ADDITEM open 4
}
#ALIAS reopen {#FORALL %1 {#CASE %i {
#NOOP Open underline
#VARIABLE newline %concat( @newline, "<SPAN STYLE='text-decoration:underline;'~>")
} {
#NOOP Open blink
#VARIABLE newline %concat( @newline, "<SPAN STYLE='text-decoration:blink;'~>")
} {
#NOOP Open hidden
#VARIABLE newline %concat( @newline, "<SPAN STYLE='visibility:hidden;'>")
} {
#NOOP Open color
#VARIABLE newline %concat( @newline, "<SPAN STYLE='color:", %item( @colors, @color), ";'>")
} {
#NOOP Open bgcolor
#VARIABLE newline %concat( @newline, "<SPAN STYLE='background-color:", %item( @colors, @bgcolor), ";'>")
}}}
#ALIAS code0 {
#FORALL @open {#VARIABLE newline %concat( @newline, "</SPAN>")}
#VARIABLE open ""
#VARIABLE invert 0
#IF (@textCol > 8) {#VARIABLE bright 1} {#VARIABLE bright 0}
#VARIABLE color @textCol
#VARIABLE bgcolor @backCol
}
#ALIAS code2 {#IF (@bright) {
#VARIABLE bright 0
#IF (@invert) {
#IF (!@bgcolor) {#IF (@backCol < 9) {#VARIABLE bgcolor %eval( @backCol + 8)} {#VARIABLE color @backCol}} {#ADD bgcolor 8}
setbgcol
} {
#IF (!@color) {#IF (@textCol < 9) {#VARIABLE color %eval( @textCol + 8)} {#VARIABLE color @textCol}} {#ADD color 8}
setcol
}
}}
#ALIAS code1 {#IF (!@bright) {
#VARIABLE bright 1
#IF (@invert) {
#IF (!@bgcolor) {#IF (@backCol < 9) {#VARIABLE bgcolor %eval( @backCol + 8)} {#VARIABLE color @backCol}} {#ADD bgcolor 8}
setbgcol
} {
#IF (!@color) {#IF (@textCol < 9) {#VARIABLE color %eval( @textCol + 8)} {#VARIABLE color @textCol}} {#ADD color 8}
setcol
}
}}
#ALIAS code4 {#IF (!%ismember( "1", @open)) {
#VARIABLE newline %concat( @newline, "<SPAN STYLE='text-decoration=underline;'>")
#ADDITEM open 1
}}
#ALIAS code5 {#IF (!%ismember( "2", @open)) {
#VARIABLE newline %concat( @newline, "<SPAN STYLE='text-decoration=blink;'>")
#ADDITEM open 2
}}
#ALIAS code7 {
#VARIABLE invert %bitxor( @invert, 1)
#VARIABLE temp ""
#VARIABLE temp @color
#VARIABLE color @bgcolor
#VARIABLE bgcolor @temp
setbgcol
setcol
}
#ALIAS code8 {#IF (!%ismember( "3", @open)) {
#VARIABLE newline %concat( @newline, "<SPAN STYLE='visibility:hidden;'>")
#ADDITEM open 3
}}
#ALIAS code30 {#IF (@invert) {#IF ((@bgcolor <> 1) or (@bgcolor <> 9)) {
#IF (@bright) {#VARIABLE bgcolor 9} {#VARIABLE bgcolor 1}
setbgcol
}} {#IF ((@color <> 1) or (@color <> 9)) {
#IF (@bright) {#VARIABLE color 9} {#VARIABLE color 1}
setcol
}}}
#ALIAS code31 {#IF (@invert) {#IF ((@bgcolor <> 2) or (@bgcolor <> 10)) {
#IF (@bright) {#VARIABLE bgcolor 10} {#VARIABLE bgcolor 2}
setbgcol
}} {#IF ((@color <> 2) or (@color <> 10)) {
#IF (@bright) {#VARIABLE color 10} {#VARIABLE color 2}
setcol
}}}
#ALIAS code32 {}
#ALIAS code33 {#IF (@invert) {#IF ((@bgcolor <> 4) or (@bgcolor <> 12)) {
#IF (@bright) {#VARIABLE bgcolor 12} {#VARIABLE bgcolor 4}
setbgcol
}} {#IF ((@color <> 4) or (@color <> 12)) {
#IF (@bright) {#VARIABLE color 12} {#VARIABLE color 4}
setcol
}}}
#ALIAS code34 {#IF (@invert) {#IF ((@bgcolor <> 5) or (@bgcolor <> 13)) {
#IF (@bright) {#VARIABLE bgcolor 13} {#VARIABLE bgcolor 5}
setbgcol
}} {#IF ((@color <> 5) or (@color <> 13)) {
#IF (@bright) {#VARIABLE color 13} {#VARIABLE color 5}
setcol
}}}
#ALIAS code35 {#IF (@invert) {#IF ((@bgcolor <> 6) or (@bgcolor <> 14)) {
#IF (@bright) {#VARIABLE bgcolor 14} {#VARIABLE bgcolor 6}
setbgcol
}} {#IF ((@color <> 6) or (@color <> 14)) {
#IF (@bright) {#VARIABLE color 14} {#VARIABLE color 6}
setcol
}}}
#ALIAS code36 {#IF (@invert) {#IF ((@bgcolor <> 7) or (@bgcolor <> 15)) {
#IF (@bright) {#VARIABLE bgcolor 15} {#VARIABLE bgcolor 7}
setbgcol
}} {#IF ((@color <> 7) or (@color <> 15)) {
#IF (@bright) {#VARIABLE color 15} {#VARIABLE color 7}
setcol
}}}
#ALIAS code37 {#IF (@invert) {#IF ((@bgcolor <> 8) or (@bgcolor <> 16)) {
#IF (@bright) {#VARIABLE bgcolor 16} {#VARIABLE bgcolor 8}
setbgcol
}} {#IF ((@color <> 8) or (@color <> 16)) {
#IF (@bright) {#VARIABLE color 16} {#VARIABLE color 8}
setcol
}}}
#ALIAS code40 {#IF (@invert) {#IF (@color <> 1) {
#VARIABLE color 1
setcol
}} {#IF (@bgcolor <> 1) {
#VARIABLE bgcolor 1
setbgcol
}}}
#ALIAS code41 {#IF (@invert) {#IF (@color <> 2) {
#VARIABLE color 2
setcol
}} {#IF (@bgcolor <> 2) {
#VARIABLE bgcolor 2
setbgcol
}}}
#ALIAS code42 {#IF (@invert) {#IF (@color <> 3) {
#VARIABLE color 3
setcol
}} {#IF (@bgcolor <> 3) {
#VARIABLE bgcolor 3
setbgcol
}}}
#ALIAS code43 {#IF (@invert) {#IF (@color <> 4) {
#VARIABLE color 4
setcol
}} {#IF (@bgcolor <> 4) {
#VARIABLE bgcolor 4
setbgcol
}}}
#ALIAS code44 {#IF (@invert) {#IF (@color <> 5) {
#VARIABLE color 5
setcol
}} {#IF (@bgcolor <> 5) {
#VARIABLE bgcolor 5
setbgcol
}}}
#ALIAS code45 {#IF (@invert) {#IF (@color <> 6) {
#VARIABLE color 6
setcol
}} {#IF (@bgcolor <> 6) {
#VARIABLE bgcolor 6
setbgcol
}}}
#ALIAS code47 {#IF (@invert) {#IF (@color <> 8) {
#VARIABLE color 8
setcol
}} {#IF (@bgcolor <> 8) {
#VARIABLE bgcolor 8
setbgcol
}}}
#ALIAS code46 {#IF (@invert) {#IF (@color <> 7) {
#VARIABLE color 7
setcol
}} {#IF (@bgcolor <> 7) {
#VARIABLE bgcolor 7
setbgcol
}}}
#ALIAS code50 {
code1
code30
}
#ALIAS code51 {
code1
code31
}
#ALIAS code52 {
code1
code32
}
#ALIAS code53 {
code1
code33
}
#ALIAS code54 {
code1
code34
}
#ALIAS code55 {
code1
code35
}
#ALIAS code56 {
code1
code36
}
#ALIAS code57 {
code1
code37
}
#ALIAS code60 {code30}
#ALIAS code61 {code34}
#ALIAS code62 {code32}
#ALIAS code63 {code36}
#ALIAS code64 {code31}
#ALIAS code65 {code35}
#ALIAS code66 {code33}
#ALIAS code67 {code37}
#ALIAS code68 {
code1
code30
}
#ALIAS code69 {
code1
code34
}
#ALIAS code70 {
code1
code32
}
#ALIAS code71 {
code1
code36
}
#ALIAS code72 {
code1
code31
}
#ALIAS code73 {
code1
code35
}
#ALIAS code74 {
code1
code33
}
#ALIAS code75 {
code1
code37
}
#ALIAS code76 {code30}
#VARIABLE endCodes {c|n|R|h|l|H|A|B|C|f|s|u|r|D|M|g|K|J|i|p|m}
#VARIABLE colors {000000|880000|008800|888800|000088|880088|008888|C0C0C0|888888|FF0000|00FF00|FFFF00|0000FF|FF00FF|00FFFF|FFFFFF}
#VARIABLE validCodes {0|1|2|4|5|7|8|30|31|32|33|34|35|36|37|40|41|42|43|44|45|46|47|50|51|52|53|54|55|56|57|60|61|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76}
#CLASS 0

Edited on 7/1/2002 - Updated the script to make it faster.

Edited on 7/1/2002 - Added support for zMUD-specific ANSI codes. The converted file should now look exactly as zMUD displays it. This also made it a little bit slower than the previous update today, since now some codes are being converted instead of ignored. However, it still faster than the one before that. Also, I removed some stuff left from the debugging process.

Kjata
Reply with quote
OmegaDeus
Apprentice


Joined: 14 Sep 2005
Posts: 121

PostPosted: Mon Sep 26, 2005 8:25 pm   hrm
 
i'm running into a huge problem with this script. it takes out all the ansi codes from my logs sure, but the color comes out really f***ing jacked up. I mean really jacked. http://www.stansfieldvn.com/damage_script.html if you wanna see what it's doing for yourself.
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Tue Sep 27, 2005 4:16 am   
 
I would take a look at using the HTML logger plugin which I believe can be found in the plugins section of the downloads
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » Finished MUD Scripts All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net