moved command line parameter parsing from DarkIce.cpp to main.cpp

This commit is contained in:
darkeye 2000-11-13 19:38:55 +00:00
parent ace84836f3
commit dc04d3518d
3 changed files with 113 additions and 74 deletions

View File

@ -62,9 +62,6 @@
#include <hash_map> #include <hash_map>
#include <string> #include <string>
#include <iostream.h>
#include <fstream.h>
#include "Util.h" #include "Util.h"
#include "DarkIce.h" #include "DarkIce.h"
@ -98,45 +95,6 @@ static const char fileid[] = "$Id$";
/* ============================================================= module code */ /* ============================================================= 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 * Initialize the object
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
@ -381,8 +339,6 @@ DarkIce :: run ( void ) throw ( Exception )
{ {
int i; int i;
cout << "DarkIce" << endl << endl << flush;
for ( i = 0; i < noOutputs; ++i ) { for ( i = 0; i < noOutputs; ++i ) {
outputs[i].pid = fork(); outputs[i].pid = fork();
@ -428,6 +384,9 @@ DarkIce :: run ( void ) throw ( Exception )
$Source$ $Source$
$Log$ $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 Revision 1.6 2000/11/13 18:46:50 darkeye
added kdoc-style documentation comments added kdoc-style documentation comments

View File

@ -156,32 +156,33 @@ class DarkIce : public virtual Referable
protected: protected:
/*
virtual void
showUsage ( ostream & os ) throw ( Exception );
*/
public:
/** /**
* Default constructor. * Default constructor. Always throws an Exception.
* *
* @exception Exception * @exception Exception
*/ */
inline inline
DarkIce ( void ) throw ( Exception ) 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 config the config Object to read initialization
* @param argv the command line arguments. * information from.
* @exception Exception * @exception Exception
*/ */
DarkIce ( int argc, inline
char * argv[] ) throw ( Exception ); DarkIce ( const Config & config ) throw ( Exception )
{
init( config);
}
/** /**
* Destructor. * Destructor.
@ -234,6 +235,9 @@ class DarkIce : public virtual Referable
$Source$ $Source$
$Log$ $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 Revision 1.4 2000/11/13 18:46:50 darkeye
added kdoc-style documentation comments added kdoc-style documentation comments

View File

@ -11,30 +11,40 @@
Abstract : Abstract :
Program entry point Program entry point
Copyright notice: Copyright notice:
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
USA.
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
/* ============================================================ include files */ /* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#else
#error need getopt.h
#endif
#include <iostream.h> #include <iostream.h>
#include <fstream.h>
#include "Ref.h" #include "Ref.h"
#include "Exception.h" #include "Exception.h"
@ -54,6 +64,12 @@ static const char fileid[] = "$Id$";
/* =============================================== local function prototypes */ /* =============================================== local function prototypes */
/*------------------------------------------------------------------------------
* Show program usage
*----------------------------------------------------------------------------*/
static void
showUsage ( ostream & os );
/* ============================================================= module code */ /* ============================================================= module code */
@ -67,10 +83,47 @@ main (
{ {
int res = -1; int res = -1;
try { cout << "DarkIce live audio streamer, http://darkice.sourceforge.net"<<endl;
cout << "Copyright (C) 2000, Tyrell Hungary, http://tyrell.hu" << endl;
cout << endl;
Ref<DarkIce> di = new DarkIce( argc, argv); try {
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<DarkIce> di = new DarkIce( config);
res = di->run();
} catch ( Exception & e ) { } catch ( Exception & e ) {
cout << "DarkIce: " << e << endl << flush; 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$ $Source$
$Log$ $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 Revision 1.2 2000/11/08 17:29:50 darkeye
added configuration file reader added configuration file reader