Frobby 0.9.7
main.cpp
Go to the documentation of this file.
1/* Frobby: Software for monomial ideal computations.
2 Copyright (C) 2007 Bjarke Hammersholt Roune (www.broune.com)
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see http://www.gnu.org/licenses/.
16*/
17#include "stdinc.h"
18#include "main.h"
19
20#include "Action.h"
21#include "DebugAllocator.h"
22#include "error.h"
23#include "display.h"
24
25#include <ctime>
26#include <cstdlib>
27#include <exception>
28#include <sys/types.h>
29#include <unistd.h>
30
35int frobbyMain(int argc, const char** argv) {
36 string prefix;
37 if (argc > 1) {
38 prefix = argv[1];
39 --argc;
40 ++argv;
41 } else
42 prefix = "help";
43
44 const unique_ptr<Action> action(Action::createActionWithPrefix(prefix));
45 action->parseCommandLine(argc - 1, argv + 1);
46 action->perform();
47
48 return ExitCodeSuccess;
49}
50
55 fputs("INTERNAL ERROR: Something caused terminate() to be called. "
56 "This should never happen.\nPlease contact the Frobby developers.\n",
57 stderr);
58 fflush(stderr);
59 ASSERT(false);
60 abort();
61}
62
67int main(int argc, const char** argv) {
68 try {
69 std::set_terminate(frobbyTerminate);
70
71 srand((unsigned int)time(0) +
72#ifdef __GNUC__ // Only GCC defines this macro.
73 (unsigned int)getpid() +
74#endif
75 (unsigned int)clock());
76
77#ifdef PROFILE
78 fputs("This is a PROFILE build of Frobby. It is therefore SLOW.\n",
79 stderr);
80#endif
81#ifdef DEBUG
82 fputs("This is a DEBUG build of Frobby. It is therefore SLOW.\n",
83 stderr);
84#endif
85
86#ifdef DEBUG
87 return DebugAllocator::getSingleton().runDebugMain(argc, argv);
88#else
89 return frobbyMain(argc, argv);
90#endif
91 } catch (const bad_alloc&) {
92 displayError("Ran out of memory.");
94 } catch (const InternalFrobbyException& e) {
97 } catch (const FrobbyException& e) {
99 return ExitCodeError;
100 } catch (...) {
101 try {
102 throw;
103 } catch (const exception& e) {
104 try {
105 displayError(e.what());
106 } catch (...) {
107 }
108 } catch (...) {
109 }
111 }
112}
static unique_ptr< Action > createActionWithPrefix(const string &prefix)
Definition Action.cpp:109
This is the base of the Frobby exception hierarchy for exceptions that can occur due to expected erro...
Definition error.h:27
This exception signals that a bug in Frobby has been detected.
Definition error.h:33
void displayError(const string &msg)
Display msg to standard error in a way that indicates that it is an error.
Definition display.cpp:139
void displayException(const std::exception &exception)
Display the message of exception.
Definition display.cpp:147
This file contains functions for printing strings to standard error.
void frobbyTerminate()
A replacement for the default C++ built-in terminate() function.
Definition main.cpp:54
int frobbyMain(int argc, const char **argv)
This function runs the Frobby console interface.
Definition main.cpp:35
static const int ExitCodeInternalError
Definition main.h:40
static const int ExitCodeUnknownError
Definition main.h:46
static const int ExitCodeOutOfMemory
Definition main.h:43
static const int ExitCodeSuccess
Definition main.h:33
static const int ExitCodeError
Definition main.h:36
This header file includes common definitions and is included as the first line of code in every imple...
#define ASSERT(X)
Definition stdinc.h:86
int main()
Definition testmain.cpp:45