gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
initest.cc
Go to the documentation of this file.
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 <fstream>
33 #include <iostream>
34 #include <string>
35 #include <vector>
36 
37 #include "base/cprintf.hh"
38 #include "base/inifile.hh"
39 
40 using namespace std;
41 
42 char *progname;
43 
44 void usage();
45 
46 void
48 {
49  cout << "Usage: " << progname << " <ini file>\n";
50  exit(1);
51 }
52 
53 #if 0
54 char *defines = getenv("CONFIG_DEFINES");
55 if (defines) {
56  char *c = defines;
57  while ((c = strchr(c, ' ')) != NULL) {
58  *c++ = '\0';
59  count++;
60  }
61  count++;
62 }
63 
64 #endif
65 
66 int
67 main(int argc, char *argv[])
68 {
69  IniFile simConfigDB;
70 
71  progname = argv[0];
72 
73  for (int i = 1; i < argc; ++i) {
74  char *arg_str = argv[i];
75 
76  // if arg starts with '-', parse as option,
77  // else treat it as a configuration file name and load it
78  if (arg_str[0] == '-') {
79  // switch on second char
80  switch (arg_str[1]) {
81  case '-':
82  // command-line configuration parameter:
83  // '--<section>:<parameter>=<value>'
84 
85  if (!simConfigDB.add(arg_str + 2)) {
86  // parse error
87  ccprintf(cerr,
88  "Could not parse configuration argument '%s'\n"
89  "Expecting --<section>:<parameter>=<value>\n",
90  arg_str);
91  exit(0);
92  }
93  break;
94 
95  default:
96  usage();
97  }
98  }
99  else {
100  // no '-', treat as config file name
101 
102  if (!simConfigDB.load(arg_str)) {
103  cprintf("Error processing file %s\n", arg_str);
104  exit(1);
105  }
106  }
107  }
108 
109  string value;
110 
111 #define FIND(C, E) \
112  if (simConfigDB.find(C, E, value)) \
113  cout << ">" << value << "<\n"; \
114  else \
115  cout << "Not Found!\n"
116 
117  FIND("General", "Test2");
118  FIND("Junk", "Test3");
119  FIND("Junk", "Test4");
120  FIND("General", "Test1");
121  FIND("Junk2", "test3");
122  FIND("General", "Test3");
123 
124  cout << "\n";
125 
126  simConfigDB.dump();
127 
128  return 0;
129 }
count
Definition: misc.hh:704
void ccprintf(cp::Print &print)
Definition: cprintf.hh:130
Bitfield< 7 > i
Definition: miscregs.hh:1378
Bitfield< 3 > exit
Definition: misc.hh:849
char * progname
Definition: initest.cc:42
void usage()
Definition: initest.cc:47
bool add(const std::string &s)
Take string of the form "<section>:<parameter>=<value>" or "<section>:<parameter>+=<value>" and add t...
Definition: inifile.cc:164
#define FIND(C, E)
bool load(std::istream &f)
Load parameter settings from given istream.
Declaration of IniFile object.
Bitfield< 29 > c
Definition: miscregs.hh:1365
void dump()
Dump contents to cout. For debugging.
Definition: inifile.cc:344
int main(int argc, char *argv[])
Definition: initest.cc:67
This class represents the contents of a ".ini" file.
Definition: inifile.hh:54
void cprintf(const char *format, const Args &...args)
Definition: cprintf.hh:155

Generated on Fri Jun 9 2017 13:03:52 for gem5 by doxygen 1.8.6