updated: [3d0f9e4] Reverted some more GString removals. (See f235b1976ee6dd7aa2be7e75c870784c424e3de3)
- From: "Patrick Winnertz" <winnie debian org>
- To: mc-devel gnome org
- Subject: updated: [3d0f9e4] Reverted some more GString removals. (See f235b1976ee6dd7aa2be7e75c870784c424e3de3)
- Date: Tue, 10 Feb 2009 12:49:53 +0100 (CET)
The following commit has been merged in the master branch:
commit 3d0f9e419a1b8a28196ee15b93adf56eafdd1a1e
Author: Patrick Winnertz <winnie debian org>
Date: Thu Feb 5 23:22:08 2009 +0100
Reverted some more GString removals. (See f235b1976ee6dd7aa2be7e75c870784c424e3de3)
Signed-off-by: Patrick Winnertz <winnie debian org>
diff --git a/edit/edit.c b/edit/edit.c
index e853a96..4504df7 100644
--- a/edit/edit.c
+++ b/edit/edit.c
@@ -153,9 +153,10 @@ edit_load_file_fast (WEdit *edit, const char *filename)
buf2 = edit->curs2 >> S_EDIT_BUF_SIZE;
if ((file = mc_open (filename, O_RDONLY | O_BINARY)) == -1) {
- char errmsg[8192];
- snprintf(errmsg, sizeof(errmsg), _(" Cannot open %s for reading "), filename);
- edit_error_dialog (_("Error"), get_sys_error (errmsg));
+ GString *errmsg = g_string_new(NULL);
+ g_string_sprintf(errmsg, _(" Cannot open %s for reading "), filename);
+ edit_error_dialog (_("Error"), get_sys_error (errmsg->str));
+ g_string_free (errmsg, TRUE);
return 1;
}
@@ -315,8 +316,7 @@ static int
check_file_access (WEdit *edit, const char *filename, struct stat *st)
{
int file;
- char errmsg[8192];
- errmsg[0] = 0;
+ GString *errmsg = (GString *) 0;
/* Try opening an existing file */
file = mc_open (filename, O_NONBLOCK | O_RDONLY | O_BINARY, 0666);
@@ -331,7 +331,8 @@ check_file_access (WEdit *edit, const char *filename, struct stat *st)
O_NONBLOCK | O_RDONLY | O_BINARY | O_CREAT | O_EXCL,
0666);
if (file < 0) {
- snprintf (errmsg, sizeof(errmsg), _(" Cannot open %s for reading "), filename);
+ g_string_sprintf (errmsg = g_string_new (NULL),
+ _(" Cannot open %s for reading "), filename);
goto cleanup;
} else {
/* New file, delete it if it's not modified or saved */
@@ -341,13 +342,15 @@ check_file_access (WEdit *edit, const char *filename, struct stat *st)
/* Check what we have opened */
if (mc_fstat (file, st) < 0) {
- snprintf (errmsg, sizeof(errmsg), _(" Cannot get size/permissions for %s "), filename);
+ g_string_sprintf (errmsg = g_string_new (NULL),
+ _(" Cannot get size/permissions for %s "), filename);
goto cleanup;
}
/* We want to open regular files only */
if (!S_ISREG (st->st_mode)) {
- snprintf (errmsg, sizeof(errmsg), _(" %s is not a regular file "), filename);
+ g_string_sprintf (errmsg = g_string_new (NULL),
+ _(" %s is not a regular file "), filename);
goto cleanup;
}
@@ -360,14 +363,16 @@ check_file_access (WEdit *edit, const char *filename, struct stat *st)
}
if (st->st_size >= SIZE_LIMIT) {
- snprintf (errmsg, sizeof(errmsg), _(" File %s is too large "), filename);
+ g_string_sprintf (errmsg = g_string_new (NULL),
+ _(" File %s is too large "), filename);
goto cleanup;
}
cleanup:
(void) mc_close (file);
- if (errmsg[0]) {
- edit_error_dialog (_("Error"), errmsg);
+ if (errmsg) {
+ edit_error_dialog (_("Error"), errmsg->str);
+ g_string_free (errmsg, TRUE);
return 1;
}
return 0;
diff --git a/edit/editcmd.c b/edit/editcmd.c
index 8de68ea..9d730e0 100644
--- a/edit/editcmd.c
+++ b/edit/editcmd.c
@@ -1214,16 +1214,14 @@ edit_replace_prompt (WEdit * edit, char *replace_text, int xpos, int ypos)
0, 0, 0, 0, 0},
NULL_QuickWidget};
- const char* label_nls = _(" Replace with: ");
- char label_text[8192];
- if (*replace_text)
- {
- size_t label_len = strlen(label_nls);
- snprintf(label_text, sizeof(label_text), "%s%s", label_nls, replace_text);
- convert_to_display((&label_text)+label_len);
+ GString *label_text = g_string_new (_(" Replace with: "));
+ if (*replace_text) {
+ size_t label_len;
+ label_len = label_text->len;
+ g_string_append (label_text, replace_text);
+ convert_to_display (label_text->str + label_len);
}
-
- quick_widgets[5].text = label_text;
+ quick_widgets[5].text = label_text->str;
{
int retval;
@@ -1242,6 +1240,7 @@ edit_replace_prompt (WEdit * edit, char *replace_text, int xpos, int ypos)
Quick_input.ypos = ypos;
retval = quick_dialog (&Quick_input);
+ g_string_free (label_text, TRUE);
return retval;
}
}
diff --git a/edit/syntax.c b/edit/syntax.c
index 5de3aaf..479f3c5 100644
--- a/edit/syntax.c
+++ b/edit/syntax.c
@@ -505,14 +505,10 @@ void edit_get_syntax_color (WEdit * edit, long byte_index, int *color)
*/
static int read_one_line (char **line, FILE * f)
{
- char buffer[8192];
- int index = 0, c, r = 0;
- buffer[0] = 0;
+ GString *p = g_string_new ("");
+ int c, r = 0;
for (;;) {
- if (index >= (sizeof(buffer)-1))
- break;
-
c = fgetc (f);
if (c == EOF) {
if (ferror (f)) {
@@ -534,11 +530,13 @@ static int read_one_line (char **line, FILE * f)
if (c == '\n')
break;
- buffer[index] = c;
- index++;
+ g_string_append_c (p, c);
}
if (r != 0) {
- *line = mhl_str_dup(buffer);
+ *line = p->str;
+ g_string_free (p, FALSE);
+ } else {
+ g_string_free (p, TRUE);
}
return r;
}
--
Midnight Commander Development
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]