Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2015
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 10.94 KB | None | 0 0
  1. ;--------------------------------------------
  2. ; irc2html [2004.04.18] by Andy Dufilie
  3. ;--------------------------------------------
  4. ; Website: http://www.cs.uml.edu/~adufilie/
  5. ;--------------------------------------------
  6.  
  7.  
  8. ; Change this alias if you want output files to go to a different directory or have different filenames.
  9. alias -l modify_output_filename {
  10.   var %directory = $nofile($1-)
  11.   var %file = $nopath($1-)
  12.  
  13.   ; replace invalid characters
  14.   %file = $mkfn(%file)
  15.  
  16.   ; remove "#"
  17.   %file = $remove(%file,$chr(35))
  18.  
  19.   ; make sure there's a character before the "."
  20.   if (.* iswm %file) %file = _ $+ %file
  21.  
  22.   ; replace char 160 (non-breaking space)
  23.   %file = $replace(%file,$chr(160),_)
  24.  
  25.   return %directory $+ %file
  26. }
  27.  
  28.  
  29. ; buffer conversion
  30. ; /buf2html [window]
  31. alias buf2html {
  32.   reset
  33.   if ($window($1-)) var %@ = $1-
  34.   else var %@ = $active
  35.   %i2h.buffermode = 1
  36.   if (%@ == status window) filter -swz @i2h
  37.   elseif (=* iswm %@) {
  38.     %i2h.buffermode = 0
  39.     savebuf %@ irc2html.tmp
  40.     loadbuf @i2h irc2html.tmp
  41.     .remove irc2html.tmp
  42.   }
  43.   else filter -wwz %@ @i2h
  44.   var %x = $line(@i2h,0)
  45.   while (%x) {
  46.     if ($line(@i2h,%x) == $chr(32)) dline @i2h %x
  47.     dec %x
  48.   }
  49.   var %t = %@ buffer
  50.   var %f = $mkfn(%@) $+ .html
  51.   var %outputfile = $i2h(%t,%f)
  52.   echo $colour(i) -q *** Done making %outputfile
  53.   ;run $shortfn(%outputfile)
  54. }
  55.  
  56. ; file conversion
  57. ; /log2html [file]
  58. alias log2html {
  59.   var %dll = 0
  60.   if ($1 == -dll) {
  61.     %dll = 1
  62.     tokenize 32 $2-
  63.   }
  64.   elseif ($1 == -mrc) {
  65.     %dll = 0
  66.     tokenize 32 $2-
  67.   }
  68.  
  69.   if ($isfile($1-)) var %log = $1-
  70.   elseif ($version < 5.8) var %log = $dir="Pick a .log" $shortfn($logdir*.log)
  71.   else var %log = $sfile($logdir*.log,Pick a .log)
  72.   if ($isfile(%log) == $false) {
  73.     if (%log) echo $colour(info) * /log2html: File doesn't exist: %log
  74.     return
  75.   }
  76.   if (*.log iswm %log) var %html = $left(%log,-3) $+ html
  77.   else var %html = %log $+ .html
  78.  
  79.   if (%dll) {
  80.     var %irc2html.dll = $findfile($scriptdir,irc2html.dll,1)
  81.     if ($isfile(%irc2html.dll) != $true) {
  82.       %irc2html.dll = $findfile($mircdir,irc2html.dll,1)
  83.       if ($isfile(%irc2html.dll) != $true) {
  84.         echo $colour(i) *** irc2html.dll is missing.
  85.         return
  86.       }
  87.     }
  88.  
  89.     ;filename $+ $cr $+ outfile?fontname?defaultfore?defaultback?rgb0?rgb1?rgb2?rgb3?rgb4?rgb5?rgb6?rgb7?rgb8?rgb9?rgb10?rgb11?rgb12?rgb13?rgb14?rgb15
  90.  
  91.     var %size = $window(@i2h).fontsize
  92.     if (%size < 0) %size = $right(%size,-1) $+ pt
  93.     else %size = %size $+ px
  94.  
  95.     window -h @irc2html
  96.     var %n = 0, %params = %log $+ $cr $+ %html $+ ? $+ $window(@i2h).font $+ ;font-size: $+ %size $+ ? $+ $colour(normal) $+ ? $+ $colour(background)
  97.     close -@ @irc2html
  98.     while (%n < 16) {
  99.       %params = %params $+ ? $+ $colour(%n)
  100.       inc %n
  101.     }
  102.     var %outputfile = $dll(%irc2html.dll,irc2html,%params)
  103.   }
  104.   else {
  105.     reset
  106.     loadbuf @i2h $shortfn(%log)
  107.     var %title = $nopath(%log)
  108.     if (*.log iswm %title) %title = $left(%title,-4) log
  109.     var %outputfile = $i2h(%title,%html)
  110.     echo $colour(i) -q *** Done making %outputfile
  111.   }
  112.  
  113.   ;run $shortfn(%outputfile)
  114. }
  115.  
  116. ; clipboard conversion
  117. ; /cb2html
  118. alias cb2html {
  119.   reset
  120.   var %x = 1, %f = clipboard.html
  121.   while (%x <= $cb(0)) {
  122.     aline @i2h $iif(* iswm $cb(%x),$cb(%x),)
  123.     inc %x
  124.   }
  125.   var %outputfile = $i2h(Clipboard,%f)
  126.   echo $colour(i) -q *** Done making %outputfile
  127.   ;run %outputfile
  128. }
  129.  
  130. ; single line conversion (output to window)
  131. ; /irc2html <text>
  132. alias irc2html {
  133.   if (* !iswm $1-) return
  134.   if (* !iswm $window(@irc2html)) reset
  135.   close -@ @i2h
  136.   window -h @i2h
  137.   aline @i2h $1-
  138.   window -h @irc2html
  139.   var %x = $line(@irc2html,0)
  140.   if (</html> isin $line(@irc2html,%x)) dline @irc2html %x
  141.   i2h
  142.   window -aw @irc2html
  143. }
  144.  
  145. on *:close:@irc2html:unset %i2h.*
  146. alias -l reset {
  147.   close -@ @i2h @irc2html
  148.   unset %i2h.*
  149.   window -h @i2h
  150. }
  151. alias -l _rgb {
  152.   tokenize 44 $rgb($colour($1))
  153.   return $base($1,10,16,2) $+ $base($2,10,16,2) $+ $base($3,10,16,2)
  154. }
  155. ; $i2h(title,outfile) returns output file w/ quotes
  156. ; /i2h with no parameters is used for /irc2html single-line conversion
  157. alias -l i2h {
  158.   var %title = $1
  159.   var %outputfile = $modify_output_filename($2)
  160.   window -h @irc2html
  161.   var %ctime = $ctime, %x = 16
  162.   while (%x) {
  163.     dec %x
  164.     %i2h. [ $+ [ %x ] ] = $_rgb(%x)
  165.   }
  166.   if (* iswm %outputfile) || ($line(@irc2html,0) !isnum 1-) {
  167.     if (* iswm %outputfile) aline @irc2html <html><head><title> $+ %title $+ </title><style type="text/css"><!--
  168.     else aline @irc2html <html><head><title>irc2html</title><style type="text/css"><!--
  169.     var %size = $window(@i2h).fontsize
  170.     if (%size < 0) %size = $right(%size,-1) $+ pt
  171.     else %size = %size $+ px
  172.     aline @irc2html body{font-family: $+ $window(@i2h).font $+ ;font-size: $+ %size $+ ;color: $+ %i2h. [ $+ [ $colour(no) ] ] $+ ;background-color: $+ %i2h. [ $+ [ $colour(b) ] ] $+ ;}
  173.     aline @irc2html --></style></head><body>
  174.   }
  175.   %x = $line(@i2h,0)
  176.   while (%x) {
  177.     %i2h.ecolor = $line(@i2h,1).color
  178.     convert $line(@i2h,1)
  179.     dline @i2h 1
  180.     editbox -a %x
  181.     dec %x
  182.   }
  183.   editbox -a
  184.   if (* iswm %outputfile) {
  185.     aline @irc2html </body></html><!-- $duration($calc($ctime -%ctime)) -->
  186.     unset %i2h.*
  187.     savebuf @irc2html " $+ %outputfile $+ "
  188.     close -@ @irc2html
  189.   }
  190.   else aline @irc2html </body></html>
  191.   close -@ @i2h
  192.   return %outputfile
  193. }
  194. alias -l classname {
  195.   var %bold = $1, %underline = $2, %fcolor = $3, %bcolor = $4, %reverse = $5, %bg = $6
  196.   var %class = $iif(%underline,$iif(%bold,W,X),$iif(%bold,Y,Z))
  197.   if (%reverse != 1) {
  198.     if (%class == Z) %class =
  199.     %class = %class $+ $chr($calc($asc(A) + %fcolor))
  200.     if (%bcolor != %bg) %class = %class $+ $chr($calc($asc(A) + %bcolor))
  201.   }
  202.   return %class
  203. }
  204. alias -l classdef {
  205.   var %class = $1, %bold = $2, %underline = $3, %fcolor = $4, %bcolor = $5, %reverse = $6, %ncolor = $7, %bg = $8
  206.   var %def = . $+ %class $+ {font-weight: $+ $iif(%bold,bold,normal)
  207.   %def = %def $+ ;text-decoration: $+ $iif(%underline,underline,none)
  208.   %def = %def $+ ;color: $+ %i2h. [ $+ [ $iif(%reverse,%bg,%fcolor) ] ]
  209.   %def = %def $+ ;background-color: $+ %i2h. [ $+ [ $iif(%reverse,%ncolor,%bcolor) ] ]
  210.   %def = %def $+ ;}
  211.   return %def
  212. }
  213. ; convert one line of text
  214. alias -l convert {
  215.   if (* !iswm $1-) return
  216.   var %nbsp = $chr(160), %b = , %r = , %u = , %k = , %o = , %text = $replace($1-,&,&amp;,<,&lt;,>,&gt;) $+ %o, %ncolor = $colour(no), %ecolor = %ncolor, %bg = $colour(b), %etag = 0
  217.   if ($version >= 6.14) && (%i2h.buffermode) %ecolor = %i2h.ecolor
  218.   elseif ($1 == *) {
  219.     if (/*: iswm $2) || ($2-3 == Invalid format:) || ($2-4 == Too many parameters:) || ($2-3 == Invalid parameters:) %ecolor = $colour(i)
  220.     elseif (Break: iswm $2) %ecolor = $colour(c)
  221.     else %ecolor = $colour(a)
  222.   }
  223.   elseif (-?*- iswm $1) var %ecolor = $colour(not)
  224.   elseif (-> [*] iswm $1-2) var %ecolor = $colour(c)
  225.   elseif ($1 == ***) var %ecolor = $colour(i)
  226.   if (%ecolor !isnum) %ecolor = %ncolor
  227.   if (%ecolor != %ncolor) %etag = 1
  228.   var %btext = $replace(%text,%k,%b,%r,%b,%u,%b,%o,%b), %codenum = 1, %numcodes = $count(%btext,%b), %nextcodepos, %codepos = 1, %prevcodepos, %nocomma, %class, %baseclass, %prevclass
  229.   var %char, %bold = 0, %underline = 0, %reverse = 0, %fcolor = %ecolor, %bcolor = %bg, %aline, %length = $len(%text), %tcolor, %inside_span = 0
  230.   %baseclass = $classname(%bold,%underline,%ecolor,%bcolor,%reverse,%bg)
  231.   %class = %baseclass
  232.   if (%etag) {
  233.     %aline = <span class= $+ %class $+ >
  234.     ; define class if not already defined
  235.     if (%i2h.c [ $+ [ %class ] ] != 1) {
  236.       iline @irc2html 2 $classdef(%class,%bold,%underline,%fcolor,%bcolor,%reverse,%ncolor,%bg)
  237.       %i2h.c [ $+ [ %class ] ] = 1
  238.     }
  239.   }
  240.   while (%codenum <= %numcodes) {
  241.     %prevcodepos = %codepos
  242.     %nextcodepos = $pos(%btext,%b,%codenum)
  243.     %codepos = %nextcodepos
  244.  
  245.     ; read control codes
  246.     while ($mid(%btext,%codepos,1) == %b) {
  247.       inc %codenum
  248.       %char = $mid(%text,%codepos,1)
  249.       if (%char == %k) {
  250.         inc %codepos
  251.         %nocomma = 1
  252.         %tcolor =
  253.         while ($mid(%text,%codepos,1) isnum) {
  254.           %tcolor = $ifmatch
  255.           inc %codepos
  256.           if ($mid(%text,%codepos,1) isnum) {
  257.             %tcolor = %tcolor $+ $ifmatch
  258.             inc %codepos
  259.           }
  260.           if (%tcolor == 99) %tcolor = %ecolor
  261.           if (%fcolor == 99) %fcolor = %bcolor
  262.           %tcolor = $calc(%tcolor % 16)
  263.           %fcolor = $calc(%fcolor % 16)
  264.           if (%nocomma) %fcolor = %tcolor
  265.           else %bcolor = %tcolor
  266.           if (%nocomma) && ($mid(%text,%codepos,1) == ,) {
  267.             %nocomma = 0
  268.             inc %codepos
  269.           }
  270.           else break
  271.         }
  272.         if (* !iswm %tcolor) {
  273.           %fcolor = %ecolor
  274.           %bcolor = %bg
  275.         }
  276.       }
  277.       else {
  278.         if (%char == %b) %bold = 1 - %bold
  279.         elseif (%char == %u) %underline = 1 - %underline
  280.         elseif (%char == %r) %reverse = 1 - %reverse
  281.         elseif (%char == %o) {
  282.           %fcolor = %ecolor
  283.           %bcolor = %bg
  284.           %bold = 0
  285.           %underline = 0
  286.           %reverse = 0
  287.         }
  288.         inc %codepos
  289.       }
  290.     }
  291.     ; done reading control codes
  292.  
  293.     %prevclass = %class
  294.     %class = $classname(%bold,%underline,%fcolor,%bcolor,%reverse,%bg)
  295.  
  296.     ; append text since last control code
  297.     if (%prevcodepos < %nextcodepos) {
  298.       var %" = " $+ $mid(%text,%prevcodepos,$calc(%nextcodepos -%prevcodepos)) $+ "
  299.       if (" * " iswm %") %aline = %aline $+ %nbsp $+ $right($left(%",-2),-2) $+ %nbsp
  300.       elseif (" * iswm %") %aline = %aline $+ %nbsp $+ $right($left(%",-1),-2)
  301.       elseif (* " iswm %") %aline = %aline $+ $right($left(%",-2),-1) $+ %nbsp
  302.       else %aline = %aline $+ $right($left(%",-1),-1)
  303.     }
  304.  
  305.     ; break out of loop if this the end of the line
  306.     if (%codepos > %length) break
  307.  
  308.     ; check if span class needs changing
  309.     if (%class != %prevclass) {
  310.       ; close off previous tag if needed
  311.       if (%inside_span) {
  312.         %aline = %aline $+ </span>
  313.         %inside_span = 0
  314.       }
  315.       ; begin new tag if needed
  316.       if (%class != %baseclass) {
  317.         ; define class if not already defined
  318.         if (%i2h.c [ $+ [ %class ] ] != 1) {
  319.           iline @irc2html 2 $classdef(%class,%bold,%underline,%fcolor,%bcolor,%reverse,%ncolor,%bg)
  320.           %i2h.c [ $+ [ %class ] ] = 1
  321.         }
  322.         ; output text & new span tag
  323.         aline @irc2html %aline $+ <span
  324.         %aline = class= $+ %class $+ >
  325.         ; remember that we're inside a span tag
  326.         %inside_span = 1
  327.       }
  328.     }
  329.   }
  330.  
  331.   ; close previous span tag if needed
  332.   if (%inside_span) {
  333.     %aline = %aline $+ </span>
  334.     %inside_span = 0
  335.   }
  336.   ; add remaining text if needed
  337.   if (%codepos <= %length) %aline $+ $mid(%text,%codepos)
  338.   ; close outer span tag if needed
  339.   if (%etag) %aline = %aline $+ </span>
  340.   ; output with line break
  341.   aline @irc2html %aline $+ <br>
  342. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement