1
1
Этот коммит содержится в:
Pavel Roskin 2002-12-15 02:54:00 +00:00
родитель ca658f44a6
Коммит ceb3e9eb60
2 изменённых файлов: 28 добавлений и 19 удалений

Просмотреть файл

@ -63,7 +63,7 @@ struct WEdit {
unsigned char modified; /* has the file been changed?: 1 if char inserted or
deleted at all since last load or save */
unsigned char screen_modified; /* has the file been changed since the last screen draw? */
int delete_file; /* has the file been created in edit_load_file? Delete
int delete_file; /* Has the file been created by the editor? Delete
it at end of editing when it hasn't been modified
or saved */
unsigned char highlight;

Просмотреть файл

@ -128,24 +128,24 @@ int edit_get_byte (WEdit * edit, long byte_index)
/*
The edit_open_file (previously edit_load_file) function uses
init_dynamic_edit_buffers to load a file. This is unnecessary
since you can just as well fopen the file and insert the
characters one by one. The real reason for
The edit_open_file function uses init_dynamic_edit_buffers to load
the file. This is unnecessary since you can just as well fopen the
file and insert the characters one by one. The real reason for
init_dynamic_edit_buffers (besides allocating the buffers) is
as an optimisation - it uses raw block reads and inserts large
chunks at a time. It is hence extremely fast at loading files.
Where we might not want to use it is if we were doing
CRLF->LF translation or if we were reading from a pipe.
optimization - it uses raw block reads and inserts large chunks at a
time, so it's much faster at loading files. We may not want to use
it if we are reading from pipe or doing CRLF->LF translation.
*/
/* Initialisation routines */
/* Initialization routines */
/* returns 1 on error */
/* loads file OR text into buffers. Only one must be none-NULL. */
/* cursor set to start of file */
/*
* Load file OR text into buffers. Set cursor to the beginning of file.
* Return 1 on error.
*/
static int
init_dynamic_edit_buffers (WEdit * edit, const char *filename, const char *text)
init_dynamic_edit_buffers (WEdit *edit, const char *filename,
const char *text)
{
long buf;
int j, file = -1, buf2;
@ -158,7 +158,11 @@ init_dynamic_edit_buffers (WEdit * edit, const char *filename, const char *text)
if (filename)
if ((file = mc_open (filename, O_RDONLY | O_BINARY)) == -1) {
/* The file-name is printed after the ':' */
edit_error_dialog (_ ("Error"), get_sys_error (catstrs (_ (" Cannot open file for reading: "), filename, " ", 0)));
edit_error_dialog (_("Error"),
get_sys_error (catstrs
(_
(" Cannot open file for reading: "),
filename, " ", 0)));
return 1;
}
edit->curs2 = edit->last_byte;
@ -168,9 +172,14 @@ init_dynamic_edit_buffers (WEdit * edit, const char *filename, const char *text)
edit->buffers2[buf2] = g_malloc (EDIT_BUF_SIZE);
if (filename) {
mc_read (file, (char *) edit->buffers2[buf2] + EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE), edit->curs2 & M_EDIT_BUF_SIZE);
mc_read (file,
(char *) edit->buffers2[buf2] + EDIT_BUF_SIZE -
(edit->curs2 & M_EDIT_BUF_SIZE),
edit->curs2 & M_EDIT_BUF_SIZE);
} else {
memcpy (edit->buffers2[buf2] + EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE), text, edit->curs2 & M_EDIT_BUF_SIZE);
memcpy (edit->buffers2[buf2] + EDIT_BUF_SIZE -
(edit->curs2 & M_EDIT_BUF_SIZE), text,
edit->curs2 & M_EDIT_BUF_SIZE);
text += edit->curs2 & M_EDIT_BUF_SIZE;
}
@ -507,7 +516,7 @@ edit_init (WEdit *edit, int lines, int columns, const char *filename,
use_filter = 1;
#endif
if (edit_open_file (edit, filename)) {
/* edit_load_file already gives an error message */
/* edit_open_file already gives an error message */
if (to_free)
g_free (edit);
return 0;