#line 107 "output.nw"
/* this is the implementation of the Output class */

#include"output.h" /* include the own header */
#line 543 "output.nw"
#include<string.h>

#line 1035 "output.nw"
#include<stdlib.h>



#line 269 "output.nw"
char *Format_command_str[] =
    {
    "null",
    "indent",
    "outdent",
    "opt0",
    "opt1",
    "opt2",
    "opt3",
    "opt4",
    "opt5",
    "opt6",
    "opt7",
    "opt8",
    "opt9",
    "backup",
    "break_space",
    "force",
    "big_force",
    "no_indent",
    "cancel"
};


#line 815 "output.nw"
static
Format_command
delta[cancel+1][cancel+1] = {

/* this line is for the [[null]] command */
{null,   null,    null,
          null, null, null, null, null, null, null, null, null,
null,    null,    null,    null,    null,    null,    null},

/* now [[indent]]: */
{null,   null,    null,
          null, null, null, null, null, null, null, null, null,
null,    null,    null,    null,    null,    null,    null},

/* now [[outdent]]: */
{null,   null,    null,
          null, null, null, null, null, null, null, null, null,
null,    null,    null,    null,    null,    null,    null},

/* now [[opt0]]: */
{null,   null,    null,
          null, null, null, null, null, null, null, null, null,
null,    null,    null,    null,    null,    null,    cancel},

/* now [[opt1]]: */
{null,   null,    null,
          null, null, null, null, null, null, null, null, null,
null,    null,    null,    null,    null,    null,    cancel},

/* now [[opt2]]: */
{null,   null,    null,
          null, null, null, null, null, null, null, null, null,
null,    null,    null,    null,    null,    null,    cancel},

/* now [[opt3]]: */
{null,   null,    null,
          null, null, null, null, null, null, null, null, null,
null,    null,    null,    null,    null,    null,    cancel},

/* now [[opt4]]: */
{null,   null,    null,
          null, null, null, null, null, null, null, null, null,
null,    null,    null,    null,    null,    null,    cancel},

/* now [[opt5]]: */
{null,   null,    null,
          null, null, null, null, null, null, null, null, null,
null,    null,    null,    null,    null,    null,    cancel},

/* now [[opt6]]: */
{null,   null,    null,
          null, null, null, null, null, null, null, null, null,
null,    null,    null,    null,    null,    null,    cancel},

/* now [[opt7]]: */
{null,   null,    null,
          null, null, null, null, null, null, null, null, null,
null,    null,    null,    null,    null,    null,    cancel},

/* now [[opt8]]: */
{null,   null,    null,
          null, null, null, null, null, null, null, null, null,
null,    null,    null,    null,    null,    null,    cancel},

/* now [[opt9]]: */
{null,   null,    null,
          null, null, null, null, null, null, null, null, null,
null,    null,    null,    null,    null,    null,    cancel},

/* now [[backup]]: */
{null,   null,    null,
          null, null, null, null, null, null, null, null, null,
null,    null,    null,    null,    null,    null,    null},

/* now [[break_space]]: */
{null,   null,    null,
          null, null, null, null, null, null, null, null, null,
null,    null,break_space,force,big_force,null, cancel},

/* now [[force]]: */
{null,   null,    null,
          null, null, null, null, null, null, null, null, null,
null,    null,    force,   force,big_force,null,   cancel},

/* now [[big_force]]: */
{null,   null,    null,
          null, null, null, null, null, null, null, null, null,
null, null, big_force,big_force,big_force,null,  cancel},

/* now [[no_indent]]: */
{null,   null,    null,
          null, null, null, null, null, null, null, null, null,
null,    null,    null,    null,    null,    null,    null},

/* now [[cancel]]: */
{null,   null,    null,    cancel,
           cancel,cancel,cancel,cancel,cancel,cancel,cancel,cancel,
cancel,  cancel,  cancel,  cancel,  cancel, null,    null }

};


#line 531 "output.nw"
void
Output::debug_on(char *bs, char *es) {
    strncpy(begin_string,bs, max_debug_del_size);
    begin_string[max_debug_del_size] = '\0';
    strncpy(end_string,es, max_debug_del_size);
    end_string[max_debug_del_size] = '\0';
    debug_mode=yes;
}

#line 549 "output.nw"
void
Output::debug_off() {
    debug_mode=no;
}

#line 662 "output.nw"
Output::Output(ostream& ostr) : os (ostr)
{
    next_output_type=empty;
    debug_mode=no;
}

#line 696 "output.nw"
void Output::do_output(char *s)
{
        flush_output();
        os << s;
}
#line 733 "output.nw"
void Output::do_output(Format_command f)
{
        if (next_output_type==empty)
        {
                next_output_type=in_use;
                next_output=f;  /* take new command as lookahead */
                return;
        }
    /* now try if a rule can be applied */

#line 920 "output.nw"
if (delta[next_output][f]!=null)
{
    next_output=delta[next_output][f];
    return;
}


#line 744 "output.nw"
        flush_output();   /* otherwise output the lookahead and store [[f]] */
        next_output_type=in_use;
        next_output=f;
}

#line 932 "output.nw"
Output::~Output()
{
    // synonym for flush_output();
    // missing?! possibly in the subclasses!
}

#line 1000 "output.nw"
void Latex_cweb_output::flush_output()
{
        if (next_output_type==empty)
                return;
        /* otherwise: */

#line 517 "output.nw"
if (debug_mode==yes) {
    os  << begin_string << Format_command_str[next_output]
        << end_string;
}
#line 1018 "output.nw"
switch (next_output)
{

#line 1042 "output.nw"
case null: /* do nothing */ break;

#line 1048 "output.nw"
case indent: os << "\\pretzelindent{}"; break;
case outdent: os << "\\pretzeloutdent{}"; break;

#line 1056 "output.nw"
case opt0: os << "\\pretzelopt0{}"; break;
case opt1: os << "\\pretzelopt1{}"; break;
case opt2: os << "\\pretzelopt2{}"; break;
case opt3: os << "\\pretzelopt3{}"; break;
case opt4: os << "\\pretzelopt4{}"; break;
case opt5: os << "\\pretzelopt5{}"; break;
case opt6: os << "\\pretzelopt6{}"; break;
case opt7: os << "\\pretzelopt7{}"; break;
case opt8: os << "\\pretzelopt8{}"; break;
case opt9: os << "\\pretzelopt9{}"; break;

#line 1071 "output.nw"
case backup: os << "\\pretzelbackup{}"; break;

#line 1076 "output.nw"
case break_space: os << "\\pretzelbreakspace{}"; break;

#line 1081 "output.nw"
case force: os << "\\pretzelforce{}"; break;

#line 1086 "output.nw"
case big_force: os << "\\pretzelbigforce{}"; break;

#line 1091 "output.nw"
case no_indent: os << "\\pretzelnoindent{}"; break;

#line 1099 "output.nw"
case cancel: /* do nothing */ break;

#line 1021 "output.nw"
    default:
#line 1027 "output.nw"
cerr << endl
    << "Unknown format command detected! Something's wrong here." << endl
    << endl;
exit(EXIT_FAILURE);

#line 1021 "output.nw"
                                            break;
};

#line 1006 "output.nw"
        next_output_type=empty;
}

