Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
/*******************************************************************************
* File: ConfigParser.java
*
* Holds the ConfigParser class, which automatically parses the given
* configuration file.
*
* Copyright (c) 2006, Ira W. Snyder (devel@irasnyder.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
******************************************************************************/
import java.io.*;
import java.lang.String;
import java.util.Vector;
class ConfigParser
{
private BufferedReader input;
private boolean kbd_input = false;
private int RRInterval;
private Vector<Process> Processes = new Vector<Process> ();
public ConfigParser ()
{
input = new BufferedReader (
new InputStreamReader (System.in));
kbd_input = true;
parse ();
}
public ConfigParser (String filename)
{
try
{
input = new BufferedReader (
new InputStreamReader (
new FileInputStream (filename)));
}
catch (java.io.FileNotFoundException e)
{
System.err.println ("Input file: " + filename + " not found!");
System.exit (1);
}
parse ();
}
private void parse ()
{
String s = null;
int ptime;
String pname;
try
{
/* Read the RR Interval */
s = input.readLine ();
this.RRInterval = Integer.parseInt (s);
/* Read each process' values */
pname = input.readLine ();
while (pname != null)
{
ptime = Integer.parseInt (input.readLine ());
Processes.add (new Process (pname, ptime));
/* Read the next Process name */
pname = input.readLine ();
}
}
catch (java.io.IOException e)
{
System.err.println ("Error reading file!");
System.exit (2);
}
}
public Vector<Process> getProcesses ()
{
return this.Processes;
}
public int getRRInterval ()
{
return this.RRInterval;
}
}
/* vim: set ts=4 sts=4 sw=4 expandtab: */