import isi.jserver.jserver;

class jstest
{
	public static void main(String args[])
	{
		jserver js;
		byte buf[] = new byte[256];
		byte[] prompt = new byte[3];
		boolean flag=true,showflag=false;
		int x=0;
		String s;
		
		js = new jserver();	// create jserver object
		js.start(0);	// 0 exe, 1 dll
		js.Log(true);
		System.out.println("Enter J expressions. Ctrl+D to quit.");
		System.out.println("Ctrl+A to show/hide J. Ctrl+G to get info on J variable abc.");
		
		while(flag)
		{
			try
			{
				System.out.write(prompt);
				x = System.in.read(buf, 0, 256);
			}
			catch(Exception e)
			{
				System.out.println(e.toString());
			}
			if(buf[0] == 4) break;	// ctrl+d
			if(buf[0] == 1)			// ctrl+a
			{
				js.Show(showflag=!showflag);
				continue;
			}
			if(buf[0] == 7)	// Ctrl+G
			{
				System.out.println("Info on abc"); // CR
				js.Get("abc");
				int type = js.getType();
				int rank = js.getRank();
				int elements = js.getElements();
				System.out.println("type: " + type + " rank: " + rank + " elements: " + elements);
				int[] shape = js.getShape();
				for(int i=0; i<rank; ++i)
					System.out.println("shape[" + i + "]: " + shape[i]);
				if(rank==0)
				{
					switch(type)
					{
					case js.TYPEBOOL:
						System.out.println("boolean value: " + js.getBool());
						System.out.println("bool =: abc");
						js.Set("bool", js.getBool());
						break;

					case js.TYPEBYTE:
						System.out.println("byte value: " + js.getByte());
						System.out.println("char value: " + js.getChar());
						System.out.println("char =: abc");
						js.Set("char", js.getByte());
						break;

					case js.TYPEINT:
						System.out.println("integer value: " + js.getInt());
						System.out.println("int =: abc");
						js.Set("int", js.getInt());
						break;

					case js.TYPEDOUBLE:
						System.out.println("double value: " + js.getDouble());
						System.out.println("double =: abc");
						js.Set("double", js.getDouble());
						break;
					}
				}
				if(rank != 0)
				{
					switch(type)
					{
					case js.TYPEBOOL:
						boolean[] bools = js.getBools();
						System.out.println("bools =: abc");
						js.Set("bools", bools);
						break;

					case js.TYPEBYTE:
						byte[] bytes = js.getBytes();
						System.out.println("string value: " + js.getString());
						System.out.println("chars =: abc");
						js.Set("chars", bytes);
						break;

					case js.TYPEINT:
						int[] ints = js.getInts();
						System.out.println("ints =: abc");
						js.Set("ints", ints);
						break;

					case js.TYPEDOUBLE:
						double[] doubles = js.getDoubles();
						System.out.println("doubles =: abc");
						js.Set("doubles", doubles);
						break;
					}
				}
				continue;
			}
			js.DoR(new String(buf, 0, 0, x-1));
			String sss = js.getString();
			String qqq = "abc";
			int kkk = qqq.length();
			int k = sss.length();
			System.out.print(js.getString()); // CR
		}
		js.close();
		System.exit(0);
	}
}