From af7c6de3c876cab3eb237a0f40796ab0994f1003 Mon Sep 17 00:00:00 2001 From: adam Date: Mon, 9 Feb 2004 22:46:28 +0000 Subject: [PATCH] fixed bug 440 darcs-hash:20040209224628-5007d-58f72a1a89adbb729643f4b2ee9cab1952312e53.gz --- Makefile | 4 ++-- src/org/ibex/Ibex.java | 3 ++- src/org/ibex/Template.java | 19 ++++++++++--------- src/org/ibex/util/Preprocessor.java | 35 ++++++++++++++++++----------------- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index 19f1e40..4e9dc64 100644 --- a/Makefile +++ b/Makefile @@ -260,9 +260,9 @@ dist: compile propose-patch: @darcs push --and-apply --edit-description -o .darcspatch -T patches@xwt.org http://darcs.ibex.org/ibex/ @(echo "To: patches@xwt.org";\ - SUB=`grep -A2 New.patches .darcspatch | tail -n 1 | cut -b 2-`;\ + SUB=`grep -A10000 New.patches .darcspatch | grep '^\\[' | cut -b 2- | tr \\\n , | sed s_,_,\ _g | sed "s_, *\\$$__"`;\ echo "Subject: $$SUB";\ echo;\ - cat .darcspatch) | cat > /tmp/foo #/usr/sbin/sendmail -bm -f $(USER)@xwt.org patches@xwt.org; + cat .darcspatch) | /usr/sbin/sendmail -bm -f $(USER)@xwt.org patches@xwt.org; @rm .darcspatch diff --git a/src/org/ibex/Ibex.java b/src/org/ibex/Ibex.java index ba80775..6a2a58a 100644 --- a/src/org/ibex/Ibex.java +++ b/src/org/ibex/Ibex.java @@ -335,7 +335,7 @@ public final class Ibex extends JS.Cloneable { public JSScope getStatic() { try { // FIXME background? - if (t == null) t = Template.buildTemplate(parentkey + ".ixt", Stream.getInputStream(parent.get(parentkey + ".ixt")), ibex); + if (t == null) t = Template.buildTemplate(parentkey + ".t", Stream.getInputStream(parent.get(parentkey + ".t")), ibex); return t.staticScope; } catch (Exception e) { Log.error(this, e); @@ -347,6 +347,7 @@ public final class Ibex extends JS.Cloneable { if (nargs == 9999) return t; if (nargs != 1) throw new JSExn("FIXME can only call with one arg"); getStatic(); + if (t == null) throw new JSExn("No such template " + parentkey); t.apply((Box)a); return a; } diff --git a/src/org/ibex/Template.java b/src/org/ibex/Template.java index ec47e7c..aa190b3 100644 --- a/src/org/ibex/Template.java +++ b/src/org/ibex/Template.java @@ -32,7 +32,7 @@ public class Template { private Vec children = new Vec(); ///< during XML parsing, this holds the list of currently-parsed children; null otherwise private JS script = null; ///< the script on this node Template prev; - JSScope staticScope = null; ///< the scope in which the static block is executed + JSScope staticScope = null; ///< the scope in which the static block is executed // Only used during parsing ///////////////////////////////////////////////////////////////// @@ -138,7 +138,7 @@ public class Template { String sourceName; private int state = STATE_INITIAL; private static final int STATE_INITIAL = 0; - private static final int STATE_IN_Ibex_NODE = 1; + private static final int STATE_IN_ROOT_NODE = 1; private static final int STATE_IN_TEMPLATE_NODE = 2; private static final int STATE_IN_META_NODE = 3; @@ -173,9 +173,9 @@ public class Template { throw new XML.Exn("root element was not ", XML.Exn.SCHEMA, getLine(), getCol()); if (c.getAttrLen() != 0) throw new XML.Exn("root element must not have attributes", XML.Exn.SCHEMA, getLine(), getCol()); - state = STATE_IN_Ibex_NODE; + state = STATE_IN_ROOT_NODE; return; - case STATE_IN_Ibex_NODE: + case STATE_IN_ROOT_NODE: if ("meta".equals(c.getPrefix())) { state = STATE_IN_META_NODE; meta = 0; return; } state = STATE_IN_TEMPLATE_NODE; t = (t == null) ? new Template(ibex) : new Template(t, getLine()); @@ -186,11 +186,12 @@ public class Template { break; } - if (!("ui".equals(c.getPrefix()) && "box".equals(c.getLocalName()))) { + if (!(/* "ui".equals(c.getPrefix()) && */ "box".equals(c.getLocalName()))) { String tagname = (c.getUri().equals("") ? "" : (c.getUri() + ".")) + c.getLocalName(); // GROSS hack try { t.prev = (Template)t.ibex.resolveString(tagname, false).call(null, null, null, null, 9999); + if (t.prev == null) throw new JSExn("template " + tagname + " not found"); } catch (Exception e) { Log.error(Template.class, e); } @@ -267,11 +268,11 @@ public class Template { public void endElement(XML.Element c) throws XML.Exn, IOException { switch(state) { - case STATE_IN_META_NODE: if (meta-- < 0) state = STATE_IN_Ibex_NODE; return; - case STATE_IN_Ibex_NODE: return; + case STATE_IN_META_NODE: if (meta-- < 0) state = STATE_IN_ROOT_NODE; return; + case STATE_IN_ROOT_NODE: return; case STATE_IN_TEMPLATE_NODE: { if (t.content != null) { t.script = parseScript(t.content, t.content_start); t.content = null; } - if (nodeStack.size() == 0) { state = STATE_IN_Ibex_NODE; return; } + if (nodeStack.size() == 0) { state = STATE_IN_ROOT_NODE; return; } Template oldt = t; t = (Template)nodeStack.lastElement(); nodeStack.setSize(nodeStack.size() - 1); @@ -293,7 +294,7 @@ public class Template { } t.content.append(ch, start, length); return; - case STATE_IN_Ibex_NODE: + case STATE_IN_ROOT_NODE: if (static_content == null) { static_content_start = getLine(); static_content = new StringBuffer(); diff --git a/src/org/ibex/util/Preprocessor.java b/src/org/ibex/util/Preprocessor.java index 0b6e1ef..54c2b1c 100644 --- a/src/org/ibex/util/Preprocessor.java +++ b/src/org/ibex/util/Preprocessor.java @@ -56,6 +56,7 @@ public class Preprocessor { private int enumSwitch = 0; // number appended to variable used in switch implementation + public Preprocessor(Reader reader, Writer writer) { setReader(reader); setWriter(writer); @@ -121,7 +122,7 @@ PROCESS: String val = trimmed.substring(keyEnd).trim(); replace.put(key, val); } - out.println(); // preserve line numbers + out.print("\n"); // preserve line numbers } else if (trimmed.startsWith("//#repeat ")) { trimmed = trimmed.substring(9); @@ -129,7 +130,7 @@ PROCESS: String s2 = in.readLine().trim(); if (s2.startsWith("//")) s2 = s2.substring(2).trim(); trimmed = trimmed.substring(0, trimmed.length() - 1) + " " + s2; - out.println(); // preserve line numbers + out.print("\n"); // preserve line numbers } StringTokenizer st = new StringTokenizer(trimmed, " "); repeatreplace = (Hashtable)replace.clone(); @@ -140,13 +141,13 @@ PROCESS: repeatreplace.put(key, val); } sinceLastRepeat = new Vector(); - out.println(); // preserve line numbers + out.print("\n"); // preserve line numbers } else if (trimmed.startsWith("//#end")) { if (sinceLastRepeat == null) { err.add(new Warning("#end orphaned")); continue PROCESS; } Hashtable save = replace; replace = repeatreplace; - out.println(); + out.print("\n"); for(int i=0; i