int main() { int i; char str[STRING_DATA_SIZE] = {0}; plc_tag tag = create_tag(TAG_PATH); int rc; if(!tag) { fprintf(stdout,"ERROR: Unable to create tag!\n"); return 0; } /* test pre-read by writing first */ for(i=0; i<ARRAY_2_DIM_SIZE; i++) { snprintf_platform(str,sizeof(str), "string value for element %d", i); update_string(tag, i, str); } /* write the data */ rc = plc_tag_write(tag, DATA_TIMEOUT); if(rc != PLCTAG_STATUS_OK) { fprintf(stdout,"ERROR: Unable to read the data! Got error code %d: %s\n",rc, plc_tag_decode_error(rc)); return 0; } /* get the data */ rc = plc_tag_read(tag, DATA_TIMEOUT); if(rc != PLCTAG_STATUS_OK) { fprintf(stdout,"ERROR: Unable to read the data! Got error code %d: %s\n",rc, plc_tag_decode_error(rc)); return 0; } dump_strings(tag); plc_tag_destroy(tag); return 0; }
int main(int argc, char* argv[]) { bool all = false; bool string = false; bool stringdata = false; bool type = false; bool proto = false; bool field = false; bool meth = false; bool clsdef = false; bool clsdata = false; bool code = false; bool enarr = false; bool anno = false; bool debug = false; uint32_t ddebug_offset = 0; char c; static const struct option options[] = { { "all", no_argument, nullptr, 'a' }, { "string", no_argument, nullptr, 's' }, { "stringdata", no_argument, nullptr, 'S' }, { "type", no_argument, nullptr, 't' }, { "proto", no_argument, nullptr, 'p' }, { "field", no_argument, nullptr, 'f' }, { "meth", no_argument, nullptr, 'm' }, { "clsdef", no_argument, nullptr, 'c' }, { "clsdata", no_argument, nullptr, 'C' }, { "code", no_argument, nullptr, 'x' }, { "enarr", no_argument, nullptr, 'e' }, { "anno", no_argument, nullptr, 'A' }, { "debug", no_argument, nullptr, 'd' }, { "ddebug", required_argument, nullptr, 'D' }, { "clean", no_argument, (int*)&clean, 1 }, { "help", no_argument, nullptr, 'h' }, { nullptr, 0, nullptr, 0 }, }; while ((c = getopt_long( argc, argv, "asStpfmcCxeAdDh", &options[0], nullptr)) != -1) { switch (c) { case 'a': all = true; break; case 's': string = true; break; case 'S': stringdata = true; break; case 't': type = true; break; case 'p': proto = true; break; case 'f': field = true; break; case 'm': meth = true; break; case 'c': clsdef = true; break; case 'C': clsdata = true; break; case 'x': code = true; break; case 'e': enarr = true; break; case 'A': anno = true; break; case 'd': debug = true; break; case 'D': sscanf(optarg, "%x", &ddebug_offset); break; case 'h': puts(ddump_usage_string); return 0; case '?': return 1; // getopt_long has printed an error case 0: // we're handling a long-only option break; default: abort(); } } if (optind == argc) { fprintf(stderr, "%s: no dex files given; use -h for help\n", argv[0]); return 1; } while (optind < argc) { const char* dexfile = argv[optind++]; ddump_data rd; open_dex_file(dexfile, &rd); redump(format_map(&rd).c_str()); if (string || all) { dump_strings(&rd); } if (stringdata || all) { dump_stringdata(&rd); } if (type || all) { dump_types(&rd); } if (proto || all) { dump_protos(&rd); } if (field || all) { dump_fields(&rd); } if (meth || all) { dump_methods(&rd); } if (clsdef || all) { dump_clsdefs(&rd); } if (clsdata || all) { dump_clsdata(&rd); } if (code || all) { dump_code(&rd); } if (enarr || all) { dump_enarr(&rd); } if (anno || all) { dump_anno(&rd); } if (debug || all) { dump_debug(&rd); } if (ddebug_offset != 0) { disassemble_debug(&rd, ddebug_offset); } fprintf(stdout, "\n"); fflush(stdout); } return 0; }
int main(int argc, char *argv[]) { struct args arguments; try { process_args(argc, argv, &arguments); BlockMgmt bm(arguments.host, arguments.port, arguments.ns, arguments.username, arguments.password); if( arguments.operation == "createvol" ) { if( arguments.opArgs.size() != 3 ) { std::cout << "create expects <storage pool> <name> <size>" << std::endl; return EXIT_FAILURE; } bm.createLun(arguments.opArgs[0], arguments.opArgs[1], atoll(arguments.opArgs[2].getCString())); } else if ( arguments.operation == "createinit" ) { if( arguments.opArgs.size() != 3 ) { std::cout << "createinit expects <Name> <ID> [WWN|IQN]" << std::endl; return EXIT_FAILURE; } if( arguments.opArgs[2] == "WWN" || arguments.opArgs[2] == "IQN" ) { bm.createInit(arguments.opArgs[0], arguments.opArgs[1], arguments.opArgs[2]); } else { std::cout << "[WWN|IQN] expected not " << arguments.opArgs[2] << std::endl; return EXIT_FAILURE; } } else if ( arguments.operation == "deleteinit" ) { if( arguments.opArgs.size() != 1 ) { std::cout << "deleteinit expects <ID>" << std::endl; return EXIT_FAILURE; } bm.deleteInit(arguments.opArgs[0]); } else if ( arguments.operation == "snapshot" ) { if( arguments.opArgs.size() != 3 ) { std::cout << "snapshot expects <source volume> <dest. storage pool> <dest. name>" << std::endl; return EXIT_FAILURE; } bm.createSnapShot(arguments.opArgs[0], arguments.opArgs[1], arguments.opArgs[2]); } else if( arguments.operation == "deletevol" ) { if( arguments.opArgs.size() != 1 ) { std::cout << "deletevol expects <name>" << std::endl; return EXIT_FAILURE; } bm.deleteLun(arguments.opArgs[0]); } else if( arguments.operation == "resize" ) { if( arguments.opArgs.size() != 2 ) { std::cout << "resize expects <name> <size>" << std::endl; return EXIT_FAILURE; } bm.resizeLun(arguments.opArgs[0], atoll(arguments.opArgs[1].getCString())); } else if( arguments.operation == "list" ) { if( arguments.opArgs.size() != 1 ) { std::cout << "list expects one of the following [volumes|pools|initiators|initgroups]" << std::endl; return EXIT_FAILURE; } arguments.opArgs[0].toLower(); if( arguments.opArgs[0] == "volumes" ) { dump_strings( bm.getLuns()); } else if( arguments.opArgs[0] == "pools" ) { dump_strings( bm.getStoragePools()); } else if( arguments.opArgs[0] == "initiators") { dump_strings( bm.getInitiators()); } else { std::cout << "Unsupported list type= " << arguments.opArgs[0] << std::endl; } } else if ( arguments.operation == "mapcreate" ) { if( arguments.opArgs.size() != 2 ) { std::cout << "mapcreate expects <initiator> <volume>" << std::endl; return EXIT_FAILURE; } bm.mapLun(arguments.opArgs[0], arguments.opArgs[1]); } else if ( arguments.operation == "mapdelete" ) { if( arguments.opArgs.size() != 2 ) { std::cout << "mapdelete expects <initiator> <volume>" << std::endl; return EXIT_FAILURE; } bm.unmapLun(arguments.opArgs[0], arguments.opArgs[1]); } else if ( arguments.operation == "jobstatus" ) { if( arguments.opArgs.size() != 1 ) { std::cout << "jobstatus expects job id" << std::endl; return EXIT_FAILURE; } bm.jobStatus(arguments.opArgs[0]); }else { std::cout << "Unsupported operation: " << arguments.operation << std::endl; } } catch (Exception &e) { std::cerr << "Error: " << e.getMessage() << std::endl; exit(1); } return 0; }