int _tmain(int argc, TCHAR* argv[]) { int result; ENSURE_DEBUGGER(); if (argc == 1 || (argc == 2 && !_tcsicmp(*(argv + 1), _T("/?")))) return PRINT_USAGE(VER_FULLVERSION, COPYRIGHT_INFO); // TODO: // /r (raw) do not interpret internal cmd commands as cmd /d /c command // /n do not copy env vars SetUp(); result = (!IsVistaOrAbove() || IsElevated()) ? ExecuteProgram() : ExecuteStub(); return CleanUp(result); }
int main(int argc, char ** argv) { int trimN = 0; int trimQ = 0; int joinQ = -1; int32_t min_output_length = INT32_MAX; int in_files = 0; int out_files = 0; FILE * fq[2] = {stdin, NULL}; FILE * out[2] = {stdout, NULL}; FILE * trimfp = NULL; enum {IN, OUT, TRIM} reading_args = IN; for (++argv;*argv;argv++) { if (**argv == '-') { switch((*argv)[1]) { case 'i': reading_args = IN; break; case 'o': reading_args = OUT; break; // case 'N': trimN = 1; reading_args = TRIM; break; // case 'T': trimQ = parse_int_or_char(*(++argv)); reading_args = TRIM; break; case 'Q': joinQ = parse_int_or_char(*(++argv)); break; // case 'm': min_output_length = atoi(*(++argv)); break; case 'h': PRINT_USAGE(); exit(1); break; case '-': if (!memcmp((*argv) + 2,"help",4)) { PRINT_USAGE(); exit(1); } break; case '\0': { switch (reading_args) { case IN: if (in_files < 2) fq[in_files++] = stdin; else { PRINT_USAGE(); exit(2); } break; case OUT: if (out_files < 2) out[out_files++] = stdout; else { PRINT_USAGE(); exit(3); } break; case TRIM: if (!trimfp) { trimfp = stdout; fprintf(stderr, "Warning: outputting reads that don't pass the trim filter to standard out.\n"); } else { PRINT_USAGE(); exit(3); } break; default: PRINT_USAGE(); exit(4); break; } } break; } } else { switch (reading_args) { case IN: if (in_files < 2) { if (!(fq[in_files++] = fopen(*argv, "r"))) { perror("fopen"); fprintf(stderr, "Cannot open file %s\n", *argv); } } else { PRINT_USAGE(); exit(2); } break; case OUT: if (out_files < 2) { if (!(out[out_files++] = fopen(*argv, "w"))) { perror("fopen"); fprintf(stderr, "Cannot open file %s\n", *argv); } } else { PRINT_USAGE(); exit(3); } break; case TRIM: if (!trimfp) { if (!(trimfp = fopen(*argv, "w"))) { perror("fopen"); fprintf(stderr, "Cannot open file %s\n", *argv); } } else { PRINT_USAGE(); exit(3); } break; default: PRINT_USAGE(); exit(4); break; } // if (reading_args == IN) { // if (in_files < 2) { // if (!(fq[in_files++] = fopen(*argv, "r"))) { // perror(__FILE__ ":" TOSTRING(__LINE__) ": " "fopen"); // fprintf(stderr, "Cannot open file %s\n", *argv); // } // } // else { PRINT_USAGE(); exit(5); } // } else if (reading_args == OUT) { // if (out_files < 2) { // if (!(out[out_files++] = fopen(*argv, "w"))) { // perror(__FILE__ ":" TOSTRING(__LINE__) ": " "fopen"); // fprintf(stderr, "Cannot open file %s\n", *argv); // } // } // else { // PRINT_USAGE(); exit(6); // } // } } } if (!fq[1]) fq[1] = fq[0]; if (!out[1]) out[1] = out[0]; struct fastx_read_list_s * fastx_read_list = fastx_read_list_create(); fastx_read_list_scan_pe(fastx_read_list, fq); fclose(fq[0]); if (fq[0] != fq[1]) fclose(fq[1]); fprintf(stderr, "read in %zu reads, %zu pairs\n", fastx_read_list->numreads, fastx_read_list->numreads >> 1); fprintf(stderr, "Using quality joining on minimum %c ~ %d\n", joinQ, joinQ); fastx_pair_unique(fastx_read_list, joinQ); fprintf(stderr, "%zu unique pairs left\n", fastx_read_list->numreads >> 1); fastx_read_list_print_pe(fastx_read_list, out); /* fprintf(stderr, "%zu unique pairs left\n", stark_read_list->numpairs); stark_print_reads(stark_read_list, out[0], out[1]); */ fclose(out[0]); if (out[0] != out[1]) fclose(out[1]); return 0; }
int main(int argc, char *argv[]) { char *dll = NULL; int i; /* module + address per line */ char line[MAXIMUM_PATH*2]; size_t modoffs; /* options that can be local vars */ bool addr2sym = false; bool addr2sym_multi = false; bool sym2addr = false; bool enumerate = false; bool enumerate_all = false; bool search = false; bool searchall = false; for (i = 1; i < argc; i++) { if (_stricmp(argv[i], "-e") == 0) { if (i+1 >= argc) { PRINT_USAGE(argv[0]); return 1; } i++; dll = argv[i]; if ( #ifdef WINDOWS _access(dll, 4/*read*/) == -1 #else !dr_file_exists(dll) #endif ) { printf("ERROR: invalid path %s\n", dll); return 1; } } else if (_stricmp(argv[i], "-f") == 0) { show_func = true; } else if (_stricmp(argv[i], "-v") == 0) { verbose = true; } else if (_stricmp(argv[i], "-a") == 0 || _stricmp(argv[i], "-s") == 0) { if (i+1 >= argc) { PRINT_USAGE(argv[0]); return 1; } if (_stricmp(argv[i], "-a") == 0) addr2sym = true; else sym2addr = true; i++; /* rest of args read below */ break; } else if (_stricmp(argv[i], "-q") == 0) { addr2sym_multi = true; } else if (_stricmp(argv[i], "--enum") == 0) { enumerate = true; } else if (_stricmp(argv[i], "--list") == 0) { enumerate_all = true; } else if (_stricmp(argv[i], "--search") == 0) { search = true; } else if (_stricmp(argv[i], "--searchall") == 0) { search = true; searchall = true; } else { PRINT_USAGE(argv[0]); return 1; } } if (((sym2addr || addr2sym) && dll == NULL) || (addr2sym_multi && dll != NULL) || (!sym2addr && !addr2sym && !addr2sym_multi && !enumerate_all)) { PRINT_USAGE(argv[0]); return 1; } dr_standalone_init(); if (drsym_init(IF_WINDOWS_ELSE(NULL, 0)) != DRSYM_SUCCESS) { printf("ERROR: unable to initialize symbol library\n"); return 1; } if (!addr2sym_multi) { if (enumerate_all) enumerate_symbols(dll, NULL, search, searchall); else { /* kind of a hack: assumes i hasn't changed and that -s/-a is last option */ for (; i < argc; i++) { if (addr2sym) { if (sscanf(argv[i], "%x", (uint *)&modoffs) == 1) lookup_address(dll, modoffs); else printf("ERROR: unknown input %s\n", argv[i]); } else if (enumerate || search) enumerate_symbols(dll, argv[i], search, searchall); else lookup_symbol(dll, argv[i]); } } } else { while (!feof(stdin)) { char modpath[MAXIMUM_PATH]; if (fgets(line, sizeof(line), stdin) == NULL || /* when postprocess.pl closes the pipe, fgets is not * returning, so using an alternative eof code */ strcmp(line, ";exit\n") == 0) break; /* Ensure we support spaces in paths by using ; to split. * Since ; separates PATH, no Windows dll will have ; in its name. */ if (sscanf(line, "%"MAX_PATH_STR"[^;];%x", (char *)&modpath, (uint *)&modoffs) == 2) { lookup_address(modpath, modoffs); fflush(stdout); /* ensure flush in case piped */ } else if (verbose) printf("Error: unknown input %s\n", line); } } if (drsym_exit() != DRSYM_SUCCESS) printf("WARNING: error cleaning up symbol library\n"); return 0; }
int main_pcmmio_dac(int argc, char **argv) { int dac; float low_voltage; float high_voltage; float step_voltage; float current_voltage; float current_step; int step_time; int maximum_time; uint32_t step_ticks; bool fail = false; int elapsed; /* * Verify that we have the right number of arguments. */ if ( (argc != 3) && (argc != 7) ) { printf( "Incorrect number of arguments\n" ); PRINT_USAGE(); return -1; } /* * Convert the string arguments into number values */ if ( rtems_string_to_int( argv[1], &dac, NULL, 0 ) ) { printf( "DAC (%s) is not a number\n", argv[1] ); fail = true; } if ( rtems_string_to_float( argv[2], &low_voltage, NULL ) ) { printf( "Voltage (%s) is not a number\n", argv[2] ); fail = true; } /* * Validate the output dac and voltage. */ if ( dac < 0 || dac > 7 ) { puts( "DAC number must be 0-7" ); fail = true; } VALIDATE_VOLTAGE( low_voltage ); /* * Now do a single write to the DAC */ if ( argc == 3 ) { if ( fail ) { PRINT_USAGE(); return -1; } printf( "Write %6.4f to to dac %d\n", low_voltage, dac ); set_dac_voltage(dac, low_voltage); return 0; } /* * Finish parsing the arguments to do a pattern */ fail = false; if ( rtems_string_to_float( argv[3], &high_voltage, NULL ) ) { printf( "Voltage (%s) is not a number\n", argv[3] ); fail = true; } VALIDATE_VOLTAGE( high_voltage ); if ( rtems_string_to_float( argv[4], &step_voltage, NULL ) ) { printf( "Step voltage (%s) is not a number\n", argv[4] ); fail = true; } VALIDATE_VOLTAGE( step_voltage ); if ( step_voltage < 0.0 ) { printf( "Step voltage must be greater than 0\n" ); fail = true; } if ( rtems_string_to_int( argv[5], &step_time, NULL, 0 ) ) { printf( "Step time (%s) is not a number\n", argv[5] ); fail = true; } if ( rtems_string_to_int( argv[6], &maximum_time, NULL, 0 ) ) { printf( "Maximum time (%s) is not a number\n", argv[6] ); fail = true; } if ( step_time >= maximum_time ) { printf( "Step time (%d) must be less than maximum time (%d)\n", step_time, maximum_time ); fail = true; } if ( step_time < 0 ) { printf( "Step time must be greater than 0\n" ); fail = true; } if ( maximum_time < 0 ) { printf( "Maximum time must be greater than 0\n" ); fail = true; } /* * Now write the pattern to the DAC */ if ( fail ) { PRINT_USAGE(); return -1; } printf( "Write %6.4f-%6.4f step=%6.4f stepTime=%d msecs dac=%d max=%d msecs\n", low_voltage, high_voltage, step_voltage, step_time, dac, maximum_time ); elapsed = 0; step_ticks = RTEMS_MILLISECONDS_TO_TICKS(step_time); current_voltage = low_voltage; current_step = step_voltage; if ( low_voltage > high_voltage ) current_step *= -1.0; while (1) { #if defined(TESTING) printf( "%d: Write %6.4f to to dac %d\n", elapsed, current_voltage, dac ); #endif set_dac_voltage(dac, current_voltage); current_voltage += current_step; if ( current_voltage < low_voltage ) { current_step = step_voltage; current_voltage = low_voltage; } else if ( current_voltage > high_voltage ) { current_step = -1.0 * step_voltage; current_voltage = high_voltage; } elapsed += step_time; if ( elapsed > maximum_time ) break; rtems_task_wake_after( step_ticks ); } return 0; }
void check_usage(void) { PRINT_USAGE(Image); PRINT_USAGE(Stack); }
int main_pcmmio_benchmark(int argc, char **argv) { int maximum; int sc; char ch; bool verbose; struct getopt_data getopt_reent; const char *s; int interrupts; uint64_t timestamp; uint64_t now; uint32_t min_cycles; uint32_t max_cycles; uint64_t total_cycles; uint64_t cycles; /* * Parse arguments here */ maximum = 1; verbose = false; memset(&getopt_reent, 0, sizeof(getopt_data)); while ((ch = getopt_r(argc, argv, "i:v", &getopt_reent)) != -1) { switch (ch) { case 'i': /* maximum interrupts */ s = getopt_reent.optarg; if ( rtems_string_to_int( s, &maximum, NULL, 0 ) ) { printf( "Maximum interrupts (%s) is not a number\n", s ); PRINT_USAGE(); return -1; } if ( maximum <= 0 ) { printf( "Maximum interrupts (%d) is invalid\n", maximum ); PRINT_USAGE(); return -1; } break; case 'v': /* verbose */ verbose = true; break; default: printf( pcmmio_benchmark_usage, argv[0] ); return -1; } } printf( "Benchmarking for DIN IRQ for %d interrupts\n", maximum ); /* * Now catch interrupts in the loop */ interrupts = 0; min_cycles = 0xffffffff; max_cycles = 0; total_cycles = 0; flush_buffered_ints(); while (1) { sc = 0; sc = wait_dio_int_with_timestamp(0, ×tamp); if ( sc == -1 ) continue; now = rdtsc(); cycles = now - timestamp; total_cycles += cycles; if ( cycles < min_cycles ) min_cycles = cycles; if ( cycles > max_cycles ) max_cycles = cycles; interrupts++; if (interrupts >= maximum ) break; } printf( "Number of Interrupts: %d\n" "Total Cycles: %lld\n" "min/max/avg cycles: %ld/%ld/%lld\n" "min/max/avg microseconds: %lld/%lld/%lld\n", maximum, total_cycles, min_cycles, max_cycles, total_cycles / maximum, to_usecs( min_cycles ), to_usecs( max_cycles ), to_usecs( total_cycles / maximum ) ); return 0; }
int main(int argc, char *argv[]) { #define PRINT_USAGE(exit_code) print_usage(argv[0], exit_code) char conf_file[POOLMAXPATHLEN + 1]; char enc_key[MAX_POOL_KEY_LEN + 1]; char pg_pass[MAX_PGPASS_LEN + 1]; char username[MAX_USER_NAME_LEN + 1]; char key_file_path[POOLMAXPATHLEN + sizeof(POOLKEYFILE) + 1]; int opt; int optindex; bool updatepasswd = false; bool prompt = false; bool prompt_for_key = false; char *pool_key = NULL; static struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {"prompt", no_argument, NULL, 'p'}, {"prompt-for-key", no_argument, NULL, 'P'}, {"update-pass", no_argument, NULL, 'm'}, {"username", required_argument, NULL, 'u'}, {"enc-key", required_argument, NULL, 'K'}, {"key-file", required_argument, NULL, 'k'}, {"config-file", required_argument, NULL, 'f'}, {NULL, 0, NULL, 0} }; snprintf(conf_file, sizeof(conf_file), "%s/%s", DEFAULT_CONFIGDIR, POOL_CONF_FILE_NAME); /* * initialize username buffer with zeros so that we can use strlen on it * later to check if a username was given on the command line */ memset(username, 0, sizeof(username)); memset(enc_key, 0, sizeof(enc_key)); memset(key_file_path, 0, sizeof(key_file_path)); while ((opt = getopt_long(argc, argv, "hPpmf:u:k:K:", long_options, &optindex)) != -1) { switch (opt) { case 'p': /* prompt for postgres password */ prompt = true; break; case 'P': /* prompt for encryption key */ prompt_for_key = true; break; case 'm': /* update password file */ updatepasswd = true; break; case 'f': /* specify configuration file */ if (!optarg) { PRINT_USAGE(EXIT_SUCCESS); } strlcpy(conf_file, optarg, sizeof(conf_file)); break; case 'k': /* specify key file for encrypting * pool_password entries */ if (!optarg) { PRINT_USAGE(EXIT_SUCCESS); } strlcpy(key_file_path, optarg, sizeof(key_file_path)); break; case 'K': /* specify configuration file */ if (!optarg) { PRINT_USAGE(EXIT_SUCCESS); } strlcpy(enc_key, optarg, sizeof(enc_key)); break; case 'u': if (!optarg) { PRINT_USAGE(EXIT_SUCCESS); } /* check the input limit early */ if (strlen(optarg) > sizeof(username)) { fprintf(stderr, "Error: input exceeds maximum username length!\n\n"); exit(EXIT_FAILURE); } strlcpy(username, optarg, sizeof(username)); break; default: PRINT_USAGE(EXIT_SUCCESS); break; } } /* Prompt for password. */ if (prompt || optind >= argc) { char buf[MAX_PGPASS_LEN]; int len; set_tio_attr(1); printf("db password: "******"Couldn't read input from stdin. (fgets(): %s)", strerror(eno)); exit(EXIT_FAILURE); } printf("\n"); set_tio_attr(0); /* Remove LF at the end of line, if there is any. */ len = strlen(buf); if (len > 0 && buf[len - 1] == '\n') { buf[len - 1] = '\0'; len--; } stpncpy(pg_pass, buf, sizeof(pg_pass)); } /* Read password from argv. */ else { int len; len = strlen(argv[optind]); if (len > MAX_PGPASS_LEN) { fprintf(stderr, "Error: Input exceeds maximum password length given:%d max allowed:%d!\n\n", len, MAX_PGPASS_LEN); PRINT_USAGE(EXIT_FAILURE); } stpncpy(pg_pass, argv[optind], sizeof(pg_pass)); } /* prompt for key, overrides all key related arguments */ if (prompt_for_key) { char buf[MAX_POOL_KEY_LEN]; int len; /* we need to read the encryption key from stdin */ set_tio_attr(1); printf("encryption key: "); if (!fgets(buf, sizeof(buf), stdin)) { int eno = errno; fprintf(stderr, "Couldn't read input from stdin. (fgets(): %s)", strerror(eno)); exit(EXIT_FAILURE); } printf("\n"); set_tio_attr(0); /* Remove LF at the end of line, if there is any. */ len = strlen(buf); if (len > 0 && buf[len - 1] == '\n') { buf[len - 1] = '\0'; len--; } if (len == 0) { fprintf(stderr, "encryption key not provided\n"); exit(EXIT_FAILURE); } stpncpy(enc_key, buf, sizeof(enc_key)); } else { /* check if we already have not got the key from command line argument */ if (strlen(enc_key) == 0) { /* read from file */ if (strlen(key_file_path) == 0) { get_pool_key_filename(key_file_path); } fprintf(stdout, "trying to read key from file %s\n", key_file_path); pool_key = read_pool_key(key_file_path); } else { pool_key = enc_key; } } if (pool_key == NULL) { fprintf(stderr, "encryption key not provided\n"); exit(EXIT_FAILURE); } if (updatepasswd) { update_pool_passwd(conf_file, username, pg_pass, pool_key); } else { unsigned char ciphertext[MAX_ENCODED_PASSWD_LEN]; unsigned char b64_enc[MAX_ENCODED_PASSWD_LEN]; int len; int cypher_len; cypher_len = aes_encrypt_with_password((unsigned char *) pg_pass, strlen(pg_pass), pool_key, ciphertext); /* generate the hash for the given username */ len = pg_b64_encode((const char *) ciphertext, cypher_len, (char *) b64_enc); b64_enc[len] = 0; fprintf(stdout, "\n%s\n", b64_enc); fprintf(stdout, "pool_passwd string: AES%s\n", b64_enc); #ifdef DEBUG_ENCODING unsigned char b64_dec[MAX_ENCODED_PASSWD_LEN]; unsigned char plaintext[MAX_PGPASS_LEN]; len = pg_b64_decode(b64_enc, len, b64_dec); len = aes_decrypt_with_password(b64_dec, len, pool_key, plaintext); plaintext[len] = 0; #endif } if (pool_key != enc_key) free(pool_key); return EXIT_SUCCESS; }
int _tmain(int argc, TCHAR *targv[]) { int res = 1; char **argv; char dll[MAXIMUM_PATH]; int i; /* module + address per line */ char line[MAXIMUM_PATH*2]; size_t modoffs; /* options that can be local vars */ bool addr2sym = false; bool addr2sym_multi = false; bool sym2addr = false; bool enumerate = false; bool enumerate_all = false; bool search = false; bool searchall = false; bool enum_lines = false; #if defined(WINDOWS) && !defined(_UNICODE) # error _UNICODE must be defined #else /* Convert to UTF-8 if necessary */ if (drfront_convert_args((const TCHAR **)targv, &argv, argc) != DRFRONT_SUCCESS) { printf("ERROR: failed to process args\n"); return 1; } #endif for (i = 1; i < argc; i++) { if (_stricmp(argv[i], "-e") == 0) { bool is_readable; if (i+1 >= argc) { PRINT_USAGE(argv[0]); goto cleanup; } i++; if (drfront_get_absolute_path(argv[i], dll, BUFFER_SIZE_ELEMENTS(dll)) != DRFRONT_SUCCESS) { printf("ERROR: invalid path %s\n", argv[i]); goto cleanup; } if (drfront_access(dll, DRFRONT_READ, &is_readable) != DRFRONT_SUCCESS || !is_readable) { printf("ERROR: invalid path %s\n", argv[i]); goto cleanup; } } else if (_stricmp(argv[i], "-f") == 0) { show_func = true; } else if (_stricmp(argv[i], "-v") == 0) { verbose = true; } else if (_stricmp(argv[i], "-a") == 0 || _stricmp(argv[i], "-s") == 0) { if (i+1 >= argc) { PRINT_USAGE(argv[0]); goto cleanup; } if (_stricmp(argv[i], "-a") == 0) addr2sym = true; else sym2addr = true; i++; /* rest of args read below */ break; } else if (_stricmp(argv[i], "--lines") == 0) { enum_lines = true; } else if (_stricmp(argv[i], "-q") == 0) { addr2sym_multi = true; } else if (_stricmp(argv[i], "--enum") == 0) { enumerate = true; } else if (_stricmp(argv[i], "--list") == 0) { enumerate_all = true; } else if (_stricmp(argv[i], "--search") == 0) { search = true; } else if (_stricmp(argv[i], "--searchall") == 0) { search = true; searchall = true; } else { PRINT_USAGE(argv[0]); goto cleanup; } } if ((!addr2sym_multi && dll == NULL) || (addr2sym_multi && dll != NULL) || (!sym2addr && !addr2sym && !addr2sym_multi && !enumerate_all && !enum_lines)) { PRINT_USAGE(argv[0]); goto cleanup; } dr_standalone_init(); if (dll != NULL) { if (!check_architecture(dll, argv)) goto cleanup; } if (drsym_init(IF_WINDOWS_ELSE(NULL, 0)) != DRSYM_SUCCESS) { printf("ERROR: unable to initialize symbol library\n"); goto cleanup; } if (!addr2sym_multi) { if (enum_lines) enumerate_lines(dll); else if (enumerate_all) enumerate_symbols(dll, NULL, search, searchall); else { /* kind of a hack: assumes i hasn't changed and that -s/-a is last option */ for (; i < argc; i++) { if (addr2sym) { if (sscanf(argv[i], SIZE_FMT, &modoffs) == 1) symquery_lookup_address(dll, modoffs); else printf("ERROR: unknown input %s\n", argv[i]); } else if (enumerate || search) enumerate_symbols(dll, argv[i], search, searchall); else symquery_lookup_symbol(dll, argv[i]); } } } else { while (!feof(stdin)) { char modpath[MAXIMUM_PATH]; if (fgets(line, sizeof(line), stdin) == NULL || /* when postprocess.pl closes the pipe, fgets is not * returning, so using an alternative eof code */ strcmp(line, ";exit\n") == 0) break; /* Ensure we support spaces in paths by using ; to split. * Since ; separates PATH, no Windows dll will have ; in its name. */ if (sscanf(line, "%"MAX_PATH_STR"[^;];"SIZE_FMT, (char *)&modpath, &modoffs) == 2) { symquery_lookup_address(modpath, modoffs); fflush(stdout); /* ensure flush in case piped */ } else if (verbose) printf("Error: unknown input %s\n", line); } } if (drsym_exit() != DRSYM_SUCCESS) printf("WARNING: error cleaning up symbol library\n"); res = 0; cleanup: if (drfront_cleanup_args(argv, argc) != DRFRONT_SUCCESS) printf("WARNING: drfront_cleanup_args failed\n"); return res; }
int main(int argc, char *argv[]) { #define PRINT_USAGE(exit_code) print_usage(argv[0], exit_code) char conf_file[POOLMAXPATHLEN+1]; char username[MAX_INPUT_SIZE+1]; int opt; int optindex; bool md5auth = false; bool prompt = false; static struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {"prompt", no_argument, NULL, 'p'}, {"md5auth", no_argument, NULL, 'm'}, {"username", required_argument, NULL, 'u'}, {"config-file", required_argument, NULL, 'f'}, {NULL, 0, NULL, 0} }; snprintf(conf_file, sizeof(conf_file), "%s/%s", DEFAULT_CONFIGDIR, POOL_CONF_FILE_NAME); /* initialize username buffer with zeros so that we can use strlen on it later to check if a username was given on the command line */ memset(username, 0, MAX_INPUT_SIZE+1); while ((opt = getopt_long(argc, argv, "hpmf:u:", long_options, &optindex)) != -1) { switch (opt) { case 'p': /* prompt for password */ prompt = true; break; case 'm': /* produce md5 authentication password */ md5auth = true; break; case 'f': /* specify configuration file */ if (!optarg) { PRINT_USAGE(EXIT_SUCCESS); } strlcpy(conf_file, optarg, sizeof(conf_file)); break; case 'u': if (!optarg) { PRINT_USAGE(EXIT_SUCCESS); } /* check the input limit early */ if (strlen(optarg) > MAX_INPUT_SIZE) { fprintf(stderr, "Error: input exceeds maximum username length!\n\n"); exit(EXIT_FAILURE); } strlcpy(username, optarg, sizeof(username)); break; default: PRINT_USAGE(EXIT_SUCCESS); break; } } /* Prompt for password. */ if (prompt) { char md5[MD5_PASSWD_LEN+1]; char buf[MAX_INPUT_SIZE+1]; int len; set_tio_attr(1); printf("password: "******"Couldn't read input from stdin. (fgets(): %s)", strerror(eno)); exit(EXIT_FAILURE); } printf("\n"); set_tio_attr(0); /* Remove LF at the end of line, if there is any. */ len = strlen(buf); if (len > 0 && buf[len-1] == '\n') { buf[len-1] = '\0'; len--; } if (md5auth) { update_pool_passwd(conf_file, username, buf); } else { pool_md5_hash(buf, len, md5); printf("%s\n", md5); } } /* Read password from argv. */ else { char md5[POOL_PASSWD_LEN+1]; int len; if (optind >= argc) { PRINT_USAGE(EXIT_FAILURE); } len = strlen(argv[optind]); if (len > MAX_INPUT_SIZE) { fprintf(stderr, "Error: Input exceeds maximum password length!\n\n"); PRINT_USAGE(EXIT_FAILURE); } if (md5auth) { update_pool_passwd(conf_file, username, argv[optind]); } else { pool_md5_hash(argv[optind], len, md5); printf("%s\n", md5); } } return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { #define PRINT_USAGE(exit_code) print_usage(argv[0], exit_code) #define COMPARE_ARG(arg) (!strcmp(argv[1], arg)) if (argc != 2) PRINT_USAGE(EXIT_FAILURE); else if (COMPARE_ARG("--help") || COMPARE_ARG("-h")) PRINT_USAGE(EXIT_SUCCESS); /* Prompt for password. */ else if (COMPARE_ARG("--prompt") || COMPARE_ARG("-p")) { char md5[MD5_PASSWD_LEN+1]; char buf[MAX_INPUT_SIZE+1]; int len; set_tio_attr(1); printf("password: "******"Couldn't read input from stdin. (fgets(): %s)", strerror(eno)); exit(EXIT_FAILURE); } set_tio_attr(0); /* Remove LF at the end of line, if there is any. */ len = strlen(buf); if (len > 0 && buf[len-1] == '\n') { buf[len-1] = '\0'; len--; } pool_md5_hash(buf, len, md5); printf("\n%s\n", md5); } /* Read password from argv[1]. */ else { char md5[MD5_PASSWD_LEN+1]; int len = strlen(argv[1]); if (len > MAX_INPUT_SIZE) { fprintf(stderr, "Error: Input exceeds maximum password length!\n\n"); PRINT_USAGE(EXIT_FAILURE); } pool_md5_hash(argv[1], len, md5); printf("%s\n", md5); } return EXIT_SUCCESS; }
int main(int argc, char** argv) { QCoreApplication app(argc, argv); QStringList arguments = app.arguments(); showClassNamesOnly = false; showParents = false; caseInsensitive = false; matchPattern = false; if (argc == 1) { PRINT_USAGE(); return 0; } int i = 1; while (i < arguments.length()) { if (arguments[i] == QLatin1String("-h") || arguments[i] == QLatin1String("--help")) { PRINT_USAGE(); return 0; } else if (arguments[i] == QLatin1String("-r") || arguments[i] == QLatin1String("--require")) { i++; if (i < arguments.length()) { smokeModules << loadSmokeModule(arguments[i]); } i++; } else if (arguments[i] == QLatin1String("-c") || arguments[i] == QLatin1String("--classes")) { showClassNamesOnly = true; i++; } else if (arguments[i] == QLatin1String("-p") || arguments[i] == QLatin1String("--parents")) { showParents = true; i++; } else if (arguments[i] == QLatin1String("-i") || arguments[i] == QLatin1String("--insensitive")) { caseInsensitive = true; i++; } else if (arguments[i] == QLatin1String("-m") || arguments[i] == QLatin1String("--match")) { i++; if (i < arguments.length()) { targetPattern = QRegExp(arguments[i]); matchPattern = true; } i++; } else { break; } } if (caseInsensitive) { targetPattern.setCaseSensitivity(Qt::CaseInsensitive); } smokeModules << loadSmokeModule("qtcore"); if (i >= arguments.length()) { if (targetPattern.isEmpty()) { PRINT_USAGE(); return 0; } else { foreach (Smoke * smoke, smokeModules) { for (int i = 1; i <= smoke->numClasses; i++) { if (!smoke->classes[i].external) { showClass(Smoke::ModuleIndex(smoke, i), 0); } } } return 0; } } while (i < arguments.length()) { QString className = arguments[i]; className.replace(".", "::"); Smoke::ModuleIndex classId = Smoke::findClass(className.toLatin1()); if (classId == Smoke::NullModuleIndex) { qFatal("Error: class '%s' not found", className.toLatin1().constData()); } if (showParents) { QList<ClassEntry> parents = getAllParents(classId, 0); foreach (ClassEntry parent, parents) { showClass(parent.first, parent.second); } } else {