1 // Copyright 2009 The Archiveopteryx Developers <info@aox.org> 2 3 #include "scope.h" 4 #include "estring.h" 5 #include "allocator.h" 6 #include "estringlist.h" 7 #include "configuration.h" 8 #include "stderrlogger.h" 9 #include "aoxcommand.h" 10 #include "eventloop.h" 11 #include "database.h" 12 #include "logger.h" 13 #include "log.h" 14 15 #include <stdio.h> 16 #include <stdlib.h> 17 18 19 /*! \nodoc */ 20 21 main(int ac,char * av[])22int main( int ac, char *av[] ) 23 { 24 Scope global; 25 26 av++; 27 ac--; 28 29 uint verbosity = 0; 30 31 int i = 0; 32 while ( i < ac ) { 33 if ( EString( av[i] ) == "-v" ) 34 verbosity++; 35 else 36 break; 37 i++; 38 } 39 40 EStringList * args = new EStringList; 41 while ( i < ac ) 42 args->append( new EString( av[i++] ) ); 43 44 EventLoop::setup(); 45 46 AoxCommand * cmd = AoxCommand::create( args ); 47 48 if ( !cmd ) { 49 fprintf( stderr, "aox: Use 'aox help' to list commands; " 50 "and 'aox help <command>' for more.\n" ); 51 exit( 0 ); 52 } 53 54 if ( cmd->done() ) 55 return 0; 56 57 Configuration::setup( "archiveopteryx.conf" ); 58 Configuration::read( 59 EString( "" ) + 60 Configuration::compiledIn( Configuration::ConfigDir) + 61 "/aoxsuper.conf", true ); 62 63 Log * l = new Log; 64 Allocator::addEternal( l, "log object" ); 65 global.setLog( l ); 66 Allocator::addEternal( new StderrLogger( "aox", verbosity ), 67 "log object" ); 68 69 Configuration::report(); 70 71 if ( Scope::current()->log()->disastersYet() ) 72 exit( -1 ); 73 74 if ( cmd ) { 75 cmd->execute(); 76 if ( !cmd->done() || !Database::idle() ) 77 EventLoop::global()->start(); 78 return cmd->status(); 79 } 80 81 return 0; 82 } 83