#!/usr/local/bin/perl -w

# make_diff v. 17 Mar 1996, Dave Schweisguth <dcs@proton.chem.yale.edu>

# Bugs:
# Hardcoded paths

### Preliminaries

require 5.002;			    # Perl 5.002 required
use strict;			    # Require optional-but-desirable practices

### Parameters

# Environment

(my $whatami = $0) =~ s|.*/||;	    # `basename $0`
chop(my $date = `date '+%d %b %Y %T %Z'`);  # RFC822, dd Mon yy hh:mm:ss ZON

# Configuration

my $rawdir = 'raw';
my $olddir = 'raw.old';
my @faqs = qw(admin apps audio graphics hardware impressario inventor misc
    movie performer pointer security);
my $diff = '/usr/bin/diff';

# Initialization (don't change these)

my($i, @diff);

### Arguments and error-checking

# Parse args

my($arg, $sign, $first, $rest);
while (@ARGV and ($sign, $first, $rest) = ($ARGV[0] =~ /^([\-+])(.)(.*)/)) {
    if ($sign eq '+' && $first !~ /[\0]/) { # -/+ switches (none at the moment)
	&usage("$whatami: $sign$first is not an option.\n");
    }
    if ($first =~ /[\0]/) {	# Switches with arguments (none at the moment)
    	shift;
    	$arg = $rest ne '' ? $rest : @ARGV ? shift :
      	    &usage("$whatami: $sign$first requires an argument.\n");
    } elsif ($rest eq '') {
	shift;
    } else {
    	$ARGV[0] = "$sign$rest";
    }
    if    ($first eq 'u') { &usage(0); }
    else		  { &usage("$whatami: $sign$first is not an option.\n"); }
}

sub usage {
    my($message) = $_[0];

    warn $message if $message;
    warn <<EOP;
Usage: $whatami [-u]
-u	This message
EOP
    exit !! $message;
}

# Post-process args

if (@ARGV) {
    &usage("$whatami: There are no non-switch arguments.\n");
}

### Do it

for $i (@faqs) {

    unless ($i eq $faqs[0]) {
	print <<EOP;

------------------------------

EOP
    }

    print <<EOP;
Subject: Changes in the SGI $i FAQ since it was last posted
Date: $date

EOP

    @diff = `$diff $olddir/$i $rawdir/$i`;
    if (@diff) {
	foreach (@diff) {
	    print "  $_";
	}
    } else {
	print "  The SGI $i FAQ has not changed since it was last posted.\n";
    }
}

exit;
