/* Copyright (C) 2011 ABRT Team Copyright (C) 2011 RedHat inc. 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "abrtlib.h" #include "event_config.h" #define EVENT_ELEMENT "event" #define LABEL_ELEMENT "label" #define DESCRIPTION_ELEMENT "description" #define LONG_DESCR_ELEMENT "long-description" #define ALLOW_EMPTY_ELEMENT "allow-empty" #define NOTE_HTML_ELEMENT "note-html" #define OPTION_ELEMENT "option" //#define ACTION_ELEMENT "action" #define NAME_ELEMENT "name" #define DEFAULT_VALUE_ELEMENT "default-value" struct my_parse_data { event_config_t *event_config; event_option_t *cur_option; const char *cur_locale; char *attribute_lang; }; static const char *const option_types[] = { [OPTION_TYPE_TEXT ] = "text", [OPTION_TYPE_BOOL ] = "bool", [OPTION_TYPE_PASSWORD ] = "password", [OPTION_TYPE_NUMBER ] = "number", [OPTION_TYPE_HINT_HTML] = "hint-html", [OPTION_TYPE_INVALID ] = NULL }; // Return xml:lang value for if value matches current locale, // "" if foo has no xml:lang attribute at all, // else (if xml:lang is for some other locale) return NULL // static char *get_element_lang(struct my_parse_data *parse_data, const gchar **att_names, const gchar **att_values) { char *short_locale_end = strchr(parse_data->cur_locale, '_'); VERB2 log("locale: %s", parse_data->cur_locale); int i; for (i = 0; att_names[i] != NULL; ++i) { VERB2 log("attr: %s:%s", att_names[i], att_values[i]); if (strcmp(att_names[i], "xml:lang") == 0) { if (strcmp(att_values[i], parse_data->cur_locale) == 0) { VERB2 log("found translation for: %s", parse_data->cur_locale); return xstrdup(att_values[i]); } /* try to match shorter locale * e.g: "cs" with cs_CZ */ if (short_locale_end && strncmp(att_values[i], parse_data->cur_locale, short_locale_end - parse_data->cur_locale) == 0 ) { VERB2 log("found translation for shortlocale: %s", parse_data->cur_locale); return xstrndup(att_values[i], short_locale_end - parse_data->cur_locale); } } } /* if the element has no attribute then it's a default non-localized value */ if (i == 0) return xstrdup(""); /* if the element is in different language than the current locale */ return NULL; } static int cmp_event_option_name_with_string(gconstpointer a, gconstpointer b) { const event_option_t *evopt = a; /* "When it is not a match?" */ return !evopt->eo_name || strcmp(evopt->eo_name, (char *)b) != 0; } static void consume_cur_option(struct my_parse_data *parse_data) { event_option_t *opt = parse_data->cur_option; if (!opt) return; parse_data->cur_option = NULL; event_config_t *event_config = parse_data->event_config; /* Example of "nameless" option: