#!/usr/bin/perl

use CGI;

$Query = new CGI;

$input = $Query->param('input');

print "Content-Type: text/html\n\n";

print "<html><title>Lumas 2 ABNF Converter</title><body><h1>Lumas 2 ABNF Converter</h1>\n";

$time = time();

if( $input ne '' && open( FOUT, ">in/in-$time-$$" ) ) {
	print FOUT $input;
	close FOUT;
	
	print "<h2>Your Compiler Results</h2>\n<pre>\n";
	
	print `./linlu2abnf in/in-$time-$$ in/in-$time-$$.abnf`;
	
	print "</pre><p><hr>\n";
	
	if( open( FIN, "in/in-$time-$$.abnf" ) ) {   # $? == 0 && 
		print "<h2>Your ABNF Results</h2>\n<pre>\n";
		while( <FIN> ) {
			$_ =~ s/&/&amp;/g;
			$_ =~ s/</&lt;/g;
			print;
		}
		close FIN;
		
		print "</pre><p><hr>\n";
	}
}

$s_input = $input;
$s_input =~ s/&/&amp;/g;
$s_input =~ s/</&lt;/g;

print << "(END_HTML)";
<h2>Enter Definition to Convert:</h2>
<center>
<form action=2abnf.cgi method=post>
<textarea name=input cols=80 rows=15>$s_input</textarea>
<br>
<input type=submit value='Convert...'>
</form>
</center>
<p>
<hr>
<h2>An Example</h2>
<pre>
lumas module com.tech-know-ware.my-example;
/*
An example Lumas definition
*/
import com.tech-know-ware.general as tkwg;

struct  my-example
{
    int &lt;0..255>    participant-id  as  ?;
    Action          action  as  ?;
    struct          my-addition[0..1] 
                            as new.tech-know-ware.com plugin
    {
            bool      tkw-app-capable  as  ?;
    };
};

union  Action
{
    Join            join;
    Message         message  as  msg;
    void            leave;
};

struct  Join
{
    unicode&lt;0..63>  name;
};

struct  Message
{
    int &lt;0..255>    to-participants[1..127]  as  to;
    unicode&lt;1..255> message  as  msg;
    [               // Version 5 additions
    ascii&lt;0..16>    font-name[0..1] as font;
    void            bold[0..1];
    void            italic[0..1];
    void            underlined[0..1] as ul;
    ]
};
</pre>
<p>
<a href='./'>[To Lumas Homepage]</a>
(END_HTML)


print "</body></html>\n";
