Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
ttx2scilab.c
Go to the documentation of this file.
1 
2 
3 
4 #include <glib.h>
5 
6 
7 static void on_start_element(GMarkupParseContext *context,
8  const gchar *element_name,
9  const gchar **attribute_names,
10  const gchar **attribute_values,
11  gpointer user_data,
12  GError **error);
13 static void on_text(GMarkupParseContext *context,
14  const gchar *text,
15  gsize text_len,
16  gpointer user_data,
17  GError **error);
18 static void on_error (GMarkupParseContext *context,
19  GError *error,
20  gpointer user_data);
21 
22 
23 
24 int main (int rgc, char** argv) {
25 
26  GMarkupParser gmp = { on_start_element, NULL, on_text, NULL, on_error};
27  GMarkupParseContext *gmpc = g_markup_parse_context_new(&gmp, 0, NULL, NULL);
28 
29  GError* my_err = NULL;
30  GIOChannel *gioc = g_io_channel_new_file("b_bhi.xml", "r", &my_err);
31 #define BUF_LEN 16384
32  gchar buf[BUF_LEN];
33  gsize bytes_read;
34  GIOStatus st = g_io_channel_read_chars(gioc, buf, BUF_LEN, &bytes_read, &my_err);
35 
36  // g_message("read file %d", bytes_read);
37 
38  if (!g_markup_parse_context_parse(gmpc, buf, bytes_read, &my_err)) {
39  g_message("error parsing xml");
40  return -1;
41  }
42  return 0;
43 }
44 
45 
46 
47 static void on_start_element(GMarkupParseContext *context,
48  const gchar *element_name,
49  const gchar **attribute_names,
50  const gchar **attribute_values,
51  gpointer user_data,
52  GError **error) {
53  // g_message("on start element (%s)", element_name);
54  if (!strcmp(element_name, "pt")) {
55  // g_message("pt ", element_name);
56  int i = 0;
57  while (attribute_names[i]) {
58  // g_message("%s %s", attribute_names[i], attribute_values[i]);
59  printf("%s ", attribute_values[i]);
60  if (!strcmp(attribute_names[i], "on")) printf("\n");
61  i++;
62  }
63  }
64 }
65 
66 static void on_text(GMarkupParseContext *context,
67  const gchar *text,
68  gsize text_len,
69  gpointer user_data,
70  GError **error) {
71  // g_message("on text (%s)", text);
72 
73 
74 }
75 
76 static void on_error (GMarkupParseContext *context,
77  GError *error,
78  gpointer user_data) {
79 
80  // g_message("on error");
81 }
82 
static void on_error(GMarkupParseContext *context, GError *error, gpointer user_data)
Definition: ttx2scilab.c:76
int main(int rgc, char **argv)
Definition: ttx2scilab.c:24
static void on_text(GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer user_data, GError **error)
Definition: ttx2scilab.c:66
#define BUF_LEN
static void on_start_element(GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer user_data, GError **error)
Definition: ttx2scilab.c:47