免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 685 | 回复: 0
打印 上一主题 下一主题

OXIM源码分析一[oxim_main.c] [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-12-08 16:11 |只看该作者 |倒序浏览

                               
               
                一  代码的主要流程是:
            1 处理命令行参数。  command_switch()
            2 设定信号处理函数。  sighandler()
            3 输入法初始化。主要包括
                                   oxim_init();
                                   gui_init(&oxim_core);
                                   xim_init(&oxim_core);
                4 进入循环处理    gui_loop(&oxim_core);
二    重要数据结构
/* *  OXIM core configuration. */typedef struct {    char *lc_ctype;    Display *display;    Window window;    /* XIM & Input Method configuration. */    IC *ic, *icp;    xmode_t oxim_mode;    inp_state_t default_im;    inp_state_t default_im_sinmd;    inp_state_t im_focus;    XIMStyles input_styles;    /* Initialization structer. */    char display_name[256];   char xim_name[64];} xccore_t;
   
/*
    Copyright (C) 1999 by  XCIN TEAM
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/      
#ifdef HAVE_CONFIG_H
#  include "config.h"
#endif
#ifdef HPUX
#  define _INCLUDE_POSIX_SOURCE
#endif
#include stdio.h>
#include stdlib.h>
#include string.h>
#include ctype.h>
#include unistd.h>
#include X11/Xlocale.h>
#include X11/Xlib.h>
#include X11/Xatom.h>
#include X11/Xft/Xft.h>
#include signal.h>
#include "oximtool.h"
#include "oxim.h"
#include "fkey.h"
int verbose, errstatus;
static xccore_t oxim_core;        /* OXIM kernel data. */
void gui_init(xccore_t *xccore);
void gui_loop(xccore_t *xccore);
void xim_init(xccore_t *xccore);
void gui_init_xft(void);
/*----------------------------------------------------------------------------
        Initial Input.
----------------------------------------------------------------------------*/
static void
oxim_setlocale(void)
{
    char loc_return[128], enc_return[128];
    oxim_set_perr("oxim");
    oxim_set_lc_ctype("", loc_return, 128, enc_return, 128, OXIMMSG_ERROR);
    oxim_core.lc_ctype = (char *)strdup(loc_return);
    oxim_set_lc_messages("", loc_return, 128);
    if (XSupportsLocale() != True)
        oxim_perr(OXIMMSG_ERROR,
         N_("X locale \"%s\" is not supported by your system.\n"),
         oxim_core.lc_ctype);
}
static void
print_usage(void)
{
    oxim_perr(OXIMMSG_EMPTY,
    N_("OXIM (Open X Input Method) version %s.\n"
       "(module ver: %s).\n"),
    PACKAGE_VERSION, MODULE_VERSION);
    oxim_perr(OXIMMSG_EMPTY,
     _("\n"
    "Usage:  oxim [-h] [-d DISPLAY] [-x XIM_name] [-v n] [-r]\n"
    "Options:  -h: print this message.\n"
    "          -d: set X Display.\n"
    "          -x: register XIM server name to Xlib.\n"
    "          -v: set debug level to n.\n"
    "          -r: reload oxim.\n\n"));
}
static void
command_switch(int argc, char **argv)
/* Command line arguements. */
{
    int  rev;
#ifdef HPUX
    extern char *optarg;
    extern int opterr, optopt;
#endif
/*
*  Command line arguement & preparing for oxim_rc_t.
*/
    bzero(&oxim_core, sizeof(xccore_t));
    oxim_setlocale();
    opterr = 0;
    Display *dpy;
    Window win;
    while ((rev = getopt(argc, argv, "hd:x:v:r")) != EOF) {
        switch (rev) {
        case 'h':
            print_usage();
            exit(0);
    case 'd':
        strncpy(oxim_core.display_name, optarg,
            sizeof(oxim_core.display_name));
        break;
    case 'x':
        strncpy(oxim_core.xim_name, optarg,
            sizeof(oxim_core.xim_name));
        break;
    case 'v':
        verbose = atoi(optarg);
        break;
    case 'r':
            
        if (! (dpy = XOpenDisplay(oxim_core.display_name)))
        {
        oxim_perr(OXIMMSG_ERROR, N_("cannot open display: %s\n"),
                oxim_core.display_name);
        }
        Atom oxim_atom = XInternAtom(dpy, OXIM_ATOM, True);
        win = XGetSelectionOwner(dpy, oxim_atom);
        if (oxim_atom != None && win != None )
        {
        XClientMessageEvent event;
        event.type = ClientMessage;
        event.window = win;
        event.message_type = oxim_atom;
        event.format = 32;
        event.data.l[0] = OXIM_CMD_RELOAD;
        XSendEvent(dpy, win, False, 0, (XEvent *)&event);
        XSync(dpy, False);
        }
        exit(0);
        break;
        case '?':
            oxim_perr(OXIMMSG_ERROR, N_("unknown option  -%c.\n"), optopt);
            break;
        }
    }
/*
*  OXIM perface.
*/
    oxim_perr(OXIMMSG_EMPTY,
    N_("OXIM (Open X Input Method) version %s.\n"
           "(use \"-h\" option for help)\n"),
    PACKAGE_VERSION);
    oxim_perr(OXIMMSG_NORMAL, N_("locale \"%s\"\n"), oxim_core.lc_ctype);
}
/*----------------------------------------------------------------------------
        Main Program.
----------------------------------------------------------------------------*/
void xim_terminate(void);
void sighandler(int sig)
{
    if (sig == SIGQUIT) {
    DebugLog(1, ("catch signal: SIGQUIT\n"));
    }
    else if (sig == SIGTERM) {
    DebugLog(1, ("catch signal: SIGTERM\n"));
    }
    else {
    DebugLog(1, ("catch signal: SIGINT\n"));
    }
    if (sig == SIGQUIT)
    return;
    if (oxim_core.ic != NULL && (oxim_core.ic->ic_state & IC_FOCUS))
    oxim_core.oxim_mode |= OXIM_RUN_KILL;
    else {
    xim_terminate();
    exit(0);
    }
}
int
main(int argc, char **argv)
{
    command_switch(argc, argv);
    signal(SIGQUIT, sighandler);
    signal(SIGTERM, sighandler);
    signal(SIGINT,  sighandler);
    /* 初始化 OXIM */
    oxim_init();
    gui_init(&oxim_core);
    xim_init(&oxim_core);
    gui_loop(&oxim_core);
    return 0;
}
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/53499/showart_1685991.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP