updated on Tue Jan 10 12:02:00 UTC 2012
[aur-mirror.git] / sdcv-svn / sdcv-svn-order.patch
blob38e00b28c04f48d7227ac0730eb1b9bf87dff553
1 diff -ur trunk.bak/src/sdcv.cpp trunk/src/sdcv.cpp
2 --- trunk.bak/src/sdcv.cpp 2011-09-18 22:13:30.551808751 -0500
3 +++ trunk/src/sdcv.cpp 2011-09-19 10:16:26.115475575 -0500
4 @@ -50,6 +50,21 @@
6 };
8 +struct GetFilename {
9 + GetFilename(std::string bookname_, std::string& filename_) :
10 + bookname(bookname_), the_filename(filename_)
11 + {}
12 + void operator()(const std::string& filename, bool) {
13 + DictInfo dict_info;
14 + if (dict_info.load_from_ifo_file(filename, false) &&
15 + bookname.compare(0, dict_info.bookname.size(), dict_info.bookname) == 0)
16 + the_filename = filename;
17 + }
18 +private:
19 + std::string bookname;
20 + std::string& the_filename;
21 +};
23 struct CreateDisableList {
24 CreateDisableList(gchar **use_dist_list, strlist_t& disable_list_) :
25 disable_list(disable_list_)
26 @@ -176,6 +191,8 @@
29 strlist_t disable_list;
30 + strlist_t order_list;
31 + strlist_t bookname_list;
32 //DictInfoList dict_info_list;
34 if (use_dict_list) {
35 @@ -183,17 +200,43 @@
36 CreateDisableList create_disable_list(get_impl(use_dict_list), disable_list);
37 for_each_file(dicts_dir_list, ".ifo", empty_list,
38 empty_list, create_disable_list);
39 - }
40 + gchar **p = get_impl(use_dict_list);
41 + while (*p) {
42 + bookname_list.push_back(*p);
43 + ++p;
44 + }
45 + }
46 + else {
47 + FILE *ordering_file;
48 + char bookname[1024];
49 + if ((ordering_file = fopen((std::string(homedir)+G_DIR_SEPARATOR+".sdcv_ordering").c_str(), "r"))) {
50 + while (fgets(bookname, 1023, ordering_file))
51 + bookname_list.push_back(bookname);
52 + fclose(ordering_file);
53 + }
54 + }
56 + // translation from bookname to filename
57 + List::const_iterator it;
58 + for (it=bookname_list.begin(); it!=bookname_list.end(); ++it) {
59 + strlist_t empty_list;
60 + std::string filename;
61 + GetFilename get_file_name(*it, filename);
62 + for_each_file(dicts_dir_list, ".ifo", empty_list,
63 + empty_list, get_file_name);
64 + if (!filename.empty() &&
65 + std::find(order_list.begin(), order_list.end(),
66 + filename)==order_list.end())
67 + order_list.push_back(filename);
68 + }
71 - string conf_dir = string(g_get_home_dir())+G_DIR_SEPARATOR+".stardict";
72 + string conf_dir = string(g_get_home_dir())+G_DIR_SEPARATOR+".stardict";
73 if (g_mkdir(conf_dir.c_str(), S_IRWXU)==-1 && errno!=EEXIST)
74 fprintf(stderr, _("g_mkdir failed: %s\n"), strerror(errno));
77 Library lib(utf8_input, utf8_output);
78 - strlist_t empty_list;
79 - lib.load(dicts_dir_list, empty_list, disable_list);
80 + lib.load(dicts_dir_list, order_list, disable_list);
83 std::auto_ptr<read_line> io(create_readline_object());