int
main(int argc, char **argv)
{
	FILE *f = fopen(argv[1], "r");

	char buf[BUFFER_SIZE];
	size_t size = fread(buf, sizeof(char), BUFFER_SIZE, f);

	if (size <= 0)
	{
		printf("Error: no input!\n");
		exit(-1);
	}

	if (size != BUFFER_SIZE && !feof(f))
	{
		printf("ERROR: %s\n", strerror(ferror(f)));
		fclose(f);
		exit(-1);
	}

	fclose(f);

	Message message;
	Message_parse(&message, buf, size);
	Envelope_fwrite(&(message.envelope), stdout);
	printf("-----\n");
	if (message.body)
		printf("%s\n", message.body);
	printf("-----\n");
	Message_free(&message);
}
Exemplo n.º 2
0
Arquivo: Window.c Projeto: benvh/Circ
void Window_add_message(Window* window, const gchar* text)
{
	printf("%s\n", Style_get_name(style));
	Message* msg = Message_new("Ben", text, MessageBuffer_get_next_id(window->_buffer));
	Message_parse(msg, style);
	MessageBuffer_add_message(window->_buffer, msg);
	
	gchar *script_add = g_strdup_printf("append_message(\"%s\")", Message_get_parsed_text(msg));
	webkit_web_view_execute_script(WEBKIT_WEB_VIEW(window->_webview), script_add);
	g_free(script_add);
	
	int id;
	if((id = MessageBuffer_message_deleted(window->_buffer)) != MESSAGEBUFFER_NO)
	{
		gchar *script_del = g_strdup_printf("delete_message(\"msg%d\")", id);
		webkit_web_view_execute_script(WEBKIT_WEB_VIEW(window->_webview), script_del);
		g_free(script_del);
	}
}