#!/usr/bin/perl

=head1 NAME
  abcDescr - Generate .htaccess descriptions from ABC files.

=head1 SYNOPSIS
  abcDescr [file]..

=head1 DESCRIPTION

=head1 OPTIONS

=head1 EXAMPLES

=head1 FILES

=head1 BUGS

=head1 SEE ALSO

=head1 AUTHOR
  John Chambers <jc@trillian.mit.edu>
=cut

$| = 1;

unless (open(H,">.htaccess")) {
	($pwd = `pwd`) =~ s/\s+$//;;
	printf STDERR "$0: Can't write .htaccess in $pwd ($!)\n";
	exit $!;
}
print H "# This file was generated by $0\n";
print H "# Any changes you make will probably be overwritten.\n";
print H "\n";

file:
for $f (@ARGV) {
	unless (open(F,$f)) {
		printf STDERR "$0: Can't read $f ($!)\n";
		next file;
	}
	for $l (<F>) {
		$l =~ s/[\s\r]+$//;			# Trim trailing white spaces
		if ($l =~ /^T:\s*(.*)$/) {
			$t = $1;
			$t =~ s/^the\s+//i;		# Trim definite article
			$t =~ s/^(a|an)\s+//i;	# Trim indefinite article
			$t = '-' unless $t;		# Apache doesn't like null descriptions
			$t = &tex2html($t);
			print H "AddDescription \"$t\" $f\n";
			next file;
		}
	}
}

sub tex2html {
	local($s) = @_;
#	print "I s=\"$s\"\n";
	$s =~ s/\\'([aeiou])/\&$+acute;/g;
	$s =~ s/\\`([aeiou])/\&$+grave;/g;
	$s =~ s/\\"([aeiou])/\&$+uml;/g;
	$s =~ s/\\\^([aeiou])/\&$+circ;/g;
#	print "O s=\"$s\"\n";
	return $s;
}

exit 0;
