import java.util.Vector;
import java.io.*;

class Configuration {
	private Runtime runtime;
	private Process process;
	private String [] argv;
	private InputStream in;
	private String buffer;
	private Vector nodes;
	private String probe_list;

	String get_probe_list(String buffer) {
		int to, from;
		String ret = null;
		if ((from = buffer.indexOf("'")) >= 0) {
			from++;
			if ((to = buffer.indexOf("'", from)) >= 0)
				ret = buffer.substring(from, to);
		}
		System.out.println(ret);
		return ret;
	}
	
	Configuration() {
		runtime = Runtime.getRuntime();
		nodes = new Vector();	
		argv = new String[3];

		argv[0] = new String("/usr/sbin/prtconf");
		argv[1] = new String("-vp");

//	Run the system command prtconf.
//	This gives information about the system config,
//	including the types of frame buffers that are installed.

//	Returns a "process" from which we can get its output (our input)

		try {
			process = runtime.exec(argv);
			in = process.getInputStream();
		} catch (IOException e) {
			System.err.println("Oh, bugger. prtconf won't play\n");
            System.err.println(e);
            System.exit(1); 
		}

//	Loop around looking for Nodes. These end with a blank line.
//	We are interested only in those that contain the word 'display'

		try {
			int c;
			int prev = 0;

			while ((c = in.read()) != -1) {
				if (c == '\n' && c == prev) {	
					int probe = 0;
//					if ((probe = buffer.indexOf("sbus-probe-list:")) > -1) {
//						probe_list = get_probe_list(buffer.substring(probe));
//					} else {
						if (buffer.indexOf("'display'") > -1) {
							nodes.addElement(new Node(buffer));
						}
//					}

//	Old buffer is freed by the bin man if not needed
					buffer = new String("");
					prev = 0;
				} else {
					buffer = buffer + (char) c;
					prev = c;
				}
			}
        } catch (IOException e) {
            System.err.println("Oh, bugger. Trouble finding a node.\n");
			System.out.println("Error:" + e.getMessage());
			System.out.println(buffer.length());
        }
	}

	int fbcount() {
		return (nodes.size());
	}

	Node node(int i) {
		return((Node) nodes.elementAt(i));
	}
}

