qse/ase/test/awk/Awk.java

125 lines
2.3 KiB
Java
Raw Normal View History

2006-10-24 06:06:16 +00:00
/*
2007-01-25 14:14:56 +00:00
* $Id: Awk.java,v 1.22 2007-01-25 14:14:56 bacon Exp $
2006-10-24 06:06:16 +00:00
*/
package ase.test.awk;
2006-11-24 13:25:12 +00:00
public class Awk extends ase.awk.StdAwk
2006-10-24 06:06:16 +00:00
{
public Awk () throws ase.awk.Exception
{
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];
sin[0] = "t.awk";
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)
{
Awk awk = null;
try
{
awk = new Awk ();
2007-01-23 14:23:18 +00:00
awk.setMaxDepth (Awk.DEPTH_BLOCK_PARSE, 30);
2007-01-25 14:14:56 +00:00
awk.setDebug (true);
//awk.setDebug (false);
//awk.setOption (awk.getOption() | OPTION_STRBASEONE);
System.out.println ("[" + awk.getOption() + "]");
2007-01-23 14:23:18 +00:00
2006-10-24 06:06:16 +00:00
awk.parse ();
awk.run ();
}
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
}
}