%{
/*************************** pn.l (lex+C file) ************************
This is the main code for a CGI script (called from
http://www.phmartin.infowf/pnml.html) that
converts the PNML output of PIPE to EPNML (the PNML accepted by
Woflan, see http://www.petriweb.org/specs/).
Created by "pm .@. phmartin dot info" on the 16/07/2004
Compilation outline: flex -Ppn -i pn.l
g++ -o pn.o -c lex.pn.c
g++ -o pn.cgi pn.o ldynStr.o
(ldynStr.cc is my implementation of dynamic strings)
***********************************************************/
#include
#include
#include
#include
#include
#include "ldynStr.h"
#define pr printf
#define ERR_HDR "CONTENT-TYPE: text/html\n\nError\n"
static int R; static char *Boundary, Attr[110], FileName[110];
static dynStr Val(110);
static int FD; static FILE *FP;
int prErrDoc (const char *format, ...);
static int prErr (const char *format, ...);
static int scpto (/*initP*/ char *s, const char *name);
static void rplSpaces ();
%}
ANY (.|\n)
QSTR1 '([^'\\]|(\\{ANY}))*'
QSTR2 \"([^"\\]|(\\{ANY}))*\"
QSTR ({QSTR1}|{QSTR2})
DUMMY (a|b)
S ([ \n\t\r ])+
s ([ \n\t\r ])*
IDENT1 ("#"?[A-Za-z0-9_¡-ÿ])
IDENTn ([A-Za-z0-9_/¡-ÿ\-.#@: ]|"\\".)
IDENT {IDENT1}{IDENTn}*
ID ([A-Za-z0-9_\- ]+)
NUM ([0-9A-Za-z]+)
BOUND ("--""-"*{NUM}{S}"Content-Disposition: form-data; name="\")
END_BOUND ("--""-"*{NUM}"--")
BOUNDofFILE ({BOUND}file\""; filename="\")
%x BOUND_NUM BOUND_SEP FILEN FILEC ATTR VAL SKARC SKIM0
%%
"Content-Type: multipart/form-data; " ;
{BOUNDofFILE} {if (strstr(pntext,Boundary)) BEGIN(FILEN);}
{IDENT}\"{s} {*(strrchr(pntext,'"'))='\0';
if(!(R=scpto(FileName,"File name")))return R;
BEGIN(FILEC);}
{BOUND} {yyless(0); BEGIN(0);}
"value>" {fputs("text>",stdout);}
"" {fputs("channel ",stdout);}
"" ;
""{s}"0" BEGIN(SKIM0);
"" BEGIN(FILEC);
. ;
"" {fputs("",stdout);}
"" {fputs("",stdout);}
"" {fputs("",stdout);}
""/>" BEGIN(FILEC);
. ;
" id="\"{ID} {rplSpaces(); fputs(pntext,stdout); /*"*/ }
"Content-Type: text/xml"{s} ;
\r\n {fputc(pntext[0],stdout);}
\n {fputc(pntext[0],stdout);}
. {fputc(pntext[0],stdout);}
{BOUND} {if (strstr(pntext,Boundary)) BEGIN(ATTR);}
{IDENT}\"{s} {*(strrchr(pntext,'"'))='\0'; Val.clear();
if(!(R=scpto(Attr,"Attribute")))return R; BEGIN(VAL);}
. {BEGIN(0); return prErr("Not an identifier: %s");}
{BOUND} {yyless(0); BEGIN(0);}
. {Val.append(pntext[0]);}
<*>{END_BOUND} {/*pr("\n\n");/}
{ANY} {/*pr(",%c",pntext[0]);*/}
%%
int prErrDoc (const char *format, ...)
{ va_list pArgs; va_start(pArgs,format); pr(ERR_HDR "Error. ");
vfprintf(stdout,format,pArgs); pr("\n