From dc04d3518d382fce1d16d5232f3f1efacf5805a7 Mon Sep 17 00:00:00 2001 From: darkeye Date: Mon, 13 Nov 2000 19:38:55 +0000 Subject: [PATCH] moved command line parameter parsing from DarkIce.cpp to main.cpp --- darkice/trunk/src/DarkIce.cpp | 47 +------------- darkice/trunk/src/DarkIce.h | 28 +++++---- darkice/trunk/src/main.cpp | 112 ++++++++++++++++++++++++++++------ 3 files changed, 113 insertions(+), 74 deletions(-) diff --git a/darkice/trunk/src/DarkIce.cpp b/darkice/trunk/src/DarkIce.cpp index 7082372..3928af1 100644 --- a/darkice/trunk/src/DarkIce.cpp +++ b/darkice/trunk/src/DarkIce.cpp @@ -62,9 +62,6 @@ #include #include -#include -#include - #include "Util.h" #include "DarkIce.h" @@ -98,45 +95,6 @@ static const char fileid[] = "$Id$"; /* ============================================================= module code */ -/*------------------------------------------------------------------------------ - * Constructor - *----------------------------------------------------------------------------*/ -DarkIce :: DarkIce ( int argc, - char * argv[] ) throw ( Exception ) -{ - const char * configFileName = 0; - int i; - - while ( (i = getopt( argc, argv, "c:")) != -1 ) { - switch ( i ) { - case 'c': - configFileName = optarg; - break; - - default: - case ':': - case '?': - throw Exception( __FILE__, __LINE__, - "error parsing command line options"); - break; - } - } - - if ( !configFileName ) { - throw Exception( __FILE__, __LINE__, "no configuration file specified"); - } - - cout << "configFileName: " << configFileName << endl; - - ifstream configFile( configFileName); - Config config( configFile); - - init( config); - - cout << "no. of outputs: " << noOutputs << endl; -} - - /*------------------------------------------------------------------------------ * Initialize the object *----------------------------------------------------------------------------*/ @@ -381,8 +339,6 @@ DarkIce :: run ( void ) throw ( Exception ) { int i; - cout << "DarkIce" << endl << endl << flush; - for ( i = 0; i < noOutputs; ++i ) { outputs[i].pid = fork(); @@ -428,6 +384,9 @@ DarkIce :: run ( void ) throw ( Exception ) $Source$ $Log$ + Revision 1.7 2000/11/13 19:38:55 darkeye + moved command line parameter parsing from DarkIce.cpp to main.cpp + Revision 1.6 2000/11/13 18:46:50 darkeye added kdoc-style documentation comments diff --git a/darkice/trunk/src/DarkIce.h b/darkice/trunk/src/DarkIce.h index 3b94266..f54d9b0 100644 --- a/darkice/trunk/src/DarkIce.h +++ b/darkice/trunk/src/DarkIce.h @@ -156,32 +156,33 @@ class DarkIce : public virtual Referable protected: -/* - virtual void - showUsage ( ostream & os ) throw ( Exception ); -*/ - - public: /** - * Default constructor. + * Default constructor. Always throws an Exception. * * @exception Exception */ inline DarkIce ( void ) throw ( Exception ) { + throw Exception( __FILE__, __LINE__); } + + public: + /** - * Constructor based on command line parameters. + * Constructor based on a configuration object. * - * @param argc number of arguments - * @param argv the command line arguments. + * @param config the config Object to read initialization + * information from. * @exception Exception */ - DarkIce ( int argc, - char * argv[] ) throw ( Exception ); + inline + DarkIce ( const Config & config ) throw ( Exception ) + { + init( config); + } /** * Destructor. @@ -234,6 +235,9 @@ class DarkIce : public virtual Referable $Source$ $Log$ + Revision 1.5 2000/11/13 19:38:55 darkeye + moved command line parameter parsing from DarkIce.cpp to main.cpp + Revision 1.4 2000/11/13 18:46:50 darkeye added kdoc-style documentation comments diff --git a/darkice/trunk/src/main.cpp b/darkice/trunk/src/main.cpp index 71e48bc..8c39fa3 100644 --- a/darkice/trunk/src/main.cpp +++ b/darkice/trunk/src/main.cpp @@ -11,30 +11,40 @@ Abstract : - Program entry point + Program entry point Copyright notice: - 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, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, - USA. + 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, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ------------------------------------------------------------------------------*/ /* ============================================================ include files */ +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#ifdef HAVE_GETOPT_H +#include +#else +#error need getopt.h +#endif + #include +#include #include "Ref.h" #include "Exception.h" @@ -54,6 +64,12 @@ static const char fileid[] = "$Id$"; /* =============================================== local function prototypes */ +/*------------------------------------------------------------------------------ + * Show program usage + *----------------------------------------------------------------------------*/ +static void +showUsage ( ostream & os ); + /* ============================================================= module code */ @@ -67,10 +83,47 @@ main ( { int res = -1; + cout << "DarkIce live audio streamer, http://darkice.sourceforge.net"< di = new DarkIce( argc, argv); - di->run(); + const char * configFileName = 0; + int i; + static struct option long_options[] = { + { "config", 1, 0, 'c'}, + { "help", 0, 0, 'h'}, + { 0, 0, 0, 0} + }; + + + while ( (i = getopt_long( argc, argv, "hc:", long_options, 0)) != -1 ) { + switch ( i ) { + case 'c': + configFileName = optarg; + break; + + default: + case ':': + case '?': + case 'h': + showUsage( cout); + return 1; + } + } + + if ( !configFileName ) { + throw Exception( __FILE__, __LINE__, + "no configuration file specified"); + } + + cout << "Using config file: " << configFileName << endl; + + ifstream configFile( configFileName); + Config config( configFile); + Ref di = new DarkIce( config); + + res = di->run(); } catch ( Exception & e ) { cout << "DarkIce: " << e << endl << flush; @@ -80,11 +133,34 @@ main ( } +/*------------------------------------------------------------------------------ + * Show program usage + *----------------------------------------------------------------------------*/ +static void +showUsage ( ostream & os ) +{ + os + << "usage: darkice -c config.file" + << endl + << endl + << "options:" + << endl + << " -c, --config=config.file use configuration file config.file" + << endl + << " -h, --help print this message and exit" + << endl + << endl; +} + + /*------------------------------------------------------------------------------ $Source$ $Log$ + Revision 1.3 2000/11/13 19:38:55 darkeye + moved command line parameter parsing from DarkIce.cpp to main.cpp + Revision 1.2 2000/11/08 17:29:50 darkeye added configuration file reader