bool gen_data_config_set_template( gen_data_config_type * config , const char * template_ecl_file , const char * template_data_key ) { char * template_buffer = NULL; bool template_valid = true; int template_buffer_size; if (template_ecl_file) { if (util_file_readable( template_ecl_file )) { template_buffer = util_fread_alloc_file_content( template_ecl_file , &template_buffer_size); if (template_data_key) { if (strstr(template_buffer , template_data_key) == NULL) template_valid = false; } } else template_valid = false; } if (template_valid) { gen_data_config_reset_template(config); if (template_ecl_file != NULL) { char *data_ptr; config->template_buffer = template_buffer; config->template_buffer_size = template_buffer_size; if (template_data_key != NULL) { data_ptr = strstr(config->template_buffer , template_data_key); if (data_ptr == NULL) util_abort("%s: template:%s can not be used - could not find data key:%s \n",__func__ , template_ecl_file , template_data_key); else { config->template_data_offset = data_ptr - config->template_buffer; config->template_data_skip = strlen( template_data_key ); } } else { /* We are using a template without a template_data_key - the data is assumed to come at the end of the template. */ config->template_data_offset = strlen( config->template_buffer ); config->template_data_skip = 0; } config->template_file = util_realloc_string_copy( config->template_file , template_ecl_file ); config->template_key = util_realloc_string_copy( config->template_key , template_data_key ); if (config->output_format != ASCII_TEMPLATE) fprintf(stderr,"**WARNING: The template settings will ignored for key:%s - use OUTPUT_FORMAT:ASCII_TEMPLATE to get template behaviour\n", config->key); } } return template_valid; }
static void config_handle_key_subtag(MBKeyboardConfigState *state, const char *tag, const char **attr) { MBKeyboardKeyStateType keystate; const char *val; KeySym found_keysym; /* TODO: Fix below with a lookup table */ if (streq(tag, "normal") || streq(tag, "default")) { keystate = MBKeyboardKeyStateNormal; } else if (streq(tag, "shifted")) { keystate = MBKeyboardKeyStateShifted; } else if (streq(tag, "mod1")) { keystate = MBKeyboardKeyStateMod1; } else if (streq(tag, "mod2")) { keystate = MBKeyboardKeyStateMod2; } else if (streq(tag, "mod3")) { keystate = MBKeyboardKeyStateMod3; } else { set_error(state, "Unknown key subtag"); return; } if ((val = attr_get_val("display", attr)) == NULL) { set_error(state, "Attribute 'display' is required"); return; } if (!strncmp(val, "image:", 6)) { MBKeyboardImage *img; if (val[6] != '/') { /* Relative, rather than absolute path, try pkddatadir and home */ char buf[512]; snprintf(buf, 512, "%s/%s", PKGDATADIR, &val[6]); if (!util_file_readable(buf)) snprintf(buf, 512, "%s/.matchbox/%s", getenv("HOME"), &val[6]); img = mb_kbd_image_new (state->keyboard, buf); } else img = mb_kbd_image_new (state->keyboard, &val[6]); if (!img) { fprintf(stderr, "matchbox-keyboard: Failed to load '%s'\n", &val[6]); state->error = True; return; } mb_kbd_key_set_image_face(state->current_key, keystate, img); } else { mb_kbd_key_set_glyph_face(state->current_key, keystate, attr_get_val("display", attr)); } if ((val = attr_get_val("action", attr)) != NULL) { /* action="utf8char" // optional, action defulats to this action="modifier:Shift|Alt|ctrl|mod1|mod2|mod3|caps" action="xkeysym:XK_BLAH" action="control:"> // return etc - not needed use lookup */ if (!strncmp(val, "modifier:", 9)) { MBKeyboardKeyModType found_type; DBG("checking '%s'", &val[9]); found_type = config_str_to_modtype(&val[9]); if (found_type) { mb_kbd_key_set_modifer_action(state->current_key, keystate, found_type); } else { set_error(state, "Unknown modifier"); return; } } else if (!strncmp(val, "xkeysym:", 8)) { DBG("Checking %s\n", &val[8]); found_keysym = XStringToKeysym(&val[8]); if (found_keysym) { mb_kbd_key_set_keysym_action(state->current_key, keystate, found_keysym); } else { /* Should this error really be terminal */ set_error(state, "Unknown keysym"); return; } } else { /* Its just 'regular' key */ if (strlen(val) > 1 /* match backspace, return etc */ && ((found_keysym = config_str_to_keysym(val)) != 0)) { mb_kbd_key_set_keysym_action(state->current_key, keystate, found_keysym); } else { /* XXX We should actually check its a single UTF8 Char here */ mb_kbd_key_set_char_action(state->current_key, keystate, val); } } } else /* fallback to reusing whats displayed */ { /* display could be an image in which case we should throw an error * or summin. */ mb_kbd_key_set_char_action(state->current_key, keystate, attr_get_val("display", attr)); } }
static char* config_load_file(MBKeyboard *kbd, char *variant_in) { struct stat stat_info; FILE* fp; char *result; char *country = NULL; char *variant = NULL; char *lang = NULL; int n = 0, i = 0; char path[1024]; /* XXX MAXPATHLEN */ /* keyboard[-country][-variant].xml */ /* This is an overide mainly for people developing keyboard layouts */ if (getenv("MB_KBD_CONFIG")) { snprintf(path, 1024, "%s", getenv("MB_KBD_CONFIG")); DBG("checking %s\n", path); if (util_file_readable(path)) goto load; return NULL; } lang = getenv("MB_KBD_LANG"); if (lang == NULL) lang = getenv("LANG"); if (lang) { n = strlen(lang) + 2; country = alloca(n); snprintf(country, n, "-%s", lang); /* strip anything after first '.' */ while(country[i] != '\0') if (country[i] == '.') country[i] = '\0'; else i++; } if (variant_in) { n = strlen(variant_in) + 2; variant = alloca(n); snprintf(variant, n, "-%s", variant_in); } if (getenv("HOME")) { snprintf(path, 1024, "%s/.matchbox/keyboard.xml", getenv("HOME")); DBG("checking %s\n", path); if (util_file_readable(path)) goto load; } /* Hmmm :/ */ snprintf(path, 1024, PKGDATADIR "/keyboard%s%s.xml", country == NULL ? "" : country, variant == NULL ? "" : variant); DBG("checking %s\n", path); if (util_file_readable(path)) goto load; snprintf(path, 1024, PKGDATADIR "/keyboard%s.xml", variant == NULL ? "" : variant); DBG("checking %s\n", path); if (util_file_readable(path)) goto load; snprintf(path, 1024, PKGDATADIR "/keyboard%s.xml", country == NULL ? "" : country); DBG("checking %s\n", path); if (util_file_readable(path)) goto load; snprintf(path, 1024, PKGDATADIR "/keyboard.xml"); DBG("checking %s\n", path); if (!util_file_readable(path)) return NULL; load: if (stat(path, &stat_info)) return NULL; if ((fp = fopen(path, "rb")) == NULL) return NULL; DBG("loading %s\n", path); kbd->config_file = strdup(path); result = malloc(stat_info.st_size + 1); n = fread(result, 1, stat_info.st_size, fp); if (n >= 0) result[n] = '\0'; fclose(fp); return result; }