Recovered from cvs revision 2007-08-24 13:17:00
This commit is contained in:
parent
a2c56938e7
commit
24b4d82eea
34
ase/awk/generrcode-net.awk
Normal file
34
ase/awk/generrcode-net.awk
Normal file
@ -0,0 +1,34 @@
|
||||
#
|
||||
# generrcode-net.awk
|
||||
#
|
||||
# aseawk -f generrcode-net.awk awk.h
|
||||
#
|
||||
|
||||
BEGIN {
|
||||
collect=0;
|
||||
tab3="\t\t";
|
||||
tab4="\t\t\t";
|
||||
}
|
||||
|
||||
/^[[:space:]]*enum[[:space:]]+ase_awk_errnum_t[[:space:]]*$/ {
|
||||
collect=1;
|
||||
print tab3 "// generated by generrcode-net.awk";
|
||||
print tab3 "enum class ERROR: int";
|
||||
print tab3 "{";
|
||||
}
|
||||
|
||||
collect && /^[[:space:]]*};[[:space:]]*$/ {
|
||||
print tab3 "};";
|
||||
print tab3 "// end of enum class ERROR";
|
||||
print "";
|
||||
collect=0;
|
||||
}
|
||||
|
||||
collect && /^[[:space:]]*ASE_AWK_E[[:alnum:]]+/ {
|
||||
split ($1, flds, ",");
|
||||
name=flds[1];
|
||||
|
||||
x = substr (name,10,length(name)-9);
|
||||
print tab4 x " = ASE::Awk::ERR_" x ",";
|
||||
}
|
||||
|
146
ase/net/Awk.cpp
146
ase/net/Awk.cpp
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.cpp,v 1.18 2007/08/21 14:24:37 bacon Exp $
|
||||
* $Id: Awk.cpp,v 1.21 2007/08/22 13:56:21 bacon Exp $
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
@ -9,14 +9,13 @@
|
||||
#include <ase/utl/stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <tchar.h>
|
||||
|
||||
#include <msclr/auto_gcroot.h>
|
||||
#include <msclr/gcroot.h>
|
||||
|
||||
using System::Runtime::InteropServices::GCHandle;
|
||||
|
||||
extern "C" void outputxxx (const wchar_t* x);
|
||||
|
||||
namespace ASE
|
||||
{
|
||||
|
||||
@ -61,6 +60,21 @@ namespace ASE
|
||||
this->wrapper = nullptr;
|
||||
}
|
||||
|
||||
const char_t* getErrorMessage (ASE::Net::Awk^ wrapper) const
|
||||
{
|
||||
this->wrapper = wrapper;
|
||||
const char_t* x = Awk::getErrorMessage();
|
||||
this->wrapper = nullptr;
|
||||
return x;
|
||||
}
|
||||
|
||||
void setError (ASE::Net::Awk^ wrapper)
|
||||
{
|
||||
this->wrapper = wrapper;
|
||||
//Awk::setError (code);
|
||||
this->wrapper = nullptr;
|
||||
}
|
||||
|
||||
int parse (ASE::Net::Awk^ wrapper)
|
||||
{
|
||||
this->wrapper = wrapper;
|
||||
@ -135,21 +149,32 @@ namespace ASE
|
||||
{
|
||||
if (wrapper->OnRunStart != nullptr)
|
||||
{
|
||||
wrapper->OnRunStart ();
|
||||
wrapper->OnRunStart (wrapper);
|
||||
}
|
||||
}
|
||||
void onRunEnd (const Run& run)
|
||||
{
|
||||
if (run.getErrorCode() != ERR_NOERR)
|
||||
{
|
||||
// TODO: SET THE ERROR CODE TO THIS AWK OBJECT...
|
||||
// TODO: set the error properly when an error is returned through this callback.
|
||||
// this callback should always be available....
|
||||
ASE::Awk::setError (run.getErrorCode(), run.getErrorLine());
|
||||
|
||||
// TODO: also make Run to return false in this case. Unlike normal c++ awk, this version of awk doesn't support multiple run instances.
|
||||
// wrapper->runFailureReported = true;
|
||||
}
|
||||
|
||||
if (wrapper->OnRunEnd != nullptr)
|
||||
{
|
||||
wrapper->OnRunEnd ();
|
||||
wrapper->OnRunEnd (wrapper);
|
||||
}
|
||||
}
|
||||
void onRunReturn (const Run& run, const Argument& ret)
|
||||
{
|
||||
if (wrapper->OnRunReturn != nullptr)
|
||||
{
|
||||
wrapper->OnRunReturn ();
|
||||
wrapper->OnRunReturn (wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,7 +182,7 @@ namespace ASE
|
||||
{
|
||||
if (wrapper->OnRunStatement != nullptr)
|
||||
{
|
||||
wrapper->OnRunStatement ();
|
||||
wrapper->OnRunStatement (wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
@ -563,6 +588,8 @@ namespace ASE
|
||||
//option = (OPTION)(awk->getOption (this) | MojoAwk::OPT_CRLF);
|
||||
option = (OPTION)(awk->getOption (this) | ASE::Awk::OPT_CRLF);
|
||||
awk->setOption (this, (int)option);
|
||||
|
||||
errorMsg = "";
|
||||
}
|
||||
|
||||
Awk::~Awk ()
|
||||
@ -595,6 +622,13 @@ System::Diagnostics::Debug::Print ("Awk::!Awk");
|
||||
}
|
||||
}
|
||||
|
||||
System::String^ Awk::ErrorMessage::get ()
|
||||
{
|
||||
if (awk != NULL)
|
||||
this->errorMsg = gcnew System::String(awk->getErrorMessage (this));
|
||||
return this->errorMsg;
|
||||
}
|
||||
|
||||
Awk::OPTION Awk::Option::get ()
|
||||
{
|
||||
if (awk != NULL) this->option = (OPTION)awk->getOption (this);
|
||||
@ -631,6 +665,11 @@ System::Diagnostics::Debug::Print ("Awk::!Awk");
|
||||
}
|
||||
|
||||
bool Awk::Run ()
|
||||
{
|
||||
return Run (nullptr, nullptr);
|
||||
}
|
||||
|
||||
bool Awk::Run (System::String^ entryPoint, cli::array<System::String^>^ args)
|
||||
{
|
||||
if (awk == NULL) return false;
|
||||
|
||||
@ -640,8 +679,95 @@ System::Diagnostics::Debug::Print ("Awk::!Awk");
|
||||
awk->enableRunCallback (this);
|
||||
}
|
||||
|
||||
if (args == nullptr || args->Length <= 0)
|
||||
{
|
||||
if (entryPoint == nullptr || entryPoint->Length <= 0)
|
||||
{
|
||||
return awk->run (this) == 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
cli::pin_ptr<const ASE::Awk::char_t> nptr = PtrToStringChars(entryPoint);
|
||||
return awk->run (this, nptr) == 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int nargs = args->Length;
|
||||
ASE::Awk::char_t** ptr = ASE_NULL;
|
||||
|
||||
try
|
||||
{
|
||||
bool r = false;
|
||||
|
||||
ptr = (ASE::Awk::char_t**)awk->allocMem (nargs * ASE_SIZEOF(ASE::Awk::char_t*));
|
||||
if (ptr == ASE_NULL)
|
||||
{
|
||||
// TODO: error handling
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < nargs; i++) ptr[i] = ASE_NULL;
|
||||
for (int i = 0; i < nargs; i++)
|
||||
{
|
||||
cli::pin_ptr<const ASE::Awk::char_t> nptr = PtrToStringChars (args[i]);
|
||||
ptr[i] = (ASE::Awk::char_t*)awk->allocMem ((args[i]->Length+1)*ASE_SIZEOF(ASE::Awk::char_t));
|
||||
if (ptr[i] == ASE_NULL)
|
||||
{
|
||||
r = false;
|
||||
goto exit_run;
|
||||
}
|
||||
memcpy (ptr[i], nptr, args[i]->Length*ASE_SIZEOF(ASE::Awk::char_t));
|
||||
ptr[i][args[i]->Length] = ASE_T('\0');
|
||||
}
|
||||
|
||||
if (entryPoint == nullptr || entryPoint->Length <= 0)
|
||||
{
|
||||
r = (awk->run (this, ASE_NULL, (const ASE::Awk::char_t**)ptr, nargs) == 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
cli::pin_ptr<const ASE::Awk::char_t> nptr = PtrToStringChars(entryPoint);
|
||||
r = (awk->run (this, nptr, (const ASE::Awk::char_t**)ptr, nargs) == 0);
|
||||
}
|
||||
|
||||
exit_run:
|
||||
if (ptr != ASE_NULL)
|
||||
{
|
||||
for (int i = 0; i < nargs; i++)
|
||||
{
|
||||
if (ptr[i] != ASE_NULL)
|
||||
{
|
||||
awk->freeMem (ptr[i]);
|
||||
ptr[i] = ASE_NULL;
|
||||
}
|
||||
}
|
||||
awk->freeMem (ptr);
|
||||
ptr = ASE_NULL;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
if (ptr != ASE_NULL)
|
||||
{
|
||||
for (int i = 0; i < nargs; i++)
|
||||
{
|
||||
if (ptr[i] != ASE_NULL)
|
||||
{
|
||||
awk->freeMem (ptr[i]);
|
||||
ptr[i] = ASE_NULL;
|
||||
}
|
||||
}
|
||||
awk->freeMem (ptr);
|
||||
ptr = ASE_NULL;
|
||||
}
|
||||
|
||||
// TODO: error...
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Awk::AddFunction (
|
||||
System::String^ name, int minArgs, int maxArgs,
|
||||
@ -715,6 +841,12 @@ System::Diagnostics::Debug::Print ("Awk::!Awk");
|
||||
return true;
|
||||
}
|
||||
|
||||
void Awk::SetError ()
|
||||
{
|
||||
if (awk == NULL) return;
|
||||
awk->setError (this);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
155
ase/net/Awk.hpp
155
ase/net/Awk.hpp
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.hpp,v 1.15 2007/08/21 14:24:37 bacon Exp $
|
||||
* $Id: Awk.hpp,v 1.18 2007/08/22 13:56:21 bacon Exp $
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
@ -328,6 +328,139 @@ namespace ASE
|
||||
REX_MATCH = ASE::Awk::DEPTH_REX_MATCH
|
||||
};
|
||||
|
||||
// generated by generrcode-net.awk
|
||||
enum class ERROR: int
|
||||
{
|
||||
NOERR = ASE::Awk::ERR_NOERR,
|
||||
INVAL = ASE::Awk::ERR_INVAL,
|
||||
NOMEM = ASE::Awk::ERR_NOMEM,
|
||||
NOSUP = ASE::Awk::ERR_NOSUP,
|
||||
NOPER = ASE::Awk::ERR_NOPER,
|
||||
NODEV = ASE::Awk::ERR_NODEV,
|
||||
NOSPC = ASE::Awk::ERR_NOSPC,
|
||||
MFILE = ASE::Awk::ERR_MFILE,
|
||||
MLINK = ASE::Awk::ERR_MLINK,
|
||||
AGAIN = ASE::Awk::ERR_AGAIN,
|
||||
NOENT = ASE::Awk::ERR_NOENT,
|
||||
EXIST = ASE::Awk::ERR_EXIST,
|
||||
FTBIG = ASE::Awk::ERR_FTBIG,
|
||||
TBUSY = ASE::Awk::ERR_TBUSY,
|
||||
ISDIR = ASE::Awk::ERR_ISDIR,
|
||||
IOERR = ASE::Awk::ERR_IOERR,
|
||||
OPEN = ASE::Awk::ERR_OPEN,
|
||||
READ = ASE::Awk::ERR_READ,
|
||||
WRITE = ASE::Awk::ERR_WRITE,
|
||||
CLOSE = ASE::Awk::ERR_CLOSE,
|
||||
INTERN = ASE::Awk::ERR_INTERN,
|
||||
RUNTIME = ASE::Awk::ERR_RUNTIME,
|
||||
BLKNST = ASE::Awk::ERR_BLKNST,
|
||||
EXPRNST = ASE::Awk::ERR_EXPRNST,
|
||||
SINOP = ASE::Awk::ERR_SINOP,
|
||||
SINCL = ASE::Awk::ERR_SINCL,
|
||||
SINRD = ASE::Awk::ERR_SINRD,
|
||||
SOUTOP = ASE::Awk::ERR_SOUTOP,
|
||||
SOUTCL = ASE::Awk::ERR_SOUTCL,
|
||||
SOUTWR = ASE::Awk::ERR_SOUTWR,
|
||||
LXCHR = ASE::Awk::ERR_LXCHR,
|
||||
LXDIG = ASE::Awk::ERR_LXDIG,
|
||||
LXUNG = ASE::Awk::ERR_LXUNG,
|
||||
ENDSRC = ASE::Awk::ERR_ENDSRC,
|
||||
ENDCMT = ASE::Awk::ERR_ENDCMT,
|
||||
ENDSTR = ASE::Awk::ERR_ENDSTR,
|
||||
ENDREX = ASE::Awk::ERR_ENDREX,
|
||||
LBRACE = ASE::Awk::ERR_LBRACE,
|
||||
LPAREN = ASE::Awk::ERR_LPAREN,
|
||||
RPAREN = ASE::Awk::ERR_RPAREN,
|
||||
RBRACK = ASE::Awk::ERR_RBRACK,
|
||||
COMMA = ASE::Awk::ERR_COMMA,
|
||||
SCOLON = ASE::Awk::ERR_SCOLON,
|
||||
COLON = ASE::Awk::ERR_COLON,
|
||||
STMEND = ASE::Awk::ERR_STMEND,
|
||||
IN = ASE::Awk::ERR_IN,
|
||||
NOTVAR = ASE::Awk::ERR_NOTVAR,
|
||||
EXPRES = ASE::Awk::ERR_EXPRES,
|
||||
WHILE = ASE::Awk::ERR_WHILE,
|
||||
ASSIGN = ASE::Awk::ERR_ASSIGN,
|
||||
IDENT = ASE::Awk::ERR_IDENT,
|
||||
FNNAME = ASE::Awk::ERR_FNNAME,
|
||||
BLKBEG = ASE::Awk::ERR_BLKBEG,
|
||||
BLKEND = ASE::Awk::ERR_BLKEND,
|
||||
DUPBEG = ASE::Awk::ERR_DUPBEG,
|
||||
DUPEND = ASE::Awk::ERR_DUPEND,
|
||||
BFNRED = ASE::Awk::ERR_BFNRED,
|
||||
AFNRED = ASE::Awk::ERR_AFNRED,
|
||||
GBLRED = ASE::Awk::ERR_GBLRED,
|
||||
PARRED = ASE::Awk::ERR_PARRED,
|
||||
DUPPAR = ASE::Awk::ERR_DUPPAR,
|
||||
DUPGBL = ASE::Awk::ERR_DUPGBL,
|
||||
DUPLCL = ASE::Awk::ERR_DUPLCL,
|
||||
BADPAR = ASE::Awk::ERR_BADPAR,
|
||||
BADVAR = ASE::Awk::ERR_BADVAR,
|
||||
UNDEF = ASE::Awk::ERR_UNDEF,
|
||||
LVALUE = ASE::Awk::ERR_LVALUE,
|
||||
GBLTM = ASE::Awk::ERR_GBLTM,
|
||||
LCLTM = ASE::Awk::ERR_LCLTM,
|
||||
PARTM = ASE::Awk::ERR_PARTM,
|
||||
DELETE = ASE::Awk::ERR_DELETE,
|
||||
BREAK = ASE::Awk::ERR_BREAK,
|
||||
CONTINUE = ASE::Awk::ERR_CONTINUE,
|
||||
NEXTBEG = ASE::Awk::ERR_NEXTBEG,
|
||||
NEXTEND = ASE::Awk::ERR_NEXTEND,
|
||||
NEXTFBEG = ASE::Awk::ERR_NEXTFBEG,
|
||||
NEXTFEND = ASE::Awk::ERR_NEXTFEND,
|
||||
PRINTFARG = ASE::Awk::ERR_PRINTFARG,
|
||||
PREPST = ASE::Awk::ERR_PREPST,
|
||||
GLNCPS = ASE::Awk::ERR_GLNCPS,
|
||||
DIVBY0 = ASE::Awk::ERR_DIVBY0,
|
||||
OPERAND = ASE::Awk::ERR_OPERAND,
|
||||
POSIDX = ASE::Awk::ERR_POSIDX,
|
||||
ARGTF = ASE::Awk::ERR_ARGTF,
|
||||
ARGTM = ASE::Awk::ERR_ARGTM,
|
||||
FNNONE = ASE::Awk::ERR_FNNONE,
|
||||
NOTIDX = ASE::Awk::ERR_NOTIDX,
|
||||
NOTDEL = ASE::Awk::ERR_NOTDEL,
|
||||
NOTMAP = ASE::Awk::ERR_NOTMAP,
|
||||
NOTMAPIN = ASE::Awk::ERR_NOTMAPIN,
|
||||
NOTMAPNILIN = ASE::Awk::ERR_NOTMAPNILIN,
|
||||
NOTREF = ASE::Awk::ERR_NOTREF,
|
||||
NOTASS = ASE::Awk::ERR_NOTASS,
|
||||
IDXVALASSMAP = ASE::Awk::ERR_IDXVALASSMAP,
|
||||
POSVALASSMAP = ASE::Awk::ERR_POSVALASSMAP,
|
||||
MAPTOSCALAR = ASE::Awk::ERR_MAPTOSCALAR,
|
||||
SCALARTOMAP = ASE::Awk::ERR_SCALARTOMAP,
|
||||
MAPNOTALLOWED = ASE::Awk::ERR_MAPNOTALLOWED,
|
||||
VALTYPE = ASE::Awk::ERR_VALTYPE,
|
||||
RDELETE = ASE::Awk::ERR_RDELETE,
|
||||
RNEXTBEG = ASE::Awk::ERR_RNEXTBEG,
|
||||
RNEXTEND = ASE::Awk::ERR_RNEXTEND,
|
||||
RNEXTFBEG = ASE::Awk::ERR_RNEXTFBEG,
|
||||
RNEXTFEND = ASE::Awk::ERR_RNEXTFEND,
|
||||
BFNUSER = ASE::Awk::ERR_BFNUSER,
|
||||
BFNIMPL = ASE::Awk::ERR_BFNIMPL,
|
||||
IOUSER = ASE::Awk::ERR_IOUSER,
|
||||
IONONE = ASE::Awk::ERR_IONONE,
|
||||
IOIMPL = ASE::Awk::ERR_IOIMPL,
|
||||
IONMEM = ASE::Awk::ERR_IONMEM,
|
||||
IONMNL = ASE::Awk::ERR_IONMNL,
|
||||
FMTARG = ASE::Awk::ERR_FMTARG,
|
||||
FMTCNV = ASE::Awk::ERR_FMTCNV,
|
||||
CONVFMTCHR = ASE::Awk::ERR_CONVFMTCHR,
|
||||
OFMTCHR = ASE::Awk::ERR_OFMTCHR,
|
||||
REXRECUR = ASE::Awk::ERR_REXRECUR,
|
||||
REXRPAREN = ASE::Awk::ERR_REXRPAREN,
|
||||
REXRBRACKET = ASE::Awk::ERR_REXRBRACKET,
|
||||
REXRBRACE = ASE::Awk::ERR_REXRBRACE,
|
||||
REXUNBALPAR = ASE::Awk::ERR_REXUNBALPAR,
|
||||
REXCOLON = ASE::Awk::ERR_REXCOLON,
|
||||
REXCRANGE = ASE::Awk::ERR_REXCRANGE,
|
||||
REXCCLASS = ASE::Awk::ERR_REXCCLASS,
|
||||
REXBRANGE = ASE::Awk::ERR_REXBRANGE,
|
||||
REXEND = ASE::Awk::ERR_REXEND,
|
||||
REXGARBAGE = ASE::Awk::ERR_REXGARBAGE
|
||||
};
|
||||
// end of enum class ERROR
|
||||
|
||||
|
||||
typedef ASE::Awk::char_t char_t;
|
||||
|
||||
Awk ();
|
||||
@ -337,18 +470,19 @@ namespace ASE
|
||||
virtual void Close ();
|
||||
virtual bool Parse ();
|
||||
virtual bool Run ();
|
||||
virtual bool Run (System::String^ entryPoint, cli::array<System::String^>^ args);
|
||||
|
||||
delegate void RunStartHandler ();
|
||||
delegate void RunEndHandler ();
|
||||
delegate void RunReturnHandler ();
|
||||
delegate void RunStatementHandler ();
|
||||
delegate void RunStartHandler (Awk^ awk);
|
||||
delegate void RunEndHandler (Awk^ awk);
|
||||
delegate void RunReturnHandler (Awk^ awk);
|
||||
delegate void RunStatementHandler (Awk^ awk);
|
||||
|
||||
/*event*/ RunStartHandler^ OnRunStart;
|
||||
/*event*/ RunEndHandler^ OnRunEnd;
|
||||
/*event*/ RunReturnHandler^ OnRunReturn;
|
||||
/*event*/ RunStatementHandler^ OnRunStatement;
|
||||
|
||||
delegate bool FunctionHandler (System::String^ name, array<Argument^>^ args, Return^ ret);
|
||||
delegate bool FunctionHandler (System::String^ name, cli::array<Argument^>^ args, Return^ ret);
|
||||
virtual bool AddFunction (System::String^ name, int minArgs, int maxArgs, FunctionHandler^ handler);
|
||||
virtual bool DeleteFunction (System::String^ name);
|
||||
|
||||
@ -365,10 +499,19 @@ namespace ASE
|
||||
void set (OPTION opt); //{ this->option = opt; }
|
||||
}
|
||||
|
||||
// TODO: Error code, Error line
|
||||
property System::String^ ErrorMessage
|
||||
{
|
||||
System::String^ get ();
|
||||
}
|
||||
|
||||
void SetError ();
|
||||
|
||||
protected:
|
||||
MojoAwk* awk;
|
||||
OPTION option;
|
||||
System::Collections::Hashtable^ funcs;
|
||||
System::String^ errorMsg;
|
||||
|
||||
public protected:
|
||||
// Source
|
||||
|
@ -23,11 +23,12 @@ namespace asetestnet
|
||||
|
||||
public bool Run(
|
||||
System.Windows.Forms.TextBox consoleInput,
|
||||
System.Windows.Forms.TextBox consoleOutput)
|
||||
System.Windows.Forms.TextBox consoleOutput,
|
||||
System.String main, System.String[] args)
|
||||
{
|
||||
this.consoleInput = consoleInput;
|
||||
this.consoleOutput = consoleOutput;
|
||||
return base.Run();
|
||||
return base.Run(main, args);
|
||||
}
|
||||
|
||||
protected override int OpenSource(ASE.Net.StdAwk.Source source)
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user