main.cpp
Go to the documentation of this file.
/* Frobby: Software for monomial ideal computations.
Copyright (C) 2007 Bjarke Hammersholt Roune (www.broune.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
*/
#include "stdinc.h"
#include "main.h"
#include "Action.h"
#include "DebugAllocator.h"
#include "error.h"
#include "display.h"
#include <ctime>
#include <cstdlib>
#include <exception>
#include <sys/types.h>
#include <unistd.h>
int frobbyMain(int argc, const char** argv) {
string prefix;
if (argc > 1) {
prefix = argv[1];
--argc;
++argv;
} else
prefix = "help";
const unique_ptr<Action> action(Action::createActionWithPrefix(prefix));
action->parseCommandLine(argc - 1, argv + 1);
action->perform();
return ExitCodeSuccess;
}
void frobbyTerminate() {
fputs("INTERNAL ERROR: Something caused terminate() to be called. "
"This should never happen.\nPlease contact the Frobby developers.\n",
stderr);
fflush(stderr);
ASSERT(false);
abort();
}
int main(int argc, const char** argv) {
try {
std::set_terminate(frobbyTerminate);
srand((unsigned int)time(0) +
#ifdef __GNUC__ // Only GCC defines this macro.
(unsigned int)getpid() +
#endif
(unsigned int)clock());
#ifdef PROFILE
fputs("This is a PROFILE build of Frobby. It is therefore SLOW.\n",
stderr);
#endif
#ifdef DEBUG
fputs("This is a DEBUG build of Frobby. It is therefore SLOW.\n",
stderr);
#endif
#ifdef DEBUG
return DebugAllocator::getSingleton().runDebugMain(argc, argv);
#else
return frobbyMain(argc, argv);
#endif
} catch (const bad_alloc&) {
displayError("Ran out of memory.");
return ExitCodeOutOfMemory;
} catch (const InternalFrobbyException& e) {
displayException(e);
return ExitCodeInternalError;
} catch (const FrobbyException& e) {
displayException(e);
return ExitCodeError;
} catch (...) {
try {
throw;
} catch (const exception& e) {
try {
displayError(e.what());
} catch (...) {
}
} catch (...) {
}
return ExitCodeUnknownError;
}
}
Action.h
DebugAllocator.h
Action::createActionWithPrefix
static unique_ptr< Action > createActionWithPrefix(const string &prefix)
Definition Action.cpp:109
FrobbyException
This is the base of the Frobby exception hierarchy for exceptions that can occur due to expected erro...
Definition error.h:27
InternalFrobbyException
This exception signals that a bug in Frobby has been detected.
Definition error.h:33
displayError
void displayError(const string &msg)
Display msg to standard error in a way that indicates that it is an error.
Definition display.cpp:139
displayException
void displayException(const std::exception &exception)
Display the message of exception.
Definition display.cpp:147
display.h
This file contains functions for printing strings to standard error.
error.h
frobbyTerminate
void frobbyTerminate()
A replacement for the default C++ built-in terminate() function.
Definition main.cpp:54
frobbyMain
int frobbyMain(int argc, const char **argv)
This function runs the Frobby console interface.
Definition main.cpp:35
main.h
ExitCodeInternalError
static const int ExitCodeInternalError
Definition main.h:40
ExitCodeUnknownError
static const int ExitCodeUnknownError
Definition main.h:46
ExitCodeOutOfMemory
static const int ExitCodeOutOfMemory
Definition main.h:43
ExitCodeSuccess
static const int ExitCodeSuccess
Definition main.h:33
ExitCodeError
static const int ExitCodeError
Definition main.h:36
stdinc.h
This header file includes common definitions and is included as the first line of code in every imple...
ASSERT
#define ASSERT(X)
Definition stdinc.h:86
main
int main()
Definition testmain.cpp:45