예제 #1
0
static void
FcitxNotifyLoadDConfig(FcitxNotify *notify)
{
    FILE *fp;
    fcitx_string_map_clear(notify->hide_notify);
    fp = FcitxXDGGetFileUserWithPrefix("conf", "fcitx-notify.config",
                                       "r", NULL);
    if (fp) {
        if (fcitx_desktop_file_load_fp(&notify->dconfig, fp)) {
            FcitxDesktopGroup *grp;
            grp = fcitx_desktop_file_ensure_group(&notify->dconfig,
                                                  "Notify/Notify");
            FcitxDesktopEntry *ety;
            ety = fcitx_desktop_group_ensure_entry(grp, "HiddenNotify");
            if (ety->value) {
                fcitx_string_map_from_string(notify->hide_notify,
                                             ety->value, ';');
            }
        }
        fclose(fp);
    }
}
예제 #2
0
static int
fxaddon_scan_addon(FILE *ifp, FILE *ofp)
{
    FcitxDesktopFile dfile;
    char *buff = NULL;
    unsigned int i;
    char **p;
    if (!fcitx_desktop_file_init(&dfile, NULL, NULL))
        return 1;
    if (!fcitx_desktop_file_load_fp(&dfile, ifp))
        return 1;
    fclose(ifp);
    FcitxDesktopGroup *addon_grp;
    FcitxDesktopEntry *tmp_ety;
    addon_grp = fcitx_desktop_file_find_group(&dfile, "FcitxAddon");
    if (!addon_grp)
        return 1;
    tmp_ety = fcitx_desktop_group_find_entry(addon_grp, "Name");
    if (!tmp_ety)
        return 1;
    const char *name = tmp_ety->value;
    tmp_ety = fcitx_desktop_group_find_entry(addon_grp, "Prefix");
    if (!tmp_ety)
        return 1;
    const char *prefix = tmp_ety->value;
    UT_array macros;
    fxaddon_load_numbered_entries(&macros, addon_grp, "Macro", false);
    UT_array includes;
    fxaddon_load_numbered_entries(&includes, addon_grp, "Include", false);
    UT_array functions;
    fxaddon_load_numbered_entries(&functions, addon_grp, "Function", true);
    fxaddon_write_copyright(ofp);
    size_t name_len = strlen(name);
    buff = fcitx_utils_set_str_with_len(buff, name, name_len);
    fxaddon_name_to_macro(buff);
    _write_str(ofp, "\n#ifndef __FCITX_MODULE_");
    _write_len(ofp, buff, name_len);
    _write_str(ofp, "_H\n");
    _write_str(ofp, "#define __FCITX_MODULE_");
    _write_len(ofp, buff, name_len);
    _write_str(ofp, "_H\n"
                    "\n"
                    "#ifdef __cplusplus\n"
                    "extern \"C\" {\n"
                    "#endif\n"
                    "\n");
    for (i = 0;i < utarray_len(&macros);i++) {
        p = (char**)_utarray_eltptr(&macros, i);
        fxaddon_write_macro(ofp, &dfile, *p);
    }
    fxaddon_write_includes(ofp, &includes);
    utarray_done(&includes);
    _write_str(ofp, "DEFINE_GET_ADDON(\"");
    _write_len(ofp, name, name_len);
    _write_str(ofp, "\", ");
    _write_str(ofp, prefix);
    _write_str(ofp, ")\n\n");
    for (i = 0;i < utarray_len(&functions);i++) {
        p = (char**)_utarray_eltptr(&functions, i);
        fxaddon_write_function(ofp, &dfile, prefix, *p, i);
    }
    _write_str(ofp, "\n"
                    "#ifdef __cplusplus\n"
                    "}\n"
                    "#endif\n"
                    "\n"
                    "#endif\n");
    fclose(ofp);
    fcitx_utils_free(buff);
    fcitx_desktop_file_done(&dfile);
    utarray_done(&functions);
    return 0;
}