--- /dev/null
+Makefile Makefile.in
--- /dev/null
+/* gs_categories.h */
+#ifndef GS_CATEGORIES_H
+#define GS_CATEGORIES_H
+
+/*
+ * Avoid some strange warnings with callback defs.
+ */
+struct s_gs_type;
+
+/*
+ * categories of types
+ */
+enum e_gs_type_category {
+ e_gs_type_cat_undefined = 0,
+
+ e_gs_type_cat_elemental,
+ e_gs_type_cat_struct,
+ e_gs_type_cat_union,
+ e_gs_type_cat_ref,
+ e_gs_type_cat_array,
+ e_gs_type_cat_ignored,
+
+ e_gs_type_cat_invalid
+};
+
+
+/*
+ * Elemental category
+ */
+enum e_gs_elemental_encoding {
+ e_gs_elemental_encoding_undefined = 0,
+
+ e_gs_elemental_encoding_unsigned_integer,
+ e_gs_elemental_encoding_signed_integer,
+ e_gs_elemental_encoding_floating_point,
+
+ e_gs_elemental_encoding_invalid
+};
+
+struct s_gs_cat_elemental {
+ int encoding;
+};
+
+
+/*
+ * Structure category
+ */
+struct s_gs_cat_struct_field {
+
+ char *name;
+ long int offset;
+ int code;
+
+ void (*before_callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data);
+
+ void (*after_callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data);
+};
+
+struct s_gs_cat_struct {
+
+ int nb_fields;
+ struct s_gs_cat_struct_field **field_array;
+};
+
+
+/*
+ * Union category
+ */
+struct s_gs_cat_union_field {
+
+ char *name;
+ int code;
+
+ void (*before_callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data);
+
+ void (*after_callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data);
+};
+
+struct s_gs_cat_union {
+
+ int nb_fields;
+ struct s_gs_cat_union_field **field_array;
+
+ /* callback used to return the field number */
+ int (*callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data);
+};
+
+
+/*
+ * Ref category
+ */
+struct s_gs_cat_ref {
+ int code;
+
+ /* callback used to return the referenced type number */
+ int (*callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data);
+};
+
+
+/*
+ * Array_categorie
+ */
+struct s_gs_cat_array {
+ int code;
+
+ /* element_count < 0 means dynamically defined */
+ long int element_count;
+
+ /* callback used to return the dynamic length */
+ long int (*callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data);
+};
+
+/*
+ * Ignored category
+ */
+struct s_gs_cat_ignored {
+ void *default_value;
+};
+
+gras_type_t *
+gs_type_new_elemental(gras_type_bag_t *p_bag,
+ gras_connection_t *p_connection,
+ const char *name,
+ enum e_gs_elemental_encoding encoding,
+ long int size);
+
+gras_type_t *
+gs_type_new_elemental_with_callback(gras_type_bag_t *p_bag,
+ gras_connection_t *p_connection,
+ const char *name,
+ enum e_gs_elemental_encoding encoding,
+ long int size,
+
+ void (*callback)(void *vars,
+ gras_type_t *p_type,
+ void *data));
+
+
+
+#endif /* GS_CATEGORIES_H */
--- /dev/null
+/* gs_connection.h */
+#ifndef GS_CONNECTION_H
+#define GS_CONNECTION_H
+
+/* used structs */
+struct s_gs_connection;
+struct s_gs_net_driver;
+struct s_gs_type_bag;
+
+enum e_gs_connection_direction {
+ e_gs_connection_direction_unknown = 0,
+ e_gs_connection_direction_outgoing,
+ e_gs_connection_direction_incoming
+};
+
+struct s_gs_connection_ops {
+
+ void
+ (*_init) (struct s_gs_connection *p_connection,
+ void *arg);
+
+ void
+ (*_exit) (struct s_gs_connection *p_connection);
+
+ void
+ (*write) (struct s_gs_connection *p_connection,
+ void *ptr,
+ long int length);
+
+ void
+ (*read) (struct s_gs_connection *p_connection,
+ void *ptr,
+ long int length);
+
+ void
+ (*flush) (struct s_gs_connection *p_connection);
+};
+
+struct s_gs_connection {
+ struct s_gs_connection_ops *connection_ops;
+ struct s_gs_net_driver *p_net_driver;
+ enum e_gs_connection_direction direction;
+ void *specific;
+};
+
+
+#endif /* GS_CONNECTION_H */
--- /dev/null
+/* gs.c */
+
+#include "gs/gs_private.h"
+
+GRAS_LOG_NEW_DEFAULT_CATEGORY(NDR);
+
+void
+gs_init(int argc,
+ char **argv) {
+
+ (void)argc;
+ (void)argv;
+
+ DEBUG0("Init");
+ gs_net_drivers_init();
+ gs_type_drivers_init();
+}
+
+void
+gs_purge_cmd_line(int *argc,
+ char **argv) {
+ (void)argc;
+ (void)argv;
+
+ /**/
+}
+
+void
+gs_exit() {
+ /**/
+}
--- /dev/null
+/* $Id$ */
+
+/* gs_private.h -- stuff internal to grassouillet, the data desc stuff */
+
+
+
+#ifndef _GS_PRIVATE_H
+#define _GS_PRIVATE_H
+
+#include "gras_private.h"
+#include "gs/categories.h"
+#include "gs/connection.h"
+#include "gs/sequence.h"
+#include "gs/net_driver.h"
+#include "gs/net_interface_fd.h"
+#include "gs/type_interface_rl.h"
+#include "gs/type_driver.h"
+#include "gs/message.h"
+#include "gs/type.h"
+
+
+#endif /* _GS_PRIVATE_H */
--- /dev/null
+/* gs_message.c */
+
+#include "gs/gs_private.h"
+
+/*
+ * Sequences
+ */
+static
+struct s_gs_sequence *
+_gs_sequence_alloc(void) {
+ struct s_gs_sequence *p_sequence = NULL;
+ p_sequence = malloc(sizeof(struct s_gs_sequence));
+ return p_sequence;
+}
+
+static
+struct s_gs_sequence *
+_gs_sequence_new(void) {
+ struct s_gs_sequence *p_sequence = NULL;
+
+ p_sequence = _gs_sequence_alloc();
+
+ p_sequence->message = NULL;
+ p_sequence->code = -1;
+ p_sequence->next = NULL;
+
+ return p_sequence;
+}
+
+/*
+ * Messages
+ */
+static
+struct s_gs_message *
+_gs_message_alloc(void) {
+ struct s_gs_message *p_message = NULL;
+
+ p_message = malloc(sizeof(struct s_gs_message));
+
+ return p_message;
+}
+
+struct s_gs_message *
+gs_message_new(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name) {
+
+ struct s_gs_type_bag_ops *bag_ops = p_bag->bag_ops;
+ struct s_gs_message *p_message = NULL;
+
+ p_message = _gs_message_alloc();
+
+ p_message->code = -1;
+ p_message->name = strdup(name);
+
+ p_message->first = NULL;
+ p_message->last = NULL;
+
+ bag_ops->store_message(p_bag, p_connection, p_message);
+
+ return p_message;
+}
+
+
+void
+gs_message_append_new_sequence(struct s_gs_message *p_message,
+ struct s_gs_type *p_type) {
+
+ struct s_gs_sequence *p_sequence = NULL;
+
+ p_sequence = _gs_sequence_new();
+
+ p_sequence->message = p_message;
+ p_sequence->code = p_type->code;
+ p_sequence->next = NULL;
+
+ if (p_message->first) {
+ p_message->last ->next = p_sequence;
+ } else {
+ p_message->first = p_sequence;
+ }
+
+ p_message->last = p_sequence;
+}
+
+
+/*
+ * Send/receive
+ */
+static
+struct s_gs_message_instance *
+_gs_message_instance_alloc(void) {
+ struct s_gs_message_instance *p_message_instance = NULL;
+ p_message_instance = malloc(sizeof (struct s_gs_message_instance));
+ return p_message_instance;
+}
+
+static
+struct s_gs_message_instance *
+_gs_message_instance_new(void) {
+ struct s_gs_message_instance *p_message_instance = NULL;
+
+ p_message_instance = _gs_message_instance_alloc();
+
+ p_message_instance->p_message = NULL;
+ p_message_instance->current = NULL;
+ p_message_instance->p_bag = NULL;
+ p_message_instance->p_connection = NULL;
+
+ return p_message_instance;
+}
+
+/* Send */
+static
+void
+_gs_message_send_type(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx,
+ void *vars,
+ gras_dict_t **p_refs,
+ struct s_gs_type *p_type,
+ void *data);
+
+static
+struct s_gs_type *
+_sg_message_send_get_type_by_code(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx,
+ void *vars,
+ int code) {
+ struct s_gs_type_bag_ops *bops = p_bag->bag_ops;
+ struct s_gs_type *p_type = NULL;
+
+ p_type = bops->get_type_by_code(p_bag, NULL, code);
+
+ if (!bops->check_type_mark(p_bag, p_cnx, p_type->name)) {
+ struct s_gs_type *p_type_type = NULL;
+ gras_dict_t *_refs = NULL;
+
+ p_type_type = bops->get_type_by_name(p_bag, NULL, "_s_gs_type");
+ if (!p_type_type)
+ GS_FAILURE("_s_gs_type default type missing");
+
+ bops->mark_type(p_bag, p_cnx, p_type->name);
+
+ fprintf(stderr, "sending type with code = %d\n", code);
+ gs_vars_enter(vars);
+ _gs_message_send_type(p_bag, p_cnx, vars, &_refs, p_type_type, p_type);
+ gs_vars_leave(vars);
+ fprintf(stderr, "type with code = %d, name = %s sent\n", code, p_type->name);
+ } else {
+ fprintf(stderr, "no need to send type with code = %d, name = %s\n", code, p_type->name);
+ }
+
+ return p_type;
+}
+
+static
+void
+_gs_message_send_type(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx,
+ void *vars,
+ gras_dict_t **p_refs,
+ struct s_gs_type *p_type,
+ void *data) {
+
+ struct s_gs_type_bag_ops *bops = p_bag->bag_ops;
+ struct s_gs_connection_ops *cops = p_cnx->connection_ops;
+
+ if (!*p_refs)
+ gras_dict_new(p_refs);
+
+ if (p_type->category_code > 1)
+ fprintf(stderr, "\n");
+ fprintf(stderr, "sending a %s\n", p_type->name);
+
+ switch (p_type->category_code) {
+
+ case e_gs_type_cat_elemental:
+ {
+ if (p_type->before_callback) {
+ p_type->before_callback(vars, p_type, data);
+ }
+
+ cops->write (p_cnx, data, p_type->size);
+ }
+ break;
+
+ case e_gs_type_cat_struct :
+ {
+ struct s_gs_cat_struct *p_struct = NULL;
+
+ if (p_type->before_callback) {
+ p_type->before_callback(vars, p_type, data);
+ }
+
+ p_struct = p_type->category.struct_data;
+
+ {
+ int nb_fields = 0;
+ int i = 0;
+
+ nb_fields = p_struct->nb_fields;
+
+ while (i < nb_fields) {
+ struct s_gs_cat_struct_field *p_field = NULL;
+ struct s_gs_type *p_field_type = NULL;
+ void *ref = NULL;
+
+ p_field = p_struct->field_array[i];
+ p_field_type = _sg_message_send_get_type_by_code(p_bag, p_cnx, vars, p_field->code);
+ ref = ((char *)data) + p_field->offset;
+
+ if (p_field->before_callback) {
+ p_field->before_callback(vars, p_field_type, ref);
+ }
+
+ _gs_message_send_type(p_bag,
+ p_cnx,
+ vars,
+ p_refs,
+ p_field_type,
+ ref);
+
+ if (p_field->after_callback) {
+ p_field->after_callback(vars, p_field_type, ref);
+ }
+
+ i++;
+ }
+ }
+
+ if (p_type->after_callback) {
+ p_type->after_callback(vars, p_type, data);
+ }
+ }
+ break;
+
+ case e_gs_type_cat_union :
+ {
+ struct s_gs_cat_union *p_union = NULL;
+
+ p_union = p_type->category.union_data;
+
+ {
+ int field_num = 0;
+ struct s_gs_cat_union_field *p_field = NULL;
+ struct s_gs_type *p_field_type = NULL;
+
+ field_num = p_union->callback(vars, p_type, data);
+
+ if ((field_num < 0) || (field_num >= p_union->nb_fields))
+ GS_FAILURE("invalid field index");
+
+ _gs_message_send_type(p_bag,
+ p_cnx,
+ vars,
+ p_refs,
+ bops->get_type_by_name(p_bag, NULL, "signed int"),
+ &field_num);
+
+ p_field = p_union->field_array[field_num];
+ p_field_type = _sg_message_send_get_type_by_code(p_bag, p_cnx, vars, p_field->code);
+
+ if (p_field->before_callback) {
+ p_field->before_callback(vars, p_field_type, data);
+ }
+
+ _gs_message_send_type(p_bag,
+ p_cnx,
+ vars,
+ p_refs,
+ p_field_type,
+ data);
+
+ if (p_field->after_callback) {
+ p_field->after_callback(vars, p_field_type, data);
+ }
+ }
+
+ if (p_type->after_callback) {
+ p_type->after_callback(vars, p_type, data);
+ }
+ }
+ break;
+
+ case e_gs_type_cat_ref :
+ {
+ void *dummy = NULL;
+ void **p_ref = (void **)data;
+ struct s_gs_cat_ref *p_ref_data = NULL;
+ int code = 0;
+
+ p_ref_data = p_type->category.ref_data;
+
+ if (p_ref_data->callback) {
+ code = p_ref_data->callback(vars, p_type, data);
+ }
+
+ if (p_ref_data->code >= 0) {
+ code = p_ref_data->code;
+ } else {
+ _gs_message_send_type(p_bag,
+ p_cnx,
+ vars,
+ p_refs,
+ bops->get_type_by_name(p_bag, NULL, "signed int"),
+ &code);
+ }
+
+ cops->write (p_cnx, data, p_type->size);
+
+ if (*p_ref && !(gras_dict_retrieve_ext(*p_refs, (char *)p_ref, sizeof(void *), &dummy), dummy)) {
+ struct s_gs_type *p_ref_type = NULL;
+
+ fprintf(stderr, "sending data referenced at %p\n", *p_ref);
+ gras_dict_insert_ext(*p_refs, (char *)p_ref, sizeof(void *), p_ref, NULL);
+
+ p_ref_type = _sg_message_send_get_type_by_code(p_bag, p_cnx, vars, code);
+
+ _gs_message_send_type(p_bag,
+ p_cnx,
+ vars,
+ p_refs,
+ p_ref_type,
+ *p_ref);
+
+ } else {
+ /**/
+ fprintf(stderr, "not sending data referenced at %p\n", *p_ref);
+ }
+
+ if (p_type->after_callback) {
+ p_type->after_callback(vars, p_type, data);
+ }
+ }
+ break;
+
+ case e_gs_type_cat_array :
+ {
+ struct s_gs_cat_array *p_array = NULL;
+ long int count = 0;
+ struct s_gs_type *p_element_type = NULL;
+ long int element_size = 0;
+ char *ptr = data;
+
+ p_array = p_type->category.array_data;
+ count = p_array->element_count;
+
+ if (count < 0) {
+ count = p_array->callback(vars, p_type, data);
+ if (count < 0)
+ GS_FAILURE("invalid array element count");
+ } else if (p_array->callback) {
+ (void)p_array->callback(vars, p_type, data);
+ }
+
+ _gs_message_send_type(p_bag,
+ p_cnx,
+ vars,
+ p_refs,
+ bops->get_type_by_name(p_bag, NULL, "signed long int"),
+ &count);
+
+ p_element_type = _sg_message_send_get_type_by_code(p_bag, p_cnx, vars, p_array->code);
+ element_size = p_element_type->aligned_size;
+
+ if (count == 0)
+ goto empty_array;
+
+ while (count --) {
+ _gs_message_send_type(p_bag,
+ p_cnx,
+ vars,
+ p_refs,
+ p_element_type,
+ ptr);
+
+ ptr += element_size;
+ }
+
+ empty_array:
+ if (p_type->after_callback) {
+ p_type->after_callback(vars, p_type, data);
+ }
+ }
+ break;
+
+
+ case e_gs_type_cat_ignored :
+ {
+ if (p_type->before_callback) {
+ p_type->before_callback(vars, p_type, data);
+ }
+ }
+ break;
+
+ default:
+ GS_FAILURE("invalid type");
+ }
+}
+
+struct s_gs_message_instance *
+gs_message_init_send_by_ref(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx,
+ struct s_gs_message *p_message) {
+ struct s_gs_type_bag_ops *bops = p_bag->bag_ops;
+ struct s_gs_message_instance *p_message_instance = NULL;
+ void *vars = NULL;
+
+ vars = gs_vars_alloc();
+
+ if (!bops->check_message_mark(p_bag, p_cnx, p_message->name)) {
+ struct s_gs_type *p_message_type = NULL;
+ gras_dict_t *_refs = NULL;
+ struct s_gs_type *signed_int = NULL;
+
+ signed_int = bops->get_type_by_name(p_bag, NULL, "signed int");
+ p_message_type = bops->get_type_by_name(p_bag, NULL, "_s_gs_message");
+
+ if (!p_message_type)
+ GS_FAILURE("_s_gs_message default type missing");
+
+ bops->mark_message(p_bag, p_cnx, p_message->name);
+
+ _gs_message_send_type(p_bag, p_cnx, vars, &_refs, signed_int, &p_message->code);
+ _gs_message_send_type(p_bag, p_cnx, vars, &_refs, p_message_type, p_message);
+ } else {
+ gras_dict_t *_refs = NULL;
+ struct s_gs_type *signed_int = NULL;
+
+ _gs_message_send_type(p_bag, p_cnx, vars, &_refs, signed_int, &p_message->code);
+ }
+
+ gs_vars_free(vars);
+
+ p_message_instance = _gs_message_instance_new();
+
+ p_message_instance->p_message = p_message;
+ p_message_instance->current = p_message->first;
+ p_message_instance->p_bag = p_bag;
+ p_message_instance->p_connection = p_cnx;
+
+
+ return p_message_instance;
+}
+
+struct s_gs_message_instance *
+gs_message_init_send_by_name(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name) {
+ struct s_gs_type_bag_ops *bag_ops = p_bag->bag_ops;
+ struct s_gs_message *p_message = NULL;
+ struct s_gs_message_instance *p_message_instance = NULL;
+
+ p_message = bag_ops->get_message_by_name(p_bag, NULL, name);
+ p_message_instance = gs_message_init_send_by_ref(p_bag, p_connection, p_message);
+
+ return p_message_instance;
+}
+
+struct s_gs_message_instance *
+gs_message_init_send_by_code(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ int code) {
+ struct s_gs_type_bag_ops *bag_ops = p_bag->bag_ops;
+ struct s_gs_message *p_message = NULL;
+ struct s_gs_message_instance *p_message_instance = NULL;
+
+ p_message = bag_ops->get_message_by_code(p_bag, NULL, code);
+ p_message_instance = gs_message_init_send_by_ref(p_bag, p_connection, p_message);
+
+ return p_message_instance;
+}
+
+void
+gs_message_send_next_sequence_ext(void *vars,
+ struct s_gs_message_instance *p_message_instance,
+ void *data) {
+ struct s_gs_type_bag *p_bag = p_message_instance->p_bag;
+ struct s_gs_connection *p_cnx = p_message_instance->p_connection;
+ struct s_gs_sequence *p_sequence = NULL;
+ struct s_gs_type *p_type = NULL;
+ gras_dict_t *refs = NULL;
+
+ p_sequence = p_message_instance->current;
+ if (!p_sequence)
+ GS_FAILURE("message type has no more sequences");
+
+ p_type = _sg_message_send_get_type_by_code(p_bag, p_cnx, vars, p_sequence->code);
+ _gs_message_send_type(p_message_instance->p_bag,
+ p_message_instance->p_connection,
+ vars,
+ &refs,
+ p_type,
+ data);
+ gras_dict_free(&refs);
+ p_message_instance->current = p_sequence->next;
+}
+
+void
+gs_message_send_next_sequence(struct s_gs_message_instance *p_message_instance,
+ void *data) {
+ void *vars = NULL;
+
+ vars = gs_vars_alloc();
+ gs_message_send_next_sequence_ext(vars, p_message_instance, data);
+ gs_vars_free(vars);
+}
+
+
+/* recv */
+
+
+/*
+ * Note: here we suppose that the remote NULL is a sequence of 'length' bytes set to 0.
+ */
+static
+int
+_gs_is_null(void **p_ptr,
+ long int length) {
+ int i;
+
+ for (i = 0; i < length; i++) {
+ if (((unsigned char *)p_ptr)[i]) {
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+
+static
+void
+_gs_alloc_ref(gras_dict_t **p_refs,
+ long int size,
+ void **p_old_ref,
+ long int length,
+ void **p_new_ref) {
+ void *new_ref = NULL;
+
+ new_ref = malloc((size_t)size);
+ *p_new_ref = new_ref;
+
+ if (p_old_ref && !_gs_is_null(p_old_ref, length)) {
+ p_old_ref = gs_memdup(p_old_ref, (size_t)length);
+ p_new_ref = gs_memdup(&new_ref, sizeof(void *));
+
+ gras_dict_insert_ext(*p_refs,(char *) p_old_ref, length, p_new_ref, NULL);
+ }
+}
+
+static
+void
+_gs_convert_elemental(void *local,
+ struct s_gs_type *p_local_type,
+ void *remote,
+ struct s_gs_type *p_remote_type) {
+ struct s_gs_cat_elemental *p_local_elemental = p_local_type->category.elemental_data;
+ struct s_gs_cat_elemental *p_remote_elemental = p_remote_type->category.elemental_data;
+
+ (void)local;
+ (void)remote;
+
+ if (p_local_elemental->encoding == p_remote_elemental->encoding) {
+ if (p_local_type->size != p_remote_type->size) {
+ GS_FAILURE("size conversion unimplemented");
+ }
+ } else {
+ GS_FAILURE("encoding conversion unimplemented");
+ }
+}
+
+static
+void
+_gs_message_receive_type(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx,
+ gras_dict_t **p_refs,
+ struct s_gs_type *p_type,
+ void **p_old_data,
+ long int old_data_length,
+ void **p_new_data);
+
+static
+struct s_gs_type *
+_sg_message_receive_get_type_by_code(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx,
+ int code) {
+ struct s_gs_type_bag_ops *bops = p_bag->bag_ops;
+ struct s_gs_type *p_type = NULL;
+
+ p_type = bops->get_type_by_code(p_bag, p_cnx, code);
+
+ if (!p_type) {
+ struct s_gs_type *p_type_type = NULL;
+ gras_dict_t *_refs = NULL;
+
+ p_type_type = bops->get_type_by_name(p_bag, p_cnx, "_s_gs_type");
+ if (!p_type_type)
+ GS_FAILURE("_s_gs_type default type missing");
+
+ fprintf(stderr, "need type with code = %d\n", code);
+ _gs_message_receive_type(p_bag, p_cnx, &_refs, p_type_type, NULL, 0, (void **)&p_type);
+ fprintf(stderr, "got type with code = %d, name = %s\n", code, p_type->name);
+
+ bops->store_incoming_type(p_bag, p_cnx, p_type);
+ } else {
+ fprintf(stderr, "already seen type with code = %d, name = %s\n", code, p_type->name);
+ }
+
+
+ return p_type;
+}
+
+static
+void
+_gs_message_receive_type(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx,
+ gras_dict_t **p_refs,
+ struct s_gs_type *p_remote_type,
+ void **p_old_ptr,
+ long int old_ptr_length,
+ void **p_new_ptr) {
+ struct s_gs_type_bag_ops *bops = p_bag->bag_ops;
+ struct s_gs_connection_ops *cops = p_cnx->connection_ops;
+ struct s_gs_type *p_local_type = NULL;
+ void *new_data = *p_new_ptr;
+
+ if (!*p_refs)
+ gras_dict_new(p_refs);
+
+ p_local_type = bops->get_type_by_name(p_bag, NULL, p_remote_type->name);
+ if (p_local_type->category_code > 1)
+ fprintf(stderr, "\n");
+ fprintf(stderr, "receiving a %s\n", p_local_type->name);
+
+ switch (p_remote_type->category_code) {
+
+ case e_gs_type_cat_elemental:
+ {
+ if (!new_data) {
+ _gs_alloc_ref(p_refs, p_local_type->size, p_old_ptr, old_ptr_length, p_new_ptr);
+ new_data = *p_new_ptr;
+ }
+
+ if (p_remote_type->size <= p_local_type->size) {
+ cops->read (p_cnx, new_data, p_remote_type->size);
+ _gs_convert_elemental(new_data, p_local_type, new_data, p_remote_type);
+ } else {
+ void *ptr = NULL;
+
+ ptr = malloc((size_t)p_remote_type->size);
+ cops->read (p_cnx, ptr, p_remote_type->size);
+ _gs_convert_elemental(new_data, p_local_type, ptr, p_remote_type);
+ free(ptr);
+ }
+ }
+ break;
+
+ case e_gs_type_cat_struct :
+ {
+ struct s_gs_cat_struct *p_struct = NULL;
+
+ p_struct = p_remote_type->category.struct_data;
+
+ if (!new_data) {
+ _gs_alloc_ref(p_refs, p_local_type->size, p_old_ptr, old_ptr_length, p_new_ptr);
+ new_data = *p_new_ptr;
+ }
+
+ {
+ int nb_fields = 0;
+ int i = 0;
+
+ nb_fields = p_struct->nb_fields;
+
+ while (i < nb_fields) {
+ struct s_gs_cat_struct_field *p_field = NULL;
+ struct s_gs_type *p_field_type = NULL;
+ void *ref = NULL;
+
+ p_field = p_struct->field_array[i];
+ p_field_type = _sg_message_receive_get_type_by_code(p_bag, p_cnx, p_field->code);
+ ref = ((char *)new_data) + p_field->offset;
+
+ _gs_message_receive_type(p_bag,
+ p_cnx,
+ p_refs,
+ p_field_type,
+ NULL,
+ 0,
+ &ref);
+ i++;
+ }
+ }
+ }
+ break;
+
+ case e_gs_type_cat_union :
+ {
+ struct s_gs_cat_union *p_union = NULL;
+
+ p_union = p_remote_type->category.union_data;
+
+ if (!new_data) {
+ _gs_alloc_ref(p_refs, p_local_type->size, p_old_ptr, old_ptr_length, p_new_ptr);
+ new_data = *p_new_ptr;
+ }
+
+ {
+ int field_num = 0;
+ struct s_gs_cat_union_field *p_field = NULL;
+ struct s_gs_type *p_field_type = NULL;
+
+ {
+ int *p_field_num = &field_num;
+
+ _gs_message_receive_type(p_bag,
+ p_cnx,
+ p_refs,
+ bops->get_type_by_name(p_bag, p_cnx, "signed int"),
+ NULL,
+ 0,
+ (void**)&p_field_num);
+ }
+
+ p_field = p_union->field_array[field_num];
+ p_field_type = _sg_message_receive_get_type_by_code(p_bag, p_cnx, p_field->code);
+
+ _gs_message_receive_type(p_bag,
+ p_cnx,
+ p_refs,
+ p_field_type,
+ NULL,
+ 0,
+ &new_data);
+ }
+ }
+ break;
+
+ case e_gs_type_cat_ref :
+ {
+ void **p_old_ref = NULL;
+ void **p_new_ref = NULL;
+ struct s_gs_cat_ref *p_ref_data = NULL;
+ int code = 0;
+
+ p_ref_data = p_remote_type->category.ref_data;
+ code = p_ref_data->code;
+
+ if (code < 0) {
+ int *p_code = &code;
+
+ _gs_message_receive_type(p_bag,
+ p_cnx,
+ p_refs,
+ bops->get_type_by_name(p_bag, p_cnx, "signed int"),
+ NULL,
+ 0,
+ (void**)&p_code);
+ }
+
+ p_old_ref = malloc((size_t)p_remote_type->size);
+ cops->read (p_cnx, p_old_ref, p_remote_type->size);
+
+ if (!new_data) {
+ _gs_alloc_ref(p_refs, p_local_type->size, p_old_ptr, old_ptr_length, p_new_ptr);
+ new_data = *p_new_ptr;
+ }
+
+ if (!_gs_is_null(p_old_ref, p_remote_type->size)) {
+ if (!(gras_dict_retrieve_ext(*p_refs, (char *)p_old_ref, p_remote_type->size, (void **)&p_new_ref), p_new_ref)) {
+ void *new_ref = NULL;
+ struct s_gs_type *p_ref_type = NULL;
+
+ fprintf(stderr, "receiving data referenced at %p\n", *(void **)p_old_ref);
+ p_ref_type = _sg_message_receive_get_type_by_code(p_bag, p_cnx, code);
+
+ _gs_message_receive_type(p_bag,
+ p_cnx,
+ p_refs,
+ p_ref_type,
+ p_old_ref,
+ p_remote_type->size,
+ &new_ref);
+
+ *(void **)new_data = new_ref;
+ } else {
+ fprintf(stderr, "not receiving data referenced at %p\n", *(void **)p_old_ref);
+ *(void **)new_data = *p_new_ref;
+ }
+ } else {
+ fprintf(stderr, "not receiving data referenced at %p\n", *(void **)p_old_ref);
+ *(void **)new_data = NULL;
+ }
+ }
+ break;
+
+ case e_gs_type_cat_array :
+ {
+ struct s_gs_cat_array *p_array = NULL;
+ long int count = 0;
+ struct s_gs_type *p_element_type = NULL;
+ struct s_gs_type *p_local_element_type = NULL;
+ long int element_size = 0;
+ char *ptr = NULL;
+
+ p_array = p_remote_type->category.array_data;
+
+ {
+ long int *p_count = &count;
+
+ _gs_message_receive_type(p_bag,
+ p_cnx,
+ p_refs,
+ bops->get_type_by_name(p_bag, p_cnx, "signed long int"),
+ NULL,
+ 0,
+ (void**)&p_count);
+ }
+
+ p_element_type = _sg_message_receive_get_type_by_code(p_bag, p_cnx, p_array->code);
+ p_local_element_type = bops->get_type_by_name(p_bag, NULL, p_element_type->name);
+ element_size = p_local_element_type->aligned_size;
+
+ if (!new_data) {
+ _gs_alloc_ref(p_refs, count*element_size, p_old_ptr, old_ptr_length, p_new_ptr);
+ new_data = *p_new_ptr;
+ }
+
+ ptr = new_data;
+
+ if (!count)
+ return;
+
+ while (count --) {
+ _gs_message_receive_type(p_bag,
+ p_cnx,
+ p_refs,
+ p_element_type,
+ NULL,
+ 0,
+ (void**)&ptr);
+
+ ptr += element_size;
+ }
+ }
+ break;
+
+ case e_gs_type_cat_ignored:
+ {
+ struct s_gs_cat_ignored *p_ignored = NULL;
+
+ if (!new_data) {
+ _gs_alloc_ref(p_refs, p_local_type->size, p_old_ptr, old_ptr_length, p_new_ptr);
+ new_data = *p_new_ptr;
+ }
+
+ p_ignored = p_local_type->category.ignored_data;
+
+ if (p_ignored->default_value) {
+ memcpy(new_data, p_ignored->default_value, (size_t)p_local_type->size);
+ }
+ }
+ break;
+
+
+ default:
+ GS_FAILURE("invalid type");
+ }
+}
+
+struct s_gs_message_instance *
+gs_message_init_receive(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx) {
+
+ struct s_gs_type_bag_ops *bops = p_bag->bag_ops;
+ struct s_gs_message_instance *p_message_instance = NULL;
+ int *p_code = NULL;
+ struct s_gs_message *p_message = NULL;
+
+ {
+ gras_dict_t *_refs = NULL;
+ struct s_gs_type *signed_int = NULL;
+
+ signed_int = bops->get_type_by_name(p_bag, p_cnx, "signed int");
+ _gs_message_receive_type(p_bag, p_cnx, &_refs, signed_int, NULL, 0, (void**)&p_code);
+
+ p_message = bops->get_message_by_code(p_bag, p_cnx, *p_code);
+
+ if (!p_message) {
+ struct s_gs_type *p_message_type = NULL;
+ p_message_type = bops->get_type_by_name(p_bag, p_cnx, "_s_gs_message");
+
+ if (!p_message_type)
+ GS_FAILURE("_s_gs_message default type missing");
+
+ _gs_message_receive_type(p_bag, p_cnx, &_refs, p_message_type, NULL, 0, (void **)&p_message);
+
+ bops->store_incoming_message(p_bag, p_cnx, p_message);
+ }
+ }
+
+ p_message_instance = _gs_message_instance_new();
+
+ p_message_instance->p_message = p_message;
+ p_message_instance->current = p_message->first;
+ p_message_instance->p_bag = p_bag;
+ p_message_instance->p_connection = p_cnx;
+
+ return p_message_instance;
+}
+
+void *
+gs_message_receive_next_sequence(struct s_gs_message_instance *p_message_instance) {
+ struct s_gs_type_bag *p_bag = p_message_instance->p_bag;
+ struct s_gs_connection *p_cnx = p_message_instance->p_connection;
+ struct s_gs_sequence *p_sequence = NULL;
+ struct s_gs_type *p_remote_type = NULL;
+ gras_dict_t *refs = NULL;
+ void *data = NULL;
+
+ p_sequence = p_message_instance->current;
+ if (!p_sequence)
+ GS_FAILURE("message type has no more sequences");
+
+ p_remote_type = _sg_message_receive_get_type_by_code(p_bag, p_cnx, p_sequence->code);
+ _gs_message_receive_type(p_bag,
+ p_cnx,
+ &refs,
+ p_remote_type,
+ NULL,
+ 0,
+ &data);
+
+ gras_dict_free(&refs);
+
+ p_message_instance->current = p_sequence->next;
+
+ return data;
+}
+
--- /dev/null
+/* gs_message.h */
+#ifndef GS_MESSAGE_H
+#define GS_MESSAGE_H
+
+struct s_gs_message {
+ int code;
+ char *name;
+
+ struct s_gs_sequence *first;
+ struct s_gs_sequence *last;
+};
+
+struct s_gs_message_instance {
+ struct s_gs_message *p_message;
+ struct s_gs_sequence *current;
+ struct s_gs_type_bag *p_bag;
+ struct s_gs_connection *p_connection;
+};
+
+#endif /* GS_MESSAGE_H */
--- /dev/null
+/* gs_net_driver.c */
+
+#include "gs/gs_private.h"
+
+//GRAS_LOG_NEW_DEFAULT_CATEGORY(FIXME_net_driver);
+
+static
+gras_dict_t *p_net_driver_dict = NULL;
+
+void
+gs_net_drivers_init(void) {
+ gras_error_t errcode;
+
+ TRYFAIL(gras_dict_new(&p_net_driver_dict));
+ TRYFAIL(gras_dict_insert(p_net_driver_dict, "fd", gs_fd_net_driver(), NULL));
+}
+
+
+struct s_gs_net_driver *
+gs_net_driver_init(const char *name) {
+
+ struct s_gs_net_driver_ops *net_driver_ops = NULL;
+ struct s_gs_net_driver *p_net_driver = NULL;
+
+ gras_dict_retrieve(p_net_driver_dict, name, (void **)&net_driver_ops);
+ if (!net_driver_ops)
+ GS_FAILURE("net driver not found");
+
+ p_net_driver = calloc(1, sizeof (struct s_gs_net_driver));
+ p_net_driver->net_ops = net_driver_ops;
+ p_net_driver->connection_ops = NULL;
+ p_net_driver->specific = NULL;
+
+ if (net_driver_ops->_init) {
+ net_driver_ops->_init(p_net_driver);
+ }
+
+ return p_net_driver;
+}
+
+
+
+void
+gs_net_driver_exit(struct s_gs_net_driver *p_net_driver){
+
+ struct s_gs_net_driver_ops *net_driver_ops = NULL;
+
+ net_driver_ops = p_net_driver->net_ops;
+ if (net_driver_ops->_exit) {
+ net_driver_ops->_exit(p_net_driver);
+ }
+
+ p_net_driver->net_ops = NULL;
+
+ if (p_net_driver->specific) {
+ free(p_net_driver->specific);
+ p_net_driver->specific = NULL;
+ }
+
+ free(p_net_driver);
+}
+
+struct s_gs_connection *
+gs_net_connection_connect(struct s_gs_net_driver *p_net_driver,
+ void *arg) {
+
+ struct s_gs_connection_ops *connection_ops = p_net_driver->connection_ops;
+ struct s_gs_connection *p_connection = NULL;
+
+ p_connection = malloc(sizeof (struct s_gs_connection));
+ p_connection->connection_ops = connection_ops;
+ p_connection->p_net_driver = p_net_driver;
+ p_connection->direction = e_gs_connection_direction_outgoing;
+
+ if (connection_ops->_init) {
+ connection_ops->_init(p_connection, arg);
+ }
+
+ return p_connection;
+}
+
+struct s_gs_connection *
+gs_net_connection_accept(struct s_gs_net_driver *p_net_driver,
+ void *arg) {
+
+ struct s_gs_connection_ops *connection_ops = p_net_driver->connection_ops;
+ struct s_gs_connection *p_connection = NULL;
+
+ p_connection = malloc(sizeof (struct s_gs_connection));
+ p_connection->connection_ops = connection_ops;
+ p_connection->p_net_driver = p_net_driver;
+ p_connection->direction = e_gs_connection_direction_incoming;
+
+ if (connection_ops->_init) {
+ connection_ops->_init(p_connection, arg);
+ }
+
+ return p_connection;
+}
+
+void
+gs_net_connection_close(struct s_gs_connection *p_connection) {
+ if (p_connection->connection_ops->_exit) {
+ p_connection->connection_ops->_exit(p_connection);
+ }
+
+ if (p_connection->specific) {
+ free(p_connection->specific);
+ p_connection->specific = NULL;
+ }
+
+ free(p_connection);
+}
--- /dev/null
+/* gs_net_driver.h */
+#ifndef GS_NET_DRIVER_H
+#define GS_NET_DRIVER_H
+
+/* used structs */
+struct s_gs_connection;
+struct s_gs_net_driver;
+
+struct s_gs_net_driver_ops {
+
+ void
+ (*_init) (struct s_gs_net_driver *p_net_driver);
+
+ void
+ (*_exit) (struct s_gs_net_driver *p_net_driver);
+};
+
+struct s_gs_net_driver {
+ struct s_gs_net_driver_ops *net_ops;
+ struct s_gs_connection_ops *connection_ops;
+ void *specific;
+};
+
+
+#endif /* GS_NET_DRIVER_H */
--- /dev/null
+/* gs_fd_net_driver.c */
+
+#include "gs/gs_private.h"
+
+struct s_gs_fd_net_driver {
+ /**/
+ int dummy;
+};
+
+struct s_gs_fd_connection {
+ int fd;
+};
+
+static
+struct s_gs_net_driver_ops *net_driver_ops = NULL;
+
+static
+struct s_gs_connection_ops *connection_ops = NULL;
+
+struct s_gs_net_driver_ops *
+gs_fd_net_driver(void) {
+ if (!connection_ops) {
+ connection_ops = calloc(1, sizeof(struct s_gs_connection_ops));
+
+ connection_ops->_init = gs_fd_connection__init;
+ connection_ops->_exit = gs_fd_connection__exit;
+ connection_ops->write = gs_fd_connection_write;
+ connection_ops->read = gs_fd_connection_read;
+ connection_ops->flush = gs_fd_connection_flush;
+ }
+
+ if (!net_driver_ops) {
+ net_driver_ops = calloc(1, sizeof(struct s_gs_net_driver_ops));
+
+ net_driver_ops->_init = gs_fd__init;
+ net_driver_ops->_exit = gs_fd__exit;
+ }
+
+ return net_driver_ops;
+}
+
+void
+gs_fd__init(struct s_gs_net_driver *p_net_driver) {
+
+ struct s_gs_fd_net_driver *p_fd = NULL;
+
+ p_fd = calloc(1, sizeof(struct s_gs_fd_net_driver));
+ p_net_driver->connection_ops = connection_ops;
+ p_net_driver->specific = p_fd;
+}
+
+void
+gs_fd__exit(struct s_gs_net_driver *p_net_driver) {
+
+ struct s_gs_fd_net_driver *p_fd = p_net_driver->specific;
+
+ free(p_fd);
+
+ p_net_driver->specific = NULL;
+}
+
+
+void
+gs_fd_connection__init(struct s_gs_connection *p_connection,
+ void *arg) {
+
+ struct s_gs_fd_net_connection_arg *p_fd_arg = arg;
+ struct s_gs_fd_connection *p_fd_cnx = NULL;
+
+ p_fd_cnx = calloc(1, sizeof(struct s_gs_fd_connection));
+ p_fd_cnx->fd = p_fd_arg->fd;
+ p_connection->specific = p_fd_cnx;
+}
+
+void
+gs_fd_connection__exit(struct s_gs_connection *p_connection) {
+ struct s_gs_fd_connection *p_fd_cnx = p_connection->specific;
+
+ free(p_fd_cnx);
+
+ p_connection->specific = NULL;
+}
+
+void
+gs_fd_connection_write(struct s_gs_connection *p_connection,
+ void *_ptr,
+ long int length) {
+ struct s_gs_fd_connection *p_fd_cnx = p_connection->specific;
+ unsigned char *ptr = _ptr;
+
+ if (p_connection->direction != e_gs_connection_direction_outgoing)
+ GS_FAILURE("invalid operation");
+
+ while (length) {
+ int status = 0;
+
+ status = write(p_fd_cnx->fd, ptr, (size_t)length);
+ fprintf(stderr, "write(%d, %p, %ld);\n", p_fd_cnx->fd, ptr, length);
+
+ if (status == -1) {
+ perror("write");
+ GS_FAILURE("system call failed");
+ }
+
+ if (status) {
+ length -= status;
+ ptr += status;
+ } else {
+ GS_FAILURE("file descriptor closed");
+ }
+ }
+}
+
+void
+gs_fd_connection_read(struct s_gs_connection *p_connection,
+ void *_ptr,
+ long int length) {
+ struct s_gs_fd_connection *p_fd_cnx = p_connection->specific;
+ unsigned char *ptr = _ptr;
+
+ if (p_connection->direction != e_gs_connection_direction_incoming)
+ GS_FAILURE("invalid operation");
+
+ while (length) {
+ int status = 0;
+
+ status = read(p_fd_cnx->fd, ptr, (size_t)length);
+ fprintf(stderr, "read(%d, %p, %ld);\n", p_fd_cnx->fd, ptr, length);
+
+ if (status == -1) {
+ perror("write");
+ GS_FAILURE("system call failed");
+ }
+
+ if (status) {
+ length -= status;
+ ptr += status;
+ } else {
+ GS_FAILURE("file descriptor closed");
+ }
+ }
+}
+void
+gs_fd_connection_flush(struct s_gs_connection *p_connection) {
+ (void)p_connection;
+
+ /* */
+}
+
--- /dev/null
+/* gs_fd_net_interface.h */
+#ifndef GS_FD_NET_INTERFACE_H
+#define GS_FD_NET_INTERFACE_H
+
+
+struct s_gs_fd_net_connection_arg {
+ int fd;
+};
+
+struct s_gs_net_driver_ops *
+gs_fd_net_driver(void);
+
+
+void
+gs_fd__init(struct s_gs_net_driver *p_driver);
+
+
+void
+gs_fd__exit(struct s_gs_net_driver *p_driver);
+
+
+void
+gs_fd_connection__init(struct s_gs_connection *p_connection,
+ void *arg);
+
+void
+gs_fd_connection__exit(struct s_gs_connection *p_connection);
+
+void
+gs_fd_connection_write(struct s_gs_connection *p_connection,
+ void *ptr,
+ long int length);
+
+void
+gs_fd_connection_read(struct s_gs_connection *p_connection,
+ void *ptr,
+ long int length);
+void
+gs_fd_connection_flush(struct s_gs_connection *p_connection);
+#endif /* GS_FD_NET_INTERFACE_H */
--- /dev/null
+/* $Id$ */
+
+/* gs/parse.c -- automatic parsing of data structures */
+
+/* Authors: Arnaud Legrand, Martin Quinson */
+
+#include "gs/gs_private.h"
+#include "gs/parse.yy.h"
+
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(NDR_parse,NDR);
+
+typedef struct s_type_modifier{
+ short is_unsigned;
+ short is_short;
+ short is_long;
+
+ short is_struct;
+ short is_union;
+ short is_enum;
+
+ short is_ref;
+} type_modifier_t;
+
+extern char *gs_parse_text;
+
+/* prototypes */
+static void parse_type_modifier(type_modifier_t *type_modifier);
+static void print_type_modifier(type_modifier_t type_modifier);
+
+static gras_error_t parse_statement(gras_type_bag_t *p_bag,
+ const char *definition,
+ gras_dynar_t **dynar);
+static gras_type_t * parse_struct(gras_type_bag_t *p_bag,
+ const char *definition);
+static gras_type_t * parse_typedef(gras_type_bag_t *p_bag,
+ const char *definition);
+
+/* local functions */
+static void parse_type_modifier(type_modifier_t *type_modifier) {
+ do {
+ if (gs_parse_tok_num == GS_PARSE_TOKEN_STAR) {
+ DEBUG0("This is a reference");
+ type_modifier->is_ref++;
+
+ } else if (!strcmp(gs_parse_text,"unsigned")) {
+ DEBUG0("This is an unsigned");
+ type_modifier->is_unsigned = 1;
+
+ } else if (!strcmp(gs_parse_text,"short")) {
+ DEBUG0("This is short");
+ type_modifier->is_short = 1;
+
+ } else if (!strcmp(gs_parse_text,"long")) {
+ DEBUG0("This is long");
+ type_modifier->is_long++; /* "long long" needs love */
+
+ } else if (!strcmp(gs_parse_text,"struct")) {
+ DEBUG0("This is a struct");
+ type_modifier->is_struct = 1;
+
+ } else if (!strcmp(gs_parse_text,"union")) {
+ DEBUG0("This is an union");
+ type_modifier->is_union = 1;
+
+ } else if (!strcmp(gs_parse_text,"enum")) {
+ DEBUG0("This is an enum");
+ type_modifier->is_enum = 1;
+
+ } else {
+ break;
+ }
+
+
+ gs_parse_tok_num = gs_parse_lex_n_dump();
+ if((gs_parse_tok_num != GS_PARSE_TOKEN_WORD) &&
+ (gs_parse_tok_num != GS_PARSE_TOKEN_STAR))
+ break;
+ } while(1);
+}
+
+static void print_type_modifier(type_modifier_t tm) {
+ int i;
+
+ if (tm.is_unsigned) printf("(unsigned) ");
+ if (tm.is_short) printf("(short) ");
+ for (i=0 ; i<tm.is_long ; i++) printf("(long) ");
+
+ if(tm.is_struct) printf("(struct) ");
+ if(tm.is_enum) printf("(enum) ");
+ if(tm.is_union) printf("(union) ");
+
+ for (i=0 ; i<tm.is_ref ; i++) printf("(ref) ");
+}
+
+/* FIXME: Missing function. Do not free the dynar... */
+#define gs_type_copy(a) a
+
+static gras_error_t parse_statement(gras_type_bag_t *bag,
+ const char *definition,
+ gras_dynar_t **dynar) {
+ gras_error_t errcode;
+ char buffname[512];
+
+ char *base_type = NULL;
+ type_modifier_t tm;
+
+ gras_type_t *res;
+
+ int starred = 0;
+ int expect_a_colon = 0;
+
+ gras_dynar_reset(*dynar);
+ memset(&tm,0,sizeof(tm));
+
+ gs_parse_tok_num = gs_parse_lex_n_dump();
+ if(gs_parse_tok_num == GS_PARSE_TOKEN_RP) {
+ return mismatch_error; /* end of the englobing structure or union */
+ }
+ DEBUG0("Parse a new statement.");
+
+
+ if(gs_parse_tok_num != GS_PARSE_TOKEN_WORD) {
+ fprintf(stderr,
+ "Unparsable symbol: found a typeless statement (got '%s' instead). Definition was:\n%s\n",
+ gs_parse_text, definition);
+ abort();
+ }
+
+ /**** get the type modifier of this statement ****/
+ parse_type_modifier(&tm);
+
+ /* FIXME: This does not detect recursive definitions at all
+ if (tm.is_union || tm.is_enum || tm.is_struct) {
+ fprintf(stderr,
+ "Cannot handle recursive type definition yet. Definition was:\n%s\n",
+ definition);
+ abort();
+ }*/
+
+ /**** get the base type, giving "short a" the needed love ****/
+ if (!tm.is_union &&
+ !tm.is_enum &&
+ !tm.is_struct &&
+
+ (tm.is_short || tm.is_long || tm.is_unsigned) &&
+
+ strcmp(gs_parse_text,"char") &&
+ strcmp(gs_parse_text,"float") &&
+ strcmp(gs_parse_text,"double") &&
+ strcmp(gs_parse_text,"int") ) {
+
+ /* bastard user, they omited "int" ! */
+ base_type=strdup("int");
+ DEBUG0("the base type is 'int', which were omited");
+ } else {
+ base_type=strdup(gs_parse_text);
+ DEBUG1("the base type is '%s'",base_type);
+ gs_parse_tok_num = gs_parse_lex_n_dump();
+ }
+
+ /**** build the base type for latter use ****/
+ if (tm.is_union) {
+ fprintf(stderr,
+ "Cannot handle union yet (need annotation to get the callback), sorry. Definition was:\n%s\n",
+ definition);
+ abort();
+
+ /* FIXME
+ sprintf(buffname,"union %s",base_type);
+ res = bag->bag_ops->get_type_by_name(bag, NULL, buffname);
+ if (!res) {
+ res = gs_type_new_union(bag,NULL,buffname);
+ }
+ */
+
+ } else if (tm.is_enum) {
+ fprintf(stderr,
+ "Cannot handle enum yet (need grassouillet's love), sorry. Definition was:\n%s\n",
+ definition);
+ abort();
+ /* FIXME
+ sprintf(buffname,"enum %s",base_type);
+ res = bag->bag_ops->get_type_by_name(bag, NULL, bufname);
+ if (!res) {
+ res = gs_type_new_enum(bag,connection,buffname);
+ }
+ */
+
+ } else if (tm.is_struct) {
+ sprintf(buffname,"struct %s",base_type);
+ res = bag->bag_ops->get_type_by_name(bag, NULL, buffname);
+ if (!res) {
+ res = gs_type_new_struct(bag,NULL,buffname);
+ }
+
+ /* Let's code like Alvin ;) */
+#define gs_parse_get_or_create(name,func) \
+ (bag->bag_ops->get_type_by_name(bag, NULL, #name) ? \
+ bag->bag_ops->get_type_by_name(bag, NULL, #name) : \
+ gs_type_new_##func##_elemental(bag, NULL, \
+ #name, sizeof(name)) \
+ )
+
+ } else if (tm.is_unsigned) {
+ if (!strcmp(base_type,"int")) {
+ if (tm.is_long == 2) {
+ res = gs_parse_get_or_create(unsigned long long int,unsigned_integer);
+ } else if (tm.is_long) {
+ res = gs_parse_get_or_create(unsigned long int,unsigned_integer);
+ } else if (tm.is_short) {
+ res = gs_parse_get_or_create(unsigned short int,unsigned_integer);
+ } else {
+ res = gs_parse_get_or_create(unsigned int,unsigned_integer);
+ }
+
+ } else if (!strcmp(base_type, "char")) {
+ res = gs_parse_get_or_create(unsigned char,unsigned_integer);
+
+ } else { /* impossible, gcc parses this shit before us */
+ abort();
+ }
+
+ } else if (!strcmp(base_type, "float")) {
+ /* no modificator allowed by gcc */
+ res = gs_parse_get_or_create(float,floating_point);
+
+ } else { /* signed integer elemental */
+ if (!strcmp(base_type,"int")) {
+ if (tm.is_long == 2) {
+ res = gs_parse_get_or_create(signed long long int,signed_integer);
+ } else if (tm.is_long) {
+ res = gs_parse_get_or_create(signed long int,signed_integer);
+ } else if (tm.is_short) {
+ res = gs_parse_get_or_create(signed short int,signed_integer);
+ } else {
+ res = gs_parse_get_or_create(int,unsigned_integer);
+ }
+
+ } else if (!strcmp(base_type, "char")) {
+ res = gs_parse_get_or_create(char,unsigned_integer);
+
+ } else { /* impossible */
+ abort();
+ }
+
+ }
+
+ if (tm.is_ref) {
+ fprintf(stderr,
+ "Cannot handle references yet (need annotations), sorry. Definition was:\n%s\n",
+ definition);
+ abort();
+ /* Should build ref on the current res (beware of int****) */
+ }
+
+ /**** look for the symbols of this type ****/
+ expect_a_colon = 0;
+ for( /* no initialization */ ;
+
+ ((gs_parse_tok_num != GS_PARSE_TOKEN_EMPTY) &&
+ (gs_parse_tok_num != GS_PARSE_TOKEN_SEMI_COLON)) ;
+
+ gs_parse_tok_num = gs_parse_lex_n_dump() ) {
+
+ if(expect_a_colon) {
+ if(gs_parse_tok_num == GS_PARSE_TOKEN_COLON) {
+ expect_a_colon = 0;
+ continue;
+ } else {
+ fprintf(stderr,
+ "Unparsable symbol: Expected a comma (','), got '%s' instead. Definition was:\n%s\n",
+ gs_parse_text, definition);
+ abort();
+ }
+ } else if(gs_parse_tok_num == GS_PARSE_TOKEN_COLON) {
+ fprintf(stderr,
+ "Unparsable symbol: Unexpected comma (','). Definition was:\n%s\n",
+ definition);
+ abort();
+ }
+
+ if(gs_parse_tok_num == GS_PARSE_TOKEN_STAR) {
+ starred = 1;
+ }
+
+ /* found a symbol name. Build the type and push it to dynar */
+ if(gs_parse_tok_num == GS_PARSE_TOKEN_WORD) {
+ if (starred) {
+ /* FIXME: Build a ref or array on the base type */
+ fprintf(stderr,
+ "Cannot handle references yet (need annotations), sorry. Definition was:\n%s\n",
+ definition);
+ abort();
+ }
+ DEBUG1("Encountered the variable (field?) %s",gs_parse_text);
+
+ TRY(gras_dynar_push(*dynar, &gs_type_copy(base_type)));
+ starred = 0;
+ expect_a_colon = 1;
+ continue;
+ }
+
+ fprintf(stderr,
+ "Unparasable symbol: Maybe a def struct in a def struct or so. The definition was:\n%s\n",
+ definition);
+ abort();
+ }
+
+ DEBUG0("End of this statement");
+ return no_error;
+}
+
+static gras_type_t *parse_struct(gras_type_bag_t *bag,
+ const char *definition) {
+
+ gras_error_t errcode;
+ char buffname[32];
+ static int anonymous_struct=0;
+
+ gras_dynar_t *fields;
+
+ gras_type_t *field;
+ int i;
+
+ gras_type_t *struct_type;
+
+ errcode=gras_dynar_new(&fields,sizeof(gras_type_t*),NULL);
+ if (errcode != no_error)
+ return NULL;
+ /* FIXME: the dynar content leaks because there is no gs_type_free.
+ But that's not a problem because each member are the same element since there is no gs_type_copy ;)
+ */
+
+ /* Create the struct descriptor */
+ if (gs_parse_tok_num == GS_PARSE_TOKEN_WORD) {
+ struct_type = gs_type_new_struct(bag,NULL, gs_parse_text);
+ DEBUG1("Parse the struct '%s'", gs_parse_text);
+ gs_parse_tok_num = gs_parse_lex_n_dump();
+ } else {
+ sprintf(buffname,"anonymous struct %d",anonymous_struct++);
+ DEBUG1("Parse the anonymous struct nb %d", anonymous_struct);
+ struct_type = gs_type_new_struct(bag,NULL,buffname);
+ }
+
+ if (gs_parse_tok_num != GS_PARSE_TOKEN_LP) {
+ fprintf(stderr,
+ "Unparasable symbol: I looked for a struct definition, but got %s instead of '{'. The definition was:\n%s\n",
+ gs_parse_text,definition);
+ abort();
+ }
+
+ /* Parse the fields */
+ for (errcode=parse_statement(bag,definition,&fields);
+ errcode == no_error ;
+ errcode=parse_statement(bag,definition,&fields)) {
+
+ DEBUG1("This statement contained %d fields",gras_dynar_length(fields));
+ gras_dynar_foreach(fields,i, field) {
+ char fname[128];
+ static int field_count=0;
+ sprintf(fname,"%d",field_count++);
+ DEBUG0("Append a field");
+ gs_type_struct_append_field(struct_type,fname,field);
+ }
+ }
+ if (errcode != mismatch_error)
+ return NULL; /* FIXME: LEAK! */
+
+ /* terminates */
+ if (gs_parse_tok_num != GS_PARSE_TOKEN_RP) {
+ fprintf(stderr,
+ "Unparasable symbol: Expected '}' at the end of struct definition, got '%s'. The definition was:\n%s\n",
+ gs_parse_text,definition);
+ abort();
+ }
+
+ gs_parse_tok_num = gs_parse_lex_n_dump();
+
+ gras_dynar_free(fields);
+ return struct_type;
+}
+
+static gras_type_t * parse_typedef(gras_type_bag_t *bag,
+ const char *definition) {
+
+ type_modifier_t tm;
+
+ gras_type_t *struct_desc=NULL;
+ gras_type_t *typedef_desc=NULL;
+
+ memset(&tm,0,sizeof(tm));
+
+ /* get the aliased type */
+ parse_type_modifier(&tm);
+
+ if (tm.is_struct) {
+ struct_desc = parse_struct(bag,definition);
+ }
+
+ parse_type_modifier(&tm);
+
+ if (tm.is_ref) {
+ fprintf(stderr,
+ "Cannot handle reference without annotation. Definition was:\n%s\n",
+ definition);
+ abort();
+ }
+
+ /* get the aliasing name */
+ if (gs_parse_tok_num != GS_PARSE_TOKEN_WORD) {
+ fprintf(stderr,
+ "Unparsable typedef: Expected the alias name, and got '%s'.\n%s\n",
+ gs_parse_text,definition);
+ abort();
+ }
+
+ /* (FIXME: should) build the alias */
+ fprintf(stderr, "Cannot handle typedef yet (need love from grassouillet), sorry. Definition was: \n%s\n",definition);
+ abort();
+
+ // res=gs_type_new_typedef(bag, NULL, strdup(gs_parse_text) );
+
+ return typedef_desc;
+}
+
+/* main function */
+gras_type_t *
+_gs_type_parse(gras_type_bag_t *bag,
+ const char *definition) {
+
+ gras_type_t * res=NULL;
+
+ /* init */
+ DEBUG1("_gs_type_parse(%s)",definition);
+ gs_parse_pointer_string_init(definition);
+
+ /* Do I have a typedef, or a raw struct ?*/
+ gs_parse_tok_num = gs_parse_lex_n_dump();
+
+ if ((gs_parse_tok_num == GS_PARSE_TOKEN_WORD) && (!strcmp(gs_parse_text,"struct"))) {
+ gs_parse_tok_num = gs_parse_lex_n_dump();
+ res = parse_struct(bag,definition);
+
+ } else if ((gs_parse_tok_num == GS_PARSE_TOKEN_WORD) && (!strcmp(gs_parse_text,"typedef"))) {
+ gs_parse_tok_num = gs_parse_lex_n_dump();
+ res = parse_typedef(bag,definition);
+
+ } else {
+ fprintf(stderr,"Failed to parse the following symbol (not a struct neither a typedef) :\n%s\n",definition);
+ abort();
+ }
+
+ gs_parse_pointer_string_close();
+ DEBUG1("end of _gs_type_parse(%s)",definition);
+
+ return res;
+}
+
+
--- /dev/null
+#define yy_create_buffer gs_parse__create_buffer
+#define yy_delete_buffer gs_parse__delete_buffer
+#define yy_scan_buffer gs_parse__scan_buffer
+#define yy_scan_string gs_parse__scan_string
+#define yy_scan_bytes gs_parse__scan_bytes
+#define yy_flex_debug gs_parse__flex_debug
+#define yy_init_buffer gs_parse__init_buffer
+#define yy_flush_buffer gs_parse__flush_buffer
+#define yy_load_buffer_state gs_parse__load_buffer_state
+#define yy_switch_to_buffer gs_parse__switch_to_buffer
+#define yyin gs_parse_in
+#define yyleng gs_parse_leng
+#define yylex gs_parse_lex
+#define yyout gs_parse_out
+#define yyrestart gs_parse_restart
+#define yytext gs_parse_text
+
+#line 19 "gs/parse.yy.c"
+/* A lexical scanner generated by flex */
+
+/* Scanner skeleton version:
+ *
+ */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+
+#include <stdio.h>
+#include <errno.h>
+
+/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
+#ifdef c_plusplus
+#ifndef __cplusplus
+#define __cplusplus
+#endif
+#endif
+
+
+#ifdef __cplusplus
+
+#include <stdlib.h>
+#ifndef _WIN32
+#include <unistd.h>
+#endif
+
+/* Use prototypes in function declarations. */
+#define YY_USE_PROTOS
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else /* ! __cplusplus */
+
+#if __STDC__
+
+#define YY_USE_PROTOS
+#define YY_USE_CONST
+
+#endif /* __STDC__ */
+#endif /* ! __cplusplus */
+
+#ifdef __TURBOC__
+ #pragma warn -rch
+ #pragma warn -use
+#include <io.h>
+#include <stdlib.h>
+#define YY_USE_CONST
+#define YY_USE_PROTOS
+#endif
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+
+#ifdef YY_USE_PROTOS
+#define YY_PROTO(proto) proto
+#else
+#define YY_PROTO(proto) ()
+#endif
+
+
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+
+/* Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index. If the signed char is negative,
+ * we want to instead treat it as an 8-bit unsigned char, hence the
+ * double cast.
+ */
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+
+/* Enter a start condition. This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN yy_start = 1 + 2 *
+
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state. The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START ((yy_start - 1) / 2)
+#define YYSTATE YY_START
+
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE yyrestart( yyin )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#define YY_BUF_SIZE 16384
+
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+
+extern int yyleng;
+extern FILE *yyin, *yyout;
+
+#define EOB_ACT_CONTINUE_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+/* The funky do-while in the following #define is used to turn the definition
+ * int a single C statement (which needs a semi-colon terminator). This
+ * avoids problems with code like:
+ *
+ * if ( condition_holds )
+ * yyless( 5 );
+ * else
+ * do_something_else();
+ *
+ * Prior to using the do-while the compiler would get upset at the
+ * "else" because it interpreted the "if" statement as being all
+ * done when it reached the ';' after the yyless() call.
+ */
+
+/* Return all but the first 'n' matched characters back to the input stream. */
+
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ *yy_cp = yy_hold_char; \
+ YY_RESTORE_YY_MORE_OFFSET \
+ yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \
+ YY_DO_BEFORE_ACTION; /* set up yytext again */ \
+ } \
+ while ( 0 )
+
+#define unput(c) yyunput( c, yytext_ptr )
+
+/* The following is because we cannot portably get our hands on size_t
+ * (without autoconf's help, which isn't available because we want
+ * flex-generated scanners to compile on their own).
+ */
+typedef unsigned int yy_size_t;
+
+
+struct yy_buffer_state
+ {
+ FILE *yy_input_file;
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ int yy_n_chars;
+
+ /* Whether we "own" the buffer - i.e., we know we created it,
+ * and can realloc() it to grow it, and should free() it to
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ int yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+ /* When an EOF's been seen but there's still some text to process
+ * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+ * shouldn't try reading from the input source any more. We might
+ * still have a bunch of tokens to match, though, because of
+ * possible backing-up.
+ *
+ * When we actually see the EOF, we change the status to "new"
+ * (via yyrestart()), so that the user can continue scanning by
+ * just pointing yyin at a new input file.
+ */
+#define YY_BUFFER_EOF_PENDING 2
+ };
+
+static YY_BUFFER_STATE yy_current_buffer = 0;
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
+ */
+#define YY_CURRENT_BUFFER yy_current_buffer
+
+
+/* yy_hold_char holds the character lost when yytext is formed. */
+static char yy_hold_char;
+
+static int yy_n_chars; /* number of characters read into yy_ch_buf */
+
+
+int yyleng;
+
+/* Points to current character in buffer. */
+static char *yy_c_buf_p = (char *) 0;
+static int yy_init = 1; /* whether we need to initialize */
+static int yy_start = 0; /* start state number */
+
+/* Flag which is used to allow yywrap()'s to do buffer switches
+ * instead of setting up a fresh yyin. A bit of a hack ...
+ */
+static int yy_did_buffer_switch_on_eof;
+
+void yyrestart YY_PROTO(( FILE *input_file ));
+
+void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer ));
+void yy_load_buffer_state YY_PROTO(( void ));
+YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size ));
+void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b ));
+void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file ));
+void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b ));
+#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer )
+
+YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size ));
+YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str ));
+YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len ));
+
+static void *yy_flex_alloc YY_PROTO(( yy_size_t ));
+static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t ));
+static void yy_flex_free YY_PROTO(( void * ));
+
+#define yy_new_buffer yy_create_buffer
+
+#define yy_set_interactive(is_interactive) \
+ { \
+ if ( ! yy_current_buffer ) \
+ yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
+ yy_current_buffer->yy_is_interactive = is_interactive; \
+ }
+
+#define yy_set_bol(at_bol) \
+ { \
+ if ( ! yy_current_buffer ) \
+ yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
+ yy_current_buffer->yy_at_bol = at_bol; \
+ }
+
+#define YY_AT_BOL() (yy_current_buffer->yy_at_bol)
+
+
+#define yywrap() 1
+#define YY_SKIP_YYWRAP
+typedef unsigned char YY_CHAR;
+FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
+typedef int yy_state_type;
+extern char *yytext;
+#define yytext_ptr yytext
+
+static yy_state_type yy_get_previous_state YY_PROTO(( void ));
+static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state ));
+static int yy_get_next_buffer YY_PROTO(( void ));
+static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up yytext.
+ */
+#define YY_DO_BEFORE_ACTION \
+ yytext_ptr = yy_bp; \
+ yyleng = (int) (yy_cp - yy_bp); \
+ yy_hold_char = *yy_cp; \
+ *yy_cp = '\0'; \
+ yy_c_buf_p = yy_cp;
+
+#define YY_NUM_RULES 28
+#define YY_END_OF_BUFFER 29
+static yyconst short int yy_accept[51] =
+ { 0,
+ 20, 20, 4, 4, 0, 0, 0, 0, 29, 27,
+ 26, 8, 23, 25, 20, 27, 24, 21, 22, 4,
+ 6, 5, 28, 28, 19, 10, 9, 28, 20, 2,
+ 1, 4, 5, 5, 7, 3, 19, 18, 11, 12,
+ 16, 17, 13, 15, 14, 1, 11, 12, 11, 0
+ } ;
+
+static yyconst int yy_ec[256] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 3, 1, 1, 1, 1, 1, 1,
+ 1, 4, 1, 5, 6, 6, 7, 8, 8, 8,
+ 8, 8, 8, 8, 8, 9, 9, 1, 10, 1,
+ 1, 1, 1, 1, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 1, 11, 1, 1, 6, 1, 6, 12, 6, 6,
+
+ 6, 13, 6, 6, 6, 6, 6, 6, 6, 14,
+ 6, 6, 6, 15, 6, 16, 6, 6, 6, 6,
+ 6, 6, 17, 1, 18, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1
+ } ;
+
+static yyconst int yy_meta[19] =
+ { 0,
+ 1, 2, 3, 4, 1, 5, 1, 5, 5, 1,
+ 3, 5, 5, 5, 5, 5, 1, 1
+ } ;
+
+static yyconst short int yy_base[59] =
+ { 0,
+ 0, 0, 17, 18, 81, 78, 21, 31, 83, 102,
+ 102, 102, 102, 102, 0, 21, 102, 102, 102, 0,
+ 102, 22, 102, 37, 0, 102, 102, 42, 0, 102,
+ 0, 0, 23, 31, 102, 102, 0, 102, 28, 31,
+ 102, 102, 102, 102, 102, 0, 53, 55, 57, 102,
+ 66, 71, 76, 26, 81, 86, 91, 96
+ } ;
+
+static yyconst short int yy_def[59] =
+ { 0,
+ 50, 1, 51, 51, 52, 52, 53, 53, 50, 50,
+ 50, 50, 50, 50, 54, 50, 50, 50, 50, 55,
+ 50, 56, 50, 50, 57, 50, 50, 50, 54, 50,
+ 58, 55, 56, 56, 50, 50, 57, 50, 50, 50,
+ 50, 50, 50, 50, 50, 58, 50, 50, 50, 0,
+ 50, 50, 50, 50, 50, 50, 50, 50
+ } ;
+
+static yyconst short int yy_nxt[121] =
+ { 0,
+ 10, 11, 12, 13, 14, 15, 16, 15, 15, 17,
+ 10, 15, 15, 15, 15, 15, 18, 19, 21, 21,
+ 22, 22, 26, 27, 30, 34, 50, 31, 35, 50,
+ 29, 28, 26, 27, 34, 47, 48, 35, 48, 48,
+ 36, 28, 38, 38, 38, 38, 38, 38, 38, 39,
+ 40, 38, 38, 41, 42, 43, 44, 45, 38, 38,
+ 49, 48, 48, 48, 48, 48, 20, 20, 20, 20,
+ 20, 23, 23, 23, 23, 23, 25, 25, 25, 25,
+ 25, 32, 50, 32, 24, 32, 33, 24, 33, 33,
+ 33, 37, 50, 50, 37, 37, 46, 50, 46, 46,
+
+ 46, 9, 50, 50, 50, 50, 50, 50, 50, 50,
+ 50, 50, 50, 50, 50, 50, 50, 50, 50, 50
+ } ;
+
+static yyconst short int yy_chk[121] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 3, 4,
+ 3, 4, 7, 7, 16, 22, 33, 16, 22, 33,
+ 54, 7, 8, 8, 34, 39, 39, 34, 40, 40,
+ 24, 8, 28, 28, 28, 28, 28, 28, 28, 28,
+ 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+ 47, 47, 48, 48, 49, 49, 51, 51, 51, 51,
+ 51, 52, 52, 52, 52, 52, 53, 53, 53, 53,
+ 53, 55, 9, 55, 6, 55, 56, 5, 56, 56,
+ 56, 57, 0, 0, 57, 57, 58, 0, 58, 58,
+
+ 58, 50, 50, 50, 50, 50, 50, 50, 50, 50,
+ 50, 50, 50, 50, 50, 50, 50, 50, 50, 50
+ } ;
+
+static yy_state_type yy_last_accepting_state;
+static char *yy_last_accepting_cpos;
+
+/* The intent behind this definition is that it'll catch
+ * any uses of REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+char *yytext;
+#line 1 "gs/parse.yy.l"
+#define INITIAL 0
+/**** MSG_LICENCE DO NOT REMOVE ****/
+#line 5 "gs/parse.yy.l"
+#include"gs/gs_private.h"
+#include"gs/parse.yy.h"
+#include <string.h>
+ YY_BUFFER_STATE input_buffer;
+ FILE *file_to_parse;
+
+ int gs_parse_line_pos = 1;
+ int gs_parse_char_pos = 0;
+ int gs_parse_tok_num = 0;
+#define comment 1
+#define foo 2
+#define str 3
+
+#line 441 "gs/parse.yy.c"
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int yywrap YY_PROTO(( void ));
+#else
+extern int yywrap YY_PROTO(( void ));
+#endif
+#endif
+
+#ifndef YY_NO_UNPUT
+static void yyunput YY_PROTO(( int c, char *buf_ptr ));
+#endif
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int ));
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen YY_PROTO(( yyconst char * ));
+#endif
+
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+static int yyinput YY_PROTO(( void ));
+#else
+static int input YY_PROTO(( void ));
+#endif
+#endif
+
+#if YY_STACK_USED
+static int yy_start_stack_ptr = 0;
+static int yy_start_stack_depth = 0;
+static int *yy_start_stack = 0;
+#ifndef YY_NO_PUSH_STATE
+static void yy_push_state YY_PROTO(( int new_state ));
+#endif
+#ifndef YY_NO_POP_STATE
+static void yy_pop_state YY_PROTO(( void ));
+#endif
+#ifndef YY_NO_TOP_STATE
+static int yy_top_state YY_PROTO(( void ));
+#endif
+
+#else
+#define YY_NO_PUSH_STATE 1
+#define YY_NO_POP_STATE 1
+#define YY_NO_TOP_STATE 1
+#endif
+
+#ifdef YY_MALLOC_DECL
+YY_MALLOC_DECL
+#else
+#if __STDC__
+#ifndef __cplusplus
+#include <stdlib.h>
+#endif
+#else
+/* Just try to get by without declaring the routines. This will fail
+ * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int)
+ * or sizeof(void*) != sizeof(int).
+ */
+#endif
+#endif
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#define YY_READ_BUF_SIZE 8192
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+
+#ifndef ECHO
+/* This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
+#endif
+
+/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+ if ( yy_current_buffer->yy_is_interactive ) \
+ { \
+ int c = '*', n; \
+ for ( n = 0; n < max_size && \
+ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
+ buf[n] = (char) c; \
+ if ( c == '\n' ) \
+ buf[n++] = (char) c; \
+ if ( c == EOF && ferror( yyin ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ result = n; \
+ } \
+ else \
+ { \
+ errno=0; \
+ while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
+ { \
+ if( errno != EINTR) \
+ { \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ break; \
+ } \
+ errno=0; \
+ clearerr(yyin); \
+ } \
+ }
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
+#endif
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL int yylex YY_PROTO(( void ))
+#endif
+
+/* Code executed at the beginning of each rule, after yytext and yyleng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+#define YY_RULE_SETUP \
+ YY_USER_ACTION
+
+YY_DECL
+ {
+ register yy_state_type yy_current_state;
+ register char *yy_cp, *yy_bp;
+ register int yy_act;
+
+#line 21 "gs/parse.yy.l"
+
+ int comment_caller=0;
+
+ char string_buf[GS_PARSE_MAX_STR_CONST];
+ char *string_buf_ptr = NULL;
+
+#line 610 "gs/parse.yy.c"
+
+ if ( yy_init )
+ {
+ yy_init = 0;
+
+#ifdef YY_USER_INIT
+ YY_USER_INIT;
+#endif
+
+ if ( ! yy_start )
+ yy_start = 1; /* first start state */
+
+ if ( ! yyin )
+ yyin = stdin;
+
+ if ( ! yyout )
+ yyout = stdout;
+
+ if ( ! yy_current_buffer )
+ yy_current_buffer =
+ yy_create_buffer( yyin, YY_BUF_SIZE );
+
+ yy_load_buffer_state();
+ }
+
+ while ( 1 ) /* loops until end-of-file is reached */
+ {
+ yy_cp = yy_c_buf_p;
+
+ /* Support of yytext. */
+ *yy_cp = yy_hold_char;
+
+ /* yy_bp points to the position in yy_ch_buf of the start of
+ * the current run.
+ */
+ yy_bp = yy_cp;
+
+ yy_current_state = yy_start;
+yy_match:
+ do
+ {
+ register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
+ if ( yy_accept[yy_current_state] )
+ {
+ yy_last_accepting_state = yy_current_state;
+ yy_last_accepting_cpos = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 51 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ ++yy_cp;
+ }
+ while ( yy_base[yy_current_state] != 102 );
+
+yy_find_action:
+ yy_act = yy_accept[yy_current_state];
+ if ( yy_act == 0 )
+ { /* have to back up */
+ yy_cp = yy_last_accepting_cpos;
+ yy_current_state = yy_last_accepting_state;
+ yy_act = yy_accept[yy_current_state];
+ }
+
+ YY_DO_BEFORE_ACTION;
+
+
+do_action: /* This label is used only to access EOF actions. */
+
+
+ switch ( yy_act )
+ { /* beginning of action switch */
+ case 0: /* must back up */
+ /* undo the effects of YY_DO_BEFORE_ACTION */
+ *yy_cp = yy_hold_char;
+ yy_cp = yy_last_accepting_cpos;
+ yy_current_state = yy_last_accepting_state;
+ goto yy_find_action;
+
+case 1:
+YY_RULE_SETUP
+#line 27 "gs/parse.yy.l"
+
+ YY_BREAK
+case 2:
+YY_RULE_SETUP
+#line 28 "gs/parse.yy.l"
+{
+ comment_caller = INITIAL;
+ BEGIN(comment);
+ }
+ YY_BREAK
+case 3:
+YY_RULE_SETUP
+#line 33 "gs/parse.yy.l"
+{
+ comment_caller = foo;
+ BEGIN(comment);
+ }
+ YY_BREAK
+case 4:
+YY_RULE_SETUP
+#line 38 "gs/parse.yy.l"
+/* eat anything that's not a '*' */
+ YY_BREAK
+case 5:
+YY_RULE_SETUP
+#line 39 "gs/parse.yy.l"
+/* eat up '*'s not followed by '/'s */
+ YY_BREAK
+case 6:
+YY_RULE_SETUP
+#line 40 "gs/parse.yy.l"
+{++gs_parse_line_pos;gs_parse_char_pos=0;}
+ YY_BREAK
+case 7:
+YY_RULE_SETUP
+#line 41 "gs/parse.yy.l"
+BEGIN(comment_caller);
+ YY_BREAK
+case 8:
+YY_RULE_SETUP
+#line 43 "gs/parse.yy.l"
+string_buf_ptr = string_buf; gs_parse_char_pos++; BEGIN(str);
+ YY_BREAK
+case 9:
+YY_RULE_SETUP
+#line 45 "gs/parse.yy.l"
+{ /* saw closing quote - all done */
+ BEGIN(INITIAL);
+ *string_buf_ptr = '\0';
+ yytext=string_buf;
+ gs_parse_char_pos++;
+ return GS_PARSE_TOKEN_WORD;
+ /* return string constant token type and
+ * value to parser
+ */
+ }
+ YY_BREAK
+case 10:
+YY_RULE_SETUP
+#line 56 "gs/parse.yy.l"
+{
+ /* error - unterminated string constant */
+ /* generate error message */
+ }
+ YY_BREAK
+case 11:
+YY_RULE_SETUP
+#line 61 "gs/parse.yy.l"
+{
+ /* octal escape sequence */
+ int result;
+
+ (void) sscanf( yytext + 1, "%o", &result );
+
+ if ( result > 0xff )
+ /* error, constant is out-of-bounds */
+
+ *string_buf_ptr++ = result;
+ gs_parse_char_pos++;
+ }
+ YY_BREAK
+case 12:
+YY_RULE_SETUP
+#line 74 "gs/parse.yy.l"
+{
+ /* generate error - bad escape sequence; something
+ * like '\48' or '\0777777'
+ */
+ }
+ YY_BREAK
+case 13:
+YY_RULE_SETUP
+#line 80 "gs/parse.yy.l"
+{*string_buf_ptr++ = '\n'; gs_parse_char_pos++;}
+ YY_BREAK
+case 14:
+YY_RULE_SETUP
+#line 81 "gs/parse.yy.l"
+{*string_buf_ptr++ = '\t'; gs_parse_char_pos++;}
+ YY_BREAK
+case 15:
+YY_RULE_SETUP
+#line 82 "gs/parse.yy.l"
+{*string_buf_ptr++ = '\r'; gs_parse_char_pos++;}
+ YY_BREAK
+case 16:
+YY_RULE_SETUP
+#line 83 "gs/parse.yy.l"
+{*string_buf_ptr++ = '\b'; gs_parse_char_pos++;}
+ YY_BREAK
+case 17:
+YY_RULE_SETUP
+#line 84 "gs/parse.yy.l"
+{*string_buf_ptr++ = '\f'; gs_parse_char_pos++;}
+ YY_BREAK
+case 18:
+YY_RULE_SETUP
+#line 86 "gs/parse.yy.l"
+{*string_buf_ptr++ = yytext[1];
+ if(yytext[1]=='\n') {
+ ++gs_parse_line_pos;gs_parse_char_pos=0;
+ } else { gs_parse_char_pos++;}
+ }
+ YY_BREAK
+case 19:
+YY_RULE_SETUP
+#line 92 "gs/parse.yy.l"
+{
+ char *yptr = yytext;
+
+ while ( *yptr )
+ *string_buf_ptr++ = *yptr++;
+ gs_parse_char_pos++;
+ }
+ YY_BREAK
+case 20:
+YY_RULE_SETUP
+#line 100 "gs/parse.yy.l"
+{ gs_parse_char_pos+= strlen(yytext); return(GS_PARSE_TOKEN_WORD);}
+ YY_BREAK
+case 21:
+YY_RULE_SETUP
+#line 101 "gs/parse.yy.l"
+{ gs_parse_char_pos++; return(GS_PARSE_TOKEN_LP);}
+ YY_BREAK
+case 22:
+YY_RULE_SETUP
+#line 102 "gs/parse.yy.l"
+{ gs_parse_char_pos++;return(GS_PARSE_TOKEN_RP);}
+ YY_BREAK
+case 23:
+YY_RULE_SETUP
+#line 103 "gs/parse.yy.l"
+{ gs_parse_char_pos++;return(GS_PARSE_TOKEN_STAR);}
+ YY_BREAK
+case 24:
+YY_RULE_SETUP
+#line 104 "gs/parse.yy.l"
+{ gs_parse_char_pos++;return(GS_PARSE_TOKEN_SEMI_COLON);}
+ YY_BREAK
+case 25:
+YY_RULE_SETUP
+#line 105 "gs/parse.yy.l"
+{ gs_parse_char_pos++;return(GS_PARSE_TOKEN_COLON);}
+ YY_BREAK
+case 26:
+YY_RULE_SETUP
+#line 106 "gs/parse.yy.l"
+{ gs_parse_line_pos++; gs_parse_char_pos=0;}
+ YY_BREAK
+case 27:
+YY_RULE_SETUP
+#line 107 "gs/parse.yy.l"
+{ gs_parse_char_pos++;}
+ YY_BREAK
+case 28:
+YY_RULE_SETUP
+#line 108 "gs/parse.yy.l"
+ECHO;
+ YY_BREAK
+#line 876 "gs/parse.yy.c"
+case YY_STATE_EOF(INITIAL):
+case YY_STATE_EOF(comment):
+case YY_STATE_EOF(foo):
+case YY_STATE_EOF(str):
+ yyterminate();
+
+ case YY_END_OF_BUFFER:
+ {
+ /* Amount of text matched not including the EOB char. */
+ int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1;
+
+ /* Undo the effects of YY_DO_BEFORE_ACTION. */
+ *yy_cp = yy_hold_char;
+ YY_RESTORE_YY_MORE_OFFSET
+
+ if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW )
+ {
+ /* We're scanning a new file or input source. It's
+ * possible that this happened because the user
+ * just pointed yyin at a new source and called
+ * yylex(). If so, then we have to assure
+ * consistency between yy_current_buffer and our
+ * globals. Here is the right place to do so, because
+ * this is the first action (other than possibly a
+ * back-up) that will match for the new input source.
+ */
+ yy_n_chars = yy_current_buffer->yy_n_chars;
+ yy_current_buffer->yy_input_file = yyin;
+ yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL;
+ }
+
+ /* Note that here we test for yy_c_buf_p "<=" to the position
+ * of the first EOB in the buffer, since yy_c_buf_p will
+ * already have been incremented past the NUL character
+ * (since all states make transitions on EOB to the
+ * end-of-buffer state). Contrast this with the test
+ * in input().
+ */
+ if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] )
+ { /* This was really a NUL. */
+ yy_state_type yy_next_state;
+
+ yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state();
+
+ /* Okay, we're now positioned to make the NUL
+ * transition. We couldn't have
+ * yy_get_previous_state() go ahead and do it
+ * for us because it doesn't know how to deal
+ * with the possibility of jamming (and we don't
+ * want to build jamming into it because then it
+ * will run more slowly).
+ */
+
+ yy_next_state = yy_try_NUL_trans( yy_current_state );
+
+ yy_bp = yytext_ptr + YY_MORE_ADJ;
+
+ if ( yy_next_state )
+ {
+ /* Consume the NUL. */
+ yy_cp = ++yy_c_buf_p;
+ yy_current_state = yy_next_state;
+ goto yy_match;
+ }
+
+ else
+ {
+ yy_cp = yy_c_buf_p;
+ goto yy_find_action;
+ }
+ }
+
+ else switch ( yy_get_next_buffer() )
+ {
+ case EOB_ACT_END_OF_FILE:
+ {
+ yy_did_buffer_switch_on_eof = 0;
+
+ if ( yywrap() )
+ {
+ /* Note: because we've taken care in
+ * yy_get_next_buffer() to have set up
+ * yytext, we can now set up
+ * yy_c_buf_p so that if some total
+ * hoser (like flex itself) wants to
+ * call the scanner after we return the
+ * YY_NULL, it'll still work - another
+ * YY_NULL will get returned.
+ */
+ yy_c_buf_p = yytext_ptr + YY_MORE_ADJ;
+
+ yy_act = YY_STATE_EOF(YY_START);
+ goto do_action;
+ }
+
+ else
+ {
+ if ( ! yy_did_buffer_switch_on_eof )
+ YY_NEW_FILE;
+ }
+ break;
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ yy_c_buf_p =
+ yytext_ptr + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state();
+
+ yy_cp = yy_c_buf_p;
+ yy_bp = yytext_ptr + YY_MORE_ADJ;
+ goto yy_match;
+
+ case EOB_ACT_LAST_MATCH:
+ yy_c_buf_p =
+ &yy_current_buffer->yy_ch_buf[yy_n_chars];
+
+ yy_current_state = yy_get_previous_state();
+
+ yy_cp = yy_c_buf_p;
+ yy_bp = yytext_ptr + YY_MORE_ADJ;
+ goto yy_find_action;
+ }
+ break;
+ }
+
+ default:
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--no action found" );
+ } /* end of action switch */
+ } /* end of scanning one token */
+ } /* end of yylex */
+
+
+/* yy_get_next_buffer - try to read in a new buffer
+ *
+ * Returns a code representing an action:
+ * EOB_ACT_LAST_MATCH -
+ * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ * EOB_ACT_END_OF_FILE - end of file
+ */
+
+static int yy_get_next_buffer()
+ {
+ register char *dest = yy_current_buffer->yy_ch_buf;
+ register char *source = yytext_ptr;
+ register int number_to_move, i;
+ int ret_val;
+
+ if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] )
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--end of buffer missed" );
+
+ if ( yy_current_buffer->yy_fill_buffer == 0 )
+ { /* Don't try to fill the buffer, so this is an EOF. */
+ if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 )
+ {
+ /* We matched a single character, the EOB, so
+ * treat this as a final EOF.
+ */
+ return EOB_ACT_END_OF_FILE;
+ }
+
+ else
+ {
+ /* We matched some text prior to the EOB, first
+ * process it.
+ */
+ return EOB_ACT_LAST_MATCH;
+ }
+ }
+
+ /* Try to read more data. */
+
+ /* First move last chars to start of buffer. */
+ number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1;
+
+ for ( i = 0; i < number_to_move; ++i )
+ *(dest++) = *(source++);
+
+ if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+ /* don't do the read, it's not guaranteed to return an EOF,
+ * just force an EOF
+ */
+ yy_current_buffer->yy_n_chars = yy_n_chars = 0;
+
+ else
+ {
+ int num_to_read =
+ yy_current_buffer->yy_buf_size - number_to_move - 1;
+
+ while ( num_to_read <= 0 )
+ { /* Not enough room in the buffer - grow it. */
+#ifdef YY_USES_REJECT
+ YY_FATAL_ERROR(
+"input buffer overflow, can't enlarge buffer because scanner uses REJECT" );
+#else
+
+ /* just a shorter name for the current buffer */
+ YY_BUFFER_STATE b = yy_current_buffer;
+
+ int yy_c_buf_p_offset =
+ (int) (yy_c_buf_p - b->yy_ch_buf);
+
+ if ( b->yy_is_our_buffer )
+ {
+ int new_size = b->yy_buf_size * 2;
+
+ if ( new_size <= 0 )
+ b->yy_buf_size += b->yy_buf_size / 8;
+ else
+ b->yy_buf_size *= 2;
+
+ b->yy_ch_buf = (char *)
+ /* Include room in for 2 EOB chars. */
+ yy_flex_realloc( (void *) b->yy_ch_buf,
+ b->yy_buf_size + 2 );
+ }
+ else
+ /* Can't grow it, we don't own it. */
+ b->yy_ch_buf = 0;
+
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR(
+ "fatal error - scanner input buffer overflow" );
+
+ yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+ num_to_read = yy_current_buffer->yy_buf_size -
+ number_to_move - 1;
+#endif
+ }
+
+ if ( num_to_read > YY_READ_BUF_SIZE )
+ num_to_read = YY_READ_BUF_SIZE;
+
+ /* Read in more data. */
+ YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]),
+ yy_n_chars, num_to_read );
+
+ yy_current_buffer->yy_n_chars = yy_n_chars;
+ }
+
+ if ( yy_n_chars == 0 )
+ {
+ if ( number_to_move == YY_MORE_ADJ )
+ {
+ ret_val = EOB_ACT_END_OF_FILE;
+ yyrestart( yyin );
+ }
+
+ else
+ {
+ ret_val = EOB_ACT_LAST_MATCH;
+ yy_current_buffer->yy_buffer_status =
+ YY_BUFFER_EOF_PENDING;
+ }
+ }
+
+ else
+ ret_val = EOB_ACT_CONTINUE_SCAN;
+
+ yy_n_chars += number_to_move;
+ yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
+ yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
+
+ yytext_ptr = &yy_current_buffer->yy_ch_buf[0];
+
+ return ret_val;
+ }
+
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+static yy_state_type yy_get_previous_state()
+ {
+ register yy_state_type yy_current_state;
+ register char *yy_cp;
+
+ yy_current_state = yy_start;
+
+ for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )
+ {
+ register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+ if ( yy_accept[yy_current_state] )
+ {
+ yy_last_accepting_state = yy_current_state;
+ yy_last_accepting_cpos = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 51 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ }
+
+ return yy_current_state;
+ }
+
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
+ *
+ * synopsis
+ * next_state = yy_try_NUL_trans( current_state );
+ */
+
+#ifdef YY_USE_PROTOS
+static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state )
+#else
+static yy_state_type yy_try_NUL_trans( yy_current_state )
+yy_state_type yy_current_state;
+#endif
+ {
+ register int yy_is_jam;
+ register char *yy_cp = yy_c_buf_p;
+
+ register YY_CHAR yy_c = 1;
+ if ( yy_accept[yy_current_state] )
+ {
+ yy_last_accepting_state = yy_current_state;
+ yy_last_accepting_cpos = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 51 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ yy_is_jam = (yy_current_state == 50);
+
+ return yy_is_jam ? 0 : yy_current_state;
+ }
+
+
+#ifndef YY_NO_UNPUT
+#ifdef YY_USE_PROTOS
+static void yyunput( int c, register char *yy_bp )
+#else
+static void yyunput( c, yy_bp )
+int c;
+register char *yy_bp;
+#endif
+ {
+ register char *yy_cp = yy_c_buf_p;
+
+ /* undo effects of setting up yytext */
+ *yy_cp = yy_hold_char;
+
+ if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
+ { /* need to shift things up to make room */
+ /* +2 for EOB chars. */
+ register int number_to_move = yy_n_chars + 2;
+ register char *dest = &yy_current_buffer->yy_ch_buf[
+ yy_current_buffer->yy_buf_size + 2];
+ register char *source =
+ &yy_current_buffer->yy_ch_buf[number_to_move];
+
+ while ( source > yy_current_buffer->yy_ch_buf )
+ *--dest = *--source;
+
+ yy_cp += (int) (dest - source);
+ yy_bp += (int) (dest - source);
+ yy_current_buffer->yy_n_chars =
+ yy_n_chars = yy_current_buffer->yy_buf_size;
+
+ if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
+ YY_FATAL_ERROR( "flex scanner push-back overflow" );
+ }
+
+ *--yy_cp = (char) c;
+
+
+ yytext_ptr = yy_bp;
+ yy_hold_char = *yy_cp;
+ yy_c_buf_p = yy_cp;
+ }
+#endif /* ifndef YY_NO_UNPUT */
+
+
+#ifdef __cplusplus
+static int yyinput()
+#else
+static int input()
+#endif
+ {
+ int c;
+
+ *yy_c_buf_p = yy_hold_char;
+
+ if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
+ {
+ /* yy_c_buf_p now points to the character we want to return.
+ * If this occurs *before* the EOB characters, then it's a
+ * valid NUL; if not, then we've hit the end of the buffer.
+ */
+ if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] )
+ /* This was really a NUL. */
+ *yy_c_buf_p = '\0';
+
+ else
+ { /* need more input */
+ int offset = yy_c_buf_p - yytext_ptr;
+ ++yy_c_buf_p;
+
+ switch ( yy_get_next_buffer() )
+ {
+ case EOB_ACT_LAST_MATCH:
+ /* This happens because yy_g_n_b()
+ * sees that we've accumulated a
+ * token and flags that we need to
+ * try matching the token before
+ * proceeding. But for input(),
+ * there's no matching to consider.
+ * So convert the EOB_ACT_LAST_MATCH
+ * to EOB_ACT_END_OF_FILE.
+ */
+
+ /* Reset buffer status. */
+ yyrestart( yyin );
+
+ /* fall through */
+
+ case EOB_ACT_END_OF_FILE:
+ {
+ if ( yywrap() )
+ return EOF;
+
+ if ( ! yy_did_buffer_switch_on_eof )
+ YY_NEW_FILE;
+#ifdef __cplusplus
+ return yyinput();
+#else
+ return input();
+#endif
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ yy_c_buf_p = yytext_ptr + offset;
+ break;
+ }
+ }
+ }
+
+ c = *(unsigned char *) yy_c_buf_p; /* cast for 8-bit char's */
+ *yy_c_buf_p = '\0'; /* preserve yytext */
+ yy_hold_char = *++yy_c_buf_p;
+
+
+ return c;
+ }
+
+
+#ifdef YY_USE_PROTOS
+void yyrestart( FILE *input_file )
+#else
+void yyrestart( input_file )
+FILE *input_file;
+#endif
+ {
+ if ( ! yy_current_buffer )
+ yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE );
+
+ yy_init_buffer( yy_current_buffer, input_file );
+ yy_load_buffer_state();
+ }
+
+
+#ifdef YY_USE_PROTOS
+void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
+#else
+void yy_switch_to_buffer( new_buffer )
+YY_BUFFER_STATE new_buffer;
+#endif
+ {
+ if ( yy_current_buffer == new_buffer )
+ return;
+
+ if ( yy_current_buffer )
+ {
+ /* Flush out information for old buffer. */
+ *yy_c_buf_p = yy_hold_char;
+ yy_current_buffer->yy_buf_pos = yy_c_buf_p;
+ yy_current_buffer->yy_n_chars = yy_n_chars;
+ }
+
+ yy_current_buffer = new_buffer;
+ yy_load_buffer_state();
+
+ /* We don't actually know whether we did this switch during
+ * EOF (yywrap()) processing, but the only time this flag
+ * is looked at is after yywrap() is called, so it's safe
+ * to go ahead and always set it.
+ */
+ yy_did_buffer_switch_on_eof = 1;
+ }
+
+
+#ifdef YY_USE_PROTOS
+void yy_load_buffer_state( void )
+#else
+void yy_load_buffer_state()
+#endif
+ {
+ yy_n_chars = yy_current_buffer->yy_n_chars;
+ yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos;
+ yyin = yy_current_buffer->yy_input_file;
+ yy_hold_char = *yy_c_buf_p;
+ }
+
+
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
+#else
+YY_BUFFER_STATE yy_create_buffer( file, size )
+FILE *file;
+int size;
+#endif
+ {
+ YY_BUFFER_STATE b;
+
+ b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+ b->yy_buf_size = size;
+
+ /* yy_ch_buf has to be 2 characters longer than the size given because
+ * we need to put in 2 end-of-buffer characters.
+ */
+ b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 );
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+ b->yy_is_our_buffer = 1;
+
+ yy_init_buffer( b, file );
+
+ return b;
+ }
+
+
+#ifdef YY_USE_PROTOS
+void yy_delete_buffer( YY_BUFFER_STATE b )
+#else
+void yy_delete_buffer( b )
+YY_BUFFER_STATE b;
+#endif
+ {
+ if ( ! b )
+ return;
+
+ if ( b == yy_current_buffer )
+ yy_current_buffer = (YY_BUFFER_STATE) 0;
+
+ if ( b->yy_is_our_buffer )
+ yy_flex_free( (void *) b->yy_ch_buf );
+
+ yy_flex_free( (void *) b );
+ }
+
+
+#ifndef _WIN32
+#include <unistd.h>
+#else
+#ifndef YY_ALWAYS_INTERACTIVE
+#ifndef YY_NEVER_INTERACTIVE
+extern int isatty YY_PROTO(( int ));
+#endif
+#endif
+#endif
+
+#ifdef YY_USE_PROTOS
+void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
+#else
+void yy_init_buffer( b, file )
+YY_BUFFER_STATE b;
+FILE *file;
+#endif
+
+
+ {
+ yy_flush_buffer( b );
+
+ b->yy_input_file = file;
+ b->yy_fill_buffer = 1;
+
+#if YY_ALWAYS_INTERACTIVE
+ b->yy_is_interactive = 1;
+#else
+#if YY_NEVER_INTERACTIVE
+ b->yy_is_interactive = 0;
+#else
+ b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
+#endif
+#endif
+ }
+
+
+#ifdef YY_USE_PROTOS
+void yy_flush_buffer( YY_BUFFER_STATE b )
+#else
+void yy_flush_buffer( b )
+YY_BUFFER_STATE b;
+#endif
+
+ {
+ if ( ! b )
+ return;
+
+ b->yy_n_chars = 0;
+
+ /* We always need two end-of-buffer characters. The first causes
+ * a transition to the end-of-buffer state. The second causes
+ * a jam in that state.
+ */
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+ b->yy_buf_pos = &b->yy_ch_buf[0];
+
+ b->yy_at_bol = 1;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ if ( b == yy_current_buffer )
+ yy_load_buffer_state();
+ }
+
+
+#ifndef YY_NO_SCAN_BUFFER
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size )
+#else
+YY_BUFFER_STATE yy_scan_buffer( base, size )
+char *base;
+yy_size_t size;
+#endif
+ {
+ YY_BUFFER_STATE b;
+
+ if ( size < 2 ||
+ base[size-2] != YY_END_OF_BUFFER_CHAR ||
+ base[size-1] != YY_END_OF_BUFFER_CHAR )
+ /* They forgot to leave room for the EOB's. */
+ return 0;
+
+ b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
+
+ b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
+ b->yy_buf_pos = b->yy_ch_buf = base;
+ b->yy_is_our_buffer = 0;
+ b->yy_input_file = 0;
+ b->yy_n_chars = b->yy_buf_size;
+ b->yy_is_interactive = 0;
+ b->yy_at_bol = 1;
+ b->yy_fill_buffer = 0;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ yy_switch_to_buffer( b );
+
+ return b;
+ }
+#endif
+
+
+#ifndef YY_NO_SCAN_STRING
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str )
+#else
+YY_BUFFER_STATE yy_scan_string( yy_str )
+yyconst char *yy_str;
+#endif
+ {
+ int len;
+ for ( len = 0; yy_str[len]; ++len )
+ ;
+
+ return yy_scan_bytes( yy_str, len );
+ }
+#endif
+
+
+#ifndef YY_NO_SCAN_BYTES
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len )
+#else
+YY_BUFFER_STATE yy_scan_bytes( bytes, len )
+yyconst char *bytes;
+int len;
+#endif
+ {
+ YY_BUFFER_STATE b;
+ char *buf;
+ yy_size_t n;
+ int i;
+
+ /* Get memory for full buffer, including space for trailing EOB's. */
+ n = len + 2;
+ buf = (char *) yy_flex_alloc( n );
+ if ( ! buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
+
+ for ( i = 0; i < len; ++i )
+ buf[i] = bytes[i];
+
+ buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR;
+
+ b = yy_scan_buffer( buf, n );
+ if ( ! b )
+ YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
+
+ /* It's okay to grow etc. this buffer, and we should throw it
+ * away when we're done.
+ */
+ b->yy_is_our_buffer = 1;
+
+ return b;
+ }
+#endif
+
+
+#ifndef YY_NO_PUSH_STATE
+#ifdef YY_USE_PROTOS
+static void yy_push_state( int new_state )
+#else
+static void yy_push_state( new_state )
+int new_state;
+#endif
+ {
+ if ( yy_start_stack_ptr >= yy_start_stack_depth )
+ {
+ yy_size_t new_size;
+
+ yy_start_stack_depth += YY_START_STACK_INCR;
+ new_size = yy_start_stack_depth * sizeof( int );
+
+ if ( ! yy_start_stack )
+ yy_start_stack = (int *) yy_flex_alloc( new_size );
+
+ else
+ yy_start_stack = (int *) yy_flex_realloc(
+ (void *) yy_start_stack, new_size );
+
+ if ( ! yy_start_stack )
+ YY_FATAL_ERROR(
+ "out of memory expanding start-condition stack" );
+ }
+
+ yy_start_stack[yy_start_stack_ptr++] = YY_START;
+
+ BEGIN(new_state);
+ }
+#endif
+
+
+#ifndef YY_NO_POP_STATE
+static void yy_pop_state()
+ {
+ if ( --yy_start_stack_ptr < 0 )
+ YY_FATAL_ERROR( "start-condition stack underflow" );
+
+ BEGIN(yy_start_stack[yy_start_stack_ptr]);
+ }
+#endif
+
+
+#ifndef YY_NO_TOP_STATE
+static int yy_top_state()
+ {
+ return yy_start_stack[yy_start_stack_ptr - 1];
+ }
+#endif
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+#ifdef YY_USE_PROTOS
+static void yy_fatal_error( yyconst char msg[] )
+#else
+static void yy_fatal_error( msg )
+char msg[];
+#endif
+ {
+ (void) fprintf( stderr, "%s\n", msg );
+ exit( YY_EXIT_FAILURE );
+ }
+
+
+
+/* Redefine yyless() so it works in section 3 code. */
+
+#undef yyless
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ yytext[yyleng] = yy_hold_char; \
+ yy_c_buf_p = yytext + n; \
+ yy_hold_char = *yy_c_buf_p; \
+ *yy_c_buf_p = '\0'; \
+ yyleng = n; \
+ } \
+ while ( 0 )
+
+
+/* Internal utility routines. */
+
+#ifndef yytext_ptr
+#ifdef YY_USE_PROTOS
+static void yy_flex_strncpy( char *s1, yyconst char *s2, int n )
+#else
+static void yy_flex_strncpy( s1, s2, n )
+char *s1;
+yyconst char *s2;
+int n;
+#endif
+ {
+ register int i;
+ for ( i = 0; i < n; ++i )
+ s1[i] = s2[i];
+ }
+#endif
+
+#ifdef YY_NEED_STRLEN
+#ifdef YY_USE_PROTOS
+static int yy_flex_strlen( yyconst char *s )
+#else
+static int yy_flex_strlen( s )
+yyconst char *s;
+#endif
+ {
+ register int n;
+ for ( n = 0; s[n]; ++n )
+ ;
+
+ return n;
+ }
+#endif
+
+
+#ifdef YY_USE_PROTOS
+static void *yy_flex_alloc( yy_size_t size )
+#else
+static void *yy_flex_alloc( size )
+yy_size_t size;
+#endif
+ {
+ return (void *) malloc( size );
+ }
+
+#ifdef YY_USE_PROTOS
+static void *yy_flex_realloc( void *ptr, yy_size_t size )
+#else
+static void *yy_flex_realloc( ptr, size )
+void *ptr;
+yy_size_t size;
+#endif
+ {
+ /* The cast to (char *) in the following accommodates both
+ * implementations that use char* generic pointers, and those
+ * that use void* generic pointers. It works with the latter
+ * because both ANSI C and C++ allow castless assignment from
+ * any pointer type to void*, and deal with argument conversions
+ * as though doing an assignment.
+ */
+ return (void *) realloc( (char *) ptr, size );
+ }
+
+#ifdef YY_USE_PROTOS
+static void yy_flex_free( void *ptr )
+#else
+static void yy_flex_free( ptr )
+void *ptr;
+#endif
+ {
+ free( ptr );
+ }
+
+#if YY_MAIN
+int main()
+ {
+ yylex();
+ return 0;
+ }
+#endif
+#line 108 "gs/parse.yy.l"
+
+/* {space}+ { return(TOKEN_SPACE);} */
+
+void gs_parse_dump(void) {
+ switch(gs_parse_tok_num) {
+ case GS_PARSE_TOKEN_LP : {printf("TOKEN_LP ");break;}
+ case GS_PARSE_TOKEN_RP : {printf("TOKEN_RP ");break;}
+ case GS_PARSE_TOKEN_WORD : {printf("TOKEN_WORD ");break;}
+ // case GS_PARSE_TOKEN_SPACE : {printf("TOKEN_SPACE ");break;}
+ // case GS_PARSE_TOKEN_COMMENT : {printf("TOKEN_COMMENT ");break;}
+ case GS_PARSE_TOKEN_NEWLINE : {printf("TOKEN_NEWLINE\n");return;}
+ case GS_PARSE_TOKEN_EMPTY : {printf("TOKEN_EMPTY\n");return;}
+ default : {printf("Unknown token %d\n", gs_parse_tok_num);return;}
+ }
+ printf("-->%s<-- [line %d, pos %d]\n",yytext,gs_parse_line_pos,gs_parse_char_pos);
+ return;
+}
+
+int gs_parse_lex_n_dump(void) {
+ gs_parse_tok_num = gs_parse_lex();
+ // voir_val();
+ // gs_parse_char_pos += strlen(yytext);
+ return(gs_parse_tok_num);
+}
+
+void gs_parse_pointer_init(const char *file) {
+ file_to_parse = fopen(file,"r");
+ input_buffer = yy_create_buffer( file_to_parse, 10 );
+ yy_switch_to_buffer(input_buffer);
+
+ gs_parse_line_pos = 1;
+ gs_parse_char_pos = 0;
+ gs_parse_tok_num = 0;
+}
+
+void gs_parse_pointer_close(void) {
+ yy_delete_buffer(input_buffer);
+ fclose(file_to_parse);
+
+ gs_parse_line_pos = 1;
+ gs_parse_char_pos = 0;
+ gs_parse_tok_num = 0;
+}
+
+
+void gs_parse_pointer_string_init(const char *string_to_parse) {
+ input_buffer = yy_scan_string (string_to_parse);
+ yy_switch_to_buffer(input_buffer);
+
+ gs_parse_line_pos = 1;
+ gs_parse_char_pos = 0;
+ gs_parse_tok_num = 0;
+}
+
+void gs_parse_pointer_string_close(void) {
+ yy_delete_buffer(input_buffer);
+
+ gs_parse_line_pos = 1;
+ gs_parse_char_pos = 0;
+ gs_parse_tok_num = 0;
+}
+
+// Local variables:
+// mode: c
+// End:
--- /dev/null
+/* $Id$ */
+
+/* gs/parse.h -- automatic parsing of data structures */
+
+/* Authors: Arnaud Legrand, Martin Quinson */
+
+typedef enum {
+ GS_PARSE_TOKEN_EMPTY = 0,
+ GS_PARSE_TOKEN_LP = 512,
+ GS_PARSE_TOKEN_RP,
+ GS_PARSE_TOKEN_WORD,
+ GS_PARSE_TOKEN_SPACE,
+ GS_PARSE_TOKEN_QUOTE,
+ GS_PARSE_TOKEN_COMMENT,
+ GS_PARSE_TOKEN_NEWLINE,
+ GS_PARSE_TOKEN_STAR,
+ GS_PARSE_TOKEN_SEMI_COLON,
+ GS_PARSE_TOKEN_COLON,
+ GS_PARSE_TOKEN_ERROR
+} gs_parse_token_t;
+
+#define GS_PARSE_MAX_STR_CONST 4048
+
+extern int gs_parse_line_pos;
+extern int gs_parse_char_pos;
+extern int gs_parse_tok_num;
+
+void gs_parse_dump(void);
+int gs_parse_lex(void);
+int gs_parse_lex_n_dump(void);
+void gs_parse_pointer_init(const char *file);
+void gs_parse_pointer_close(void);
+void gs_parse_pointer_string_init(const char *string_to_parse);
+void gs_parse_pointer_string_close(void);
--- /dev/null
+/**** MSG_LICENCE DO NOT REMOVE ****/
+
+%option noyywrap
+%{
+#include"gs/gs_private.h"
+#include"gs/parse.yy.h"
+#include <string.h>
+ YY_BUFFER_STATE input_buffer;
+ FILE *file_to_parse;
+
+ int gs_parse_line_pos = 1;
+ int gs_parse_char_pos = 0;
+ int gs_parse_tok_num = 0;
+%}
+
+%x comment foo str
+space [ \t]
+letter [A-Za-z._-]
+digit [0-9]
+
+%%
+ int comment_caller=0;
+
+ char string_buf[GS_PARSE_MAX_STR_CONST];
+ char *string_buf_ptr = NULL;
+
+"//"[^\n]*
+"/*" {
+ comment_caller = INITIAL;
+ BEGIN(comment);
+ }
+
+<foo>"/*" {
+ comment_caller = foo;
+ BEGIN(comment);
+ }
+
+<comment>[^*\n]* /* eat anything that's not a '*' */
+<comment>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
+<comment>\n {++gs_parse_line_pos;gs_parse_char_pos=0;}
+<comment>"*"+"/" BEGIN(comment_caller);
+
+\" string_buf_ptr = string_buf; gs_parse_char_pos++; BEGIN(str);
+
+<str>\" { /* saw closing quote - all done */
+ BEGIN(INITIAL);
+ *string_buf_ptr = '\0';
+ yytext=string_buf;
+ gs_parse_char_pos++;
+ return GS_PARSE_TOKEN_WORD;
+ /* return string constant token type and
+ * value to parser
+ */
+ }
+
+<str>\n {
+ /* error - unterminated string constant */
+ /* generate error message */
+ }
+
+<str>\\[0-7]{1,3} {
+ /* octal escape sequence */
+ int result;
+
+ (void) sscanf( yytext + 1, "%o", &result );
+
+ if ( result > 0xff )
+ /* error, constant is out-of-bounds */
+
+ *string_buf_ptr++ = result;
+ gs_parse_char_pos++;
+ }
+
+<str>\\[0-9]+ {
+ /* generate error - bad escape sequence; something
+ * like '\48' or '\0777777'
+ */
+ }
+
+<str>\\n {*string_buf_ptr++ = '\n'; gs_parse_char_pos++;}
+<str>\\t {*string_buf_ptr++ = '\t'; gs_parse_char_pos++;}
+<str>\\r {*string_buf_ptr++ = '\r'; gs_parse_char_pos++;}
+<str>\\b {*string_buf_ptr++ = '\b'; gs_parse_char_pos++;}
+<str>\\f {*string_buf_ptr++ = '\f'; gs_parse_char_pos++;}
+
+<str>\\(.|\n) {*string_buf_ptr++ = yytext[1];
+ if(yytext[1]=='\n') {
+ ++gs_parse_line_pos;gs_parse_char_pos=0;
+ } else { gs_parse_char_pos++;}
+ }
+
+<str>[^\\\n\"]+ {
+ char *yptr = yytext;
+
+ while ( *yptr )
+ *string_buf_ptr++ = *yptr++;
+ gs_parse_char_pos++;
+ }
+
+({letter}|{digit})* { gs_parse_char_pos+= strlen(yytext); return(GS_PARSE_TOKEN_WORD);}
+"{" { gs_parse_char_pos++; return(GS_PARSE_TOKEN_LP);}
+"}" { gs_parse_char_pos++;return(GS_PARSE_TOKEN_RP);}
+"*" { gs_parse_char_pos++;return(GS_PARSE_TOKEN_STAR);}
+";" { gs_parse_char_pos++;return(GS_PARSE_TOKEN_SEMI_COLON);}
+"," { gs_parse_char_pos++;return(GS_PARSE_TOKEN_COLON);}
+"\n" { gs_parse_line_pos++; gs_parse_char_pos=0;}
+. { gs_parse_char_pos++;}
+%%
+/* {space}+ { return(TOKEN_SPACE);} */
+
+void gs_parse_dump(void) {
+ switch(gs_parse_tok_num) {
+ case GS_PARSE_TOKEN_LP : {printf("TOKEN_LP ");break;}
+ case GS_PARSE_TOKEN_RP : {printf("TOKEN_RP ");break;}
+ case GS_PARSE_TOKEN_WORD : {printf("TOKEN_WORD ");break;}
+ // case GS_PARSE_TOKEN_SPACE : {printf("TOKEN_SPACE ");break;}
+ // case GS_PARSE_TOKEN_COMMENT : {printf("TOKEN_COMMENT ");break;}
+ case GS_PARSE_TOKEN_NEWLINE : {printf("TOKEN_NEWLINE\n");return;}
+ case GS_PARSE_TOKEN_EMPTY : {printf("TOKEN_EMPTY\n");return;}
+ default : {printf("Unknown token %d\n", gs_parse_tok_num);return;}
+ }
+ printf("-->%s<-- [line %d, pos %d]\n",yytext,gs_parse_line_pos,gs_parse_char_pos);
+ return;
+}
+
+int gs_parse_lex_n_dump(void) {
+ gs_parse_tok_num = gs_parse_lex();
+ // voir_val();
+ // gs_parse_char_pos += strlen(yytext);
+ return(gs_parse_tok_num);
+}
+
+void gs_parse_pointer_init(const char *file) {
+ file_to_parse = fopen(file,"r");
+ input_buffer = yy_create_buffer( file_to_parse, 10 );
+ yy_switch_to_buffer(input_buffer);
+
+ gs_parse_line_pos = 1;
+ gs_parse_char_pos = 0;
+ gs_parse_tok_num = 0;
+}
+
+void gs_parse_pointer_close(void) {
+ yy_delete_buffer(input_buffer);
+ fclose(file_to_parse);
+
+ gs_parse_line_pos = 1;
+ gs_parse_char_pos = 0;
+ gs_parse_tok_num = 0;
+}
+
+
+void gs_parse_pointer_string_init(const char *string_to_parse) {
+ input_buffer = yy_scan_string (string_to_parse);
+ yy_switch_to_buffer(input_buffer);
+
+ gs_parse_line_pos = 1;
+ gs_parse_char_pos = 0;
+ gs_parse_tok_num = 0;
+}
+
+void gs_parse_pointer_string_close(void) {
+ yy_delete_buffer(input_buffer);
+
+ gs_parse_line_pos = 1;
+ gs_parse_char_pos = 0;
+ gs_parse_tok_num = 0;
+}
+
+// Local variables:
+// mode: c
+// End:
--- /dev/null
+/* gs_sequence.h */
+#ifndef GS_SEQUENCE_H
+#define GS_SEQUENCE_H
+
+struct s_gs_sequence {
+ struct s_gs_message *message;
+ int code;
+ struct s_gs_sequence *next;
+};
+
+#endif /* GS_SEQUENCE_H */
--- /dev/null
+/* gs_tools.c */
+
+#include "gs/gs_private.h"
+
+void *
+gs_memdup(const void * const ptr,
+ const size_t length) {
+ void * new_ptr = NULL;
+
+ new_ptr = malloc(length);
+
+ if (new_ptr) {
+ memcpy(new_ptr, ptr, length);
+ }
+
+ return new_ptr;
+}
+
--- /dev/null
+/* gs_type.c */
+
+#include "gs/gs_private.h"
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(NDR_type_creation,NDR);
+
+/*......................................................................
+ * Type
+ */
+
+/* alloc/free */
+static
+struct s_gs_type *
+_gs_type_alloc(void) {
+ struct s_gs_type *p_type = NULL;
+ p_type = malloc(sizeof(struct s_gs_type));
+ return p_type;
+}
+
+static
+struct s_gs_type *
+_gs_type_new(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name) {
+
+ struct s_gs_type_bag_ops *bag_ops = p_bag->bag_ops;
+ struct s_gs_type *p_type = NULL;
+
+ p_type = _gs_type_alloc();
+
+ p_type->code = -1;
+ p_type->name = strdup(name);
+
+ p_type->size = 0;
+ p_type->alignment = 0;
+ p_type->aligned_size = 0;
+ p_type->category_code = e_gs_type_cat_undefined;
+ p_type->category.undefined_data = NULL;
+ p_type->before_callback = NULL;
+ p_type->after_callback = NULL;
+
+ bag_ops->store_type(p_bag, p_connection, p_type);
+
+ return p_type;
+}
+
+
+
+
+
+/*......................................................................
+ * Elemental
+ */
+static
+struct s_gs_cat_elemental *
+_gs_elemental_cat_alloc(void) {
+ struct s_gs_cat_elemental *p_elemental = NULL;
+
+ p_elemental = malloc(sizeof (struct s_gs_cat_elemental));
+
+ return p_elemental;
+}
+
+static
+struct s_gs_cat_elemental *
+_gs_elemental_cat_new(void) {
+ struct s_gs_cat_elemental *p_elemental = NULL;
+
+ p_elemental = _gs_elemental_cat_alloc();
+ p_elemental->encoding = e_gs_elemental_encoding_undefined;
+
+ return p_elemental;
+}
+
+struct s_gs_type *
+gs_type_new_elemental_with_callback(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name,
+ enum e_gs_elemental_encoding encoding,
+ long int size,
+
+ void (*callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data)) {
+
+ struct s_gs_type *p_type = NULL;
+ struct s_gs_cat_elemental *p_elemental = NULL;
+
+ if (callback)
+ DEBUG1("%s",__FUNCTION__);
+ p_elemental = _gs_elemental_cat_new();
+ p_elemental->encoding = encoding;
+
+ p_type = _gs_type_new(p_bag, p_connection, name);
+
+ p_type->size = size > 0?size:0;
+
+ if (size > 0) {
+ long int sz = size;
+ long int mask = sz;
+
+ while ((sz >>= 1)) {
+ mask |= sz;
+ }
+
+ if (size & (mask >> 1)) {
+ long int alignment = 0;
+ long int aligned_size = 0;
+
+ alignment = (size & ~(mask >> 1)) << 1;
+ if (alignment < 0)
+ GS_FAILURE("elemental type is too large");
+
+ aligned_size = aligned(size, alignment);
+ if (aligned_size < 0)
+ GS_FAILURE("elemental type is too large");
+
+ p_type->alignment = alignment;
+ p_type->aligned_size = aligned_size;
+
+ } else {
+ long int alignment = size & ~(mask >> 1);
+ long int aligned_size = aligned(size, alignment);
+
+ p_type->alignment = alignment;
+ p_type->aligned_size = aligned_size;
+ }
+
+ } else {
+ p_type->alignment = 0;
+ p_type->aligned_size = 0;
+ }
+
+ p_type->category_code = e_gs_type_cat_elemental;
+ p_type->category.elemental_data = p_elemental;
+
+ p_type->before_callback = callback;
+
+ return p_type;
+}
+
+struct s_gs_type *
+gs_type_new_elemental(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name,
+ enum e_gs_elemental_encoding encoding,
+ long int size) {
+ DEBUG1("%s",__FUNCTION__);
+ return gs_type_new_elemental_with_callback(p_bag, p_connection, name, encoding, size, NULL);
+}
+
+
+struct s_gs_type *
+gs_type_new_unsigned_integer_elemental_with_callback(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name,
+ long int size,
+
+ void (*callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data)) {
+ if (callback)
+ DEBUG1("%s",__FUNCTION__);
+ return gs_type_new_elemental_with_callback(p_bag, p_connection, name,
+ e_gs_elemental_encoding_unsigned_integer,
+ size,
+ callback);
+}
+
+struct s_gs_type *
+gs_type_new_unsigned_integer_elemental(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name,
+ long int size) {
+ DEBUG1("%s",__FUNCTION__);
+ return gs_type_new_unsigned_integer_elemental_with_callback(p_bag, p_connection, name, size, NULL);
+}
+
+
+struct s_gs_type *
+gs_type_new_signed_integer_elemental_with_callback(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name,
+ long int size,
+
+ void (*callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data)) {
+ if (callback)
+ DEBUG1("%s",__FUNCTION__);
+ return gs_type_new_elemental_with_callback(p_bag, p_connection, name,
+ e_gs_elemental_encoding_signed_integer,
+ size,
+ callback);
+}
+
+struct s_gs_type *
+gs_type_new_signed_integer_elemental(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name,
+ long int size) {
+ DEBUG1("%s",__FUNCTION__);
+ return gs_type_new_signed_integer_elemental_with_callback(p_bag, p_connection, name, size, NULL);
+}
+
+
+struct s_gs_type *
+gs_type_new_floating_point_elemental_with_callback(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name,
+ long int size,
+
+ void (*callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data)) {
+ DEBUG1("%s",__FUNCTION__);
+ return gs_type_new_elemental_with_callback(p_bag, p_connection, name,
+ e_gs_elemental_encoding_floating_point,
+ size,
+ callback);
+
+}
+
+struct s_gs_type *
+gs_type_new_floating_point_elemental(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name,
+ long int size) {
+ DEBUG1("%s",__FUNCTION__);
+ return gs_type_new_floating_point_elemental_with_callback(p_bag, p_connection, name, size, NULL);
+}
+
+
+
+
+
+/*......................................................................
+ * Struct
+ */
+static
+struct s_gs_cat_struct *
+_gs_struct_cat_alloc(void) {
+ struct s_gs_cat_struct *p_struct = NULL;
+ p_struct = malloc(sizeof (struct s_gs_cat_struct));
+ return p_struct;
+}
+
+static
+struct s_gs_cat_struct *
+_gs_struct_cat_new(void) {
+ struct s_gs_cat_struct *p_struct = NULL;
+
+ p_struct = _gs_struct_cat_alloc();
+
+ p_struct->nb_fields = 0;
+ p_struct->field_array = NULL;
+
+ return p_struct;
+}
+
+struct s_gs_type *
+gs_type_new_struct_with_callback(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name,
+
+ void (*before_callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data),
+
+ void (*after_callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data)) {
+ struct s_gs_type *p_type = NULL;
+ struct s_gs_cat_struct *p_struct = NULL;
+
+ if (before_callback || after_callback)
+ DEBUG1("%s",__FUNCTION__);
+ p_struct = _gs_struct_cat_new();
+
+ p_type = _gs_type_new(p_bag, p_connection, name);
+
+ p_type->size = 0;
+ p_type->alignment = 0;
+ p_type->aligned_size = 0;
+ p_type->category_code = e_gs_type_cat_struct;
+ p_type->category.struct_data = p_struct;
+ p_type->before_callback = before_callback;
+ p_type->after_callback = after_callback;
+
+ return p_type;
+}
+
+struct s_gs_type *
+gs_type_new_struct(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name) {
+ DEBUG2("%s(%s)",__FUNCTION__,name);
+ return gs_type_new_struct_with_callback(p_bag, p_connection, name, NULL, NULL);
+}
+
+
+static
+struct s_gs_cat_struct_field *
+_gs_struct_field_cat_alloc(void) {
+ struct s_gs_cat_struct_field *p_struct_field = NULL;
+ p_struct_field = malloc(sizeof (struct s_gs_cat_struct_field));
+ return p_struct_field;
+}
+
+static
+struct s_gs_cat_struct_field *
+_gs_struct_field_cat_new(const char *name,
+ long int offset,
+ struct s_gs_type *p_field_type,
+
+ void (*before_callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data),
+
+ void (*after_callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data)) {
+
+ struct s_gs_cat_struct_field *p_struct_field = NULL;
+
+ if (p_field_type->size < 0)
+ GS_FAILURE("variable length field not allowed in structure");
+
+ p_struct_field = _gs_struct_field_cat_alloc();
+
+ p_struct_field->name = strdup(name);
+ p_struct_field->offset = aligned(offset, p_field_type->alignment);
+ p_struct_field->code = p_field_type->code;
+ p_struct_field->before_callback = before_callback;
+ p_struct_field->after_callback = after_callback;
+
+ return p_struct_field;
+}
+
+void
+gs_type_struct_append_field_with_callback(struct s_gs_type *p_struct_type,
+ const char *name,
+ struct s_gs_type *p_field_type,
+
+ void (*before_callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data),
+
+ void (*after_callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data)) {
+
+ struct s_gs_cat_struct *p_struct = NULL;
+ int field_num = -1;
+ struct s_gs_cat_struct_field *p_field = NULL;
+
+ if (before_callback || after_callback)
+ DEBUG1("%s",__FUNCTION__);
+
+ if (p_field_type->size < 0)
+ GS_FAILURE("field size must be statically known");
+
+ p_struct = p_struct_type->category.struct_data;
+
+ if ((field_num = p_struct->nb_fields++)) {
+ p_struct->field_array = realloc(p_struct->field_array, p_struct->nb_fields * sizeof (struct s_gs_cat_struct_field *));
+ } else {
+ p_struct->field_array = malloc(sizeof (struct s_gs_cat_struct_field *));
+ }
+
+ p_field = _gs_struct_field_cat_new(name, p_struct_type->size, p_field_type, before_callback, after_callback);
+ p_struct->field_array[field_num] = p_field;
+
+ p_struct_type->size = p_field->offset + p_field_type->size;
+ p_struct_type->alignment = max(p_struct_type->alignment, p_field_type->alignment);
+ p_struct_type->aligned_size = aligned(p_struct_type->size, p_struct_type->alignment);
+}
+
+void
+gs_type_struct_append_field(struct s_gs_type *p_struct_type,
+ const char *name,
+ struct s_gs_type *p_field_type) {
+ DEBUG1("%s",__FUNCTION__);
+ gs_type_struct_append_field_with_callback(p_struct_type, name, p_field_type, NULL, NULL);
+}
+
+
+
+
+/*......................................................................
+ * Union
+ */
+static
+struct s_gs_cat_union *
+_gs_union_cat_alloc(void) {
+ struct s_gs_cat_union *p_union = NULL;
+ p_union = malloc(sizeof (struct s_gs_cat_union));
+ return p_union;
+}
+
+static
+struct s_gs_cat_union *
+_gs_union_cat_new(void) {
+ struct s_gs_cat_union *p_union = NULL;
+
+ p_union = _gs_union_cat_alloc();
+
+ p_union->nb_fields = 0;
+ p_union->field_array = NULL;
+
+ return p_union;
+}
+
+struct s_gs_type *
+gs_type_new_union_with_callback(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name,
+
+ int (*field_callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data),
+
+ void (*after_callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data)) {
+ struct s_gs_type *p_type = NULL;
+ struct s_gs_cat_union *p_union = NULL;
+
+ if (!field_callback
+ &&
+ (!p_connection||p_connection->direction != e_gs_connection_direction_incoming))
+ GS_FAILURE("attempt to create a union type without discriminant");
+
+ p_union = _gs_union_cat_new();
+
+ p_type = _gs_type_new(p_bag, p_connection, name);
+
+ p_type->size = 0;
+ p_type->alignment = 0;
+ p_type->aligned_size = 0;
+ p_type->category_code = e_gs_type_cat_union;
+ p_type->category.union_data = p_union;
+ p_type->before_callback = NULL;
+
+ p_union->callback = field_callback;
+ p_type->after_callback = after_callback;
+
+ return p_type;
+}
+
+struct s_gs_type *
+gs_type_new_union(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name,
+
+ int (*field_callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data)) {
+ return gs_type_new_union_with_callback(p_bag, p_connection, name, field_callback, NULL);
+}
+
+
+static
+struct s_gs_cat_union_field *
+_gs_union_field_cat_alloc(void) {
+ struct s_gs_cat_union_field *p_union_field = NULL;
+ p_union_field = malloc(sizeof (struct s_gs_cat_union_field));
+ return p_union_field;
+}
+
+static
+struct s_gs_cat_union_field *
+_gs_union_field_cat_new(const char *name,
+ struct s_gs_type *p_field_type,
+
+ void (*before_callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data),
+
+ void (*after_callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data)) {
+
+ struct s_gs_cat_union_field *p_union_field = NULL;
+
+ if (p_field_type->size < 0)
+ GS_FAILURE("variable length field not allowed in structure");
+
+ p_union_field = _gs_union_field_cat_alloc();
+
+ p_union_field->name = strdup(name);
+ p_union_field->code = p_field_type->code;
+ p_union_field->before_callback = before_callback;
+ p_union_field->after_callback = after_callback;
+
+ return p_union_field;
+}
+
+void
+gs_type_union_append_field_with_callback(struct s_gs_type *p_union_type,
+ const char *name,
+ struct s_gs_type *p_field_type,
+
+ void (*before_callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data),
+
+ void (*after_callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data)) {
+
+ struct s_gs_cat_union *p_union = NULL;
+ int field_num = -1;
+ struct s_gs_cat_union_field *p_field = NULL;
+
+ if (p_field_type->size < 0)
+ GS_FAILURE("field size must be statically known");
+
+ p_union = p_union_type->category.union_data;
+
+ if ((field_num = p_union->nb_fields++)) {
+ p_union->field_array = realloc(p_union->field_array, p_union->nb_fields * sizeof (struct s_gs_cat_union_field *));
+ } else {
+ p_union->field_array = malloc(sizeof (struct s_gs_cat_union_field *));
+ }
+
+ p_field = _gs_union_field_cat_new(name, p_field_type, before_callback, after_callback);
+ p_union->field_array[field_num] = p_field;
+
+ p_union_type->size = max(p_union_type->size, p_field_type->size);
+ p_union_type->alignment = max(p_union_type->alignment, p_field_type->alignment);
+ p_union_type->aligned_size = aligned(p_union_type->size, p_union_type->alignment);
+}
+
+void
+gs_type_union_append_field(struct s_gs_type *p_union_type,
+ const char *name,
+ struct s_gs_type *p_field_type) {
+ gs_type_union_append_field_with_callback(p_union_type, name, p_field_type, NULL, NULL);
+}
+
+
+
+
+/*......................................................................
+ * Ref
+ */
+static
+struct s_gs_cat_ref *
+_gs_ref_cat_alloc(void) {
+ struct s_gs_cat_ref *p_ref = NULL;
+ p_ref = malloc(sizeof (struct s_gs_cat_ref));
+ return p_ref;
+}
+
+static
+struct s_gs_cat_ref *
+_gs_ref_cat_new(void) {
+ struct s_gs_cat_ref *p_ref = NULL;
+
+ p_ref = _gs_ref_cat_alloc();
+ p_ref->code = 0;
+ p_ref->callback = NULL;
+
+ return p_ref;
+}
+
+struct s_gs_type *
+gs_type_new_ref_with_callback(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name,
+ struct s_gs_type *p_referenced_type,
+
+ int (*type_callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data),
+
+ void (*after_callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data)) {
+ struct s_gs_type *p_type = NULL;
+ struct s_gs_cat_ref *p_ref = NULL;
+
+ p_ref = _gs_ref_cat_new();
+
+ if (!p_referenced_type
+ &&
+ !type_callback
+ &&
+ (!p_connection||p_connection->direction != e_gs_connection_direction_incoming))
+ GS_FAILURE("attempt to declare a generic ref without discriminant");
+
+ p_ref->code = p_referenced_type?p_referenced_type->code:-1;
+ p_ref->callback = type_callback;
+
+ p_type = _gs_type_new(p_bag, p_connection, name);
+
+ {
+ struct s_gs_type_bag_ops *bag_ops = p_bag->bag_ops;
+ struct s_gs_type *p_pointer_type = NULL;
+
+ p_pointer_type = bag_ops->get_type_by_name(p_bag, p_connection, "data pointer");
+ p_type->size = p_pointer_type->size;
+ p_type->alignment = p_pointer_type->alignment;
+ p_type->aligned_size = p_pointer_type->aligned_size;
+ }
+
+ p_type->category_code = e_gs_type_cat_ref;
+ p_type->category.ref_data = p_ref;
+
+ p_type->before_callback = NULL;
+ p_type->after_callback = after_callback;
+
+ return p_type;
+}
+
+struct s_gs_type *
+gs_type_new_ref(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name,
+ struct s_gs_type *p_referenced_type) {
+ return gs_type_new_ref_with_callback(p_bag, p_connection, name, p_referenced_type, NULL, NULL);
+}
+
+
+
+
+/*......................................................................
+ * Array
+ */
+static
+struct s_gs_cat_array *
+_gs_array_cat_alloc(void) {
+ struct s_gs_cat_array *p_array = NULL;
+ p_array = malloc(sizeof (struct s_gs_cat_array));
+ return p_array;
+}
+
+static
+struct s_gs_cat_array *
+_gs_array_cat_new(void) {
+ struct s_gs_cat_array *p_array = NULL;
+
+ p_array = _gs_array_cat_alloc();
+ p_array->code = 0;
+ p_array->element_count = 0;
+
+ return p_array;
+}
+
+struct s_gs_type *
+gs_type_new_array_with_callback(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name,
+ long int size,
+ struct s_gs_type *p_array_element_type,
+
+ long int (*size_callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data),
+
+ void (*after_callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data)) {
+
+ struct s_gs_type *p_type = NULL;
+ struct s_gs_cat_array *p_array = NULL;
+
+ p_array = _gs_array_cat_new();
+ p_array->code = p_array_element_type->code;
+ p_array->element_count = size;
+
+ p_type = _gs_type_new(p_bag, p_connection, name);
+
+ if (size <= 0) {
+ if (size < 0 && !size_callback
+ &&
+ (!p_connection||p_connection->direction != e_gs_connection_direction_incoming))
+ GS_FAILURE("attempt to construct a variable sized array with no callback");
+
+ p_type->size = size;
+ } else {
+ p_type->size = size * p_array_element_type->aligned_size;
+ }
+
+ p_type->alignment = p_array_element_type->alignment;
+ p_type->aligned_size = size;
+
+ p_type->category_code = e_gs_type_cat_array;
+ p_type->category.array_data = p_array;
+
+ p_array->callback = size_callback;
+
+ p_type->before_callback = NULL;
+ p_type->after_callback = after_callback;
+
+ return p_type;
+}
+
+struct s_gs_type *
+gs_type_new_array(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name,
+ long int size,
+ struct s_gs_type *p_array_element_type) {
+ return gs_type_new_array_with_callback(p_bag, p_connection, name, size, p_array_element_type, NULL, NULL);
+}
+
+
+
+
+
+/*......................................................................
+ * Type structure bootstrap
+ */
+static
+long int
+_strlen_cb(void *p_vars,
+ struct s_gs_type *p_type,
+ void *data) {
+
+ (void)p_vars;
+ (void)p_type;
+
+ return 1+(long int)strlen(data);
+}
+
+static
+void
+_category_code_push_cb(void *p_vars,
+ struct s_gs_type *p_type,
+ void *data) {
+ gs_vars_push(p_vars, p_type, "_category_code", data);
+}
+
+static
+int
+_category_code_pop_cb(void *p_vars,
+ struct s_gs_type *p_type,
+ void *data) {
+ int *p_cat = NULL;
+
+ (void)p_type;
+ (void)data;
+
+ p_cat = gs_vars_pop(p_vars, "_category_code", NULL);
+
+ if (!p_cat)
+ GS_FAILURE("categoy code not found");
+
+ return *p_cat;
+}
+
+static
+void
+_field_count_push_cb(void *p_vars,
+ struct s_gs_type *p_type,
+ void *data) {
+ gs_vars_push(p_vars, p_type, "_field_count", data);
+}
+
+static
+long
+int
+_field_count_pop_cb(void *p_vars,
+ struct s_gs_type *p_type,
+ void *data) {
+ long int *p_cat = NULL;
+
+ (void)p_type;
+ (void)data;
+
+ p_cat = gs_vars_pop(p_vars, "_field_count", NULL);
+
+ if (!p_cat)
+ GS_FAILURE("categoy code not found");
+
+ return *p_cat;
+}
+
+void
+gs_bootstrap_type_bag(struct s_gs_type_bag *p_bag) {
+ DEBUG0("###################### BEGIN OF TYPE BOOTSTRAPING");
+ gs_bootstrap_incoming_connection(p_bag, NULL);
+ DEBUG0("###################### END OF TYPE BOOTSTRAPING");
+}
+
+void
+gs_bootstrap_incoming_connection(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx) {
+
+ /* basic types */
+ struct s_gs_type *signed_char = NULL;
+ struct s_gs_type *unsigned_char = NULL;
+ struct s_gs_type *signed_short_int = NULL;
+ struct s_gs_type *unsigned_short_int = NULL;
+ struct s_gs_type *signed_int = NULL;
+ struct s_gs_type *unsigned_int = NULL;
+ struct s_gs_type *signed_long_int = NULL;
+ struct s_gs_type *unsigned_long_int = NULL;
+ struct s_gs_type *signed_long_long_int = NULL;
+ struct s_gs_type *unsigned_long_long_int = NULL;
+ struct s_gs_type *data_pointer = NULL;
+ struct s_gs_type *function_pointer = NULL;
+ struct s_gs_type *char_array = NULL;
+ struct s_gs_type *string = NULL;
+
+ /* categories */
+ struct s_gs_type *s_gs_cat_elemental = NULL; /* Elemental */
+
+ struct s_gs_type *s_gs_cat_struct_field = NULL; /* Struct */
+ struct s_gs_type *ref_s_gs_cat_struct_field = NULL;
+ struct s_gs_type *tab_ref_s_gs_cat_struct_field = NULL;
+ struct s_gs_type *ref_tab_ref_s_gs_cat_struct_field = NULL;
+ struct s_gs_type *s_gs_cat_struct = NULL;
+
+ struct s_gs_type *s_gs_cat_union_field = NULL; /* Union */
+ struct s_gs_type *ref_s_gs_cat_union_field = NULL;
+ struct s_gs_type *tab_ref_s_gs_cat_union_field = NULL;
+ struct s_gs_type *ref_tab_ref_s_gs_cat_union_field = NULL;
+ struct s_gs_type *s_gs_cat_union = NULL;
+
+ struct s_gs_type *s_gs_cat_ref = NULL; /* Ref */
+
+ struct s_gs_type *s_gs_cat_array = NULL; /* Array */
+
+ struct s_gs_type *s_gs_cat_ignored = NULL; /* Ignored */
+
+ /* type */
+ struct s_gs_type *ref_s_gs_cat_elemental = NULL;
+ struct s_gs_type *ref_s_gs_cat_struct = NULL;
+ struct s_gs_type *ref_s_gs_cat_union = NULL;
+ struct s_gs_type *ref_s_gs_cat_ref = NULL;
+ struct s_gs_type *ref_s_gs_cat_array = NULL;
+ struct s_gs_type *ref_s_gs_cat_ignored = NULL;
+
+ struct s_gs_type *u_gs_category = NULL;
+ struct s_gs_type *s_gs_type = NULL;
+
+ /* message */
+ struct s_gs_type *s_gs_sequence = NULL;
+ struct s_gs_type *s_gs_message = NULL;
+
+ struct s_gs_type *ref_s_gs_sequence = NULL;
+ struct s_gs_type *ref_s_gs_message = NULL;
+
+
+ /*
+ * connection boostrap sequence
+ */
+
+ signed_char = gs_type_new_signed_integer_elemental (p_bag, p_cnx, "signed char", 1);
+ unsigned_char = gs_type_new_unsigned_integer_elemental(p_bag, p_cnx, "unsigned char", 1);
+
+
+ if (p_cnx) {
+ struct s_gs_connection_ops *cops = p_cnx->connection_ops;
+ unsigned char a = 0;
+ unsigned char b = 0;
+
+ if (p_cnx->direction != e_gs_connection_direction_incoming)
+ GS_FAILURE("invalid connection");
+
+ cops->read(p_cnx, &b, 1);
+ signed_short_int = gs_type_new_signed_integer_elemental (p_bag, p_cnx, "signed short int", b);
+
+ cops->read(p_cnx, &b, 1);
+ unsigned_short_int = gs_type_new_unsigned_integer_elemental(p_bag, p_cnx, "unsigned short int", b);
+
+
+ cops->read(p_cnx, &b, 1);
+ signed_int = gs_type_new_signed_integer_elemental (p_bag, p_cnx, "signed int", b);
+
+ cops->read(p_cnx, &b, 1);
+ unsigned_int = gs_type_new_unsigned_integer_elemental(p_bag, p_cnx, "unsigned int", b);
+
+
+ cops->read(p_cnx, &b, 1);
+ signed_long_int = gs_type_new_signed_integer_elemental (p_bag, p_cnx, "signed long int", b);
+
+ cops->read(p_cnx, &b, 1);
+ unsigned_long_int = gs_type_new_unsigned_integer_elemental(p_bag, p_cnx, "unsigned long int", b);
+
+
+ cops->read(p_cnx, &b, 1);
+ signed_long_long_int = gs_type_new_signed_integer_elemental (p_bag, p_cnx, "signed long long int", b);
+
+ cops->read(p_cnx, &b, 1);
+ unsigned_long_long_int = gs_type_new_unsigned_integer_elemental(p_bag, p_cnx, "unsigned long long int", b);
+
+ cops->read(p_cnx, &b, 1);
+ cops->read(p_cnx, &a, 1);
+ data_pointer = gs_type_new_ignored(p_bag, p_cnx, "data pointer", b, a, NULL);
+
+ cops->read(p_cnx, &b, 1);
+ cops->read(p_cnx, &a, 1);
+ function_pointer = gs_type_new_ignored(p_bag, p_cnx, "function pointer", b, a, NULL);
+ } else {
+ signed_short_int = gs_type_new_signed_integer_elemental (p_bag, NULL, "signed short int", sizeof (signed short int));
+ unsigned_short_int = gs_type_new_unsigned_integer_elemental(p_bag, NULL, "unsigned short int", sizeof (unsigned short int));
+
+ signed_int = gs_type_new_signed_integer_elemental (p_bag, NULL, "signed int", sizeof (signed int));
+ unsigned_int = gs_type_new_unsigned_integer_elemental(p_bag, NULL, "unsigned int", sizeof (unsigned int));
+
+ signed_long_int = gs_type_new_signed_integer_elemental (p_bag, NULL, "signed long int", sizeof (signed long int));
+ unsigned_long_int = gs_type_new_unsigned_integer_elemental(p_bag, NULL, "unsigned long int", sizeof (unsigned long int));
+
+ signed_long_long_int = gs_type_new_signed_integer_elemental (p_bag, NULL, "signed long long int", sizeof (signed long long int));
+ unsigned_long_long_int = gs_type_new_unsigned_integer_elemental(p_bag, NULL, "unsigned long long int", sizeof (unsigned long long int));
+
+ data_pointer = gs_type_new_ignored(p_bag, NULL, "data pointer", sizeof (void *), sizeof (void *), NULL);
+ function_pointer = gs_type_new_ignored(p_bag, NULL, "function pointer", sizeof (void (*) (void)), sizeof (void (*) (void)), NULL);
+ }
+
+ char_array = gs_type_new_array_with_callback(p_bag, p_cnx, "_char_array", -1, signed_char, _strlen_cb, NULL);
+ string = gs_type_new_ref(p_bag, p_cnx, "_string", char_array);
+
+ /* Elemental cat */
+ s_gs_cat_elemental = gs_type_new_struct(p_bag, p_cnx, "_s_gs_cat_elemental");
+ gs_type_struct_append_field(s_gs_cat_elemental, "encoding", signed_int);
+
+ /* Struct cat */
+ s_gs_cat_struct_field = gs_type_new_struct(p_bag, p_cnx, "_s_gs_cat_struct_field");
+ gs_type_struct_append_field(s_gs_cat_struct_field, "name", string);
+ gs_type_struct_append_field(s_gs_cat_struct_field, "offset", signed_long_int);
+ gs_type_struct_append_field(s_gs_cat_struct_field, "code", signed_int);
+ gs_type_struct_append_field(s_gs_cat_struct_field, "before_callback", function_pointer);
+ gs_type_struct_append_field(s_gs_cat_struct_field, "after_callback", function_pointer);
+
+ ref_s_gs_cat_struct_field = gs_type_new_ref (p_bag, p_cnx, "_ps_gs_cat_struct_field", s_gs_cat_struct_field);
+ tab_ref_s_gs_cat_struct_field = gs_type_new_array_with_callback(p_bag, p_cnx, "_aps_gs_cat_struct_field", -1, ref_s_gs_cat_struct_field, _field_count_pop_cb, NULL);
+ ref_tab_ref_s_gs_cat_struct_field = gs_type_new_ref (p_bag, p_cnx, "_paps_gs_cat_struct_field", tab_ref_s_gs_cat_struct_field);
+
+ s_gs_cat_struct = gs_type_new_struct(p_bag, p_cnx, "_s_gs_cat_struct");
+ gs_type_struct_append_field_with_callback(s_gs_cat_struct, "nb_fields", signed_int, _field_count_push_cb, NULL);
+ gs_type_struct_append_field(s_gs_cat_struct, "field_array", ref_tab_ref_s_gs_cat_struct_field);
+
+ /* Union cat */
+ s_gs_cat_union_field = gs_type_new_struct(p_bag, p_cnx, "_s_gs_cat_union_field");
+ gs_type_struct_append_field(s_gs_cat_union_field, "name", string);
+ gs_type_struct_append_field(s_gs_cat_union_field, "code", signed_int);
+ gs_type_struct_append_field(s_gs_cat_union_field, "before_callback", function_pointer);
+ gs_type_struct_append_field(s_gs_cat_union_field, "after_callback", function_pointer);
+
+ ref_s_gs_cat_union_field = gs_type_new_ref (p_bag, p_cnx, "_ps_gs_cat_union_field", s_gs_cat_union_field);
+ tab_ref_s_gs_cat_union_field = gs_type_new_array_with_callback(p_bag, p_cnx, "_aps_gs_cat_union_field", -1, ref_s_gs_cat_union_field, _field_count_pop_cb, NULL);
+ ref_tab_ref_s_gs_cat_union_field = gs_type_new_ref (p_bag, p_cnx, "_paps_gs_cat_union_field", tab_ref_s_gs_cat_union_field);
+
+ s_gs_cat_union = gs_type_new_struct(p_bag, p_cnx, "_s_gs_cat_union");
+ gs_type_struct_append_field_with_callback(s_gs_cat_union, "nb_fields", signed_int, _field_count_push_cb, NULL);
+ gs_type_struct_append_field(s_gs_cat_union, "field_array", ref_tab_ref_s_gs_cat_union_field);
+ gs_type_struct_append_field(s_gs_cat_union, "callback", function_pointer);
+
+ /* Ref cat */
+ s_gs_cat_ref = gs_type_new_struct(p_bag, p_cnx, "_s_gs_cat_ref");
+ gs_type_struct_append_field(s_gs_cat_ref, "code", signed_int);
+ gs_type_struct_append_field(s_gs_cat_ref, "callback", function_pointer);
+
+ /* Array cat */
+ s_gs_cat_array = gs_type_new_struct(p_bag, p_cnx, "_s_gs_cat_array");
+ gs_type_struct_append_field(s_gs_cat_array, "code", signed_int);
+ gs_type_struct_append_field(s_gs_cat_array, "element_count", signed_long_int);
+ gs_type_struct_append_field(s_gs_cat_array, "callback", function_pointer);
+
+ /* Ignored cat */
+ s_gs_cat_ignored = gs_type_new_struct(p_bag, p_cnx, "_s_gs_cat_ignored");
+ gs_type_struct_append_field(s_gs_cat_ignored, "default_value", data_pointer);
+
+ /* refs to categories */
+ ref_s_gs_cat_elemental = gs_type_new_ref(p_bag, p_cnx, "_ref_s_gs_cat_elemental", s_gs_cat_elemental);
+ ref_s_gs_cat_struct = gs_type_new_ref(p_bag, p_cnx, "_ref_s_gs_cat_struct", s_gs_cat_struct );
+ ref_s_gs_cat_union = gs_type_new_ref(p_bag, p_cnx, "_ref_s_gs_cat_union", s_gs_cat_union );
+ ref_s_gs_cat_ref = gs_type_new_ref(p_bag, p_cnx, "_ref_s_gs_cat_ref", s_gs_cat_ref );
+ ref_s_gs_cat_array = gs_type_new_ref(p_bag, p_cnx, "_ref_s_gs_cat_array", s_gs_cat_array );
+ ref_s_gs_cat_ignored = gs_type_new_ref(p_bag, p_cnx, "_ref_s_gs_cat_ignored", s_gs_cat_ignored );
+
+ /* union of categories */
+ u_gs_category = gs_type_new_union(p_bag, p_cnx, "_u_gs_category", _category_code_pop_cb);
+ gs_type_union_append_field(u_gs_category, "undefined_data", data_pointer);
+ gs_type_union_append_field(u_gs_category, "elemental_data", ref_s_gs_cat_elemental);
+ gs_type_union_append_field(u_gs_category, "struct_data", ref_s_gs_cat_struct);
+ gs_type_union_append_field(u_gs_category, "union_data", ref_s_gs_cat_union);
+ gs_type_union_append_field(u_gs_category, "ref_data", ref_s_gs_cat_ref);
+ gs_type_union_append_field(u_gs_category, "array_data", ref_s_gs_cat_array);
+ gs_type_union_append_field(u_gs_category, "ignored_data", ref_s_gs_cat_ignored);
+
+ /* type */
+ s_gs_type = gs_type_new_struct(p_bag, p_cnx, "_s_gs_type");
+ gs_type_struct_append_field (s_gs_type, "code", signed_int);
+ gs_type_struct_append_field (s_gs_type, "name", string);
+ gs_type_struct_append_field (s_gs_type, "size", signed_long_int);
+ gs_type_struct_append_field (s_gs_type, "alignment", signed_long_int);
+ gs_type_struct_append_field (s_gs_type, "aligned_size", signed_long_int);
+ gs_type_struct_append_field_with_callback(s_gs_type, "category_code", signed_int, _category_code_push_cb, NULL);
+ gs_type_struct_append_field (s_gs_type, "category", u_gs_category);
+ gs_type_struct_append_field (s_gs_type, "before_callback", function_pointer);
+ gs_type_struct_append_field (s_gs_type, "after_callback", function_pointer);
+
+ /* message */
+ s_gs_sequence = gs_type_new_struct(p_bag, p_cnx, "_s_gs_sequence");
+ s_gs_message = gs_type_new_struct(p_bag, p_cnx, "_s_gs_message");
+
+ ref_s_gs_sequence = gs_type_new_ref(p_bag, p_cnx, "_ref_s_gs_sequence", s_gs_sequence);
+ ref_s_gs_message = gs_type_new_ref(p_bag, p_cnx, "_ref_s_gs_message", s_gs_message);
+
+ gs_type_struct_append_field(s_gs_sequence, "message", ref_s_gs_message);
+ gs_type_struct_append_field(s_gs_sequence, "code", signed_int);
+ gs_type_struct_append_field(s_gs_sequence, "next", ref_s_gs_sequence);
+
+ gs_type_struct_append_field(s_gs_message, "code", signed_int);
+ gs_type_struct_append_field(s_gs_message, "name", string);
+ gs_type_struct_append_field(s_gs_message, "first", ref_s_gs_sequence);
+ gs_type_struct_append_field(s_gs_message, "next", ref_s_gs_sequence);
+}
+
+void
+gs_bootstrap_outgoing_connection(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx) {
+ struct s_gs_type_bag_ops *bops = p_bag->bag_ops;
+ struct s_gs_connection_ops *cops = p_cnx->connection_ops;
+ unsigned char b = 0;
+
+ if (p_cnx->direction != e_gs_connection_direction_outgoing)
+ GS_FAILURE("invalid connection");
+
+ bops->mark_type(p_bag, p_cnx, "signed char");
+ bops->mark_type(p_bag, p_cnx, "unsigned char");
+
+ b = sizeof(signed short int);
+ cops->write(p_cnx, &b, 1);
+ bops->mark_type(p_bag, p_cnx, "signed short int");
+
+ b = sizeof(unsigned short int);
+ cops->write(p_cnx, &b, 1);
+ bops->mark_type(p_bag, p_cnx, "unsigned short int");
+
+ b = sizeof(signed int);
+ cops->write(p_cnx, &b, 1);
+ bops->mark_type(p_bag, p_cnx, "signed int");
+
+ b = sizeof(unsigned int);
+ cops->write(p_cnx, &b, 1);
+ bops->mark_type(p_bag, p_cnx, "unsigned in");
+
+ b = sizeof(signed long int);
+ cops->write(p_cnx, &b, 1);
+ bops->mark_type(p_bag, p_cnx, "signed long int");
+
+ b = sizeof(unsigned long int);
+ cops->write(p_cnx, &b, 1);
+ bops->mark_type(p_bag, p_cnx, "unsigned long int");
+
+ b = sizeof(signed long long int);
+ cops->write(p_cnx, &b, 1);
+ bops->mark_type(p_bag, p_cnx, "signed long long int");
+
+ b = sizeof(unsigned long long int);
+ cops->write(p_cnx, &b, 1);
+ bops->mark_type(p_bag, p_cnx, "unsigned long long int");
+
+ b = sizeof(void *);
+ cops->write(p_cnx, &b, 1); /* size */
+ cops->write(p_cnx, &b, 1); /* alignment */
+ bops->mark_type(p_bag, p_cnx, "data pointer");
+
+ b = sizeof(void (*) (void));
+ cops->write(p_cnx, &b, 1); /* size */
+ cops->write(p_cnx, &b, 1); /* alignment */
+ bops->mark_type(p_bag, p_cnx, "function pointer");
+
+ bops->mark_type(p_bag, p_cnx, "_char_array");
+ bops->mark_type(p_bag, p_cnx, "_string");
+
+ bops->mark_type(p_bag, p_cnx, "_s_gs_cat_elemental");
+
+ bops->mark_type(p_bag, p_cnx, "_s_gs_cat_struct_field");
+ bops->mark_type(p_bag, p_cnx, "_ps_gs_cat_struct_field");
+ bops->mark_type(p_bag, p_cnx, "_aps_gs_cat_struct_field");
+ bops->mark_type(p_bag, p_cnx, "_paps_gs_cat_struct_field");
+ bops->mark_type(p_bag, p_cnx, "_s_gs_cat_struct");
+
+ bops->mark_type(p_bag, p_cnx, "_s_gs_cat_union_field");
+ bops->mark_type(p_bag, p_cnx, "_ps_gs_cat_union_field");
+ bops->mark_type(p_bag, p_cnx, "_aps_gs_cat_union_field");
+ bops->mark_type(p_bag, p_cnx, "_paps_gs_cat_union_field");
+ bops->mark_type(p_bag, p_cnx, "_s_gs_cat_union");
+
+ bops->mark_type(p_bag, p_cnx, "_s_gs_cat_ref");
+
+ bops->mark_type(p_bag, p_cnx, "_s_gs_cat_array");
+
+ bops->mark_type(p_bag, p_cnx, "_s_gs_cat_ignored");
+
+ bops->mark_type(p_bag, p_cnx, "_ref_s_gs_cat_elemental");
+ bops->mark_type(p_bag, p_cnx, "_ref_s_gs_cat_struct");
+ bops->mark_type(p_bag, p_cnx, "_ref_s_gs_cat_union");
+ bops->mark_type(p_bag, p_cnx, "_ref_s_gs_cat_ref");
+ bops->mark_type(p_bag, p_cnx, "_ref_s_gs_cat_array");
+ bops->mark_type(p_bag, p_cnx, "_ref_s_gs_cat_ignored");
+
+ bops->mark_type(p_bag, p_cnx, "_u_gs_category");
+ bops->mark_type(p_bag, p_cnx, "_s_gs_type");
+
+ bops->mark_type(p_bag, p_cnx, "_s_gs_sequence");
+ bops->mark_type(p_bag, p_cnx, "_s_gs_message" );
+
+ bops->mark_type(p_bag, p_cnx, "_ref_s_gs_sequence");
+ bops->mark_type(p_bag, p_cnx, "_ref_s_gs_message");
+}
+
+
+/*......................................................................
+ * Ignored
+ */
+static
+struct s_gs_cat_ignored *
+_gs_ignored_cat_alloc(void) {
+ struct s_gs_cat_ignored *p_ignored = NULL;
+
+ p_ignored = malloc(sizeof (struct s_gs_cat_ignored));
+
+ return p_ignored;
+}
+
+static
+struct s_gs_cat_ignored *
+_gs_ignored_cat_new(void) {
+ struct s_gs_cat_ignored *p_ignored = NULL;
+
+ p_ignored = _gs_ignored_cat_alloc();
+ p_ignored->default_value = NULL;
+
+ return p_ignored;
+}
+
+
+struct s_gs_type *
+gs_type_new_ignored_with_callback(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name,
+ long int size,
+ long int alignment,
+ void *default_value,
+ void (*callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data)) {
+
+ struct s_gs_type *p_type = NULL;
+ struct s_gs_cat_ignored *p_ignored = NULL;
+
+ p_ignored = _gs_ignored_cat_new();
+ p_type = _gs_type_new(p_bag, p_connection, name);
+
+ p_type->size = size > 0?size:0;
+ p_type->alignment = alignment;
+
+ if (size > 0) {
+ long int aligned_size = aligned(size, alignment);
+
+ p_type->aligned_size = aligned_size;
+ } else {
+ p_type->aligned_size = 0;
+ }
+
+ if (default_value && p_type->size) {
+ p_ignored->default_value = gs_memdup(default_value, (size_t)size);
+ }
+
+ p_type->category_code = e_gs_type_cat_ignored;
+ p_type->category.ignored_data = p_ignored;
+
+ p_type->before_callback = callback;
+
+ return p_type;
+}
+
+struct s_gs_type *
+gs_type_new_ignored(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name,
+ long int size,
+ long int alignment,
+ void *default_value) {
+ return gs_type_new_ignored_with_callback(p_bag, p_connection, name, size, alignment, default_value, NULL);
+}
--- /dev/null
+/* gs_type.h */
+#ifndef GS_TYPE_H
+#define GS_TYPE_H
+
+
+/*
+ * Set of categories
+ */
+union u_gs_category {
+ void *undefined_data;
+ struct s_gs_cat_elemental *elemental_data;
+ struct s_gs_cat_struct *struct_data;
+ struct s_gs_cat_union *union_data;
+ struct s_gs_cat_ref *ref_data;
+ struct s_gs_cat_array *array_data;
+ struct s_gs_cat_ignored *ignored_data;
+};
+
+
+/*
+ * A type
+ */
+struct s_gs_type {
+ int code;
+ char *name;
+
+ long int size;
+
+ long int alignment;
+ long int aligned_size;
+
+ enum e_gs_type_category category_code;
+ union u_gs_category category;
+
+ void (*before_callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data);
+
+ void (*after_callback)(void *vars,
+ struct s_gs_type *p_type,
+ void *data);
+};
+
+#endif /* GS_TYPE_H */
--- /dev/null
+/* gs_type_driver.c */
+
+#include "gs/gs_private.h"
+
+static
+gras_dict_t *p_type_driver_dict = NULL;
+
+//GRAS_LOG_NEW_DEFAULT_CATEGORY(FIXME_type_driver);
+
+void
+gs_type_drivers_init(void) {
+ gras_error_t errcode;
+
+ TRYFAIL(gras_dict_new(&p_type_driver_dict));
+ TRYFAIL(gras_dict_insert(p_type_driver_dict, "rl", gs_rl_type_driver(), NULL));
+}
+
+
+struct s_gs_type_driver *
+gs_type_driver_init(const char *name) {
+
+ struct s_gs_type_driver_ops *type_driver_ops = NULL;
+ struct s_gs_type_driver *p_type_driver = NULL;
+
+ gras_dict_retrieve(p_type_driver_dict, name, (void **)&type_driver_ops);
+ if (!type_driver_ops)
+ GS_FAILURE("type driver not found");
+
+ p_type_driver = calloc(1, sizeof (struct s_gs_type_driver));
+ p_type_driver->type_ops = type_driver_ops;
+ p_type_driver->specific = NULL;
+
+ if (type_driver_ops->_init) {
+ type_driver_ops->_init(p_type_driver);
+ }
+
+ return p_type_driver;
+}
+
+
+
+void
+gs_type_driver_exit(struct s_gs_type_driver *p_type_driver){
+
+ struct s_gs_type_driver_ops *type_driver_ops = NULL;
+
+ type_driver_ops = p_type_driver->type_ops;
+ if (type_driver_ops->_exit) {
+ type_driver_ops->_exit(p_type_driver);
+ }
+
+ p_type_driver->type_ops = NULL;
+
+ if (p_type_driver->specific) {
+ free(p_type_driver->specific);
+ p_type_driver->specific = NULL;
+ }
+
+ free(p_type_driver);
+}
+
+struct s_gs_type_bag *
+gs_type_bag_alloc(struct s_gs_type_driver *p_driver) {
+
+ struct s_gs_type_bag *p_bag = NULL;
+ struct s_gs_type_bag_ops *bag_ops = p_driver->bag_ops;
+
+ p_bag = calloc(1, sizeof(struct s_gs_type_bag));
+
+ p_bag->bag_ops = bag_ops;
+ p_bag->p_type_driver = p_driver;
+ p_bag->specific = NULL;
+
+ if (bag_ops->_init) {
+ bag_ops->_init(p_bag);
+ }
+
+ return p_bag;
+}
+
+void
+gs_type_bag_free(struct s_gs_type_bag *p_bag) {
+
+ struct s_gs_type_bag_ops *bag_ops = p_bag->bag_ops;
+
+ if (bag_ops->_exit) {
+ bag_ops->_exit(p_bag);
+ }
+
+ if (p_bag->specific) {
+ free(p_bag->specific);
+ p_bag->specific = NULL;
+ }
+
+ free(p_bag);
+}
+
--- /dev/null
+/* gs_type_driver.h */
+#ifndef GS_TYPE_DRIVER_H
+#define GS_TYPE_DRIVER_H
+
+/* used structs */
+struct s_gs_type_bag;
+struct s_gs_type_driver;
+
+struct s_gs_type_driver_ops {
+
+ void
+ (*_init) (struct s_gs_type_driver *p_type_driver);
+
+ void
+ (*_exit) (struct s_gs_type_driver *p_type_driver);
+};
+
+struct s_gs_type_driver {
+ struct s_gs_type_driver_ops *type_ops;
+ struct s_gs_type_bag_ops *bag_ops;
+ void *specific;
+};
+
+
+#endif /* GS_TYPE_DRIVER_H */
--- /dev/null
+/* gs_rl_type_driver.c */
+
+#include "gs/gs_private.h"
+
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(NDR_tdriver_rl,NDR);
+/*
+ * structs
+ */
+struct s_gs_rl_type_driver {
+ /**/
+ int dummy;
+};
+
+struct s_gs_rl_type_bag {
+ gras_dict_t *incoming_dict;
+
+ gras_dynar_t *type_dynar;
+ gras_dict_t *type_dict;
+
+ gras_dynar_t *message_dynar;
+ gras_dict_t *message_dict;
+
+ gras_dict_t *outgoing_dict;
+};
+
+struct s_gs_rl_incoming_connection {
+ struct s_gs_connection *p_connection;
+
+ gras_dynar_t *type_dynar;
+ gras_dict_t *type_dict;
+
+ gras_dynar_t *message_dynar;
+ gras_dict_t *message_dict;
+};
+
+struct s_gs_rl_outgoing_connection {
+ struct s_gs_connection *p_connection;
+ gras_dict_t *type_marker_dict;
+ gras_dict_t *message_marker_dict;
+};
+
+
+/*
+ * static vars
+ */
+static
+struct s_gs_type_driver_ops *type_driver_ops = NULL;
+
+static
+struct s_gs_type_bag_ops *type_bag_ops = NULL;
+
+/*
+ * exported functions, driver part
+ */
+struct s_gs_type_driver_ops *
+gs_rl_type_driver(void) {
+
+ if (!type_bag_ops) {
+ type_bag_ops = calloc(1, sizeof(struct s_gs_type_bag_ops));
+
+
+ type_bag_ops->_init = gs_rl_bag__init;
+ type_bag_ops->_exit = gs_rl_bag__exit;
+
+
+ type_bag_ops->register_incoming_connection = gs_rl_bag_register_incoming_connection;
+ type_bag_ops->register_outgoing_connection = gs_rl_bag_register_outgoing_connection;
+
+
+ type_bag_ops->store_type = gs_rl_bag_store_type;
+ type_bag_ops->store_incoming_type = gs_rl_bag_store_incoming_type;
+ type_bag_ops->get_type_by_name = gs_rl_bag_get_type_by_name;
+ type_bag_ops->get_type_by_code = gs_rl_bag_get_type_by_code;
+ type_bag_ops->mark_type = gs_rl_bag_mark_type;
+ type_bag_ops->check_type_mark = gs_rl_bag_check_type_mark;
+
+
+ type_bag_ops->store_message = gs_rl_bag_store_message;
+ type_bag_ops->store_incoming_message = gs_rl_bag_store_incoming_message;
+ type_bag_ops->get_message_by_name = gs_rl_bag_get_message_by_name;
+ type_bag_ops->get_message_by_code = gs_rl_bag_get_message_by_code;
+ type_bag_ops->mark_message = gs_rl_bag_mark_message;
+ type_bag_ops->check_message_mark = gs_rl_bag_check_message_mark;
+ }
+
+ if (!type_driver_ops) {
+ type_driver_ops = calloc(1, sizeof(struct s_gs_type_driver_ops));
+
+ type_driver_ops->_init = gs_rl__init;
+ type_driver_ops->_exit = gs_rl__exit;
+ }
+
+ return type_driver_ops;
+}
+
+void
+gs_rl__init(struct s_gs_type_driver *p_driver) {
+
+ struct s_gs_rl_type_driver *p_rl = NULL;
+
+ p_rl = calloc(1, sizeof(struct s_gs_rl_type_driver));
+ p_driver->specific = p_rl;
+ p_driver->bag_ops = type_bag_ops;
+}
+
+void
+gs_rl__exit(struct s_gs_type_driver *p_driver) {
+
+ struct s_gs_rl_type_driver *p_rl = p_driver->specific;
+
+ free(p_rl);
+ p_driver->specific = NULL;
+}
+
+/*
+ * exported functions, bag part
+ */
+
+/* management */
+void
+gs_rl_bag__init(struct s_gs_type_bag *p_bag) {
+
+ struct s_gs_rl_type_bag *p_rl = NULL;
+
+ p_rl = calloc(1, sizeof(struct s_gs_rl_type_bag));
+
+ gras_dict_new(&p_rl->incoming_dict);
+
+ gras_dynar_new(&p_rl->type_dynar, sizeof(struct s_gs_type *), NULL);
+ gras_dict_new (&p_rl->type_dict);
+
+ gras_dynar_new(&p_rl->message_dynar, sizeof(struct s_gs_type *), NULL);
+ gras_dict_new (&p_rl->message_dict);
+
+ gras_dict_new (&p_rl->outgoing_dict);
+
+ p_bag->specific = p_rl;
+ p_bag->bag_ops = type_bag_ops;
+
+ gs_bootstrap_type_bag(p_bag);
+}
+
+void
+gs_rl_bag__exit(struct s_gs_type_bag *p_bag) {
+
+ struct s_gs_rl_type_bag *p_rl = p_bag->specific;
+
+ gras_dict_free(&p_rl->type_dict);
+ gras_dynar_free(p_rl->type_dynar);
+
+ free(p_rl);
+ p_bag->specific = NULL;
+}
+
+/* connection */
+void
+gs_rl_bag_register_incoming_connection(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx) {
+
+ struct s_gs_rl_type_bag *p_rl = p_bag->specific;
+ struct s_gs_rl_incoming_connection *p_in = NULL;
+
+ if (p_cnx->direction != e_gs_connection_direction_incoming)
+ GS_FAILURE("invalid operation");
+
+ p_in = malloc(sizeof (struct s_gs_rl_incoming_connection));
+
+ p_in->p_connection = p_cnx;
+
+ gras_dynar_new(&p_in->type_dynar, sizeof(struct s_gs_type *), NULL);
+ gras_dict_new (&p_in->type_dict);
+
+ gras_dynar_new(&p_in->message_dynar, sizeof(struct s_gs_type *), NULL);
+ gras_dict_new (&p_in->message_dict);
+
+ gras_dict_insert_ext(p_rl->incoming_dict,
+ (char *)&p_cnx,
+ sizeof(p_cnx),
+ p_in,
+ NULL);
+
+ gs_bootstrap_incoming_connection(p_bag, p_cnx);
+}
+
+
+void
+gs_rl_bag_register_outgoing_connection(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx) {
+
+ struct s_gs_rl_type_bag *p_rl = p_bag->specific;
+ struct s_gs_rl_outgoing_connection *p_out = NULL;
+
+ if (p_cnx->direction != e_gs_connection_direction_outgoing)
+ GS_FAILURE("invalid operation");
+
+ p_out = malloc(sizeof (struct s_gs_rl_outgoing_connection));
+
+ p_out->p_connection = p_cnx;
+ gras_dict_new(&p_out->type_marker_dict);
+ gras_dict_new(&p_out->message_marker_dict);
+
+ gras_dict_insert_ext(p_rl->outgoing_dict, (char *)&p_cnx, sizeof(p_cnx), p_out, NULL);
+
+ gs_bootstrap_outgoing_connection(p_bag, p_cnx);
+}
+
+
+/* types */
+void
+gs_rl_bag_store_type(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx,
+ struct s_gs_type *p_type) {
+
+ struct s_gs_rl_type_bag *p_rl = p_bag->specific;
+ struct s_gs_type **pp_type = NULL;
+
+ pp_type = malloc(sizeof(struct s_gs_type *));
+ *pp_type = p_type;
+
+ if (p_cnx) {
+ struct s_gs_rl_incoming_connection *p_in = NULL;
+
+ if (p_cnx->direction != e_gs_connection_direction_incoming)
+ GS_FAILURE("invalid operation");
+
+ gras_dict_retrieve_ext(p_rl->incoming_dict,
+ (char *)&p_cnx,
+ sizeof(p_cnx),
+ (void **)&p_in);
+
+
+ p_type->code = gras_dynar_length(p_in->type_dynar);
+ gras_dynar_insert_at(p_in->type_dynar, p_type->code, pp_type);
+ gras_dict_insert(p_in->type_dict, p_type->name, pp_type, NULL);
+ } else {
+ p_type->code = gras_dynar_length(p_rl->type_dynar);
+ gras_dynar_insert_at(p_rl->type_dynar, p_type->code, pp_type);
+ gras_dict_insert(p_rl->type_dict, p_type->name, pp_type, NULL);
+ }
+}
+
+void
+gs_rl_bag_store_incoming_type(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx,
+ struct s_gs_type *p_type) {
+
+ struct s_gs_rl_type_bag *p_rl = p_bag->specific;
+ struct s_gs_rl_incoming_connection *p_in = NULL;
+ struct s_gs_type **pp_type = NULL;
+
+ if (p_cnx->direction != e_gs_connection_direction_incoming)
+ GS_FAILURE("invalid operation");
+
+ gras_dict_retrieve_ext(p_rl->incoming_dict,
+ (char *)&p_cnx,
+ sizeof(p_cnx),
+ (void **)&p_in);
+
+ pp_type = malloc(sizeof(struct s_gs_type *));
+ *pp_type = p_type;
+
+ gras_dynar_set(p_in->type_dynar, p_type->code, pp_type);
+ gras_dict_insert(p_in->type_dict, p_type->name, pp_type, NULL);
+}
+
+struct s_gs_type *
+gs_rl_bag_get_type_by_name(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx,
+ const char *name) {
+
+ struct s_gs_rl_type_bag *p_rl = p_bag->specific;
+ struct s_gs_type **pp_type = NULL;
+
+ if (p_cnx) {
+ struct s_gs_rl_incoming_connection *p_in = NULL;
+
+ if (p_cnx->direction != e_gs_connection_direction_incoming)
+ GS_FAILURE("invalid operation");
+
+ gras_dict_retrieve_ext(p_rl->incoming_dict,
+ (char *)&p_cnx,
+ sizeof(p_cnx),
+ (void **)&p_in);
+
+ gras_dict_retrieve(p_in->type_dict, name, (void **)&pp_type);
+ } else {
+ gras_dict_retrieve(p_rl->type_dict, name, (void **)&pp_type);
+ }
+
+ if (!pp_type) {
+ DEBUG1("Get type by name '%s': not found",name);
+ return NULL;
+ }
+
+ DEBUG1("Get type by name '%s': found",name);
+ return *pp_type;
+}
+
+struct s_gs_type *
+gs_rl_bag_get_type_by_code(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx,
+ int code) {
+
+ struct s_gs_rl_type_bag *p_rl = p_bag->specific;
+ struct s_gs_type *p_type = NULL;
+
+ if (p_cnx) {
+ struct s_gs_rl_incoming_connection *p_in = NULL;
+
+ if (p_cnx->direction != e_gs_connection_direction_incoming)
+ GS_FAILURE("invalid operation");
+
+ gras_dict_retrieve_ext(p_rl->incoming_dict,
+ (char *)&p_cnx,
+ sizeof(p_cnx),
+ (void **)&p_in);
+
+ if ((unsigned int)code < gras_dynar_length(p_in->type_dynar)) {
+ gras_dynar_get(p_in->type_dynar, code, (void **)&p_type);
+ }
+ } else {
+ if ((unsigned int)code < gras_dynar_length(p_rl->type_dynar)) {
+ gras_dynar_get(p_rl->type_dynar, code, (void **)&p_type);
+ }
+ }
+
+ return p_type;
+}
+
+void
+gs_rl_bag_mark_type(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx,
+ const char *name) {
+
+ struct s_gs_rl_type_bag *p_rl = p_bag->specific;
+ struct s_gs_rl_outgoing_connection *p_out = NULL;
+
+ if (p_cnx->direction != e_gs_connection_direction_outgoing)
+ GS_FAILURE("invalid operation");
+
+ gras_dict_retrieve_ext(p_rl->outgoing_dict, (char *)&p_cnx, sizeof(p_cnx), (void **)&p_out);
+
+ if (!p_out)
+ GS_FAILURE("unregistered connection");
+
+ gras_dict_insert(p_out->type_marker_dict, name, strdup(name), NULL);
+}
+
+int
+gs_rl_bag_check_type_mark(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx,
+ const char *name) {
+
+ struct s_gs_rl_type_bag *p_rl = p_bag->specific;
+ struct s_gs_rl_outgoing_connection *p_out = NULL;
+ char *result = NULL;
+
+ if (p_cnx->direction != e_gs_connection_direction_outgoing)
+ GS_FAILURE("invalid operation");
+
+ gras_dict_retrieve_ext(p_rl->outgoing_dict, (char *)&p_cnx, sizeof(p_cnx), (void **)&p_out);
+
+ if (!p_out)
+ GS_FAILURE("unregistered connection");
+
+ gras_dict_retrieve(p_out->type_marker_dict, name, (void **)&result);
+
+ return !!result;
+}
+
+/* messages */
+void
+gs_rl_bag_store_message(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx,
+ struct s_gs_message *p_message) {
+
+ struct s_gs_rl_type_bag *p_rl = p_bag->specific;
+ struct s_gs_message **pp_message = NULL;
+
+ pp_message = malloc(sizeof(struct s_gs_message *));
+ *pp_message = p_message;
+
+ if (p_cnx) {
+ struct s_gs_rl_incoming_connection *p_in = NULL;
+
+ if (p_cnx->direction != e_gs_connection_direction_incoming)
+ GS_FAILURE("invalid operation");
+
+ gras_dict_retrieve_ext(p_rl->incoming_dict,
+ (char *)&p_cnx,
+ sizeof(p_cnx),
+ (void **)&p_in);
+
+
+ p_message->code = gras_dynar_length(p_in->message_dynar);
+ gras_dynar_insert_at(p_in->message_dynar, p_message->code, pp_message);
+ gras_dict_insert(p_in->message_dict, p_message->name, pp_message, NULL);
+ } else {
+ p_message->code = gras_dynar_length(p_rl->message_dynar);
+ gras_dynar_insert_at(p_rl->message_dynar, p_message->code, pp_message);
+ gras_dict_insert(p_rl->message_dict, p_message->name, pp_message, NULL);
+ }
+}
+
+void
+gs_rl_bag_store_incoming_message(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx,
+ struct s_gs_message *p_message) {
+
+ struct s_gs_rl_type_bag *p_rl = p_bag->specific;
+ struct s_gs_rl_incoming_connection *p_in = NULL;
+ struct s_gs_message **pp_message = NULL;
+
+ if (p_cnx->direction != e_gs_connection_direction_incoming)
+ GS_FAILURE("invalid operation");
+
+ gras_dict_retrieve_ext(p_rl->incoming_dict,
+ (char *)&p_cnx,
+ sizeof(p_cnx),
+ (void **)&p_in);
+
+ pp_message = malloc(sizeof(struct s_gs_message *));
+ *pp_message = p_message;
+
+ gras_dynar_set(p_in->message_dynar, p_message->code, pp_message);
+ gras_dict_insert(p_in->message_dict, p_message->name, pp_message, NULL);
+}
+
+struct s_gs_message *
+gs_rl_bag_get_message_by_name(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx,
+ const char *name) {
+
+ struct s_gs_rl_type_bag *p_rl = p_bag->specific;
+ struct s_gs_message **pp_message = NULL;
+
+ if (p_cnx) {
+ struct s_gs_rl_incoming_connection *p_in = NULL;
+
+ if (p_cnx->direction != e_gs_connection_direction_incoming)
+ GS_FAILURE("invalid operation");
+
+ gras_dict_retrieve_ext(p_rl->incoming_dict,
+ (char *)&p_cnx,
+ sizeof(p_cnx),
+ (void **)&p_in);
+
+ gras_dict_retrieve(p_in->message_dict, name, (void **)&pp_message);
+ } else {
+ gras_dict_retrieve(p_rl->message_dict, name, (void **)&pp_message);
+ }
+
+ if (!pp_message) {
+ return NULL;
+ }
+
+ return *pp_message;
+}
+
+struct s_gs_message *
+gs_rl_bag_get_message_by_code(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx,
+ int code) {
+
+ struct s_gs_rl_type_bag *p_rl = p_bag->specific;
+ struct s_gs_message *p_message = NULL;
+
+ if (p_cnx) {
+ struct s_gs_rl_incoming_connection *p_in = NULL;
+
+ if (p_cnx->direction != e_gs_connection_direction_incoming)
+ GS_FAILURE("invalid operation");
+
+ gras_dict_retrieve_ext(p_rl->incoming_dict,
+ (char *)&p_cnx,
+ sizeof(p_cnx),
+ (void **)&p_in);
+
+ if ((unsigned int)code < gras_dynar_length(p_in->message_dynar)) {
+ gras_dynar_get(p_in->message_dynar, code, (void **)&p_message);
+ }
+ } else {
+ if ((unsigned int)code < gras_dynar_length(p_rl->message_dynar)) {
+ gras_dynar_get(p_rl->message_dynar, code, (void **)&p_message);
+ }
+ }
+
+ return p_message;
+}
+
+void
+gs_rl_bag_mark_message(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx,
+ const char *name) {
+
+ struct s_gs_rl_type_bag *p_rl = p_bag->specific;
+ struct s_gs_rl_outgoing_connection *p_out = NULL;
+
+ if (p_cnx->direction != e_gs_connection_direction_outgoing)
+ GS_FAILURE("invalid operation");
+
+ gras_dict_retrieve_ext(p_rl->outgoing_dict, (char *)&p_cnx, sizeof(p_cnx), (void **)&p_out);
+
+ if (!p_out)
+ GS_FAILURE("unregistered connection");
+
+ gras_dict_insert(p_out->message_marker_dict, name, strdup(name), NULL);
+}
+
+int
+gs_rl_bag_check_message_mark(struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx,
+ const char *name) {
+
+ struct s_gs_rl_type_bag *p_rl = p_bag->specific;
+ struct s_gs_rl_outgoing_connection *p_out = NULL;
+ char *result = NULL;
+
+ if (p_cnx->direction != e_gs_connection_direction_outgoing)
+ GS_FAILURE("invalid operation");
+
+ gras_dict_retrieve_ext(p_rl->outgoing_dict, (char *)&p_cnx, sizeof(p_cnx), (void **)&p_out);
+
+ if (!p_out)
+ GS_FAILURE("unregistered connection");
+
+ gras_dict_retrieve(p_out->message_marker_dict, name, (void **)&result);
+
+ return !!result;
+}
+
+
--- /dev/null
+/* gs_rl_type_interface.h */
+#ifndef GS_RL_TYPE_INTERFACE_H
+#define GS_RL_TYPE_INTERFACE_H
+
+struct s_gs_type_driver_ops *
+gs_rl_type_driver(void);
+
+
+
+void
+gs_rl__init(struct s_gs_type_driver *p_driver);
+
+void
+gs_rl__exit(struct s_gs_type_driver *p_driver);
+
+
+
+void
+gs_rl_bag__init(struct s_gs_type_bag *p_bag);
+
+void
+gs_rl_bag__exit(struct s_gs_type_bag *p_bag);
+
+
+
+void
+gs_rl_bag_register_incoming_connection (struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection);
+
+void
+gs_rl_bag_register_outgoing_connection (struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection);
+
+
+
+void
+gs_rl_bag_store_type (struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ struct s_gs_type *p_type);
+
+void
+gs_rl_bag_store_incoming_type (struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx,
+ struct s_gs_type *p_type);
+
+struct s_gs_type *
+gs_rl_bag_get_type_by_name (struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name);
+
+struct s_gs_type *
+gs_rl_bag_get_type_by_code (struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ int code);
+
+void
+gs_rl_bag_mark_type (struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name);
+
+int
+gs_rl_bag_check_type_mark (struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name);
+
+
+
+void
+gs_rl_bag_store_message (struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ struct s_gs_message *p_message);
+
+void
+gs_rl_bag_store_incoming_message (struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_cnx,
+ struct s_gs_message *p_message);
+
+struct s_gs_message *
+gs_rl_bag_get_message_by_name (struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name);
+
+struct s_gs_message *
+gs_rl_bag_get_message_by_code (struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ int code);
+
+void
+gs_rl_bag_mark_message (struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name);
+
+int
+gs_rl_bag_check_message_mark (struct s_gs_type_bag *p_bag,
+ struct s_gs_connection *p_connection,
+ const char *name);
+
+#endif /* GS_RL_TYPE_INTERFACE_H */
--- /dev/null
+/* gs_vars.c */
+
+#include "gs/gs_private.h"
+
+struct s_gs_var {
+ struct s_gs_type *p_type;
+ void *data;
+};
+
+
+struct s_gs_vars {
+ gras_dict_t *space;
+ gras_dynar_t *stack;
+ gras_dynar_t *globals;
+};
+
+
+static
+void
+_gs_vars_pop(struct s_gs_vars *p_vars,
+ const char *name) {
+
+ gras_dynar_t *p_dynar = NULL;
+ struct s_gs_var *p_var = NULL;
+
+ gras_dict_retrieve(p_vars->space, name, (void **)&p_dynar);
+ gras_dynar_pop(p_dynar, &p_var);
+
+ if (!gras_dynar_length(p_dynar)) {
+ gras_dict_remove(p_vars->space, name);
+ gras_dynar_free_container(p_dynar);
+ }
+
+ free(p_var);
+}
+
+void *
+gs_vars_pop(void *_p_vars,
+ const char *name,
+ struct s_gs_type **pp_type) {
+
+ struct s_gs_vars *p_vars = _p_vars;
+ gras_dynar_t *p_dynar = NULL;
+ struct s_gs_var *p_var = NULL;
+ void *data = NULL;
+
+ gras_dict_retrieve(p_vars->space, name, (void **)&p_dynar);
+ gras_dynar_pop(p_dynar, &p_var);
+
+ if (!gras_dynar_length(p_dynar)) {
+ gras_dict_remove(p_vars->space, name);
+ gras_dynar_free_container(p_dynar);
+ }
+
+ if (pp_type) {
+ *pp_type = p_var->p_type;
+ }
+
+ data = p_var->data;
+
+ free(p_var);
+
+ gras_dynar_pop(p_vars->stack, &p_dynar);
+ {
+ int l = gras_dynar_length(p_dynar);
+
+ while (l--) {
+ char *_name = NULL;
+
+ gras_dynar_get(p_dynar, l, &_name);
+ if (!strcmp(name, _name)) {
+ gras_dynar_remove_at(p_dynar, l, &_name);
+ free(_name);
+ break;
+ }
+ }
+ }
+ gras_dynar_push(p_vars->stack, &p_dynar);
+
+
+ return data;
+}
+
+void
+gs_vars_push(void *_p_vars,
+ struct s_gs_type *p_type,
+ const char *name,
+ void *data) {
+
+ struct s_gs_vars *p_vars = _p_vars;
+ gras_dynar_t *p_dynar = NULL;
+ struct s_gs_var *p_var = NULL;
+
+ name = strdup(name);
+
+ gras_dict_retrieve(p_vars->space, name, (void **)&p_dynar);
+
+ if (!p_dynar) {
+ gras_dynar_new(&p_dynar, sizeof (struct s_gs_var *), NULL);
+ gras_dict_insert(p_vars->space, name, (void **)p_dynar, NULL);
+ }
+
+ p_var = calloc(1, sizeof(struct s_gs_var));
+ p_var->p_type = p_type;
+ p_var->data = data;
+
+ gras_dynar_push(p_dynar, &p_var);
+
+ gras_dynar_pop(p_vars->stack, &p_dynar);
+ gras_dynar_push(p_dynar, &name);
+ gras_dynar_push(p_vars->stack, &p_dynar);
+}
+
+void
+gs_vars_set(void *_p_vars,
+ struct s_gs_type *p_type,
+ const char *name,
+ void *data) {
+
+ struct s_gs_vars *p_vars = _p_vars;
+ gras_dynar_t *p_dynar = NULL;
+ struct s_gs_var *p_var = NULL;
+
+ name = strdup(name);
+ gras_dict_retrieve(p_vars->space, name, (void **)&p_dynar);
+
+ if (!p_dynar) {
+ gras_dynar_new(&p_dynar, sizeof (struct s_gs_var *), NULL);
+ gras_dict_insert(p_vars->space, name, (void **)p_dynar, NULL);
+
+ p_var = calloc(1, sizeof(struct s_gs_var));
+ gras_dynar_push(p_vars->globals, &name);
+ } else {
+ gras_dynar_pop(p_dynar, &p_var);
+ }
+
+ p_var->p_type = p_type;
+ p_var->data = data;
+
+ gras_dynar_push(p_dynar, &p_var);
+}
+
+void *
+gs_vars_get(void *_p_vars,
+ const char *name,
+ struct s_gs_type **pp_type) {
+
+ struct s_gs_vars *p_vars = _p_vars;
+ gras_dynar_t *p_dynar = NULL;
+ struct s_gs_var *p_var = NULL;
+
+ gras_dict_retrieve(p_vars->space, name, (void **)&p_dynar);
+ gras_dynar_pop(p_dynar, &p_var);
+ gras_dynar_push(p_dynar, &p_var);
+
+ if (pp_type) {
+ *pp_type = p_var->p_type;
+ }
+
+ return p_var->data;
+}
+
+void
+gs_vars_enter(void *_p_vars) {
+
+ struct s_gs_vars *p_vars = _p_vars;
+ gras_dynar_t *p_dynar = NULL;
+
+ gras_dynar_new(&p_dynar, sizeof (char *), NULL);
+ gras_dynar_push(p_vars->stack, &p_dynar);
+}
+
+
+void
+gs_vars_leave(void *_p_vars) {
+ struct s_gs_vars *p_vars = _p_vars;
+ gras_dynar_t *p_dynar = NULL;
+ int cursor = 0;
+ char *name = NULL;
+
+ gras_dynar_pop(p_vars->stack, &p_dynar);
+
+ gras_dynar_foreach(p_dynar, cursor, name) {
+ _gs_vars_pop(p_vars, name);
+ free(name);
+ }
+
+ gras_dynar_free_container(p_dynar);
+}
+
+
+void *
+gs_vars_alloc(void) {
+
+ struct s_gs_vars *p_vars = NULL;
+
+ p_vars = calloc(1, sizeof (struct s_gs_vars));
+
+ gras_dict_new (&p_vars->space);
+ gras_dynar_new(&p_vars->stack, sizeof (gras_dynar_t *), NULL);
+
+ gs_vars_enter(p_vars);
+
+ gras_dynar_pop(p_vars->stack, &p_vars->globals);
+ gras_dynar_push(p_vars->stack, &p_vars->globals);
+
+ return p_vars;
+}
+
+
+void
+gs_vars_free(void *_p_vars) {
+
+ struct s_gs_vars *p_vars = _p_vars;
+
+ gs_vars_leave(p_vars);
+
+ gras_dynar_free_container(p_vars->stack);
+ gras_dict_free(&p_vars->space);
+
+ free(p_vars);
+}
+