int main(int argc, char* argv[]) { std::cerr << Botan::runtime_version_check(BOTAN_VERSION_MAJOR, BOTAN_VERSION_MINOR, BOTAN_VERSION_PATCH); const std::string cmd_name = (argc <= 1) ? "help" : argv[1]; if(cmd_name == "help" || cmd_name == "--help" || cmd_name == "-h") { std::cout << main_help(); return 1; } std::unique_ptr<Botan_CLI::Command> cmd(Botan_CLI::Command::get_cmd(cmd_name)); if(!cmd) { std::cout << "Unknown command " << cmd_name << " (try --help)\n"; return 1; } std::vector<std::string> args(argv + 2, argv + argc); return cmd->run(args); }
int main(int argc, char **argv) { char *file_in; char *code; struct stat st; Evolve *evolve; progname = argv[0]; if (argc < 2) { main_help(); exit(-1); } file_in = argv[1]; if (stat(file_in, &st) || !S_ISREG(st.st_mode)) { fprintf(stderr, "%s: Error: file not found: %s.\n", progname, file_in); main_help(); exit(-1); } evolve_init(); evolve = evolve_eet_load(file_in); if (!evolve) { fprintf(stderr, "%s: Error parsing file: %s.\n", progname, file_in); exit(-1); } code = evolve_code_get(evolve); printf("%s\n", code); return 0; }
int main(int argc, char **argv) { if(argc < 2) { main_help(); return EXIT_FAILURE; } if(!strcmp(argv[1], "convert")) return convert(argc-2, argv+2); else if(!strcmp(argv[1], "train")) return train(argc-2, argv+2); else if(!strcmp(argv[1], "predict")) return predict(argc-2, argv+2); else if(!strcmp(argv[1], "view")) return view(argc-2, argv+2); else if(!strcmp(argv[1],"similarity")) return similarity(argc-2,argv+2); fprintf(stderr, "Error: Invalid command %s\n", argv[1]); return EXIT_FAILURE; }
int main(int argc, char **argv) { Edje_Part_Collection_Directory_Entry *ce; Old_Edje_File *oef; Edje_File *nef; Eina_Iterator *it; Eet_File *ef; setlocale(LC_NUMERIC, "C"); ecore_app_no_system_modules(); if (!eina_init()) return -1; _edje_cc_log_dom = eina_log_domain_register ("edje_convert", EDJE_CC_DEFAULT_LOG_COLOR); if (_edje_cc_log_dom < 0) { EINA_LOG_ERR("Enable to create a log domain."); exit(-1); } eet_init(); progname = argv[0]; if (argc > 2 || argc < 2 || !strcmp(argv[1], "-h")) { main_help(); return 0; } _edje_edd_old_init(); _edje_edd_init(); ef = eet_open(argv[1], EET_FILE_MODE_READ_WRITE); if (!ef) { EINA_LOG_ERR("Unable to open `%s'.", argv[1]); return -1; } oef = eet_data_read(ef, _edje_edd_old_edje_file, "edje_file"); if (!oef) { EINA_LOG_ERR("Unable to get edje_file section from old file format, are you sure it's an old file ?"); return -1; } nef = _edje_file_convert(ef, oef); _edje_file_set(nef); /* convert old structure to new one */ it = eina_hash_iterator_data_new(nef->collection); EINA_ITERATOR_FOREACH(it, ce) { Old_Edje_Part_Collection *opc; Edje_Part_Collection *npc; char buf[1024]; int bytes = 0; snprintf(buf, sizeof (buf), "collections/%i", ce->id); opc = eet_data_read(ef, _edje_edd_old_edje_part_collection, buf); if (!opc) { EINA_LOG_ERR("Unable to find collection `%s'[%i] in `%s'.", ce->entry, ce->id, argv[1]); return -1; } npc = _edje_collection_convert(ef, ce, opc); snprintf(buf, sizeof (buf), "edje/collections/%i", ce->id); bytes = eet_data_write(ef, _edje_edd_edje_part_collection, buf, npc, 1); if (bytes <= 0) { EINA_LOG_ERR("Unable to save `%s' in section `%s' of `%s'.", ce->entry, buf, argv[1]); return -1; } }
int main(int argc, char **argv) { int i; struct stat st; #ifdef HAVE_REALPATH char rpath[PATH_MAX], rpath2[PATH_MAX]; #endif setlocale(LC_NUMERIC, "C"); ecore_app_no_system_modules(); if (!eina_init()) return -1; _edje_cc_log_dom = eina_log_domain_register ("edje_cc", EDJE_CC_DEFAULT_LOG_COLOR); if (_edje_cc_log_dom < 0) { EINA_LOG_ERR("Enable to create a log domain."); exit(-1); } if (!eina_log_domain_level_check(_edje_cc_log_dom, EINA_LOG_LEVEL_WARN)) eina_log_domain_level_set("edje_cc", EINA_LOG_LEVEL_WARN); progname = ecore_file_file_get(argv[0]); eina_log_print_cb_set(_edje_cc_log_cb, NULL); tmp_dir = getenv("TMPDIR"); img_dirs = eina_list_append(img_dirs, "."); /* add defines to epp so edc files can detect edje_cc version */ defines = eina_list_append(defines, mem_strdup("-DEDJE_VERSION_12=12")); for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-h")) { main_help(); exit(0); } else if ((!strcmp(argv[i], "-V")) || (!strcmp(argv[i], "--version"))) { printf("Version: %s\n", PACKAGE_VERSION); exit(0); } else if (!strcmp(argv[i], "-v")) { eina_log_domain_level_set("edje_cc", EINA_LOG_LEVEL_INFO); } else if (!strcmp(argv[i], "-no-lossy")) { no_lossy = 1; } else if (!strcmp(argv[i], "-no-comp")) { no_comp = 1; } else if (!strcmp(argv[i], "-no-raw")) { no_raw = 1; } else if (!strcmp(argv[i], "-no-etc1")) { no_etc1 = 1; } else if (!strcmp(argv[i], "-no-etc2")) { no_etc2 = 1; } else if (!strcmp(argv[i], "-no-save")) { no_save = 1; } else if ((!strcmp(argv[i], "-id") || !strcmp(argv[i], "--image_dir")) && (i < (argc - 1))) { i++; img_dirs = eina_list_append(img_dirs, argv[i]); } else if ((!strcmp(argv[i], "-fd") || !strcmp(argv[i], "--font_dir")) && (i < (argc - 1))) { i++; fnt_dirs = eina_list_append(fnt_dirs, argv[i]); } else if ((!strcmp(argv[i], "-sd") || !strcmp(argv[i], "--sound_dir")) && (i < (argc - 1))) { i++; snd_dirs = eina_list_append(snd_dirs, argv[i]); } else if ((!strcmp(argv[i], "-md") || !strcmp(argv[i], "--mo_dir")) && (i < (argc - 1))) { i++; mo_dirs = eina_list_append(mo_dirs, argv[i]); } else if ((!strcmp(argv[i], "-vd") || !strcmp(argv[i], "--vibration_dir")) && (i < (argc - 1))) { i++; vibration_dirs = eina_list_append(vibration_dirs, argv[i]); } else if ((!strcmp(argv[i], "-dd") || !strcmp(argv[i], "--data_dir")) && (i < (argc - 1))) { i++; data_dirs = eina_list_append(data_dirs, argv[i]); } else if ((!strcmp(argv[i], "-td") || !strcmp(argv[i], "--tmp_dir")) && (i < (argc - 1))) { i++; if (!tmp_dir) tmp_dir = argv[i]; } else if ((!strcmp(argv[i], "-l") || !strcmp(argv[i], "--license")) && (i < (argc - 1))) { i++; if (!license) license = argv[i]; else licenses = eina_list_append(licenses, argv[i]); } else if ((!strcmp(argv[i], "-a") || !strcmp(argv[i], "--authors")) && (i < (argc - 1))) { i++; if (!authors) authors = argv[i]; } else if ((!strcmp(argv[i], "-min-quality")) && (i < (argc - 1))) { i++; min_quality = atoi(argv[i]); if (min_quality < 0) min_quality = 0; if (min_quality > 100) min_quality = 100; } else if ((!strcmp(argv[i], "-max-quality")) && (i < (argc - 1))) { i++; max_quality = atoi(argv[i]); if (max_quality < 0) max_quality = 0; if (max_quality > 100) max_quality = 100; } else if (!strcmp(argv[i], "-fastcomp")) { compress_mode = EET_COMPRESSION_SUPERFAST; } else if (!strcmp(argv[i], "-fastdecomp")) { compress_mode = EET_COMPRESSION_VERYFAST; } else if (!strcmp(argv[i], "-threads")) { threads = 1; } else if (!strcmp(argv[i], "-nothreads")) { threads = 0; } else if (!strncmp(argv[i], "-D", 2)) { defines = eina_list_append(defines, mem_strdup(argv[i])); } else if ((!strcmp(argv[i], "-o")) && (i < (argc - 1))) { i++; file_out = argv[i]; } else if ((!strcmp(argv[i], "-w")) && (i < (argc - 1))) { i++; watchfile = argv[i]; unlink(watchfile); } else if (!strcmp(argv[i], "-annotate")) { annotate = 1; } else if ((!strcmp(argv[i], "-deps")) && (i < (argc - 1))) { i++; depfile = argv[i]; unlink(depfile); } else if (!file_in) file_in = argv[i]; else if (!file_out) file_out = argv[i]; } if (!file_in) { ERR("no input file specified."); main_help(); exit(-1); } pfx = eina_prefix_new(argv[0], /* argv[0] value (optional) */ main, /* an optional symbol to check path of */ "EDJE", /* env var prefix to use (XXX_PREFIX, XXX_BIN_DIR etc. */ "edje", /* dir to add after "share" (PREFIX/share/DIRNAME) */ "include/edje.inc", /* a magic file to check for in PREFIX/share/DIRNAME for success */ PACKAGE_BIN_DIR, /* package bin dir @ compile time */ PACKAGE_LIB_DIR, /* package lib dir @ compile time */ PACKAGE_DATA_DIR, /* package data dir @ compile time */ PACKAGE_DATA_DIR /* if locale needed use LOCALE_DIR */ ); /* check whether file_in exists */ #ifdef HAVE_REALPATH if (!realpath(file_in, rpath) || stat(rpath, &st) || !S_ISREG(st.st_mode)) #else if (stat(file_in, &st) || !S_ISREG(st.st_mode)) #endif { ERR("file not found: %s.", file_in); main_help(); exit(-1); } if (!file_out) { char *suffix; if ((suffix = strstr(file_in,".edc")) && (suffix[4] == 0)) { file_out = strdup(file_in); if (file_out) { suffix = strstr(file_out,".edc"); strcpy(suffix,".edj"); } } } if (!file_out) { ERR("no output file specified."); main_help(); exit(-1); } #ifdef HAVE_REALPATH if (realpath(file_out, rpath2) && !strcmp (rpath, rpath2)) #else if (!strcmp (file_in, file_out)) #endif { ERR("input file equals output file."); main_help(); exit(-1); } using_file(file_in, 'E'); if (annotate) using_file(file_out, 'O'); if (!edje_init()) exit(-1); edje_file = mem_alloc(SZ(Edje_File)); edje_file->compiler = strdup("edje_cc"); edje_file->version = EDJE_FILE_VERSION; edje_file->minor = EDJE_FILE_MINOR; edje_file->feature_ver = 1; /* increment this every time we add a field * or feature to the edje file format that * does not load nicely as a NULL or 0 value * and needs a special fallback initialization */ edje_file->base_scale = FROM_INT(1); source_edd(); source_fetch(); data_setup(); compile(); reorder_parts(); data_process_scripts(); data_process_lookups(); data_process_script_lookups(); data_write(); eina_prefix_free(pfx); pfx = NULL; edje_shutdown(); eina_log_domain_unregister(_edje_cc_log_dom); eina_shutdown(); return 0; }
int main(int argc, char **argv) { int32_t opt; char *pwd = NULL; char *secret = NULL; char *new_pwd = NULL; if (container_call(container1, init_secret)) { EMBARC_PRINTF("secret key initialized error\r\n"); return E_SYS; } if (!strcmp(argv[1], "challenge")) { EMBARC_PRINTF("try to steal the secret\r\n"); switch (argv[2][0]) { case '0' : EMBARC_PRINTF("the secret from container 1 context is:%s\r\n", challenge->secret); break; case '1' : EMBARC_PRINTF("the secret init data is:%s\r\n", secret_const_data); break; case '2' : EMBARC_PRINTF("the private shared data is:%s\r\n", private_shared_data); break; default: EMBARC_PRINTF("Please use challenge 0, 1, or 2\r\n"); return E_OK; } return E_OK; } opterr = 0; optind = 1; while ((opt=getopt(argc, argv, "tp:s:n:hH?")) != -1) { switch (opt) { case 'h': case '?': case 'H': main_help(); goto error_exit; break; case 'p': pwd = optarg; break; case 's': secret = optarg; if (strlen(secret) > SECRET_LEN) { EMBARC_PRINTF("secret is too long\r\n"); goto error_exit; } break; case 't': EMBARC_PRINTF("Requesting operation from trusted container\r\n"); container_call(container2, trusted_ops); return E_OK; break; case 'n': new_pwd = optarg; if (strlen(new_pwd) > PWD_LEN) { EMBARC_PRINTF("max password length 6 bytes\r\n"); goto error_exit; } break; default: main_help(); goto error_exit; break; } } /* UART is in background container, so a hacker could hijack or access the UART and public_data to get the secret. Here it's just for demo. In a real application, container 2's method should be used */ if (pwd != NULL) { if (secret == NULL && new_pwd == NULL) { if(container_call(container1, operate_secret, pwd, GET_SECRET, public_data)) { EMBARC_PRINTF("get secret failed\r\n"); } else { EMBARC_PRINTF("the secret is:%s\r\n", public_data); memset(public_data, 0, SECRET_LEN); } } else if (secret != NULL && new_pwd == NULL) { if(container_call(container1, operate_secret, pwd, SET_SECRET, secret)) { EMBARC_PRINTF("set new secret failed\r\n"); } } else if (secret == NULL && new_pwd != NULL) { if(container_call(container1, operate_secret, pwd, SET_PWD, new_pwd)) { EMBARC_PRINTF("set new password failed\r\n"); } } else { EMBARC_PRINTF("cannot set password and secret at the same time\r\n"); } } else { EMBARC_PRINTF("no password input\r\n"); } error_exit: return E_OK; }
int main( int argc, char *arg[]) { int retVal = 0; int i,retry; int fd; unsigned char resBuf[256]; //unsigned char cmd_echo[] = {0x00, 0xf0, 0x01, 0x08, 0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88}; unsigned char cmd_echo[] = { 0x01, 0x02, 0x00, 0x00, 0x03, 0x00}; unsigned char cmd_get_version[] = { 0x05, 0x01, 0x00, 0x06, 0x00}; unsigned char cmd_rf_power_on[] = { 0x42, 0x02, 0x80, 0x05, 0xC9, 0x00}; unsigned char cmd_rf_power_off[] = { 0x42, 0x02, 0x80, 0x04, 0xC8, 0x00}; msr3110fw_upgrade_info msr3110FwInfo; FILE *fp = NULL; unsigned long fileLen = 0; unsigned char *fwBuf = NULL; unsigned int fileRead = 0; int pinVal = 0; char inputCmd = arg[1][0]; msr3110_isp_info ispInfo; printf("msr3110_dev_test - test 03 \n"); printf("msr3110_dev_test start... \n"); printf( "command: %c \n", inputCmd); fd = open( "/dev/msr3110", O_RDWR); if( fd < 0) { printf( "FAIL: open msr3110, fd: %d \n", fd); retVal = -1; goto end; } printf( "SUCCESS: open msr3110, fd: %d \n", fd); switch( arg[1][0]) { case 'a': //ioctl test: VEN on pinVal = 0; retVal = ioctl( fd, MSR3110_IOCTL_SET_VEN, ( int)&pinVal); printf( "MSR3110_IOCTL_SET_VEN retVal: %d \n", retVal); goto end; break; case 'b': //ioctl test: VEN off pinVal = 1; retVal = ioctl( fd, MSR3110_IOCTL_SET_VEN, ( int)&pinVal); printf( "MSR3110_IOCTL_SET_VEN retVal: %d \n", retVal); goto end; break; case 'c': //ioctl test: RST on pinVal = 0; retVal = ioctl( fd, MSR3110_IOCTL_SET_RST, ( int)&pinVal); printf( "MSR3110_IOCTL_SET_RST retVal: %d \n", retVal); goto end; break; case 'd': //ioctl test: RST off pinVal = 1; retVal = ioctl( fd, MSR3110_IOCTL_SET_RST, ( int)&pinVal); printf( "MSR3110_IOCTL_SET_RST retVal: %d \n", retVal); goto end; break; case 'e': printf( "MSR3110_IOCTL_FW_UPGRADE \n"); memset( &msr3110FwInfo, 0, sizeof( msr3110fw_upgrade_info)); fp = fopen( "/data/MSR3110_U03.BIN", "rb"); if( fp == NULL) { printf( "FAIL: open msr3110 firmware bin file, fp: %d \n", fp); retVal = -1; goto end; } fseek( fp, 0, SEEK_SET); fseek( fp, 0, SEEK_END); fileLen = ftell( fp); printf( "file len: %lu \n", fileLen); fseek( fp, 0, SEEK_SET); fwBuf = ( unsigned char*)malloc( fileLen); if( fwBuf == NULL) { printf( "FAIL: fwBuf malloc \n"); retVal = -1; goto end; } memset( fwBuf, 0, fileLen); fileRead = fread( fwBuf, fileLen, 1, fp); printf( "fileRead: %d \n", fileRead); msr3110FwInfo.FwBufLen = fileLen; msr3110FwInfo.FwBuf = fwBuf; retVal = ioctl( fd, MSR3110_IOCTL_FW_UPGRADE, ( unsigned long)&msr3110FwInfo); printf( "MSR3110_IOCTL_FW_UPGRADE retVal: %d \n", retVal); goto end; break; case '1': retVal = write( fd, cmd_echo, sizeof( cmd_echo)); printf( "cmd_echo retVal: %d \n", retVal); if( retVal != sizeof( cmd_echo)) { printf( "FAIL: write msr3110, retVal: %d \n", retVal); goto end; } goto read; break; case '2': retVal = write( fd, cmd_get_version, sizeof( cmd_get_version)); printf( "cmd_get_version retVal: %d \n", retVal); if( retVal != sizeof( cmd_get_version)) { printf( "FAIL: write msr3110, retVal: %d \n", retVal); goto end; } goto read; break; case '3': printf( "ioctl, read isp reg val \n"); ispInfo.isp_addrs = 0x59; ispInfo.reg_pos_1 = 0x08; ispInfo.reg_pos_2 = 0x00; ispInfo.reg_val = 0x00; retVal = ioctl( fd, MSR3110_IOCTL_ISP_READ_REG, ( unsigned long)&ispInfo); printf( "retVal: %02X \n", ispInfo.reg_val); printf( "retVal: %d \n", retVal); goto end; break; case '4': printf( "ioctl, write isp reg val \n"); ispInfo.isp_addrs = 0x59; ispInfo.reg_pos_1 = 0x08; ispInfo.reg_pos_2 = 0x00; ispInfo.write_val = 0x79; ispInfo.reg_val = 0x00; retVal = ioctl( fd, MSR3110_IOCTL_ISP_WRITE_REG, ( unsigned long)&ispInfo); printf( "retVal: %d \n", retVal); goto end; break; case '5': printf( "RF Power On \n"); retVal = write( fd, cmd_rf_power_on, sizeof( cmd_rf_power_on)); printf( "cmd_rf_power_on retVal: %d \n", retVal); if( retVal != sizeof( cmd_echo)) { printf( "FAIL: write msr3110, retVal: %d \n", retVal); goto end; } goto read; break; case '6': printf( "RF Power off \n"); retVal = write( fd, cmd_rf_power_off, sizeof( cmd_rf_power_off)); printf( "cmd_rf_power_off retVal: %d \n", retVal); if( retVal != sizeof( cmd_echo)) { printf( "FAIL: write msr3110, retVal: %d \n", retVal); goto end; } goto read; break; case 'h': printf( "[User Manual] \n"); main_help(); goto end; break; default: printf( "FAIL: unknown command: %c \n", inputCmd); goto end; break; } // read // #if 1 read: // read 2 bytes // retVal = read( fd, resBuf, 2); if( retVal < 0) { printf( "FAIL: read fail. retVal: %d \n", retVal); goto end; } printf( "SUCCESS. RCV BUF: "); for( i = 0; i < retVal; i++) { printf( "%02X ", resBuf[i]); } printf( " \n"); // read data bytes // retVal = read( fd, &resBuf[2], resBuf[1] + 2); if( retVal < 0) { printf( "FAIL: read fail. retVal: %d \n", retVal); goto end; } printf( "SUCCESS. RCV BUF: "); for( i = 0; i < retVal + 2; i++) { printf( "%02X ", resBuf[i]); } printf( " \n"); #endif end: close( fd); if( fp) { fclose( fp); } if( fwBuf) { free( fwBuf); } printf("msr3110_dev_test end... \n"); return retVal; }
/* Parse the command-line */ static int main_cmdline(int argc, char *argv[]) { int c; int option_index = 0; char * locale; struct option long_options[] = { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, { "config", required_argument, NULL, 'c' }, { "debug", no_argument, NULL, 'd' }, { "quiet", no_argument, NULL, 'q' }, { "dbglocale", optional_argument, NULL, 'l' }, { "dbg_func", required_argument, NULL, 'f' }, { "dbg_file", required_argument, NULL, 'F' }, { "dbg_gnutls", required_argument, NULL, 'g' }, { NULL, 0, NULL, 0 } }; /* Loop on arguments */ while (1) { c = getopt_long (argc, argv, "hVc:dql:M:", long_options, &option_index); if (c == -1) break; /* Exit from the loop. */ switch (c) { case 'h': /* Print help and exit. */ main_help(); exit(0); case 'V': /* Print version and exit. */ main_version(); exit(0); case 'c': /* Read configuration from this file instead of the default location.. */ if (optarg == NULL ) { fprintf(stderr, "Missing argument with --config directive\n"); return EINVAL; } conffile = optarg; break; case 'l': /* Change the locale. */ locale = setlocale(LC_ALL, optarg?:""); if (!locale) { fprintf(stderr, "Unable to set locale (%s)\n", optarg); return EINVAL; } break; case 'd': /* Increase verbosity of debug messages. */ fd_g_debug_lvl--; break; case 'f': /* Full debug for the function with this name. */ #ifdef DEBUG fd_debug_one_function = optarg; #else /* DEBUG */ fprintf(stderr, "Error: must compile with DEBUG support to use --dbg_func feature!\n"); return EINVAL; #endif /* DEBUG */ break; case 'F': /* Full debug for the file with this name. */ #ifdef DEBUG fd_debug_one_file = basename(optarg); #else /* DEBUG */ fprintf(stderr, "Error: must compile with DEBUG support to use --dbg_file feature!\n"); return EINVAL; #endif /* DEBUG */ break; case 'g': /* Set a debug level and function for GNU TLS calls. */ gnutls_debug = (int)atoi(optarg); break; case 'q': /* Decrease verbosity then remove debug messages. */ fd_g_debug_lvl++; break; case '?': /* Invalid option. */ /* `getopt_long' already printed an error message. */ fprintf(stderr, "getopt_long found an invalid character\n"); return EINVAL; default: /* bug: option not considered. */ fprintf(stderr, "A command-line option is missing in parser: %c\n", c); ASSERT(0); return EINVAL; } } return 0; }