本文整理汇总了C++中printHelp函数的典型用法代码示例。如果您正苦于以下问题:C++ printHelp函数的具体用法?C++ printHelp怎么用?C++ printHelp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了printHelp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv)
{
if ( argc == 2 )
{
if( (std::string(argv[1]) == "--help" ||
std::string(argv[1]) == "-h" ) )
{
printHelp();
return 0;
}
}
if (argc != 5)
{
printHelp();
return -1;
}
std::string urdf_file_name = argv[1];
std::string base_link_name = argv[2];
std::string end_effector_link_name = argv[3];
std::string ikin_ini_file_name = argv[4];
KDL::Tree kdl_tree;
KDL::Chain kdl_chain;
iCub::iKin::iKinLimb ikin_limb;
std::vector<std::string> joint_names;
KDL::JntArray min,max;
//
// URDF --> KDL::Tree
//
bool root_inertia_workaround = true;
if( !treeFromUrdfFile(urdf_file_name,kdl_tree,root_inertia_workaround) )
{
cerr << "urdf2dh: Could not parse urdf robot model" << endl;
std::cerr << "urdf2dh: Please open an issue at https://github.com/robotology-playground/idyntree/issues " << std::endl;
return EXIT_FAILURE;
}
//
// URDF --> position ranges
//
if( !jointPosLimitsFromUrdfFile(urdf_file_name,joint_names,min,max) )
{
cerr << "Could not parse urdf robot model limits" << endl;
return EXIT_FAILURE;
}
if( joint_names.size() != min.rows() ||
joint_names.size() != max.rows() ||
joint_names.size() == 0)
{
cerr << "Inconsistent joint limits got from urdf (nr of joints extracted: " << joint_names.size() << " ) " << endl;
return EXIT_FAILURE;
}
//
// KDL::Tree --> KDL::CoDyCo::UndirectedTree
// (for extracting arbitrary chains,
// using KDL::Tree you can just get chains where the base of the chain
// is proximal to the tree base with respect to the end effector.
//
KDL::CoDyCo::UndirectedTree undirected_tree(kdl_tree);
KDL::Tree kdl_rotated_tree = undirected_tree.getTree(base_link_name);
bool result = kdl_rotated_tree.getChain(base_link_name,end_effector_link_name,kdl_chain);
if( !result )
{
cerr << "urdf2dh: Impossible to find " << base_link_name << " or "
<< end_effector_link_name << " in the URDF." << endl;
return EXIT_FAILURE;
}
//
// Copy the limits extracted from the URDF to the chain
//
int nj = kdl_chain.getNrOfJoints();
KDL::JntArray chain_min(nj), chain_max(nj);
size_t seg_i, jnt_i;
for(seg_i=0,jnt_i=0; seg_i < kdl_chain.getNrOfSegments(); seg_i++)
{
const Segment & seg = kdl_chain.getSegment(seg_i);
if( seg.getJoint().getType() != KDL::Joint::None )
{
std::string jnt_name = seg.getJoint().getName();
// std::cerr << "searching for joint " << jnt_name << std::endl;
int tree_jnt = 0;
for(tree_jnt = 0; tree_jnt < joint_names.size(); tree_jnt++ )
{
//std::cerr << "joint_names[ " << tree_jnt << "] is " << joint_names[tree_jnt] << std::endl;
if( joint_names[tree_jnt] == jnt_name )
{
chain_min(jnt_i) = min(tree_jnt);
chain_max(jnt_i) = max(tree_jnt);
jnt_i++;
break;
}
//.........这里部分代码省略.........
示例2: parseCmdLine
int parseCmdLine(int argc, char *argv[]) {
int j, more;
if (argc < 3) {
printHelp();
return 0;
}
for (j = 1; j < argc; j++) {
more = ((j + 1) < argc);
if (!strcmp(argv[j], "--remove")) {
estgbconf.isRemove = 1;
} else if (!strcmp(argv[j], "--force-remove")) {
estgbconf.isRemove = 2;
} else if (!strcmp(argv[j], "--escape-seq")) {
estgbconf.needUnescape = 1;
} else if (!strcmp(argv[j], "--singleton")) {
estgbconf.isSingleton = 1;
} else if (!strcmp(argv[j], "--daemon")) {
estgbconf.isDaemonize = 1;
} else if (!strcmp(argv[j], "--mediagroup")) {
estgbconf.isPicsMediagroup = 1;
} else if (!strcmp(argv[j], "--repeat-send") && more) {
estgbconf.isScan = atoi(argv[++j]);
} else if (!strcmp(argv[j], "--time-sleep") && more) {
estgbconf.timeRescan = atoi(argv[++j]);
} else if (!strcmp(argv[j], "--animation")) {
estgbconf.isAnimation = 1;
} else if (!strcmp(argv[j], "--wildcard")) {
estgbconf.isWildcard = 1;
} else if (!strcmp(argv[j], "--weakconfig")) {
estgbconf.isWeakConfig = 1;
} else if (!strcmp(argv[j], "--sendpic") && more) {
estgbconf.imgfile = strdup(argv[++j]);
} else if (!strcmp(argv[j], "--sendvideo") && more) {
estgbconf.videofile = strdup(argv[++j]);
} else if (!strcmp(argv[j], "--sendtext") && more) {
estgbconf.text = strdup(argv[++j]);
} else if (!strcmp(argv[j], "--senddoc") && more) {
estgbconf.docfile = strdup(argv[++j]);
} else if (!strcmp(argv[j], "--sendaudio") && more) {
estgbconf.audiofile = strdup(argv[++j]);
} else if (!strcmp(argv[j], "--fileconfigs")) {
estgbconf.useFileConfig = 1;
} else if (!strcmp(argv[j], "--token") && more) {
estgbconf.token = strdup(argv[++j]);
} else if (!strcmp(argv[j], "--userid") && more) {
estgbconf.user_id = atoll(argv[++j]);
} else if (!strcmp(argv[j], "--path") && more) {
estgbconf.path = strdup(argv[++j]);
} else if (!strcmp(argv[j], "--comment") && more) {
estgbconf.comment = strdup(argv[++j]);
} else if (!strcmp(argv[j], "--proxy") && more) {
estgbconf.proxy_addr = strdup(argv[++j]);
} else if (!strcmp(argv[j], "--proxyauth") && more) {
estgbconf.proxy_auth = strdup(argv[++j]);
}
else if (!strcmp(argv[j], "--help")) {
printHelp();
return 0;
} else {
printHelp();
printConfig();
printf("Unknown or not enough arguments for option '%s'.\n\n",
argv[j]);
return 0;
}
}
return 1;
}
示例3: ImagePathInit
imagePathPars ImagePathInit(int argc, char *argv[],int * verbose)
{
imagePathPars par = {argc,0,
(char **)malloc(sizeof(char *) * argc),
(char **)malloc(sizeof(char *) * argc),
(char **)malloc(sizeof(char *) * argc),
(char **)malloc(sizeof(char *) * argc),
(char **)malloc(sizeof(char *) * argc)};
if (argc == 1)
{
printHelp();
}
else
{
//指针没学好的结果....
//*par.imagePath = (char *)malloc(sizeof(char *) * argc);
//*par.imageInputPath = (char *)malloc(sizeof(char *) * argc);
//*par.imageOutputPath = (char *)malloc(sizeof(char *) * argc);
//*par.imageInputName = (char *)malloc(sizeof(char *) * argc);
//*par.imageOutputName = (char *)malloc(sizeof(char *) * argc);
char inputPath[255] = "\0";
char inputName[255] = "\0";
char outputPath[255] = "\0";
char outputName[255] = "\0";
char exName[255] = "\0";
int j = 0;
int posSplit = -1;
int posDot = -1;
for (int i = 1; i < argc; i++)
{
if(strcmp("--version",argv[i]) == 0)
{
//输出版本信息
if (i != 1) exit(0);
printVersion();
par.imageNum = -1;
break;
}
else if(strcmp("-h",argv[i]) == 0 || strcmp("--help",argv[i]) == 0)
{
//输出help
if (i != 1) exit(0);
printHelp();
par.imageNum = -1;
break;
}
else if (strcmp("-v",argv[i]) == 0 || strcmp("--verbose",argv[i]) == 0)
{
//屏幕输出
*verbose = true;
}
else
{
//添加路径
par.imagePath[par.imageNum] = argv[i];
//从path中获取最后一个路径分隔符和.并将内容copy到inputPath中
j = 0;
posSplit = -1;
posDot = -1;
while(par.imagePath[par.imageNum][j])
{
inputPath[j] = par.imagePath[par.imageNum][j];
//Windows系统分隔符多一个":"
#ifdef WIN32
if (inputPath[j] == '\\' || inputPath[j] == '/' || inputPath[j] == ':')
#else
if (inputPath[j] == '\\' || inputPath[j] == '/')
#endif
{
posSplit = j;
}
else if (inputPath[j] == '.')
{
posDot = j;
}
j++;
}
inputPath[j] = '\0';
if(posSplit != -1)
{
//设置inputName
strcpy(inputName,&(inputPath[posSplit + 1]));
par.imageInputName[par.imageNum] = (char *)malloc(strlen(inputName) + 1);
strcpy(par.imageInputName[par.imageNum],inputName);
//设置inputPath
inputPath[posSplit + 1] = '\0';
par.imageInputPath[par.imageNum] = (char *)malloc(posSplit + strlen(inputName) + 2);
strcpy(par.imageInputPath[par.imageNum],inputPath);
strcat(par.imageInputPath[par.imageNum],inputName);
//设置outputPath
par.imageOutputPath[par.imageNum] = (char *)malloc(posSplit + strlen("_output") + 2);
strcpy(outputPath,inputPath);
strcpy(par.imageOutputPath[par.imageNum],outputPath);
}
else
{
//设置inputName
strcpy(inputName,inputPath);
par.imageInputName[par.imageNum] = (char *)malloc(strlen(inputName) + 1);
//.........这里部分代码省略.........
示例4: main
int main(int argc, char** argv) {
// Argument parsing
if ((argc == 1) ||
((argc >= 2) && (std::string("--help") == argv[1]))) {
printHelp();
return 0;
}
if ((argc == 2) && (std::string("--version") == argv[1])) {
printVersion();
return 0;
}
std::string src = "";
std::string dst = "";
// Figure out source and dest filenames
if (argc >= 4) {
if (std::string("-o") != argv[1]) {
printf("Invalid command line to GLSLCheck. Expected '-o' or"
" filename as 1st argument, found: '%s'\n", argv[1]);
return -1;
}
dst = argv[2];
src = argv[3];
} else {
src = argv[1];
}
if (! fileExists(src)) {
printf("GLSLCheck error : input file '%s' not found\n", src.c_str());
return -4;
}
if (endsWith(dst, "/") || endsWith(dst, "\\")) {
if (! fileExists(dst.substr(0, dst.size() - 1))) {
printf("GLSLCheck error : output directory '%s' not found\n", dst.c_str());
return -5;
}
// Add the filename part of src to dst, since dst is a directory
dst = dst + filenameBaseExt(src);
}
Mode mode;
if (endsWith(toLower(src), ".vert")) {
mode = VERTEX;
} else if (endsWith(toLower(src), ".frag")) {
mode = FRAGMENT;
} else {
printf("Invalid filename; source file must end with .vert or .frag\n");
return -2;
}
// We must create a GL context before loading extensions.
GWindowSettings settings;
settings.visible = false;
settings.width = 200;
settings.height = 200;
GWindow* window;
#ifdef G3D_WIN32
window = new Win32Window(settings);
#else
window = new SDLWindow(settings);
#endif
GLCaps::loadExtensions();
if (! VertexAndPixelShader::fullySupported()) {
printf("GLSL not supported by your graphics card and driver.\n");
return -3;
}
int result = check(mode, src);
if ((result == 0) && (dst != "")) {
copyFile(src, dst);
}
delete window;
return result;
}
示例5: parseArgs
/**
* Given an argument count and list, parses the arguments
* and sets the global options as desired
*
* @param argc
* The number of arguments
* @param argv
* The list of cmd line arguments
* @param paths
* A vector of strings to be filled with lint paths
*/
void parseArgs(int argc, char* argv[], vector<string> &paths) {
// Set default values
Options.RECURSIVE = false;
Options.CMODE = false;
Options.JSON = false;
Options.VERBOSE = false;
Options.LEVEL = Lint::ADVICE;
bool HELP = false;
bool l1 = false;
bool l2 = false;
bool l3 = false;
enum ArgType {
BOOL, INT
};
struct Arg {
ArgType type;
const void *ptr;
};
// Map values to their cmd line flags
Arg argHelp = { ArgType::BOOL, &HELP };
Arg argRecursive = { ArgType::BOOL, &Options.RECURSIVE };
Arg argCMode = { ArgType::BOOL, &Options.CMODE };
Arg argJSON = { ArgType::BOOL, &Options.JSON };
Arg argVerbose = { ArgType::BOOL, &Options.VERBOSE };
Arg argLevel = { ArgType::INT, &Options.LEVEL };
Arg argL1 = { ArgType::BOOL, &l1 };
Arg argL2 = { ArgType::BOOL, &l2 };
Arg argL3 = { ArgType::BOOL, &l3 };
static const unordered_map<string, Arg &> params = {
{ "-h", argHelp },
{ "--help", argHelp },
{ "-r", argRecursive },
{ "--recursive", argRecursive },
{ "-c", argCMode },
{ "--cmode", argCMode },
{ "-j", argJSON },
{ "--json", argJSON },
{ "-l", argLevel },
{ "--level", argLevel },
{ "-l1", argL1 },
{ "-l2", argL2 },
{ "-l3", argL3 },
{ "-v", argVerbose },
{ "--verbose", argVerbose }
};
// Loop over the given argument list
for (int i = 1; i < argc; ++i) {
// If the current argument is in the map
// then set its value to true
auto it = params.find(string(argv[i]));
if (it != params.end()) {
if (it->second.type == ArgType::BOOL) {
bool *arg = (bool*)it->second.ptr;
*arg = true;
}
else if (it->second.type == ArgType::INT) {
int *arg = (int*) it->second.ptr;
++i;
if (i >= argc) {
printf("Missing (int) value for parameter: %s\n\n",
it->first.c_str());
printHelp();
}
int val = atoi(argv[i]) - 1;
*arg = val;
continue;
}
}
else {
// Push another path onto the lint list
string p = argv[i];
if (p.back() == '/' || p.back() == '\\') {
p.erase(p.end()-1, p.end());
}
//.........这里部分代码省略.........
示例6: main
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
app.setOrganizationName("Graphem");
app.setApplicationName("Graphem");
QCA::Initializer crypto_init;
InputWidget *input = new InputWidget();
WindowMode mode = CONFIG;
int tries = 0; //ignored if mode != ASK
for(int i = 1; i < argc; i++) {
if(argv[i] == QString("--help")) {
printHelp(argv[0]);
return 0;
} else if(argv[i] == QString("--ask")) {
mode = ASK;
} else if(argv[i] == QString("--lock")) {
mode = LOCK;
} else if(argv[i] == QString("--tries")) {
if(i+1 >= argc)
break; //parameter not found
tries = QString(argv[i+1]).toInt();
i++;
} else if(argv[i] == QString("-v") or argv[i] == QString("--verbose")) {
input->auth()->setVerbose(true);
}
#ifndef NO_DEBUG
else if(argv[i] == QString("--print-data")) {
QObject::connect(input, SIGNAL(dataReady()),
input, SLOT(printData()));
} else if(argv[i] == QString("--print-pattern")) {
input->auth()->setPrintPattern(true);
}
#endif
else {
std::cerr << "Unknown command line option '" << argv[i] << "'\n";
printHelp(argv[0]);
return 1;
}
}
if(mode == CONFIG) { //show main window
MainWindow *main = new MainWindow(input);
//main->setWindowIcon(QIcon("icon.png"));
main->setWindowTitle(GRAPHEM_VERSION);
main->show();
} else {
if(!input->hashLoaded()) {
std::cerr << "Couldn't load key pattern! Please start Graphem without any arguments to create one.\n";
return 1;
}
QObject::connect(input->auth(), SIGNAL(passed()),
input, SLOT(quit()));
//input->setWindowIcon(QIcon("icon.png"));
if(mode == ASK) {
input->setWindowTitle(QObject::tr("%1 - Press ESC to cancel").arg(GRAPHEM_VERSION));
new QShortcut(QKeySequence("Esc"), input, SLOT(exit()));
input->auth()->setTries(tries);
input->showMaximized();
} else { //mode == LOCK
input->setWindowTitle(GRAPHEM_VERSION);
input->setGrab(true);
//for full screen, we strip WM decorations and resize the window manually
input->setWindowFlags(Qt::X11BypassWindowManagerHint);
input->setVisible(true);
QDesktopWidget dw;
input->setGeometry(dw.screenGeometry());
}
}
return app.exec();
}
示例7: parseArguments
struct config parseArguments(double argc, char** argv) {
struct config c;
c.exposure = -1;
c.pixel = 96;
c.frames = 1;
c.filename = std::string("default.fit");
c.aoi[0] = -1;
c.bmp = false;
c.jpg = false;
c.sex = false;
c.error = false;
c.blocks = 1;
c.degrees = 0.0;
char o;
static struct option opts[] = {
{"exposure", required_argument, 0, 'e'},
{"frames", required_argument, 0, 'n'},
{"pixelclock", required_argument, 0, 'p'},
{"file", required_argument, 0, 'f'},
{"aoi", required_argument, 0, 'a'},
{"bmp", no_argument, 0, 'b'},
{"jpg", no_argument, 0, 'j'},
{"sex", no_argument, 0, 's'},
{"help", no_argument, 0, 'h'},
{"blocks",required_argument, 0, 'm'},
{"degrees",required_argument, 0, 'd'},
{0, 0, 0, 0}
};
int i = 0;
o = getopt_long (argc, argv, "e:n:p:f:a:m:d:bjsh", opts, &i);
while (o != -1) {
std::string aoi;
int pos;
switch (o) {
case 0:
std::cout << "Option "<< opts[i].name;
if (optarg) {
std::cout << " with argument " << optarg << std::endl;
} else {
std::cout << " without argument." << std::endl;
}
break;
case 'e':
std::cout << "Known Option " << o << " with argument " << optarg << std::endl;
c.exposure = std::stoi(optarg);
break;
case 'n':
std::cout << "Known Option " << o << " with argument " << optarg << std::endl;
c.frames = std::stoi(optarg);
break;
case 'm':
std::cout << "Known Option " << o << " with argument " << optarg << std::endl;
c.blocks = std::stoi(optarg);
break;
case 'd':
std::cout << "Known Option " << o << " with argument " << optarg << std::endl;
c.degrees = std::stoi(optarg);
std::cout << "Known Option " << o << " with argument " << c.degrees << std::endl;
break;
case 'p':
std::cout << "Known Option " << o << " with argument " << optarg << std::endl;
c.pixel = std::stoi(optarg);
break;
case 'f':
std::cout << "Known Option " << o << " with argument " << optarg << std::endl;
c.filename = optarg;
break;
case 'a':
std::cout << "Known Option " << o << " with argument " << optarg << std::endl;
aoi = std::string(optarg);
if(std::count(aoi.begin(), aoi.end(), ',') != 3) {
std::cout << "Error!" << std::endl;
c.error = true;
} else {
for (int i = 0; i < 4; i++) {
pos = aoi.find(',');
if (pos != aoi.npos) {
c.aoi[i] = std::stoi(aoi.substr(0, pos));
aoi = aoi.substr(pos+1, aoi.size()-pos);
} else {
c.aoi[i] = std::stoi(aoi);
}
}
}
break;
case 'b':
c.bmp = true;
break;
case 'j':
c.jpg = true;
break;
case 's':
c.sex = true;
break;
case 'h':
printHelp(argv[0]);
c.error = true;
break;
default:
std::cout << "Unknown option " << o;
//.........这里部分代码省略.........
示例8: showError
static void showError(const char * pgm_msg) {
Serial.pgm_print(PSTR("Error "));
Serial.pgm_println(pgm_msg);
Serial.println();
printHelp();
}
示例9: main
int main( int argc, char **argv )
{
QCoreApplication app(argc, argv);
PolyArchiveExtractor qsaExtractor( QStringList() << "qsa",
"qsauncompress \1 \2" );
PolyArchiveExtractor tarExtractor( QStringList() << "tar",
"tar -C \2 -xf \1" );
PolyArchiveExtractor tazExtractor( QStringList() << "taz",
"tar -C \2 -Zxf \1" );
PolyArchiveExtractor tbz2Extractor( QStringList() << "tbz" << "tbz2",
"tar -C \2 -jxf \1" );
PolyArchiveExtractor tgzExtractor( QStringList() << "tgz",
"tar -C \2 -zxf \1" );
PolyArchiveExtractor zipExtractor( QStringList() << "zip",
"unzip \1 -d \2" );
PolyUncompressor bz2Uncompressor( QStringList() << "bz" << "bz2",
"bunzip2 -c \1 > \2" );
PolyUncompressor gzAndZUncompressor( QStringList() << "gz" << "z" << "Z",
"gunzip -c \1 > \2" );
PolyUncompressor zipUncompressor( QStringList() << "zip",
"unzip -c \1 > \2" );
CCodeParser cParser;
CppCodeParser cppParser;
Tree *cppTree = treeForLanguage( cppParser.language() );
QsCodeParser qsParser( cppTree );
QsaKernelParser qsaKernelParser( cppTree );
JambiApiParser jambiParser(cppTree);
PlainCodeMarker plainMarker;
CppCodeMarker cppMarker;
JavaCodeMarker javaMarker;
QsCodeMarker qsMarker;
ApiGenerator apiGenerator;
HtmlGenerator htmlGenerator;
JavadocGenerator javadocGenerator;
LoutGenerator loutGenerator;
ManGenerator manGenerator;
SgmlGenerator smglGenerator;
WebXMLGenerator webxmlGenerator;
QStringList qdocFiles;
QString opt;
int i = 1;
while ( i < argc ) {
opt = argv[i++];
if ( opt == "-help" ) {
printHelp();
return EXIT_SUCCESS;
} else if ( opt == "-version" ) {
printVersion();
return EXIT_SUCCESS;
} else if ( opt == "--" ) {
while ( i < argc )
qdocFiles.append( argv[i++] );
} else if ( opt.startsWith("-D") ) {
QString define = opt.mid(2);
defines += define;
} else if (opt == "-slow") {
slow = true;
} else {
qdocFiles.append( opt );
}
}
if ( qdocFiles.isEmpty() ) {
printHelp();
return EXIT_FAILURE;
}
foreach (QString qf, qdocFiles)
processQdocconfFile( qf );
qDeleteAll(trees);
return EXIT_SUCCESS;
}
示例10: main
int main(int argc, char** argv )
{
int fd; /* file descriptor */
char comm[20]; /* point to command string */
bzero(comm, sizeof(comm));
char rbuf[RCVBUF_SIZE]; /* receive buffer */
__tod_t texp; /* to receive the expended time */
int r;
char* port = "/dev/ttyUSB0";
speed_t speed = B9600;
switch ( argc )
{
case 2:
if (!strcmp(argv[1], "--help") || !strcmp (argv[1], "-h") )
printManual();
else
printHelp();
exit(-1);
case 3:
contstr(argv[1], argv[2], comm );
break;
case 4:
contstr( argv[1], argv[2], comm );
speed = consspeed( argv[3] );
break;
case 5:
contstr( argv[1], argv[2], comm );
speed = consspeed( argv[3] );
port = argv[4];
break;
default:
printHelp();
exit ( -1 );
}
fd = sio_open( port, speed, DATA_BITS_8, NO_PARITY,
ONE_STOP_BIT);
if (fd == ERR_PORT_OPEN) {
printf("open port failed!\n");
return (-1);
}
comm[strlen(comm)] = '\r';
printf("send command: %s\n", comm );
sio_set_noncan(fd);
sio_set_timer(fd, 0, 10); /* set timeout for 1 sec */
r = i7k_send_readt(fd, comm, rbuf, RCVBUF_SIZE, &texp);
//char* cmd = "$01P\r";
//r = i7k_send_readt(fd, cmd, rbuf, RCVBUF_SIZE, &texp);
char buff[16];
memcpy (buff, rbuf+1, 15);
switch (r) {
case 0:
printf("time-out!\ntime expended: %llu us\n", texp);
break;
case -1:
printf("error!\ntime expended: %llu us\n", texp);
break;
default:
printf("ret: %s\ntime expended: %llu us\n", buff, texp);
break;
}
sio_close(fd);
return (0);
}
示例11: switch
void RepRapPCBTest::loop() {
pcb.update();
reader.update();
btn.update();
led.update();
if (reader.available()) {
char *line = reader.readln();
Serial.println(line);
switch (line++[0]) {
case 'i':
stop();
repRapMode = InitializeAllMotors;
modeState= 0;
case 'a':
doAxis(pgmAxisNameX, line, pcb.axisX);
doAxis(pgmAxisNameY, line, pcb.axisY);
doAxis(pgmAxisNameZ, line, pcb.axisZ);
break;
case 'x':
doAxis(pgmAxisNameX, line, pcb.axisX);
break;
case 'y':
doAxis(pgmAxisNameY, line, pcb.axisY);
break;
case 'z':
doAxis(pgmAxisNameZ, line, pcb.axisZ);
break;
case 'h':
printHelp();
break;
case 's':
stop();
break;
default:
showError(PSTR("invalid command"));
break;
}
}
switch (repRapMode) {
case AlterDelayBetweenSteps:
doAlterDelayBetweenSteps();
break;
case GotoStep:
doGotoStep();
break;
case DetermineAvailableSteps:
doDetermineAvailableSteps();
break;
case MoveForthAndBackAtSpeed:
doMoveForthAndBackAtSpeed();
break;
case InitializeAllMotors:
doInitializeAllMotors();
break;
case StepTicking:
doStepTicking();
if (btn.isClicked()) {
modeState = !modeState;
btn.reset();
}
break;
case Idle:
default:
break;
}
if (btn.isLongClicked()) {
stop();
printHelp();
} else if (btn.isClicked()) {
stop();
}
}
示例12: setGlobalAuthorizationManager
int Tool::main( int argc , char ** argv, char ** envp ) {
static StaticObserver staticObserver;
setGlobalAuthorizationManager(new AuthorizationManager(new AuthzManagerExternalStateMock()));
mongo::runGlobalInitializersOrDie(argc, argv, envp);
// hide password from ps output
for (int i=0; i < (argc-1); ++i) {
if (!strcmp(argv[i], "-p") || !strcmp(argv[i], "--password")) {
char* arg = argv[i+1];
while (*arg) {
*arg++ = 'x';
}
}
}
if (!toolGlobalParams.useDirectClient) {
if (toolGlobalParams.noconnection) {
// do nothing
}
else {
string errmsg;
ConnectionString cs = ConnectionString::parse(toolGlobalParams.connectionString,
errmsg);
if ( ! cs.isValid() ) {
toolError() << "invalid hostname [" << toolGlobalParams.connectionString << "] "
<< errmsg << std::endl;
::_exit(-1);
}
_conn = cs.connect( errmsg );
if ( ! _conn ) {
toolError() << "couldn't connect to [" << toolGlobalParams.connectionString
<< "] " << errmsg << std::endl;
::_exit(-1);
}
toolInfoOutput() << "connected to: " << toolGlobalParams.connectionString
<< std::endl;
}
}
else {
verify( lastError.get( true ) );
Client::initThread("tools");
_conn = new DBDirectClient();
storageGlobalParams.dbpath = toolGlobalParams.dbpath;
try {
acquirePathLock();
}
catch ( DBException& ) {
toolError() << std::endl << "If you are running a mongod on the same "
"path you should connect to that instead of direct data "
"file access" << std::endl << std::endl;
dbexit( EXIT_FS );
::_exit(EXIT_FAILURE);
}
FileAllocator::get()->start();
dur::startup();
}
int ret = -1;
try {
if (!toolGlobalParams.useDirectClient && !toolGlobalParams.noconnection)
auth();
ret = run();
}
catch ( DBException& e ) {
toolError() << "assertion: " << e.toString() << std::endl;
ret = -1;
}
catch(const boost::filesystem::filesystem_error &fse) {
/*
https://jira.mongodb.org/browse/SERVER-2904
Simple tools that don't access the database, such as
bsondump, aren't throwing DBExceptions, but are throwing
boost exceptions.
The currently available set of error codes don't seem to match
boost documentation. boost::filesystem::not_found_error
(from http://www.boost.org/doc/libs/1_31_0/libs/filesystem/doc/exception.htm)
doesn't seem to exist in our headers. Also, fse.code() isn't
boost::system::errc::no_such_file_or_directory when this
happens, as you would expect. And, determined from
experimentation that the command-line argument gets turned into
"\\?" instead of "/?" !!!
*/
#if defined(_WIN32)
if (/*(fse.code() == boost::system::errc::no_such_file_or_directory) &&*/
(fse.path1() == "\\?"))
printHelp(cerr);
else
#endif // _WIN32
toolError() << "error: " << fse.what() << std::endl;
//.........这里部分代码省略.........
示例13: main
int main(int argc, char *argv[]) {
std::string command,
ucMode,
volMode,
inodeMapFile,
diskMapFile;
uint64_t maxUcBlockSize;
po::options_description desc("Allowed Options");
po::positional_options_description posOpts;
posOpts.add("command", 1);
posOpts.add("ev-files", -1);
desc.add_options()
("help", "produce help message")
("command", po::value< std::string >(&command), "command to perform [info|dumpimg|dumpfs|dumpfiles]")
("overview-file", po::value< std::string >(), "output disk overview information")
("unallocated", po::value< std::string >(&ucMode)->default_value("none"), "how to handle unallocated [none|fragment|block]")
("max-unallocated-block-size", po::value< uint64_t >(&maxUcBlockSize)->default_value(std::numeric_limits<uint64_t>::max()), "Maximum size of an unallocated entry, in blocks")
("ev-files", po::value< std::vector< std::string > >(), "evidence files")
("inode-map-file", po::value<std::string>(&inodeMapFile)->default_value(""), "optional file to output containing directory entry to inode map")
("disk-map-file", po::value<std::string>(&diskMapFile)->default_value(""), "optional file to output containing disk data to inode map");
po::variables_map vm;
try {
po::store(po::command_line_parser(argc, argv).options(desc).positional(posOpts).run(), vm);
po::notify(vm);
std::shared_ptr<LbtTskAuto> walker;
std::vector< std::string > imgSegs;
if (vm.count("ev-files")) {
imgSegs = vm["ev-files"].as< std::vector< std::string > >();
}
if (vm.count("help")) {
printHelp(desc);
}
else if (vm.count("command") && vm.count("ev-files") && (walker = createVisitor(command, std::cout, imgSegs))) {
std_binary_io();
boost::scoped_array< const char* > segments(new const char*[imgSegs.size()]);
for (unsigned int i = 0; i < imgSegs.size(); ++i) {
segments[i] = imgSegs[i].c_str();
}
if (0 == walker->openImageUtf8(imgSegs.size(), segments.get(), TSK_IMG_TYPE_DETECT, 0)) {
if (vm.count("overview-file")) {
std::ofstream file(vm["overview-file"].as<std::string>().c_str(), std::ios::out);
file << *(walker->getImage(imgSegs));
file.close();
}
walker->setVolFilterFlags((TSK_VS_PART_FLAG_ENUM)(TSK_VS_PART_FLAG_ALLOC | TSK_VS_PART_FLAG_UNALLOC | TSK_VS_PART_FLAG_META));
walker->setFileFilterFlags((TSK_FS_DIR_WALK_FLAG_ENUM)(TSK_FS_DIR_WALK_FLAG_RECURSE | TSK_FS_DIR_WALK_FLAG_UNALLOC | TSK_FS_DIR_WALK_FLAG_ALLOC));
if (ucMode == "fragment") {
walker->setUnallocatedMode(LbtTskAuto::FRAGMENT);
walker->setMaxUnallocatedBlockSize(maxUcBlockSize);
}
else if (ucMode == "block") {
walker->setUnallocatedMode(LbtTskAuto::BLOCK);
}
else {
walker->setUnallocatedMode(LbtTskAuto::NONE);
}
if (0 == walker->start()) {
walker->startUnallocated();
walker->finishWalk();
std::vector<std::future<void>> futs;
if (vm.count("disk-map-file") && command == "dumpfs") {
futs.emplace_back(std::async(outputDiskMap, diskMapFile, walker));
}
if (vm.count("inode-map-file") && command == "dumpfs") {
futs.emplace_back(std::async(outputInodeMap, inodeMapFile, walker));
}
for (auto& fut: futs) {
fut.get();
}
return 0;
}
else {
std::cout.flush();
std::cerr << "Had an error parsing filesystem" << std::endl;
for (auto& err: walker->getErrorList()) {
std::cerr << err.msg1 << " " << err.msg2 << std::endl;
}
}
}
else {
std::cerr << "Had an error opening the evidence file" << std::endl;
for (unsigned int i = 0; i < imgSegs.size(); ++i) {
std::cerr << " ** seg[" << i << "] = " << imgSegs[i] << std::endl;
}
return 1;
}
}
else {
std::cerr << "Error: did not understand arguments\n\n";
printHelp(desc);
return 1;
}
}
catch (std::exception& err) {
//.........这里部分代码省略.........
示例14: main
int main(int argc,char** argv){
//Seed the timer.
srand(time(0));
//printf("Begin GPU PBF..\n");
//Does the user need help?
if(wasArgSpecified("--help",argv,argc)!=0){
printHelp();
return 0;
}
//Initialize with default configuration.
BloomOptions_t bloomOptions_t;
setDefault(&bloomOptions_t);
//Parse the user's configuration.
getConfiguration(&bloomOptions_t,argv,argc);
bloomOptions_t.prob = calculateProb(bloomOptions_t.freq,bloomOptions_t.numKeys);
bloomOptions_t.size = calculateSize(bloomOptions_t.numHashes,bloomOptions_t.numKeys,bloomOptions_t.prob);
//showDetails(&bloomOptions_t);
//Create the bloom filter being used, and initialize it with all 0's.
char* bloom = (char*)malloc(sizeof(char)*bloomOptions_t.size);
memset(bloom,0,bloomOptions_t.size);
//Allocate the GPU bloom filter.
char* dev_bloom = allocateAndCopyChar(bloom,bloomOptions_t.size);
if(dev_bloom==0){
printf("Could not allocate the bloom filter \n");
return -1;
}
//Read input keys and insert to PBF
char* fileName = (char*)malloc(sizeof(char)*50);
sprintf(fileName,"./data/total_keys.txt");
WordAttributes* allKeys = loadFileByName(fileName);
int total_keys = allKeys->numWords;
int randOffset = rand()%2432+10;
insertWordsPBF(dev_bloom,bloomOptions_t.size,allKeys->currentWords,allKeys->positions,allKeys->numWords,allKeys->numBytes,bloomOptions_t.numHashes,bloomOptions_t.device,bloomOptions_t.prob,randOffset);
freeWordAttributes(allKeys);
//Query PBF
sprintf(fileName,"./data/distinct_keys.txt");
WordAttributes* distinctKeys = loadFileByName(fileName);
int distinct_keys = distinctKeys->numWords;
//printf("distinct keys = %d, total keys = %d\n",distinct_keys,total_keys);
int* results = (int*)calloc(sizeof(int)*distinct_keys,sizeof(int));
queryWordsPBF(dev_bloom,bloomOptions_t.size,distinctKeys->currentWords,distinctKeys->positions,distinctKeys->numWords,
distinctKeys->numBytes,bloomOptions_t.numHashes,bloomOptions_t.device,results);
freeWordAttributes(distinctKeys);
//Read the actual frequency of keys
int* actual = (int*)calloc(sizeof(int)*distinct_keys,sizeof(int));
FILE* actualFreqFile = fopen("./data/freq.txt","r");
if(!actualFreqFile){
printf("Can not open actual frequency file!\n");
return -1;
}
for(int i = 0; i < distinct_keys; i++){
char* temp = (char*)malloc(sizeof(char)*15);
if(fgets(temp,15,actualFreqFile)!=NULL){
int len = strlen(temp);
temp[len-1]='\0';
actual[i]=atoi(temp);
//printf("%d: actual = %d\n",i,actual[i]);
}
free(temp);
}
//Copy the bloom filter to main memory.
//copyCharsToHost(bloom,dev_bloom,bloomOptions_t.size);
//Write the result to output file
//data format: index, number of 1s, calculated frequency, actual frequency, relative error
if(bloomOptions_t.pbfOutput){
FILE* outputFile = fopen(bloomOptions_t.pbfOutput,"w");
writeStats(outputFile,actual,results,distinct_keys, bloomOptions_t.numHashes,bloomOptions_t.prob,total_keys,bloomOptions_t.size);
fclose(outputFile);
}
free(fileName);
free(actual);
free(results);
freeChars(dev_bloom);
free(bloom);
//printf("\n");
return 0;
}
示例15: parseCommandLine
static int parseCommandLine(int argc, const char **argv, Params *params)
{
memset(params, 0, sizeof(Params));
if (argc < 2 || argv[1][0] != '-')
return printHelp("Invalid command");
int index = 1;
const char *arg = argv[index];
if (!strcmp(arg, "-l"))
{
if (argc != 2)
return printHelp("No arguments are allowed after '-l'\n");
params->command = 'l';
return 0;
}
if (!strcmp(arg, "-r"))
{
if (argc < 3)
return printHelp("No reader number are specified after '-r'\n");
params->readerNr = atoi(argv[2]);
index += 2;
arg = argv[index];
}
if (!strcmp(arg, "-s"))
{
if (argc - index != 2)
return printHelp("Only 1 argument allowed after '-s'\n");
params->command = 's';
params->timeout = atoi(argv[index + 1]);
return 0;
}
if (!strcmp(arg, "-a"))
{
if (argc - index < 2)
return printHelp("No arguments specified after '-a'\n");
params->command = 'a';
params->apduCount = argc - index - 1;
params->apdus = argv + (index + 1);
}
else if (!strcmp(arg, "-t"))
{
if (argc - index > 2)
return printHelp("Only 1 argument allowed after '-t'\n");
params->command = 't';
if (argc - index == 2)
params->chipnr = argv[index + 1];
}
else if (!strcmp(arg, "-f"))
{
if (argc - index > 1)
return printHelp("No arguments are allowed after '-f'\n");
params->command = 'f';
}
else if (!strcmp(arg, "-x"))
{
if (argc < 3)
return printHelp("No tests specified for '-x'\n");
params->command = 'x';
params->test = atoi(argv[2]);
}
else
return printHelp("Unknown command\n");
return 0;
}