src/genx-glib.c (3983B) - raw
1 /* 2 * http://www.djc.id.au/blog/genx-vala 3 * Released into the public domain 4 */ 5 6 #include <glib.h> 7 #include <genx.h> 8 9 G_STATIC_ASSERT(sizeof(char) == sizeof(gchar)); 10 11 genxNamespace genx_writer_declare_namespace(genxWriter w, const char *uri, const char *prefix) { 12 genxStatus status; 13 genxNamespace retval = genxDeclareNamespace(w, (constUtf8) uri, (constUtf8) prefix, &status); 14 g_return_val_if_fail(status == GENX_SUCCESS, NULL); 15 return retval; 16 } 17 18 genxElement genx_writer_declare_element(genxWriter w, genxNamespace ns, const char *type) { 19 genxStatus status; 20 genxElement retval = genxDeclareElement(w, ns, (constUtf8) type, &status); 21 g_return_val_if_fail(status == GENX_SUCCESS, NULL); 22 return retval; 23 } 24 25 genxAttribute genx_writer_declare_attribute(genxWriter w, genxNamespace ns, const char *name) { 26 genxStatus status; 27 genxAttribute retval = genxDeclareAttribute(w, ns, (constUtf8) name, &status); 28 g_return_val_if_fail(status == GENX_SUCCESS, NULL); 29 return retval; 30 } 31 32 static genxStatus _genx_send_gstring(void *userData, constUtf8 s) { 33 g_string_append((GString *)userData, (const gchar *)s); 34 return GENX_SUCCESS; 35 } 36 37 static genxStatus _genx_sendBounded_gstring(void *userData, constUtf8 start, constUtf8 end) { 38 g_string_append_len((GString *)userData, (const gchar *)start, (gssize) (end - start)); 39 return GENX_SUCCESS; 40 } 41 42 static genxStatus _genx_flush_gstring(void *userData) { 43 return GENX_SUCCESS; 44 } 45 46 static genxSender _genx_sender_gstring = { 47 _genx_send_gstring, 48 _genx_sendBounded_gstring, 49 _genx_flush_gstring 50 }; 51 52 void genx_writer_start_doc_gstring(genxWriter w, GString *gs) { 53 // XXX bad, we should hold a proper ref to gs here 54 genxSetUserData(w, (void *)gs); 55 genxStatus status = genxStartDocSender(w, &_genx_sender_gstring); 56 g_return_if_fail(status == GENX_SUCCESS); 57 } 58 59 void genx_writer_end_document(genxWriter w) { 60 genxStatus status = genxEndDocument(w); 61 g_return_if_fail(status == GENX_SUCCESS); 62 } 63 64 void genx_writer_comment(genxWriter w, const char *text) { 65 genxStatus status = genxComment(w, (constUtf8) text); 66 g_return_if_fail(status == GENX_SUCCESS); 67 } 68 69 void genx_writer_pi(genxWriter w, const char *target, const char *text) { 70 genxStatus status = genxPI(w, (constUtf8) target, (constUtf8) text); 71 g_return_if_fail(status == GENX_SUCCESS); 72 } 73 74 void genx_writer_start_element_literal(genxWriter w, const char *xmlns, const char *type) { 75 genxStatus status = genxStartElementLiteral(w, (constUtf8) xmlns, (constUtf8) type); 76 g_return_if_fail(status == GENX_SUCCESS); 77 } 78 79 void genx_element_start(genxElement e) { 80 genxStatus status = genxStartElement(e); 81 g_return_if_fail(status == GENX_SUCCESS); 82 } 83 84 void genx_writer_add_attribute_literal(genxWriter w, const char *xmlns, 85 const char *name, const char *value) { 86 genxStatus status = genxAddAttributeLiteral(w, 87 (constUtf8) xmlns, (constUtf8) name, (constUtf8) value); 88 g_return_if_fail(status == GENX_SUCCESS); 89 } 90 91 void genx_attribute_add(genxAttribute a, const char *value) { 92 genxStatus status = genxAddAttribute(a, (constUtf8) value); 93 g_return_if_fail(status == GENX_SUCCESS); 94 } 95 96 void genx_namespace_add(genxNamespace ns, char *prefix) { 97 genxStatus status = genxAddNamespace(ns, (utf8) prefix); 98 g_return_if_fail(status == GENX_SUCCESS); 99 } 100 101 void genx_writer_unset_default_namespace(genxWriter w) { 102 genxStatus status = genxUnsetDefaultNamespace(w); 103 g_return_if_fail(status == GENX_SUCCESS); 104 } 105 106 void genx_writer_end_element(genxWriter w) { 107 genxStatus status = genxEndElement(w); 108 g_return_if_fail(status == GENX_SUCCESS); 109 } 110 111 void genx_writer_add_text(genxWriter w, const char *start) { 112 genxStatus status = genxAddText(w, (constUtf8) start); 113 g_return_if_fail(status == GENX_SUCCESS); 114 } 115 116 void genx_writer_add_character(genxWriter w, int c) { 117 genxStatus status = genxAddCharacter(w, c); 118 g_return_if_fail(status == GENX_SUCCESS); 119 }