Esempio n. 1
0
static wi_string_t * _wi_p7_message_description(wi_runtime_instance_t *instance) {
	wi_p7_message_t			*p7_message = instance;
	wi_enumerator_t			*enumerator;
	wi_dictionary_t			*fields;
	wi_mutable_string_t		*string;
	wi_string_t				*field_name, *field_value;
	
	string = wi_mutable_string_with_format(WI_STR("<%@ %p>{name = %@, buffer = %@, fields = (\n"),
        wi_runtime_class_name(p7_message),
        p7_message,
		p7_message->name,
		wi_data_with_bytes_no_copy(p7_message->binary_buffer, p7_message->binary_size, false));
	
	fields		= wi_p7_message_fields(p7_message);
	enumerator	= wi_dictionary_key_enumerator(fields);
	
	while((field_name = wi_enumerator_next_data(enumerator))) {
		field_value = wi_dictionary_data_for_key(fields, field_name);

		wi_mutable_string_append_format(string, WI_STR("    %@ = %@\n"),
			field_name, field_value);
	}
	
	wi_mutable_string_append_string(string, WI_STR(")}"));
	
	wi_runtime_make_immutable(string);
	
	return string;
}
Esempio n. 2
0
static wi_string_t * _wi_set_description(wi_runtime_instance_t *instance) {
	wi_set_t				*set = instance;
	_wi_set_bucket_t		*bucket;
	wi_mutable_string_t		*string;
	wi_string_t				*description;
	wi_uinteger_t			i;

	string = wi_mutable_string_with_format(WI_STR("<%@ %p>{count = %lu, mutable = %u, values = (\n"),
		wi_runtime_class_name(set),
		set,
		set->data_count,
		wi_runtime_options(set) & WI_RUNTIME_OPTION_MUTABLE ? 1 : 0);

	for(i = 0; i < set->buckets_count; i++) {
		for(bucket = set->buckets[i]; bucket; bucket = bucket->next) {
			if(set->callbacks.description)
				description = (*set->callbacks.description)(bucket->data);
			else
				description = wi_string_with_format(WI_STR("%p"), bucket->data);

			wi_mutable_string_append_format(string, WI_STR("    %@\n"), description);
		}
	}
	
	wi_mutable_string_append_string(string, WI_STR(")}"));
	
	wi_runtime_make_immutable(string);

	return string;
}
Esempio n. 3
0
static wi_string_t * _wi_dictionary_description(wi_runtime_instance_t *instance) {
    wi_dictionary_t             *dictionary = instance;
    _wi_dictionary_bucket_t     *bucket;
    wi_mutable_string_t         *string;
    wi_string_t                 *key_description, *value_description;
    wi_uinteger_t               i;

    string = wi_mutable_string_with_format(WI_STR("<%@ %p>{count = %lu, mutable = %u, values = (\n"),
                                           wi_runtime_class_name(dictionary),
                                           dictionary,
                                           dictionary->key_count,
                                           wi_runtime_options(dictionary) & WI_RUNTIME_OPTION_MUTABLE ? 1 : 0);

    for(i = 0; i < dictionary->buckets_count; i++) {
        for(bucket = dictionary->buckets[i]; bucket; bucket = bucket->next) {
            if(dictionary->key_callbacks.description)
                key_description = (*dictionary->key_callbacks.description)(bucket->key);
            else
                key_description = wi_string_with_format(WI_STR("%p"), bucket->key);

            if(dictionary->value_callbacks.description)
                value_description = (*dictionary->value_callbacks.description)(bucket->data);
            else
                value_description = wi_string_with_format(WI_STR("%p"), bucket->data);

            wi_mutable_string_append_format(string, WI_STR("    %@: %@\n"), key_description, value_description);
        }
    }

    wi_mutable_string_append_string(string, WI_STR(")}"));

    wi_runtime_make_immutable(string);

    return string;
}
Esempio n. 4
0
static wi_string_t * _wi_number_description(wi_runtime_instance_t *instance) {
	wi_number_t				*number = instance;
	wi_mutable_string_t		*string;
	
	string = wi_mutable_string_with_format(WI_STR("<%@ %p>{value = "),
		wi_runtime_class_name(number),
		number);
	
	if(_wi_number_is_float(number))
		wi_mutable_string_append_format(string, WI_STR("%f"), wi_number_double(number));
	else
		wi_mutable_string_append_format(string, WI_STR("%lld"), wi_number_int64(number));
	
	wi_mutable_string_append_string(string, WI_STR("}"));
	
	wi_runtime_make_immutable(string);
	
	return string;
}
Esempio n. 5
0
void _wi_url_regenerate_string(wi_url_t *url) {
	wi_release(url->string);
	
	url->string = wi_string_init_with_format(wi_mutable_string_alloc(), WI_STR("%#@://"), url->scheme);
	
	if(url->user && wi_string_length(url->user) > 0) {
		wi_mutable_string_append_format(url->string, WI_STR("%#@"), url->user);
		
		if(url->password && wi_string_length(url->password) > 0)
			wi_mutable_string_append_format(url->string, WI_STR(":%#@"), url->password);
	
		wi_mutable_string_append_string(url->string, WI_STR("@"));
	}
	wi_mutable_string_append_format(url->string, WI_STR("%#@"), url->host);
	
	if(url->port > 0)
		wi_mutable_string_append_format(url->string, WI_STR(":%lu"), url->port);
	
	if(url->path)
		wi_mutable_string_append_string(url->string, url->path);
	else
		wi_mutable_string_append_string(url->string, WI_STR("/"));
}
Esempio n. 6
0
static void wr_command_help(wi_array_t *arguments) {
	wi_mutable_string_t		*string;
	wi_size_t				size;
	wi_uinteger_t			i, x, max, length, max_length;

	if(wi_array_count(arguments) > 0) {
		wr_commands_print_usage_for_command(WI_ARRAY(arguments, 0));
	} else {
		wr_printf_prefix(WI_STR("Commands:"));

		max			= WI_ARRAY_SIZE(wr_commands) - 1;
		max_length	= 0;

		for(i = 0; i < max; i++) {
			if(wr_commands[i].help) {
				length = strlen(wr_commands[i].name);
				max_length = WI_MAX(length, max_length);
			}
		}
		
		size		= wi_terminal_size(wr_terminal);
		string		= wi_mutable_string();

		for(i = 0, x = 0; i < max; i++) {
			if(wr_commands[i].help) {
				if(!string)
					string = wi_string_init(wi_string_alloc());

				wi_mutable_string_append_format(string, WI_STR("   %s%*s"),
					wr_commands[i].name,
					max_length - strlen(wr_commands[i].name) + 1,
					" ");

				if(wi_terminal_width_of_string(wr_terminal, string) >=
				   size.width - max_length - max_length) {
					wr_printf(WI_STR("%@"), string);
					
					wi_mutable_string_set_string(string, WI_STR(""));
				}
			}
		}
		
		if(wi_string_length(string) > 0)
			wr_printf(WI_STR("%@"), string);
	}
}
Esempio n. 7
0
static wi_string_t * _wi_data_description(wi_runtime_instance_t *instance) {
	wi_data_t				*data = instance;
	wi_mutable_string_t		*string;
	const unsigned char		*bytes;
	wi_uinteger_t			i;
	
	string		= wi_mutable_string();
	bytes		= data->bytes;
	
	for(i = 0; i < data->length; i++) {
		if(i > 0 && i % 4 == 0)
			wi_mutable_string_append_string(string, WI_STR(" "));

		wi_mutable_string_append_format(string, WI_STR("%02X"), bytes[i]);
	}
	
	wi_runtime_make_immutable(string);
	
	return string;
}
Esempio n. 8
0
void wr_draw_divider(void) {
	wi_enumerator_t			*enumerator;
	wi_mutable_string_t		*string, *action;
	wi_string_t				*position;
	wr_window_t				*window;
	wi_size_t				size;
	wi_range_t				scroll;
	wi_point_t				location;
	const char				*color;
	wi_uinteger_t			users, line, lines, windows;
	
	string = wi_mutable_string_with_format(WI_STR("%s%@"), WR_PREFIX, wr_nick);
	
	if(wr_connected && wr_server) {
		users = wi_array_count(wr_chat_users(wr_console_window->chat));
		
		wi_mutable_string_append_format(string, WI_STR(" - %@ - %u %@"),
										wr_server_name(wr_server),
										users,
										users == 1
											? WI_STR("user")
											: WI_STR("users"));
	}
	
	action = wi_mutable_string();
	windows = 0;
	
	enumerator = wi_array_data_enumerator(wr_windows);
	
	while((window = wi_enumerator_next_data(enumerator))) {
		switch(window->status) {
			case WR_WINDOW_STATUS_ACTION:
				color = WR_INTERFACE_COLOR;
				break;

			case WR_WINDOW_STATUS_CHAT:
				color = WR_STATUS_COLOR;
				break;

			case WR_WINDOW_STATUS_HIGHLIGHT:
				color = WR_HIGHLIGHT_COLOR;
				break;
				
			default:
				color = NULL;
				break;
		}
		
		if(color) {
			if(windows > 0)
				wi_mutable_string_append_string(action, WI_STR(","));
			
			wi_mutable_string_append_format(action, WI_STR("%s%s%s%u%s%s"),
				WR_TERMINATE_COLOR,
				WR_INTERFACE_COLOR,
				color,
				window->wid,
				WR_TERMINATE_COLOR,
				WR_INTERFACE_COLOR);
			
			windows++;
		}
	}

	if(windows > 0)
		wi_mutable_string_append_format(string, WI_STR(" [%@]"), action);
	
	line = wi_terminal_buffer_current_line(wr_current_window->buffer);
	lines = wi_terminal_buffer_lines(wr_current_window->buffer);
	scroll = wi_terminal_scroll(wr_terminal);
	
	if(lines == 0 || line == lines)
		position = NULL;
	else if(line <= scroll.length)
		position = wi_string_with_cstring("TOP");
	else
		position = wi_string_with_format(WI_STR("%.0f%%"), 100 * ((double) (line - scroll.length)  / (double) lines));
	
	wi_terminal_adjust_string_to_fit_width(wr_terminal, string);
	
	if(position) {
		wi_mutable_string_delete_characters_from_index(string, wi_string_length(string) - wi_string_length(position));
		wi_mutable_string_append_string(string, position);
	}

	size = wi_terminal_size(wr_terminal);

	location = wi_terminal_location(wr_terminal);
	wi_terminal_move_printf(wr_terminal, wi_make_point(0, size.height - 3), WI_STR("%s%@%s"),
		WR_INTERFACE_COLOR,
		string,
		WR_TERMINATE_COLOR);
	wi_terminal_move(wr_terminal, location);
}