* edit.h (edit_save_mode_t): New enum for file saving mode.
* editcmd.c (): Use edit_save_mode_t. (pipe_mail): Quote to, subject and cc with name_quote(). * edit.c (edit_get_filter): Use quoted filename. (edit_get_write_filter): Use quoted writename. (edit_push_action): Use g_realloc().
Этот коммит содержится в:
родитель
76a86209d4
Коммит
bce2ba99e9
@ -1,3 +1,12 @@
|
|||||||
|
2002-12-18 Andrew V. Samoilov <sav@bcs.zp.ua>
|
||||||
|
|
||||||
|
* edit.h (edit_save_mode_t): New enum for file saving mode.
|
||||||
|
* editcmd.c (): Use edit_save_mode_t.
|
||||||
|
(pipe_mail): Quote to, subject and cc with name_quote().
|
||||||
|
* edit.c (edit_get_filter): Use quoted filename.
|
||||||
|
(edit_get_write_filter): Use quoted writename.
|
||||||
|
(edit_push_action): Use g_realloc().
|
||||||
|
|
||||||
2002-12-16 Pavel Roskin <proski@gnu.org>
|
2002-12-16 Pavel Roskin <proski@gnu.org>
|
||||||
|
|
||||||
* editcmd.c (edit_goto_cmd): Add support for negative line
|
* editcmd.c (edit_goto_cmd): Add support for negative line
|
||||||
|
21
edit/edit.c
21
edit/edit.c
@ -48,7 +48,7 @@ int option_fill_tabs_with_spaces = 0;
|
|||||||
int option_return_does_auto_indent = 1;
|
int option_return_does_auto_indent = 1;
|
||||||
int option_backspace_through_tabs = 0;
|
int option_backspace_through_tabs = 0;
|
||||||
int option_fake_half_tabs = 1;
|
int option_fake_half_tabs = 1;
|
||||||
int option_save_mode = 0;
|
int option_save_mode = EDIT_QUICK_SAVE;
|
||||||
int option_save_position = 1;
|
int option_save_position = 1;
|
||||||
int option_backup_ext_int = -1;
|
int option_backup_ext_int = -1;
|
||||||
int option_max_undo = 32768;
|
int option_max_undo = 32768;
|
||||||
@ -218,26 +218,31 @@ static char *
|
|||||||
edit_get_filter (const char *filename)
|
edit_get_filter (const char *filename)
|
||||||
{
|
{
|
||||||
int i, l;
|
int i, l;
|
||||||
char *p;
|
char *p, *quoted_name;
|
||||||
i = edit_find_filter (filename);
|
i = edit_find_filter (filename);
|
||||||
if (i < 0)
|
if (i < 0)
|
||||||
return 0;
|
return 0;
|
||||||
l = strlen (filename);
|
quoted_name = name_quote (filename, 0);
|
||||||
|
l = strlen (quoted_name);
|
||||||
p = g_malloc (strlen (all_filters[i].read) + l + 2);
|
p = g_malloc (strlen (all_filters[i].read) + l + 2);
|
||||||
sprintf (p, all_filters[i].read, filename);
|
sprintf (p, all_filters[i].read, quoted_name);
|
||||||
|
g_free (quoted_name);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *edit_get_write_filter (char *writename, const char *filename)
|
char *
|
||||||
|
edit_get_write_filter (const char *write_name, const char *filename)
|
||||||
{
|
{
|
||||||
int i, l;
|
int i, l;
|
||||||
char *p;
|
char *p, *writename;
|
||||||
i = edit_find_filter (filename);
|
i = edit_find_filter (filename);
|
||||||
if (i < 0)
|
if (i < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
writename = name_quote (write_name, 0);
|
||||||
l = strlen (writename);
|
l = strlen (writename);
|
||||||
p = g_malloc (strlen (all_filters[i].write) + l + 2);
|
p = g_malloc (strlen (all_filters[i].write) + l + 2);
|
||||||
sprintf (p, all_filters[i].write, writename);
|
sprintf (p, all_filters[i].write, writename);
|
||||||
|
g_free (writename);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -695,10 +700,8 @@ void edit_push_action (WEdit * edit, long c,...)
|
|||||||
if (option_max_undo < 256)
|
if (option_max_undo < 256)
|
||||||
option_max_undo = 256;
|
option_max_undo = 256;
|
||||||
if (edit->stack_size < option_max_undo) {
|
if (edit->stack_size < option_max_undo) {
|
||||||
t = g_malloc ((edit->stack_size * 2 + 10) * sizeof (long));
|
t = g_realloc (edit->undo_stack, (edit->stack_size * 2 + 10) * sizeof (long));
|
||||||
if (t) {
|
if (t) {
|
||||||
memcpy (t, edit->undo_stack, sizeof (long) * edit->stack_size);
|
|
||||||
g_free (edit->undo_stack);
|
|
||||||
edit->undo_stack = t;
|
edit->undo_stack = t;
|
||||||
edit->stack_size <<= 1;
|
edit->stack_size <<= 1;
|
||||||
edit->stack_size_mask = edit->stack_size - 1;
|
edit->stack_size_mask = edit->stack_size - 1;
|
||||||
|
10
edit/edit.h
10
edit/edit.h
@ -175,7 +175,7 @@ void edit_push_key_press (WEdit * edit);
|
|||||||
void edit_insert_ahead (WEdit * edit, int c);
|
void edit_insert_ahead (WEdit * edit, int c);
|
||||||
int edit_save_file (WEdit * edit, const char *filename);
|
int edit_save_file (WEdit * edit, const char *filename);
|
||||||
long edit_write_stream (WEdit * edit, FILE * f);
|
long edit_write_stream (WEdit * edit, FILE * f);
|
||||||
char *edit_get_write_filter (char *writename, const char *filename);
|
char *edit_get_write_filter (const char *writename, const char *filename);
|
||||||
int edit_save_cmd (WEdit * edit);
|
int edit_save_cmd (WEdit * edit);
|
||||||
int edit_save_confirm_cmd (WEdit * edit);
|
int edit_save_confirm_cmd (WEdit * edit);
|
||||||
int edit_save_as_cmd (WEdit * edit);
|
int edit_save_as_cmd (WEdit * edit);
|
||||||
@ -300,11 +300,19 @@ extern int option_fill_tabs_with_spaces;
|
|||||||
extern int option_return_does_auto_indent;
|
extern int option_return_does_auto_indent;
|
||||||
extern int option_backspace_through_tabs;
|
extern int option_backspace_through_tabs;
|
||||||
extern int option_fake_half_tabs;
|
extern int option_fake_half_tabs;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
EDIT_QUICK_SAVE = 0,
|
||||||
|
EDIT_SAFE_SAVE,
|
||||||
|
EDIT_DO_BACKUP
|
||||||
|
} edit_save_mode_t;
|
||||||
|
|
||||||
extern int option_save_mode;
|
extern int option_save_mode;
|
||||||
extern int option_save_position;
|
extern int option_save_position;
|
||||||
extern int option_backup_ext_int;
|
extern int option_backup_ext_int;
|
||||||
extern int option_max_undo;
|
extern int option_max_undo;
|
||||||
extern int option_syntax_highlighting;
|
extern int option_syntax_highlighting;
|
||||||
|
extern int editor_option_check_nl_at_eof;
|
||||||
|
|
||||||
extern int option_edit_right_extreme;
|
extern int option_edit_right_extreme;
|
||||||
extern int option_edit_left_extreme;
|
extern int option_edit_left_extreme;
|
||||||
|
@ -214,13 +214,13 @@ edit_save_file (WEdit *edit, const char *filename)
|
|||||||
* The file does not exists yet, so no safe save or
|
* The file does not exists yet, so no safe save or
|
||||||
* backup are necessary.
|
* backup are necessary.
|
||||||
*/
|
*/
|
||||||
this_save_mode = 0;
|
this_save_mode = EDIT_QUICK_SAVE;
|
||||||
} else {
|
} else {
|
||||||
mc_close (fd);
|
mc_close (fd);
|
||||||
this_save_mode = option_save_mode;
|
this_save_mode = option_save_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this_save_mode > 0) {
|
if (this_save_mode != EDIT_QUICK_SAVE) {
|
||||||
char *savedir, *slashpos, *saveprefix;
|
char *savedir, *slashpos, *saveprefix;
|
||||||
slashpos = strrchr (filename, PATH_SEP);
|
slashpos = strrchr (filename, PATH_SEP);
|
||||||
if (slashpos) {
|
if (slashpos) {
|
||||||
@ -252,7 +252,7 @@ edit_save_file (WEdit *edit, const char *filename)
|
|||||||
goto error_save;
|
goto error_save;
|
||||||
|
|
||||||
/* pipe save */
|
/* pipe save */
|
||||||
if ((p = (char *) edit_get_write_filter (savename, filename))) {
|
if ((p = edit_get_write_filter (savename, filename))) {
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
|
||||||
mc_close (fd);
|
mc_close (fd);
|
||||||
@ -326,19 +326,21 @@ edit_save_file (WEdit *edit, const char *filename)
|
|||||||
|
|
||||||
if (filelen != edit->last_byte)
|
if (filelen != edit->last_byte)
|
||||||
goto error_save;
|
goto error_save;
|
||||||
if (this_save_mode == 2)
|
if (this_save_mode == EDIT_DO_BACKUP)
|
||||||
if (mc_rename (filename, catstrs (filename, option_backup_ext, 0))
|
if (mc_rename (filename, catstrs (filename, option_backup_ext, 0))
|
||||||
== -1)
|
== -1)
|
||||||
goto error_save;
|
goto error_save;
|
||||||
if (this_save_mode > 0)
|
if (this_save_mode != EDIT_QUICK_SAVE)
|
||||||
if (mc_rename (savename, filename) == -1)
|
if (mc_rename (savename, filename) == -1)
|
||||||
goto error_save;
|
goto error_save;
|
||||||
if (savename)
|
g_free (savename);
|
||||||
g_free (savename);
|
|
||||||
return 1;
|
return 1;
|
||||||
error_save:
|
error_save:
|
||||||
if (savename)
|
/* FIXME: Is this safe ?
|
||||||
g_free (savename);
|
* if (this_save_mode != EDIT_QUICK_SAVE)
|
||||||
|
* mc_unlink (savename);
|
||||||
|
*/
|
||||||
|
g_free (savename);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2435,7 +2437,13 @@ static void pipe_mail (WEdit *edit, char *to, char *subject, char *cc)
|
|||||||
FILE *p = 0;
|
FILE *p = 0;
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
s = g_strdup_printf ("mail -s \"%s\" -c \"%s\" \"%s\"", subject, cc, to);
|
to = name_quote (to, 0);
|
||||||
|
subject = name_quote (subject, 0);
|
||||||
|
cc = name_quote (cc, 0);
|
||||||
|
s = g_strdup_printf ("mail -s %s -c %s %s", subject, cc, to);
|
||||||
|
g_free (to);
|
||||||
|
g_free (subject);
|
||||||
|
g_free (cc);
|
||||||
|
|
||||||
if (s) {
|
if (s) {
|
||||||
p = popen (s, "w");
|
p = popen (s, "w");
|
||||||
|
Загрузка…
Ссылка в новой задаче
Block a user