OpenASIP  2.0
CreateHDB.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file CreateHDB.cc
26  *
27  * The command line tool that creates a new HDB.
28  *
29  * @author Pekka Jääskeläinen 2005 (pjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include "Application.hh"
35 #include "HDBManager.hh"
36 #include "Exception.hh"
37 #include "FileSystem.hh"
38 
39 /**
40  * Main function.
41  *
42  * Parses the command line and creates a new HDB.
43  *
44  * @param argc The command line argument count.
45  * @param argv The command line arguments (passed to the interpreter).
46  * @return The return status.
47  */
48 int
49 main(int argc, char* argv[]) {
50 
52 
54  try {
55  options.parse(argv, argc);
56  } catch (ParserStopRequest) {
57  return EXIT_SUCCESS;
58  } catch (const IllegalCommandLine& i) {
59  std::cerr << i.errorMessage() << std::endl;
60  return EXIT_FAILURE;
61  }
62 
63  if (options.numberOfArguments() != 1) {
64  std::cerr << "Illegal number of arguments." << std::endl;
65  return EXIT_FAILURE;
66  }
67 
68  const std::string fileName = options.argument(1);
69 
70  if (FileSystem::fileExists(fileName)) {
71  std::cerr << "File already exists." << std::endl;
72  return EXIT_SUCCESS;
73  }
74 
75  try {
77  } catch (const Exception& e) {
78  std::cerr << "Error while creating HDB. "
79  << e.errorMessage() << std::endl;
80  return EXIT_FAILURE;
81  }
82 
83  return EXIT_SUCCESS;
84 }
FileSystem.hh
ParserStopRequest
Definition: Exception.hh:491
Exception.hh
CmdLineParser::numberOfArguments
virtual int numberOfArguments() const
main
int main(int argc, char *argv[])
Definition: CreateHDB.cc:49
IllegalCommandLine
Definition: Exception.hh:438
Application.hh
HDB::HDBManager::createNew
static void createNew(const std::string &file)
Definition: HDBManager.cc:548
Exception
Definition: Exception.hh:54
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
CmdLineOptions::parse
void parse(char *argv[], int argc)
Definition: CmdLineOptions.cc:107
options
static MachInfoCmdLineOptions options
Definition: MachInfo.cc:46
CreateHDBCmdLineOptions
Definition: CreateHDBCmdLineOptions.hh:43
CreateHDBCmdLineOptions.hh
FileSystem::fileExists
static bool fileExists(const std::string fileName)
Application::initialize
static void initialize()
Definition: Application.cc:99
HDBManager.hh
CmdLineParser::argument
virtual std::string argument(int index) const