types: clean up types, especially signed vs unsigned
[gem5.git] / src / unittest / initest.cc
1 /*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Nathan Binkert
29 * Steve Reinhardt
30 */
31
32 #include <iostream>
33 #include <fstream>
34 #include <string>
35 #include <vector>
36
37 #include "base/inifile.hh"
38 #include "base/cprintf.hh"
39
40 using namespace std;
41
42 char *progname;
43
44 void
45 usage()
46 {
47 cout << "Usage: " << progname << " <ini file>\n";
48 exit(1);
49 }
50
51 #if 0
52 char *defines = getenv("CONFIG_DEFINES");
53 if (defines) {
54 char *c = defines;
55 while ((c = strchr(c, ' ')) != NULL) {
56 *c++ = '\0';
57 count++;
58 }
59 count++;
60 }
61
62 #endif
63
64 int
65 main(int argc, char *argv[])
66 {
67 IniFile simConfigDB;
68
69 progname = argv[0];
70
71 for (int i = 1; i < argc; ++i) {
72 char *arg_str = argv[i];
73
74 // if arg starts with '-', parse as option,
75 // else treat it as a configuration file name and load it
76 if (arg_str[0] == '-') {
77 // switch on second char
78 switch (arg_str[1]) {
79 case '-':
80 // command-line configuration parameter:
81 // '--<section>:<parameter>=<value>'
82
83 if (!simConfigDB.add(arg_str + 2)) {
84 // parse error
85 ccprintf(cerr,
86 "Could not parse configuration argument '%s'\n"
87 "Expecting --<section>:<parameter>=<value>\n",
88 arg_str);
89 exit(0);
90 }
91 break;
92
93 default:
94 usage();
95 }
96 }
97 else {
98 // no '-', treat as config file name
99
100 if (!simConfigDB.load(arg_str)) {
101 cprintf("Error processing file %s\n", arg_str);
102 exit(1);
103 }
104 }
105 }
106
107 string value;
108
109 #define FIND(C, E) \
110 if (simConfigDB.find(C, E, value)) \
111 cout << ">" << value << "<\n"; \
112 else \
113 cout << "Not Found!\n"
114
115 FIND("General", "Test2");
116 FIND("Junk", "Test3");
117 FIND("Junk", "Test4");
118 FIND("General", "Test1");
119 FIND("Junk2", "test3");
120 FIND("General", "Test3");
121
122 cout << "\n";
123
124 simConfigDB.dump();
125
126 return 0;
127 }