#!/bin/sh
# This is a shell archive (produced by shar 3.49)
# To extract the files from this archive, save it to a file, remove
# everything above the "!/bin/sh" line above, and type "sh file_name".
#
# made 11/19/1991 21:42 UTC by tjt@sparc-8
# Source directory /b0/local/midi/tmp/mft
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#   8799 -rw-r--r-- README
#   4179 -rw-r--r-- crack.c
#     81 -rw-r--r-- example1.mid
#    300 -rw-r--r-- example1.txt
#    118 -rw-r--r-- example2.mid
#    376 -rw-r--r-- example2.txt
#    117 -rw-r--r-- example3.mid
#    428 -rw-r--r-- example3.txt
#   1805 -rw-r--r-- example4.mid
#  11751 -rw-r--r-- example4.txt
#   1016 -rw-r--r-- example5.mid
#   5715 -rw-r--r-- example5.txt
#   1145 -rw-r--r-- makefile
#   1017 -rw-r--r-- makefile.st
#   1145 -rw-r--r-- makefile.unx
#   6855 -rw-r--r-- mf2t.c
#  21131 -rw-r--r-- midifile.c
#   3329 -rw-r--r-- midifile.h
#  10498 -rw-r--r-- t2mf.c
#   1968 -rw-r--r-- t2mf.fl
#   1081 -rw-r--r-- t2mf.h
#  38341 -rw-r--r-- t2mflex.c
#    646 -rw-r--r-- yyread.c
#
# ============= README ==============
if test -f 'README' -a X"$1" != X"-c"; then
	echo 'x - skipping README (File already exists)'
else
echo 'x - extracting README (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'README' &&
X		MF2T/T2MF
X
Two programs to manipulate standard midifiles.
X
mf2t is a program that reads a standard midifile (format 0 or 1) and
writes an ASCII representation of it that is both compact and easily parsable.
X
t2mf is the companion program that reparses the text representation
into a midifile.
-----------------------------------------------------------------------
Please report any problems, suggestion for improvement, or actual
improvements to:
X
Piet van Oostrum, Dept of Computer Science, Utrecht University,
P.O. Box 80.089, 2508 TB Utrecht, The Netherlands
email: piet@cs.ruu.nl
X
-----------------------------------------------------------------------
You can do with this program what you like, but if you think it is
useful I would appreciate if you send me some of your midifiles. Not
ones that I can find on the Internet. And only PD ones. Please send
them uu- or btoa-encoded. Zoo and Arc archives (encoded) are also OK,
Zip and Lharc may be problematic.
------------------------------------------------------------------------
X
The text representation is chosen such that it is easily recognized and
manipulated by programs like sed, awk or perl. Yet it is also humanly
readable so that it can be manipulated with an ordianary text editor.
X
In this way you can make changes to your midifiles using these
powerful programs or even a Fortran program :=). Or you can write
algorithmic compositions using a familiar programming language.
X
The programs use the midifile library written by Tim Thompson
(tjt@blink.att.com) and updated by Michael Czeiszperger (mike@pan.com).
However, there were some bugs in the write code and I added some
features that I needed. I also changes some of the names to cope with
the 7-character limit for external identifiers in the Sozobon
compiler. I will make an updated version of the library available
soon. I also anticipate to split the read and write portions.
X
Usage:
X	mf2t [-mntv] [-f[n]] [midifile [textfile]]
X	
X	translate midifile to textfile.
X	
When textfile is not given, the text is written to standard output.
When midifile is not given it is read from standard input. The meaning
of the options is:
X
-m	merge partial sysex into a single sysex message
-n	write notes in symbolic rather than numeric form. A-C
X	optionally followed by # (sharp) followed by octave number.
-b	or
-t	event times are written as bar:beat:click rather than a click number
-v	use a slightly more verbose output
-f<n>	fold long text and hex entries into more lines <n>=line length
X	(default 80).
X
X	t2mf [-r] [[textfile] midifile]
X	
X	translate textfile to midifile.
X	
When textfile is not given, text is read from standard input, when
midifile is not given it is written to standard output.
X
-r	Use running status
X
Note that if one file is given it is always the midifile. This is so
that on systems like Unix you can write a pipeline:
X
X	mf2t x.mid | sed ... | t2mf y.mid
X	
Format of the textfile:
-----------------------
X
The following representation of the midievents is generated (between
[] the form when -v is used:
X
File header:		Mfile <format> <ntrks> <division>
Start of track:		MTrk
End of track:		TrkEnd
X
Note On:		On <ch> <note> <vol>
Note Off:		Off <ch> <note> <vol>
Poly Pressure:		PoPr[PolyPr] <ch> <note> <val>
Channel Pressure:	ChPr[ChanPr] <ch> <val>
Controller parameter:	Par[Param] <ch> <con> <val>
Pitch bend:		Pb <ch> <val>
Program change:		PrCh[ProgCh] <ch> <prog>
Sysex message:		SysEx <hex>
Arbutrary midi bytes:	Arb <hex>
X
Sequence nr:		Seqnr <num>
Key signature:		KeySig <num> <manor>
Tempo:			Tempo <num>
Time signature:		TimeSig <num>/<num> <num> <num>
SMPTE event:		SMPTE <num> <num> <num> <num> <num>
X
Meta text events:	Meta <texttype> <string>
Meta end of track:	Meta TrkEnd
Sequencer specific:	SeqSpec <type> <hex>
Misc meta events:	Meta <type> <hex>
X
The <> have the following meaning:
X
<ch>		ch=<num>
<note>		n=<noteval>  [note=<noteval>]
<vol>		v=<num> [vol=<num>]
<val>		v=<num> [val=<num>]
<con>		c=<num> [con=<num>]
<prog>		p=<num> [prog=<num>]
<manor>		minor or major
<noteval>	either a <num> or A-G optionally followed by #,
X		followed by <num> without intermediate spaces.
X
<texttype>	Text Copyright SeqName TrkName InstrName Lyric Marker Cue
X		or <type>
<type>		a hex number of the form 0xab
<hex>		a sequence of 2-digit hex numbers (without 0x)
X		separated by space
<string>	a string between double quotes (like "text").
X
Channel numbers are 1-based, all other numbers are as they appear in
the midifile.
<division> is either a positive number (giving the time resolution in
clicks per quarter note) or a negative number followed by a positive
number (giving SMPTE timing).
<format> <ntrks> <num> are decimal numbers.
The <num> in the Pb is the real value (two midibytes combined)
In Tempo it is a long (32 bits) value. Others are in the interval 0-127
The SysEx sequence contains the leading F0 and the trailing F7.
X
In a string certain characters are escaped:
" and \ are escaped with a \
a zero byte is written as \0
CR and LF are written as \r and \n respectively
other non-printable characters are written as \x<2 hex digits>
When -f is given long strings and long hex sequences are folded by inserting
\<newline><tab>. If in a string the next character would be a space or
tab it will be escaped by \
This facility is for those programs that have a limited buffer length.
Of course parsing is more difficult with this option (see below).
X
Input:
------
t2mf will accept all formats that mf2t can produce, plus a number of others.
Input is case insensitive (except in strings) and extra tabs and
spaces are allowed. Newlines are required but empty lines are allowed.
Comment starts with # at the beginning of a lexical item and continues
to the end of the line. The only other places where a # is legal are
insides strings and as a sharp symbol in a symbolic note.
X
In symbolic notes + and # are allowed for sharp, b and - for flat.
X
In bar:beat:click time the : may also be /
X
On input a string may also contain \t for a tab, and in a folded
string any whitespace at the beginning of a continuation line is skipped.
X
Hex sequences may be input without intervening spaces if each byte is
given as exactly 2 hex digits.
X
Hex sequences may be given where a string is required and vice versa.
X
Hex numbers of the form 0xaaa and decimal numbers are equivalent.
Also allowed as numbers are "bank numbers" of the form '123. In fact
this is equivalent to the octal number 012 (subtract 1 from each
digit, digits 1-8 allowed). The letters a-h may also be used for 1-8.
X
The input is checked for correctness but not extensively. An
errormessage will generally imply that the resulting midifile is illegal.
X
Implementation:
---------------
X
I have compiled the programs on an Atari ST with the Sozobon compiler
and the dlibs library. The scanner is generated using flex 2.3. The
output of flex (t2mflex.c) is included for those that do not have
flex.  The module yyread.c is a flex library module that you need on
TOS (and on MSDOS).  The corresponding makefile is makefile.st. For
Unix use makefile.unx. The makefiles may need minor changes for other
systems. 
X
Useful hints:
-------------
X
channel number can be recognized by the regular expression /ch=/.
note numbers by /n=/ or /note=/, program numbers by /p=/ or /prog=/.
Meta events by /^Meta/ or /^SeqSpec/.
Text events by /"/, continued lines by /\\$/, continuation lines by /$\t/
(that was a TAB character).
X
In awk each parameter is a field, in perl you can use split to get the
parameters (except for strings).
X
The following perl script changes note off messages to note on with
vol=0, deletes controller 3 changes, makes some note reassignments on
channel 10, and changes the channel numbers from channel 1 depending
on the track number. 
X
------------------------------- test.pl -------------------------------
%drum = (62, 36, 63, 47, 65, 61, 67, 40, 68, 54);
X
while (<>) {
X	next if /c=3/;
X	s/Off(.*)v=[0-9]*/On\1v=0/;
X	if (/ch=10/ && /n=([0-9]*)/ && $drum{$1}) {
X		s/n=$1/"n=".$drum{$1}/e;
X	}
X	if (/^MTrk/) {++$trknr ; print "track $trknr\n";}
X	if ($trknr > 2) { s/ch=1\b/ch=3/; }
X	else  { s/ch=1\b/ch=4/; }
X	print || die "Error: $!\n";
}	
------------------------------------------------------------------------
X
and this is the corresponding awk script.
X
------------------------------- test.awk -------------------------------
BEGIN { drum[62] = 36; drum[63] = 47; drum[65] = 61; \
X	drum[67] = 40; drum[68] = 54 }
/c=3/ { next }
($2 == "Off") { $2 = "On"; $5 = "v=0" }
/ch=10/ { n = substr($4, 3); if (n in drum) $4 = "n=" drum[n] }
/^MTrk/ { trknr++ }
/ch=1 / { if (trknr > 2) { $3 = "ch=2" } else { $3 = "ch=3" } } 
{ print }
------------------------------------------------------------------------
X
Good luck!
X
$Id: readme.,v 1.5 1991/11/16 20:26:48 piet Rel $
SHAR_EOF
chmod 0644 README ||
echo 'restore of README failed'
Wc_c="`wc -c < 'README'`"
test 8799 -eq "$Wc_c" ||
	echo 'README: original size 8799, current size' "$Wc_c"
fi
# ============= crack.c ==============
if test -f 'crack.c' -a X"$1" != X"-c"; then
	echo 'x - skipping crack.c (File already exists)'
else
echo 'x - extracting crack.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'crack.c' &&
/* $Id: crack.c,v 1.2 1991/11/03 21:50:50 piet Rel $ */
/*
X * crack - put the command line to the vice.
X *
X * This routine takes four arguments, the variables argc and argv from
X * the program's main procedure, a list of flags to recognize, and an
X * indication whether to ignore unknown flags or not.
X *
X * The action of crack is to read a command line laid out in the format:
X *
X * % command [flags]... [files]...
X *
X * where the flags are of the form -foption, that is, a minus, a character
X * and an optional argument, butted up to the character.  No space may
X * appear between any flag and its option.  The first command line
X * argument not preceeded by '-' is taken as the end of the flags and the
X * beginning of file names.
X * 
X * The flags argument to crack looks like this: "a|b|cd" for flags a b c
X * and d.  In this example, a and b take (optional!) options, as specified
X * by the trailing colon, c and d do not.  When crack scans a flag, it
X * returns the flag character after setting the external character pointer
X * arg_option to the option part.  It also sets arg_index to the index of
X * the argv variable scanned.  Crack returns NULL when it has scanned the
X * last flag.  The value of arg_index then points at the first 
X * argument after the last flag, which should be the first filename, if
X * any.  If there are no arguments, or no more arguments after reading 
X * the flags, arg_index == argc;
X *
X * Flags may be concatenated, for instance, using the flags argument
X * given above: -cd will treat c and d as
X * flags.  -cdaoption also works.  However, tacking what you think is
X * a flag after another flag that takes an option will cause the flag to
X * be lost.  I.e., -ac will treat c as an option, not a flag.
X * 
X * When the ignore flag is zero,  flags scanned that are not in the flags
X * variable generate an error message and crack returns EOF.  If ignore is
X * nonzero, unknown flags are suppressed, that is, no flag is returned.
X * The purpose of ignoring flags is so that more than one part of a
X * program can scan the command line without having to know about the
X * flags of all the other parts.  For instance, where a program calculates
X * a sampling rate by one flag and a value in seconds in another, it must
X * search for the sampling rate first, then the time value.  Two calls to
X * crack() would be required, one to scan just for the flag setting sampling
X * rate, another to ignore the rate flag, but to set the time value based
X * on the sampling rate.
X * NOTE: WHEN MAKING MORE THAN ONE CALL TO crack() IN A PROGRAM, IT
X * IS NECESSARY TO RESET arg_index TO 0 FIRST.
X *
X * When ignoring unknown flags, if an unknown flag has an option
X * associated with it, the option is also ignored.  Care should be excercised
X * here because it may be possible that the associated "option" is really
X * more concatenated flags.  These, if any, are lost.  The rule is that,
X * when ignoring unknown flags, the first instance of an unknown flag
X * causes that flag and the rest of that argument to be discarded.  For
X * instance, if flags is set to "a:b:cd", and a command line:
X * "-zcdaoption" is supplied, c d and a would be ignored because they come
X * after z in the same argument.  The point is there is no way to disambiguate
X * flags from unknown options when ignoring flags, so concatenating options,
X * while nice, is problematical.
X */
X
#include <stdio.h>
X
int arg_index = 0;
char *arg_option;
char *pvcon = NULL;
X
char crack(argc, argv, flags, ign)
X    int argc; char **argv; char *flags; int ign;
{
X    char *pv, *flgp, *strchr();
X    while ((arg_index) < argc)
X	{
X	if (pvcon != NULL)
X	    pv = pvcon;
X	else
X	    {
X	    if (++arg_index >= argc) return(NULL); 
X	    pv = argv[arg_index];
X	    if (*pv != '-') 
X		return(NULL);
X	    }
X	pv++;		/* skip '-' or prev. flag */
X	if (*pv != NULL)
X	    {
X	    if ((flgp=strchr(flags,*pv)) != NULL)
X		{
X		pvcon = pv;
X		if (*(flgp+1) == '|') { arg_option = pv+1; pvcon = NULL; }
X		return(*pv);
X		}
X	    else
X		if (!ign)
X		    {
X		    fprintf(stderr, "%s: no such flag: %s\n", argv[0], pv);
X		    return(EOF);
X		    }
X		else
X		    pvcon = NULL;
X	    }
X	pvcon = NULL;
X	}
X    return(NULL);
X    }
X
SHAR_EOF
chmod 0644 crack.c ||
echo 'restore of crack.c failed'
Wc_c="`wc -c < 'crack.c'`"
test 4179 -eq "$Wc_c" ||
	echo 'crack.c: original size 4179, current size' "$Wc_c"
fi
# ============= example1.mid ==============
if test -f 'example1.mid' -a X"$1" != X"-c"; then
	echo 'x - skipping example1.mid (File already exists)'
else
echo 'x - extracting example1.mid (Binary)'
sed 's/^X//' << 'SHAR_EOF' | uudecode &&
begin 600 example1.mid
M351H9`````8````!`&!-5')K````.P#_6`0$`A@(`/]1`P>A(`#`!0#!+@#"
D1@"2,&``/&!@D4-`8)!,((%`@C!``#Q``(%#0`"`3$``_R\`
`
end
SHAR_EOF
chmod 0644 example1.mid ||
echo 'restore of example1.mid failed'
Wc_c="`wc -c < 'example1.mid'`"
test 81 -eq "$Wc_c" ||
	echo 'example1.mid: original size 81, current size' "$Wc_c"
fi
# ============= example1.txt ==============
if test -f 'example1.txt' -a X"$1" != X"-c"; then
	echo 'x - skipping example1.txt (File already exists)'
else
echo 'x - extracting example1.txt (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'example1.txt' &&
MFile 0 1 96
MTrk
0 TimeSig 4/4 24 8
0 Tempo 500000
0 PrCh ch=1 p=5
0 PrCh ch=2 p=46
0 PrCh ch=3 p=70
0 On ch=3 n=48 v=96
0 On ch=3 n=60 v=96
96 On ch=2 n=67 v=64
192 On ch=1 n=76 v=32
384 Off ch=3 n=48 v=64
384 Off ch=3 n=60 v=64
384 Off ch=2 n=67 v=64
384 Off ch=1 n=76 v=64
384 Meta TrkEnd
TrkEnd
SHAR_EOF
chmod 0644 example1.txt ||
echo 'restore of example1.txt failed'
Wc_c="`wc -c < 'example1.txt'`"
test 300 -eq "$Wc_c" ||
	echo 'example1.txt: original size 300, current size' "$Wc_c"
fi
# ============= example2.mid ==============
if test -f 'example2.mid' -a X"$1" != X"-c"; then
	echo 'x - skipping example2.mid (File already exists)'
else
echo 'x - extracting example2.mid (Binary)'
sed 's/^X//' << 'SHAR_EOF' | uudecode &&
begin 600 example2.mid
M351H9`````8``0`$`&!-5')K````%`#_6`0$`A@(`/]1`P>A((,`_R\`351R
M:P```!``P`6!0)!,((%`3```_R\`351R:P````\`P2Y@D4-`@B!#``#_+P!-
<5')K````%0#"1@"2,&``/&"#`#```#P``/\O``\`
`
end
SHAR_EOF
chmod 0644 example2.mid ||
echo 'restore of example2.mid failed'
Wc_c="`wc -c < 'example2.mid'`"
test 118 -eq "$Wc_c" ||
	echo 'example2.mid: original size 118, current size' "$Wc_c"
fi
# ============= example2.txt ==============
if test -f 'example2.txt' -a X"$1" != X"-c"; then
	echo 'x - skipping example2.txt (File already exists)'
else
echo 'x - extracting example2.txt (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'example2.txt' &&
MFile 1 4 96
MTrk
0 TimeSig 4/4 24 8
0 Tempo 500000
384 Meta TrkEnd
TrkEnd
MTrk
0 PrCh ch=1 p=5
192 On ch=1 n=76 v=32
384 On ch=1 n=76 v=0
384 Meta TrkEnd
TrkEnd
MTrk
0 PrCh ch=2 p=46
96 On ch=2 n=67 v=64
384 On ch=2 n=67 v=0
384 Meta TrkEnd
TrkEnd
MTrk
0 PrCh ch=3 p=70
0 On ch=3 n=48 v=96
0 On ch=3 n=60 v=96
384 On ch=3 n=48 v=0
384 On ch=3 n=60 v=0
384 Meta TrkEnd
TrkEnd
SHAR_EOF
chmod 0644 example2.txt ||
echo 'restore of example2.txt failed'
Wc_c="`wc -c < 'example2.txt'`"
test 376 -eq "$Wc_c" ||
	echo 'example2.txt: original size 376, current size' "$Wc_c"
fi
# ============= example3.mid ==============
if test -f 'example3.mid' -a X"$1" != X"-c"; then
	echo 'x - skipping example3.mid (File already exists)'
else
echo 'x - extracting example3.mid (Binary)'
sed 's/^X//' << 'SHAR_EOF' | uudecode &&
begin 600 example3.mid
M351H9`````8````!`!A-5')K````7P#_`29$('-C86QE("`@("`@("`@("`@
M("`@("`@("`@("`@("`@("`@(`"0/D`,/@`,0$`,0``,0D`,0@`,0T`,0P`,
;14`,10`,1T`,1P`,24`,20`,2D`,2@`,_R\`
`
end
SHAR_EOF
chmod 0644 example3.mid ||
echo 'restore of example3.mid failed'
Wc_c="`wc -c < 'example3.mid'`"
test 117 -eq "$Wc_c" ||
	echo 'example3.mid: original size 117, current size' "$Wc_c"
fi
# ============= example3.txt ==============
if test -f 'example3.txt' -a X"$1" != X"-c"; then
	echo 'x - skipping example3.txt (File already exists)'
else
echo 'x - extracting example3.txt (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'example3.txt' &&
MFile 0 1 24
MTrk
0 Meta Text "D scale                               "
0 On ch=1 n=62 v=64
12 On ch=1 n=62 v=0
24 On ch=1 n=64 v=64
36 On ch=1 n=64 v=0
48 On ch=1 n=66 v=64
60 On ch=1 n=66 v=0
72 On ch=1 n=67 v=64
84 On ch=1 n=67 v=0
96 On ch=1 n=69 v=64
108 On ch=1 n=69 v=0
120 On ch=1 n=71 v=64
132 On ch=1 n=71 v=0
144 On ch=1 n=73 v=64
156 On ch=1 n=73 v=0
168 On ch=1 n=74 v=64
180 On ch=1 n=74 v=0
192 Meta TrkEnd
TrkEnd
SHAR_EOF
chmod 0644 example3.txt ||
echo 'restore of example3.txt failed'
Wc_c="`wc -c < 'example3.txt'`"
test 428 -eq "$Wc_c" ||
	echo 'example3.txt: original size 428, current size' "$Wc_c"
fi
# ============= example4.mid ==============
if test -f 'example4.mid' -a X"$1" != X"-c"; then
	echo 'x - skipping example4.mid (File already exists)'
else
echo 'x - extracting example4.mid (Binary)'
sed 's/^X//' << 'SHAR_EOF' | uudecode &&
begin 600 example4.mid
M351H9`````8````!`#!-5')K```&]P#_`28Y-G!P<3$L,B`@("`@("`@("`@
M("`@("`@("`@("`@("`@("`@(`"0*U``/E@`.U``05`$D4]T%)`^```[``!!
M``613F`$3P`/D"L``9%/7`!.`!I19`!/`!!1``%/:A5/`$^0*T0`.E@`/5``
M0&@"D4]T%I`Z```]``!```613EP"3P`/3V@`3@`"D"L`&)%19`!/`!-/:`51
M`!)/`$U37`&0*T0`/E``.TX`05`0D5,``E10!I`^```[``!!``614UL#5``,
M4F0"4P`"D"L`#9%2`"%15`*0*T0`.E0`/5``0$T.D5)4`E$`")`Z```]``!`
M``214@`"45H/4%0#D"L``9%1``E0`")/6`20*T@`/EH`.U``05H#D4\`%9`^
M```[``!!``:10U0*0P`#148%D"L``9%#9`%%``A"=`1#`!5"``%#7!%$6P!#
M`!E$``)%9!%&4`)%`!!&``M'9!!'``*0)$0"D4AH+I`\1@`W0`!`3``D``*1
M2``6D#P``#<``$``!9%(6P=(``M(9`&0*T8*D4@`)4A<`9`\2``W.P!`4``K
M``N12``-D#P``#<``$``&"1(`Y%(7"V0/$T`-T0`0$\`)``!D4@`%Y`\```W
M``!``!@K1@&11UP51P`:D#Q0`#=(`$!0`"L``I%(7!:0/```-P``0``$D4@`
M`DE;#4D``DIH`Y`F2#`W2``[3@`U2``^*P`F`!@W```[```U```^`!@K2":1
M2@`*D#Y.`#=.`#5&`#M(`"L`&#X``#<``#4``#L`&"9`&I%#7`Q%:`1#``:0
M/DT`-T@`-3X`.T<`)@`!D44``D-D"T)H!$,`!I`^```W```U```[``Z10@`"
M0V8(D"M,#9%-9`!#`!E*9`%-``F0/DX`-T8`.TT`-3T`*P`(D4=<`TH`#9`^
M```W```[```U``611P`#0UP0D"],`)%#``)*="Z0/E``-4@`-TP`.T\`+P`#
MD4H`%9`^```U```W```[``612F@)2@`(2F0"D"M$#Y%*`"!*:@&0/E``-T@`
M-44`.T@`*P`1D4H`!Y`^```W```U```[`!@F4`&12F@OD#Y,`#=(`#M-`#5`
M`"8``I%)8`)*`!20/@``-P``.P``-0`%D4D``4IH$I`K2`.12UP"2@`72P`"
M4V@2D#Y0`#5&`#=/`#M0`"L`#I%27`)3``B0/@``-0``-P``.P`%D5%8`%(`
M#5!;!%$``I`D1PF13V0!4``FD#Q,`#=0`$!4`"0`&#P``#<``$``%Y%/``&0
M*TP?D4AD#4QF`4@``Y`\3``W0`!`4``K``B13``$1V0+2UL!D#P``#<``$``
M`Y%'``M+``-*7`-&9`20)$TP/%@`-UH`0%@`)``5D48``Y`\```W``!```B1
M2@`0D"9$&"8`&"A/`#Q8`#=0`$!:"I%+=`Z0*```/```-P``0```D4L`"4QJ
M#Y`I3`"13``"370ND#E0`#Q(`$%-`"D``Y%-`!60.0``/```00`"D4QD#DP`
M!DUH`I`D3"2130`,D#E/`#Q(`$%.`"0`&)%/7`"0.0``/```00`1D4\`!$U;
M`Y`I4#`Y3``\3@!!3``I`!@Y```\``!!``:130`2D"1',#E(`#Q0`$%4`"0`
M`Y%/:!)/``.0.0``/```00`%D4U<$$T``Y`P3`&13%POD#=,`#Q4`$!4`#``
M!Y%,`!&0-P``/```0``$D4M;#4L`!TQH`)`K1!"13``+2UP.2P`"2F0%D#Q0
M`#=``$!0`"L`#I%*``J0/```-P``0``#D4E4#4D`!DAD`I`P4#`\4``W0`!`
M2``P``:12``2D#P``#<``$``&"](&"\`&)%'6`"0+4@`/%@`-T@`0$@0D4A4
M`$<`")`M```\```W``!```2125P%2``,2F@#D"M$`)%)`!%*`!^0/D@`-40`
M-T<`.T``*P`!D4-'$454`$,`!I`^```U```W```[``*11EL&10`)1VH&1@`!
MD"90")%'`"8^9`*0/DX`-40`-T0`.T0`)@`+D3]<`CX`"Y`^```U```W```[
M``210'0`/P`-0``'070`D"M(&I%!``)%9!)%``)(9`"0/D\`-U``-4T`.TX`
M*P`8/@``-P``-0``.P`!D4@``TQJ$$P`!)`F3`.12G062@`,3UL+D#L[`#X^
M`#5``#=``"8`"I%37`1/``J0.P``/@``-P`'D5,`!E9T!Y`U``0D3P`\7@61
M5%P`5@`3D#P`$9%4``>0)``8+4P`.5@8*U@`-UP`+0`4.0`$*P``-P`8*%X`
M-%@8*```-``8)%\`,&@8,``8)``>D5M3!UU8!%L`!%]<!%T`!&!T`U\`"6``
%@T__+P``
`
end
SHAR_EOF
chmod 0644 example4.mid ||
echo 'restore of example4.mid failed'
Wc_c="`wc -c < 'example4.mid'`"
test 1805 -eq "$Wc_c" ||
	echo 'example4.mid: original size 1805, current size' "$Wc_c"
fi
# ============= example4.txt ==============
if test -f 'example4.txt' -a X"$1" != X"-c"; then
	echo 'x - skipping example4.txt (File already exists)'
else
echo 'x - extracting example4.txt (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'example4.txt' &&
MFile 0 1 48
MTrk
0 Meta Text "96ppq1,2                              "
0 On ch=1 n=43 v=80
0 On ch=1 n=62 v=88
0 On ch=1 n=59 v=80
0 On ch=1 n=65 v=80
4 On ch=2 n=79 v=116
24 On ch=1 n=62 v=0
24 On ch=1 n=59 v=0
24 On ch=1 n=65 v=0
29 On ch=2 n=78 v=96
33 On ch=2 n=79 v=0
48 On ch=1 n=43 v=0
49 On ch=2 n=79 v=92
49 On ch=2 n=78 v=0
75 On ch=2 n=81 v=100
75 On ch=2 n=79 v=0
91 On ch=2 n=81 v=0
92 On ch=2 n=79 v=106
113 On ch=2 n=79 v=0
192 On ch=1 n=43 v=68
192 On ch=1 n=58 v=88
192 On ch=1 n=61 v=80
192 On ch=1 n=64 v=104
194 On ch=2 n=79 v=116
216 On ch=1 n=58 v=0
216 On ch=1 n=61 v=0
216 On ch=1 n=64 v=0
221 On ch=2 n=78 v=92
223 On ch=2 n=79 v=0
238 On ch=2 n=79 v=104
238 On ch=2 n=78 v=0
240 On ch=1 n=43 v=0
264 On ch=2 n=81 v=100
264 On ch=2 n=79 v=0
283 On ch=2 n=79 v=104
288 On ch=2 n=81 v=0
306 On ch=2 n=79 v=0
383 On ch=2 n=83 v=92
384 On ch=1 n=43 v=68
384 On ch=1 n=62 v=80
384 On ch=1 n=59 v=78
384 On ch=1 n=65 v=80
400 On ch=2 n=83 v=0
402 On ch=2 n=84 v=80
408 On ch=1 n=62 v=0
408 On ch=1 n=59 v=0
408 On ch=1 n=65 v=0
413 On ch=2 n=83 v=91
416 On ch=2 n=84 v=0
428 On ch=2 n=82 v=100
430 On ch=2 n=83 v=0
432 On ch=1 n=43 v=0
445 On ch=2 n=82 v=0
478 On ch=2 n=81 v=84
480 On ch=1 n=43 v=68
480 On ch=1 n=58 v=84
480 On ch=1 n=61 v=80
480 On ch=1 n=64 v=77
494 On ch=2 n=82 v=84
496 On ch=2 n=81 v=0
504 On ch=1 n=58 v=0
504 On ch=1 n=61 v=0
504 On ch=1 n=64 v=0
508 On ch=2 n=82 v=0
510 On ch=2 n=81 v=90
525 On ch=2 n=80 v=84
528 On ch=1 n=43 v=0
529 On ch=2 n=81 v=0
538 On ch=2 n=80 v=0
572 On ch=2 n=79 v=88
576 On ch=1 n=43 v=72
576 On ch=1 n=62 v=90
576 On ch=1 n=59 v=80
576 On ch=1 n=65 v=90
579 On ch=2 n=79 v=0
600 On ch=1 n=62 v=0
600 On ch=1 n=59 v=0
600 On ch=1 n=65 v=0
606 On ch=2 n=67 v=84
616 On ch=2 n=67 v=0
619 On ch=2 n=69 v=70
624 On ch=1 n=43 v=0
625 On ch=2 n=67 v=100
626 On ch=2 n=69 v=0
634 On ch=2 n=66 v=116
638 On ch=2 n=67 v=0
659 On ch=2 n=66 v=0
660 On ch=2 n=67 v=92
677 On ch=2 n=68 v=91
677 On ch=2 n=67 v=0
702 On ch=2 n=68 v=0
704 On ch=2 n=69 v=100
721 On ch=2 n=70 v=80
723 On ch=2 n=69 v=0
739 On ch=2 n=70 v=0
750 On ch=2 n=71 v=100
766 On ch=2 n=71 v=0
768 On ch=1 n=36 v=68
770 On ch=2 n=72 v=104
816 On ch=1 n=60 v=70
816 On ch=1 n=55 v=64
816 On ch=1 n=64 v=76
816 On ch=1 n=36 v=0
818 On ch=2 n=72 v=0
840 On ch=1 n=60 v=0
840 On ch=1 n=55 v=0
840 On ch=1 n=64 v=0
845 On ch=2 n=72 v=91
852 On ch=2 n=72 v=0
863 On ch=2 n=72 v=100
864 On ch=1 n=43 v=70
874 On ch=2 n=72 v=0
911 On ch=2 n=72 v=92
912 On ch=1 n=60 v=72
912 On ch=1 n=55 v=59
912 On ch=1 n=64 v=80
912 On ch=1 n=43 v=0
923 On ch=2 n=72 v=0
936 On ch=1 n=60 v=0
936 On ch=1 n=55 v=0
936 On ch=1 n=64 v=0
960 On ch=1 n=36 v=72
963 On ch=2 n=72 v=92
1008 On ch=1 n=60 v=77
1008 On ch=1 n=55 v=68
1008 On ch=1 n=64 v=79
1008 On ch=1 n=36 v=0
1009 On ch=2 n=72 v=0
1032 On ch=1 n=60 v=0
1032 On ch=1 n=55 v=0
1032 On ch=1 n=64 v=0
1056 On ch=1 n=43 v=70
1057 On ch=2 n=71 v=92
1078 On ch=2 n=71 v=0
1104 On ch=1 n=60 v=80
1104 On ch=1 n=55 v=72
1104 On ch=1 n=64 v=80
1104 On ch=1 n=43 v=0
1106 On ch=2 n=72 v=92
1128 On ch=1 n=60 v=0
1128 On ch=1 n=55 v=0
1128 On ch=1 n=64 v=0
1132 On ch=2 n=72 v=0
1134 On ch=2 n=73 v=91
1147 On ch=2 n=73 v=0
1149 On ch=2 n=74 v=104
1152 On ch=1 n=38 v=72
1200 On ch=1 n=55 v=72
1200 On ch=1 n=59 v=78
1200 On ch=1 n=53 v=72
1200 On ch=1 n=62 v=43
1200 On ch=1 n=38 v=0
1224 On ch=1 n=55 v=0
1224 On ch=1 n=59 v=0
1224 On ch=1 n=53 v=0
1224 On ch=1 n=62 v=0
1248 On ch=1 n=43 v=72
1286 On ch=2 n=74 v=0
1296 On ch=1 n=62 v=78
1296 On ch=1 n=55 v=78
1296 On ch=1 n=53 v=70
1296 On ch=1 n=59 v=72
1296 On ch=1 n=43 v=0
1320 On ch=1 n=62 v=0
1320 On ch=1 n=55 v=0
1320 On ch=1 n=53 v=0
1320 On ch=1 n=59 v=0
1344 On ch=1 n=38 v=64
1370 On ch=2 n=67 v=92
1382 On ch=2 n=69 v=104
1386 On ch=2 n=67 v=0
1392 On ch=1 n=62 v=77
1392 On ch=1 n=55 v=72
1392 On ch=1 n=53 v=62
1392 On ch=1 n=59 v=71
1392 On ch=1 n=38 v=0
1393 On ch=2 n=69 v=0
1395 On ch=2 n=67 v=100
1406 On ch=2 n=66 v=104
1410 On ch=2 n=67 v=0
1416 On ch=1 n=62 v=0
1416 On ch=1 n=55 v=0
1416 On ch=1 n=53 v=0
1416 On ch=1 n=59 v=0
1430 On ch=2 n=66 v=0
1432 On ch=2 n=67 v=102
1440 On ch=1 n=43 v=76
1453 On ch=2 n=77 v=100
1453 On ch=2 n=67 v=0
1478 On ch=2 n=74 v=100
1479 On ch=2 n=77 v=0
1488 On ch=1 n=62 v=78
1488 On ch=1 n=55 v=70
1488 On ch=1 n=59 v=77
1488 On ch=1 n=53 v=61
1488 On ch=1 n=43 v=0
1496 On ch=2 n=71 v=92
1499 On ch=2 n=74 v=0
1512 On ch=1 n=62 v=0
1512 On ch=1 n=55 v=0
1512 On ch=1 n=59 v=0
1512 On ch=1 n=53 v=0
1517 On ch=2 n=71 v=0
1520 On ch=2 n=67 v=92
1536 On ch=1 n=47 v=76
1536 On ch=2 n=67 v=0
1538 On ch=2 n=74 v=116
1584 On ch=1 n=62 v=80
1584 On ch=1 n=53 v=72
1584 On ch=1 n=55 v=76
1584 On ch=1 n=59 v=79
1584 On ch=1 n=47 v=0
1587 On ch=2 n=74 v=0
1608 On ch=1 n=62 v=0
1608 On ch=1 n=53 v=0
1608 On ch=1 n=55 v=0
1608 On ch=1 n=59 v=0
1613 On ch=2 n=74 v=104
1622 On ch=2 n=74 v=0
1630 On ch=2 n=74 v=100
1632 On ch=1 n=43 v=68
1647 On ch=2 n=74 v=0
1679 On ch=2 n=74 v=106
1680 On ch=1 n=62 v=80
1680 On ch=1 n=55 v=72
1680 On ch=1 n=53 v=69
1680 On ch=1 n=59 v=72
1680 On ch=1 n=43 v=0
1697 On ch=2 n=74 v=0
1704 On ch=1 n=62 v=0
1704 On ch=1 n=55 v=0
1704 On ch=1 n=53 v=0
1704 On ch=1 n=59 v=0
1728 On ch=1 n=38 v=80
1729 On ch=2 n=74 v=104
1776 On ch=1 n=62 v=76
1776 On ch=1 n=55 v=72
1776 On ch=1 n=59 v=77
1776 On ch=1 n=53 v=64
1776 On ch=1 n=38 v=0
1778 On ch=2 n=73 v=96
1780 On ch=2 n=74 v=0
1800 On ch=1 n=62 v=0
1800 On ch=1 n=55 v=0
1800 On ch=1 n=59 v=0
1800 On ch=1 n=53 v=0
1805 On ch=2 n=73 v=0
1806 On ch=2 n=74 v=104
1824 On ch=1 n=43 v=72
1827 On ch=2 n=75 v=92
1829 On ch=2 n=74 v=0
1852 On ch=2 n=75 v=0
1854 On ch=2 n=83 v=104
1872 On ch=1 n=62 v=80
1872 On ch=1 n=53 v=70
1872 On ch=1 n=55 v=79
1872 On ch=1 n=59 v=80
1872 On ch=1 n=43 v=0
1886 On ch=2 n=82 v=92
1888 On ch=2 n=83 v=0
1896 On ch=1 n=62 v=0
1896 On ch=1 n=53 v=0
1896 On ch=1 n=55 v=0
1896 On ch=1 n=59 v=0
1901 On ch=2 n=81 v=88
1901 On ch=2 n=82 v=0
1914 On ch=2 n=80 v=91
1918 On ch=2 n=81 v=0
1920 On ch=1 n=36 v=71
1929 On ch=2 n=79 v=100
1930 On ch=2 n=80 v=0
1968 On ch=1 n=60 v=76
1968 On ch=1 n=55 v=80
1968 On ch=1 n=64 v=84
1968 On ch=1 n=36 v=0
1992 On ch=1 n=60 v=0
1992 On ch=1 n=55 v=0
1992 On ch=1 n=64 v=0
2015 On ch=2 n=79 v=0
2016 On ch=1 n=43 v=76
2047 On ch=2 n=72 v=100
2060 On ch=2 n=76 v=102
2061 On ch=2 n=72 v=0
2064 On ch=1 n=60 v=76
2064 On ch=1 n=55 v=64
2064 On ch=1 n=64 v=80
2064 On ch=1 n=43 v=0
2072 On ch=2 n=76 v=0
2076 On ch=2 n=71 v=100
2087 On ch=2 n=75 v=91
2088 On ch=1 n=60 v=0
2088 On ch=1 n=55 v=0
2088 On ch=1 n=64 v=0
2091 On ch=2 n=71 v=0
2102 On ch=2 n=75 v=0
2105 On ch=2 n=74 v=92
2108 On ch=2 n=70 v=100
2112 On ch=1 n=36 v=77
2160 On ch=1 n=60 v=88
2160 On ch=1 n=55 v=90
2160 On ch=1 n=64 v=88
2160 On ch=1 n=36 v=0
2181 On ch=2 n=70 v=0
2184 On ch=1 n=60 v=0
2184 On ch=1 n=55 v=0
2184 On ch=1 n=64 v=0
2192 On ch=2 n=74 v=0
2208 On ch=1 n=38 v=68
2232 On ch=1 n=38 v=0
2256 On ch=1 n=40 v=79
2256 On ch=1 n=60 v=88
2256 On ch=1 n=55 v=80
2256 On ch=1 n=64 v=90
2266 On ch=2 n=75 v=116
2280 On ch=1 n=40 v=0
2280 On ch=1 n=60 v=0
2280 On ch=1 n=55 v=0
2280 On ch=1 n=64 v=0
2280 On ch=2 n=75 v=0
2289 On ch=2 n=76 v=106
2304 On ch=1 n=41 v=76
2304 On ch=2 n=76 v=0
2306 On ch=2 n=77 v=116
2352 On ch=1 n=57 v=80
2352 On ch=1 n=60 v=72
2352 On ch=1 n=65 v=77
2352 On ch=1 n=41 v=0
2355 On ch=2 n=77 v=0
2376 On ch=1 n=57 v=0
2376 On ch=1 n=60 v=0
2376 On ch=1 n=65 v=0
2378 On ch=2 n=76 v=100
2392 On ch=2 n=76 v=0
2398 On ch=2 n=77 v=104
2400 On ch=1 n=36 v=76
2436 On ch=2 n=77 v=0
2448 On ch=1 n=57 v=79
2448 On ch=1 n=60 v=72
2448 On ch=1 n=65 v=78
2448 On ch=1 n=36 v=0
2472 On ch=2 n=79 v=92
2472 On ch=1 n=57 v=0
2472 On ch=1 n=60 v=0
2472 On ch=1 n=65 v=0
2489 On ch=2 n=79 v=0
2493 On ch=2 n=77 v=91
2496 On ch=1 n=41 v=80
2544 On ch=1 n=57 v=76
2544 On ch=1 n=60 v=78
2544 On ch=1 n=65 v=76
2544 On ch=1 n=41 v=0
2568 On ch=1 n=57 v=0
2568 On ch=1 n=60 v=0
2568 On ch=1 n=65 v=0
2574 On ch=2 n=77 v=0
2592 On ch=1 n=36 v=71
2640 On ch=1 n=57 v=72
2640 On ch=1 n=60 v=80
2640 On ch=1 n=65 v=84
2640 On ch=1 n=36 v=0
2643 On ch=2 n=79 v=104
2661 On ch=2 n=79 v=0
2664 On ch=1 n=57 v=0
2664 On ch=1 n=60 v=0
2664 On ch=1 n=65 v=0
2669 On ch=2 n=77 v=92
2685 On ch=2 n=77 v=0
2688 On ch=1 n=48 v=76
2689 On ch=2 n=76 v=92
2736 On ch=1 n=55 v=76
2736 On ch=1 n=60 v=84
2736 On ch=1 n=64 v=84
2736 On ch=1 n=48 v=0
2743 On ch=2 n=76 v=0
2760 On ch=1 n=55 v=0
2760 On ch=1 n=60 v=0
2760 On ch=1 n=64 v=0
2764 On ch=2 n=75 v=91
2777 On ch=2 n=75 v=0
2784 On ch=2 n=76 v=104
2784 On ch=1 n=43 v=68
2800 On ch=2 n=76 v=0
2811 On ch=2 n=75 v=92
2825 On ch=2 n=75 v=0
2827 On ch=2 n=74 v=100
2832 On ch=1 n=60 v=80
2832 On ch=1 n=55 v=64
2832 On ch=1 n=64 v=80
2832 On ch=1 n=43 v=0
2846 On ch=2 n=74 v=0
2856 On ch=1 n=60 v=0
2856 On ch=1 n=55 v=0
2856 On ch=1 n=64 v=0
2859 On ch=2 n=73 v=84
2872 On ch=2 n=73 v=0
2878 On ch=2 n=72 v=100
2880 On ch=1 n=48 v=80
2928 On ch=1 n=60 v=80
2928 On ch=1 n=55 v=64
2928 On ch=1 n=64 v=72
2928 On ch=1 n=48 v=0
2934 On ch=2 n=72 v=0
2952 On ch=1 n=60 v=0
2952 On ch=1 n=55 v=0
2952 On ch=1 n=64 v=0
2976 On ch=1 n=47 v=72
3000 On ch=1 n=47 v=0
3024 On ch=2 n=71 v=88
3024 On ch=1 n=45 v=72
3024 On ch=1 n=60 v=88
3024 On ch=1 n=55 v=72
3024 On ch=1 n=64 v=72
3040 On ch=2 n=72 v=84
3040 On ch=2 n=71 v=0
3048 On ch=1 n=45 v=0
3048 On ch=1 n=60 v=0
3048 On ch=1 n=55 v=0
3048 On ch=1 n=64 v=0
3052 On ch=2 n=73 v=92
3057 On ch=2 n=72 v=0
3069 On ch=2 n=74 v=104
3072 On ch=1 n=43 v=68
3072 On ch=2 n=73 v=0
3089 On ch=2 n=74 v=0
3120 On ch=1 n=62 v=72
3120 On ch=1 n=53 v=68
3120 On ch=1 n=55 v=71
3120 On ch=1 n=59 v=64
3120 On ch=1 n=43 v=0
3121 On ch=2 n=67 v=71
3138 On ch=2 n=69 v=84
3138 On ch=2 n=67 v=0
3144 On ch=1 n=62 v=0
3144 On ch=1 n=53 v=0
3144 On ch=1 n=55 v=0
3144 On ch=1 n=59 v=0
3146 On ch=2 n=70 v=91
3152 On ch=2 n=69 v=0
3161 On ch=2 n=71 v=106
3167 On ch=2 n=70 v=0
3168 On ch=1 n=38 v=80
3176 On ch=2 n=71 v=0
3214 On ch=2 n=62 v=100
3216 On ch=1 n=62 v=78
3216 On ch=1 n=53 v=68
3216 On ch=1 n=55 v=68
3216 On ch=1 n=59 v=68
3216 On ch=1 n=38 v=0
3227 On ch=2 n=63 v=92
3229 On ch=2 n=62 v=0
3240 On ch=1 n=62 v=0
3240 On ch=1 n=53 v=0
3240 On ch=1 n=55 v=0
3240 On ch=1 n=59 v=0
3244 On ch=2 n=64 v=116
3244 On ch=2 n=63 v=0
3257 On ch=2 n=64 v=0
3264 On ch=2 n=65 v=116
3264 On ch=1 n=43 v=72
3290 On ch=2 n=65 v=0
3292 On ch=2 n=69 v=100
3310 On ch=2 n=69 v=0
3312 On ch=2 n=72 v=100
3312 On ch=1 n=62 v=79
3312 On ch=1 n=55 v=80
3312 On ch=1 n=53 v=77
3312 On ch=1 n=59 v=78
3312 On ch=1 n=43 v=0
3336 On ch=1 n=62 v=0
3336 On ch=1 n=55 v=0
3336 On ch=1 n=53 v=0
3336 On ch=1 n=59 v=0
3337 On ch=2 n=72 v=0
3340 On ch=2 n=76 v=106
3356 On ch=2 n=76 v=0
3360 On ch=1 n=38 v=76
3363 On ch=2 n=74 v=116
3385 On ch=2 n=74 v=0
3397 On ch=2 n=79 v=91
3408 On ch=1 n=59 v=59
3408 On ch=1 n=62 v=62
3408 On ch=1 n=53 v=64
3408 On ch=1 n=55 v=64
3408 On ch=1 n=38 v=0
3418 On ch=2 n=83 v=92
3422 On ch=2 n=79 v=0
3432 On ch=1 n=59 v=0
3432 On ch=1 n=62 v=0
3432 On ch=1 n=55 v=0
3439 On ch=2 n=83 v=0
3445 On ch=2 n=86 v=116
3452 On ch=1 n=53 v=0
3456 On ch=1 n=36 v=79
3456 On ch=1 n=60 v=94
3461 On ch=2 n=84 v=92
3461 On ch=2 n=86 v=0
3480 On ch=1 n=60 v=0
3497 On ch=2 n=84 v=0
3504 On ch=1 n=36 v=0
3528 On ch=1 n=45 v=76
3528 On ch=1 n=57 v=88
3552 On ch=1 n=43 v=88
3552 On ch=1 n=55 v=92
3552 On ch=1 n=45 v=0
3572 On ch=1 n=57 v=0
3576 On ch=1 n=43 v=0
3576 On ch=1 n=55 v=0
3600 On ch=1 n=40 v=94
3600 On ch=1 n=52 v=88
3624 On ch=1 n=40 v=0
3624 On ch=1 n=52 v=0
3648 On ch=1 n=36 v=95
3648 On ch=1 n=48 v=104
3672 On ch=1 n=48 v=0
3696 On ch=1 n=36 v=0
3726 On ch=2 n=91 v=83
3733 On ch=2 n=93 v=88
3737 On ch=2 n=91 v=0
3741 On ch=2 n=95 v=92
3745 On ch=2 n=93 v=0
3749 On ch=2 n=96 v=116
3752 On ch=2 n=95 v=0
3761 On ch=2 n=96 v=0
4224 Meta TrkEnd
TrkEnd
SHAR_EOF
chmod 0644 example4.txt ||
echo 'restore of example4.txt failed'
Wc_c="`wc -c < 'example4.txt'`"
test 11751 -eq "$Wc_c" ||
	echo 'example4.txt: original size 11751, current size' "$Wc_c"
fi
# ============= example5.mid ==============
if test -f 'example5.mid' -a X"$1" != X"-c"; then
	echo 'x - skipping example5.mid (File already exists)'
else
echo 'x - extracting example5.mid (Binary)'
sed 's/^X//' << 'SHAR_EOF' | uudecode &&
begin 600 example5.mid
M351H9`````8````!`#!-5')K```#X@#_`294<F%S:"$A`"`@("`@("`@("`@
M("`@("`@("`@("`@("`@("`@(`"0/D``L`0K``0N`00S`@0W`00Z`00^`01!
M`01$`=`"`@4!L`1(`=```+`$30"0/@`!L`13`01:`01A`01G`=`#`;`$;`'0
M$@"P!'`!!'0!T#``L`1W`01Z`=!3`+`$?P&00$`!T'4"?P2P`5,"`5`"`4P!
M!'<`D$```;`$<`$!20`$:@$$9`$$7P$!1P$$6@$$50$$4`$$3`$!00`$1P$$
M0@&00D``L`0\`0$^``0W`00Q`0$Z``0K`00E`@$U``0>`009`0$Q``03`>!\
M/@"P!`\!X'L]`+`$"@'@>#P`L`0$`0$L``0``)!"``'@=SL`=#H!L`$H`>!S
M.0%P.`!L-@%K-0"P`2,!X&@T`6<S`&,Q`6`P`+`!'`'@7"X!6"P`5RL!5"H`
ML`$7`9!#0`#@4RD!4"@!3R<`L`$3`00#`00(`00,`000`006`0$8``0<`>!3
M*0%7*P"P!"(!`1T`!"@!X%LM`+`$+P"00P`!X&`P`+`$-P$!)`#@9#(`L`0^
M`>!H-`"P!$0!X&PV`+`!+``$2@'@<#@`L`11`>!T.@"P!%8!X'@\`+`!,P`$
M70'@?#X`L`1C`>``0`"P!&H!`3H!!&\!D$5``+`!/@`$<@$$=`$!0@`$=P$$
M>@$$?0$!10`$?P(!2`(!3`(!40&010`!L`%4`@%8`@%<`P%A`>`$0@$(1`$,
M1@&01T``L`%J``1_`>`02``42@"P!'@!!'(!`7``X!M-`+`$;`+@'T\`L`%T
M``1H`01E`>`C40"P!&0!X"=3`+`$8@$!>``$70'@*U4`L`16`01.`>`O5P"P
M!$8`D$<``;`!?``$/@$$.`$$-`$$,`'@+%8`L`0M`>`K50"P`7D!X"=3`+`$
M*0'@(U$`'T\`L`0E`>`;30"P`6X`!"$!X!1*`+`$'`'@$$@`"T4`L`08`9!)
M0`#@!T,`L`%@``03`>``0`"P!`X!!`H!`5``!`8!!`(!`44`!``"`3P"`38#
M`3(`D$D``K`!+P$$`@$!*P`$!@$$"P'@?#X!>ST`L`$E``00`>!W.P!S.0"P
M!!8!X&\W`+`$'0'@:S4`L`$9``0D`>!D,@!C,0"P!"L!D$I``.!<+@"P!#(!
MX%LM`+`!#0`$.@'@5RL`L`1"`>!3*0!0*`"P!$<!X$\G`+`!`@`$2@+@2R4!
ML`$``.!()`602@`"X$PF`5`H`;`!"0#@5RL!8#`!:S4!<#@`L`$A`>![/0``
:0`*P`3,`T"@"L`$_`=```K`!1P(!2FS_+P`!
`
end
SHAR_EOF
chmod 0644 example5.mid ||
echo 'restore of example5.mid failed'
Wc_c="`wc -c < 'example5.mid'`"
test 1016 -eq "$Wc_c" ||
	echo 'example5.mid: original size 1016, current size' "$Wc_c"
fi
# ============= example5.txt ==============
if test -f 'example5.txt' -a X"$1" != X"-c"; then
	echo 'x - skipping example5.txt (File already exists)'
else
echo 'x - extracting example5.txt (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'example5.txt' &&
MFile 0 1 48
MTrk
0 Meta Text "Trash!!\0                              "
0 On ch=1 n=62 v=64
0 Par ch=1 c=4 v=43
0 Par ch=1 c=4 v=46
1 Par ch=1 c=4 v=51
3 Par ch=1 c=4 v=55
4 Par ch=1 c=4 v=58
5 Par ch=1 c=4 v=62
6 Par ch=1 c=4 v=65
7 Par ch=1 c=4 v=68
8 ChPr ch=1 v=2
10 ChPr ch=1 v=5
11 Par ch=1 c=4 v=72
12 ChPr ch=1 v=0
12 Par ch=1 c=4 v=77
12 On ch=1 n=62 v=0
13 Par ch=1 c=4 v=83
14 Par ch=1 c=4 v=90
15 Par ch=1 c=4 v=97
16 Par ch=1 c=4 v=103
17 ChPr ch=1 v=3
18 Par ch=1 c=4 v=108
19 ChPr ch=1 v=18
19 Par ch=1 c=4 v=112
20 Par ch=1 c=4 v=116
21 ChPr ch=1 v=48
21 Par ch=1 c=4 v=119
22 Par ch=1 c=4 v=122
23 ChPr ch=1 v=83
23 Par ch=1 c=4 v=127
24 On ch=1 n=64 v=64
25 ChPr ch=1 v=117
27 ChPr ch=1 v=127
31 Par ch=1 c=1 v=83
33 Par ch=1 c=1 v=80
35 Par ch=1 c=1 v=76
36 Par ch=1 c=4 v=119
36 On ch=1 n=64 v=0
37 Par ch=1 c=4 v=112
38 Par ch=1 c=1 v=73
38 Par ch=1 c=4 v=106
39 Par ch=1 c=4 v=100
40 Par ch=1 c=4 v=95
41 Par ch=1 c=1 v=71
42 Par ch=1 c=4 v=90
43 Par ch=1 c=4 v=85
44 Par ch=1 c=4 v=80
45 Par ch=1 c=4 v=76
46 Par ch=1 c=1 v=65
46 Par ch=1 c=4 v=71
47 Par ch=1 c=4 v=66
48 On ch=1 n=66 v=64
48 Par ch=1 c=4 v=60
49 Par ch=1 c=1 v=62
49 Par ch=1 c=4 v=55
50 Par ch=1 c=4 v=49
51 Par ch=1 c=1 v=58
51 Par ch=1 c=4 v=43
52 Par ch=1 c=4 v=37
54 Par ch=1 c=1 v=53
54 Par ch=1 c=4 v=30
55 Par ch=1 c=4 v=25
56 Par ch=1 c=1 v=49
56 Par ch=1 c=4 v=19
57 Pb ch=1 v=15934
57 Par ch=1 c=4 v=15
58 Pb ch=1 v=15805
58 Par ch=1 c=4 v=10
59 Pb ch=1 v=15420
59 Par ch=1 c=4 v=4
60 Par ch=1 c=1 v=44
60 Par ch=1 c=4 v=0
60 On ch=1 n=66 v=0
61 Pb ch=1 v=15291
61 Pb ch=1 v=14906
62 Par ch=1 c=1 v=40
63 Pb ch=1 v=14777
64 Pb ch=1 v=14392
64 Pb ch=1 v=13878
65 Pb ch=1 v=13749
65 Par ch=1 c=1 v=35
66 Pb ch=1 v=13364
67 Pb ch=1 v=13235
67 Pb ch=1 v=12721
68 Pb ch=1 v=12336
68 Par ch=1 c=1 v=28
69 Pb ch=1 v=11822
70 Pb ch=1 v=11308
70 Pb ch=1 v=11179
71 Pb ch=1 v=10794
71 Par ch=1 c=1 v=23
72 On ch=1 n=67 v=64
72 Pb ch=1 v=10665
73 Pb ch=1 v=10280
74 Pb ch=1 v=10151
74 Par ch=1 c=1 v=19
75 Par ch=1 c=4 v=3
76 Par ch=1 c=4 v=8
77 Par ch=1 c=4 v=12
78 Par ch=1 c=4 v=16
79 Par ch=1 c=4 v=22
80 Par ch=1 c=1 v=24
80 Par ch=1 c=4 v=28
81 Pb ch=1 v=10665
82 Pb ch=1 v=11179
82 Par ch=1 c=4 v=34
83 Par ch=1 c=1 v=29
83 Par ch=1 c=4 v=40
84 Pb ch=1 v=11693
84 Par ch=1 c=4 v=47
84 On ch=1 n=67 v=0
85 Pb ch=1 v=12336
85 Par ch=1 c=4 v=55
86 Par ch=1 c=1 v=36
86 Pb ch=1 v=12850
86 Par ch=1 c=4 v=62
87 Pb ch=1 v=13364
87 Par ch=1 c=4 v=68
88 Pb ch=1 v=13878
88 Par ch=1 c=1 v=44
88 Par ch=1 c=4 v=74
89 Pb ch=1 v=14392
89 Par ch=1 c=4 v=81
90 Pb ch=1 v=14906
90 Par ch=1 c=4 v=86
91 Pb ch=1 v=15420
91 Par ch=1 c=1 v=51
91 Par ch=1 c=4 v=93
92 Pb ch=1 v=15934
92 Par ch=1 c=4 v=99
93 Pb ch=1 v=64
93 Par ch=1 c=4 v=106
94 Par ch=1 c=1 v=58
95 Par ch=1 c=4 v=111
96 On ch=1 n=69 v=64
96 Par ch=1 c=1 v=62
96 Par ch=1 c=4 v=114
97 Par ch=1 c=4 v=116
98 Par ch=1 c=1 v=66
98 Par ch=1 c=4 v=119
99 Par ch=1 c=4 v=122
100 Par ch=1 c=4 v=125
101 Par ch=1 c=1 v=69
101 Par ch=1 c=4 v=127
103 Par ch=1 c=1 v=72
105 Par ch=1 c=1 v=76
107 Par ch=1 c=1 v=81
108 On ch=1 n=69 v=0
109 Par ch=1 c=1 v=84
111 Par ch=1 c=1 v=88
113 Par ch=1 c=1 v=92
116 Par ch=1 c=1 v=97
117 Pb ch=1 v=578
118 Pb ch=1 v=1092
119 Pb ch=1 v=1606
120 On ch=1 n=71 v=64
120 Par ch=1 c=1 v=106
120 Par ch=1 c=4 v=127
121 Pb ch=1 v=2120
121 Pb ch=1 v=2634
121 Par ch=1 c=4 v=120
122 Par ch=1 c=4 v=114
123 Par ch=1 c=1 v=112
123 Pb ch=1 v=3533
123 Par ch=1 c=4 v=108
125 Pb ch=1 v=4047
125 Par ch=1 c=1 v=116
125 Par ch=1 c=4 v=104
126 Par ch=1 c=4 v=101
127 Pb ch=1 v=4561
127 Par ch=1 c=4 v=100
128 Pb ch=1 v=5075
128 Par ch=1 c=4 v=98
129 Par ch=1 c=1 v=120
129 Par ch=1 c=4 v=93
130 Pb ch=1 v=5589
130 Par ch=1 c=4 v=86
131 Par ch=1 c=4 v=78
132 Pb ch=1 v=6103
132 Par ch=1 c=4 v=70
132 On ch=1 n=71 v=0
133 Par ch=1 c=1 v=124
133 Par ch=1 c=4 v=62
134 Par ch=1 c=4 v=56
135 Par ch=1 c=4 v=52
136 Par ch=1 c=4 v=48
137 Pb ch=1 v=5718
137 Par ch=1 c=4 v=45
138 Pb ch=1 v=5589
138 Par ch=1 c=1 v=121
139 Pb ch=1 v=5075
139 Par ch=1 c=4 v=41
140 Pb ch=1 v=4561
140 Pb ch=1 v=4047
140 Par ch=1 c=4 v=37
141 Pb ch=1 v=3533
141 Par ch=1 c=1 v=110
141 Par ch=1 c=4 v=33
142 Pb ch=1 v=2634
142 Par ch=1 c=4 v=28
143 Pb ch=1 v=2120
143 Pb ch=1 v=1477
143 Par ch=1 c=4 v=24
144 On ch=1 n=73 v=64
144 Pb ch=1 v=963
144 Par ch=1 c=1 v=96
144 Par ch=1 c=4 v=19
145 Pb ch=1 v=64
145 Par ch=1 c=4 v=14
146 Par ch=1 c=4 v=10
147 Par ch=1 c=1 v=80
147 Par ch=1 c=4 v=6
148 Par ch=1 c=4 v=2
149 Par ch=1 c=1 v=69
149 Par ch=1 c=4 v=0
151 Par ch=1 c=1 v=60
153 Par ch=1 c=1 v=54
156 Par ch=1 c=1 v=50
156 On ch=1 n=73 v=0
158 Par ch=1 c=1 v=47
159 Par ch=1 c=4 v=2
160 Par ch=1 c=1 v=43
160 Par ch=1 c=4 v=6
161 Par ch=1 c=4 v=11
162 Pb ch=1 v=15934
163 Pb ch=1 v=15805
163 Par ch=1 c=1 v=37
163 Par ch=1 c=4 v=16
164 Pb ch=1 v=15291
164 Pb ch=1 v=14777
164 Par ch=1 c=4 v=22
165 Pb ch=1 v=14263
165 Par ch=1 c=4 v=29
166 Pb ch=1 v=13749
166 Par ch=1 c=1 v=25
166 Par ch=1 c=4 v=36
167 Pb ch=1 v=12850
167 Pb ch=1 v=12721
167 Par ch=1 c=4 v=43
168 On ch=1 n=74 v=64
168 Pb ch=1 v=11822
168 Par ch=1 c=4 v=50
169 Pb ch=1 v=11693
169 Par ch=1 c=1 v=13
169 Par ch=1 c=4 v=58
170 Pb ch=1 v=11179
170 Par ch=1 c=4 v=66
171 Pb ch=1 v=10665
171 Pb ch=1 v=10280
171 Par ch=1 c=4 v=71
172 Pb ch=1 v=10151
172 Par ch=1 c=1 v=2
172 Par ch=1 c=4 v=74
174 Pb ch=1 v=9637
175 Par ch=1 c=1 v=0
175 Pb ch=1 v=9252
180 On ch=1 n=74 v=0
182 Pb ch=1 v=9766
183 Pb ch=1 v=10280
184 Par ch=1 c=1 v=9
184 Pb ch=1 v=11179
185 Pb ch=1 v=12336
186 Pb ch=1 v=13749
187 Pb ch=1 v=14392
187 Par ch=1 c=1 v=33
188 Pb ch=1 v=15805
188 Pb ch=1 v=64
190 Par ch=1 c=1 v=51
190 ChPr ch=1 v=40
192 Par ch=1 c=1 v=63
193 ChPr ch=1 v=0
195 Par ch=1 c=1 v=71
197 Par ch=1 c=1 v=74
305 Meta TrkEnd
TrkEnd
SHAR_EOF
chmod 0644 example5.txt ||
echo 'restore of example5.txt failed'
Wc_c="`wc -c < 'example5.txt'`"
test 5715 -eq "$Wc_c" ||
	echo 'example5.txt: original size 5715, current size' "$Wc_c"
fi
# ============= makefile ==============
if test -f 'makefile' -a X"$1" != X"-c"; then
	echo 'x - skipping makefile (File already exists)'
else
echo 'x - extracting makefile (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'makefile' &&
# $Id: makefile.unx,v 1.3 1991/11/15 19:31:00 piet Rel $
X
CFLAGS = -O
# If you have an old version of flex that defines yyleng
# as a macro rather than a variable, uncomment the following line:
# CFLAGS = -O -DNO_YYLENG_VAR
X
SRCS = crack.c mf2t.c midifile.c midifile.h t2mf.c t2mf.h \
X       t2mf.fl t2mflex.c yyread.c \
X       README makefile.st makefile.unx \
X       example1.mid example1.txt example2.mid example2.txt example3.mid \
X       example3.txt example4.mid example4.txt example5.mid example5.txt
X
EXECS = mf2t t2mf
X       
all:	$(EXECS)
X
t2mf:	midifile.o t2mf.o t2mf.h t2mflex.o crack.o
X	$(CC) t2mf.o midifile.o crack.o t2mflex.o -o t2mf
X	
t2mflex.c: t2mf.fl
X	flex -is -Ce t2mf.fl
X	mv lex.yy.c t2mflex.c
X
t2mflex.o: t2mflex.c t2mf.h
X
mf2t:	midifile.o mf2t.o crack.o
X	$(CC) mf2t.o midifile.o crack.o -o mf2t
X
tar:	
X	tar cf mf2t.tar $(SRCS)
X	compress mf2t.tar
X
test :
X	@-for i in *.mid ; \
X	do \
X		mf2t $$i | t2mf > tmp.mf1 ; \
X		mf2t tmp.mf1 | t2mf > tmp.mf2 ; \
X		if [ "`cmp tmp.mf1 tmp.mf2`" != "" ] ; \
X		then \
X			echo "Test on $$i failed!" ; \
X		else \
X			echo "Test on $$i succeeded!" ; \
X		fi ; \
X	done ; rm -f tmp.mf1 tmp.mf2
SHAR_EOF
chmod 0644 makefile ||
echo 'restore of makefile failed'
Wc_c="`wc -c < 'makefile'`"
test 1145 -eq "$Wc_c" ||
	echo 'makefile: original size 1145, current size' "$Wc_c"
fi
# ============= makefile.st ==============
if test -f 'makefile.st' -a X"$1" != X"-c"; then
	echo 'x - skipping makefile.st (File already exists)'
else
echo 'x - extracting makefile.st (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'makefile.st' &&
# $Id: makefile.st,v 1.3 1991/11/15 19:31:00 piet Rel $
# Makefile for Atari ST with Sozobon C.
# CP = cp
X
CFLAGS = -O -Datarist
# If you have an old version of flex that defines yyleng
# as a macro rather than a variable, uncomment the following line:
# CFLAGS = -O -DNO_YYLENG_VAR
X
SRCS = crack.c mf2t.c midifile.c midifile.h t2mf.c t2mf.h \
X       t2mf.fl t2mflex.c yyread.c \
X       README makefile.st makefile.unx \
X       example1.mid example1.txt example2.mid example2.txt example3.mid \
X       example3.txt example4.mid example4.txt example5.mid example5.txt
X
EXECS = mf2t.ttp t2mf.ttp
X       
all:	$(EXECS)
X
t2mf.ttp:	midifile.o t2mf.o t2mf.h t2mflex.o crack.o
X	$(CC) -f t2mf.o midifile.o crack.o t2mflex.o libfl.a -o t2mf.ttp
X	
t2mflex.c: t2mf.fl
X	flex -is -Ce t2mf.fl
X	mv lexyy.c t2mflex.c
X
t2mflex.o: t2mflex.c t2mf.h
X	
mf2t.ttp:	midifile.o mf2t.o crack.o
X	$(CC) -f mf2t.o midifile.o crack.o -o mf2t.ttp
X
libfl.a:	yyread.o
X	ar r libfl.a yyread.o
X
zoo:	$(SRCS) $(EXECS)
X	zoo ah// mf2t.zoo $(SRCS) $(EXECS)
SHAR_EOF
chmod 0644 makefile.st ||
echo 'restore of makefile.st failed'
Wc_c="`wc -c < 'makefile.st'`"
test 1017 -eq "$Wc_c" ||
	echo 'makefile.st: original size 1017, current size' "$Wc_c"
fi
# ============= makefile.unx ==============
if test -f 'makefile.unx' -a X"$1" != X"-c"; then
	echo 'x - skipping makefile.unx (File already exists)'
else
echo 'x - extracting makefile.unx (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'makefile.unx' &&
# $Id: makefile.unx,v 1.3 1991/11/15 19:31:00 piet Rel $
X
CFLAGS = -O
# If you have an old version of flex that defines yyleng
# as a macro rather than a variable, uncomment the following line:
# CFLAGS = -O -DNO_YYLENG_VAR
X
SRCS = crack.c mf2t.c midifile.c midifile.h t2mf.c t2mf.h \
X       t2mf.fl t2mflex.c yyread.c \
X       README makefile.st makefile.unx \
X       example1.mid example1.txt example2.mid example2.txt example3.mid \
X       example3.txt example4.mid example4.txt example5.mid example5.txt
X
EXECS = mf2t t2mf
X       
all:	$(EXECS)
X
t2mf:	midifile.o t2mf.o t2mf.h t2mflex.o crack.o
X	$(CC) t2mf.o midifile.o crack.o t2mflex.o -o t2mf
X	
t2mflex.c: t2mf.fl
X	flex -is -Ce t2mf.fl
X	mv lex.yy.c t2mflex.c
X
t2mflex.o: t2mflex.c t2mf.h
X
mf2t:	midifile.o mf2t.o crack.o
X	$(CC) mf2t.o midifile.o crack.o -o mf2t
X
tar:	
X	tar cf mf2t.tar $(SRCS)
X	compress mf2t.tar
X
test :
X	@-for i in *.mid ; \
X	do \
X		mf2t $$i | t2mf > tmp.mf1 ; \
X		mf2t tmp.mf1 | t2mf > tmp.mf2 ; \
X		if [ "`cmp tmp.mf1 tmp.mf2`" != "" ] ; \
X		then \
X			echo "Test on $$i failed!" ; \
X		else \
X			echo "Test on $$i succeeded!" ; \
X		fi ; \
X	done ; rm -f tmp.mf1 tmp.mf2
SHAR_EOF
chmod 0644 makefile.unx ||
echo 'restore of makefile.unx failed'
Wc_c="`wc -c < 'makefile.unx'`"
test 1145 -eq "$Wc_c" ||
	echo 'makefile.unx: original size 1145, current size' "$Wc_c"
fi
# ============= mf2t.c ==============
if test -f 'mf2t.c' -a X"$1" != X"-c"; then
	echo 'x - skipping mf2t.c (File already exists)'
else
echo 'x - extracting mf2t.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'mf2t.c' &&
/* $Id: mf2t.c,v 1.4 1991/11/16 20:20:10 piet Rel $ */
/*
X * mf2t
X * 
X * Convert a MIDI file to text.
X */
X
#include <stdio.h>
#include <ctype.h>
#include "midifile.h"
X
static int TrkNr;
static int Measure, Beat, Clicks;
X
extern int arg_index;
extern char *arg_option;
X
/* options */
X
static int fold = 0;		/* fold long lines */
static int notes = 0;		/* print notes as a-g */
static int times = 0;		/* print times as Measure/beat/click */
X
static char *Onmsg  = "On ch=%d n=%s v=%d\n";
static char *Offmsg = "Off ch=%d n=%s v=%d\n";
static char *PoPrmsg = "PoPr ch=%d n=%s v=%d\n";
static char *Parmsg = "Par ch=%d c=%d v=%d\n";
static char *Pbmsg  = "Pb ch=%d v=%d\n";
static char *PrChmsg = "PrCh ch=%d p=%d\n";
static char *ChPrmsg = "ChPr ch=%d v=%d\n";
X
static FILE *F;
X
filegetc()
{
X	return(getc(F));
}
X
main(argc,argv)
char **argv;
{
X	FILE *efopen();
X	int flg;
X	
X	Mf_nomerge = 1;
X	while (flg = crack (argc, argv, "F|f|BbNnTtVvMm", 0)) {
X		switch (flg) {
X		case 'f':
X		case 'F':
X			if (*arg_option)
X				fold = atoi(arg_option);
X			else
X				fold = 80;
X			break;
X		case 'm':
X		case 'M':
X			Mf_nomerge = 0;
X			break;
X		case 'n':
X		case 'N':
X			notes++;
X			break;
X		case 't':
X		case 'T':
X		case 'b':
X		case 'B':
X			times++;
X			break;
X		case 'v':
X		case 'V':
X			Onmsg  = "On ch=%d note=%s vol=%d\n";
X			Offmsg = "Off ch=%d note=%s vol=%d\n";
X			PoPrmsg = "PolyPr ch=%d note=%s val=%d\n";
X			Parmsg = "Param ch=%d con=%d val=%d\n";
X			Pbmsg  = "Pb ch=%d val=%d\n";
X			PrChmsg = "ProgCh ch=%d prog=%d\n";
X			ChPrmsg = "ChanPr ch=%d val=%d\n";
X			break;
X		}
X	}
X	if ( arg_index < argc )
X		F = efopen(argv[arg_index++],"rb");
X	else
X		F = fdopen(fileno(stdin),"rb");
X	if (arg_index < argc &&
X		!freopen (argv[arg_index],"w",stdout))
X			error ("Can't open output file");
X
X	initfuncs();
X	Mf_getc = filegetc;
X	TrkNr = 0;
X	Measure = 4;
X	Beat = 96;
X	Clicks = 96;
X	mfread();
X	if (ferror(F)) error ("Output file error");
X	fclose(F);
X	exit(0);
}
X
FILE *
efopen(name,mode)
char *name;
char *mode;
{
X	FILE *f;
X	extern int errno;
X	extern char *sys_errlist[];
X	extern int sys_nerr;
X	char *errmess;
X
X	if ( (f=fopen(name,mode)) == NULL ) {
X		(void) fprintf(stderr,"*** ERROR *** Cannot open '%s'!\n",name);
X		if ( errno <= sys_nerr )
X			errmess = sys_errlist[errno];
X		else
X			errmess = "Unknown error!";
X		(void) fprintf(stderr,"************* Reason: %s\n",errmess);
X		exit(1);
X	}
X	return(f);
}
X
error(s)
char *s;
{
X	fprintf(stderr,"Error: %s\n",s);
}
X
X	
char *
mknote(pitch)
{
X	static char * Notes [] =
X		{ "c", "c#", "d", "d#", "e", "f", "f#", "g",
X		  "g#", "a", "a#", "b" };
X	static char buf[5];
X	if ( notes )
X		sprintf (buf, "%s%d", Notes[pitch % 12], pitch/12);
X	else
X		sprintf (buf, "%d", pitch);
X	return buf;
}
X
myheader(format,ntrks,division)
{
X	if (division & 0x8000) { /* SMPTE */
X	    times = 0;		 /* Can't do beats */
X	    printf("MFile %d %d %d %d\n",format,ntrks,
X	    			-((-(division>>8))&0xff), division&0xff);
X	} else
X	    printf("MFile %d %d %d\n",format,ntrks,division);
X	if (format > 2) {
X		fprintf(stderr, "Can't deal with format %d files\n", format);
X		exit (1);
X	}
X	Clicks = division;
}
X
mytrstart()
{
X	printf("MTrk\n");
X	TrkNr ++;
}
X
mytrend()
{
X	printf("TrkEnd\n");
}
X
mynon(chan,pitch,vol)
{
X	prtime();
X	printf(Onmsg,chan+1,mknote(pitch),vol);
}
X
mynoff(chan,pitch,vol)
{
X	prtime();
X	printf(Offmsg,chan+1,mknote(pitch),vol);
}
X
mypressure(chan,pitch,press)
{
X	prtime();
X	printf(PoPrmsg,chan+1,mknote(pitch),press);
}
X
myparameter(chan,control,value)
{
X	prtime();
X	printf(Parmsg,chan+1,control,value);
}
X
mypitchbend(chan,msb,lsb)
{
X	prtime();
X	printf(Pbmsg,chan+1,128*msb+lsb);
}
X
myprogram(chan,program)
{
X	prtime();
X	printf(PrChmsg,chan+1,program);
}
X
mychanpressure(chan,press)
{
X	prtime();
X	printf(ChPrmsg,chan+1,press);
}
X
mysysex(leng,mess)
char *mess;
{
X	prtime();
X	printf("SysEx");
X	prhex (mess, leng);
}
X
mymmisc(type,leng,mess)
char *mess;
{
X	prtime();
X	printf("Meta 0x%02x",type);
X	prhex (mess, leng);
}
X
mymspecial(type,leng,mess)
char *mess;
{
X	prtime();
X	printf("SeqSpec 0x%02x",type);
X	prhex (mess, leng);
}
X
mymtext(type,leng,mess)
char *mess;
{
X	static char *ttype[] = {
X		NULL,
X		"Text",		/* type=0x01 */
X		"Copyright",	/* type=0x02 */
X		"TrkName",
X		"InstrName",	/* ...       */
X		"Lyric",
X		"Marker",
X		"Cue",		/* type=0x07 */
X		"Unrec"
X	};
X	int unrecognized = (sizeof(ttype)/sizeof(char *)) - 1;
X
X	prtime();
X	if ( type < 1 || type > unrecognized )
X		printf("Meta 0x%02x ",type);
X	else if (type == 3 && TrkNr == 1)
X		printf("Meta SeqName ");
X	else
X		printf("Meta %s ",ttype[type]);
X	prtext (mess, leng);
}
X
mymseq(num)
{
X	prtime();
X	printf("SeqNr %d\n",num);
}
X
mymeot()
{
X	prtime();
X	printf("Meta TrkEnd\n");
}
X
mykeysig(sf,mi)
{
X	prtime();
X	printf("KeySig %d %s\n", sf, (mi?"minor":"major"));
}
X
mytempo(tempo)
long tempo;
{
X	prtime();
X	printf("Tempo %ld\n",tempo);
}
X
mytimesig(nn,dd,cc,bb)
{
X	int denom = 1;
X	while ( dd-- > 0 )
X		denom *= 2;
X	prtime();
X	printf("TimeSig %d/%d %d %d\n",
X		nn,denom,cc,bb);
X	Measure = nn;
X	Beat = 4 * Clicks / denom;
}
X
mysmpte(hr,mn,se,fr,ff)
{
X	prtime();
X	printf("SMPTE %d %d %d %d %d\n",
X		hr,mn,se,fr,ff);
}
X
myarbitrary(leng,mess)
char *mess;
{
X	prtime();
X	printf("Arb",leng);
X	prhex (mess, leng);
}
X
prtime()
{
X	if (times) {
X		long m = Mf_currtime/Beat;
X		printf ("%ld:%ld:%ld ", m/Measure, m%Measure, Mf_currtime%Beat);
X	} else
X		printf("%ld ",Mf_currtime);
}
X
prtext(p, leng)
unsigned char *p; int leng;
{
X	int n, c;
X	int pos = 25;
X	
X	printf("\"");
X	for ( n=0; n<leng; n++ ) {
X		c = *p++;
X		if (fold && pos >= fold) {
X			printf ("\\\n\t");
X			pos = 13;	/* tab + \xab + \ */
X			if (c == ' ' || c == '\t') {
X				putchar ('\\');
X				++pos;
X			}
X		}
X		switch (c) {
X		case '\\':
X		case '"':
X			printf ("\\%c", c);
X			pos += 2;
X			break;
X		case '\r':
X			printf ("\\r");
X			pos += 2;
X			break;
X		case '\n':
X			printf ("\\n");
X			pos += 2;
X			break;
X		case '\0':
X			printf ("\\0");
X			pos += 2;
X			break;
X		default:
X			if (isprint(c)) {
X				putchar(c);
X				++pos;
X			} else {
X				printf("\\x%02x" , c);
X				pos += 4;
X			}
X		}
X	}
X	printf("\"\n");
}
X
prhex(p, leng)
unsigned char *p; int leng;
{
X	int n;
X	int pos = 25;
X
X	for ( n=0; n<leng; n++,p++ ) {
X		if (fold && pos >= fold) {
X			printf ("\\\n\t%02x" , *p);
X			pos = 14;	/* tab + ab + " ab" + \ */
X		}
X		else {
X			printf(" %02x" , *p);
X			pos += 3;
X		}
X	}
X	printf("\n");
X	
}
X
initfuncs()
{
X	Mf_error = error;
X	Mf_header =  myheader;
X	Mf_starttrack =  mytrstart;
X	Mf_endtrack =  mytrend;
X	Mf_on =  mynon;
X	Mf_off =  mynoff;
X	Mf_pressure =  mypressure;
X	Mf_parameter =  myparameter;
X	Mf_pitchbend =  mypitchbend;
X	Mf_program =  myprogram;
X	Mf_chanpressure =  mychanpressure;
X	Mf_sysex =  mysysex;
X	Mf_metamisc =  mymmisc;
X	Mf_seqnum =  mymseq;
X	Mf_eot =  mymeot;
X	Mf_timesig =  mytimesig;
X	Mf_smpte =  mysmpte;
X	Mf_tempo =  mytempo;
X	Mf_keysig =  mykeysig;
X	Mf_sqspecific =  mymspecial;
X	Mf_text =  mymtext;
X	Mf_arbitrary =  myarbitrary;
}
SHAR_EOF
chmod 0644 mf2t.c ||
echo 'restore of mf2t.c failed'
Wc_c="`wc -c < 'mf2t.c'`"
test 6855 -eq "$Wc_c" ||
	echo 'mf2t.c: original size 6855, current size' "$Wc_c"
fi
# ============= midifile.c ==============
if test -f 'midifile.c' -a X"$1" != X"-c"; then
	echo 'x - skipping midifile.c (File already exists)'
else
echo 'x - extracting midifile.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'midifile.c' &&
/* $Id: midifile.c,v 1.4 1991/11/17 21:57:26 piet Rel piet $ */
/*
X * midifile 1.11
X * 
X * Read and write a MIDI file.  Externally-assigned function pointers are 
X * called upon recognizing things in the file.
X *
X * Original release by Tim Thompson, tjt@twitch.att.com
X *
X * June 1989 - Added writing capability, M. Czeiszperger.
X *
X * Oct 1991 - Modifications by Piet van Oostrum <piet@cs.ruu.nl>:
X *	Changed identifiers to be 7 char unique.
X *	Added sysex write capability (mf_w_sysex_event)
X *	Corrected a bug in writing of tempo track
X *	Added code to implement running status on write
X *	Added check for meta end of track insertion
X *	Added a couple of include files to get proper int=short compilation
X *
X * Nov 1991 - Piet van Oostrum <piet@cs.ruu.nl>
X *	mf_w_tempo needs a delta time parameter otherwise the tempo cannot
X *      be changed during the piece.
X *
X *          The file format implemented here is called
X *          Standard MIDI Files, and is part of the Musical
X *          instrument Digital Interface specification.
X *          The spec is avaiable from:
X *
X *               International MIDI Association
X *               5316 West 57th Street
X *               Los Angeles, CA 90056
X *
X *          An in-depth description of the spec can also be found
X *          in the article "Introducing Standard MIDI Files", published
X *          in Electronic Musician magazine, April, 1989.
X * 
X */
#include "midifile.h"
#define NULLFUNC 0
#define NULL 0
X
/*#define THINK*/
X
#ifdef THINK
#include <stdlib.h>
#endif
X
#include <stdio.h>
X
char *strcpy(), *strcat();
char *malloc();
void exit(), free();
X
/* public stuff */
X
/* Functions to be called while processing the MIDI file. */
int (*Mf_getc)() = NULLFUNC;
int (*Mf_error)() = NULLFUNC;
int (*Mf_header)() = NULLFUNC;
int (*Mf_starttrack)() = NULLFUNC;
int (*Mf_endtrack)() = NULLFUNC;
int (*Mf_on)() = NULLFUNC;
int (*Mf_off)() = NULLFUNC;
int (*Mf_pressure)() = NULLFUNC;
int (*Mf_parameter)() = NULLFUNC;
int (*Mf_pitchbend)() = NULLFUNC;
int (*Mf_program)() = NULLFUNC;
int (*Mf_chanpressure)() = NULLFUNC;
int (*Mf_sysex)() = NULLFUNC;
int (*Mf_arbitrary)() = NULLFUNC;
int (*Mf_metamisc)() = NULLFUNC;
int (*Mf_seqnum)() = NULLFUNC;
int (*Mf_eot)() = NULLFUNC;
int (*Mf_smpte)() = NULLFUNC;
int (*Mf_tempo)() = NULLFUNC;
int (*Mf_timesig)() = NULLFUNC;
int (*Mf_keysig)() = NULLFUNC;
int (*Mf_sqspecific)() = NULLFUNC;
int (*Mf_text)() = NULLFUNC;
X
/* Functions to implement in order to write a MIDI file */
int (*Mf_putc)() = NULLFUNC;
int (*Mf_wtrack)() = NULLFUNC;
int (*Mf_wtempotrack)() = NULLFUNC;
X
int Mf_nomerge = 0;		/* 1 => continue'ed system exclusives are */
X				            /* not collapsed. */
long Mf_currtime = 0L;		/* current time in delta-time units */
X
/* private stuff */
static long Mf_toberead = 0L;
static long Mf_numbyteswritten = 0L;
X
static long readvarinum();
static long read32bit();
static long to32bit();
static int read16bit();
static int to16bit();
static char *msg();
X
mfread()	 	/* The only non-static function in this file. */
{
X	if ( Mf_getc == NULLFUNC )
X		mferror("mfread() called without setting Mf_getc"); 
X
X	readheader();
X	while ( readtrack() )
X		;
}
X
/* for backward compatibility with the original lib */
midifile()
{
X    mfread();
}
X
static
readmt(s)		/* read through the "MThd" or "MTrk" header string */
char *s;
{
X	int n = 0;
X	char *p = s;
X	int c;
X
X	while ( n++<4 && (c=(*Mf_getc)()) != EOF ) {
X		if ( c != *p++ ) {
X			char buff[32];
X			(void) strcpy(buff,"expecting ");
X			(void) strcat(buff,s);
X			mferror(buff);
X		}
X	}
X	return(c);
}
X
static
egetc()			/* read a single character and abort on EOF */
{
X	int c = (*Mf_getc)();
X
X	if ( c == EOF )
X		mferror("premature EOF");
X	Mf_toberead--;
X	return(c);
}
X
static
readheader()		/* read a header chunk */
{
X	int format, ntrks, division;
X
X	if ( readmt("MThd") == EOF )
X		return;
X
X	Mf_toberead = read32bit();
X	format = read16bit();
X	ntrks = read16bit();
X	division = read16bit();
X
X	if ( Mf_header )
X		(*Mf_header)(format,ntrks,division);
X
X	/* flush any extra stuff, in case the length of header is not 6 */
X	while ( Mf_toberead > 0 )
X		(void) egetc();
}
X
static
readtrack()		 /* read a track chunk */
{
X	/* This array is indexed by the high half of a status byte.  It's */
X	/* value is either the number of bytes needed (1 or 2) for a channel */
X	/* message, or 0 (meaning it's not  a channel message). */
X	static int chantype[] = {
X		0, 0, 0, 0, 0, 0, 0, 0,		/* 0x00 through 0x70 */
X		2, 2, 2, 2, 1, 1, 2, 0		/* 0x80 through 0xf0 */
X	};
X	long lookfor;
X	int c, c1, type;
X	int sysexcontinue = 0;	/* 1 if last message was an unfinished sysex */
X	int running = 0;	/* 1 when running status used */
X	int status = 0;		/* status value (e.g. 0x90==note-on) */
X	int needed;
X
X	if ( readmt("MTrk") == EOF )
X		return(0);
X
X	Mf_toberead = read32bit();
X	Mf_currtime = 0;
X
X	if ( Mf_starttrack )
X		(*Mf_starttrack)();
X
X	while ( Mf_toberead > 0 ) {
X
X		Mf_currtime += readvarinum();	/* delta time */
X
X		c = egetc();
X
X		if ( sysexcontinue && c != 0xf7 )
X			mferror("didn't find expected continuation of a sysex");
X
X		if ( (c & 0x80) == 0 ) {	 /* running status? */
X			if ( status == 0 )
X				mferror("unexpected running status");
X			running = 1;
X		}
X		else {
X			status = c;
X			running = 0;
X		}
X
X		needed = chantype[ (status>>4) & 0xf ];
X
X		if ( needed ) {		/* ie. is it a channel message? */
X
X			if ( running )
X				c1 = c;
X			else
X				c1 = egetc();
X			chanmessage( status, c1, (needed>1) ? egetc() : 0 );
X			continue;;
X		}
X
X		switch ( c ) {
X
X		case 0xff:			/* meta event */
X
X			type = egetc();
X			lookfor = Mf_toberead - readvarinum();
X			msginit();
X
X			while ( Mf_toberead > lookfor )
X				msgadd(egetc());
X
X			metaevent(type);
X			break;
X
X		case 0xf0:		/* start of system exclusive */
X
X			lookfor = Mf_toberead - readvarinum();
X			msginit();
X			msgadd(0xf0);
X
X			while ( Mf_toberead > lookfor )
X				msgadd(c=egetc());
X
X			if ( c==0xf7 || Mf_nomerge==0 )
X				sysex();
X			else
X				sysexcontinue = 1;  /* merge into next msg */
X			break;
X
X		case 0xf7:	/* sysex continuation or arbitrary stuff */
X
X			lookfor = Mf_toberead - readvarinum();
X
X			if ( ! sysexcontinue )
X				msginit();
X
X			while ( Mf_toberead > lookfor )
X				msgadd(c=egetc());
X
X			if ( ! sysexcontinue ) {
X				if ( Mf_arbitrary )
X					(*Mf_arbitrary)(msgleng(),msg());
X			}
X			else if ( c == 0xf7 ) {
X				sysex();
X				sysexcontinue = 0;
X			}
X			break;
X		default:
X			badbyte(c);
X			break;
X		}
X	}
X	if ( Mf_endtrack )
X		(*Mf_endtrack)();
X	return(1);
}
X
static
badbyte(c)
int c;
{
X	char buff[32];
X
X	(void) sprintf(buff,"unexpected byte: 0x%02x",c);
X	mferror(buff);
}
X
static
metaevent(type)
{
X	int leng = msgleng();
X	char *m = msg();
X
X	switch  ( type ) {
X	case 0x00:
X		if ( Mf_seqnum )
X			(*Mf_seqnum)(to16bit(m[0],m[1]));
X		break;
X	case 0x01:	/* Text event */
X	case 0x02:	/* Copyright notice */
X	case 0x03:	/* Sequence/Track name */
X	case 0x04:	/* Instrument name */
X	case 0x05:	/* Lyric */
X	case 0x06:	/* Marker */
X	case 0x07:	/* Cue point */
X	case 0x08:
X	case 0x09:
X	case 0x0a:
X	case 0x0b:
X	case 0x0c:
X	case 0x0d:
X	case 0x0e:
X	case 0x0f:
X		/* These are all text events */
X		if ( Mf_text )
X			(*Mf_text)(type,leng,m);
X		break;
X	case 0x2f:	/* End of Track */
X		if ( Mf_eot )
X			(*Mf_eot)();
X		break;
X	case 0x51:	/* Set tempo */
X		if ( Mf_tempo )
X			(*Mf_tempo)(to32bit(0,m[0],m[1],m[2]));
X		break;
X	case 0x54:
X		if ( Mf_smpte )
X			(*Mf_smpte)(m[0],m[1],m[2],m[3],m[4]);
X		break;
X	case 0x58:
X		if ( Mf_timesig )
X			(*Mf_timesig)(m[0],m[1],m[2],m[3]);
X		break;
X	case 0x59:
X		if ( Mf_keysig )
X			(*Mf_keysig)(m[0],m[1]);
X		break;
X	case 0x7f:
X		if ( Mf_sqspecific )
X			(*Mf_sqspecific)(leng,m);
X		break;
X	default:
X		if ( Mf_metamisc )
X			(*Mf_metamisc)(type,leng,m);
X	}
}
X
static
sysex()
{
X	if ( Mf_sysex )
X		(*Mf_sysex)(msgleng(),msg());
}
X
static
chanmessage(status,c1,c2)
int status;
int c1, c2;
{
X	int chan = status & 0xf;
X
X	switch ( status & 0xf0 ) {
X	case 0x80:
X		if ( Mf_off )
X			(*Mf_off)(chan,c1,c2);
X		break;
X	case 0x90:
X		if ( Mf_on )
X			(*Mf_on)(chan,c1,c2);
X		break;
X	case 0xa0:
X		if ( Mf_pressure )
X			(*Mf_pressure)(chan,c1,c2);
X		break;
X	case 0xb0:
X		if ( Mf_parameter )
X			(*Mf_parameter)(chan,c1,c2);
X		break;
X	case 0xe0:
X		if ( Mf_pitchbend )
X			(*Mf_pitchbend)(chan,c1,c2);
X		break;
X	case 0xc0:
X		if ( Mf_program )
X			(*Mf_program)(chan,c1);
X		break;
X	case 0xd0:
X		if ( Mf_chanpressure )
X			(*Mf_chanpressure)(chan,c1);
X		break;
X	}
}
X
/* readvarinum - read a varying-length number, and return the */
/* number of characters it took. */
X
static long
readvarinum()
{
X	long value;
X	int c;
X
X	c = egetc();
X	value = c;
X	if ( c & 0x80 ) {
X		value &= 0x7f;
X		do {
X			c = egetc();
X			value = (value << 7) + (c & 0x7f);
X		} while (c & 0x80);
X	}
X	return (value);
}
X
static long
to32bit(c1,c2,c3,c4)
{
X	long value = 0L;
X
X	value = (c1 & 0xff);
X	value = (value<<8) + (c2 & 0xff);
X	value = (value<<8) + (c3 & 0xff);
X	value = (value<<8) + (c4 & 0xff);
X	return (value);
}
X
static
to16bit(c1,c2)
int c1, c2;
{
X	return ((c1 & 0xff ) << 8) + (c2 & 0xff);
}
X
static long
read32bit()
{
X	int c1, c2, c3, c4;
X
X	c1 = egetc();
X	c2 = egetc();
X	c3 = egetc();
X	c4 = egetc();
X	return to32bit(c1,c2,c3,c4);
}
X
static
read16bit()
{
X	int c1, c2;
X	c1 = egetc();
X	c2 = egetc();
X	return to16bit(c1,c2);
}
X
/* static */
mferror(s)
char *s;
{
X	if ( Mf_error )
X		(*Mf_error)(s);
X	exit(1);
}
X
/* The code below allows collection of a system exclusive message of */
/* arbitrary length.  The Msgbuff is expanded as necessary.  The only */
/* visible data/routines are msginit(), msgadd(), msg(), msgleng(). */
X
#define MSGINCREMENT 128
static char *Msgbuff = NULL;	/* message buffer */
static int Msgsize = 0;		/* Size of currently allocated Msg */
static int Msgindex = 0;	/* index of next available location in Msg */
X
static
msginit()
{
X	Msgindex = 0;
}
X
static char *
msg()
{
X	return(Msgbuff);
}
X
static
msgleng()
{
X	return(Msgindex);
}
X
static
msgadd(c)
int c;
{
X	/* If necessary, allocate larger message buffer. */
X	if ( Msgindex >= Msgsize )
X		biggermsg();
X	Msgbuff[Msgindex++] = c;
}
X
static
biggermsg()
{
X	char *newmess;
X	char *oldmess = Msgbuff;
X	int oldleng = Msgsize;
X
X	Msgsize += MSGINCREMENT;
X	newmess = (char *) malloc( (unsigned)(sizeof(char)*Msgsize) );
X
X	if(newmess == NULL)
X		mferror("malloc error!");
X		
X	/* copy old message into larger new one */
X	if ( oldmess != NULL ) {
X		register char *p = newmess;
X		register char *q = oldmess;
X		register char *endq = &oldmess[oldleng];
X
X		for ( ; q!=endq ; p++,q++ )
X			*p = *q;
X		free(oldmess);
X	}
X	Msgbuff = newmess;
}
X
long ftell();
long fseek();
X
/*
X * mfwrite() - The only fuction you'll need to call to write out
X *             a midi file.
X *
X * format      0 - Single multi-channel track
X *             1 - Multiple simultaneous tracks
X *             2 - One or more sequentially independent
X *                 single track patterns                
X * ntracks     The number of tracks in the file.
X * division    This is kind of tricky, it can represent two
X *             things, depending on whether it is positive or negative
X *             (bit 15 set or not).  If  bit  15  of division  is zero,
X *             bits 14 through 0 represent the number of delta-time
X *             "ticks" which make up a quarter note.  If bit  15 of
X *             division  is  a one, delta-times in a file correspond to
X *             subdivisions of a second similiar to  SMPTE  and  MIDI
X *             time code.  In  this format bits 14 through 8 contain
X *             one of four values - 24, -25, -29, or -30,
X *             corresponding  to  the  four standard  SMPTE and MIDI
X *             time code frame per second formats, where  -29
X *             represents  30  drop  frame.   The  second  byte
X *             consisting  of  bits 7 through 0 corresponds the the
X *             resolution within a frame.  Refer the Standard MIDI
X *             Files 1.0 spec for more details.
X * fp          This should be the open file pointer to the file you
X *             want to write.  It will have be a global in order
X *             to work with Mf_putc.  
X * Global variables:
X * Mf_RunStat  if nonzero use running status.
X */ 
X 
int Mf_RunStat = 0;
static int laststat;		/* last status code */
static int lastmeta;		/* last meta event type */
X
void 
mfwrite(format,ntracks,division,fp) 
int format,ntracks,division; 
FILE *fp; 
{
X    int i; void mf_w_track_chunk(), mf_w_header_chunk();
X
X    if ( Mf_putc == NULLFUNC )
X	    mferror("mfmf_write() called without setting Mf_putc");
X
X    if ( Mf_wtrack == NULLFUNC )
X	    mferror("mfmf_write() called without setting Mf_mf_writetrack"); 
X
X    /* every MIDI file starts with a header */
X    mf_w_header_chunk(format,ntracks,division);
X
X    /* In format 1 files, the first track is a tempo map */
X    if(format == 1 && ( Mf_wtempotrack ))
X    {
X        mf_w_track_chunk(-1,fp,Mf_wtempotrack);
X	ntracks--;
X    }
X
X    /* The rest of the file is a series of tracks */
X    for(i = 0; i < ntracks; i++)
X        mf_w_track_chunk(i,fp,Mf_wtrack);
}
X
void 
mf_w_track_chunk(which_track,fp,wtrack)
int which_track;
FILE *fp;
int (*wtrack)();
{
X	unsigned long trkhdr,trklength;
X	long offset, place_marker;
X	void write16bit(),write32bit();
X	
X	trkhdr = MTrk;
X	trklength = 0;
X
X	/* Remember where the length was written, because we don't
X	   know how long it will be until we've finished writing */
X	offset = ftell(fp); 
X
#ifdef DEBUG
X        printf("offset = %d\n",(int) offset);
#endif
X
X	/* Write the track chunk header */
X	write32bit(trkhdr);
X	write32bit(trklength);
X
X	Mf_numbyteswritten = 0L; /* the header's length doesn't count */
X	laststat = 0;
X	
X	/* Note: this calls Mf_writetempotrack with an unused parameter (-1)
X	   But this is innocent */
X
X	(*wtrack)(which_track);
X
X	if (laststat != meta_event || lastmeta != end_of_track) {
X	    /* mf_write End of track meta event */
X	    eputc(0);
X	    eputc(meta_event);
X	    eputc(end_of_track);
X	    eputc(0);
X	}
X
X	laststat = 0;
X	 
X	/* It's impossible to know how long the track chunk will be beforehand,
X           so the position of the track length data is kept so that it can
X           be written after the chunk has been generated */
X	place_marker = ftell(fp);
X	
X	/* This method turned out not to be portable because the
X           parameter returned from ftell is not guaranteed to be
X           in bytes on every machine */
X 	/* track.length = place_marker - offset - (long) sizeof(track); */
X
#ifdef DEBUG
printf("length = %d\n",(int) trklength);
#endif
X
X 	if(fseek(fp,offset,0) < 0)
X	    mferror("error seeking during final stage of write");
X
X	trklength = Mf_numbyteswritten;
X
X	/* Re-mf_write the track chunk header with right length */
X	write32bit(trkhdr);
X	write32bit(trklength);
X
X	fseek(fp,place_marker,0);
} /* End gen_track_chunk() */
X
X
void 
mf_w_header_chunk(format,ntracks,division)
int format,ntracks,division;
{
X    unsigned long ident,length;
X    void write16bit(),write32bit();
X    
X    ident = MThd;           /* Head chunk identifier                    */
X    length = 6;             /* Chunk length                             */
X
X    /* individual bytes of the header must be written separately
X       to preserve byte order across cpu types :-( */
X    write32bit(ident);
X    write32bit(length);
X    write16bit(format);
X    write16bit(ntracks);
X    write16bit(division);
} /* end gen_header_chunk() */
X
void WriteVarLen();
X
/*
X * mf_w_midi_event()
X * 
X * Library routine to mf_write a single MIDI track event in the standard MIDI
X * file format. The format is:
X *
X *                    <delta-time><event>
X *
X * In this case, event can be any multi-byte midi message, such as
X * "note on", "note off", etc.      
X *
X * delta_time - the time in ticks since the last event.
X * type - the type of event.
X * chan - The midi channel.
X * data - A pointer to a block of chars containing the META EVENT,
X *        data.
X * size - The length of the midi-event data.
X */
int 
mf_w_midi_event(delta_time, type, chan, data, size)
unsigned long delta_time;
unsigned int chan,type;
unsigned long size;
unsigned char *data;
{
X    int i;
X    unsigned char c;
X
X    WriteVarLen(delta_time);
X
X    /* all MIDI events start with the type in the first four bits,
X       and the channel in the lower four bits */
X    c = type | chan;
X
X    if(chan > 15)
X        perror("error: MIDI channel greater than 16\n");
X
X    if (!Mf_RunStat || laststat != c)
X    	eputc(c);
X	
X    laststat = c;
X
X    /* write out the data bytes */
X    for(i = 0; i < size; i++)
X	eputc(data[i]);
X
X    return(size);
} /* end mf_write MIDI event */
X
/*
X * mf_w_meta_event()
X *
X * Library routine to mf_write a single meta event in the standard MIDI
X * file format. The format of a meta event is:
X *
X *          <delta-time><FF><type><length><bytes>
X *
X * delta_time - the time in ticks since the last event.
X * type - the type of meta event.
X * data - A pointer to a block of chars containing the META EVENT,
X *        data.
X * size - The length of the meta-event data.
X */
int
mf_w_meta_event(delta_time, type, data, size)
unsigned long delta_time;
unsigned char *data,type;
unsigned long size;
{
X    int i;
X
X    WriteVarLen(delta_time);
X    
X    /* This marks the fact we're writing a meta-event */
X    eputc(meta_event);
X    laststat = meta_event;
X
X    /* The type of meta event */
X    eputc(type);
X    lastmeta = type;
X
X    /* The length of the data bytes to follow */
X    WriteVarLen(size); 
X
X    for(i = 0; i < size; i++)
X    {
X	if(eputc(data[i]) != data[i])
X	    return(-1); 
X    }
X    return(size);
} /* end mf_w_meta_event */
X
/*
X * mf_w_sysex_event()
X *
X * Library routine to mf_write a single sysex (or arbitrary)
X * event in the standard MIDI file format. The format of the event is:
X *
X *          <delta-time><type><length><bytes>
X *
X * delta_time - the time in ticks since the last event.
X * data - A pointer to a block of chars containing the EVENT data.
X *        The first byte is the type (0xf0 for sysex, 0xf7 otherwise)
X * size - The length of the sysex-event data.
X */
int
mf_w_sysex_event(delta_time, data, size)
unsigned long delta_time;
unsigned char *data;
unsigned long size;
{
X    int i;
X
X    WriteVarLen(delta_time);
X    
X    /* The type of sysex event */
X    eputc(*data);
X    laststat = 0;
X
X    /* The length of the data bytes to follow */
X    WriteVarLen(size-1); 
X
X    for(i = 1; i < size; i++)
X    {
X	if(eputc(data[i]) != data[i])
X	    return(-1); 
X    }
X    return(size);
} /* end mf_w_sysex_event */
X
void 
mf_w_tempo(delta_time, tempo)
unsigned long delta_time;
unsigned long tempo;
{
X    /* Write tempo */
X    /* all tempos are written as 120 beats/minute, */
X    /* expressed in microseconds/quarter note     */
X
X    WriteVarLen(delta_time);
X
X    eputc(meta_event);
X    laststat = meta_event;
X    eputc(set_tempo);
X
X    eputc(3);
X    eputc((unsigned)(0xff & (tempo >> 16)));
X    eputc((unsigned)(0xff & (tempo >> 8)));
X    eputc((unsigned)(0xff & tempo));
}
X
unsigned long 
mf_sec2ticks(secs,division,tempo)
int division;
unsigned int tempo;
float secs;
{    
X     return (long)(((secs * 1000.0) / 4.0 * division) / tempo);
}
X
/*
X * Write multi-length bytes to MIDI format files
X */
void 
WriteVarLen(value)
unsigned long value;
{
X  unsigned long buffer;
X
X  buffer = value & 0x7f;
X  while((value >>= 7) > 0)
X  {
X	buffer <<= 8;
X	buffer |= 0x80;
X	buffer += (value & 0x7f);
X  }
X  while(1){
X       eputc((unsigned)(buffer & 0xff));
X       
X	if(buffer & 0x80)
X		buffer >>= 8;
X	else
X		return;
X	}
}/* end of WriteVarLen */
X
/* 
X * This routine converts delta times in ticks into seconds. The
X * else statement is needed because the formula is different for tracks
X * based on notes and tracks based on SMPTE times.
X *
X */
float 
mf_ticks2sec(ticks,division,tempo)
int division;
unsigned int tempo;
unsigned long ticks;
{
X    float smpte_format, smpte_resolution;
X
X    if(division > 0)
X        return ((float) (((float)(ticks) * (float)(tempo)) / ((float)(division) * 1000000.0)));
X    else
X    {
X       smpte_format = upperbyte(division);
X       smpte_resolution = lowerbyte(division);
X       return (float) ((float) ticks / (smpte_format * smpte_resolution * 1000000.0));
X    }
} /* end of ticks2sec() */
X
X
/*
X * write32bit()
X * write16bit()
X *
X * These routines are used to make sure that the byte order of
X * the various data types remains constant between machines. This
X * helps make sure that the code will be portable from one system
X * to the next.  It is slightly dangerous that it assumes that longs
X * have at least 32 bits and ints have at least 16 bits, but this
X * has been true at least on PCs, UNIX machines, and Macintosh's.
X *
X */
void 
write32bit(data)
unsigned long data;
{
X    eputc((unsigned)((data >> 24) & 0xff));
X    eputc((unsigned)((data >> 16) & 0xff));
X    eputc((unsigned)((data >> 8 ) & 0xff));
X    eputc((unsigned)(data & 0xff));
}
X
void 
write16bit(data)
int data;
{
X    eputc((unsigned)((data & 0xff00) >> 8));
X    eputc((unsigned)(data & 0xff));
}
X
/* write a single character and abort on error */
eputc(c)			
unsigned char c;
{
X	int return_val;
X	
X	if((Mf_putc) == NULLFUNC)
X	{
X		mferror("Mf_putc undefined");
X		return(-1);
X	}
X	
X	return_val = (*Mf_putc)(c);
X
X	if ( return_val == EOF )
X		mferror("error writing");
X		
X	Mf_numbyteswritten++;
X	return(return_val);
}
SHAR_EOF
chmod 0644 midifile.c ||
echo 'restore of midifile.c failed'
Wc_c="`wc -c < 'midifile.c'`"
test 21131 -eq "$Wc_c" ||
	echo 'midifile.c: original size 21131, current size' "$Wc_c"
fi
# ============= midifile.h ==============
if test -f 'midifile.h' -a X"$1" != X"-c"; then
	echo 'x - skipping midifile.h (File already exists)'
else
echo 'x - extracting midifile.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'midifile.h' &&
/* $Id: midifile.h,v 1.3 1991/11/03 21:50:50 piet Rel $ */
/* definitions for MIDI file parsing code */
extern int (*Mf_getc)();
extern int (*Mf_header)();
extern int (*Mf_starttrack)();
extern int (*Mf_endtrack)();
extern int (*Mf_on)();
extern int (*Mf_off)();
extern int (*Mf_pressure)();
extern int (*Mf_parameter)();
extern int (*Mf_pitchbend)();
extern int (*Mf_program)();
extern int (*Mf_chanpressure)();
extern int (*Mf_sysex)();
extern int (*Mf_metamisc)();
extern int (*Mf_sqspecific)();
extern int (*Mf_seqnum)();
extern int (*Mf_text)();
extern int (*Mf_eot)();
extern int (*Mf_timesig)();
extern int (*Mf_smpte)();
extern int (*Mf_tempo)();
extern int (*Mf_keysig)();
extern int (*Mf_arbitrary)();
extern int (*Mf_error)();
extern long Mf_currtime;
extern int Mf_nomerge;
X
/* definitions for MIDI file writing code */
extern int (*Mf_putc)();
extern int (*Mf_wtrack)();
extern int (*Mf_wtempotrack)();
float mf_ticks2sec();
unsigned long mf_sec2ticks();
void mfwrite();
X
/* MIDI status commands most significant bit is 1 */
#define note_off         	0x80
#define note_on          	0x90
#define poly_aftertouch  	0xa0
#define control_change    	0xb0
#define program_chng     	0xc0
#define channel_aftertouch      0xd0
#define pitch_wheel      	0xe0
#define system_exclusive      	0xf0
#define delay_packet	 	(1111)
X
/* 7 bit controllers */
#define damper_pedal            0x40
#define portamento	        0x41 	
#define sostenuto	        0x42
#define soft_pedal	        0x43
#define general_4               0x44
#define	hold_2		        0x45
#define	general_5	        0x50
#define	general_6	        0x51
#define general_7	        0x52
#define general_8	        0x53
#define tremolo_depth	        0x5c
#define chorus_depth	        0x5d
#define	detune		        0x5e
#define phaser_depth	        0x5f
X
/* parameter values */
#define data_inc	        0x60
#define data_dec	        0x61
X
/* parameter selection */
#define non_reg_lsb	        0x62
#define non_reg_msb	        0x63
#define reg_lsb		        0x64
#define reg_msb		        0x65
X
/* Standard MIDI Files meta event definitions */
#define	meta_event		0xFF
#define	sequence_number 	0x00
#define	text_event		0x01
#define copyright_notice 	0x02
#define sequence_name    	0x03
#define instrument_name 	0x04
#define lyric	        	0x05
#define marker			0x06
#define	cue_point		0x07
#define channel_prefix		0x20
#define	end_of_track		0x2f
#define	set_tempo		0x51
#define	smpte_offset		0x54
#define	time_signature		0x58
#define	key_signature		0x59
#define	sequencer_specific	0x74
X
/* Manufacturer's ID number */
#define Seq_Circuits (0x01) /* Sequential Circuits Inc. */
#define Big_Briar    (0x02) /* Big Briar Inc.           */
#define Octave       (0x03) /* Octave/Plateau           */
#define Moog         (0x04) /* Moog Music               */
#define Passport     (0x05) /* Passport Designs         */
#define Lexicon      (0x06) /* Lexicon 			*/
#define Tempi        (0x20) /* Bon Tempi                */
#define Siel         (0x21) /* S.I.E.L.                 */
#define Kawai        (0x41) 
#define Roland       (0x42)
#define Korg         (0x42)
#define Yamaha       (0x43)
X
/* miscellaneous definitions */
#define MThd 0x4d546864L
#define MTrk 0x4d54726bL
#define lowerbyte(x) ((unsigned char)(x & 0xff))
#define upperbyte(x) ((unsigned char)((x & 0xff00)>>8))
SHAR_EOF
chmod 0644 midifile.h ||
echo 'restore of midifile.h failed'
Wc_c="`wc -c < 'midifile.h'`"
test 3329 -eq "$Wc_c" ||
	echo 'midifile.h: original size 3329, current size' "$Wc_c"
fi
# ============= t2mf.c ==============
if test -f 't2mf.c' -a X"$1" != X"-c"; then
	echo 'x - skipping t2mf.c (File already exists)'
else
echo 'x - extracting t2mf.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 't2mf.c' &&
/* $Id: t2mf.c,v 1.4 1991/11/17 21:58:36 piet Rel piet $ */
/*
X * t2mf
X * 
X * Convert text file to a MIDI file.
X */
X
#include <stdio.h>
#include <ctype.h>
#include <setjmp.h>
#include <memory.h>
#include <malloc.h>
#include "t2mf.h"
X
#ifdef NO_YYLENG_VAR
#define	yyleng yylength
#endif
X
static jmp_buf erjump;
static int err_cont = 0;
X
static int TrkNr;
static int Format, Ntrks;
static int Measure, Beat, Clicks;
static char* buffer = 0;
static int bufsiz = 0, buflen;
X
extern int arg_index;
extern char *arg_option;
extern long yyval;
extern int yyleng;
extern int lineno;
extern char *yytext;
extern int do_hex;
extern int eol_seen;
extern FILE  *yyin;
X
extern int arg_index;
extern char *arg_option;
extern int Mf_RunStat;
X
static FILE *F;
X
fileputc(c)
int c;
{
X    return putc(c, F);
}
X
int mywritetrack();
X
main(argc,argv)
int argc;
char **argv;
{
X    	FILE *efopen();
X	int flg;
X
X	while (flg = crack (argc, argv, "Rr", 0)) {
X		switch (flg) {
X		case 'r':
X		case 'R':
X			Mf_RunStat = 1;
X			break;
X		}
X	}
X
X    if ( arg_index < argc )
X        yyin = efopen (argv[arg_index++], "r");
X    else
X        yyin = stdin;
X    if (arg_index < argc )
X        F = efopen(argv[arg_index],"wb");
X    else
X        F = fdopen (fileno(stdout), "wb");
X
X    Mf_putc = fileputc;
X    Mf_wtrack = mywritetrack;
X    TrkNr = 0;
X    Measure = 4;
X    Beat = 96;
X    Clicks = 96;
X    translate();
X    fclose(F);
X    fclose(yyin);
X    exit(0);
}
X
FILE *
efopen(name,mode)
char *name;
char *mode;
{
X    FILE *f;
X    extern int errno;
X    extern char *sys_errlist[];
X    extern int sys_nerr;
X    char *errmess;
X
X    if ( (f=fopen(name,mode)) == NULL ) {
X        (void) fprintf(stderr,"*** ERROR *** Cannot open '%s'!\n",name);
X        if ( errno <= sys_nerr )
X            errmess = sys_errlist[errno];
X        else
X            errmess = "Unknown error!";
X        (void) fprintf(stderr,"************* Reason: %s\n",errmess);
X        exit(1);
X    }
X    return(f);
}
X
error(s)
char *s;
{
X    fprintf(stderr,"Error: %s\n",s);
}
X
prs_error(s)
char *s;
{
X    int c;
X    int ln = (eol_seen? lineno-1 : lineno);
X    fprintf (stderr, "%d: %s\n", ln, s);
X    if (yyleng > 0 && *yytext != '\n')
X        fprintf (stderr, "*** %*s ***\n", yyleng, yytext);
X    while ((c=yylex()) != EOL && c != EOF) /* skip rest of line */;
X    if (c == EOF) exit(1);
X    if (err_cont)
X        longjmp (erjump,1);
}
X
syntax()
{
X    prs_error ("Syntax error");
}
X
translate()
{
X    if (yylex()==MTHD) {
X        Format = getint("MFile format");
X        Ntrks = getint("MFile #tracks");
X        Clicks = getint("MFile Clicks");
X	if (Clicks < 0)
X		Clicks = (Clicks&0xff)<<8|getint("MFile SMPTE division");
X	checkeol();
X        mfwrite(Format, Ntrks, Clicks, F);
X    } else {
X        prs_error ("Missing MFile - can't continue");
X	exit(1);
X    }
}
X
char data[4];
int chan;
X
mywritetrack()
{
X    int opcode, c;
X    long currtime = 0;
X    long newtime, delta;
X    int i, k;
X    
X    while ((opcode = yylex()) == EOL) ;
X    if (opcode != MTRK)
X        prs_error("Missing MTrk");
X    checkeol();
X    while (1) {
X	err_cont = 1;
X	setjmp (erjump);
X        switch (yylex()) {
X        case MTRK:
X            prs_error("Unexpected MTrk");
X	case EOF:
X	    err_cont = 0;
X	    error ("Unexpected EOF");
X	    return;
X        case TRKEND:
X	    err_cont = 0;
X	    checkeol();
X            return;
X        case INT:
X            newtime = yyval;
X            if ((opcode=yylex())=='/') {
X                if (yylex()!=INT) prs_error("Illegal time value");
X                newtime = newtime*Measure+yyval;
X                if (yylex()!='/'||yylex()!=INT) prs_error("Illegal time value");
X                newtime = newtime*Beat+yyval;
X		opcode = yylex();
X            }
X            delta = newtime - currtime;
X            switch (opcode) {
X            case ON:
X            case OFF:
X            case POPR:
X		checkchan();
X		checknote();
X		checkval();
X		mf_w_midi_event (delta, opcode, chan, data, 2L);
X		break;
X
X            case PAR:
X		checkchan();
X		checkcon();
X		checkval();
X		mf_w_midi_event (delta, opcode, chan, data, 2L);
X		break;
X		
X            case PB:
X		checkchan();
X		splitval();
X		mf_w_midi_event (delta, opcode, chan, data, 2L);
X		break;
X
X            case PRCH:
X		checkchan();
X		checkprog();
X		mf_w_midi_event (delta, opcode, chan, data, 1L);
X		break;
X                
X	    case CHPR:
X		checkchan();
X		checkval();
X		data[0] = data[1];
X		mf_w_midi_event (delta, opcode, chan, data, 1L);
X		break;
X	    	
X            case SYSEX:
X            case ARB:
X	    	gethex();
X		mf_w_sysex_event (delta, buffer, (long)buflen);
X		break;
X		
X            case TEMPO:
X	    	if (yylex() != INT) syntax();
X		mf_w_tempo (delta, yyval);
X		break;
X		
X            case TIMESIG: {
X	        int nn, denom, cc, bb;
X	        if (yylex() != INT || yylex() != '/') syntax();
X		nn = yyval;
X		denom = getbyte("Denom");
X		cc = getbyte("clocks per click");
X		bb = getbyte("32nd notes per 24 clocks");
X		for (i=0, k=1 ; k<denom; i++, k<<=1);
X		if (k!=denom) error ("Illegal TimeSig");
X		data[0] = nn;
X		data[1] = i;
X		data[2] = cc;
X		data[3] = bb;
X		Measure = nn;
X		Beat = 4 * Clicks / denom;
X		mf_w_meta_event (delta, time_signature, data, 4L);
X		}
X		break;
X		
X            case SMPTE:
X		for (i=0; i<4; i++) {
X		    data[i] = getbyte("SMPTE");
X		}
X		mf_w_meta_event (delta, smpte_offset, data, 4L);
X		break;
X		
X            case KEYSIG:
X		data[0] = getbyte ("Keysig");
X		if ((c=yylex()) != MINOR && c != MAJOR)
X			syntax();
X		data[1] = (c == MINOR);
X		mf_w_meta_event (delta, key_signature, data, 2L);
X		break;
X		
X            case SEQNR:
X		get16val ("SeqNr");
X		mf_w_meta_event (delta, sequence_number, data, 2L);
X		break;
X
X	    case META:
X            case SEQSPEC: {
X	        int type = yylex();
X		switch (type) {
X		case TRKEND:
X		    type = end_of_track;
X		    break;
X		case TEXT:
X		case COPYRIGHT:
X		case SEQNAME:
X		case INSTRNAME:
X		case LYRIC:
X		case MARKER:
X		case CUE:
X		    type -= (META+1);
X		    break;
X		case INT:
X		    type = yyval;
X		    break;
X		default:
X		    prs_error ("Illegal Meta type");
X		}
X		if (type == end_of_track)
X		    buflen = 0;
X		else
X		    gethex();
X		mf_w_meta_event (delta, type, buffer, (long)buflen);
X		break;
X	    }
X	    default:
X	        prs_error ("Unknown input");
X		break;
X	    }
X            currtime = newtime;
X        case EOL:
X	    break;
X	default:
X	    prs_error ("Unknown input");
X	    break;
X	}
X	checkeol();
X    }
}
X
getbyte(mess)
char *mess;
{
X    char ermesg[100];
X    getint (mess);
X    if (yyval < 0 || yyval > 127) {
X	sprintf (ermesg, "Wrong value (%ld) for %s", yyval, mess);
X        error (ermesg);
X	yyval = 0;
X    }
X    return yyval;
}
X
getint(mess)
char *mess;
{
X    char ermesg[100];
X    if (yylex() != INT) {
X	sprintf (ermesg, "Integer expected for %s", mess);
X        error (ermesg);
X	yyval = 0;
X    }
X    return yyval;
}
X
checkchan()
{
X    if (yylex() != CH || yylex() != INT) syntax();
X    if (yyval < 1 || yyval > 16)
X	error ("Chan must be between 1 and 16");
X    chan = yyval-1;
}
X
checknote()
{
X    int c;
X    if (yylex() != NOTE || ((c=yylex()) != INT && c != NOTEVAL))
X	syntax();
X    if (c == NOTEVAL) {
X        static int notes[] = {
X	    9,		/* a */
X	    11,		/* b */
X	    0,		/* c */
X	    2,		/* d */
X	    4,		/* e */
X	    5,		/* f */
X	    7		/* g */
X        };
X	char *p = yytext;
X        c = *p++;
X        if (isupper(c)) c = tolower(c);
X        yyval = notes[c-'a'];
X        switch (*p) {
X        case '#':
X        case '+':
X       	    yyval++;
X	    p++;
X	    break;
X	case 'b':
X	case 'B':
X	case '-':
X	    yyval--;
X	    p++;
X	    break;
X	}	
X	yyval += 12 * atoi(p);
X    }
X    if (yyval < 0 || yyval > 127)
X	error ("Note must be between 0 and 127");
X    data[0] = yyval;
}
X
checkval()
{
X    if (yylex() != VAL || yylex() != INT) syntax();
X    if (yyval < 0 || yyval > 127)
X	error ("Value must be between 0 and 127");
X    data[1] = yyval;
}
X
splitval()
{
X    if (yylex() != VAL || yylex() != INT) syntax();
X    if (yyval < 0 || yyval > 16383)
X	error ("Value must be between 0 and 16383");
X    data[0] = yyval/128;
X    data[1] = yyval%128;
}
X
get16val()
{
X    if (yylex() != VAL || yylex() != INT) syntax();
X    if (yyval < 0 || yyval > 65535)
X	error ("Value must be between 0 and 65535");
X    data[0] = (yyval>>8)&0xff;
X    data[1] = yyval&0xff;
}
X
checkcon()
{
X    if (yylex() != CON || yylex() != INT)
X	syntax();
X    if (yyval < 0 || yyval > 127)
X	error ("Controller must be between 0 and 127");
X    data[0] = yyval;
}
X
checkprog()
{
X    if (yylex() != PROG || yylex() != INT) syntax();
X    if (yyval < 0 || yyval > 127)
X	error ("Program number must be between 0 and 127");
X    data[0] = yyval;
}
X
checkeol()
{
X    if (eol_seen) return;
X    if (yylex() != EOL) {
X    	prs_error ("Garbage deleted");
X	while (!eol_seen) yylex();	 /* skip rest of line */
X    }
}
X
gethex()
{
X    int c;
X    buflen = 0;
X    do_hex = 1;
X    c = yylex();
X    if (c==STRING) {
X	/* Note: yytext includes the trailing, but not the starting quote */
X	int i = 0;
X    	if (yyleng-1 > bufsiz) {
X	    bufsiz = yyleng-1;
X	    if (buffer)
X	    	buffer = realloc (buffer, bufsiz);
X	    else
X	    	buffer = malloc (bufsiz);
X	    if (! buffer) error ("Out of memory");
X	}
X	while (i<yyleng-1) {
X	    c = yytext[i++];
rescan:
X	    if (c == '\\') {
X	    	switch (c = yytext[i++]) {
X		case '0':
X		    c = '\0';
X		    break;
X		case 'n':
X		    c = '\n';
X		    break;
X		case 'r':
X		    c = '\r';
X		    break;
X		case 't':
X		    c = '\t';
X		    break;
X		case 'x':
X		    if (sscanf (yytext+i, "%2x", &c) != 1)
X		    	prs_error ("Illegal \\x in string");
X		    i += 2;
X		    break;
X		case '\r':
X		case '\n':
X		    while ((c=yytext[i++])==' '||c=='\t'||c=='\r'||c=='\n')
X		    	/* skip whitespace */;
X		    goto rescan; /* sorry EWD :=) */
X		}
X	    }
X	    buffer[buflen++] = c;
X	}	    
X    }
X    else if (c == INT) {
X	do {
X    	    if (buflen >= bufsiz) {
X	        bufsiz += 128;
X	        if (buffer)
X	    	    buffer = realloc (buffer, bufsiz);
X	        else
X	    	    buffer = malloc (bufsiz);
X	        if (! buffer) error ("Out of memory");
X	    }
/* This test not applicable for sysex
X	    if (yyval < 0 || yyval > 127)
X	        error ("Illegal hex value"); */
X	    buffer[buflen++] = yyval;
X	    c = yylex();
X	} while (c == INT);
X	if (c != EOL) prs_error ("Unknown hex input");
X    }
X    else prs_error ("String or hex input expected");
}
X
long bankno (s, n)
char *s; int n;
{
X    long res = 0;
X    int c;
X    while (n-- > 0) {
X        c = (*s++);
X	if (islower(c))
X	    c -= 'a';
X	else if (isupper(c))
X	    c -= 'A';
X	else
X	    c -= '1';
X    	res = res * 8 + c;
X    }
X    return res;
}
SHAR_EOF
chmod 0644 t2mf.c ||
echo 'restore of t2mf.c failed'
Wc_c="`wc -c < 't2mf.c'`"
test 10498 -eq "$Wc_c" ||
	echo 't2mf.c: original size 10498, current size' "$Wc_c"
fi
# ============= t2mf.fl ==============
if test -f 't2mf.fl' -a X"$1" != X"-c"; then
	echo 'x - skipping t2mf.fl (File already exists)'
else
echo 'x - extracting t2mf.fl (Text)'
sed 's/^X//' << 'SHAR_EOF' > 't2mf.fl' &&
/* $Id: t2mf.fl,v 1.3 1991/11/15 19:31:00 piet Rel $ */
X
%{
X
#include "t2mf.h"
X
#ifdef NO_YYLENG_VAR
int yylength;
#define YY_USER_ACTION	yylength = yyleng
#endif
X
int do_hex = 0;
int eol_seen = 0;
int lineno = 1;
long yyval;
long bankno();
X
%}
X
Hex	[0-9a-f]
X
%x	QUOTE
%x	QUOTEA
%x	HEX
%%
X	if (do_hex) {
X		BEGIN(HEX);
X		do_hex = 0;
X	}
X	eol_seen = 0;
X		
<INITIAL,HEX>[ \t\r]		/* skip whitespace */;
<INITIAL,HEX>"#".*\n		/* skip comment */ lineno++;
X
MFile		return MTHD;
MTrk		return MTRK;
TrkEnd		return TRKEND;
X
On		return ON;
Off		return OFF;
Po(ly)?Pr	return POPR;
Par(am)?	return PAR;
Pb		return PB;
Pr(og)?Ch	return PRCH;
Ch(an)?Pr	return CHPR;
SysEx		return SYSEX;
Meta		return META;
SeqSpec		return SEQSPEC;
Text		return TEXT;
Copyright	return COPYRIGHT;
TrkName|SeqName		return SEQNAME;
InstrName	return INSTRNAME;
Lyric		return LYRIC;
Marker		return MARKER;
Cue		return CUE;
SeqNr		return SEQNR;
KeySig		return KEYSIG;
Tempo		return TEMPO;
TimeSig		return TIMESIG;
SMPTE		return SMPTE;
Arb		return ARB;
[:/]		return '/';
X
minor		return MINOR;
major		return MAJOR;
X
ch=		return CH;
n(ote)?=	return NOTE;
v([oa]l)?=	return VAL;
c(on)?=		return CON;
p(rog)?=	return PROG;
X
[-+]?[0-9]+		sscanf (yytext, "%ld", &yyval); return INT;
0x{Hex}+		sscanf (yytext+2, "%lx", &yyval); return INT;
\$[A-H1-8]+		yyval = bankno (yytext+1, yyleng-1); return INT;
<HEX>{Hex}{Hex}?	sscanf (yytext, "%lx", &yyval); return INT;
X
[a-g][#b+-]?[0-9]+	return NOTEVAL;
<INITIAL,HEX>\"		BEGIN (QUOTE);
<QUOTE>[^\\"\r\n]*	BEGIN (QUOTEA); yymore();
<QUOTE,QUOTEA>\"	BEGIN (0); return STRING;
<QUOTEA>\\(.|\n)	BEGIN(QUOTE); yymore();
<QUOTEA>[\r\n]		error ("unterminated string"); BEGIN(0);
X			
<QUOTE,QUOTEA><<EOF>>		error ("EOF in string"); return EOF;
X
<INITIAL,HEX>\\[ \t\r]*\n	lineno++;
<INITIAL,HEX>\n		lineno++; eol_seen++; BEGIN(0); return EOL;
X
<HEX>[g-z][a-z]+	BEGIN (0); return ERR;
<HEX>.			BEGIN (0); return ERR;
[a-z]+			return ERR;
.			return ERR;
X
<<EOF>>			return EOF;
X
%%
SHAR_EOF
chmod 0644 t2mf.fl ||
echo 'restore of t2mf.fl failed'
Wc_c="`wc -c < 't2mf.fl'`"
test 1968 -eq "$Wc_c" ||
	echo 't2mf.fl: original size 1968, current size' "$Wc_c"
fi
# ============= t2mf.h ==============
if test -f 't2mf.h' -a X"$1" != X"-c"; then
	echo 'x - skipping t2mf.h (File already exists)'
else
echo 'x - extracting t2mf.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 't2mf.h' &&
/* $Id: t2mf.h,v 1.2 1991/11/03 21:50:50 piet Rel $ */
#include "midifile.h"
X
#define MTHD	256
#define MTRK	257
#define TRKEND	258
X
#define ON	note_on
#define OFF	note_off
#define POPR	poly_aftertouch
#define PAR	control_change
#define PB	pitch_wheel
#define PRCH	program_chng
#define CHPR	channel_aftertouch
#define SYSEX	system_exclusive
X
#define ARB	259
#define MINOR	260
#define MAJOR	261
X	
#define CH	262
#define NOTE	263
#define VAL	264
#define CON	265
#define PROG	266
X
#define INT	267
#define STRING	268
#define STRESC	269
#define ERR	270
#define NOTEVAL 271
#define EOL	272
X
#define META	273
#define SEQSPEC	(META+1+sequencer_specific)
#define TEXT	(META+1+text_event)
#define COPYRIGHT	(META+1+copyright_notice)
#define SEQNAME	(META+1+sequence_name)
#define INSTRNAME	(META+1+instrument_name)
#define LYRIC	(META+1+lyric)
#define MARKER	(META+1+marker)
#define CUE	(META+1+cue_point)
#define SEQNR	(META+1+sequence_number)
#define KEYSIG	(META+1+key_signature)
#define TEMPO	(META+1+set_tempo)
#define TIMESIG	(META+1+time_signature)
#define SMPTE	(META+1+smpte_offset)
SHAR_EOF
chmod 0644 t2mf.h ||
echo 'restore of t2mf.h failed'
Wc_c="`wc -c < 't2mf.h'`"
test 1081 -eq "$Wc_c" ||
	echo 't2mf.h: original size 1081, current size' "$Wc_c"
fi
# ============= t2mflex.c ==============
if test -f 't2mflex.c' -a X"$1" != X"-c"; then
	echo 'x - skipping t2mflex.c (File already exists)'
else
echo 'x - extracting t2mflex.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 't2mflex.c' &&
/* A lexical scanner generated by flex */
X
/* scanner skeleton version:
X * $Header: /usr/fsys/odin/a/vern/flex/RCS/flex.skel,v 2.16 90/08/03 14:09:36 vern Exp $
X */
X
#define FLEX_SCANNER
X
#include <stdio.h>
X
X
/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
#ifdef c_plusplus
#ifndef __cplusplus
#define __cplusplus
#endif
#endif
X
X
#ifdef __cplusplus
X
#include <stdlib.h>
#include <osfcn.h>
X
/* use prototypes in function declarations */
#define YY_USE_PROTOS
X
/* the "const" storage-class-modifier is valid */
#define YY_USE_CONST
X
#else	/* ! __cplusplus */
X
#ifdef __STDC__
X
#ifdef __GNUC__
#include <stddef.h>
void *malloc( size_t );
void free( void* );
#else
#include <stdlib.h>
#endif	/* __GNUC__ */
X
#define YY_USE_PROTOS
#define YY_USE_CONST
X
#endif	/* __STDC__ */
#endif	/* ! __cplusplus */
X
X
#ifdef __TURBOC__
#define YY_USE_CONST
#endif
X
#ifdef atarist
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#define YY_INPUT(buf,result,max_size) \
X	if ( (result = _yyread( fileno(yyin), (char *) buf, max_size )) < 0 ) \
X	    YY_FATAL_ERROR( "read() in flex scanner failed" );
#endif
X
X
#ifndef YY_USE_CONST
#define const
#endif
X
X
#ifdef YY_USE_PROTOS
#define YY_PROTO(proto) proto
#else
#define YY_PROTO(proto) ()
/* we can't get here if it's an ANSI C compiler, or a C++ compiler,
X * so it's got to be a K&R compiler, and therefore there's no standard
X * place from which to include these definitions
X */
char *malloc();
int free();
int read();
#endif
X
X
/* amount of stuff to slurp up with each read */
#ifndef YY_READ_BUF_SIZE
#define YY_READ_BUF_SIZE 8192
#endif
X
/* returned upon end-of-file */
#define YY_END_TOK 0
X
/* copy whatever the last rule matched to the standard output */
X
/* cast to (char *) is because for 8-bit chars, yytext is (unsigned char *) */
/* this used to be an fputs(), but since the string might contain NUL's,
X * we now use fwrite()
X */
#define ECHO (void) fwrite( (char *) yytext, yyleng, 1, yyout )
X
/* gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
X * is returned in "result".
X */
#ifndef YY_INPUT
#define YY_INPUT(buf,result,max_size) \
X	if ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \
X	    YY_FATAL_ERROR( "read() in flex scanner failed" );
#endif
#define YY_NULL 0
X
/* no semi-colon after return; correct usage is to write "yyterminate();" -
X * we don't want an extra ';' after the "return" because that will cause
X * some compilers to complain about unreachable statements.
X */
#define yyterminate() return ( YY_NULL )
X
/* report a fatal error */
X
/* The funky do-while is used to turn this macro definition into
X * a single C statement (which needs a semi-colon terminator).
X * This avoids problems with code like:
X *
X * 	if ( something_happens )
X *		YY_FATAL_ERROR( "oops, the something happened" );
X *	else
X *		everything_okay();
X *
X * Prior to using the do-while the compiler would get upset at the
X * "else" because it interpreted the "if" statement as being all
X * done when it reached the ';' after the YY_FATAL_ERROR() call.
X */
X
#define YY_FATAL_ERROR(msg) \
X	do \
X		{ \
X		(void) fputs( msg, stderr ); \
X		(void) putc( '\n', stderr ); \
X		exit( 1 ); \
X		} \
X	while ( 0 )
X
/* default yywrap function - always treat EOF as an EOF */
#define yywrap() 1
X
/* enter a start condition.  This macro really ought to take a parameter,
X * but we do it the disgusting crufty way forced on us by the ()-less
X * definition of BEGIN
X */
#define BEGIN yy_start = 1 + 2 *
X
/* action number for EOF rule of a given start state */
#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
X
/* special action meaning "start processing a new file" */
#define YY_NEW_FILE \
X	do \
X		{ \
X		yy_init_buffer( yy_current_buffer, yyin ); \
X		yy_load_buffer_state(); \
X		} \
X	while ( 0 )
X
/* default declaration of generated scanner - a define so the user can
X * easily add parameters
X */
#define YY_DECL int yylex YY_PROTO(( void )) 
X
/* code executed at the end of each rule */
#define YY_BREAK break;
X
#define YY_END_OF_BUFFER_CHAR 0
X
#ifndef YY_BUF_SIZE
#define YY_BUF_SIZE (YY_READ_BUF_SIZE * 2) /* size of default input buffer */
#endif
X
typedef struct yy_buffer_state *YY_BUFFER_STATE;
X
#define YY_CHAR char
# line 1 "t2mf.fl"
#define INITIAL 0
/* $Id: t2mf.fl,v 1.3 1991/11/15 19:31:00 piet Rel $ */
# line 4 "t2mf.fl"
X
#include "t2mf.h"
X
#ifdef NO_YYLENG_VAR
int yylength;
#define YY_USER_ACTION	yylength = yyleng
#endif
X
int do_hex = 0;
int eol_seen = 0;
int lineno = 1;
long yyval;
long bankno();
X
#define QUOTE 1
#define QUOTEA 2
#define HEX 3
# line 25 "t2mf.fl"
X
/* done after the current pattern has been matched and before the
X * corresponding action - sets up yytext
X */
#define YY_DO_BEFORE_ACTION \
X	yytext = yy_bp; \
X	yytext -= yy_more_len; \
X	yyleng = yy_cp - yytext; \
X	yy_hold_char = *yy_cp; \
X	*yy_cp = '\0'; \
X	yy_c_buf_p = yy_cp;
X
#define EOB_ACT_CONTINUE_SCAN 0
#define EOB_ACT_END_OF_FILE 1
#define EOB_ACT_LAST_MATCH 2
X
/* return all but the first 'n' matched characters back to the input stream */
#define yyless(n) \
X	do \
X		{ \
X		/* undo effects of setting up yytext */ \
X		*yy_cp = yy_hold_char; \
X		yy_c_buf_p = yy_cp = yy_bp + n; \
X		YY_DO_BEFORE_ACTION; /* set up yytext again */ \
X		} \
X	while ( 0 )
X
#define unput(c) yyunput( c, yytext )
X
X
struct yy_buffer_state
X    {
X    FILE *yy_input_file;
X
X    YY_CHAR *yy_ch_buf;		/* input buffer */
X    YY_CHAR *yy_buf_pos;	/* current position in input buffer */
X
X    /* size of input buffer in bytes, not including room for EOB characters*/
X    int yy_buf_size;	
X
X    /* number of characters read into yy_ch_buf, not including EOB characters */
X    int yy_n_chars;
X
X    int yy_eof_status;		/* whether we've seen an EOF on this buffer */
#define EOF_NOT_SEEN 0
X    /* "pending" happens when the EOF has been seen but there's still
X     * some text process
X     */
#define EOF_PENDING 1
#define EOF_DONE 2
X    };
X
static YY_BUFFER_STATE yy_current_buffer;
X
/* we provide macros for accessing buffer states in case in the
X * future we want to put the buffer states in a more general
X * "scanner state"
X */
#define YY_CURRENT_BUFFER yy_current_buffer
X
X
/* yy_hold_char holds the character lost when yytext is formed */
static YY_CHAR yy_hold_char;
X
static int yy_n_chars;		/* number of characters read into yy_ch_buf */
X
X
X
#ifndef YY_USER_ACTION
#define YY_USER_ACTION
#endif
X
#ifndef YY_USER_INIT
#define YY_USER_INIT
#endif
X
extern YY_CHAR *yytext;
extern int yyleng;
extern FILE *yyin, *yyout;
X
YY_CHAR *yytext;
int yyleng;
X
FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
X
#define YY_END_OF_BUFFER 56
typedef int yy_state_type;
static const short int yy_accept[188] =
X    {   0,
X        0,    0,   43,   43,    0,    0,    0,    0,   56,   53,
X        1,   49,   42,   53,   53,   53,   29,   37,   37,   53,
X       52,   52,   52,   52,   52,   52,   52,   52,   52,   52,
X       52,   52,   52,   52,   43,   55,   44,   46,   55,   51,
X        1,   42,   51,   40,   51,   51,    0,    2,   39,   37,
X        0,    0,   48,    0,   41,   52,   52,   52,   35,   52,
X       52,   52,   52,   52,   52,   52,   52,   52,   52,   52,
X       33,   52,   52,    6,   36,   52,   10,   52,   52,   52,
X       52,   52,   52,   52,   52,   34,   52,   43,   45,   40,
X       50,   38,   28,   32,   52,   52,   52,   52,   22,   52,
X
X       52,   52,   52,   52,   52,   52,   52,   52,   52,    7,
X        9,   52,   52,   52,   52,   52,   52,   52,   52,   52,
X       52,   52,   52,   52,   12,   52,   52,   52,   52,   52,
X       52,   14,   52,   52,    4,   52,   52,   52,    8,   11,
X       52,   52,   52,   52,   52,   52,   16,   52,   52,   52,
X       52,   52,   52,   20,   31,   52,    3,   30,    9,   52,
X       23,   52,   27,   13,   25,   52,   52,   52,   52,   52,
X       24,   21,   52,   52,   52,    5,   52,   52,   52,   18,
X       15,   26,   52,   52,   17,   19,    0
X    } ;
X
static const YY_CHAR yy_ec[128] =
X    {   0,
X        1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
X        1,    1,    4,    1,    1,    1,    1,    1,    1,    1,
X        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
X        1,    2,    1,    5,    6,    7,    1,    1,    1,    1,
X        1,    1,    8,    1,    8,    1,    9,   10,   11,   11,
X       11,   11,   11,   11,   11,   11,   12,    9,    1,    1,
X       13,    1,    1,    1,   15,   16,   17,   18,   19,   20,
X       21,   22,   23,   24,   25,   26,   27,   28,   29,   30,
X       31,   32,   33,   34,   35,   36,   37,   38,   39,   37,
X        1,   14,    1,    1,    1,    1,   15,   16,   17,   18,
X
X       19,   20,   21,   22,   23,   24,   25,   26,   27,   28,
X       29,   30,   31,   32,   33,   34,   35,   36,   37,   38,
X       39,   37,    1,    1,    1,    1,    1
X    } ;
X
static const short int yy_base[198] =
X    {   0,
X        0,    0,   37,   40,   43,   55,   69,    0,  552,  553,
X      553,  553,  553,  548,    0,   51,  553,   99,   54,  110,
X      132,  159,  104,  110,  522,  530,  509,  112,   39,   95,
X      134,  133,  122,  144,    0,  553,  553,  553,    0,  553,
X      553,  553,  544,    0,  126,    0,  543,  553,    0,  166,
X        0,  177,  553,  172,  175,    0,  178,  529,  553,  121,
X       25,  525,  510,  503,  509,  129,  506,  516,  510,  505,
X      553,  502,  515,    0,  553,  502,    0,  132,  139,  502,
X      502,  498,   29,  503,  504,  553,  502,    0,  553,  553,
X        0,    0,    0,  553,  499,  494,  512,  485,    0,  489,
X
X      489,  498,  491,  494,  503,  491,  487,  490,  495,    0,
X      498,  473,  479,  488,  488,   91,  474,  488,  476,  471,
X      485,  172,  490,  472,    0,  469,  468,  476,  475,  459,
X      437,    0,  436,  355,    0,  365,  350,  346,    0,    0,
X      179,  178,  318,  328,  305,  312,    0,  298,  302,  314,
X      186,  180,  186,    0,    0,  174,    0,    0,    0,  178,
X        0,  185,    0,    0,    0,  180,  184,  174,  178,  183,
X        0,    0,  178,  178,  173,    0,  155,  133,   98,    0,
X        0,    0,   16,   30,    0,    0,  553,  210,  249,  288,
X      317,  334,  373,  412,  442,  448,  478
X
X    } ;
X
static const short int yy_def[198] =
X    {   0,
X      187,    1,  188,  188,  189,  189,  187,    7,  187,  187,
X      187,  187,  187,  190,  191,  187,  187,  187,  187,  187,
X      192,  192,   22,  192,   24,   24,   24,   24,   24,   24,
X       24,   24,   24,   24,  193,  187,  187,  187,  194,  187,
X      187,  187,  190,  195,  187,  196,  190,  187,  191,  187,
X      197,  187,  187,  187,  187,   24,   24,   24,  187,   24,
X       24,   24,   24,   24,   24,   24,   24,   24,   24,   24,
X      187,   24,   24,   24,  187,   24,   24,   24,   24,   24,
X       24,   24,   24,   24,   24,  187,   24,  193,  187,  187,
X      196,  197,   24,  187,   24,   24,   24,   24,   24,   24,
X
X       24,   24,   24,   24,   24,   24,   24,   24,   24,   24,
X       24,   24,   24,   24,   24,   24,   24,   24,   24,   24,
X       24,   24,   24,   24,   24,   24,   24,   24,   24,   24,
X       24,   24,   24,   24,   24,   24,   24,   24,   24,   24,
X       24,   24,   24,   24,   24,   24,   24,   24,   24,   24,
X       24,   24,   24,   24,   24,   24,   24,   24,   24,   24,
X       24,   24,   24,   24,   24,   24,   24,   24,   24,   24,
X       24,   24,   24,   24,   24,   24,   24,   24,   24,   24,
X       24,   24,   24,   24,   24,   24,    0,  187,  187,  187,
X      187,  187,  187,  187,  187,  187,  187
X
X    } ;
X
static const short int yy_nxt[593] =
X    {   0,
X       10,   11,   12,   11,   13,   14,   15,   16,   17,   18,
X       19,   19,   10,   20,   21,   22,   23,   22,   22,   22,
X       22,   24,   25,   24,   26,   27,   28,   29,   30,   31,
X       24,   24,   32,   33,   24,   34,   24,   24,   24,   36,
X       36,   37,   36,   36,   37,   38,   38,   37,  186,  185,
X       36,   71,   97,   36,   98,  119,   39,   38,   38,   37,
X       50,   50,   50,   50,   50,   50,  120,   72,   39,   40,
X       41,   12,   41,   42,   43,   40,   40,   40,   44,   44,
X       44,   40,   45,   44,   44,   44,   44,   44,   44,   46,
X       46,   46,   46,   46,   46,   46,   46,   46,   46,   46,
X
X       46,   46,   46,   46,   46,   46,   46,   46,   50,   50,
X       50,   52,   53,   52,   73,  187,   59,  187,  142,  187,
X      187,  187,   74,  143,  184,   60,   66,   52,   53,   52,
X       67,   68,   61,   94,   69,   95,   51,   54,   62,   54,
X       83,   55,   55,   55,   84,   70,   75,   57,   76,   77,
X       96,   80,  103,   85,  183,  114,   86,  112,   87,   81,
X      104,  113,   78,   58,   54,   79,   54,  115,   55,   55,
X       55,   82,   87,  180,   57,   50,   50,   50,   52,   53,
X       52,   55,   55,   55,   55,   55,   55,   55,   55,   55,
X      149,   75,  160,  182,  181,  114,  180,  179,  178,  150,
X
X      177,  176,  175,  174,  173,  172,  171,  170,  169,  161,
X       35,   35,   35,   35,   35,   35,   35,   35,   35,   35,
X       35,   35,   35,   35,   35,   35,   35,   35,   35,   35,
X       35,   35,   35,   35,   35,   35,   35,   35,   35,   35,
X       35,   35,   35,   35,   35,   35,   35,   35,   35,   36,
X       36,   36,   36,   36,   36,   36,   36,   36,   36,   36,
X       36,   36,   36,   36,   36,   36,   36,   36,   36,   36,
X       36,   36,   36,   36,   36,   36,   36,   36,   36,   36,
X       36,   36,   36,   36,   36,   36,   36,   36,   47,   47,
X       47,   47,   47,   47,   47,   47,   47,   47,   47,   47,
X
X       47,   47,   47,   47,   47,   47,   47,   47,   47,   47,
X       47,   47,   47,   47,   47,   47,   47,   47,   47,   47,
X       47,   47,   47,   47,   47,   47,   47,   49,  168,  167,
X      166,   49,   49,   49,   49,   49,   49,   49,   49,   56,
X      165,   56,  164,   56,   56,   56,  163,  162,   56,   56,
X       56,   56,   56,   56,   56,   56,   56,   56,   56,   56,
X       56,   56,   56,   56,   56,   56,   56,   56,   56,   56,
X       56,   56,   56,   88,   88,  113,  159,   71,   88,   88,
X       88,   88,   88,   88,   88,   88,  158,   88,   88,   88,
X       88,   88,   88,   88,   88,   88,   88,   88,   88,   88,
X
X       88,   88,   88,   88,   88,   88,   88,   88,   88,   88,
X       88,   88,   89,   89,   89,   89,   89,   89,   89,   89,
X       89,   89,   89,   89,   89,   89,   89,   89,   89,   89,
X       89,   89,   89,   89,   89,   89,   89,   89,   89,   89,
X       89,   89,   89,   89,   89,   89,   89,   89,   89,   89,
X       89,   90,   90,   90,  157,  156,   90,   90,   90,   90,
X       90,   90,   91,   91,   91,   91,   91,   91,   91,   91,
X       91,   91,   91,   91,   91,   91,   91,   91,   91,   91,
X       91,   91,   91,   91,   91,   91,   91,   92,   92,   92,
X      155,  154,   92,   92,   92,   92,   92,   92,  153,  152,
X
X      151,   96,   86,  148,  147,  146,  145,  144,  141,  140,
X      139,  138,  137,  136,  135,  134,  133,  132,  131,  130,
X      129,  128,  127,  126,   59,  125,  124,  123,  122,  121,
X      118,  117,  116,  111,  110,  109,  108,  107,  106,  105,
X      102,  101,  100,   99,   93,   48,   48,   65,   64,   63,
X       48,  187,    9,  187,  187,  187,  187,  187,  187,  187,
X      187,  187,  187,  187,  187,  187,  187,  187,  187,  187,
X      187,  187,  187,  187,  187,  187,  187,  187,  187,  187,
X      187,  187,  187,  187,  187,  187,  187,  187,  187,  187,
X      187,  187
X
X    } ;
X
static const short int yy_chk[593] =
X    {   0,
X        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
X        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
X        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
X        1,    1,    1,    1,    1,    1,    1,    1,    1,    3,
X        3,    3,    4,    4,    4,    5,    5,    5,  184,  183,
X        3,   29,   61,    4,   61,   83,    5,    6,    6,    6,
X       16,   16,   16,   19,   19,   19,   83,   29,    6,    7,
X        7,    7,    7,    7,    7,    7,    7,    7,    7,    7,
X        7,    7,    7,    7,    7,    7,    7,    7,    7,    7,
X        7,    7,    7,    7,    7,    7,    7,    7,    7,    7,
X
X        7,    7,    7,    7,    7,    7,    7,    7,   18,   18,
X       18,   20,   20,   20,   30,   24,   23,   24,  116,   24,
X       24,   24,   30,  116,  179,   23,   28,   45,   45,   45,
X       28,   28,   23,   60,   28,   60,   18,   21,   23,   21,
X       33,   21,   21,   21,   33,   28,   31,   21,   31,   31,
X       60,   32,   66,   33,  178,   79,   34,   78,   34,   32,
X       66,   78,   31,   21,   22,   31,   22,   79,   22,   22,
X       22,   32,   34,  177,   22,   50,   50,   50,   52,   52,
X       52,   54,   54,   54,   55,   55,   55,   57,   57,   57,
X      122,  141,  142,  175,  174,  141,  173,  170,  169,  122,
X
X      168,  167,  166,  162,  160,  156,  153,  152,  151,  142,
X      188,  188,  188,  188,  188,  188,  188,  188,  188,  188,
X      188,  188,  188,  188,  188,  188,  188,  188,  188,  188,
X      188,  188,  188,  188,  188,  188,  188,  188,  188,  188,
X      188,  188,  188,  188,  188,  188,  188,  188,  188,  189,
X      189,  189,  189,  189,  189,  189,  189,  189,  189,  189,
X      189,  189,  189,  189,  189,  189,  189,  189,  189,  189,
X      189,  189,  189,  189,  189,  189,  189,  189,  189,  189,
X      189,  189,  189,  189,  189,  189,  189,  189,  190,  190,
X      190,  190,  190,  190,  190,  190,  190,  190,  190,  190,
X
X      190,  190,  190,  190,  190,  190,  190,  190,  190,  190,
X      190,  190,  190,  190,  190,  190,  190,  190,  190,  190,
X      190,  190,  190,  190,  190,  190,  190,  191,  150,  149,
X      148,  191,  191,  191,  191,  191,  191,  191,  191,  192,
X      146,  192,  145,  192,  192,  192,  144,  143,  192,  192,
X      192,  192,  192,  192,  192,  192,  192,  192,  192,  192,
X      192,  192,  192,  192,  192,  192,  192,  192,  192,  192,
X      192,  192,  192,  193,  193,  138,  137,  136,  193,  193,
X      193,  193,  193,  193,  193,  193,  134,  193,  193,  193,
X      193,  193,  193,  193,  193,  193,  193,  193,  193,  193,
X
X      193,  193,  193,  193,  193,  193,  193,  193,  193,  193,
X      193,  193,  194,  194,  194,  194,  194,  194,  194,  194,
X      194,  194,  194,  194,  194,  194,  194,  194,  194,  194,
X      194,  194,  194,  194,  194,  194,  194,  194,  194,  194,
X      194,  194,  194,  194,  194,  194,  194,  194,  194,  194,
X      194,  195,  195,  195,  133,  131,  195,  195,  195,  195,
X      195,  195,  196,  196,  196,  196,  196,  196,  196,  196,
X      196,  196,  196,  196,  196,  196,  196,  196,  196,  196,
X      196,  196,  196,  196,  196,  196,  196,  197,  197,  197,
X      130,  129,  197,  197,  197,  197,  197,  197,  128,  127,
X
X      126,  124,  123,  121,  120,  119,  118,  117,  115,  114,
X      113,  112,  111,  109,  108,  107,  106,  105,  104,  103,
X      102,  101,  100,   98,   97,   96,   95,   87,   85,   84,
X       82,   81,   80,   76,   73,   72,   70,   69,   68,   67,
X       65,   64,   63,   62,   58,   47,   43,   27,   26,   25,
X       14,    9,  187,  187,  187,  187,  187,  187,  187,  187,
X      187,  187,  187,  187,  187,  187,  187,  187,  187,  187,
X      187,  187,  187,  187,  187,  187,  187,  187,  187,  187,
X      187,  187,  187,  187,  187,  187,  187,  187,  187,  187,
X      187,  187
X
X    } ;
X
static yy_state_type yy_last_accepting_state;
static YY_CHAR *yy_last_accepting_cpos;
X
/* the intent behind this definition is that it'll catch
X * any uses of REJECT which flex missed
X */
#define REJECT reject_used_but_not_detected
static int yy_more_flag = 0;
static int yy_doing_yy_more = 0;
static int yy_more_len = 0;
#define yymore() { yy_more_flag = 1; }
#define YY_MORE_ADJ (yy_doing_yy_more ? yy_more_len : 0)
X
/* these variables are all declared out here so that section 3 code can
X * manipulate them
X */
/* points to current character in buffer */
static YY_CHAR *yy_c_buf_p = (YY_CHAR *) 0;
static int yy_init = 1;		/* whether we need to initialize */
static int yy_start = 0;	/* start state number */
X
/* flag which is used to allow yywrap()'s to do buffer switches
X * instead of setting up a fresh yyin.  A bit of a hack ...
X */
static int yy_did_buffer_switch_on_eof;
X
static yy_state_type yy_get_previous_state YY_PROTO(( void ));
static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state ));
static int yy_get_next_buffer YY_PROTO(( void ));
static void yyunput YY_PROTO(( YY_CHAR c, YY_CHAR *buf_ptr ));
void yyrestart YY_PROTO(( FILE *input_file ));
void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer ));
void yy_load_buffer_state YY_PROTO(( void ));
YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size ));
void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b ));
void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file ));
X
#define yy_new_buffer yy_create_buffer
X
#ifdef __cplusplus
static int yyinput YY_PROTO(( void ));
#else
static int input YY_PROTO(( void ));
#endif
X
YY_DECL
X    {
X    register yy_state_type yy_current_state;
X    register YY_CHAR *yy_cp, *yy_bp;
X    register int yy_act;
X
X
X	if (do_hex) {
X		BEGIN(HEX);
X		do_hex = 0;
X	}
X	eol_seen = 0;
X		
X
X    if ( yy_init )
X	{
X	YY_USER_INIT;
X
X	if ( ! yy_start )
X	    yy_start = 1;	/* first start state */
X
X	if ( ! yyin )
X	    yyin = stdin;
X
X	if ( ! yyout )
X	    yyout = stdout;
X
X	if ( yy_current_buffer )
X	    yy_init_buffer( yy_current_buffer, yyin );
X	else
X	    yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE );
X
X	yy_load_buffer_state();
X
X	yy_init = 0;
X	}
X
X    while ( 1 )		/* loops until end-of-file is reached */
X	{
X	yy_more_len = 0;
X	yy_doing_yy_more = yy_more_flag;
X	if ( yy_doing_yy_more )
X	    {
X	    yy_more_len = yyleng;
X	    yy_more_flag = 0;
X	    }
X	yy_cp = yy_c_buf_p;
X
X	/* support of yytext */
X	*yy_cp = yy_hold_char;
X
X	/* yy_bp points to the position in yy_ch_buf of the start of the
X	 * current run.
X	 */
X	yy_bp = yy_cp;
X
X	yy_current_state = yy_start;
yy_match:
X	do
X	    {
X	    register YY_CHAR yy_c = yy_ec[*yy_cp];
X	    if ( yy_accept[yy_current_state] )
X		{
X		yy_last_accepting_state = yy_current_state;
X		yy_last_accepting_cpos = yy_cp;
X		}
X	    while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
X		{
X		yy_current_state = yy_def[yy_current_state];
X		}
X	    yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
X	    ++yy_cp;
X	    }
X	while ( yy_current_state != 187 );
X	yy_cp = yy_last_accepting_cpos;
X	yy_current_state = yy_last_accepting_state;
X
yy_find_action:
X	yy_act = yy_accept[yy_current_state];
X
X	YY_DO_BEFORE_ACTION;
X	YY_USER_ACTION;
X
do_action:	/* this label is used only to access EOF actions */
X
X
X	switch ( yy_act )
X	    {
X	    case 0: /* must backtrack */
X	    /* undo the effects of YY_DO_BEFORE_ACTION */
X	    *yy_cp = yy_hold_char;
X	    yy_cp = yy_last_accepting_cpos;
X	    yy_current_state = yy_last_accepting_state;
X	    goto yy_find_action;
X
case 1:
# line 32 "t2mf.fl"
/* skip whitespace */;
X	YY_BREAK
case 2:
# line 33 "t2mf.fl"
/* skip comment */ lineno++;
X	YY_BREAK
case 3:
# line 35 "t2mf.fl"
return MTHD;
X	YY_BREAK
case 4:
# line 36 "t2mf.fl"
return MTRK;
X	YY_BREAK
case 5:
# line 37 "t2mf.fl"
return TRKEND;
X	YY_BREAK
case 6:
# line 39 "t2mf.fl"
return ON;
X	YY_BREAK
case 7:
# line 40 "t2mf.fl"
return OFF;
X	YY_BREAK
case 8:
# line 41 "t2mf.fl"
return POPR;
X	YY_BREAK
case 9:
# line 42 "t2mf.fl"
return PAR;
X	YY_BREAK
case 10:
# line 43 "t2mf.fl"
return PB;
X	YY_BREAK
case 11:
# line 44 "t2mf.fl"
return PRCH;
X	YY_BREAK
case 12:
# line 45 "t2mf.fl"
return CHPR;
X	YY_BREAK
case 13:
# line 46 "t2mf.fl"
return SYSEX;
X	YY_BREAK
case 14:
# line 47 "t2mf.fl"
return META;
X	YY_BREAK
case 15:
# line 48 "t2mf.fl"
return SEQSPEC;
X	YY_BREAK
case 16:
# line 49 "t2mf.fl"
return TEXT;
X	YY_BREAK
case 17:
# line 50 "t2mf.fl"
return COPYRIGHT;
X	YY_BREAK
case 18:
# line 51 "t2mf.fl"
return SEQNAME;
X	YY_BREAK
case 19:
# line 52 "t2mf.fl"
return INSTRNAME;
X	YY_BREAK
case 20:
# line 53 "t2mf.fl"
return LYRIC;
X	YY_BREAK
case 21:
# line 54 "t2mf.fl"
return MARKER;
X	YY_BREAK
case 22:
# line 55 "t2mf.fl"
return CUE;
X	YY_BREAK
case 23:
# line 56 "t2mf.fl"
return SEQNR;
X	YY_BREAK
case 24:
# line 57 "t2mf.fl"
return KEYSIG;
X	YY_BREAK
case 25:
# line 58 "t2mf.fl"
return TEMPO;
X	YY_BREAK
case 26:
# line 59 "t2mf.fl"
return TIMESIG;
X	YY_BREAK
case 27:
# line 60 "t2mf.fl"
return SMPTE;
X	YY_BREAK
case 28:
# line 61 "t2mf.fl"
return ARB;
X	YY_BREAK
case 29:
# line 62 "t2mf.fl"
return '/';
X	YY_BREAK
case 30:
# line 64 "t2mf.fl"
return MINOR;
X	YY_BREAK
case 31:
# line 65 "t2mf.fl"
return MAJOR;
X	YY_BREAK
case 32:
# line 67 "t2mf.fl"
return CH;
X	YY_BREAK
case 33:
# line 68 "t2mf.fl"
return NOTE;
X	YY_BREAK
case 34:
# line 69 "t2mf.fl"
return VAL;
X	YY_BREAK
case 35:
# line 70 "t2mf.fl"
return CON;
X	YY_BREAK
case 36:
# line 71 "t2mf.fl"
return PROG;
X	YY_BREAK
case 37:
# line 73 "t2mf.fl"
sscanf (yytext, "%ld", &yyval); return INT;
X	YY_BREAK
case 38:
# line 74 "t2mf.fl"
sscanf (yytext+2, "%lx", &yyval); return INT;
X	YY_BREAK
case 39:
# line 75 "t2mf.fl"
yyval = bankno (yytext+1, yyleng-1); return INT;
X	YY_BREAK
case 40:
# line 76 "t2mf.fl"
sscanf (yytext, "%lx", &yyval); return INT;
X	YY_BREAK
case 41:
# line 78 "t2mf.fl"
return NOTEVAL;
X	YY_BREAK
case 42:
# line 79 "t2mf.fl"
BEGIN (QUOTE);
X	YY_BREAK
case 43:
# line 80 "t2mf.fl"
BEGIN (QUOTEA); yymore();
X	YY_BREAK
case 44:
# line 81 "t2mf.fl"
BEGIN (0); return STRING;
X	YY_BREAK
case 45:
# line 82 "t2mf.fl"
BEGIN(QUOTE); yymore();
X	YY_BREAK
case 46:
# line 83 "t2mf.fl"
error ("unterminated string"); BEGIN(0);
X	YY_BREAK
case YY_STATE_EOF(QUOTE):
case YY_STATE_EOF(QUOTEA):
# line 85 "t2mf.fl"
error ("EOF in string"); return EOF;
X	YY_BREAK
case 48:
# line 87 "t2mf.fl"
lineno++;
X	YY_BREAK
case 49:
# line 88 "t2mf.fl"
lineno++; eol_seen++; BEGIN(0); return EOL;
X	YY_BREAK
case 50:
# line 90 "t2mf.fl"
BEGIN (0); return ERR;
X	YY_BREAK
case 51:
# line 91 "t2mf.fl"
BEGIN (0); return ERR;
X	YY_BREAK
case 52:
# line 92 "t2mf.fl"
return ERR;
X	YY_BREAK
case 53:
# line 93 "t2mf.fl"
return ERR;
X	YY_BREAK
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(HEX):
# line 95 "t2mf.fl"
return EOF;
X	YY_BREAK
case 55:
# line 97 "t2mf.fl"
YY_FATAL_ERROR( "flex scanner jammed" );
X	YY_BREAK
X
X	    case YY_END_OF_BUFFER:
X		{
X		/* amount of text matched not including the EOB char */
X		int yy_amount_of_matched_text = yy_cp - yytext - 1;
X
X		/* undo the effects of YY_DO_BEFORE_ACTION */
X		*yy_cp = yy_hold_char;
X
X		/* note that here we test for yy_c_buf_p "<=" to the position
X		 * of the first EOB in the buffer, since yy_c_buf_p will
X		 * already have been incremented past the NUL character
X		 * (since all states make transitions on EOB to the end-
X		 * of-buffer state).  Contrast this with the test in yyinput().
X		 */
X		if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] )
X		    /* this was really a NUL */
X		    {
X		    yy_state_type yy_next_state;
X
X		    yy_c_buf_p = yytext + yy_amount_of_matched_text;
X
X		    yy_current_state = yy_get_previous_state();
X
X		    /* okay, we're now positioned to make the
X		     * NUL transition.  We couldn't have
X		     * yy_get_previous_state() go ahead and do it
X		     * for us because it doesn't know how to deal
X		     * with the possibility of jamming (and we
X		     * don't want to build jamming into it because
X		     * then it will run more slowly)
X		     */
X
X		    yy_next_state = yy_try_NUL_trans( yy_current_state );
X
X		    yy_bp = yytext + YY_MORE_ADJ;
X
X		    if ( yy_next_state )
X			{
X			/* consume the NUL */
X			yy_cp = ++yy_c_buf_p;
X			yy_current_state = yy_next_state;
X			goto yy_match;
X			}
X
X		    else
X			{
X			    yy_cp = yy_last_accepting_cpos;
X			    yy_current_state = yy_last_accepting_state;
X			goto yy_find_action;
X			}
X		    }
X
X		else switch ( yy_get_next_buffer() )
X		    {
X		    case EOB_ACT_END_OF_FILE:
X			{
X			yy_did_buffer_switch_on_eof = 0;
X
X			if ( yywrap() )
X			    {
X			    /* note: because we've taken care in
X			     * yy_get_next_buffer() to have set up yytext,
X			     * we can now set up yy_c_buf_p so that if some
X			     * total hoser (like flex itself) wants
X			     * to call the scanner after we return the
X			     * YY_NULL, it'll still work - another YY_NULL
X			     * will get returned.
X			     */
X			    yy_c_buf_p = yytext + YY_MORE_ADJ;
X
X			    yy_act = YY_STATE_EOF((yy_start - 1) / 2);
X			    goto do_action;
X			    }
X
X			else
X			    {
X			    if ( ! yy_did_buffer_switch_on_eof )
X				YY_NEW_FILE;
X			    }
X			}
X			break;
X
X		    case EOB_ACT_CONTINUE_SCAN:
X			yy_c_buf_p = yytext + yy_amount_of_matched_text;
X
X			yy_current_state = yy_get_previous_state();
X
X			yy_cp = yy_c_buf_p;
X			yy_bp = yytext + YY_MORE_ADJ;
X			goto yy_match;
X
X		    case EOB_ACT_LAST_MATCH:
X			yy_c_buf_p =
X			    &yy_current_buffer->yy_ch_buf[yy_n_chars];
X
X			yy_current_state = yy_get_previous_state();
X
X			yy_cp = yy_c_buf_p;
X			yy_bp = yytext + YY_MORE_ADJ;
X			goto yy_find_action;
X		    }
X		break;
X		}
X
X	    default:
#ifdef FLEX_DEBUG
X		printf( "action # %d\n", yy_act );
#endif
X		YY_FATAL_ERROR(
X			"fatal flex scanner internal error--no action found" );
X	    }
X	}
X    }
X
X
/* yy_get_next_buffer - try to read in a new buffer
X *
X * synopsis
X *     int yy_get_next_buffer();
X *     
X * returns a code representing an action
X *     EOB_ACT_LAST_MATCH - 
X *     EOB_ACT_CONTINUE_SCAN - continue scanning from current position
X *     EOB_ACT_END_OF_FILE - end of file
X */
X
static int yy_get_next_buffer()
X
X    {
X    register YY_CHAR *dest = yy_current_buffer->yy_ch_buf;
X    register YY_CHAR *source = yytext - 1; /* copy prev. char, too */
X    register int number_to_move, i;
X    int ret_val;
X
X    if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] )
X	YY_FATAL_ERROR(
X		"fatal flex scanner internal error--end of buffer missed" );
X
X    /* try to read more data */
X
X    /* first move last chars to start of buffer */
X    number_to_move = yy_c_buf_p - yytext;
X
X    for ( i = 0; i < number_to_move; ++i )
X	*(dest++) = *(source++);
X
X    if ( yy_current_buffer->yy_eof_status != EOF_NOT_SEEN )
X	/* don't do the read, it's not guaranteed to return an EOF,
X	 * just force an EOF
X	 */
X	yy_n_chars = 0;
X
X    else
X	{
X	int num_to_read = yy_current_buffer->yy_buf_size - number_to_move - 1;
X
X	if ( num_to_read > YY_READ_BUF_SIZE )
X	    num_to_read = YY_READ_BUF_SIZE;
X
X	else if ( num_to_read <= 0 )
X	    YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" );
X
X	/* read in more data */
X	YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]),
X		  yy_n_chars, num_to_read );
X	}
X
X    if ( yy_n_chars == 0 )
X	{
X	if ( number_to_move == 1 )
X	    {
X	    ret_val = EOB_ACT_END_OF_FILE;
X	    yy_current_buffer->yy_eof_status = EOF_DONE;
X	    }
X
X	else
X	    {
X	    ret_val = EOB_ACT_LAST_MATCH;
X	    yy_current_buffer->yy_eof_status = EOF_PENDING;
X	    }
X	}
X
X    else
X	ret_val = EOB_ACT_CONTINUE_SCAN;
X
X    yy_n_chars += number_to_move;
X    yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
X    yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
X
X    /* yytext begins at the second character in yy_ch_buf; the first
X     * character is the one which preceded it before reading in the latest
X     * buffer; it needs to be kept around in case it's a newline, so
X     * yy_get_previous_state() will have with '^' rules active
X     */
X
X    yytext = &yy_current_buffer->yy_ch_buf[1];
X
X    return ( ret_val );
X    }
X
X
/* yy_get_previous_state - get the state just before the EOB char was reached
X *
X * synopsis
X *     yy_state_type yy_get_previous_state();
X */
X
static yy_state_type yy_get_previous_state()
X
X    {
X    register yy_state_type yy_current_state;
X    register YY_CHAR *yy_cp;
X
X    yy_current_state = yy_start;
X
X    for ( yy_cp = yytext + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )
X	{
X	register YY_CHAR yy_c = (*yy_cp ? yy_ec[*yy_cp] : 1);
X	if ( yy_accept[yy_current_state] )
X	    {
X	    yy_last_accepting_state = yy_current_state;
X	    yy_last_accepting_cpos = yy_cp;
X	    }
X	while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
X	    {
X	    yy_current_state = yy_def[yy_current_state];
X	    }
X	yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
X	}
X
X    return ( yy_current_state );
X    }
X
X
/* yy_try_NUL_trans - try to make a transition on the NUL character
X *
X * synopsis
X *     next_state = yy_try_NUL_trans( current_state );
X */
X
#ifdef YY_USE_PROTOS
static yy_state_type yy_try_NUL_trans( register yy_state_type yy_current_state )
#else
static yy_state_type yy_try_NUL_trans( yy_current_state )
register yy_state_type yy_current_state;
#endif
X
X    {
X    register int yy_is_jam;
X    register YY_CHAR *yy_cp = yy_c_buf_p;
X
X    register YY_CHAR yy_c = 1;
X    if ( yy_accept[yy_current_state] )
X	{
X	yy_last_accepting_state = yy_current_state;
X	yy_last_accepting_cpos = yy_cp;
X	}
X    while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
X	{
X	yy_current_state = yy_def[yy_current_state];
X	}
X    yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
X    yy_is_jam = (yy_current_state == 187);
X
X    return ( yy_is_jam ? 0 : yy_current_state );
X    }
X
X
#ifdef YY_USE_PROTOS
static void yyunput( YY_CHAR c, register YY_CHAR *yy_bp )
#else
static void yyunput( c, yy_bp )
YY_CHAR c;
register YY_CHAR *yy_bp;
#endif
X
X    {
X    register YY_CHAR *yy_cp = yy_c_buf_p;
X
X    /* undo effects of setting up yytext */
X    *yy_cp = yy_hold_char;
X
X    if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
X	{ /* need to shift things up to make room */
X	register int number_to_move = yy_n_chars + 2; /* +2 for EOB chars */
X	register YY_CHAR *dest =
X	    &yy_current_buffer->yy_ch_buf[yy_current_buffer->yy_buf_size + 2];
X	register YY_CHAR *source =
X	    &yy_current_buffer->yy_ch_buf[number_to_move];
X
X	while ( source > yy_current_buffer->yy_ch_buf )
X	    *--dest = *--source;
X
X	yy_cp += dest - source;
X	yy_bp += dest - source;
X	yy_n_chars = yy_current_buffer->yy_buf_size;
X
X	if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
X	    YY_FATAL_ERROR( "flex scanner push-back overflow" );
X	}
X
X    if ( yy_cp > yy_bp && yy_cp[-1] == '\n' )
X	yy_cp[-2] = '\n';
X
X    *--yy_cp = c;
X
X    /* note: the formal parameter *must* be called "yy_bp" for this
X     *       macro to now work correctly
X     */
X    YY_DO_BEFORE_ACTION; /* set up yytext again */
X    }
X
X
#ifdef __cplusplus
static int yyinput()
#else
static int input()
#endif
X
X    {
X    int c;
X    YY_CHAR *yy_cp = yy_c_buf_p;
X
X    *yy_cp = yy_hold_char;
X
X    if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
X	{
X	/* yy_c_buf_p now points to the character we want to return.
X	 * If this occurs *before* the EOB characters, then it's a
X	 * valid NUL; if not, then we've hit the end of the buffer.
X	 */
X	if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] )
X	    /* this was really a NUL */
X	    *yy_c_buf_p = '\0';
X
X	else
X	    { /* need more input */
X	    yytext = yy_c_buf_p;
X	    ++yy_c_buf_p;
X
X	    switch ( yy_get_next_buffer() )
X		{
X		case EOB_ACT_END_OF_FILE:
X		    {
X		    if ( yywrap() )
X			{
X			yy_c_buf_p = yytext + YY_MORE_ADJ;
X			return ( EOF );
X			}
X
X		    YY_NEW_FILE;
X
#ifdef __cplusplus
X		    return ( yyinput() );
#else
X		    return ( input() );
#endif
X		    }
X		    break;
X
X		case EOB_ACT_CONTINUE_SCAN:
X		    yy_c_buf_p = yytext + YY_MORE_ADJ;
X		    break;
X
X		case EOB_ACT_LAST_MATCH:
#ifdef __cplusplus
X		    YY_FATAL_ERROR( "unexpected last match in yyinput()" );
#else
X		    YY_FATAL_ERROR( "unexpected last match in input()" );
#endif
X		}
X	    }
X	}
X
X    c = *yy_c_buf_p;
X    yy_hold_char = *++yy_c_buf_p;
X
X    return ( c );
X    }
X
X
#ifdef YY_USE_PROTOS
void yyrestart( FILE *input_file )
#else
void yyrestart( input_file )
FILE *input_file;
#endif
X
X    {
X    yy_init_buffer( yy_current_buffer, input_file );
X    yy_load_buffer_state();
X    }
X
X
#ifdef YY_USE_PROTOS
void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
#else
void yy_switch_to_buffer( new_buffer )
YY_BUFFER_STATE new_buffer;
#endif
X
X    {
X    if ( yy_current_buffer == new_buffer )
X	return;
X
X    if ( yy_current_buffer )
X	{
X	/* flush out information for old buffer */
X	*yy_c_buf_p = yy_hold_char;
X	yy_current_buffer->yy_buf_pos = yy_c_buf_p;
X	yy_current_buffer->yy_n_chars = yy_n_chars;
X	}
X
X    yy_current_buffer = new_buffer;
X    yy_load_buffer_state();
X
X    /* we don't actually know whether we did this switch during
X     * EOF (yywrap()) processing, but the only time this flag
X     * is looked at is after yywrap() is called, so it's safe
X     * to go ahead and always set it.
X     */
X    yy_did_buffer_switch_on_eof = 1;
X    }
X
X
#ifdef YY_USE_PROTOS
void yy_load_buffer_state( void )
#else
void yy_load_buffer_state()
#endif
X
X    {
X    yy_n_chars = yy_current_buffer->yy_n_chars;
X    yytext = yy_c_buf_p = yy_current_buffer->yy_buf_pos;
X    yyin = yy_current_buffer->yy_input_file;
X    yy_hold_char = *yy_c_buf_p;
X    }
X
X
#ifdef YY_USE_PROTOS
YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
#else
YY_BUFFER_STATE yy_create_buffer( file, size )
FILE *file;
int size;
#endif
X
X    {
X    YY_BUFFER_STATE b;
X
X    b = (YY_BUFFER_STATE) malloc( sizeof( struct yy_buffer_state ) );
X
X    if ( ! b )
X	YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
X
X    b->yy_buf_size = size;
X
X    /* yy_ch_buf has to be 2 characters longer than the size given because
X     * we need to put in 2 end-of-buffer characters.
X     */
X    b->yy_ch_buf = (YY_CHAR *) malloc( (unsigned) (b->yy_buf_size + 2) );
X
X    if ( ! b->yy_ch_buf )
X	YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
X
X    yy_init_buffer( b, file );
X
X    return ( b );
X    }
X
X
#ifdef YY_USE_PROTOS
void yy_delete_buffer( YY_BUFFER_STATE b )
#else
void yy_delete_buffer( b )
YY_BUFFER_STATE b;
#endif
X
X    {
X    if ( b == yy_current_buffer )
X	yy_current_buffer = (YY_BUFFER_STATE) 0;
X
X    free( (char *) b->yy_ch_buf );
X    free( (char *) b );
X    }
X
X
#ifdef YY_USE_PROTOS
void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
#else
void yy_init_buffer( b, file )
YY_BUFFER_STATE b;
FILE *file;
#endif
X
X    {
X    b->yy_input_file = file;
X
X    /* we put in the '\n' and start reading from [1] so that an
X     * initial match-at-newline will be true.
X     */
X
X    b->yy_ch_buf[0] = '\n';
X    b->yy_n_chars = 1;
X
X    /* we always need two end-of-buffer characters.  The first causes
X     * a transition to the end-of-buffer state.  The second causes
X     * a jam in that state.
X     */
X    b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
X    b->yy_ch_buf[2] = YY_END_OF_BUFFER_CHAR;
X
X    b->yy_buf_pos = &b->yy_ch_buf[1];
X
X    b->yy_eof_status = EOF_NOT_SEEN;
X    }
# line 97 "t2mf.fl"
X
SHAR_EOF
chmod 0644 t2mflex.c ||
echo 'restore of t2mflex.c failed'
Wc_c="`wc -c < 't2mflex.c'`"
test 38341 -eq "$Wc_c" ||
	echo 't2mflex.c: original size 38341, current size' "$Wc_c"
fi
# ============= yyread.c ==============
if test -f 'yyread.c' -a X"$1" != X"-c"; then
	echo 'x - skipping yyread.c (File already exists)'
else
echo 'x - extracting yyread.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'yyread.c' &&
/* $Id: yyread.c,v 1.2 1991/11/03 21:53:20 piet Rel $ */
/* sozobon version */
X
#include <memory.h>
#include <string.h>
X
/*
X * read, ignoring CR's
X *
X *  ++jrb
X */
int _yyread(fd, buf, size)
int fd; char *buf; int size;
{
X    int count = read(fd, buf, size);
X    int done = 0, i;
X
X    if(count <= 0)
X	return count;
X
X    do{
X	for(i = done; i < (done+count); i++)
X	{
X	    if(buf[i] == '\r')
X	    {
X		if(i < done + count - 1)
X		  bcopy(&buf[i+1], &buf[i], (count -1 - (i - done)));
X		count -= 1;
X	    }
X	}
X	done += count;
X	if(done == size)
X	    return done;
X	count = read(fd, &buf[done], (size - done));
X    } while(count > 0);
X
X    return done;
}
X
SHAR_EOF
chmod 0644 yyread.c ||
echo 'restore of yyread.c failed'
Wc_c="`wc -c < 'yyread.c'`"
test 646 -eq "$Wc_c" ||
	echo 'yyread.c: original size 646, current size' "$Wc_c"
fi
exit 0
