use hkpcore; use Win32::OLE::Variant; my @words=qw/data xdata bit org equ set db dw ds end add addc subb inc dec mul div da anl orl xrl clr cpl rl rlc rr rrc swap mov movx movx push pop xch xchd clr setb cpl anl orl mov jc jnc jb jnb jbc acall lcall ret reti ajmp ljmp sjmp jmp jz jnz cjne djnz nop/; my $asm_prog_class ='asm_prog'; my $asm_line_class ='asm_line'; my $asm_command_class='asm_command'; my $asm_comment_class='asm_comment'; my $asm_bold ='asm_bold'; my $asm_under='asm_under'; my $asm_noita='asm_noita'; sub filt($$@){ my $want_struct=shift; my $progress=shift; my @lines=@_; my $res=''; my $reg; $reg=join '|',@words; $res.=<<HEAD if $want_struct; <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <style type='text/css'> body { } .$asm_prog_class { background-color: white; color: black; font-size: 10pt; font-family: "Courier New"; } .$asm_line_class { /* background-color: black; color: white; border: 1 solid white; */ } .$asm_command_class { font-weight: bold; } .$asm_comment_class { font-style: italic; } .$asm_bold { font-weight: bold; } .$asm_under { text-decoration: underline; } .$asm_noita { font-style: normal; } </style> <title>A '51 listing</title> </head> <body> HEAD $res.=<<PRE; <pre class='$asm_prog_class'> PRE my $size=scalar @lines; my $cur=0; my $code; while($code=shift @lines){ &$progress($cur++,$size) if defined $progress; chomp $code; $code =~ s/&/&amp;/g; $code =~ s/</&lt;/g; $code =~ s/>/&gt;/g; # back apos (@ tilde key) # ~baaa~ ~Baaa~ # ~uaaa~ ~Uaaa~ # ~iaaa~ ~Iaaa~ $code =~ s!`[bB]([^`]+?)\`!<span class='$asm_bold'>$1</span>!g; # +bold $code =~ s!`[uU]([^`]+?)\`!<span class='$asm_under'>$1</span>!g; # + underl $code =~ s!`[iI]([^`]+?)\`!<span class='$asm_noita'>$1</span>!g; # + underl # comment not @ beging $code =~ s! ; ([^\n]*)!<span class='$asm_comment_class'> ; $1</spa +n>!g; # comment @ begin of line $code =~ s!^;([^\n]*)!<span class='$asm_comment_class'>; $1</span> +!g; # reg words my @terms=split /;/,$code; $terms[0] =~ s!(\b)($reg)(\b)!$1<span class='$asm_command_class'>$ +2</span>$3!g; $code=join ';',@terms; $code =~ s/[\n\r]+//g; my $tmp=sprintf "<span class='$asm_line_class'>[%04d]</span> ",$cu +r; $tmp.=$code; $tmp =~ s/[\n\r]+//g; $res.=$tmp."\n"; } $res.=<<PRE; </pre> PRE $res.=<<TAIL if $want_struct; </body> </html> TAIL $res; }# filt my $pcore = hkp_CreateObjectHKPCore(); sub progress($$){ my $cur=shift; my $lines=shift; return if $cur & 3; $pcore->hkp_FuncOpen($hkp_f_Progress); $pcore->hkp_DataAddInt($hkp_STATUS_PERCENT_COMPLETED,int($cur/$lines +*100)); $pcore->hkp_DataAdd ($hkp_STATUS_PROGRESS_MESSAGE,"Processing ..." +); $pcore->hkp_AddDataInt($hkp_STATUS_LINES_IN_TOTAL,int($cur)); $pcore->hkp_AddDataInt($hkp_STATUS_LINES_IN_CURRENT,int($cur)); $pcore->hkp_AddDataInt($hkp_STATUS_LINES_OUT_TOTAL,int($cur)); $pcore->hkp_AddDataInt($hkp_STATUS_LINES_OUT_CURRENT,int($cur)); $pcore->hkp_AddDataInt($hkp_STATUS_DIVIDER_LINES,int($cur)); $pcore->hkp_FuncRun(); $pcore->hkp_FuncClose(); }# progress if('-hkpreg' eq $ARGV[0]) { # Register the plugin. my $v = hkp_CreateObjectHKPCore(); $v->hkp_DataSetGlobalSuffix('_1'); $v->hkp_DataAdd($hkp_NAME,'ASM\'51'); $v->hkp_DataAdd($hkp_ICON_CAPTION,'51'); $v->hkp_DataAdd($hkp_SECTION,'js29a'); $v->hkp_DataAddInt($hkp_MODE_IN_TEXT_SELECTED, 1); $v->hkp_DataAddInt($hkp_MODE_IN_TEXT_FULL, 1); $v->hkp_DataAddInt($hkp_MODE_SHOW_STATUS, 1 ); # enable progress $v->hkp_DataSetGlobalSuffix(''); } elsif('-hkprun' eq $ARGV[0]){ my $v = hkp_CreateObjectHKPCore(); $text = Variant(VT_BSTR|VT_BYREF, ''); my $want_struct=0; $v->hkp_DataGet($hkp_INPUT_SELECTED, $text); chomp $text; if($text eq ''){ $v->hkp_DataGet($hkp_INPUT, $text); $want_struct=1; } my @lines=split /\n/,$text; my $all=filt($want_struct,\&progress,@lines); $v->hkp_DataAdd('OUTPUT', $all); }

holli added readmore tags


In reply to HTML-Kit plugin for formatting '51 microcontroler assembly code by js29a

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.