Commit 59c4e33b authored by Paolo Maggi's avatar Paolo Maggi Committed by Paolo Maggi

new file

2002-09-27  Paolo Maggi <maggi@athena.polito.it>

	* message-of-doom: new file

	* configure.in: print the message-of-doom

2002-09-22  James Willcox  <jwillcox@gnome.org>

	* gedit-debug.c: (gedit_debug):
	* gedit-debug.h: Added DEBUG_UTILS

	* gedit-document.c: (gedit_document_load),
	(gedit_document_load_from_stdin): Use the functions in gedit-utils.c

	* gedit-utils.c: (gedit_utils_get_stdin),
	(gedit_utils_convert_to_utf8), (gedit_utils_convert_to_utf8_blah):
	* gedit-utils.h:  New functions

	* gedit2.c: (gedit_handle_automation_cmdline):  Insert data from
	stdin into an existing instance.
parent c115fe97
2002-09-27 Paolo Maggi <maggi@athena.polito.it>
* message-of-doom: new file
* configure.in: print the message-of-doom
2002-09-20 Marius Andreiana <mandreiana@yahoo.com>
* help/ro/gedit.xml: small update
......
......@@ -224,3 +224,4 @@ Configuration:
"
cat $srcdir/message-of-doom
2002-09-22 James Willcox <jwillcox@gnome.org>
* gedit-debug.c: (gedit_debug):
* gedit-debug.h: Added DEBUG_UTILS
* gedit-document.c: (gedit_document_load),
(gedit_document_load_from_stdin): Use the functions in gedit-utils.c
* gedit-utils.c: (gedit_utils_get_stdin),
(gedit_utils_convert_to_utf8), (gedit_utils_convert_to_utf8_blah):
* gedit-utils.h: New functions
* gedit2.c: (gedit_handle_automation_cmdline): Insert data from
stdin into an existing instance.
2002-09-20 Paolo Maggi <maggi@athena.polito.it>
* gedit-plugins-engine.c (gedit_plugins_engine_load_dir):
......
......@@ -46,6 +46,7 @@ gint debug_commands = 0;
gint debug_recent = 0;
gint debug_mdi = 0;
gint debug_session = 0;
gint debug_utils = 0;
void
gedit_debug (gint section, gchar *file, gint line, gchar* function, gchar* format, ...)
......@@ -62,7 +63,8 @@ gedit_debug (gint section, gchar *file, gint line, gchar* function, gchar* forma
(debug_commands && section == GEDIT_DEBUG_COMMANDS) ||
(debug_recent && section == GEDIT_DEBUG_RECENT) ||
(debug_session && section == GEDIT_DEBUG_SESSION) ||
(debug_mdi && section == GEDIT_DEBUG_MDI) )
(debug_mdi && section == GEDIT_DEBUG_MDI) ||
(debug_utils && section == GEDIT_DEBUG_UTILS))
{
va_list args;
gchar *msg;
......
......@@ -43,7 +43,8 @@ typedef enum {
GEDIT_DEBUG_RECENT,
GEDIT_DEBUG_COMMANDS,
GEDIT_DEBUG_MDI,
GEDIT_DEBUG_SESSION
GEDIT_DEBUG_SESSION,
GEDIT_DEBUG_UTILS
} GeditDebugSection;
extern gint debug;
......@@ -59,6 +60,7 @@ extern gint debug_commands;
extern gint debug_recent;
extern gint debug_mdi;
extern gint debug_session;
extern gint debug_utils;
/* __FUNCTION_ is not defined in Irix according to David Kaelbling <drk@sgi.com>*/
#ifndef __GNUC__
......@@ -77,6 +79,7 @@ extern gint debug_session;
#define DEBUG_COMMANDS GEDIT_DEBUG_COMMANDS,__FILE__, __LINE__, __FUNCTION__
#define DEBUG_MDI GEDIT_DEBUG_MDI, __FILE__, __LINE__, __FUNCTION__
#define DEBUG_SESSION GEDIT_DEBUG_SESSION, __FILE__, __LINE__, __FUNCTION__
#define DEBUG_UTILS GEDIT_DEBUG_UTILS, __FILE__, __LINE__, __FUNCTION__
void gedit_debug (gint section, gchar *file,
gint line, gchar* function, gchar* format, ...);
......
......@@ -62,8 +62,6 @@
#define GEDIT_MAX_PATH_LEN 2048
#endif
#define DEFAULT_ENCODING "ISO-8859-15"
struct _GeditDocumentPrivate
{
gchar *uri;
......@@ -716,84 +714,21 @@ gedit_document_load (GeditDocument* doc, const gchar *uri, GError **error)
if (file_size > 0)
{
if (!g_utf8_validate (file_contents, file_size, NULL))
{
/* The file contains invalid UTF8 data */
/* Try to convert it to UTF-8 from currence locale */
GError *conv_error = NULL;
gchar* converted_file_contents = NULL;
gsize bytes_written;
converted_file_contents = g_locale_to_utf8 (file_contents, file_size,
NULL, &bytes_written, &conv_error);
if ((conv_error != NULL) ||
!g_utf8_validate (converted_file_contents, bytes_written, NULL))
{
/* Coversion failed */
if (conv_error != NULL) {
g_error_free (conv_error);
conv_error = NULL;
}
gchar *converted_text;
if (converted_file_contents != NULL)
g_free (converted_file_contents);
/* Try to convert it to UTF-8 from default encoding */
converted_file_contents = g_convert (file_contents, file_size,
"UTF-8", DEFAULT_ENCODING,
NULL, &bytes_written, &conv_error);
if ((conv_error != NULL) ||
!g_utf8_validate (converted_file_contents, bytes_written, NULL))
{
/* Coversion failed */
if (conv_error != NULL)
g_error_free (conv_error);
converted_text = gedit_utils_convert_to_utf8 (file_contents,
&doc->priv->encoding);
g_set_error (error, GEDIT_DOCUMENT_IO_ERROR,
GEDIT_ERROR_INVALID_UTF8_DATA,
_("Invalid UTF-8 data"));
if (converted_file_contents != NULL)
g_free (converted_file_contents);
g_free (file_contents);
if (converted_text == NULL)
{
/* bail out */
g_set_error (error, GEDIT_DOCUMENT_IO_ERROR,
GEDIT_ERROR_INVALID_UTF8_DATA,
_("Invalid UTF-8 data"));
return FALSE;
}
else
{
if (doc->priv->encoding != NULL)
g_free (doc->priv->encoding);
doc->priv->encoding = g_strdup (DEFAULT_ENCODING);
}
}
else
{
const gchar *encoding = NULL;
g_get_charset(&encoding);
if (doc->priv->encoding != NULL)
g_free (doc->priv->encoding);
doc->priv->encoding = g_strdup (encoding);
}
g_free (file_contents);
file_contents = converted_file_contents;
file_size = bytes_written;
}
else
{
if (doc->priv->encoding != NULL)
{
g_free (doc->priv->encoding);
doc->priv->encoding = NULL;
}
return FALSE;
}
gedit_debug (DEBUG_DOCUMENT, "Document encoding: %s",
......@@ -802,7 +737,8 @@ gedit_document_load (GeditDocument* doc, const gchar *uri, GError **error)
gedit_undo_manager_begin_not_undoable_action (doc->priv->undo_manager);
/* Insert text in the buffer */
gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &iter, 0);
gtk_text_buffer_insert (GTK_TEXT_BUFFER (doc), &iter, file_contents, file_size);
gtk_text_buffer_insert (GTK_TEXT_BUFFER (doc), &iter, converted_text, file_size);
g_free (converted_text);
/* We had a newline in the buffer to begin with. (The buffer always contains
* a newline, so we delete to the end of the buffer to clean up. */
......@@ -840,97 +776,41 @@ gedit_document_load (GeditDocument* doc, const gchar *uri, GError **error)
return TRUE;
}
#define GEDIT_STDIN_BUFSIZE 1024
gboolean
gedit_document_load_from_stdin (GeditDocument* doc, GError **error)
{
GString * file_contents;
gchar *tmp_buf = NULL;
struct stat stats;
guint buffer_length;
gchar *stdin_data;
GtkTextIter iter, end;
GnomeVFSResult res;
gedit_debug (DEBUG_DOCUMENT, "");
g_return_val_if_fail (doc != NULL, FALSE);
fstat (STDIN_FILENO, &stats);
if (stats.st_size == 0)
return FALSE;
tmp_buf = g_new0 (gchar, GEDIT_STDIN_BUFSIZE + 1);
g_return_val_if_fail (tmp_buf != NULL, FALSE);
stdin_data = gedit_utils_get_stdin ();
file_contents = g_string_new (NULL);
while (feof (stdin) == 0)
if (stdin_data != NULL && strlen (stdin_data) > 0)
{
buffer_length = fread (tmp_buf, 1, GEDIT_STDIN_BUFSIZE, stdin);
tmp_buf [buffer_length] = '\0';
g_string_append (file_contents, tmp_buf);
if (ferror (stdin) != 0)
{
res = gnome_vfs_result_from_errno ();
g_set_error (error, GEDIT_DOCUMENT_IO_ERROR, res,
gnome_vfs_result_to_string (res));
g_free (tmp_buf);
g_string_free (file_contents, TRUE);
return FALSE;
}
}
gchar *converted_text;
fclose (stdin);
converted_text = gedit_utils_convert_to_utf8 (stdin_data,
&doc->priv->encoding);
if (file_contents->len > 0)
{
if (!g_utf8_validate (file_contents->str, file_contents->len, NULL))
if (converted_text == NULL)
{
/* The file contains invalid UTF8 data */
/* Try to convert it to UTF-8 from currence locale */
GError *conv_error = NULL;
gchar* converted_file_contents = NULL;
gsize bytes_written;
converted_file_contents = g_locale_to_utf8 (file_contents->str, file_contents->len,
NULL, &bytes_written, &conv_error);
if ((conv_error != NULL) ||
!g_utf8_validate (converted_file_contents, bytes_written, NULL))
{
/* Coversion failed */
if (conv_error != NULL)
g_error_free (conv_error);
/* bail out */
g_set_error (error, GEDIT_DOCUMENT_IO_ERROR,
GEDIT_ERROR_INVALID_UTF8_DATA,
_("Invalid UTF-8 data"));
g_set_error (error, GEDIT_DOCUMENT_IO_ERROR,
GEDIT_ERROR_INVALID_UTF8_DATA,
_("Invalid UTF-8 data"));
if (converted_file_contents != NULL)
g_free (converted_file_contents);
g_string_free (file_contents, TRUE);
return FALSE;
}
g_free (stdin_data);
g_string_free (file_contents, TRUE);
/* FIXME: this could be more efficient */
file_contents = g_string_new (converted_file_contents);
return FALSE;
}
gedit_undo_manager_begin_not_undoable_action (doc->priv->undo_manager);
/* Insert text in the buffer */
gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &iter, 0);
gtk_text_buffer_insert (GTK_TEXT_BUFFER (doc), &iter, file_contents->str, file_contents->len);
gtk_text_buffer_insert (GTK_TEXT_BUFFER (doc), &iter, converted_text, -1);
/* We had a newline in the buffer to begin with. (The buffer always contains
* a newline, so we delete to the end of the buffer to clean up. */
......@@ -942,10 +822,9 @@ gedit_document_load_from_stdin (GeditDocument* doc, GError **error)
gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc), &iter);
gedit_undo_manager_end_not_undoable_action (doc->priv->undo_manager);
g_free (converted_text);
}
g_string_free (file_contents, TRUE);
gedit_document_set_readonly (doc, FALSE);
gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (doc), TRUE);
......
......@@ -47,6 +47,8 @@
#include "gedit-document.h"
#include "gedit-debug.h"
#define DEFAULT_ENCODING "ISO-8859-15"
/* =================================================== */
/* Flash */
......@@ -1535,3 +1537,147 @@ gedit_utils_create_empty_file (const gchar *uri)
return (close (fd) == 0);
}
#define GEDIT_STDIN_BUFSIZE 1024
gchar *
gedit_utils_get_stdin (void)
{
GString * file_contents;
gchar *tmp_buf = NULL;
struct stat stats;
guint buffer_length;
GnomeVFSResult res;
fstat (STDIN_FILENO, &stats);
if (stats.st_size == 0)
return NULL;
tmp_buf = g_new0 (gchar, GEDIT_STDIN_BUFSIZE + 1);
g_return_val_if_fail (tmp_buf != NULL, FALSE);
file_contents = g_string_new (NULL);
while (feof (stdin) == 0)
{
buffer_length = fread (tmp_buf, 1, GEDIT_STDIN_BUFSIZE, stdin);
tmp_buf [buffer_length] = '\0';
g_string_append (file_contents, tmp_buf);
if (ferror (stdin) != 0)
{
res = gnome_vfs_result_from_errno ();
g_free (tmp_buf);
g_string_free (file_contents, TRUE);
return NULL;
}
}
fclose (stdin);
return g_string_free (file_contents, FALSE);
}
gchar *
gedit_utils_convert_to_utf8 (const gchar *content, gchar **encoding)
{
gchar *utf8_content = NULL;
g_return_val_if_fail (content != NULL, NULL);
if (strlen (content) > 0)
{
gedit_debug (DEBUG_UTILS, "Checking to see if input is valid UTF-8");
if (!g_utf8_validate (content, -1, NULL))
{
/* The file contains invalid UTF8 data */
/* Try to convert it to UTF-8 from currence locale */
GError *conv_error = NULL;
gchar* converted_contents = NULL;
gsize bytes_written;
gedit_debug (DEBUG_UTILS, "Trying to convert from locale to UTF-8");
converted_contents = g_locale_to_utf8 (content, -1,
NULL, &bytes_written, &conv_error);
if ((conv_error != NULL) ||
!g_utf8_validate (converted_contents, bytes_written, NULL))
{
gedit_debug (DEBUG_UTILS,
"Couldn't convert from locale to UTF-8.");
if (converted_contents != NULL)
g_free (converted_contents);
if (conv_error != NULL)
{
g_error_free (conv_error);
conv_error = NULL;
}
/* try to convert from the default encoding */
converted_contents =
g_convert (content, strlen (content),
"UTF-8", DEFAULT_ENCODING,
NULL, &bytes_written,
&conv_error);
if ((conv_error != NULL) ||
!g_utf8_validate (converted_contents,
bytes_written, NULL))
{
gedit_debug (DEBUG_UTILS,
"Couldn't convert from %s to UTF-8.", DEFAULT_ENCODING);
/* Coversion failed */
if (conv_error != NULL)
g_error_free (conv_error);
if (converted_contents != NULL)
g_free (converted_contents);
return NULL;
}
else
{
gedit_debug (DEBUG_UTILS,
"Converted from %s to UTF-8.", DEFAULT_ENCODING);
if (encoding != NULL)
*encoding = g_strdup (DEFAULT_ENCODING);
}
}
else
{
/* successfully converted from their locale
* to utf8
*/
const gchar *charset;
g_get_charset (&charset);
if (encoding != NULL)
*encoding = g_strdup (charset);
gedit_debug (DEBUG_UTILS,
"Converted from locale to UTF-8.");
}
utf8_content = converted_contents;
}
else
{
/* they gave us valid UTF-8 */
utf8_content = g_strdup (content);
}
}
return utf8_content;
}
......@@ -89,6 +89,10 @@ gchar *gedit_utils_convert_search_text (const gchar *text);
gboolean gedit_utils_create_empty_file (const gchar *uri);
gchar *gedit_utils_get_stdin (void);
gchar *gedit_utils_convert_to_utf8 (const gchar *content,
gchar **encoding);
#endif /* __GEDIT_UTILS_H__ */
......@@ -30,6 +30,8 @@
#include <config.h>
#include <string.h>
#include <libgnome/libgnome.h>
#include <libgnomeui/libgnomeui.h>
#include <libgnomeui/gnome-window-icon.h>
......@@ -71,6 +73,9 @@ static void gedit_load_file_list (CommandLineData *data);
static const struct poptOption options [] =
{
{ "debug-utils", '\0', POPT_ARG_NONE, &debug_utils, 0,
N_("Show utility debugging messages."), NULL },
{ "debug-mdi", '\0', POPT_ARG_NONE, &debug_mdi, 0,
N_("Show mdi debugging messages."), NULL },
......@@ -211,6 +216,7 @@ gedit_handle_automation_cmdline (GnomeProgram *program)
CommandLineData *data;
GNOME_Gedit_URIList *uri_list;
GList *list;
gchar *stdin_data;
int i;
CORBA_exception_init (&env);
......@@ -219,6 +225,7 @@ gedit_handle_automation_cmdline (GnomeProgram *program)
0, NULL, &env);
g_return_if_fail (server != NULL);
if (quit_option)
GNOME_Gedit_Application_quit (server, &env);
......@@ -266,6 +273,24 @@ gedit_handle_automation_cmdline (GnomeProgram *program)
g_free (data);
}
stdin_data = gedit_utils_get_stdin ();
if (stdin_data != NULL)
{
gchar *converted;
converted = gedit_utils_convert_to_utf8 (stdin_data, NULL);
if (converted != NULL)
{
window = GNOME_Gedit_Application_getActiveWindow (server, &env);
document = GNOME_Gedit_Window_newDocument (window, &env);
GNOME_Gedit_Document_insert (document, 0, converted,
strlen (converted), &env);
}
}
if (!quit_option)
{
window = GNOME_Gedit_Application_getActiveWindow (server, &env);
......
*** IMPORTANT ***
This is an unstable version of gedit.
It is for test purpose only.
Please, DO NOT use it in a production environment.
Most probably it will crash and you will lose your data.
If you are looking for a stable release of gedit, either download
it from:
http://ftp.gnome.org/pub/gnome/sources/gedit/2.0/
Or checkout the gnome-2-0 branch of the gedit module from gnome CVS.
Thanks,
The gedit team
*** END OF WARNING ***
2002-09-22 James Willcox <jwillcox@gnome.org>
* gedit-debug.c: (gedit_debug):
* gedit-debug.h: Added DEBUG_UTILS
* gedit-document.c: (gedit_document_load),
(gedit_document_load_from_stdin): Use the functions in gedit-utils.c
* gedit-utils.c: (gedit_utils_get_stdin),
(gedit_utils_convert_to_utf8), (gedit_utils_convert_to_utf8_blah):
* gedit-utils.h: New functions
* gedit2.c: (gedit_handle_automation_cmdline): Insert data from
stdin into an existing instance.
2002-09-20 Paolo Maggi <maggi@athena.polito.it>
* gedit-plugins-engine.c (gedit_plugins_engine_load_dir):
......
......@@ -46,6 +46,7 @@ gint debug_commands = 0;
gint debug_recent = 0;
gint debug_mdi = 0;
gint debug_session = 0;
gint debug_utils = 0;
void
gedit_debug (gint section, gchar *file, gint line, gchar* function, gchar* format, ...)
......@@ -62,7 +63,8 @@ gedit_debug (gint section, gchar *file, gint line, gchar* function, gchar* forma
(debug_commands && section == GEDIT_DEBUG_COMMANDS) ||
(debug_recent && section == GEDIT_DEBUG_RECENT) ||
(debug_session && section == GEDIT_DEBUG_SESSION) ||
(debug_mdi && section == GEDIT_DEBUG_MDI) )
(debug_mdi && section == GEDIT_DEBUG_MDI) ||
(debug_utils && section == GEDIT_DEBUG_UTILS))
{
va_list args;
gchar *msg;
......
......@@ -43,7 +43,8 @@ typedef enum {
GEDIT_DEBUG_RECENT,
GEDIT_DEBUG_COMMANDS,
GEDIT_DEBUG_MDI,
GEDIT_DEBUG_SESSION
GEDIT_DEBUG_SESSION,
GEDIT_DEBUG_UTILS
} GeditDebugSection;
extern gint debug;
......@@ -59,6 +60,7 @@ extern gint debug_commands;
extern gint debug_recent;
extern gint debug_mdi;
extern gint debug_session;
extern gint debug_utils;
/* __FUNCTION_ is not defined in Irix according to David Kaelbling <drk@sgi.com>*/
#ifndef __GNUC__
......@@ -77,6 +79,7 @@ extern gint debug_session;
#define DEBUG_COMMANDS GEDIT_DEBUG_COMMANDS,__FILE__, __LINE__, __FUNCTION__
#define DEBUG_MDI GEDIT_DEBUG_MDI, __FILE__, __LINE__, __FUNCTION__
#define DEBUG_SESSION GEDIT_DEBUG_SESSION, __FILE__, __LINE__, __FUNCTION__
#define DEBUG_UTILS GEDIT_DEBUG_UTILS, __FILE__, __LINE__, __FUNCTION__
void gedit_debug (gint section, gchar *file,
gint line, gchar* function, gchar* format, ...);
......
......@@ -62,8 +62,6 @@
#define GEDIT_MAX_PATH_LEN 2048
#endif
#define DEFAULT_ENCODING "ISO-8859-15"
struct _GeditDocumentPrivate
{
gchar *uri;
......@@ -716,84 +714,21 @@ gedit_document_load (GeditDocument* doc, const gchar *uri, GError **error)
if (file_size > 0)
{
if (!g_utf8_validate (file_contents, file_size, NULL))
{
/* The file contains invalid UTF8 data */
/* Try to convert it to UTF-8 from currence locale */
GError *conv_error = NULL;
gchar* converted_file_contents = NULL;
gsize bytes_written;
converted_file_contents = g_locale_to_utf8 (file_contents, file_size,
NULL, &bytes_written, &conv_error);
if ((conv_error != NULL) ||
!g_utf8_validate (converted_file_contents, bytes_written, NULL))
{
/* Coversion failed */
if (conv_error != NULL) {
g_error_free (conv_error);
conv_error = NULL;
}
gchar *converted_text;
if (converted_file_contents != NULL)
g_free (converted_file_contents);
/* Try to convert it to UTF-8 from default encoding */
converted_file_contents = g_convert (file_contents, file_size,
"UTF-8", DEFAULT_ENCODING,
NULL, &bytes_written, &conv_error);
if ((conv_error != NULL) ||
!g_utf8_validate (converted_file_contents, bytes_written, NULL))
{
/* Coversion failed */
if (conv_error != NULL)
g_error_free (conv_error);
converted_text = gedit_utils_convert_to_utf8 (file_contents,
&doc->priv->encoding);
g_set_error (error, GEDIT_DOCUMENT_IO_ERROR,
GEDIT_ERROR_INVALID_UTF8_DATA,
_("Invalid UTF-8 data"));
if (converted_file_contents != NULL)
g_free (converted_file_contents);
g_free (file_contents);
if (converted_text == NULL)
{
/* bail out */
g_set_error (error, GEDIT_DOCUMENT_IO_ERROR,
GEDIT_ERROR_INVALID_UTF8_DATA,
_("Invalid UTF-8 data"));
return FALSE;
}
else
{
if (doc->priv->encoding != NULL)
g_free (doc->priv->encoding);
doc->priv->encoding = g_strdup (DEFAULT_ENCODING);
}
}
else
{
const gchar *encoding = NULL;
g_get_charset(&encoding);
if (doc->priv->encoding != NULL)
g_free (doc->priv->encoding);
doc->priv->encoding = g_strdup (encoding);
}
g_free (file_contents);
file_contents = converted_file_contents;
file_size = bytes_written;
}
else
{
if (doc->priv->encoding != NULL)
{
g_free (doc->priv->encoding);
doc->priv->encoding = NULL;
}
return FALSE;
}
gedit_debug (DEBUG_DOCUMENT, "Document encoding: %s",
......@@ -802,7 +737,8 @@ gedit_document_load (GeditDocument* doc, const gchar *uri, GError **error)
gedit_undo_manager_begin_not_undoable_action (doc->priv->undo_manager);
/* Insert text in the buffer */
gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &iter, 0);
gtk_text_buffer_insert (GTK_TEXT_BUFFER (doc), &iter, file_contents, file_size);
gtk_text_buffer_insert (GTK_TEXT_BUFFER (doc), &iter, converted_text, file_size);
g_free (converted_text);
/* We had a newline in the buffer to begin with. (The buffer always contains
* a newline, so we delete to the end of the buffer to clean up. */
......@@ -840,97 +776,41 @@ gedit_document_load (GeditDocument* doc, const gchar *uri, GError **error)
return TRUE;
}
#define GEDIT_STDIN_BUFSIZE 1024
gboolean
gedit_document_load_from_stdin (GeditDocument* doc, GError **error)
{
GString * file_contents;