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 <string>
#include <iostream.h>
#include <fstream.h>
#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

View File

@ -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

View File

@ -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 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.
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.
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 <getopt.h>
#else
#error need getopt.h
#endif
#include <iostream.h>
#include <fstream.h>
#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;
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);
di->run();
try {
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 ) {
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