Logo Search packages:      
Sourcecode: fcitx version File versions  Download package

void LoadProfile ( void   )

加载配置文件

Parameters:
void
Returns:
void

Definition at line 1498 of file tools.c.

References SaveConfig().

{
    FILE           *fp;
    char            buf[PATH_MAX], *pbuf, *pbuf1;
    int             i;
    Configure       *tmpconfig;

    /* 前将窗口的位置设定为最原始的默认值,接下来如果配置文件有,
     * 会从配置文件中读取,如果没有就使用这个了*/
    iMainWindowX = MAINWND_STARTX;        //主窗口位置X
    iMainWindowY = MAINWND_STARTY;        //主窗口位置Y
    iInputWindowX = INPUTWND_STARTX;      //输入窗口位置X
    iInputWindowY = INPUTWND_STARTY;      //输入窗口位置Y

    pbuf = getenv("HOME");
    if(!pbuf){
        fprintf(stderr, "error: get environment variable HOME\n");
        exit(1);
    }
    snprintf(buf, PATH_MAX, "%s/.fcitx/profile", pbuf);

    fp = fopen(buf, "r");
    if(!fp){
        if(errno == ENOENT)
            SaveProfile();
        return;
    }

    /* FIXME: 也许应该用另外更恰当的缓冲区长度 */
    while(fgets(buf, PATH_MAX, fp)){
        i = strlen(buf);
        if(buf[i-1] != '\n'){
            fprintf(stderr, "error: profile file: line length\n");
            exit(1);
        }else
            buf[i-1] = '\0';

        pbuf = buf;
        while(*pbuf && isspace(*pbuf))
            pbuf++;
        if(!*pbuf || *pbuf == '#')
            continue;

        pbuf1 = strchr(pbuf, '=');
        if(!pbuf1){
            fprintf(stderr, "error: profile file: configure entry name\n");
            exit(1);
        }

        for(tmpconfig = profiles; tmpconfig->name; tmpconfig++)
            if(strncmp(tmpconfig->name, pbuf, pbuf1-pbuf) == 0)
                read_configure(tmpconfig, ++pbuf1);
    }

    fclose(fp);

    iIMIndex = iIMIndex_tmp;        /* piaoairy add 20080518 */

    if(bIsNeedSaveConfig){
        SaveConfig();
        SaveProfile();
     }
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index