Subversion Repositories programming

Rev

Rev 415 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
412 ira 1
/*******************************************************************************
2
 * File: ConfigParser.java
3
 *
4
 * Holds the ConfigParser class, which automatically parses the given
5
 * configuration file.
6
 *
7
 * Copyright (c) 2006, Ira W. Snyder (devel@irasnyder.com)
8
 *
9
 * Permission is hereby granted, free of charge, to any person obtaining a copy
10
 * of this software and associated documentation files (the "Software"), to deal
11
 * in the Software without restriction, including without limitation the rights
12
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
 * copies of the Software, and to permit persons to whom the Software is
14
 * furnished to do so, subject to the following conditions:
15
 *
16
 * The above copyright notice and this permission notice shall be included in
17
 * all copies or substantial portions of the Software.
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25
 * IN THE SOFTWARE.
26
 ******************************************************************************/
27
 
28
import java.io.*;
29
import java.lang.String;
30
import java.util.Vector;
31
 
32
class ConfigParser
33
{
34
    private BufferedReader input;
35
    private boolean kbd_input = false;
36
    private int RRInterval;
37
    private Vector<Process> Processes = new Vector<Process> ();
38
 
39
    public ConfigParser ()
40
    {
41
        input = new BufferedReader (
42
                    new InputStreamReader (System.in));
43
        kbd_input = true;
44
 
45
        parse ();
46
    }
47
 
48
    public ConfigParser (String filename)
49
    {
50
        try
51
        {
52
            input = new BufferedReader (
53
                        new InputStreamReader (
54
                            new FileInputStream (filename)));
55
        }
56
        catch (java.io.FileNotFoundException e)
57
        {
58
            System.err.println ("Input file: " + filename + " not found!");
59
            System.exit (1);
60
        }
61
 
62
        parse ();
63
    }
64
 
65
    private void parse ()
66
    {
67
        String s = null;
68
        int ptime;
69
        String pname;
70
 
71
        try
72
        {
73
            /* Read the RR Interval */
74
            s = input.readLine ();
75
            this.RRInterval = Integer.parseInt (s);
76
 
77
            /* Read each process' values */
78
            pname = input.readLine ();
79
            while (pname != null)
80
            {
81
                ptime = Integer.parseInt (input.readLine ());
82
                Processes.add (new Process (pname, ptime));
83
 
84
                /* Read the next Process name */
85
                pname = input.readLine ();
86
            }
87
        }
88
        catch (java.io.IOException e)
89
        {
90
            System.err.println ("Error reading file!");
91
            System.exit (2);
92
        }
93
    }
94
 
95
    public Vector<Process> getProcesses ()
96
    {
97
        return this.Processes;
98
    }
99
 
100
    public int getRRInterval ()
101
    {
102
        return this.RRInterval;
103
    }
104
}
105
 
106
/* vim: set ts=4 sts=4 sw=4 expandtab: */
107