static void traverse_file(char *filename) { struct stat buf; int st; int link = 0; int r; st = lstat(filename, &buf); if (!st && S_ISLNK(buf.st_mode)) { /* is a symbolic link */ link = 1; st = stat(filename, &buf); } if (st || !S_ISDIR(buf.st_mode)) { file_action(filename); return; } /* is a directory */ if (cmd.recursive<=1 && link==1) { /* ignore link */ if (cmd.verbose>=0) { fprintf(stderr, "%s: %s: directory is a symbolic link -- ignored\n", cmd.name, filename); symlink_warnings++; } return; } if (cmd.recursive==0) { /* ignore */ if (cmd.verbose>=0) { fprintf(stderr, "%s: %s: is a directory -- ignored\n", cmd.name, filename); isreg_warnings++; } return; } r = known_inode(buf.st_ino, buf.st_dev); if (r != -1) { /* already traversed */ if (cmd.verbose>0) { fprintf(stderr, "Already visited directory %s -- skipped.\n", filename); } return; } add_inode(buf.st_ino, buf.st_dev, 1); /* recursively traverse directory */ { char **filelist; int count; get_filelist(filename, &filelist, &count); traverse_files(filelist, count); free_filelist(filelist, count); } return; }
/** * Loads the emails contained in a path and stores its tokens in a berkeley database. */ void load_directory_mail(char *directory, char *db_path, int type){ filelist *mails_directory=list_files(directory,"eml"); int i=0; DB *dbp=NULL; DB_ENV *bayes_env; map_t tokenbody; char *email; int count=0; //bayes_env=malloc(sizeof(DB_ENV *)); /* If the path is incorrect. */ if(mails_directory==NULL){ wblprintf(LOG_CRITICAL,"LEARN_BAYES","Directory not found"); exit(EXIT_FAILURE); } /* If the directory not contains any e-mail.*/ if (count_files_filelist(mails_directory)==0){ wblprintf(LOG_CRITICAL,"LEARN_BAYES","Directory empty\n"); exit(EXIT_FAILURE); } /*If the environment can't be created.*/ if(create_env(&bayes_env,BAYES_SPAM_LEARN_ENV_PATH)!=DB_OK){ wblprintf(LOG_CRITICAL,"LEARN_BAYES","Could not create environment\n"); exit(EXIT_FAILURE); } /* If the database can't be open.*/ if(create_db_conexion(&dbp, bayes_env, db_path, DB_CREATE)!=DB_OK){ wblprintf(LOG_CRITICAL,"LEARN_BAYES","Could not open database\n"); exit(EXIT_FAILURE); } /*If the e-mail is a spam message, its tokens will be stored in the database as spam tokens.*/ if(type==OPT_SPAM) for(;i<count_files_filelist(mails_directory);i++){ wblprintf(LOG_INFO,"LEARN_BAYES","Spam file name: %s\n",get_file_at(mails_directory,i)); email=loademail(get_file_at(mails_directory,i)); if((tokenbody=tokenizebody(email))!=NULL){ count++; store_mail(dbp,tokenbody,OPT_SPAM); free_tokenize(tokenbody); } else{} free(email); }/*If the e-mail is a ham message, its tokens will be stored in the database as ham tokens.*/ else for(;i<count_files_filelist(mails_directory);i++){ wblprintf(LOG_INFO,"LEARN_BAYES","Ham file name: %s\n",get_file_at(mails_directory,i)); email=loademail(get_file_at(mails_directory,i)); if((tokenbody=tokenizebody(email))!=NULL){ count++; store_mail(dbp,tokenbody,OPT_HAM); free_tokenize(tokenbody); } free(email); } free_filelist(mails_directory); close_db_conexion(&dbp, db_path); bayes_env->close(bayes_env,0); //free(bayes_env); freeEMLParser(); printf("Summary %d messages\n",i); printf(" %d messages inserted\n",count); printf(" %d messages wrong\n",i-count); }
void XMondoRestore::go() { if (!doneSetup) { popup_and_OK ("Please wait for the setup to be completed."); ok = false; return; } pthread_cancel (preparer_thread); disconnect (XMondoCancel, SIGNAL(clicked()), 0, 0); connect (XMondoCancel, SIGNAL(clicked()), this, SLOT(slotAbortRestore())); XMondoProgress->show(); XMondoProgress->setTotalSteps (100); XMondoProgress->setProgress (0); XMondoProgressWhat->show(); XMondoProgressWhat->setText ("Saving your filelist choices."); XMondoProgressWhat2->hide(); XMondoProgressWhat3->hide(); XMondoTimeTaken->hide(); XMondoTimeToGo->hide(); XMondoStatus->setText ("Saving filelist"); XMondoStatus->show(); XMondoLog->setText (""); XMondoLog->show(); if (XM_save_filelist (fList->firstChild()->firstChild(), g_filelist_full) != 0) { XMondoStatus->setText ("Error saving filelist"); ok = false; return; } XMondoStatus->setText ("Reloading filelist"); /*DEBUG*/ system (QString ("cp %1 /home/oremanj/filelist.tested").arg (g_filelist_full).ascii()); s_node *flist = load_filelist (g_filelist_full); if (!flist) { XMondoStatus->setText ("Error loading filelist"); ok = false; return; } XM_toggle_everything_on (flist); XMondoProgress->hide(); XMondoStatus->setText ("Beginning restore"); XMondoProgressWhat->hide(); strcpy (bkpinfo->restore_path, fRestoreDir->text().ascii()); g_text_mode = 1; // avoid crashing on NEWT functions th = new RestoreThread (bkpinfo, flist); th->start(); while (th->running()) { usleep (100000); events.send(); kapp->processEvents(); } free_filelist (flist); if (th->aborted()) { /* do nothing */ } else if (th->returns() == 0) { popup_and_OK ("Restore completed with no errors."); } else { popup_and_OK ("Restore completed; however, there were some errors."); } delete th; th = 0; ok = true; // call destructor in caller }
int main(int argc, char **argv) { static struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"noclear", no_argument, 0, 'c'}, {"alpha", no_argument, 0, 'a'}, {"unhide", no_argument, 0, 'u'}, {"noinfo", no_argument, 0, 'i'}, {"stretch", no_argument, 0, 'f'}, {"colorstrech", no_argument, 0, 'k'}, {"delay", required_argument, 0, 's'}, {"enlarge", no_argument, 0, 'e'}, {"ignore-aspect", no_argument, 0, 'r'}, {"play_folder", required_argument, 0, 'd'}, {0, 0, 0, 0} }; int c, i; char* filelist=NULL; video_out_t vo={0}; vo.name="gles"; if(argc < 2) { help(argv[0]); fprintf(stderr, "Error: Required argument missing.\n"); return(1); } while((c = getopt_long_only(argc, argv, "hcauifks:er", long_options, NULL)) != EOF) { switch(c) { case 'a': opt_alpha = 1; break; case 'c': opt_clear = 0; break; case 's': opt_delay = atoi(optarg); break; case 'u': opt_hide_cursor = 0; break; case 'h': help(argv[0]); return(0); case 'i': opt_image_info = 0; break; case 'f': opt_stretch = 1; break; case 'k': opt_stretch = 2; break; case 'e': opt_enlarge = 1; break; case 'r': opt_ignore_aspect = 1; break; case 'd': filelist = create_filelist(optarg); break; } } #if 0 if(!argv[optind]) { fprintf(stderr, "Required argument missing! Consult %s -h.\n", argv[0]); return(1); } #endif if(vo_cfg(&vo)!=VO_ERROR_OK) { printf("video out device invalid\n"); exit(1); } vo_preinit(&vo); #ifndef WIN32 signal(SIGHUP, sighandler); signal(SIGINT, sighandler); signal(SIGQUIT, sighandler); signal(SIGSEGV, sighandler); signal(SIGTERM, sighandler); signal(SIGABRT, sighandler); if(opt_hide_cursor) { printf("\033[?25l"); fflush(stdout); } setup_console(1); #endif if(filelist) { filelist_t* pre=NULL; char* filename; while(enum_file(filelist,&pre,&filename)!=-1) { if(filename&&strlen(filename)>3) show_image(filename,&vo); } free_filelist(filelist); } else { for(i = optind; argv[i]; ) { int r = show_image(argv[i],&vo); if(!r) break; i += r; if(i < optind) i = optind; } } setup_console(0); if(opt_hide_cursor) { printf("\033[?25h"); fflush(stdout); } vo_uninit(&vo); return(0); }
int main(int argc, char **argv) { signed char op; parserinfo_mv_t pinfo; filelist_t fl; struct option longopts[] = { { "version", 0, NULL, MV_VERSION }, { "help", 0, NULL, MV_HELP }, { "write-files", 0, NULL, MV_FILES }, { "prepend", 0, NULL, MV_PREPEND }, { "replace", 0, NULL, MV_REPLACE }, { "append", 0, NULL, MV_APPEND }, { 0 } }; progname = "xml-mv"; inputfile = ""; inputline = 0; if( create_parserinfo_mv(&pinfo) ) { while( (op = getopt_long(argc, argv, "", longopts, NULL)) > -1 ) { set_option_mv(op, optarg, &pinfo); } init_signal_handling(SIGNALS_DEFAULT); init_file_handling(); init_tempfile_handling(); init_rollback_handling(); if( !checkflag(pinfo.rcm.flags,RCM_CP_PREPEND|RCM_CP_APPEND) ) { setflag(&pinfo.rcm.flags,RCM_CP_APPEND); setflag(&pinfo.rcm.flags,RCM_CP_REPLACE); } if( create_filelist(&fl, -1, argv + optind, FILELIST_MIN2) ) { pinfo.files = getfiles_filelist(&fl); pinfo.xpaths = getxpaths_filelist(&fl); pinfo.n = getsize_filelist(&fl); if( pinfo.n < 2 ) { errormsg(E_FATAL, "no target specified (try --help).\n"); } pinfo.target = pinfo.files[pinfo.n - 1]; pinfo.tpaths = pinfo.xpaths[pinfo.n - 1]; if( !checkflag(pinfo.rcm.flags,RCM_WRITE_FILES) ) { /* When --write-files is not selected, we cannot write * to the files on the command line. So we use the following * trick to implement moves within the target file (last on command * line): we replace all instances of the target with a common * tempfile, which we can write to as required. The first instance * of the target is not replaced, since it must be read (to copy * its contents into the tempfile). */ substitute_target(&pinfo); } if( stdparse2(pinfo.n - 1, pinfo.files, pinfo.xpaths, &pinfo.std) ) { if( reinit_parserinfo_mv(&pinfo) ) { /* output always to stdout */ setflag(&pinfo.rcm.flags, RCM_CP_OUTPUT); clearflag(&pinfo.rcm.flags, RCM_RM_OUTPUT); stdparse2(1, &pinfo.files[pinfo.n - 1], &pinfo.xpaths[pinfo.n - 1], &pinfo.std); } } free_filelist(&fl); } exit_rollback_handling(); exit_tempfile_handling(); exit_file_handling(); exit_signal_handling(); free_parserinfo_mv(&pinfo); } return EXIT_SUCCESS; }