int main(int argc, char **argv) { std::vector<std::string> args; bool extrinsic = true, dominant = false, align_to_boundaries = false; bool fullscreen = false, help = false, deterministic = false, compat = false; int rosy = 4, posy = 4, face_count = -1, vertex_count = -1; uint32_t knn_points = 10, smooth_iter = 2; Float crease_angle = -1, scale = -1; std::string batchOutput; #if defined(__APPLE__) bool launched_from_finder = false; #endif try { for (int i=1; i<argc; ++i) { if (strcmp("--fullscreen", argv[i]) == 0 || strcmp("-F", argv[i]) == 0) { fullscreen = true; } else if (strcmp("--help", argv[i]) == 0 || strcmp("-h", argv[i]) == 0) { help = true; } else if (strcmp("--deterministic", argv[i]) == 0 || strcmp("-d", argv[i]) == 0) { deterministic = true; } else if (strcmp("--intrinsic", argv[i]) == 0 || strcmp("-i", argv[i]) == 0) { extrinsic = false; } else if (strcmp("--boundaries", argv[i]) == 0 || strcmp("-b", argv[i]) == 0) { align_to_boundaries = true; } else if (strcmp("--threads", argv[i]) == 0 || strcmp("-t", argv[i]) == 0) { if (++i >= argc) { cerr << "Missing thread count!" << endl; return -1; } nprocs = str_to_uint32_t(argv[i]); } else if (strcmp("--smooth", argv[i]) == 0 || strcmp("-S", argv[i]) == 0) { if (++i >= argc) { cerr << "Missing smoothing iteration count argument!" << endl; return -1; } smooth_iter = str_to_uint32_t(argv[i]); } else if (strcmp("--knn", argv[i]) == 0 || strcmp("-k", argv[i]) == 0) { if (++i >= argc) { cerr << "Missing knn point count argument!" << endl; return -1; } knn_points = str_to_uint32_t(argv[i]); } else if (strcmp("--crease", argv[i]) == 0 || strcmp("-c", argv[i]) == 0) { if (++i >= argc) { cerr << "Missing crease angle argument!" << endl; return -1; } crease_angle = str_to_float(argv[i]); } else if (strcmp("--rosy", argv[i]) == 0 || strcmp("-r", argv[i]) == 0) { if (++i >= argc) { cerr << "Missing rotation symmetry type!" << endl; return -1; } rosy = str_to_int32_t(argv[i]); } else if (strcmp("--posy", argv[i]) == 0 || strcmp("-p", argv[i]) == 0) { if (++i >= argc) { cerr << "Missing position symmetry type!" << endl; return -1; } posy = str_to_int32_t(argv[i]); if (posy == 6) posy = 3; } else if (strcmp("--scale", argv[i]) == 0 || strcmp("-s", argv[i]) == 0) { if (++i >= argc) { cerr << "Missing scale argument!" << endl; return -1; } scale = str_to_float(argv[i]); } else if (strcmp("--faces", argv[i]) == 0 || strcmp("-f", argv[i]) == 0) { if (++i >= argc) { cerr << "Missing face count argument!" << endl; return -1; } face_count = str_to_int32_t(argv[i]); } else if (strcmp("--vertices", argv[i]) == 0 || strcmp("-v", argv[i]) == 0) { if (++i >= argc) { cerr << "Missing vertex count argument!" << endl; return -1; } vertex_count = str_to_int32_t(argv[i]); } else if (strcmp("--output", argv[i]) == 0 || strcmp("-o", argv[i]) == 0) { if (++i >= argc) { cerr << "Missing batch mode output file argument!" << endl; return -1; } batchOutput = argv[i]; } else if (strcmp("--dominant", argv[i]) == 0 || strcmp("-D", argv[i]) == 0) { dominant = true; } else if (strcmp("--compat", argv[i]) == 0 || strcmp("-C", argv[i]) == 0) { compat = true; #if defined(__APPLE__) } else if (strncmp("-psn", argv[i], 4) == 0) { launched_from_finder = true; #endif } else { if (strncmp(argv[i], "-", 1) == 0) { cerr << "Invalid argument: \"" << argv[i] << "\"!" << endl; help = true; } args.push_back(argv[i]); } } } catch (const std::exception &e) { cout << "Error: " << e.what() << endl; help = true; } if ((posy != 3 && posy != 4) || (rosy != 2 && rosy != 4 && rosy != 6)) { cerr << "Error: Invalid symmetry type!" << endl; help = true; } int nConstraints = 0; nConstraints += scale > 0 ? 1 : 0; nConstraints += face_count > 0 ? 1 : 0; nConstraints += vertex_count > 0 ? 1 : 0; if (nConstraints > 1) { cerr << "Error: Only one of the --scale, --face and --vertices parameters can be used at once!" << endl; help = true; } if (args.size() > 1 || help || (!batchOutput.empty() && args.size() == 0)) { cout << "Syntax: " << argv[0] << " [options] <input mesh / point cloud / application state snapshot>" << endl; cout << "Options:" << endl; cout << " -o, --output <output> Writes to the specified PLY/OBJ output file in batch mode" << endl; cout << " -t, --threads <count> Number of threads used for parallel computations" << endl; cout << " -d, --deterministic Prefer (slower) deterministic algorithms" << endl; cout << " -c, --crease <degrees> Dihedral angle threshold for creases" << endl; cout << " -S, --smooth <iter> Number of smoothing & ray tracing reprojection steps (default: 2)" << endl; cout << " -D, --dominant Generate a tri/quad dominant mesh instead of a pure tri/quad mesh" << endl; cout << " -i, --intrinsic Intrinsic mode (extrinsic is the default)" << endl; cout << " -b, --boundaries Align to boundaries (only applies when the mesh is not closed)" << endl; cout << " -r, --rosy <number> Specifies the orientation symmetry type (2, 4, or 6)" << endl; cout << " -p, --posy <number> Specifies the position symmetry type (4 or 6)" << endl; cout << " -s, --scale <scale> Desired world space length of edges in the output" << endl; cout << " -f, --faces <count> Desired face count of the output mesh" << endl; cout << " -v, --vertices <count> Desired vertex count of the output mesh" << endl; cout << " -C, --compat Compatibility mode to load snapshots from old software versions" << endl; cout << " -k, --knn <count> Point cloud mode: number of adjacent points to consider" << endl; cout << " -F, --fullscreen Open a full-screen window" << endl; cout << " -h, --help Display this message" << endl; return -1; } if (args.size() == 0) cout << "Running in GUI mode, start with -h for instructions on batch mode." << endl; tbb::task_scheduler_init init(nprocs == -1 ? tbb::task_scheduler_init::automatic : nprocs); if (!batchOutput.empty() && args.size() == 1) { try { batch_process(args[0], batchOutput, rosy, posy, scale, face_count, vertex_count, crease_angle, extrinsic, align_to_boundaries, smooth_iter, knn_points, !dominant, deterministic); return 0; } catch (const std::exception &e) { cerr << "Caught runtime error : " << e.what() << endl; return -1; } } try { nanogui::init(); #if defined(__APPLE__) if (launched_from_finder) nanogui::chdir_to_bundle_parent(); #endif { nanogui::ref<Viewer> viewer = new Viewer(fullscreen, deterministic); viewer->setVisible(true); if (args.size() == 1) { if (Serializer::isSerializedFile(args[0])) { viewer->loadState(args[0], compat); } else { viewer->loadInput(args[0], crease_angle, scale, face_count, vertex_count, rosy, posy, knn_points); viewer->setExtrinsic(extrinsic); } } nanogui::mainloop(); } nanogui::shutdown(); } catch (const std::runtime_error &e) { std::string error_msg = std::string("Caught a fatal error: ") + std::string(e.what()); #if defined(_WIN32) MessageBoxA(nullptr, error_msg.c_str(), NULL, MB_ICONERROR | MB_OK); #else std::cerr << error_msg << endl; #endif return -1; } return EXIT_SUCCESS; }
int main(int argc, char **argv) { sqlite3 *db; int option_index, option; if( argc < 3 ){ print_help(NULL); return 1; } db = NULL; option_index = 0; static struct option long_options[] = { {"batch", 0, 0, 'b'}, {"clean", 2, 0, 'c'}, {"export", 2, 0, 'e'}, {"h", 0, 0, 'h'}, {"help", 0, 0, 'h'}, {"import", 2, 0, 'i'}, {"sql", 1, 0, 's'}, {"stats", 2, 0, 't'}, {"statistics", 2, 0, 't'}, {"verify", 2, 0, 'v'}, {"vacuum", 2, 0, 'c'}, // TODO: implement options like '-e essid' to limit // operations to a certain essid where possible {"essid", 1, 0, 'd'}, {0, 0, 0, 0 } }; option = getopt_long( argc, argv, "bc:d:e:hi:s:t:v:", long_options, &option_index ); if( option > 0 ) { switch (option) { case 'b': // Batch if ( check_for_db(&db, argv[1], 0, 1) ) { return 1; } batch_process(db); break; case 'c': // Clean if ( check_for_db(&db, argv[1], 0, 0) ) { return 1; } vacuum(db, (argc > 3 && strcasecmp(argv[3],"all") == 0) ? 1 : 0); break; case 'e': if (argc < 4) { print_help("You must specify an export format."); } else if (strcmp(argv[3],"cowpatty")==0) { if (argc < 6) { print_help("You must specify essid and output file."); } else { // Export if ( check_for_db(&db, argv[1], 0, 0) ) { return 1; } export_cowpatty(db,argv[4],argv[5]); } } else { print_help("Invalid export format specified."); } break; case ':' : case '?' : case 'h': // Show help print_help(NULL); break; case 'i': // Import if (argc < 5) { print_help("You must specifiy an import format and a file."); } else if (strcasecmp(argv[3], IMPORT_COWPATTY) == 0) { if ( check_for_db(&db, argv[1], 1, 0) ) { return 1; } import_cowpatty(db,argv[4]); } else if (strcasecmp(argv[3], IMPORT_ESSID) == 0) { if ( check_for_db(&db, argv[1], 1, 0) ) { return 1; } import_ascii(db, IMPORT_ESSID,argv[4]); } else if (strcasecmp(argv[3], IMPORT_PASSWD) == 0 || strcasecmp(argv[3],"password") == 0) { if ( check_for_db(&db, argv[1], 1, 0) ) { return 1; } import_ascii(db,IMPORT_PASSWD, argv[4]); } else { print_help("Invalid import format specified."); return 1; } break; case 's': // SQL // We don't know if the SQL order is changing the file or not if ( check_for_db(&db, argv[1], 0, 0) ) { return 1; } sql_stdout(db, argv[3], 0); break; case 't': // Stats if ( check_for_db(&db, argv[1], 0, 1) ) { return 1; } show_stats(db, (argv[3] == NULL) ? 0 : 1); break; case 'v': // Verify if ( check_for_db(&db, argv[1], 0, (argc > 3 && strcasecmp(argv[3],"all")==0) ? 0 : 1) ) { return 1; } verify(db, (argc > 3 && strcasecmp(argv[3],"all")==0) ? 1 : 0); break; default: print_help("Invalid option"); break; } } else { print_help(NULL); } if (db) sqlite3_close(db); return 0; }
int main(int argc, char **argv) { struct zint_symbol *my_symbol; int c; int error_number; int rotate_angle; int generated; int batch_mode; error_number = 0; rotate_angle = 0; generated = 0; my_symbol = ZBarcode_Create(); my_symbol->input_mode = UNICODE_MODE; batch_mode = 0; if(argc == 1) die(help_usage); while(1) { int option_index = 0; static struct option long_options[] = { {"help", 0, 0, 'h'}, {"types", 0, 0, 't'}, {"bind", 0, 0, 0}, {"box", 0, 0, 0}, {"directeps", 0, 0, 0}, {"directpdf", 0, 0, 0}, {"directpng", 0, 0, 0}, {"directsvg", 0, 0, 0}, {"dump", 0, 0, 0}, {"barcode", 1, 0, 'b'}, {"height", 1, 0, 0}, {"whitesp", 1, 0, 'w'}, {"border", 1, 0, 0}, {"data", 1, 0, 'd'}, {"output", 1, 0, 'o'}, {"input", 1, 0, 'i'}, {"fg", 1, 0, 0}, {"bg", 1, 0, 0}, {"cols", 1, 0, 0}, {"vers", 1, 0, 0}, {"rotate", 1, 0, 0}, {"secure", 1, 0, 0}, {"reverse", 1, 0, 'r'}, {"mode", 1, 0, 0}, {"primary", 1, 0, 0}, {"scale", 1, 0, 0}, {"gs1", 0, 0, 0}, {"kanji", 0, 0, 0}, {"sjis", 0, 0, 0}, {"binary", 0, 0, 0}, {"notext", 0, 0, 0}, {"square", 0, 0, 0}, {"init", 0, 0, 0}, {"smalltext", 0, 0, 0}, {"batch", 0, 0, 0}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, "htb:w:d:o:i:rcmp", long_options, &option_index); if(c == -1) break; switch(c) { case 0: if(!strcmp(long_options[option_index].name, "bind")) { my_symbol->output_options += BARCODE_BIND; } if(!strcmp(long_options[option_index].name, "box")) { my_symbol->output_options += BARCODE_BOX; } if(!strcmp(long_options[option_index].name, "init")) { my_symbol->output_options += READER_INIT; } if(!strcmp(long_options[option_index].name, "smalltext")) { my_symbol->output_options += SMALL_TEXT; } if(!strcmp(long_options[option_index].name, "directeps")) { my_symbol->output_options += BARCODE_STDOUT; strncpy(my_symbol->outfile, "dummy.eps", 10); } if(!strcmp(long_options[option_index].name, "directpdf")) { my_symbol->output_options += BARCODE_STDOUT; strncpy(my_symbol->outfile, "dummy.pdf", 10); } if(!strcmp(long_options[option_index].name, "directpng")) { my_symbol->output_options += BARCODE_STDOUT; strncpy(my_symbol->outfile, "dummy.png", 10); } if(!strcmp(long_options[option_index].name, "directsvg")) { my_symbol->output_options += BARCODE_STDOUT; strncpy(my_symbol->outfile, "dummy.svg", 10); } if(!strcmp(long_options[option_index].name, "dump")) { my_symbol->output_options += BARCODE_STDOUT; strncpy(my_symbol->outfile, "dummy.txt", 10); } if(!strcmp(long_options[option_index].name, "gs1")) { my_symbol->input_mode = GS1_MODE; } if(!strcmp(long_options[option_index].name, "kanji")) { my_symbol->input_mode = KANJI_MODE; } if(!strcmp(long_options[option_index].name, "sjis")) { my_symbol->input_mode = SJIS_MODE; } if(!strcmp(long_options[option_index].name, "binary")) { my_symbol->input_mode = DATA_MODE; } if(!strcmp(long_options[option_index].name, "fg")) { strncpy(my_symbol->fgcolour, optarg, 7); } if(!strcmp(long_options[option_index].name, "bg")) { strncpy(my_symbol->bgcolour, optarg, 7); } if(!strcmp(long_options[option_index].name, "notext")) { my_symbol->show_hrt = 0; } if(!strcmp(long_options[option_index].name, "square")) { my_symbol->option_3 = DM_SQUARE; } if(!strcmp(long_options[option_index].name, "scale")) { my_symbol->scale = (float)(atof(optarg)); if(my_symbol->scale < 0.01) { /* Zero and negative values are not permitted */ fprintf(stderr, "Invalid scale value\n"); my_symbol->scale = 1.0; } } if(!strcmp(long_options[option_index].name, "border")) { error_number = validator(NESET, optarg); if(error_number == ZERROR_INVALID_DATA) die("Invalid border width\n"); if((atoi(optarg) >= 0) && (atoi(optarg) <= 1000)) { my_symbol->border_width = atoi(optarg); } else { fprintf(stderr, "Border width out of range\n"); } } if(!strcmp(long_options[option_index].name, "height")) { error_number = validator(NESET, optarg); if(error_number == ZERROR_INVALID_DATA) die("Invalid symbol height\n"); if((atoi(optarg) >= 1) && (atoi(optarg) <= 1000)) { my_symbol->height = atoi(optarg); } else { fprintf(stderr, "Symbol height out of range\n"); } } if(!strcmp(long_options[option_index].name, "cols")) { if((atoi(optarg) >= 1) && (atoi(optarg) <= 30)) { my_symbol->option_2 = atoi(optarg); } else { fprintf(stderr, "Number of columns out of range\n"); } } if(!strcmp(long_options[option_index].name, "vers")) { if((atoi(optarg) >= 1) && (atoi(optarg) <= 40)) { my_symbol->option_2 = atoi(optarg); } else { fprintf(stderr, "Invalid QR Code version\n"); } } if(!strcmp(long_options[option_index].name, "secure")) { if((atoi(optarg) >= 1) && (atoi(optarg) <= 8)) { my_symbol->option_1 = atoi(optarg); } else { fprintf(stderr, "ECC level out of range\n"); } } if(!strcmp(long_options[option_index].name, "primary")) { if(strlen(optarg) <= 90) { strcpy(my_symbol->primary, optarg); } else { fprintf(stderr, "Primary data string too long"); } } if(!strcmp(long_options[option_index].name, "mode")) { if((optarg[0] >= '0') && (optarg[0] <= '6')) { my_symbol->option_1 = optarg[0] - '0'; } else { fprintf(stderr, "Invalid mode\n"); } } if(!strcmp(long_options[option_index].name, "rotate")) { /* Only certain inputs allowed */ error_number = validator(NESET, optarg); if(error_number == ZERROR_INVALID_DATA) die("Invalid rotation parameter\n"); switch(atoi(optarg)) { case 90: rotate_angle = 90; break; case 180: rotate_angle = 180; break; case 270: rotate_angle = 270; break; default: rotate_angle = 0; break; } } if(!strcmp(long_options[option_index].name, "batch")) { /* Switch to batch processing mode */ batch_mode = 1; } break; case 'h': die(help_usage); case 't': die(help_types); case 'b': error_number = validator(NESET, optarg); if (error_number == ZERROR_INVALID_DATA) die("Invalid barcode type\n"); my_symbol->symbology = atoi(optarg); break; case 'w': error_number = validator(NESET, optarg); if (error_number == ZERROR_INVALID_DATA) die("Invalid whitespace value\n"); if((atoi(optarg) >= 0) && (atoi(optarg) <= 1000)) { my_symbol->whitespace_width = atoi(optarg); } else { fprintf(stderr, "Whitespace value out of range"); } break; case 'd': /* we have some data! */ if(batch_mode == 0) { error_number = escape_char_process(my_symbol, (unsigned char*)optarg, strlen(optarg)); if(error_number == 0) { error_number = ZBarcode_Print(my_symbol, rotate_angle); } generated = 1; if(error_number != 0) { fprintf(stderr, "%s\n", my_symbol->errtxt); ZBarcode_Delete(my_symbol); return 1; } } else { fprintf(stderr, "Cannot define data in batch mode"); } break; case 'i': /* Take data from file */ if(batch_mode == 0) { error_number = ZBarcode_Encode_File(my_symbol, optarg); if(error_number == 0) { error_number = ZBarcode_Print(my_symbol, rotate_angle); } generated = 1; if(error_number != 0) { fprintf(stderr, "%s\n", my_symbol->errtxt); ZBarcode_Delete(my_symbol); return 1; } } else { /* Take each line of text as a separate data set */ error_number = batch_process(my_symbol, optarg); generated = 1; if(error_number != 0) { fprintf(stderr, "%s\n", my_symbol->errtxt); ZBarcode_Delete(my_symbol); return 1; } } break; case 'o': strncpy(my_symbol->outfile, optarg, 250); break; case 'r': strcpy(my_symbol->fgcolour, "ffffff"); strcpy(my_symbol->bgcolour, "000000"); break; case '?': break; default: fprintf(stderr, "?? getopt error 0%o\n", c); } } if (optind < argc) { fprintf(stderr, "Invalid option "); while (optind < argc) fprintf(stderr, "%s", argv[optind++]); fprintf(stderr, "\n"); } if(generated == 0) { fprintf(stderr, "error: No data received, no symbol generated\n"); } ZBarcode_Delete(my_symbol); return error_number; }