1 | #include <gtk/gtk.h> |
2 | #include "gtk/gtkcomposetable.h" |
3 | #include <locale.h> |
4 | #include <stdlib.h> |
5 | |
6 | /* This program reads a Compose file and generates files with sequences, |
7 | * character data, and definitions for the builtin compose table of GTK. |
8 | * Run it like this: |
9 | * |
10 | * cpp -DXCOMM='#' Compose.pre | sed -e 's/^ *#/#/' > Compose |
11 | * compose-parse Compose sequences-little-endian sequences-big-endian chars gtkcomposedata.h |
12 | * |
13 | * The GTK build expects the output files to be in the source tree, in |
14 | * the gtk/compose directory. |
15 | */ |
16 | int |
17 | main (int argc, char *argv[]) |
18 | { |
19 | const guint16 *sequences_le; |
20 | const guint16 *sequences_be; |
21 | guint16 *other_sequences; |
22 | GtkComposeTable *table; |
23 | GError *error = NULL; |
24 | GString *str; |
25 | gsize i; |
26 | |
27 | setlocale (LC_ALL, locale: "" ); |
28 | |
29 | if (argc < 5) |
30 | { |
31 | g_print (format: "Usage: compose-parse INPUT SEQUENCES-LE SEQUENCES-BE CHARS HEADER\n" ); |
32 | exit (status: 1); |
33 | } |
34 | |
35 | table = gtk_compose_table_parse (compose_file: argv[1], NULL); |
36 | if (!table) |
37 | g_error ("Failed to parse %s" , argv[1]); |
38 | |
39 | #if G_BYTE_ORDER == G_BIG_ENDIAN |
40 | sequences_le = other_sequences = g_new0 (guint16, table->data_size); |
41 | sequences_be = (const guint16 *) table->data; |
42 | #else |
43 | sequences_le = (const guint16 *) table->data; |
44 | sequences_be = other_sequences = g_new0 (guint16, table->data_size); |
45 | #endif |
46 | |
47 | for (i = 0; i < table->data_size; i++) |
48 | other_sequences[i] = GUINT16_SWAP_LE_BE (table->data[i]); |
49 | |
50 | /* data_size is the size in guint16 */ |
51 | if (!g_file_set_contents (filename: argv[2], contents: (char *) sequences_le, length: 2 * table->data_size, error: &error)) |
52 | g_error ("%s" , error->message); |
53 | |
54 | /* data_size is the size in guint16 */ |
55 | if (!g_file_set_contents (filename: argv[3], contents: (char *) sequences_be, length: 2 * table->data_size, error: &error)) |
56 | g_error ("%s" , error->message); |
57 | |
58 | if (!g_file_set_contents (filename: argv[4], contents: table->char_data, length: table->n_chars + 1, error: &error)) |
59 | g_error ("%s" , error->message); |
60 | |
61 | str = g_string_new (init: "" ); |
62 | g_string_append (string: str, |
63 | val: "#ifndef __GTK_COMPOSE_DATA__\n" |
64 | "#define __GTK_COMPOSE_DATA__\n" |
65 | "\n" ); |
66 | g_string_append_printf (string: str, |
67 | format: "#define MAX_SEQ_LEN %d\n" , table->max_seq_len); |
68 | g_string_append_printf (string: str, |
69 | format: "#define N_INDEX_SIZE %d\n" , table->n_index_size); |
70 | g_string_append_printf (string: str, |
71 | format: "#define DATA_SIZE %d\n" , table->data_size); |
72 | g_string_append_printf (string: str, |
73 | format: "#define N_CHARS %d\n" , table->n_chars); |
74 | g_string_append (string: str, |
75 | val: "\n" |
76 | "#endif\n" ); |
77 | |
78 | if (!g_file_set_contents (filename: argv[5], contents: str->str, length: str->len, error: &error)) |
79 | g_error ("%s" , error->message); |
80 | |
81 | g_string_free (string: str, TRUE); |
82 | g_free (mem: other_sequences); |
83 | |
84 | return 0; |
85 | } |
86 | |