#!/usr/bin/perl
#
# NAME
#   abc_netscape - netscape helper for abc music notation
#
# SYNOPSIS
#   abc_netscape [options] < file
#
# DESCRIPTION
#   This script accepts abc music notation from stdin.  The abc notation
#   is fed to abc2ps (which must be in our search path), and  Out.ps  is
#   generated.   We  then  start up ghostview (which must also be in our
#   search path), telling it to display the Out.ps file.
#
#   Any command-line options are passed to abc2ps.
#
# SETUP
#   This program is designed to be  a  "helper"  app  for  netscape  and
#   possibly other browsers.. To use this as a netscape helper, you need
#   to install it:
#
#   1.  Use the Options ..  General Preferences menu  to  bring  up  the
#   general  config  window.   Select the "Helper" tab to get the helper
#   config list.
#
#   2.  Scroll down to the "text/plain" entry and click to select it.
#
#   3.  Press the "New..." button to get the helper edit window.
#
#   4. Fill in "text/plain" as the Type and "abc" as the Suffix. Fill in
#   the Description field with something descriptive, such as "abc music
#   notation".
#
#   5.  Click the Application button to enable the input field, and fill
#   in "abc_netscape < %s" in the input field.
#
#   6.  Press the OK button at the bottom.
#
#   7.  Press the OK button at the bottom of the Helpers window.
#
#   You  should  be all set, assuming that abc2ps and ghostview are both
#   installed and in your search path. To test it, point your browser at
#   any web page with links to .abc files, and click on one of them. The
#   ghostview window should pop up a few seconds later with the tune  in
#   it.
#
# DIAGNOSTICS
#   If it doesn't work, look in your home directory (or wherever you are
#   running netscape), and see if there are any Out.* files. If so, they
#   were produced by this script. Out.abc should contain the abc source.
#   Look at Out.out and Out.err to see if there  are  any  useful  error
#   messages.
#
# FILES
#   Because abc2ps has hard-wired the name "Out.ps" as its output file,
#   I decided to name the rest of our output files similarly.
#
#   Out.abc  will contain the abc source.
#   Out.ps   will contain the postscript output from abc2ps.
#   Out.out  will contain stdout message from abc2ps and/or ghostview.
#   Out.err  will contain stderr message from abc2ps and/or ghostview.
#
#   These files are overwritten each time this script is run.
#
# AUTHOR
#   John Chambers <jc@trillian.mit.edu> http://trillian.mit.edu/~jc/

$| = 1;
$" = ' ';
open(O,">Out.abc")
	|| die "$0: Can't write Out.abc ($!)\n";
while (<STDIN>) {print O}	# Copy all the abc to Out.abc
close O;

system "abc2ps @ARGV Out.abc 1> Out.out 2> Out.err -o";
system "ghostview    Out.ps  1>>Out.out 2>>Out.err  &";
