/**********************************************************************
*
* Prolog+CG : Prolog with conceptual graphs
*
* Copyright (C) 2000-2004 Adil Kabbaj
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
*
* Website
* =======
*
* Prolog+CG has a website here:
*
* http://prologpluscg.sourceforge.net/
*
*
* Contact
* =======
*
* Please DO NOT send email to Prof. Kabbaj. Instead, all
* correspondence regarding Prolog+CG should be sent to the current
* maintainter:
*
* Ulrik Petersen <ulrikp{t-a}users{dot}sourceforge{|dot|}net
*
* (Email obfuscated to foil spammers).
*
*
* NO SUPPORT
* ==========
*
* Note that NEITHER Prof. KABBAJ NOR ULRIK PETERSEN WILL GIVE
* SUPPORT! No support is available.
*
* If you need help in using Prolog+CG, please check out the resources
* available at:
*
* http://prologpluscg.sourceforge.net/docs.html
*
* That page points to ample resources for learning Prolog+CG.
*
*
* Bugreports
* ==========
*
* Notwithstanding the lack of support, the maintainer will gladly
* receive bugreports and bugfixes. Please feel free to send such
* bulletins to the address given above.
*
*
*/
package PrologPlusCG.gui;
import java.lang.Thread;
import PrologPlusCG.prolog.CompileException;
import PrologPlusCG.prolog.DataTypes;
import PrologPlusCG.prolog.PPCGEnv;
import PrologPlusCG.prolog.PrologTerm;
public class ReaderThread extends Thread implements DataTypes {
byte readingMode = 1;
private volatile boolean bContinueRunning = true;
private PrologPlusCGFrame prologFrame = null;
private PPCGEnv env = null;
public ReaderThread(byte mode, PPCGEnv myenv, PrologPlusCGFrame prlgFrame) {
readingMode = mode;
prologFrame = prlgFrame;
env = myenv;
env.bInReadingMode = true;
env.aReaderThread = this;
}
public void run() {
bContinueRunning = true;
while (bContinueRunning) {
; // Loop until done...
}
}
public void readSomething() {
if (readingMode == uReadData) {
readData();
} else if (readingMode == uReadSentence) {
readSentence();
}
env.bInReadingMode = false;
env.aReaderThread = null;
bContinueRunning = false;
}
void readData() {
prologFrame.pCurPrologTextArea = prologFrame.consoleArea;
try {
env.compile.CompileTxt = env.io.getNextQuery();
env.compile.textEndIndex = env.compile.CompileTxt.length();
env.compile.curCharIndex = 0;
env.compile.readChar();
env.compile.vctUnitTyp.removeAllElements();
PrologTerm vct = null;
env.compile.tPrologData(false, vct); // cette passe va servir uniquement a lire la donnee et remplir le vecteur vctUnitTyp
// la suite du traitement sera effectuee au sein de l'interpretation de l'operation read()
} catch (CompileException e1) {
if (!e1.getMessage().equals("End Of Text") ||
env.compile.vctUnitTyp.isEmpty()) {
env.io.appendToConsole(
"\n Error in the given data.");
env.compile.vctUnitTyp.removeAllElements();
}
}
env.io.appendToConsole(" \n");
}
void readSentence() {
prologFrame.pCurPrologTextArea = prologFrame.consoleArea;
try {
env.compile.CompileTxt = env.io.getNextQuery();
env.compile.textEndIndex = env.compile.CompileTxt.length();
env.compile.curCharIndex = 0;
env.compile.readChar();
env.compile.vctUnitTyp.removeAllElements();
env.compile.tSentence(); // cette passe va servir uniquement a lire la donnee et remplir le vecteur vctUnitTyp
// la suite du traitement sera effectuee au sein de l'interpretation de l'operation read_sentence()
} catch (CompileException e1) {
if (!e1.getMessage().equals("End Of Text") ||
env.compile.vctUnitTyp.isEmpty()) {
env.io.appendToConsole(
"\n Error in the given data.");
env.compile.vctUnitTyp.removeAllElements();
}
}
env.io.appendToConsole(" \n");
}
}