8 #define ROOTNODE "/PropertyList/generic"
11 #define PRINT_ERROR_AND_EXIT(id) \
12 if (xmlErrorGetNo(id, 0) != XML_NO_ERROR) { \
13 const char *errstr = xmlErrorGetString(id, 0); \
14 size_t column = xmlErrorGetColumnNo(id, 0); \
15 size_t lineno = xmlErrorGetLineNo(id, 1); \
16 printf("Error at line %i, column %i: %s\n", lineno, column, errstr); \
20 void print_binary_protocol(void *, char *, char *);
22 int main(int argc, char **argv)
24 void *root_id, *protocol_id = 0;
29 printf("Usage: %s <filename>\n", argv[0]);
34 root_id = xmlOpen(filename);
35 if (root_id) protocol_id = xmlNodeGet(root_id, ROOTNODE);
41 dir_id = xmlNodeGet(protocol_id, "input");
44 if (!xmlNodeCompareString(dir_id, "binary_mode", "true")) {
45 print_binary_protocol(dir_id, filename, "input");
47 printf("Only binary mode support is implemented at the moment.\n");
52 dir_id = xmlNodeGet(protocol_id, "output");
55 if (!xmlNodeCompareString(dir_id, "binary_mode", "true")) {
56 print_binary_protocol(dir_id, filename, "output");
58 printf("Only binary mode support is implemented at the moment.\n");
74 /* -------------------------------------------------------------------------- */
76 void print_binary_protocol(void *id, char *filename, char *dir)
78 unsigned int i, num, pos = 0;
81 printf("\n%s\n", filename);
82 printf("Generic binary %s protocol packet description:\n\n", dir);
83 printf(" pos | size | type | factor | description\n");
84 printf("-----|------|--------|------------|------------------------\n");
86 num = xmlNodeGetNum(xid, "chunk");
89 if (xmlNodeGetPos(id, xid, "chunk", i) != 0)
95 type = xmlNodeGetString(xid, "type");
96 if (!strcasecmp(type, "bool")) {
98 } else if (!strcasecmp(type, "float")) {
100 } else if (!strcasecmp(type, "double")) {
102 } else if (!strcasecmp(type, "int")) {
105 printf("Unsupported type sepcified: '%s'\n\n", type);
111 xmlNodeCopyString(xid, "factor", (char *)&factor, 10);
112 name = xmlNodeGetString(xid, "name");
114 printf("%4i | %4i | %6s | %10s | %s\n", pos, size, type, factor, name);
122 printf("\ntotal package size: %i bytes\n\n", pos);