emoji: Some work on the conversion tool
Document the variant format, and write out json format if asked to.
This commit is contained in:
committed by
Marco Trevisan (Treviño)
parent
bfad7693bf
commit
cb32ff5b18
@ -18,6 +18,15 @@
|
|||||||
/* Build with gcc -o convert-emoji convert-emoji.c `pkg-config --cflags --libs json-glib-1.0`
|
/* Build with gcc -o convert-emoji convert-emoji.c `pkg-config --cflags --libs json-glib-1.0`
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* The format of the generated data is: a(auss).
|
||||||
|
* Each member of the array has the following fields:
|
||||||
|
* au - sequence of unicode codepoints. If the
|
||||||
|
* sequence contains a 0, it marks the point
|
||||||
|
* where skin tone modifiers should be inserted
|
||||||
|
* s - name, e.g. "man worker"
|
||||||
|
* s - shortname, for completion. This includes
|
||||||
|
* colons to mark the ends, e.g. ":guardsman:"
|
||||||
|
*/
|
||||||
#include <json-glib/json-glib.h>
|
#include <json-glib/json-glib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -70,7 +79,6 @@ main (int argc, char *argv[])
|
|||||||
GVariantBuilder builder;
|
GVariantBuilder builder;
|
||||||
GVariant *v;
|
GVariant *v;
|
||||||
GString *s;
|
GString *s;
|
||||||
GBytes *bytes;
|
|
||||||
GHashTable *names;
|
GHashTable *names;
|
||||||
GString *name_key;
|
GString *name_key;
|
||||||
|
|
||||||
@ -175,11 +183,29 @@ main (int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
v = g_variant_builder_end (&builder);
|
v = g_variant_builder_end (&builder);
|
||||||
bytes = g_variant_get_data_as_bytes (v);
|
if (g_str_has_suffix (argv[3], ".json"))
|
||||||
if (!g_file_set_contents (argv[3], g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes), &error))
|
|
||||||
{
|
{
|
||||||
g_error ("%s", error->message);
|
JsonNode *node;
|
||||||
return 1;
|
char *out;
|
||||||
|
|
||||||
|
node = json_gvariant_serialize (v);
|
||||||
|
out = json_to_string (node, TRUE);
|
||||||
|
if (!g_file_set_contents (argv[3], out, -1, &error))
|
||||||
|
{
|
||||||
|
g_error ("%s", error->message);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GBytes *bytes;
|
||||||
|
|
||||||
|
bytes = g_variant_get_data_as_bytes (v);
|
||||||
|
if (!g_file_set_contents (argv[3], g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes), &error))
|
||||||
|
{
|
||||||
|
g_error ("%s", error->message);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user