int main(int argc, char** argv) { QApplication app(argc, argv); if (app.arguments().contains("--help")) { printUsage(); return 0; } if(app.arguments().contains("--console")) { QString output = getArgValue("--output"); QString family = getArgValue("--family"); QString type = getArgValue("--type"); QString name = getArgValue("--name"); bool paramsMissing = output.isEmpty() || family.isEmpty() || type.isEmpty() || name.isEmpty(); if( paramsMissing ) { printUsage(); return 1; } if( ! app.arguments().contains("--quiet")) { qDebug() << "output = " << output; qDebug() << "name = " << name; qDebug() << "type = " << type; qDebug() << "family = " << family; } medPluginGenerator generator; generator.setOutputDirectory(output); generator.setName(name); generator.setType(type); generator.setPluginFamily(family); bool resultGenerator = generator.run(); if( ! app.arguments().contains("--quiet")) { if(resultGenerator) { qDebug() << "Generation succeeded."; } else { qDebug() << "Plugin generation: Generation failed."; } } ::exit(resultGenerator ? 0 : 1); } else { medPluginGeneratorMainWindow generator; generator.show(); return app.exec(); } }
bool getArgValue(const QVariant& arg, QChar& res) { unsigned short unicode; if ( !getArgValue(arg,unicode) ) { } res = QChar(unicode); return true; }
/* ArgsFlagsControl::onCheck * Event handler called when a checkbox or radio button is toggled. * Update the value in the textbox. *******************************************************************/ void onCheck(wxCommandEvent& event) { // Note that this function does NOT recompute the arg value from // scratch! There might be newer flags we don't know about, and // blindly erasing them would be rude. Instead, only twiddle the // single flag corresponding to this checkbox. event.Skip(); int val = getArgValue(); if (val < 0) return; // Doesn't matter what type of pointer this is; only need it to find // the flag index wxObject* control = event.GetEventObject(); for (unsigned i = 0; i < flags.size(); i++) { if (controls[i] == control) { // Remove the entire group if (flag_to_bit_group[i]) val &= ~flag_to_bit_group[i]; else val &= ~flags[i].value; // Then re-add if appropriate if (event.IsChecked()) val |= flags[i].value; ArgsTextControl::setArgValue(val); return; } } }
bool getArgValue(const QVariant& arg, unsigned char& res) { unsigned long long num; if ( !getArgValue(arg,num) ) { return false; } if ( num > std::numeric_limits<unsigned char>::max() ) { return false; } res = (unsigned char)num; return true; }
bool getArgValue(const QVariant& arg, char& res) { long long num; if ( !getArgValue(arg,num) ) { return false; } if ( num < std::numeric_limits<char>::min() || num > std::numeric_limits<char>::max() ) { return false; } res = (char)num; return true; }
bool getArgValue(const QVariant& arg, long long& res) { if ( !arg.canConvert<long long>() ) { return false; } if ( arg.type() == QVariant::Double ) { return false; } if ( arg.type() == QVariant::ULongLong ) { unsigned long long num; if ( !getArgValue(arg,num) ) { return false; // unexpected error } if ( num > (unsigned long long)std::numeric_limits<long long>::max() ) { return false; } } bool convRes = false; res = arg.toLongLong(&convRes); return convRes; }
//loop through command line arguments and extract settings void Settings::parse(const int argc, const char** argv) { bool hasUserName = false; //assume user hasn't entered a username //loops through arguments, reads in each argument and decides what to do with it for(int ii = 0; ii < argc; ++ii) { std::string arg(argv[ii]); if (arg[0] != '-') { continue; //not a switch, skip it } if(arg.find("-username="******"-address=") == 0) //are we setting a server IP? { std::string address(getArgValue(arg)); try { (void)serverAddress(address); //set and validate requested server address } catch (BeeChatException bce) { throw; //rethrow the same exception } } else if(arg.find("-server") == 0) { (void)isServer(true); //request to bee a server } else if(arg.find("-port=") == 0) { std::string portStr(getArgValue(arg)); try { (void)port((unsigned short)atoi(portStr.c_str())); //set and validate requested port } catch(BeeChatException e) { std::stringstream ss; ss << "Could not set port: " << e.type() << ":" << e.message(); throw BeeChatException(eET_invalid_port, ss.str()); } } else { std::stringstream ss; ss << "Unknown argument: " << arg; throw BeeChatException(eET_unknown_arg, ss.str()); } } if(!hasUserName) { throw BeeChatException(eET_empty_username, "No username supplied"); } }
int main(int argc, char** argv) { ros::init(argc, argv, "rf_node"); int forestSize = 1000; int attributeSample = 16; //three suggested values 0.5*sqrt(n), sqrt(n), 2*sqrt(n) where n is equal to number of attributes float forestAccuracy = 0.01f; char* fileName = getArgValue(argc, argv, "--file-location"); if (fileName == NULL) { std::cout << "No --file-location argument has been supplied. Exiting.\n"; return 1; } char* forestSizeChar = getArgValue(argc, argv, "--forest-size"); if (forestSizeChar != NULL) { forestSize = strtol(forestSizeChar, NULL, 10); std::cout << "Using forest size: " << forestSize << std::endl; } char* attributeSampleChar = getArgValue(argc, argv, "--attribute-sample"); if (attributeSampleChar != NULL) { attributeSample = strtol(attributeSampleChar, NULL, 10); std::cout << "Using attribute sample (m): " << attributeSample << std::endl; } char* forestAccuracyChar = getArgValue(argc, argv, "--forest-accuracy"); if (forestAccuracyChar != NULL) { forestAccuracy = atof(forestAccuracyChar); std::cout << "Using forest accuracy (OOB error): " << forestAccuracy << std::endl; } std::cout << "Loading data from: " << fileName << std::endl; std::vector<Instance> instances; //Load in training data std::ifstream ifs; ifs.open(fileName, std::ios::in); while (!ifs.eof()) { char c; bool eof; do { ifs >> c; eof = ifs.eof(); } while ((c == ' ' || c == '\n') && !eof); if (eof) break; //New instance if (c == '+' || c == '-') { ifs.unget(); Instance newInstance; ifs >> newInstance.classification; for (int i=0; i<NUMBER_OF_ATTRIBUTES; i++) { int pos; ifs >> pos; ifs >> c; if (c == ':') { float val; ifs >> val; newInstance.data.push_back(val); } } instances.push_back(newInstance); }
int main( int argc, char **argv ) { /* DATA */ int rc = 0; char *argValue = 0; int seed = 1; char flagTestAll = 0; char flagTestPreconditions = 0; char flagTestMisc = 0; char flagTestMemory = 0; char flagTestEncodingDecoding = 0; char flagTestAnySet = 0; /* CODE */ printf( "Testing:\n" ); printf( " %s %s\n", PINTO_NAME, PINTO_VERSION_STRING ); printf( " %s\n", PINTO_COPYRIGHT ); printf( "\n" ); /* **************************************** */ rc = getArgValue( argc, argv, "-s", &argValue ); if ( rc == 0 ) { seed = atol( argValue ); } else { seed = time( NULL ); } /* **************************************** */ rc = getArgValue( argc, argv, "-t", &argValue ); if ( rc == 0 ) { if ( strcmp( argValue, "all" ) == 0 ) { flagTestAll = 1; flagTestAnySet = 1; } else if ( strcmp( argValue, "pre" ) == 0 ) { flagTestPreconditions = 1; flagTestAnySet = 1; } else if ( strcmp( argValue, "misc" ) == 0 ) { flagTestMisc = 1; flagTestAnySet = 1; } else if ( strcmp( argValue, "memory" ) == 0 ) { flagTestMemory = 1; flagTestAnySet = 1; } else if ( strcmp( argValue, "image" ) == 0 ) { flagTestEncodingDecoding = 1; flagTestAnySet = 1; } else { fprintf( stderr, "UNKNOWN TEST TO RUN: \"%s\"\n", argValue ); TEST_ERR_IF( 1 ); } } if ( flagTestAnySet == 0 ) { fprintf( stderr, "Usage: pintoTest [options]\n" ); fprintf( stderr, " -s <NUMBER> Seed for random number generator\n" ); fprintf( stderr, " -t <TEST> Test to run\n" ); fprintf( stderr, " Possible tests:\n" ); fprintf( stderr, " all = all tests\n" ); fprintf( stderr, " pre = preconditions\n" ); fprintf( stderr, " misc = misc\n" ); fprintf( stderr, " memory = memory\n" ); fprintf( stderr, " image = encoding/decoding\n" ); fprintf( stderr, "\n" ); return -1; } /* **************************************** */ printf( "Using seed: %d\n", seed ); fflush( stdout ); srand( seed ); /* **************************************** */ TEST_ERR_IF( sizeof( s32 ) != 4 ); TEST_ERR_IF( sizeof( u8 ) != 1 ); /* **************************************** */ if ( flagTestAll || flagTestPreconditions ) { TEST_ERR_IF( testPreconditions() != 0 ); } if ( flagTestAll || flagTestMisc ) { TEST_ERR_IF( testMisc() != 0 ); } if ( flagTestAll || flagTestEncodingDecoding ) { TEST_ERR_IF( testEncodingDecoding() != 0 ); } if ( flagTestAll || flagTestMemory ) { TEST_ERR_IF( testMemory() != 0 ); } /* **************************************** */ /* success! */ printf( "SUCCESS!\n\n" ); return 0; /* CLEANUP */ cleanup: printf( "FAILED AT %d\n\n", rc ); return rc; }
static rc_t main_1(int argc, char *argv[], bool const continuing, unsigned const load) { Args *args; rc_t rc; unsigned n_aligned = 0; unsigned n_unalgnd = 0; char *aligned[256]; char *unalgnd[256]; char *name_buffer = NULL; unsigned next_name = 0; unsigned nbsz = 0; char const *value; char *dummy; rc = ArgsMakeAndHandle (&args, argc, argv, 1, Options, sizeof(Options)/sizeof(Options[0])); while (rc == 0) { uint32_t pcount; rc = ArgsOptionCount(args, option_only_verify, &pcount); if (rc) break; G.onlyVerifyReferences |= (pcount > 0); rc = ArgsOptionCount(args, option_no_verify, &pcount); if (rc) break; G.noVerifyReferences |= (pcount > 0); rc = ArgsOptionCount(args, option_use_qual, &pcount); if (rc) break; G.useQUAL |= (pcount > 0); rc = ArgsOptionCount(args, option_ref_config, &pcount); if (rc) break; G.limit2config |= (pcount > 0); rc = ArgsOptionCount(args, OPTION_REF_FILE, &pcount); if (rc) break; if (pcount && G.refFiles) { int i; for (i = 0; G.refFiles[i]; ++i) free((void *)G.refFiles[i]); free((void *)G.refFiles); } G.refFiles = calloc(pcount + 1, sizeof(*(G.refFiles))); if (!G.refFiles) { rc = RC(rcApp, rcArgv, rcAccessing, rcMemory, rcExhausted); break; } while(pcount-- > 0) { rc = getArgValue(args, OPTION_REF_FILE, pcount, &G.refFiles[pcount]); if (rc) break; } rc = ArgsOptionCount (args, OPTION_TMPFS, &pcount); if (rc) break; if (pcount == 1) { rc = getArgValue(args, OPTION_TMPFS, 0, &G.tmpfs); if (rc) break; } else if (pcount > 1) { rc = RC(rcApp, rcArgv, rcAccessing, rcParam, rcExcessive); OUTMSG (("Single parameter required\n")); MiniUsage (args); break; } rc = ArgsOptionCount (args, OPTION_INPUT, &pcount); if (rc) break; if (pcount == 1) { rc = getArgValue(args, OPTION_INPUT, 0, &G.inpath); if (rc) break; } else if (pcount > 1) { rc = RC(rcApp, rcArgv, rcAccessing, rcParam, rcExcessive); OUTMSG (("Single input parameter required\n")); MiniUsage (args); break; } rc = ArgsOptionCount (args, option_ref_filter, &pcount); if (rc) break; if (pcount == 1) { rc = getArgValue(args, option_ref_filter, 0, &G.refFilter); if (rc) break; } else if (pcount > 1) { rc = RC(rcApp, rcArgv, rcAccessing, rcParam, rcExcessive); OUTMSG (("Single parameter required\n")); MiniUsage (args); break; } rc = ArgsOptionCount (args, OPTION_CONFIG, &pcount); if (rc) break; if (pcount == 1) { rc = getArgValue(args, OPTION_CONFIG, 0, &G.refXRefPath); if (rc) break; } else if (pcount > 1) { rc = RC(rcApp, rcArgv, rcAccessing, rcParam, rcExcessive); OUTMSG (("Single input parameter required\n")); MiniUsage (args); break; } rc = ArgsOptionCount (args, OPTION_OUTPUT, &pcount); if (rc) break; if (pcount == 1) { rc = getArgValue(args, OPTION_OUTPUT, 0, &G.outpath); if (rc) break; if (load == 0) { G.firstOut = strdup(G.outpath); } value = strrchr(G.outpath, '/'); G.outname = value ? (value + 1) : G.outpath; } else if (pcount > 1) { rc = RC(rcApp, rcArgv, rcAccessing, rcParam, rcExcessive); OUTMSG (("Single output parameter required\n")); MiniUsage (args); break; } else if (!G.onlyVerifyReferences) { rc = RC(rcApp, rcArgv, rcAccessing, rcParam, rcInsufficient); OUTMSG (("Output parameter required\n")); MiniUsage (args); break; } rc = ArgsOptionCount (args, OPTION_MINMAPQ, &pcount); if (rc) break; if (pcount == 1) { rc = ArgsOptionValue(args, OPTION_MINMAPQ, 0, (const void **)&value); if (rc) break; G.minMapQual = strtoul(value, &dummy, 0); } rc = ArgsOptionCount (args, OPTION_QCOMP, &pcount); if (rc) break; if (pcount == 1) { rc = getArgValue(args, OPTION_QCOMP, 0, &G.QualQuantizer); if (rc) break; } rc = ArgsOptionCount (args, option_edit_aligned_qual, &pcount); if (rc) break; if (pcount == 1) { rc = ArgsOptionValue (args, option_edit_aligned_qual, 0, (const void **)&value); if (rc) break; G.alignedQualValue = strtoul(value, &dummy, 0); if (G.alignedQualValue == 0) { rc = RC(rcApp, rcArgv, rcAccessing, rcParam, rcIncorrect); OUTMSG (("edit-aligned-qual: bad value\n")); MiniUsage (args); break; } G.editAlignedQual = true; } rc = ArgsOptionCount (args, OPTION_CACHE_SIZE, &pcount); if (rc) break; if (pcount == 1) { rc = ArgsOptionValue (args, OPTION_CACHE_SIZE, 0, (const void **)&value); if (rc) break; G.cache_size = strtoul(value, &dummy, 0) * 1024UL * 1024UL; if (G.cache_size == 0) { rc = RC(rcApp, rcArgv, rcAccessing, rcParam, rcIncorrect); OUTMSG (("cache-size: bad value\n")); MiniUsage (args); break; } } rc = ArgsOptionCount (args, OPTION_MAX_WARN_DUP_FLAG, &pcount); if (rc) break; if (pcount == 1) { rc = ArgsOptionValue (args, OPTION_MAX_WARN_DUP_FLAG, 0, (const void **)&value); if (rc) break; G.maxWarnCount_DupConflict = strtoul(value, &dummy, 0); } rc = ArgsOptionCount (args, option_unsorted, &pcount); if (rc) break; G.expectUnsorted |= (pcount > 0); rc = ArgsOptionCount (args, option_sorted, &pcount); if (rc) break; G.requireSorted |= (pcount > 0); rc = ArgsOptionCount (args, OPTION_MAX_REC_COUNT, &pcount); if (rc) break; if (pcount == 1) { rc = ArgsOptionValue (args, OPTION_MAX_REC_COUNT, 0, (const void **)&value); if (rc) break; G.maxAlignCount = strtoul(value, &dummy, 0); } rc = ArgsOptionCount (args, OPTION_MAX_ERR_COUNT, &pcount); if (rc) break; if (pcount == 1) { rc = ArgsOptionValue (args, OPTION_MAX_ERR_COUNT, 0, (const void **)&value); if (rc) break; G.maxErrCount = strtoul(value, &dummy, 0); } rc = ArgsOptionCount (args, OPTION_MIN_MATCH, &pcount); if (rc) break; if (pcount == 1) { rc = ArgsOptionValue (args, OPTION_MIN_MATCH, 0, (const void **)&value); if (rc) break; G.minMatchCount = strtoul(value, &dummy, 0); } rc = ArgsOptionCount (args, OPTION_ACCEPT_DUP, &pcount); if (rc) break; G.acceptBadDups |= (pcount > 0); rc = ArgsOptionCount (args, OPTION_ACCEPT_NOMATCH, &pcount); if (rc) break; G.acceptNoMatch |= (pcount > 0); rc = ArgsOptionCount (args, option_keep_mismatch_qual, &pcount); if (rc) break; G.keepMismatchQual |= (pcount > 0); rc = ArgsOptionCount (args, OPTION_NO_CS, &pcount); if (rc) break; G.noColorSpace |= (pcount > 0); rc = ArgsOptionCount (args, OPTION_NO_SECONDARY, &pcount); if (rc) break; G.noSecondary |= (pcount > 0); rc = ArgsOptionCount (args, OPTION_TI, &pcount); if (rc) break; G.hasTI |= (pcount > 0); rc = ArgsOptionCount (args, OPTION_ACCEPT_HARD_CLIP, &pcount); if (rc) break; G.acceptHardClip |= (pcount > 0); rc = ArgsOptionCount (args, OPTION_ALLOW_MULTI_MAP, &pcount); if (rc) break; G.allowMultiMapping |= (pcount > 0); rc = ArgsOptionCount (args, OPTION_ALLOW_SECONDARY, &pcount); if (rc) break; G.assembleWithSecondary |= (pcount > 0); rc = ArgsOptionCount (args, OPTION_DEFER_SECONDARY, &pcount); if (rc) break; G.deferSecondary |= (pcount > 0); rc = ArgsOptionCount (args, OPTION_NOMATCH_LOG, &pcount); if (rc) break; if (pcount == 1) { KDirectory *dir; rc = ArgsOptionValue (args, OPTION_NOMATCH_LOG, 0, (const void **)&value); if (rc) break; rc = KDirectoryNativeDir(&dir); if (rc) break; rc = KDirectoryCreateFile(dir, &G.noMatchLog, 0, 0664, kcmInit, "%s", value); KDirectoryRelease(dir); if (rc) break; } rc = ArgsOptionCount (args, OPTION_HEADER, &pcount); if (rc) break; if (pcount == 1) { rc = ArgsOptionValue (args, OPTION_HEADER, 0, (const void **)&value); if (rc) break; free((void *)G.headerText); rc = LoadHeader(&G.headerText, value, G.inpath); if (rc) break; } rc = ArgsParamCount (args, &pcount); if (rc) break; if (pcount == 0) { rc = RC(rcApp, rcArgv, rcAccessing, rcParam, rcInsufficient); MiniUsage (args); break; } else if (pcount > sizeof(aligned)/sizeof(aligned[0])) { rc = RC(rcApp, rcArgv, rcAccessing, rcParam, rcExcessive); (void)PLOGERR(klogErr, (klogErr, rc, "$(count) input files is too many, $(max) is the limit", "count=%u,max=%u", (unsigned)pcount, (unsigned)(sizeof(aligned)/sizeof(aligned[0])))); break; } else { unsigned need = G.inpath ? (strlen(G.inpath) + 1) * pcount : 0; unsigned i; for (i = 0; i < pcount; ++i) { rc = ArgsParamValue(args, i, (const void **)&value); if (rc) break; need += strlen(value) + 1; } nbsz = need; } rc = ArgsOptionCount (args, OPTION_UNALIGNED, &pcount); if (rc) break; if (pcount > 0) { unsigned need = G.inpath ? (strlen(G.inpath) + 1) * pcount : 0; unsigned i; for (i = 0; i < pcount; ++i) { rc = ArgsOptionValue(args, OPTION_UNALIGNED, i, (const void **)&value); if (rc) break; need += strlen(value) + 1; } if (rc) break; nbsz += need; } name_buffer = malloc(nbsz); if (name_buffer == NULL) { rc = RC(rcApp, rcArgv, rcAccessing, rcMemory, rcExhausted); break; } rc = ArgsOptionCount (args, OPTION_UNALIGNED, &pcount); if (rc == 0) { unsigned i; for (i = 0; i < pcount; ++i) { rc = ArgsOptionValue(args, OPTION_UNALIGNED, i, (const void **)&value); if (rc) break; unalgnd[n_unalgnd++] = name_buffer + next_name; rc = PathWithBasePath(name_buffer + next_name, nbsz - next_name, value, G.inpath); if (rc) break; next_name += strlen(name_buffer + next_name) + 1; } if (rc) break; } else break; rc = ArgsParamCount (args, &pcount); if (rc == 0) { unsigned i; for (i = 0; i < pcount; ++i) { rc = ArgsParamValue(args, i, (const void **)&value); if (rc) break; aligned[n_aligned++] = name_buffer + next_name; rc = PathWithBasePath(name_buffer + next_name, nbsz - next_name, value, G.inpath); if (rc) break; next_name += strlen(name_buffer + next_name) + 1; } } else break; rc = run(argv[0], n_aligned, (char const **)aligned, n_unalgnd, (char const **)unalgnd, continuing); break; } free(name_buffer); if (rc) { (void)PLOGERR(klogErr, (klogErr, rc, "load failed", "severity=total,status=failure,accession=%s,errors=%u", G.outname, G.errCount)); } else { (void)PLOGMSG(klogInfo, (klogInfo, "loaded", "severity=total,status=success,accession=%s,errors=%u", G.outname, G.errCount)); } ArgsWhack(args); return rc; }
/* ArgsFlagsControl::onKeypress * Event handler called when a key is pressed in the textbox. Refresh * all the flag states. *******************************************************************/ void onKeypress(wxKeyEvent& event) { event.Skip(); updateCheckState(getArgValue()); }