/*----------------------------------------------------------------------*/ static int initialize_option_handling(int argc, const char **argv) { options = gopt_sort(&argc, argv, gopt_start( gopt_option('x', GOPT_ARG, gopt_shorts('x'), gopt_longs("xml") ), gopt_option('s', GOPT_ARG, gopt_shorts('s'), gopt_longs("suite") ), gopt_option('v', GOPT_NOARG, gopt_shorts('v'), gopt_longs("verbose") ), gopt_option('c', GOPT_NOARG, gopt_shorts('c'), gopt_longs("colours") ), gopt_option('c', GOPT_NOARG, gopt_shorts('c'), gopt_longs("colors") ), gopt_option('n', GOPT_NOARG, gopt_shorts('n'), gopt_longs("no-run") ), gopt_option('h', GOPT_NOARG, gopt_shorts('h'), gopt_longs("help") ) ) ); return(argc); }
int main (int argc, char *argv[]) { // setvbuf(stdout, NULL, _IONBF, 0); setlinebuf(stdout); assert(setenv("TZ", "UTC", 1) == 0); tzset(); // see http://www.purposeful.co.uk/software/gopt/ void *options = gopt_sort(&argc, (const char **)argv, gopt_start( gopt_option('h', 0, gopt_shorts('h', '?'), gopt_longs("help", "HELP"))//, // gopt_option('t', GOPT_ARG, gopt_shorts('t'), gopt_longs("thread-num")), // gopt_option('s', 0, gopt_shorts('s'), gopt_longs("silent", "quiet")), )); //TODO make customizable assert(setenv("LUA_PATH", "src/?.lua", 0) == 0); //http://rtmpdump.mplayerhq.hu/librtmp.3.html // const char usage[] = "usage: rtmp_load [--thread-num/-t N(default 1)] \"rtmp://example.com:1935/ app=app_name_or_empty playpath=path timeout=30\"\n"; const char usage[] = "usage: rtmp_load test.lua\n"; if (gopt(options, 'h')) { fprintf(stdout, usage); exit(EXIT_SUCCESS); } gopt_free(options); if (argc != 2) { // fprintf(stderr, "provide target rtmp string\n"); fprintf(stderr, "provide test file\n"); fprintf(stderr, usage); exit(EXIT_FAILURE); } char *script_path = argv[1]; lua_State *lua_state = luaL_newstate(); assert(lua_state != NULL); lua_gc(lua_state, LUA_GCSTOP, 0); luaL_openlibs(lua_state); lua_gc(lua_state, LUA_GCRESTART, -1); int r = luaL_loadfile(lua_state, script_path); if (r != 0) { if (r == LUA_ERRSYNTAX) { fprintf(stderr, "error loading %s, syntax error: %s\n", script_path, lua_tostring(lua_state, -1)); } else if (r == LUA_ERRFILE) { fprintf(stderr, "failed to open %s: %s\n", script_path, lua_tostring(lua_state, -1)); } else { fprintf(stderr, "error loading %s, ret = %i\n", script_path, r); } exit(EXIT_FAILURE); } lua_call(lua_state, 0, 1); // av_log_set_level(AV_LOG_ERROR); // av_log_set_level(AV_LOG_INFO); //http://libav.org/doxygen/master/log_8h.html av_log_set_level(AV_LOG_VERBOSE); // for parsing lib log // av_log_set_level(AV_LOG_DEBUG); // shows binary packet data //TODO http://libav.org/doxygen/master/librtmp_8c_source.html#l00080 av_log_set_callback(av_log_my_callback); av_register_all(); avcodec_register_all(); avformat_network_init(); if (av_lockmgr_register(handle_av_lock) != 0) { fprintf(stderr, "av_lockmgr_register failed\n"); exit(EXIT_FAILURE); } lua_call(lua_state, 0, 0); lua_close(lua_state); av_lockmgr_register(NULL); avformat_network_deinit(); exit(EXIT_SUCCESS); return 0; }
#include <stdlib.h> #include <stdarg.h> #include <stdint.h> #include <stdio.h> #include <string.h> #include <third_party/gopt/gopt.h> #include <cfg/prscfg.h> #include <cfg/tarantool_box_cfg.h> #include "tc_options.h" static const void *opts_def = gopt_start( gopt_option('G', GOPT_ARG, gopt_shorts('G'), gopt_longs("generate"), " <file>", "generate signature file"), gopt_option('W', GOPT_ARG, gopt_shorts('W'), gopt_longs("verify"), " <file>", "verify signature file"), gopt_option('?', 0, gopt_shorts('?'), gopt_longs("help"), NULL, "display this help and exit"), gopt_option('V', 0, gopt_shorts('V'), gopt_longs("version"), NULL, "display version information and exit") ); void tc_options_init(struct tc_options *opts) { memset(opts, 0, sizeof(struct tc_options)); init_tarantool_cfg(&opts->cfg); } void tc_options_free(struct tc_options *opts) { destroy_tarantool_cfg(&opts->cfg);
int main(int argc, const char *argv[]) { const char* argument; long int initial_timestamp; float initial_lat, initial_lng, initial_alt; float burst_alt, ascent_rate, drag_coeff, rmswinderror; int descent_mode; int scenario_idx, n_scenarios; int alarm_time; char* endptr; // used to check for errors on strtod calls wind_file_cache_t* file_cache; dictionary* scenario = NULL; // configure command-line options parsing void *options = gopt_sort(&argc, argv, gopt_start( gopt_option('h', 0, gopt_shorts('h', '?'), gopt_longs("help")), gopt_option('z', 0, gopt_shorts(0), gopt_longs("version")), gopt_option('v', GOPT_REPEAT, gopt_shorts('v'), gopt_longs("verbose")), gopt_option('o', GOPT_ARG, gopt_shorts('o'), gopt_longs("output")), gopt_option('k', GOPT_ARG, gopt_shorts('k'), gopt_longs("kml")), gopt_option('t', GOPT_ARG, gopt_shorts('t'), gopt_longs("start_time")), gopt_option('i', GOPT_ARG, gopt_shorts('i'), gopt_longs("data_dir")), gopt_option('d', 0, gopt_shorts('d'), gopt_longs("descending")), gopt_option('e', GOPT_ARG, gopt_shorts('e'), gopt_longs("wind_error")), gopt_option('a', GOPT_ARG, gopt_shorts('a'), gopt_longs("alarm")) )); if (gopt(options, 'h')) { // Help! // Print usage information printf("Usage: %s [options] [scenario files]\n", argv[0]); printf("Options:\n\n"); printf(" -h --help Display this information.\n"); printf(" --version Display version information.\n"); printf(" -v --verbose Display more information while running,\n"); printf(" Use -vv, -vvv etc. for even more verbose output.\n"); printf(" -t --start_time <int> Start time of model, defaults to current time.\n"); printf(" Should be a UNIX standard format timestamp.\n"); printf(" -o --output <file> Output file for CSV data, defaults to stdout. Overrides scenario.\n"); printf(" -k --kml <file> Output KML file.\n"); printf(" -d --descending We are in the descent phase of the flight, i.e. after\n"); printf(" burst or cutdown. burst_alt and ascent_rate ignored.\n"); printf(" -i --data_dir <dir> Input directory for wind data, defaults to current dir.\n\n"); printf(" -e --wind_error <err> RMS windspeed error (m/s).\n"); printf(" -a --alarm <seconds> Use alarm() to kill pred incase it hangs.\n"); printf("The scenario file is an INI-like file giving the launch scenario. If it is\n"); printf("omitted, the scenario is read from standard input.\n"); exit(0); } if (gopt(options, 'z')) { // Version information printf("Landing Prediction version: %s\nCopyright (c) CU Spaceflight 2009\n", VERSION); exit(0); } if (gopt_arg(options, 'a', &argument) && strcmp(argument, "-")) { alarm_time = strtol(argument, &endptr, 0); if (endptr == argument) { fprintf(stderr, "ERROR: %s: invalid alarm length\n", argument); exit(1); } alarm(alarm_time); } verbosity = gopt(options, 'v'); if (gopt(options, 'd')) descent_mode = DESCENT_MODE_DESCENDING; else descent_mode = DESCENT_MODE_NORMAL; if (gopt_arg(options, 'k', &argument) && strcmp(argument, "-")) { kml_file = fopen(argument, "wb"); if (!kml_file) { fprintf(stderr, "ERROR: %s: could not open KML file for output\n", argument); exit(1); } } else kml_file = NULL; if (gopt_arg(options, 't', &argument) && strcmp(argument, "-")) { initial_timestamp = strtol(argument, &endptr, 0); if (endptr == argument) { fprintf(stderr, "ERROR: %s: invalid start timestamp\n", argument); exit(1); } } else { initial_timestamp = time(NULL); } if (!(gopt_arg(options, 'i', &data_dir) && strcmp(data_dir, "-"))) data_dir = "./"; // populate wind data file cache file_cache = wind_file_cache_new(data_dir); // read in flight parameters n_scenarios = argc - 1; if(n_scenarios == 0) { // we'll parse from std in n_scenarios = 1; } for(scenario_idx = 0; scenario_idx < n_scenarios; ++scenario_idx) { char* scenario_output = NULL; if(argc > scenario_idx+1) { scenario = iniparser_load(argv[scenario_idx+1]); } else { scenario = iniparser_loadfile(stdin); } if(!scenario) { fprintf(stderr, "ERROR: could not parse scanario file.\n"); exit(1); } if(verbosity > 1) { fprintf(stderr, "INFO: Parsed scenario file:\n"); iniparser_dump_ini(scenario, stderr); } scenario_output = iniparser_getstring(scenario, "output:filename", NULL); if (gopt_arg(options, 'o', &argument) && strcmp(argument, "-")) { if(verbosity > 0) { fprintf(stderr, "INFO: Writing output to file specified on command line: %s\n", argument); } output = fopen(argument, "wb"); if (!output) { fprintf(stderr, "ERROR: %s: could not open CSV file for output\n", argument); exit(1); } } else if (scenario_output != NULL) { if(verbosity > 0) { fprintf(stderr, "INFO: Writing output to file specified in scenario: %s\n", scenario_output); } output = fopen(scenario_output, "wb"); if (!output) { fprintf(stderr, "ERROR: %s: could not open CSV file for output\n", scenario_output); exit(1); } } else { if(verbosity > 0) { fprintf(stderr, "INFO: Writing output to stdout.\n"); } output = stdout; } // write KML header if (kml_file) start_kml(); // The observant amongst you will notice that there are default values for // *all* keys. This information should not be spread around too well. // Unfortunately, this means we lack some error checking. initial_lat = iniparser_getdouble(scenario, "launch-site:latitude", 0.0); initial_lng = iniparser_getdouble(scenario, "launch-site:longitude", 0.0); initial_alt = iniparser_getdouble(scenario, "launch-site:altitude", 0.0); ascent_rate = iniparser_getdouble(scenario, "altitude-model:ascent-rate", 1.0); // The 1.1045 comes from a magic constant buried in // ~cuspaceflight/public_html/predict/index.php. drag_coeff = iniparser_getdouble(scenario, "altitude-model:descent-rate", 1.0) * 1.1045; burst_alt = iniparser_getdouble(scenario, "altitude-model:burst-altitude", 1.0); rmswinderror = iniparser_getdouble(scenario, "atmosphere:wind-error", 0.0); if(gopt_arg(options, 'e', &argument) && strcmp(argument, "-")) { rmswinderror = strtod(argument, &endptr); if (endptr == argument) { fprintf(stderr, "ERROR: %s: invalid RMS wind speed error\n", argument); exit(1); } } { int year, month, day, hour, minute, second; year = iniparser_getint(scenario, "launch-time:year", -1); month = iniparser_getint(scenario, "launch-time:month", -1); day = iniparser_getint(scenario, "launch-time:day", -1); hour = iniparser_getint(scenario, "launch-time:hour", -1); minute = iniparser_getint(scenario, "launch-time:minute", -1); second = iniparser_getint(scenario, "launch-time:second", -1); if((year >= 0) && (month >= 0) && (day >= 0) && (hour >= 0) && (minute >= 0) && (second >= 0)) { struct tm timeval = { 0 }; time_t scenario_launch_time = -1; if(verbosity > 0) { fprintf(stderr, "INFO: Using launch time from scenario: " "%i/%i/%i %i:%i:%i\n", year, month, day, hour, minute, second); } timeval.tm_sec = second; timeval.tm_min = minute; timeval.tm_hour = hour; timeval.tm_mday = day; /* 1 - 31 */ timeval.tm_mon = month - 1; /* 0 - 11 */ timeval.tm_year = year - 1900; /* f**k you Millenium Bug! */ #ifndef _BSD_SOURCE # warning This version of mktime does not allow explicit setting of timezone. #else timeval.tm_zone = "UTC"; #endif scenario_launch_time = mktime(&timeval); if(scenario_launch_time <= 0) { fprintf(stderr, "ERROR: Launch time in scenario is invalid\n"); exit(1); } else { initial_timestamp = scenario_launch_time; } } } if(verbosity > 0) { fprintf(stderr, "INFO: Scenario loaded:\n"); fprintf(stderr, " - Initial latitude : %lf deg N\n", initial_lat); fprintf(stderr, " - Initial longitude : %lf deg E\n", initial_lng); fprintf(stderr, " - Initial altitude : %lf m above sea level\n", initial_alt); fprintf(stderr, " - Initial timestamp : %li\n", initial_timestamp); fprintf(stderr, " - Drag coeff. : %lf\n", drag_coeff); if(!descent_mode) { fprintf(stderr, " - Ascent rate : %lf m/s\n", ascent_rate); fprintf(stderr, " - Burst alt. : %lf m\n", burst_alt); } fprintf(stderr, " - Windspeed err. : %f m/s\n", rmswinderror); } { // do the actual stuff!! altitude_model_t* alt_model = altitude_model_new(descent_mode, burst_alt, ascent_rate, drag_coeff); if(!alt_model) { fprintf(stderr, "ERROR: error initialising altitude profile\n"); exit(1); } if (!run_model(file_cache, alt_model, initial_lat, initial_lng, initial_alt, initial_timestamp, rmswinderror)) { fprintf(stderr, "ERROR: error during model run!\n"); exit(1); } altitude_model_free(alt_model); } // release the scenario iniparser_freedict(scenario); // write footer to KML and close output files if (kml_file) { finish_kml(); fclose(kml_file); } if (output != stdout) { fclose(output); } } // release gopt data, gopt_free(options); // release the file cache resources. wind_file_cache_free(file_cache); return 0; }
int main(int argc, const char **argv) { FILE *fdin, *fdout; char ch; int cid, secu_flag, sim_unlock, verify = 0; const char* s_secu_flag; const char* s_cid; if (argc>1) { void *options= gopt_sort( & argc, argv, gopt_start( gopt_option( 'h', 0, gopt_shorts( 'h', '?' ), gopt_longs( "help", "HELP" )), gopt_option( 'v', 0, gopt_shorts( 'v' ), gopt_longs( "version" )), gopt_option( 's', GOPT_ARG, gopt_shorts( 's' ), gopt_longs( "secu_flag" )), gopt_option( 'c', GOPT_ARG, gopt_shorts( 'c' ), gopt_longs( "cid" )), gopt_option( 'S', 0, gopt_shorts( 'S' ), gopt_longs( "sim_unlock" )), gopt_option( 'V', 0, gopt_shorts( 'V' ), gopt_longs( "verify" )))); /* * there are possible options to this program, some of which have multiple names: * * -h -? --help --HELP * -v --version * -s --secu_flag (which requires an option argument on|off) * -c --cid (which requires an option 8-character string argument <CID>) * -S --sim_unlock */ if( gopt( options, 'h' ) ){ //if any of the help options was specified fprintf( stdout, "gfree usage:\n" ); fprintf( stdout, "gfree [-h|-?|--help] [-v|--version] [-s|--secu_flag on|off]\n" ); fprintf( stdout, "\t-h | -? | --help: display this message\n" ); fprintf( stdout, "\t-v | --version: display program version\n" ); fprintf( stdout, "\t-s | --secu_flag on|off: turn secu_flag on or off\n" ); fprintf( stdout, "\t-c | --cid <CID>: set the CID to the 8-char long CID\n" ); fprintf( stdout, "\t-S | --sim_unlock: remove the SIMLOCK\n" ); fprintf( stdout, "\t-V | --verify: verify the CID, secu_flag, SIMLOCK\n" ); fprintf( stdout, "\n" ); fprintf( stdout, "calling gfree without arguments is the same as calling it:\n" ); fprintf( stdout, "\tgfree --secu_flag off --sim_unlock --cid 11111111\n" ); exit( 0 ); } if( gopt( options, 'v' ) ){ //if any of the version options was specified fprintf( stdout, "gfree version: %d.%d\n",VERSION_A,VERSION_B); exit (0); } if( gopt_arg(options, 's', &s_secu_flag)){ // if -s or --secu_flag was specified, check s_secu_flag if (strcmp(s_secu_flag, "on")==0){ secu_flag = 1; fprintf( stdout, "--secu_flag on set\n"); } else if (strcmp(s_secu_flag, "off")==0){ secu_flag = 2; fprintf( stdout, "--secu_flag off set\n"); } } if( gopt_arg(options, 'c', &s_cid)){ // if -c or --cid was specified, check s_cid size_t size; size = strlen(s_cid); if (size!=8){ fprintf( stderr, "Error: CID must be a 8 character string. Length of specified string: %d\n",(int)size); exit (1); } else { cid = 1; fprintf( stdout, "--cid set. CID will be changed to: %s\n",s_cid); } } if( gopt( options, 'S' ) ){ //if any of the sim_unlock options was specified sim_unlock = 1; fprintf( stdout, "--sim_unlock. SIMLOCK will be removed\n"); } if( gopt( options, 'V' ) ){ //if any of the sim_unlock options was specified verify = 1; fprintf( stdout, "--verify. CID, secu_flag, SIMLOCK will be verified\n"); } } else { secu_flag = 2; fprintf( stdout, "--secu_flag off set\n"); cid = 1; s_cid = "11111111"; fprintf( stdout, "--cid set. CID will be changed to: %s\n",s_cid); sim_unlock = 1; fprintf( stdout, "--sim_unlock. SIMLOCK will be removed\n"); } // if verify is set just verify and exit if (verify==1){ if (verify_init_device()!=0){ fprintf( stderr, "Error: verify could not initialize device!"); exit (-1); } if (verify_init_modem()!=0){ fprintf( stderr, "Error: verify could not initialize radio!"); exit (-1); } verify_set_verbose(); verify_cid(); verify_secu_flag(); verify_simlock(); verify_close_device(); exit (0); } fdin = fopen(INFILE, "rb"); if (fdin == NULL){ printf("Error opening input file.\n"); return -1; } fdout = fopen(CPYFILE, "wb"); if (fdout == NULL){ printf("Error opening copy file.\n"); return -1; } // create a copy of the partition while(!feof(fdin)) { ch = fgetc(fdin); if(ferror(fdin)) { printf("Error reading input file.\n"); exit(1); } if(!feof(fdin)) fputc(ch, fdout); if(ferror(fdout)) { printf("Error writing copy file.\n"); exit(1); } } if(fclose(fdin)==EOF) { printf("Error closing input file.\n"); exit(1); } if(fclose(fdout)==EOF) { printf("Error closing copy file.\n"); exit(1); } // copy back and patch long i; fdin = fopen(CPYFILE, "rb"); if (fdin == NULL){ printf("Error opening copy file.\n"); return -1; } fdout = fopen(OUTFILE, "wb"); if (fdout == NULL){ printf("Error opening output file.\n"); return -1; } i = 0; while(!feof(fdin)) { ch = fgetc(fdin); if(ferror(fdin)) { printf("Error reading copy file.\n"); exit(1); } // secu_flag if (i==0xa00 && secu_flag!=0) { ch = secu_flag==2 ? 0x00 : 0x01; } // CID if ((i>=0x200 && i<=0x207)&& (cid!=0)) { ch = s_cid[i-0x200]; } // SIM LOCK if (sim_unlock!=0){ if ((i>0x80003 && i<0x807fc) || (i>=0x80800 && i<=0x82fff)){ ch = 0x00; } else if (i==0x80000) { ch = 0x78; } else if (i==0x80001) { ch = 0x56; } else if (i==0x80002) { ch = 0xF3; } else if (i==0x80003) { ch = 0xC9; } else if (i==0x807fc) { ch = 0x49; } else if (i==0x807fd) { ch = 0x53; } else if (i==0x807fe) { ch = 0xF4; } else if (i==0x807ff) { ch = 0x7D; } } if(!feof(fdin)) fputc(ch, fdout); if(ferror(fdout)) { printf("Error writing output file.\n"); exit(1); } i++; } if(fclose(fdin)==EOF) { printf("Error closing copy file.\n"); exit(1); } if(fclose(fdout)==EOF) { printf("Error closing output file.\n"); exit(1); } return 0; }
int main(int argc, const char **argv) { int i=0; /* holds the return (read bytes) from fread() */ int nc=0; /* Sum of read bytes. */ int loopc=0; /* number of loop iterations */ char inbuf[BUFLEN+1]; /* Input-buffer */ const char *out_filename =0; const char *str_address, *str_port, *str_address_family; FILE *fout; int af=0; int fd_sock, fd_in; socklen_t sa_len; struct sockaddr *sa; struct sockaddr_in ip4_sa; void *options= gopt_sort( &argc, argv, gopt_start( gopt_option( 'h', 0, gopt_shorts( 'h', '?' ), gopt_longs( "help", "HELP" )), gopt_option( 'o', GOPT_ARG, gopt_shorts( 'o' ), gopt_longs( "out" )), gopt_option( 'a', GOPT_ARG, gopt_shorts( 0 ), gopt_longs( "address" )), gopt_option( 't', GOPT_ARG, gopt_shorts( 0 ), gopt_longs( "address_family", "af" )), gopt_option( 'p', GOPT_ARG, gopt_shorts( 'p' ), gopt_longs( "port" )) )); if( gopt( options, 'h' ) ) { /* * if any of the help options was specified */ fprintf( stdout, "Usage: sender \n" ); fprintf( stdout, " [-o file| --out file] \n" ); fprintf( stdout, "\n" ); fprintf( stdout, "Report bugs to <javier at ubillos.org>.\n" ); exit( EXIT_SUCCESS ); } /* If we have specified an output file, or it is specified to "-" */ if( !gopt_arg( options, 'p', &str_port ) || !gopt_arg( options, 't', &str_address_family) ) { fprintf(stderr, "To use \"network\" as an output, --port and --af need to be specified\n"); exit( EXIT_FAILURE ); } str_address = 0; gopt_arg( options, 'a', &str_address ); if( 0 == strcmp("AF_INET", str_address_family) ) { ip4_sa.sin_family = af = AF_INET; memset(&ip4_sa, 0, sizeof(ip4_sa)); sa = (struct sockaddr *)&ip4_sa; ip4_sa.sin_port = htons(atoi(str_port)); if( gopt_arg( options, 'a', &str_address) ) { fprintf(stderr, "ERROR binding to specific address not yet supported.\n"); exit( EXIT_FAILURE ); } else { ip4_sa.sin_addr.s_addr = INADDR_ANY; } if( 0 > (fd_sock = socket(AF_INET, SOCK_STREAM, 0)) ) { perror("ERROR opening socket\n"); exit( EXIT_FAILURE ); } ip4_sa.sin_port = htons(atoi(str_port)); fprintf(stderr, "bind()\n"); if( 0 > bind(fd_sock, (struct sockaddr *)&ip4_sa, sizeof(ip4_sa)) ) { perror("ERROR could not bind\n"); exit( EXIT_FAILURE ); } fprintf(stderr, "listen()\n"); if( 0 > listen(fd_sock,5) ) { perror("ERROR could not listen\n"); exit( EXIT_FAILURE ); } } else { fprintf(stderr, "Address family: %s is not a supported address family\n", str_address_family); exit( EXIT_FAILURE ); } if ( gopt_arg( options, 'o', &out_filename ) && strcmp( out_filename, "-" ) ) { fout = fopen( out_filename, "wb" ); if( ! fout ) { fprintf(stderr, "Could not open output (-o/--out) file.\n"); exit( EXIT_FAILURE ); } } /* If we have not specified an output file, or it is specified to "-" */ else { fout = stdout; } /* Prepare (zero) the data-buffer */ memset(inbuf, 0, BUFLEN+1); while(1) { sa_len = sizeof(ip4_sa); fprintf(stderr, "accept()\n"); if ( 0 > (fd_in = accept(fd_sock, (struct sockaddr *)&ip4_sa, &sa_len)) ) { perror( "ERROR accept failed\n"); exit( EXIT_FAILURE ); } fprintf(stderr, "read()\n"); while( 0 < (i = read(fd_in, inbuf, BUFLEN )) ) { fprintf(stderr, "loopc: %d\n", loopc); nc += i; fprintf(stderr, "Read characters: i:%d, %s\n", i, inbuf); /* Output to stdout */ fwrite(inbuf, sizeof(char), i, fout); } } fprintf(stderr, "Counted characters: %d\n", nc); return EXIT_SUCCESS; }
#include <stdio.h> #include <string.h> #include <stdint.h> #include <third_party/gopt/gopt.h> #include "client/tarantool/tc_opt.h" #define TC_DEFAULT_HOST "localhost" #define TC_DEFAULT_PORT_ADMIN 33015 /* supported cli options */ static const void *tc_options_def = gopt_start( gopt_option('h', GOPT_ARG, gopt_shorts('h'), gopt_longs("host"), " <host>", "server address"), gopt_option('p', GOPT_ARG, gopt_shorts('p'), gopt_longs("port"), " <port>", "server port"), gopt_option('a', GOPT_ARG, gopt_shorts('a'), gopt_longs("admin-port"), " <port>", "server admin port"), gopt_option('C', GOPT_ARG, gopt_shorts('C'), gopt_longs("cat"), " <file>", "print xlog or snapshot file content"), gopt_option('P', GOPT_ARG, gopt_shorts('P'), gopt_longs("play"), " <file>", "replay xlog file to the specified server"), gopt_option('S', GOPT_ARG, gopt_shorts('S'), gopt_longs("space"), " <space>", "filter by space number"), gopt_option('F', GOPT_ARG, gopt_shorts('F'), gopt_longs("from"), " <lsn>", "start xlog file from the specified lsn"), gopt_option('T', GOPT_ARG, gopt_shorts('T'), gopt_longs("to"), " <lsn>", "stop on specified xlog lsn"), gopt_option('M', GOPT_ARG, gopt_shorts('M'),
int main(int argc, const char **argv) { int status, i; bool verbose = false; bool no_run = false; const char *prefix_option; const char *suite_option = NULL; const char *tmp; atexit(cleanup); options = gopt_sort(&argc, argv, gopt_start( gopt_option('x', GOPT_ARG, gopt_shorts('x'), gopt_longs("xml") ), gopt_option('s', GOPT_ARG, gopt_shorts('s'), gopt_longs("suite") ), gopt_option('v', GOPT_NOARG, gopt_shorts('v'), gopt_longs("verbose") ), gopt_option('c', GOPT_NOARG, gopt_shorts('c'), gopt_longs("colours") ), gopt_option('c', GOPT_NOARG, gopt_shorts('c'), gopt_longs("colors") ), gopt_option('n', GOPT_NOARG, gopt_shorts('n'), gopt_longs("no-run") ), gopt_option('h', GOPT_NOARG, gopt_shorts('h'), gopt_longs("help") ) ) ); if (gopt_arg(options, 'x', &prefix_option)) reporter = create_xml_reporter(prefix_option); else reporter = create_text_reporter(); gopt_arg(options, 's', &suite_option); if (gopt_arg(options, 'v', &tmp)) verbose = true; if (gopt_arg(options, 'n', &tmp)) no_run = true; if (gopt_arg(options, 'c', &tmp)) reporter_options.use_colours = true; else reporter_options.use_colours = false; if (gopt_arg(options, 'h', &tmp)) { usage(argv); return EXIT_SUCCESS; } if (argc < 2) { usage(argv); return EXIT_FAILURE; } set_reporter_options(reporter, &reporter_options); i = 1; while(i < argc) { const char *suite_name = suite_option; const char *test_name = NULL; const char *test_library = argv[i++]; if (!file_exists(test_library)) { printf("Couldn't find library: %s\n", test_library); return EXIT_FAILURE; } suite_name = get_a_suite_name(suite_option, test_library); /* Check if the next argument is not a filename, thus a test name */ if (!file_exists(argv[i])) { test_name = argv[i++]; } status = runner(reporter, test_library, suite_name, test_name, verbose, no_run); if (status != 0) { printf("Library %s resulted in error status: %i\n", test_library, status); return status; } } return EXIT_SUCCESS; }
int main(int argc, const char* argv[]) { void *options = gopt_sort(&argc, argv, gopt_start( gopt_option('h', 0, gopt_shorts('h', '?'), gopt_longs("help", "HELP")), gopt_option('m', 0, gopt_shorts('m'), gopt_longs("mute")), gopt_option('v', GOPT_REPEAT, gopt_shorts('v'), gopt_longs("verbose")), gopt_option('i', GOPT_ARG, gopt_shorts('i'), gopt_longs("icon")))); int help = gopt(options, 'h'); int debug = gopt(options, 'v'); int muted = gopt(options, 'm'); const char *icon; if (gopt_arg(options, 'i', &icon) == 0) { icon = "speaker"; } gopt_free(options); if (help) print_usage(argv[0], FALSE); gint volume; if (muted) { if (argc > 2) { print_usage(argv[0], TRUE); } else if (argc == 2) { if (sscanf(argv[1], "%d", &volume) != 1) print_usage(argv[0], TRUE); if (volume > 100 || volume < 0) print_usage(argv[0], TRUE); } else { volume = 0; } } else { if (argc != 2) print_usage(argv[0], TRUE); if (sscanf(argv[1], "%d", &volume) != 1) print_usage(argv[0], TRUE); if (volume > 100 || volume < 0) print_usage(argv[0], TRUE); } // round volume volume = (int)(round(volume / 5.0) * 5.0); DBusGConnection *bus = NULL; DBusGProxy *proxy = NULL; GError *error = NULL; // initialize GObject g_type_init(); // connect to D-Bus print_debug("Connecting to D-Bus...", debug); bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); if (error != NULL) handle_error("Couldn't connect to D-Bus", error->message, TRUE); print_debug_ok(debug); // get the proxy print_debug("Getting proxy...", debug); proxy = dbus_g_proxy_new_for_name(bus, VALUE_SERVICE_NAME, VALUE_SERVICE_OBJECT_PATH, VALUE_SERVICE_INTERFACE); if (proxy == NULL) handle_error("Couldn't get a proxy for D-Bus", "Unknown(dbus_g_proxy_new_for_name)", TRUE); print_debug_ok(debug); print_debug("Sending volume...", debug); uk_ac_cam_db538_VolumeNotification_notify(proxy, volume, muted, icon, &error); if (error != NULL) { handle_error("Failed to send notification", error->message, FALSE); g_clear_error(&error); return EXIT_FAILURE; } print_debug_ok(debug); return EXIT_SUCCESS; }
* copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials * provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "trivia/config.h" #include <stddef.h> #include <third_party/gopt/gopt.h> const void *opt_def = gopt_start( gopt_option('h', 0, gopt_shorts('h', '?'), gopt_longs("help"), NULL, "display this help and exit"), gopt_option('V', 0, gopt_shorts('V'), gopt_longs("version"), NULL, "print program version and exit") );