*/
/* Prologue {{{1 */
-#define _GNU_SOURCE
#include "config.h"
#include <gstdio.h>
-#include <locale.h>
+#include <gi18n.h>
+
#include <string.h>
-#include <unistd.h>
#include <stdio.h>
+#include <locale.h>
-#include <gi18n.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
#include "gvdb/gvdb-builder.h"
#include "strinfo.c"
const gchar *max_str,
GError **error)
{
+ const struct {
+ const gchar type;
+ const gchar *min;
+ const gchar *max;
+ } table[] = {
+ { 'y', "0", "255" },
+ { 'n', "-32768", "32767" },
+ { 'q', "0", "65535" },
+ { 'i', "-2147483648", "2147483647" },
+ { 'u', "0", "4294967295" },
+ { 'x', "-9223372036854775808", "9223372036854775807" },
+ { 't', "0", "18446744073709551615" },
+ { 'd', "-inf", "inf" },
+ };
+ gboolean type_ok = FALSE;
+ gint i;
+
if (state->minimum)
{
g_set_error_literal (error, G_MARKUP_ERROR,
return;
}
- if (strchr ("ynqiuxtd", *(char *) state->type) == NULL)
+ for (i = 0; i < G_N_ELEMENTS (table); i++)
+ if (*(char *) state->type == table[i].type)
+ {
+ min_str = min_str ? min_str : table[i].min;
+ max_str = max_str ? max_str : table[i].max;
+ type_ok = TRUE;
+ break;
+ }
+
+ if (!type_ok)
{
gchar *type = g_variant_type_dup_string (state->type);
g_set_error (error, G_MARKUP_ERROR,
OPTIONAL | STRING, "gettext-domain", &gettext_domain,
OPTIONAL | STRING, "extends", &extends,
OPTIONAL | STRING, "list-of", &list_of))
- parse_state_start_schema (state, id, path, gettext_domain,
+ parse_state_start_schema (state, id, path,
+ gettext_domain ? gettext_domain
+ : state->schemalist_domain,
extends, list_of, error);
return;
}
else if (strcmp (element_name, "range") == 0)
{
const gchar *min, *max;
- if (COLLECT (STRING, "min", &min, STRING, "max", &max))
+ if (COLLECT (STRING | OPTIONAL, "min", &min,
+ STRING | OPTIONAL, "max", &max))
key_state_set_range (state->key_state, min, max, error);
return;
}
schema_state_end (SchemaState **state_ptr,
GError **error)
{
- SchemaState *state;
-
- state = *state_ptr;
*state_ptr = NULL;
}
typedef struct
{
+ GHashTable *schema_table;
+ GvdbPair root_pair;
+} WriteToFileData;
+
+typedef struct
+{
+ GHashTable *schema_table;
GvdbPair pair;
gboolean l10n;
} OutputSchemaData;
if (state->l10n)
data->l10n = TRUE;
+
+ if (state->child_schema &&
+ !g_hash_table_lookup (data->schema_table, state->child_schema))
+ g_printerr ("warning: undefined reference to <schema id='%s'/>\n",
+ state->child_schema);
}
static void
gpointer value,
gpointer user_data)
{
+ WriteToFileData *wtf_data = user_data;
OutputSchemaData data;
GvdbPair *root_pair;
SchemaState *state;
id = key;
state = value;
- root_pair = user_data;
+ root_pair = &wtf_data->root_pair;
+ data.schema_table = wtf_data->schema_table;
gvdb_pair_init (&data.pair);
data.l10n = FALSE;
const gchar *filename,
GError **error)
{
+ WriteToFileData data;
gboolean success;
- GvdbPair pair;
- gvdb_pair_init (&pair);
+ data.schema_table = schema_table;
+
+ gvdb_pair_init (&data.root_pair);
- g_hash_table_foreach (schema_table, output_schema, &pair);
+ g_hash_table_foreach (schema_table, output_schema, &data);
- success = gvdb_table_write_contents (pair.table, filename,
+ success = gvdb_table_write_contents (data.root_pair.table, filename,
G_BYTE_ORDER != G_LITTLE_ENDIAN,
error);
- g_hash_table_unref (pair.table);
+ g_hash_table_unref (data.root_pair.table);
return success;
}
{ NULL }
};
+#ifdef G_OS_WIN32
+ extern gchar *_glib_get_locale_dir (void);
+ gchar *tmp;
+#endif
+
setlocale (LC_ALL, "");
+ textdomain (GETTEXT_PACKAGE);
+
+#ifdef G_OS_WIN32
+ tmp = _glib_get_locale_dir ();
+ bindtextdomain (GETTEXT_PACKAGE, tmp);
+ g_free (tmp);
+#else
+ bindtextdomain (GETTEXT_PACKAGE, GLIB_LOCALE_DIR);
+#endif
+
+#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+#endif
context = g_option_context_new (N_("DIRECTORY"));
g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
if (files->len == 0)
{
- fprintf (stderr, _("No schema files found: "));
+ fprintf (stdout, _("No schema files found: "));
if (g_unlink (target))
- fprintf (stderr, _("doing nothing.\n"));
+ fprintf (stdout, _("doing nothing.\n"));
else
- fprintf (stderr, _("removed existing output file.\n"));
+ fprintf (stdout, _("removed existing output file.\n"));
return 0;
}