groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Groff] Re: 2nd try -- Would you like a diffmk that works on Linux?


From: M Bianchi
Subject: [Groff] Re: 2nd try -- Would you like a diffmk that works on Linux?
Date: Tue, 20 Jul 2004 10:13:16 -0400

>  Larry McVoy <address@hidden>  wrote:
> It's just a shell script.
>       :

I realize  diffmk  is just a shell script, and has been since forever.

The question is
        "Shouldn't  diffmk  be part of the standard Groff package offering?"

I would like to see it there, but haven't found it.  When I looked for it using
Google, the only one I found didn't work with Linux.

This perl version is slightly different from the one Larry sent in that
        it uses  +  for added lines
        allows for alternative added/changed/delected markers
        sends the result to the standard output

So I would like to see it added to the standard Groff package, and am willing
to be the owner for a while.

How does one do that?
                                                        Mike Bianchi


#!/usr/bin/perl
# original version by merlyn (Randal L. Schwartz @ Stonehenge)
# requires /usr/bin/diff that understands -D
#       fixed to understand more modern -D output       M Bianchi

($myname = $0) =~ s!.*/!!; # save this very early

sub usage {
        die join("\n",@_) .
        "\nusage: $myname [-aA] [-cC] [-dD] old-file new-file >marked-file\n";
}

# defaults:
$marka = "+"; # lines that are added
$markc = "|"; # lines that are changed
$markd = "*"; # deletions (near where they were deleted)

while ($_ = shift) {
        $marka = $1, next if /^-a(.+)$/;
        $markc = $1, next if /^-c(.+)$/;
        $markd = $1, next if /^-d(.+)$/;
        do usage("unknown flag: $1") if /^(-.*)$/;
        unshift (@ARGV,$_), last;
}

do usage("missing old-file") unless $#ARGV > -1;
do usage("cannot read old-file '$old': $!") unless -r ($old = shift);
do usage("missing new-file") unless $#ARGV > -1;
do usage("cannot read new-file '$new': $!") unless -r ($new = shift);
do usage("extra args") if $#ARGV > -1;

# separator string with a random number
$_ = rand();
s/..//;
$zzz = "___A_VERY_UNLIKELY_STRING___" . $_;

open(I,"exec /usr/bin/diff -D$zzz $old $new |") || die "cannot open diff: $!";

MAIN: while (<I>) {
        if (/^#ifdef $zzz/) {
                print ".mc $marka\n";
                print while ($_ = <I>) && !/^#endif \/\* $zzz/;
                print ".mc\n";
                last MAIN if eof;
                next MAIN;
        }
        if (/^#ifndef $zzz/) {
                while (<I>) {
                        if (/^#else \/\* $zzz/) {
                                print ".mc $markc\n";
                                print while ($_ = <I>) && !/^#endif \/\* $zzz/;
                                print ".mc\n";
                                last MAIN if eof;
                                next MAIN;
                        }
                        if (/^#endif \/\* not $zzz/) {
                                print ".mc $markd\n.mc\n";
                                next MAIN;
                        }
                }
        }
        print;
}

close(I);
exit 0;


reply via email to

[Prev in Thread] Current Thread [Next in Thread]