2007-10-13 15:28:00 +00:00
|
|
|
/*
|
2008-03-04 05:13:15 +00:00
|
|
|
* $Id: Context.java 115 2008-03-03 11:13:15Z baconevi $
|
2007-11-03 23:35:00 +00:00
|
|
|
*
|
|
|
|
* {License}
|
2007-10-13 15:28:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package ase.awk;
|
|
|
|
|
2007-10-31 22:56:00 +00:00
|
|
|
import java.util.Stack;
|
|
|
|
|
2007-10-13 15:28:00 +00:00
|
|
|
public class Context
|
|
|
|
{
|
2007-10-31 00:01:00 +00:00
|
|
|
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;
|
|
|
|
|
2007-10-31 22:56:00 +00:00
|
|
|
protected Awk awk;
|
|
|
|
protected long runid;
|
|
|
|
protected Object custom;
|
2007-11-03 23:35:00 +00:00
|
|
|
protected Stack clearableStack;
|
2007-10-13 15:28:00 +00:00
|
|
|
|
2007-10-17 00:30:00 +00:00
|
|
|
Context (Awk awk)
|
2007-10-13 15:28:00 +00:00
|
|
|
{
|
2007-10-17 00:30:00 +00:00
|
|
|
this.awk = awk;
|
|
|
|
this.runid = 0;
|
|
|
|
this.custom = null;
|
2007-11-03 23:35:00 +00:00
|
|
|
this.clearableStack = new Stack ();
|
2007-10-31 22:56:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void clear ()
|
|
|
|
{
|
2007-11-03 23:35:00 +00:00
|
|
|
Clearable obj;
|
|
|
|
while ((obj = popClearable()) != null) obj.clear ();
|
2007-10-31 22:56:00 +00:00
|
|
|
}
|
|
|
|
|
2007-11-03 23:35:00 +00:00
|
|
|
void pushClearable (Clearable obj)
|
2007-10-31 22:56:00 +00:00
|
|
|
{
|
2007-11-03 23:35:00 +00:00
|
|
|
clearableStack.push (obj);
|
2007-10-31 22:56:00 +00:00
|
|
|
}
|
|
|
|
|
2007-11-03 23:35:00 +00:00
|
|
|
Clearable popClearable ()
|
2007-10-31 22:56:00 +00:00
|
|
|
{
|
2007-11-03 23:35:00 +00:00
|
|
|
if (clearableStack.empty()) return null;
|
|
|
|
return (Clearable)clearableStack.pop ();
|
2007-10-17 00:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Awk getAwk ()
|
|
|
|
{
|
|
|
|
return awk;
|
2007-10-13 15:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public long getId ()
|
|
|
|
{
|
2007-10-17 00:30:00 +00:00
|
|
|
return this.runid;
|
2007-10-13 15:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setCustom (Object custom)
|
|
|
|
{
|
|
|
|
this.custom = custom;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Object getCustom ()
|
|
|
|
{
|
|
|
|
return this.custom;
|
|
|
|
}
|
2007-10-17 00:30:00 +00:00
|
|
|
|
|
|
|
public void setConsoleInputName (String name) throws Exception
|
|
|
|
{
|
|
|
|
awk.setfilename (this.runid, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setConsoleOutputName (String name) throws Exception
|
|
|
|
{
|
|
|
|
awk.setofilename (this.runid, name);
|
|
|
|
}
|
|
|
|
|
2007-10-17 23:38:00 +00:00
|
|
|
public void stop ()
|
|
|
|
{
|
2007-10-18 23:51:00 +00:00
|
|
|
stop (this.runid);
|
2007-10-17 23:38:00 +00:00
|
|
|
}
|
|
|
|
|
2007-10-31 00:01:00 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2007-11-02 22:16:00 +00:00
|
|
|
public Argument getGlobal (int id) throws Exception
|
2007-10-31 00:01:00 +00:00
|
|
|
{
|
2007-11-02 22:16:00 +00:00
|
|
|
return getglobal (this.runid, id);
|
2007-10-31 00:01:00 +00:00
|
|
|
}
|
|
|
|
|
2007-10-18 23:51:00 +00:00
|
|
|
protected native void stop (long runid);
|
2007-10-31 00:01:00 +00:00
|
|
|
protected native void setglobal (long runid, int id, Return ret);
|
2007-11-02 22:16:00 +00:00
|
|
|
protected native Argument getglobal (long runid, int id);
|
2007-10-18 23:51:00 +00:00
|
|
|
|
2007-10-17 00:30:00 +00:00
|
|
|
// TODO:
|
|
|
|
// setError
|
|
|
|
// getError
|
2007-10-13 15:28:00 +00:00
|
|
|
}
|