int main(int argc, char **argv) { opt_t *options; int rc = EXIT_FAILURE; options = opt_new(argc, argv); if (options->input) { if (!(yyin = fopen(options->input, "r"))) { int n = errno; log_error("cannot open input file '%s': %s\n", options->input, strerror(n)); goto end; } } if (yyparse() != 0) { log_error("could not parse DDL"); goto end; } if (node_create(file, NULL, options) != 0) { log_error("error creating HDF5 file"); } node_free(file); rc = EXIT_SUCCESS; end: if (options->input) { fclose(yyin); } opt_free(options); return rc; }
int main(int argc, const char *argv[]) { opt_t *o; setlocale(LC_ALL, ""); o = opt_read(argc, argv); if(o->info) sub_info(o); else sub_convert(o); opt_free(o); return 0; }
static void sub_convert(opt_t *o) { buf_t *b = NULL, *bswap = NULL; FILE *f; bool is_8xp; int i; /* if files provided as arguments, loop through them */ if(o->extra_args != NULL) { i = 0; while(o->extra_args[i] != NULL) { /* read file */ f = fopen(o->extra_args[i], "r"); if(f == NULL) { MAIN_ERR_CONV(errno, "could not open file \"%s\" for reading", o->extra_args[i]); } b = buf_read(f); fclose(f); /* ensure input formats are consistent */ if(i == 0) { is_8xp = b->is_8xp; } else { if(is_8xp != b->is_8xp) MAIN_ERR_CONV(EPERM, "inconsistent input file formats"); } /* convert file and append to bswap */ if(is_8xp) { /* TODO: expand */ if(bswap == NULL) bswap = buf_new(false); bswap = parse_buf_byte(b, bswap, o->list, o->extra_args[i], o->pretty, o->safe); } else { if(bswap == NULL) bswap = buf_new(true); bswap = parse_buf_str(b, bswap, o->list, o->extra_args[i]); } buf_free(b); b = NULL; /* error converting. */ if(bswap == NULL) { opt_free(o); exit(EINVAL); } i++; } /* else read a single file from stdin */ } else { b = buf_read(stdin); is_8xp = b->is_8xp; /* convert stdin */ if(is_8xp) { bswap = buf_new(true); bswap = parse_buf_byte(b, bswap, o->list, "stdin", o->pretty, o->safe); } else { bswap = buf_new(false); bswap = parse_buf_str(b, bswap, o->list, "stdin"); } buf_free(b); b = NULL; /* error converting. */ if(bswap == NULL) { opt_free(o); exit(EINVAL); } } /* end reading */ b = bswap; bswap = NULL; /* pack, if necessary */ if(!is_8xp) { if(o->name != NULL) bswap = header_pack_buf(b, o->name, o->archived); else bswap = header_pack_buf(b, "A", o->archived); buf_free(b); b = bswap; bswap = NULL; /* TODO: compact */ } /* write to file */ if(o->output != NULL) { f = fopen(o->output, "w"); if(f == NULL) { MAIN_ERR_CONV(errno, "could not open file \"%s\" for writing", o->output); } buf_write(b, f); fclose(f); buf_free(b); return; } else { buf_write(b, stdout); buf_free(b); return; } }
int main(int argc, char *argv[]) { opt_t opt; int retval = 0; const char *m; /* * Initialize. */ err_init(xbasename(argv[0])); /* init err package */ /* * If running setuid, fork a child to handle * all privileged operations and drop privs in this process. */ privsep_init(); /* * Seed options with default values: */ opt_default(&opt, argv[0]); /* * Override defaults with environment */ opt_env(&opt); /* * Process any options that need to be handled early: */ opt_args_early(&opt, argc, argv); /* * Load static or dynamic pdsh modules */ mod_init(); /* * Allow module directory to be overridden, but not when * running as root or setuid. (This is mainly for testing...) */ if (!(m = getenv ("PDSH_MODULE_DIR")) || getuid() == 0 || getuid() != geteuid()) m = pdsh_module_dir; if (mod_load_modules(m, &opt) < 0) errx("%p: Couldn't load any pdsh modules\n"); /* * Handle options. */ opt_args(&opt, argc, argv); /* override with command line */ if (opt_verify(&opt)) { /* verify options, print errors */ /* * Do the work. */ if (opt.info_only) /* display info only */ opt_list(&opt); else if (pdsh_personality() == PCP && opt.pcp_server) retval = (_pcp_remote_server (&opt) < 0); else if (pdsh_personality() == PCP && opt.pcp_client) retval = (_pcp_remote_client (&opt) < 0); else if (pdsh_personality() == PCP || opt.cmd != NULL) retval = dsh(&opt); /* single dsh/pcp command */ else /* prompt loop */ _interactive_dsh(&opt); } else { retval = 1; } mod_exit(); /* * Clean up. */ privsep_fini(); opt_free(&opt); /* free heap storage in opt struct */ err_cleanup(); return retval; }
int main(int argc, char** argv) { MYOPT o = opt_new("Verbose,Expression:,selMatch::(with optiona arg),~Maxim,nothing"); opt_usage("test",o); INT32 c; CHAR* arg; while ( -1 != (c = opt_parse(&arg,o,argc,argv)) ) printf("[%s] arg:%c%s%s\n",opt_fromc(o,c),c,(arg) ? " = " : " ",(arg) ? arg : " "); opt_free(o); /* INT32 optindex = 0; CHAR p[512]; INT32 c; CHAR* carg; while ( -1 != (c = getopt_long (argc, argv, "hve:s:", long_options, &optindex)) ) { if ( optarg ) { if (optarg[0] == '=' ) carg = &optarg[1]; else carg = &optarg[0]; carg = str_skipspace(carg); } else { carg = NULL; } switch (c) { default: case '?': case ':':case 'h': usage(); break; case 'v': verbose = TRUE; break; case 'p': port = atoi(optarg); break; case 's': if ( carg ) { if ( server_new(&irc,carg,port) ) {if ( verbose ) puts("ok");} else {if ( verbose ) puts("error on create new server");} break; } view_dir(irc.path,TRUE); break; case 'n': if ( carg ) { nick_set(&irc,carg,irc.user); if ( !verbose ) break; } printf("<%s>\n",irc.nick); break; case 'u': if ( carg ) { nick_set(&irc,irc.nick,carg); if ( !verbose ) break; } printf("<!%s>\n",irc.user); break; case 'd': con_cls(); debug(&irc); con_gets(p,512); break; } } CHAR inp[2048]; while( fgets(inp,2048,stdin) ) { } puts("Regular expression:"); CHAR* s = "if ( \'ciao mondo\' )"; printf("expression:\"%s\"\n",s); printf("regex:"); con_flush(); CHAR inp[1024]; con_gets(inp,1024); if ( !inp[0] ) return 0; REGEX rex; INT32 ret = rex_mk(&rex,inp); if ( ret ) { rex_perror(ret,&rex); return 0; } CHAR* sto; CHAR* eno; CHAR* f = s; puts("match:"); while ( 0 == (ret = rex_exec(&sto,&eno,&f,&rex)) ) { printf("(%p)\'%.*s\'\n",sto,eno-sto,sto); } if ( REX_NOMATCH == ret ) { puts(":end"); } else { printf(":(%d)",ret); rex_perror(ret,&rex); } */ return 0; }
/* zerstört das GUI */ void gui_destroy(void) { opt_free(); gtk_main_quit(); }
int main(int argc, char **argv) { int ds, dms, ret; double mb; struct timeval t1, t2; #ifndef C_WINDOWS struct timezone tz; sigset_t sigset; #endif struct optstruct *opt; const char *pt; #if defined(C_WINDOWS) && defined(CL_THREAD_SAFE) if(!pthread_win32_process_attach_np()) { mprintf("!Can't start the win32 pthreads layer\n"); return 72; } #endif #if !defined(C_WINDOWS) && !defined(C_BEOS) sigemptyset(&sigset); sigaddset(&sigset, SIGXFSZ); sigprocmask(SIG_SETMASK, &sigset, NULL); #endif opt = opt_parse(argc, argv, clamscan_shortopt, clamscan_longopt, NULL, clamscan_deprecated); if(!opt) { mprintf("!Can't parse the command line\n"); return 40; } if(opt_check(opt, "verbose")) { mprintf_verbose = 1; logg_verbose = 1; } if(opt_check(opt, "quiet")) mprintf_quiet = 1; if(opt_check(opt, "stdout")) mprintf_stdout = 1; if(opt_check(opt, "debug")) { #if defined(C_LINUX) /* [email protected]: create a dump if needed */ struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = RLIM_INFINITY; if(setrlimit(RLIMIT_CORE, &rlim) < 0) perror("setrlimit"); #endif cl_debug(); /* enable debug messages */ } if(opt_check(opt, "version")) { print_version(opt_arg(opt, "database")); opt_free(opt); return 0; } if(opt_check(opt, "help")) { opt_free(opt); help(); return 0; } if(opt_check(opt, "recursive")) recursion = 1; if(opt_check(opt, "infected")) printinfected = 1; if(opt_check(opt, "bell")) bell = 1; if(opt_check(opt, "tempdir")) cl_settempdir(opt_arg(opt, "tempdir"), 0); if(opt_check(opt, "leave-temps")) cl_settempdir(NULL, 1); /* initialize logger */ if(opt_check(opt, "log")) { logg_file = opt_arg(opt, "log"); if(logg("#\n-------------------------------------------------------------------------------\n\n")) { mprintf("!Problem with internal logger.\n"); opt_free(opt); return 62; } } else logg_file = NULL; /* validate some numerical options */ if(opt_check(opt, "max-scansize")) { pt = opt_arg(opt, "max-scansize"); if(!strchr(pt, 'M') && !strchr(pt, 'm')) { if(!cli_isnumber(pt)) { logg("!--max-scansize requires a natural number\n"); opt_free(opt); return 40; } } } if(opt_check(opt, "max-filesize")) { pt = opt_arg(opt, "max-filesize"); if(!strchr(pt, 'M') && !strchr(pt, 'm')) { if(!cli_isnumber(pt)) { logg("!--max-filesize requires a natural number\n"); opt_free(opt); return 40; } } } if(opt_check(opt, "max-files")) { if(!cli_isnumber(opt_arg(opt, "max-files"))) { logg("!--max-files requires a natural number\n"); opt_free(opt); return 40; } } if(opt_check(opt, "max-recursion")) { if(!cli_isnumber(opt_arg(opt, "max-recursion"))) { logg("!--max-recursion requires a natural number\n"); opt_free(opt); return 40; } } if(opt_check(opt, "max-mail-recursion")) { if(!cli_isnumber(opt_arg(opt, "max-mail-recursion"))) { logg("!--max-mail-recursion requires a natural number\n"); opt_free(opt); return 40; } } if(opt_check(opt, "max-dir-recursion")) { if(!cli_isnumber(opt_arg(opt, "max-dir-recursion"))) { logg("!--max-dir-recursion requires a natural number\n"); opt_free(opt); return 40; } } if(opt_check(opt, "max-ratio")) { if(!cli_isnumber(opt_arg(opt, "max-ratio"))) { logg("!--max-ratio requires a natural number\n"); opt_free(opt); return 40; } } memset(&info, 0, sizeof(struct s_info)); #ifdef _WIN32 SetConsoleCtrlHandler((PHANDLER_ROUTINE) clamscan_ctrl_handler, TRUE); #endif #ifdef C_WINDOWS _set_fmode(_O_BINARY); #ifdef CL_DEBUG { _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); } #endif gettimeofday(&t1, NULL); #else gettimeofday(&t1, &tz); #endif ret = scanmanager(opt); if(!opt_check(opt, "disable-summary") && !opt_check(opt, "no-summary")) { #ifdef C_WINDOWS gettimeofday(&t2, NULL); #else gettimeofday(&t2, &tz); #endif ds = t2.tv_sec - t1.tv_sec; dms = t2.tv_usec - t1.tv_usec; ds -= (dms < 0) ? (1):(0); dms += (dms < 0) ? (1000000):(0); logg("\n----------- SCAN SUMMARY -----------\n"); logg("Known viruses: %u\n", info.sigs); logg("Engine version: %s\n", get_version()); logg("Scanned directories: %u\n", info.dirs); logg("Scanned files: %u\n", info.files); logg("Infected files: %u\n", info.ifiles); if(info.notremoved) { logg("Not removed: %u\n", info.notremoved); } if(info.notmoved) { logg("Not %s: %u\n", opt_check(opt, "copy") ? "moved" : "copied", info.notmoved); } mb = info.blocks * (CL_COUNT_PRECISION / 1024) / 1024.0; logg("Data scanned: %2.2lf MB\n", mb); logg("Time: %u.%3.3u sec (%u m %u s)\n", ds, dms/1000, ds/60, ds%60); } opt_free(opt); #if defined(C_WINDOWS) && defined(CL_THREAD_SAFE) if(!pthread_win32_process_detach_np()) { logg("!Can't stop the win32 pthreads layer\n"); return 72; } #endif return ret; }