package no.uio.ifi.alboc.chargenerator;

/*
 * module CharGenerator
 */

import java.io.*;

import no.uio.ifi.alboc.alboc.AlboC;
import no.uio.ifi.alboc.error.Error;
import no.uio.ifi.alboc.log.Log;

/*
 * Module for reading single characters.
 */
public class CharGenerator {
	public static char curC, nextC;

	private static LineNumberReader sourceFile = null;
	private static String sourceLine;
	private static int sourcePos;
	private static int sourceLength;

	public static void init() {
		try {
			sourceFile = new LineNumberReader(new FileReader(AlboC.sourceName));
		} catch (FileNotFoundException e) {
			Error.error("Cannot read " + AlboC.sourceName + "!");
		}
		sourceLine = "";
		sourcePos = 0;
		curC = nextC = ' ';
		readNext();
		readNext();
	}

	public static void finish() {
		if (sourceFile != null) {
			try {
				sourceFile.close();
			} catch (IOException e) {
				Error.error("Could not close source file!");
			}
		}
	}

	public static boolean isMoreToRead() {

		return false;
	}

	public static int curLineNum() {
		return (sourceFile == null ? 0 : sourceFile.getLineNumber());
	}

	public static void readNext() {
		curC = nextC;
		
		if (!isMoreToRead())
			return;
		try {
			if (sourcePos == sourceLine.length()){
				nextC = sourceLine.charAt(sourcePos);
				sourcePos++;
				sourceLine = sourceFile.readLine();
				if(sourceLine.charAt(0) == '#')
					sourceLine = sourceFile.readLine();
				sourcePos = 0;
				
			}
			nextC = sourceLine.charAt(sourcePos);
			sourcePos++;
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
		
		
	}
}

@@ -978,17 +978,42 @@
 ead() %7B%0A
-%0A
+%09%09if(sourceLine == null)%0A%09
 %09%09return
@@ -1020,16 +1020,31 @@
  false;%0A
+%09%09return true;%0A
 %09%7D%0A%0A%09pub
@@ -1252,18 +1252,17 @@
 urcePos 
-==
+%3E
  sourceL
@@ -1273,16 +1273,18 @@
 length()
+-1
 )%7B%0A%09%09%09%09n
@@ -1373,24 +1373,64 @@
 readLine();%0A
+%09%09%09%09if(sourceLine == null)%0A%09%09%09%09%09return;%0A
 %09%09%09%09if(sourc
@@ -1634,24 +1634,12 @@
 ();%0A
+
 %09%09%7D%0A
-%09%09%0A%09%09%0A%09%09%0A%09%09%0A
 %09%7D%0A%7D

fixd charGenerator. isMoreToRead and ReadNext should work