Пример #1
0
void
notify_load (void)
{
	int fh;
	char buf[256];
	char *sep;

	fh = xchat_open_file ("notify.conf", O_RDONLY, 0, 0);
	if (fh != -1)
	{
		while (waitline (fh, buf, sizeof buf, FALSE) != -1)
		{
			if (buf[0] != '#' && buf[0] != 0)
			{
				sep = strchr (buf, ' ');
				if (sep)
				{
					sep[0] = 0;
					notify_adduser (buf, sep + 1);					
				}
				else
					notify_adduser (buf, NULL);
			}
		}
		close (fh);
	}
}
Пример #2
0
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);
}
Пример #3
0
static void
chanopt_load_all (void)
{
	int fh;
	char buf[256];
	char *eq;
	char *network = NULL;
	chanopt_in_memory *current = NULL;

	/* 1. load the old file into our GSList */
	fh = hexchat_open_file ("chanopt.conf", O_RDONLY, 0, 0);
	if (fh != -1)
	{
		while (waitline (fh, buf, sizeof buf, FALSE) != -1)
		{
			eq = strchr (buf, '=');
			if (!eq)
				continue;
			eq[0] = 0;

			if (eq != buf && eq[-1] == ' ')
				eq[-1] = 0;

			if (!strcmp (buf, "network"))
			{
				g_free (network);
				network = g_strdup (eq + 2);
			}
			else if (!strcmp (buf, "channel"))
			{
				current = chanopt_find (network, eq + 2, TRUE);
				chanopt_changed = FALSE;
			}
			else
			{
				if (current)
					chanopt_add_opt (current, buf, atoi (eq + 2));
			}

		}
		close (fh);
		g_free (network);
	}
}
Пример #4
0
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);
}