/* * Initialize dlr_waiting_list and return out storage handles. */ struct dlr_storage *dlr_init_spool(Cfg *cfg) { CfgGroup *grp; if (!(grp = cfg_get_single_group(cfg, octstr_imm("core")))) panic(0, "DLR: spool: group 'core' is not specified!"); if (!(spool_dir = cfg_get(grp, octstr_imm("dlr-spool")))) panic(0, "DLR: spool: directive 'dlr-spool' is not specified!"); #ifdef HAVE_LIBSSL OpenSSL_add_all_digests(); #endif counter = counter_create(); /* we need to traverse the DLR spool to determine how * many entries we have. */ #ifdef VERIFIED for_each_file(spool_dir, 1, verified_file); #else for_each_file(spool_dir, 1, non_verified_file); #endif return &handles; }
int save_scenario(int kind) { int i; for (i=0; save_dialog[i].proc; i++) { save_dialog[i].fg = colors[black]; save_dialog[i].bg = colors[gray]; } save_dialog[SAVE_LISTBOX].bg = colors[white]; save_dialog[SAVE_EDIT].bg = colors[white]; if (kind) strcpy(ext, "*.sce"); else strcpy(ext, "*.sav"); file_index = for_each_file(ext, FA_ARCH, foo, 0); files = (files_t *)malloc(sizeof(files_t)*file_index); file_index=0; for_each_file(ext, FA_ARCH, add_file, 0); filename[0]='\0'; if (kind==SL_SCENARIO) { save_dialog[SAVE_FRAME].dp = "Save Scenario"; strcpy(ext, ".sce"); } else { save_dialog[SAVE_FRAME].dp = "Save Game"; strcpy(ext, ".sav"); } i=1; if (do_dialog(save_dialog, -1)==SAVE_OKAY) { PACKFILE *file; unsigned short magic = MAGIC; if (filename[0]=='\0') { file = pack_fopen(files[save_dialog[SAVE_LISTBOX].d1].name, "wb"); } else { char fn[16]; sprintf(fn, "%s%s", filename, ext); file = pack_fopen(fn, "wb"); } if (file) { pack_fwrite(&game, sizeof(game_t), file); pack_fwrite(matrix, sizeof(tile_t)*game.tiles, file); pack_fwrite(players, sizeof(players_t)*8, file); pack_fwrite(&magic, sizeof(unsigned short), file); pack_fclose(file); printf("Game saved.\n"); i=0; } if (i==1) alert("!ERROR", "Could not save the scenario", NULL, "OK", NULL, 'o', 0); } free(files); return i; }
static void get_all_dict_list(std::list<std::string> &dict_all_list) { std::list<std::string> dict_order_list; std::list<std::string> dict_disable_list; for_each_file(conf->get_strlist("/apps/stardict/manage_dictionaries/dict_dirs_list"), ".ifo", dict_order_list, dict_disable_list, GetAllDictList(dict_all_list)); }
/* * Set up a log for storing io patterns. */ static int init_iolog_write(struct thread_data *td) { struct fio_file *ff; FILE *f; unsigned int i; f = fopen(td->o.write_iolog_file, "a"); if (!f) { perror("fopen write iolog"); return 1; } /* * That's it for writing, setup a log buffer and we're done. */ td->iolog_f = f; td->iolog_buf = malloc(8192); setvbuf(f, td->iolog_buf, _IOFBF, 8192); /* * write our version line */ if (fprintf(f, "%s\n", iolog_ver2) < 0) { perror("iolog init\n"); return 1; } /* * add all known files */ for_each_file(td, ff, i) log_file(td, ff, FIO_LOG_ADD_FILE); return 0; }
int main(int argc, char **argv) { Octstr *os1; Octstr *os2; time_t start, diff; gwlib_init(); os1 = octstr_create(argv[1]); os2 = octstr_create(argv[2]); counter = counter_create(); start = time(NULL); for_each_file(os1, 1, count_file); diff = (time(NULL) - start); debug("",0,"file count: %ld in %lds", (long) counter_value(counter), (long) diff); #ifdef HAVE_NFTW counter_set(counter, 0); start = time(NULL); for_each_file2(os2, 1, count_file2); diff = (time(NULL) - start); debug("",0,"file count: %ld in %lds", (long) counter_value(counter), (long) diff); #endif counter_destroy(counter); octstr_destroy(os1); octstr_destroy(os2); gwlib_shutdown(); return 0; }
void StarDictPlugins::get_plugin_list(const std::list<std::string>& order_list, std::list<std::pair<StarDictPlugInType, std::list<StarDictPluginInfo> > > &plugin_list) { plugin_list.clear(); std::list<StarDictPluginInfo> virtualdict_pluginlist; std::list<StarDictPluginInfo> netdict_pluginlist; std::list<StarDictPluginInfo> specialdict_pluginlist; std::list<StarDictPluginInfo> tts_pluginlist; std::list<StarDictPluginInfo> parsedata_pluginlist; std::list<StarDictPluginInfo> misc_pluginlist; std::list<std::string> plugins_dirs; plugins_dirs.push_back(plugindirpath); std::list<std::string> disable_list; for_each_file(plugins_dirs, "." G_MODULE_SUFFIX, order_list, disable_list, PluginInfoLoader(*this, virtualdict_pluginlist, netdict_pluginlist, specialdict_pluginlist, tts_pluginlist, parsedata_pluginlist, misc_pluginlist)); if (!virtualdict_pluginlist.empty()) { plugin_list.push_back(std::pair<StarDictPlugInType, std::list<StarDictPluginInfo> >(StarDictPlugInType_VIRTUALDICT, virtualdict_pluginlist)); } if (!netdict_pluginlist.empty()) { plugin_list.push_back(std::pair<StarDictPlugInType, std::list<StarDictPluginInfo> >(StarDictPlugInType_NETDICT, netdict_pluginlist)); } if (!specialdict_pluginlist.empty()) { plugin_list.push_back(std::pair<StarDictPlugInType, std::list<StarDictPluginInfo> >(StarDictPlugInType_SPECIALDICT, specialdict_pluginlist)); } if (!tts_pluginlist.empty()) { plugin_list.push_back(std::pair<StarDictPlugInType, std::list<StarDictPluginInfo> >(StarDictPlugInType_TTS, tts_pluginlist)); } if (!parsedata_pluginlist.empty()) { plugin_list.push_back(std::pair<StarDictPlugInType, std::list<StarDictPluginInfo> >(StarDictPlugInType_PARSEDATA, parsedata_pluginlist)); } if (!misc_pluginlist.empty()) { plugin_list.push_back(std::pair<StarDictPlugInType, std::list<StarDictPluginInfo> >(StarDictPlugInType_MISC, misc_pluginlist)); } }
static int for_each_file(const Octstr *dir_s, int ignore_err, void(*cb)(const Octstr*, void*), void *data) { DIR *dir; struct dirent *ent; struct stat stat; int ret = 0; if ((dir = opendir(octstr_get_cstr(dir_s))) == NULL) { error(errno, "Could not open directory `%s'", octstr_get_cstr(dir_s)); return -1; } while((ent = readdir(dir)) != NULL) { Octstr *filename; if (*(ent->d_name) == '.') /* skip hidden files */ continue; filename = octstr_format("%S/%s", dir_s, ent->d_name); if (lstat(octstr_get_cstr(filename), &stat) == -1) { if (!ignore_err) error(errno, "Could not get stat for `%s'", octstr_get_cstr(filename)); ret = -1; } else if (S_ISDIR(stat.st_mode) && for_each_file(filename, ignore_err, cb, data) == -1) { ret = -1; } else if (S_ISREG(stat.st_mode) && cb != NULL) cb(filename, data); octstr_destroy(filename); if (ret == -1 && ignore_err) ret = 0; else if (ret == -1) break; } closedir(dir); return ret; }
static void list_dicts(const std::list<std::string> &dicts_dir_list, bool use_json) { bool first_entry = true; if (!use_json) printf(_("Dictionary's name Word count\n")); else fputc('[', stdout); std::list<std::string> order_list, disable_list; for_each_file(dicts_dir_list, ".ifo", order_list, disable_list, [use_json, &first_entry](const std::string &filename, bool) -> void { DictInfo dict_info; if (dict_info.load_from_ifo_file(filename, false)) { const std::string bookname = utf8_to_locale_ign_err(dict_info.bookname); if (use_json) { if (first_entry) { first_entry = false; } else { fputc(',', stdout); // comma between entries } printf("{\"name\": \"%s\", \"wordcount\": \"%d\"}", json_escape_string(bookname).c_str(), dict_info.wordcount); } else { printf("%s %d\n", bookname.c_str(), dict_info.wordcount); } } }); if (use_json) fputs("]\n", stdout); }
static int for_each_file(const Octstr *dir_s, int ignore_err, int(*cb)(const char *, const struct stat *, int, void *)) { DIR *dir; struct dirent *ent; int ret = 0; #ifndef _DIRENT_HAVE_D_TYPE struct stat stat; #endif if ((dir = opendir(octstr_get_cstr(dir_s))) == NULL) { error(errno, "Could not open directory `%s'", octstr_get_cstr(dir_s)); return -1; } while ((ent = readdir(dir)) != NULL) { Octstr *filename; if (!(strcmp((char*)ent->d_name, "." ) != 0 && strcmp((char*)ent->d_name, ".." ) != 0)) continue; filename = octstr_format("%S/%s", dir_s, ent->d_name); #ifdef _DIRENT_HAVE_D_TYPE if (ent->d_type == DT_DIR && for_each_file(filename, ignore_err, cb) == -1) { ret = -1; } else if (ent->d_type == DT_REG && cb != NULL) { cb(octstr_get_cstr(filename), NULL, 0, NULL); } #else if (lstat(octstr_get_cstr(filename), &stat) == -1) { if (!ignore_err) error(errno, "Could not get stat for `%s'", octstr_get_cstr(filename)); ret = -1; } else if (S_ISDIR(stat.st_mode) && for_each_file(filename, ignore_err, cb) == -1) { ret = -1; } else if (S_ISREG(stat.st_mode) && cb != NULL) { cb(octstr_get_cstr(filename), &stat, 0, NULL); } #endif octstr_destroy(filename); if (ret == -1 && ignore_err) ret = 0; else if (ret == -1) break; } closedir(dir); return ret; }
int for_each_file (GPParams *p, FileAction action) { CameraList *list; int i, count, r; const char *name = NULL; char *f = NULL; CR (gp_list_new (&list)); /* Iterate on all files */ CR (gp_camera_folder_list_files (p->camera, p->folder, list, p->context)); CR (count = gp_list_count (list)); if (p->flags & FLAGS_REVERSE) { for (i = count ; i--; ) { CL (gp_list_get_name (list, i, &name), list); CL (action (p, name), list); } } else { for (i = 0; i < count; i++) { CL (gp_list_get_name (list, i, &name), list); CL (action (p, name), list); } } /* If no recursion is requested, we are done. */ if (!(p->flags & FLAGS_RECURSE)) { gp_list_free (list); return (GP_OK); } /* Recursion requested. Descend into subfolders. */ CL (gp_camera_folder_list_folders (p->camera, p->folder, list, p->context), list); CL (count = gp_list_count (list), list); for (i = 0; i < count; i++) { CL (gp_list_get_name (list, i, &name), list); f = p->folder; p->folder = malloc (sizeof (char) * (strlen (f) + 1 + strlen (name) + 1)); if (!p->folder) { p->folder = f; gp_list_free (list); return (GP_ERROR_NO_MEMORY); } strcpy (p->folder, f); if (p->folder[strlen (p->folder) - 1] != '/') strcat (p->folder, "/"); strcat (p->folder, name); r = for_each_file (p, action); free (p->folder); p->folder = f; CL (r, list); } gp_list_free (list); return (GP_OK); }
GtkTreeStore* TreeDicts::Load(const strlist_t& tree_dicts_dirs, const strlist_t& order_list, const strlist_t& disable_list) { TreeDictLoader load(*this); for_each_file(tree_dicts_dirs, ".ifo", order_list, disable_list, load); return TreeDict::get_model(); }
static int fill_file_completions(struct thread_data *td, struct thread_io_list *s, unsigned int *index) { struct fio_file *f; unsigned int i; int comps = 0; for_each_file(td, f, i) comps += __fill_file_completions(td, s, f, index); return comps; }
int load_scenario(int kind) { int i; for (i=0; load_dialog[i].proc; i++) { load_dialog[i].fg = colors[black]; load_dialog[i].bg = colors[gray]; } load_dialog[LOAD_LISTBOX].bg = colors[white]; file_index = for_each_file("*.sce", FA_ARCH, foo, 0); if (kind==SL_GAME) file_index += for_each_file("*.sav", FA_ARCH, foo, 0); files = (files_t *)malloc(sizeof(files_t)*file_index); file_index=0; for_each_file("*.sce", FA_ARCH, add_file, 0); if (kind==SL_GAME) for_each_file("*.sav", FA_ARCH, add_file, 0); i=1; if (do_dialog(load_dialog, -1)==LOAD_OKAY) { PACKFILE *file; unsigned short magic; file = pack_fopen(files[load_dialog[LOAD_LISTBOX].d1].name, "rb"); if (file) { pack_fread(&game, sizeof(game_t), file); pack_fread(matrix, sizeof(tile_t)*game.tiles, file); pack_fread(players, sizeof(players_t)*8, file); pack_fread(&magic, sizeof(unsigned short), file); pack_fclose(file); if (magic==MAGIC) { printf("Game loaded.\n"); i=0; } } if (i==1) alert("!ERROR", "Not a valid scenario file", NULL, "OK", NULL, 'o', 0); } free(files); return i; }
static void store_spool_for_each_message(void(*callback_fn)(Msg* msg, void *data), void *data) { struct status d; if (spool == NULL) return; d.callback_fn = callback_fn; d.data = data; /* ignore error because files may disappear */ for_each_file(spool, 1, status_cb, &d); }
static int for_each(const char *filepath, const struct stat *info, int typeflag, struct FTW *ftwinfo) { const char *const filename = filepath + ftwinfo->base; struct tm atime; FILE *in; if (typeflag == FTW_F) { localtime_r(&(info->st_atime), &atime); for_each_file(in, filepath, info, &atime); return 0; } return 0; }
void clear_io_state(struct thread_data *td) { struct fio_file *f; unsigned int i; reset_io_counters(td); close_files(td); for_each_file(td, f, i) fio_file_clear_done(f); /* * Set the same seed to get repeatable runs */ td_fill_rand_seeds(td); }
void DictMngr::GetAllDictionaryList(std::list < std::string > &dict_list) { strlist_t dicts_dir_list; strlist_t order_list; strlist_t disable_list; /* default mstardict dictionary directory */ dicts_dir_list.push_back(std::string(DEFAULT_DICT_DIR)); /* stardict dictionary directory */ dicts_dir_list.push_back(std::string(STARDICT_DICT_DIR)); oStarDict->oConf->GetStringList("/apps/maemo/mstardict/dict_list", order_list); for_each_file(dicts_dir_list, ".ifo", order_list, disable_list, GetAllDictList(dict_list)); }
static Octstr *store_spool_status(int status_type) { Octstr *ret = octstr_create(""); const char *format; struct status data; /* check if we are active */ if (spool == NULL) return ret; /* set the type based header */ if (status_type == BBSTATUS_HTML) { octstr_append_cstr(ret, "<table border=1>\n" "<tr><td>SMS ID</td><td>Type</td><td>Time</td><td>Sender</td><td>Receiver</td>" "<td>SMSC ID</td><td>BOX ID</td><td>UDH</td><td>Message</td>" "</tr>\n"); format = "<tr><td>%s</td><td>%s</td>" "<td>%04d-%02d-%02d %02d:%02d:%02d</td>" "<td>%s</td><td>%s</td><td>%s</td>" "<td>%s</td><td>%s</td><td>%s</td></tr>\n"; } else if (status_type == BBSTATUS_XML) { format = "<message>\n\t<id>%s</id>\n\t<type>%s</type>\n\t" "<time>%04d-%02d-%02d %02d:%02d:%02d</time>\n\t" "<sender>%s</sender>\n\t" "<receiver>%s</receiver>\n\t<smsc-id>%s</smsc-id>\n\t" "<box-id>%s</box-id>\n\t" "<udh-data>%s</udh-data>\n\t<msg-data>%s</msg-data>\n\t" "</message>\n"; } else { octstr_append_cstr(ret, "[SMS ID] [Type] [Time] [Sender] [Receiver] [SMSC ID] [BOX ID] [UDH] [Message]\n"); format = "[%s] [%s] [%04d-%02d-%02d %02d:%02d:%02d] [%s] [%s] [%s] [%s] [%s] [%s]\n"; } data.format = format; data.status = ret; /* ignore error because files may disappear */ for_each_file(spool, 1, status_cb, &data); /* set the type based footer */ if (status_type == BBSTATUS_HTML) { octstr_append_cstr(ret,"</table>"); } return ret; }
static int store_spool_load(void(*receive_msg)(Msg*)) { int rc; /* check if we are active */ if (spool == NULL) return 0; /* sanity check */ if (receive_msg == NULL) return -1; rc = for_each_file(spool, 0, dispatch, receive_msg); info(0, "Loaded %ld messages from store.", counter_value(counter)); /* allow using of storage */ gwlist_remove_producer(loaded); return rc; }
int luas_load_dir(luas_state* s, const char* path, bool recursive) { return for_each_file(path, ".lua", recursive, _load_file, s); }
/* * Adds a job to the list of things todo. Sanitizes the various options * to make sure we don't have conflicts, and initializes various * members of td. */ static int add_job(struct thread_data *td, const char *jobname, int job_add_num) { const char *ddir_str[] = { NULL, "read", "write", "rw", NULL, "randread", "randwrite", "randrw" }; unsigned int i; char fname[PATH_MAX]; int numjobs, file_alloced; /* * the def_thread is just for options, it's not a real job */ if (td == &def_thread) return 0; /* * if we are just dumping the output command line, don't add the job */ if (dump_cmdline) { put_job(td); return 0; } if (profile_td_init(td)) goto err; if (ioengine_load(td)) goto err; if (td->o.use_thread) nr_thread++; else nr_process++; if (td->o.odirect) td->io_ops->flags |= FIO_RAWIO; file_alloced = 0; if (!td->o.filename && !td->files_index && !td->o.read_iolog_file) { file_alloced = 1; if (td->o.nr_files == 1 && exists_and_not_file(jobname)) add_file(td, jobname); else { for (i = 0; i < td->o.nr_files; i++) { sprintf(fname, "%s.%d.%d", jobname, td->thread_number, i); add_file(td, fname); } } } if (fixup_options(td)) goto err; flow_init_job(td); /* * IO engines only need this for option callbacks, and the address may * change in subprocesses. */ if (td->eo) *(struct thread_data **)td->eo = NULL; if (td->io_ops->flags & FIO_DISKLESSIO) { struct fio_file *f; for_each_file(td, f, i) f->real_file_size = -1ULL; } td->mutex = fio_mutex_init(0); td->ts.clat_percentiles = td->o.clat_percentiles; if (td->o.overwrite_plist) memcpy(td->ts.percentile_list, td->o.percentile_list, sizeof(td->o.percentile_list)); else memcpy(td->ts.percentile_list, def_percentile_list, sizeof(def_percentile_list)); td->ts.clat_stat[0].min_val = td->ts.clat_stat[1].min_val = ULONG_MAX; td->ts.slat_stat[0].min_val = td->ts.slat_stat[1].min_val = ULONG_MAX; td->ts.lat_stat[0].min_val = td->ts.lat_stat[1].min_val = ULONG_MAX; td->ts.bw_stat[0].min_val = td->ts.bw_stat[1].min_val = ULONG_MAX; td->ddir_seq_nr = td->o.ddir_seq_nr; if ((td->o.stonewall || td->o.new_group) && prev_group_jobs) { prev_group_jobs = 0; groupid++; } td->groupid = groupid; prev_group_jobs++; if (init_random_state(td, td->rand_seeds, sizeof(td->rand_seeds))) { td_verror(td, errno, "init_random_state"); goto err; } if (setup_rate(td)) goto err; if (td->o.write_lat_log) { setup_log(&td->lat_log, td->o.log_avg_msec); setup_log(&td->slat_log, td->o.log_avg_msec); setup_log(&td->clat_log, td->o.log_avg_msec); } if (td->o.write_bw_log) setup_log(&td->bw_log, td->o.log_avg_msec); if (td->o.write_iops_log) setup_log(&td->iops_log, td->o.log_avg_msec); if (!td->o.name) td->o.name = strdup(jobname); if (!terse_output) { if (!job_add_num) { if (!strcmp(td->io_ops->name, "cpuio")) { log_info("%s: ioengine=cpu, cpuload=%u," " cpucycle=%u\n", td->o.name, td->o.cpuload, td->o.cpucycle); } else { char *c1, *c2, *c3, *c4; c1 = to_kmg(td->o.min_bs[DDIR_READ]); c2 = to_kmg(td->o.max_bs[DDIR_READ]); c3 = to_kmg(td->o.min_bs[DDIR_WRITE]); c4 = to_kmg(td->o.max_bs[DDIR_WRITE]); log_info("%s: (g=%d): rw=%s, bs=%s-%s/%s-%s," " ioengine=%s, iodepth=%u\n", td->o.name, td->groupid, ddir_str[td->o.td_ddir], c1, c2, c3, c4, td->io_ops->name, td->o.iodepth); free(c1); free(c2); free(c3); free(c4); } } else if (job_add_num == 1) log_info("...\n"); } /* * recurse add identical jobs, clear numjobs and stonewall options * as they don't apply to sub-jobs */ numjobs = td->o.numjobs; while (--numjobs) { struct thread_data *td_new = get_new_job(0, td, 1); if (!td_new) goto err; td_new->o.numjobs = 1; td_new->o.stonewall = 0; td_new->o.new_group = 0; if (file_alloced) { td_new->o.filename = NULL; td_new->files_index = 0; td_new->files_size = 0; td_new->files = NULL; } job_add_num = numjobs - 1; if (add_job(td_new, jobname, job_add_num)) goto err; } return 0; err: put_job(td); return -1; }
int main(int argc, char *argv[]) try { setlocale(LC_ALL, ""); #if ENABLE_NLS bindtextdomain("sdcv", //"./locale"//< for testing GETTEXT_TRANSLATIONS_PATH //< should be ); textdomain("sdcv"); #endif gboolean show_version = FALSE; gboolean show_list_dicts = FALSE; glib::StrArr use_dict_list; gboolean non_interactive = FALSE; gboolean json_output = FALSE; gboolean no_fuzzy = FALSE; gboolean utf8_output = FALSE; gboolean utf8_input = FALSE; glib::CharStr opt_data_dir; gboolean only_data_dir = FALSE; gboolean colorize = FALSE; const GOptionEntry entries[] = { { "version", 'v', 0, G_OPTION_ARG_NONE, &show_version, _("display version information and exit"), nullptr }, { "list-dicts", 'l', 0, G_OPTION_ARG_NONE, &show_list_dicts, _("display list of available dictionaries and exit"), nullptr }, { "use-dict", 'u', 0, G_OPTION_ARG_STRING_ARRAY, get_addr(use_dict_list), _("for search use only dictionary with this bookname"), _("bookname") }, { "non-interactive", 'n', 0, G_OPTION_ARG_NONE, &non_interactive, _("for use in scripts"), nullptr }, { "json-output", 'j', 0, G_OPTION_ARG_NONE, &json_output, _("print the result formatted as JSON"), nullptr }, { "exact-search", 'e', 0, G_OPTION_ARG_NONE, &no_fuzzy, _("do not fuzzy-search for similar words, only return exact matches"), nullptr }, { "utf8-output", '0', 0, G_OPTION_ARG_NONE, &utf8_output, _("output must be in utf8"), nullptr }, { "utf8-input", '1', 0, G_OPTION_ARG_NONE, &utf8_input, _("input of sdcv in utf8"), nullptr }, { "data-dir", '2', 0, G_OPTION_ARG_STRING, get_addr(opt_data_dir), _("use this directory as path to stardict data directory"), _("path/to/dir") }, { "only-data-dir", 'x', 0, G_OPTION_ARG_NONE, &only_data_dir, _("only use the dictionaries in data-dir, do not search in user and system directories"), nullptr }, { "color", 'c', 0, G_OPTION_ARG_NONE, &colorize, _("colorize the output"), nullptr }, {}, }; glib::Error error; GOptionContext *context = g_option_context_new(_(" words")); g_option_context_set_help_enabled(context, TRUE); g_option_context_add_main_entries(context, entries, nullptr); const gboolean parse_res = g_option_context_parse(context, &argc, &argv, get_addr(error)); g_option_context_free(context); if (!parse_res) { fprintf(stderr, _("Invalid command line arguments: %s\n"), error->message); return EXIT_FAILURE; } if (show_version) { printf(_("Console version of Stardict, version %s\n"), gVersion); return EXIT_SUCCESS; } const gchar *stardict_data_dir = g_getenv("STARDICT_DATA_DIR"); std::string data_dir; if (!opt_data_dir) { if (!only_data_dir) { if (stardict_data_dir) data_dir = stardict_data_dir; else data_dir = "/usr/share/stardict/dic"; } } else { data_dir = get_impl(opt_data_dir); } const char *homedir = g_getenv("HOME"); if (!homedir) homedir = g_get_home_dir(); std::list<std::string> dicts_dir_list; if (!only_data_dir) dicts_dir_list.push_back(std::string(homedir) + G_DIR_SEPARATOR + ".stardict" + G_DIR_SEPARATOR + "dic"); dicts_dir_list.push_back(data_dir); if (show_list_dicts) { list_dicts(dicts_dir_list, json_output); return EXIT_SUCCESS; } std::list<std::string> disable_list; std::map<std::string, std::string> bookname_to_ifo; for_each_file(dicts_dir_list, ".ifo", std::list<std::string>(), std::list<std::string>(), [&bookname_to_ifo](const std::string &fname, bool) { DictInfo dict_info; const bool load_ok = dict_info.load_from_ifo_file(fname, false); if (!load_ok) return; bookname_to_ifo[dict_info.bookname] = dict_info.ifo_file_name; }); std::list<std::string> order_list; if (use_dict_list != nullptr) { for (auto &&x : bookname_to_ifo) { gchar **p = get_impl(use_dict_list); for (; *p != nullptr; ++p) if (x.first.compare(*p) == 0) { break; } if (*p == nullptr) { disable_list.push_back(x.second); } } // add bookname to list gchar **p = get_impl(use_dict_list); while (*p) { order_list.push_back(bookname_to_ifo.at(*p)); ++p; } } else { const std::string odering_cfg_file = std::string(homedir) + G_DIR_SEPARATOR_S ".sdcv_ordering"; FILE *ordering_file = fopen(odering_cfg_file.c_str(), "r"); if (ordering_file != nullptr) { std::string line; while (stdio_getline(ordering_file, line)) { order_list.push_back(bookname_to_ifo.at(line)); } fclose(ordering_file); } } const std::string conf_dir = std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".stardict"; if (g_mkdir(conf_dir.c_str(), S_IRWXU) == -1 && errno != EEXIST) { fprintf(stderr, _("g_mkdir failed: %s\n"), strerror(errno)); } Library lib(utf8_input, utf8_output, colorize, json_output, no_fuzzy); lib.load(dicts_dir_list, order_list, disable_list); std::unique_ptr<IReadLine> io(create_readline_object()); if (optind < argc) { for (int i = optind; i < argc; ++i) if (!lib.process_phrase(argv[i], *io, non_interactive)) { return EXIT_FAILURE; } } else if (!non_interactive) { std::string phrase; while (io->read(_("Enter word or phrase: "), phrase)) { if (!lib.process_phrase(phrase.c_str(), *io)) return EXIT_FAILURE; phrase.clear(); } putchar('\n'); } else { fprintf(stderr, _("There are no words/phrases to translate.\n")); } return EXIT_SUCCESS; } catch (const std::exception &ex) { fprintf(stderr, "Internal error: %s\n", ex.what()); exit(EXIT_FAILURE); }
/* * Flush all DLR messages out of the spool, removing all. */ static void dlr_spool_flush(void) { for_each_file(spool_dir, 1, unlink_file); counter_set(counter, 0); }
int main(int argc, char *argv[]) { setlocale(LC_ALL, ""); #if ENABLE_NLS bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); #endif int optc; bool h = false, v = false, show_list_dicts=false, use_book_name=false, non_interactive=false, utf8_output=false, utf8_input=false; strlist_t enable_list; string data_dir; int option_index = 0; while ((optc = getopt_long (argc, argv, "hvu:ln", longopts, &option_index))!=-1) switch (optc){ case 0: utf8_output=true; break; case 1: utf8_input=true; break; case 2: data_dir=optarg; break; case 'v': v = true; break; case 'h': h = true; break; case 'l': show_list_dicts=true; break; case 'u': use_book_name=true; enable_list.push_back(locale_to_utf8(optarg)); break; case 'n': non_interactive=true; break; case '?': fprintf(stderr, _("Unknown option.\nTry '%s --help' for more information.\n"), argv[0]); return EXIT_FAILURE; } if (h) { printf("sdcv - console version of StarDict.\n"); printf(_("Usage: %s [OPTIONS] words\n"), argv[0]); printf(_("-h, --help display this help and exit\n")); printf(_("-v, --version display version information and exit\n")); printf(_("-l, --list-dicts display list of available dictionaries and exit\n")); printf(_("-u, --use-dict bookname for search use only dictionary with this bookname\n")); printf(_("-n, --non-interactive for use in scripts\n")); printf(_("--utf8-output output must be in utf8\n")); printf(_("--utf8-input input of sdcv in utf8\n")); printf(_("--data-dir path/to/dir use this directory as path to stardict data directory\n")); return EXIT_SUCCESS; } if (v) { printf(_("Console version of Stardict, version %s\n"), gVersion); return EXIT_SUCCESS; } const gchar *stardict_data_dir=g_getenv("STARDICT_DATA_DIR"); if (data_dir.empty()) { if (stardict_data_dir) data_dir=stardict_data_dir; else data_dir="/usr/share/stardict/dic"; } strlist_t dicts_dir_list; dicts_dir_list.push_back(std::string(g_get_home_dir())+G_DIR_SEPARATOR+ ".stardict"+G_DIR_SEPARATOR+"dic"); dicts_dir_list.push_back(data_dir); if (show_list_dicts) { printf(_("Dictionary's name Word count\n")); PrintDictInfo print_dict_info; strlist_t order_list, disable_list; for_each_file(dicts_dir_list, ".ifo", order_list, disable_list, print_dict_info); return EXIT_SUCCESS; } strlist_t disable_list; //DictInfoList dict_info_list; if (use_book_name) { strlist_t empty_list; CreateDisableList create_disable_list(enable_list, disable_list); for_each_file(dicts_dir_list, ".ifo", empty_list, empty_list, create_disable_list); } string conf_dir = string(g_get_home_dir())+G_DIR_SEPARATOR+".stardict"; if (g_mkdir(conf_dir.c_str(), S_IRWXU)==-1 && errno!=EEXIST) fprintf(stderr, _("g_mkdir failed: %s\n"), strerror(errno)); Library lib(utf8_input, utf8_output); strlist_t empty_list; lib.load(dicts_dir_list, empty_list, disable_list); std::auto_ptr<read_line> io(create_readline_object()); if (optind < argc) { for(int i=optind; i<argc; ++i) if (!lib.process_phrase(argv[i], *io, non_interactive)) return EXIT_FAILURE; } else if (!non_interactive) { string phrase; while (io->read(_("Enter word or phrase: "), phrase)) { if (!lib.process_phrase(phrase.c_str(), *io)) return EXIT_FAILURE; phrase.clear(); } putchar('\n'); } else fprintf(stderr, _("There are no words/phrases to translate.\n")); return EXIT_SUCCESS; }
void StarDictPlugins::load(const std::string& dirpath, const std::list<std::string>& order_list, const std::list<std::string>& disable_list) { std::list<std::string> plugins_dirs; plugins_dirs.push_back(dirpath); for_each_file(plugins_dirs, "." G_MODULE_SUFFIX, order_list, disable_list, PluginLoader(*this)); }
static bool test_directory(char const * base) { for_each_file_smt foreach; return for_each_file(foreach, base, "*.smt"); }
const FileItemList& FileItem::getChildren() { // Is the file-item a folder? if (IS_FOLDER(this) && // if the children list is empty, or the file-system version // change (it's like to say: the current this->children list // is outdated)... (this->children.empty() || current_file_system_version > this->version)) { FileItemList::iterator it; FileItem* child; // we have to mark current items as deprecated for (it=this->children.begin(); it!=this->children.end(); ++it) { child = static_cast<FileItem*>(*it); child->removed = true; } //PRINTF("FS: Loading files for %p (%s)\n", fileitem, fileitem->displayname); #ifdef USE_PIDLS { IShellFolder* pFolder = NULL; if (this == rootitem) pFolder = shl_idesktop; else shl_idesktop->BindToObject(this->fullpidl, NULL, IID_IShellFolder, (LPVOID *)&pFolder); if (pFolder != NULL) { IEnumIDList *pEnum = NULL; ULONG c, fetched; /* get the interface to enumerate subitems */ pFolder->EnumObjects(win_get_window(), SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &pEnum); if (pEnum != NULL) { LPITEMIDLIST itempidl[256]; SFGAOF attribs[256]; /* enumerate the items in the folder */ while (pEnum->Next(256, itempidl, &fetched) == S_OK && fetched > 0) { /* request the SFGAO_FOLDER attribute to know what of the item is a folder */ for (c=0; c<fetched; ++c) { attribs[c] = SFGAO_FOLDER; pFolder->GetAttributesOf(1, (LPCITEMIDLIST *)itempidl, attribs+c); } /* generate the FileItems */ for (c=0; c<fetched; ++c) { LPITEMIDLIST fullpidl = concat_pidl(this->fullpidl, itempidl[c]); child = get_fileitem_by_fullpidl(fullpidl, false); if (!child) { child = new FileItem(this); child->pidl = itempidl[c]; child->fullpidl = fullpidl; child->attrib = attribs[c]; update_by_pidl(child); put_fileitem(child); } else { ASSERT(child->parent == this); free_pidl(fullpidl); free_pidl(itempidl[c]); } this->insertChildSorted(child); } } pEnum->Release(); } if (pFolder != shl_idesktop) pFolder->Release(); } } #else { char buf[MAX_PATH], path[MAX_PATH], tmp[32]; ustrcpy(path, this->filename.c_str()); put_backslash(path); replace_filename(buf, path, uconvert_ascii("*.*", tmp), sizeof(buf)); #ifdef WORKAROUND_64BITS_SUPPORT // we cannot use the for_each_file's 'param' to wrap a 64-bits pointer for_each_child_callback_param = this; for_each_file(buf, FA_TO_SHOW, for_each_child_callback, 0); #else for_each_file(buf, FA_TO_SHOW, for_each_child_callback, (int)this); #endif } #endif // check old file-items (maybe removed directories or file-items) for (it=this->children.begin(); it!=this->children.end(); ) { child = static_cast<FileItem*>(*it); if (child->removed) { it = this->children.erase(it); fileitems_map->erase(fileitems_map->find(child->keyname)); delete child; } else ++it; } // now this file-item is updated this->version = current_file_system_version; } return this->children; }
/* fs_flist_proc: * Dialog procedure for the file selector list. */ static int fs_flist_proc(int msg, DIALOG *d, int c) { static int recurse_flag = 0; char *s = file_selector[FS_EDIT].dp; char tmp[32]; int sel = d->d1; int i, ret; int ch, count; if (msg == MSG_START) { if (!flist) { flist = malloc(sizeof(FLIST)); if (!flist) { *allegro_errno = ENOMEM; return D_CLOSE; } } else { for (i=0; i<flist->size; i++) if (flist->name[i]) free(flist->name[i]); } flist->size = 0; replace_filename(flist->dir, s, uconvert_ascii("*.*", tmp), sizeof(flist->dir)); for_each_file(flist->dir, FA_RDONLY | FA_DIREC | FA_ARCH | FA_HIDDEN | FA_SYSTEM, fs_flist_putter, 0); if (*allegro_errno) raine_alert("", "Disk error", NULL, NULL, "OK", NULL, 13, 0); usetc(get_filename(flist->dir), 0); d->d1 = d->d2 = 0; sel = 0; } if (msg == MSG_END) { if (flist) { for (i=0; i<flist->size; i++) if (flist->name[i]) free(flist->name[i]); free(flist); flist = NULL; } } recurse_flag++; ret = d_text_list_proc(msg, d, c); /* call the parent procedure */ recurse_flag--; if (((sel != d->d1) || (ret == D_CLOSE)) && (recurse_flag == 0)) { replace_filename(s, flist->dir, flist->name[d->d1], 512); /* check if we want to `cd ..' */ if ((!ustrncmp(flist->name[d->d1], "..", 2)) && (ret == D_CLOSE)) { /* let's remember the previous directory */ ustrcpy(updir, empty_string); i = ustrlen(flist->dir); count = 0; while (i>0) { ch = ugetat(flist->dir, i); if ((ch == '/') || (ch == OTHER_PATH_SEPARATOR)) { if (++count == 2) break; } uinsert(updir, 0, ch); i--; } /* ok, we have the dirname in updir */ } else { ustrcpy(updir, empty_string); } scare_mouse(); SEND_MESSAGE(file_selector+FS_EDIT, MSG_START, 0); SEND_MESSAGE(file_selector+FS_EDIT, MSG_DRAW, 0); unscare_mouse(); if (ret == D_CLOSE) return SEND_MESSAGE(file_selector+FS_EDIT, MSG_KEY, 0); } return ret; }
void fill_filename_list(filename_list *&f_file, char *wildcard) { for_each_file(wildcard,255,&save_filename,(int)&f_file); }
static void AuditDir (dir_s *dir) { for_each_file(dir, AuditChild, dir); }