2006-10-24 06:06:16 +00:00
|
|
|
/*
|
2007-04-02 11:14:01 +00:00
|
|
|
* $Id: AseAwk.java,v 1.1 2007-04-02 11:14:01 bacon Exp $
|
2006-10-24 06:06:16 +00:00
|
|
|
*/
|
|
|
|
|
2007-01-31 09:31:29 +00:00
|
|
|
import java.net.URL;
|
|
|
|
|
2007-04-02 11:14:01 +00:00
|
|
|
public class AseAwk extends ase.awk.StdAwk
|
2006-10-24 06:06:16 +00:00
|
|
|
{
|
2007-04-02 11:14:01 +00:00
|
|
|
public AseAwk () throws ase.awk.Exception
|
2006-10-24 06:06:16 +00:00
|
|
|
{
|
|
|
|
super ();
|
2006-11-27 04:33:22 +00:00
|
|
|
|
2006-12-02 16:26:29 +00:00
|
|
|
addBuiltinFunction ("sin", 1, 1);
|
|
|
|
addBuiltinFunction ("cos", 1, 1);
|
|
|
|
addBuiltinFunction ("tan", 1, 1);
|
2007-01-23 14:23:18 +00:00
|
|
|
addBuiltinFunction ("srand", 0, 1);
|
|
|
|
addBuiltinFunction ("rand", 0, 0);
|
2006-12-02 16:26:29 +00:00
|
|
|
|
|
|
|
addBuiltinFunction ("system", 1, 1);
|
2006-11-29 14:52:36 +00:00
|
|
|
|
2006-12-02 16:26:29 +00:00
|
|
|
addBuiltinFunction ("xxx", 1, 10);
|
|
|
|
//addBuiltinFunction ("xxx", 1, 1);
|
2006-11-29 14:52:36 +00:00
|
|
|
//deleteBuiltinFunction ("sin");
|
|
|
|
//deleteBuiltinFunction ("sin");
|
2006-11-27 04:33:22 +00:00
|
|
|
}
|
|
|
|
|
2006-12-02 16:26:29 +00:00
|
|
|
public Object xxx (long runid, Object[] args)
|
2006-11-28 15:09:53 +00:00
|
|
|
{
|
2007-01-24 14:21:30 +00:00
|
|
|
System.out.println ("<<BFN_XXX>>");
|
2006-11-29 11:41:15 +00:00
|
|
|
for (int i = 0; i < args.length; i++)
|
|
|
|
{
|
|
|
|
System.out.print ("ARG #" + i);
|
|
|
|
System.out.print (": ");
|
|
|
|
if (args[i] == null) System.out.println ("nil");
|
|
|
|
else System.out.println (args[i].toString());
|
|
|
|
}
|
|
|
|
return null;
|
2006-11-29 14:52:36 +00:00
|
|
|
//return new String ("return value");
|
|
|
|
//return new Double (1.234);
|
|
|
|
//return new Float (1.234);
|
|
|
|
//return new Integer (1001);
|
|
|
|
//return new Long (1001);
|
|
|
|
//return new Short ((short)1001);
|
2006-11-24 13:25:12 +00:00
|
|
|
}
|
2006-11-22 15:12:04 +00:00
|
|
|
|
2007-01-23 14:23:18 +00:00
|
|
|
protected String[] consoleInputNames ()
|
2006-11-24 13:25:12 +00:00
|
|
|
{
|
|
|
|
String[] cin = new String[3];
|
2006-11-22 15:12:04 +00:00
|
|
|
cin[0] = "c1.txt";
|
|
|
|
cin[1] = "c2.txt";
|
|
|
|
cin[2] = "c3.txt";
|
2006-11-24 13:25:12 +00:00
|
|
|
return cin;
|
|
|
|
}
|
2006-11-22 15:12:04 +00:00
|
|
|
|
2007-01-23 14:23:18 +00:00
|
|
|
protected String[] consoleOutputNames ()
|
2006-11-24 13:25:12 +00:00
|
|
|
{
|
2007-01-21 13:21:14 +00:00
|
|
|
String[] cout = new String[1];
|
|
|
|
cout[0] = "";
|
|
|
|
return cout;
|
|
|
|
/*
|
2006-11-24 13:25:12 +00:00
|
|
|
String[] cout = new String[3];
|
2006-11-23 03:31:58 +00:00
|
|
|
cout[0] = "c4.txt";
|
|
|
|
cout[1] = "c5.txt";
|
|
|
|
cout[2] = "";
|
2006-11-24 13:25:12 +00:00
|
|
|
return cout;
|
2007-01-21 13:21:14 +00:00
|
|
|
*/
|
2006-10-24 06:06:16 +00:00
|
|
|
}
|
|
|
|
|
2007-01-23 14:23:18 +00:00
|
|
|
protected String[] sourceInputNames ()
|
2006-10-24 06:06:16 +00:00
|
|
|
{
|
2007-01-23 14:23:18 +00:00
|
|
|
String[] sin = new String[1];
|
2007-03-23 07:45:22 +00:00
|
|
|
sin[0] = "c:/projects/ase/test/awk/t.awk";
|
2007-01-23 14:23:18 +00:00
|
|
|
return sin;
|
2006-10-24 06:06:16 +00:00
|
|
|
}
|
|
|
|
|
2006-11-25 15:51:57 +00:00
|
|
|
/*
|
2007-01-23 14:23:18 +00:00
|
|
|
protected String sourceOutputName ()
|
2006-11-25 15:51:57 +00:00
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2006-10-24 06:06:16 +00:00
|
|
|
public static void main (String[] args)
|
|
|
|
{
|
2007-04-02 11:14:01 +00:00
|
|
|
AseAwk awk = null;
|
2006-10-24 06:06:16 +00:00
|
|
|
|
2007-04-02 11:14:01 +00:00
|
|
|
/*
|
2007-01-31 09:31:29 +00:00
|
|
|
URL url = ase.awk.Awk.class.getResource ("aseawk_jni.dll");
|
|
|
|
if (url == null) url = ase.awk.Awk.class.getResource ("aseawk_jni.so");
|
|
|
|
if (url != null) System.load (url.getFile());
|
2007-04-02 11:14:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (args.length != 1)
|
|
|
|
{
|
|
|
|
System.err.println ("Usage: " + AseAwk.class.getName() + " jni");
|
|
|
|
System.err.println ("Where jni := the full path to the jni library");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
System.load (args[0]);
|
|
|
|
}
|
|
|
|
catch (java.lang.UnsatisfiedLinkError e)
|
|
|
|
{
|
|
|
|
System.err.println ("Error: cannot load the library - " + args[0]);
|
|
|
|
return;
|
|
|
|
}
|
2007-01-31 09:31:29 +00:00
|
|
|
|
2006-10-24 06:06:16 +00:00
|
|
|
try
|
|
|
|
{
|
2007-04-02 11:14:01 +00:00
|
|
|
awk = new AseAwk ();
|
|
|
|
awk.setMaxDepth (AseAwk.DEPTH_BLOCK_PARSE, 30);
|
2007-01-25 14:14:56 +00:00
|
|
|
awk.setDebug (true);
|
|
|
|
//awk.setDebug (false);
|
|
|
|
|
|
|
|
//awk.setOption (awk.getOption() | OPTION_STRBASEONE);
|
2007-01-29 04:39:23 +00:00
|
|
|
System.out.println ("Option: [" + awk.getOption() + "]");
|
2007-01-23 14:23:18 +00:00
|
|
|
|
2006-10-24 06:06:16 +00:00
|
|
|
awk.parse ();
|
2007-02-01 07:24:00 +00:00
|
|
|
|
2007-02-23 08:54:03 +00:00
|
|
|
System.out.println ("about to run");
|
2007-02-01 07:24:00 +00:00
|
|
|
String[] aaa = new String[3];
|
|
|
|
aaa[0] = "abcdefg";
|
|
|
|
aaa[1] = "qwerty";
|
|
|
|
aaa[2] = "awk is bad";
|
|
|
|
awk.run ("main", aaa);
|
2006-10-24 06:06:16 +00:00
|
|
|
}
|
|
|
|
catch (ase.awk.Exception e)
|
|
|
|
{
|
2007-01-23 14:23:18 +00:00
|
|
|
if (e.getLine() == 0)
|
|
|
|
{
|
|
|
|
System.out.println ("ase.awk.Exception - " + e.getMessage());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
System.out.println (
|
|
|
|
"ase.awk.Exception at line " +
|
|
|
|
e.getLine() + " - " + e.getMessage());
|
|
|
|
}
|
2006-10-24 06:06:16 +00:00
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
2007-01-23 14:23:18 +00:00
|
|
|
if (awk != null)
|
|
|
|
{
|
|
|
|
awk.close ();
|
|
|
|
awk = null;
|
|
|
|
}
|
2006-10-24 06:06:16 +00:00
|
|
|
}
|
2007-01-23 14:23:18 +00:00
|
|
|
System.out.println ("==== end of awk ====");
|
2006-10-24 06:06:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|