コード例 #1
0
ファイル: text.cpp プロジェクト: wowzaman12/libPChat
void scrollback_load(session *sess)
{
	int fh;
	char buf[512 * 4];
	char *text;
	time_t stamp;
	int lines;

	if (sess->text_scrollback == SET_DEFAULT)
	{
		if (!prefs.text_replay)
			return;
	}
	else
	{
		if (sess->text_scrollback != SET_ON)
			return;
	}

	if (scrollback_get_filename(sess, buf, sizeof(buf)) == nullptr)
		return;

	fh = open(buf, O_RDONLY | OFLAGS);
	if (fh == -1)
		return;

	
	lines = 0;
	while (waitline(fh, buf, sizeof buf, FALSE) != -1)
	{
		if (buf[0] == 'T')
		{
			if (sizeof(time_t) == 4)
				stamp = strtoul(buf + 2, nullptr, 10);
			else
				stamp = strtoull(buf + 2, nullptr, 10); // just incase time_t is 64 bits
			text = strchr(buf + 3, ' ');
			if (text)
			{
				text = strip_color(text + 1, -1, STRIP_COLOR);
				fe_print_text(sess, text, stamp);
				g_free(text);
			}
			lines++;
		}
	}

	sess->scrollwritten = lines;

	if (lines)
	{
		text = ctime(&stamp);
		text[24] = 0;	// get rid of the \n
		snprintf(buf, sizeof(buf), "\n*\t%s %s\n\n", _("Loaded log from"), text);
		fe_print_text(sess, buf, 0);
		//EMIT_SIGNAL(XP_TE_GENMSG, sess, "*", buf, nullptr, nullptr, nullptr, 0);
	}

	close(fh);
}
コード例 #2
0
ファイル: text.c プロジェクト: Cynede/hexchat
void
PrintTextTimeStamp (session *sess, char *text, time_t timestamp)
{
	if (!sess)
	{
		if (!sess_list)
			return;
		sess = (session *) sess_list->data;
	}

	/* make sure it's valid utf8 */
	if (text[0] == '\0')
	{
		text = g_strdup ("\n");
	}
	else
	{
		text = text_fixup_invalid_utf8 (text, -1, NULL);
	}

	log_write (sess, text, timestamp);
	scrollback_save (sess, text, timestamp);
	fe_print_text (sess, text, timestamp, FALSE);
	g_free (text);
}
コード例 #3
0
ファイル: fe-text.c プロジェクト: PlaidFlannel43/hexchat
void
fe_new_window (struct session *sess, int focus)
{
	char buf[512];

	sess->gui = malloc (4);
	current_sess = sess;

	if (!sess->server->front_session)
		sess->server->front_session = sess;
	if (!sess->server->server_session)
		sess->server->server_session = sess;
	if (!current_tab || focus)
		current_tab = sess;

	if (done_intro)
		return;
	done_intro = 1;

	snprintf (buf, sizeof (buf),
				"\n"
				" \017XChat-Text \00310"PACKAGE_VERSION"\n"
				" \017Running on \00310%s \017glib \00310%d.%d.%d\n"
				" \017This binary compiled \00310"__DATE__"\017\n",
				get_cpu_str(),
				glib_major_version, glib_minor_version, glib_micro_version);
	fe_print_text (sess, buf, 0);

	fe_print_text (sess, "\n\nCompiled in Features\0032:\017 "
#ifdef USE_PLUGIN
	"Plugin "
#endif
#ifdef ENABLE_NLS
	"NLS "
#endif
#ifdef USE_OPENSSL
	"OpenSSL "
#endif
#ifdef USE_IPV6
	"IPv6"
#endif
	"\n\n", 0);
	fflush (stdout);
	fflush (stdin);
}
コード例 #4
0
ファイル: fe-text.c プロジェクト: DCBoland/hexchat
void
fe_new_window (struct session *sess, int focus)
{
	char buf[512];

	current_sess = sess;

	if (!sess->server->front_session)
		sess->server->front_session = sess;
	if (!sess->server->server_session)
		sess->server->server_session = sess;
	if (!current_tab || focus)
		current_tab = sess;

	if (done_intro)
		return;
	done_intro = 1;

	g_snprintf (buf, sizeof (buf),
				"\n"
				" \017HexChat-Text \00310"PACKAGE_VERSION"\n"
				" \017Running on \00310%s\n",
				get_sys_str (1));
	fe_print_text (sess, buf, 0, FALSE);

	fe_print_text (sess, "\n\nCompiled in Features\0032:\017 "
#ifdef USE_PLUGIN
	"Plugin "
#endif
#ifdef ENABLE_NLS
	"NLS "
#endif
#ifdef USE_OPENSSL
	"OpenSSL "
#endif
	"\n\n", 0, FALSE);
	fflush (stdout);
}
コード例 #5
0
ファイル: text.c プロジェクト: TheWug/hexchat
void
scrollback_load (session *sess)
{
	char *buf;
	char *text;
	time_t stamp;
	int lines;
	GIOChannel *io;
	GError *file_error = NULL;
	GError *io_err = NULL;

	if (sess->text_scrollback == SET_DEFAULT)
	{
		if (!prefs.hex_text_replay)
			return;
	}
	else
	{
		if (sess->text_scrollback != SET_ON)
			return;
	}

	if ((buf = scrollback_get_filename (sess)) == NULL)
		return;

	io = g_io_channel_new_file (buf, "r", &file_error);
	g_free (buf);
	if (!io)
		return;

	lines = 0;

	while (1)
	{
		gsize n_bytes;
		GIOStatus io_status;

		io_status = g_io_channel_read_line (io, &buf, &n_bytes, NULL, &io_err);
		
		if (io_status == G_IO_STATUS_NORMAL)
		{
			char *buf_tmp;

			/* If nothing but funny trailing matter e.g. 0x0d or 0x0d0a, toss it */
			if (n_bytes >= 1 && buf[0] == 0x0d)
			{
				g_free (buf);
				continue;
			}

			n_bytes--;
			buf_tmp = buf;
			buf = g_strndup (buf_tmp, n_bytes);
			g_free (buf_tmp);

			/*
			 * Some scrollback lines have three blanks after the timestamp and a newline
			 * Some have only one blank and a newline
			 * Some don't even have a timestamp
			 * Some don't have any text at all
			 */
			if (buf[0] == 'T')
			{
				if (sizeof (time_t) == 4)
					stamp = strtoul (buf + 2, NULL, 10);
				else
					stamp = strtoull (buf + 2, NULL, 10); /* in case time_t is 64 bits */
				text = strchr (buf + 3, ' ');
				if (text && text[1])
				{
					if (prefs.hex_text_stripcolor_replay)
					{
						text = strip_color (text + 1, -1, STRIP_COLOR);
					}

					fe_print_text (sess, text, stamp, TRUE);

					if (prefs.hex_text_stripcolor_replay)
					{
						g_free (text);
					}
				}
				else
				{
					fe_print_text (sess, "  ", stamp, TRUE);
				}
			}
			else
			{
				if (strlen (buf))
					fe_print_text (sess, buf, 0, TRUE);
				else
					fe_print_text (sess, "  ", 0, TRUE);
			}
			lines++;

			g_free (buf);
		}

		else
			break;
	}

	g_io_channel_unref (io);

	sess->scrollwritten = lines;

	if (lines)
	{
		text = ctime (&stamp);
		text[24] = 0;	/* get rid of the \n */
		buf = g_strdup_printf ("\n*\t%s %s\n\n", _("Loaded log from"), text);
		fe_print_text (sess, buf, 0, TRUE);
		g_free (buf);
		/*EMIT_SIGNAL (XP_TE_GENMSG, sess, "*", buf);*/
	}
}
コード例 #6
0
ファイル: text.c プロジェクト: DoctorWho11/pchat
void
scrollback_load (session *sess)
{
	char *buf;
	char *text;
	time_t stamp;
	int lines;
	GIOChannel *io;
	GError *file_error = NULL;
	GError *io_err = NULL;

	if (sess->text_scrollback == SET_DEFAULT)
	{
		if (!prefs.pchat_text_replay)
			return;
	}
	else
	{
		if (sess->text_scrollback != SET_ON)
			return;
	}

	if ((buf = scrollback_get_filename (sess)) == NULL)
		return;

	io = g_io_channel_new_file (buf, "r", &file_error);
	g_free (buf);
	if (!io)
		return;

	lines = 0;

	while (1)
	{
		gsize n_bytes;
		GIOStatus io_status;

		io_status = g_io_channel_read_line (io, &buf, &n_bytes, NULL, &io_err);

		if (io_status == G_IO_STATUS_NORMAL)
		{
			char *buf_tmp;

			n_bytes--;
			buf_tmp = buf;
			buf = g_strndup (buf_tmp, n_bytes);
			g_free (buf_tmp);

			if (buf[0] == 'T')
			{
				if (sizeof (time_t) == 4)
					stamp = g_ascii_strtoul (buf + 2, NULL, 10);
				else
					stamp = g_ascii_strtoull (buf + 2, NULL, 10); /* in case time_t is 64 bits */
				text = strchr (buf + 3, ' ');
				if (text)
				{
					if (prefs.pchat_text_stripcolor_replay)
					{
						text = strip_color (text + 1, -1, STRIP_COLOR);
					}

					fe_print_text (sess, text, stamp, TRUE);

					if (prefs.pchat_text_stripcolor_replay)
					{
						g_free (text);
					}
				}
				lines++;
			}

			g_free (buf);
		}

		else
			break;
	}

	g_io_channel_unref (io);

	sess->scrollwritten = lines;

	if (lines)
	{
		text = ctime (&stamp);
		text[24] = 0;	/* get rid of the \n */
		buf = g_strdup_printf ("\n*\t%s %s\n\n", _("Loaded log from"), text);
		fe_print_text (sess, buf, 0, TRUE);
		g_free (buf);
		/*EMIT_SIGNAL (XP_TE_GENMSG, sess, "*", buf, NULL, NULL, NULL, 0);*/
	}
}
コード例 #7
0
ファイル: text.c プロジェクト: Cynede/hexchat
void
scrollback_load (session *sess)
{
	GInputStream *stream;
	GDataInputStream *istream;
	gchar *buf, *text;
	gint lines = 0;
	time_t stamp = 0;

	if (sess->text_scrollback == SET_DEFAULT)
	{
		if (!prefs.hex_text_replay)
			return;
	}
	else
	{
		if (sess->text_scrollback != SET_ON)
			return;
	}

	if (!sess->scrollfile)
	{
		if ((buf = scrollback_get_filename (sess)) == NULL)
			return;

		sess->scrollfile = g_file_new_for_path (buf);
		g_free (buf);
	}

	stream = G_INPUT_STREAM(g_file_read (sess->scrollfile, NULL, NULL));
	if (!stream)
		return;

	istream = g_data_input_stream_new (stream);
	/*
	 * This is to avoid any issues moving between windows/unix
	 * but the docs mention an invalid \r without a following \n
	 * can lock up the program... (Our write() always adds \n)
	 */
	g_data_input_stream_set_newline_type (istream, G_DATA_STREAM_NEWLINE_TYPE_ANY);
	g_object_unref (stream);

	while (1)
	{
		GError *err = NULL;
		gsize n_bytes;

		buf = g_data_input_stream_read_line_utf8 (istream, &n_bytes, NULL, &err);

		if (!err && buf)
		{
			/*
			 * Some scrollback lines have three blanks after the timestamp and a newline
			 * Some have only one blank and a newline
			 * Some don't even have a timestamp
			 * Some don't have any text at all
			 */
			if (buf[0] == 'T' && buf[1] == ' ')
			{
				if (sizeof (time_t) == 4)
					stamp = strtoul (buf + 2, NULL, 10);
				else
					stamp = g_ascii_strtoull (buf + 2, NULL, 10); /* in case time_t is 64 bits */

				if (G_UNLIKELY(stamp == 0))
				{
					g_warning ("Invalid timestamp in scrollback file");
					continue;
				}

				text = strchr (buf + 3, ' ');
				if (text && text[1])
				{
					if (prefs.hex_text_stripcolor_replay)
					{
						text = strip_color (text + 1, -1, STRIP_COLOR);
					}

					fe_print_text (sess, text, stamp, TRUE);

					if (prefs.hex_text_stripcolor_replay)
					{
						g_free (text);
					}
				}
				else
				{
					fe_print_text (sess, "  ", stamp, TRUE);
				}
			}
			else
			{
				if (strlen (buf))
					fe_print_text (sess, buf, 0, TRUE);
				else
					fe_print_text (sess, "  ", 0, TRUE);
			}
			lines++;

			g_free (buf);
		}
		else if (err)
		{
			/* If its only an encoding error it may be specific to the line */
			if (g_error_matches (err, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE))
			{
				g_warning ("Invalid utf8 in scrollback file");
				g_clear_error (&err);
				continue;
			}

			/* For general errors just give up */
			g_clear_error (&err);
			break;
		}
		else /* No new line */
		{
			break;
		}
	}

	g_object_unref (istream);

	sess->scrollwritten = lines;

	if (lines)
	{
		text = ctime (&stamp);
		buf = g_strdup_printf ("\n*\t%s %s\n", _("Loaded log from"), text);
		fe_print_text (sess, buf, 0, TRUE);
		g_free (buf);
		/*EMIT_SIGNAL (XP_TE_GENMSG, sess, "*", buf, NULL, NULL, NULL, 0);*/
	}
}
コード例 #8
0
ファイル: text.c プロジェクト: sb057/hexchat
void
scrollback_load (session *sess)
{
	int fh;
	char buf[512 * 4];
	char *text;
	time_t stamp;
	int lines;

#ifdef WIN32
#if 0
	char *cleaned_text;
	int cleaned_len;
#endif
#else
	char *map, *end_map;
	struct stat statbuf;
	const char *begin, *eol;
#endif

	if (sess->text_scrollback == SET_DEFAULT)
	{
		if (!prefs.text_replay)
			return;
	}
	else
	{
		if (sess->text_scrollback != SET_ON)
			return;
	}

	if (scrollback_get_filename (sess, buf, sizeof (buf)) == NULL)
		return;

	fh = open (buf, O_RDONLY | OFLAGS);
	if (fh == -1)
		return;

#ifndef WIN32
	if (fstat (fh, &statbuf) < 0)
		return;

	map = mmap (NULL, statbuf.st_size, PROT_READ, MAP_PRIVATE, fh, 0);
	if (map == MAP_FAILED)
		return;

	end_map = map + statbuf.st_size;

	lines = 0;
	begin = map;
	while (begin < end_map)
	{
		int n_bytes;

		eol = memchr (begin, '\n', end_map - begin);

		if (!eol)
			eol = end_map;

		n_bytes = MIN (eol - begin, sizeof (buf) - 1);

		strncpy (buf, begin, n_bytes);

		buf[n_bytes] = 0;

		if (buf[0] == 'T')
		{
			if (sizeof (time_t) == 4)
				stamp = strtoul (buf + 2, NULL, 10);
			else
				stamp = strtoull (buf + 2, NULL, 10); /* just incase time_t is 64 bits */
			text = strchr (buf + 3, ' ');
			if (text)
			{
				if (prefs.text_stripcolor_replay)
				{
					text = strip_color (text + 1, -1, STRIP_COLOR);
				}
				fe_print_text (sess, text, stamp);
				if (prefs.text_stripcolor_replay)
				{
					g_free (text);
				}
			}
			lines++;
		}

		begin = eol + 1;
	}

	sess->scrollwritten = lines;

	if (lines)
	{
		text = ctime (&stamp);
		text[24] = 0;	/* get rid of the \n */
		snprintf (buf, sizeof (buf), "\n*\t%s %s\n\n", _("Loaded log from"), text);
		fe_print_text (sess, buf, 0);
		/*EMIT_SIGNAL (XP_TE_GENMSG, sess, "*", buf, NULL, NULL, NULL, 0);*/
	}

	munmap (map, statbuf.st_size);
#else
	lines = 0;
	while (waitline (fh, buf, sizeof buf, FALSE) != -1)
	{
		if (buf[0] == 'T')
		{
			if (sizeof (time_t) == 4)
				stamp = strtoul (buf + 2, NULL, 10);
			else
				stamp = strtoull (buf + 2, NULL, 10); /* just incase time_t is 64 bits */
			text = strchr (buf + 3, ' ');
			if (text)
			{
				if (prefs.text_stripcolor_replay)
				{
					text = strip_color (text + 1, -1, STRIP_COLOR);
				}
#if 0
				cleaned_text = text_replace_non_bmp (text, -1, &cleaned_len);
				if (cleaned_text != NULL)
				{
					if (prefs.text_stripcolor_replay)
					{
						g_free (text);
					}
					text = cleaned_text;
				}
#endif
				text_replace_non_bmp2 (text);
				fe_print_text (sess, text, stamp);
				if (prefs.text_stripcolor_replay)
				{
					g_free (text);
				}
			}
			lines++;
		}
	}

	sess->scrollwritten = lines;

	if (lines)
	{
		text = ctime (&stamp);
		text[24] = 0;	/* get rid of the \n */
		snprintf (buf, sizeof (buf), "\n*\t%s %s\n\n", _("Loaded log from"), text);
		fe_print_text (sess, buf, 0);
		/*EMIT_SIGNAL (XP_TE_GENMSG, sess, "*", buf, NULL, NULL, NULL, 0);*/
	}
#endif

	close (fh);
}
コード例 #9
0
ファイル: fe-text.c プロジェクト: UIKit0/picogui
void
fe_new_window (struct session *sess)
{
    char buf[512];

    sess->gui = malloc (4);

    if (!sess->server->front_session)
        sess->server->front_session = sess;
    if (!current_tab)
        current_tab = sess;

    if (done_intro)
        return;
    done_intro = 1;

    snprintf (buf, sizeof (buf),
              "\n"
              " \017xchat \00310"VERSION"\n"
              " \017Running on \00310%s \017glib \00310%d.%d.%d\n"
              " \017This binary compiled \00310"__DATE__"\017\n",
              get_cpu_str(),
              glib_major_version, glib_minor_version, glib_micro_version);
    fe_print_text (sess, buf);

    strcpy (buf, "\n\nCompiled in Features\0032:\017 ");
#ifdef USE_PERL
    strcat (buf, "Perl ");
#endif
#ifdef USE_PYTHON
    strcat (buf, "Python ");
#endif
#ifdef USE_PLUGIN
    strcat (buf, "Plugin ");
#endif
#ifdef ENABLE_NLS
    strcat (buf, "NLS ");
#endif
#ifdef USE_TRANS
    strcat (buf, "Trans ");
#endif
#ifdef USE_HEBREW
    strcat (buf, "Hebrew ");
#endif
#ifdef USE_OPENSSL
    strcat (buf, "OpenSSL ");
#endif
#ifdef SOCKS
    strcat (buf, "Socks5 ");
#endif
#ifdef HAVE_ICONV
    strcat (buf, "JCode ");
#endif
#ifdef USE_IPV6
    strcat (buf, "IPv6 ");
#endif
    strcat (buf, "\n\n");
    fe_print_text (sess, buf);
    fflush (stdout);
    fflush (stdin);
}