Subject: Re: [Tools-discuss] Rfcdiff translated to Perl or PHP?

From: Henrik Levkowetz <[email-masked]>
Date: Sun, 18 Apr 2010 23:40:41 +0200

Hi Peter,

On 2010-04-18 22:02 Peter Krauss said the following:
> 
> Dear henrik,
> 
> About the software
>    http://tools.ietf.org/tools/rfcdiff/code
> 
> there are a "translated version" for Perl or PHP?

No, sorry.  There's a plan to extract the interesting parts into a
Python library module, skipping all the cgi-related and argument-
parsing stuff, but that won't help you particularly.  Sorry I can't
help you more.

Regards,

	Henrik

---

From: Adam Roach <[email-masked]>
Date: Sun, 18 Apr 2010 21:21:58 -0500

> parsing stuff, but that won't help you particularly.  Sorry I can't

While it's not *that* script, I have done a very mechanical translation 
of the other HTML diff script (the one that generates the "diff1" 
format) into perl -- but it still relies on the wdiff command line program.

In case you might find *that* useful, here it is:

######################################################################
# Adaptation of Bill Fenner's htmlwdiff script
# Requires: wdiff from ftp://ftp.gnu.org/gnu/wdiff/
######################################################################
sub htmlwdiff
{
   my ($diff);
   my ($first, $second) = @_;
   my ($first_name, $second_name) = @_;
   my ($temp1) = "/tmp/iddiff1.$$";
   my ($temp2) = "/tmp/iddiff2.$$";

&strip($first, $temp1);
&strip($second, $temp2);

   $first_name =~ s/.*\///g;
   $second_name =~ s/.*\///g;

   $diff = "<html><head><title>wdiff $first_name 
$second_name</title></head><body>\n<pre>\n";
   $diff .= `wdiff -w "<strike><font color='red'>" -x "</font></strike>" 
-y "<strong><font color='green'>" -z "</font></strong>" $temp1 $temp2`;
   $diff .= "</pre>\n</body></html>\n";

   unlink ($temp1);
   unlink ($temp2);

   return $diff;
}

######################################################################
# Adaptation of Henrik's gawk script to strip internet-draft cruft
######################################################################
sub strip
{
   my ($input, $output) = @_;

   my ($newpage, $sentence, $haveblank, $outline);

   open (STRIP_INPUT, $input);
   open (STRIP_OUTPUT, '>'.$output);

   while (<STRIP_INPUT>)
   {
     s/[\r\n]//g;
     s/[ \t]+$//g;

     if (/\[?[Pp]age [0-9ivx]+\]?[ \t]*$/) { next; }

     if (/^[ \t]*\f/)                    { $newpage=1; next; }
     if (/^ *Internet.Draft.+[0-9]+ *$/) { $newpage=1; next; }
     if (/^ *INTERNET.DRAFT.+[0-9]+ *$/) { $newpage=1; next; }
     if (/^RFC.+[0-9]+$/)                { $newpage=1; next; }
     if (/^draft-[-a-z0-9_.]+.*[0-9][0-9][0-9][0-9]$/) { $newpage=1; next; }

     if (/^[^ \t]/) { $sentence=1; }

     if (/[^ \t]/) {
       if ($newpage) {
         if ($sentence) {
           $outline++;
           print STRIP_OUTPUT "\n";
         }
       } else {
         if ($haveblank) {
           $outline++;
           print STRIP_OUTPUT "\n";
         }
       }
       $haveblank=0;
       $sentence=0;
       $newpage=0;
     }

     if (/[.:][ \t]*$/) { $sentence=1; }
     if (/^[ \t]*$/) { $haveblank=1; next; }

     $outline++;
     s/\&/&amp;/g;
     s/\</&lt;/g;
     s/\>/&gt;/g;
     print STRIP_OUTPUT "$_\n";

   }

   close (STRIP_OUTPUT);
   close (STRIP_INPUT);
}

---

From: Peter Krauss <[email-masked]>
Date: Sun, 18 Apr 2010 17:02:21 -0300

Dear henrik,

About the software

thanks

Peter Krauss

---

From: Peter Krauss <[email-masked]>
Date: Mon, 19 Apr 2010 11:54:58 -0300

Dear Adam,

Thanks a lot, your  $diff  3 lines show how to use wdiff (!),
I think this is the "kernel" of the "diff1 format",  
http://tools.ietf.org/rfcdiff?difftype=--hwdiff
and using it into a PHP code.

Peter

Adam Roach escreveu:
> While it's not *that* script, I have done a very mechanical 
> translation of the other HTML diff script (the one that generates the 
> "diff1" format) into perl -- but it still relies on the wdiff command 
> line program.
>
>   $diff .= `wdiff -w "<strike><font color='red'>" -x 
> "</font></strike>" -y "<strong><font color='green'>" -z 
> "</font></strong>" $temp1 $temp2`;