Example #1
0
static  void  CompoundOptOption( char *buff ) {
//===============================

// Process a "compound" optimization option - multiple in one option
    char        single_opt[4];
    int         i;
    int         opt_i;

    single_opt[0] = buff[0];
    i = 0;
    
    while( buff[++i] != '\0' ) {
        opt_i = 1;
        single_opt[opt_i++] = buff[i];
        
        switch( tolower( buff[i] ) ) {
            case 'l':
                if( buff[i+1] == '+' )
                    single_opt[opt_i++] = buff[++i];
                break;
            case 'b':
                if( tolower( buff[i+1] ) == 'p' )
                    single_opt[opt_i++] = buff[++i];
                break;
            case 'd':
                if( tolower( buff[i+1] ) == 'o' )
                    single_opt[opt_i++] = buff[++i];
                break;
        }
        
        single_opt[opt_i] = '\0';
        CmdOption( single_opt );
    }
}
Example #2
0
void    ProcOpts( char **opt_array ) {
//====================================

    InitOptions();
    NewOptions = Options;
    for(;;) {
        if( *opt_array == NULL ) break;
        CmdOption( *opt_array );
        ++opt_array;
    }
    Options = NewOptions;
}
Example #3
0
int main( int argc, char** argv )
{

    signal( SIGSEGV, sigSegvHandler );

    options.push_back( CmdOption( "", "--port", "\t\tlistening port", "port", true ) );
    options.push_back( CmdOption( "-h", "--help", "\t\tprints help", "help" ) );
    options.push_back( CmdOption( "-v", "--version", "\t\tprints version", "version" ) );
    options.push_back( CmdOption( "", "--connectionThreads", "\tconnection threads", "connectionThreads", true ) );
    options.push_back( CmdOption( "", "--poolThreads", "\tpool threads", "poolThreads", true ) );
    
    //
    //  parse command line
    //
    std::string script;
    unsigned int port = 8080;
    unsigned int connectionThreads = 0;
    unsigned int poolThreads = 0;
    
    try
    {
        for ( int i = 1; i < argc; i++ )
        {
            if ( CmdOption::isOption( argv[i] ) )
            {
                const CmdOption* option = findOption( argv[i] );

                if ( !option )
                {
                    printf( "Unrecognized option %s \n", argv[i] );
                    throw argv[i];
                }

                if ( option->name( ) == "help" )
                {
                    usage( true );
                }
                
                if ( option->name( ) == "version" )
                {
                    printf( "%s \n",  BREEZE_VERSION );
                    exit(1);
                }

                if ( option->name( ) == "port" )
                {
                    port = atoi( option->value( ) );
                }
                
                if ( option->name( ) == "connectionThreads" )
                {
                    connectionThreads = atoi( option->value( ) );
                }
                
                
             }
            else
            {
                script = argv[i];
            }

        }
    }
    catch ( ... )
    {
        usage();
    }

    if ( !script.size() )
    {
        usage( true );
    }
    

    Breeze* breeze = Breeze::create( port );
    
    breeze->setEnvironment( getenv("BREEZE_ENV") );
    
    
    //      
    //  add paths to locate lua files
    //
    breeze->addPath( BREEZE_PATH );
    std::string path;
    size_t lastSlash = script.rfind( '/' );
        
    
    if ( lastSlash != std::string::npos )
    {
        path = script.substr( 0, lastSlash );
        script = script.substr( lastSlash + 1 );
    }
        
    //
    //  get script path
    //
    if ( script[0] != '/' )
    {
        char buffer[256] = "/0";
        getcwd( buffer, sizeof( buffer ) );
        
        if ( path != "." )
        {
            std::string temp = path;
            path = buffer;
            
            if ( temp.size() )
            {
                path = path + "/" + temp;
            }
        }
    }
    
    //
    //  set working directory
    //
    chdir( path.c_str() );
    
    breeze->addPath( path );
    breeze->setScript( script );
    
    try
    {
        printf( "starting server on port %d \n", port );
        breeze->run();
    }
    catch( ... )
    {
        return 1;
    }
    
    return 0;
}