Public feed #726089

Untitled

public text v1 · immutable
Raw Edit
·published 2007-10-04 21:36 UTC
rendered paste body
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include "cmds.h"
#include "conf.h"
#include "globales.h"
#include "log.h"
#include "timestamp.h"
#include <gtk/gtk.h>
#include "window.h"
#include "main.h"

// function to read buffer line

int
readirccmd (char *rbuffer, int len, int sockfd)
{
  int i;
  for (i = 0; i < len && rbuffer[i - 1] != '\n'; i++)
    {
     recv (sockfd, rbuffer + i, 1, 0);
    }
  return i;
}

// function to read entire data

int read_socket(GtkWidget *widget, gpointer data) {
	
	static char r_buffer[1024];
	gchar *sschem;
	gchar *lbuf = r_buffer;
	gchar *utf8 = NULL;
			
 	memset (rbuffer, 0, sizeof (rbuffer)); 
	readirccmd (rbuffer, sizeof (rbuffer), sockfd);
	memset (r_buffer, 0, sizeof (r_buffer)); 
	snprintf (r_buffer, sizeof r_buffer, "%s %s", gettimestamp(), rbuffer);
	
	// to scroll bottom of window
	GtkTextMark *p_text_mark = NULL;
	g_return_if_fail (textview1 != NULL);
	g_return_if_fail (&End != NULL);
	g_return_if_fail (sschem != NULL);
	// 
	
	TextBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview1));
	gtk_text_buffer_get_start_iter(TextBuffer, &Start);
	gtk_text_buffer_get_end_iter(TextBuffer, &End);
	sschem = g_strdup(lbuf);
	utf8 = g_locale_to_utf8 (sschem, -1, NULL, NULL, NULL);
		
	gtk_text_buffer_insert(TextBuffer, &End, utf8, -1); 
		
	g_free (utf8), utf8 = NULL;
		
	// scroll again...
	p_text_mark = gtk_text_buffer_create_mark (TextBuffer, NULL, &End, FALSE);
	gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW(textview1), p_text_mark, 0, FALSE, 0, 0);
	//
	
	//write_log_file();
	authme();
	ping_response();
	//join_channel();
	g_free(sschem);
	return 1; // avoid end of loop
}