From 2420cfe9dd645ec8c88e9e6ef0dd0f21fc651ed7 Mon Sep 17 00:00:00 2001 From: "Andrew V. Samoilov" Date: Thu, 7 Sep 2000 17:18:32 +0000 Subject: [PATCH] 2000-09-07 Andrew V. Samoilov * edit.c (check_file_access) [MIDNIGHT,GTK]: error message localized; some cosmetics changes to avoid annoying warnings * editcmd.c (edit_save_file): pclose returns 0 on success, file fclose()d when fwrite fails (pipe_mail): malloc () + sprintf () replaced by g_strdup_printf () * syntax.c (syntax_text): Makefile replaced by [Mm]akefile to cover makefile and GNUmakefile (upgrade_syntax_file): infinitive loop fixed when rule file is outdated but it cannot be unlinked/overwritten --- gtkedit/ChangeLog | 15 +++++++++++++ gtkedit/edit.c | 20 +++++++++-------- gtkedit/editcmd.c | 55 ++++++++++++++++++++++++----------------------- 3 files changed, 54 insertions(+), 36 deletions(-) diff --git a/gtkedit/ChangeLog b/gtkedit/ChangeLog index d2f57cee8..27c37dc02 100644 --- a/gtkedit/ChangeLog +++ b/gtkedit/ChangeLog @@ -1,3 +1,18 @@ +2000-09-07 Andrew V. Samoilov + + * edit.c (check_file_access) [MIDNIGHT,GTK]: error message localized; + some cosmetics changes to avoid annoying warnings + + * editcmd.c (edit_save_file): pclose returns 0 on success, + file fclose()d when fwrite fails + + (pipe_mail): malloc () + sprintf () replaced by g_strdup_printf () + + * syntax.c (syntax_text): Makefile replaced by [Mm]akefile to cover + makefile and GNUmakefile + (upgrade_syntax_file): infinitive loop fixed when rule file + is outdated but it cannot be unlinked/overwritten + 2000-08-30 Pavel Roskin * editwidget.c [!MIDNIGHT]: include xdnd.h diff --git a/gtkedit/edit.c b/gtkedit/edit.c index 65e434a00..f592104df 100644 --- a/gtkedit/edit.c +++ b/gtkedit/edit.c @@ -4,6 +4,8 @@ Authors: 1996, 1997 Paul Sheer + $Id$ + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -280,7 +282,7 @@ long edit_write_stream (WEdit * edit, FILE * f) } return i; } -#else +#else /* CR_LF_TRANSLATION */ long edit_insert_stream (WEdit * edit, FILE * f) { int c; @@ -299,7 +301,7 @@ long edit_write_stream (WEdit * edit, FILE * f) break; return i; } -#endif +#endif /* CR_LF_TRANSLATION */ #define TEMP_BUF_LEN 1024 @@ -370,7 +372,7 @@ static int check_file_access (WEdit *edit, const char *filename, struct stat *st if ((file = open ((char *) filename, O_RDONLY)) < 0) { close (creat ((char *) filename, 0666)); if ((file = open ((char *) filename, O_RDONLY)) < 0) { - edit_error_dialog (_ (" Error "), get_sys_error (catstrs (" Fail trying to open the file, ", filename, ", for reading ", 0))); + edit_error_dialog (_ (" Error "), get_sys_error (catstrs (_ (" Failed trying to open file for reading: "), filename, " ", 0))); return 2; } } @@ -2752,13 +2754,13 @@ void user_menu (WEdit *edit) edit_cursor_to_bol (edit); edit_insert_file (edit, block_file); edit_cursor_to_eol (edit); - if (fd = fopen (block_file, "w")) fclose(fd); + if ((fd = fopen (block_file, "w"))) fclose(fd); } } else { /* it is error */ edit_cursor_to_bol (edit); edit_insert_file (edit, error_file); - if (fd = fopen (error_file, "w")) fclose(fd); - if (fd = fopen (block_file, "w")) fclose(fd); + if ((fd = fopen (error_file, "w"))) fclose(fd); + if ((fd = fopen (block_file, "w"))) fclose(fd); } } else { edit_error_dialog ("", @@ -2775,8 +2777,8 @@ void edit_init_file() { FILE *f; - if (f = fopen (catstrs (home_dir, ERROR_FILE, 0), "w")) fclose(f); - if (f = fopen (catstrs (home_dir, BLOCK_FILE, 0), "w")) fclose(f); - if (f = fopen (catstrs (home_dir, TEMP_FILE, 0) , "w")) fclose(f); + if ((f = fopen (catstrs (home_dir, ERROR_FILE, 0), "w"))) fclose(f); + if ((f = fopen (catstrs (home_dir, BLOCK_FILE, 0), "w"))) fclose(f); + if ((f = fopen (catstrs (home_dir, TEMP_FILE, 0) , "w"))) fclose(f); return; } diff --git a/gtkedit/editcmd.c b/gtkedit/editcmd.c index a38d7af69..ba33fcc58 100644 --- a/gtkedit/editcmd.c +++ b/gtkedit/editcmd.c @@ -4,6 +4,8 @@ Authors: 1996, 1997 Paul Sheer + $Id$ + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -18,6 +20,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ /* #define PIPE_BLOCKS_SO_READ_BYTE_BY_BYTE */ @@ -179,12 +182,12 @@ void edit_refresh_cmd (WEdit * edit) edit_get_syntax_color (edit, -1, &fg, &bg); } touchwin(stdscr); -#endif +#endif /* !HAVE_SLANG */ mc_refresh(); doupdate(); } -#else +#else /* MIDNIGHT */ void edit_help_cmd (WEdit * edit) { @@ -202,7 +205,7 @@ void CRefreshEditor (WEdit * edit) edit_refresh_cmd (edit); } -#endif +#endif /* MIDNIGHT */ #ifndef MIDNIGHT #ifndef GTK @@ -227,8 +230,8 @@ int my_open (const char *pathname, int flags,...) #define open my_open -#endif -#endif +#endif /* !GTK */ +#endif /* !MIDNIGHT */ /* "Oleg Yu. Repin" added backup filenames ...thanks -paul */ @@ -294,7 +297,7 @@ int edit_save_file (WEdit * edit, const char *filename) #if 1 pclose (file); #else - if (pclose (file) > 0) { + if (pclose (file) != 0) { edit_error_dialog (_ (" Error "), catstrs (_ (" Error writing to pipe: "), p, " ", 0)); free (p); goto error_save; @@ -318,6 +321,7 @@ int edit_save_file (WEdit * edit, const char *filename) filelen = edit->last_byte; while (buf <= (edit->curs1 >> S_EDIT_BUF_SIZE) - 1) { if (fwrite ((char *) edit->buffers1[buf], EDIT_BUF_SIZE, 1, file) != 1) { + fclose (file); goto error_save; } buf++; @@ -418,10 +422,6 @@ void menu_save_mode_cmd (void) memcpy ((char *) &option_backup_ext_int, str_result, strlen (option_backup_ext)); } -#endif - -#ifdef MIDNIGHT - void edit_split_filename (WEdit * edit, char *f) { if (edit->filename) @@ -432,7 +432,7 @@ void edit_split_filename (WEdit * edit, char *f) edit->dir = (char *) strdup (""); } -#else +#else /* MIDNIGHT */ #ifdef GTK @@ -496,7 +496,7 @@ static char *canonicalize_pathname (char *p) void edit_split_filename (WEdit * edit, char *longname) { char *exp, *p; -#if defined(MIDNIGHT) || defined(GTK) +#ifdef GTK exp = canonicalize_pathname (longname); #else exp = pathdup (longname); /* this ensures a full path */ @@ -620,7 +620,7 @@ int edit_raw_key_query (char *heading, char *query, int cancel) return w; } -#else +#else /* MIDNIGHT */ int edit_raw_key_query (char *heading, char *query, int cancel) { @@ -632,7 +632,7 @@ int edit_raw_key_query (char *heading, char *query, int cancel) #endif } -#endif +#endif /* MIDNIGHT */ /* creates a macro file if it doesn't exist */ static FILE *edit_open_macro_file (const char *r) @@ -705,7 +705,7 @@ int edit_delete_macro (WEdit * edit, int k) fprintf (g, "%hd %hd, ", macro[i].command, macro[i].ch); fprintf (g, ";\n"); } - }; + } fclose (f); fclose (g); if (rename (catstrs (home_dir, TEMP_FILE, 0), catstrs (home_dir, MACRO_FILE, 0)) == -1) { @@ -2887,7 +2887,7 @@ void edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block) return; } else { while (fgets(buf, sizeof(buf), script_src)) - fprintf(script_home, "%s",buf); + fputs (buf, script_home); if (fclose(script_home)) { edit_error_dialog ("", get_sys_error (catstrs (_ ("Error close script:"), h, 0))); @@ -2946,7 +2946,7 @@ void edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block) return; } -#endif +#endif /* MIDNIGHT */ int edit_execute_cmd (WEdit * edit, int command, int char_for_insertion); @@ -2980,21 +2980,22 @@ int edit_printf (WEdit * e, const char *fmt,...) static void pipe_mail (WEdit *edit, char *to, char *subject, char *cc) { - FILE *p; + FILE *p = 0; char *s; - s = malloc (4096); - sprintf (s, "mail -s \"%s\" -c \"%s\" \"%s\"", subject, cc, to); - p = popen (s, "w"); - if (!p) { - free (s); - return; - } else { + + s = g_strdup_printf ("mail -s \"%s\" -c \"%s\" \"%s\"", subject, cc, to); + + if (s) { + p = popen (s, "w"); + g_free (s); + } + + if (p) { long i; for (i = 0; i < edit->last_byte; i++) fputc (edit_get_byte (edit, i), p); pclose (p); } - free (s); } #define MAIL_DLG_HEIGHT 12 @@ -3060,5 +3061,5 @@ void edit_mail_dialog (WEdit * edit) } } -#endif +#endif /* MIDNIGHT */