- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

main.cpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 Graeme Walker <graeme_walker@users.sourceforge.net>
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 3 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 //
18 // main.cpp
19 //
20
21 #include "gdef.h"
22 #include "gsmtp.h"
23 #include "gstr.h"
24 #include "garg.h"
25 #include "run.h"
26 #include "commandline.h"
27 #include <exception>
28 #include <cstdlib>
29
35 struct App : public Main::Output
36 {
37 void output( const std::string & text , bool e )
38 {
39 std::ostream & s = e ? std::cerr : std::cout ;
40 s << text << std::flush ;
41 }
42 } ;
43
44 int main( int argc , char * argv [] )
45 {
46 bool ok = false ;
47 try
48 {
49 G::Arg arg( argc , argv ) ;
50 App app ;
51 Main::Run main( app , arg , Main::CommandLine::switchSpec(false) ) ;
52 if( main.prepare() )
53 {
54 main.run() ;
55 }
56 ok = ! main.prepareError() ;
57 }
58 catch( std::exception & e )
59 {
60 std::cerr << G::Arg::prefix(argv) << ": exception: " << e.what() << std::endl ;
61 }
62 catch(...)
63 {
64 std::cerr << G::Arg::prefix(argv) << ": unrecognised exception" << std::endl ;
65 }
66 return ok ? EXIT_SUCCESS : EXIT_FAILURE ;
67 }
68
Main::Run::prepare
bool prepare()
Prepares to run() typically by parsing the commandline.
Definition: run.cpp:150
Main::Run::run
void run()
Runs the application.
Definition: run.cpp:247
G::Arg::prefix
std::string prefix() const
Returns the basename of v(0) without any extension.
Definition: garg.cpp:142
Main::Output
An abstract interface for generating output on a command-line or a GUI.
Definition: output.h:38
garg.h
gstr.h
run.h
commandline.h
Main::Run::prepareError
bool prepareError() const
Returns true if prepare() failed.
Definition: run.cpp:114
Main::Run
A top-level class for the process.
Definition: run.h:71
App::output
void output(const std::string &text, bool e)
Outputs the given string.
Definition: main.cpp:37
App
An implementation of the Main::Output abstract interface for command-line output. ...
Definition: main.cpp:35
G::Arg
A class which holds a represention of the argc/argv command line array, and supports simple command-l...
Definition: garg.h:46
gsmtp.h
main
int main(int argc, char *argv[])
Definition: main.cpp:44
Main::CommandLine::switchSpec
static std::string switchSpec(bool is_windows)
Returns an o/s-specific G::GetOpt switch specification string.
Definition: commandline_full.cpp:604