From cb920a78a1ee3eeaf6d45c0c29aa74714b2d9319 Mon Sep 17 00:00:00 2001 From: jestin Date: Wed, 10 Oct 2001 15:36:44 +0000 Subject: Bugfix related to the "a(.*) (.*)' regexp causing the loss of front empty messages. --- src/Ivy.java | 29 +++++++++++++++++++++++------ src/IvyClient.java | 22 ++++++++++++++-------- src/Makefile | 6 +++--- src/Probe.java | 16 ++++++++++------ 4 files changed, 50 insertions(+), 23 deletions(-) diff --git a/src/Ivy.java b/src/Ivy.java index f7511ba..ad8a4e6 100755 --- a/src/Ivy.java +++ b/src/Ivy.java @@ -12,7 +12,6 @@ import java.net.*; import java.io.*; import java.util.Vector; import java.util.Hashtable; -import java.util.StringTokenizer; /** * A class connecting to the Ivy software bus. @@ -260,11 +259,29 @@ public class Ivy implements Runnable, IvyApplicationListener { if (callback==null){ throw new IvyException("(callCallback) Not regexp matching id "+key.intValue()); } - StringTokenizer st = new StringTokenizer(msgarg,IvyClient.EndArg); - String args[] = new String[st.countTokens()]; - int i=0; - while (st.hasMoreTokens()){ args[i++] = st.nextToken();} - callback.receive( client, args ); + String[] tab= myTokenize(msgarg,IvyClient.EndArg); + System.out.println("received " + tab.length + " args"); + callback.receive( client, tab); + } + + private static String[] myTokenize(String s,String separator) { + int index=0, last=0, length=s.length(); + Vector v = new Vector(); + if (length!=0) while (true) { + index=s.indexOf(separator,last); + if (index==-1) { + v.add(s.substring(last,length)); + break; + } else if (index> matching "+regexp.getNumSubs()+" blocks "+tmp); send(Msg,key,regexp.getNumSubs(),result); count++; } @@ -160,14 +164,8 @@ public class IvyClient extends Thread { break; } if(!st.hasMoreTokens()){close("Bad format no id '"+msg+"'");break;} - /* IST */ token=st.nextToken(StartArg).trim(); - /* - * TODO - * this doesn't work on jdk1.3 !!! - * the token equals " 3992", which provoques a NumberFormatException - */ try { msgid=Integer.valueOf(token); } catch ( NumberFormatException e ) { @@ -175,13 +173,20 @@ public class IvyClient extends Thread { break; } String msgarg=""; - if (st.hasMoreTokens()) msgarg=st.nextToken("\n").trim(); + // if (st.hasMoreTokens()) msgarg=st.nextToken("\n").trim(); + if (st.hasMoreTokens()) msgarg=st.nextToken("\n"); + // TODO: here is a bug ! + // quick and dirty fix: I do the trimming by hand later on. + // (cf ref: This method may be used to trim whitespace from the + // beginning and end of a string; in fact, it trims all ASCII control characters as well. + /* * second stage: process the message */ switch (msgtype) { case Bye: break; case AddRegexp: + msgarg.trim(); if ( bus.CheckRegexp(msgarg) ) { try { regexp_in.put(msgid,new RE(msgarg)); @@ -208,7 +213,7 @@ public class IvyClient extends Thread { break; case Msg: try { - bus.callCallback(this,msgid,msgarg); + bus.callCallback(this,msgid,msgarg.substring(1,msgarg.length()-1)); } catch (IvyException ie) { // calling an inexistant callback System.err.println("calling an inexistant callback, the caller must be wrong !"); @@ -226,6 +231,7 @@ public class IvyClient extends Thread { } break; case DirectMsg: + msgarg.trim(); bus.directMessage( this, msgid.intValue(), msgarg ); break; case Die: diff --git a/src/Makefile b/src/Makefile index f37bae6..18beb1c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,7 +3,7 @@ JAVACOPTS = -d . -deprecation $(CLASSPATH) SRCS = *.java JAR = ../lib/Ivy.jar - VER = 1.0.5 + VER = 1.0.7 DIST = ../lib/ivy-java-$(VER).jar JAVAC = jikes # JAVAC = javac @@ -20,11 +20,11 @@ clean: ctags $(SRCS) jar: - fastjar cvfm $(JAR) manifest fr + fastjar cvfm $(JAR) ../manifest fr dist: cd .. - fastjar cvfm $(DIST) manifest fr src debian redhat doc Makefile manifest TODO + fastjar cvfm $(DIST) ../manifest fr src debian redhat doc Makefile manifest TODO docs: rm -fR $(DOCS)/* diff --git a/src/Probe.java b/src/Probe.java index 84e282f..6e4543b 100644 --- a/src/Probe.java +++ b/src/Probe.java @@ -12,11 +12,11 @@ import java.io.*; */ class Probe implements IvyApplicationListener, IvyMessageListener { - public static void main(String[] args) { + public static void main(String[] args) throws IvyException { Probe p = new Probe(); Getopt opt = new Getopt("Probe",args,"b:d"); int c; - String domain=Ivy.DEFAULT_DOMAIN; + String domain=Ivy.getDomain(null); while ((c = opt.getopt()) != -1) switch (c) { case 'b': domain=opt.getOptarg(); @@ -37,11 +37,10 @@ class Probe implements IvyApplicationListener, IvyMessageListener { System.out.println("broadcasting on "+domain); bus.start(domain); String s; - BufferedReader in = - new BufferedReader(new InputStreamReader(System.in)); + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); // infinite loop on keyboard input try { - while ((s=in.readLine()).length()!=0) + while (p.looping() && (s=in.readLine()).length()!=0) System.out.println("-> Sent to " +bus.sendMsg(s)+" peers"); } catch (NullPointerException e) { bus.stop(); @@ -53,6 +52,10 @@ class Probe implements IvyApplicationListener, IvyMessageListener { } } + private boolean looping=true; + + public boolean looping() { return looping ; } // accessor + public void connect(IvyClient client) { System.out.println(client.getApplicationName() + " connected " ); for (java.util.Enumeration e=client.getRegexps();e.hasMoreElements();) @@ -65,7 +68,8 @@ class Probe implements IvyApplicationListener, IvyMessageListener { } public void die(IvyClient client, int id) { - System.out.println(client.getApplicationName() + " die "+ id ); + looping=false; + System.out.println(client.getApplicationName() + " received die msg from "+ id ); } public void directMessage(IvyClient client, int id, String arg) { -- cgit v1.1