Stardict的入口函数main函数在stardict.cpp的1654行,这个函数涉及到跨平台、软件国际化及CORBA的C/S模式,以下是其简要说明和注释:

// 这里的条件编译用于跨平台

1654 #ifdef _WIN32 // _WIN32 是在windows系统下特有的宏, windows平台

1660 //set gStarDictDataDir; // 设置stardict主目录

1664 if ((hmod = GetModuleHandle(NULL))==0) // 返回指向模块的句柄

1667 if (GetModuleFileName(hmod, tmp_buf, sizeof(tmp_buf))==0) // 获取程序当前执行文件名

1674 gStarDictDataDir=STARDICT_DATA_DIR; //STARDICT_DATA_DIR=\""$(datadir)/stardict"\"

1676 // 以下使用GNU GetText进行软件国际化

1677 #ifdef _WIN32

// bindtextdomain设置本地化文件的根路径(即(LANG)\LC_MESSAGES的所在目录)

1678 bindtextdomain (GETTEXT_PACKAGE, (gStarDictDataDir + G_DIR_SEPARATOR_S "locale").c_str());

1682 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); // 使用utf8编码

1684 // 获取用户指定的配置目录

1685 std::string userdir(get_user_config_dir());

// 将utf8字符串转换为系统环境的编码方式

1691 gchar *title=g_locale_from_utf8(_("StarDict"), -1, NULL, NULL, NULL);

1692 HWND ll_winhandle = FindWindowA(0, title); // 查找StarDict程序是否已运行

1695 if (IsIconic(ll_winhandle)) // 判断窗口是否最小化

1696 ShowWindow(ll_winhandle,SW_RESTORE); //从任务里恢复窗口显示

1698 SetForegroundWindow(ll_winhandle); // 激活该窗口

1703 gtk_set_locale(); // 调用setlocale(LC_ALL,""),为本地环境读入本地化数据库, 如果应用程序需要调用gtk_set_locale(),则必须在gtk_init()前调用

1704 gtk_init(&argc, &argv); // 为应用程序初始化GDK和GTK+库, 在argv中搜索它能识别的运行库参数, 处理并从argv矢量中删除已识别的参数

1706 #ifdef CONFIG_GPE //GPE掌上电脑环境,GPE Palmtop Environment

1727 #ifndef CONFIG_GNOME // 如果是命令行模式
1737if (g_utf8_validate (argv[i], -1, NULL)) / 验证字符串是否是utf8编码

1738 queryword= g_strdup(argv[i]); // 复制字符串作为查询词

1740 queryword = g_locale_to_utf8(argv[i],-1,NULL,NULL,NULL); // 将字符串转换为utf8编码

1745 #else // 如果在Gnome图形界面下

1746 GnomeProgram *program;

// Initialises the current GNOME libraries for use by the application

1747 program = gnome_program_init ("stardict", VERSION,

1756 // An opaque structure used to hold different types of values

1757 GValue value = { 0 };

1758 poptContext pctx; // popt 库是一个用来分析 GNU 风格命令行参数的函数库.

1759 // Gets a property of an object.

1760 g_object_get_property (G_OBJECT (program),

1767 args = (char**) poptGetArgs(pctx); // 把所有非选项的参数提取出来放到args里

1777 poptFreeContext (pctx);

1778

1779 CORBA_Object factory; // 定义服务器端

1793 // GnomeClient — Interactions with the session manager

1794 GnomeClient *client; // 客户端

1795 if ((client = gnome_master_client()) != NULL) { //Get the master session management client

1796 g_signal_connect (client, "save_yourself", G_CALLBACK (save_yourself_cb), (gpointer) argv[0]);

注:原创文章,转载请注明出处“我爱自然语言处理”:www.52nlp.cn

本文链接地址:
https://www.52nlp.cn/stardict-main-function-brief-description/

作者 52nlp

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注