changeset 90:8affa0aa0fc0

*** empty log message ***
author kono
date Fri, 18 Jan 2008 17:31:49 +0900
parents aed27c25859e
children f9579d8afd29
files src/parser/LogicNodeParser.java src/parser/LogicNodeScanner.java
diffstat 2 files changed, 29 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/parser/LogicNodeParser.java	Fri Jan 18 16:50:12 2008 +0900
+++ b/src/parser/LogicNodeParser.java	Fri Jan 18 17:31:49 2008 +0900
@@ -1,5 +1,6 @@
 package parser;
 
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
@@ -104,10 +105,15 @@
 	}
 	
 	public void parse(InputStream file) {
-		scanner = scanner.pushScannerFile(file);
+		scanner = scanner.pushScannerFile(file,null);
 		doParse();
 	}
 
+	public void parse(InputStream in, String prompt) {
+		scanner = scanner.pushScannerFile(in,prompt);
+		doParse();
+	}
+	
 	public Node doParse() {
 		Node n;
 		do {
@@ -281,6 +287,21 @@
 			return false;
 		}
 	}
+
+	public void showResourceFile(String file) {
+		try {
+			InputStream in;
+			in = getClass().getResourceAsStream("/"+file);
+			if (in==null) {
+				in = new FileInputStream(file);
+			}
+			byte[] buf = new byte[4096];
+			for(int len; (len=in.read(buf,0,4096))>0;) {
+				System.out.write(buf,0,len);
+			}
+		} catch (IOException e) {
+		}
+	}
 	
 	public void error(String err) {
 		scanner.error(err);
--- a/src/parser/LogicNodeScanner.java	Fri Jan 18 16:50:12 2008 +0900
+++ b/src/parser/LogicNodeScanner.java	Fri Jan 18 17:31:49 2008 +0900
@@ -35,6 +35,7 @@
 	private String filename;
 	public LogicNodeScanner<Node> prev;
 	public Token<Node> nullToken ;
+	public String prompt;
 
 	public LogicNodeScanner(Dictionary<Node> dict) {
 		this.dict = dict;
@@ -160,6 +161,7 @@
 			// move remaining data to the top, set position for next read
 			cb.compact();
 			try {
+				if (prompt!=null) System.out.print(prompt);
 				if (file.read(cb)>0) {
 					cb.flip();    // prepare for get (but we don't...) 
 					return true;
@@ -184,8 +186,8 @@
 		return new LogicNodeScanner<Node>(this,dict,nullToken).setFile(newfile);
 	}
 
-	public LogicNodeScanner<Node> pushScannerFile(InputStream newfile) {
-		return new LogicNodeScanner<Node>(this,dict,nullToken).setFile(newfile);
+	public LogicNodeScanner<Node> pushScannerFile(InputStream newfile,String prompt) {
+		return new LogicNodeScanner<Node>(this,dict,nullToken).setFile(newfile,prompt);
 	}
 
 	protected LogicNodeScanner<Node> popScanner() {
@@ -225,6 +227,7 @@
 		this.file = file;
 		cb = CharBuffer.allocate(BufferSize);
 		try {
+			if (prompt!=null) System.out.print(prompt);
 			if (file.read(cb) <= 0) {
 				throw new IOException();
 			}
@@ -280,9 +283,10 @@
 		};
 	}
 
-	private LogicNodeScanner<Node> setFile(InputStream newfile) {
+	private LogicNodeScanner<Node> setFile(InputStream newfile,String prompt) {
 		this.filename = newfile.toString();
 		nextToken = nullToken;
+		this.prompt = prompt;
 		set(new InputStreamReader(newfile));
 		return this;
 	}