mirror of
https://github.com/moparisthebest/hexchat
synced 2025-02-20 04:31:52 -05:00
Create convenience function to get datastreams
This commit is contained in:
parent
a38f7ba910
commit
29000e857f
@ -1473,3 +1473,25 @@ stream_writef (GOutputStream *ostream, const char *fmt, ...)
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GDataInputStream *
|
||||||
|
file_get_datainputstream (GFile *file)
|
||||||
|
{
|
||||||
|
GInputStream *stream;
|
||||||
|
GDataInputStream *datastream;
|
||||||
|
|
||||||
|
stream = G_INPUT_STREAM(g_file_read (file, NULL, NULL));
|
||||||
|
if (!stream)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
datastream = 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
|
||||||
|
*/
|
||||||
|
g_data_input_stream_set_newline_type (datastream, G_DATA_STREAM_NEWLINE_TYPE_ANY);
|
||||||
|
g_object_unref (stream);
|
||||||
|
|
||||||
|
return datastream;
|
||||||
|
}
|
||||||
|
@ -53,6 +53,7 @@ int hexchat_open_file (char *file, int flags, int mode, int xof_flags);
|
|||||||
FILE *hexchat_fopen_file (const char *file, const char *mode, int xof_flags);
|
FILE *hexchat_fopen_file (const char *file, const char *mode, int xof_flags);
|
||||||
GFile *hexchat_open_gfile (const char *filename);
|
GFile *hexchat_open_gfile (const char *filename);
|
||||||
gsize stream_writef (GOutputStream *ostream, const char *fmt, ...) G_GNUC_PRINTF (2, 3);
|
gsize stream_writef (GOutputStream *ostream, const char *fmt, ...) G_GNUC_PRINTF (2, 3);
|
||||||
|
GDataInputStream *file_get_datainputstream (GFile *file);
|
||||||
|
|
||||||
char *unescape_newlines (const gchar *value);
|
char *unescape_newlines (const gchar *value);
|
||||||
char *escape_newlines (const gchar *value);
|
char *escape_newlines (const gchar *value);
|
||||||
|
@ -1918,7 +1918,6 @@ int
|
|||||||
hexchat_pluginpref_list (hexchat_plugin *pl, char* dest)
|
hexchat_pluginpref_list (hexchat_plugin *pl, char* dest)
|
||||||
{
|
{
|
||||||
GFile *file;
|
GFile *file;
|
||||||
GInputStream *stream;
|
|
||||||
GDataInputStream *istream;
|
GDataInputStream *istream;
|
||||||
char *confname, *canon, *buf;
|
char *confname, *canon, *buf;
|
||||||
|
|
||||||
@ -1930,14 +1929,10 @@ hexchat_pluginpref_list (hexchat_plugin *pl, char* dest)
|
|||||||
file = hexchat_open_gfile (confname);
|
file = hexchat_open_gfile (confname);
|
||||||
g_free (confname);
|
g_free (confname);
|
||||||
|
|
||||||
stream = G_INPUT_STREAM(g_file_read (file, NULL, NULL));
|
istream = file_get_datainputstream (file);
|
||||||
if (!stream)
|
if (!istream)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
istream = g_data_input_stream_new (stream);
|
|
||||||
g_data_input_stream_set_newline_type (istream, G_DATA_STREAM_NEWLINE_TYPE_ANY);
|
|
||||||
g_object_unref (stream);
|
|
||||||
|
|
||||||
strcpy (dest, ""); /* clean up garbage */
|
strcpy (dest, ""); /* clean up garbage */
|
||||||
while ((buf = g_data_input_stream_read_line_utf8 (istream, NULL, NULL, NULL)))
|
while ((buf = g_data_input_stream_read_line_utf8 (istream, NULL, NULL, NULL)))
|
||||||
{
|
{
|
||||||
|
@ -1180,7 +1180,6 @@ static int
|
|||||||
servlist_load (void)
|
servlist_load (void)
|
||||||
{
|
{
|
||||||
GFile *file;
|
GFile *file;
|
||||||
GInputStream *stream;
|
|
||||||
GDataInputStream *istream;
|
GDataInputStream *istream;
|
||||||
gchar *buf;
|
gchar *buf;
|
||||||
ircnet *net = NULL;
|
ircnet *net = NULL;
|
||||||
@ -1200,13 +1199,10 @@ servlist_load (void)
|
|||||||
|
|
||||||
file = hexchat_open_gfile ("servlist.conf");
|
file = hexchat_open_gfile ("servlist.conf");
|
||||||
|
|
||||||
stream = G_INPUT_STREAM(g_file_read (file, NULL, NULL));
|
istream = file_get_datainputstream (file);
|
||||||
if (!stream)
|
if (!istream)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
istream = g_data_input_stream_new (stream);
|
|
||||||
g_data_input_stream_set_newline_type (istream, G_DATA_STREAM_NEWLINE_TYPE_ANY);
|
|
||||||
g_object_unref (stream);
|
|
||||||
|
|
||||||
while ((buf = g_data_input_stream_read_line_utf8 (istream, NULL, NULL, NULL)))
|
while ((buf = g_data_input_stream_read_line_utf8 (istream, NULL, NULL, NULL)))
|
||||||
{
|
{
|
||||||
|
@ -220,7 +220,6 @@ scrollback_save (session *sess, char *text)
|
|||||||
void
|
void
|
||||||
scrollback_load (session *sess)
|
scrollback_load (session *sess)
|
||||||
{
|
{
|
||||||
GInputStream *stream;
|
|
||||||
GDataInputStream *istream;
|
GDataInputStream *istream;
|
||||||
gchar *buf, *text;
|
gchar *buf, *text;
|
||||||
gint lines = 0;
|
gint lines = 0;
|
||||||
@ -246,19 +245,10 @@ scrollback_load (session *sess)
|
|||||||
g_free (buf);
|
g_free (buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
stream = G_INPUT_STREAM(g_file_read (sess->scrollfile, NULL, NULL));
|
istream = file_get_datainputstream (sess->scrollfile);
|
||||||
if (!stream)
|
if (!istream)
|
||||||
return;
|
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)
|
while (1)
|
||||||
{
|
{
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user