This commit is contained in:
2008-06-04 02:18:55 +00:00
parent 5786cae59c
commit 8179c37c29
105 changed files with 0 additions and 0 deletions

80
ase/lib/awk/Argument.java Normal file
View File

@ -0,0 +1,80 @@
/*
* $Id: Argument.java 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
package ase.awk;
public class Argument implements Clearable
{
protected long runid;
//protected long valid;
public long valid;
/* An instance of the Argument class should not be used
* outside the context where it is availble. When it is
* referenced that way, the getXXX methods may cause
* JVM to crash */
Argument (Context ctx, long runid, long valid)
{
if (ctx != null) ctx.pushClearable (this);
this.runid = runid;
this.valid = valid;
}
Argument (long runid, long valid)
{
this (null, runid, valid);
}
public void clear ()
{
clearval (this.runid, this.valid);
}
public long getIntValue ()
{
if (this.valid == 0) return 0;
return getintval (this.runid, this.valid);
}
public double getRealValue ()
{
if (this.valid == 0) return 0.0;
return getrealval (this.runid, this.valid);
}
public String getStringValue () throws Exception
{
if (this.valid == 0) return "";
return getstrval (this.runid, this.valid);
}
public boolean isIndexed ()
{
if (this.valid == 0) return false;
return isindexed (this.runid, this.valid);
}
public Argument getIndexed (String idx) throws Exception
{
if (this.valid == 0) return null;
return getindexed (this.runid, this.valid, idx);
}
public Argument getIndexed (long idx) throws Exception
{
if (this.valid == 0) return null;
return getIndexed (Long.toString(idx));
}
protected native long getintval (long runid, long valid);
protected native double getrealval (long runid, long valid);
protected native String getstrval (long runid, long valid) throws Exception;
protected native boolean isindexed (long runid, long valid);
protected native Argument getindexed (long runid, long valid, String idx) throws Exception;
protected native void clearval (long runid, long valid);
}

1837
ase/lib/awk/Awk.cpp Normal file

File diff suppressed because it is too large Load Diff

1109
ase/lib/awk/Awk.hpp Normal file

File diff suppressed because it is too large Load Diff

459
ase/lib/awk/Awk.java Normal file
View File

@ -0,0 +1,459 @@
/*
* $Id: Awk.java 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
package ase.awk;
import java.io.*;
import java.util.HashMap;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
/**
* Represents the AWK interpreter engine
*/
public abstract class Awk
{
private HashMap functionTable;
// mode for open_source & close_source
public static final int SOURCE_READ = 1;
public static final int SOURCE_WRITE = 2;
// depth id
public static final int DEPTH_BLOCK_PARSE = (1 << 0);
public static final int DEPTH_BLOCK_RUN = (1 << 1);
public static final int DEPTH_EXPR_PARSE = (1 << 2);
public static final int DEPTH_EXPR_RUN = (1 << 3);
public static final int DEPTH_REX_BUILD = (1 << 4);
public static final int DEPTH_REX_MATCH = (1 << 5);
// options
public static final int OPTION_IMPLICIT = (1 << 0);
public static final int OPTION_EXPLICIT = (1 << 1);
public static final int OPTION_SHIFT = (1 << 4);
public static final int OPTION_IDIV = (1 << 5);
public static final int OPTION_STRCONCAT = (1 << 6);
public static final int OPTION_EXTIO = (1 << 7);
public static final int OPTION_COPROC = (1 << 8);
public static final int OPTION_BLOCKLESS = (1 << 9);
public static final int OPTION_BASEONE = (1 << 10);
public static final int OPTION_STRIPSPACES = (1 << 11);
public static final int OPTION_NEXTOFILE = (1 << 12);
public static final int OPTION_CRLF = (1 << 13);
public static final int OPTION_ARGSTOMAIN = (1 << 14);
public static final int OPTION_RESET = (1 << 15);
public static final int OPTION_MAPTOVAR = (1 << 16);
public static final int OPTION_PABLOCK = (1 << 17);
protected final static Reader stdin = new BufferedReader (new InputStreamReader (System.in));
protected final static Writer stdout = new BufferedWriter (new OutputStreamWriter (System.out));
private long awkid;
public Awk () throws Exception
{
this.awkid = 0;
this.functionTable = new HashMap ();
open ();
}
/* == just in case == */
protected void finalize () throws Throwable
{
close ();
super.finalize ();
}
public void close ()
{
if (this.awkid != 0)
{
close (this.awkid);
this.awkid = 0;
}
}
/**
* Parse a source program
*/
public void parse () throws Exception
{
parse (this.awkid);
}
/**
* Executes a parsed program
*/
public void run (String main, String[] args) throws Exception
{
run (this.awkid, main, args);
}
/**
* Executes a parsed program
*/
public void run (String main) throws Exception
{
run (this.awkid, main, null);
}
/**
* Executes a parsed program
*/
public void run (String[] args) throws Exception
{
run (this.awkid, null, args);
}
/**
* Executes a parsed program
*/
public void run () throws Exception
{
run (this.awkid, null, null);
}
/**
* Makes a request to stop a running program
*/
public void stop () throws Exception
{
stop (this.awkid);
}
/* == native methods == */
private native void open () throws Exception;
protected native void close (long awkid);
protected native void parse (long awkid) throws Exception;
protected native void run (long awkid, String main, String[] args) throws Exception;
protected native void stop (long awkid) throws Exception;
protected native int getmaxdepth (long awkid, int id) throws Exception;
protected native void setmaxdepth (long awkid, int id, int depth) throws Exception;
protected native int getoption (long awkid) throws Exception;
protected native void setoption (long awkid, int opt) throws Exception;
protected native boolean getdebug (long awkid) throws Exception;
protected native void setdebug (long awkid, boolean debug) throws Exception;
protected native String getword (long awkid, String ow) throws Exception;
protected native void setword (long awkid, String ow, String nw) throws Exception;
protected native void addfunc (String name, int min_args, int max_args) throws Exception;
protected native void delfunc (String name) throws Exception;
native void setfilename (long runid, String name) throws Exception;
native void setofilename (long runid, String name) throws Exception;
protected native String strftime (String fmt, long sec);
protected native String strfgmtime (String fmt, long sec);
protected native int system (String cmd);
/* == intrinsic functions == */
public void addFunction (String name, int min_args, int max_args) throws Exception
{
addFunction (name, min_args, max_args, name);
}
public void addFunction (String name, int min_args, int max_args, String method) throws Exception
{
if (functionTable.containsKey (name))
{
throw new Exception (
"cannot add existing function '" + name + "'",
Exception.EXIST);
}
functionTable.put (name, method);
try { addfunc (name, min_args, max_args); }
catch (Exception e)
{
functionTable.remove (name);
throw e;
}
}
public void deleteFunction (String name) throws Exception
{
delfunc (name);
functionTable.remove (name);
}
protected void handleFunction (
Context ctx, String name, Return ret, Argument[] args) throws Exception
{
String mn = (String)functionTable.get(name);
// name should always be found in this table.
// otherwise, there is something wrong with this program.
Class c = this.getClass ();
Class[] a = { Context.class, String.class, Return.class, Argument[].class };
try
{
Method m = c.getMethod (mn, a);
//m.invoke (this, ctx, name, ret, args) ;
m.invoke (this, new Object[] {ctx, name, ret, args});
}
catch (java.lang.reflect.InvocationTargetException e)
{
/* the underlying method has throw an exception */
Throwable t = e.getCause();
if (t == null)
{
throw new Exception (null, Exception.BFNIMPL);
}
else if (t instanceof Exception)
{
throw (Exception)t;
}
else
{
throw new Exception (
t.getMessage(), Exception.BFNIMPL);
}
}
catch (java.lang.Exception e)
{
throw new Exception (e.getMessage(), Exception.BFNIMPL);
}
}
/* == depth limiting == */
public int getMaxDepth (int id) throws Exception
{
return getmaxdepth (this.awkid, id);
}
public void setMaxDepth (int ids, int depth) throws Exception
{
setmaxdepth (this.awkid, ids, depth);
}
/* == option == */
public int getOption () throws Exception
{
return getoption (this.awkid);
}
public void setOption (int opt) throws Exception
{
setoption (this.awkid, opt);
}
/* == debug == */
public boolean getDebug () throws Exception
{
return getdebug (this.awkid);
}
public void setDebug (boolean debug) throws Exception
{
setdebug (this.awkid, debug);
}
/* == word replacement == */
public String getWord (String ow) throws Exception
{
return getword (this.awkid, ow);
}
public void setWord (String ow, String nw) throws Exception
{
setword (this.awkid, ow, nw);
}
public void unsetWord (String ow) throws Exception
{
setword (this.awkid, ow, null);
}
public void unsetAllWords () throws Exception
{
setword (this.awkid, null, null);
}
/* == source code management == */
protected abstract int openSource (int mode);
protected abstract int closeSource (int mode);
protected abstract int readSource (char[] buf, int len);
protected abstract int writeSource (char[] buf, int len);
/* == external io interface == */
protected int openExtio (Extio extio)
{
switch (extio.getType())
{
case Extio.TYPE_CONSOLE:
{
Console con = new Console (this, extio);
int n = openConsole (con);
extio.setHandle (con);
return n;
}
case Extio.TYPE_FILE:
{
File file = new File (this, extio);
int n = openFile (file);
extio.setHandle (file);
return n;
}
case Extio.TYPE_PIPE:
{
Pipe pipe = new Pipe (this, extio);
int n = openPipe (pipe);
extio.setHandle (pipe);
return n;
}
}
return -1;
}
protected int closeExtio (Extio extio)
{
switch (extio.getType())
{
case Extio.TYPE_CONSOLE:
return closeConsole (
(Console)extio.getHandle());
case Extio.TYPE_FILE:
return closeFile ((File)extio.getHandle());
case Extio.TYPE_PIPE:
return closePipe ((Pipe)extio.getHandle());
}
return -1;
}
protected int readExtio (Extio extio, char[] buf, int len)
{
// this check is needed because 0 is used to indicate
// the end of the stream. java streams can return 0
// if the data given is 0 bytes and it didn't reach
// the end of the stream.
if (len <= 0) return -1;
switch (extio.getType())
{
case Extio.TYPE_CONSOLE:
{
return readConsole (
(Console)extio.getHandle(), buf, len);
}
case Extio.TYPE_FILE:
{
return readFile (
(File)extio.getHandle(), buf, len);
}
case Extio.TYPE_PIPE:
{
return readPipe (
(Pipe)extio.getHandle(), buf, len);
}
}
return -1;
}
protected int writeExtio (Extio extio, char[] buf, int len)
{
if (len <= 0) return -1;
switch (extio.getType())
{
case Extio.TYPE_CONSOLE:
{
return writeConsole (
(Console)extio.getHandle(), buf, len);
}
case Extio.TYPE_FILE:
{
return writeFile (
(File)extio.getHandle(), buf, len);
}
case Extio.TYPE_PIPE:
{
return writePipe (
(Pipe)extio.getHandle(), buf, len);
}
}
return -1;
}
protected int flushExtio (Extio extio)
{
switch (extio.getType())
{
case Extio.TYPE_CONSOLE:
{
return flushConsole ((Console)extio.getHandle());
}
case Extio.TYPE_FILE:
{
return flushFile ((File)extio.getHandle());
}
case Extio.TYPE_PIPE:
{
return flushPipe ((Pipe)extio.getHandle());
}
}
return -1;
}
protected int nextExtio (Extio extio)
{
int type = extio.getType ();
switch (extio.getType())
{
case Extio.TYPE_CONSOLE:
{
return nextConsole ((Console)extio.getHandle());
}
}
return -1;
}
protected abstract int openConsole (Console con);
protected abstract int closeConsole (Console con);
protected abstract int readConsole (Console con, char[] buf, int len);
protected abstract int writeConsole (Console con, char[] buf, int len);
protected abstract int flushConsole (Console con);
protected abstract int nextConsole (Console con);
protected abstract int openFile (File file);
protected abstract int closeFile (File file);
protected abstract int readFile (File file, char[] buf, int len);
protected abstract int writeFile (File file, char[] buf, int len);
protected abstract int flushFile (File file);
protected abstract int openPipe (Pipe pipe);
protected abstract int closePipe (Pipe pipe);
protected abstract int readPipe (Pipe pipe, char[] buf, int len);
protected abstract int writePipe (Pipe pipe, char[] buf, int len);
protected abstract int flushPipe (Pipe pipe);
/* TODO: ...
protected void onRunStart (Context ctx) {}
protected void onRunEnd (Context ctx) {}
protected void onRunReturn (Context ctx) {}
protected void onRunStatement (Context ctx) {}
*/
}

View File

@ -0,0 +1,13 @@
/*
* $Id: Clearable.java 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
package ase.awk;
public interface Clearable
{
public void clear ();
}

30
ase/lib/awk/Console.java Normal file
View File

@ -0,0 +1,30 @@
/*
* $Id: Console.java 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
package ase.awk;
public class Console extends IO
{
public static final int MODE_READ = Extio.MODE_CONSOLE_READ;
public static final int MODE_WRITE = Extio.MODE_CONSOLE_WRITE;
protected Console (Awk awk, Extio extio)
{
super (awk, extio);
}
public void setFileName (String name) throws Exception
{
if (getMode() == MODE_READ)
{
awk.setfilename (getRunId(), name);
}
else
{
awk.setofilename (getRunId(), name);
}
}
}

115
ase/lib/awk/Context.java Normal file
View File

@ -0,0 +1,115 @@
/*
* $Id: Context.java 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
package ase.awk;
import java.util.Stack;
public class Context
{
public static int GLOBAL_ARGC = 0;
public static int GLOBAL_ARGV = 1;
public static int GLOBAL_CONVFMT = 2;
public static int GLOBAL_FILENAME = 3;
public static int GLOBAL_FNR = 4;
public static int GLOBAL_FS = 5;
public static int GLOBAL_IGNORECASE = 6;
public static int GLOBAL_NF = 7;
public static int GLOBAL_NR = 8;
public static int GLOBAL_OFILENAME = 9;
public static int GLOBAL_OFMT = 10;
public static int GLOBAL_OFS = 11;
public static int GLOBAL_ORS = 12;
public static int GLOBAL_RLENGTH = 13;
public static int GLOBAL_RS = 14;
public static int GLOBAL_RSTART = 15;
public static int GLOBAL_SUBSEP = 16;
protected Awk awk;
protected long runid;
protected Object custom;
protected Stack clearableStack;
Context (Awk awk)
{
this.awk = awk;
this.runid = 0;
this.custom = null;
this.clearableStack = new Stack ();
}
void clear ()
{
Clearable obj;
while ((obj = popClearable()) != null) obj.clear ();
}
void pushClearable (Clearable obj)
{
clearableStack.push (obj);
}
Clearable popClearable ()
{
if (clearableStack.empty()) return null;
return (Clearable)clearableStack.pop ();
}
public Awk getAwk ()
{
return awk;
}
public long getId ()
{
return this.runid;
}
public void setCustom (Object custom)
{
this.custom = custom;
}
public Object getCustom ()
{
return this.custom;
}
public void setConsoleInputName (String name) throws Exception
{
awk.setfilename (this.runid, name);
}
public void setConsoleOutputName (String name) throws Exception
{
awk.setofilename (this.runid, name);
}
public void stop ()
{
stop (this.runid);
}
public void setGlobal (int id, Return ret) throws Exception
{
// regardless of the result, the value field
// of the return object is reset to 0 by setglobal.
setglobal (this.runid, id, ret);
}
public Argument getGlobal (int id) throws Exception
{
return getglobal (this.runid, id);
}
protected native void stop (long runid);
protected native void setglobal (long runid, int id, Return ret);
protected native Argument getglobal (long runid, int id);
// TODO:
// setError
// getError
}

184
ase/lib/awk/Exception.java Normal file
View File

@ -0,0 +1,184 @@
/*
* $Id: Exception.java 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
package ase.awk;
public class Exception extends java.lang.Exception
{
private int code;
private int line;
// generated by generrcode-java.awk
public static final int NOERR = 0;
public static final int CUSTOM = 1;
public static final int INVAL = 2;
public static final int NOMEM = 3;
public static final int NOSUP = 4;
public static final int NOPER = 5;
public static final int NODEV = 6;
public static final int NOSPC = 7;
public static final int MFILE = 8;
public static final int MLINK = 9;
public static final int AGAIN = 10;
public static final int NOENT = 11;
public static final int EXIST = 12;
public static final int FTBIG = 13;
public static final int TBUSY = 14;
public static final int ISDIR = 15;
public static final int IOERR = 16;
public static final int OPEN = 17;
public static final int READ = 18;
public static final int WRITE = 19;
public static final int CLOSE = 20;
public static final int INTERN = 21;
public static final int RUNTIME = 22;
public static final int BLKNST = 23;
public static final int EXPRNST = 24;
public static final int SINOP = 25;
public static final int SINCL = 26;
public static final int SINRD = 27;
public static final int SOUTOP = 28;
public static final int SOUTCL = 29;
public static final int SOUTWR = 30;
public static final int LXCHR = 31;
public static final int LXDIG = 32;
public static final int LXUNG = 33;
public static final int ENDSRC = 34;
public static final int ENDCMT = 35;
public static final int ENDSTR = 36;
public static final int ENDREX = 37;
public static final int LBRACE = 38;
public static final int LPAREN = 39;
public static final int RPAREN = 40;
public static final int RBRACK = 41;
public static final int COMMA = 42;
public static final int SCOLON = 43;
public static final int COLON = 44;
public static final int STMEND = 45;
public static final int IN = 46;
public static final int NOTVAR = 47;
public static final int EXPRES = 48;
public static final int FUNC = 49;
public static final int WHILE = 50;
public static final int ASSIGN = 51;
public static final int IDENT = 52;
public static final int FNNAME = 53;
public static final int BLKBEG = 54;
public static final int BLKEND = 55;
public static final int DUPBEG = 56;
public static final int DUPEND = 57;
public static final int BFNRED = 58;
public static final int AFNRED = 59;
public static final int GBLRED = 60;
public static final int PARRED = 61;
public static final int DUPPAR = 62;
public static final int DUPGBL = 63;
public static final int DUPLCL = 64;
public static final int BADPAR = 65;
public static final int BADVAR = 66;
public static final int UNDEF = 67;
public static final int LVALUE = 68;
public static final int GBLTM = 69;
public static final int LCLTM = 70;
public static final int PARTM = 71;
public static final int DELETE = 72;
public static final int RESET = 73;
public static final int BREAK = 74;
public static final int CONTINUE = 75;
public static final int NEXTBEG = 76;
public static final int NEXTEND = 77;
public static final int NEXTFBEG = 78;
public static final int NEXTFEND = 79;
public static final int PRINTFARG = 80;
public static final int PREPST = 81;
public static final int GLNCPS = 82;
public static final int DIVBY0 = 83;
public static final int OPERAND = 84;
public static final int POSIDX = 85;
public static final int ARGTF = 86;
public static final int ARGTM = 87;
public static final int FNNONE = 88;
public static final int NOTIDX = 89;
public static final int NOTDEL = 90;
public static final int NOTMAP = 91;
public static final int NOTMAPIN = 92;
public static final int NOTMAPNILIN = 93;
public static final int NOTREF = 94;
public static final int NOTASS = 95;
public static final int IDXVALASSMAP = 96;
public static final int POSVALASSMAP = 97;
public static final int MAPTOSCALAR = 98;
public static final int SCALARTOMAP = 99;
public static final int MAPNOTALLOWED = 100;
public static final int VALTYPE = 101;
public static final int RDELETE = 102;
public static final int RRESET = 103;
public static final int RNEXTBEG = 104;
public static final int RNEXTEND = 105;
public static final int RNEXTFBEG = 106;
public static final int RNEXTFEND = 107;
public static final int BFNUSER = 108;
public static final int BFNIMPL = 109;
public static final int IOUSER = 110;
public static final int IONONE = 111;
public static final int IOIMPL = 112;
public static final int IONMEM = 113;
public static final int IONMNL = 114;
public static final int FMTARG = 115;
public static final int FMTCNV = 116;
public static final int CONVFMTCHR = 117;
public static final int OFMTCHR = 118;
public static final int REXRECUR = 119;
public static final int REXRPAREN = 120;
public static final int REXRBRACKET = 121;
public static final int REXRBRACE = 122;
public static final int REXUNBALPAR = 123;
public static final int REXCOLON = 124;
public static final int REXCRANGE = 125;
public static final int REXCCLASS = 126;
public static final int REXBRANGE = 127;
public static final int REXEND = 128;
public static final int REXGARBAGE = 129;
// end of error codes
public Exception ()
{
super ();
this.code = NOERR;
this.line = 0;
}
public Exception (String msg)
{
super (msg);
this.code = CUSTOM;
this.line = 0;
}
public Exception (String msg, int code)
{
super (msg);
this.code = code;
this.line = 0;
}
public Exception (String msg, int code, int line)
{
super (msg);
this.code = code;
this.line = line;
}
public int getCode ()
{
return this.code;
}
public int getLine ()
{
return this.line;
}
}

80
ase/lib/awk/Extio.java Normal file
View File

@ -0,0 +1,80 @@
/*
* $Id: Extio.java 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
package ase.awk;
public class Extio
{
protected static final int TYPE_PIPE = 0;
protected static final int TYPE_COPROC = 1;
protected static final int TYPE_FILE = 2;
protected static final int TYPE_CONSOLE = 3;
/* PROBLEMS WITH GCJ 3.4.6 if these fields are protected.
*
protected static final int MODE_PIPE_READ = 0;
protected static final int MODE_PIPE_WRITE = 1;
protected static final int MODE_FILE_READ = 0;
protected static final int MODE_FILE_WRITE = 1;
protected static final int MODE_FILE_APPEND = 2;
protected static final int MODE_CONSOLE_READ = 0;
protected static final int MODE_CONSOLE_WRITE = 1;
*/
public static final int MODE_PIPE_READ = 0;
public static final int MODE_PIPE_WRITE = 1;
public static final int MODE_FILE_READ = 0;
public static final int MODE_FILE_WRITE = 1;
public static final int MODE_FILE_APPEND = 2;
public static final int MODE_CONSOLE_READ = 0;
public static final int MODE_CONSOLE_WRITE = 1;
private String name;
private int type;
private int mode;
private long run_id;
private Object handle;
protected Extio (String name, int type, int mode, long run_id)
{
this.name = name;
this.type = type;
this.mode = mode;
this.run_id = run_id;
this.handle = null;
}
public String getName ()
{
return this.name;
}
public int getType ()
{
return this.type;
}
public int getMode ()
{
return this.mode;
}
public long getRunId ()
{
return this.run_id;
}
public void setHandle (Object handle)
{
this.handle = handle;
}
public Object getHandle ()
{
return this.handle;
}
};

20
ase/lib/awk/File.java Normal file
View File

@ -0,0 +1,20 @@
/*
* $Id: File.java 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
package ase.awk;
public class File extends IO
{
public static final int MODE_READ = Extio.MODE_FILE_READ;
public static final int MODE_WRITE = Extio.MODE_FILE_WRITE;
public static final int MODE_APPEND = Extio.MODE_FILE_APPEND;
protected File (Awk awk, Extio extio)
{
super (awk, extio);
}
}

46
ase/lib/awk/IO.java Normal file
View File

@ -0,0 +1,46 @@
/*
* $Id: IO.java 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
package ase.awk;
class IO
{
protected Awk awk;
protected Extio extio;
protected Object handle;
protected IO (Awk awk, Extio extio)
{
this.awk = awk;
this.extio = extio;
}
public String getName ()
{
return extio.getName();
}
public int getMode ()
{
return extio.getMode();
}
public long getRunId ()
{
return extio.getRunId();
}
public void setHandle (Object handle)
{
this.handle = handle;
}
public Object getHandle ()
{
return handle;
}
}

18
ase/lib/awk/Pipe.java Normal file
View File

@ -0,0 +1,18 @@
/*
* $Id: Pipe.java 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
package ase.awk;
public class Pipe extends IO
{
public static final int MODE_READ = Extio.MODE_PIPE_READ;
public static final int MODE_WRITE = Extio.MODE_PIPE_WRITE;
protected Pipe (Awk awk, Extio extio)
{
super (awk, extio);
}
}

184
ase/lib/awk/Return.java Normal file
View File

@ -0,0 +1,184 @@
/*
* $Id: Return.java 115 2008-03-03 11:13:15Z baconevi $
*
* ${License}
*/
package ase.awk;
public class Return implements Clearable
{
protected long runid;
protected long valid;
/* An instance of the Return class should not be used
* outside the context where it is availble. When it is
* referenced that way, the setXXX methods may cause
* JVM to crash */
public Return (Context ctx)
{
ctx.pushClearable (this);
this.runid = ctx.getId();
this.valid = 0;
}
Return (long runid, long valid)
{
this.runid = runid;
this.valid = valid;
}
public boolean isIndexed ()
{
if (this.runid == 0) return false;
return isindexed (this.runid, this.valid);
}
public void setIntValue (long v)
{
if (this.runid == 0) return;
setintval (this.runid, this.valid, v);
}
public void setIntValue (int v)
{
if (this.runid == 0) return;
setintval (this.runid, this.valid, (long)v);
}
public void setIntValue (short v)
{
if (this.runid == 0) return;
setintval (this.runid, this.valid, (long)v);
}
public void setIntValue (byte v)
{
if (this.runid == 0) return;
setintval (this.runid, this.valid, (long)v);
}
public void setRealValue (double v)
{
if (this.runid == 0) return;
setrealval (this.runid, this.valid, v);
}
public void setRealValue (float v)
{
if (this.runid == 0) return;
setrealval (this.runid, this.valid, (double)v);
}
public void setStringValue (String v)
{
if (this.runid == 0) return;
setstrval (this.runid, this.valid, v);
}
public void setIndexedIntValue (String index, long v)
{
if (this.runid == 0) return;
setindexedintval (this.runid, this.valid, index, v);
}
public void setIndexedIntValue (String index, int v)
{
if (this.runid == 0) return;
setindexedintval (this.runid, this.valid, index, (long)v);
}
public void setIndexedIntValue (String index, short v)
{
if (this.runid == 0) return;
setindexedintval (this.runid, this.valid, index, (long)v);
}
public void setIndexedIntValue (String index, byte v)
{
if (this.runid == 0) return;
setindexedintval (this.runid, this.valid, index, (long)v);
}
public void setIndexedRealValue (String index, double v)
{
if (this.runid == 0) return;
setindexedrealval (this.runid, this.valid, index, v);
}
public void setIndexedRealValue (String index, float v)
{
if (this.runid == 0) return;
setindexedrealval (this.runid, this.valid, index, (double)v);
}
public void setIndexedStringValue (String index, String v)
{
if (this.runid == 0) return;
setindexedstrval (this.runid, this.valid, index, v);
}
public void setIndexedIntValue (long index, long v)
{
if (this.runid == 0) return;
setindexedintval (this.runid, this.valid, Long.toString(index), v);
}
public void setIndexedIntValue (long index, int v)
{
if (this.runid == 0) return;
setindexedintval (this.runid, this.valid, Long.toString(index), (long)v);
}
public void setIndexedIntValue (long index, short v)
{
if (this.runid == 0) return;
setindexedintval (this.runid, this.valid, Long.toString(index), (long)v);
}
public void setIndexedIntValue (long index, byte v)
{
if (this.runid == 0) return;
setindexedintval (this.runid, this.valid, Long.toString(index), (long)v);
}
public void setIndexedRealValue (long index, double v)
{
if (this.runid == 0) return;
setindexedrealval (this.runid, this.valid, Long.toString(index), v);
}
public void setIndexedRealValue (long index, float v)
{
if (this.runid == 0) return;
setindexedrealval (this.runid, this.valid, Long.toString(index), (double)v);
}
public void setIndexedStringValue (long index, String v)
{
if (this.runid == 0) return;
setindexedstrval (this.runid, this.valid, Long.toString(index), v);
}
public void clear ()
{
if (this.runid == 0) return;
clearval (this.runid, this.valid);
}
protected native boolean isindexed (long runid, long valid);
protected native void setintval (long runid, long valid, long v);
protected native void setrealval (long runid, long valid, double v);
protected native void setstrval (long runid, long valid, String v);
protected native void setindexedintval (
long runid, long valid, String index, long v);
protected native void setindexedrealval (
long runid, long valid, String index, double v);
protected native void setindexedstrval (
long runid, long valid, String index, String v);
protected native void clearval (long runid, long valid);
}

524
ase/lib/awk/StdAwk.cpp Normal file
View File

@ -0,0 +1,524 @@
/*
* $Id: StdAwk.cpp 152 2008-03-21 11:57:29Z baconevi $
*
* {License}
*/
#if defined(hpux) || defined(__hpux) || defined(__hpux__)
#define _INCLUDE__STDC_A1_SOURCE
#endif
#include <ase/awk/StdAwk.hpp>
#include <ase/cmn/str.h>
#include <ase/utl/stdio.h>
#include <ase/utl/ctype.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#ifdef _WIN32
#include <tchar.h>
#else
#include <wchar.h>
#endif
/////////////////////////////////
ASE_BEGIN_NAMESPACE(ASE)
/////////////////////////////////
StdAwk::StdAwk ()
{
seed = (unsigned int)::time(NULL);
::srand (seed);
}
#define ADD_FUNC(name,min,max,impl) \
do { \
if (addFunction (name, min, max, \
(FunctionHandler)impl) == -1) \
{ \
Awk::close (); \
return -1; \
} \
} while (0)
int StdAwk::open ()
{
int n = Awk::open ();
if (n == -1) return n;
ADD_FUNC (ASE_T("sin"), 1, 1, &StdAwk::sin);
ADD_FUNC (ASE_T("cos"), 1, 1, &StdAwk::cos);
ADD_FUNC (ASE_T("tan"), 1, 1, &StdAwk::tan);
ADD_FUNC (ASE_T("atan"), 1, 1, &StdAwk::atan);
ADD_FUNC (ASE_T("atan2"), 2, 2, &StdAwk::atan2);
ADD_FUNC (ASE_T("log"), 1, 1, &StdAwk::log);
ADD_FUNC (ASE_T("exp"), 1, 1, &StdAwk::exp);
ADD_FUNC (ASE_T("sqrt"), 1, 1, &StdAwk::sqrt);
ADD_FUNC (ASE_T("int"), 1, 1, &StdAwk::fnint);
ADD_FUNC (ASE_T("rand"), 0, 0, &StdAwk::rand);
ADD_FUNC (ASE_T("srand"), 0, 1, &StdAwk::srand);
ADD_FUNC (ASE_T("systime"), 0, 0, &StdAwk::systime);
ADD_FUNC (ASE_T("strftime"), 0, 2, &StdAwk::strftime);
ADD_FUNC (ASE_T("strfgmtime"), 0, 2, &StdAwk::strfgmtime);
ADD_FUNC (ASE_T("system"), 1, 1, &StdAwk::system);
return 0;
}
int StdAwk::sin (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len)
{
return ret.set ((real_t)::sin(args[0].toReal()));
}
int StdAwk::cos (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len)
{
return ret.set ((real_t)::cos(args[0].toReal()));
}
int StdAwk::tan (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len)
{
return ret.set ((real_t)::tan(args[0].toReal()));
}
int StdAwk::atan (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len)
{
return ret.set ((real_t)::atan(args[0].toReal()));
}
int StdAwk::atan2 (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len)
{
return ret.set ((real_t)::atan2(args[0].toReal(), args[1].toReal()));
}
int StdAwk::log (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len)
{
return ret.set ((real_t)::log(args[0].toReal()));
}
int StdAwk::exp (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len)
{
return ret.set ((real_t)::exp(args[0].toReal()));
}
int StdAwk::sqrt (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len)
{
return ret.set ((real_t)::sqrt(args[0].toReal()));
}
int StdAwk::fnint (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len)
{
return ret.set (args[0].toInt());
}
int StdAwk::rand (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len)
{
return ret.set ((long_t)::rand());
}
int StdAwk::srand (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len)
{
unsigned int prevSeed = seed;
seed = (nargs == 0)?
(unsigned int)::time(NULL):
(unsigned int)args[0].toInt();
::srand (seed);
return ret.set ((long_t)prevSeed);
}
#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER>=1400)
#define time_t __time64_t
#define time _time64
#define localtime _localtime64
#define gmtime _gmtime64
#endif
int StdAwk::systime (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len)
{
return ret.set ((long_t)::time(NULL));
}
int StdAwk::strftime (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len)
{
const char_t* fmt;
size_t fln;
fmt = (nargs < 1)? ASE_T("%c"): args[0].toStr(&fln);
time_t t = (nargs < 2)? ::time(NULL): (time_t)args[1].toInt();
char_t buf[128];
struct tm* tm;
#ifdef _WIN32
tm = ::localtime (&t);
#else
struct tm tmb;
tm = ::localtime_r (&t, &tmb);
#endif
#ifdef ASE_CHAR_IS_MCHAR
size_t l = ::strftime (buf, ASE_COUNTOF(buf), fmt, tm);
#else
size_t l = ::wcsftime (buf, ASE_COUNTOF(buf), fmt, tm);
#endif
return ret.set (buf, l);
}
int StdAwk::strfgmtime (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len)
{
const char_t* fmt;
size_t fln;
fmt = (nargs < 1)? ASE_T("%c"): args[0].toStr(&fln);
time_t t = (nargs < 2)? ::time(NULL): (time_t)args[1].toInt();
char_t buf[128];
struct tm* tm;
#ifdef _WIN32
tm = ::gmtime (&t);
#else
struct tm tmb;
tm = ::gmtime_r (&t, &tmb);
#endif
#ifdef ASE_CHAR_IS_MCHAR
size_t l = ::strftime (buf, ASE_COUNTOF(buf), fmt, tm);
#else
size_t l = ::wcsftime (buf, ASE_COUNTOF(buf), fmt, tm);
#endif
return ret.set (buf, l);
}
int StdAwk::system (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len)
{
size_t l;
const char_t* ptr = args[0].toStr(&l);
#ifdef _WIN32
return ret.set ((long_t)::_tsystem(ptr));
#elif defined(ASE_CHAR_IS_MCHAR)
return ret.set ((long_t)::system(ptr));
#else
char* mbs = (char*)ase_awk_malloc (awk, l*5+1);
if (mbs == ASE_NULL) return -1;
::size_t mbl = ::wcstombs (mbs, ptr, l*5);
if (mbl == (::size_t)-1)
{
ase_awk_free (awk, mbs);
return -1;
}
mbs[mbl] = '\0';
int n = ret.set ((long_t)::system(mbs));
ase_awk_free (awk, mbs);
return n;
#endif
}
int StdAwk::openPipe (Pipe& io)
{
Awk::Pipe::Mode mode = io.getMode();
FILE* fp = NULL;
switch (mode)
{
case Awk::Pipe::READ:
fp = ase_popen (io.getName(), ASE_T("r"));
break;
case Awk::Pipe::WRITE:
fp = ase_popen (io.getName(), ASE_T("w"));
break;
}
if (fp == NULL) return -1;
io.setHandle (fp);
return 1;
}
int StdAwk::closePipe (Pipe& io)
{
fclose ((FILE*)io.getHandle());
return 0;
}
StdAwk::ssize_t StdAwk::readPipe (Pipe& io, char_t* buf, size_t len)
{
FILE* fp = (FILE*)io.getHandle();
ssize_t n = 0;
while (n < (ssize_t)len)
{
ase_cint_t c = ase_fgetc (fp);
if (c == ASE_CHAR_EOF)
{
if (ase_ferror(fp)) n = -1;
break;
}
buf[n++] = c;
if (c == ASE_T('\n')) break;
}
return n;
}
StdAwk::ssize_t StdAwk::writePipe (Pipe& io, char_t* buf, size_t len)
{
FILE* fp = (FILE*)io.getHandle();
size_t left = len;
while (left > 0)
{
if (*buf == ASE_T('\0'))
{
#if defined(ASE_CHAR_IS_WCHAR) && defined(__linux)
if (fputc ('\0', fp) == EOF)
#else
if (ase_fputc (*buf, fp) == ASE_CHAR_EOF)
#endif
{
return -1;
}
left -= 1; buf += 1;
}
else
{
#if defined(ASE_CHAR_IS_WCHAR) && defined(__linux)
// fwprintf seems to return an error with the file
// pointer opened by popen, as of this writing.
// anyway, hopefully the following replacement
// will work all the way.
int chunk = (left > ASE_TYPE_MAX(int))? ASE_TYPE_MAX(int): (int)left;
int n = fprintf (fp, "%.*ls", chunk, buf);
if (n >= 0)
{
size_t x;
for (x = 0; x < chunk; x++)
{
if (buf[x] == ASE_T('\0')) break;
}
n = x;
}
#else
int chunk = (left > ASE_TYPE_MAX(int))? ASE_TYPE_MAX(int): (int)left;
int n = ase_fprintf (fp, ASE_T("%.*s"), chunk, buf);
#endif
if (n < 0 || n > chunk) return -1;
left -= n; buf += n;
}
}
return len;
}
int StdAwk::flushPipe (Pipe& io)
{
return ::fflush ((FILE*)io.getHandle());
}
// file io handlers
int StdAwk::openFile (File& io)
{
Awk::File::Mode mode = io.getMode();
FILE* fp = NULL;
switch (mode)
{
case Awk::File::READ:
fp = ase_fopen (io.getName(), ASE_T("r"));
break;
case Awk::File::WRITE:
fp = ase_fopen (io.getName(), ASE_T("w"));
break;
case Awk::File::APPEND:
fp = ase_fopen (io.getName(), ASE_T("a"));
break;
}
if (fp == NULL) return -1;
io.setHandle (fp);
return 1;
}
int StdAwk::closeFile (File& io)
{
fclose ((FILE*)io.getHandle());
return 0;
}
StdAwk::ssize_t StdAwk::readFile (File& io, char_t* buf, size_t len)
{
FILE* fp = (FILE*)io.getHandle();
ssize_t n = 0;
while (n < (ssize_t)len)
{
ase_cint_t c = ase_fgetc (fp);
if (c == ASE_CHAR_EOF)
{
if (ase_ferror(fp)) n = -1;
break;
}
buf[n++] = c;
if (c == ASE_T('\n')) break;
}
return n;
}
StdAwk::ssize_t StdAwk::writeFile (File& io, char_t* buf, size_t len)
{
FILE* fp = (FILE*)io.getHandle();
size_t left = len;
while (left > 0)
{
if (*buf == ASE_T('\0'))
{
if (ase_fputc (*buf, fp) == ASE_CHAR_EOF) return -1;
left -= 1; buf += 1;
}
else
{
int chunk = (left > ASE_TYPE_MAX(int))? ASE_TYPE_MAX(int): (int)left;
int n = ase_fprintf (fp, ASE_T("%.*s"), chunk, buf);
if (n < 0 || n > chunk) return -1;
left -= n; buf += n;
}
}
return len;
}
int StdAwk::flushFile (File& io)
{
return ::fflush ((FILE*)io.getHandle());
}
// memory allocation primitives
void* StdAwk::allocMem (size_t n)
{
return ::malloc (n);
}
void* StdAwk::reallocMem (void* ptr, size_t n)
{
return ::realloc (ptr, n);
}
void StdAwk::freeMem (void* ptr)
{
::free (ptr);
}
// character class primitives
StdAwk::bool_t StdAwk::isUpper (cint_t c)
{
return ase_isupper (c);
}
StdAwk::bool_t StdAwk::isLower (cint_t c)
{
return ase_islower (c);
}
StdAwk::bool_t StdAwk::isAlpha (cint_t c)
{
return ase_isalpha (c);
}
StdAwk::bool_t StdAwk::isDigit (cint_t c)
{
return ase_isdigit (c);
}
StdAwk::bool_t StdAwk::isXdigit (cint_t c)
{
return ase_isxdigit (c);
}
StdAwk::bool_t StdAwk::isAlnum (cint_t c)
{
return ase_isalnum (c);
}
StdAwk::bool_t StdAwk::isSpace (cint_t c)
{
return ase_isspace (c);
}
StdAwk::bool_t StdAwk::isPrint (cint_t c)
{
return ase_isprint (c);
}
StdAwk::bool_t StdAwk::isGraph (cint_t c)
{
return ase_isgraph (c);
}
StdAwk::bool_t StdAwk::isCntrl (cint_t c)
{
return ase_iscntrl (c);
}
StdAwk::bool_t StdAwk::isPunct (cint_t c)
{
return ase_ispunct (c);
}
StdAwk::cint_t StdAwk::toUpper (cint_t c)
{
return ase_toupper (c);
}
StdAwk::cint_t StdAwk::toLower (cint_t c)
{
return ase_tolower (c);
}
// miscellaneous primitive
StdAwk::real_t StdAwk::pow (real_t x, real_t y)
{
return ::pow (x, y);
}
int StdAwk::vsprintf (
char_t* buf, size_t size, const char_t* fmt, va_list arg)
{
return ase_vsprintf (buf, size, fmt, arg);
}
void StdAwk::vdprintf (const char_t* fmt, va_list arg)
{
ase_vfprintf (stderr, fmt, arg);
}
/////////////////////////////////
ASE_END_NAMESPACE(ASE)
/////////////////////////////////

109
ase/lib/awk/StdAwk.hpp Normal file
View File

@ -0,0 +1,109 @@
/*
* $Id: StdAwk.hpp 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
#ifndef _ASE_AWK_STDAWK_HPP_
#define _ASE_AWK_STDAWK_HPP_
#include <ase/awk/Awk.hpp>
/////////////////////////////////
ASE_BEGIN_NAMESPACE(ASE)
/////////////////////////////////
/**
* Provides a more useful AWK interpreter by overriding primitive methods,
* the file handler, the pipe handler and implementing common AWK intrinsic
* functions.
*/
class StdAwk: public Awk
{
public:
StdAwk ();
int open ();
protected:
// intrinsic functions
int sin (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len);
int cos (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len);
int tan (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len);
int atan (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len);
int atan2 (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len);
int log (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len);
int exp (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len);
int sqrt (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len);
int fnint (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len);
int rand (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len);
int srand (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len);
int systime (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len);
int strftime (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len);
int strfgmtime (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len);
int system (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len);
// pipe io handlers
int openPipe (Pipe& io);
int closePipe (Pipe& io);
ssize_t readPipe (Pipe& io, char_t* buf, size_t len);
ssize_t writePipe (Pipe& io, char_t* buf, size_t len);
int flushPipe (Pipe& io);
// file io handlers
int openFile (File& io);
int closeFile (File& io);
ssize_t readFile (File& io, char_t* buf, size_t len);
ssize_t writeFile (File& io, char_t* buf, size_t len);
int flushFile (File& io);
// primitive handlers
void* allocMem (size_t n);
void* reallocMem (void* ptr, size_t n);
void freeMem (void* ptr);
bool_t isUpper (cint_t c);
bool_t isLower (cint_t c);
bool_t isAlpha (cint_t c);
bool_t isDigit (cint_t c);
bool_t isXdigit (cint_t c);
bool_t isAlnum (cint_t c);
bool_t isSpace (cint_t c);
bool_t isPrint (cint_t c);
bool_t isGraph (cint_t c);
bool_t isCntrl (cint_t c);
bool_t isPunct (cint_t c);
cint_t toUpper (cint_t c);
cint_t toLower (cint_t c);
real_t pow (real_t x, real_t y);
int vsprintf (char_t* buf, size_t size,
const char_t* fmt, va_list arg);
void vdprintf (const char_t* fmt, va_list arg);
protected:
unsigned int seed;
};
/////////////////////////////////
ASE_END_NAMESPACE(ASE)
/////////////////////////////////
#endif

451
ase/lib/awk/StdAwk.java Normal file
View File

@ -0,0 +1,451 @@
/*
* $Id: StdAwk.java 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
package ase.awk;
import java.io.*;
/**
* Extends the core interpreter engine to implement the language closer to
* the standard.
*/
public abstract class StdAwk extends Awk
{
private long seed;
private java.util.Random random;
public StdAwk () throws Exception
{
super ();
seed = System.currentTimeMillis();
random = new java.util.Random (seed);
addFunction ("sin", 1, 1);
addFunction ("cos", 1, 1);
addFunction ("tan", 1, 1);
addFunction ("atan", 1, 1);
addFunction ("atan2", 2, 2);
addFunction ("log", 1, 1);
addFunction ("exp", 1, 1);
addFunction ("sqrt", 1, 1);
addFunction ("int", 1, 1, "bfnint");
addFunction ("srand", 0, 1);
addFunction ("rand", 0, 0);
addFunction ("systime", 0, 0);
addFunction ("strftime", 0, 2);
addFunction ("strfgmtime", 0, 2);
addFunction ("system", 1, 1);
}
/* == file interface == */
protected int openFile (File file)
{
int mode = file.getMode();
if (mode == File.MODE_READ)
{
FileInputStream fis;
try { fis = new FileInputStream (file.getName()); }
catch (IOException e) { return -1; }
Reader rd = new BufferedReader (
new InputStreamReader (fis));
file.setHandle (rd);
return 1;
}
else if (mode == File.MODE_WRITE)
{
FileOutputStream fos;
try { fos = new FileOutputStream (file.getName()); }
catch (IOException e) { return -1; }
Writer wr = new BufferedWriter (
new OutputStreamWriter (fos));
file.setHandle (wr);
return 1;
}
else if (mode == File.MODE_APPEND)
{
FileOutputStream fos;
try { fos = new FileOutputStream (file.getName(), true); }
catch (IOException e) { return -1; }
Writer wr = new BufferedWriter (
new OutputStreamWriter (fos));
file.setHandle (wr);
return 1;
}
return -1;
}
protected int closeFile (File file)
{
int mode = file.getMode();
if (mode == File.MODE_READ)
{
Reader isr = (Reader)file.getHandle();
try { isr.close (); }
catch (IOException e) { return -1; }
return 0;
}
else if (mode == File.MODE_WRITE)
{
Writer osw = (Writer)file.getHandle();
try { osw.close (); }
catch (IOException e) { return -1; }
return 0;
}
else if (mode == File.MODE_APPEND)
{
Writer osw = (Writer)file.getHandle();
try { osw.close (); }
catch (IOException e) { return -1; }
return 0;
}
return -1;
}
protected int readFile (File file, char[] buf, int len)
{
int mode = file.getMode();
if (mode == File.MODE_READ)
{
Reader rd = (Reader)file.getHandle();
try
{
len = rd.read (buf, 0, len);
if (len == -1) return 0;
}
catch (IOException e) { return -1; }
return len;
}
return -1;
}
protected int writeFile (File file, char[] buf, int len)
{
int mode = file.getMode();
if (mode == File.MODE_WRITE ||
mode == File.MODE_APPEND)
{
Writer wr = (Writer)file.getHandle();
try { wr.write (buf, 0, len); }
catch (IOException e) { return -1; }
return len;
}
return -1;
}
protected int flushFile (File file)
{
int mode = file.getMode ();
if (mode == File.MODE_WRITE ||
mode == File.MODE_APPEND)
{
Writer wr = (Writer)file.getHandle ();
try { wr.flush (); }
catch (IOException e) { return -1; }
return 0;
}
return -1;
}
private class RWE
{
public Writer wr;
public Reader rd;
public Reader er;
public RWE (Writer wr, Reader rd, Reader er)
{
this.wr = wr;
this.rd = rd;
this.er = er;
}
};
/* == pipe interface == */
protected int openPipe (Pipe pipe)
{
int mode = pipe.getMode();
if (mode == Pipe.MODE_READ)
{
Process proc;
try { proc = popen (pipe.getName()); }
catch (IOException e) { return -1; }
Reader rd = new BufferedReader (
new InputStreamReader (proc.getInputStream()));
pipe.setHandle (rd);
return 1;
}
else if (mode == Pipe.MODE_WRITE)
{
Process proc;
try { proc = popen (pipe.getName()); }
catch (IOException e) { return -1; }
Writer wr = new BufferedWriter (
new OutputStreamWriter (proc.getOutputStream()));
Reader rd = new BufferedReader (
new InputStreamReader (proc.getInputStream()));
Reader er = new BufferedReader (
new InputStreamReader (proc.getErrorStream()));
pipe.setHandle (new RWE (wr, rd, er));
return 1;
}
return -1;
}
protected int closePipe (Pipe pipe)
{
int mode = pipe.getMode();
if (mode == Pipe.MODE_READ)
{
Reader rd = (Reader)pipe.getHandle();
try { rd.close (); }
catch (IOException e) { return -1; }
return 0;
}
else if (mode == Pipe.MODE_WRITE)
{
//Writer wr = (Writer)pipe.getHandle();
RWE rwe = (RWE)pipe.getHandle();
try { rwe.wr.close (); }
catch (IOException e) { return -1; }
char[] buf = new char[256];
try
{
while (true)
{
int len = rwe.rd.read (buf, 0, buf.length);
if (len == -1) break;
System.out.print (new String (buf, 0, len));
}
System.out.flush ();
}
catch (IOException e) {}
try
{
while (true)
{
int len = rwe.er.read (buf, 0, buf.length);
if (len == -1) break;
System.err.print (new String (buf, 0, len));
}
System.err.flush ();
}
catch (IOException e) {}
try { rwe.rd.close (); } catch (IOException e) {}
try { rwe.er.close (); } catch (IOException e) {}
pipe.setHandle (null);
return 0;
}
return -1;
}
protected int readPipe (Pipe pipe, char[] buf, int len)
{
int mode = pipe.getMode();
if (mode == Pipe.MODE_READ)
{
Reader rd = (Reader)pipe.getHandle();
try
{
len = rd.read (buf, 0, len);
if (len == -1) len = 0;
}
catch (IOException e) { len = -1; }
return len;
}
return -1;
}
protected int writePipe (Pipe pipe, char[] buf, int len)
{
int mode = pipe.getMode();
if (mode == Pipe.MODE_WRITE)
{
//Writer wr = (Writer)pipe.getHandle ();
RWE rw = (RWE)pipe.getHandle();
try
{
rw.wr.write (buf, 0, len);
rw.wr.flush ();
}
catch (IOException e) { return -1; }
return len;
}
return -1;
}
protected int flushPipe (Pipe pipe)
{
int mode = pipe.getMode ();
if (mode == Pipe.MODE_WRITE)
{
Writer wr = (Writer)pipe.getHandle ();
try { wr.flush (); }
catch (IOException e) { return -1; }
return 0;
}
return -1;
}
/* == arithmetic built-in functions */
public void sin (Context ctx, String name, Return ret, Argument[] args)
{
ret.setRealValue (Math.sin(args[0].getRealValue()));
}
public void cos (Context ctx, String name, Return ret, Argument[] args)
{
ret.setRealValue (Math.cos(args[0].getRealValue()));
}
public void tan (Context ctx, String name, Return ret, Argument[] args)
{
ret.setRealValue (Math.tan(args[0].getRealValue()));
}
public void atan (Context ctx, String name, Return ret, Argument[] args)
{
ret.setRealValue (Math.atan(args[0].getRealValue()));
}
public void atan2 (Context ctx, String name, Return ret, Argument[] args)
{
double y = args[0].getRealValue();
double x = args[1].getRealValue();
ret.setRealValue (Math.atan2(y,x));
}
public void log (Context ctx, String name, Return ret, Argument[] args)
{
ret.setRealValue (Math.log(args[0].getRealValue()));
}
public void exp (Context ctx, String name, Return ret, Argument[] args)
{
ret.setRealValue (Math.exp(args[0].getRealValue()));
}
public void sqrt (Context ctx, String name, Return ret, Argument[] args)
{
ret.setRealValue (Math.sqrt(args[0].getRealValue()));
}
public void bfnint (Context ctx, String name, Return ret, Argument[] args)
{
ret.setIntValue (args[0].getIntValue());
}
public void rand (Context ctx, String name, Return ret, Argument[] args)
{
ret.setRealValue (random.nextDouble ());
}
public void srand (Context ctx, String name, Return ret, Argument[] args)
{
long prev_seed = seed;
seed = (args == null || args.length == 0)?
System.currentTimeMillis ():
args[0].getIntValue();
random.setSeed (seed);
ret.setIntValue (prev_seed);
}
public void systime (Context ctx, String name, Return ret, Argument[] args)
{
long msec = System.currentTimeMillis ();
ret.setIntValue (msec / 1000);
}
public void strftime (Context ctx, String name, Return ret, Argument[] args) throws Exception
{
String fmt = (args.length<1)? "%c": args[0].getStringValue();
long t = (args.length<2)? (System.currentTimeMillis()/1000): args[1].getIntValue();
ret.setStringValue (strftime (fmt, t));
}
public void strfgmtime (Context ctx, String name, Return ret, Argument[] args) throws Exception
{
String fmt = (args.length<1)? "%c": args[0].getStringValue();
long t = (args.length<2)? (System.currentTimeMillis()/1000): args[1].getIntValue();
ret.setStringValue (strfgmtime (fmt, t));
}
/* miscellaneous built-in functions */
public void system (Context ctx, String name, Return ret, Argument[] args) throws Exception
{
ret.setIntValue (system (args[0].getStringValue()));
}
/* == utility functions == */
private Process popen (String command) throws IOException
{
String full;
/* TODO: consider OS names and versions */
full = System.getenv ("ComSpec");
if (full != null)
{
full = full + " /c " + command;
}
else
{
full = System.getenv ("SHELL");
if (full != null)
{
full = "/bin/sh -c \"" + command + "\"";
}
else full = command;
}
return Runtime.getRuntime().exec (full);
}
}

View File

@ -0,0 +1,265 @@
<?xml version="1.0" encoding="utf-8"?>
<BorlandProject>
<PersonalityInfo>
<Option>
<Option Name="Personality">CPlusPlusBuilder.Personality</Option>
<Option Name="ProjectType">CppStaticLibrary</Option>
<Option Name="Version">1.0</Option>
<Option Name="GUID">{EDEF16CC-0C39-4E6B-A3CC-3DBF585BBD77}</Option>
</Option>
</PersonalityInfo>
<CPlusPlusBuilder.Personality>
<Source>
<Source Name="MainSource">Awk.cpp</Source>
</Source>
<BCBPROJECT>
<project version="10.0">
<property category="build.config" name="active" value="0"/>
<property category="build.config" name="count" value="1"/>
<property category="build.config" name="excludedefaultforzero" value="0"/>
<property category="build.config.0" name="builddir" value="Debug"/>
<property category="build.config.0" name="key" value="Debug_Build"/>
<property category="build.config.0" name="name" value="Debug Build"/>
<property category="build.config.0" name="settings.win32b" value="default"/>
<property category="build.config.0" name="type" value="Toolset"/>
<property category="build.config.0" name="win32.win32b.builddir" value="debug"/>
<property category="build.config.1" name="key" value="Release_Build"/>
<property category="build.config.1" name="name" value="Release Build"/>
<property category="build.config.1" name="settings.win32b" value="default"/>
<property category="build.config.1" name="type" value="Toolset"/>
<property category="build.config.1" name="win32.win32b.builddir" value="release"/>
<property category="build.node" name="lastconfig" value="Debug_Build"/>
<property category="build.node" name="libraries" value="vcl.lib rtl.lib"/>
<property category="build.node" name="name" value="aseawk++.lib"/>
<property category="build.node" name="packages" value="vclx;vcl;rtl;dbrtl;vcldb;adortl;dbxcds;dbexpress;xmlrtl;vclie;inet;inetdbbde;inetdbxpress;soaprtl;dsnap;bdertl;vcldbx"/>
<property category="build.node" name="sparelibs" value="rtl.lib vcl.lib"/>
<property category="build.node" name="use_packages" value="0"/>
<property category="build.platform" name="active" value="win32"/>
<property category="build.platform" name="win32.Debug_Build.toolset" value="win32b"/>
<property category="build.platform" name="win32.Release_Build.toolset" value="win32b"/>
<property category="build.platform" name="win32.config2.toolset" value="win32b"/>
<property category="build.platform" name="win32.default" value="win32b"/>
<property category="build.platform" name="win32.enabled" value="1"/>
<property category="build.platform" name="win32.win32b.enabled" value="1"/>
<property category="win32.*.win32b.dcc32" name="param.filenames.merge" value="1"/>
<property category="win32.*.win32b.tasm32" name="param.listfile.merge" value="1"/>
<property category="win32.*.win32b.tasm32" name="param.objfile.merge" value="1"/>
<property category="win32.*.win32b.tasm32" name="param.xreffile.merge" value="1"/>
<property category="win32.Debug_Build.win32b.bcc32" name="container.SelectedOptimizations.containerenabled" value="0"/>
<property category="win32.Debug_Build.win32b.bcc32" name="container.SelectedWarnings.containerenabled" value="1"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.D.arg.1" value="_DEBUG"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.D.arg.merge" value="1"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.D.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.Od.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.k.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.n.arg.1" value="debug\cpp"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.n.arg.merge" value="0"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.n.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.r.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.v.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.vi.enabled" value="0"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.y.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.brcc32" name="option.16.enabled" value="0"/>
<property category="win32.Debug_Build.win32b.brcc32" name="option.31.enabled" value="0"/>
<property category="win32.Debug_Build.win32b.dcc32" name="option.$D.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.dcc32" name="option.$O.enabled" value="0"/>
<property category="win32.Debug_Build.win32b.dcc32" name="option.D.arg.1" value="DEBUG"/>
<property category="win32.Debug_Build.win32b.dcc32" name="option.D.arg.merge" value="1"/>
<property category="win32.Debug_Build.win32b.dcc32" name="option.D.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.dcc32" name="option.V.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.ilink32" name="option.D.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.ilink32" name="option.Gn.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.ilink32" name="option.L.arg.1" value="$(BDS)\lib\debug"/>
<property category="win32.Debug_Build.win32b.ilink32" name="option.L.arg.merge" value="1"/>
<property category="win32.Debug_Build.win32b.ilink32" name="option.L.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.ilink32" name="option.v.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.tasm32" name="option.z.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.tasm32" name="option.zd.enabled" value="0"/>
<property category="win32.Debug_Build.win32b.tasm32" name="option.zi.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.tlib" name="option.E.enabled" value="0"/>
<property category="win32.Debug_Build.win32b.tlib" name="option.outputdir.arg.1" value="..\debug\lib"/>
<property category="win32.Debug_Build.win32b.tlib" name="option.outputdir.arg.merge" value="0"/>
<property category="win32.Debug_Build.win32b.tlib" name="option.outputdir.enabled" value="1"/>
<property category="win32.Release_Build.win32b.bcc32" name="option.D.arg.1" value="NDEBUG"/>
<property category="win32.Release_Build.win32b.bcc32" name="option.D.arg.merge" value="1"/>
<property category="win32.Release_Build.win32b.bcc32" name="option.D.enabled" value="1"/>
<property category="win32.Release_Build.win32b.bcc32" name="option.O2.enabled" value="1"/>
<property category="win32.Release_Build.win32b.bcc32" name="option.k.enabled" value="0"/>
<property category="win32.Release_Build.win32b.bcc32" name="option.n.arg.1" value="release\cpp"/>
<property category="win32.Release_Build.win32b.bcc32" name="option.n.arg.merge" value="0"/>
<property category="win32.Release_Build.win32b.bcc32" name="option.n.enabled" value="1"/>
<property category="win32.Release_Build.win32b.bcc32" name="option.r.enabled" value="1"/>
<property category="win32.Release_Build.win32b.bcc32" name="option.vi.enabled" value="1"/>
<property category="win32.Release_Build.win32b.dcc32" name="option.$D.enabled" value="0"/>
<property category="win32.Release_Build.win32b.dcc32" name="option.$O.enabled" value="1"/>
<property category="win32.Release_Build.win32b.dcc32" name="option.V.enabled" value="0"/>
<property category="win32.Release_Build.win32b.ilink32" name="option.L.arg.1" value="$(BDS)\lib\release"/>
<property category="win32.Release_Build.win32b.ilink32" name="option.L.arg.merge" value="1"/>
<property category="win32.Release_Build.win32b.ilink32" name="option.L.enabled" value="1"/>
<property category="win32.Release_Build.win32b.tasm32" name="option.z.enabled" value="0"/>
<property category="win32.Release_Build.win32b.tasm32" name="option.zd.enabled" value="0"/>
<property category="win32.Release_Build.win32b.tasm32" name="option.zi.enabled" value="0"/>
<property category="win32.Release_Build.win32b.tasm32" name="option.zn.enabled" value="1"/>
<property category="win32.Release_Build.win32b.tlib" name="option.outputdir.arg.1" value="..\release\lib"/>
<property category="win32.Release_Build.win32b.tlib" name="option.outputdir.arg.merge" value="0"/>
<property category="win32.Release_Build.win32b.tlib" name="option.outputdir.enabled" value="1"/>
<optionset name="all_configurations">
<property category="node" name="displayname" value="All Configurations"/>
<property category="win32.*.win32b.bcc32" name="container.SelectedOptimizations.containerenabled" value="1"/>
<property category="win32.*.win32b.bcc32" name="container.SelectedWarnings.containerenabled" value="1"/>
<property category="win32.*.win32b.bcc32" name="option.4.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.5.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.6.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.A.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.AK.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.AT.enabled" value="1"/>
<property category="win32.*.win32b.bcc32" name="option.AU.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.H=.arg.1" value="$(BDS)\lib\vcl100.csm"/>
<property category="win32.*.win32b.bcc32" name="option.H=.arg.merge" value="1"/>
<property category="win32.*.win32b.bcc32" name="option.H=.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.Hc.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.He.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.Hs.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.I.arg.1" value="..\.."/>
<property category="win32.*.win32b.bcc32" name="option.I.arg.2" value="$(BDS)\include"/>
<property category="win32.*.win32b.bcc32" name="option.I.arg.3" value="$(BDS)\include\dinkumware"/>
<property category="win32.*.win32b.bcc32" name="option.I.arg.4" value="$(BDS)\include\vcl"/>
<property category="win32.*.win32b.bcc32" name="option.I.arg.merge" value="1"/>
<property category="win32.*.win32b.bcc32" name="option.I.enabled" value="1"/>
<property category="win32.*.win32b.bcc32" name="option.Jgi.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.Jgx.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.O1.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.O2.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.Od.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.V0.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.V1.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.Vmd.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.Vmm.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.Vms.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.align-1.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.align-2.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.align-3.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.align-5.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.b.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.disablewarns.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.noregistervars.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.p.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.pm.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.pr.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.ps.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.rd.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.sysdefines.arg.1" value="_RTLDLL"/>
<property category="win32.*.win32b.bcc32" name="option.sysdefines.arg.2" value="NO_STRICT"/>
<property category="win32.*.win32b.bcc32" name="option.sysdefines.arg.merge" value="1"/>
<property category="win32.*.win32b.bcc32" name="option.sysdefines.enabled" value="1"/>
<property category="win32.*.win32b.bcc32" name="option.tW.enabled" value="1"/>
<property category="win32.*.win32b.bcc32" name="option.tWC.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.tWD.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.tWM.enabled" value="1"/>
<property category="win32.*.win32b.bcc32" name="option.vG.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.w.enabled" value="0"/>
<property category="win32.*.win32b.dcc32" name="option.I.arg.1" value="C:\projects\ase\awk"/>
<property category="win32.*.win32b.dcc32" name="option.I.arg.merge" value="1"/>
<property category="win32.*.win32b.dcc32" name="option.I.enabled" value="0"/>
<property category="win32.*.win32b.dcc32" name="option.O.arg.1" value="C:\projects\ase\awk"/>
<property category="win32.*.win32b.dcc32" name="option.O.arg.merge" value="1"/>
<property category="win32.*.win32b.dcc32" name="option.O.enabled" value="0"/>
<property category="win32.*.win32b.dcc32" name="option.R.arg.1" value="C:\projects\ase\awk"/>
<property category="win32.*.win32b.dcc32" name="option.R.arg.merge" value="1"/>
<property category="win32.*.win32b.dcc32" name="option.R.enabled" value="0"/>
<property category="win32.*.win32b.dcc32" name="option.U.arg.1" value="C:\projects\ase\awk"/>
<property category="win32.*.win32b.dcc32" name="option.U.arg.2" value="C:\Documents and Settings\evi\My Documents\Borland Studio Projects"/>
<property category="win32.*.win32b.dcc32" name="option.U.arg.3" value="$(BDS)\lib"/>
<property category="win32.*.win32b.dcc32" name="option.U.arg.4" value="$(BDS)\lib\obj"/>
<property category="win32.*.win32b.dcc32" name="option.U.arg.merge" value="1"/>
<property category="win32.*.win32b.dcc32" name="option.U.enabled" value="1"/>
<property category="win32.*.win32b.dcc32" name="param.filenames.merge" value="1"/>
<property category="win32.*.win32b.idl2cpp" name="option.I.arg.1" value="C:\projects\ase\awk"/>
<property category="win32.*.win32b.idl2cpp" name="option.I.arg.merge" value="1"/>
<property category="win32.*.win32b.idl2cpp" name="option.I.enabled" value="1"/>
<property category="win32.*.win32b.ilink32" name="option.Gi.enabled" value="0"/>
<property category="win32.*.win32b.ilink32" name="option.L.arg.1" value="$(BDS)\lib"/>
<property category="win32.*.win32b.ilink32" name="option.L.arg.2" value="$(BDS)\lib\obj"/>
<property category="win32.*.win32b.ilink32" name="option.L.arg.3" value="$(BDS)\lib\psdk"/>
<property category="win32.*.win32b.ilink32" name="option.L.arg.merge" value="1"/>
<property category="win32.*.win32b.ilink32" name="option.L.enabled" value="1"/>
<property category="win32.*.win32b.ilink32" name="option.Tpd.enabled" value="0"/>
<property category="win32.*.win32b.ilink32" name="option.Tpe.enabled" value="0"/>
<property category="win32.*.win32b.ilink32" name="option.Tpp.enabled" value="0"/>
<property category="win32.*.win32b.ilink32" name="option.aa.enabled" value="0"/>
<property category="win32.*.win32b.ilink32" name="option.ap.enabled" value="0"/>
<property category="win32.*.win32b.ilink32" name="option.dynamicrtl.enabled" value="1"/>
<property category="win32.*.win32b.tlib" name="option.E.enabled" value="1"/>
<property category="win32.*.win32b.tlib" name="option.dynamicrtl.enabled" value="0"/>
<property category="win32.*.win32b.tlib" name="option.outputdir.arg.merge" value="1"/>
<property category="win32.*.win32b.tlib" name="option.outputdir.enabled" value="0"/>
</optionset>
</project>
<FILELIST>
<FILE FILENAME="Awk.cpp" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="Awk" FORMNAME="" DESIGNCLASS=""/>
<FILE FILENAME="StdAwk.cpp" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="err" FORMNAME="" DESIGNCLASS=""/>
</FILELIST>
<IDEOPTIONS>
<VersionInfo>
<VersionInfo Name="IncludeVerInfo">False</VersionInfo>
<VersionInfo Name="AutoIncBuild">False</VersionInfo>
<VersionInfo Name="MajorVer">1</VersionInfo>
<VersionInfo Name="MinorVer">0</VersionInfo>
<VersionInfo Name="Release">0</VersionInfo>
<VersionInfo Name="Build">0</VersionInfo>
<VersionInfo Name="Debug">False</VersionInfo>
<VersionInfo Name="PreRelease">False</VersionInfo>
<VersionInfo Name="Special">False</VersionInfo>
<VersionInfo Name="Private">False</VersionInfo>
<VersionInfo Name="DLL">False</VersionInfo>
<VersionInfo Name="Locale">1033</VersionInfo>
<VersionInfo Name="CodePage">1252</VersionInfo>
</VersionInfo>
<VersionInfoKeys>
<VersionInfoKeys Name="CompanyName"></VersionInfoKeys>
<VersionInfoKeys Name="FileDescription"></VersionInfoKeys>
<VersionInfoKeys Name="FileVersion">1.0.0.0</VersionInfoKeys>
<VersionInfoKeys Name="InternalName"></VersionInfoKeys>
<VersionInfoKeys Name="LegalCopyright"></VersionInfoKeys>
<VersionInfoKeys Name="LegalTrademarks"></VersionInfoKeys>
<VersionInfoKeys Name="OriginalFilename"></VersionInfoKeys>
<VersionInfoKeys Name="ProductName"></VersionInfoKeys>
<VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys>
<VersionInfoKeys Name="Comments"></VersionInfoKeys>
</VersionInfoKeys>
<Debugging>
<Debugging Name="DebugSourceDirs"></Debugging>
</Debugging>
<Parameters>
<Parameters Name="RunParams"></Parameters>
<Parameters Name="Launcher"></Parameters>
<Parameters Name="UseLauncher">False</Parameters>
<Parameters Name="DebugCWD"></Parameters>
<Parameters Name="HostApplication"></Parameters>
<Parameters Name="RemoteHost"></Parameters>
<Parameters Name="RemotePath"></Parameters>
<Parameters Name="RemoteParams"></Parameters>
<Parameters Name="RemoteLauncher"></Parameters>
<Parameters Name="UseRemoteLauncher">False</Parameters>
<Parameters Name="RemoteCWD"></Parameters>
<Parameters Name="RemoteDebug">False</Parameters>
<Parameters Name="Debug Symbols Search Path"></Parameters>
<Parameters Name="LoadAllSymbols">True</Parameters>
<Parameters Name="LoadUnspecifiedSymbols">False</Parameters>
</Parameters>
<Linker>
<Linker Name="LibPrefix"></Linker>
<Linker Name="LibSuffix"></Linker>
<Linker Name="LibVersion"></Linker>
</Linker>
</IDEOPTIONS>
</BCBPROJECT>
<buildevents>
<buildevent file="aseawk++.bdsproj">
<precompile mode="0" cancancel="0" capture="-1" showconsole="0">mkdir $(PROJECTDIR)..\release\lib
mkdir $(PROJECTDIR)..\debug\lib
</precompile>
</buildevent>
</buildevents>
</CPlusPlusBuilder.Personality>
</BorlandProject>

122
ase/lib/awk/aseawk++.dsp Normal file
View File

@ -0,0 +1,122 @@
# Microsoft Developer Studio Project File - Name="aseawk++" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
CFG=aseawk++ - Win32 Release
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "aseawk++.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "aseawk++.mak" CFG="aseawk++ - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "aseawk++ - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "aseawk++ - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "aseawk++ - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "../release/lib"
# PROP Intermediate_Dir "release/cpp"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
MTL=midl.exe
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_UNICODE" /D "_USRDLL" /Yu"stdafx.h" /FD /c
# ADD CPP /nologo /MT /Za /W3 /GX /O2 /I "..\.." /D "NDEBUG" /D "WIN32" /D "_UNICODE" /FD /c
# SUBTRACT CPP /YX /Yc /Yu
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "aseawk++ - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "../debug/lib"
# PROP Intermediate_Dir "debug/cpp"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
MTL=midl.exe
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_UNICODE" /D "_USRDLL" /Yu"stdafx.h" /FD /GZ /c
# ADD CPP /nologo /MTd /Za /W3 /Gm /GX /ZI /Od /I "..\.." /D "_DEBUG" /D "WIN32" /D "_UNICODE" /FD /GZ /c
# SUBTRACT CPP /YX /Yc /Yu
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ENDIF
# Begin Target
# Name "aseawk++ - Win32 Release"
# Name "aseawk++ - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\Awk.cpp
# End Source File
# Begin Source File
SOURCE=.\StdAwk.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\Awk.hpp
# End Source File
# Begin Source File
SOURCE=.\StdAwk.hpp
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

376
ase/lib/awk/aseawk++.vcproj Normal file
View File

@ -0,0 +1,376 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="aseawk++"
ProjectGUID="{E7A8B741-4E9D-4ED4-9F77-E7F637A678A5}"
RootNamespace="aseawk++"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)\lib"
IntermediateDirectory="$(ConfigurationName)\cpp"
ConfigurationType="4"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\.."
PreprocessorDefinitions="_DEBUG;WIN32"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
DisableLanguageExtensions="true"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|x64"
OutputDirectory="$(SolutionDir)$(ConfigurationName)\lib"
IntermediateDirectory="$(ConfigurationName)\cpp"
ConfigurationType="4"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\.."
PreprocessorDefinitions="_DEBUG;WIN32"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
DisableLanguageExtensions="true"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)\lib"
IntermediateDirectory="$(ConfigurationName)\cpp"
ConfigurationType="4"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="..\.."
PreprocessorDefinitions="NDEBUG;WIN32"
StringPooling="true"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
DisableLanguageExtensions="true"
WarningLevel="3"
SuppressStartupBanner="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|x64"
OutputDirectory="$(SolutionDir)$(ConfigurationName)\lib"
IntermediateDirectory="$(ConfigurationName)\cpp"
ConfigurationType="4"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="..\.."
PreprocessorDefinitions="NDEBUG;WIN32"
StringPooling="true"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
DisableLanguageExtensions="true"
WarningLevel="3"
SuppressStartupBanner="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
RelativePath="Awk.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath=".\StdAwk.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl"
>
<File
RelativePath="Awk.hpp"
>
</File>
<File
RelativePath=".\StdAwk.hpp"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

275
ase/lib/awk/aseawk.bdsproj Normal file
View File

@ -0,0 +1,275 @@
<?xml version="1.0" encoding="utf-8"?>
<BorlandProject>
<PersonalityInfo>
<Option>
<Option Name="Personality">CPlusPlusBuilder.Personality</Option>
<Option Name="ProjectType">CppStaticLibrary</Option>
<Option Name="Version">1.0</Option>
<Option Name="GUID">{EDEF16CC-0C39-4E6B-A3CC-3DBF585BBD77}</Option>
</Option>
</PersonalityInfo>
<CPlusPlusBuilder.Personality>
<Source>
<Source Name="MainSource">awk.c</Source>
</Source>
<BCBPROJECT>
<project version="10.0">
<property category="build.config" name="active" value="0"/>
<property category="build.config" name="count" value="1"/>
<property category="build.config" name="excludedefaultforzero" value="0"/>
<property category="build.config.0" name="builddir" value="Debug"/>
<property category="build.config.0" name="key" value="Debug_Build"/>
<property category="build.config.0" name="name" value="Debug Build"/>
<property category="build.config.0" name="settings.win32b" value="default"/>
<property category="build.config.0" name="type" value="Toolset"/>
<property category="build.config.0" name="win32.win32b.builddir" value="debug"/>
<property category="build.config.1" name="key" value="Release_Build"/>
<property category="build.config.1" name="name" value="Release Build"/>
<property category="build.config.1" name="settings.win32b" value="default"/>
<property category="build.config.1" name="type" value="Toolset"/>
<property category="build.config.1" name="win32.win32b.builddir" value="release"/>
<property category="build.node" name="lastconfig" value="Debug_Build"/>
<property category="build.node" name="libraries" value="vcl.lib rtl.lib"/>
<property category="build.node" name="name" value="aseawk.lib"/>
<property category="build.node" name="packages" value="vclx;vcl;rtl;dbrtl;vcldb;adortl;dbxcds;dbexpress;xmlrtl;vclie;inet;inetdbbde;inetdbxpress;soaprtl;dsnap;bdertl;vcldbx"/>
<property category="build.node" name="sparelibs" value="rtl.lib vcl.lib"/>
<property category="build.node" name="use_packages" value="0"/>
<property category="build.platform" name="active" value="win32"/>
<property category="build.platform" name="win32.Debug_Build.toolset" value="win32b"/>
<property category="build.platform" name="win32.Release_Build.toolset" value="win32b"/>
<property category="build.platform" name="win32.config2.toolset" value="win32b"/>
<property category="build.platform" name="win32.default" value="win32b"/>
<property category="build.platform" name="win32.enabled" value="1"/>
<property category="build.platform" name="win32.win32b.enabled" value="1"/>
<property category="win32.*.win32b.dcc32" name="param.filenames.merge" value="1"/>
<property category="win32.*.win32b.tasm32" name="param.listfile.merge" value="1"/>
<property category="win32.*.win32b.tasm32" name="param.objfile.merge" value="1"/>
<property category="win32.*.win32b.tasm32" name="param.xreffile.merge" value="1"/>
<property category="win32.Debug_Build.win32b.bcc32" name="container.SelectedOptimizations.containerenabled" value="0"/>
<property category="win32.Debug_Build.win32b.bcc32" name="container.SelectedWarnings.containerenabled" value="1"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.D.arg.1" value="_DEBUG"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.D.arg.merge" value="1"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.D.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.Od.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.k.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.n.arg.1" value="debug"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.n.arg.merge" value="0"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.n.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.r.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.v.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.vG.enabled" value="0"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.vG0.enabled" value="0"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.vi.enabled" value="0"/>
<property category="win32.Debug_Build.win32b.bcc32" name="option.y.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.brcc32" name="option.16.enabled" value="0"/>
<property category="win32.Debug_Build.win32b.brcc32" name="option.31.enabled" value="0"/>
<property category="win32.Debug_Build.win32b.dcc32" name="option.$D.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.dcc32" name="option.$O.enabled" value="0"/>
<property category="win32.Debug_Build.win32b.dcc32" name="option.D.arg.1" value="DEBUG"/>
<property category="win32.Debug_Build.win32b.dcc32" name="option.D.arg.merge" value="1"/>
<property category="win32.Debug_Build.win32b.dcc32" name="option.D.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.dcc32" name="option.V.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.ilink32" name="option.D.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.ilink32" name="option.Gn.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.ilink32" name="option.L.arg.1" value="$(BDS)\lib\debug"/>
<property category="win32.Debug_Build.win32b.ilink32" name="option.L.arg.merge" value="1"/>
<property category="win32.Debug_Build.win32b.ilink32" name="option.L.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.ilink32" name="option.v.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.tasm32" name="option.z.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.tasm32" name="option.zd.enabled" value="0"/>
<property category="win32.Debug_Build.win32b.tasm32" name="option.zi.enabled" value="1"/>
<property category="win32.Debug_Build.win32b.tlib" name="option.E.enabled" value="0"/>
<property category="win32.Debug_Build.win32b.tlib" name="option.outputdir.arg.1" value="..\debug\lib"/>
<property category="win32.Debug_Build.win32b.tlib" name="option.outputdir.arg.merge" value="0"/>
<property category="win32.Debug_Build.win32b.tlib" name="option.outputdir.enabled" value="1"/>
<property category="win32.Release_Build.win32b.bcc32" name="option.D.arg.1" value="NDEBUG"/>
<property category="win32.Release_Build.win32b.bcc32" name="option.D.arg.merge" value="1"/>
<property category="win32.Release_Build.win32b.bcc32" name="option.D.enabled" value="1"/>
<property category="win32.Release_Build.win32b.bcc32" name="option.O2.enabled" value="1"/>
<property category="win32.Release_Build.win32b.bcc32" name="option.k.enabled" value="0"/>
<property category="win32.Release_Build.win32b.bcc32" name="option.n.arg.1" value="release"/>
<property category="win32.Release_Build.win32b.bcc32" name="option.n.arg.merge" value="0"/>
<property category="win32.Release_Build.win32b.bcc32" name="option.n.enabled" value="1"/>
<property category="win32.Release_Build.win32b.bcc32" name="option.r.enabled" value="1"/>
<property category="win32.Release_Build.win32b.bcc32" name="option.vi.enabled" value="1"/>
<property category="win32.Release_Build.win32b.dcc32" name="option.$D.enabled" value="0"/>
<property category="win32.Release_Build.win32b.dcc32" name="option.$O.enabled" value="1"/>
<property category="win32.Release_Build.win32b.dcc32" name="option.V.enabled" value="0"/>
<property category="win32.Release_Build.win32b.ilink32" name="option.L.arg.1" value="$(BDS)\lib\release"/>
<property category="win32.Release_Build.win32b.ilink32" name="option.L.arg.merge" value="1"/>
<property category="win32.Release_Build.win32b.ilink32" name="option.L.enabled" value="1"/>
<property category="win32.Release_Build.win32b.tasm32" name="option.z.enabled" value="0"/>
<property category="win32.Release_Build.win32b.tasm32" name="option.zd.enabled" value="0"/>
<property category="win32.Release_Build.win32b.tasm32" name="option.zi.enabled" value="0"/>
<property category="win32.Release_Build.win32b.tasm32" name="option.zn.enabled" value="1"/>
<property category="win32.Release_Build.win32b.tlib" name="option.outputdir.arg.1" value="..\release\lib"/>
<property category="win32.Release_Build.win32b.tlib" name="option.outputdir.arg.merge" value="0"/>
<property category="win32.Release_Build.win32b.tlib" name="option.outputdir.enabled" value="1"/>
<optionset name="all_configurations">
<property category="node" name="displayname" value="All Configurations"/>
<property category="win32.*.win32b.bcc32" name="container.SelectedOptimizations.containerenabled" value="1"/>
<property category="win32.*.win32b.bcc32" name="container.SelectedWarnings.containerenabled" value="1"/>
<property category="win32.*.win32b.bcc32" name="option.4.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.5.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.6.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.A.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.AK.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.AU.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.H=.arg.1" value="$(BDS)\lib\vcl100.csm"/>
<property category="win32.*.win32b.bcc32" name="option.H=.arg.merge" value="1"/>
<property category="win32.*.win32b.bcc32" name="option.H=.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.Hc.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.He.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.Hs.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.I.arg.1" value="..\.."/>
<property category="win32.*.win32b.bcc32" name="option.I.arg.2" value="$(BDS)\include"/>
<property category="win32.*.win32b.bcc32" name="option.I.arg.3" value="$(BDS)\include\dinkumware"/>
<property category="win32.*.win32b.bcc32" name="option.I.arg.4" value="$(BDS)\include\vcl"/>
<property category="win32.*.win32b.bcc32" name="option.I.arg.merge" value="1"/>
<property category="win32.*.win32b.bcc32" name="option.I.enabled" value="1"/>
<property category="win32.*.win32b.bcc32" name="option.Jgi.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.Jgx.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.O1.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.O2.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.Od.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.V0.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.V1.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.Vmd.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.Vmm.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.Vms.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.align-1.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.align-2.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.align-3.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.align-5.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.b.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.disablewarns.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.noregistervars.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.p.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.pm.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.pr.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.ps.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.rd.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.sysdefines.arg.1" value="_RTLDLL"/>
<property category="win32.*.win32b.bcc32" name="option.sysdefines.arg.2" value="NO_STRICT"/>
<property category="win32.*.win32b.bcc32" name="option.sysdefines.arg.merge" value="1"/>
<property category="win32.*.win32b.bcc32" name="option.sysdefines.enabled" value="1"/>
<property category="win32.*.win32b.bcc32" name="option.tW.enabled" value="1"/>
<property category="win32.*.win32b.bcc32" name="option.tWC.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.tWD.enabled" value="0"/>
<property category="win32.*.win32b.bcc32" name="option.tWM.enabled" value="1"/>
<property category="win32.*.win32b.bcc32" name="option.w.enabled" value="0"/>
<property category="win32.*.win32b.dcc32" name="option.I.arg.1" value="C:\projects\ase\awk"/>
<property category="win32.*.win32b.dcc32" name="option.I.arg.merge" value="1"/>
<property category="win32.*.win32b.dcc32" name="option.I.enabled" value="0"/>
<property category="win32.*.win32b.dcc32" name="option.O.arg.1" value="C:\projects\ase\awk"/>
<property category="win32.*.win32b.dcc32" name="option.O.arg.merge" value="1"/>
<property category="win32.*.win32b.dcc32" name="option.O.enabled" value="0"/>
<property category="win32.*.win32b.dcc32" name="option.R.arg.1" value="C:\projects\ase\awk"/>
<property category="win32.*.win32b.dcc32" name="option.R.arg.merge" value="1"/>
<property category="win32.*.win32b.dcc32" name="option.R.enabled" value="0"/>
<property category="win32.*.win32b.dcc32" name="option.U.arg.1" value="C:\projects\ase\awk"/>
<property category="win32.*.win32b.dcc32" name="option.U.arg.2" value="C:\Documents and Settings\evi\My Documents\Borland Studio Projects"/>
<property category="win32.*.win32b.dcc32" name="option.U.arg.3" value="$(BDS)\lib"/>
<property category="win32.*.win32b.dcc32" name="option.U.arg.4" value="$(BDS)\lib\obj"/>
<property category="win32.*.win32b.dcc32" name="option.U.arg.merge" value="1"/>
<property category="win32.*.win32b.dcc32" name="option.U.enabled" value="1"/>
<property category="win32.*.win32b.dcc32" name="param.filenames.merge" value="1"/>
<property category="win32.*.win32b.idl2cpp" name="option.I.arg.1" value="C:\projects\ase\awk"/>
<property category="win32.*.win32b.idl2cpp" name="option.I.arg.merge" value="1"/>
<property category="win32.*.win32b.idl2cpp" name="option.I.enabled" value="1"/>
<property category="win32.*.win32b.ilink32" name="option.Gi.enabled" value="0"/>
<property category="win32.*.win32b.ilink32" name="option.L.arg.1" value="$(BDS)\lib"/>
<property category="win32.*.win32b.ilink32" name="option.L.arg.2" value="$(BDS)\lib\obj"/>
<property category="win32.*.win32b.ilink32" name="option.L.arg.3" value="$(BDS)\lib\psdk"/>
<property category="win32.*.win32b.ilink32" name="option.L.arg.merge" value="1"/>
<property category="win32.*.win32b.ilink32" name="option.L.enabled" value="1"/>
<property category="win32.*.win32b.ilink32" name="option.Tpd.enabled" value="0"/>
<property category="win32.*.win32b.ilink32" name="option.Tpe.enabled" value="0"/>
<property category="win32.*.win32b.ilink32" name="option.Tpp.enabled" value="0"/>
<property category="win32.*.win32b.ilink32" name="option.aa.enabled" value="0"/>
<property category="win32.*.win32b.ilink32" name="option.ap.enabled" value="0"/>
<property category="win32.*.win32b.ilink32" name="option.dynamicrtl.enabled" value="1"/>
<property category="win32.*.win32b.tlib" name="option.E.enabled" value="1"/>
<property category="win32.*.win32b.tlib" name="option.dynamicrtl.enabled" value="0"/>
<property category="win32.*.win32b.tlib" name="option.outputdir.arg.merge" value="1"/>
<property category="win32.*.win32b.tlib" name="option.outputdir.enabled" value="0"/>
</optionset>
</project>
<FILELIST>
<FILE FILENAME="awk.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="awk" FORMNAME="" DESIGNCLASS=""/>
<FILE FILENAME="err.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="err" FORMNAME="" DESIGNCLASS=""/>
<FILE FILENAME="extio.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="extio" FORMNAME="" DESIGNCLASS=""/>
<FILE FILENAME="func.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="func" FORMNAME="" DESIGNCLASS=""/>
<FILE FILENAME="misc.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="misc" FORMNAME="" DESIGNCLASS=""/>
<FILE FILENAME="parse.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="parse" FORMNAME="" DESIGNCLASS=""/>
<FILE FILENAME="rec.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="rec" FORMNAME="" DESIGNCLASS=""/>
<FILE FILENAME="rex.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="rex" FORMNAME="" DESIGNCLASS=""/>
<FILE FILENAME="run.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="run" FORMNAME="" DESIGNCLASS=""/>
<FILE FILENAME="tab.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="tab" FORMNAME="" DESIGNCLASS=""/>
<FILE FILENAME="tree.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="tree" FORMNAME="" DESIGNCLASS=""/>
<FILE FILENAME="val.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="val" FORMNAME="" DESIGNCLASS=""/>
</FILELIST>
<IDEOPTIONS>
<VersionInfo>
<VersionInfo Name="IncludeVerInfo">False</VersionInfo>
<VersionInfo Name="AutoIncBuild">False</VersionInfo>
<VersionInfo Name="MajorVer">1</VersionInfo>
<VersionInfo Name="MinorVer">0</VersionInfo>
<VersionInfo Name="Release">0</VersionInfo>
<VersionInfo Name="Build">0</VersionInfo>
<VersionInfo Name="Debug">False</VersionInfo>
<VersionInfo Name="PreRelease">False</VersionInfo>
<VersionInfo Name="Special">False</VersionInfo>
<VersionInfo Name="Private">False</VersionInfo>
<VersionInfo Name="DLL">False</VersionInfo>
<VersionInfo Name="Locale">1033</VersionInfo>
<VersionInfo Name="CodePage">1252</VersionInfo>
</VersionInfo>
<VersionInfoKeys>
<VersionInfoKeys Name="CompanyName"></VersionInfoKeys>
<VersionInfoKeys Name="FileDescription"></VersionInfoKeys>
<VersionInfoKeys Name="FileVersion">1.0.0.0</VersionInfoKeys>
<VersionInfoKeys Name="InternalName"></VersionInfoKeys>
<VersionInfoKeys Name="LegalCopyright"></VersionInfoKeys>
<VersionInfoKeys Name="LegalTrademarks"></VersionInfoKeys>
<VersionInfoKeys Name="OriginalFilename"></VersionInfoKeys>
<VersionInfoKeys Name="ProductName"></VersionInfoKeys>
<VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys>
<VersionInfoKeys Name="Comments"></VersionInfoKeys>
</VersionInfoKeys>
<Debugging>
<Debugging Name="DebugSourceDirs"></Debugging>
</Debugging>
<Parameters>
<Parameters Name="RunParams"></Parameters>
<Parameters Name="Launcher"></Parameters>
<Parameters Name="UseLauncher">False</Parameters>
<Parameters Name="DebugCWD"></Parameters>
<Parameters Name="HostApplication"></Parameters>
<Parameters Name="RemoteHost"></Parameters>
<Parameters Name="RemotePath"></Parameters>
<Parameters Name="RemoteParams"></Parameters>
<Parameters Name="RemoteLauncher"></Parameters>
<Parameters Name="UseRemoteLauncher">False</Parameters>
<Parameters Name="RemoteCWD"></Parameters>
<Parameters Name="RemoteDebug">False</Parameters>
<Parameters Name="Debug Symbols Search Path"></Parameters>
<Parameters Name="LoadAllSymbols">True</Parameters>
<Parameters Name="LoadUnspecifiedSymbols">False</Parameters>
</Parameters>
<Linker>
<Linker Name="LibPrefix"></Linker>
<Linker Name="LibSuffix"></Linker>
<Linker Name="LibVersion"></Linker>
</Linker>
</IDEOPTIONS>
</BCBPROJECT>
<buildevents>
<buildevent file="aseawk.bdsproj">
<precompile mode="0" cancancel="0" capture="-1" showconsole="0">mkdir $(PROJECTDIR)..\release\lib
mkdir $(PROJECTDIR)..\debug\lib
</precompile>
</buildevent>
</buildevents>
</CPlusPlusBuilder.Personality>
</BorlandProject>

186
ase/lib/awk/aseawk.dsp Normal file
View File

@ -0,0 +1,186 @@
# Microsoft Developer Studio Project File - Name="aseawk" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
CFG=aseawk - Win32 Release
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "aseawk.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "aseawk.mak" CFG="aseawk - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "aseawk - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "aseawk - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "aseawk - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "../release/lib"
# PROP Intermediate_Dir "release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
MTL=midl.exe
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_UNICODE" /D "_USRDLL" /Yu"stdafx.h" /FD /c
# ADD CPP /nologo /MT /Za /W3 /GX /O2 /I "..\.." /D "NDEBUG" /D "WIN32" /D "_UNICODE" /FD /c
# SUBTRACT CPP /YX /Yc /Yu
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "aseawk - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "../debug/lib"
# PROP Intermediate_Dir "debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
MTL=midl.exe
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_UNICODE" /D "_USRDLL" /Yu"stdafx.h" /FD /GZ /c
# ADD CPP /nologo /MTd /Za /W3 /Gm /GX /ZI /Od /I "..\.." /D "_DEBUG" /D "WIN32" /D "_UNICODE" /FD /GZ /c
# SUBTRACT CPP /YX /Yc /Yu
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ENDIF
# Begin Target
# Name "aseawk - Win32 Release"
# Name "aseawk - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\awk.c
# End Source File
# Begin Source File
SOURCE=.\err.c
# End Source File
# Begin Source File
SOURCE=.\extio.c
# End Source File
# Begin Source File
SOURCE=.\func.c
# End Source File
# Begin Source File
SOURCE=.\misc.c
# End Source File
# Begin Source File
SOURCE=.\parse.c
# End Source File
# Begin Source File
SOURCE=.\rec.c
# End Source File
# Begin Source File
SOURCE=.\run.c
# End Source File
# Begin Source File
SOURCE=.\tab.c
# End Source File
# Begin Source File
SOURCE=.\tree.c
# End Source File
# Begin Source File
SOURCE=.\val.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\awk.h
# End Source File
# Begin Source File
SOURCE=.\awk_i.h
# End Source File
# Begin Source File
SOURCE=.\extio.h
# End Source File
# Begin Source File
SOURCE=.\func.h
# End Source File
# Begin Source File
SOURCE=.\parse.h
# End Source File
# Begin Source File
SOURCE=.\run.h
# End Source File
# Begin Source File
SOURCE=.\tab.h
# End Source File
# Begin Source File
SOURCE=.\tree.h
# End Source File
# Begin Source File
SOURCE=.\val.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

800
ase/lib/awk/aseawk.vcproj Normal file
View File

@ -0,0 +1,800 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="aseawk"
ProjectGUID="{5F2E77D5-1485-48D1-9371-987BC55FEE83}"
RootNamespace="aseawk"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)\lib"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="..\.."
PreprocessorDefinitions="NDEBUG;WIN32"
StringPooling="true"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
DisableLanguageExtensions="true"
WarningLevel="3"
SuppressStartupBanner="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|x64"
OutputDirectory="$(SolutionDir)$(ConfigurationName)\lib"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="..\.."
PreprocessorDefinitions="NDEBUG;WIN32"
StringPooling="true"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
DisableLanguageExtensions="true"
WarningLevel="3"
SuppressStartupBanner="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)\lib"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\.."
PreprocessorDefinitions="_DEBUG;WIN32"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
DisableLanguageExtensions="true"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|x64"
OutputDirectory="$(SolutionDir)$(ConfigurationName)\lib"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\.."
PreprocessorDefinitions="_DEBUG;WIN32"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
DisableLanguageExtensions="true"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
RelativePath="awk.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="err.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="extio.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="func.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="misc.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="parse.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="rec.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="run.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="tab.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="tree.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="val.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl"
>
<File
RelativePath="awk.h"
>
</File>
<File
RelativePath="awk_i.h"
>
</File>
<File
RelativePath="extio.h"
>
</File>
<File
RelativePath="func.h"
>
</File>
<File
RelativePath="parse.h"
>
</File>
<File
RelativePath="run.h"
>
</File>
<File
RelativePath="tab.h"
>
</File>
<File
RelativePath="tree.h"
>
</File>
<File
RelativePath="val.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

113
ase/lib/awk/aseawk_jni.dsp Normal file
View File

@ -0,0 +1,113 @@
# Microsoft Developer Studio Project File - Name="aseawk_jni" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
CFG=aseawk_jni - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "aseawk_jni.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "aseawk_jni.mak" CFG="aseawk_jni - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "aseawk_jni - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "aseawk_jni - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "aseawk_jni - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "../release/lib"
# PROP Intermediate_Dir "release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "JNI_EXPORTS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\.." /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_UNICODE" /D "_USRDLL" /FD /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
# ADD LINK32 asecmn.lib aseawk.lib aseutl.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /implib:"release/aseawk_jni.lib" /libpath:"$(OutDir)"
!ELSEIF "$(CFG)" == "aseawk_jni - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "../debug/lib"
# PROP Intermediate_Dir "debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "JNI_EXPORTS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\.." /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_UNICODE" /D "_USRDLL" /FD /GZ /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
# ADD LINK32 asecmn.lib aseawk.lib aseutl.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /implib:"debug/aseawk_jni.lib" /pdbtype:sept /libpath:"$(OutDir)"
!ENDIF
# Begin Target
# Name "aseawk_jni - Win32 Release"
# Name "aseawk_jni - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\jni.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\jni.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

View File

@ -0,0 +1,442 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="aseawk_jni"
ProjectGUID="{23B58791-FD44-4F95-9F77-34E4AF45A296}"
RootNamespace="aseawk_jni"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)\lib"
IntermediateDirectory="$(ConfigurationName)\jni"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="NDEBUG"
MkTypLibCompatible="true"
SuppressStartupBanner="true"
TargetEnvironment="1"
TypeLibraryName=".\../release/lib/aseawk_jni.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="..\..,$(JAVA_HOME)\include,$(JAVA_HOME)\include\win32"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL"
StringPooling="true"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
WarningLevel="3"
SuppressStartupBanner="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="asecmn.lib aseawk.lib aseutl.lib odbc32.lib odbccp32.lib"
OutputFile="$(OutDir)\aseawk_jni.dll"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="$(OutDir)"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|x64"
OutputDirectory="$(SolutionDir)$(ConfigurationName)\lib"
IntermediateDirectory="$(ConfigurationName)\jni"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="NDEBUG"
MkTypLibCompatible="true"
SuppressStartupBanner="true"
TargetEnvironment="3"
TypeLibraryName=".\../release/lib/aseawk_jni.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="..\..,$(JAVA_HOME)\include,$(JAVA_HOME)\include\win32"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL"
StringPooling="true"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
WarningLevel="3"
SuppressStartupBanner="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="asecmn.lib aseawk.lib aseutl.lib odbc32.lib odbccp32.lib"
OutputFile="$(OutDir)\aseawk_jni.dll"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="$(OutDir)"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)\lib"
IntermediateDirectory="$(ConfigurationName)\jni"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="_DEBUG"
MkTypLibCompatible="true"
SuppressStartupBanner="true"
TargetEnvironment="1"
TypeLibraryName=".\../debug/lib/aseawk_jni.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..,$(JAVA_HOME)\include,$(JAVA_HOME)\include\win32"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="asecmn.lib aseawk.lib aseutl.lib odbc32.lib odbccp32.lib"
OutputFile="$(OutDir)\aseawk_jni.dll"
LinkIncremental="2"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="$(OutDir)"
GenerateDebugInformation="true"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|x64"
OutputDirectory="$(SolutionDir)$(ConfigurationName)\lib"
IntermediateDirectory="$(ConfigurationName)\jni"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="_DEBUG"
MkTypLibCompatible="true"
SuppressStartupBanner="true"
TargetEnvironment="3"
TypeLibraryName=".\../debug/lib/aseawk_jni.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..,$(JAVA_HOME)\include,$(JAVA_HOME)\include\win32"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="asecmn.lib aseawk.lib aseutl.lib odbc32.lib odbccp32.lib"
OutputFile="$(OutDir)\aseawk_jni.dll"
LinkIncremental="2"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="$(OutDir)"
GenerateDebugInformation="true"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
RelativePath="jni.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl"
>
<File
RelativePath="jni.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

513
ase/lib/awk/awk.c Normal file
View File

@ -0,0 +1,513 @@
/*
* $Id: awk.c 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
#if defined(__BORLANDC__)
#pragma hdrstop
#define Library
#endif
#include <ase/awk/awk_i.h>
static void free_word (void* awk, void* ptr);
static void free_afn (void* awk, void* afn);
static void free_bfn (void* awk, void* afn);
#define SETERR(awk,code) ase_awk_seterrnum(awk,code)
#define SETERRARG(awk,code,line,arg,leng) \
do { \
ase_cstr_t errarg; \
errarg.len = (leng); \
errarg.ptr = (arg); \
ase_awk_seterror ((awk), (code), (line), &errarg, 1); \
} while (0)
ase_awk_t* ase_awk_open (const ase_awk_prmfns_t* prmfns, void* custom_data)
{
ase_awk_t* awk;
ASE_ASSERT (prmfns != ASE_NULL);
ASE_ASSERT (prmfns->mmgr.malloc != ASE_NULL &&
prmfns->mmgr.free != ASE_NULL);
ASE_ASSERT (prmfns->ccls.is_upper != ASE_NULL &&
prmfns->ccls.is_lower != ASE_NULL &&
prmfns->ccls.is_alpha != ASE_NULL &&
prmfns->ccls.is_digit != ASE_NULL &&
prmfns->ccls.is_xdigit != ASE_NULL &&
prmfns->ccls.is_alnum != ASE_NULL &&
prmfns->ccls.is_space != ASE_NULL &&
prmfns->ccls.is_print != ASE_NULL &&
prmfns->ccls.is_graph != ASE_NULL &&
prmfns->ccls.is_cntrl != ASE_NULL &&
prmfns->ccls.is_punct != ASE_NULL &&
prmfns->ccls.to_upper != ASE_NULL &&
prmfns->ccls.to_lower != ASE_NULL);
ASE_ASSERT (prmfns->misc.pow != ASE_NULL &&
prmfns->misc.sprintf != ASE_NULL &&
prmfns->misc.dprintf != ASE_NULL);
/* use ASE_MALLOC instead of ASE_AWK_MALLOC because
* the awk object has not been initialized yet */
awk = ASE_MALLOC (&prmfns->mmgr, ASE_SIZEOF(ase_awk_t));
if (awk == ASE_NULL) return ASE_NULL;
/* it uses the built-in ase_awk_memset because awk is not
* fully initialized yet */
ase_memset (awk, 0, ASE_SIZEOF(ase_awk_t));
ase_memcpy (&awk->prmfns, prmfns, ASE_SIZEOF(awk->prmfns));
if (ase_str_open (
&awk->token.name, 128, &awk->prmfns.mmgr) == ASE_NULL)
{
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
awk->wtab = ase_map_open (
awk, 512, 70, free_word, ASE_NULL, &awk->prmfns.mmgr);
if (awk->wtab == ASE_NULL)
{
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
awk->rwtab = ase_map_open (
awk, 512, 70, free_word, ASE_NULL, &awk->prmfns.mmgr);
if (awk->rwtab == ASE_NULL)
{
ase_map_close (awk->wtab);
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
/* TODO: initial map size?? */
awk->tree.afns = ase_map_open (
awk, 512, 70, free_afn, ASE_NULL, &awk->prmfns.mmgr);
if (awk->tree.afns == ASE_NULL)
{
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
awk->parse.afns = ase_map_open (
awk, 256, 70, ASE_NULL, ASE_NULL, &awk->prmfns.mmgr);
if (awk->parse.afns == ASE_NULL)
{
ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
awk->parse.named = ase_map_open (
awk, 256, 70, ASE_NULL, ASE_NULL, &awk->prmfns.mmgr);
if (awk->parse.named == ASE_NULL)
{
ase_map_close (awk->parse.afns);
ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
if (ase_awk_tab_open (&awk->parse.globals, awk) == ASE_NULL)
{
ase_map_close (awk->parse.named);
ase_map_close (awk->parse.afns);
ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
if (ase_awk_tab_open (&awk->parse.locals, awk) == ASE_NULL)
{
ase_awk_tab_close (&awk->parse.globals);
ase_map_close (awk->parse.named);
ase_map_close (awk->parse.afns);
ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
if (ase_awk_tab_open (&awk->parse.params, awk) == ASE_NULL)
{
ase_awk_tab_close (&awk->parse.locals);
ase_awk_tab_close (&awk->parse.globals);
ase_map_close (awk->parse.named);
ase_map_close (awk->parse.afns);
ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
awk->option = 0;
awk->errnum = ASE_AWK_ENOERR;
awk->errlin = 0;
awk->stopall = ase_false;
awk->parse.nlocals_max = 0;
awk->tree.nglobals = 0;
awk->tree.nbglobals = 0;
awk->tree.begin = ASE_NULL;
awk->tree.begin_tail = ASE_NULL;
awk->tree.end = ASE_NULL;
awk->tree.end_tail = ASE_NULL;
awk->tree.chain = ASE_NULL;
awk->tree.chain_tail = ASE_NULL;
awk->tree.chain_size = 0;
awk->token.prev.type = 0;
awk->token.prev.line = 0;
awk->token.prev.column = 0;
awk->token.type = 0;
awk->token.line = 0;
awk->token.column = 0;
awk->src.lex.curc = ASE_CHAR_EOF;
awk->src.lex.ungotc_count = 0;
awk->src.lex.line = 1;
awk->src.lex.column = 1;
awk->src.shared.buf_pos = 0;
awk->src.shared.buf_len = 0;
awk->bfn.sys = ASE_NULL;
/*awk->bfn.user = ASE_NULL;*/
awk->bfn.user = ase_map_open (
awk, 512, 70, free_bfn, ASE_NULL, &awk->prmfns.mmgr);
if (awk->bfn.user == ASE_NULL)
{
ase_awk_tab_close (&awk->parse.params);
ase_awk_tab_close (&awk->parse.locals);
ase_awk_tab_close (&awk->parse.globals);
ase_map_close (awk->parse.named);
ase_map_close (awk->parse.afns);
ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
awk->parse.depth.cur.block = 0;
awk->parse.depth.cur.loop = 0;
awk->parse.depth.cur.expr = 0;
ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_BLOCK_PARSE, 0);
ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_BLOCK_RUN, 0);
ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_EXPR_PARSE, 0);
ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_EXPR_RUN, 0);
ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_REX_BUILD, 0);
ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_REX_MATCH, 0);
awk->custom_data = custom_data;
if (ase_awk_initglobals (awk) == -1)
{
ase_map_close (awk->bfn.user);
ase_awk_tab_close (&awk->parse.params);
ase_awk_tab_close (&awk->parse.locals);
ase_awk_tab_close (&awk->parse.globals);
ase_map_close (awk->parse.named);
ase_map_close (awk->parse.afns);
ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
return awk;
}
static void free_word (void* owner, void* ptr)
{
ASE_AWK_FREE ((ase_awk_t*)owner, ptr);
}
static void free_afn (void* owner, void* afn)
{
ase_awk_afn_t* f = (ase_awk_afn_t*)afn;
/* f->name doesn't have to be freed */
/*ASE_AWK_FREE ((ase_awk_t*)owner, f->name);*/
ase_awk_clrpt ((ase_awk_t*)owner, f->body);
ASE_AWK_FREE ((ase_awk_t*)owner, f);
}
static void free_bfn (void* owner, void* bfn)
{
ase_awk_bfn_t* f = (ase_awk_bfn_t*)bfn;
ASE_AWK_FREE ((ase_awk_t*)owner, f);
}
int ase_awk_close (ase_awk_t* awk)
{
ase_size_t i;
if (ase_awk_clear (awk) == -1) return -1;
/*ase_awk_clrbfn (awk);*/
ase_map_close (awk->bfn.user);
ase_awk_tab_close (&awk->parse.params);
ase_awk_tab_close (&awk->parse.locals);
ase_awk_tab_close (&awk->parse.globals);
ase_map_close (awk->parse.named);
ase_map_close (awk->parse.afns);
ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_close (&awk->token.name);
for (i = 0; i < ASE_COUNTOF(awk->errstr); i++)
{
if (awk->errstr[i] != ASE_NULL)
{
ASE_AWK_FREE (awk, awk->errstr[i]);
awk->errstr[i] = ASE_NULL;
}
}
/* ASE_AWK_ALLOC, ASE_AWK_FREE, etc can not be used
* from the next line onwards */
ASE_AWK_FREE (awk, awk);
return 0;
}
int ase_awk_clear (ase_awk_t* awk)
{
awk->stopall = ase_false;
ase_memset (&awk->src.ios, 0, ASE_SIZEOF(awk->src.ios));
awk->src.lex.curc = ASE_CHAR_EOF;
awk->src.lex.ungotc_count = 0;
awk->src.lex.line = 1;
awk->src.lex.column = 1;
awk->src.shared.buf_pos = 0;
awk->src.shared.buf_len = 0;
/*ase_awk_tab_clear (&awk->parse.globals);*/
ASE_ASSERT (awk->parse.globals.size == awk->tree.nglobals);
ase_awk_tab_remove (
&awk->parse.globals, awk->tree.nbglobals,
awk->parse.globals.size - awk->tree.nbglobals);
ase_awk_tab_clear (&awk->parse.locals);
ase_awk_tab_clear (&awk->parse.params);
ase_map_clear (awk->parse.named);
ase_map_clear (awk->parse.afns);
awk->parse.nlocals_max = 0;
awk->parse.depth.cur.block = 0;
awk->parse.depth.cur.loop = 0;
awk->parse.depth.cur.expr = 0;
/* clear parse trees */
awk->tree.ok = 0;
/*awk->tree.nbglobals = 0;
awk->tree.nglobals = 0; */
awk->tree.nglobals = awk->tree.nbglobals;
awk->tree.cur_afn.ptr = ASE_NULL;
awk->tree.cur_afn.len = 0;
ase_map_clear (awk->tree.afns);
if (awk->tree.begin != ASE_NULL)
{
ase_awk_nde_t* next = awk->tree.begin->next;
/*ASE_ASSERT (awk->tree.begin->next == ASE_NULL);*/
ase_awk_clrpt (awk, awk->tree.begin);
awk->tree.begin = ASE_NULL;
awk->tree.begin_tail = ASE_NULL;
}
if (awk->tree.end != ASE_NULL)
{
/*ASE_ASSERT (awk->tree.end->next == ASE_NULL);*/
ase_awk_clrpt (awk, awk->tree.end);
awk->tree.end = ASE_NULL;
awk->tree.end_tail = ASE_NULL;
}
while (awk->tree.chain != ASE_NULL)
{
ase_awk_chain_t* next = awk->tree.chain->next;
if (awk->tree.chain->pattern != ASE_NULL)
ase_awk_clrpt (awk, awk->tree.chain->pattern);
if (awk->tree.chain->action != ASE_NULL)
ase_awk_clrpt (awk, awk->tree.chain->action);
ASE_AWK_FREE (awk, awk->tree.chain);
awk->tree.chain = next;
}
awk->tree.chain_tail = ASE_NULL;
awk->tree.chain_size = 0;
return 0;
}
int ase_awk_getoption (ase_awk_t* awk)
{
return awk->option;
}
void ase_awk_setoption (ase_awk_t* awk, int opt)
{
awk->option = opt;
}
ase_mmgr_t* ase_awk_getmmgr (ase_awk_t* awk)
{
return &awk->prmfns.mmgr;
}
void* ase_awk_getcustomdata (ase_awk_t* awk)
{
return awk->custom_data;
}
void ase_awk_stopall (ase_awk_t* awk)
{
awk->stopall = ase_true;
}
int ase_awk_getword (ase_awk_t* awk,
const ase_char_t* okw, ase_size_t olen,
const ase_char_t** nkw, ase_size_t* nlen)
{
ase_pair_t* p;
p = ase_map_get (awk->wtab, okw, olen);
if (p == ASE_NULL) return -1;
*nkw = ((ase_cstr_t*)p->val)->ptr;
*nlen = ((ase_cstr_t*)p->val)->len;
return 0;
}
int ase_awk_setword (ase_awk_t* awk,
const ase_char_t* okw, ase_size_t olen,
const ase_char_t* nkw, ase_size_t nlen)
{
ase_cstr_t* vn, * vo;
if (nkw == ASE_NULL || nlen == 0)
{
ase_pair_t* p;
if (okw == ASE_NULL || olen == 0)
{
/* clear the entire table */
ase_map_clear (awk->wtab);
ase_map_clear (awk->rwtab);
return 0;
}
/* delete the word */
p = ase_map_get (awk->wtab, okw, olen);
if (p != ASE_NULL)
{
ase_cstr_t* s = (ase_cstr_t*)p->val;
ase_map_remove (awk->rwtab, s->ptr, s->len);
ase_map_remove (awk->wtab, okw, olen);
return 0;
}
else
{
SETERRARG (awk, ASE_AWK_ENOENT, 0, okw, olen);
return -1;
}
}
else if (okw == ASE_NULL || olen == 0)
{
SETERR (awk, ASE_AWK_EINVAL);
return -1;
}
/* set the word */
vn = (ase_cstr_t*) ASE_AWK_MALLOC (
awk, ASE_SIZEOF(ase_cstr_t)+((nlen+1)*ASE_SIZEOF(*nkw)));
if (vn == ASE_NULL)
{
SETERR (awk, ASE_AWK_ENOMEM);
return -1;
}
vn->len = nlen;
vn->ptr = (const ase_char_t*)(vn + 1);
ase_strncpy ((ase_char_t*)vn->ptr, nkw, nlen);
vo = (ase_cstr_t*)ASE_AWK_MALLOC (
awk, ASE_SIZEOF(ase_cstr_t)+((olen+1)*ASE_SIZEOF(*okw)));
if (vo == ASE_NULL)
{
ASE_AWK_FREE (awk, vn);
SETERR (awk, ASE_AWK_ENOMEM);
return -1;
}
vo->len = olen;
vo->ptr = (const ase_char_t*)(vo + 1);
ase_strncpy ((ase_char_t*)vo->ptr, okw, olen);
if (ase_map_put (awk->wtab, okw, olen, vn) == ASE_NULL)
{
ASE_AWK_FREE (awk, vo);
ASE_AWK_FREE (awk, vn);
SETERR (awk, ASE_AWK_ENOMEM);
return -1;
}
if (ase_map_put (awk->rwtab, nkw, nlen, vo) == ASE_NULL)
{
ase_map_remove (awk->wtab, okw, olen);
ASE_AWK_FREE (awk, vo);
SETERR (awk, ASE_AWK_ENOMEM);
return -1;
}
return 0;
}
int ase_awk_setrexfns (ase_awk_t* awk, ase_awk_rexfns_t* rexfns)
{
if (rexfns->build == ASE_NULL ||
rexfns->match == ASE_NULL ||
rexfns->free == ASE_NULL ||
rexfns->isempty == ASE_NULL)
{
SETERR (awk, ASE_AWK_EINVAL);
return -1;
}
awk->rexfns = rexfns;
return 0;
}

674
ase/lib/awk/awk.h Normal file
View File

@ -0,0 +1,674 @@
/*
* $Id: awk.h 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
#ifndef _ASE_AWK_AWK_H_
#define _ASE_AWK_AWK_H_
/**
* @file awk.h
* @brief Primary header file for the engine
*
* This file defines most of the data types and functions required to embed
* the interpreter engine.
*/
#include <ase/cmn/types.h>
#include <ase/cmn/macros.h>
#include <ase/cmn/map.h>
typedef struct ase_awk_t ase_awk_t;
typedef struct ase_awk_run_t ase_awk_run_t;
typedef struct ase_awk_val_t ase_awk_val_t;
typedef struct ase_awk_extio_t ase_awk_extio_t;
typedef struct ase_awk_prmfns_t ase_awk_prmfns_t;
typedef struct ase_awk_srcios_t ase_awk_srcios_t;
typedef struct ase_awk_runios_t ase_awk_runios_t;
typedef struct ase_awk_runcbs_t ase_awk_runcbs_t;
typedef struct ase_awk_runarg_t ase_awk_runarg_t;
typedef struct ase_awk_rexfns_t ase_awk_rexfns_t;
typedef ase_real_t (*ase_awk_pow_t) (void* custom, ase_real_t x, ase_real_t y);
typedef int (*ase_awk_sprintf_t) (
void* custom, ase_char_t* buf, ase_size_t size,
const ase_char_t* fmt, ...);
typedef void (*ase_awk_dprintf_t) (void* custom, const ase_char_t* fmt, ...);
typedef ase_ssize_t (*ase_awk_io_t) (
int cmd, void* arg, ase_char_t* data, ase_size_t count);
struct ase_awk_extio_t
{
ase_awk_run_t* run; /* [IN] */
int type; /* [IN] console, file, coproc, pipe */
int mode; /* [IN] read, write, etc */
ase_char_t* name; /* [IN] */
void* custom_data; /* [IN] */
void* handle; /* [OUT] */
/* input */
struct
{
ase_char_t buf[2048];
ase_size_t pos;
ase_size_t len;
ase_bool_t eof;
ase_bool_t eos;
} in;
/* output */
struct
{
ase_bool_t eof;
ase_bool_t eos;
} out;
ase_awk_extio_t* next;
};
struct ase_awk_prmfns_t
{
ase_mmgr_t mmgr;
ase_ccls_t ccls;
struct
{
/* utilities */
ase_awk_pow_t pow; /* required */
ase_awk_sprintf_t sprintf; /* required */
ase_awk_dprintf_t dprintf; /* required in the debug mode */
/* user-defined data passed to the functions above */
void* custom_data; /* optional */
} misc;
};
struct ase_awk_srcios_t
{
ase_awk_io_t in;
ase_awk_io_t out;
void* custom_data;
};
struct ase_awk_runios_t
{
ase_awk_io_t pipe;
ase_awk_io_t coproc;
ase_awk_io_t file;
ase_awk_io_t console;
void* custom_data;
};
struct ase_awk_runcbs_t
{
void (*on_start) (
ase_awk_run_t* run, void* custom_data);
void (*on_statement) (
ase_awk_run_t* run, ase_size_t line, void* custom_data);
void (*on_return) (
ase_awk_run_t* run, ase_awk_val_t* ret, void* custom_data);
void (*on_end) (
ase_awk_run_t* run, int errnum, void* custom_data);
void* custom_data;
};
struct ase_awk_runarg_t
{
ase_char_t* ptr;
ase_size_t len;
};
struct ase_awk_rexfns_t
{
void* (*build) (
ase_awk_t* awk, const ase_char_t* ptn,
ase_size_t len, int* errnum);
int (*match) (
ase_awk_t* awk, void* code, int option,
const ase_char_t* str, ase_size_t len,
const ase_char_t** mptr, ase_size_t* mlen,
int* errnum);
void (*free) (ase_awk_t* awk, void* code);
ase_bool_t (*isempty) (ase_awk_t* awk, void* code);
};
/* io function commands */
enum ase_awk_iocmd_t
{
ASE_AWK_IO_OPEN = 0,
ASE_AWK_IO_CLOSE = 1,
ASE_AWK_IO_READ = 2,
ASE_AWK_IO_WRITE = 3,
ASE_AWK_IO_FLUSH = 4,
ASE_AWK_IO_NEXT = 5
};
/* various options */
enum ase_awk_option_t
{
/* allow undeclared variables and implicit concatenation */
ASE_AWK_IMPLICIT = (1 << 0),
/* allow explicit variable declaration, the concatenation
* operator(.), and a parse-time function check. */
ASE_AWK_EXPLICIT = (1 << 1),
/* a function name should not coincide to be a variable name */
/*ASE_AWK_UNIQUEFN = (1 << 2),*/
/* allow variable shading */
/*ASE_AWK_SHADING = (1 << 3),*/
/* support shift operators */
ASE_AWK_SHIFT = (1 << 4),
/* enable the idiv operator (double slashes) */
ASE_AWK_IDIV = (1 << 5),
/* support string concatenation in tokenization.
* this option can change the behavior of a certain construct.
* getline < "abc" ".def" is treated as if it is getline < "abc.def"
* when this option is on. If this option is off, the same expression
* is treated as if it is (getline < "abc") ".def". */
ASE_AWK_STRCONCAT = (1 << 6),
/* support getline and print */
ASE_AWK_EXTIO = (1 << 7),
/* support co-process - NOT IMPLEMENTED YET */
ASE_AWK_COPROC = (1 << 8),
/* support blockless patterns */
ASE_AWK_BLOCKLESS = (1 << 9),
/* use 1 as the start index for string operations and ARGV */
ASE_AWK_BASEONE = (1 << 10),
/* strip off leading and trailing spaces when splitting a record
* into fields with a regular expression.
*
* Consider the following program.
* BEGIN { FS="[:[:space:]]+"; }
* {
* print "NF=" NF;
* for (i = 0; i < NF; i++) print i " [" $(i+1) "]";
* }
*
* The program splits " a b c " into [a], [b], [c] when this
* option is on while into [], [a], [b], [c], [] when it is off.
*/
ASE_AWK_STRIPSPACES = (1 << 11),
/* enable the nextoutfile keyword */
ASE_AWK_NEXTOFILE = (1 << 12),
/* cr + lf by default */
ASE_AWK_CRLF = (1 << 13),
/* pass the arguments to the main function */
ASE_AWK_ARGSTOMAIN = (1 << 14),
/* enable the non-standard keyworkd reset */
ASE_AWK_RESET = (1 << 15),
/* allows the assignment of a map value to a variable */
ASE_AWK_MAPTOVAR = (1 << 16),
/* allows BEGIN, END, pattern-action blocks */
ASE_AWK_PABLOCK = (1 << 17)
};
/* error code */
enum ase_awk_errnum_t
{
ASE_AWK_ENOERR, /* no error */
ASE_AWK_ECUSTOM, /* custom error */
ASE_AWK_EINVAL, /* invalid parameter or data */
ASE_AWK_ENOMEM, /* out of memory */
ASE_AWK_ENOSUP, /* not supported */
ASE_AWK_ENOPER, /* operation not allowed */
ASE_AWK_ENODEV, /* no such device */
ASE_AWK_ENOSPC, /* no space left on device */
ASE_AWK_EMFILE, /* too many open files */
ASE_AWK_EMLINK, /* too many links */
ASE_AWK_EAGAIN, /* resource temporarily unavailable */
ASE_AWK_ENOENT, /* "'%.*s' not existing */
ASE_AWK_EEXIST, /* file or data exists */
ASE_AWK_EFTBIG, /* file or data too big */
ASE_AWK_ETBUSY, /* system too busy */
ASE_AWK_EISDIR, /* is a directory */
ASE_AWK_EIOERR, /* i/o error */
ASE_AWK_EOPEN, /* cannot open */
ASE_AWK_EREAD, /* cannot read */
ASE_AWK_EWRITE, /* cannot write */
ASE_AWK_ECLOSE, /* cannot close */
ASE_AWK_EINTERN, /* internal error */
ASE_AWK_ERUNTIME, /* run-time error */
ASE_AWK_EBLKNST, /* blocke nested too deeply */
ASE_AWK_EEXPRNST, /* expression nested too deeply */
ASE_AWK_ESINOP,
ASE_AWK_ESINCL,
ASE_AWK_ESINRD,
ASE_AWK_ESOUTOP,
ASE_AWK_ESOUTCL,
ASE_AWK_ESOUTWR,
ASE_AWK_ELXCHR, /* lexer came accross an wrong character */
ASE_AWK_ELXDIG, /* invalid digit */
ASE_AWK_ELXUNG, /* lexer failed to unget a character */
ASE_AWK_EENDSRC, /* unexpected end of source */
ASE_AWK_EENDCMT, /* a comment not closed properly */
ASE_AWK_EENDSTR, /* a string not closed with a quote */
ASE_AWK_EENDREX, /* unexpected end of a regular expression */
ASE_AWK_ELBRACE, /* left brace expected */
ASE_AWK_ELPAREN, /* left parenthesis expected */
ASE_AWK_ERPAREN, /* right parenthesis expected */
ASE_AWK_ERBRACK, /* right bracket expected */
ASE_AWK_ECOMMA, /* comma expected */
ASE_AWK_ESCOLON, /* semicolon expected */
ASE_AWK_ECOLON, /* colon expected */
ASE_AWK_ESTMEND, /* statement not ending with a semicolon */
ASE_AWK_EIN, /* keyword 'in' is expected */
ASE_AWK_ENOTVAR, /* not a variable name after 'in' */
ASE_AWK_EEXPRES, /* expression expected */
ASE_AWK_EFUNC, /* keyword 'func' is expected */
ASE_AWK_EWHILE, /* keyword 'while' is expected */
ASE_AWK_EASSIGN, /* assignment statement expected */
ASE_AWK_EIDENT, /* identifier expected */
ASE_AWK_EFNNAME, /* not a valid function name */
ASE_AWK_EBLKBEG, /* BEGIN requires an action block */
ASE_AWK_EBLKEND, /* END requires an action block */
ASE_AWK_EDUPBEG, /* duplicate BEGIN */
ASE_AWK_EDUPEND, /* duplicate END */
ASE_AWK_EBFNRED, /* intrinsic function redefined */
ASE_AWK_EAFNRED, /* function redefined */
ASE_AWK_EGBLRED, /* global variable redefined */
ASE_AWK_EPARRED, /* parameter redefined */
ASE_AWK_EVARRED, /* named variable redefined */
ASE_AWK_EDUPPAR, /* duplicate parameter name */
ASE_AWK_EDUPGBL, /* duplicate global variable name */
ASE_AWK_EDUPLCL, /* duplicate local variable name */
ASE_AWK_EBADPAR, /* not a valid parameter name */
ASE_AWK_EBADVAR, /* not a valid variable name */
ASE_AWK_EUNDEF, /* undefined identifier */
ASE_AWK_ELVALUE, /* l-value required */
ASE_AWK_EGBLTM, /* too many global variables */
ASE_AWK_ELCLTM, /* too many local variables */
ASE_AWK_EPARTM, /* too many parameters */
ASE_AWK_EDELETE, /* delete not followed by a variable */
ASE_AWK_ERESET, /* reset not followed by a variable */
ASE_AWK_EBREAK, /* break outside a loop */
ASE_AWK_ECONTINUE, /* continue outside a loop */
ASE_AWK_ENEXTBEG, /* next illegal in BEGIN block */
ASE_AWK_ENEXTEND, /* next illegal in END block */
ASE_AWK_ENEXTFBEG, /* nextfile illegal in BEGIN block */
ASE_AWK_ENEXTFEND, /* nextfile illegal in END block */
ASE_AWK_EPRINTFARG, /* printf not followed by any arguments */
ASE_AWK_EPREPST, /* both prefix and postfix increment/decrement
operator present */
ASE_AWK_EGLNCPS, /* coprocess not supported by getline */
/* run time error */
ASE_AWK_EDIVBY0, /* divide by zero */
ASE_AWK_EOPERAND, /* invalid operand */
ASE_AWK_EPOSIDX, /* wrong position index */
ASE_AWK_EARGTF, /* too few arguments */
ASE_AWK_EARGTM, /* too many arguments */
ASE_AWK_EFNNONE, /* "function '%.*s' not found" */
ASE_AWK_ENOTIDX, /* variable not indexable */
ASE_AWK_ENOTDEL, /* variable not deletable */
ASE_AWK_ENOTMAP, /* value not a map */
ASE_AWK_ENOTMAPIN, /* right-hand side of 'in' not a map */
ASE_AWK_ENOTMAPNILIN, /* right-hand side of 'in' not a map nor nil */
ASE_AWK_ENOTREF, /* value not referenceable */
ASE_AWK_ENOTASS, /* value not assignable */
ASE_AWK_EIDXVALASSMAP, /* indexed value cannot be assigned a map */
ASE_AWK_EPOSVALASSMAP, /* a positional cannot be assigned a map */
ASE_AWK_EMAPTOSCALAR, /* cannot change a map to a scalar value */
ASE_AWK_ESCALARTOMAP, /* cannot change a scalar value to a map */
ASE_AWK_EMAPNOTALLOWED, /* a map is not allowed */
ASE_AWK_EVALTYPE, /* wrong value type */
ASE_AWK_ERDELETE, /* delete called with a wrong target */
ASE_AWK_ERRESET, /* reset called with a wrong target */
ASE_AWK_ERNEXTBEG, /* next called from BEGIN */
ASE_AWK_ERNEXTEND, /* next called from END */
ASE_AWK_ERNEXTFBEG, /* nextfile called from BEGIN */
ASE_AWK_ERNEXTFEND, /* nextfile called from END */
ASE_AWK_EBFNUSER, /* wrong intrinsic function implementation */
ASE_AWK_EBFNIMPL, /* intrinsic function handler failed */
ASE_AWK_EIOUSER, /* wrong user io handler implementation */
ASE_AWK_EIONONE, /* no such io name found */
ASE_AWK_EIOIMPL, /* i/o callback returned an error */
ASE_AWK_EIONMEM, /* i/o name empty */
ASE_AWK_EIONMNL, /* i/o name contains '\0' */
ASE_AWK_EFMTARG, /* arguments to format string not sufficient */
ASE_AWK_EFMTCNV, /* recursion detected in format conversion */
ASE_AWK_ECONVFMTCHR, /* an invalid character found in CONVFMT */
ASE_AWK_EOFMTCHR, /* an invalid character found in OFMT */
/* regular expression error */
ASE_AWK_EREXRECUR, /* recursion too deep */
ASE_AWK_EREXRPAREN, /* a right parenthesis is expected */
ASE_AWK_EREXRBRACKET, /* a right bracket is expected */
ASE_AWK_EREXRBRACE, /* a right brace is expected */
ASE_AWK_EREXUNBALPAR, /* unbalanced parenthesis */
ASE_AWK_EREXCOLON, /* a colon is expected */
ASE_AWK_EREXCRANGE, /* invalid character range */
ASE_AWK_EREXCCLASS, /* invalid character class */
ASE_AWK_EREXBRANGE, /* invalid boundary range */
ASE_AWK_EREXEND, /* unexpected end of the pattern */
ASE_AWK_EREXGARBAGE, /* garbage after the pattern */
/* the number of error numbers, internal use only */
ASE_AWK_NUMERRNUM
};
/* depth types */
enum ase_awk_depth_t
{
ASE_AWK_DEPTH_BLOCK_PARSE = (1 << 0),
ASE_AWK_DEPTH_BLOCK_RUN = (1 << 1),
ASE_AWK_DEPTH_EXPR_PARSE = (1 << 2),
ASE_AWK_DEPTH_EXPR_RUN = (1 << 3),
ASE_AWK_DEPTH_REX_BUILD = (1 << 4),
ASE_AWK_DEPTH_REX_MATCH = (1 << 5)
};
/* extio types */
enum ase_awk_extio_type_t
{
/* extio types available */
ASE_AWK_EXTIO_PIPE,
ASE_AWK_EXTIO_COPROC,
ASE_AWK_EXTIO_FILE,
ASE_AWK_EXTIO_CONSOLE,
/* reserved for internal use only */
ASE_AWK_EXTIO_NUM
};
enum ase_awk_extio_mode_t
{
ASE_AWK_EXTIO_PIPE_READ = 0,
ASE_AWK_EXTIO_PIPE_WRITE = 1,
/*
ASE_AWK_EXTIO_COPROC_READ = 0,
ASE_AWK_EXTIO_COPROC_WRITE = 1,
ASE_AWK_EXTIO_COPROC_RDWR = 2,
*/
ASE_AWK_EXTIO_FILE_READ = 0,
ASE_AWK_EXTIO_FILE_WRITE = 1,
ASE_AWK_EXTIO_FILE_APPEND = 2,
ASE_AWK_EXTIO_CONSOLE_READ = 0,
ASE_AWK_EXTIO_CONSOLE_WRITE = 1
};
enum ase_awk_global_id_t
{
/* this table should match gtab in parse.c.
* in addition, ase_awk_setglobal also counts
* on the order of these values */
ASE_AWK_GLOBAL_ARGC,
ASE_AWK_GLOBAL_ARGV,
ASE_AWK_GLOBAL_CONVFMT,
ASE_AWK_GLOBAL_FILENAME,
ASE_AWK_GLOBAL_FNR,
ASE_AWK_GLOBAL_FS,
ASE_AWK_GLOBAL_IGNORECASE,
ASE_AWK_GLOBAL_NF,
ASE_AWK_GLOBAL_NR,
ASE_AWK_GLOBAL_OFILENAME,
ASE_AWK_GLOBAL_OFMT,
ASE_AWK_GLOBAL_OFS,
ASE_AWK_GLOBAL_ORS,
ASE_AWK_GLOBAL_RLENGTH,
ASE_AWK_GLOBAL_RS,
ASE_AWK_GLOBAL_RSTART,
ASE_AWK_GLOBAL_SUBSEP,
/* these are not not the actual IDs and are used internally only
* Make sure you update these values properly if you add more
* ID definitions, however */
ASE_AWK_MIN_GLOBAL_ID = ASE_AWK_GLOBAL_ARGC,
ASE_AWK_MAX_GLOBAL_ID = ASE_AWK_GLOBAL_SUBSEP
};
#ifdef __cplusplus
extern "C" {
#endif
ase_awk_t* ase_awk_open (const ase_awk_prmfns_t* prmfns, void* custom_data);
int ase_awk_close (ase_awk_t* awk);
int ase_awk_clear (ase_awk_t* awk);
ase_mmgr_t* ase_awk_getmmgr (ase_awk_t* awk);
void* ase_awk_getcustomdata (ase_awk_t* awk);
const ase_char_t* ase_awk_geterrstr (ase_awk_t* awk, int num);
int ase_awk_seterrstr (ase_awk_t* awk, int num, const ase_char_t* str);
int ase_awk_geterrnum (ase_awk_t* awk);
ase_size_t ase_awk_geterrlin (ase_awk_t* awk);
const ase_char_t* ase_awk_geterrmsg (ase_awk_t* awk);
void ase_awk_seterrnum (ase_awk_t* awk, int errnum);
void ase_awk_seterrmsg (ase_awk_t* awk,
int errnum, ase_size_t errlin, const ase_char_t* errmsg);
void ase_awk_geterror (
ase_awk_t* awk, int* errnum,
ase_size_t* errlin, const ase_char_t** errmsg);
void ase_awk_seterror (
ase_awk_t* awk, int errnum, ase_size_t errlin,
const ase_cstr_t* errarg, ase_size_t argcnt);
int ase_awk_getoption (ase_awk_t* awk);
void ase_awk_setoption (ase_awk_t* awk, int opt);
ase_size_t ase_awk_getmaxdepth (ase_awk_t* awk, int type);
void ase_awk_setmaxdepth (ase_awk_t* awk, int types, ase_size_t depth);
int ase_awk_getword (ase_awk_t* awk,
const ase_char_t* okw, ase_size_t olen,
const ase_char_t** nkw, ase_size_t* nlen);
/**
* Enables replacement of a name of a keyword, intrinsic global variables,
* and intrinsic functions.
*
* If nkw is ASE_NULL or nlen is zero and okw is ASE_NULL or olen is zero,
* it unsets all word replacements. If nkw is ASE_NULL or nlen is zero,
* it unsets the replacement for okw and olen. If all of them are valid,
* it sets the word replace for okw and olen to nkw and nlen.
*
* @return
* On success, 0 is returned.
* On failure, -1 is returned.
*/
int ase_awk_setword (ase_awk_t* awk,
const ase_char_t* okw, ase_size_t olen,
const ase_char_t* nkw, ase_size_t nlen);
/**
* Sets the customized regular processing routine.
*
* @return
* On success, 0 is returned.
* On failure, -1 is returned.
*/
int ase_awk_setrexfns (ase_awk_t* awk, ase_awk_rexfns_t* rexfns);
/**
* Adds an intrinsic global variable.
*
* @return
* On success, the ID of the global variable added is returned.
* On failure, -1 is returned.
*/
int ase_awk_addglobal (ase_awk_t* awk, const ase_char_t* name, ase_size_t len);
/**
* Deletes a instrinsic global variable.
*
* @return
* On success, 0 is returned.
* On failure, -1 is returned.
*/
int ase_awk_delglobal (ase_awk_t* awk, const ase_char_t* name, ase_size_t len);
/**
* Parses the source code
*
* @return
* On success, 0 is returned.
* On failure, -1 is returned.
*/
int ase_awk_parse (ase_awk_t* awk, ase_awk_srcios_t* srcios);
/**
* Executes a parsed program.
*
* ase_awk_run returns 0 on success and -1 on failure, generally speaking.
* A runtime context is required for it to start running the program.
* Once the runtime context is created, the program starts to run.
* The context creation failure is reported by the return value -1 of
* this function. however, the runtime error after the context creation
* is reported differently depending on the use of the callback.
* When no callback is specified (i.e. runcbs is ASE_NULL), ase_awk_run
* returns -1 on an error and awk->errnum is set accordingly.
* However, if a callback is specified (i.e. runcbs is not ASE_NULL),
* ase_awk_run returns 0 on both success and failure. Instead, the
* on_end handler of the callback is triggered with the relevant
* error number. The third parameter to on_end denotes this error number.
*/
int ase_awk_run (
ase_awk_t* awk, const ase_char_t* main,
ase_awk_runios_t* runios, ase_awk_runcbs_t* runcbs,
ase_awk_runarg_t* runarg, void* custom_data);
void ase_awk_stop (ase_awk_run_t* run);
void ase_awk_stopall (ase_awk_t* awk);
ase_bool_t ase_awk_isstop (ase_awk_run_t* run);
/**
* Gets the number of arguments passed to ase_awk_run
*/
ase_size_t ase_awk_getnargs (ase_awk_run_t* run);
/**
* Gets an argument passed to ase_awk_run
*/
ase_awk_val_t* ase_awk_getarg (ase_awk_run_t* run, ase_size_t idx);
/**
* Gets the value of a global variable.
*
* @param run A run-time context
* @param id The ID to a global variable.
* This value correspondsto the predefined global variable IDs or
* the value returned by ase_awk_addglobal.
* @return
* The pointer to a value is returned. This function never fails
* so long as id is valid. Otherwise, you may fall into trouble.
*/
ase_awk_val_t* ase_awk_getglobal (ase_awk_run_t* run, int id);
int ase_awk_setglobal (ase_awk_run_t* run, int id, ase_awk_val_t* val);
/**
* Sets the return value of a function from within a function handler.
*
* @param run A run-time context
* @param val A pointer to the value to set.
* ase_awk_refupval and ase_awk_refdownval are not needed because
* ase_awk_setretval never fails and it updates the reference count
* of the value properly.
*/
void ase_awk_setretval (ase_awk_run_t* run, ase_awk_val_t* val);
int ase_awk_setfilename (
ase_awk_run_t* run, const ase_char_t* name, ase_size_t len);
int ase_awk_setofilename (
ase_awk_run_t* run, const ase_char_t* name, ase_size_t len);
ase_awk_t* ase_awk_getrunawk (ase_awk_run_t* awk);
void* ase_awk_getruncustomdata (ase_awk_run_t* awk);
ase_map_t* ase_awk_getrunnamedvarmap (ase_awk_run_t* awk);
/* functions to manipulate the run-time error */
int ase_awk_getrunerrnum (ase_awk_run_t* run);
ase_size_t ase_awk_getrunerrlin (ase_awk_run_t* run);
const ase_char_t* ase_awk_getrunerrmsg (ase_awk_run_t* run);
void ase_awk_setrunerrnum (ase_awk_run_t* run, int errnum);
void ase_awk_setrunerrmsg (ase_awk_run_t* run,
int errnum, ase_size_t errlin, const ase_char_t* errmsg);
void ase_awk_getrunerror (
ase_awk_run_t* run, int* errnum,
ase_size_t* errlin, const ase_char_t** errmsg);
void ase_awk_setrunerror (
ase_awk_run_t* run, int errnum, ase_size_t errlin,
const ase_cstr_t* errarg, ase_size_t argcnt);
/* functions to manipulate intrinsic functions */
void* ase_awk_addfunc (
ase_awk_t* awk, const ase_char_t* name, ase_size_t name_len,
int when_valid, ase_size_t min_args, ase_size_t max_args,
const ase_char_t* arg_spec,
int (*handler)(ase_awk_run_t*,const ase_char_t*,ase_size_t));
int ase_awk_delfunc (
ase_awk_t* awk, const ase_char_t* name, ase_size_t name_len);
void ase_awk_clrbfn (ase_awk_t* awk);
/* record and field functions */
int ase_awk_clrrec (ase_awk_run_t* run, ase_bool_t skip_inrec_line);
int ase_awk_setrec (ase_awk_run_t* run, ase_size_t idx, const ase_char_t* str, ase_size_t len);
/* utility functions exported by awk.h */
void* ase_awk_malloc (ase_awk_t* awk, ase_size_t size);
void ase_awk_free (ase_awk_t* awk, void* ptr);
ase_char_t* ase_awk_strxdup (
ase_awk_t* awk, const ase_char_t* ptr, ase_size_t len);
ase_long_t ase_awk_strxtolong (
ase_awk_t* awk, const ase_char_t* str, ase_size_t len,
int base, const ase_char_t** endptr);
ase_real_t ase_awk_strxtoreal (
ase_awk_t* awk, const ase_char_t* str, ase_size_t len,
const ase_char_t** endptr);
ase_size_t ase_awk_longtostr (
ase_long_t value, int radix, const ase_char_t* prefix,
ase_char_t* buf, ase_size_t size);
#ifdef __cplusplus
}
#endif
#endif

71
ase/lib/awk/awk.txt Normal file
View File

@ -0,0 +1,71 @@
Programs
pattern { action }
function name (parameter-list) { statement }
Patterns
BEGIN
END
expresion
/regular expression/
pattern && pattern
pattern || pattern
!pattern
(pattern)
pattern, pattern -> range pattern
Actions
break
continue
delete array-element
do statement while (expression)
exit [expression]
expression
if (expression) statement [else statement]
input-output statement
for (expression; expression; expression) statement
for (variable in array) statement
next
return [expression]
while (expression) statement
{ statements }
Variables
global variables (enabled when awk->opt & ASE_AWK_OPT_VARDCL)
global x;
global x, y;
local variables (enabled when awk->opt & ASE_AWK_OPT_VARDCL)
local x;
local x, y;
function arguments (enabled always)
function funca (x, y)
local variables in function declaration (enabled when awk->opt & ASE_AWK_OPT_FUNCLOCAL)
function funca (x, y, v1, v2)
variables without any declarations (enabled when awk->opt & ASE_AWK_OPT_NAMEDVAR)
x = 10; // x is put into the global hash table.
Optimization
constant folding
2 * 10 => 20
loop
remove while (0) { ... }
if
remove if (0) {}
use else_part only

376
ase/lib/awk/awk_i.h Normal file
View File

@ -0,0 +1,376 @@
/*
* $Id: awk_i.h 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
#ifndef _ASE_AWK_AWKI_H_
#define _ASE_AWK_AWKI_H_
#include <ase/cmn/mem.h>
#include <ase/cmn/str.h>
#include <ase/cmn/map.h>
#include <ase/cmn/rex.h>
typedef struct ase_awk_chain_t ase_awk_chain_t;
typedef struct ase_awk_tree_t ase_awk_tree_t;
#include <ase/awk/awk.h>
#include <ase/awk/tree.h>
#include <ase/awk/val.h>
#include <ase/awk/func.h>
#include <ase/awk/tab.h>
#include <ase/awk/parse.h>
#include <ase/awk/run.h>
#include <ase/awk/extio.h>
#include <ase/awk/misc.h>
#ifdef _MSC_VER
#pragma warning (disable: 4996)
#pragma warning (disable: 4296)
#endif
#define ASE_AWK_MAX_GLOBALS 9999
#define ASE_AWK_MAX_LOCALS 9999
#define ASE_AWK_MAX_PARAMS 9999
#define ASE_AWK_MALLOC(awk,size) ASE_MALLOC(&(awk)->prmfns.mmgr,size)
#define ASE_AWK_REALLOC(awk,ptr,size) ASE_REALLOC(&(awk)->prmfns.mmgr,ptr,size)
#define ASE_AWK_FREE(awk,ptr) ASE_FREE(&(awk)->prmfns.mmgr,ptr)
#define ASE_AWK_ISUPPER(awk,c) ASE_ISUPPER(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISLOWER(awk,c) ASE_ISLOWER(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISALPHA(awk,c) ASE_ISALPHA(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISDIGIT(awk,c) ASE_ISDIGIT(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISXDIGIT(awk,c) ASE_ISXDIGIT(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISALNUM(awk,c) ASE_ISALNUM(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISSPACE(awk,c) ASE_ISSPACE(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISPRINT(awk,c) ASE_ISPRINT(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISGRAPH(awk,c) ASE_ISGRAPH(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISCNTRL(awk,c) ASE_ISCNTRL(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISPUNCT(awk,c) ASE_ISPUNCT(&(awk)->prmfns.ccls,c)
#define ASE_AWK_TOUPPER(awk,c) ASE_TOUPPER(&(awk)->prmfns.ccls,c)
#define ASE_AWK_TOLOWER(awk,c) ASE_TOLOWER(&(awk)->prmfns.ccls,c)
struct ase_awk_tree_t
{
ase_size_t nglobals; /* total number of globals */
ase_size_t nbglobals; /* number of intrinsic globals */
ase_cstr_t cur_afn;
ase_map_t* afns; /* awk function map */
ase_awk_nde_t* begin;
ase_awk_nde_t* begin_tail;
ase_awk_nde_t* end;
ase_awk_nde_t* end_tail;
ase_awk_chain_t* chain;
ase_awk_chain_t* chain_tail;
ase_size_t chain_size; /* number of nodes in the chain */
int ok;
};
struct ase_awk_t
{
ase_awk_prmfns_t prmfns;
void* custom_data;
/* options */
int option;
/* word table */
ase_map_t* wtab;
/* reverse word table */
ase_map_t* rwtab;
/* regular expression processing routines */
ase_awk_rexfns_t* rexfns;
/* parse tree */
ase_awk_tree_t tree;
/* temporary information that the parser needs */
struct
{
struct
{
int block;
int loop;
int stmnt; /* statement */
} id;
struct
{
struct
{
ase_size_t block;
ase_size_t loop;
ase_size_t expr; /* expression */
} cur;
struct
{
ase_size_t block;
ase_size_t expr;
} max;
} depth;
/* function calls */
ase_map_t* afns;
/* named variables */
ase_map_t* named;
/* global variables */
ase_awk_tab_t globals;
/* local variables */
ase_awk_tab_t locals;
/* parameters to a function */
ase_awk_tab_t params;
/* maximum number of local variables */
ase_size_t nlocals_max;
ase_awk_nde_t* (*parse_block) (
ase_awk_t*,ase_size_t,ase_bool_t);
} parse;
/* source code management */
struct
{
ase_awk_srcios_t ios;
struct
{
ase_cint_t curc;
ase_cint_t ungotc[5];
ase_size_t ungotc_line[5];
ase_size_t ungotc_column[5];
ase_size_t ungotc_count;
ase_size_t line;
ase_size_t column;
} lex;
struct
{
ase_char_t buf[512];
ase_size_t buf_pos;
ase_size_t buf_len;
} shared;
} src;
/* token */
struct
{
struct
{
int type;
ase_size_t line;
ase_size_t column;
} prev;
int type;
ase_str_t name;
ase_size_t line;
ase_size_t column;
} token;
/* intrinsic functions */
struct
{
ase_awk_bfn_t* sys;
ase_map_t* user;
} bfn;
struct
{
struct
{
struct
{
ase_size_t block;
ase_size_t expr;
} max;
} depth;
} run;
struct
{
struct
{
struct
{
ase_size_t build;
ase_size_t match;
} max;
} depth;
} rex;
struct
{
ase_char_t fmt[1024];
} tmp;
/* housekeeping */
int errnum;
ase_size_t errlin;
ase_char_t errmsg[256];
ase_char_t* errstr[ASE_AWK_NUMERRNUM];
ase_bool_t stopall;
};
struct ase_awk_chain_t
{
ase_awk_nde_t* pattern;
ase_awk_nde_t* action;
ase_awk_chain_t* next;
};
struct ase_awk_run_t
{
int id;
ase_map_t* named;
void** stack;
ase_size_t stack_top;
ase_size_t stack_base;
ase_size_t stack_limit;
int exit_level;
ase_awk_val_ref_t* fcache[128];
/*ase_awk_val_str_t* scache32[128];
ase_awk_val_str_t* scache64[128];*/
ase_size_t fcache_count;
/*ase_size_t scache32_count;
ase_size_t scache64_count;*/
struct
{
ase_awk_val_int_t* ifree;
ase_awk_val_chunk_t* ichunk;
ase_awk_val_real_t* rfree;
ase_awk_val_chunk_t* rchunk;
} vmgr;
ase_awk_nde_blk_t* active_block;
ase_byte_t* pattern_range_state;
struct
{
ase_char_t buf[1024];
ase_size_t buf_pos;
ase_size_t buf_len;
ase_bool_t eof;
ase_str_t line;
ase_awk_val_t* d0; /* $0 */
ase_size_t maxflds;
ase_size_t nflds; /* NF */
struct
{
ase_char_t* ptr;
ase_size_t len;
ase_awk_val_t* val; /* $1 .. $NF */
}* flds;
} inrec;
struct
{
void* rs;
void* fs;
int ignorecase;
ase_long_t nr;
ase_long_t fnr;
struct
{
ase_char_t* ptr;
ase_size_t len;
} convfmt;
struct
{
ase_char_t* ptr;
ase_size_t len;
} ofmt;
struct
{
ase_char_t* ptr;
ase_size_t len;
} ofs;
struct
{
ase_char_t* ptr;
ase_size_t len;
} ors;
struct
{
ase_char_t* ptr;
ase_size_t len;
} subsep;
} global;
/* extio chain */
struct
{
ase_awk_io_t handler[ASE_AWK_EXTIO_NUM];
void* custom_data;
ase_awk_extio_t* chain;
} extio;
struct
{
ase_str_t fmt;
ase_str_t out;
struct
{
ase_char_t* ptr;
ase_size_t len; /* length */
ase_size_t inc; /* increment */
} tmp;
} format;
struct
{
struct
{
ase_size_t block;
ase_size_t expr; /* expression */
} cur;
struct
{
ase_size_t block;
ase_size_t expr;
} max;
} depth;
int errnum;
ase_size_t errlin;
ase_char_t errmsg[256];
void* custom_data;
ase_awk_t* awk;
ase_awk_runcbs_t* cbs;
};
#define ASE_AWK_FREEREX(awk,code) ase_freerex(&(awk)->prmfns.mmgr,code)
#define ASE_AWK_ISEMPTYREX(awk,code) ase_isemptyrex(code)
#define ASE_AWK_BUILDREX(awk,ptn,len,errnum) \
ase_awk_buildrex(awk,ptn,len,errnum)
#define ASE_AWK_MATCHREX(awk,code,option,str,len,match_ptr,match_len,errnum) \
ase_awk_matchrex(awk,code,option,str,len,match_ptr,match_len,errnum)
#endif

25
ase/lib/awk/descrip.mms Normal file
View File

@ -0,0 +1,25 @@
#
# OpenVMS MMS/MMK
#
objects = awk.obj,err.obj,tree.obj,tab.obj,parse.obj,run.obj,rec.obj,val.obj,func.obj,misc.obj,extio.obj
CFLAGS = /include="../.."
#CFLAGS = /pointer_size=long /include="../.."
LIBRFLAGS =
aseawk.olb : $(objects)
$(LIBR)/create $(MMS$TARGET) $(objects)
# $(LIBR)/replace $(LIBRFLAGS) $(MMS$TARGET),$(objects)
awk.obj depends_on awk.c
err.obj depends_on err.c
tree.obj depends_on tree.c
tab.obj depends_on tab.c
parse.obj depends_on parse.c
run.obj depends_on run.c
rec.obj depends_on rec.c
val.obj depends_on val.c
func.obj depends_on func.c
misc.obj depends_on misc.c
extio.obj depends_on extio.c

490
ase/lib/awk/err.c Normal file
View File

@ -0,0 +1,490 @@
/*
* $Id: err.c 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
#include <ase/awk/awk_i.h>
static const ase_char_t* __geterrstr (int errnum)
{
static const ase_char_t* errstr[] =
{
ASE_T("no error"),
ASE_T("custom error"),
ASE_T("invalid parameter or data"),
ASE_T("out of memory"),
ASE_T("not supported"),
ASE_T("operation not allowed"),
ASE_T("no such device"),
ASE_T("no space left on device"),
ASE_T("too many open files"),
ASE_T("too many links"),
ASE_T("resource temporarily unavailable"),
ASE_T("'%.*s' not existing"),
ASE_T("'%.*s' already exists"),
ASE_T("file or data too big"),
ASE_T("system too busy"),
ASE_T("is a directory"),
ASE_T("i/o error"),
ASE_T("cannot open '%.*s'"),
ASE_T("cannot read '%.*s'"),
ASE_T("cannot write '%.*s'"),
ASE_T("cannot close '%.*s'"),
ASE_T("internal error that should never have happened"),
ASE_T("general run-time error"),
ASE_T("block nested too deeply"),
ASE_T("expressio nested too deeply"),
ASE_T("cannot open source input"),
ASE_T("cannot close source input"),
ASE_T("cannot read source input"),
ASE_T("cannot open source output"),
ASE_T("cannot close source output"),
ASE_T("cannot write source output"),
ASE_T("invalid character '%.*s'"),
ASE_T("invalid digit '%.*s'"),
ASE_T("cannot unget character"),
ASE_T("unexpected end of source"),
ASE_T("a comment not closed properly"),
ASE_T("a string not closed with a quote"),
ASE_T("unexpected end of a regular expression"),
ASE_T("a left brace expected in place of '%.*s'"),
ASE_T("a left parenthesis expected in place of '%.*s'"),
ASE_T("a right parenthesis expected in place of '%.*s'"),
ASE_T("a right bracket expected in place of '%.*s'"),
ASE_T("a comma expected in place of '%.*s'"),
ASE_T("a semicolon expected in place of '%.*s'"),
ASE_T("a colon expected in place of '%.*s'"),
ASE_T("statement not ending with a semicolon"),
ASE_T("'in' expected in place of '%.*s'"),
ASE_T("right-hand side of the 'in' operator not a variable"),
ASE_T("invalid expression"),
ASE_T("keyword 'function' expected in place of '%.*s'"),
ASE_T("keyword 'while' expected in place of '%.*s'"),
ASE_T("invalid assignment statement"),
ASE_T("an identifier expected in place of '%.*s'"),
ASE_T("'%.*s' not a valid function name"),
ASE_T("BEGIN not followed by a left bracket on the same line"),
ASE_T("END not followed by a left bracket on the same line"),
ASE_T("duplicate BEGIN"),
ASE_T("duplicate END"),
ASE_T("intrinsic function '%.*s' redefined"),
ASE_T("function '%.*s' redefined"),
ASE_T("global variable '%.*s' redefined"),
ASE_T("parameter '%.*s' redefined"),
ASE_T("variable '%.*s' redefined"),
ASE_T("duplicate parameter name '%.*s'"),
ASE_T("duplicate global variable '%.*s'"),
ASE_T("duplicate local variable '%.*s'"),
ASE_T("'%.*s' not a valid parameter name"),
ASE_T("'%.*s' not a valid variable name"),
ASE_T("undefined identifier '%.*s'"),
ASE_T("l-value required"),
ASE_T("too many global variables"),
ASE_T("too many local variables"),
ASE_T("too many parameters"),
ASE_T("delete statement not followed by a normal variable"),
ASE_T("reset statement not followed by a normal variable"),
ASE_T("break statement outside a loop"),
ASE_T("continue statement outside a loop"),
ASE_T("next statement illegal in the BEGIN block"),
ASE_T("next statement illegal in the END block"),
ASE_T("nextfile statement illegal in the BEGIN block"),
ASE_T("nextfile statement illegal in the END block"),
ASE_T("printf not followed by any arguments"),
ASE_T("both prefix and postfix increment/decrement operator present"),
ASE_T("coprocess not supported by getline"),
ASE_T("divide by zero"),
ASE_T("invalid operand"),
ASE_T("wrong position index"),
ASE_T("too few arguments"),
ASE_T("too many arguments"),
ASE_T("function '%.*s' not found"),
ASE_T("variable not indexable"),
ASE_T("variable '%.*s' not deletable"),
ASE_T("value not a map"),
ASE_T("right-hand side of the 'in' operator not a map"),
ASE_T("right-hand side of the 'in' operator not a map nor nil"),
ASE_T("value not referenceable"),
ASE_T("value not assignable"),
ASE_T("an indexed value cannot be assigned a map"),
ASE_T("a positional value cannot be assigned a map"),
ASE_T("map '%.*s' not assignable with a scalar"),
ASE_T("cannot change a scalar value to a map"),
ASE_T("a map is not allowed"),
ASE_T("invalid value type"),
ASE_T("delete statement called with a wrong target"),
ASE_T("reset statement called with a wrong target"),
ASE_T("next statement called from the BEGIN block"),
ASE_T("next statement called from the END block"),
ASE_T("nextfile statement called from the BEGIN block"),
ASE_T("nextfile statement called from the END block"),
ASE_T("wrong implementation of intrinsic function handler"),
ASE_T("intrinsic function handler returned an error"),
ASE_T("wrong implementation of user-defined io handler"),
ASE_T("no such io name found"),
ASE_T("i/o handler returned an error"),
ASE_T("i/o name empty"),
ASE_T("i/o name containing a null character"),
ASE_T("not sufficient arguments to formatting sequence"),
ASE_T("recursion detected in format conversion"),
ASE_T("invalid character in CONVFMT"),
ASE_T("invalid character in OFMT"),
ASE_T("recursion too deep in the regular expression"),
ASE_T("a right parenthesis expected in the regular expression"),
ASE_T("a right bracket expected in the regular expression"),
ASE_T("a right brace expected in the regular expression"),
ASE_T("unbalanced parenthesis in the regular expression"),
ASE_T("a colon expected in the regular expression"),
ASE_T("invalid character range in the regular expression"),
ASE_T("invalid character class in the regular expression"),
ASE_T("invalid boundary range in the regular expression"),
ASE_T("unexpected end of the regular expression"),
ASE_T("garbage after the regular expression")
};
if (errnum >= 0 && errnum < ASE_COUNTOF(errstr))
{
return errstr[errnum];
}
return ASE_T("unknown error");
}
const ase_char_t* ase_awk_geterrstr (ase_awk_t* awk, int num)
{
if (awk != ASE_NULL &&
awk->errstr[num] != ASE_NULL) return awk->errstr[num];
return __geterrstr (num);
}
int ase_awk_seterrstr (ase_awk_t* awk, int num, const ase_char_t* str)
{
ase_char_t* dup;
if (str == ASE_NULL) dup = ASE_NULL;
else
{
dup = ase_strdup (str, &awk->prmfns.mmgr);
if (dup == ASE_NULL) return -1;
}
if (awk->errstr[num] != ASE_NULL)
ASE_AWK_FREE (awk, awk->errstr[num]);
else awk->errstr[num] = dup;
return 0;
}
int ase_awk_geterrnum (ase_awk_t* awk)
{
return awk->errnum;
}
ase_size_t ase_awk_geterrlin (ase_awk_t* awk)
{
return awk->errlin;
}
const ase_char_t* ase_awk_geterrmsg (ase_awk_t* awk)
{
if (awk->errmsg[0] == ASE_T('\0'))
return ase_awk_geterrstr (awk, awk->errnum);
return awk->errmsg;
}
void ase_awk_geterror (
ase_awk_t* awk, int* errnum,
ase_size_t* errlin, const ase_char_t** errmsg)
{
if (errnum != ASE_NULL) *errnum = awk->errnum;
if (errlin != ASE_NULL) *errlin = awk->errlin;
if (errmsg != ASE_NULL)
{
if (awk->errmsg[0] == ASE_T('\0'))
*errmsg = ase_awk_geterrstr (awk, awk->errnum);
else
*errmsg = awk->errmsg;
}
}
void ase_awk_seterrnum (ase_awk_t* awk, int errnum)
{
awk->errnum = errnum;
awk->errlin = 0;
awk->errmsg[0] = ASE_T('\0');
}
void ase_awk_seterrmsg (ase_awk_t* awk,
int errnum, ase_size_t errlin, const ase_char_t* errmsg)
{
awk->errnum = errnum;
awk->errlin = errlin;
ase_strxcpy (awk->errmsg, ASE_COUNTOF(awk->errmsg), errmsg);
}
void ase_awk_seterror (
ase_awk_t* awk, int errnum, ase_size_t errlin,
const ase_cstr_t* errarg, ase_size_t argcnt)
{
const ase_char_t* errfmt;
ase_size_t fmtlen;
ASE_ASSERT (argcnt <= 5);
awk->errnum = errnum;
awk->errlin = errlin;
errfmt = ase_awk_geterrstr (awk, errnum);
fmtlen = ase_strlen(errfmt);
switch (argcnt)
{
case 0:
awk->prmfns.misc.sprintf (
awk->prmfns.misc.custom_data,
awk->errmsg,
ASE_COUNTOF(awk->errmsg),
errfmt);
return;
case 1:
{
ase_char_t tmp[ASE_COUNTOF(awk->errmsg)];
ase_size_t len, tl;
if (fmtlen < ASE_COUNTOF(awk->errmsg) &&
errarg[0].len + fmtlen >= ASE_COUNTOF(awk->errmsg))
{
len = ASE_COUNTOF(awk->errmsg) - fmtlen - 3 - 1;
tl = ase_strxncpy (tmp, ASE_COUNTOF(tmp), errarg[0].ptr, len);
tmp[tl] = ASE_T('.');
tmp[tl+1] = ASE_T('.');
tmp[tl+2] = ASE_T('.');
len += 3;
}
else
{
len = errarg[0].len;
ase_strxncpy (tmp, ASE_COUNTOF(tmp), errarg[0].ptr, len);
}
awk->prmfns.misc.sprintf (
awk->prmfns.misc.custom_data,
awk->errmsg,
ASE_COUNTOF(awk->errmsg),
errfmt, (int)len, tmp);
return;
}
case 2:
awk->prmfns.misc.sprintf (
awk->prmfns.misc.custom_data,
awk->errmsg,
ASE_COUNTOF(awk->errmsg),
errfmt,
(int)errarg[0].len, errarg[0].ptr,
(int)errarg[1].len, errarg[1].ptr);
return;
case 3:
awk->prmfns.misc.sprintf (
awk->prmfns.misc.custom_data,
awk->errmsg,
ASE_COUNTOF(awk->errmsg),
errfmt,
(int)errarg[0].len, errarg[0].ptr,
(int)errarg[1].len, errarg[1].ptr,
(int)errarg[2].len, errarg[2].ptr);
return;
case 4:
awk->prmfns.misc.sprintf (
awk->prmfns.misc.custom_data,
awk->errmsg,
ASE_COUNTOF(awk->errmsg),
errfmt,
(int)errarg[0].len, errarg[0].ptr,
(int)errarg[1].len, errarg[1].ptr,
(int)errarg[2].len, errarg[2].ptr,
(int)errarg[3].len, errarg[3].ptr);
return;
case 5:
awk->prmfns.misc.sprintf (
awk->prmfns.misc.custom_data,
awk->errmsg,
ASE_COUNTOF(awk->errmsg),
errfmt,
(int)errarg[0].len, errarg[0].ptr,
(int)errarg[1].len, errarg[1].ptr,
(int)errarg[2].len, errarg[2].ptr,
(int)errarg[3].len, errarg[3].ptr,
(int)errarg[4].len, errarg[4].ptr);
return;
}
}
int ase_awk_getrunerrnum (ase_awk_run_t* run)
{
return run->errnum;
}
ase_size_t ase_awk_getrunerrlin (ase_awk_run_t* run)
{
return run->errlin;
}
const ase_char_t* ase_awk_getrunerrmsg (ase_awk_run_t* run)
{
if (run->errmsg[0] == ASE_T('\0'))
return ase_awk_geterrstr (run->awk, run->errnum);
return run->errmsg;
}
void ase_awk_setrunerrnum (ase_awk_run_t* run, int errnum)
{
run->errnum = errnum;
run->errlin = 0;
run->errmsg[0] = ASE_T('\0');
}
void ase_awk_setrunerrmsg (ase_awk_run_t* run,
int errnum, ase_size_t errlin, const ase_char_t* errmsg)
{
run->errnum = errnum;
run->errlin = errlin;
ase_strxcpy (run->errmsg, ASE_COUNTOF(run->errmsg), errmsg);
}
void ase_awk_getrunerror (
ase_awk_run_t* run, int* errnum,
ase_size_t* errlin, const ase_char_t** errmsg)
{
if (errnum != ASE_NULL) *errnum = run->errnum;
if (errlin != ASE_NULL) *errlin = run->errlin;
if (errmsg != ASE_NULL)
{
if (run->errmsg[0] == ASE_T('\0'))
*errmsg = ase_awk_geterrstr (run->awk, run->errnum);
else
*errmsg = run->errmsg;
}
}
void ase_awk_setrunerror (
ase_awk_run_t* run, int errnum, ase_size_t errlin,
const ase_cstr_t* errarg, ase_size_t argcnt)
{
const ase_char_t* errfmt;
ase_size_t fmtlen;
ASE_ASSERT (argcnt <= 5);
run->errnum = errnum;
run->errlin = errlin;
errfmt = ase_awk_geterrstr (run->awk, errnum);
fmtlen = ase_strlen (errfmt);
switch (argcnt)
{
case 0:
/* TODO: convert % to %% if the original % is not
* the first % of the %% sequence */
run->awk->prmfns.misc.sprintf (
run->awk->prmfns.misc.custom_data,
run->errmsg,
ASE_COUNTOF(run->errmsg),
errfmt);
return;
case 1:
{
/* TODO: what if the argument contains a null character?
* handle the case more gracefully than now... */
ase_char_t tmp[ASE_COUNTOF(run->errmsg)];
ase_size_t len, tl;
if (fmtlen < ASE_COUNTOF(run->errmsg) &&
errarg[0].len + fmtlen >= ASE_COUNTOF(run->errmsg))
{
len = ASE_COUNTOF(run->errmsg) - fmtlen - 3 - 1;
tl = ase_strxncpy (tmp, ASE_COUNTOF(tmp), errarg[0].ptr, len);
tmp[tl] = ASE_T('.');
tmp[tl+1] = ASE_T('.');
tmp[tl+2] = ASE_T('.');
len += 3;
}
else
{
len = errarg[0].len;
ase_strxncpy (tmp, ASE_COUNTOF(tmp), errarg[0].ptr, len);
}
run->awk->prmfns.misc.sprintf (
run->awk->prmfns.misc.custom_data,
run->errmsg,
ASE_COUNTOF(run->errmsg),
errfmt, len, tmp);
return;
}
case 2:
run->awk->prmfns.misc.sprintf (
run->awk->prmfns.misc.custom_data,
run->errmsg,
ASE_COUNTOF(run->errmsg),
errfmt,
errarg[0].len, errarg[0].ptr,
errarg[1].len, errarg[1].ptr);
return;
case 3:
run->awk->prmfns.misc.sprintf (
run->awk->prmfns.misc.custom_data,
run->errmsg,
ASE_COUNTOF(run->errmsg),
errfmt,
errarg[0].len, errarg[0].ptr,
errarg[1].len, errarg[1].ptr,
errarg[2].len, errarg[2].ptr);
return;
case 4:
run->awk->prmfns.misc.sprintf (
run->awk->prmfns.misc.custom_data,
run->errmsg,
ASE_COUNTOF(run->errmsg),
errfmt,
errarg[0].len, errarg[0].ptr,
errarg[1].len, errarg[1].ptr,
errarg[2].len, errarg[2].ptr,
errarg[3].len, errarg[3].ptr);
return;
case 5:
run->awk->prmfns.misc.sprintf (
run->awk->prmfns.misc.custom_data,
run->errmsg,
ASE_COUNTOF(run->errmsg),
errfmt,
errarg[0].len, errarg[0].ptr,
errarg[1].len, errarg[1].ptr,
errarg[2].len, errarg[2].ptr,
errarg[3].len, errarg[3].ptr,
errarg[4].len, errarg[4].ptr);
return;
}
}

962
ase/lib/awk/extio.c Normal file
View File

@ -0,0 +1,962 @@
/*
* $Id: extio.c 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
#include <ase/awk/awk_i.h>
enum
{
MASK_READ = 0x0100,
MASK_WRITE = 0x0200,
MASK_RDWR = 0x0400,
MASK_CLEAR = 0x00FF
};
static int in_type_map[] =
{
/* the order should match the order of the
* ASE_AWK_IN_XXX values in tree.h */
ASE_AWK_EXTIO_PIPE,
ASE_AWK_EXTIO_COPROC,
ASE_AWK_EXTIO_FILE,
ASE_AWK_EXTIO_CONSOLE
};
static int in_mode_map[] =
{
/* the order should match the order of the
* ASE_AWK_IN_XXX values in tree.h */
ASE_AWK_EXTIO_PIPE_READ,
0,
ASE_AWK_EXTIO_FILE_READ,
ASE_AWK_EXTIO_CONSOLE_READ
};
static int in_mask_map[] =
{
MASK_READ,
MASK_RDWR,
MASK_READ,
MASK_READ
};
static int out_type_map[] =
{
/* the order should match the order of the
* ASE_AWK_OUT_XXX values in tree.h */
ASE_AWK_EXTIO_PIPE,
ASE_AWK_EXTIO_COPROC,
ASE_AWK_EXTIO_FILE,
ASE_AWK_EXTIO_FILE,
ASE_AWK_EXTIO_CONSOLE
};
static int out_mode_map[] =
{
/* the order should match the order of the
* ASE_AWK_OUT_XXX values in tree.h */
ASE_AWK_EXTIO_PIPE_WRITE,
0,
ASE_AWK_EXTIO_FILE_WRITE,
ASE_AWK_EXTIO_FILE_APPEND,
ASE_AWK_EXTIO_CONSOLE_WRITE
};
static int out_mask_map[] =
{
MASK_WRITE,
MASK_RDWR,
MASK_WRITE,
MASK_WRITE,
MASK_WRITE
};
int ase_awk_readextio (
ase_awk_run_t* run, int in_type,
const ase_char_t* name, ase_str_t* buf)
{
ase_awk_extio_t* p = run->extio.chain;
ase_awk_io_t handler;
int extio_type, extio_mode, extio_mask, ret, n;
ase_ssize_t x;
ase_awk_val_t* rs;
ase_char_t* rs_ptr;
ase_size_t rs_len;
ase_size_t line_len = 0;
ase_char_t c = ASE_T('\0'), pc;
ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_type_map));
ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_mode_map));
ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_mask_map));
/* translate the in_type into the relevant extio type and mode */
extio_type = in_type_map[in_type];
extio_mode = in_mode_map[in_type];
extio_mask = in_mask_map[in_type];
handler = run->extio.handler[extio_type];
if (handler == ASE_NULL)
{
/* no io handler provided */
ase_awk_setrunerrnum (run, ASE_AWK_EIOUSER);
return -1;
}
while (p != ASE_NULL)
{
if (p->type == (extio_type | extio_mask) &&
ase_strcmp (p->name,name) == 0) break;
p = p->next;
}
if (p == ASE_NULL)
{
p = (ase_awk_extio_t*) ASE_AWK_MALLOC (
run->awk, ASE_SIZEOF(ase_awk_extio_t));
if (p == ASE_NULL)
{
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
return -1;
}
p->name = ase_strdup (name, &run->awk->prmfns.mmgr);
if (p->name == ASE_NULL)
{
ASE_AWK_FREE (run->awk, p);
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
return -1;
}
p->run = run;
p->type = (extio_type | extio_mask);
p->mode = extio_mode;
p->handle = ASE_NULL;
p->next = ASE_NULL;
p->custom_data = run->extio.custom_data;
p->in.buf[0] = ASE_T('\0');
p->in.pos = 0;
p->in.len = 0;
p->in.eof = ase_false;
p->in.eos = ase_false;
ase_awk_setrunerrnum (run, ASE_AWK_ENOERR);
x = handler (ASE_AWK_IO_OPEN, p, ASE_NULL, 0);
if (x <= -1)
{
ASE_AWK_FREE (run->awk, p->name);
ASE_AWK_FREE (run->awk, p);
if (run->errnum == ASE_AWK_ENOERR)
{
/* if the error number has not been
* set by the user handler */
ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL);
}
return -1;
}
/* chain it */
p->next = run->extio.chain;
run->extio.chain = p;
/* usually, x == 0 indicates that it has reached the end
* of the input. the user io handler can return 0 for the
* open request if it doesn't have any files to open. One
* advantage of doing this would be that you can skip the
* entire pattern-block matching and exeuction. */
if (x == 0)
{
p->in.eos = ase_true;
return 0;
}
}
if (p->in.eos)
{
/* no more streams. */
return 0;
}
/* ready to read a line */
ase_str_clear (buf);
/* get the record separator */
rs = ase_awk_getglobal (run, ASE_AWK_GLOBAL_RS);
ase_awk_refupval (run, rs);
if (rs->type == ASE_AWK_VAL_NIL)
{
rs_ptr = ASE_NULL;
rs_len = 0;
}
else if (rs->type == ASE_AWK_VAL_STR)
{
rs_ptr = ((ase_awk_val_str_t*)rs)->buf;
rs_len = ((ase_awk_val_str_t*)rs)->len;
}
else
{
rs_ptr = ase_awk_valtostr (
run, rs, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &rs_len);
if (rs_ptr == ASE_NULL)
{
ase_awk_refdownval (run, rs);
return -1;
}
}
ret = 1;
/* call the io handler */
while (1)
{
if (p->in.pos >= p->in.len)
{
ase_ssize_t n;
if (p->in.eof)
{
if (ASE_STR_LEN(buf) == 0) ret = 0;
break;
}
ase_awk_setrunerrnum (run, ASE_AWK_ENOERR);
n = handler (ASE_AWK_IO_READ,
p, p->in.buf, ASE_COUNTOF(p->in.buf));
if (n <= -1)
{
if (run->errnum == ASE_AWK_ENOERR)
{
/* if the error number has not been
* set by the user handler */
ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL);
}
ret = -1;
break;
}
if (n == 0)
{
p->in.eof = ase_true;
if (ASE_STR_LEN(buf) == 0) ret = 0;
else if (rs_len >= 2)
{
/* when RS is multiple characters, it needs to check
* for the match at the end of the input stream as
* the buffer has been appened with the last character
* after the previous matchrex has failed */
const ase_char_t* match_ptr;
ase_size_t match_len;
ASE_ASSERT (run->global.rs != ASE_NULL);
n = ASE_AWK_MATCHREX (
run->awk, run->global.rs,
((run->global.ignorecase)? ASE_REX_IGNORECASE: 0),
ASE_STR_BUF(buf), ASE_STR_LEN(buf),
&match_ptr, &match_len, &run->errnum);
if (n == -1)
{
ret = -1;
break;
}
if (n == 1)
{
/* the match should be found at the end of
* the current buffer */
ASE_ASSERT (
ASE_STR_BUF(buf) + ASE_STR_LEN(buf) ==
match_ptr + match_len);
ASE_STR_LEN(buf) -= match_len;
break;
}
}
break;
}
p->in.len = n;
p->in.pos = 0;
}
pc = c;
c = p->in.buf[p->in.pos++];
if (rs_ptr == ASE_NULL)
{
/* separate by a new line */
if (c == ASE_T('\n'))
{
if (pc == ASE_T('\r') &&
ASE_STR_LEN(buf) > 0)
{
ASE_STR_LEN(buf) -= 1;
}
break;
}
}
else if (rs_len == 0)
{
/* separate by a blank line */
if (c == ASE_T('\n'))
{
if (pc == ASE_T('\r') &&
ASE_STR_LEN(buf) > 0)
{
ASE_STR_LEN(buf) -= 1;
}
}
if (line_len == 0 && c == ASE_T('\n'))
{
if (ASE_STR_LEN(buf) <= 0)
{
/* if the record is empty when a blank
* line is encountered, the line
* terminator should not be added to
* the record */
continue;
}
/* when a blank line is encountered,
* it needs to snip off the line
* terminator of the previous line */
ASE_STR_LEN(buf) -= 1;
break;
}
}
else if (rs_len == 1)
{
if (c == rs_ptr[0]) break;
}
else
{
const ase_char_t* match_ptr;
ase_size_t match_len;
ASE_ASSERT (run->global.rs != ASE_NULL);
n = ASE_AWK_MATCHREX (
run->awk, run->global.rs,
((run->global.ignorecase)? ASE_REX_IGNORECASE: 0),
ASE_STR_BUF(buf), ASE_STR_LEN(buf),
&match_ptr, &match_len, &run->errnum);
if (n == -1)
{
ret = -1;
p->in.pos--; /* unread the character in c */
break;
}
if (n == 1)
{
/* the match should be found at the end of
* the current buffer */
ASE_ASSERT (
ASE_STR_BUF(buf) + ASE_STR_LEN(buf) ==
match_ptr + match_len);
ASE_STR_LEN(buf) -= match_len;
p->in.pos--; /* unread the character in c */
break;
}
}
if (ase_str_ccat (buf, c) == (ase_size_t)-1)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
ret = -1;
break;
}
/* TODO: handle different line terminator like \r\n */
if (c == ASE_T('\n')) line_len = 0;
else line_len = line_len + 1;
}
if (rs_ptr != ASE_NULL &&
rs->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, rs_ptr);
ase_awk_refdownval (run, rs);
return ret;
}
int ase_awk_writeextio_val (
ase_awk_run_t* run, int out_type,
const ase_char_t* name, ase_awk_val_t* v)
{
ase_char_t* str;
ase_size_t len;
int n;
if (v->type == ASE_AWK_VAL_STR)
{
str = ((ase_awk_val_str_t*)v)->buf;
len = ((ase_awk_val_str_t*)v)->len;
}
else
{
str = ase_awk_valtostr (
run, v,
ASE_AWK_VALTOSTR_CLEAR | ASE_AWK_VALTOSTR_PRINT,
ASE_NULL, &len);
if (str == ASE_NULL) return -1;
}
n = ase_awk_writeextio_str (run, out_type, name, str, len);
if (v->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str);
return n;
}
int ase_awk_writeextio_str (
ase_awk_run_t* run, int out_type,
const ase_char_t* name, ase_char_t* str, ase_size_t len)
{
ase_awk_extio_t* p = run->extio.chain;
ase_awk_io_t handler;
int extio_type, extio_mode, extio_mask;
ase_ssize_t n;
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_type_map));
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mode_map));
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mask_map));
/* translate the out_type into the relevant extio type and mode */
extio_type = out_type_map[out_type];
extio_mode = out_mode_map[out_type];
extio_mask = out_mask_map[out_type];
handler = run->extio.handler[extio_type];
if (handler == ASE_NULL)
{
/* no io handler provided */
ase_awk_setrunerrnum (run, ASE_AWK_EIOUSER);
return -1;
}
/* look for the corresponding extio for name */
while (p != ASE_NULL)
{
/* the file "1.tmp", in the following code snippets,
* would be opened by the first print statement, but not by
* the second print statement. this is because
* both ASE_AWK_OUT_FILE and ASE_AWK_OUT_FILE_APPEND are
* translated to ASE_AWK_EXTIO_FILE and it is used to
* keep track of file handles..
*
* print "1111" >> "1.tmp"
* print "1111" > "1.tmp"
*/
if (p->type == (extio_type | extio_mask) &&
ase_strcmp (p->name, name) == 0) break;
p = p->next;
}
/* if there is not corresponding extio for name, create one */
if (p == ASE_NULL)
{
p = (ase_awk_extio_t*) ASE_AWK_MALLOC (
run->awk, ASE_SIZEOF(ase_awk_extio_t));
if (p == ASE_NULL)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
p->name = ase_strdup (name, &run->awk->prmfns.mmgr);
if (p->name == ASE_NULL)
{
ASE_AWK_FREE (run->awk, p);
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
p->run = run;
p->type = (extio_type | extio_mask);
p->mode = extio_mode;
p->handle = ASE_NULL;
p->next = ASE_NULL;
p->custom_data = run->extio.custom_data;
p->out.eof = ase_false;
p->out.eos = ase_false;
ase_awk_setrunerrnum (run, ASE_AWK_ENOERR);
n = handler (ASE_AWK_IO_OPEN, p, ASE_NULL, 0);
if (n <= -1)
{
ASE_AWK_FREE (run->awk, p->name);
ASE_AWK_FREE (run->awk, p);
if (run->errnum == ASE_AWK_ENOERR)
ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL);
return -1;
}
/* chain it */
p->next = run->extio.chain;
run->extio.chain = p;
/* usually, n == 0 indicates that it has reached the end
* of the input. the user io handler can return 0 for the
* open request if it doesn't have any files to open. One
* advantage of doing this would be that you can skip the
* entire pattern-block matching and exeuction. */
if (n == 0)
{
p->out.eos = ase_true;
return 0;
}
}
if (p->out.eos)
{
/* no more streams */
return 0;
}
if (p->out.eof)
{
/* it has reached the end of the stream but this function
* has been recalled */
return 0;
}
while (len > 0)
{
ase_awk_setrunerrnum (run, ASE_AWK_ENOERR);
n = handler (ASE_AWK_IO_WRITE, p, str, len);
if (n <= -1)
{
if (run->errnum == ASE_AWK_ENOERR)
ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL);
return -1;
}
if (n == 0)
{
p->out.eof = ase_true;
return 0;
}
len -= n;
str += n;
}
return 1;
}
int ase_awk_flushextio (
ase_awk_run_t* run, int out_type, const ase_char_t* name)
{
ase_awk_extio_t* p = run->extio.chain;
ase_awk_io_t handler;
int extio_type, /*extio_mode,*/ extio_mask;
ase_ssize_t n;
ase_bool_t ok = ase_false;
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_type_map));
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mode_map));
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mask_map));
/* translate the out_type into the relevant extio type and mode */
extio_type = out_type_map[out_type];
/*extio_mode = out_mode_map[out_type];*/
extio_mask = out_mask_map[out_type];
handler = run->extio.handler[extio_type];
if (handler == ASE_NULL)
{
/* no io handler provided */
ase_awk_setrunerrnum (run, ASE_AWK_EIOUSER);
return -1;
}
/* look for the corresponding extio for name */
while (p != ASE_NULL)
{
if (p->type == (extio_type | extio_mask) &&
(name == ASE_NULL || ase_strcmp(p->name,name) == 0))
{
ase_awk_setrunerrnum (run, ASE_AWK_ENOERR);
n = handler (ASE_AWK_IO_FLUSH, p, ASE_NULL, 0);
if (n <= -1)
{
if (run->errnum == ASE_AWK_ENOERR)
ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL);
return -1;
}
ok = ase_true;
}
p = p->next;
}
if (ok) return 0;
/* there is no corresponding extio for name */
ase_awk_setrunerrnum (run, ASE_AWK_EIONONE);
return -1;
}
int ase_awk_nextextio_read (
ase_awk_run_t* run, int in_type, const ase_char_t* name)
{
ase_awk_extio_t* p = run->extio.chain;
ase_awk_io_t handler;
int extio_type, /*extio_mode,*/ extio_mask;
ase_ssize_t n;
ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_type_map));
ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_mode_map));
ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_mask_map));
/* translate the in_type into the relevant extio type and mode */
extio_type = in_type_map[in_type];
/*extio_mode = in_mode_map[in_type];*/
extio_mask = in_mask_map[in_type];
handler = run->extio.handler[extio_type];
if (handler == ASE_NULL)
{
/* no io handler provided */
ase_awk_setrunerrnum (run, ASE_AWK_EIOUSER);
return -1;
}
while (p != ASE_NULL)
{
if (p->type == (extio_type | extio_mask) &&
ase_strcmp (p->name,name) == 0) break;
p = p->next;
}
if (p == ASE_NULL)
{
/* something is totally wrong */
ASE_ASSERT (
!"should never happen - cannot find the relevant extio entry");
ase_awk_setrunerror (run, ASE_AWK_EINTERN, 0, ASE_NULL, 0);
return -1;
}
if (p->in.eos)
{
/* no more streams. */
return 0;
}
ase_awk_setrunerrnum (run, ASE_AWK_ENOERR);
n = handler (ASE_AWK_IO_NEXT, p, ASE_NULL, 0);
if (n <= -1)
{
if (run->errnum == ASE_AWK_ENOERR)
ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL);
return -1;
}
if (n == 0)
{
/* the next stream cannot be opened.
* set the eos flags so that the next call to nextextio_read
* will return 0 without executing the handler */
p->in.eos = ase_true;
return 0;
}
else
{
/* as the next stream has been opened successfully,
* the eof flag should be cleared if set */
p->in.eof = ase_false;
/* also the previous input buffer must be reset */
p->in.pos = 0;
p->in.len = 0;
return 1;
}
}
int ase_awk_nextextio_write (
ase_awk_run_t* run, int out_type, const ase_char_t* name)
{
ase_awk_extio_t* p = run->extio.chain;
ase_awk_io_t handler;
int extio_type, /*extio_mode,*/ extio_mask;
ase_ssize_t n;
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_type_map));
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mode_map));
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mask_map));
/* translate the out_type into the relevant extio type and mode */
extio_type = out_type_map[out_type];
/*extio_mode = out_mode_map[out_type];*/
extio_mask = out_mask_map[out_type];
handler = run->extio.handler[extio_type];
if (handler == ASE_NULL)
{
/* no io handler provided */
ase_awk_setrunerrnum (run, ASE_AWK_EIOUSER);
return -1;
}
while (p != ASE_NULL)
{
if (p->type == (extio_type | extio_mask) &&
ase_strcmp (p->name,name) == 0) break;
p = p->next;
}
if (p == ASE_NULL)
{
/* something is totally wrong */
ASE_ASSERT (!"should never happen - cannot find the relevant extio entry");
ase_awk_setrunerror (run, ASE_AWK_EINTERN, 0, ASE_NULL, 0);
return -1;
}
if (p->out.eos)
{
/* no more streams. */
return 0;
}
ase_awk_setrunerrnum (run, ASE_AWK_ENOERR);
n = handler (ASE_AWK_IO_NEXT, p, ASE_NULL, 0);
if (n <= -1)
{
if (run->errnum == ASE_AWK_ENOERR)
ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL);
return -1;
}
if (n == 0)
{
/* the next stream cannot be opened.
* set the eos flags so that the next call to nextextio_write
* will return 0 without executing the handler */
p->out.eos = ase_true;
return 0;
}
else
{
/* as the next stream has been opened successfully,
* the eof flag should be cleared if set */
p->out.eof = ase_false;
return 1;
}
}
int ase_awk_closeextio_read (
ase_awk_run_t* run, int in_type, const ase_char_t* name)
{
ase_awk_extio_t* p = run->extio.chain, * px = ASE_NULL;
ase_awk_io_t handler;
int extio_type, /*extio_mode,*/ extio_mask;
ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_type_map));
ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_mode_map));
ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_mask_map));
/* translate the in_type into the relevant extio type and mode */
extio_type = in_type_map[in_type];
/*extio_mode = in_mode_map[in_type];*/
extio_mask = in_mask_map[in_type];
handler = run->extio.handler[extio_type];
if (handler == ASE_NULL)
{
/* no io handler provided */
ase_awk_setrunerrnum (run, ASE_AWK_EIOUSER);
return -1;
}
while (p != ASE_NULL)
{
if (p->type == (extio_type | extio_mask) &&
ase_strcmp (p->name, name) == 0)
{
ase_awk_io_t handler;
handler = run->extio.handler[p->type & MASK_CLEAR];
if (handler != ASE_NULL)
{
if (handler (ASE_AWK_IO_CLOSE, p, ASE_NULL, 0) <= -1)
{
/* this is not a run-time error.*/
ase_awk_setrunerror (run, ASE_AWK_EIOIMPL, 0, ASE_NULL, 0);
return -1;
}
}
if (px != ASE_NULL) px->next = p->next;
else run->extio.chain = p->next;
ASE_AWK_FREE (run->awk, p->name);
ASE_AWK_FREE (run->awk, p);
return 0;
}
px = p;
p = p->next;
}
/* the name given is not found */
ase_awk_setrunerrnum (run, ASE_AWK_EIONONE);
return -1;
}
int ase_awk_closeextio_write (
ase_awk_run_t* run, int out_type, const ase_char_t* name)
{
ase_awk_extio_t* p = run->extio.chain, * px = ASE_NULL;
ase_awk_io_t handler;
int extio_type, /*extio_mode,*/ extio_mask;
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_type_map));
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mode_map));
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mask_map));
/* translate the out_type into the relevant extio type and mode */
extio_type = out_type_map[out_type];
/*extio_mode = out_mode_map[out_type];*/
extio_mask = out_mask_map[out_type];
handler = run->extio.handler[extio_type];
if (handler == ASE_NULL)
{
/* no io handler provided */
ase_awk_setrunerror (run, ASE_AWK_EIOUSER, 0, ASE_NULL, 0);
return -1;
}
while (p != ASE_NULL)
{
if (p->type == (extio_type | extio_mask) &&
ase_strcmp (p->name, name) == 0)
{
ase_awk_io_t handler;
handler = run->extio.handler[p->type & MASK_CLEAR];
if (handler != ASE_NULL)
{
ase_awk_setrunerrnum (run, ASE_AWK_ENOERR);
if (handler (ASE_AWK_IO_CLOSE, p, ASE_NULL, 0) <= -1)
{
if (run->errnum == ASE_AWK_ENOERR)
ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL);
return -1;
}
}
if (px != ASE_NULL) px->next = p->next;
else run->extio.chain = p->next;
ASE_AWK_FREE (run->awk, p->name);
ASE_AWK_FREE (run->awk, p);
return 0;
}
px = p;
p = p->next;
}
ase_awk_setrunerrnum (run, ASE_AWK_EIONONE);
return -1;
}
int ase_awk_closeextio (ase_awk_run_t* run, const ase_char_t* name)
{
ase_awk_extio_t* p = run->extio.chain, * px = ASE_NULL;
while (p != ASE_NULL)
{
/* it handles the first that matches the given name
* regardless of the extio type */
if (ase_strcmp (p->name, name) == 0)
{
ase_awk_io_t handler;
handler = run->extio.handler[p->type & MASK_CLEAR];
if (handler != ASE_NULL)
{
ase_awk_setrunerrnum (run, ASE_AWK_ENOERR);
if (handler (ASE_AWK_IO_CLOSE, p, ASE_NULL, 0) <= -1)
{
/* this is not a run-time error.*/
if (run->errnum == ASE_AWK_ENOERR)
ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL);
return -1;
}
}
if (px != ASE_NULL) px->next = p->next;
else run->extio.chain = p->next;
ASE_AWK_FREE (run->awk, p->name);
ASE_AWK_FREE (run->awk, p);
return 0;
}
px = p;
p = p->next;
}
ase_awk_setrunerrnum (run, ASE_AWK_EIONONE);
return -1;
}
void ase_awk_clearextio (ase_awk_run_t* run)
{
ase_awk_extio_t* next;
ase_awk_io_t handler;
ase_ssize_t n;
while (run->extio.chain != ASE_NULL)
{
handler = run->extio.handler[
run->extio.chain->type & MASK_CLEAR];
next = run->extio.chain->next;
if (handler != ASE_NULL)
{
ase_awk_setrunerrnum (run, ASE_AWK_ENOERR);
n = handler (ASE_AWK_IO_CLOSE, run->extio.chain, ASE_NULL, 0);
if (n <= -1)
{
if (run->errnum == ASE_AWK_ENOERR)
ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL);
/* TODO: some warnings need to be shown??? */
}
}
ASE_AWK_FREE (run->awk, run->extio.chain->name);
ASE_AWK_FREE (run->awk, run->extio.chain);
run->extio.chain = next;
}
}

51
ase/lib/awk/extio.h Normal file
View File

@ -0,0 +1,51 @@
/*
* $Id: extio.h 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
#ifndef _ASE_AWK_EXTIO_H_
#define _ASE_AWK_EXTIO_H_
#ifndef _ASE_AWK_AWK_H_
#error Never include this file directly. Include <ase/awk/awk.h> instead
#endif
#ifdef __cplusplus
extern "C"
#endif
int ase_awk_readextio (
ase_awk_run_t* run, int in_type,
const ase_char_t* name, ase_str_t* buf);
int ase_awk_writeextio_val (
ase_awk_run_t* run, int out_type,
const ase_char_t* name, ase_awk_val_t* v);
int ase_awk_writeextio_str (
ase_awk_run_t* run, int out_type,
const ase_char_t* name, ase_char_t* str, ase_size_t len);
int ase_awk_flushextio (
ase_awk_run_t* run, int out_type, const ase_char_t* name);
int ase_awk_nextextio_read (
ase_awk_run_t* run, int in_type, const ase_char_t* name);
int ase_awk_nextextio_write (
ase_awk_run_t* run, int out_type, const ase_char_t* name);
int ase_awk_closeextio_read (
ase_awk_run_t* run, int in_type, const ase_char_t* name);
int ase_awk_closeextio_write (
ase_awk_run_t* run, int out_type, const ase_char_t* name);
int ase_awk_closeextio (ase_awk_run_t* run, const ase_char_t* name);
void ase_awk_clearextio (ase_awk_run_t* run);
#ifdef __cplusplus
}
#endif
#endif

1405
ase/lib/awk/func.c Normal file

File diff suppressed because it is too large Load Diff

49
ase/lib/awk/func.h Normal file
View File

@ -0,0 +1,49 @@
/*
* $Id: func.h 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
#ifndef _ASE_AWK_FUNC_H_
#define _ASE_AWK_FUNC_H_
#ifndef _ASE_AWK_AWK_H_
#error Never include this file directly. Include <ase/awk/awk.h> instead
#endif
typedef struct ase_awk_bfn_t ase_awk_bfn_t;
struct ase_awk_bfn_t
{
struct
{
ase_char_t* ptr;
ase_size_t len;
} name;
int valid; /* the entry is valid when this option is set */
struct
{
ase_size_t min;
ase_size_t max;
ase_char_t* spec;
} arg;
int (*handler) (ase_awk_run_t*, const ase_char_t*, ase_size_t);
/*ase_awk_bfn_t* next;*/
};
#ifdef __cplusplus
extern "C" {
#endif
ase_awk_bfn_t* ase_awk_getbfn (
ase_awk_t* awk, const ase_char_t* name, ase_size_t len);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,34 @@
#
# generrcode-java.awk
#
# aseawk -f generrcode-java.awk awk.h
#
BEGIN {
collect=0;
tab2="\t";
tab3="\t\t";
count=0;
}
/^[[:space:]]*enum[[:space:]]+ase_awk_errnum_t[[:space:]]*$/ {
collect=1;
print tab2 "// generated by generrcode-java.awk";
#print tab2 "enum ErrorCode";
#print tab2 "{";
}
collect && /^[[:space:]]*};[[:space:]]*$/ {
#print tab2 "};";
print tab2 "// end of error codes";
print "";
collect=0;
}
collect && /^[[:space:]]*ASE_AWK_E[[:alnum:]]+/ {
split ($1, flds, ",");
name=flds[1];
print tab2 "public static final int " substr (name,10,length(name)-9) " = " count++ ";";
}

View 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 ",";
}

View File

@ -0,0 +1,33 @@
#
# generrcode.awk
#
# aseawk -f generrcode.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.awk";
print tab3 "enum ErrorCode";
print tab3 "{";
}
collect && /^[[:space:]]*};[[:space:]]*$/ {
print tab3 "};";
print tab3 "// end of enum ErrorCode";
print "";
collect=0;
}
collect && /^[[:space:]]*ASE_AWK_E[[:alnum:]]+/ {
split ($1, flds, ",");
name=flds[1];
print tab4 "ERR_" substr (name,10,length(name)-9) " = " name ",";
}

View File

@ -0,0 +1,33 @@
#
# genoptcode.awk
#
# aseawk -f generror.awk awk.h
#
BEGIN {
collect=0;
tab3="\t\t";
tab4="\t\t\t";
}
/^[[:space:]]*enum[[:space:]]+ase_awk_option_t[[:space:]]*$/ {
collect=1;
print tab3 "// generated by genoptcode.awk";
print tab3 "enum Option";
print tab3 "{";
}
collect && /^[[:space:]]*};[[:space:]]*$/ {
print tab3 "};";
print tab3 "// end of enum Option";
print "";
collect=0;
}
collect && /^[[:space:]]*ASE_AWK_[[:alnum:]]+/ {
split ($1, flds, ",");
name=flds[1];
print tab4 "OPT_" substr (name,9,length(name)-8) " = " name ",";
}

41
ase/lib/awk/jni-dmc.def Normal file
View File

@ -0,0 +1,41 @@
LIBRARY "aseawk_jni.dll"
EXETYPE NT
EXPORTS
Java_ase_awk_Awk_open
Java_ase_awk_Awk_close
Java_ase_awk_Awk_parse
Java_ase_awk_Awk_run
Java_ase_awk_Awk_stop
Java_ase_awk_Awk_getmaxdepth
Java_ase_awk_Awk_setmaxdepth
Java_ase_awk_Awk_getoption
Java_ase_awk_Awk_setoption
Java_ase_awk_Awk_getdebug
Java_ase_awk_Awk_setdebug
Java_ase_awk_Awk_getword
Java_ase_awk_Awk_setword
Java_ase_awk_Awk_addfunc
Java_ase_awk_Awk_delfunc
Java_ase_awk_Awk_setfilename
Java_ase_awk_Awk_setofilename
Java_ase_awk_Awk_strftime
Java_ase_awk_Awk_strfgmtime
Java_ase_awk_Awk_system
Java_ase_awk_Context_stop
Java_ase_awk_Context_getglobal
Java_ase_awk_Context_setglobal
Java_ase_awk_Argument_getintval
Java_ase_awk_Argument_getrealval
Java_ase_awk_Argument_getstrval
Java_ase_awk_Argument_isindexed
Java_ase_awk_Argument_getindexed
Java_ase_awk_Argument_clearval
Java_ase_awk_Return_isindexed
Java_ase_awk_Return_setintval
Java_ase_awk_Return_setrealval
Java_ase_awk_Return_setstrval
Java_ase_awk_Return_setindexedintval
Java_ase_awk_Return_setindexedrealval
Java_ase_awk_Return_setindexedstrval
Java_ase_awk_Return_clearval

3010
ase/lib/awk/jni.c Normal file

File diff suppressed because it is too large Load Diff

40
ase/lib/awk/jni.def Normal file
View File

@ -0,0 +1,40 @@
LIBRARY "aseawk_jni.dll"
EXPORTS
Java_ase_awk_Awk_open
Java_ase_awk_Awk_close
Java_ase_awk_Awk_parse
Java_ase_awk_Awk_run
Java_ase_awk_Awk_stop
Java_ase_awk_Awk_getmaxdepth
Java_ase_awk_Awk_setmaxdepth
Java_ase_awk_Awk_getoption
Java_ase_awk_Awk_setoption
Java_ase_awk_Awk_getdebug
Java_ase_awk_Awk_setdebug
Java_ase_awk_Awk_getword
Java_ase_awk_Awk_setword
Java_ase_awk_Awk_addfunc
Java_ase_awk_Awk_delfunc
Java_ase_awk_Awk_setfilename
Java_ase_awk_Awk_setofilename
Java_ase_awk_Awk_strftime
Java_ase_awk_Awk_strfgmtime
Java_ase_awk_Awk_system
Java_ase_awk_Context_stop
Java_ase_awk_Context_getglobal
Java_ase_awk_Context_setglobal
Java_ase_awk_Argument_getintval
Java_ase_awk_Argument_getrealval
Java_ase_awk_Argument_getstrval
Java_ase_awk_Argument_isindexed
Java_ase_awk_Argument_getindexed
Java_ase_awk_Argument_clearval
Java_ase_awk_Return_isindexed
Java_ase_awk_Return_setintval
Java_ase_awk_Return_setrealval
Java_ase_awk_Return_setstrval
Java_ase_awk_Return_setindexedintval
Java_ase_awk_Return_setindexedrealval
Java_ase_awk_Return_setindexedstrval
Java_ase_awk_Return_clearval

88
ase/lib/awk/jni.h Normal file
View File

@ -0,0 +1,88 @@
/*
* $Id: jni.h 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
#ifndef _ASE_AWK_JNI_H_
#define _ASE_AWK_JNI_H_
#if defined(__APPLE__) && defined(__MACH__)
#include <JavaVM/jni.h>
#else
#include <jni.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj);
JNIEXPORT void JNICALL Java_ase_awk_Awk_close (JNIEnv* env, jobject obj, jlong awkid);
JNIEXPORT void JNICALL Java_ase_awk_Awk_parse (JNIEnv* env, jobject obj, jlong awkid);
JNIEXPORT void JNICALL Java_ase_awk_Awk_run (
JNIEnv* env, jobject obj, jlong awkid, jstring mfn, jobjectArray args);
JNIEXPORT void JNICALL Java_ase_awk_Awk_stop (JNIEnv* env, jobject obj, jlong awkid);
JNIEXPORT void JNICALL Java_ase_awk_Awk_addfunc (
JNIEnv* env, jobject obj, jstring name, jint min_args, jint max_args);
JNIEXPORT void JNICALL Java_ase_awk_Awk_delfunc (
JNIEnv* env, jobject obj, jstring name);
JNIEXPORT jint JNICALL Java_ase_awk_Awk_getmaxdepth (
JNIEnv* env, jobject obj, jlong awkid, jint id);
JNIEXPORT void JNICALL Java_ase_awk_Awk_setmaxdepth (
JNIEnv* env, jobject obj, jlong awkid, jint ids, jint depth);
JNIEXPORT jint JNICALL Java_ase_awk_Awk_getoption (
JNIEnv* env, jobject obj, jlong awkid);
JNIEXPORT void JNICALL Java_ase_awk_Awk_setoption (
JNIEnv* env, jobject obj, jlong awkid, jint options);
JNIEXPORT jboolean JNICALL Java_ase_awk_Awk_getdebug (
JNIEnv* env, jobject obj, jlong awkid);
JNIEXPORT void JNICALL Java_ase_awk_Awk_setdebug (
JNIEnv* env, jobject obj, jlong awkid, jboolean debug);
JNIEXPORT jstring JNICALL Java_ase_awk_Awk_getword (
JNIEnv* env, jobject obj, jlong awkid, jstring ow);
JNIEXPORT void JNICALL Java_ase_awk_Awk_setword (
JNIEnv* env, jobject obj, jlong awkid, jstring ow, jstring nw);
JNIEXPORT void JNICALL Java_ase_awk_Awk_setfilename (
JNIEnv* env, jobject obj, jlong runid, jstring name);
JNIEXPORT void JNICALL Java_ase_awk_Awk_setofilename (
JNIEnv* env, jobject obj, jlong runid, jstring name);
JNIEXPORT jstring JNICALL Java_ase_awk_Awk_strftime (
JNIEnv* env, jobject obj, jstring fmt, jlong sec);
JNIEXPORT jstring JNICALL Java_ase_awk_Awk_strfgmtime (
JNIEnv* env, jobject obj, jstring fmt, jlong sec);
JNIEXPORT jint JNICALL Java_ase_awk_Awk_system (
JNIEnv* env, jobject obj, jstring cmd);
JNIEXPORT void JNICALL Java_ase_awk_Context_stop (JNIEnv* env, jobject obj, jlong runid);
JNIEXPORT jobject JNICALL Java_ase_awk_Context_getglobal (JNIEnv* env, jobject obj, jlong runid, jint id);
JNIEXPORT void JNICALL Java_ase_awk_Context_setglobal (JNIEnv* env, jobject obj, jlong runid, jint id, jobject ret);
JNIEXPORT jlong JNICALL Java_ase_awk_Argument_getintval (JNIEnv* env, jobject obj, jlong runid, jlong valid);
JNIEXPORT jdouble JNICALL Java_ase_awk_Argument_getrealval (JNIEnv* env, jobject obj, jlong runid, jlong valid);
JNIEXPORT jstring JNICALL Java_ase_awk_Argument_getstrval (JNIEnv* env, jobject obj, jlong runid, jlong valid);
JNIEXPORT jboolean JNICALL Java_ase_awk_Argument_isindexed (JNIEnv* env, jobject obj, jlong runid, jlong valid);
JNIEXPORT jobject JNICALL Java_ase_awk_Argument_getindexed (JNIEnv* env, jobject obj, jlong runid, jlong valid, jstring index);
JNIEXPORT void JNICALL Java_ase_awk_Argument_clearval (JNIEnv* env, jobject obj, jlong runid, jlong valid);
JNIEXPORT jboolean JNICALL Java_ase_awk_Return_isindexed (JNIEnv* env, jobject obj, jlong runid, jlong valid);
JNIEXPORT void JNICALL Java_ase_awk_Return_setintval (JNIEnv* env, jobject obj, jlong runid, jlong valid, jlong newval);
JNIEXPORT void JNICALL Java_ase_awk_Return_setrealval (JNIEnv* env, jobject obj, jlong runid, jlong valid, jdouble newval);
JNIEXPORT void JNICALL Java_ase_awk_Return_setstrval (JNIEnv* env, jobject obj, jlong runid, jlong valid, jstring newval);
JNIEXPORT void JNICALL Java_ase_awk_Return_setindexedintval (JNIEnv* env, jobject obj, jlong runid, jlong valid, jstring index, jlong newval);
JNIEXPORT void JNICALL Java_ase_awk_Return_setindexedrealval (JNIEnv* env, jobject obj, jlong runid, jlong valid, jstring index, jdouble newval);
JNIEXPORT void JNICALL Java_ase_awk_Return_setindexedstrval (JNIEnv* env, jobject obj, jlong runid, jlong valid, jstring index, jstring newval);
JNIEXPORT void JNICALL Java_ase_awk_Return_clearval (JNIEnv* env, jobject obj, jlong runid, jlong valid);
#ifdef __cplusplus
}
#endif
#endif

248
ase/lib/awk/makefile.in Normal file
View File

@ -0,0 +1,248 @@
#
# $Id: makefile.in,v 1.10 2007/10/15 16:15:42 bacon Exp $
#
NAME = aseawk
TOP_BUILDDIR = @abs_top_builddir@
TOP_INSTALLDIR = @prefix@/ase
CC = @CC@
CXX = @CXX@
AR = @AR@
RANLIB = @RANLIB@
CFLAGS = @CFLAGS@ -I@abs_top_builddir@/..
CXXFLAGS = @CXXFLAGS@ -I@abs_top_builddir@/..
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
MODE = @BUILDMODE@
CJ = @CJ@
CJFLAGS = @CJFLAGS@ --classpath=@abs_top_builddir@/.. -fjni
BUILD_CJ = @BUILD_CJ@
JAVAC = @JAVAC@
JAR = @JAR@
CFLAGS_JNI = @CFLAGS_JNI@
BUILD_JNI = @BUILD_JNI@
LIBTOOL_COMPILE = ../libtool --mode=compile
LIBTOOL_LINK = ../libtool --mode=link
OUT_DIR = ../$(MODE)/lib
OUT_FILE_LIB = $(OUT_DIR)/lib$(NAME).a
OUT_FILE_JNI = $(OUT_DIR)/lib$(NAME)_jni.la
OUT_FILE_LIB_CXX = $(OUT_DIR)/lib$(NAME)++.a
OUT_FILE_LIB_CJ = $(OUT_DIR)/lib$(NAME)ja.a
OUT_FILE_JAR = $(OUT_DIR)/$(NAME).jar
TMP_DIR = $(MODE)
TMP_DIR_CXX = $(TMP_DIR)/cxx
TMP_DIR_CJ = $(TMP_DIR)/cj
OBJ_FILES_LIB = \
$(TMP_DIR)/awk.o \
$(TMP_DIR)/err.o \
$(TMP_DIR)/tree.o \
$(TMP_DIR)/tab.o \
$(TMP_DIR)/parse.o \
$(TMP_DIR)/run.o \
$(TMP_DIR)/rec.o \
$(TMP_DIR)/val.o \
$(TMP_DIR)/func.o \
$(TMP_DIR)/misc.o \
$(TMP_DIR)/extio.o
OBJ_FILES_JNI = $(TMP_DIR)/jni.o
OBJ_FILES_LIB_CXX = \
$(TMP_DIR)/cxx/Awk.o \
$(TMP_DIR)/cxx/StdAwk.o
OBJ_FILES_LIB_CJ = \
$(TMP_DIR)/cj/Awk.o \
$(TMP_DIR)/cj/StdAwk.o \
$(TMP_DIR)/cj/Context.o \
$(TMP_DIR)/cj/Extio.o \
$(TMP_DIR)/cj/IO.o \
$(TMP_DIR)/cj/Console.o \
$(TMP_DIR)/cj/File.o \
$(TMP_DIR)/cj/Pipe.o \
$(TMP_DIR)/cj/Exception.o \
$(TMP_DIR)/cj/Return.o \
$(TMP_DIR)/cj/Argument.o \
$(TMP_DIR)/cj/Clearable.o
OBJ_FILES_SO = $(OBJ_FILES_LIB:.o=.lo) $(OBJ_FILES_JNI:.o=.lo)
OBJ_FILES_JAR = \
$(TMP_DIR)/ase/awk/Awk.class \
$(TMP_DIR)/ase/awk/StdAwk.class \
$(TMP_DIR)/ase/awk/Context.class \
$(TMP_DIR)/ase/awk/Extio.class \
$(TMP_DIR)/ase/awk/IO.class \
$(TMP_DIR)/ase/awk/Console.class \
$(TMP_DIR)/ase/awk/File.class \
$(TMP_DIR)/ase/awk/Pipe.class \
$(TMP_DIR)/ase/awk/Exception.class \
$(TMP_DIR)/ase/awk/Return.class \
$(TMP_DIR)/ase/awk/Argument.class \
$(TMP_DIR)/ase/awk/Clearable.class
lib: build$(BUILD_JNI)$(BUILD_CJ)
build: $(OUT_FILE_LIB) $(OUT_FILE_LIB_CXX)
buildjnicj: buildjni buildcj
buildjni: build $(OUT_FILE_JNI)
buildcj: build $(OUT_FILE_LIB_CJ)
$(OUT_FILE_LIB): $(TMP_DIR) $(OUT_DIR) $(OBJ_FILES_LIB)
$(AR) cr $(OUT_FILE_LIB) $(OBJ_FILES_LIB)
if [ ! -z "$(RANLIB)" ]; then $(RANLIB) $(OUT_FILE_LIB); fi
$(OUT_FILE_JNI): $(TMP_DIR) $(OBJ_FILES_JNI) $(OBJ_FILES_JAR) $(OUT_FILE_LIB)
$(LIBTOOL_LINK) $(CC) -rpath $(TOP_INSTALLDIR)/lib -version-info 1:0:0 -o $(OUT_FILE_JNI) $(OBJ_FILES_SO) -lm -L$(OUT_DIR) -l$(NAME) -lasecmn -laseutl
$(JAR) -Mcvf $(OUT_FILE_JAR) -C $(TMP_DIR) ase
$(OUT_FILE_LIB_CXX): $(TMP_DIR_CXX) $(OUT_DIR) $(OUT_FILE_LIB) $(OBJ_FILES_LIB_CXX)
$(AR) cr $(OUT_FILE_LIB_CXX) $(OBJ_FILES_LIB_CXX)
if [ ! -z "$(RANLIB)" ]; then $(RANLIB) $(OUT_FILE_LIB_CXX); fi
$(OUT_FILE_LIB_CJ): $(TMP_DIR_CJ) $(OUT_DIR) $(OBJ_FILES_LIB_CJ)
$(AR) cr $(OUT_FILE_LIB_CJ) $(OBJ_FILES_LIB_CJ)
if [ ! -z "$(RANLIB)" ]; then $(RANLIB) $(OUT_FILE_LIB_CJ); fi
$(TMP_DIR)/awk.o: awk.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c awk.c
$(TMP_DIR)/err.o: err.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c err.c
$(TMP_DIR)/tree.o: tree.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c tree.c
$(TMP_DIR)/tab.o: tab.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c tab.c
$(TMP_DIR)/parse.o: parse.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c parse.c
$(TMP_DIR)/run.o: run.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c run.c
$(TMP_DIR)/rec.o: rec.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c rec.c
$(TMP_DIR)/val.o: val.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c val.c
$(TMP_DIR)/func.o: func.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c func.c
$(TMP_DIR)/misc.o: misc.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c misc.c
$(TMP_DIR)/extio.o: extio.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c extio.c
$(TMP_DIR)/jni.o: jni.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) $(CFLAGS_JNI) -o $@ -c jni.c
$(TMP_DIR)/ase/awk/Awk.class: Awk.java
$(JAVAC) -classpath ../.. -d $(TMP_DIR) Awk.java
$(TMP_DIR)/ase/awk/StdAwk.class: StdAwk.java
$(JAVAC) -classpath ../.. -d $(TMP_DIR) StdAwk.java
$(TMP_DIR)/ase/awk/Context.class: Context.java
$(JAVAC) -classpath ../.. -d $(TMP_DIR) Context.java
$(TMP_DIR)/ase/awk/Extio.class: Extio.java
$(JAVAC) -classpath ../.. -d $(TMP_DIR) Extio.java
$(TMP_DIR)/ase/awk/IO.class: IO.java
$(JAVAC) -classpath ../.. -d $(TMP_DIR) IO.java
$(TMP_DIR)/ase/awk/Console.class: Console.java
$(JAVAC) -classpath ../.. -d $(TMP_DIR) Console.java
$(TMP_DIR)/ase/awk/File.class: File.java
$(JAVAC) -classpath ../.. -d $(TMP_DIR) File.java
$(TMP_DIR)/ase/awk/Pipe.class: Pipe.java
$(JAVAC) -classpath ../.. -d $(TMP_DIR) Pipe.java
$(TMP_DIR)/ase/awk/Exception.class: Exception.java
$(JAVAC) -classpath ../.. -d $(TMP_DIR) Exception.java
$(TMP_DIR)/ase/awk/Return.class: Return.java
$(JAVAC) -classpath ../.. -d $(TMP_DIR) Return.java
$(TMP_DIR)/ase/awk/Argument.class: Argument.java
$(JAVAC) -classpath ../.. -d $(TMP_DIR) Argument.java
$(TMP_DIR)/ase/awk/Clearable.class: Clearable.java
$(JAVAC) -classpath ../.. -d $(TMP_DIR) Clearable.java
$(TMP_DIR)/cxx/Awk.o: Awk.cpp Awk.hpp
$(CXX) $(CXXFLAGS) -o $@ -c Awk.cpp
$(TMP_DIR)/cxx/StdAwk.o: StdAwk.cpp StdAwk.hpp Awk.hpp
$(CXX) $(CXXFLAGS) -o $@ -c StdAwk.cpp
$(TMP_DIR)/cj/Awk.o: Awk.java
$(CJ) $(CJFLAGS) -o $@ -c Awk.java
$(TMP_DIR)/cj/StdAwk.o: StdAwk.java
$(CJ) $(CJFLAGS) -o $@ -c StdAwk.java
$(TMP_DIR)/cj/Context.o: Context.java
$(CJ) $(CJFLAGS) -o $@ -c Context.java
$(TMP_DIR)/cj/Extio.o: Extio.java
$(CJ) $(CJFLAGS) -o $@ -c Extio.java
$(TMP_DIR)/cj/IO.o: IO.java
$(CJ) $(CJFLAGS) -o $@ -c IO.java
$(TMP_DIR)/cj/Console.o: Console.java
$(CJ) $(CJFLAGS) -o $@ -c Console.java
$(TMP_DIR)/cj/File.o: File.java
$(CJ) $(CJFLAGS) -o $@ -c File.java
$(TMP_DIR)/cj/Pipe.o: Pipe.java
$(CJ) $(CJFLAGS) -o $@ -c Pipe.java
$(TMP_DIR)/cj/Exception.o: Exception.java
$(CJ) $(CJFLAGS) -o $@ -c Exception.java
$(TMP_DIR)/cj/Return.o: Return.java
$(CJ) $(CJFLAGS) -o $@ -c Return.java
$(TMP_DIR)/cj/Argument.o: Argument.java
$(CJ) $(CJFLAGS) -o $@ -c Argument.java
$(TMP_DIR)/cj/Clearable.o: Clearable.java
$(CJ) $(CJFLAGS) -o $@ -c Clearable.java
$(OUT_DIR):
mkdir -p $(OUT_DIR)
$(TMP_DIR):
mkdir -p $(TMP_DIR)
$(TMP_DIR_CXX): $(TMP_DIR)
mkdir -p $(TMP_DIR_CXX)
$(TMP_DIR_CJ): $(TMP_DIR)
mkdir -p $(TMP_DIR_CJ)
clean:
rm -rf $(OUT_FILE_LIB) $(OUT_FILE_JNI) $(OUT_FILE_JAR) $(OUT_FILE_LIB_CXX) $(OUT_FILE_LIB_CJ)
rm -rf $(OBJ_FILES_LIB) $(OBJ_FILES_JNI) $(OBJ_FILES_JAR) $(OBJ_FILES_LIB_CXX) $(OBJ_FILES_LIB_CJ)

952
ase/lib/awk/misc.c Normal file
View File

@ -0,0 +1,952 @@
/*
* $Id: misc.c 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
#include <ase/awk/awk_i.h>
void* ase_awk_malloc (ase_awk_t* awk, ase_size_t size)
{
return ASE_AWK_MALLOC (awk, size);
}
void ase_awk_free (ase_awk_t* awk, void* ptr)
{
ASE_AWK_FREE (awk, ptr);
}
ase_char_t* ase_awk_strxdup (
ase_awk_t* awk, const ase_char_t* ptr, ase_size_t len)
{
return ase_strxdup (ptr, len, &awk->prmfns.mmgr);
}
ase_long_t ase_awk_strxtolong (
ase_awk_t* awk, const ase_char_t* str, ase_size_t len,
int base, const ase_char_t** endptr)
{
ase_long_t n = 0;
const ase_char_t* p;
const ase_char_t* end;
ase_size_t rem;
int digit, negative = 0;
ASE_ASSERT (base < 37);
p = str;
end = str + len;
/* strip off leading spaces */
/*while (ASE_AWK_ISSPACE(awk,*p)) p++;*/
/* check for a sign */
/*while (*p != ASE_T('\0')) */
while (p < end)
{
if (*p == ASE_T('-'))
{
negative = ~negative;
p++;
}
else if (*p == ASE_T('+')) p++;
else break;
}
/* check for a binary/octal/hexadecimal notation */
rem = end - p;
if (base == 0)
{
if (rem >= 1 && *p == ASE_T('0'))
{
p++;
if (rem == 1) base = 8;
else if (*p == ASE_T('x') || *p == ASE_T('X'))
{
p++; base = 16;
}
else if (*p == ASE_T('b') || *p == ASE_T('B'))
{
p++; base = 2;
}
else base = 8;
}
else base = 10;
}
else if (rem >= 2 && base == 16)
{
if (*p == ASE_T('0') &&
(*(p+1) == ASE_T('x') || *(p+1) == ASE_T('X'))) p += 2;
}
else if (rem >= 2 && base == 2)
{
if (*p == ASE_T('0') &&
(*(p+1) == ASE_T('b') || *(p+1) == ASE_T('B'))) p += 2;
}
/* process the digits */
/*while (*p != ASE_T('\0'))*/
while (p < end)
{
if (*p >= ASE_T('0') && *p <= ASE_T('9'))
digit = *p - ASE_T('0');
else if (*p >= ASE_T('A') && *p <= ASE_T('Z'))
digit = *p - ASE_T('A') + 10;
else if (*p >= ASE_T('a') && *p <= ASE_T('z'))
digit = *p - ASE_T('a') + 10;
else break;
if (digit >= base) break;
n = n * base + digit;
p++;
}
if (endptr != ASE_NULL) *endptr = p;
return (negative)? -n: n;
}
/*
* ase_awk_strtoreal is almost a replica of strtod.
*
* strtod.c --
*
* Source code for the "strtod" library procedure.
*
* Copyright (c) 1988-1993 The Regents of the University of California.
* Copyright (c) 1994 Sun Microsystems, Inc.
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
* fee is hereby granted, provided that the above copyright
* notice appear in all copies. The University of California
* makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without
* express or implied warranty.
*/
#define MAX_EXPONENT 511
ase_real_t ase_awk_strtoreal (ase_awk_t* awk, const ase_char_t* str)
{
/*
* Table giving binary powers of 10. Entry is 10^2^i.
* Used to convert decimal exponents into floating-point numbers.
*/
static ase_real_t powers_of_10[] =
{
10., 100., 1.0e4, 1.0e8, 1.0e16,
1.0e32, 1.0e64, 1.0e128, 1.0e256
};
ase_real_t fraction, dbl_exp, * d;
const ase_char_t* p;
ase_cint_t c;
int exp = 0; /* Esseonent read from "EX" field */
/*
* Esseonent that derives from the fractional part. Under normal
* circumstatnces, it is the negative of the number of digits in F.
* However, if I is very long, the last digits of I get dropped
* (otherwise a long I with a large negative exponent could cause an
* unnecessary overflow on I alone). In this case, frac_exp is
* incremented one for each dropped digit.
*/
int frac_exp;
int mant_size; /* Number of digits in mantissa. */
int dec_pt; /* Number of mantissa digits BEFORE decimal point */
const ase_char_t *pexp; /* Temporarily holds location of exponent in string */
int negative = 0, exp_negative = 0;
p = str;
/* strip off leading blanks */
/*while (ASE_AWK_ISSPACE(awk,*p)) p++;*/
/* check for a sign */
while (*p != ASE_T('\0'))
{
if (*p == ASE_T('-'))
{
negative = ~negative;
p++;
}
else if (*p == ASE_T('+')) p++;
else break;
}
/* Count the number of digits in the mantissa (including the decimal
* point), and also locate the decimal point. */
dec_pt = -1;
for (mant_size = 0; ; mant_size++)
{
c = *p;
if (!ASE_AWK_ISDIGIT (awk, c))
{
if ((c != ASE_T('.')) || (dec_pt >= 0)) break;
dec_pt = mant_size;
}
p++;
}
/*
* Now suck up the digits in the mantissa. Use two integers to
* collect 9 digits each (this is faster than using floating-point).
* If the mantissa has more than 18 digits, ignore the extras, since
* they can't affect the value anyway.
*/
pexp = p;
p -= mant_size;
if (dec_pt < 0)
{
dec_pt = mant_size;
}
else
{
mant_size--; /* One of the digits was the point */
}
if (mant_size > 18)
{
frac_exp = dec_pt - 18;
mant_size = 18;
}
else
{
frac_exp = dec_pt - mant_size;
}
if (mant_size == 0)
{
fraction = 0.0;
/*p = str;*/
p = pexp;
goto done;
}
else
{
int frac1, frac2;
frac1 = 0;
for ( ; mant_size > 9; mant_size--)
{
c = *p;
p++;
if (c == ASE_T('.'))
{
c = *p;
p++;
}
frac1 = 10 * frac1 + (c - ASE_T('0'));
}
frac2 = 0;
for (; mant_size > 0; mant_size--) {
c = *p;
p++;
if (c == ASE_T('.'))
{
c = *p;
p++;
}
frac2 = 10*frac2 + (c - ASE_T('0'));
}
fraction = (1.0e9 * frac1) + frac2;
}
/* Skim off the exponent */
p = pexp;
if ((*p == ASE_T('E')) || (*p == ASE_T('e')))
{
p++;
if (*p == ASE_T('-'))
{
exp_negative = 1;
p++;
}
else
{
if (*p == ASE_T('+')) p++;
exp_negative = 0;
}
if (!ASE_AWK_ISDIGIT (awk, *p))
{
/* p = pexp; */
/* goto done; */
goto no_exp;
}
while (ASE_AWK_ISDIGIT (awk, *p))
{
exp = exp * 10 + (*p - ASE_T('0'));
p++;
}
}
no_exp:
if (exp_negative) exp = frac_exp - exp;
else exp = frac_exp + exp;
/*
* Generate a floating-point number that represents the exponent.
* Do this by processing the exponent one bit at a time to combine
* many powers of 2 of 10. Then combine the exponent with the
* fraction.
*/
if (exp < 0)
{
exp_negative = 1;
exp = -exp;
}
else exp_negative = 0;
if (exp > MAX_EXPONENT) exp = MAX_EXPONENT;
dbl_exp = 1.0;
for (d = powers_of_10; exp != 0; exp >>= 1, d++)
{
if (exp & 01) dbl_exp *= *d;
}
if (exp_negative) fraction /= dbl_exp;
else fraction *= dbl_exp;
done:
return (negative)? -fraction: fraction;
}
ase_real_t ase_awk_strxtoreal (
ase_awk_t* awk, const ase_char_t* str, ase_size_t len,
const ase_char_t** endptr)
{
/*
* Table giving binary powers of 10. Entry is 10^2^i.
* Used to convert decimal exponents into floating-point numbers.
*/
static ase_real_t powers_of_10[] =
{
10., 100., 1.0e4, 1.0e8, 1.0e16,
1.0e32, 1.0e64, 1.0e128, 1.0e256
};
ase_real_t fraction, dbl_exp, * d;
const ase_char_t* p, * end;
ase_cint_t c;
int exp = 0; /* Esseonent read from "EX" field */
/*
* Esseonent that derives from the fractional part. Under normal
* circumstatnces, it is the negative of the number of digits in F.
* However, if I is very long, the last digits of I get dropped
* (otherwise a long I with a large negative exponent could cause an
* unnecessary overflow on I alone). In this case, frac_exp is
* incremented one for each dropped digit.
*/
int frac_exp;
int mant_size; /* Number of digits in mantissa. */
int dec_pt; /* Number of mantissa digits BEFORE decimal point */
const ase_char_t *pexp; /* Temporarily holds location of exponent in string */
int negative = 0, exp_negative = 0;
p = str;
end = str + len;
/* Strip off leading blanks and check for a sign */
/*while (ASE_AWK_ISSPACE(awk,*p)) p++;*/
/*while (*p != ASE_T('\0')) */
while (p < end)
{
if (*p == ASE_T('-'))
{
negative = ~negative;
p++;
}
else if (*p == ASE_T('+')) p++;
else break;
}
/* Count the number of digits in the mantissa (including the decimal
* point), and also locate the decimal point. */
dec_pt = -1;
/*for (mant_size = 0; ; mant_size++) */
for (mant_size = 0; p < end; mant_size++)
{
c = *p;
if (!ASE_AWK_ISDIGIT (awk, c))
{
if (c != ASE_T('.') || dec_pt >= 0) break;
dec_pt = mant_size;
}
p++;
}
/*
* Now suck up the digits in the mantissa. Use two integers to
* collect 9 digits each (this is faster than using floating-point).
* If the mantissa has more than 18 digits, ignore the extras, since
* they can't affect the value anyway.
*/
pexp = p;
p -= mant_size;
if (dec_pt < 0)
{
dec_pt = mant_size;
}
else
{
mant_size--; /* One of the digits was the point */
}
if (mant_size > 18) /* TODO: is 18 correct for ase_real_t??? */
{
frac_exp = dec_pt - 18;
mant_size = 18;
}
else
{
frac_exp = dec_pt - mant_size;
}
if (mant_size == 0)
{
fraction = 0.0;
/*p = str;*/
p = pexp;
goto done;
}
else
{
int frac1, frac2;
frac1 = 0;
for ( ; mant_size > 9; mant_size--)
{
c = *p;
p++;
if (c == ASE_T('.'))
{
c = *p;
p++;
}
frac1 = 10 * frac1 + (c - ASE_T('0'));
}
frac2 = 0;
for (; mant_size > 0; mant_size--) {
c = *p++;
if (c == ASE_T('.'))
{
c = *p;
p++;
}
frac2 = 10 * frac2 + (c - ASE_T('0'));
}
fraction = (1.0e9 * frac1) + frac2;
}
/* Skim off the exponent */
p = pexp;
if (p < end && (*p == ASE_T('E') || *p == ASE_T('e')))
{
p++;
if (p < end)
{
if (*p == ASE_T('-'))
{
exp_negative = 1;
p++;
}
else
{
if (*p == ASE_T('+')) p++;
exp_negative = 0;
}
}
else exp_negative = 0;
if (!(p < end && ASE_AWK_ISDIGIT (awk, *p)))
{
/*p = pexp;*/
/*goto done;*/
goto no_exp;
}
while (p < end && ASE_AWK_ISDIGIT (awk, *p))
{
exp = exp * 10 + (*p - ASE_T('0'));
p++;
}
}
no_exp:
if (exp_negative) exp = frac_exp - exp;
else exp = frac_exp + exp;
/*
* Generate a floating-point number that represents the exponent.
* Do this by processing the exponent one bit at a time to combine
* many powers of 2 of 10. Then combine the exponent with the
* fraction.
*/
if (exp < 0)
{
exp_negative = 1;
exp = -exp;
}
else exp_negative = 0;
if (exp > MAX_EXPONENT) exp = MAX_EXPONENT;
dbl_exp = 1.0;
for (d = powers_of_10; exp != 0; exp >>= 1, d++)
{
if (exp & 01) dbl_exp *= *d;
}
if (exp_negative) fraction /= dbl_exp;
else fraction *= dbl_exp;
done:
if (endptr != ASE_NULL) *endptr = p;
return (negative)? -fraction: fraction;
}
ase_size_t ase_awk_longtostr (
ase_long_t value, int radix, const ase_char_t* prefix,
ase_char_t* buf, ase_size_t size)
{
ase_long_t t, rem;
ase_size_t len, ret, i;
ase_size_t prefix_len;
prefix_len = (prefix != ASE_NULL)? ase_strlen(prefix): 0;
t = value;
if (t == 0)
{
/* zero */
if (buf == ASE_NULL)
{
/* if buf is not given,
* return the number of bytes required */
return prefix_len + 1;
}
if (size < prefix_len+1)
{
/* buffer too small */
return (ase_size_t)-1;
}
for (i = 0; i < prefix_len; i++) buf[i] = prefix[i];
buf[prefix_len] = ASE_T('0');
if (size > prefix_len+1) buf[prefix_len+1] = ASE_T('\0');
return prefix_len+1;
}
/* non-zero values */
len = prefix_len;
if (t < 0) { t = -t; len++; }
while (t > 0) { len++; t /= radix; }
if (buf == ASE_NULL)
{
/* if buf is not given, return the number of bytes required */
return len;
}
if (size < len) return (ase_size_t)-1; /* buffer too small */
if (size > len) buf[len] = ASE_T('\0');
ret = len;
t = value;
if (t < 0) t = -t;
while (t > 0)
{
rem = t % radix;
if (rem >= 10)
buf[--len] = (ase_char_t)rem + ASE_T('a') - 10;
else
buf[--len] = (ase_char_t)rem + ASE_T('0');
t /= radix;
}
if (value < 0)
{
for (i = 1; i <= prefix_len; i++)
{
buf[i] = prefix[i-1];
len--;
}
buf[--len] = ASE_T('-');
}
else
{
for (i = 0; i < prefix_len; i++) buf[i] = prefix[i];
}
return ret;
}
ase_char_t* ase_awk_strtok (
ase_awk_run_t* run, const ase_char_t* s,
const ase_char_t* delim, ase_char_t** tok, ase_size_t* tok_len)
{
return ase_awk_strxntok (
run, s, ase_strlen(s),
delim, ase_strlen(delim), tok, tok_len);
}
ase_char_t* ase_awk_strxtok (
ase_awk_run_t* run, const ase_char_t* s, ase_size_t len,
const ase_char_t* delim, ase_char_t** tok, ase_size_t* tok_len)
{
return ase_awk_strxntok (
run, s, len,
delim, ase_strlen(delim), tok, tok_len);
}
ase_char_t* ase_awk_strntok (
ase_awk_run_t* run, const ase_char_t* s,
const ase_char_t* delim, ase_size_t delim_len,
ase_char_t** tok, ase_size_t* tok_len)
{
return ase_awk_strxntok (
run, s, ase_strlen(s),
delim, delim_len, tok, tok_len);
}
ase_char_t* ase_awk_strxntok (
ase_awk_run_t* run, const ase_char_t* s, ase_size_t len,
const ase_char_t* delim, ase_size_t delim_len,
ase_char_t** tok, ase_size_t* tok_len)
{
const ase_char_t* p = s, *d;
const ase_char_t* end = s + len;
const ase_char_t* sp = ASE_NULL, * ep = ASE_NULL;
const ase_char_t* delim_end = delim + delim_len;
ase_char_t c;
int delim_mode;
#define __DELIM_NULL 0
#define __DELIM_EMPTY 1
#define __DELIM_SPACES 2
#define __DELIM_NOSPACES 3
#define __DELIM_COMPOSITE 4
if (delim == ASE_NULL) delim_mode = __DELIM_NULL;
else
{
delim_mode = __DELIM_EMPTY;
for (d = delim; d < delim_end; d++)
{
if (ASE_AWK_ISSPACE(run->awk,*d))
{
if (delim_mode == __DELIM_EMPTY)
delim_mode = __DELIM_SPACES;
else if (delim_mode == __DELIM_NOSPACES)
{
delim_mode = __DELIM_COMPOSITE;
break;
}
}
else
{
if (delim_mode == __DELIM_EMPTY)
delim_mode = __DELIM_NOSPACES;
else if (delim_mode == __DELIM_SPACES)
{
delim_mode = __DELIM_COMPOSITE;
break;
}
}
}
/* TODO: verify the following statement... */
if (delim_mode == __DELIM_SPACES &&
delim_len == 1 &&
delim[0] != ASE_T(' ')) delim_mode = __DELIM_NOSPACES;
}
if (delim_mode == __DELIM_NULL)
{
/* when ASE_NULL is given as "delim", it trims off the
* leading and trailing spaces characters off the source
* string "s" eventually. */
while (p < end && ASE_AWK_ISSPACE(run->awk,*p)) p++;
while (p < end)
{
c = *p;
if (!ASE_AWK_ISSPACE(run->awk,c))
{
if (sp == ASE_NULL) sp = p;
ep = p;
}
p++;
}
}
else if (delim_mode == __DELIM_EMPTY)
{
/* each character in the source string "s" becomes a token. */
if (p < end)
{
c = *p;
sp = p;
ep = p++;
}
}
else if (delim_mode == __DELIM_SPACES)
{
/* each token is delimited by space characters. all leading
* and trailing spaces are removed. */
while (p < end && ASE_AWK_ISSPACE(run->awk,*p)) p++;
while (p < end)
{
c = *p;
if (ASE_AWK_ISSPACE(run->awk,c)) break;
if (sp == ASE_NULL) sp = p;
ep = p++;
}
while (p < end && ASE_AWK_ISSPACE(run->awk,*p)) p++;
}
else if (delim_mode == __DELIM_NOSPACES)
{
/* each token is delimited by one of charaters
* in the delimeter set "delim". */
if (run->global.ignorecase)
{
while (p < end)
{
c = ASE_AWK_TOUPPER(run->awk, *p);
for (d = delim; d < delim_end; d++)
{
if (c == ASE_AWK_TOUPPER(run->awk,*d)) goto exit_loop;
}
if (sp == ASE_NULL) sp = p;
ep = p++;
}
}
else
{
while (p < end)
{
c = *p;
for (d = delim; d < delim_end; d++)
{
if (c == *d) goto exit_loop;
}
if (sp == ASE_NULL) sp = p;
ep = p++;
}
}
}
else /* if (delim_mode == __DELIM_COMPOSITE) */
{
/* each token is delimited by one of non-space charaters
* in the delimeter set "delim". however, all space characters
* surrounding the token are removed */
while (p < end && ASE_AWK_ISSPACE(run->awk,*p)) p++;
if (run->global.ignorecase)
{
while (p < end)
{
c = ASE_AWK_TOUPPER(run->awk, *p);
if (ASE_AWK_ISSPACE(run->awk,c))
{
p++;
continue;
}
for (d = delim; d < delim_end; d++)
{
if (c == ASE_AWK_TOUPPER(run->awk,*d)) goto exit_loop;
}
if (sp == ASE_NULL) sp = p;
ep = p++;
}
}
else
{
while (p < end)
{
c = *p;
if (ASE_AWK_ISSPACE(run->awk,c))
{
p++;
continue;
}
for (d = delim; d < delim_end; d++)
{
if (c == *d) goto exit_loop;
}
if (sp == ASE_NULL) sp = p;
ep = p++;
}
}
}
exit_loop:
if (sp == ASE_NULL)
{
*tok = ASE_NULL;
*tok_len = (ase_size_t)0;
}
else
{
*tok = (ase_char_t*)sp;
*tok_len = ep - sp + 1;
}
/* if ASE_NULL is returned, this function should not be called anymore */
if (p >= end) return ASE_NULL;
if (delim_mode == __DELIM_EMPTY ||
delim_mode == __DELIM_SPACES) return (ase_char_t*)p;
return (ase_char_t*)++p;
}
ase_char_t* ase_awk_strxntokbyrex (
ase_awk_run_t* run, const ase_char_t* s, ase_size_t len,
void* rex, ase_char_t** tok, ase_size_t* tok_len, int* errnum)
{
int n;
ase_char_t* match_ptr;
ase_size_t match_len, i;
ase_size_t left = len;
const ase_char_t* ptr = s;
const ase_char_t* str_ptr = s;
ase_size_t str_len = len;
while (len > 0)
{
n = ASE_AWK_MATCHREX (
run->awk, rex,
((run->global.ignorecase)? ASE_REX_IGNORECASE: 0),
ptr, left, (const ase_char_t**)&match_ptr, &match_len,
errnum);
if (n == -1) return ASE_NULL;
if (n == 0)
{
/* no match has been found.
* return the entire string as a token */
*tok = (ase_char_t*)str_ptr;
*tok_len = str_len;
*errnum = ASE_AWK_ENOERR;
return ASE_NULL;
}
ASE_ASSERT (n == 1);
if (match_len == 0)
{
ptr++;
left--;
}
else if (run->awk->option & ASE_AWK_STRIPSPACES)
{
/* match at the beginning of the input string */
if (match_ptr == s)
{
for (i = 0; i < match_len; i++)
{
if (!ASE_AWK_ISSPACE(run->awk, match_ptr[i]))
goto exit_loop;
}
/* the match that are all spaces at the
* beginning of the input string is skipped */
ptr += match_len;
left -= match_len;
str_ptr = s + match_len;
str_len -= match_len;
}
else break;
}
else break;
}
exit_loop:
if (len == 0)
{
*tok = (ase_char_t*)str_ptr;
*tok_len = str_len;
*errnum = ASE_AWK_ENOERR;
return ASE_NULL;
}
*tok = (ase_char_t*)str_ptr;
*tok_len = match_ptr - str_ptr;
for (i = 0; i < match_len; i++)
{
if (!ASE_AWK_ISSPACE(run->awk, match_ptr[i]))
{
*errnum = ASE_AWK_ENOERR;
return match_ptr+match_len;
}
}
*errnum = ASE_AWK_ENOERR;
if (run->awk->option & ASE_AWK_STRIPSPACES)
{
return (match_ptr+match_len >= s+len)?
ASE_NULL: (match_ptr+match_len);
}
else
{
return (match_ptr+match_len > s+len)?
ASE_NULL: (match_ptr+match_len);
}
}
#define ASE_AWK_REXERRTOERR(err) \
((err == ASE_REX_ENOERR)? ASE_AWK_ENOERR: \
(err == ASE_REX_ENOMEM)? ASE_AWK_ENOMEM: \
(err == ASE_REX_ERECUR)? ASE_AWK_EREXRECUR: \
(err == ASE_REX_ERPAREN)? ASE_AWK_EREXRPAREN: \
(err == ASE_REX_ERBRACKET)? ASE_AWK_EREXRBRACKET: \
(err == ASE_REX_ERBRACE)? ASE_AWK_EREXRBRACE: \
(err == ASE_REX_EUNBALPAR)? ASE_AWK_EREXUNBALPAR: \
(err == ASE_REX_ECOLON)? ASE_AWK_EREXCOLON: \
(err == ASE_REX_ECRANGE)? ASE_AWK_EREXCRANGE: \
(err == ASE_REX_ECCLASS)? ASE_AWK_EREXCCLASS: \
(err == ASE_REX_EBRANGE)? ASE_AWK_EREXBRANGE: \
(err == ASE_REX_EEND)? ASE_AWK_EREXEND: \
(err == ASE_REX_EGARBAGE)? ASE_AWK_EREXGARBAGE: \
ASE_AWK_EINTERN)
void* ase_awk_buildrex (
ase_awk_t* awk, const ase_char_t* ptn, ase_size_t len, int* errnum)
{
int err;
void* p;
p = ase_buildrex (
&awk->prmfns.mmgr, awk->rex.depth.max.build, ptn, len, &err);
if (p == ASE_NULL) *errnum = ASE_AWK_REXERRTOERR(err);
return p;
}
int ase_awk_matchrex (
ase_awk_t* awk, void* code, int option,
const ase_char_t* str, ase_size_t len,
const ase_char_t** match_ptr, ase_size_t* match_len, int* errnum)
{
int err, x;
x = ase_matchrex (
&awk->prmfns.mmgr, &awk->prmfns.ccls, awk->rex.depth.max.match,
code, option, str, len, match_ptr, match_len, &err);
if (x < 0) *errnum = ASE_AWK_REXERRTOERR(err);
return x;
}

54
ase/lib/awk/misc.h Normal file
View File

@ -0,0 +1,54 @@
/*
* $Id: misc.h 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
#ifndef _ASE_AWK_MISC_H_
#define _ASE_AWK_MISC_H_
#ifndef _ASE_AWK_AWK_H_
#error Never include this file directly. Include <ase/awk/awk.h> instead
#endif
#ifdef __cplusplus
extern "C" {
#endif
ase_char_t* ase_awk_strtok (
ase_awk_run_t* run, const ase_char_t* s,
const ase_char_t* delim, ase_char_t** tok, ase_size_t* tok_len);
ase_char_t* ase_awk_strxtok (
ase_awk_run_t* run, const ase_char_t* s, ase_size_t len,
const ase_char_t* delim, ase_char_t** tok, ase_size_t* tok_len);
ase_char_t* ase_awk_strntok (
ase_awk_run_t* run, const ase_char_t* s,
const ase_char_t* delim, ase_size_t delim_len,
ase_char_t** tok, ase_size_t* tok_len);
ase_char_t* ase_awk_strxntok (
ase_awk_run_t* run, const ase_char_t* s, ase_size_t len,
const ase_char_t* delim, ase_size_t delim_len,
ase_char_t** tok, ase_size_t* tok_len);
ase_char_t* ase_awk_strxntokbyrex (
ase_awk_run_t* run, const ase_char_t* s, ase_size_t len,
void* rex, ase_char_t** tok, ase_size_t* tok_len, int* errnum);
void* ase_awk_buildrex (
ase_awk_t* awk, const ase_char_t* ptn, ase_size_t len, int* errnum);
int ase_awk_matchrex (
ase_awk_t* awk, void* code, int option,
const ase_char_t* str, ase_size_t len,
const ase_char_t** match_ptr, ase_size_t* match_len, int* errnum);
#ifdef __cplusplus
}
#endif
#endif

208
ase/lib/awk/msw-bcc.mak Normal file
View File

@ -0,0 +1,208 @@
NAME = aseawk
!ifndef MODE
MODE = release
!endif
JNI_INC = \
-I"$(JAVA_HOME)\include" \
-I"$(JAVA_HOME)\include\win32"
CC = bcc32
CXX = bcc32
LD = ilink32
AR = tlib
JAVAC = javac
JAR = jar
CFLAGS = -WM -WU -RT- -w -q -I..\..
CXXFLAGS = -WM -WU -RT- -w -q -I..\..
!IF "$(MODE)" == "debug"
CFLAGS = $(CFLAGS) -D_DEBUG -DDEBUG
CXXFLAGS = $(CXXFLAGS) -D_DEBUG -DDEBUG
!ELSEIF "$(MODE)" == "release"
CFLAGS = $(CFLAGS) -DNDEBUG -O2
CXXFLAGS = $(CXXFLAGS) -DNDEBUG -O2
!ELSE
CFLAGS = $(CFLAGS)
CXXFLAGS = $(CXXFLAGS)
!ENDIF
JAVACFLAGS = -classpath ..\.. -Xlint:unchecked
LDFLAGS = -Tpd -ap -Gn -c -q -L..\$(MODE)\lib
STARTUP = c0d32w.obj
LIBS = import32.lib cw32mt.lib asecmn.lib aseutl.lib $(NAME).lib
OUT_DIR = ..\$(MODE)\lib
OUT_FILE_LIB = $(OUT_DIR)\$(NAME).lib
OUT_FILE_JNI = $(OUT_DIR)\$(NAME)_jni.dll
OUT_FILE_LIB_CXX = "$(OUT_DIR)\$(NAME)++.lib"
OUT_FILE_JAR = $(OUT_DIR)\$(NAME).jar
TMP_DIR = $(MODE)
TMP_DIR_CXX = $(TMP_DIR)\cxx
OBJ_FILES_LIB = \
$(TMP_DIR)\awk.obj \
$(TMP_DIR)\err.obj \
$(TMP_DIR)\tree.obj \
$(TMP_DIR)\tab.obj \
$(TMP_DIR)\parse.obj \
$(TMP_DIR)\run.obj \
$(TMP_DIR)\rec.obj \
$(TMP_DIR)\val.obj \
$(TMP_DIR)\func.obj \
$(TMP_DIR)\misc.obj \
$(TMP_DIR)\extio.obj
OBJ_FILES_JNI = $(TMP_DIR)\jni.obj
OBJ_FILES_LIB_CXX = \
$(TMP_DIR)\cxx\Awk.obj \
$(TMP_DIR)\cxx\StdAwk.obj
OBJ_FILES_JAR = \
$(TMP_DIR)\ase\awk\Awk.class \
$(TMP_DIR)\ase\awk\StdAwk.class \
$(TMP_DIR)\ase\awk\Context.class \
$(TMP_DIR)\ase\awk\Clearable.class \
$(TMP_DIR)\ase\awk\Argument.class \
$(TMP_DIR)\ase\awk\Return.class \
$(TMP_DIR)\ase\awk\Extio.class \
$(TMP_DIR)\ase\awk\IO.class \
$(TMP_DIR)\ase\awk\Console.class \
$(TMP_DIR)\ase\awk\File.class \
$(TMP_DIR)\ase\awk\Pipe.class \
$(TMP_DIR)\ase\awk\Exception.class
TARGETS = lib
!if "$(JAVA_HOME)" != ""
TARGETS = $(TARGETS) jnidll jar
JNI_INC = -I"$(JAVA_HOME)\include" -I"$(JAVA_HOME)\include\win32"
!endif
all: $(TARGETS)
lib: $(TMP_DIR) $(OUT_DIR) $(OUT_DIR_CXX) $(OUT_FILE_LIB) $(OUT_FILE_LIB_CXX)
jnidll: $(TMP_DIR) $(OUT_DIR) $(OUT_FILE_JNI)
jar: $(OUT_FILE_JAR)
$(OUT_FILE_LIB): $(OBJ_FILES_LIB)
$(AR) $(OUT_FILE_LIB) @&&!
+-$(**: = &^
+-)
!
$(OUT_FILE_LIB_CXX): $(OBJ_FILES_LIB_CXX)
$(AR) $(OUT_FILE_LIB_CXX) @&&!
+-$(**: = &^
+-)
!
$(OUT_FILE_JNI): $(OUT_FILE_LIB) $(OBJ_FILES_JNI)
$(LD) $(LDFLAGS) $(STARTUP) $(OBJ_FILES_JNI),$(OUT_FILE_JNI),,$(LIBS),jni.def,
$(OUT_FILE_JAR): $(OBJ_FILES_JAR)
$(JAR) -Mcvf $(OUT_FILE_JAR) -C $(TMP_DIR) ase
$(TMP_DIR)\awk.obj: awk.c
$(CC) $(CFLAGS) -o$@ -c awk.c
$(TMP_DIR)\err.obj: err.c
$(CC) $(CFLAGS) -o$@ -c err.c
$(TMP_DIR)\tree.obj: tree.c
$(CC) $(CFLAGS) -o$@ -c tree.c
$(TMP_DIR)\tab.obj: tab.c
$(CC) $(CFLAGS) -o$@ -c tab.c
$(TMP_DIR)\parse.obj: parse.c
$(CC) $(CFLAGS) -o$@ -c parse.c
$(TMP_DIR)\run.obj: run.c
$(CC) $(CFLAGS) -o$@ -c run.c
$(TMP_DIR)\rec.obj: rec.c
$(CC) $(CFLAGS) -o$@ -c rec.c
$(TMP_DIR)\val.obj: val.c
$(CC) $(CFLAGS) -o$@ -c val.c
$(TMP_DIR)\func.obj: func.c
$(CC) $(CFLAGS) -o$@ -c func.c
$(TMP_DIR)\misc.obj: misc.c
$(CC) $(CFLAGS) -o$@ -c misc.c
$(TMP_DIR)\extio.obj: extio.c
$(CC) $(CFLAGS) -o$@ -c extio.c
$(TMP_DIR)\jni.obj: jni.c
$(CC) $(CFLAGS) $(JNI_INC) -o$@ -c jni.c
$(TMP_DIR)\cxx\Awk.obj: Awk.cpp Awk.hpp
$(CXX) $(CXXFLAGS) -o$@ -c Awk.cpp
$(TMP_DIR)\cxx\StdAwk.obj: StdAwk.cpp StdAwk.hpp Awk.hpp
$(CXX) $(CXXFLAGS) -o$@ -c StdAwk.cpp
$(TMP_DIR)\ase\awk\Awk.class: Awk.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Awk.java
$(TMP_DIR)\ase\awk\StdAwk.class: StdAwk.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) StdAwk.java
$(TMP_DIR)\ase\awk\Context.class: Context.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Context.java
$(TMP_DIR)\ase\awk\Clearable.class: Clearable.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Clearable.java
$(TMP_DIR)\ase\awk\Argument.class: Argument.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Argument.java
$(TMP_DIR)\ase\awk\Return.class: Return.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Return.java
$(TMP_DIR)\ase\awk\Extio.class: Extio.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Extio.java
$(TMP_DIR)\ase\awk\IO.class: IO.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) IO.java
$(TMP_DIR)\ase\awk\Console.class: Console.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Console.java
$(TMP_DIR)\ase\awk\File.class: File.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) File.java
$(TMP_DIR)\ase\awk\Pipe.class: Pipe.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Pipe.java
$(TMP_DIR)\ase\awk\Exception.class: Exception.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Exception.java
$(OUT_DIR):
-md $(OUT_DIR)
$(TMP_DIR):
-md $(TMP_DIR)
$(TMP_DIR_CXX): $(TMP_DIR)
-md $(TMP_DIR_CXX)
clean:
-del $(OUT_FILE_LIB)
-del $(OUT_FILE_JNI)
-del $(OUT_FILE_JAR)
-del $(OUT_FILE_LIB_CXX)
-del $(OBJ_FILES_LIB)
-del $(OBJ_FILES_JNI)
-del $(OBJ_FILES_JAR)
-del $(OBJ_FILES_LIB_CXX)

219
ase/lib/awk/msw-cl.mak Normal file
View File

@ -0,0 +1,219 @@
NAME = aseawk
MODE = release
!if !defined(CPU) || "$(CPU)" == ""
CPU = $(PROCESSOR_ARCHITECTURE)
!endif
!if "$(CPU)" == ""
CPU = i386
!endif
CC = cl
CXX = cl
LD = link
AR = link
JAVAC = javac
JAR = jar
CFLAGS = /nologo /W3 -I..\..
CXXFLAGS = /nologo /W3 -I..\..
JAVACFLAGS = -classpath ..\.. -Xlint:unchecked
#LDFLAGS = /subsystem:console
LDFLAGS = /subsystem:windows
LIBS=
!IF "$(MODE)" == "debug"
CFLAGS = $(CFLAGS) -D_DEBUG -DDEBUG /MTd /Zi
CXXFLAGS = $(CXXFLAGS) -D_DEBUG -DDEBUG /MTd /Zi
!ELSEIF "$(MODE)" == "release"
CFLAGS = $(CFLAGS) -DNDEBUG /MT /O2
CXXFLAGS = $(CXXFLAGS) -DNDEBUG /MT /O2
!ELSE
CFLAGS = $(CFLAGS) /MT
CXXFLAGS = $(CXXFLAGS) /MT
!ENDIF
OUT_DIR = ..\$(MODE)\lib
OUT_FILE_LIB = $(OUT_DIR)\$(NAME).lib
OUT_FILE_JNI = $(OUT_DIR)\$(NAME)_jni.dll
OUT_FILE_LIB_CXX = $(OUT_DIR)\$(NAME)++.lib
OUT_FILE_JAR = $(OUT_DIR)\$(NAME).jar
TMP_DIR = $(MODE)
TMP_DIR_CXX = $(TMP_DIR)\cxx
OBJ_FILES_LIB = \
$(TMP_DIR)\awk.obj \
$(TMP_DIR)\err.obj \
$(TMP_DIR)\tree.obj \
$(TMP_DIR)\tab.obj \
$(TMP_DIR)\parse.obj \
$(TMP_DIR)\run.obj \
$(TMP_DIR)\rec.obj \
$(TMP_DIR)\val.obj \
$(TMP_DIR)\func.obj \
$(TMP_DIR)\misc.obj \
$(TMP_DIR)\extio.obj
OBJ_FILES_JNI = $(TMP_DIR)\jni.obj
OBJ_FILES_LIB_CXX = \
$(TMP_DIR)\cxx\Awk.obj \
$(TMP_DIR)\cxx\StdAwk.obj
OBJ_FILES_JAR = \
$(TMP_DIR)\ase\awk\Awk.class \
$(TMP_DIR)\ase\awk\StdAwk.class \
$(TMP_DIR)\ase\awk\Context.class \
$(TMP_DIR)\ase\awk\Clearable.class \
$(TMP_DIR)\ase\awk\Argument.class \
$(TMP_DIR)\ase\awk\Return.class \
$(TMP_DIR)\ase\awk\Extio.class \
$(TMP_DIR)\ase\awk\IO.class \
$(TMP_DIR)\ase\awk\Console.class \
$(TMP_DIR)\ase\awk\File.class \
$(TMP_DIR)\ase\awk\Pipe.class \
$(TMP_DIR)\ase\awk\Exception.class
LIBS_JNIDLL=user32.lib $(OUT_FILE_LIB) asecmn.lib aseutl.lib
!if "$(CPU)" == "IA64" || "$(CPU)" == "AMD64"
# comment out the following line if you encounter this link error.
# LINK : fatal error LNK1181: cannot open input file 'bufferoverflowu.lib'
LIBS_JNIDLL = $(LIBS_JNIDLL) bufferoverflowu.lib
!endif
TARGETS = lib
!if "$(JAVA_HOME)" != ""
TARGETS = $(TARGETS) jnidll jar
JNI_INC = -I"$(JAVA_HOME)\include" -I"$(JAVA_HOME)\include\win32"
!endif
all: $(TARGETS)
lib: $(OUT_FILE_LIB) $(OUT_FILE_LIB_CXX)
jnidll: $(OUT_FILE_JNI)
jar: $(OUT_FILE_JAR)
$(OUT_FILE_LIB): $(TMP_DIR) $(OUT_DIR) $(OBJ_FILES_LIB)
$(AR) /lib @<<
/nologo /out:$(OUT_FILE_LIB) $(OBJ_FILES_LIB)
<<
$(OUT_FILE_LIB_CXX): $(TMP_DIR_CXX) $(OUT_FILE_LIB) $(OBJ_FILES_LIB_CXX)
$(AR) /lib @<<
/nologo /out:$(OUT_FILE_LIB_CXX) $(OBJ_FILES_LIB_CXX)
<<
$(OUT_FILE_JNI): $(OUT_FILE_LIB) $(OBJ_FILES_JNI)
$(LD) /dll /def:jni.def $(LDFLAGS) /release @<<
/nologo /out:$(OUT_FILE_JNI) $(OBJ_FILES_JNI) /libpath:../$(MODE)/lib /implib:tmp.lib $(LIBS_JNIDLL)
<<
del tmp.lib tmp.exp
$(OUT_FILE_JAR): $(OBJ_FILES_JAR)
$(JAR) -Mcvf $(OUT_FILE_JAR) -C $(TMP_DIR) ase
$(TMP_DIR)\awk.obj: awk.c
$(CC) $(CFLAGS) /Fo$@ /c awk.c
$(TMP_DIR)\err.obj: err.c
$(CC) $(CFLAGS) /Fo$@ /c err.c
$(TMP_DIR)\tree.obj: tree.c
$(CC) $(CFLAGS) /Fo$@ /c tree.c
$(TMP_DIR)\tab.obj: tab.c
$(CC) $(CFLAGS) /Fo$@ /c tab.c
$(TMP_DIR)\parse.obj: parse.c
$(CC) $(CFLAGS) /Fo$@ /c parse.c
$(TMP_DIR)\run.obj: run.c
$(CC) $(CFLAGS) /Fo$@ /c run.c
$(TMP_DIR)\rec.obj: rec.c
$(CC) $(CFLAGS) /Fo$@ /c rec.c
$(TMP_DIR)\val.obj: val.c
$(CC) $(CFLAGS) /Fo$@ /c val.c
$(TMP_DIR)\func.obj: func.c
$(CC) $(CFLAGS) /Fo$@ /c func.c
$(TMP_DIR)\misc.obj: misc.c
$(CC) $(CFLAGS) /Fo$@ /c misc.c
$(TMP_DIR)\extio.obj: extio.c
$(CC) $(CFLAGS) /Fo$@ /c extio.c
$(TMP_DIR)\jni.obj: jni.c
$(CC) $(CFLAGS) $(JNI_INC) /Fo$@ /c jni.c
$(TMP_DIR)\cxx\Awk.obj: Awk.cpp Awk.hpp
$(CXX) $(CXXFLAGS) /Fo$@ /c Awk.cpp
$(TMP_DIR)\cxx\StdAwk.obj: StdAwk.cpp StdAwk.hpp Awk.hpp
$(CXX) $(CXXFLAGS) /Fo$@ /c StdAwk.cpp
$(TMP_DIR)\ase\awk\Awk.class: Awk.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Awk.java
$(TMP_DIR)\ase\awk\StdAwk.class: StdAwk.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) StdAwk.java
$(TMP_DIR)\ase\awk\Context.class: Context.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Context.java
$(TMP_DIR)\ase\awk\Clearable.class: Clearable.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Clearable.java
$(TMP_DIR)\ase\awk\Argument.class: Argument.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Argument.java
$(TMP_DIR)\ase\awk\Return.class: Return.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Return.java
$(TMP_DIR)\ase\awk\Extio.class: Extio.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Extio.java
$(TMP_DIR)\ase\awk\IO.class: IO.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) IO.java
$(TMP_DIR)\ase\awk\Console.class: Console.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Console.java
$(TMP_DIR)\ase\awk\File.class: File.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) File.java
$(TMP_DIR)\ase\awk\Pipe.class: Pipe.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Pipe.java
$(TMP_DIR)\ase\awk\Exception.class: Exception.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Exception.java
$(OUT_DIR):
-md $(OUT_DIR)
$(TMP_DIR):
-md $(TMP_DIR)
$(TMP_DIR_CXX): $(TMP_DIR)
-md $(TMP_DIR_CXX)
clean:
-del $(OUT_FILE_LIB)
-del $(OUT_FILE_JNI)
-del $(OUT_FILE_JAR)
-del $(OUT_FILE_LIB_CXX)
-del $(OBJ_FILES_LIB)
-del $(OBJ_FILES_JNI)
-del $(OBJ_FILES_JAR)
-del $(OBJ_FILES_LIB_CXX)

155
ase/lib/awk/msw-dmc.mak Normal file
View File

@ -0,0 +1,155 @@
NAME = aseawk
MODE = release
JNI_INC = \
-I"$(JAVA_HOME)\include" \
-I"$(JAVA_HOME)\include\win32"
CC = dmc
LD = dmc
AR = lib
JAVAC = javac
JAR = jar
CFLAGS = -mn -I..\.. -DUNICODE -D_UNICODE #-D_DEBUG
JAVACFLAGS = -classpath ..\.. -Xlint:unchecked
OUT_DIR = ..\$(MODE)\lib
OUT_FILE_LIB = $(OUT_DIR)\$(NAME).lib
OUT_FILE_JNI = $(OUT_DIR)\$(NAME)_jni.dll
OUT_FILE_JAR = $(OUT_DIR)\$(NAME).jar
TMP_DIR = $(MODE)
OBJ_FILES_LIB = \
$(TMP_DIR)\awk.obj \
$(TMP_DIR)\err.obj \
$(TMP_DIR)\tree.obj \
$(TMP_DIR)\tab.obj \
$(TMP_DIR)\parse.obj \
$(TMP_DIR)\run.obj \
$(TMP_DIR)\rec.obj \
$(TMP_DIR)\val.obj \
$(TMP_DIR)\func.obj \
$(TMP_DIR)\misc.obj \
$(TMP_DIR)\extio.obj
OBJ_FILES_JNI = $(TMP_DIR)\jni.obj
OBJ_FILES_JAR = \
$(TMP_DIR)\ase\awk\Awk.class \
$(TMP_DIR)\ase\awk\StdAwk.class \
$(TMP_DIR)\ase\awk\Context.class \
$(TMP_DIR)\ase\awk\Clearable.class \
$(TMP_DIR)\ase\awk\Argument.class \
$(TMP_DIR)\ase\awk\Return.class
$(TMP_DIR)\ase\awk\Extio.class \
$(TMP_DIR)\ase\awk\IO.class \
$(TMP_DIR)\ase\awk\Console.class \
$(TMP_DIR)\ase\awk\File.class \
$(TMP_DIR)\ase\awk\Pipe.class \
$(TMP_DIR)\ase\awk\Exception.class
all: lib
lib: $(OUT_FILE_LIB)
jnidll: $(OUT_FILE_JNI)
jar: $(OUT_FILE_JAR)
$(OUT_FILE_LIB): $(TMP_DIR) $(OUT_DIR) $(OBJ_FILES_LIB)
$(AR) -c $(OUT_FILE_LIB) $(OBJ_FILES_LIB)
$(OUT_FILE_JNI): $(OUT_FILE_LIB) $(OBJ_FILES_JNI)
$(LD) -WD -o$(OUT_FILE_JNI) $(OBJ_FILES_JNI) $(OUT_FILE_LIB) $(OUT_DIR)\asecmn.lib $(OUT_DIR)\aseutl.lib kernel32.lib jni-dmc.def
$(OUT_FILE_JAR): $(OBJ_FILES_JAR)
$(JAR) -Mcvf $(OUT_FILE_JAR) -C $(TMP_DIR) ase
$(TMP_DIR)\awk.obj: awk.c
$(CC) $(CFLAGS) -o$@ -c awk.c
$(TMP_DIR)\err.obj: err.c
$(CC) $(CFLAGS) -o$@ -c err.c
$(TMP_DIR)\tree.obj: tree.c
$(CC) $(CFLAGS) -o$@ -c tree.c
$(TMP_DIR)\tab.obj: tab.c
$(CC) $(CFLAGS) -o$@ -c tab.c
$(TMP_DIR)\parse.obj: parse.c
$(CC) $(CFLAGS) -o$@ -c parse.c
$(TMP_DIR)\run.obj: run.c
$(CC) $(CFLAGS) -o$@ -c run.c
$(TMP_DIR)\rec.obj: rec.c
$(CC) $(CFLAGS) -o$@ -c rec.c
$(TMP_DIR)\val.obj: val.c
$(CC) $(CFLAGS) -o$@ -c val.c
$(TMP_DIR)\func.obj: func.c
$(CC) $(CFLAGS) -o$@ -c func.c
$(TMP_DIR)\misc.obj: misc.c
$(CC) $(CFLAGS) -o$@ -c misc.c
$(TMP_DIR)\extio.obj: extio.c
$(CC) $(CFLAGS) -o$@ -c extio.c
$(TMP_DIR)\jni.obj: jni.c
$(CC) $(CFLAGS) $(JNI_INC) -o$@ -c jni.c
$(TMP_DIR)\ase\awk\Awk.class: Awk.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Awk.java
$(TMP_DIR)\ase\awk\StdAwk.class: StdAwk.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) StdAwk.java
$(TMP_DIR)\ase\awk\Context.class: Context.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Context.java
$(TMP_DIR)\ase\awk\Clearable.class: Clearable.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Clearable.java
$(TMP_DIR)\ase\awk\Argument.class: Argument.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Argument.java
$(TMP_DIR)\ase\awk\Return.class: Return.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Return.java
$(TMP_DIR)\ase\awk\Extio.class: Extio.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Extio.java
$(TMP_DIR)\ase\awk\IO.class: IO.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) IO.java
$(TMP_DIR)\ase\awk\Console.class: Console.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Console.java
$(TMP_DIR)\ase\awk\File.class: File.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) File.java
$(TMP_DIR)\ase\awk\Pipe.class: Pipe.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Pipe.java
$(TMP_DIR)\ase\awk\Exception.class: Exception.java
$(JAVAC) $(JAVACFLAGS) -d $(TMP_DIR) Exception.java
$(OUT_DIR):
md $(OUT_DIR)
$(TMP_DIR):
md $(TMP_DIR)
clean:
del $(OUT_FILE_LIB)
del $(OUT_FILE_JNI)
del $(OUT_FILE_JAR)
del $(OBJ_FILES_LIB)
del $(OBJ_FILES_JNI)
del $(OBJ_FILES_JAR)

5798
ase/lib/awk/parse.c Normal file

File diff suppressed because it is too large Load Diff

32
ase/lib/awk/parse.h Normal file
View File

@ -0,0 +1,32 @@
/*
* $Id: parse.h 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
#ifndef _ASE_AWK_PARSE_H_
#define _ASE_AWK_PARSE_H_
#ifndef _ASE_AWK_AWK_H_
#error Never include this file directly. Include <ase/awk/awk.h> instead
#endif
#ifdef __cplusplus
extern "C" {
#endif
int ase_awk_putsrcstr (ase_awk_t* awk, const ase_char_t* str);
int ase_awk_putsrcstrx (
ase_awk_t* awk, const ase_char_t* str, ase_size_t len);
const ase_char_t* ase_awk_getglobalname (
ase_awk_t* awk, ase_size_t idx, ase_size_t* len);
const ase_char_t* ase_awk_getkw (ase_awk_t* awk, const ase_char_t* kw);
int ase_awk_initglobals (ase_awk_t* awk);
#ifdef __cplusplus
}
#endif
#endif

442
ase/lib/awk/rec.c Normal file
View File

@ -0,0 +1,442 @@
/*
* $Id: rec.c 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
#include <ase/awk/awk_i.h>
static int split_record (ase_awk_run_t* run);
static int recomp_record_fields (
ase_awk_run_t* run, ase_size_t lv,
const ase_char_t* str, ase_size_t len);
int ase_awk_setrec (
ase_awk_run_t* run, ase_size_t idx,
const ase_char_t* str, ase_size_t len)
{
ase_awk_val_t* v;
if (idx == 0)
{
if (str == ASE_STR_BUF(&run->inrec.line) &&
len == ASE_STR_LEN(&run->inrec.line))
{
if (ase_awk_clrrec (run, ase_true) == -1) return -1;
}
else
{
if (ase_awk_clrrec (run, ase_false) == -1) return -1;
if (ase_str_ncpy (&run->inrec.line, str, len) == (ase_size_t)-1)
{
ase_awk_clrrec (run, ase_false);
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
}
v = ase_awk_makestrval (run, str, len);
if (v == ASE_NULL)
{
ase_awk_clrrec (run, ase_false);
return -1;
}
ASE_ASSERT (run->inrec.d0->type == ASE_AWK_VAL_NIL);
/* d0 should be cleared before the next line is reached
* as it doesn't call ase_awk_refdownval on run->inrec.d0 */
run->inrec.d0 = v;
ase_awk_refupval (run, v);
if (split_record (run) == -1)
{
ase_awk_clrrec (run, ase_false);
return -1;
}
}
else
{
if (recomp_record_fields (run, idx, str, len) == -1)
{
ase_awk_clrrec (run, ase_false);
return -1;
}
/* recompose $0 */
v = ase_awk_makestrval (run,
ASE_STR_BUF(&run->inrec.line),
ASE_STR_LEN(&run->inrec.line));
if (v == ASE_NULL)
{
ase_awk_clrrec (run, ase_false);
return -1;
}
ase_awk_refdownval (run, run->inrec.d0);
run->inrec.d0 = v;
ase_awk_refupval (run, v);
}
return 0;
}
static int split_record (ase_awk_run_t* run)
{
ase_char_t* p, * tok;
ase_size_t len, tok_len, nflds;
ase_awk_val_t* v, * fs;
ase_char_t* fs_ptr, * fs_free;
ase_size_t fs_len;
int errnum;
/* inrec should be cleared before split_record is called */
ASE_ASSERT (run->inrec.nflds == 0);
/* get FS */
fs = ase_awk_getglobal (run, ASE_AWK_GLOBAL_FS);
if (fs->type == ASE_AWK_VAL_NIL)
{
fs_ptr = ASE_T(" ");
fs_len = 1;
fs_free = ASE_NULL;
}
else if (fs->type == ASE_AWK_VAL_STR)
{
fs_ptr = ((ase_awk_val_str_t*)fs)->buf;
fs_len = ((ase_awk_val_str_t*)fs)->len;
fs_free = ASE_NULL;
}
else
{
fs_ptr = ase_awk_valtostr (
run, fs, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &fs_len);
if (fs_ptr == ASE_NULL) return -1;
fs_free = fs_ptr;
}
/* scan the input record to count the fields */
p = ASE_STR_BUF(&run->inrec.line);
len = ASE_STR_LEN(&run->inrec.line);
nflds = 0;
while (p != ASE_NULL)
{
if (fs_len <= 1)
{
p = ase_awk_strxntok (run,
p, len, fs_ptr, fs_len, &tok, &tok_len);
}
else
{
p = ase_awk_strxntokbyrex (run, p, len,
run->global.fs, &tok, &tok_len, &errnum);
if (p == ASE_NULL && errnum != ASE_AWK_ENOERR)
{
if (fs_free != ASE_NULL)
ASE_AWK_FREE (run->awk, fs_free);
ase_awk_setrunerror (run, errnum, 0, ASE_NULL, 0);
return -1;
}
}
if (nflds == 0 && p == ASE_NULL && tok_len == 0)
{
/* there are no fields. it can just return here
* as ase_awk_clrrec has been called before this */
if (fs_free != ASE_NULL) ASE_AWK_FREE (run->awk, fs_free);
return 0;
}
ASE_ASSERT ((tok != ASE_NULL && tok_len > 0) || tok_len == 0);
nflds++;
len = ASE_STR_LEN(&run->inrec.line) -
(p - ASE_STR_BUF(&run->inrec.line));
}
/* allocate space */
if (nflds > run->inrec.maxflds)
{
void* tmp = ASE_AWK_MALLOC (
run->awk, ASE_SIZEOF(*run->inrec.flds) * nflds);
if (tmp == ASE_NULL)
{
if (fs_free != ASE_NULL) ASE_AWK_FREE (run->awk, fs_free);
ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
if (run->inrec.flds != ASE_NULL)
ASE_AWK_FREE (run->awk, run->inrec.flds);
run->inrec.flds = tmp;
run->inrec.maxflds = nflds;
}
/* scan again and split it */
p = ASE_STR_BUF(&run->inrec.line);
len = ASE_STR_LEN(&run->inrec.line);
while (p != ASE_NULL)
{
if (fs_len <= 1)
{
p = ase_awk_strxntok (
run, p, len, fs_ptr, fs_len, &tok, &tok_len);
}
else
{
p = ase_awk_strxntokbyrex (run, p, len,
run->global.fs, &tok, &tok_len, &errnum);
if (p == ASE_NULL && errnum != ASE_AWK_ENOERR)
{
if (fs_free != ASE_NULL)
ASE_AWK_FREE (run->awk, fs_free);
ase_awk_setrunerror (run, errnum, 0, ASE_NULL, 0);
return -1;
}
}
ASE_ASSERT ((tok != ASE_NULL && tok_len > 0) || tok_len == 0);
run->inrec.flds[run->inrec.nflds].ptr = tok;
run->inrec.flds[run->inrec.nflds].len = tok_len;
run->inrec.flds[run->inrec.nflds].val =
ase_awk_makestrval (run, tok, tok_len);
if (run->inrec.flds[run->inrec.nflds].val == ASE_NULL)
{
if (fs_free != ASE_NULL) ASE_AWK_FREE (run->awk, fs_free);
return -1;
}
ase_awk_refupval (run, run->inrec.flds[run->inrec.nflds].val);
run->inrec.nflds++;
len = ASE_STR_LEN(&run->inrec.line) -
(p - ASE_STR_BUF(&run->inrec.line));
}
if (fs_free != ASE_NULL) ASE_AWK_FREE (run->awk, fs_free);
/* set the number of fields */
v = ase_awk_makeintval (run, (ase_long_t)nflds);
if (v == ASE_NULL) return -1;
ase_awk_refupval (run, v);
if (ase_awk_setglobal (run, ASE_AWK_GLOBAL_NF, v) == -1)
{
ase_awk_refdownval (run, v);
return -1;
}
ase_awk_refdownval (run, v);
ASE_ASSERT (nflds == run->inrec.nflds);
return 0;
}
int ase_awk_clrrec (ase_awk_run_t* run, ase_bool_t skip_inrec_line)
{
ase_size_t i;
int n = 0;
if (run->inrec.d0 != ase_awk_val_nil)
{
ase_awk_refdownval (run, run->inrec.d0);
run->inrec.d0 = ase_awk_val_nil;
}
if (run->inrec.nflds > 0)
{
ASE_ASSERT (run->inrec.flds != ASE_NULL);
for (i = 0; i < run->inrec.nflds; i++)
{
ASE_ASSERT (run->inrec.flds[i].val != ASE_NULL);
ase_awk_refdownval (run, run->inrec.flds[i].val);
}
run->inrec.nflds = 0;
if (ase_awk_setglobal (
run, ASE_AWK_GLOBAL_NF, ase_awk_val_zero) == -1)
{
/* first of all, this should never happen.
* if it happened, it would return an error
* after all the clearance tasks */
n = -1;
}
}
ASE_ASSERT (run->inrec.nflds == 0);
if (!skip_inrec_line) ase_str_clear (&run->inrec.line);
return n;
}
static int recomp_record_fields (
ase_awk_run_t* run, ase_size_t lv,
const ase_char_t* str, ase_size_t len)
{
ase_awk_val_t* v;
ase_size_t max, i, nflds;
/* recomposes the record and the fields when $N has been assigned
* a new value and recomputes NF accordingly */
ASE_ASSERT (lv > 0);
max = (lv > run->inrec.nflds)? lv: run->inrec.nflds;
nflds = run->inrec.nflds;
if (max > run->inrec.maxflds)
{
void* tmp;
/* if the given field number is greater than the maximum
* number of fields that the current record can hold,
* the field spaces are resized */
if (run->awk->prmfns.mmgr.realloc != ASE_NULL)
{
tmp = ASE_AWK_REALLOC (
run->awk, run->inrec.flds,
ASE_SIZEOF(*run->inrec.flds) * max);
if (tmp == ASE_NULL)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
}
else
{
tmp = ASE_AWK_MALLOC (
run->awk, ASE_SIZEOF(*run->inrec.flds) * max);
if (tmp == ASE_NULL)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
if (run->inrec.flds != ASE_NULL)
{
ase_memcpy (tmp, run->inrec.flds,
ASE_SIZEOF(*run->inrec.flds)*run->inrec.maxflds);
ASE_AWK_FREE (run->awk, run->inrec.flds);
}
}
run->inrec.flds = tmp;
run->inrec.maxflds = max;
}
lv = lv - 1; /* adjust the value to 0-based index */
ase_str_clear (&run->inrec.line);
for (i = 0; i < max; i++)
{
if (i > 0)
{
if (ase_str_ncat (
&run->inrec.line,
run->global.ofs.ptr,
run->global.ofs.len) == (ase_size_t)-1)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
}
if (i == lv)
{
ase_awk_val_t* tmp;
run->inrec.flds[i].ptr =
ASE_STR_BUF(&run->inrec.line) +
ASE_STR_LEN(&run->inrec.line);
run->inrec.flds[i].len = len;
if (ase_str_ncat (
&run->inrec.line, str, len) == (ase_size_t)-1)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
tmp = ase_awk_makestrval (run, str,len);
if (tmp == ASE_NULL) return -1;
if (i < nflds)
ase_awk_refdownval (run, run->inrec.flds[i].val);
else run->inrec.nflds++;
run->inrec.flds[i].val = tmp;
ase_awk_refupval (run, tmp);
}
else if (i >= nflds)
{
run->inrec.flds[i].ptr =
ASE_STR_BUF(&run->inrec.line) +
ASE_STR_LEN(&run->inrec.line);
run->inrec.flds[i].len = 0;
if (ase_str_cat (
&run->inrec.line, ASE_T("")) == (ase_size_t)-1)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
/* ase_awk_refdownval should not be called over
* run->inrec.flds[i].val as it is not initialized
* to any valid values */
/*ase_awk_refdownval (run, run->inrec.flds[i].val);*/
run->inrec.flds[i].val = ase_awk_val_zls;
ase_awk_refupval (run, ase_awk_val_zls);
run->inrec.nflds++;
}
else
{
ase_awk_val_str_t* tmp;
tmp = (ase_awk_val_str_t*)run->inrec.flds[i].val;
run->inrec.flds[i].ptr =
ASE_STR_BUF(&run->inrec.line) +
ASE_STR_LEN(&run->inrec.line);
run->inrec.flds[i].len = tmp->len;
if (ase_str_ncat (&run->inrec.line,
tmp->buf, tmp->len) == (ase_size_t)-1)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
}
}
v = ase_awk_getglobal (run, ASE_AWK_GLOBAL_NF);
ASE_ASSERT (v->type == ASE_AWK_VAL_INT);
if (((ase_awk_val_int_t*)v)->val != max)
{
v = ase_awk_makeintval (run, (ase_long_t)max);
if (v == ASE_NULL) return -1;
ase_awk_refupval (run, v);
if (ase_awk_setglobal (run, ASE_AWK_GLOBAL_NF, v) == -1)
{
ase_awk_refdownval (run, v);
return -1;
}
ase_awk_refdownval (run, v);
}
return 0;
}

7253
ase/lib/awk/run.c Normal file

File diff suppressed because it is too large Load Diff

99
ase/lib/awk/run.h Normal file
View File

@ -0,0 +1,99 @@
/*
* $Id: run.h 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
#ifndef _ASE_AWK_RUN_H_
#define _ASE_AWK_RUN_H_
#ifndef _ASE_AWK_AWK_H_
#error Never include this file directly. Include <ase/awk/awk.h> instead
#endif
enum ase_awk_assop_type_t
{
/* if you change this, you have to change assop_str in tree.c.
* synchronize it with binop_func of eval_assignment in run.c */
ASE_AWK_ASSOP_NONE,
ASE_AWK_ASSOP_PLUS, /* += */
ASE_AWK_ASSOP_MINUS, /* -= */
ASE_AWK_ASSOP_MUL, /* *= */
ASE_AWK_ASSOP_DIV, /* /= */
ASE_AWK_ASSOP_IDIV, /* //= */
ASE_AWK_ASSOP_MOD, /* %= */
ASE_AWK_ASSOP_EXP, /* **= */
ASE_AWK_ASSOP_RSHIFT, /* >>= */
ASE_AWK_ASSOP_LSHIFT, /* <<= */
ASE_AWK_ASSOP_BAND, /* &= */
ASE_AWK_ASSOP_BXOR, /* ^= */
ASE_AWK_ASSOP_BOR /* |= */
};
enum ase_awk_binop_type_t
{
/* if you change this, you have to change
* binop_str in tree.c and binop_func in run.c accordingly. */
ASE_AWK_BINOP_LOR,
ASE_AWK_BINOP_LAND,
ASE_AWK_BINOP_IN,
ASE_AWK_BINOP_BOR,
ASE_AWK_BINOP_BXOR,
ASE_AWK_BINOP_BAND,
ASE_AWK_BINOP_EQ,
ASE_AWK_BINOP_NE,
ASE_AWK_BINOP_GT,
ASE_AWK_BINOP_GE,
ASE_AWK_BINOP_LT,
ASE_AWK_BINOP_LE,
ASE_AWK_BINOP_LSHIFT,
ASE_AWK_BINOP_RSHIFT,
ASE_AWK_BINOP_PLUS,
ASE_AWK_BINOP_MINUS,
ASE_AWK_BINOP_MUL,
ASE_AWK_BINOP_DIV,
ASE_AWK_BINOP_IDIV,
ASE_AWK_BINOP_MOD,
ASE_AWK_BINOP_EXP,
ASE_AWK_BINOP_CONCAT,
ASE_AWK_BINOP_MA,
ASE_AWK_BINOP_NM
};
enum ase_awk_unrop_type_t
{
/* if you change this, you have to change
* __unrop_str in tree.c accordingly. */
ASE_AWK_UNROP_PLUS,
ASE_AWK_UNROP_MINUS,
ASE_AWK_UNROP_LNOT,
ASE_AWK_UNROP_BNOT
};
enum ase_awk_incop_type_t
{
/* if you change this, you have to change
* __incop_str in tree.c accordingly. */
ASE_AWK_INCOP_PLUS,
ASE_AWK_INCOP_MINUS
};
#ifdef __cplusplus
extern "C" {
#endif
ase_char_t* ase_awk_format (
ase_awk_run_t* run, ase_str_t* out, ase_str_t* fbu,
const ase_char_t* fmt, ase_size_t fmt_len,
ase_size_t nargs_on_stack, ase_awk_nde_t* args, ase_size_t* len);
#ifdef __cplusplus
}
#endif
#endif

317
ase/lib/awk/tab.c Normal file
View File

@ -0,0 +1,317 @@
/*
* $Id: tab.c 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
#include <ase/awk/awk_i.h>
ase_awk_tab_t* ase_awk_tab_open (ase_awk_tab_t* tab, ase_awk_t* awk)
{
if (tab == ASE_NULL)
{
tab = (ase_awk_tab_t*) ASE_AWK_MALLOC (
awk, ASE_SIZEOF(ase_awk_tab_t));
if (tab == ASE_NULL) return ASE_NULL;
tab->__dynamic = ase_true;
}
else tab->__dynamic = ase_false;
tab->awk = awk;
tab->buf = ASE_NULL;
tab->size = 0;
tab->capa = 0;
return tab;
}
void ase_awk_tab_close (ase_awk_tab_t* tab)
{
ase_awk_tab_clear (tab);
if (tab->buf != ASE_NULL)
{
ASE_AWK_FREE (tab->awk, tab->buf);
tab->buf = ASE_NULL;
tab->capa = 0;
}
if (tab->__dynamic) ASE_AWK_FREE (tab->awk, tab);
}
ase_size_t ase_awk_tab_getsize (ase_awk_tab_t* tab)
{
return tab->size;
}
ase_size_t ase_awk_tab_getcapa (ase_awk_tab_t* tab)
{
return tab->capa;
}
ase_awk_tab_t* ase_awk_tab_setcapa (ase_awk_tab_t* tab, ase_size_t capa)
{
void* tmp;
if (tab->size > capa)
{
ase_awk_tab_remove (tab, capa, tab->size - capa);
ASE_ASSERT (tab->size <= capa);
}
if (capa > 0)
{
if (tab->awk->prmfns.mmgr.realloc != ASE_NULL)
{
tmp = ASE_AWK_REALLOC (tab->awk,
tab->buf, ASE_SIZEOF(*tab->buf) * capa);
if (tmp == ASE_NULL) return ASE_NULL;
}
else
{
tmp = ASE_AWK_MALLOC (
tab->awk, ASE_SIZEOF(*tab->buf) * capa);
if (tmp == ASE_NULL) return ASE_NULL;
if (tab->buf != ASE_NULL)
{
ase_size_t x;
x = (capa > tab->capa)? tab->capa: capa;
ase_memcpy (
tmp, tab->buf,
ASE_SIZEOF(*tab->buf) * x);
ASE_AWK_FREE (tab->awk, tab->buf);
}
}
}
else
{
if (tab->buf != ASE_NULL) ASE_AWK_FREE (tab->awk, tab->buf);
tmp = ASE_NULL;
}
tab->buf = tmp;
tab->capa = capa;
return tab;
}
void ase_awk_tab_clear (ase_awk_tab_t* tab)
{
ase_size_t i;
for (i = 0; i < tab->size; i++)
{
ASE_AWK_FREE (tab->awk, tab->buf[i].name.ptr);
tab->buf[i].name.ptr = ASE_NULL;
tab->buf[i].name.len = 0;
}
tab->size = 0;
}
ase_size_t ase_awk_tab_insert (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len)
{
ase_size_t i;
ase_char_t* dup;
dup = ase_awk_strxdup (tab->awk, str, len);
if (dup == ASE_NULL) return (ase_size_t)-1;
if (index >= tab->capa)
{
ase_size_t capa;
if (tab->capa <= 0) capa = (index + 1);
else
{
do { capa = tab->capa * 2; } while (index >= capa);
}
if (ase_awk_tab_setcapa(tab,capa) == ASE_NULL)
{
ASE_AWK_FREE (tab->awk, dup);
return (ase_size_t)-1;
}
}
for (i = tab->size; i > index; i--) tab->buf[i] = tab->buf[i-1];
tab->buf[index].name.ptr = dup;
tab->buf[index].name.len = len;
if (index > tab->size) tab->size = index + 1;
else tab->size++;
return index;
}
ase_size_t ase_awk_tab_remove (
ase_awk_tab_t* tab, ase_size_t index, ase_size_t count)
{
ase_size_t i, j, k;
if (index >= tab->size) return 0;
if (count > tab->size - index) count = tab->size - index;
i = index;
j = index + count;
k = index + count;
while (i < k)
{
ASE_AWK_FREE (tab->awk, tab->buf[i].name.ptr);
if (j >= tab->size)
{
tab->buf[i].name.ptr = ASE_NULL;
tab->buf[i].name.len = 0;
i++;
}
else
{
tab->buf[i].name.ptr = tab->buf[j].name.ptr;
tab->buf[i].name.len = tab->buf[j].name.len;
i++; j++;
}
}
tab->size -= count;
return count;
}
ase_size_t ase_awk_tab_add (
ase_awk_tab_t* tab, const ase_char_t* str, ase_size_t len)
{
return ase_awk_tab_insert (tab, tab->size, str, len);
}
ase_size_t ase_awk_tab_adduniq (
ase_awk_tab_t* tab, const ase_char_t* str, ase_size_t len)
{
ase_size_t i;
i = ase_awk_tab_find (tab, 0, str, len);
if (i != (ase_size_t)-1) return i; /* found. return the current index */
/* insert a new entry */
return ase_awk_tab_insert (tab, tab->size, str, len);
}
ase_size_t ase_awk_tab_find (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len)
{
ase_size_t i;
for (i = index; i < tab->size; i++)
{
if (ase_strxncmp (
tab->buf[i].name.ptr, tab->buf[i].name.len,
str, len) == 0) return i;
}
return (ase_size_t)-1;
}
ase_size_t ase_awk_tab_rfind (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len)
{
ase_size_t i;
if (index >= tab->size) return (ase_size_t)-1;
for (i = index + 1; i-- > 0; )
{
if (ase_strxncmp (
tab->buf[i].name.ptr, tab->buf[i].name.len,
str, len) == 0) return i;
}
return (ase_size_t)-1;
}
ase_size_t ase_awk_tab_rrfind (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len)
{
ase_size_t i;
if (index >= tab->size) return (ase_size_t)-1;
for (i = tab->size - index; i-- > 0; )
{
if (ase_strxncmp (
tab->buf[i].name.ptr, tab->buf[i].name.len,
str, len) == 0) return i;
}
return (ase_size_t)-1;
}
ase_size_t ase_awk_tab_findx (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len,
void(*transform)(ase_size_t, ase_cstr_t*,void*), void* arg)
{
ase_size_t i;
for (i = index; i < tab->size; i++)
{
ase_cstr_t x;
x.ptr = tab->buf[i].name.ptr;
x.len = tab->buf[i].name.len;
transform (i, &x, arg);
if (ase_strxncmp (x.ptr, x.len, str, len) == 0) return i;
}
return (ase_size_t)-1;
}
ase_size_t ase_awk_tab_rfindx (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len,
void(*transform)(ase_size_t, ase_cstr_t*,void*), void* arg)
{
ase_size_t i;
if (index >= tab->size) return (ase_size_t)-1;
for (i = index + 1; i-- > 0; )
{
ase_cstr_t x;
x.ptr = tab->buf[i].name.ptr;
x.len = tab->buf[i].name.len;
transform (i, &x, arg);
if (ase_strxncmp (x.ptr, x.len, str, len) == 0) return i;
}
return (ase_size_t)-1;
}
ase_size_t ase_awk_tab_rrfindx (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len,
void(*transform)(ase_size_t, ase_cstr_t*,void*), void* arg)
{
ase_size_t i;
if (index >= tab->size) return (ase_size_t)-1;
for (i = tab->size - index; i-- > 0; )
{
ase_cstr_t x;
x.ptr = tab->buf[i].name.ptr;
x.len = tab->buf[i].name.len;
transform (i, &x, arg);
if (ase_strxncmp (x.ptr, x.len, str, len) == 0) return i;
}
return (ase_size_t)-1;
}

87
ase/lib/awk/tab.h Normal file
View File

@ -0,0 +1,87 @@
/*
* $Id: tab.h 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
#ifndef _ASE_AWK_TAB_H_
#define _ASE_AWK_TAB_H_
#ifndef _ASE_AWK_AWK_H_
#error Never include this file directly. Include <ase/awk/awk.h> instead
#endif
/* TODO: you have to turn this into a hash table.
as of now, this is an arrayed table. */
typedef struct ase_awk_tab_t ase_awk_tab_t;
struct ase_awk_tab_t
{
struct
{
struct
{
ase_char_t* ptr;
ase_size_t len;
} name;
}* buf;
ase_size_t size;
ase_size_t capa;
ase_awk_t* awk;
ase_bool_t __dynamic;
};
#ifdef __cplusplus
extern "C" {
#endif
ase_awk_tab_t* ase_awk_tab_open (ase_awk_tab_t* tab, ase_awk_t* awk);
void ase_awk_tab_close (ase_awk_tab_t* tab);
ase_size_t ase_awk_tab_getsize (ase_awk_tab_t* tab);
ase_size_t ase_awk_tab_getcapa (ase_awk_tab_t* tab);
ase_awk_tab_t* ase_awk_tab_setcapa (ase_awk_tab_t* tab, ase_size_t capa);
void ase_awk_tab_clear (ase_awk_tab_t* tab);
ase_size_t ase_awk_tab_insert (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len);
ase_size_t ase_awk_tab_remove (
ase_awk_tab_t* tab, ase_size_t index, ase_size_t count);
ase_size_t ase_awk_tab_add (
ase_awk_tab_t* tab, const ase_char_t* str, ase_size_t len);
ase_size_t ase_awk_tab_adduniq (
ase_awk_tab_t* tab, const ase_char_t* str, ase_size_t len);
ase_size_t ase_awk_tab_find (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len);
ase_size_t ase_awk_tab_rfind (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len);
ase_size_t ase_awk_tab_rrfind (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len);
ase_size_t ase_awk_tab_findx (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len,
void(*transform)(ase_size_t, ase_cstr_t*,void*), void* arg);
ase_size_t ase_awk_tab_rfindx (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len,
void(*transform)(ase_size_t, ase_cstr_t*,void*), void* arg);
ase_size_t ase_awk_tab_rrfindx (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len,
void(*transform)(ase_size_t, ase_cstr_t*,void*), void* arg);
#ifdef __cplusplus
}
#endif
#endif

1263
ase/lib/awk/tree.c Normal file

File diff suppressed because it is too large Load Diff

424
ase/lib/awk/tree.h Normal file
View File

@ -0,0 +1,424 @@
/*
* $Id: tree.h 115 2008-03-03 11:13:15Z baconevi $
*
* {License}
*/
#ifndef _ASE_AWK_TREE_H_
#define _ASE_AWK_TREE_H_
#ifndef _ASE_AWK_AWK_H_
#error Never include this file directly. Include <ase/awk/awk.h> instead
#endif
enum ase_awk_nde_type_t
{
ASE_AWK_NDE_NULL,
/* statement */
ASE_AWK_NDE_BLK,
ASE_AWK_NDE_IF,
ASE_AWK_NDE_WHILE,
ASE_AWK_NDE_DOWHILE,
ASE_AWK_NDE_FOR,
ASE_AWK_NDE_FOREACH,
ASE_AWK_NDE_BREAK,
ASE_AWK_NDE_CONTINUE,
ASE_AWK_NDE_RETURN,
ASE_AWK_NDE_EXIT,
ASE_AWK_NDE_NEXT,
ASE_AWK_NDE_NEXTFILE,
ASE_AWK_NDE_DELETE,
ASE_AWK_NDE_RESET,
ASE_AWK_NDE_PRINT,
ASE_AWK_NDE_PRINTF,
/* expression */
/* if you change the following values including their order,
* you should change __eval_func of __eval_expression
* in run.c accordingly */
ASE_AWK_NDE_GRP,
ASE_AWK_NDE_ASS,
ASE_AWK_NDE_EXP_BIN,
ASE_AWK_NDE_EXP_UNR,
ASE_AWK_NDE_EXP_INCPRE,
ASE_AWK_NDE_EXP_INCPST,
ASE_AWK_NDE_CND,
ASE_AWK_NDE_BFN,
ASE_AWK_NDE_AFN,
ASE_AWK_NDE_INT,
ASE_AWK_NDE_REAL,
ASE_AWK_NDE_STR,
ASE_AWK_NDE_REX,
/* keep this order for the following items otherwise, you may have
* to change eval_incpre and eval_incpst in run.c as well as
* ASE_AWK_VAL_REF_XXX in val.h */
ASE_AWK_NDE_NAMED,
ASE_AWK_NDE_GLOBAL,
ASE_AWK_NDE_LOCAL,
ASE_AWK_NDE_ARG,
ASE_AWK_NDE_NAMEDIDX,
ASE_AWK_NDE_GLOBALIDX,
ASE_AWK_NDE_LOCALIDX,
ASE_AWK_NDE_ARGIDX,
ASE_AWK_NDE_POS,
/* ---------------------------------- */
ASE_AWK_NDE_GETLINE
};
enum ase_awk_in_type_t
{
/* the order of these values match
* __in_type_map and __in_opt_map in extio.c */
ASE_AWK_IN_PIPE,
ASE_AWK_IN_COPROC,
ASE_AWK_IN_FILE,
ASE_AWK_IN_CONSOLE
};
enum ase_awk_out_type_t
{
/* the order of these values match
* __out_type_map and __out_opt_map in extio.c */
ASE_AWK_OUT_PIPE,
ASE_AWK_OUT_COPROC,
ASE_AWK_OUT_FILE,
ASE_AWK_OUT_FILE_APPEND,
ASE_AWK_OUT_CONSOLE
};
/* afn (awk function defined with the keyword function) */
typedef struct ase_awk_afn_t ase_awk_afn_t;
typedef struct ase_awk_nde_t ase_awk_nde_t;
typedef struct ase_awk_nde_blk_t ase_awk_nde_blk_t;
typedef struct ase_awk_nde_grp_t ase_awk_nde_grp_t;
typedef struct ase_awk_nde_ass_t ase_awk_nde_ass_t;
typedef struct ase_awk_nde_exp_t ase_awk_nde_exp_t;
typedef struct ase_awk_nde_cnd_t ase_awk_nde_cnd_t;
typedef struct ase_awk_nde_pos_t ase_awk_nde_pos_t;
#ifndef ASE_AWK_NDE_INT_DEFINED
#define ASE_AWK_NDE_INT_DEFINED
typedef struct ase_awk_nde_int_t ase_awk_nde_int_t;
#endif
#ifndef ASE_AWK_NDE_REAL_DEFINED
#define ASE_AWK_NDE_REAL_DEFINED
typedef struct ase_awk_nde_real_t ase_awk_nde_real_t;
#endif
typedef struct ase_awk_nde_str_t ase_awk_nde_str_t;
typedef struct ase_awk_nde_rex_t ase_awk_nde_rex_t;
typedef struct ase_awk_nde_var_t ase_awk_nde_var_t;
typedef struct ase_awk_nde_call_t ase_awk_nde_call_t;
typedef struct ase_awk_nde_getline_t ase_awk_nde_getline_t;
typedef struct ase_awk_nde_if_t ase_awk_nde_if_t;
typedef struct ase_awk_nde_while_t ase_awk_nde_while_t;
typedef struct ase_awk_nde_for_t ase_awk_nde_for_t;
typedef struct ase_awk_nde_foreach_t ase_awk_nde_foreach_t;
typedef struct ase_awk_nde_break_t ase_awk_nde_break_t;
typedef struct ase_awk_nde_continue_t ase_awk_nde_continue_t;
typedef struct ase_awk_nde_return_t ase_awk_nde_return_t;
typedef struct ase_awk_nde_exit_t ase_awk_nde_exit_t;
typedef struct ase_awk_nde_next_t ase_awk_nde_next_t;
typedef struct ase_awk_nde_nextfile_t ase_awk_nde_nextfile_t;
typedef struct ase_awk_nde_delete_t ase_awk_nde_delete_t;
typedef struct ase_awk_nde_reset_t ase_awk_nde_reset_t;
typedef struct ase_awk_nde_print_t ase_awk_nde_print_t;
struct ase_awk_afn_t
{
ase_char_t* name;
ase_size_t name_len;
ase_size_t nargs;
ase_awk_nde_t* body;
};
#define ASE_AWK_NDE_HDR \
int type; \
ase_size_t line; \
ase_awk_nde_t* next
struct ase_awk_nde_t
{
ASE_AWK_NDE_HDR;
};
/* ASE_AWK_NDE_BLK - block statement including top-level blocks */
struct ase_awk_nde_blk_t
{
ASE_AWK_NDE_HDR;
ase_size_t nlocals;
ase_awk_nde_t* body;
};
/* ASE_AWK_NDE_GRP - expression group */
struct ase_awk_nde_grp_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* body;
};
/* ASE_AWK_NDE_ASS - assignment */
struct ase_awk_nde_ass_t
{
ASE_AWK_NDE_HDR;
int opcode;
ase_awk_nde_t* left;
ase_awk_nde_t* right;
};
/* ASE_AWK_NDE_EXP_BIN, ASE_AWK_NDE_EXP_UNR,
* ASE_AWK_NDE_EXP_INCPRE, ASE_AW_NDE_EXP_INCPST */
struct ase_awk_nde_exp_t
{
ASE_AWK_NDE_HDR;
int opcode;
ase_awk_nde_t* left;
ase_awk_nde_t* right; /* ASE_NULL for UNR, INCPRE, INCPST */
};
/* ASE_AWK_NDE_CND */
struct ase_awk_nde_cnd_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* test;
ase_awk_nde_t* left;
ase_awk_nde_t* right;
};
/* ASE_AWK_NDE_POS - positional - $1, $2, $x, etc */
struct ase_awk_nde_pos_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* val;
};
/* ASE_AWK_NDE_INT */
struct ase_awk_nde_int_t
{
ASE_AWK_NDE_HDR;
ase_long_t val;
ase_char_t* str;
ase_size_t len;
};
/* ASE_AWK_NDE_REAL */
struct ase_awk_nde_real_t
{
ASE_AWK_NDE_HDR;
ase_real_t val;
ase_char_t* str;
ase_size_t len;
};
/* ASE_AWK_NDE_STR */
struct ase_awk_nde_str_t
{
ASE_AWK_NDE_HDR;
ase_char_t* buf;
ase_size_t len;
};
/* ASE_AWK_NDE_REX */
struct ase_awk_nde_rex_t
{
ASE_AWK_NDE_HDR;
ase_char_t* buf;
ase_size_t len;
void* code;
};
/* ASE_AWK_NDE_NAMED, ASE_AWK_NDE_GLOBAL,
* ASE_AWK_NDE_LOCAL, ASE_AWK_NDE_ARG
* ASE_AWK_NDE_NAMEDIDX, ASE_AWK_NDE_GLOBALIDX,
* ASE_AWK_NDE_LOCALIDX, ASE_AWK_NDE_ARGIDX */
struct ase_awk_nde_var_t
{
ASE_AWK_NDE_HDR;
struct
{
ase_char_t* name;
ase_size_t name_len;
ase_size_t idxa;
} id;
ase_awk_nde_t* idx; /* ASE_NULL for non-XXXXIDX */
};
/* ASE_AWK_NDE_BFN, ASE_AWK_NDE_AFN */
struct ase_awk_nde_call_t
{
ASE_AWK_NDE_HDR;
union
{
struct
{
struct
{
ase_char_t* ptr;
ase_size_t len;
} name;
} afn;
/* minimum information of a intrinsic function
* needed during run-time. */
struct
{
struct
{
ase_char_t* ptr;
ase_size_t len;
} name;
/* original name. if ase_awk_setword has been
* invoked, oname can be different from name */
struct
{
ase_char_t* ptr;
ase_size_t len;
} oname;
struct
{
ase_size_t min;
ase_size_t max;
const ase_char_t* spec;
} arg;
int (*handler) (
ase_awk_run_t*, const ase_char_t*, ase_size_t);
} bfn;
} what;
ase_awk_nde_t* args;
ase_size_t nargs;
};
/* ASE_AWK_NDE_GETLINE */
struct ase_awk_nde_getline_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* var;
int in_type; /* ASE_AWK_GETLINE_XXX */
ase_awk_nde_t* in;
};
/* ASE_AWK_NDE_IF */
struct ase_awk_nde_if_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* test;
ase_awk_nde_t* then_part;
ase_awk_nde_t* else_part; /* optional */
};
/* ASE_AWK_NDE_WHILE, ASE_AWK_NDE_DOWHILE */
struct ase_awk_nde_while_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* test;
ase_awk_nde_t* body;
};
/* ASE_AWK_NDE_FOR */
struct ase_awk_nde_for_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* init; /* optional */
ase_awk_nde_t* test; /* optional */
ase_awk_nde_t* incr; /* optional */
ase_awk_nde_t* body;
};
/* ASE_AWK_NDE_FOREACH */
struct ase_awk_nde_foreach_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* test;
ase_awk_nde_t* body;
};
/* ASE_AWK_NDE_BREAK */
struct ase_awk_nde_break_t
{
ASE_AWK_NDE_HDR;
};
/* ASE_AWK_NDE_CONTINUE */
struct ase_awk_nde_continue_t
{
ASE_AWK_NDE_HDR;
};
/* ASE_AWK_NDE_RETURN */
struct ase_awk_nde_return_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* val; /* optional (no return code if ASE_NULL) */
};
/* ASE_AWK_NDE_EXIT */
struct ase_awk_nde_exit_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* val; /* optional (no exit code if ASE_NULL) */
};
/* ASE_AWK_NDE_NEXT */
struct ase_awk_nde_next_t
{
ASE_AWK_NDE_HDR;
};
/* ASE_AWK_NDE_NEXTFILE */
struct ase_awk_nde_nextfile_t
{
ASE_AWK_NDE_HDR;
int out;
};
/* ASE_AWK_NDE_DELETE */
struct ase_awk_nde_delete_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* var;
};
/* ASE_AWK_NDE_RESET */
struct ase_awk_nde_reset_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* var;
};
/* ASE_AWK_NDE_PRINT */
struct ase_awk_nde_print_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* args;
int out_type; /* ASE_AWK_OUT_XXX */
ase_awk_nde_t* out;
};
#ifdef __cplusplus
extern "C" {
#endif
/* print the entire tree */
int ase_awk_prnpt (ase_awk_t* awk, ase_awk_nde_t* tree);
/* print a single top-level node */
int ase_awk_prnnde (ase_awk_t* awk, ase_awk_nde_t* node);
/* print the pattern part */
int ase_awk_prnptnpt (ase_awk_t* awk, ase_awk_nde_t* tree);
void ase_awk_clrpt (ase_awk_t* awk, ase_awk_nde_t* tree);
#ifdef __cplusplus
}
#endif
#endif

1134
ase/lib/awk/val.c Normal file

File diff suppressed because it is too large Load Diff

213
ase/lib/awk/val.h Normal file
View File

@ -0,0 +1,213 @@
/*
* $Id: val.h 155 2008-03-22 06:47:27Z baconevi $
*
* {License}
*/
#ifndef _ASE_AWK_VAL_H_
#define _ASE_AWK_VAL_H_
#ifndef _ASE_AWK_AWK_H_
#error Include <ase/awk/awk.h> first
#endif
#include <ase/cmn/str.h>
enum ase_awk_val_type_t
{
/* the values between ASE_AWK_VAL_NIL and ASE_AWK_VAL_STR inclusive
* must be synchronized with an internal table of the __cmp_val
* function in run.c */
ASE_AWK_VAL_NIL = 0,
ASE_AWK_VAL_INT = 1,
ASE_AWK_VAL_REAL = 2,
ASE_AWK_VAL_STR = 3,
ASE_AWK_VAL_REX = 4,
ASE_AWK_VAL_MAP = 5,
ASE_AWK_VAL_REF = 6
};
enum ase_awk_val_ref_id_t
{
/* keep these items in the same order as corresponding items
* in tree.h */
ASE_AWK_VAL_REF_NAMED,
ASE_AWK_VAL_REF_GLOBAL,
ASE_AWK_VAL_REF_LOCAL,
ASE_AWK_VAL_REF_ARG,
ASE_AWK_VAL_REF_NAMEDIDX,
ASE_AWK_VAL_REF_GLOBALIDX,
ASE_AWK_VAL_REF_LOCALIDX,
ASE_AWK_VAL_REF_ARGIDX,
ASE_AWK_VAL_REF_POS
};
enum ase_awk_valtostr_opt_t
{
ASE_AWK_VALTOSTR_CLEAR = (1 << 0),
ASE_AWK_VALTOSTR_FIXED = (1 << 1),/* this overrides CLEAR */
ASE_AWK_VALTOSTR_PRINT = (1 << 2)
};
typedef struct ase_awk_val_nil_t ase_awk_val_nil_t;
typedef struct ase_awk_val_int_t ase_awk_val_int_t;
typedef struct ase_awk_val_real_t ase_awk_val_real_t;
typedef struct ase_awk_val_str_t ase_awk_val_str_t;
typedef struct ase_awk_val_rex_t ase_awk_val_rex_t;
typedef struct ase_awk_val_map_t ase_awk_val_map_t;
typedef struct ase_awk_val_ref_t ase_awk_val_ref_t;
/* this is not a value. it is just a value holder */
typedef struct ase_awk_val_chunk_t ase_awk_val_chunk_t;
#if ASE_SIZEOF_INT == 2
#define ASE_AWK_VAL_HDR \
unsigned int type: 3; \
unsigned int ref: 13
#else
#define ASE_AWK_VAL_HDR \
unsigned int type: 3; \
unsigned int ref: 29
#endif
#ifndef ASE_AWK_NDE_INT_DEFINED
#define ASE_AWK_NDE_INT_DEFINED
typedef struct ase_awk_nde_int_t ase_awk_nde_int_t;
#endif
#ifndef ASE_AWK_NDE_REAL_DEFINED
#define ASE_AWK_NDE_REAL_DEFINED
typedef struct ase_awk_nde_real_t ase_awk_nde_real_t;
#endif
#define ASE_AWK_VAL_TYPE(x) ((x)->type)
struct ase_awk_val_t
{
ASE_AWK_VAL_HDR;
};
/* ASE_AWK_VAL_NIL */
struct ase_awk_val_nil_t
{
ASE_AWK_VAL_HDR;
};
/* ASE_AWK_VAL_INT */
struct ase_awk_val_int_t
{
ASE_AWK_VAL_HDR;
ase_long_t val;
ase_awk_nde_int_t* nde;
};
/* ASE_AWK_VAL_REAL */
struct ase_awk_val_real_t
{
ASE_AWK_VAL_HDR;
ase_real_t val;
ase_awk_nde_real_t* nde;
};
/* ASE_AWK_VAL_STR */
struct ase_awk_val_str_t
{
ASE_AWK_VAL_HDR;
ase_char_t* buf;
ase_size_t len;
};
/* ASE_AWK_VAL_REX */
struct ase_awk_val_rex_t
{
ASE_AWK_VAL_HDR;
ase_char_t* buf;
ase_size_t len;
void* code;
};
/* ASE_AWK_VAL_MAP */
struct ase_awk_val_map_t
{
ASE_AWK_VAL_HDR;
/* TODO: make val_map to array if the indices used are all
* integers switch to map dynamically once the
* non-integral index is seen.
*/
ase_map_t* map;
};
/* ASE_AWK_VAL_REF */
struct ase_awk_val_ref_t
{
ASE_AWK_VAL_HDR;
int id;
/* if id is ASE_AWK_VAL_REF_POS, adr holds an index of the
* positional variable. Otherwise, adr points to the value
* directly. */
ase_awk_val_t** adr;
};
#ifdef __cplusplus
extern "C" {
#endif
extern ase_awk_val_t* ase_awk_val_nil;
extern ase_awk_val_t* ase_awk_val_zls;
extern ase_awk_val_t* ase_awk_val_negone;
extern ase_awk_val_t* ase_awk_val_zero;
extern ase_awk_val_t* ase_awk_val_one;
ase_awk_val_t* ase_awk_makeintval (ase_awk_run_t* run, ase_long_t v);
ase_awk_val_t* ase_awk_makerealval (ase_awk_run_t* run, ase_real_t v);
ase_awk_val_t* ase_awk_makestrval0 (
ase_awk_run_t* run, const ase_char_t* str);
ase_awk_val_t* ase_awk_makestrval (
ase_awk_run_t* run, const ase_char_t* str, ase_size_t len);
ase_awk_val_t* ase_awk_makestrval_nodup (
ase_awk_run_t* run, ase_char_t* str, ase_size_t len);
ase_awk_val_t* ase_awk_makestrval2 (
ase_awk_run_t* run,
const ase_char_t* str1, ase_size_t len1,
const ase_char_t* str2, ase_size_t len2);
ase_awk_val_t* ase_awk_makerexval (
ase_awk_run_t* run, const ase_char_t* buf, ase_size_t len, void* code);
ase_awk_val_t* ase_awk_makemapval (ase_awk_run_t* run);
ase_awk_val_t* ase_awk_makerefval (
ase_awk_run_t* run, int id, ase_awk_val_t** adr);
ase_bool_t ase_awk_isstaticval (ase_awk_val_t* val);
void ase_awk_freeval (ase_awk_run_t* run, ase_awk_val_t* val, ase_bool_t cache);
void ase_awk_refupval (ase_awk_run_t* run, ase_awk_val_t* val);
void ase_awk_refdownval (ase_awk_run_t* run, ase_awk_val_t* val);
void ase_awk_refdownval_nofree (ase_awk_run_t* run, ase_awk_val_t* val);
void ase_awk_freevalchunk (ase_awk_run_t* run, ase_awk_val_chunk_t* chunk);
ase_bool_t ase_awk_valtobool (
ase_awk_run_t* run, ase_awk_val_t* val);
ase_char_t* ase_awk_valtostr (
ase_awk_run_t* run, ase_awk_val_t* val,
int opt, ase_str_t* buf, ase_size_t* len);
int ase_awk_valtonum (
ase_awk_run_t* run, ase_awk_val_t* v, ase_long_t* l, ase_real_t* r);
int ase_awk_strtonum (
ase_awk_run_t* run, const ase_char_t* ptr, ase_size_t len,
ase_long_t* l, ase_real_t* r);
void ase_awk_dprintval (ase_awk_run_t* run, ase_awk_val_t* val);
#ifdef __cplusplus
}
#endif
#endif