/****************************************** * arg example with apr * Sylvain Marechal * 25/10/2005 *****************************************/ #include "apr_general.h" #include "apr_file_io.h" #include "apr_getopt.h" /********************************************* * test_arg ********************************************/ void test_arg( apr_pool_t *pool, int argc, char * argv[] ) { apr_getopt_t *os; apr_status_t ret; apr_getopt_option_t opts[] = { { "help", 'h', 0, "display the help" }, { "test", 't', 0, "the big test" }, { "arg", 'a', 1, "a test with one arg" }, { 0, 0, 0, 0 } }; apr_getopt_init( &os, pool, argc, (const char * const *)argv ); do { int opt_ch; const char * opt_arg; ret = apr_getopt_long( os, opts, &opt_ch, &opt_arg ); if( ret == APR_SUCCESS ) { printf( "Option i:\n" "\topt_ch: '%c'\n" "\topt_arg: '%s'\n", opt_ch, opt_arg ? opt_arg : "no arg" ); } } while( ret == APR_SUCCESS ); } /********************************************* * main ********************************************/ int main( int argc, char * argv[] ) { apr_pool_t *pool; if (apr_initialize() != APR_SUCCESS) { printf( "Could not initialize\n"); exit(-1); } if (apr_pool_create(&pool, NULL) != APR_SUCCESS) { printf( "Could not allocate pool\n"); exit( -1); } test_arg( pool, argc, argv ); apr_pool_destroy( pool ); return 0; }