#######################################################################
# SGMLSPL script produced automatically by the script sgmlspl.pl
#
# Document Type: dtd (gellmu)
# Output Type: text/plain (SGML DTD)
# Author:  William F. Hammond <hammond@math.albany.edu>
# Begun:   19980925
# Last-revison: check the file system datestamp or the http header
#
########################################################################

use SGMLS;			# Use the SGMLS package.
use SGMLS::Output;		# Use stack-based output.

$doctype = "";
$dtdref = "";
@elt_arg = ();
$elt_argc = 0;
@enp_arg = ();
$enp_argc = 0;
@ent_arg = ();
$ent_argc = 0;
@empt_arg = ();
$empt_argc = 0;
@precmt = ();
$precn = 0;
$verb_on = 0;

# Document Handlers.

sgml('start', "");
sgml('end', "");

# Element Handlers.

# Element: dtd
sgml('<dtd>', "");
sgml('</dtd>', "\n");

# Element: preamble
sgml('<preamble>', sub{
    push_output('string');
});
sgml('</preamble>', sub{
    my $pos = pop_output;
    my $os = "";
    my $es = "";
    my $jj = 0;
# Write a comment <!-- Use <!DOCTYPE test SYSTEM \"ref.dtd\"> -->\n";
# where "test" is the value of $doctype
# and  "ref.dtd" is the value of $dtdref
# Then pull up any comments found in the preamble.
# There should be no output to pop.
    if($doctype eq ""){
	$es =  "This markup does not declare a DOCUMENT TYPE,\n";
	$es = $es . "i.e., there is no name declared for its root ELEMENT\n";
	die $es;
    }
    elsif($dtdref ne ""){
	$os = $os . "<!-- Use <!DOCTYPE " . $doctype
                  . " SYSTEM \"" . $dtdref . "\"> -->\n";
    }
    else{
	;
    };
    $jj = 1;
    while($jj <= $precn){
	$os = $os . $precmt[$jj] . "\n";
	$jj++;
    };
    output($os);
});

# Element: doctype
sgml('<doctype>', sub{
    push_output('string');
});
sgml('</doctype>', sub{
    $doctype = pop_output;
});

# Element: dtdref
sgml('<dtdref>', sub{
    push_output('string');
});
sgml('</dtdref>', sub{
    $dtdref = pop_output;
});


# Element: body
sgml('<body>', "");
sgml('</body>', "");

# Element: verb -- possibly headed for LaTeX "\verb+...+"
sgml('<verb>', sub{
    $verb_on = 1;
});
sgml('</verb>', sub{
    $verb_on = 0;
});

# Element: ag0 -- auto-generated command argument
sgml('<ag0>', sub{
    push_output('string');
    my $pan = $_[0]->parent->name;
    if($pan eq "elt"){
	;
    }
    elsif($pan eq "enp"){
	;
    }
    elsif($pan eq "ent"){
	;
    }
    elsif($pan eq "empt"){
	;
    }
    elsif($pan eq "cmt"){
	;
    }
    else{
	output("{*ELT " . $_[0]->name . " IN " . $pan);
    }
});
sgml('</ag0>', sub{
    my $pos = pop_output;
    my $os = "";
    my $pan = $_[0]->parent->name;
    if($pan eq "elt"){
	$elt_argc++;
	$elt_arg[$elt_argc] = $pos;
    }
    elsif($pan eq "enp"){
	$enp_argc++;
	$enp_arg[$enp_argc] = $pos;
    }
    elsif($pan eq "ent"){
	$ent_argc++;
	$ent_arg[$ent_argc] = $pos;
    }
    elsif($pan eq "empt"){
	$empt_argc++;
	$empt_arg[$empt_argc] = $pos;
    }
    elsif($pan eq "cmt"){
	$os = "<!-- ERROR: ELT cmt has no ag0; comment is in content -->\n";
	$os = $os . "<!-- Parent ELT is " . $pan . " -->\n";
	$os = $os . "<!-- " . $pos . " -->\n";
	output($os);
    }
    else{
	$os = $os . "<!-- ERROR:ELT " . $_[0]->name . " IN " . $pan . " -->\n";
	output($os);
    };
});

# Element: elt
sgml('<elt>',sub{
    $elt_argc = 0;
    push_output('string');
});
sgml('</elt>', sub{
# args: name, tags, defn, comment?
    my $name = "";
    my $pos = pop_output;
    my $os = "";
    my $es = "";
    my $jj = 0;
    my $reqarg = 3;
    my $itags = "";
    my $jtags = "";
    my $tags = "";
    if($elt_argc < $reqarg){
	$es = "<!-- Error: Number of args for elt -- " . $elt_argc .
              " is too small (" . $reqarg . ") -->\n";
	output($es);
    }
    else{
	$itags = $elt_arg[2];
	$jtags = $itags;
	$jtags =~ s/\s*//g;
        # Now check the correctness of the input tagging requirement
	if(($jtags eq "rr")||($jtags eq "RR")||($jtags eq "--")){
	    $tags = " - - ";
	}
	elsif(($jtags eq "ro")||($jtags eq "RO")||($jtags eq "-O")){
	    $tags = " - O ";
	}
	elsif(($jtags eq "or")||($jtags eq "OR")||($jtags eq "O-")){
	    $tags = " O - ";
	}
	elsif(($jtags eq "oo")||($jtags eq "OO")){
	    $tags = " O O ";
	}
	else{
	    $es = "<!-- ERROR in element \"" . $elt_arg[1] 
                  . "\" input tagging req. was " . $itags . " -->\n";
	    output($es);
	    $tags = " x x ";
	};
	$os = $os . "<!ELEMENT " . $elt_arg[1] . $tags . $elt_arg[3];
	$jj = $reqarg + 1;
	while($jj <= $elt_argc){
	    $os = $os . " -- " . $elt_arg[$jj] . " --";
	    $jj++;
	};
	$os = $os . ">\n";
	output($os);
    };
});

# Element: enp
sgml('<enp>',sub{
# args: name, defn, comment?
    $enp_argc = 0;
    push_output('string');
});
sgml('</enp>', sub{
    my $name = "enp";
    my $pos = pop_output;
    my $os = "";
    my $es = "";
    my $jj = 0;
    my $reqarg = 2;
    if($enp_argc < $reqarg){
	$es = "Error: Number of args for enp -- " . $enp_argc .
              " is too small (" . $reqarg . ")\n";
	output($es);
    }
    else{
	$os = $os . "<!ENTITY % " . $enp_arg[1] . " \"" . $enp_arg[2] . "\"";
	$jj = $reqarg + 1;
	while($jj <= $enp_argc){
	    $os = $os . " -- " . $enp_arg[$jj] . " --";
	    $jj++;
	};
	$os = $os . ">\n";
	output($os);
    }
});

# Element: ent
sgml('<ent>',sub{
    $ent_argc = 0;
    push_output('string');
});
sgml('</ent>', sub{
    my $name = "ent";
    my $pos = pop_output;
    my $os = "";
    my $es = "";
    my $jj = 0;
    my $reqarg = 2;
    if($ent_argc < $reqarg){
	$es = "Error: Number of args for ent -- " . $ent_argc .
              " is too small (" . $reqarg . ")\n";
	output($es);
    }
    else{
	$os = $os . "<!ENTITY " . $ent_arg[1] . " \"" . $ent_arg[2] . "\"";
	$jj = $reqarg + 1;
	while($jj <= $ent_argc){
	    $os = $os . " -- " . $ent_arg[$jj] . " --";
	    $jj++;
	};
	$os = $os . ">\n";
	output($os);
    };
});

# Element: empt
sgml('<empt>',sub{
    $empt_argc = 0;
    push_output('string');
});
sgml('</empt>', sub{
    my $name = "empt";
    my $pos = pop_output;
    my $os = "";
    my $es = "";
    my $jj = 0;
    my $reqarg = 1;
    if($empt_argc < $reqarg){
	$es = "Error: Number of args for empt -- " . $empt_argc .
              " is too small (" . $reqarg . ")\n";
	output($es);
    }
    else{
	$os = $os . "<!ELEMENT " . $empt_arg[1] . " - O EMPTY";
	$jj = $reqarg + 1;
	while($jj <= $empt_argc){
	    $os = $os . " -- " . $empt_arg[$jj] . " --";
	    $jj++;
	};
	$os = $os . ">\n";
	output($os);
    };
});

# Element: cmt
sgml('<cmt>', sub{
    $precn++;
    push_output('string');
});
sgml('</cmt>', sub{
    my $pos = pop_output;
    $precmt[$precn] = "<!-- " . $pos . " -->";
});

# Element: gx0 -- for bootstrapping new DTD tags
sgml('<gx0>',sub{
    $gx0_argc = 0;
    push_output('string');
});
sgml('</gx0>', sub{
    my $name = "gx0";
    my $pos = pop_output;
    my $os = "";
    my $es = "";
    my $jj = 0;
    my $reqarg = 0; # number of required <ag0>'s; check "boot.dtd"
    if($gx0_argc < $reqarg){
	$es = "<!-- Error: Number of args found for gx0 is " . $gx0_argc .
              ", which is too small (" . $reqarg . ") -->\n";
	output($es);
    };
    $os = $os . "<!";

    $os = $os . ">\n";
    output($os);
});

# Code for setting comments embedded in other declaration tags.
# (The design of "boot.dtd" is that any <ag0> beyond the required
# number is a comment.)

sub set_cmt{
    my $is = $_[0];
    my $os = " -- " . $is . "--";
    return($os);
};

#
# Default handlers (uncomment these if needed).  Right now, these are set
# up to gag on any unrecognised elements, sdata, processing-instructions,
# or entities.
#
sgml('start_element', sub{
    output("*ELT " . $_[0]->name . "*");
    push_output('string');
});
sgml('end_element',sub{
    my $os = pop_output;
    output($os . "**");
});
# sgml('cdata',sub {output("*CDATA* " . $_[0] . "**");});
sgml('sdata',sub { die "Unknown SDATA: " . $_[0]; });
# sgml('re',"\n");
sgml('pi',sub { die "Unknown processing instruction: " . $_[0]; });
sgml('entity',sub { die "Unknown external entity: " . $_[0]->name; });
sgml('start_subdoc',sub { die "Unknown subdoc entity: " . $_[0]->name; });
# sgml('end_subdoc','');
# sgml('conforming','');

# Element: eos -- end of sentence mark
sgml('<eos>', ". ");
sgml('</eos>', "");

# Element: eoq -- end of question mark
sgml('<eoq>', "? ");
sgml('</eoq>', "");

# Element: eoe -- end of exclamation mark
sgml('<eoe>', "! ");
sgml('</eoe>', "");

# Element: bsl -- abstract char "\"
sgml('<bsl>', "\\");
sgml('</bsl>', "");

# Element: lbr -- abstract char "{"
sgml('<lbr>', "{");
sgml('</lbr>', "");

# Element: rbr -- abstract char "}"
sgml('<rbr>', "}");
sgml('</rbr>', "");

# Element: lsb -- abstract char "["
sgml('<lsb>', "[");
sgml('</lsb>', "");

# Element: rsb -- abstract char "]"
sgml('<rsb>', "]");
sgml('</rsb>', "");

# Element: quo -- abstract char "\""
sgml('<quo>', '"');
sgml('</quo>', "");

# Element: sol -- abstract char "/"
sgml('<sol>', "/");
sgml('</sol>', "");

# Element: eqc -- abstract char "="
sgml('<eqc>', "=");
sgml('</eqc>', "");

# Element: spc -- ordinary blank (like LaTeX's "\ ")
sgml('<spc>', " ");  # no forcing
sgml('</spc>', "");

# Element: brk
sgml('<brk>', "\n");
sgml('</brk>', "");

# Element: exc
sgml('<exc>', "!");
sgml('</exc>', "");

# Element: atc
sgml('<atc>', "@");
sgml('</atc>', "");

# Element: hsh
sgml('<hsh>', "#");
sgml('</hsh>', "");

# Element: dol
sgml('<dol>', "\$");
sgml('</dol>', "");

# Element: pct
sgml('<pct>', "%");
sgml('</pct>', "");

# Element: crt
sgml('<crt>', "^");
sgml('</crt>', "");

# Element: amp
sgml('<amp>', sub{
    my $pan = $_[0]->parent->name;
    if(($pan eq "cmt")||($pan eq "verb")){
	output("&");
    }
    else{
	output("&amp;");
    };
});
sgml('</amp>', "");

# Element: ast
sgml('<ast>', "*");
sgml('</ast>', "");

# Element: und
sgml('<und>', "_");
sgml('</und>', "");

# Element: tld
sgml('<tld>', "~");
sgml('</tld>', "");

# Element: lsq
sgml('<lsq>', '`');
sgml('</lsq>', "");

# Element: rsq
sgml('<rsq>', "'");
sgml('</rsq>', "");

# Element: plu
sgml('<plu>', "+");
sgml('</plu>', "");

# Element: hyp -- abstract hyphen (deliberate, but could be "minus")
sgml('<hyp>', "-");
sgml('</hyp>', "");

# Element: lpr
sgml('<lpr>', "(");
sgml('</lpr>', "");

# Element: rpr
sgml('<rpr>', ")");
sgml('</rpr>', "");

# Element: ltc
sgml('<ltc>', sub{
    my $pan = $_[0]->parent->name;
    if(($pan eq "cmt")||($pan eq "verb")){
	output("<");
    }
    else{
	output("&lt;");
    };
});
sgml('</ltc>', "");

# Element: gtc
sgml('<gtc>', sub{
    my $pan = $_[0]->parent->name;
    if(($pan eq "cmt")||($pan eq "verb")){
	output(">");
    }
    else{
	output("&gt;");
    };
});
sgml('</gtc>', "");

# Element: vbr
sgml('<vbr>', "|");
sgml('</vbr>', "");

# Element: cln
sgml('<cln>', ":");
sgml('</cln>', "");

# Element: scl
sgml('<scl>', ";");
sgml('</scl>', "");

# Element: per
sgml('<per>', ".");
sgml('</per>', "");

# Element: cma
sgml('<cma>', ",");
sgml('</cma>', "");

# Element: qum
sgml('<qum>', "?");
sgml('</qum>', "");

# Element: rdash -- set in GELLMU input as "--", not allowed here
#          inasmuch as separate comments may be done with "\cmt"
#          and in-tag comments with extra arguments
sgml('<rdash>', sub{
    my $pan = $_[0]->parent->name;
    my $gpan = $_[0]->parent->parent->name;
    my $os = "";
    my $es = "ERROR: detected element \"rdash\", probably arising from\n";
# Note: the tagging requirement is the SECOND argument of an element,
#   but the argument sequence counter is only advanced with the closetag.
    if(($pan eq "ag0") && ($gpan eq "elt") && ($elt_argc == 1)){
	$os = "rr";
	output($os);
    }
    else{
	$es = $es . "the string \"--\" in GELLMU input for this DTD\n";
	$es = $es . "at a dangerous location with ancestry as follows.\n";
	$es = $es . "  Parent element: " . $pan . "\n";
	if ($pan eq "ag0"){
	    $es = $es . "    Arg. sequence: " . $elt_argc . "\n";
	}
	$es = $es . "Grandparent elt.: " . $gpan . "\n";
	my $element = shift;
	my $event = shift;
	my $line = $event->line;
	$es = $es . "   Error exit at input line " . $line . ".\n";
	die $es;
    };
});
sgml('</rdash>', "");

# Element: pdash -- set in GELLMU input as "---"; hazardous in a DTD.
sgml('<pdash>', sub{
    my $pan = $_[0]->parent->name;
    my $es = "ERROR: detected element \"pdash\", probably arising from\n";
    $es = $es . "the hazardous string \"---\" in GELLMU input for this DTD.\n";
    $es = $es . "  Parent element: " . $pan . "\n";
    my $element = shift;
    my $event = shift;
    my $line = $event->line;
    $es = $es . "   Error exit at input line " . $line . ".\n";
    die $es;
});
sgml('</pdash>', "");

1;
