git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4233 818b1a75-f10b-46b9-bf7c-635c3b92a50f
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
AM_CFLAGS = \
|
||||
@ADD_CFLAGS@ \
|
||||
-I$(top_srcdir) \
|
||||
-I$(top_srcdir)/libbuffers \
|
||||
-I$(top_srcdir)/libui
|
||||
|
||||
noinst_LTLIBRARIES = libparser.la
|
||||
|
||||
libparser_la_LDFLAGS = -all-static
|
||||
libparser_la_SOURCES = \
|
||||
xml_parse.c \
|
||||
array_type.c array_type.h \
|
||||
enum_type.c enum_type.h \
|
||||
enum_value_type.c enum_value_type.h \
|
||||
file_type.c file_type.h \
|
||||
field_type.c field_type.h \
|
||||
fundamental_type.c fundamental_type.h \
|
||||
pointer_type.h pointer_type.c \
|
||||
reference_type.c reference_type.h \
|
||||
struct_type.c struct_type.h \
|
||||
typedef_type.c typedef_type.h \
|
||||
types.h types.c \
|
||||
union_type.c union_type.h
|
||||
@@ -0,0 +1,113 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "array_type.h"
|
||||
#include "fundamental_type.h"
|
||||
#include "ui_interface.h"
|
||||
|
||||
int array_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset,
|
||||
int indent) {
|
||||
struct types_s *type_child;
|
||||
|
||||
DISPLAY_PARSE_INFO("array", type->name, offset, parent_offset);
|
||||
|
||||
/* Ignore TYPEDEF children */
|
||||
for (type_child = type->child; type_child != NULL && type_child->type == TYPE_TYPEDEF;
|
||||
type_child = type_child->child) {
|
||||
}
|
||||
|
||||
if (type->name) {
|
||||
INDENTED(stdout, indent, fprintf(stdout, "<%s>\n", type->name));
|
||||
}
|
||||
if (type->child != NULL) {
|
||||
int items = type->size / type_child->size;
|
||||
int i;
|
||||
int zero_counter = 0;
|
||||
|
||||
/* Factorizes trailing 0 */
|
||||
if ((items > 1) && (type_child->type == TYPE_FUNDAMENTAL))
|
||||
{
|
||||
for (i = items - 1; i >= 0; i--)
|
||||
{
|
||||
if (fundamental_read_from_buffer(type_child, buffer, parent_offset, offset + i * type_child->size) == 0)
|
||||
{
|
||||
zero_counter ++;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Do not factorize if there is only one item */
|
||||
if (zero_counter <= 1)
|
||||
{
|
||||
zero_counter = 0;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < (items - zero_counter); i++)
|
||||
type->child->type_dissect_from_buffer (type->child, buffer, parent_offset, offset + i * type_child->size,
|
||||
type->name == NULL ? indent : indent + 4);
|
||||
if (zero_counter > 0)
|
||||
{
|
||||
int length = 0;
|
||||
char cbuf[50];
|
||||
char *cpy = NULL;
|
||||
|
||||
INDENTED_STRING(cbuf, type->name == NULL ? indent : indent + 4,);
|
||||
|
||||
length = sprintf(cbuf, "[%d .. %d] ", i, items -1);
|
||||
cpy = malloc(sizeof(char) * length);
|
||||
memcpy(cpy, cbuf, length);
|
||||
ui_interface.ui_signal_set_text(cpy, length);
|
||||
if (cpy)
|
||||
free(cpy);
|
||||
|
||||
type->child->type_dissect_from_buffer (type->child, buffer, parent_offset, offset + i * type_child->size, 0);
|
||||
}
|
||||
}
|
||||
if (type->name) {
|
||||
INDENTED(stdout, indent, fprintf(stdout, "</%s>\n", type->name));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int array_type_file_print(struct types_s *type, int indent, FILE *file) {
|
||||
if (type == NULL)
|
||||
return -1;
|
||||
INDENTED(file, indent, fprintf(file, "<Array>\n"));
|
||||
INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id));
|
||||
INDENTED(file, indent+4, fprintf(file, "Min ........: %d\n", type->min));
|
||||
INDENTED(file, indent+4, fprintf(file, "Max ........: %d\n", type->max));
|
||||
INDENTED(file, indent+4, fprintf(file, "Type .......: %d\n", type->type_xml));
|
||||
INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size));
|
||||
INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align));
|
||||
if (type->file_ref != NULL)
|
||||
type->file_ref->type_file_print (type->file_ref, indent + 4, file);
|
||||
if (type->child != NULL)
|
||||
type->child->type_file_print (type->child, indent + 4, file);
|
||||
INDENTED(file, indent, fprintf(file, "</Array>\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int array_type_hr_display(struct types_s *type, int indent) {
|
||||
if (type == NULL)
|
||||
return -1;
|
||||
INDENTED(stdout, indent, printf("<Array>\n"));
|
||||
INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id));
|
||||
INDENTED(stdout, indent+4, printf("Min ........: %d\n", type->min));
|
||||
INDENTED(stdout, indent+4, printf("Max ........: %d\n", type->max));
|
||||
INDENTED(stdout, indent+4, printf("Type .......: %d\n", type->type_xml));
|
||||
INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size));
|
||||
INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align));
|
||||
if (type->file_ref != NULL)
|
||||
type->file_ref->type_hr_display (type->file_ref, indent + 4);
|
||||
if (type->child != NULL)
|
||||
type->child->type_hr_display (type->child, indent + 4);
|
||||
INDENTED(stdout, indent, printf("</Array>\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#include "types.h"
|
||||
|
||||
#ifndef ARRAY_TYPE_H_
|
||||
#define ARRAY_TYPE_H_
|
||||
|
||||
int array_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
|
||||
uint32_t offset, uint32_t parent_offset, int indent);
|
||||
|
||||
int array_type_hr_display(struct types_s *type, int indent);
|
||||
|
||||
int array_type_file_print(struct types_s *type, int indent, FILE *file);
|
||||
|
||||
#endif /* ARRAY_TYPE_H_ */
|
||||
@@ -0,0 +1,97 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "enum_type.h"
|
||||
#include "ui_interface.h"
|
||||
|
||||
int enum_type_dissect_from_buffer(
|
||||
struct types_s *type, buffer_t *buffer, uint32_t offset,
|
||||
uint32_t parent_offset, int indent)
|
||||
{
|
||||
uint32_t value = 0;
|
||||
types_t *values;
|
||||
|
||||
DISPLAY_PARSE_INFO("enum", type->name, offset, parent_offset);
|
||||
|
||||
value = buffer_get_uint32_t(buffer, parent_offset + offset);
|
||||
|
||||
// if (type->name) {
|
||||
// INDENTED(stdout, indent, fprintf(stdout, "<%s>\n", type->name));
|
||||
// }
|
||||
for (values = type->child; values; values = values->next) {
|
||||
if (value == values->init_value) {
|
||||
values->type_dissect_from_buffer(
|
||||
values, buffer, offset, parent_offset,
|
||||
type->name == NULL ? indent: indent+4);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (values == NULL) {
|
||||
// INDENTED(stdout, indent+4, fprintf(stdout, "<UNKNOWN/>\n"));
|
||||
int length = 0;
|
||||
char cbuf[50];
|
||||
char *cpy = NULL;
|
||||
|
||||
length = sprintf(cbuf, "(0x%08x) UNKNOWN;\n", value);
|
||||
cpy = malloc(sizeof(char) * length);
|
||||
memcpy(cpy, cbuf, length);
|
||||
ui_interface.ui_signal_set_text(cpy, length);
|
||||
if (cpy)
|
||||
free(cpy);
|
||||
}
|
||||
// if (type->name) {
|
||||
// INDENTED(stdout, indent, fprintf(stdout, "</%s>\n", type->name));
|
||||
// }
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int enum_type_file_print(struct types_s *type, int indent, FILE *file)
|
||||
{
|
||||
types_t *values;
|
||||
|
||||
if (type == NULL)
|
||||
return -1;
|
||||
INDENTED(file, indent, fprintf(file, "<Enumeration>\n"));
|
||||
INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name));
|
||||
INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size));
|
||||
INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align));
|
||||
INDENTED(file, indent+4, fprintf(file, "Artificial .: %d\n", type->artificial));
|
||||
INDENTED(file, indent+4, fprintf(file, "File .......: %s\n", type->file));
|
||||
INDENTED(file, indent+4, fprintf(file, "Line .......: %d\n", type->line));
|
||||
if (type->file_ref != NULL)
|
||||
type->file_ref->type_file_print(type->file_ref, indent+4, file);
|
||||
/* Call enum values display */
|
||||
for (values = type->child; values; values = values->next) {
|
||||
values->type_file_print(values, indent + 4, file);
|
||||
}
|
||||
INDENTED(file, indent, fprintf(file, "</Enumeration>\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int enum_type_hr_display(struct types_s *type, int indent)
|
||||
{
|
||||
types_t *values;
|
||||
|
||||
if (type == NULL)
|
||||
return -1;
|
||||
INDENTED(stdout, indent, printf("<Enumeration>\n"));
|
||||
INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name));
|
||||
INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size));
|
||||
INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align));
|
||||
INDENTED(stdout, indent+4, printf("Artificial .: %d\n", type->artificial));
|
||||
INDENTED(stdout, indent+4, printf("File .......: %s\n", type->file));
|
||||
INDENTED(stdout, indent+4, printf("Line .......: %d\n", type->line));
|
||||
if (type->file_ref != NULL)
|
||||
type->file_ref->type_hr_display(type->file_ref, indent+4);
|
||||
/* Call enum values display */
|
||||
for (values = type->child; values; values = values->next) {
|
||||
values->type_hr_display(values, indent + 4);
|
||||
}
|
||||
INDENTED(stdout, indent, printf("</Enumeration>\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#include "types.h"
|
||||
|
||||
#ifndef ENUM_TYPE_H_
|
||||
#define ENUM_TYPE_H_
|
||||
|
||||
int enum_type_dissect_from_buffer(
|
||||
struct types_s *type, buffer_t *buffer, uint32_t offset,
|
||||
uint32_t parent_offset, int indent);
|
||||
|
||||
int enum_type_file_print(struct types_s *type, int indent, FILE *file);
|
||||
|
||||
int enum_type_hr_display(struct types_s *type, int indent);
|
||||
|
||||
#endif /* ENUM_TYPE_H_ */
|
||||
@@ -0,0 +1,61 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "enum_value_type.h"
|
||||
#include "ui_interface.h"
|
||||
|
||||
int enum_value_dissect_from_buffer(
|
||||
struct types_s *type, buffer_t *buffer, uint32_t offset,
|
||||
uint32_t parent_offset, int indent)
|
||||
{
|
||||
uint32_t value = 0;
|
||||
|
||||
DISPLAY_PARSE_INFO("enum_value", type->name, offset, parent_offset);
|
||||
|
||||
value = buffer_get_uint32_t(buffer, parent_offset + offset);
|
||||
if (type->name) {
|
||||
int length = 0;
|
||||
char cbuf[50 + strlen(type->name)];
|
||||
char *cpy = NULL;
|
||||
|
||||
sprintf(cbuf, "(0x%08x) %s;\n", value, type->name);
|
||||
length = strlen(cbuf);
|
||||
cpy = malloc(sizeof(char) * length);
|
||||
memcpy(cpy, cbuf, length);
|
||||
ui_interface.ui_signal_set_text(cpy, length);
|
||||
if (cpy)
|
||||
free(cpy);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int enum_value_file_print(struct types_s *type, int indent, FILE *file)
|
||||
{
|
||||
if (type == NULL)
|
||||
return -1;
|
||||
INDENTED(file, indent, fprintf(file, "<Value>\n"));
|
||||
INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name));
|
||||
INDENTED(file, indent+4, fprintf(file, "Value ......: %d\n", type->init_value));
|
||||
if (type->file_ref != NULL)
|
||||
type->file_ref->type_file_print(type->file_ref, indent+4, file);
|
||||
INDENTED(file, indent, fprintf(file, "</Value>\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int enum_value_type_hr_display(struct types_s *type, int indent)
|
||||
{
|
||||
if (type == NULL)
|
||||
return -1;
|
||||
INDENTED(stdout, indent, printf("<Value>\n"));
|
||||
INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name));
|
||||
INDENTED(stdout, indent+4, printf("Value ......: %d\n", type->init_value));
|
||||
if (type->file_ref != NULL)
|
||||
type->file_ref->type_hr_display(type->file_ref, indent+4);
|
||||
INDENTED(stdout, indent, printf("</Value>\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#include "types.h"
|
||||
|
||||
#ifndef ENUM_VALUE_TYPE_H_
|
||||
#define ENUM_VALUE_TYPE_H_
|
||||
|
||||
int enum_value_dissect_from_buffer(
|
||||
struct types_s *type, buffer_t *buffer, uint32_t offset,
|
||||
uint32_t parent_offset, int indent);
|
||||
|
||||
int enum_value_file_print(struct types_s *type, int indent, FILE *file);
|
||||
|
||||
int enum_value_type_hr_display(struct types_s *type, int indent);
|
||||
|
||||
#endif /* ENUM_VALUE_TYPE_H_ */
|
||||
@@ -0,0 +1,143 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../rc.h"
|
||||
|
||||
#include "field_type.h"
|
||||
#include "buffers.h"
|
||||
#include "ui_interface.h"
|
||||
|
||||
int field_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset,
|
||||
int indent) {
|
||||
int length = 0;
|
||||
char cbuf[50];
|
||||
char *cpy = NULL;
|
||||
struct types_s *type_child;
|
||||
char array_info[50];
|
||||
int indent_child;
|
||||
|
||||
DISPLAY_PARSE_INFO("field", type->name, offset, parent_offset);
|
||||
|
||||
CHECK_FCT(buffer_has_enouch_data(buffer, parent_offset + offset, type->size / 8));
|
||||
|
||||
if (type->bits == -1) {
|
||||
if (type->child != NULL) {
|
||||
/* Ignore TYPEDEF children */
|
||||
for (type_child = type->child; type_child != NULL && type_child->type == TYPE_TYPEDEF; type_child =
|
||||
type_child->child) {
|
||||
}
|
||||
|
||||
if (type_child->type == TYPE_ARRAY) {
|
||||
struct types_s *type_array_child;
|
||||
|
||||
/* Ignore TYPEDEF children */
|
||||
for (type_array_child = type_child->child;
|
||||
type_array_child != NULL && type_array_child->type == TYPE_TYPEDEF; type_array_child =
|
||||
type_array_child->child) {
|
||||
}
|
||||
|
||||
sprintf (array_info, "[%d]", type_child->size / type_array_child->size);
|
||||
}
|
||||
else {
|
||||
array_info[0] = '\0';
|
||||
}
|
||||
|
||||
DISPLAY_TYPE("Fld");
|
||||
INDENTED_STRING(cbuf, indent, sprintf(cbuf, ".%s%s = ", type->name ? type->name : "Field", array_info));
|
||||
length = strlen (cbuf);
|
||||
cpy = malloc (sizeof(char) * length);
|
||||
memcpy (cpy, cbuf, length);
|
||||
ui_interface.ui_signal_set_text (cpy, length);
|
||||
if (cpy)
|
||||
free (cpy);
|
||||
|
||||
indent_child = indent;
|
||||
if (type_child->type == TYPE_ARRAY || type_child->type == TYPE_STRUCT || type_child->type == TYPE_UNION) {
|
||||
DISPLAY_BRACE(ui_interface.ui_signal_set_text ("{", 1);)
|
||||
ui_interface.ui_signal_set_text ("\n", 1);
|
||||
indent_child += 4;
|
||||
}
|
||||
if (type_child->type == TYPE_FUNDAMENTAL || type_child->type == TYPE_POINTER) {
|
||||
indent_child = 0;
|
||||
}
|
||||
|
||||
CHECK_FCT(
|
||||
type->child->type_dissect_from_buffer( type->child, buffer, parent_offset, offset + type->offset, indent_child));
|
||||
|
||||
DISPLAY_BRACE(
|
||||
if (type_child->type == TYPE_ARRAY || type_child->type == TYPE_STRUCT || type_child->type == TYPE_UNION) {
|
||||
DISPLAY_TYPE("Fld");
|
||||
INDENTED_STRING(cbuf, indent, sprintf(cbuf, "};\n"));
|
||||
length = strlen (cbuf);
|
||||
cpy = malloc (sizeof(char) * length); memcpy (cpy, cbuf, length);
|
||||
ui_interface.ui_signal_set_text (cpy, length);
|
||||
if (cpy)
|
||||
free (cpy);
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* The field is only composed of bits */
|
||||
uint32_t value = 0;
|
||||
|
||||
CHECK_FCT(buffer_fetch_bits(buffer, offset + type->offset + parent_offset, type->bits, &value));
|
||||
|
||||
DISPLAY_TYPE("Fld");
|
||||
INDENTED_STRING(
|
||||
cbuf,
|
||||
indent,
|
||||
sprintf(cbuf, ".%s:%d = (0x%0*x) %d;\n", type->name ? type->name : "Field", type->bits, (type->bits + 3) / 4, value, value));
|
||||
length = strlen (cbuf);
|
||||
cpy = malloc (sizeof(char) * length);
|
||||
memcpy (cpy, cbuf, length);
|
||||
ui_interface.ui_signal_set_text (cpy, length);
|
||||
if (cpy)
|
||||
free (cpy);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int field_type_file_print(struct types_s *type, int indent, FILE *file) {
|
||||
if (type == NULL)
|
||||
return -1;
|
||||
INDENTED(file, indent, fprintf(file, "<Field>\n"));
|
||||
INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id));
|
||||
INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name));
|
||||
INDENTED(file, indent+4, fprintf(file, "Bits .......: %d\n", type->bits));
|
||||
INDENTED(file, indent+4, fprintf(file, "Type .......: %d\n", type->type_xml));
|
||||
INDENTED(file, indent+4, fprintf(file, "Offset .....: %d\n", type->offset));
|
||||
INDENTED(file, indent+4, fprintf(file, "Context ....: %d\n", type->context));
|
||||
INDENTED(file, indent+4, fprintf(file, "File .......: %s\n", type->file));
|
||||
INDENTED(file, indent+4, fprintf(file, "Line .......: %d\n", type->line));
|
||||
if (type->file_ref != NULL)
|
||||
type->file_ref->type_file_print (type->file_ref, indent + 4, file);
|
||||
if (type->child != NULL)
|
||||
type->child->type_file_print (type->child, indent + 4, file);
|
||||
INDENTED(file, indent, fprintf(file, "</Field>\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int field_type_hr_display(struct types_s *type, int indent) {
|
||||
if (type == NULL)
|
||||
return -1;
|
||||
INDENTED(stdout, indent, printf("<Field>\n"));
|
||||
INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id));
|
||||
INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name));
|
||||
INDENTED(stdout, indent+4, printf("Bits .......: %d\n", type->bits));
|
||||
INDENTED(stdout, indent+4, printf("Type .......: %d\n", type->type_xml));
|
||||
INDENTED(stdout, indent+4, printf("Offset .....: %d\n", type->offset));
|
||||
INDENTED(stdout, indent+4, printf("Context ....: %d\n", type->context));
|
||||
INDENTED(stdout, indent+4, printf("File .......: %s\n", type->file));
|
||||
INDENTED(stdout, indent+4, printf("Line .......: %d\n", type->line));
|
||||
if (type->file_ref != NULL)
|
||||
type->file_ref->type_hr_display (type->file_ref, indent + 4);
|
||||
if (type->child != NULL)
|
||||
type->child->type_hr_display (type->child, indent + 4);
|
||||
INDENTED(stdout, indent, printf("</Field>\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#include "types.h"
|
||||
|
||||
#ifndef FIELD_TYPE_H_
|
||||
#define FIELD_TYPE_H_
|
||||
|
||||
int field_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
|
||||
uint32_t offset, uint32_t parent_offset, int indent);
|
||||
|
||||
int field_type_file_print(struct types_s *type, int indent, FILE *file);
|
||||
|
||||
int field_type_hr_display(struct types_s *type, int indent);
|
||||
|
||||
#endif /* FIELD_TYPE_H_ */
|
||||
@@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "file_type.h"
|
||||
|
||||
int file_type_file_print(struct types_s *type, int indent, FILE *file)
|
||||
{
|
||||
if (type == NULL)
|
||||
return -1;
|
||||
INDENTED(file, indent, fprintf(file, "<File>\n"));
|
||||
INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id));
|
||||
INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name));
|
||||
INDENTED(file, indent, fprintf(file, "</File>\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int file_type_hr_display(struct types_s *type, int indent)
|
||||
{
|
||||
if (type == NULL)
|
||||
return -1;
|
||||
INDENTED(stdout, indent, printf("<File>\n"));
|
||||
INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id));
|
||||
INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name));
|
||||
INDENTED(stdout, indent, printf("</File>\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#include "types.h"
|
||||
|
||||
#ifndef FILE_TYPE_H_
|
||||
#define FILE_TYPE_H_
|
||||
|
||||
int file_type_file_print(struct types_s *type, int indent, FILE *file);
|
||||
|
||||
int file_type_hr_display(struct types_s *type, int indent);
|
||||
|
||||
#endif /* FILE_TYPE_H_ */
|
||||
@@ -0,0 +1,111 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "fundamental_type.h"
|
||||
#include "ui_interface.h"
|
||||
|
||||
uint32_t fundamental_read_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset) {
|
||||
uint32_t value;
|
||||
|
||||
switch (type->size) {
|
||||
case 8: {
|
||||
value = buffer_get_uint8_t (buffer, offset + parent_offset);
|
||||
}
|
||||
break;
|
||||
case 16: {
|
||||
value = buffer_get_uint16_t (buffer, offset + parent_offset);
|
||||
}
|
||||
break;
|
||||
case 32: {
|
||||
value = buffer_get_uint32_t (buffer, offset + parent_offset);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* ??? */
|
||||
value = 0;
|
||||
break;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
int fundamental_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset,
|
||||
int indent) {
|
||||
int length = 0;
|
||||
char cbuf[200];
|
||||
char *cpy = NULL;
|
||||
int type_unsigned;
|
||||
uint32_t value;
|
||||
|
||||
DISPLAY_PARSE_INFO("fundamental", type->name, offset, parent_offset);
|
||||
|
||||
memset (cbuf, 0, 200);
|
||||
|
||||
type_unsigned = strstr (type->name, "unsigned") == NULL ? 0 : 1;
|
||||
|
||||
value = fundamental_read_from_buffer(type, buffer, offset, parent_offset);
|
||||
|
||||
if (indent > 0)
|
||||
{
|
||||
DISPLAY_TYPE("Fun");
|
||||
}
|
||||
switch (type->size) {
|
||||
case 8: {
|
||||
INDENTED_STRING(cbuf, indent,
|
||||
sprintf(cbuf, type_unsigned ? "(0x%02x) %3u '%c';\n" : "(0x%02x) %4d '%c';\n", value, value, isprint(value) ? value : '.'));
|
||||
}
|
||||
break;
|
||||
case 16: {
|
||||
INDENTED_STRING(cbuf, indent,
|
||||
sprintf(cbuf, type_unsigned ? "(0x%04x) %5u;\n" : "(0x%04x) %6d;\n", value, value));
|
||||
}
|
||||
break;
|
||||
case 32: {
|
||||
INDENTED_STRING(cbuf, indent,
|
||||
sprintf(cbuf, type_unsigned ? "(0x%08x) %9u;\n" : "(0x%08x) %10d;\n", value, value));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* ??? */
|
||||
break;
|
||||
}
|
||||
|
||||
length = strlen (cbuf);
|
||||
cpy = malloc (length * sizeof(char));
|
||||
memcpy (cpy, cbuf, length);
|
||||
ui_interface.ui_signal_set_text (cpy, length);
|
||||
|
||||
if (cpy)
|
||||
free (cpy);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fundamental_type_file_print(struct types_s *type, int indent, FILE *file) {
|
||||
if (type == NULL)
|
||||
return -1;
|
||||
INDENTED(file, indent, fprintf(file, "<Fundamental>\n"));
|
||||
INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name));
|
||||
INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id));
|
||||
INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size));
|
||||
INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align));
|
||||
if (type->file_ref != NULL)
|
||||
type->file_ref->type_file_print (type->file_ref, indent + 4, file);
|
||||
INDENTED(file, indent, fprintf(file, "</Fundamental>\n"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fundamental_type_hr_display(struct types_s *type, int indent) {
|
||||
if (type == NULL)
|
||||
return -1;
|
||||
INDENTED(stdout, indent, printf("<Fundamental>\n"));
|
||||
INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name));
|
||||
INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id));
|
||||
INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size));
|
||||
INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align));
|
||||
if (type->file_ref != NULL)
|
||||
type->file_ref->type_hr_display (type->file_ref, indent + 4);
|
||||
INDENTED(stdout, indent, printf("</Fundamental>\n"));
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#include "types.h"
|
||||
|
||||
#ifndef FUNDAMENTAL_TYPE_H_
|
||||
#define FUNDAMENTAL_TYPE_H_
|
||||
|
||||
uint32_t fundamental_read_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset);
|
||||
|
||||
int fundamental_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset,
|
||||
int indent);
|
||||
|
||||
int fundamental_type_file_print(struct types_s *type, int indent, FILE *file);
|
||||
|
||||
int fundamental_type_hr_display(struct types_s *type, int indent);
|
||||
|
||||
#endif /* FUNDAMENTAL_TYPE_H_ */
|
||||
@@ -0,0 +1,14 @@
|
||||
#include "fundamental_type.h"
|
||||
#include "struct_type.h"
|
||||
|
||||
#ifndef INTERTASK_CONTEXTS_H_
|
||||
#define INTERTASK_CONTEXTS_H_
|
||||
|
||||
typedef struct {
|
||||
/* List of fundamental types that can contruct any other type */
|
||||
fundamental_type_t *ft_list;
|
||||
|
||||
struct_type_t *struct_list;
|
||||
} intertask_context_t;
|
||||
|
||||
#endif /* INTERTASK_CONTEXTS_H_ */
|
||||
@@ -0,0 +1,181 @@
|
||||
/* For development only : */
|
||||
%debug
|
||||
%error-verbose
|
||||
|
||||
/* Keep track of location */
|
||||
%locations
|
||||
%defines
|
||||
%pure-parser
|
||||
|
||||
%{
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
int
|
||||
yyerror(const char *msg);
|
||||
|
||||
extern int yywrap();
|
||||
extern int yylex();
|
||||
|
||||
extern int yylineno;
|
||||
|
||||
/* The Lex parser prototype */
|
||||
int fddlex(YYSTYPE *lvalp, YYLTYPE *llocp);
|
||||
%}
|
||||
|
||||
/* Values returned by lex for token */
|
||||
%union {
|
||||
char *string; /* The string is allocated by strdup in lex.*/
|
||||
int integer; /* Store integer values */
|
||||
}
|
||||
|
||||
%token LEX_ERROR
|
||||
|
||||
%token <string> QSTRING
|
||||
%token <string> STRING
|
||||
%token <integer> INTEGER
|
||||
%token Y_TYPEDEF
|
||||
%token Y_STRUCT
|
||||
%token Y_UNION
|
||||
%token Y_CHARTYPE
|
||||
%token Y_SHORTTYPE
|
||||
%token Y_INTTYPE
|
||||
%token Y_LONGTYPE
|
||||
%token Y_ENUM
|
||||
%token Y_UNSIGNED
|
||||
%token Y_SIGNED
|
||||
%token Y_EXTENSION
|
||||
%token Y_ATTRIBUTE
|
||||
%token Y_ATTRIBUTE_MODE
|
||||
%token Y_ATTRIBUTE_HI
|
||||
%token Y_ATTRIBUTE_SI
|
||||
%token Y_VOIDTYPE
|
||||
%token Y_POINTER
|
||||
%token Y_SIZEOF
|
||||
|
||||
%%
|
||||
messages:
|
||||
| messages definition
|
||||
| messages errors
|
||||
{
|
||||
yyerror("An error occurred while parsing the configuration file");
|
||||
return EINVAL;
|
||||
}
|
||||
;
|
||||
|
||||
definition:
|
||||
| Y_EXTENSION definition
|
||||
| Y_TYPEDEF enumerate
|
||||
| Y_TYPEDEF structure
|
||||
| structure
|
||||
| enumerate
|
||||
| Y_STRUCT STRING ';'
|
||||
| Y_TYPEDEF singletype attribute ';'
|
||||
;
|
||||
|
||||
enumerate:
|
||||
| Y_ENUM '{' enumlist '}' STRING ';'
|
||||
| Y_ENUM STRING '{' enumlist '}' ';'
|
||||
| Y_ENUM STRING '{' enumlist '}' STRING ';'
|
||||
;
|
||||
|
||||
enumlist:
|
||||
| enumitem ',' enumlist
|
||||
| enumitem
|
||||
;
|
||||
|
||||
enumitem: STRING '=' INTEGER
|
||||
| STRING '=' STRING
|
||||
| STRING
|
||||
;
|
||||
|
||||
structure: Y_STRUCT STRING '{' paramlist '}' STRING ';'
|
||||
| Y_STRUCT '{' paramlist '}' STRING ';'
|
||||
| Y_STRUCT STRING '{' paramlist '}' ';'
|
||||
| Y_STRUCT STRING ';'
|
||||
| Y_STRUCT STRING STRING attribute ';'
|
||||
| Y_STRUCT singletype ';'
|
||||
;
|
||||
|
||||
paramlist:
|
||||
| paramlist singletype ';'
|
||||
| paramlist union
|
||||
| paramlist structure
|
||||
;
|
||||
|
||||
union: Y_UNION STRING '{' paramlist '}' STRING ';'
|
||||
| Y_UNION '{' paramlist '}' STRING ';'
|
||||
| Y_UNION STRING '{' paramlist '}' ';'
|
||||
;
|
||||
|
||||
singletype:
|
||||
| Y_SIGNED singletype
|
||||
| Y_UNSIGNED singletype
|
||||
| STRING STRING
|
||||
| Y_CHARTYPE STRING
|
||||
| Y_SHORTTYPE STRING
|
||||
| Y_INTTYPE STRING
|
||||
| Y_SHORTTYPE Y_INTTYPE STRING
|
||||
| Y_LONGTYPE STRING
|
||||
| Y_LONGTYPE Y_INTTYPE STRING
|
||||
| Y_LONGTYPE Y_LONGTYPE Y_INTTYPE STRING
|
||||
| Y_VOIDTYPE Y_POINTER STRING
|
||||
| Y_VOIDTYPE STRING
|
||||
| STRING Y_POINTER STRING
|
||||
| basictype Y_POINTER STRING
|
||||
| singletype '[' arraydef ']'
|
||||
| structure
|
||||
;
|
||||
|
||||
arraydef:
|
||||
| INTEGER arraydef
|
||||
| '*' arraydef
|
||||
| Y_POINTER arraydef
|
||||
| Y_SIZEOF arraydef
|
||||
| '(' arraydef
|
||||
| ')' arraydef
|
||||
| basictype arraydef
|
||||
| '-' arraydef
|
||||
| STRING arraydef
|
||||
;
|
||||
|
||||
attribute:
|
||||
| Y_ATTRIBUTE '(' attributevalue ')'
|
||||
;
|
||||
|
||||
attributevalue:
|
||||
| '(' Y_ATTRIBUTE_MODE attributeparam ')'
|
||||
| Y_ATTRIBUTE_MODE attributeparam
|
||||
;
|
||||
|
||||
attributeparam:
|
||||
| '(' Y_ATTRIBUTE_HI ')'
|
||||
| '(' Y_ATTRIBUTE_SI ')'
|
||||
;
|
||||
|
||||
basictype:
|
||||
| Y_CHARTYPE
|
||||
| Y_SHORTTYPE
|
||||
| Y_INTTYPE
|
||||
| Y_LONGTYPE
|
||||
| Y_VOIDTYPE
|
||||
;
|
||||
|
||||
/* Lexical or syntax error */
|
||||
errors: LEX_ERROR
|
||||
| error
|
||||
;
|
||||
|
||||
%%
|
||||
|
||||
int
|
||||
yyerror(const char *msg) {
|
||||
extern char *yytext;
|
||||
fprintf(stderr,
|
||||
"Parse error near line %d (token \"%s\"): %s\n",
|
||||
yylineno, yytext, msg);
|
||||
return -1;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "pointer_type.h"
|
||||
#include "ui_interface.h"
|
||||
|
||||
int pointer_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset,
|
||||
int indent) {
|
||||
int length = 0;
|
||||
char cbuf[200];
|
||||
char *cpy = NULL;
|
||||
|
||||
DISPLAY_PARSE_INFO("pointer", type->name, offset, parent_offset);
|
||||
|
||||
memset (cbuf, 0, 200);
|
||||
|
||||
// int i;
|
||||
// CHECK_FCT(buffer_has_enouch_data(buffer, offset, type->size / 8));
|
||||
uint32_t value;
|
||||
|
||||
value = buffer_get_uint32_t (buffer, parent_offset + offset);
|
||||
|
||||
DISPLAY_TYPE("Ptr");
|
||||
if (type->child->name) {
|
||||
/*
|
||||
INDENTED(stdout, indent, fprintf(stdout, "<%s>0x%08x</%s>\n",
|
||||
type->child->name, value, type->child->name));
|
||||
*/
|
||||
INDENTED_STRING(cbuf, indent, sprintf(cbuf, "(%s *) 0x%08x;\n", type->child->name, value));
|
||||
}
|
||||
else {
|
||||
/*
|
||||
INDENTED(stdout, indent, fprintf(stdout, "<Pointer>0x%08x</Pointer>\n",
|
||||
value));
|
||||
*/
|
||||
INDENTED_STRING(cbuf, indent, sprintf(cbuf, "(void *) 0x%08x;\n", value));
|
||||
}
|
||||
|
||||
length = strlen (cbuf);
|
||||
cpy = malloc (length * sizeof(char));
|
||||
memcpy (cpy, cbuf, length);
|
||||
ui_interface.ui_signal_set_text (cpy, length);
|
||||
|
||||
if (cpy)
|
||||
free (cpy);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pointer_type_file_print(struct types_s *type, int indent, FILE *file) {
|
||||
if (type == NULL)
|
||||
return -1;
|
||||
INDENTED(file, indent, fprintf(file, "<Pointer>\n"));
|
||||
INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id));
|
||||
INDENTED(file, indent+4, fprintf(file, "Type .......: %d\n", type->type_xml));
|
||||
INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size));
|
||||
INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align));
|
||||
if (type->child != NULL)
|
||||
type->child->type_file_print (type->child, indent + 4, file);
|
||||
if (type->file_ref != NULL)
|
||||
type->file_ref->type_file_print (type->file_ref, indent + 4, file);
|
||||
INDENTED(file, indent, fprintf(file, "</Pointer>\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pointer_type_hr_display(struct types_s *type, int indent) {
|
||||
if (type == NULL)
|
||||
return -1;
|
||||
INDENTED(stdout, indent, printf("<Pointer>\n"));
|
||||
INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id));
|
||||
INDENTED(stdout, indent+4, printf("Type .......: %d\n", type->type_xml));
|
||||
INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size));
|
||||
INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align));
|
||||
if (type->child != NULL)
|
||||
type->child->type_hr_display (type->child, indent + 4);
|
||||
if (type->file_ref != NULL)
|
||||
type->file_ref->type_hr_display (type->file_ref, indent + 4);
|
||||
INDENTED(stdout, indent, printf("</Pointer>\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#include "types.h"
|
||||
|
||||
#ifndef POINTER_TYPE_H_
|
||||
#define POINTER_TYPE_H_
|
||||
|
||||
int pointer_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
|
||||
uint32_t offset, uint32_t parent_offset, int indent);
|
||||
|
||||
int pointer_type_file_print(struct types_s *type, int indent, FILE *file);
|
||||
|
||||
int pointer_type_hr_display(struct types_s *type, int indent);
|
||||
|
||||
#endif /* POINTER_TYPE_H_ */
|
||||
@@ -0,0 +1,71 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "reference_type.h"
|
||||
#include "ui_interface.h"
|
||||
|
||||
int reference_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
|
||||
uint32_t offset, uint32_t parent_offset, int indent)
|
||||
{
|
||||
DISPLAY_PARSE_INFO("reference", type->name, offset, parent_offset);
|
||||
|
||||
if (type->name) {
|
||||
INDENTED(stdout, indent, fprintf(stdout, "<%s>\n", type->name));
|
||||
}
|
||||
if (type->child != NULL)
|
||||
type->child->type_dissect_from_buffer(type->child, buffer, offset, parent_offset,
|
||||
type->name == NULL ? indent: indent+4);
|
||||
if (type->name) {
|
||||
INDENTED(stdout, indent, fprintf(stdout, "</%s>\n", type->name));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int reference_type_file_print(struct types_s *type, int indent, FILE *file)
|
||||
{
|
||||
if (type == NULL)
|
||||
return -1;
|
||||
INDENTED(file, indent, fprintf(file, "<Reference>\n"));
|
||||
INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name));
|
||||
INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id));
|
||||
INDENTED(file, indent+4, fprintf(file, "Type .......: %d\n", type->type_xml));
|
||||
INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size));
|
||||
INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align));
|
||||
INDENTED(file, indent+4, fprintf(file, "Context ....: %d\n", type->context));
|
||||
INDENTED(file, indent+4, fprintf(file, "Offset .....: %d\n", type->offset));
|
||||
INDENTED(file, indent+4, fprintf(file, "Line .......: %d\n", type->line));
|
||||
INDENTED(file, indent+4, fprintf(file, "File .......: %s\n", type->file));
|
||||
if (type->child != NULL)
|
||||
type->child->type_file_print(type->child, indent+4, file);
|
||||
if (type->file_ref != NULL)
|
||||
type->file_ref->type_file_print(type->file_ref, indent+4, file);
|
||||
INDENTED(file, indent, fprintf(file, "</Reference>\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int reference_type_hr_display(struct types_s *type, int indent)
|
||||
{
|
||||
if (type == NULL)
|
||||
return -1;
|
||||
INDENTED(stdout, indent, printf("<Reference>\n"));
|
||||
INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name));
|
||||
INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id));
|
||||
INDENTED(stdout, indent+4, printf("Type .......: %d\n", type->type_xml));
|
||||
INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size));
|
||||
INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align));
|
||||
INDENTED(stdout, indent+4, printf("Context ....: %d\n", type->context));
|
||||
INDENTED(stdout, indent+4, printf("Offset .....: %d\n", type->offset));
|
||||
INDENTED(stdout, indent+4, printf("Line .......: %d\n", type->line));
|
||||
INDENTED(stdout, indent+4, printf("File .......: %s\n", type->file));
|
||||
if (type->child != NULL)
|
||||
type->child->type_hr_display(type->child, indent+4);
|
||||
if (type->file_ref != NULL)
|
||||
type->file_ref->type_hr_display(type->file_ref, indent+4);
|
||||
INDENTED(stdout, indent, printf("</Reference>\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#include "types.h"
|
||||
|
||||
#ifndef REFERENCE_TYPE_H_
|
||||
#define REFERENCE_TYPE_H_
|
||||
|
||||
int reference_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
|
||||
uint32_t offset, uint32_t parent_offset, int indent);
|
||||
|
||||
int reference_type_file_print(struct types_s *type, int indent, FILE *file);
|
||||
|
||||
int reference_type_hr_display(struct types_s *type, int indent);
|
||||
|
||||
#endif /* REFERENCE_TYPE_H_ */
|
||||
@@ -0,0 +1,123 @@
|
||||
|
||||
/* Lex configuration parser.
|
||||
*
|
||||
* This file defines the token for parsing the configuration file
|
||||
*
|
||||
* Note : This module is NOT thread-safe. All processing must be done from one thread only.
|
||||
*/
|
||||
%{
|
||||
#include <stdio.h>
|
||||
|
||||
/* Include yacc tokens definitions */
|
||||
#include "parser.h"
|
||||
|
||||
/* Update the column information */
|
||||
#ifdef DEBUG_LEX
|
||||
#define YY_USER_ACTION { \
|
||||
yylloc->first_column = yylloc->last_column + 1; \
|
||||
yylloc->last_column = yylloc->first_column + yyleng - 1; \
|
||||
TRACE_DEBUG(FULL, \
|
||||
"(%d:%d-%d:%d) matched rule %d, length=%d, txt='%s'\n", \
|
||||
yylloc->first_line, yylloc->first_column, \
|
||||
yylloc->last_line, yylloc->last_column, \
|
||||
yy_act, yyleng, yytext); \
|
||||
}
|
||||
#else /* DEBUG_LEX */
|
||||
#define YY_USER_ACTION { \
|
||||
yylloc->first_column = yylloc->last_column + 1; \
|
||||
yylloc->last_column = yylloc->first_column + yyleng - 1; \
|
||||
}
|
||||
#endif
|
||||
|
||||
#define YY_NO_INPUT
|
||||
%}
|
||||
|
||||
%option bison-bridge bison-locations
|
||||
%option noyywrap
|
||||
%option nounput
|
||||
%option yylineno
|
||||
|
||||
/* Quoted string. Multilines do not match. */
|
||||
qstring \"[^\"\n]*\"
|
||||
|
||||
%%
|
||||
|
||||
/* List of patterns and actions */
|
||||
|
||||
<*>\n {
|
||||
/* Update the line count */
|
||||
yylloc->first_line++;
|
||||
yylloc->last_line++;
|
||||
yylloc->last_column=0;
|
||||
}
|
||||
|
||||
<*>([[:space:]]{-}[\n])+ ; /* Eat all spaces, not new lines */
|
||||
<*>#.*$ ; /* Eat all comments */
|
||||
|
||||
/* Full words tokens (keywords) */
|
||||
(?i:"typedef") { return Y_TYPEDEF; }
|
||||
(?i:"struct") { return Y_STRUCT; }
|
||||
(?i:"union") { return Y_UNION; }
|
||||
(?i:"enum") { return Y_ENUM; }
|
||||
(?i:"signed") { return Y_SIGNED; }
|
||||
(?i:"unsigned") { return Y_UNSIGNED; }
|
||||
(?i:"short") { return Y_SHORTTYPE; }
|
||||
(?i:"char") { return Y_CHARTYPE; }
|
||||
(?i:"int") { return Y_INTTYPE; }
|
||||
(?i:"long") { return Y_LONGTYPE; }
|
||||
(?i:"void") { return Y_VOIDTYPE; }
|
||||
(?i:"__extension__") { return Y_EXTENSION; }
|
||||
(?i:"__attribute__") { return Y_ATTRIBUTE; }
|
||||
(?i:"__mode__") { return Y_ATTRIBUTE_MODE; }
|
||||
(?i:"__HI__") { return Y_ATTRIBUTE_HI; }
|
||||
(?i:"__SI__") { return Y_ATTRIBUTE_SI; }
|
||||
(?i:"sizeof") { return Y_SIZEOF; }
|
||||
|
||||
[A-Za-z_][A-Za-z0-9_]* {
|
||||
/* First copy the string without the quotes for use in the yacc parser */
|
||||
if ((yylval->string = strdup(yytext+1)) == NULL) { /* This allocates one useless tail char but... it's easier :D */
|
||||
return LEX_ERROR;/* on error, trig an error in yacc parser */
|
||||
}
|
||||
yylval->string[yyleng-2] = '\0';
|
||||
|
||||
/* the yacc parser will check the string is valid */
|
||||
return STRING;
|
||||
}
|
||||
|
||||
{qstring} {
|
||||
/* First copy the string without the quotes for use in the yacc parser */
|
||||
if ((yylval->string = strdup(yytext+1)) == NULL) { /* This allocates one useless tail char but... it's easier :D */
|
||||
return LEX_ERROR;/* on error, trig an error in yacc parser */
|
||||
}
|
||||
yylval->string[yyleng-2] = '\0';
|
||||
|
||||
/* the yacc parser will check the string is valid */
|
||||
return QSTRING;
|
||||
}
|
||||
|
||||
[[:digit:]]+ {
|
||||
/* Convert this to an integer value */
|
||||
int ret = sscanf(yytext, "%i", &yylval->integer);
|
||||
if (ret != 1) {
|
||||
/* No matching: an error occurred */
|
||||
fprintf(stderr, "Unable to convert the value '%s' to a valid number: %s\n",
|
||||
yytext, strerror(errno));
|
||||
return LEX_ERROR; /* trig an error in yacc parser */
|
||||
/* Maybe we could REJECT instead of failing here? */
|
||||
}
|
||||
return INTEGER;
|
||||
}
|
||||
|
||||
/* Valid single characters for yyparse */
|
||||
<*>[\-+=,:;{}\[\]\(\)] { return yytext[0]; }
|
||||
<*>[*]* { return Y_POINTER; }
|
||||
|
||||
<*>[[:alnum:]]+ | /* This rule is only useful to print a complete token in error messages */
|
||||
/* Unrecognized character */
|
||||
<*>. {
|
||||
fprintf(stderr, "Unrecognized text on line %d col %d: '%s'.\n",
|
||||
yylloc->first_line, yylloc->first_column, yytext);
|
||||
return LEX_ERROR;
|
||||
}
|
||||
|
||||
%%
|
||||
@@ -0,0 +1,109 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "rc.h"
|
||||
|
||||
#include "struct_type.h"
|
||||
#include "buffers.h"
|
||||
#include "ui_interface.h"
|
||||
|
||||
int struct_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset,
|
||||
int indent) {
|
||||
int i;
|
||||
int length = 0;
|
||||
char cbuf[200];
|
||||
char *cpy = NULL;
|
||||
|
||||
DISPLAY_PARSE_INFO("structure", type->name, offset, parent_offset);
|
||||
|
||||
memset (cbuf, 0, 200);
|
||||
|
||||
if (type->name) {
|
||||
DISPLAY_TYPE("Str");
|
||||
INDENTED_STRING(cbuf, indent, sprintf (cbuf, "%s =%s\n", type->name, "" DISPLAY_BRACE(" {")));
|
||||
}
|
||||
|
||||
length = strlen (cbuf);
|
||||
cpy = malloc (length * sizeof(char));
|
||||
memcpy (cpy, cbuf, length);
|
||||
ui_interface.ui_signal_set_text (cpy, length);
|
||||
|
||||
if (cpy)
|
||||
free (cpy);
|
||||
|
||||
for (i = 0; i < type->nb_members; i++) {
|
||||
if (type->members_child[i] != NULL)
|
||||
type->members_child[i]->type_dissect_from_buffer (type->members_child[i], buffer, offset, parent_offset,
|
||||
type->name == NULL ? indent : indent + 4);
|
||||
}
|
||||
|
||||
DISPLAY_BRACE(
|
||||
if (type->name) {
|
||||
DISPLAY_TYPE("Str");
|
||||
INDENTED_STRING(cbuf, indent, sprintf(cbuf, "};\n"));
|
||||
}
|
||||
length = strlen (cbuf);
|
||||
cpy = malloc (length * sizeof(char));
|
||||
memcpy (cpy, cbuf, length);
|
||||
ui_interface.ui_signal_set_text (cpy, length);
|
||||
if (cpy)
|
||||
free (cpy);)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int struct_type_file_print(struct types_s *type, int indent, FILE *file) {
|
||||
int i;
|
||||
if (type == NULL)
|
||||
return -1;
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
INDENTED(file, indent, fprintf(file, "<Struct>\n"));
|
||||
INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name));
|
||||
INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id));
|
||||
INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size));
|
||||
INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align));
|
||||
INDENTED(file, indent+4, fprintf(file, "Artificial .: %d\n", type->artificial));
|
||||
INDENTED(file, indent+4, fprintf(file, "File .......: %s\n", type->file));
|
||||
INDENTED(file, indent+4, fprintf(file, "Line .......: %d\n", type->line));
|
||||
INDENTED(file, indent+4, fprintf(file, "Members ....: %s\n", type->members));
|
||||
INDENTED(file, indent+4, fprintf(file, "Mangled ....: %s\n", type->mangled));
|
||||
INDENTED(file, indent+4, fprintf(file, "Demangled ..: %s\n", type->demangled));
|
||||
if (type->file_ref != NULL)
|
||||
type->file_ref->type_file_print (type->file_ref, indent + 4, file);
|
||||
for (i = 0; i < type->nb_members; i++) {
|
||||
if (type->members_child[i] != NULL)
|
||||
type->members_child[i]->type_file_print (type->members_child[i], indent + 4, file);
|
||||
}
|
||||
INDENTED(file, indent, fprintf(file, "</Struct>\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int struct_type_hr_display(struct types_s *type, int indent) {
|
||||
int i;
|
||||
if (type == NULL)
|
||||
return -1;
|
||||
INDENTED(stdout, indent, printf("<Struct>\n"));
|
||||
INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name));
|
||||
INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id));
|
||||
INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size));
|
||||
INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align));
|
||||
INDENTED(stdout, indent+4, printf("Artificial .: %d\n", type->artificial));
|
||||
INDENTED(stdout, indent+4, printf("File .......: %s\n", type->file));
|
||||
INDENTED(stdout, indent+4, printf("Line .......: %d\n", type->line));
|
||||
INDENTED(stdout, indent+4, printf("Members ....: %s\n", type->members));
|
||||
INDENTED(stdout, indent+4, printf("Mangled ....: %s\n", type->mangled));
|
||||
INDENTED(stdout, indent+4, printf("Demangled ..: %s\n", type->demangled));
|
||||
if (type->file_ref != NULL)
|
||||
type->file_ref->type_hr_display (type->file_ref, indent + 4);
|
||||
for (i = 0; i < type->nb_members; i++) {
|
||||
if (type->members_child[i] != NULL)
|
||||
type->members_child[i]->type_hr_display (type->members_child[i], indent + 4);
|
||||
}
|
||||
INDENTED(stdout, indent, printf("</Struct>\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#include "types.h"
|
||||
|
||||
#ifndef STRUCT_TYPE_H_
|
||||
#define STRUCT_TYPE_H_
|
||||
|
||||
int struct_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
|
||||
uint32_t offset, uint32_t parent_offset, int indent);
|
||||
|
||||
int struct_type_hr_display(struct types_s *type, int indent);
|
||||
|
||||
int struct_type_file_print(struct types_s *type, int indent, FILE *file);
|
||||
|
||||
#endif /* STRUCT_TYPE_H_ */
|
||||
@@ -0,0 +1,69 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "typedef_type.h"
|
||||
#include "ui_interface.h"
|
||||
|
||||
int typedef_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
|
||||
uint32_t offset, uint32_t parent_offset, int indent)
|
||||
{
|
||||
DISPLAY_PARSE_INFO("typedef", type->name, offset, parent_offset);
|
||||
|
||||
/* Simply call next_type */
|
||||
if (type->child != NULL) {
|
||||
type->child->type_dissect_from_buffer(
|
||||
type->child, buffer, offset, parent_offset, indent);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int typedef_type_file_print(struct types_s *type, int indent, FILE *file)
|
||||
{
|
||||
if (type == NULL)
|
||||
return -1;
|
||||
INDENTED(file, indent, fprintf(file, "<Typedef>\n"));
|
||||
INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name));
|
||||
INDENTED(file, indent+4, fprintf(file, "Type .......: %d\n", type->type_xml));
|
||||
INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size));
|
||||
INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align));
|
||||
INDENTED(file, indent+4, fprintf(file, "Artificial .: %d\n", type->artificial));
|
||||
INDENTED(file, indent+4, fprintf(file, "File .......: %s\n", type->file));
|
||||
INDENTED(file, indent+4, fprintf(file, "Line .......: %d\n", type->line));
|
||||
INDENTED(file, indent+4, fprintf(file, "Members ....: %s\n", type->members));
|
||||
INDENTED(file, indent+4, fprintf(file, "Mangled ....: %s\n", type->mangled));
|
||||
INDENTED(file, indent+4, fprintf(file, "Demangled ..: %s\n", type->demangled));
|
||||
if (type->file_ref != NULL)
|
||||
type->file_ref->type_file_print(type->file_ref, indent+4, file);
|
||||
if (type->child != NULL)
|
||||
type->child->type_file_print(type->child, indent+4, file);
|
||||
INDENTED(file, indent, fprintf(file, "</Typedef>\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int typedef_type_hr_display(struct types_s *type, int indent)
|
||||
{
|
||||
if (type == NULL)
|
||||
return -1;
|
||||
INDENTED(stdout, indent, printf("<Typedef>\n"));
|
||||
INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name));
|
||||
INDENTED(stdout, indent+4, printf("Type .......: %d\n", type->type_xml));
|
||||
INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size));
|
||||
INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align));
|
||||
INDENTED(stdout, indent+4, printf("Artificial .: %d\n", type->artificial));
|
||||
INDENTED(stdout, indent+4, printf("File .......: %s\n", type->file));
|
||||
INDENTED(stdout, indent+4, printf("Line .......: %d\n", type->line));
|
||||
INDENTED(stdout, indent+4, printf("Members ....: %s\n", type->members));
|
||||
INDENTED(stdout, indent+4, printf("Mangled ....: %s\n", type->mangled));
|
||||
INDENTED(stdout, indent+4, printf("Demangled ..: %s\n", type->demangled));
|
||||
if (type->file_ref != NULL)
|
||||
type->file_ref->type_hr_display(type->file_ref, indent+4);
|
||||
if (type->child != NULL)
|
||||
type->child->type_hr_display(type->child, indent+4);
|
||||
INDENTED(stdout, indent, printf("</Typedef>\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#include "types.h"
|
||||
|
||||
#ifndef TYPEDEF_TYPE_H_
|
||||
#define TYPEDEF_TYPE_H_
|
||||
|
||||
int typedef_type_file_print(struct types_s *type, int indent, FILE *file);
|
||||
|
||||
int typedef_type_hr_display(struct types_s *type, int indent);
|
||||
|
||||
int typedef_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
|
||||
uint32_t offset, uint32_t parent_offset, int indent);
|
||||
|
||||
#endif /* TYPEDEF_TYPE_H_ */
|
||||
@@ -0,0 +1,123 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "types.h"
|
||||
#include "array_type.h"
|
||||
#include "enum_type.h"
|
||||
#include "fundamental_type.h"
|
||||
#include "struct_type.h"
|
||||
#include "union_type.h"
|
||||
#include "typedef_type.h"
|
||||
#include "enum_value_type.h"
|
||||
#include "file_type.h"
|
||||
#include "field_type.h"
|
||||
#include "reference_type.h"
|
||||
#include "pointer_type.h"
|
||||
|
||||
types_t *type_new(enum type_e type)
|
||||
{
|
||||
types_t *new_p;
|
||||
|
||||
new_p = malloc(sizeof(types_t));
|
||||
|
||||
memset(new_p, 0, sizeof(types_t));
|
||||
|
||||
new_p->type = type;
|
||||
|
||||
switch(type) {
|
||||
case TYPE_ENUMERATION:
|
||||
new_p->type_hr_display = enum_type_hr_display;
|
||||
new_p->type_file_print = enum_type_file_print;
|
||||
new_p->type_dissect_from_buffer = enum_type_dissect_from_buffer;
|
||||
break;
|
||||
case TYPE_FUNDAMENTAL:
|
||||
new_p->type_hr_display = fundamental_type_hr_display;
|
||||
new_p->type_file_print = fundamental_type_file_print;
|
||||
new_p->type_dissect_from_buffer = fundamental_dissect_from_buffer;
|
||||
break;
|
||||
case TYPE_STRUCT:
|
||||
new_p->type_hr_display = struct_type_hr_display;
|
||||
new_p->type_file_print = struct_type_file_print;
|
||||
new_p->type_dissect_from_buffer = struct_dissect_from_buffer;
|
||||
break;
|
||||
case TYPE_UNION:
|
||||
new_p->type_hr_display = union_type_hr_display;
|
||||
new_p->type_file_print = union_type_file_print;
|
||||
new_p->type_dissect_from_buffer = union_dissect_from_buffer;
|
||||
break;
|
||||
case TYPE_TYPEDEF:
|
||||
new_p->type_hr_display = typedef_type_hr_display;
|
||||
new_p->type_file_print = typedef_type_file_print;
|
||||
new_p->type_dissect_from_buffer = typedef_dissect_from_buffer;
|
||||
break;
|
||||
case TYPE_ENUMERATION_VALUE:
|
||||
new_p->type_hr_display = enum_value_type_hr_display;
|
||||
new_p->type_file_print = enum_value_file_print;
|
||||
new_p->type_dissect_from_buffer = enum_value_dissect_from_buffer;
|
||||
break;
|
||||
case TYPE_FILE:
|
||||
new_p->type_hr_display = file_type_hr_display;
|
||||
new_p->type_file_print = file_type_file_print;
|
||||
// new_p->type_dissect_from_buffer = file_dissect_from_buffer;
|
||||
break;
|
||||
case TYPE_FIELD:
|
||||
new_p->type_hr_display = field_type_hr_display;
|
||||
new_p->type_file_print = field_type_file_print;
|
||||
new_p->type_dissect_from_buffer = field_dissect_from_buffer;
|
||||
break;
|
||||
case TYPE_REFERENCE:
|
||||
new_p->type_hr_display = reference_type_hr_display;
|
||||
new_p->type_file_print = reference_type_file_print;
|
||||
new_p->type_dissect_from_buffer = reference_dissect_from_buffer;
|
||||
break;
|
||||
case TYPE_ARRAY:
|
||||
new_p->type_hr_display = array_type_hr_display;
|
||||
new_p->type_file_print = array_type_file_print;
|
||||
new_p->type_dissect_from_buffer = array_dissect_from_buffer;
|
||||
break;
|
||||
case TYPE_POINTER:
|
||||
new_p->type_hr_display = pointer_type_hr_display;
|
||||
new_p->type_file_print = pointer_type_file_print;
|
||||
new_p->type_dissect_from_buffer = pointer_dissect_from_buffer;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return new_p;
|
||||
}
|
||||
|
||||
int types_insert_tail(types_t **head, types_t *to_insert)
|
||||
{
|
||||
if (to_insert == NULL || head == NULL)
|
||||
return -1;
|
||||
if (*head == NULL) {
|
||||
*head = to_insert;
|
||||
} else {
|
||||
types_t *last = *head;
|
||||
while(last->next != NULL) {
|
||||
last = last->next;
|
||||
}
|
||||
last->next = to_insert;
|
||||
to_insert->previous = last;
|
||||
}
|
||||
to_insert->head = *head;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void types_hr_display(types_t *head)
|
||||
{
|
||||
types_t *current = head;
|
||||
|
||||
if (head == NULL) {
|
||||
printf("Empty list\n");
|
||||
/* Empty list */
|
||||
return;
|
||||
}
|
||||
|
||||
while((current = current->next) != NULL)
|
||||
{
|
||||
current->type_hr_display(current, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "buffers.h"
|
||||
|
||||
#ifndef TYPES_H_
|
||||
#define TYPES_H_
|
||||
|
||||
/* Activate to display the type at the beginning of the line (debug option) */
|
||||
#define ENABLE_DISPLAY_TYPE 0
|
||||
|
||||
/* Activate to display the parse information before processing each item (debug option) */
|
||||
#define ENABLE_DISPLAY_PARSE_INFO 0
|
||||
|
||||
/* Activate to show braces, in increase the number of displayed lines (formating option)*/
|
||||
#define ENABLE_DISPLAY_BRACE 0
|
||||
|
||||
#if (ENABLE_DISPLAY_TYPE != 0)
|
||||
# define DISPLAY_TYPE(tYPE) ui_interface.ui_signal_set_text(tYPE, strlen(tYPE));
|
||||
#else
|
||||
# define DISPLAY_TYPE(tYPE)
|
||||
#endif
|
||||
|
||||
#if (ENABLE_DISPLAY_PARSE_INFO != 0)
|
||||
# define DISPLAY_PARSE_INFO(tYPE, nAME, oFFSET, pARENToFFSET) \
|
||||
{ \
|
||||
char buf[200]; \
|
||||
sprintf(buf, "/* %s \"%s\" %d %d */\n", tYPE, nAME, oFFSET, pARENToFFSET); \
|
||||
ui_interface.ui_signal_set_text(buf, strlen(buf)); \
|
||||
}
|
||||
#else
|
||||
# define DISPLAY_PARSE_INFO(tYPE, nAME, oFFSET, pARENToFFSET)
|
||||
#endif
|
||||
|
||||
#if (ENABLE_DISPLAY_BRACE != 0)
|
||||
# define DISPLAY_BRACE(cODE) cODE
|
||||
#else
|
||||
# define DISPLAY_BRACE(cODE)
|
||||
#endif
|
||||
|
||||
enum type_e {
|
||||
TYPE_ENUMERATION,
|
||||
TYPE_ENUMERATION_VALUE,
|
||||
TYPE_STRUCT,
|
||||
TYPE_UNION,
|
||||
TYPE_FUNDAMENTAL,
|
||||
TYPE_TYPEDEF,
|
||||
TYPE_ARRAY,
|
||||
TYPE_REFERENCE,
|
||||
TYPE_FIELD,
|
||||
TYPE_FUNCTION,
|
||||
TYPE_ARGUMENT,
|
||||
TYPE_POINTER,
|
||||
TYPE_FILE,
|
||||
};
|
||||
|
||||
/* Forward declarations */
|
||||
struct types_s;
|
||||
|
||||
typedef int (*type_hr_display_t)(struct types_s *type, int indent);
|
||||
typedef int (*type_ui_display_t)(struct types_s *type, int indent);
|
||||
typedef int (*type_file_print_t)(struct types_s *type, int indent, FILE *file);
|
||||
|
||||
/**
|
||||
* type_dissect_from_buffer_t
|
||||
* @param type The current type
|
||||
* @param buffer The buffer containing data to dissect
|
||||
* @param offset offset of field from the beginning of the parent
|
||||
* @param parent_offset offset of the parent from begining
|
||||
**/
|
||||
typedef int (*type_dissect_from_buffer_t)(struct types_s *type, buffer_t *buffer,
|
||||
uint32_t offset, uint32_t parent_offset, int indent);
|
||||
|
||||
typedef struct types_s {
|
||||
/* The type of the current description */
|
||||
enum type_e type;
|
||||
|
||||
/* Printable name for the current type */
|
||||
char *name;
|
||||
|
||||
int type_xml;
|
||||
|
||||
int size;
|
||||
int align;
|
||||
int bits;
|
||||
|
||||
/* Used only for arrays */
|
||||
int min;
|
||||
int max;
|
||||
|
||||
int context;
|
||||
|
||||
/* Init value for enumerations */
|
||||
int init_value;
|
||||
|
||||
int incomplete;
|
||||
|
||||
/* Id of the type as defined in XML file */
|
||||
int id;
|
||||
int artificial;
|
||||
|
||||
char *mangled;
|
||||
char *demangled;
|
||||
|
||||
/* List of members in constructed types */
|
||||
char *members;
|
||||
|
||||
/* The file containing the definition */
|
||||
char *file;
|
||||
/* Line number of the current definition */
|
||||
int line;
|
||||
|
||||
/* offset of the field in the parent type
|
||||
* -1 means no parent
|
||||
*/
|
||||
int offset;
|
||||
|
||||
struct types_s *previous;
|
||||
struct types_s *next;
|
||||
struct types_s *parent;
|
||||
struct types_s *child;
|
||||
struct types_s *file_ref;
|
||||
/* Reference to the head */
|
||||
struct types_s *head;
|
||||
|
||||
/* For structures or union */
|
||||
int nb_members;
|
||||
struct types_s **members_child;
|
||||
|
||||
/* Some procedures to display the type on terminal */
|
||||
type_hr_display_t type_hr_display;
|
||||
/* Some procedures to display the type on UI */
|
||||
type_ui_display_t type_ui_display;
|
||||
/* Procedure to display the type to a file */
|
||||
type_file_print_t type_file_print;
|
||||
/* Dissect the type */
|
||||
type_dissect_from_buffer_t type_dissect_from_buffer;
|
||||
} types_t;
|
||||
|
||||
types_t *type_new(enum type_e type);
|
||||
|
||||
int types_insert_tail(types_t **head, types_t *to_insert);
|
||||
|
||||
void types_hr_display(types_t *head);
|
||||
|
||||
#define INDENTED(fILE, x, y) \
|
||||
do { \
|
||||
int indentation = x; \
|
||||
while(indentation--) fprintf(fILE, " "); \
|
||||
y; \
|
||||
} while(0)
|
||||
|
||||
#define INDENTED_STRING(sTR, x, y) \
|
||||
do { \
|
||||
int indentation = x; \
|
||||
while(indentation--) ui_interface.ui_signal_set_text(" ", 1); \
|
||||
y; \
|
||||
} while(0)
|
||||
|
||||
#endif /* TYPES_H_ */
|
||||
@@ -0,0 +1,126 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "rc.h"
|
||||
|
||||
#include "union_type.h"
|
||||
#include "../libresolver/locate_root.h"
|
||||
#include "ui_interface.h"
|
||||
|
||||
/* There is only one special case of union which is associated to an index: the message id */
|
||||
int union_msg_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset,
|
||||
int indent) {
|
||||
uint32_t message_id;
|
||||
|
||||
DISPLAY_PARSE_INFO("union_msg", type->name, offset, parent_offset);
|
||||
|
||||
CHECK_FCT(get_message_id(type->head, buffer, &message_id));
|
||||
|
||||
if (type->members_child[message_id] != NULL)
|
||||
type->members_child[message_id]->type_dissect_from_buffer (type->members_child[message_id], buffer, offset,
|
||||
parent_offset, indent);
|
||||
|
||||
return RC_OK;
|
||||
}
|
||||
|
||||
int union_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset,
|
||||
int indent) {
|
||||
int length = 0;
|
||||
char cbuf[200];
|
||||
char *cpy = NULL;
|
||||
|
||||
DISPLAY_PARSE_INFO("union", type->name, offset, parent_offset);
|
||||
|
||||
memset (cbuf, 0, 200);
|
||||
|
||||
// CHECK_FCT(buffer_has_enouch_data(buffer, offset + parent_offset, type->size / 8));
|
||||
|
||||
if (type->name) {
|
||||
// INDENTED(stdout, indent, fprintf(stdout, "<%s>\n", type->name));
|
||||
DISPLAY_TYPE("Uni");
|
||||
INDENTED_STRING(cbuf, indent, sprintf(cbuf, "%s {\n", type->name));
|
||||
}
|
||||
|
||||
length = strlen (cbuf);
|
||||
cpy = malloc (length * sizeof(char));
|
||||
memcpy (cpy, cbuf, length);
|
||||
ui_interface.ui_signal_set_text (cpy, length);
|
||||
|
||||
if (cpy)
|
||||
free (cpy);
|
||||
|
||||
/* Only dissect the first field present in unions */
|
||||
if (type->members_child[0] != NULL)
|
||||
type->members_child[0]->type_dissect_from_buffer (type->members_child[0], buffer, offset, parent_offset,
|
||||
type->name == NULL ? indent : indent + 4);
|
||||
|
||||
if (type->name) {
|
||||
// INDENTED(stdout, indent, fprintf(stdout, "</%s>\n", type->name));
|
||||
DISPLAY_TYPE("Uni");
|
||||
INDENTED_STRING(cbuf, indent, sprintf(cbuf, "};\n"));
|
||||
}
|
||||
|
||||
length = strlen (cbuf);
|
||||
cpy = malloc (length * sizeof(char));
|
||||
memcpy (cpy, cbuf, length);
|
||||
ui_interface.ui_signal_set_text (cpy, length);
|
||||
|
||||
if (cpy)
|
||||
free (cpy);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int union_type_file_print(struct types_s *type, int indent, FILE *file) {
|
||||
int i;
|
||||
if (type == NULL)
|
||||
return -1;
|
||||
INDENTED(file, indent, fprintf(file, "<Union>\n"));
|
||||
INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name));
|
||||
INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id));
|
||||
INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size));
|
||||
INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align));
|
||||
INDENTED(file, indent+4, fprintf(file, "Artificial .: %d\n", type->artificial));
|
||||
INDENTED(file, indent+4, fprintf(file, "File .......: %s\n", type->file));
|
||||
INDENTED(file, indent+4, fprintf(file, "Line .......: %d\n", type->line));
|
||||
INDENTED(file, indent+4, fprintf(file, "Members ....: %s\n", type->members));
|
||||
INDENTED(file, indent+4, fprintf(file, "Mangled ....: %s\n", type->mangled));
|
||||
INDENTED(file, indent+4, fprintf(file, "Demangled ..: %s\n", type->demangled));
|
||||
if (type->file_ref != NULL)
|
||||
type->file_ref->type_file_print (type->file_ref, indent + 4, file);
|
||||
for (i = 0; i < type->nb_members; i++) {
|
||||
if (type->members_child[i] != NULL)
|
||||
type->members_child[i]->type_file_print (type->members_child[i], indent + 4, file);
|
||||
}
|
||||
INDENTED(file, indent, fprintf(file, "</Union>\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int union_type_hr_display(struct types_s *type, int indent) {
|
||||
int i;
|
||||
if (type == NULL)
|
||||
return -1;
|
||||
INDENTED(stdout, indent, printf("<Union>\n"));
|
||||
INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name));
|
||||
INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id));
|
||||
INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size));
|
||||
INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align));
|
||||
INDENTED(stdout, indent+4, printf("Artificial .: %d\n", type->artificial));
|
||||
INDENTED(stdout, indent+4, printf("File .......: %s\n", type->file));
|
||||
INDENTED(stdout, indent+4, printf("Line .......: %d\n", type->line));
|
||||
INDENTED(stdout, indent+4, printf("Members ....: %s\n", type->members));
|
||||
INDENTED(stdout, indent+4, printf("Mangled ....: %s\n", type->mangled));
|
||||
INDENTED(stdout, indent+4, printf("Demangled ..: %s\n", type->demangled));
|
||||
if (type->file_ref != NULL)
|
||||
type->file_ref->type_hr_display (type->file_ref, indent + 4);
|
||||
for (i = 0; i < type->nb_members; i++) {
|
||||
if (type->members_child[i] != NULL)
|
||||
type->members_child[i]->type_hr_display (type->members_child[i], indent + 4);
|
||||
}
|
||||
INDENTED(stdout, indent, printf("</Union>\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#include "types.h"
|
||||
|
||||
#ifndef UNION_TYPE_H_
|
||||
#define UNION_TYPE_H_
|
||||
|
||||
int union_msg_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
|
||||
uint32_t offset, uint32_t parent_offset, int indent);
|
||||
|
||||
int union_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
|
||||
uint32_t offset, uint32_t parent_offset, int indent);
|
||||
|
||||
int union_type_file_print(struct types_s *type, int indent, FILE *file);
|
||||
|
||||
int union_type_hr_display(struct types_s *type, int indent);
|
||||
|
||||
#endif /* UNION_TYPE_H_ */
|
||||
@@ -0,0 +1,757 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/tree.h>
|
||||
|
||||
#include "types.h"
|
||||
#include "xml_parse.h"
|
||||
#include "union_type.h"
|
||||
|
||||
#include "ui_interface.h"
|
||||
|
||||
#include "../libresolver/locate_root.h"
|
||||
#include "../libresolver/resolvers.h"
|
||||
|
||||
extern int debug_parser;
|
||||
|
||||
#if (ENABLE_DISPLAY_PARSE_INFO != 0)
|
||||
# define INDENT_START 30
|
||||
#else
|
||||
# define INDENT_START 0
|
||||
#endif
|
||||
|
||||
#define PARSER_DEBUG(fmt, args...) \
|
||||
do { \
|
||||
if (debug_parser) \
|
||||
fprintf(stdout, "WARNING: "fmt, ##args); \
|
||||
} while(0)
|
||||
|
||||
#define PARSER_ERROR(fmt, args...) \
|
||||
do { \
|
||||
fprintf(stderr, "FATAL: "fmt, ##args); \
|
||||
} while(0)
|
||||
|
||||
types_t *root = NULL;
|
||||
|
||||
static int xml_parse_doc(xmlDocPtr doc);
|
||||
|
||||
static int parse_attribute_name(xmlNode *node, types_t *type, int mandatory) {
|
||||
xmlAttrPtr node_attribute;
|
||||
if ((node_attribute = xmlHasProp (node, (xmlChar *) "name")) == NULL) {
|
||||
if (mandatory) {
|
||||
PARSER_ERROR("cannot retrieve name attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
PARSER_DEBUG("cannot retrieve name attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
type->name = strdup ((char *) node_attribute->children->content);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_attribute_id(xmlNode *node, types_t *type) {
|
||||
xmlAttrPtr node_attribute;
|
||||
if ((node_attribute = xmlHasProp (node, (xmlChar *) "id")) == NULL) {
|
||||
PARSER_ERROR("cannot retrieve id attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
return -1;
|
||||
}
|
||||
type->id = atoi ((char *) &node_attribute->children->content[1]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_attribute_size(xmlNode *node, types_t *type, int mandatory) {
|
||||
xmlAttrPtr node_attribute;
|
||||
if ((node_attribute = xmlHasProp (node, (xmlChar *) "size")) == NULL) {
|
||||
if (mandatory) {
|
||||
PARSER_ERROR("cannot retrieve size attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
type->size = -1;
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
PARSER_DEBUG("cannot retrieve size attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
type->size = -1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
type->size = atoi ((char *) node_attribute->children->content);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_attribute_align(xmlNode *node, types_t *type, int mandatory) {
|
||||
xmlAttrPtr node_attribute;
|
||||
if ((node_attribute = xmlHasProp (node, (xmlChar *) "align")) == NULL) {
|
||||
if (mandatory) {
|
||||
PARSER_ERROR("cannot retrieve align attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
type->align = -1;
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
PARSER_DEBUG("cannot retrieve align attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
type->align = -1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
type->align = atoi ((char *) node_attribute->children->content);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_attribute_line(xmlNode *node, types_t *type) {
|
||||
xmlAttrPtr node_attribute;
|
||||
if ((node_attribute = xmlHasProp (node, (xmlChar *) "line")) == NULL) {
|
||||
type->line = -1;
|
||||
return 0;
|
||||
}
|
||||
type->line = atoi ((char *) node_attribute->children->content);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_attribute_file(xmlNode *node, types_t *type) {
|
||||
xmlAttrPtr node_attribute;
|
||||
if ((node_attribute = xmlHasProp (node, (xmlChar *) "file")) == NULL) {
|
||||
type->file = NULL;
|
||||
return 0;
|
||||
}
|
||||
type->file = strdup ((char *) node_attribute->children->content);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_attribute_context(xmlNode *node, types_t *type, int mandatory) {
|
||||
xmlAttrPtr node_attribute;
|
||||
if ((node_attribute = xmlHasProp (node, (xmlChar *) "context")) == NULL) {
|
||||
if (mandatory) {
|
||||
PARSER_ERROR("cannot retrieve context attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
type->context = -1;
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
type->context = -1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
type->context = atoi ((char *) &node_attribute->children->content[1]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_attribute_artificial(xmlNode *node, types_t *type) {
|
||||
xmlAttrPtr node_attribute;
|
||||
if ((node_attribute = xmlHasProp (node, (xmlChar *) "artificial")) == NULL) {
|
||||
PARSER_DEBUG("cannot retrieve artificial attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
type->artificial = -1;
|
||||
return 0;
|
||||
}
|
||||
type->artificial = atoi ((char *) &node_attribute->children->content[1]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_attribute_init(xmlNode *node, types_t *type) {
|
||||
xmlAttrPtr node_attribute;
|
||||
if ((node_attribute = xmlHasProp (node, (xmlChar *) "init")) == NULL) {
|
||||
PARSER_ERROR("cannot retrieve init attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
type->init_value = -1;
|
||||
return 0;
|
||||
}
|
||||
type->init_value = atoi ((char *) node_attribute->children->content);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_attribute_members(xmlNode *node, types_t *type, int mandatory) {
|
||||
xmlAttrPtr node_attribute;
|
||||
if ((node_attribute = xmlHasProp (node, (xmlChar *) "members")) == NULL) {
|
||||
if (mandatory) {
|
||||
PARSER_ERROR("cannot retrieve members attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
type->members = 0;
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
PARSER_DEBUG("cannot retrieve members attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
type->members = 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
type->members = strdup ((char *) node_attribute->children->content);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_attribute_mangled(xmlNode *node, types_t *type, int mandatory) {
|
||||
xmlAttrPtr node_attribute;
|
||||
if ((node_attribute = xmlHasProp (node, (xmlChar *) "mangled")) == NULL) {
|
||||
if (mandatory) {
|
||||
PARSER_ERROR("cannot retrieve mangled attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
type->mangled = 0;
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
PARSER_DEBUG("cannot retrieve mangled attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
type->mangled = 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
type->mangled = strdup ((char *) node_attribute->children->content);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_attribute_demangled(xmlNode *node, types_t *type, int mandatory) {
|
||||
xmlAttrPtr node_attribute;
|
||||
if ((node_attribute = xmlHasProp (node, (xmlChar *) "mangled")) == NULL) {
|
||||
if (mandatory) {
|
||||
PARSER_ERROR("cannot retrieve demangled attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
type->demangled = 0;
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
PARSER_DEBUG("cannot retrieve demangled attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
type->demangled = 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
type->demangled = strdup ((char *) node_attribute->children->content);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_attribute_offset(xmlNode *node, types_t *type, int mandatory) {
|
||||
xmlAttrPtr node_attribute;
|
||||
if ((node_attribute = xmlHasProp (node, (xmlChar *) "offset")) == NULL) {
|
||||
if (mandatory) {
|
||||
PARSER_ERROR("cannot retrieve offset attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
type->offset = -1;
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
PARSER_DEBUG("cannot retrieve offset attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
type->offset = -1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
type->offset = atoi ((char *) node_attribute->children->content);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_attribute_bits(xmlNode *node, types_t *type, int mandatory) {
|
||||
xmlAttrPtr node_attribute;
|
||||
if ((node_attribute = xmlHasProp (node, (xmlChar *) "bits")) == NULL) {
|
||||
if (mandatory) {
|
||||
PARSER_ERROR("cannot retrieve bits attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
type->bits = -1;
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
PARSER_DEBUG("cannot retrieve bits attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
type->bits = -1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
type->bits = atoi ((char *) node_attribute->children->content);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_attribute_type(xmlNode *node, types_t *type, int mandatory) {
|
||||
xmlAttrPtr node_attribute;
|
||||
if ((node_attribute = xmlHasProp (node, (xmlChar *) "type")) == NULL) {
|
||||
if (mandatory) {
|
||||
PARSER_ERROR("cannot retrieve type attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
type->type_xml = 0;
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
PARSER_DEBUG("cannot retrieve type attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
type->type_xml = 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
type->type_xml = atoi ((char *) &node_attribute->children->content[1]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_attribute_min(xmlNode *node, types_t *type, int mandatory) {
|
||||
xmlAttrPtr node_attribute;
|
||||
if ((node_attribute = xmlHasProp (node, (xmlChar *) "min")) == NULL) {
|
||||
if (mandatory) {
|
||||
PARSER_ERROR("cannot retrieve min attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
type->min = 0;
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
PARSER_DEBUG("cannot retrieve min attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
type->min = 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
type->min = atoi ((char *) node_attribute->children->content);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_attribute_max(xmlNode *node, types_t *type, int mandatory) {
|
||||
xmlAttrPtr node_attribute;
|
||||
if ((node_attribute = xmlHasProp (node, (xmlChar *) "max")) == NULL) {
|
||||
if (mandatory) {
|
||||
PARSER_ERROR("cannot retrieve max attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
type->max = 0;
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
PARSER_DEBUG("cannot retrieve max attribute in node %s, %s:%ld\n",
|
||||
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
|
||||
type->max = 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
type->max = atoi ((char *) &node_attribute->children->content[1]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_enum_values(xmlNode *node, types_t *parent) {
|
||||
types_t *new;
|
||||
|
||||
if (node == NULL || parent == NULL)
|
||||
return -1;
|
||||
|
||||
new = type_new (TYPE_ENUMERATION_VALUE);
|
||||
|
||||
CHECK_FCT(parse_attribute_name(node, new, 1));
|
||||
CHECK_FCT(parse_attribute_init(node, new));
|
||||
|
||||
CHECK_FCT(types_insert_tail(&parent->child, new));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_enumeration(xmlNode *node, types_t **head) {
|
||||
types_t *new;
|
||||
xmlNode *enum_value_node;
|
||||
|
||||
if (node == NULL)
|
||||
return -1;
|
||||
|
||||
new = type_new (TYPE_ENUMERATION);
|
||||
|
||||
CHECK_FCT(parse_attribute_name(node, new, 1));
|
||||
CHECK_FCT(parse_attribute_id(node, new));
|
||||
CHECK_FCT(parse_attribute_size(node, new, 1));
|
||||
CHECK_FCT(parse_attribute_align(node, new, 1));
|
||||
CHECK_FCT(parse_attribute_context(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_line(node, new));
|
||||
CHECK_FCT(parse_attribute_file(node, new));
|
||||
CHECK_FCT(parse_attribute_artificial(node, new));
|
||||
|
||||
CHECK_FCT(types_insert_tail(head, new));
|
||||
|
||||
/* Parse enum values */
|
||||
for (enum_value_node = node->children; enum_value_node; enum_value_node = enum_value_node->next) {
|
||||
if (strcmp ((char *) enum_value_node->name, "EnumValue") == 0)
|
||||
CHECK_FCT(parse_enum_values(enum_value_node, new));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_union(xmlNode *node, types_t **head) {
|
||||
types_t *new;
|
||||
|
||||
if (node == NULL)
|
||||
return -1;
|
||||
|
||||
new = type_new (TYPE_UNION);
|
||||
|
||||
CHECK_FCT(parse_attribute_name(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_id(node, new));
|
||||
CHECK_FCT(parse_attribute_size(node, new, 1));
|
||||
CHECK_FCT(parse_attribute_align(node, new, 1));
|
||||
CHECK_FCT(parse_attribute_context(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_members(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_line(node, new));
|
||||
CHECK_FCT(parse_attribute_file(node, new));
|
||||
CHECK_FCT(parse_attribute_artificial(node, new));
|
||||
CHECK_FCT(parse_attribute_mangled(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_demangled(node, new, 0));
|
||||
|
||||
if (new->name)
|
||||
if (strcmp (new->name, "msg_s") == 0)
|
||||
new->type_dissect_from_buffer = union_msg_dissect_from_buffer;
|
||||
|
||||
CHECK_FCT(types_insert_tail(head, new));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_fundamental(xmlNode *node, types_t **head) {
|
||||
types_t *new;
|
||||
|
||||
if (node == NULL)
|
||||
return -1;
|
||||
|
||||
new = type_new (TYPE_FUNDAMENTAL);
|
||||
|
||||
CHECK_FCT(parse_attribute_name(node, new, 1));
|
||||
CHECK_FCT(parse_attribute_id(node, new));
|
||||
CHECK_FCT(parse_attribute_size(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_align(node, new, 0));
|
||||
|
||||
CHECK_FCT(types_insert_tail(head, new));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_struct(xmlNode *node, types_t **head) {
|
||||
types_t *new;
|
||||
|
||||
if (node == NULL)
|
||||
return -1;
|
||||
|
||||
new = type_new (TYPE_STRUCT);
|
||||
|
||||
CHECK_FCT(parse_attribute_name(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_id(node, new));
|
||||
CHECK_FCT(parse_attribute_size(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_align(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_file(node, new));
|
||||
CHECK_FCT(parse_attribute_line(node, new));
|
||||
CHECK_FCT(parse_attribute_context(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_artificial(node, new));
|
||||
CHECK_FCT(parse_attribute_members(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_mangled(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_demangled(node, new, 0));
|
||||
|
||||
CHECK_FCT(types_insert_tail(head, new));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_typedef(xmlNode *node, types_t **head) {
|
||||
types_t *new;
|
||||
|
||||
if (node == NULL)
|
||||
return -1;
|
||||
|
||||
new = type_new (TYPE_TYPEDEF);
|
||||
|
||||
CHECK_FCT(parse_attribute_name(node, new, 1));
|
||||
CHECK_FCT(parse_attribute_id(node, new));
|
||||
CHECK_FCT(parse_attribute_file(node, new));
|
||||
CHECK_FCT(parse_attribute_line(node, new));
|
||||
CHECK_FCT(parse_attribute_type(node, new, 1));
|
||||
CHECK_FCT(parse_attribute_size(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_align(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_context(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_artificial(node, new));
|
||||
CHECK_FCT(parse_attribute_members(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_mangled(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_demangled(node, new, 0));
|
||||
|
||||
CHECK_FCT(types_insert_tail(head, new));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_field(xmlNode *node, types_t **head) {
|
||||
types_t *new;
|
||||
|
||||
if (node == NULL)
|
||||
return -1;
|
||||
|
||||
new = type_new (TYPE_FIELD);
|
||||
|
||||
CHECK_FCT(parse_attribute_name(node, new, 1));
|
||||
CHECK_FCT(parse_attribute_id(node, new));
|
||||
CHECK_FCT(parse_attribute_type(node, new, 1));
|
||||
CHECK_FCT(parse_attribute_size(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_bits(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_offset(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_align(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_context(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_artificial(node, new));
|
||||
CHECK_FCT(parse_attribute_members(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_mangled(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_demangled(node, new, 0));
|
||||
|
||||
CHECK_FCT(types_insert_tail(head, new));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_file(xmlNode *node, types_t **head) {
|
||||
types_t *new;
|
||||
|
||||
if (node == NULL)
|
||||
return -1;
|
||||
|
||||
new = type_new (TYPE_FILE);
|
||||
|
||||
CHECK_FCT(parse_attribute_name(node, new, 1));
|
||||
CHECK_FCT(parse_attribute_id(node, new));
|
||||
|
||||
CHECK_FCT(types_insert_tail(head, new));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_reference_type(xmlNode *node, types_t **head) {
|
||||
types_t *new;
|
||||
|
||||
if (node == NULL)
|
||||
return -1;
|
||||
|
||||
new = type_new (TYPE_REFERENCE);
|
||||
|
||||
CHECK_FCT(parse_attribute_id(node, new));
|
||||
CHECK_FCT(parse_attribute_type(node, new, 1));
|
||||
CHECK_FCT(parse_attribute_size(node, new, 1));
|
||||
CHECK_FCT(parse_attribute_align(node, new, 1));
|
||||
CHECK_FCT(parse_attribute_context(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_offset(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_file(node, new));
|
||||
CHECK_FCT(parse_attribute_line(node, new));
|
||||
|
||||
CHECK_FCT(types_insert_tail(head, new));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_array_type(xmlNode *node, types_t **head) {
|
||||
types_t *new;
|
||||
|
||||
if (node == NULL)
|
||||
return -1;
|
||||
|
||||
new = type_new (TYPE_ARRAY);
|
||||
|
||||
CHECK_FCT(parse_attribute_id(node, new));
|
||||
CHECK_FCT(parse_attribute_type(node, new, 1));
|
||||
CHECK_FCT(parse_attribute_size(node, new, 0));
|
||||
CHECK_FCT(parse_attribute_align(node, new, 1));
|
||||
CHECK_FCT(parse_attribute_min(node, new, 1));
|
||||
CHECK_FCT(parse_attribute_max(node, new, 1));
|
||||
|
||||
CHECK_FCT(types_insert_tail(head, new));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_pointer_type(xmlNode *node, types_t **head) {
|
||||
types_t *new;
|
||||
|
||||
if (node == NULL)
|
||||
return -1;
|
||||
|
||||
new = type_new (TYPE_POINTER);
|
||||
|
||||
CHECK_FCT(parse_attribute_id(node, new));
|
||||
CHECK_FCT(parse_attribute_type(node, new, 1));
|
||||
CHECK_FCT(parse_attribute_size(node, new, 1));
|
||||
CHECK_FCT(parse_attribute_align(node, new, 1));
|
||||
|
||||
CHECK_FCT(types_insert_tail(head, new));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* print_element_names:
|
||||
* @a_node: the initial xml node to consider.
|
||||
*
|
||||
* Prints the names of the all the xml elements
|
||||
* that are siblings or children of a given xml node.
|
||||
*/
|
||||
static int parse_elements(xmlNode * a_node, types_t **head) {
|
||||
xmlNode *cur_node = NULL;
|
||||
xmlNode *child_node = NULL;
|
||||
unsigned long nb_nodes;
|
||||
unsigned long node_count = 0;
|
||||
|
||||
nb_nodes = xmlChildElementCount (a_node);
|
||||
|
||||
for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
|
||||
node_count++;
|
||||
sleep (1);
|
||||
ui_interface.ui_progress_bar_set_fraction ((double) node_count / nb_nodes);
|
||||
for (child_node = cur_node->children; child_node; child_node = child_node->next) {
|
||||
if (child_node->type == XML_ELEMENT_NODE) {
|
||||
if (strcmp ((char *) child_node->name, "Enumeration") == 0) {
|
||||
CHECK_FCT_DO(parse_enumeration(child_node, head), goto fail);
|
||||
}
|
||||
else
|
||||
if (strcmp ((char *) child_node->name, "FundamentalType") == 0) {
|
||||
CHECK_FCT_DO(parse_fundamental(child_node, head), goto fail);
|
||||
}
|
||||
else
|
||||
if (strcmp ((char *) child_node->name, "Struct") == 0) {
|
||||
CHECK_FCT_DO(parse_struct(child_node, head), goto fail);
|
||||
}
|
||||
else
|
||||
if (strcmp ((char *) child_node->name, "Union") == 0) {
|
||||
CHECK_FCT_DO(parse_union(child_node, head), goto fail);
|
||||
}
|
||||
else
|
||||
if (strcmp ((char *) child_node->name, "Typedef") == 0) {
|
||||
CHECK_FCT_DO(parse_typedef(child_node, head), goto fail);
|
||||
}
|
||||
else
|
||||
if (strcmp ((char *) child_node->name, "File") == 0) {
|
||||
CHECK_FCT_DO(parse_file(child_node, head), goto fail);
|
||||
}
|
||||
else
|
||||
if (strcmp ((char *) child_node->name, "Field") == 0) {
|
||||
CHECK_FCT_DO(parse_field(child_node, head), goto fail);
|
||||
}
|
||||
else
|
||||
if (strcmp ((char *) child_node->name, "ReferenceType") == 0) {
|
||||
CHECK_FCT_DO(parse_reference_type(child_node, head), goto fail);
|
||||
}
|
||||
else
|
||||
if (strcmp ((char *) child_node->name, "ArrayType") == 0) {
|
||||
CHECK_FCT_DO(parse_array_type(child_node, head), goto fail);
|
||||
}
|
||||
else
|
||||
if (strcmp ((char *) child_node->name, "PointerType") == 0) {
|
||||
CHECK_FCT_DO(parse_pointer_type(child_node, head), goto fail);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ui_interface.ui_progress_bar_terminate ();
|
||||
|
||||
return RC_OK;
|
||||
|
||||
fail: ui_interface.ui_progress_bar_terminate ();
|
||||
return RC_FAIL;
|
||||
}
|
||||
|
||||
int xml_parse_buffer(const char *xml_buffer, const int size) {
|
||||
xmlDocPtr doc; /* the resulting document tree */
|
||||
|
||||
if (xml_buffer == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
fprintf(stdout, "Parsing XML definition from buffer\n");
|
||||
|
||||
/* This initialize the library and check potential ABI mismatches
|
||||
* between the version it was compiled for and the actual shared
|
||||
* library used.
|
||||
*/
|
||||
LIBXML_TEST_VERSION
|
||||
|
||||
doc = xmlReadMemory(xml_buffer, size, NULL, NULL, 0);
|
||||
|
||||
if (doc == NULL) {
|
||||
fprintf (stderr, "Failed to parse buffer: %s\n", xml_buffer);
|
||||
ui_interface.ui_notification_dialog (DIALOG_WARNING, "Fail to parse XML buffer");
|
||||
return RC_FAIL;
|
||||
}
|
||||
|
||||
return xml_parse_doc(doc);
|
||||
}
|
||||
|
||||
int xml_parse_file(const char *filename) {
|
||||
xmlDocPtr doc; /* the resulting document tree */
|
||||
|
||||
/* This initialize the library and check potential ABI mismatches
|
||||
* between the version it was compiled for and the actual shared
|
||||
* library used.
|
||||
*/
|
||||
LIBXML_TEST_VERSION
|
||||
|
||||
if (filename == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
doc = xmlReadFile (filename, NULL, 0);
|
||||
|
||||
if (doc == NULL) {
|
||||
fprintf (stderr, "Failed to parse %s\n", filename);
|
||||
ui_interface.ui_notification_dialog (DIALOG_WARNING, "Failed to parse file %s", filename);
|
||||
return RC_FAIL;
|
||||
}
|
||||
|
||||
return xml_parse_doc(doc);
|
||||
}
|
||||
|
||||
static int xml_parse_doc(xmlDocPtr doc) {
|
||||
xmlNode *root_element = NULL;
|
||||
types_t *head = NULL;
|
||||
int ret = 0;
|
||||
FILE *dissect_file;
|
||||
|
||||
dissect_file = fopen ("./dissect_xml.txt", "w");
|
||||
|
||||
/* Get the root element node */
|
||||
root_element = xmlDocGetRootElement (doc);
|
||||
|
||||
ret = parse_elements (root_element, &head);
|
||||
|
||||
/* Free the document */
|
||||
xmlFreeDoc (doc);
|
||||
|
||||
/* Free the global variables that may
|
||||
* have been allocated by the parser.
|
||||
*/
|
||||
xmlCleanupParser ();
|
||||
|
||||
if (ret == RC_OK) {
|
||||
resolve_typedefs (&head);
|
||||
resolve_pointer_type (&head);
|
||||
resolve_field (&head);
|
||||
resolve_array (&head);
|
||||
resolve_reference (&head);
|
||||
resolve_struct (&head);
|
||||
resolve_file (&head);
|
||||
resolve_union (&head);
|
||||
CHECK_FCT(locate_root("MessageDef", head, &root));
|
||||
// root->type_hr_display(root, 0);
|
||||
if (dissect_file != NULL) {
|
||||
root->type_file_print (root, 0, dissect_file);
|
||||
}
|
||||
ui_interface.dissector_ready = 1;
|
||||
}
|
||||
|
||||
fclose (dissect_file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int dissect_signal(const uint32_t message_number) {
|
||||
buffer_t *buffer;
|
||||
|
||||
if (root == NULL) {
|
||||
ui_interface.ui_notification_dialog (DIALOG_ERROR, "No message XML file provided");
|
||||
return RC_FAIL;
|
||||
}
|
||||
|
||||
CHECK_FCT(buffer_get_from_mn(message_number, &buffer));
|
||||
|
||||
if (buffer == NULL) {
|
||||
fprintf (stderr, "Failed buffer %u in list\n", message_number);
|
||||
return RC_FAIL;
|
||||
}
|
||||
|
||||
root->type_dissect_from_buffer (root, buffer, 0, 0, INDENT_START);
|
||||
|
||||
return RC_OK;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#include "../rc.h"
|
||||
#include "types.h"
|
||||
|
||||
#ifndef XML_PARSE_H_
|
||||
#define XML_PARSE_H_
|
||||
|
||||
int xml_parse_file(const char *filename);
|
||||
|
||||
int xml_parse_buffer(const char *xml_buffer, const int size);
|
||||
|
||||
int dissect_signal(const uint32_t message_number);
|
||||
|
||||
#endif /* XML_PARSE_H_ */
|
||||
Reference in New Issue
Block a user