/* loadsave values: * 0 : Load Model * 1 : Save Model * 2 : Load Template * 3 : Load Icon * 4 : Load Layout */ void MODELPage_ShowLoadSave(int loadsave, void(*return_page)(int page)) { u8 num_models = 0; PAGE_RemoveAllObjects(); PAGE_SetModal(1); mp->return_page = return_page; _show_buttons(loadsave); if (loadsave == LOAD_TEMPLATE) { //Template num_models = count_files("template", ".ini", NULL); mp->selected = 1; } else if (loadsave == LOAD_ICON) { //Icon mp->selected = 0; num_models = 1 + count_files("modelico", ".bmp", Model.icon[0] ? Model.icon+9 : NULL); const char *ico = mp->selected == 0 ? CONFIG_GetIcon(Model.type) : CONFIG_GetCurrentIcon(); strlcpy(mp->iconstr, ico, sizeof(mp->iconstr)); mp->selected++; } else if (loadsave == LOAD_LAYOUT) { //Layout mp->selected = 1; num_models = count_files("layout", ".ini", "default.ini"); mp->file_state = num_models; num_models += model_count(); } else { num_models = model_count(); strlcpy(mp->iconstr, CONFIG_GetCurrentIcon(), sizeof(mp->iconstr)); if (loadsave == SAVE_MODEL) mp->selected = 0; else mp->selected = CONFIG_GetCurrentModel(); } _show_list(loadsave, num_models); }
void do_memory(USER_DATA *usr, char *argument) { HELP_DATA *fHelp; char buf[STRING]; int count1, count2; memory_other(usr); do_statforum(usr, ""); memory_validates(usr); memory_banishes(usr); count1 = count2 = 0; for (fHelp = first_help; fHelp; fHelp = fHelp->next) count1++; sprintf(buf, "Help : %4d -- %d bytes\n\r", count1, count1 * (sizeof(*fHelp))); send_to_user(buf, usr); sprintf(buf, "Strings %5d strings of %7d bytes (max %d).\n\r", nAllocString, sAllocString, MAX_STRING); send_to_user(buf, usr); sprintf(buf, "Perms %5d blocks of %7d bytes.\n\r", nAllocPerm, sAllocPerm); send_to_user(buf, usr); sprintf(buf, "Total %d users found.\n\r", count_files(USER_DIR)); send_to_user(buf, usr); return; }
int get_file_size(const char* filename) { int i; for(i=0; i < count_files(); i++) if(strcmp(filename, get_file_name_at(i))==0) return fs_files[i].size; return -1; }
static unsigned int get_offset(const char* filename) { int i; for(i=0; i < count_files(); i++) if(strcmp(filename, get_file_name_at(i))==0) return fs_files[i].offset; return -1; }
/* return 0 on success, -1 on failure */ static int print_count (notmuch_database_t *notmuch, const char *query_str, const char **exclude_tags, size_t exclude_tags_length, int output, int print_lastmod) { notmuch_query_t *query; size_t i; int count; unsigned int ucount; unsigned long revision; const char *uuid; int ret = 0; notmuch_status_t status; query = notmuch_query_create (notmuch, query_str); if (query == NULL) { fprintf (stderr, "Out of memory\n"); return -1; } for (i = 0; i < exclude_tags_length; i++) notmuch_query_add_tag_exclude (query, exclude_tags[i]); switch (output) { case OUTPUT_MESSAGES: status = notmuch_query_count_messages_st (query, &ucount); if (print_status_query ("notmuch count", query, status)) return -1; printf ("%u", ucount); break; case OUTPUT_THREADS: status = notmuch_query_count_threads_st (query, &ucount); if (print_status_query ("notmuch count", query, status)) return -1; printf ("%u", ucount); break; case OUTPUT_FILES: count = count_files (query); if (count >= 0) { printf ("%u", count); } else { ret = -1; goto DONE; } break; } if (print_lastmod) { revision = notmuch_database_get_revision (notmuch, &uuid); printf ("\t%s\t%lu\n", uuid, revision); } else { fputs ("\n", stdout); } DONE: notmuch_query_destroy (query); return ret; }
void LocalZipTask::run() { set_has_error(false); // 检查路径存在性 const QString source = get_source(), destination = get_destination(); if (!QFileInfo(source).exists()) { set_msg("Source path not exists: " + source); set_has_error(true); return; } if (!QFileInfo(QFileInfo(destination).path()).exists()) // XXX QFileInfo.path() 返回父目录 { set_msg("Parent directory of ZIP destination not exists: " + QFileInfo(destination).path()); set_has_error(true); return; } // 首先检查是否需要更新 set_msg("Checking..."); bool needUpdate = true; if (QFileInfo(destination).exists() && !QFileInfo(destination).isDir()) { const QDateTime mtime = QFileInfo(destination).lastModified(); needUpdate = newer_than(source, mtime); } if (!needUpdate) { set_msg("No need to update at " + QString::fromStdString(DateTime().get_clock_str()) + "."); return; } // 计算工作量 set_msg("Counting..."); _total_files = count_files(source); _compressed_files = 0; // 压缩文件/文件夹到zip bool rs = zip(); if (rs) set_msg("Last done at " + QString::fromStdString(DateTime().get_clock_str()) + "."); state_changed(); }
/* * Initialisieren der Datenstruktur zum Abbilden des programminternen * Berechnungsstatus */ void init_values(struct state* state) { memset(state, 0, sizeof(struct state)); /* Initialisieren der Farbskala */ init_colorclasses(state); /* Anzahl der Trajektorinedateien auslesen */ state->list_max = count_files(); /* Speicherplatz reservieren */ state->list = (char**)calloc(sizeof(char*), state->list_max); /* Minimale und maximale Koordinatenwerte der in den fuer die * Berechnung zu verwendenden Trajektorienaufpunkte bestimmen */ get_lo_la_min_max(state); /* Bestimmen der benoetigten Netzelementeanzahl (abhaengig von * Netzelementgroesse (Aufloesung) und der Groesse des * Berechnungsgebiets (lo_min, la_min, lo_max, la_max)) */ count_squares(state); /* Errechnen der Gesamtanzahl der Netzelemente */ state->field_max = state->x_field * state->y_field; /* Reservieren des benoetigten Speicherplatzes fuer die * Trajektoriendichte-Speicherstruktur */ state->field_grid = (double*)calloc(sizeof(double), state->field_max); /* Berechnungsnetz Initialisieren */ init_field(state->field_grid, state->field_max); /* Kann gewuenschte Ausgabedatei angelegt werden? */ if (!(state->fh = fopen(get_string(FILENAME), "w"))) { printf("Couldn't write file %s!\n", get_string(FILENAME)); exit(1); } }
int count_files(char* dirname) { int return_code, i; DIR *dir_ptr; struct dirent entry; struct dirent *result; struct stat mybuf; char buf[256]; int num_of_files=0; if ((dir_ptr = opendir (dirname)) == NULL) { fprintf(stderr,"count files: couldn't open folder"); return -1; } else { while( ( return_code = readdir_r(dir_ptr, &entry, &result) ) == 0 && result!=NULL) { if (entry.d_ino==0) continue; if ( strcmp(entry.d_name,".")==0 || strcmp(entry.d_name,"..")==0) continue; strcpy(buf,dirname); strcat(buf,"/"); strcat(buf, entry.d_name); if ( stat (buf, & mybuf ) < 0) { perror ( buf ) ; continue ; } if (( mybuf.st_mode & S_IFMT ) == S_IFDIR ) // directory encountered { if ( (num_of_files += count_files(buf)) == -1) { fprintf(stderr,"count files recursion error"); return -1; } } else // file encountered { num_of_files++; } } closedir(dir_ptr); } return num_of_files; }
void count_files(char *dir, long *idx_range_count, long idx_range[MAX_IDX_RANGE][2], long *max_file_size) { struct dirent *de = NULL; DIR *d = NULL; char path[256]; long file_names[MAX_FILE_PER_FOLDER]; char file_types[MAX_FILE_PER_FOLDER]; int file_count = 0; int i; struct stat file_stat; d = opendir(dir); if(d == NULL) return; // Loop while not NULL while ((de = readdir(d)) != NULL) { if (de->d_name[0] != '.') { add_file_name(atol(de->d_name), de->d_type, file_names, file_types, &file_count); } } for (i = 0; i < file_count; i++) { if (file_types[i] == DT_DIR) { sprintf(path, "%s/%ld", dir, file_names[i]); count_files(path, idx_range_count, idx_range, max_file_size); } else if (file_types[i] == DT_REG) { add_idx_to_range(file_names[i], idx_range_count, idx_range); sprintf(path, "%s/%ld", dir, file_names[i]); stat(path, &file_stat); if (file_stat.st_size > *max_file_size) *max_file_size = file_stat.st_size; } } closedir(d); }
int read_arg_dir(t_file *paths, t_command *command, int newline) { t_file *tmp; tmp = paths; while (tmp) { if (tmp->infos && S_ISDIR(tmp->infos->st_mode)) { if (!(read_directory(tmp->name, command, newline, count_files(paths)))) return (-1); if (newline == 0) newline++; } tmp = tmp->next; } return (1); }
void search_directory(char *absolute_dirname, bool recursive) { struct z_story_list *z_story_list = get_z_story_list(); struct babel_info *babel = load_babel_info(); #ifndef DISABLE_CONFIGFILES ensure_dot_fizmo_dir_exists(); #endif // DISABLE_CONFIGFILES if ((nof_files_found = count_files(absolute_dirname, recursive)) > 0) { show_progress = true; nof_files_searched = 0; nof_directories_searched = 0; build_filelist(absolute_dirname, z_story_list, recursive, babel); } //printf("%d, %s\n", z_story_list->nof_entries, absolute_dirname); save_story_list(z_story_list); store_babel_info_timestamps(babel); free_z_story_list(z_story_list); free_babel_info(babel); }
static int check_config(void) { int i, n1 = 0, n2, j, k; int total = 0; struct section_problem_data *prb = 0; struct section_tester_data *tst = 0; unsigned char *var_test_dir; unsigned char *var_corr_dir; unsigned char *var_info_dir; unsigned char *var_tgz_dir; problem_xml_t px; const struct section_global_data *global = serve_state.global; if (skip_arch_count > 0) { for (i = 0; i < serve_state.max_abstr_tester; ++i) { tst = serve_state.abstr_testers[i]; if (!tst) continue; tst->skip_testing = -1; for (j = 0; j < skip_arch_count; ++j) { if (!strcmp(skip_archs[j], tst->arch)) { break; } } if (j < skip_arch_count) { tst->skip_testing = 1; } } } /* check spooler dirs */ if (check_writable_spool(global->run_queue_dir, SPOOL_OUT) < 0) return -1; if (check_writable_dir(global->run_exe_dir) < 0) return -1; /* check working dirs */ if (make_writable(global->run_work_dir) < 0) return -1; if (check_writable_dir(global->run_work_dir) < 0) return -1; for (i = 1; i <= serve_state.max_prob; i++) { prb = serve_state.probs[i]; if (!prb) continue; if (prb->disable_testing) continue; if (prb->manual_checking) continue; /* ignore output-only problems with XML and answer variants */ px = 0; if (prb->variant_num > 0 && prb->xml.a) { px = prb->xml.a[0]; } else { px = prb->xml.p; } if (px && px->answers) { prb->disable_testing = 1; continue; } // check if there exists a tester for this problem for (j = 1; j <= serve_state.max_tester; j++) { if (!serve_state.testers[j]) continue; if (serve_state.testers[j]->any) break; if (serve_state.testers[j]->problem == i) break; } if (j > serve_state.max_tester) { // no checker for the problem :-( info("no checker found for problem %d", i); continue; } if (prb->type > 0 && prb->type != PROB_TYPE_TESTS) { // output-only problems have no input file if (prb->variant_num <= 0) { if (prb->use_corr) { if (!prb->corr_dir[0]) { err("directory with answers is not defined"); return -1; } if (global->advanced_layout > 0) { var_corr_dir = (unsigned char*) alloca(sizeof(path_t)); get_advanced_layout_path(var_corr_dir, sizeof(path_t), global, prb, DFLT_P_CORR_DIR, -1); } else { var_corr_dir = prb->corr_dir; } if (check_readable_dir(var_corr_dir) < 0) return -1; if ((n2 = count_files(var_corr_dir,prb->corr_sfx,prb->corr_pat)) < 0) return -1; n1 = n2; info("found %d answers for problem %s", n2, prb->short_name); if (n2 != 1) { err("output-only problem must define only one answer file"); return -1; } } if (prb->use_info) { if (!prb->info_dir[0]) { err("directory with test information is not defined"); return -1; } if (global->advanced_layout > 0) { var_info_dir = (unsigned char*) alloca(sizeof(path_t)); get_advanced_layout_path(var_info_dir, sizeof(path_t), global, prb, DFLT_P_INFO_DIR, -1); } else { var_info_dir = prb->info_dir; } if (check_readable_dir(var_info_dir) < 0) return -1; if ((n2 = count_files(var_info_dir,prb->info_sfx,prb->info_pat)) < 0) return -1; info("found %d info files for problem %s", n2, prb->short_name); if (n2 != 1) { err("output-only problem must define only one info file"); return -1; } } if (prb->use_tgz) { if (!prb->tgz_dir[0]) { err("directory with tgz information is not defined"); return -1; } if (global->advanced_layout > 0) { var_tgz_dir = (unsigned char*) alloca(sizeof(path_t)); get_advanced_layout_path(var_tgz_dir, sizeof(path_t), global, prb, DFLT_P_TGZ_DIR, -1); } else { var_tgz_dir = prb->tgz_dir; } if (check_readable_dir(var_tgz_dir) < 0) return -1; if ((n2 = count_files(var_tgz_dir, prb->tgz_sfx, 0)) < 0) return -1; info("found %d tgz files for problem %s", n2, prb->short_name); if (n2 != 1) { err("output-only problem must define only one tgz file"); return -1; } } } else { var_test_dir = (unsigned char *) alloca(sizeof(path_t)); var_corr_dir = (unsigned char *) alloca(sizeof(path_t)); var_info_dir = (unsigned char *) alloca(sizeof(path_t)); var_tgz_dir = (unsigned char *) alloca(sizeof(path_t)); for (k = 1; k <= prb->variant_num; k++) { if (global->advanced_layout > 0) { get_advanced_layout_path(var_test_dir, sizeof(path_t), global, prb, DFLT_P_TEST_DIR, k); get_advanced_layout_path(var_corr_dir, sizeof(path_t), global, prb, DFLT_P_CORR_DIR, k); get_advanced_layout_path(var_info_dir, sizeof(path_t), global, prb, DFLT_P_INFO_DIR, k); get_advanced_layout_path(var_tgz_dir, sizeof(path_t), global, prb, DFLT_P_TGZ_DIR, k); } else { snprintf(var_test_dir, sizeof(path_t), "%s-%d", prb->test_dir, k); snprintf(var_corr_dir, sizeof(path_t), "%s-%d", prb->corr_dir, k); snprintf(var_info_dir, sizeof(path_t), "%s-%d", prb->info_dir, k); snprintf(var_tgz_dir, sizeof(path_t), "%s-%d", prb->tgz_dir, k); } if (prb->use_corr) { if (!prb->corr_dir[0]) { err("directory with answers is not defined"); return -1; } if (check_readable_dir(var_corr_dir) < 0) return -1; if ((j = count_files(var_corr_dir,prb->corr_sfx,prb->corr_pat)) < 0) return -1; if (j != 1) { err("output-only problem must define only one answer file"); return -1; } } if (prb->use_info) { if (!prb->info_dir[0]) { err("directory with test infos is not defined"); return -1; } if (check_readable_dir(var_info_dir) < 0) return -1; if ((j = count_files(var_info_dir,prb->info_sfx,prb->info_pat)) < 0) return -1; if (j != 1) { err("output-only problem must define only one info file"); return -1; } } if (prb->use_tgz) { if (!prb->tgz_dir[0]) { err("directory with tgz is not defined"); return -1; } if (check_readable_dir(var_tgz_dir) < 0) return -1; if ((j = count_files(var_tgz_dir, prb->tgz_sfx, 0)) < 0) return -1; if (j != 1) { err("output-only problem must define only one info file"); return -1; } } } n1 = n2 = 1; } } else if (!prb->type) { /* check existence of tests */ if (prb->variant_num <= 0) { if (global->advanced_layout > 0) { var_test_dir = (unsigned char *) alloca(sizeof(path_t)); get_advanced_layout_path(var_test_dir, sizeof(path_t), global, prb, DFLT_P_TEST_DIR, -1); } else { var_test_dir = prb->test_dir; } if (check_readable_dir(var_test_dir) < 0) return -1; if ((n1 = count_files(var_test_dir, prb->test_sfx, prb->test_pat)) < 0) return -1; if (!n1) { err("'%s' does not contain any tests", var_test_dir); return -1; } /* if (prb->type_val > 0 && n1 != 1) { err("`%s' must have only one test (as output-only problem)", prb->short_name); return -1; } */ info("found %d tests for problem %s", n1, prb->short_name); if (n1 < prb->tests_to_accept) { err("%d tests required for problem acceptance!",prb->tests_to_accept); return -1; } if (prb->use_corr) { if (!prb->corr_dir[0]) { err("directory with answers is not defined"); return -1; } if (global->advanced_layout > 0) { var_corr_dir = (unsigned char *) alloca(sizeof(path_t)); get_advanced_layout_path(var_corr_dir, sizeof(path_t), global, prb, DFLT_P_CORR_DIR, -1); } else { var_corr_dir = prb->corr_dir; } if (check_readable_dir(var_corr_dir) < 0) return -1; if ((n2 = count_files(var_corr_dir,prb->corr_sfx,prb->corr_pat)) < 0) return -1; info("found %d answers for problem %s", n2, prb->short_name); if (n1 != n2) { err("number of test does not match number of answers"); return -1; } } if (prb->use_info) { if (!prb->info_dir[0]) { err("directory with test information is not defined"); return -1; } if (global->advanced_layout > 0) { var_info_dir = (unsigned char *) alloca(sizeof(path_t)); get_advanced_layout_path(var_info_dir, sizeof(path_t), global, prb, DFLT_P_INFO_DIR, -1); } else { var_info_dir = prb->info_dir; } if (check_readable_dir(var_info_dir) < 0) return -1; if ((n2 = count_files(var_info_dir,prb->info_sfx,prb->info_pat)) < 0) return -1; info("found %d info files for problem %s", n2, prb->short_name); if (n1 != n2) { err("number of test does not match number of info files"); return -1; } } if (prb->use_tgz) { if (!prb->tgz_dir[0]) { err("directory with tgz information is not defined"); return -1; } if (global->advanced_layout > 0) { var_tgz_dir = (unsigned char *) alloca(sizeof(path_t)); get_advanced_layout_path(var_tgz_dir, sizeof(path_t), global, prb, DFLT_P_TGZ_DIR, -1); } else { var_tgz_dir = prb->tgz_dir; } if (check_readable_dir(var_tgz_dir) < 0) return -1; if ((n2 = count_files(var_tgz_dir, prb->tgz_sfx, 0)) < 0) return -1; info("found %d tgz files for problem %s", n2, prb->short_name); if (n1 != n2) { err("number of test does not match number of tgz files"); return -1; } } } else { n1 = n2 = -1; var_test_dir = (unsigned char *) alloca(sizeof(path_t)); var_corr_dir = (unsigned char *) alloca(sizeof(path_t)); var_info_dir = (unsigned char *) alloca(sizeof(path_t)); var_tgz_dir = (unsigned char *) alloca(sizeof(path_t)); for (k = 1; k <= prb->variant_num; k++) { if (global->advanced_layout > 0) { get_advanced_layout_path(var_test_dir, sizeof(path_t), global, prb, DFLT_P_TEST_DIR, k); get_advanced_layout_path(var_corr_dir, sizeof(path_t), global, prb, DFLT_P_CORR_DIR, k); get_advanced_layout_path(var_info_dir, sizeof(path_t), global, prb, DFLT_P_INFO_DIR, k); get_advanced_layout_path(var_tgz_dir, sizeof(path_t), global, prb, DFLT_P_TGZ_DIR, k); } else { snprintf(var_test_dir, sizeof(path_t), "%s-%d", prb->test_dir, k); snprintf(var_corr_dir, sizeof(path_t), "%s-%d", prb->corr_dir, k); snprintf(var_info_dir, sizeof(path_t), "%s-%d", prb->info_dir, k); snprintf(var_tgz_dir, sizeof(path_t), "%s-%d", prb->tgz_dir, k); } if (check_readable_dir(var_test_dir) < 0) return -1; if ((j = count_files(var_test_dir, prb->test_sfx, prb->test_pat)) < 0) return -1; if (!j) { err("'%s' does not contain any tests", var_test_dir); return -1; } /* if (prb->type_val > 0 && n1 != 1) { err("`%s', variant %d must have only one test (as output-only problem)", prb->short_name, j); return -1; } */ if (n1 < 0) n1 = j; if (n1 != j) { err("number of tests %d for variant %d does not equal %d", j, k, n1); return -1; } info("found %d tests for problem %s, variant %d", n1, prb->short_name, k); if (n1 < prb->tests_to_accept) { err("%d tests required for problem acceptance!", prb->tests_to_accept); return -1; } if (prb->use_corr) { if (!prb->corr_dir[0]) { err("directory with answers is not defined"); return -1; } if (check_readable_dir(var_corr_dir) < 0) return -1; if ((j = count_files(var_corr_dir,prb->corr_sfx,prb->corr_pat)) < 0) return -1; info("found %d answers for problem %s, variant %d", j, prb->short_name, k); if (n1 != j) { err("number of tests %d does not match number of answers %d", n1, j); return -1; } } if (prb->use_info) { if (!prb->info_dir[0]) { err("directory with test infos is not defined"); return -1; } if (check_readable_dir(var_info_dir) < 0) return -1; if ((j = count_files(var_info_dir,prb->info_sfx,prb->info_pat)) < 0) return -1; info("found %d test infos for problem %s, variant %d", j, prb->short_name, k); if (n1 != j) { err("number of tests %d does not match number of test infos %d", n1, j); return -1; } } if (prb->use_tgz) { if (!prb->tgz_dir[0]) { err("directory with tgz is not defined"); return -1; } if (check_readable_dir(var_tgz_dir) < 0) return -1; if ((j = count_files(var_tgz_dir, prb->tgz_sfx, 0)) < 0) return -1; info("found %d tgzs for problem %s, variant %d", j, prb->short_name, k); if (n1 != j) { err("number of tests %d does not match number of tgz %d", n1, j); return -1; } } n2 = n1; } } } if (n1 >= tests_a - 1) { if (!tests_a) tests_a = 128; while (n1 >= tests_a - 1) tests_a *= 2; xfree(tests); XCALLOC(tests, tests_a); } ASSERT(prb->test_score >= 0); if (global->score_system == SCORE_MOSCOW) { if (prb->full_score <= 0) { err("problem %s: problem full_score is not set", prb->short_name); return -1; } prb->ntests = n1; if (!prb->scoring_checker) { if (!(prb->x_score_tests = prepare_parse_score_tests(prb->score_tests, prb->full_score))){ err("problem %s: parsing of score_tests failed", prb->short_name); return -1; } prb->x_score_tests[prb->full_score - 1] = n1 + 1; if (prb->full_score > 1 && prb->x_score_tests[prb->full_score - 2] > n1 + 1) { err("problem %s: score_tests[%d] > score_tests[%d]", prb->short_name, prb->full_score - 2, prb->full_score - 1); return -1; } } } else if (prb->test_score >= 0 && global->score_system != SCORE_ACM) { int score_summ = 0; prb->ntests = n1; XCALLOC(prb->tscores, prb->ntests + 1); for (j = 1; j <= prb->ntests; j++) prb->tscores[j] = prb->test_score; // test_score_list overrides test_score if (prb->test_score_list && prb->test_score_list[0]) { char const *s = prb->test_score_list; int tn = 1; int was_indices = 0; int n; int index, score; while (1) { while (*s > 0 && *s <= ' ') s++; if (!*s) break; if (*s == '[') { if (sscanf(s, "[ %d ] %d%n", &index, &score, &n) != 2) { err("cannot parse test_score_list for problem %s", prb->short_name); return -1; } if (index < 1 || index > prb->ntests) { err("problem %s: test_score_list: index out of range", prb->short_name); return -1; } if (score < 0) { err("problem %s: test_score_list: invalid score", prb->short_name); return -1; } tn = index; was_indices = 1; prb->tscores[tn++] = score; s += n; } else { if (sscanf(s, "%d%n", &score, &n) != 1) { err("cannot parse test_score_list for problem %s", prb->short_name); return -1; } if (score < 0) { err("problem %s: test_score_list: invalid score", prb->short_name); return -1; } if (tn > prb->ntests) { err("problem %s: too many scores specified", prb->short_name); return -1; } prb->tscores[tn++] = score; s += n; } } if (!was_indices && tn <= prb->ntests) { info("test_score_list for problem %s defines only %d tests", prb->short_name, tn - 1); } } for (j = 1; j <= prb->ntests; j++) score_summ += prb->tscores[j]; if (score_summ > prb->full_score && !prb->valuer_cmd[0]) { err("total score (%d) > full score (%d) for problem %s", score_summ, prb->full_score, prb->short_name); return -1; } } } for (i = 1; i <= serve_state.max_tester; i++) { if (!serve_state.testers[i]) continue; if (serve_state.testers[i]->any) continue; prb = serve_state.probs[serve_state.testers[i]->problem]; total++; /* check working dirs */ if (make_writable(serve_state.testers[i]->check_dir) < 0) return -1; if (check_writable_dir(serve_state.testers[i]->check_dir) < 0) return -1; if (serve_state.testers[i]->prepare_cmd[0] && check_executable(serve_state.testers[i]->prepare_cmd) < 0) return -1; if (serve_state.testers[i]->start_cmd[0] && check_executable(serve_state.testers[i]->start_cmd) < 0) return -1; } info("checking default testers..."); if ((i = process_default_testers()) < 0) return -1; info("checking default testers done"); total += i; if (!total) info("no testers"); #if CONF_HAS_LIBINTL - 0 == 1 // bind message catalogs, if specified if (global->enable_l10n && global->l10n_dir[0]) { bindtextdomain("ejudge", global->l10n_dir); textdomain("ejudge"); } #endif return 0; }
static int bee_dep_list(int argc, char *argv[]) { int c, i, opt_count, help, files, packages, count, depending_on, required_by, removable, provider_of, not_cached, broken; struct hash *graph; char *name; struct option long_options[] = { {"help", 0, &help, 1}, {"files", 0, &files, 1}, {"packages", 0, &packages, 1}, {"count", 0, &count, 1}, {"depending-on", 0, &depending_on, 1}, {"required-by", 0, &required_by, 1}, {"removable", 0, &removable, 1}, {"provider-of", 0, &provider_of, 1}, {"not-cached", 0, ¬_cached, 1}, {"broken", 0, &broken, 1}, {0, 0, 0, 0} }; opt_count = help = files = packages = provider_of = count = depending_on = required_by = removable = not_cached = broken = 0; while ((c = getopt_long(argc, argv, "", long_options, NULL)) != -1) { switch (c) { case '?': usage_list(); return 1; default: opt_count++; } } if (help) { usage_list(); return 0; } if (!opt_count && optind != argc) { fprintf(stderr, "bee-dep: too many arguments\n"); return 1; } if (!opt_count) packages = 1; if (opt_count > 1 && !count) { fprintf(stderr, "bee-dep: too many options specified\n"); return 1; } if (packages) { graph = get_cache(); if (count) printf("%d\n", count_packages(graph)); else list_packages(graph); hash_free(graph); return 0; } if (broken && optind < argc) { fprintf(stderr, "bee-dep: too many arguments\n"); return 1; } if (optind == argc && !broken) { fprintf(stderr, "bee-dep: arguments needed\n"); return 1; } if (count && (depending_on || required_by)) fprintf(stderr, "bee-dep: ignoring option --count\n"); graph = get_cache(); for (i = optind; i < argc; i++) { name = argv[i]; if (optind < argc - 1) printf("%s:\n", name); if (files) { if (count) { c = count_files(graph, name); if (c < 0) { hash_free(graph); return 1; } printf("%d\n", c); } else if (list_files(graph, name)) { hash_free(graph); return 1; } } if (removable) { if (count) { c = count_removable(graph, name); if (c < 0) { hash_free(graph); return 1; } printf("%d\n", c); } else if (print_removable(graph, name)) { hash_free(graph); return 1; } } if (depending_on && print_neededby(graph, name)) { hash_free(graph); return 1; } if (required_by && print_needs(graph, name)) { hash_free(graph); return 1; } if (provider_of) { if (count) { c = count_providers(graph, name); if (c < 0) { hash_free(graph); return 1; } printf("%d\n", c); } else if (print_providers(graph, name)) { hash_free(graph); return 1; } } if (not_cached) { c = print_not_cached(graph, name, !count); if (c < 0) { hash_free(graph); return 1; } if (count) printf("%d\n", c); } } if (broken) { c = print_broken(graph, !count); if (c < 0) { hash_free(graph); return 1; } if (count) printf("%d\n", c); } hash_free(graph); return 0; }
/* Recursively count all regular files in path and all sub-directories * of path. The result is added to *count (which should be * initialized to zero by the top-level caller before calling * count_files). */ static void count_files (const char *path, int *count) { struct dirent *entry = NULL; char *next; struct stat st; struct dirent **fs_entries = NULL; int num_fs_entries = scandir (path, &fs_entries, 0, dirent_sort_inode); int i = 0; if (num_fs_entries == -1) { fprintf (stderr, "Warning: failed to open directory %s: %s\n", path, strerror (errno)); goto DONE; } while (!interrupted) { if (i == num_fs_entries) break; entry = fs_entries[i++]; /* Ignore special directories to avoid infinite recursion. * Also ignore the .notmuch directory. */ /* XXX: Eventually we'll want more sophistication to let the * user specify files to be ignored. */ if (strcmp (entry->d_name, ".") == 0 || strcmp (entry->d_name, "..") == 0 || strcmp (entry->d_name, ".notmuch") == 0) { continue; } if (asprintf (&next, "%s/%s", path, entry->d_name) == -1) { next = NULL; fprintf (stderr, "Error descending from %s to %s: Out of memory\n", path, entry->d_name); continue; } stat (next, &st); if (S_ISREG (st.st_mode)) { *count = *count + 1; if (*count % 1000 == 0) { printf ("Found %d files so far.\r", *count); fflush (stdout); } } else if (S_ISDIR (st.st_mode)) { count_files (next, count); } free (next); } DONE: if (entry) free (entry); if (fs_entries) free (fs_entries); }
static int count_files(char *abs_dir_name, bool recursive) { z_dir *current_dir; struct z_dir_ent z_dir_entry; char *dirname = NULL; int dirname_size = 0; int len; int result = 0; char *cwd = fsi->get_cwd(NULL, 0); if ((fsi->ch_dir(abs_dir_name)) == -1) { free(cwd); return 0; } TRACE_LOG("Counting files for \"%s\".\n", abs_dir_name); if ((current_dir = fsi->open_dir(".")) == NULL) { printf("\"%s\":\n", abs_dir_name); perror("could not opendir"); fsi->ch_dir(cwd); free(cwd); return 0; } while (fsi->read_dir(&z_dir_entry, current_dir) == 0) { if ( (strcmp(z_dir_entry.d_name, ".") == 0) || (strcmp(z_dir_entry.d_name, "..") == 0) ) continue; len = strlen(abs_dir_name) + strlen(z_dir_entry.d_name) + 2; if (len > dirname_size) { dirname = (char*)fizmo_realloc(dirname, len); dirname_size = len; } strcpy(dirname, abs_dir_name); if (dirname[strlen(dirname) - 1] != '/') strcat(dirname, "/"); strcat(dirname, z_dir_entry.d_name); if (fsi->is_filename_directory(z_dir_entry.d_name) == true) { if (recursive == true) result += count_files(dirname, true); } else result++; } if (dirname != NULL) free(dirname); fsi->close_dir(current_dir); fsi->ch_dir(cwd); free(cwd); //printf("result:%d\n", result); TRACE_LOG("count-result: %d\n", result); return result; }
char* get_file_name_at(int index) { if(index >= count_files() || index < 0) return (char*)NULL; return fs_files[index].filename; }
int main(int argc, char **argv) { int pass = 0; int bNew = 0; long batch = -1; long idxStart = 0; long idxEnd = 0; long idx = 1; long seq = 0; long titlesToProcess = 0; char sFileName[1024]; char sServer[256]; char sDB[256]; char sId[256]; char sPassword[256]; char sTitle[256]; off64_t file_offset_for_pass_1; long max_article_idx; MYSQL *conn; MYSQL *conn2; MYSQL_RES *res; MYSQL_ROW row; char sSQL[MAX_SQL_STR]; int rc; char c; time_t t; nMsgLevel = 0; printf("wiki-xml-parser - (C) 2009 by Openmoko Inc.\n" "This program is Free Software and has ABSOLUTELY NO WARRANTY\n\n"); if (argc <2) { help(); exit(2); } sFileName[0] = '\0'; sServer[0] = '\0'; sDB[0] = '\0'; sId[0] = '\0'; sPassword[0] = '\0'; sTitle[0] = '\0'; while (1) { int c, option_index = 0; c = getopt_long(argc, argv, "hf:p:nb:g:e:m:t:u:w:s:d:i:l:q:", opts, &option_index); if (c == -1) break; switch (c) { case 'h': help(); exit(0); break; case 'f': strncpy(sFileName, optarg, sizeof(sFileName) - 1); sFileName[sizeof(sFileName) - 1] = '\0'; break; case 'p': pass = atoi(optarg); break; case 'b': batch = atoi(optarg); break; case 'g': idxStart = atol(optarg); break; case 'e': idxEnd = atol(optarg); break; case 'n': bNew = 1; break; case 'm': nMsgLevel = atoi(optarg); break; case 't': titlesToProcess = atol(optarg); break; case 'u': strncpy(sId, optarg, sizeof(sId) - 1); sId[sizeof(sId) - 1] = '\0'; break; case 'w': strncpy(sPassword, optarg, sizeof(sPassword) - 1); sPassword[sizeof(sPassword) - 1] = '\0'; break; case 's': strncpy(sServer, optarg, sizeof(sServer) - 1); sServer[sizeof(sServer) - 1] = '\0'; break; case 'd': strncpy(sDB, optarg, sizeof(sDB) - 1); sDB[sizeof(sDB) - 1] = '\0'; break; case 'i': idx = atol(optarg); break; case 'q': seq = atol(optarg); break; case 'l': strncpy(sTitle, optarg, sizeof(sTitle) - 1); sServer[sizeof(sTitle) - 1] = '\0'; break; default: help(); exit(2); } } if (pass == 5) { generate_pedia_hsh(); exit(0); } if (!titlesToProcess) titlesToProcess = 1024; if (!sFileName[0]) strcpy(sFileName, "enwiki-latest-pages-articles.xml"); if (!sId[0]) strcpy(sId, "root"); if (!sServer[0]) strcpy(sServer, "localhost"); if (!sDB[0]) strcpy(sDB, "wikixml"); if (batch >= 0) { idxStart = MAX_ARTICLES_PER_DAT * batch; idxEnd = idxStart + MAX_ARTICLES_PER_DAT - 1; if (!idxStart) idxStart = 1; } else if (idxEnd < idxStart) idxEnd = idxStart; my_init(); g_conn = mysql_init(NULL); if (!mysql_real_connect(g_conn, sServer, sId, sPassword, sDB, 0, NULL, 0)) { showMsg(0, "Error connecting DB %s/%s using %s/%s\n", sServer, sDB, sId, sPassword); exit(1); } conn = mysql_init(NULL); if (!mysql_real_connect(conn, sServer, sId, sPassword, sDB, 0, NULL, 0)) { showMsg(0, "Error connecting DB %s/%s using %s/%s\n", sServer, sDB, sId, sPassword); exit(1); } if (pass==0) { if (sTitle[0]) sprintf(sSQL, "select title, text_start_offset, text_len, redirect_title, entry_type from entries where title='%s'", sTitle); else if (seq) sprintf(sSQL, "select title, text_start_offset, text_len, redirect_title, entry_type from entries where seq=%ld", seq); else sprintf(sSQL, "select title, text_start_offset, text_len, redirect_title, entry_type from entries where idx=%ld", idx); printf("SQL: %s\n", sSQL); rc = mysql_query(conn, sSQL); if (rc) { showMsg(0, "query entries error - %d (%s)\n", rc, mysql_error(conn)); exit(1); } res = mysql_use_result(conn); if ((row = mysql_fetch_row(res)) != NULL) { FILE *fd; off64_t nArticleOffset; long nTextLen; char buf[1025]; int len; if (!row[1]) { if (row[4]) printf("title: [%s], redirect: [%s]\n", row[0], row[3]); else printf("title: [%s], entry type: %s\n", row[0], row[4]); exit(0); } sscanf(row[1], "%Ld", &nArticleOffset); nTextLen = atol(row[2]); printf("offset: %Lx, len: %lx\n\n", nArticleOffset, nTextLen); fd = fopen64(sFileName, "rb"); fseeko64(fd, nArticleOffset, SEEK_SET); printf("<mediawiki>\n<page>\n<title>%s</title>\n <revision>\n<text>", row[0]); while (nTextLen > 0) { if (nTextLen > 1024) len = fread(buf, 1, 1024, fd); else len = fread(buf, 1, nTextLen, fd); nTextLen -= 1024; buf[len] = '\0'; printf(buf); } printf("\n</text>\n</revision>\n</page>\n</mediawiki>"); } else printf("not found\n"); exit(0); } else if (pass == 4) { long idx_range[MAX_IDX_RANGE][2]; long idx_range_count = 0; long count = 0; int i; long max_file_size = 0; count_files("./dat", &idx_range_count, idx_range, &max_file_size); for (i = 0; i < idx_range_count; i++) { showMsg(0, "%8ld ~ %8ld\n", idx_range[i][0], idx_range[i][1]); count += idx_range[i][1] - idx_range[i][0] + 1; } showMsg(0, "Total file count: %ld, Max file size: %ld\n", count, max_file_size); exit(0); } rc = mysql_query(conn, "select idx from entries order by idx desc limit 1"); res = mysql_use_result(conn); if ((row = mysql_fetch_row(res)) != NULL && row[0]) { showMsg(0, "max article idx:\t\t%ld\n", (max_article_idx=atol(row[0]))); mysql_free_result(res); mysql_commit(conn); rc = mysql_query(conn, "select count(*) from entries"); res = mysql_use_result(conn); if ((row = mysql_fetch_row(res)) != NULL && row[0]) showMsg(0, "pass1 processed entries:\t%ld\n", atol(row[0])); // mysql_free_result(res); // mysql_commit(conn); // rc = mysql_query(conn, "select count(*) from entries where entry_type=0 and pass_2_processed=1"); // res = mysql_use_result(conn); // if ((row = mysql_fetch_row(res)) != NULL && row[0]) // showMsg(0, "pass2 processed articles:\t%ld\n", atol(row[0])); // mysql_free_result(res); // mysql_commit(conn); // rc = mysql_query(conn, "select count(*) from entries where entry_type=0 and pass_2_processed=0"); // res = mysql_use_result(conn); // if ((row = mysql_fetch_row(res)) != NULL && row[0]) // showMsg(0, "pass2 to be processed articles:\t%ld\n", atol(row[0])); } else { showMsg(0, "no process status\n"); file_offset_for_pass_1 = 0; max_article_idx = 0; init_bigram_table(conn); } mysql_free_result(res); if (pass == 1) { // if (nBatch <= 0) // nBatch = 8; // else if (nBatch > MAX_DAT_FILES) // nBatch = MAX_DAT_FILES; showMsg(0, "\nProcessing %s for %ld titles.\n", sFileName, titlesToProcess); } else if (pass == 2) showMsg(0, "\nProcessing idx %ld ~ %ld.\n", idxStart, idxEnd); showMsg(3, "Server-%s, DB-%s, user-%s, password-%s.\n\n", sServer, sDB, sId, sPassword); if (bNew && pass == 1) printf("\nAll previously processed records will be deleted. Continue processing? (y to continue)\n"); else printf("\nStart processing? (y to continue)\n"); c = getchar(); if (c == 'y') { if (bNew) { if (pass == 1) { mysql_query(conn, "delete from entries"); rc = mysql_commit(conn); mysql_query(conn, "alter table entries AUTO_INCREMENT=1"); rc = mysql_commit(conn); showMsg(3, "commit update process_status rc=%d\n", rc); file_offset_for_pass_1 = 0; max_article_idx = 0; init_bigram_table(conn); } } time(&t); showMsg(0, "start pass %d - %s\n", pass, ctime(&t)); if (pass == 1) { process_pass_1(conn, sFileName, nMsgLevel, titlesToProcess, file_offset_for_pass_1, max_article_idx); } else if (pass == 2) { conn2 = mysql_init(NULL); if (!mysql_real_connect(conn2, sServer, sId, sPassword, sDB, 0, NULL, 0)) { showMsg(0, "Error connecting DB %s/%s using %s/%s\n", sServer, sDB, sId, sPassword); exit(1); } process_pass_2(conn, conn2, sFileName, nMsgLevel, titlesToProcess, batch, idxStart, idxEnd); mysql_close(conn2); } else if (pass == 3) { conn2 = mysql_init(NULL); if (!mysql_real_connect(conn2, sServer, sId, sPassword, sDB, 0, NULL, 0)) { showMsg(0, "Error connecting DB %s/%s using %s/%s\n", sServer, sDB, sId, sPassword); exit(1); } unlink("pedia.idx"); unlink("pedia.fnd"); unlink("pedia.pfx"); if (max_article_idx > 2000) process_pass_3(conn, conn2, 1); else process_pass_3(conn, conn2, 0); mysql_close(conn2); } time(&t); showMsg(0, "end pass %d - %s\n", pass, ctime(&t)); } /* close connection */ mysql_close(conn); mysql_close(g_conn); exit(0); }
struct z_story_list *update_fizmo_story_list() { #ifdef DISABLE_CONFIGFILES return NULL; #else // DISABLE_CONFIGFILES struct z_story_list *result; struct z_story_list_entry *entry; char *str, *str_copy, *path; z_file *file; struct babel_info *babel; int i; nof_files_found = 0; nof_files_searched = 0; nof_directories_searched = 0; ensure_dot_fizmo_dir_exists(); babel = load_babel_info(); if (babel_files_have_changed(babel) == true) { // Don't load current list of story, rebuild index with the newly // changed babel data. result = get_empty_z_story_list(); store_babel_info_timestamps(babel); } else { // Babel data is the same, use pre-indexed story list. result = get_z_story_list(); i = 0; while (i < result->nof_entries) { entry = result->entries[i]; if ((file = fsi->openfile( entry->filename, FILETYPE_DATA, FILEACCESS_READ)) == NULL) remove_entry_from_list(result, entry); else { fsi->closefile(file); i++; } } } if ((str = getenv("ZCODE_PATH")) == NULL) str = getenv("INFOCOM_PATH"); if (str != NULL) set_configuration_value("z-code-path", str); if ((str = getenv("ZCODE_ROOT_PATH")) != NULL) set_configuration_value("z-code-root-path", str); if ((str = get_configuration_value("z-code-path")) != NULL) { path = strtok(str, ":"); while (path != NULL) { TRACE_LOG("Counting for token \"%s\".\n", path); nof_files_found += count_files(path, false); path = strtok(NULL, ":"); } } if ((str = get_configuration_value("z-code-root-path")) != NULL) { str_copy = strdup(str); path = strtok(str_copy, ":"); while (path != NULL) { TRACE_LOG("Counting for token \"%s\".\n", path); nof_files_found += count_files(path, true); path = strtok(NULL, ":"); } free(str_copy); } TRACE_LOG("nof_files_found: %d, %d\n", nof_files_found, NUMBER_OF_FILES_TO_SHOW_PROGRESS_FOR); if (nof_files_found >= NUMBER_OF_FILES_TO_SHOW_PROGRESS_FOR) show_progress = true; else show_progress = false; //printf("\n"); // newline for \r-progress indicator //build_filelist(".", result, false, babel); if ((str = get_configuration_value("z-code-path")) != NULL) { str_copy = strdup(str); path = strtok(str_copy, ":"); while (path != NULL) { build_filelist(path, result, false, babel); path = strtok(NULL, ":"); } free(str_copy); } if ((str = get_configuration_value("z-code-root-path")) != NULL) { str_copy = strdup(str); path = strtok(str_copy, ":"); while (path != NULL) { build_filelist(path, result, true, babel); path = strtok(NULL, ":"); } free(str_copy); } if (show_progress == true) printf("\n"); TRACE_LOG("noffiles: %d\n", result->nof_entries); save_story_list(result); store_babel_info_timestamps(babel); free_babel_info(babel); return result; #endif // DISABLE_CONFIGFILES }
bool LocalZipTask::zip() { const QString source = get_source(), destination = get_destination(); // 在临时文件区新建zip文件 QTemporaryFile tmp("XXXXXX.zip"); tmp.open(); QuaZip zip(tmp.fileName()); zip.setFileNameCodec("UTF8"); zip.open(QuaZip::mdCreate); // 添加注释 zip.setComment("Create automatically by organic/syncer."); // 添加文件 IgnoreList ignore_list; stack<QString> relatives; relatives.push(""); while (!relatives.empty()) { const QString r = relatives.top(); relatives.pop(); // 执行栈里的特殊操作 if (r == SPECIAL_ID) { ignore_list.pop_config(); continue; } update_state(r + " ..."); // 处理中断操作 if (RUNNING != get_state()) { set_msg("Cancled."); return false; } // 处理忽略列表 const QString p = path_join(source, r); if (ignore_list.is_ignored(r)) { _compressed_files += count_files(p); continue; } if (!QFileInfo(p).isDir()) { QFile in(p); if (!in.open(QIODevice::ReadOnly)) { set_msg("Failed to open file: " + p); set_has_error(true); return false; } QuaZipFile out(&zip); const QString rr = (r.isEmpty() ? QFileInfo(source).fileName() : r); out.open(QIODevice::WriteOnly, QuaZipNewInfo(rr, p)); const qint64 BUF_LEN = 64 * 1024; char buf[BUF_LEN]; for (qint64 pos = 0, len = in.size(); pos < len; ) { qint64 readSize = qMin(BUF_LEN, len - pos); if (in.read(buf, readSize) != readSize) { set_msg("Failed to read file: " + rr); set_has_error(true); return false; } out.write(buf, readSize); pos += readSize; } in.close(); out.close(); ++_compressed_files; } else { // 处理忽略列表 if (QFileInfo(path_join(p, IGNORE_FILE1)).exists()) { ignore_list.push_config(r, path_join(p, IGNORE_FILE1)); relatives.push(SPECIAL_ID); } else if (QFileInfo(path_join(p, IGNORE_FILE2)).exists()) { ignore_list.push_config(r, path_join(p, IGNORE_FILE2)); relatives.push(SPECIAL_ID); } else if (QFileInfo(path_join(p, IGNORE_FILE3)).exists()) { ignore_list.push_config(r, path_join(p, IGNORE_FILE3)); relatives.push(SPECIAL_ID); } // 遍历文件夹 QStringList children = QDir(p).entryList(QDir::Files | QDir::Dirs | QDir::AccessMask | QDir::NoDotAndDotDot); for (size_t i = 0, size = children.size(); i < size; ++i) { const QString& e = children.at(i); relatives.push(path_join(r, e)); } } } zip.close(); tmp.close(); // 拷贝临时文件到目标地址 if (QFileInfo(destination).exists() && !remove_file(destination)) { set_msg("Failed to remove old destination ZIP file."); set_has_error(true); return false; } if (!copy_file(tmp.fileName(), destination)) { set_msg("Failed to copy tmp file to destination ZIP file."); set_has_error(true); return false; } tmp.remove(); return true; }
int main(int argc, char *argv[]) { FILE * inpipe; fsid_index_t * fsid_index; dir_index_t * dir_index; int files; int fd; pid_t pid; int policy; char txtbuf[100]; struct sched_param param; if (argc != 1) usage(); pid = getpid(); param.sched_priority = 1; sched_setscheduler(pid,1,¶m); logger_init( log_info, stdout, 0,0 ); daemon(0,0); /* Start indexing */ while (1) { fsid_index = NULL; dir_index = NULL; fsid_index = parse_nowshowing_tivo(); if(!fsid_index) { printf("Warning no FSID index\n"); sleep(90); continue; } fd = open("/var/index/nowshowing", O_WRONLY|O_CREAT|O_TRUNC|OS_FLAGS, READWRITE_PERMISSIONS); if(fd == -1) { LOG_ERROR("Unable to write /var/index/nowshowing"); exit(1); } write_fsid_index_list(fd, fsid_index); close(fd); dir_index = remove_old_files(fsid_index); files = 1; if(!dir_index) { /* Okat there might not be any files */ if( (files = count_files()) != 0) { printf("No dir index\n"); exit(1); } } if((create_index_files(fsid_index, dir_index, files)) == 0) { //free_fsid_index_list(fsid_index); //free_dir_index_list(dir_index); printf("Error indexing one or more recordings\n" "It may be that it got deleted during the indexing\n"); //exit(1); } //write_now_showing(fsid_index); free_fsid_index_list(fsid_index); if(dir_index) { free_dir_index_list(dir_index); } /* Sleep for 15 min */ sleep(900); } logger_free(); return(0); }
void process_test_data(char * dir_path, struct fann *ann1, struct fann *ann2){ int i, j, high_index; int results[6] = {0,0,0,0,0,0}; float high; int maxsize = 1; int currentsize = 0; FILE * test; char * token; char test_path[100]; char data[100]; int num_files = count_files(dir_path); float ann1_input[ann1->num_input]; float ** ann1_output; float * ann2_input; float * ann2_output; float * temp_output; ann1_output = (float**) malloc(maxsize*sizeof(float *)); for(i=0; i<num_files; i++){ currentsize=0; sprintf(test_path, "%s%d" ,dir_path, i); test = fopen(test_path, "r"); while(fscanf(test, "%[^\n]%*c",data) !=EOF){ j=0; // printf("%s\n", data); token = strtok(data, " "); while(token != NULL){ ann1_input[j++] = atof(token); token = strtok(NULL, " "); } temp_output = fann_run(ann1, ann1_input); ann1_output[currentsize] = (float *) malloc(ann1->num_output*sizeof(float)); high_index =find_index(ann1->num_output, temp_output); for(j=0; j<ann1->num_output; j++){ if(j == high_index){ ann1_output[currentsize][j] = 1; }else{ ann1_output[currentsize][j] = 0; } } ++currentsize; if(currentsize == maxsize){ maxsize = maxsize*2; ann1_output = realloc(ann1_output, maxsize*sizeof(float *)); } } ann2_input = resample(ann1_output, ann1->num_output, currentsize, ann2->num_input); ann2_output = fann_run(ann2, ann2_input); // for(j=0; j<ann2->num_output; j++){ // printf("%f ", ann2_output[j]); // } // printf("\n"); high = FLT_MIN; high_index = 0; for(j=0; j<ann2->num_output; j++){ if(ann2_output[j]>high){ high = ann2_output[j]; high_index =j; } } ++results[high_index]; } for(i=0; i<6; i++){ printf("%s:\t\t\t%d\n", gestures[i], results[i]); } printf("\nTotal files:\t\t%d\n\n\n", num_files); }
int notmuch_new_command (void *ctx, int argc, char *argv[]) { notmuch_config_t *config; notmuch_database_t *notmuch; add_files_state_t add_files_state; double elapsed; struct timeval tv_now, tv_start; int ret = 0; struct stat st; const char *db_path; char *dot_notmuch_path; struct sigaction action; _filename_node_t *f; int renamed_files, removed_files; notmuch_status_t status; int i; notmuch_bool_t timer_is_active = FALSE; add_files_state.verbose = 0; add_files_state.output_is_a_tty = isatty (fileno (stdout)); for (i = 0; i < argc && argv[i][0] == '-'; i++) { if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) { add_files_state.verbose = 1; } else { fprintf (stderr, "Unrecognized option: %s\n", argv[i]); return 1; } } config = notmuch_config_open (ctx, NULL, NULL); if (config == NULL) return 1; add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length); add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config); add_files_state.message_ids_to_sync = _filename_list_create (ctx); db_path = notmuch_config_get_database_path (config); dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch"); if (stat (dot_notmuch_path, &st)) { int count; count = 0; count_files (db_path, &count); if (interrupted) return 1; printf ("Found %d total files (that's not much mail).\n", count); notmuch = notmuch_database_create (db_path); add_files_state.total_files = count; } else { notmuch = notmuch_database_open (db_path, NOTMUCH_DATABASE_MODE_READ_WRITE); if (notmuch == NULL) return 1; if (notmuch_database_needs_upgrade (notmuch)) { printf ("Welcome to a new version of notmuch! Your database will now be upgraded.\n"); gettimeofday (&add_files_state.tv_start, NULL); notmuch_database_upgrade (notmuch, upgrade_print_progress, &add_files_state); printf ("Your notmuch database has now been upgraded to database format version %u.\n", notmuch_database_get_version (notmuch)); } add_files_state.total_files = 0; } if (notmuch == NULL) return 1; /* Setup our handler for SIGINT. We do this after having * potentially done a database upgrade we this interrupt handler * won't support. */ memset (&action, 0, sizeof (struct sigaction)); action.sa_handler = handle_sigint; sigemptyset (&action.sa_mask); action.sa_flags = SA_RESTART; sigaction (SIGINT, &action, NULL); talloc_free (dot_notmuch_path); dot_notmuch_path = NULL; add_files_state.processed_files = 0; add_files_state.added_messages = 0; gettimeofday (&add_files_state.tv_start, NULL); add_files_state.removed_files = _filename_list_create (ctx); add_files_state.removed_directories = _filename_list_create (ctx); if (! debugger_is_active () && add_files_state.output_is_a_tty && ! add_files_state.verbose) { setup_progress_printing_timer (); timer_is_active = TRUE; } ret = add_files (notmuch, db_path, &add_files_state); removed_files = 0; renamed_files = 0; gettimeofday (&tv_start, NULL); for (f = add_files_state.removed_files->head; f; f = f->next) { status = notmuch_database_remove_message (notmuch, f->filename); if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) renamed_files++; else removed_files++; if (do_print_progress) { do_print_progress = 0; generic_print_progress ("Cleaned up", "messages", tv_start, removed_files + renamed_files, add_files_state.removed_files->count); } } gettimeofday (&tv_start, NULL); for (f = add_files_state.removed_directories->head, i = 0; f; f = f->next, i++) { _remove_directory (ctx, notmuch, f->filename, &renamed_files, &removed_files); if (do_print_progress) { do_print_progress = 0; generic_print_progress ("Cleaned up", "directories", tv_start, i, add_files_state.removed_directories->count); } } talloc_free (add_files_state.removed_files); talloc_free (add_files_state.removed_directories); /* Now that removals are done (hence the database is aware of all * renames), we can synchronize maildir_flags to tags for all * messages that had new filenames appear on this run. */ gettimeofday (&tv_start, NULL); if (add_files_state.synchronize_flags) { _filename_node_t *node; notmuch_message_t *message; for (node = add_files_state.message_ids_to_sync->head, i = 0; node; node = node->next, i++) { message = notmuch_database_find_message (notmuch, node->filename); notmuch_message_maildir_flags_to_tags (message); notmuch_message_destroy (message); if (do_print_progress) { do_print_progress = 0; generic_print_progress ( "Synchronized tags for", "messages", tv_start, i, add_files_state.message_ids_to_sync->count); } } } talloc_free (add_files_state.message_ids_to_sync); add_files_state.message_ids_to_sync = NULL; if (timer_is_active) stop_progress_printing_timer (); gettimeofday (&tv_now, NULL); elapsed = notmuch_time_elapsed (add_files_state.tv_start, tv_now); if (add_files_state.processed_files) { printf ("Processed %d %s in ", add_files_state.processed_files, add_files_state.processed_files == 1 ? "file" : "total files"); notmuch_time_print_formatted_seconds (elapsed); if (elapsed > 1) { printf (" (%d files/sec.).\033[K\n", (int) (add_files_state.processed_files / elapsed)); } else { printf (".\033[K\n"); } } if (add_files_state.added_messages) { printf ("Added %d new %s to the database.", add_files_state.added_messages, add_files_state.added_messages == 1 ? "message" : "messages"); } else { printf ("No new mail."); } if (removed_files) { printf (" Removed %d %s.", removed_files, removed_files == 1 ? "message" : "messages"); } if (renamed_files) { printf (" Detected %d file %s.", renamed_files, renamed_files == 1 ? "rename" : "renames"); } printf ("\n"); if (ret) { printf ("\nNote: At least one error was encountered: %s\n", notmuch_status_to_string (ret)); } notmuch_database_close (notmuch); return ret || interrupted; }
int main(int argc, char **argv) { tdata_t *mstrtd, *savetd; char *uniqfile = NULL, *uniqlabel = NULL; char *withfile = NULL; char *label = NULL; char **ifiles, **tifiles; int verbose = 0, docopy = 0; int write_fuzzy_match = 0; int require_ctf = 0; int nifiles, nielems; int c, i, idx, tidx, err; progname = basename(argv[0]); if (getenv("CTFMERGE_DEBUG_LEVEL")) debug_level = atoi(getenv("CTFMERGE_DEBUG_LEVEL")); err = 0; while ((c = getopt(argc, argv, ":cd:D:fl:L:o:tvw:s")) != EOF) { switch (c) { case 'c': docopy = 1; break; case 'd': /* Uniquify against `uniqfile' */ uniqfile = optarg; break; case 'D': /* Uniquify against label `uniqlabel' in `uniqfile' */ uniqlabel = optarg; break; case 'f': write_fuzzy_match = CTF_FUZZY_MATCH; break; case 'l': /* Label merged types with `label' */ label = optarg; break; case 'L': /* Label merged types with getenv(`label`) */ if ((label = getenv(optarg)) == NULL) label = CTF_DEFAULT_LABEL; break; case 'o': /* Place merged types in CTF section in `outfile' */ outfile = optarg; break; case 't': /* Insist *all* object files built from C have CTF */ require_ctf = 1; break; case 'v': /* More debugging information */ verbose = 1; break; case 'w': /* Additive merge with data from `withfile' */ withfile = optarg; break; case 's': /* use the dynsym rather than the symtab */ dynsym = CTF_USE_DYNSYM; break; default: usage(); exit(2); } } /* Validate arguments */ if (docopy) { if (uniqfile != NULL || uniqlabel != NULL || label != NULL || outfile != NULL || withfile != NULL || dynsym != 0) err++; if (argc - optind != 2) err++; } else { if (uniqfile != NULL && withfile != NULL) err++; if (uniqlabel != NULL && uniqfile == NULL) err++; if (outfile == NULL || label == NULL) err++; if (argc - optind == 0) err++; } if (err) { usage(); exit(2); } if (uniqfile && access(uniqfile, R_OK) != 0) { warning("Uniquification file %s couldn't be opened and " "will be ignored.\n", uniqfile); uniqfile = NULL; } if (withfile && access(withfile, R_OK) != 0) { warning("With file %s couldn't be opened and will be " "ignored.\n", withfile); withfile = NULL; } if (outfile && access(outfile, R_OK|W_OK) != 0) terminate("Cannot open output file %s for r/w", outfile); /* * This is ugly, but we don't want to have to have a separate tool * (yet) just for copying an ELF section with our specific requirements, * so we shoe-horn a copier into ctfmerge. */ if (docopy) { copy_ctf_data(argv[optind], argv[optind + 1]); exit(0); } set_terminate_cleanup(terminate_cleanup); /* Sort the input files and strip out duplicates */ nifiles = argc - optind; ifiles = xmalloc(sizeof (char *) * nifiles); tifiles = xmalloc(sizeof (char *) * nifiles); for (i = 0; i < nifiles; i++) tifiles[i] = argv[optind + i]; qsort(tifiles, nifiles, sizeof (char *), (int (*)())strcompare); ifiles[0] = tifiles[0]; for (idx = 0, tidx = 1; tidx < nifiles; tidx++) { if (strcmp(ifiles[idx], tifiles[tidx]) != 0) ifiles[++idx] = tifiles[tidx]; } nifiles = idx + 1; /* Make sure they all exist */ if ((nielems = count_files(ifiles, nifiles)) < 0) terminate("Some input files were inaccessible\n"); /* Prepare for the merge */ wq_init(&wq, nielems); start_threads(&wq); /* * Start the merge * * We're reading everything from each of the object files, so we * don't need to specify labels. */ if (read_ctf(ifiles, nifiles, NULL, merge_ctf_cb, &wq, require_ctf) == 0) { /* * If we're verifying that C files have CTF, it's safe to * assume that in this case, we're building only from assembly * inputs. */ if (require_ctf) exit(0); terminate("No ctf sections found to merge\n"); } pthread_mutex_lock(&wq.wq_queue_lock); wq.wq_nomorefiles = 1; pthread_cond_broadcast(&wq.wq_work_avail); pthread_mutex_unlock(&wq.wq_queue_lock); pthread_mutex_lock(&wq.wq_queue_lock); while (wq.wq_alldone == 0) pthread_cond_wait(&wq.wq_alldone_cv, &wq.wq_queue_lock); pthread_mutex_unlock(&wq.wq_queue_lock); join_threads(&wq); /* * All requested files have been merged, with the resulting tree in * mstrtd. savetd is the tree that will be placed into the output file. * * Regardless of whether we're doing a normal uniquification or an * additive merge, we need a type tree that has been uniquified * against uniqfile or withfile, as appropriate. * * If we're doing a uniquification, we stuff the resulting tree into * outfile. Otherwise, we add the tree to the tree already in withfile. */ assert(fifo_len(wq.wq_queue) == 1); mstrtd = fifo_remove(wq.wq_queue); if (verbose || debug_level) { debug(2, "Statistics for td %p\n", (void *)mstrtd); iidesc_stats(mstrtd->td_iihash); } if (uniqfile != NULL || withfile != NULL) { char *reffile, *reflabel = NULL; tdata_t *reftd; if (uniqfile != NULL) { reffile = uniqfile; reflabel = uniqlabel; } else reffile = withfile; if (read_ctf(&reffile, 1, reflabel, read_ctf_save_cb, &reftd, require_ctf) == 0) { terminate("No CTF data found in reference file %s\n", reffile); } savetd = tdata_new(); if (CTF_TYPE_ISCHILD(reftd->td_nextid)) terminate("No room for additional types in master\n"); savetd->td_nextid = withfile ? reftd->td_nextid : CTF_INDEX_TO_TYPE(1, TRUE); merge_into_master(mstrtd, reftd, savetd, 0); tdata_label_add(savetd, label, CTF_LABEL_LASTIDX); if (withfile) { /* * savetd holds the new data to be added to the withfile */ tdata_t *withtd = reftd; tdata_merge(withtd, savetd); savetd = withtd; } else { char uniqname[MAXPATHLEN]; labelent_t *parle; parle = tdata_label_top(reftd); savetd->td_parlabel = xstrdup(parle->le_name); strncpy(uniqname, reffile, sizeof (uniqname)); uniqname[MAXPATHLEN - 1] = '\0'; savetd->td_parname = xstrdup(basename(uniqname)); } } else { /* * No post processing. Write the merged tree as-is into the * output file. */ tdata_label_free(mstrtd); tdata_label_add(mstrtd, label, CTF_LABEL_LASTIDX); savetd = mstrtd; } tmpname = mktmpname(outfile, ".ctf"); write_ctf(savetd, outfile, tmpname, CTF_COMPRESS | write_fuzzy_match | dynsym); if (rename(tmpname, outfile) != 0) terminate("Couldn't rename output temp file %s", tmpname); free(tmpname); return (0); }
int run_main (int argc, ACE_TCHAR *argv []) { ACE_START_TEST (ACE_TEXT ("Logging_Strategy_Test")); ACE_TCHAR *l_argv[4]; if (argc > 1) { if (parse_args (argc, argv) == -1) ACE_ERROR_RETURN ((LM_ERROR, "Invalid command-line parameters.\n"), 1); } else { l_argv[0] = argv[0]; l_argv[1] = (ACE_TCHAR *) ACE_TEXT ("-slog/Logging_Strategy_Test") ACE_LOG_FILE_EXT_NAME; l_argv[2] = (ACE_TCHAR *) ACE_TEXT ("-o"); l_argv[3] = 0; if (parse_args (3, l_argv) == -1) ACE_ERROR_RETURN ((LM_ERROR, "Invalid command-line parameters.\n"), 1); argv = l_argv; argc = 3; } // Remove existing files. remove_files (); // This is necessary only if the provided logfile name is the same // as the default name. If so, nothing will be written as the // previous ofstream is closed only at the end (ACE_END_TEST) ACE_CLOSE_TEST_LOG; // When Dlls are used, we utilize the dynamic service configuration // mechanism to activate the logging strategy. This is not a must // though, and you may activate the logging strategy as described in // the non-DLL section below under DLL environments as well. #if !defined (ACE_HAS_STATIC_LIBS) && \ (defined (ACE_WIN32) || defined (ACE_HAS_SVR4_DYNAMIC_LINKING) || \ defined (__hpux)) // Platform support DLLs, and not configured to link statically ACE_TCHAR arg_str[250]; ACE_OS::sprintf (arg_str, ACE_TEXT ("dynamic Logger Service_Object ") ACE_TEXT ("*ACE:_make_ACE_Logging_Strategy()") ACE_TEXT ("\"")); for (int i = 1; i < argc; i++) { ACE_OS::strcat (arg_str, argv[i]); ACE_OS::strcat (arg_str, ACE_TEXT (" ")); } ACE_OS::strcat (arg_str, ACE_TEXT ("\"")); if (ACE_Service_Config::process_directive (arg_str) == -1) ACE_ERROR_RETURN ((LM_ERROR, "Error opening _make_ACE_Log_Strategy.\n"), 1); #else // Platform doesn't support DLLs, or configured to link // statically ACE_Logging_Strategy logging_strategy; char ls_argc = argc - 1; ACE_Auto_Basic_Ptr<ACE_TCHAR *> ls_argv (new ACE_TCHAR *[ls_argc]); for (char c = 0; c < ls_argc; c++) (ls_argv.get ())[c] = argv[c+1]; if (logging_strategy.init (ls_argc, ls_argv.get ()) == -1) ACE_ERROR_RETURN ((LM_ERROR, "Error initializing the ACE_Logging_Strategy.\n"), 1); #endif /* !ACE_HAS_STATIC_LIBS && (ACE_WIN32 || ACE_HAS_SVR4_DYNAMIC_LINKING || __hpux) */ // launch a new Thread if (ACE_Thread_Manager::instance ()->spawn (ACE_THR_FUNC (run_reactor)) == -1) ACE_ERROR_RETURN ((LM_ERROR, "Spawning Reactor.\n"), 1); // Function to print the message print_till_death (); // Counts the generated files count_files (); // Get the file order order (); // Wait for the thread to exit before we exit. ACE_Thread_Manager::instance ()->wait (); ACE_END_TEST; return 0; }
int main(void) { char *chrootdir; char *distributions; int retval; size_t config_size = sizeof(struct dpv_config); size_t file_node_size = sizeof(struct dpv_file_node); size_t span; struct dpv_config *config; struct dpv_file_node *dist = dists; static char backtitle[] = "FreeBSD Installer"; static char title[] = "Archive Extraction"; static char aprompt[] = "\n Overall Progress:"; static char pprompt[] = "Extracting distribution files...\n"; struct sigaction act; char error[PATH_MAX + 512]; if ((distributions = getenv("DISTRIBUTIONS")) == NULL) errx(EXIT_FAILURE, "DISTRIBUTIONS variable is not set"); if ((distdir = getenv("BSDINSTALL_DISTDIR")) == NULL) distdir = __DECONST(char *, ""); /* Initialize dialog(3) */ init_dialog(stdin, stdout); dialog_vars.backtitle = backtitle; dlg_put_backtitle(); dialog_msgbox("", "Checking distribution archives.\nPlease wait...", 4, 35, FALSE); /* * Parse $DISTRIBUTIONS into dpv(3) linked-list */ while (*distributions != '\0') { span = strcspn(distributions, "\t\n\v\f\r "); if (span < 1) { /* currently on whitespace */ distributions++; continue; } /* Allocate a new struct for the distribution */ if (dist == NULL) { if ((dist = calloc(1, file_node_size)) == NULL) _errx(EXIT_FAILURE, "Out of memory!"); dists = dist; } else { dist->next = calloc(1, file_node_size); if (dist->next == NULL) _errx(EXIT_FAILURE, "Out of memory!"); dist = dist->next; } /* Set path */ if ((dist->path = malloc(span + 1)) == NULL) _errx(EXIT_FAILURE, "Out of memory!"); snprintf(dist->path, span + 1, "%s", distributions); dist->path[span] = '\0'; /* Set display name */ dist->name = strrchr(dist->path, '/'); if (dist->name == NULL) dist->name = dist->path; /* Set initial length in files (-1 == error) */ dist->length = count_files(dist->path); if (dist->length < 0) { end_dialog(); return (EXIT_FAILURE); } distributions += span; } /* Optionally chdir(2) into $BSDINSTALL_CHROOT */ chrootdir = getenv("BSDINSTALL_CHROOT"); if (chrootdir != NULL && chdir(chrootdir) != 0) { snprintf(error, sizeof(error), "Could not change to directory %s: %s\n", chrootdir, strerror(errno)); dialog_msgbox("Error", error, 0, 0, TRUE); end_dialog(); return (EXIT_FAILURE); } /* Set cleanup routine for Ctrl-C action */ act.sa_handler = sig_int; sigaction(SIGINT, &act, 0); /* * Hand off to dpv(3) */ if ((config = calloc(1, config_size)) == NULL) _errx(EXIT_FAILURE, "Out of memory!"); config->backtitle = backtitle; config->title = title; config->pprompt = pprompt; config->aprompt = aprompt; config->options |= DPV_WIDE_MODE; config->label_size = -1; config->action = extract_files; config->status_solo = "%10lli files read @ %'9.1f files/sec."; config->status_many = "%10lli files read @ %'9.1f files/sec. [%i/%i busy/wait]"; end_dialog(); retval = dpv(config, dists); dpv_free(); while ((dist = dists) != NULL) { dists = dist->next; if (dist->path != NULL) free(dist->path); free(dist); } return (retval); }