1
1

View now relies on sfs, few bugs killed

Этот коммит содержится в:
Pavel Machek 1998-11-02 21:47:06 +00:00
родитель 4aeaf0099f
Коммит 9989eb0202
5 изменённых файлов: 84 добавлений и 82 удалений

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

@ -1,3 +1,23 @@
Sun Nov 1 20:59:05 1998 Pavel Machek <pavel@bug.ucw.cz>
* file.c (erase_file): translated goto into while loop (it is both
shorter AND cleaner)
* subshell.c (feed_subshell): do NOT print anything if we get
errors/eofs from read(subshell) - this fixes (or at least hides)
nasty bug where typing "exit" on mc prompt prints lots of garbage
and falls into infinite loop. Someone with better knowledge should
read feed_subshell(), and make it handle errors properly. (Why do
we ignore EIO for example?)
Sun Oct 18 22:56:17 1998 Pavel Machek <pavel@bug.ucw.cz>
* view.c: we now rely on sfs to do file decompressing for us. That
has advantage of displaying #ugz at first line, so user knows what
we are doing behind his back
* view.c: fix indentation, fallback to read whole file if mmap fails.
1998-11-01 Federico Mena Quintero <federico@nuclecu.unam.mx> 1998-11-01 Federico Mena Quintero <federico@nuclecu.unam.mx>
* setup.c: #ifdef'ed out stuff in the menus that will get changed * setup.c: #ifdef'ed out stuff in the menus that will get changed

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

@ -378,8 +378,10 @@ int handle_dirent (dir_list *list, char *filter, struct dirent *dp,
} }
if (!show_backups && dp->d_name [NLENGTH (dp)-1] == '~') if (!show_backups && dp->d_name [NLENGTH (dp)-1] == '~')
return 0; return 0;
if (mc_lstat (dp->d_name, buf1) == -1) if (mc_lstat (dp->d_name, buf1) == -1) {
message(1, _(" Error "), _("File exists but can not be stat-ed: %s %s"), dp->d_name, strerror(errno));
return 0; return 0;
}
if (S_ISDIR (buf1->st_mode)) if (S_ISDIR (buf1->st_mode))
tree_check (dp->d_name); tree_check (dp->d_name);

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

@ -1667,12 +1667,10 @@ erase_file (char *s)
mc_refresh (); mc_refresh ();
retry_unlink: while (mc_unlink (s)){
if (mc_unlink (s)){
return_status = file_error (_(" Cannot delete file \"%s\" \n %s "), s); return_status = file_error (_(" Cannot delete file \"%s\" \n %s "), s);
if (return_status == FILE_RETRY) if (return_status != FILE_RETRY)
goto retry_unlink; return return_status;
return return_status;
} }
return FILE_CONT; return FILE_CONT;
} }
@ -2339,8 +2337,12 @@ panel_operate (void *source_panel, int operation, char *thedefault)
} }
#endif #endif
/* Initialize things */ /* Initialize things */
/* We turn on ETA display if the source is an ftp file system */ /* We now have ETA in all cases */
create_op_win (operation, 1); create_op_win (operation, 1);
/* We do not want to trash cache every time file is
created/touched. However, this will make our cache contain
invalid data. */
mc_setctl (dest, MCCTL_WANT_STALE_DATA, NULL);
ftpfs_hint_reread (0); ftpfs_hint_reread (0);
/* Now, let's do the job */ /* Now, let's do the job */
@ -2489,6 +2491,7 @@ panel_operate (void *source_panel, int operation, char *thedefault)
clean_up: clean_up:
/* Clean up */ /* Clean up */
destroy_op_win (); destroy_op_win ();
mc_setctl (dest, MCCTL_NO_STALE_DATA, NULL);
ftpfs_hint_reread (1); ftpfs_hint_reread (1);
free_linklist (&linklist); free_linklist (&linklist);
free_linklist (&dest_dirs); free_linklist (&dest_dirs);

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

@ -925,8 +925,9 @@ static int feed_subshell (int how, int fail_on_error)
perror ("\n"__FILE__": read (subshell_pty...)"); perror ("\n"__FILE__": read (subshell_pty...)");
exit (1); exit (1);
} }
if (how == VISIBLY) if (bytes > 0)
write (STDOUT_FILENO, pty_buffer, bytes); if (how == VISIBLY)
write (STDOUT_FILENO, pty_buffer, bytes);
} }
/* }}} */ /* }}} */

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

@ -7,6 +7,7 @@
1995 Jakub Jelinek 1995 Jakub Jelinek
1996 Joseph M. Hinkle 1996 Joseph M. Hinkle
1997 Norbert Warmuth 1997 Norbert Warmuth
1998 Pavel Machek
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -146,12 +147,11 @@ free_file (WView *view)
int i; int i;
#ifdef HAVE_MMAP #ifdef HAVE_MMAP
if (view->mmapping){ if (view->mmapping){
mc_munmap (view->data, view->s.st_size); mc_munmap (view->data, view->s.st_size);
close_view_file (view); close_view_file (view);
} else } else
#endif /* HAVE_MMAP */ #endif
{ {
if (view->reading_pipe){ if (view->reading_pipe){
/* Check error messages */ /* Check error messages */
@ -183,15 +183,13 @@ enum { off, on };
void void
view_done (WView *view) view_done (WView *view)
{ {
set_monitor (view, off); set_monitor (view, off);
#ifndef HAVE_MMAP
/* alex: release core, used to replace mmap */ /* alex: release core, used to replace mmap */
if (!view->growing_buffer && view->data != (unsigned char*)0) if (!view->mmapping && !view->growing_buffer && view->data != NULL){
{ free(view->data);
free(view->data); view->data = NULL;
view->data = NULL; }
}
#endif /* HAVE_MMAP */
if (view->view_active){ if (view->view_active){
if (view->localcopy) if (view->localcopy)
@ -245,6 +243,7 @@ get_byte (WView *view, int byte_index)
n = fread (p, 1, VIEW_PAGE_SIZE, view->stdfile); n = fread (p, 1, VIEW_PAGE_SIZE, view->stdfile);
else else
n = mc_read (view->file, p, VIEW_PAGE_SIZE); n = mc_read (view->file, p, VIEW_PAGE_SIZE);
#warning FIXME: Errors are ignored at this point, also should report preliminary EOF
if (n != -1) if (n != -1)
view->bytes_read += n; view->bytes_read += n;
if (view->s.st_size < view->bytes_read){ if (view->s.st_size < view->bytes_read){
@ -343,13 +342,11 @@ put_editkey (WView *view, unsigned char key)
if (node) { if (node) {
#ifndef HAVE_MMAP #ifndef HAVE_MMAP
/* /* alex@bcs.zaporizhzhe.ua: here we are using file copy
** alex@bcs.zaporizhzhe.ua: here we are using file copy * completely loaded into memory, so we can replace bytes in
** completely loaded into memory, so we can replace bytes * view->data array to allow changes to be reflected when
** in view->data array to allow changes to be reflected * user switches back to ascii mode */
** when user switches back to ascii mode view->data[view->edit_cursor] = byte_val;
*/
view->data[view->edit_cursor] = byte_val;
#endif /* HAVE_MMAP */ #endif /* HAVE_MMAP */
node->offset = view->edit_cursor; node->offset = view->edit_cursor;
node->value = byte_val; node->value = byte_val;
@ -437,7 +434,7 @@ set_view_init_error (WView *view, char *msg)
return 0; return 0;
} }
/* return values: 0 for success, else points to error message */ /* return values: NULL for success, else points to error message */
static char * static char *
init_growing_view (WView *view, char *name, char *filename) init_growing_view (WView *view, char *name, char *filename)
{ {
@ -468,7 +465,7 @@ init_growing_view (WView *view, char *name, char *filename)
if ((view->file = mc_open (filename, O_RDONLY)) == -1) if ((view->file = mc_open (filename, O_RDONLY)) == -1)
return set_view_init_error (view, _(" Could not open file ")); return set_view_init_error (view, _(" Could not open file "));
} }
return 0; return NULL;
} }
/* Load filename into core */ /* Load filename into core */
@ -479,15 +476,11 @@ init_growing_view (WView *view, char *name, char *filename)
*/ */
static char *load_view_file (WView *view, char *filename) static char *load_view_file (WView *view, char *filename)
{ {
char *cmd;
int type;
if ((view->file = mc_open (filename, O_RDONLY)) < 0){ if ((view->file = mc_open (filename, O_RDONLY)) < 0){
set_view_init_error (view, 0); set_view_init_error (view, 0);
return (copy_strings (_(" Can't open file \""), return (copy_strings (_(" Can't open file \""),
filename, "\"\n ", filename, "\"\n ",
unix_error_string (errno), " ", 0)); unix_error_string (errno), " ", 0));
} }
if (mc_fstat (view->file, &view->s) < 0){ if (mc_fstat (view->file, &view->s) < 0){
set_view_init_error (view, 0); set_view_init_error (view, 0);
@ -506,62 +499,36 @@ static char *load_view_file (WView *view, char *filename)
close_view_file (view); close_view_file (view);
return init_growing_view (view, 0, filename); return init_growing_view (view, 0, filename);
} }
/* First, try to open a compressed file */
if (view->viewer_magic_flag && (is_gunzipable (view->file, &type)) != 0){
close_view_file (view);
if (vfs_file_is_local (filename)) {
char *tmp = name_quote (filename, 0);
cmd = copy_strings (decompress_command (type), " ", tmp, 0);
free (tmp);
}
else {
char *tmp;
if ((view->localcopy = mc_getlocalcopy (filename)) == 0)
return set_view_init_error (view, _(" Can not fetch local copy ") );
tmp = name_quote (view->localcopy, 0);
cmd = copy_strings (decompress_command (type), " ", tmp, 0);
free (tmp);
}
return init_growing_view (view, cmd, filename);
}
/* Otherwise, the file wasn't compressed */
#ifdef HAVE_MMAP #ifdef HAVE_MMAP
view->data = mc_mmap (0, view->s.st_size, PROT_READ, MAP_FILE | MAP_SHARED, view->data = mc_mmap (0, view->s.st_size, PROT_READ, MAP_FILE | MAP_SHARED,
view->file, 0); view->file, 0);
if ((caddr_t) view->data == (caddr_t) -1){ if ((caddr_t) view->data == (caddr_t) -1)
close_view_file (view); goto no_mmap;
/* set_view_init_error (view, 0);
return copy_strings (" Can't mmap file \n ",
unix_error_string (errno), " ", 0);*/
return init_growing_view (view, 0, filename);
}
view->first = 0; view->first = 0;
view->bytes_read = view->s.st_size; view->bytes_read = view->s.st_size;
view->mmapping = 1; view->mmapping = 1;
return 0; return NULL;
#else /* ! HAVE_MMAP */ #endif
/*
** For those OS that dont provide mmap call. Try to load all the file no_mmap:
** into memory (alex@bcs.zaporizhzhe.ua) /* For those OS that dont provide mmap call. Try to load all the
*/ * file into memory (alex@bcs.zaporizhzhe.ua). Also, mmap can fail
view->data = (unsigned char*) xmalloc (view->s.st_size, "load_view_file"); * for any reason, so we use this as fallback (pavel@ucw.cz) */
if (view->data == (unsigned char*) 0
|| mc_lseek(view->file,0,0) != 0 view->data = (unsigned char*) xmalloc (view->s.st_size, "load_view_file");
|| mc_read(view->file, view->data, view->s.st_size) != view->s.st_size if (view->data == NULL
) { || mc_lseek(view->file,0,0) != 0
if (view->data != (unsigned char*)0) || mc_read(view->file, view->data, view->s.st_size) != view->s.st_size){
free(view->data); if (view->data != NULL)
close_view_file (view); free(view->data);
return init_growing_view (view, 0, filename); close_view_file (view);
return init_growing_view (view, 0, filename);
} }
view->first = 0; view->first = 0;
view->bytes_read = view->s.st_size; view->bytes_read = view->s.st_size;
return 0; return NULL;
#endif
} }
/* Return zero on success, -1 on failure */ /* Return zero on success, -1 on failure */
@ -569,7 +536,7 @@ int
do_view_init (WView *view, char *_command, char *_file, int start_line) do_view_init (WView *view, char *_command, char *_file, int start_line)
{ {
char *error = 0; char *error = 0;
int i; int i, type;
if (view->view_active) if (view->view_active)
view_done (view); view_done (view);
@ -598,10 +565,20 @@ do_view_init (WView *view, char *_command, char *_file, int start_line)
if (!view->have_frame){ if (!view->have_frame){
view->start_col = 0; view->start_col = 0;
} }
{
int fd;
fd = mc_open(_file, O_RDONLY);
if (_file[0] && view->viewer_magic_flag && (is_gunzipable (fd, &type)) != 0)
view->filename = copy_strings (_file, decompress_extension(type), NULL);
else view->filename = strdup (_file);
mc_close(fd);
}
if (_command && (view->viewer_magic_flag || _file[0] == '\0')) if (_command && (view->viewer_magic_flag || _file[0] == '\0'))
error = init_growing_view (view, _command, _file); error = init_growing_view (view, _command, view->filename);
else else
error = load_view_file (view, _file); error = load_view_file (view, view->filename);
if (error){ if (error){
if (!view->have_frame){ if (!view->have_frame){
@ -612,7 +589,6 @@ do_view_init (WView *view, char *_command, char *_file, int start_line)
} }
view->view_active = 1; view->view_active = 1;
view->filename = strdup (_file);
if (_command) if (_command)
view->command = strdup (_command); view->command = strdup (_command);
else else