2000-10-30 Andrew V. Samoilov <sav@bcs.zp.ua>

* editcmd.c (edit_save_file): better error handling on writting

	(edit_sort_cmd): saved sort options proposed in dialog

	edit.h, editcmd.c: declaration for edit_save_block () added

	(edit_split_filename): f constified

	* edit.c (edit_init) [ENABLE_NLS]: option_whole_chars_search
	expanded by national letters using current locale on first call

	(edit_file_is_open) [MIDNIGHT]: all occurences and related code
	are commented

	(edit_execute_cmd): typo in error message fixed
This commit is contained in:
Andrew V. Samoilov 2000-10-30 18:07:19 +00:00
parent 5aac944afe
commit 2b8546dc21
3 changed files with 49 additions and 30 deletions

View File

@ -446,10 +446,10 @@ void edit_set_space_width (int s)
space_width = s;
}
#endif
int (*edit_file_is_open) (char *) = 0;
#endif
/* fills in the edit struct. returns 0 on fail. Pass edit as NULL for this */
WEdit *edit_init (WEdit * edit, int lines, int columns, const char *filename, const char *text, const char *dir, unsigned long text_size)
{
@ -463,6 +463,30 @@ WEdit *edit_init (WEdit * edit, int lines, int columns, const char *filename, co
edit_set_space_width (FONT_PER_CHAR[' ']);
#endif
if (!edit) {
#ifdef ENABLE_NLS
/*
* Expand option_whole_chars_search by national letters using
* current locale
*/
static char option_whole_chars_search_buf [256];
if (option_whole_chars_search_buf != option_whole_chars_search) {
int i;
int len = strlen (option_whole_chars_search);
strcpy (option_whole_chars_search_buf, option_whole_chars_search);
for (i = 1; i <= sizeof (option_whole_chars_search_buf); i++) {
if (islower (i) && !strchr (option_whole_chars_search, i)) {
option_whole_chars_search_buf [len++] = i;
}
}
option_whole_chars_search_buf [len] = 0;
option_whole_chars_search = option_whole_chars_search_buf;
}
#endif /* ENABLE_NLS */
edit = malloc (sizeof (WEdit));
memset (edit, 0, sizeof (WEdit));
to_free = 1;
@ -482,12 +506,14 @@ WEdit *edit_init (WEdit * edit, int lines, int columns, const char *filename, co
f = (char *) filename;
if (filename) {
f = catstrs (dir, filename, 0);
#ifndef MIDNIGHT
if (edit_file_is_open)
if ((*edit_file_is_open) (f)) {
if (to_free)
free (edit);
return 0;
}
#endif
}
if (edit_find_filter (f) < 0) {
#ifdef CR_LF_TRANSLATION
@ -1215,7 +1241,7 @@ long edit_move_forward3 (WEdit * edit, long current, int cols, long upto)
return p;
}
}
return (float) col;
return col;
}
#endif
@ -2136,17 +2162,16 @@ int edit_execute_key_command (WEdit * edit, int command, int char_for_insertion)
#ifdef MIDNIGHT
static const char *shell_cmd[] = SHELL_COMMANDS_i
void edit_mail_dialog (WEdit * edit);
#else
static void (*user_commamd) (WEdit *, int) = 0;
void edit_set_user_command (void (*func) (WEdit *, int))
{
user_commamd = func;
}
#endif
void edit_mail_dialog (WEdit * edit);
/*
This executes a command at a lower level than macro recording.
It also does not push a key_press onto the undo stack. This means
@ -2277,11 +2302,11 @@ int edit_execute_cmd (WEdit * edit, int command, int char_for_insertion)
if (option_return_does_auto_indent)
edit_auto_indent (edit, 0, 1);
format_paragraph (edit, 0);
} else if (option_return_does_auto_indent) {
edit_insert (edit, '\n');
edit_auto_indent (edit, 0, 1);
} else {
edit_insert (edit, '\n');
if (option_return_does_auto_indent) {
edit_auto_indent (edit, 0, 1);
}
}
break;
case CK_Return:
@ -2543,7 +2568,7 @@ int edit_execute_cmd (WEdit * edit, int command, int char_for_insertion)
#endif
time (&t);
#ifdef HAVE_STRFTIME
strftime (s, 1024, "%c", localtime (&t));
strftime (s, sizeof (s), "%c", localtime (&t));
edit_printf (edit, s);
#else
edit_printf (edit, ctime (&t));
@ -2566,7 +2591,7 @@ int edit_execute_cmd (WEdit * edit, int command, int char_for_insertion)
break;
case CK_User_Menu:
if (edit_one_file) {
message (1, MSG_ERROR, _("User menu avalaible only in mcedit invoked from mc"));
message (1, MSG_ERROR, _("User menu available only in mcedit invoked from mc"));
break;
}
else

View File

@ -396,6 +396,7 @@ void edit_push_markers (WEdit * edit);
void edit_quit_cmd (WEdit * edit);
void edit_replace_cmd (WEdit * edit, int again);
void edit_search_cmd (WEdit * edit, int again);
int edit_save_block (WEdit * edit, const char *filename, long start, long finish);
int edit_save_block_cmd (WEdit * edit);
int edit_insert_file_cmd (WEdit * edit);
int edit_insert_file (WEdit * edit, const char *filename);
@ -431,7 +432,7 @@ void edit_paste_from_X_buf_cmd (WEdit * edit);
void edit_paste_from_history (WEdit *edit);
void edit_split_filename (WEdit * edit, char *name);
void edit_split_filename (WEdit * edit, const char *name);
#ifdef MIDNIGHT
#define CWidget Widget

View File

@ -324,22 +324,22 @@ int edit_save_file (WEdit * edit, const char *filename)
buf = 0;
filelen = edit->last_byte;
while (buf <= (edit->curs1 >> S_EDIT_BUF_SIZE) - 1) {
if (write (fd, (char *) edit->buffers1[buf], EDIT_BUF_SIZE) == -1) {
if (write (fd, (char *) edit->buffers1[buf], EDIT_BUF_SIZE) != EDIT_BUF_SIZE) {
close (fd);
goto error_save;
}
buf++;
}
if (write (fd, (char *) edit->buffers1[buf], edit->curs1 & M_EDIT_BUF_SIZE) == -1) {
if (write (fd, (char *) edit->buffers1[buf], edit->curs1 & M_EDIT_BUF_SIZE) != (edit->curs1 & M_EDIT_BUF_SIZE)) {
filelen = -1;
} else if (edit->curs2) {
edit->curs2--;
buf = (edit->curs2 >> S_EDIT_BUF_SIZE);
if (write (fd, (char *) edit->buffers2[buf] + EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE) - 1, 1 + (edit->curs2 & M_EDIT_BUF_SIZE)) == -1) {
if (write (fd, (char *) edit->buffers2[buf] + EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE) - 1, 1 + (edit->curs2 & M_EDIT_BUF_SIZE)) != 1 + (edit->curs2 & M_EDIT_BUF_SIZE)) {
filelen = -1;
} else {
while (--buf >= 0) {
if (write (fd, (char *) edit->buffers2[buf], EDIT_BUF_SIZE) == -1) {
if (write (fd, (char *) edit->buffers2[buf], EDIT_BUF_SIZE) != EDIT_BUF_SIZE) {
filelen = -1;
break;
}
@ -400,7 +400,6 @@ void menu_save_mode_cmd (void)
0, &save_mode_new, str, XV_WLAY_DONTCARE, "t"},
{0}};
static QuickDialog dialog =
/* NLS ? */
{DLG_X, DLG_Y, -1, -1, N_(" Edit Save Mode "), "[Edit Save Mode]",
"esm", widgets};
static int i18n_flag = 0;
@ -424,7 +423,7 @@ void menu_save_mode_cmd (void)
memcpy ((char *) &option_backup_ext_int, str_result, strlen (option_backup_ext));
}
void edit_split_filename (WEdit * edit, char *f)
void edit_split_filename (WEdit * edit, const char *f)
{
if (edit->filename)
free (edit->filename);
@ -1188,7 +1187,6 @@ int edit_replace_prompt (WEdit * edit, char *replace_text, int xpos, int ypos)
{
QuickWidget quick_widgets[] =
{
/* NLS for hotkeys? */
{quick_button, 63, CONFIRM_DLG_WIDTH, 3, CONFIRM_DLG_HEIGTH, N_ ("&Cancel"),
0, B_CANCEL, 0, 0, XV_WLAY_DONTCARE, NULL},
{quick_button, 50, CONFIRM_DLG_WIDTH, 3, CONFIRM_DLG_HEIGTH, N_ ("o&Ne"),
@ -2782,8 +2780,6 @@ int edit_save_block_cmd (WEdit * edit)
} else {
free (exp);
edit_error_dialog (_ (" Save Block "), get_sys_error (_ (" Error trying to save file. ")));
edit->force |= REDRAW_COMPLETELY;
return 0;
}
}
}
@ -2809,8 +2805,6 @@ int edit_insert_file_cmd (WEdit * edit)
} else {
free (exp);
edit_error_dialog (_ (" Insert file "), get_sys_error (_ (" Error trying to insert file. ")));
edit->force |= REDRAW_COMPLETELY;
return 0;
}
}
}
@ -2834,8 +2828,10 @@ int edit_sort_cmd (WEdit * edit)
}
edit_save_block (edit, catstrs (home_dir, BLOCK_FILE, 0), start_mark, end_mark);
exp = old ? old : "";
exp = input_dialog (_(" Run Sort "),
_(" Enter sort options (see manpage) separated by whitespace: "), "");
_(" Enter sort options (see manpage) separated by whitespace: "), exp);
if (!exp)
return 1;
@ -2922,14 +2918,13 @@ void edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block)
edit->filename, " ", home_dir, BLOCK_FILE, " ",
home_dir, ERROR_FILE, 0));
edit_refresh_cmd (edit);
} else { /* for missing marked block run ... */
my_system (0, shell, catstrs (EDIT_DIR, shell_cmd));
edit_refresh_cmd (edit);
}
edit_refresh_cmd (edit);
edit->force |= REDRAW_COMPLETELY;
/* insert result block */
if (block) {
if (stat (e, &s) == 0) {
@ -3018,12 +3013,10 @@ void edit_mail_dialog (WEdit * edit)
QuickDialog Quick_input =
{50, MAIL_DLG_HEIGHT, -1, 0, N_(" Mail "),
/* NLS ? */
"[Input Line Keys]", "quick_input", 0};
QuickWidget quick_widgets[] =
{
/* NLS ? */
{quick_button, 6, 10, 9, MAIL_DLG_HEIGHT, N_("&Cancel"), 0, B_CANCEL, 0,
0, XV_WLAY_DONTCARE, NULL},
{quick_button, 2, 10, 9, MAIL_DLG_HEIGHT, N_("&Ok"), 0, B_ENTER, 0,