2021-07-08 21:59:50 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include "gtk/gtkcomposetable.h"
|
|
|
|
#include <locale.h>
|
2021-07-28 07:10:37 +00:00
|
|
|
#include <stdlib.h>
|
2021-07-08 21:59:50 +00:00
|
|
|
|
|
|
|
/* This program reads a Compose file and generates files with sequences,
|
|
|
|
* character data, and definitions for the builtin compose table of GTK.
|
|
|
|
* Run it like this:
|
|
|
|
*
|
2021-08-30 09:48:49 +00:00
|
|
|
* cpp -DXCOMM='#' Compose.pre | sed -e 's/^ *#/#/' > Compose
|
2021-08-30 09:13:33 +00:00
|
|
|
* compose-parse Compose sequences-little-endian sequences-big-endian chars gtkcomposedata.h
|
2021-07-08 21:59:50 +00:00
|
|
|
*
|
|
|
|
* The GTK build expects the output files to be in the source tree, in
|
|
|
|
* the gtk/compose directory.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2021-08-30 09:13:33 +00:00
|
|
|
const guint16 *sequences_le;
|
|
|
|
const guint16 *sequences_be;
|
|
|
|
guint16 *other_sequences;
|
2021-07-08 21:59:50 +00:00
|
|
|
GtkComposeTable *table;
|
|
|
|
GError *error = NULL;
|
|
|
|
GString *str;
|
2021-08-30 09:13:33 +00:00
|
|
|
gsize i;
|
2021-07-08 21:59:50 +00:00
|
|
|
|
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
|
|
|
|
if (argc < 5)
|
|
|
|
{
|
2021-08-30 09:13:33 +00:00
|
|
|
g_print ("Usage: compose-parse INPUT SEQUENCES-LE SEQUENCES-BE CHARS HEADER\n");
|
2021-07-08 21:59:50 +00:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2021-07-14 11:38:32 +00:00
|
|
|
table = gtk_compose_table_parse (argv[1], NULL);
|
2021-07-08 21:59:50 +00:00
|
|
|
if (!table)
|
|
|
|
g_error ("Failed to parse %s", argv[1]);
|
|
|
|
|
2021-08-30 09:13:33 +00:00
|
|
|
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
|
|
|
sequences_le = other_sequences = g_new0 (guint16, table->data_size);
|
|
|
|
sequences_be = (const guint16 *) table->data;
|
|
|
|
#else
|
|
|
|
sequences_le = (const guint16 *) table->data;
|
|
|
|
sequences_be = other_sequences = g_new0 (guint16, table->data_size);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (i = 0; i < table->data_size; i++)
|
|
|
|
other_sequences[i] = GUINT16_SWAP_LE_BE (table->data[i]);
|
|
|
|
|
|
|
|
/* data_size is the size in guint16 */
|
|
|
|
if (!g_file_set_contents (argv[2], (char *) sequences_le, 2 * table->data_size, &error))
|
|
|
|
g_error ("%s", error->message);
|
|
|
|
|
2021-07-08 21:59:50 +00:00
|
|
|
/* data_size is the size in guint16 */
|
2021-08-30 09:13:33 +00:00
|
|
|
if (!g_file_set_contents (argv[3], (char *) sequences_be, 2 * table->data_size, &error))
|
2021-07-08 21:59:50 +00:00
|
|
|
g_error ("%s", error->message);
|
|
|
|
|
2021-08-30 09:13:33 +00:00
|
|
|
if (!g_file_set_contents (argv[4], table->char_data, table->n_chars + 1, &error))
|
2021-07-08 21:59:50 +00:00
|
|
|
g_error ("%s", error->message);
|
|
|
|
|
|
|
|
str = g_string_new ("");
|
|
|
|
g_string_append (str,
|
|
|
|
"#ifndef __GTK_COMPOSE_DATA__\n"
|
|
|
|
"#define __GTK_COMPOSE_DATA__\n"
|
|
|
|
"\n");
|
|
|
|
g_string_append_printf (str,
|
|
|
|
"#define MAX_SEQ_LEN %d\n", table->max_seq_len);
|
|
|
|
g_string_append_printf (str,
|
|
|
|
"#define N_INDEX_SIZE %d\n", table->n_index_size);
|
|
|
|
g_string_append_printf (str,
|
|
|
|
"#define DATA_SIZE %d\n", table->data_size);
|
|
|
|
g_string_append_printf (str,
|
|
|
|
"#define N_CHARS %d\n", table->n_chars);
|
|
|
|
g_string_append (str,
|
|
|
|
"\n"
|
|
|
|
"#endif\n");
|
|
|
|
|
2021-08-30 09:13:33 +00:00
|
|
|
if (!g_file_set_contents (argv[5], str->str, str->len, &error))
|
2021-07-08 21:59:50 +00:00
|
|
|
g_error ("%s", error->message);
|
|
|
|
|
|
|
|
g_string_free (str, TRUE);
|
2021-08-30 09:13:33 +00:00
|
|
|
g_free (other_sequences);
|
2021-07-08 21:59:50 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|