Imported version 0.4-1
[mstardict] / stardict-plugins / stardict-wiki-parsedata-plugin / stardict_wiki_parsedata.cpp
1 #include "stardict_wiki_parsedata.h"
2 #include "stardict_wiki2xml.h"
3 #include <glib/gi18n.h>
4
5 #ifdef _WIN32
6 #include <windows.h>
7 #endif
8
9 static bool parse(const char *p, unsigned int *parsed_size, ParseResult &result, const char *oword)
10 {
11         if (*p != 'w')
12                 return false;
13         p++;
14         size_t len = strlen(p);
15         if (len) {
16                 ParseResultItem item;
17                 item.type = ParseResultItemType_mark;
18                 item.mark = new ParseResultMarkItem;
19                 std::string res(p, len);
20                 std::string xml = wiki2xml(res);
21                 item.mark->pango = wikixml2pango(xml);
22                 result.item_list.push_back(item);
23         }
24         *parsed_size = 1 + len + 1;
25         return true;
26 }
27
28 static void configure()
29 {
30 }
31
32 DLLIMPORT bool stardict_plugin_init(StarDictPlugInObject *obj)
33 {
34         if (strcmp(obj->version_str, PLUGIN_SYSTEM_VERSION)!=0) {
35                 g_print("Error: Wiki data parsing plugin version doesn't match!\n");
36                 return true;
37         }
38         obj->type = StarDictPlugInType_PARSEDATA;
39         obj->info_xml = g_strdup_printf("<plugin_info><name>%s</name><version>1.0</version><short_desc>%s</short_desc><long_desc>%s</long_desc><author>Hu Zheng &lt;huzheng_001@163.com&gt;</author><website>http://stardict.sourceforge.net</website></plugin_info>", _("Wiki data parsing"), _("Wiki data parsing engine."), _("Parse the wiki data."));
40         obj->configure_func = configure;
41         return false;
42 }
43
44 DLLIMPORT void stardict_plugin_exit(void)
45 {
46 }
47
48 DLLIMPORT bool stardict_parsedata_plugin_init(StarDictParseDataPlugInObject *obj)
49 {
50         obj->parse_func = parse;
51         g_print(_("Wiki data parsing plug-in loaded.\n"));
52         return false;
53 }
54
55 #ifdef _WIN32
56 BOOL APIENTRY DllMain (HINSTANCE hInst     /* Library instance handle. */ ,
57                        DWORD reason        /* Reason this function is being called. */ ,
58                        LPVOID reserved     /* Not used. */ )
59 {
60     switch (reason)
61     {
62       case DLL_PROCESS_ATTACH:
63         break;
64
65       case DLL_PROCESS_DETACH:
66         break;
67
68       case DLL_THREAD_ATTACH:
69         break;
70
71       case DLL_THREAD_DETACH:
72         break;
73     }
74
75     /* Returns TRUE on success, FALSE on failure */
76     return TRUE;
77 }
78 #endif