Esempio n. 1
0
attr_info_t *add_attribute (arff_info_t * info, char *name)
{
	attr_info_t *r =
		(attr_info_t *) malloc_dbg (31, sizeof (attr_info_t)), *x;

	r->name = (char *) malloc_dbg (32, strlen (name) + 1);
	strcpy (r->name, name);
	r->type = ATTR_NUM_TYPES;
	r->nom_info = NULL;
	r->next = NULL;

	if (first_attr == NULL) {
		first_attr = r;
	} else {
		for (x = first_attr; x->next != NULL; x = x->next);
		x->next = r;
	}

	if (!stricmp (name, class_name)) {
		info->class_index = info->num_attributes;
	}

	info->num_attributes++;

	DEBUGMSG (("  create attribute %s, total = %i\n", name,
		   info->num_attributes));

	return r;
}
Esempio n. 2
0
/* functions */
arff_info_t *read_arff (char *filename, char *class_attribute_name)
{
	arff_info_t *info = init (class_attribute_name);
	FILE *in;
	int size;
	char *buf;

	if (!(in = fopen (filename, "r"))) {
		sprintf (error_string, "unable to open file: %s", filename);
	} else {
		fseek (in, 0, SEEK_END);
		size = ftell (in);
		buf = (char *) malloc_dbg (25, size + 1);
		fseek (in, 0, SEEK_SET);
		size = fread (buf, 1, size, in);

		if (FAIL (lex (buf, info))) {
			release_read_info (info);
			info = NULL;
		}

		free (buf);
	}
	return info;
}
Esempio n. 3
0
void add_nominal_class (nom_info_t * info, char *name)
{
	nom_val_t *r = (nom_val_t *) malloc_dbg (33, sizeof (nom_val_t)), *x;
	r->name = (char *) malloc_dbg (34, strlen (name) + 1);
	strcpy (r->name, name);
	r->val = info->num_classes++;
	r->next = NULL;

	if (info->first == NULL) {
		info->first = r;
	} else {
		for (x = info->first; x->next != NULL; x = x->next);
		x->next = r;
	}

	DEBUGMSG (("  create nominal class %s, index = %i\n", name, r->val));
}
Esempio n. 4
0
void parse_end (arff_info_t * info)
{
	int i;
	attr_info_t *attr_info;
	instance_t *instance;
	info->attributes =
		(attr_info_t **) malloc_dbg (29, sizeof (attr_info_t *) *
					     info->num_attributes);
	for (i = 0, attr_info = first_attr; attr_info != NULL;
	     attr_info = attr_info->next, i++) {
		info->attributes[i] = attr_info;
	}
	info->instances =
		(instance_t **) malloc_dbg (30, sizeof (instance_t *) *
					    info->num_instances);
	for (i = 0, instance = first_inst; instance != NULL;
	     instance = instance->next, i++) {
		info->instances[i] = instance;
	}
}
Esempio n. 5
0
parse_state_t parse_attribute2_nominal (token_t token, char *name,
					arff_info_t * info)
{
	curr_attr->type = ATTR_NOMINAL;
	curr_attr->nom_info =
		(nom_info_t *) malloc_dbg (28, sizeof (nom_info_t));
	curr_attr->nom_info->num_classes = 0;
	curr_attr->nom_info->first = NULL;
	DEBUGMSG (("  set attribute type = ATTR_NOMINAL\n"));
	return PARSE_STATE_ATTRIBUTE_NOM1;
}
Esempio n. 6
0
instance_t *add_instance (arff_info_t * info)
{
	instance_t *r =
		(instance_t *) malloc_dbg (35, sizeof (instance_t)), *x;
	r->data =
		(data_t *) malloc_dbg (36,
				       sizeof (data_t) *
				       info->num_attributes);
	r->next = NULL;

	if (first_inst == NULL) {
		first_inst = r;
	} else {
		for (x = first_inst; x->next != NULL; x = x->next);
		x->next = r;
	}
	info->num_instances++;

	DEBUGMSG (("  create instance, total = %i\n", info->num_instances));

	return r;
}
Esempio n. 7
0
return_value_t http_init()
{
    http_state.parser = malloc_dbg(sizeof(http_parser),10);
    parser = http_state.parser;
    http_parser_init(parser,HTTP_REQUEST);
    http_state.parser_settings = malloc_dbg(sizeof(http_parser_settings),11);
    settings = http_state.parser_settings;
    settings->on_body = 0;
    settings->on_header_field = 0;
    settings->on_header_value = 0;
    settings->on_headers_complete = 0;
    settings->on_message_begin = 0;
    settings->on_message_complete = 0;
    settings->on_status_complete = 0;
    settings->on_url = 0;
    http_state.num_requests = 0;
    http_state.json_parser = malloc_dbg(sizeof(jsmn_parser),44);
    json_parser = http_state.json_parser;
    if(parser == NULL || settings == NULL || json_parser == NULL){
        //could not allocate parser, error
        http_state.init_return = RET_ERROR;
    } else {
        http_state.init_return = RET_OK;
    }


    if(http_state.init_return == RET_OK){
        if(CB_Init(&http_state.rx_buffer,http_rx_buffer,HTTP_RX_BUFFER_SIZE*sizeof(xbee_rx_ip_packet_t))!=SUCCESS){
            http_state.init_return = RET_ERROR;
        } else {
            http_state.init_return = RET_OK;
        }
    }
    
    if(http_state.init_return == RET_OK){
        rf_add_ip_rx_packet_handler(http_handle_rx_packet);
    }
    return http_state.init_return;
}
Esempio n. 8
0
parse_state_t parse_relation1 (token_t token, char *name, arff_info_t * info)
{
	parse_state_t r = PARSE_STATE_ERROR;
	if (name == NULL) {
		sprintf (error_string, "unexpected token: %s",
			 name == NULL ? token_names[token] : name);
	} else {
		info->relation_name =
			(char *) malloc_dbg (27, strlen (name) + 1);
		strcpy (info->relation_name, name);
		r = PARSE_STATE_GET_NEWLINE;
		DEBUGMSG (("  set relation name = %s\n", name));
	}
	return r;
}
Esempio n. 9
0
arff_info_t *init (char *class_attribute_name)
{
	arff_info_t *info =
		(arff_info_t *) malloc_dbg (26, sizeof (arff_info_t));
	info->relation_name = NULL;
	info->num_attributes = 0;
	info->attributes = NULL;
	info->num_instances = 0;
	info->instances = NULL;
	info->class_index = -1;

	state = PARSE_STATE_NEWLINE;
	first_attr = NULL;
	first_inst = NULL;
	curr_instance = NULL;
	strcpy (error_string, "");
	class_name = class_attribute_name;
	line_no = 1;
	return info;
}