1998-02-27 04:54:42 +00:00
|
|
|
/* {{{ Copyright notice */
|
|
|
|
|
|
|
|
/* View file module for the Midnight Commander
|
|
|
|
Copyright (C) 1994, 1995, 1996 The Free Software Foundation
|
1998-04-09 04:58:24 +00:00
|
|
|
Written by: 1994, 1995, 1998 Miguel de Icaza
|
1998-02-27 04:54:42 +00:00
|
|
|
1994, 1995 Janne Kukonlehto
|
|
|
|
1995 Jakub Jelinek
|
|
|
|
1996 Joseph M. Hinkle
|
|
|
|
1997 Norbert Warmuth
|
1998-11-02 21:47:06 +00:00
|
|
|
1998 Pavel Machek
|
1998-02-27 04:54:42 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2000-08-22 22:50:00 +00:00
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
1998-02-27 04:54:42 +00:00
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
/* {{{ Declarations */
|
|
|
|
#include <config.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#ifdef HAVE_MMAP
|
|
|
|
# include <sys/mman.h>
|
|
|
|
#endif
|
|
|
|
#include <ctype.h> /* For toupper() */
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
2001-08-07 16:53:55 +00:00
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
#include "global.h"
|
2001-08-07 16:53:55 +00:00
|
|
|
#include "tty.h"
|
|
|
|
#include "cmd.h" /* For view_other_cmd */
|
1998-02-27 04:54:42 +00:00
|
|
|
#include "dlg.h" /* Needed by widget.h */
|
|
|
|
#include "widget.h" /* Needed for buttonbar_new */
|
|
|
|
#include "color.h"
|
|
|
|
#include "dialog.h"
|
|
|
|
#include "mouse.h"
|
|
|
|
#include "help.h"
|
|
|
|
#include "key.h" /* For mi_getch() */
|
|
|
|
#include "layout.h"
|
1998-11-18 02:31:23 +00:00
|
|
|
#include "setup.h"
|
1998-02-27 04:54:42 +00:00
|
|
|
#include "wtools.h" /* For query_set_sel() */
|
|
|
|
#include "../vfs/vfs.h"
|
|
|
|
#include "dir.h"
|
|
|
|
#include "panel.h" /* Needed for current_panel and other_panel */
|
|
|
|
#include "win.h"
|
|
|
|
#include "main.h" /* For the externs */
|
|
|
|
#define WANT_WIDGETS
|
|
|
|
#include "view.h"
|
|
|
|
|
2001-06-05 22:49:15 +00:00
|
|
|
#ifdef HAVE_CHARSET
|
|
|
|
#include "charsets.h"
|
2001-06-25 11:24:49 +00:00
|
|
|
#include "selcodepage.h"
|
2001-09-16 01:22:12 +00:00
|
|
|
#endif /* HAVE_CHARSET */
|
2001-06-05 22:49:15 +00:00
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
#ifndef MAP_FILE
|
|
|
|
#define MAP_FILE 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Block size for reading files in parts */
|
|
|
|
#define READ_BLOCK 8192
|
|
|
|
#define VIEW_PAGE_SIZE 8192
|
|
|
|
|
|
|
|
#ifdef IS_AIX
|
|
|
|
# define IFAIX(x) case (x):
|
|
|
|
#else
|
|
|
|
# define IFAIX(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Maxlimit for skipping updates */
|
2002-08-27 19:10:54 +00:00
|
|
|
static int max_dirt_limit =
|
2002-09-10 22:04:11 +00:00
|
|
|
#ifdef NATIVE_WIN32
|
1998-02-27 04:54:42 +00:00
|
|
|
0;
|
|
|
|
#else
|
|
|
|
10;
|
|
|
|
#endif
|
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
extern Hook *idle_hook;
|
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
/* If set, show a ruler */
|
2001-06-25 11:24:49 +00:00
|
|
|
static int ruler = 0;
|
1998-02-27 04:54:42 +00:00
|
|
|
|
|
|
|
/* Scrolling is done in pages or line increments */
|
|
|
|
int mouse_move_pages_viewer = 1;
|
|
|
|
|
|
|
|
/* Used to compute the bottom first variable */
|
|
|
|
int have_fast_cpu = 0;
|
|
|
|
|
1998-03-14 00:42:23 +00:00
|
|
|
/* wrap mode default */
|
|
|
|
int global_wrap_mode = 1;
|
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
int default_hex_mode = 0;
|
2002-08-27 19:10:54 +00:00
|
|
|
static int default_hexedit_mode = 0;
|
1998-02-27 04:54:42 +00:00
|
|
|
int default_magic_flag = 1;
|
|
|
|
int default_nroff_flag = 1;
|
|
|
|
int altered_hex_mode = 0;
|
|
|
|
int altered_magic_flag = 0;
|
|
|
|
int altered_nroff_flag = 0;
|
|
|
|
/* }}} */
|
|
|
|
|
1999-12-10 16:04:35 +00:00
|
|
|
static const char hex_char[] = "0123456789ABCDEF";
|
1998-02-27 04:54:42 +00:00
|
|
|
|
2002-08-27 19:10:54 +00:00
|
|
|
/* Our callback */
|
|
|
|
static int view_callback (Dlg_head *h, WView *view, int msg, int par);
|
|
|
|
|
|
|
|
static int regexp_view_search (WView *view, char *pattern, char *string, int match_type);
|
|
|
|
static void view_move_forward (WView *view, int i);
|
|
|
|
static void view_labels (WView *view);
|
|
|
|
static void set_monitor (WView *view, int set_on);
|
|
|
|
static void view_update (WView *view, gboolean update_gui);
|
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ Clean-up functions */
|
|
|
|
|
1998-12-02 21:27:27 +00:00
|
|
|
static void
|
1998-02-27 04:54:42 +00:00
|
|
|
close_view_file (WView *view)
|
|
|
|
{
|
|
|
|
if (view->file != -1){
|
|
|
|
mc_close (view->file);
|
|
|
|
view->file = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-02 21:27:27 +00:00
|
|
|
static void
|
1998-02-27 04:54:42 +00:00
|
|
|
free_file (WView *view)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
#ifdef HAVE_MMAP
|
|
|
|
if (view->mmapping){
|
|
|
|
mc_munmap (view->data, view->s.st_size);
|
|
|
|
close_view_file (view);
|
|
|
|
} else
|
2001-09-16 01:22:12 +00:00
|
|
|
#endif /* HAVE_MMAP */
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
|
|
|
if (view->reading_pipe){
|
|
|
|
/* Check error messages */
|
|
|
|
if (!view->have_frame)
|
|
|
|
check_error_pipe ();
|
|
|
|
|
|
|
|
/* Close pipe */
|
|
|
|
pclose (view->stdfile);
|
|
|
|
view->stdfile = NULL;
|
|
|
|
|
|
|
|
/* Ignore errors because we don't want to hear about broken pipe */
|
|
|
|
close_error_pipe (-1, NULL);
|
|
|
|
} else
|
|
|
|
close_view_file (view);
|
|
|
|
}
|
|
|
|
/* Block_ptr may be zero if the file was a file with 0 bytes */
|
|
|
|
if (view->growing_buffer && view->block_ptr){
|
|
|
|
for (i = 0; i < view->blocks; i++){
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
g_free (view->block_ptr [i].data);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
g_free (view->block_ptr);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-03-26 06:05:44 +00:00
|
|
|
/* Valid parameters for second parameter to set_monitor */
|
|
|
|
enum { off, on };
|
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
/* Both views */
|
1998-12-02 21:27:27 +00:00
|
|
|
static void
|
1998-02-27 04:54:42 +00:00
|
|
|
view_done (WView *view)
|
|
|
|
{
|
1998-11-02 21:47:06 +00:00
|
|
|
set_monitor (view, off);
|
|
|
|
|
|
|
|
/* alex: release core, used to replace mmap */
|
|
|
|
if (!view->mmapping && !view->growing_buffer && view->data != NULL){
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
g_free (view->data);
|
1998-11-02 21:47:06 +00:00
|
|
|
view->data = NULL;
|
|
|
|
}
|
1998-02-27 04:54:42 +00:00
|
|
|
|
|
|
|
if (view->view_active){
|
|
|
|
if (view->localcopy)
|
|
|
|
mc_ungetlocalcopy (view->filename, view->localcopy, 0);
|
|
|
|
free_file (view);
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
g_free (view->filename);
|
1998-02-27 04:54:42 +00:00
|
|
|
if (view->command)
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
g_free (view->command);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
view->view_active = 0;
|
|
|
|
default_hex_mode = view->hex_mode;
|
|
|
|
default_nroff_flag = view->viewer_nroff_flag;
|
|
|
|
default_magic_flag = view->viewer_magic_flag;
|
1998-06-08 00:27:27 +00:00
|
|
|
global_wrap_mode = view->wrap_mode;
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void view_hook (void *);
|
|
|
|
|
1998-12-02 21:27:27 +00:00
|
|
|
static void
|
1998-02-27 04:54:42 +00:00
|
|
|
view_destroy (WView *view)
|
|
|
|
{
|
|
|
|
view_done (view);
|
|
|
|
if (view->have_frame)
|
|
|
|
delete_hook (&select_file_hook, view_hook);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1999-04-16 23:28:50 +00:00
|
|
|
get_byte (WView *view, unsigned int byte_index)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
|
|
|
int page = byte_index / VIEW_PAGE_SIZE + 1;
|
|
|
|
int offset = byte_index % VIEW_PAGE_SIZE;
|
|
|
|
int i, n;
|
2001-04-24 21:28:17 +00:00
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
if (view->growing_buffer){
|
|
|
|
if (page > view->blocks){
|
2001-04-24 21:28:17 +00:00
|
|
|
view->block_ptr = g_realloc (view->block_ptr,
|
|
|
|
sizeof (block_ptr_t) * page);
|
1998-02-27 04:54:42 +00:00
|
|
|
for (i = view->blocks; i < page; i++){
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
char *p = g_malloc (VIEW_PAGE_SIZE);
|
1998-02-27 04:54:42 +00:00
|
|
|
view->block_ptr [i].data = p;
|
|
|
|
if (!p)
|
|
|
|
return '\n';
|
|
|
|
if (view->stdfile != NULL)
|
|
|
|
n = fread (p, 1, VIEW_PAGE_SIZE, view->stdfile);
|
|
|
|
else
|
|
|
|
n = mc_read (view->file, p, VIEW_PAGE_SIZE);
|
1999-12-22 04:04:23 +00:00
|
|
|
/*
|
|
|
|
* FIXME: Errors are ignored at this point
|
|
|
|
* Also should report preliminary EOF
|
|
|
|
*/
|
1998-02-27 04:54:42 +00:00
|
|
|
if (n != -1)
|
|
|
|
view->bytes_read += n;
|
|
|
|
if (view->s.st_size < view->bytes_read){
|
|
|
|
view->bottom_first = -1; /* Invalidate cache */
|
|
|
|
view->s.st_size = view->bytes_read;
|
|
|
|
view->last_byte = view->bytes_read;
|
|
|
|
if (view->reading_pipe)
|
|
|
|
view->last_byte = view->first + view->bytes_read;
|
|
|
|
}
|
|
|
|
/* To force loading the next page */
|
|
|
|
if (n == VIEW_PAGE_SIZE && view->reading_pipe){
|
|
|
|
view->last_byte++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
view->blocks = page;
|
|
|
|
}
|
|
|
|
if (byte_index > view->bytes_read){
|
|
|
|
return -1;
|
|
|
|
} else
|
|
|
|
return view->block_ptr [page-1].data [offset];
|
|
|
|
} else {
|
|
|
|
if (byte_index >= view->last_byte)
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return view->data [byte_index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
enqueue_change (struct hexedit_change_node **head, struct hexedit_change_node *node)
|
|
|
|
{
|
|
|
|
struct hexedit_change_node *curr = *head;
|
|
|
|
|
|
|
|
while (curr) {
|
|
|
|
if (node->offset < curr->offset) {
|
|
|
|
*head = node;
|
|
|
|
node->next = curr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
head = (struct hexedit_change_node **) curr;
|
|
|
|
curr = curr->next;
|
|
|
|
}
|
|
|
|
*head = node;
|
|
|
|
node->next = curr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void move_right (WView *);
|
|
|
|
|
|
|
|
static void
|
|
|
|
put_editkey (WView *view, unsigned char key)
|
|
|
|
{
|
|
|
|
struct hexedit_change_node *node;
|
|
|
|
unsigned char byte_val;
|
|
|
|
|
|
|
|
if (!view->hexedit_mode || view->growing_buffer != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Has there been a change at this position ? */
|
|
|
|
node = view->change_list;
|
2000-04-18 08:58:42 +00:00
|
|
|
while (node && (node->offset != view->edit_cursor)) {
|
|
|
|
node = node->next;
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (view->view_side == view_side_left) {
|
|
|
|
/* Hex editing */
|
|
|
|
|
|
|
|
if (key >= '0' && key <= '9')
|
|
|
|
key -= '0';
|
|
|
|
else if (key >= 'A' && key <= 'F')
|
|
|
|
key -= '7';
|
|
|
|
else if (key >= 'a' && key <= 'f')
|
|
|
|
key -= 'W';
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (node)
|
|
|
|
byte_val = node->value;
|
|
|
|
else
|
|
|
|
byte_val = get_byte(view, view->edit_cursor);
|
|
|
|
|
|
|
|
if (view->nib_shift == 0) {
|
|
|
|
byte_val = (byte_val & 0x0f) | (key << 4);
|
|
|
|
} else {
|
|
|
|
byte_val = (byte_val & 0xf0) | (key);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Text editing */
|
|
|
|
byte_val = key;
|
|
|
|
}
|
|
|
|
if (!node) {
|
|
|
|
node = (struct hexedit_change_node *)
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
g_new (struct hexedit_change_node, 1);
|
1998-02-27 04:54:42 +00:00
|
|
|
|
|
|
|
if (node) {
|
|
|
|
#ifndef HAVE_MMAP
|
1998-11-02 21:47:06 +00:00
|
|
|
/* alex@bcs.zaporizhzhe.ua: here we are using file copy
|
|
|
|
* completely loaded into memory, so we can replace bytes in
|
|
|
|
* view->data array to allow changes to be reflected when
|
|
|
|
* user switches back to ascii mode */
|
|
|
|
view->data[view->edit_cursor] = byte_val;
|
2001-09-16 01:22:12 +00:00
|
|
|
#endif /* !HAVE_MMAP */
|
1998-02-27 04:54:42 +00:00
|
|
|
node->offset = view->edit_cursor;
|
|
|
|
node->value = byte_val;
|
|
|
|
enqueue_change (&view->change_list, node);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
node->value = byte_val;
|
|
|
|
}
|
|
|
|
view->dirty++;
|
1999-02-26 07:26:40 +00:00
|
|
|
view_update (view, TRUE);
|
1998-02-27 04:54:42 +00:00
|
|
|
move_right (view);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_change_list (WView *view)
|
|
|
|
{
|
|
|
|
struct hexedit_change_node *n = view->change_list;
|
|
|
|
|
|
|
|
while (n) {
|
|
|
|
view->change_list = n->next;
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
g_free (n);
|
1998-02-27 04:54:42 +00:00
|
|
|
n = view->change_list;
|
|
|
|
}
|
|
|
|
view->file_dirty = 0;
|
|
|
|
view->dirty++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
save_edit_changes (WView *view)
|
|
|
|
{
|
|
|
|
struct hexedit_change_node *node = view->change_list;
|
|
|
|
int fp;
|
2002-05-27 16:20:35 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
fp = open (view->filename, O_WRONLY);
|
|
|
|
if (fp >= 0) {
|
|
|
|
while (node) {
|
|
|
|
if (lseek (fp, node->offset, SEEK_SET) == -1 ||
|
|
|
|
write (fp, &node->value, 1) != 1) {
|
|
|
|
close (fp);
|
|
|
|
fp = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
node = node->next;
|
|
|
|
}
|
|
|
|
close (fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fp == -1) {
|
2002-05-30 13:12:56 +00:00
|
|
|
fp = query_dialog (_(" Save file "),
|
|
|
|
_(" Error trying to save file. "),
|
|
|
|
2, 2, _("&Retry"), _("&Cancel"));
|
2002-05-27 16:20:35 +00:00
|
|
|
if (fp == 0)
|
|
|
|
fp = -1;
|
|
|
|
}
|
|
|
|
} while (fp == -1);
|
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
free_change_list (view);
|
|
|
|
}
|
|
|
|
|
2002-08-27 19:10:54 +00:00
|
|
|
static int
|
1998-02-27 04:54:42 +00:00
|
|
|
view_ok_to_quit (WView *view)
|
|
|
|
{
|
|
|
|
int r;
|
2002-10-17 05:33:10 +00:00
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
if (!view->change_list)
|
|
|
|
return 1;
|
2002-10-17 05:33:10 +00:00
|
|
|
|
|
|
|
r = query_dialog (_(" Quit "),
|
|
|
|
_(" File was modified, Save with exit? "), 2, 3,
|
|
|
|
_("Cancel quit"), _("&Yes"), _("&No"));
|
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
switch (r) {
|
2002-10-17 05:33:10 +00:00
|
|
|
case 1:
|
1998-02-27 04:54:42 +00:00
|
|
|
save_edit_changes (view);
|
|
|
|
return 1;
|
2002-10-17 05:33:10 +00:00
|
|
|
case 2:
|
1998-02-27 04:54:42 +00:00
|
|
|
free_change_list (view);
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
set_view_init_error (WView *view, char *msg)
|
|
|
|
{
|
|
|
|
view->growing_buffer = 0;
|
|
|
|
view->reading_pipe = 0;
|
|
|
|
view->first = 0;
|
|
|
|
view->last_byte = 0;
|
|
|
|
if (msg){
|
|
|
|
view->bytes_read = strlen (msg);
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
return g_strdup (msg);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-11-02 21:47:06 +00:00
|
|
|
/* return values: NULL for success, else points to error message */
|
1998-02-27 04:54:42 +00:00
|
|
|
static char *
|
2002-09-08 15:22:28 +00:00
|
|
|
init_growing_view (WView * view, char *name, char *filename)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
2002-09-08 15:22:28 +00:00
|
|
|
char *err_msg = NULL;
|
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
view->growing_buffer = 1;
|
|
|
|
|
2002-09-08 15:22:28 +00:00
|
|
|
if (name) {
|
1998-02-27 04:54:42 +00:00
|
|
|
view->reading_pipe = 1;
|
|
|
|
view->s.st_size = 0;
|
|
|
|
|
|
|
|
open_error_pipe ();
|
2002-09-08 15:22:28 +00:00
|
|
|
if ((view->stdfile = popen (name, "r")) == NULL) {
|
|
|
|
/* Avoid two messages. Message from stderr has priority. */
|
|
|
|
if (!close_error_pipe (view->have_frame ? -1 : 1, view->data))
|
|
|
|
err_msg = _(" Cannot spawn child program ");
|
|
|
|
return set_view_init_error (view, err_msg);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* First, check if filter produced any output */
|
|
|
|
get_byte (view, 0);
|
2002-09-08 15:22:28 +00:00
|
|
|
if (view->bytes_read <= 0) {
|
1998-02-27 04:54:42 +00:00
|
|
|
pclose (view->stdfile);
|
|
|
|
view->stdfile = NULL;
|
2002-09-08 15:22:28 +00:00
|
|
|
/* Avoid two messages. Message from stderr has priority. */
|
|
|
|
if (!close_error_pipe (view->have_frame ? -1 : 1, view->data))
|
|
|
|
err_msg = (" Empty output from child filter ");
|
|
|
|
return set_view_init_error (view, err_msg);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
2002-09-08 15:22:28 +00:00
|
|
|
view->stdfile = NULL;
|
2001-10-18 08:39:41 +00:00
|
|
|
if ((view->file = mc_open (filename, O_RDONLY)) == -1)
|
|
|
|
return set_view_init_error (view, _(" Could not open file "));
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
1998-11-02 21:47:06 +00:00
|
|
|
return NULL;
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Load filename into core */
|
|
|
|
/* returns:
|
|
|
|
-1 on failure.
|
|
|
|
if (have_frame), we return success, but data points to a
|
|
|
|
error message instead of the file buffer (quick_view feature).
|
|
|
|
*/
|
2001-10-18 06:23:02 +00:00
|
|
|
static char *load_view_file (WView *view, int fd)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
2001-10-18 06:23:02 +00:00
|
|
|
view->file = fd;
|
1998-02-27 04:54:42 +00:00
|
|
|
|
|
|
|
if (view->s.st_size == 0){
|
|
|
|
/* Must be one of those nice files that grow (/proc) */
|
|
|
|
close_view_file (view);
|
2001-10-18 08:39:41 +00:00
|
|
|
return init_growing_view (view, 0, view->filename);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_MMAP
|
|
|
|
view->data = mc_mmap (0, view->s.st_size, PROT_READ, MAP_FILE | MAP_SHARED,
|
|
|
|
view->file, 0);
|
2001-08-20 07:46:04 +00:00
|
|
|
if ((caddr_t) view->data != (caddr_t) -1) {
|
|
|
|
/* mmap worked */
|
|
|
|
view->first = 0;
|
|
|
|
view->bytes_read = view->s.st_size;
|
|
|
|
view->mmapping = 1;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_MMAP */
|
1998-11-02 21:47:06 +00:00
|
|
|
|
|
|
|
/* For those OS that dont provide mmap call. Try to load all the
|
|
|
|
* file into memory (alex@bcs.zaporizhzhe.ua). Also, mmap can fail
|
|
|
|
* for any reason, so we use this as fallback (pavel@ucw.cz) */
|
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
view->data = (unsigned char*) g_malloc (view->s.st_size);
|
1998-11-02 21:47:06 +00:00
|
|
|
if (view->data == NULL
|
2002-07-29 21:18:51 +00:00
|
|
|
|| mc_lseek(view->file, 0, SEEK_SET) != 0
|
1998-11-02 21:47:06 +00:00
|
|
|
|| mc_read(view->file, view->data, view->s.st_size) != view->s.st_size){
|
|
|
|
if (view->data != NULL)
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
g_free (view->data);
|
1998-11-02 21:47:06 +00:00
|
|
|
close_view_file (view);
|
2001-10-18 08:39:41 +00:00
|
|
|
return init_growing_view (view, 0, view->filename);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
view->first = 0;
|
|
|
|
view->bytes_read = view->s.st_size;
|
1998-11-02 21:47:06 +00:00
|
|
|
return NULL;
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return zero on success, -1 on failure */
|
1998-12-02 21:27:27 +00:00
|
|
|
static int
|
2000-04-18 08:58:42 +00:00
|
|
|
do_view_init (WView *view, char *_command, const char *_file, int start_line)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
|
|
|
char *error = 0;
|
1998-11-02 21:47:06 +00:00
|
|
|
int i, type;
|
2001-11-14 20:15:36 +00:00
|
|
|
int fd = -1;
|
2001-10-18 06:23:02 +00:00
|
|
|
char tmp[BUF_MEDIUM];
|
1998-02-27 04:54:42 +00:00
|
|
|
|
|
|
|
if (view->view_active)
|
|
|
|
view_done (view);
|
|
|
|
|
|
|
|
/* Set up the state */
|
|
|
|
view->block_ptr = 0;
|
|
|
|
view->data = NULL;
|
|
|
|
view->growing_buffer = 0;
|
|
|
|
view->reading_pipe = 0;
|
|
|
|
view->mmapping = 0;
|
|
|
|
view->blocks = 0;
|
|
|
|
view->block_ptr = 0;
|
|
|
|
view->first = view->bytes_read = 0;
|
|
|
|
view->last_byte = 0;
|
2001-10-18 06:23:02 +00:00
|
|
|
view->filename = g_strdup (_file);
|
1998-02-27 04:54:42 +00:00
|
|
|
view->localcopy = 0;
|
|
|
|
view->command = 0;
|
|
|
|
view->last = view->first + ((LINES-2) * view->bytes_per_line);
|
|
|
|
|
|
|
|
/* Clear the markers */
|
|
|
|
view->marker = 0;
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
view->marks [i] = 0;
|
|
|
|
|
|
|
|
if (!view->have_frame){
|
|
|
|
view->start_col = 0;
|
|
|
|
}
|
1998-11-02 21:47:06 +00:00
|
|
|
|
2002-05-27 16:20:35 +00:00
|
|
|
if (_command && (view->viewer_magic_flag || _file[0] == '\0')) {
|
|
|
|
error = init_growing_view (view, _command, view->filename);
|
|
|
|
} else if (_file[0]) {
|
2001-11-14 20:15:36 +00:00
|
|
|
/* Make sure we are working with a regular file */
|
|
|
|
if (mc_stat (view->filename, &view->s) == -1) {
|
|
|
|
g_snprintf (tmp, sizeof (tmp), _(" Cannot stat \"%s\"\n %s "),
|
|
|
|
_file, unix_error_string (errno));
|
|
|
|
error = set_view_init_error (view, tmp);
|
|
|
|
goto finish;
|
|
|
|
}
|
2001-10-18 06:23:02 +00:00
|
|
|
|
2001-11-14 20:15:36 +00:00
|
|
|
if (!S_ISREG (view->s.st_mode)) {
|
|
|
|
g_snprintf (tmp, sizeof (tmp),
|
|
|
|
_(" Cannot view: not a regular file "));
|
|
|
|
error = set_view_init_error (view, tmp);
|
|
|
|
goto finish;
|
|
|
|
}
|
1999-04-16 05:53:46 +00:00
|
|
|
|
2001-11-14 20:15:36 +00:00
|
|
|
/* Actually open the file */
|
|
|
|
if ((fd = mc_open(_file, O_RDONLY)) == -1) {
|
|
|
|
g_snprintf (tmp, sizeof (tmp), _(" Cannot open \"%s\"\n %s "),
|
|
|
|
_file, unix_error_string (errno));
|
|
|
|
error = set_view_init_error (view, tmp);
|
|
|
|
goto finish;
|
|
|
|
}
|
2001-10-18 06:23:02 +00:00
|
|
|
|
2002-07-02 21:09:25 +00:00
|
|
|
type = get_compression_type (fd);
|
|
|
|
|
|
|
|
if (view->viewer_magic_flag && (type != COMPRESSION_NONE)) {
|
2001-11-14 20:15:36 +00:00
|
|
|
g_free (view->filename);
|
|
|
|
view->filename = g_strconcat (_file, decompress_extension(type), NULL);
|
|
|
|
}
|
1998-11-02 21:47:06 +00:00
|
|
|
|
2001-10-18 06:23:02 +00:00
|
|
|
error = load_view_file (view, fd);
|
2002-05-27 16:20:35 +00:00
|
|
|
}
|
1998-02-27 04:54:42 +00:00
|
|
|
|
1999-06-22 10:29:29 +00:00
|
|
|
finish:
|
1998-02-27 04:54:42 +00:00
|
|
|
if (error){
|
|
|
|
if (!view->have_frame){
|
2001-05-14 19:01:20 +00:00
|
|
|
message (1, MSG_ERROR, "%s", error);
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
g_free (error);
|
1998-02-27 04:54:42 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
view->view_active = 1;
|
|
|
|
if (_command)
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
view->command = g_strdup (_command);
|
1998-02-27 04:54:42 +00:00
|
|
|
else
|
|
|
|
view->command = 0;
|
|
|
|
view->search_start = view->start_display = view->start_save = view->first;
|
|
|
|
view->found_len = 0;
|
|
|
|
view->start_col = 0;
|
|
|
|
view->last_search = 0; /* Start a new search */
|
|
|
|
|
|
|
|
/* Special case: The data points to the error message */
|
|
|
|
if (error){
|
|
|
|
view->data = error;
|
1999-06-22 10:29:29 +00:00
|
|
|
view->file = -1;
|
1998-02-27 04:54:42 +00:00
|
|
|
view->s.st_size = view->bytes_read = strlen (view->data);
|
|
|
|
}
|
|
|
|
view->last_byte = view->first + view->s.st_size;
|
|
|
|
|
|
|
|
if (start_line > 1 && !error){
|
I improved the movement keys of the internal viewer a little bit.
Now in wrap mode the End key and cursor up key behave much better
(e.g. when viewing binary files with lots of wrapped lines).
It's not perfekt but it's better than it used to be.
Tue Apr 28 06:52:24 1998 Norbert Warmuth <k3190@fh-sw.de>
* gnome/gcmd.c (gnome_open_terminal): Changed my_system(1,...) to
my_system(EXECUTE_AS_SHELL,...)
Tue Apr 28 06:06:03 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/extfs.c (extfs_open, extfs_close): Changed my_system(1,...)
to my_system(EXECUTE_AS_SHELL,...), this fixes the broken copyin and
copyout in 4.1.32.
Tue Apr 28 06:11:08 1998 Norbert Warmuth <k3190@fh-sw.de>
* view.c (toggle_wrap_mode, toggle_hex_mode): Force recalculation
of bottom_first (we mustn't use an already calculated and cached
value because it is invalid for the new mode and the End key would
not move to the end of the file).
* configure.in: Renamed the option `--with-our-slang' to
`--with-included-slang' (this one looks better because we also
have an `--with-included-gettext').
Make the option `--with-ext2undel' recognice a given path.
* cmd.c (view_file_at_line): In plain view (F13) set the default
magic flag to zero in order to view the file content unprocessed
(esp. don't uncompress files if they are compressed). The
view_simple_cmd got broken when the default magic flag in view.c
was changed from 0 to 1.
* view.c (do_view_init, goto_line): Set wrap mode temporary off
to make goto line number work, i.e. `line number' now always means
line number in file and not line number on screen (in wrap mode
one long line wrapped once is displayed in two lines on the screen).
That's important when the viewer is invoked from the find file
dialog to display even in wrap mode approxiamtly the part of the
file where we found the content we searched for.
(move_forward2): In wrap mode lines were sometimes counted wrong
causing cursor up to move more than one line.
(move_backward2): Fixed the movement in wrap mode.
(change_viewer): Always re-init viewer when we have a filename,
i. e. if the viewer is invoked with simple_view_cmd then we can switch
with the F8 key between unprocessed file content und uncompressed
file content.
(view_init): re-init view also when magic flag was altered
1998-04-28 14:19:48 +00:00
|
|
|
int saved_wrap_mode = view->wrap_mode;
|
|
|
|
|
|
|
|
view->wrap_mode = 0;
|
1998-02-27 04:54:42 +00:00
|
|
|
get_byte (view, 0);
|
1998-04-16 02:45:53 +00:00
|
|
|
view_move_forward (view, start_line - 1);
|
I improved the movement keys of the internal viewer a little bit.
Now in wrap mode the End key and cursor up key behave much better
(e.g. when viewing binary files with lots of wrapped lines).
It's not perfekt but it's better than it used to be.
Tue Apr 28 06:52:24 1998 Norbert Warmuth <k3190@fh-sw.de>
* gnome/gcmd.c (gnome_open_terminal): Changed my_system(1,...) to
my_system(EXECUTE_AS_SHELL,...)
Tue Apr 28 06:06:03 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/extfs.c (extfs_open, extfs_close): Changed my_system(1,...)
to my_system(EXECUTE_AS_SHELL,...), this fixes the broken copyin and
copyout in 4.1.32.
Tue Apr 28 06:11:08 1998 Norbert Warmuth <k3190@fh-sw.de>
* view.c (toggle_wrap_mode, toggle_hex_mode): Force recalculation
of bottom_first (we mustn't use an already calculated and cached
value because it is invalid for the new mode and the End key would
not move to the end of the file).
* configure.in: Renamed the option `--with-our-slang' to
`--with-included-slang' (this one looks better because we also
have an `--with-included-gettext').
Make the option `--with-ext2undel' recognice a given path.
* cmd.c (view_file_at_line): In plain view (F13) set the default
magic flag to zero in order to view the file content unprocessed
(esp. don't uncompress files if they are compressed). The
view_simple_cmd got broken when the default magic flag in view.c
was changed from 0 to 1.
* view.c (do_view_init, goto_line): Set wrap mode temporary off
to make goto line number work, i.e. `line number' now always means
line number in file and not line number on screen (in wrap mode
one long line wrapped once is displayed in two lines on the screen).
That's important when the viewer is invoked from the find file
dialog to display even in wrap mode approxiamtly the part of the
file where we found the content we searched for.
(move_forward2): In wrap mode lines were sometimes counted wrong
causing cursor up to move more than one line.
(move_backward2): Fixed the movement in wrap mode.
(change_viewer): Always re-init viewer when we have a filename,
i. e. if the viewer is invoked with simple_view_cmd then we can switch
with the F8 key between unprocessed file content und uncompressed
file content.
(view_init): re-init view also when magic flag was altered
1998-04-28 14:19:48 +00:00
|
|
|
view->wrap_mode = saved_wrap_mode;
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
view->edit_cursor = view->first;
|
|
|
|
view->file_dirty = 0;
|
|
|
|
view->nib_shift = 0;
|
|
|
|
view->view_side = view_side_left;
|
|
|
|
view->change_list = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-04-06 19:00:16 +00:00
|
|
|
void
|
2002-10-07 18:09:50 +00:00
|
|
|
view_update_bytes_per_line (WView *view)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
|
|
|
int cols;
|
|
|
|
|
|
|
|
if (view->have_frame)
|
|
|
|
cols = view->widget.cols - 2;
|
|
|
|
else
|
|
|
|
cols = view->widget.cols;
|
2000-11-20 17:25:43 +00:00
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
view->bottom_first = -1;
|
2002-10-07 18:09:50 +00:00
|
|
|
if (cols < 80)
|
|
|
|
view->bytes_per_line = ((cols - 8) / 17) * 4;
|
|
|
|
else
|
|
|
|
view->bytes_per_line = ((cols - 8) / 18) * 4;
|
|
|
|
|
1999-04-06 19:00:16 +00:00
|
|
|
if (view->bytes_per_line == 0)
|
2002-10-07 18:09:50 +00:00
|
|
|
view->bytes_per_line++; /* To avoid division by 0 */
|
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
view->dirty = max_dirt_limit + 1; /* To force refresh */
|
1999-04-06 19:00:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Both views */
|
|
|
|
/* Return zero on success, -1 on failure */
|
|
|
|
int
|
2000-04-18 08:58:42 +00:00
|
|
|
view_init (WView *view, char *_command, const char *_file, int start_line)
|
1999-04-06 19:00:16 +00:00
|
|
|
{
|
I improved the movement keys of the internal viewer a little bit.
Now in wrap mode the End key and cursor up key behave much better
(e.g. when viewing binary files with lots of wrapped lines).
It's not perfekt but it's better than it used to be.
Tue Apr 28 06:52:24 1998 Norbert Warmuth <k3190@fh-sw.de>
* gnome/gcmd.c (gnome_open_terminal): Changed my_system(1,...) to
my_system(EXECUTE_AS_SHELL,...)
Tue Apr 28 06:06:03 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/extfs.c (extfs_open, extfs_close): Changed my_system(1,...)
to my_system(EXECUTE_AS_SHELL,...), this fixes the broken copyin and
copyout in 4.1.32.
Tue Apr 28 06:11:08 1998 Norbert Warmuth <k3190@fh-sw.de>
* view.c (toggle_wrap_mode, toggle_hex_mode): Force recalculation
of bottom_first (we mustn't use an already calculated and cached
value because it is invalid for the new mode and the End key would
not move to the end of the file).
* configure.in: Renamed the option `--with-our-slang' to
`--with-included-slang' (this one looks better because we also
have an `--with-included-gettext').
Make the option `--with-ext2undel' recognice a given path.
* cmd.c (view_file_at_line): In plain view (F13) set the default
magic flag to zero in order to view the file content unprocessed
(esp. don't uncompress files if they are compressed). The
view_simple_cmd got broken when the default magic flag in view.c
was changed from 0 to 1.
* view.c (do_view_init, goto_line): Set wrap mode temporary off
to make goto line number work, i.e. `line number' now always means
line number in file and not line number on screen (in wrap mode
one long line wrapped once is displayed in two lines on the screen).
That's important when the viewer is invoked from the find file
dialog to display even in wrap mode approxiamtly the part of the
file where we found the content we searched for.
(move_forward2): In wrap mode lines were sometimes counted wrong
causing cursor up to move more than one line.
(move_backward2): Fixed the movement in wrap mode.
(change_viewer): Always re-init viewer when we have a filename,
i. e. if the viewer is invoked with simple_view_cmd then we can switch
with the F8 key between unprocessed file content und uncompressed
file content.
(view_init): re-init view also when magic flag was altered
1998-04-28 14:19:48 +00:00
|
|
|
if (!view->view_active || strcmp (_file, view->filename) || altered_magic_flag)
|
1998-02-27 04:54:42 +00:00
|
|
|
return do_view_init (view, _command, _file, start_line);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ Screen update functions */
|
|
|
|
|
2002-08-27 19:10:54 +00:00
|
|
|
static void
|
1999-02-26 07:26:40 +00:00
|
|
|
view_percent (WView *view, int p, int w, gboolean update_gui)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
|
|
|
int percent;
|
|
|
|
|
|
|
|
percent = (view->s.st_size == 0 || view->last_byte == view->last) ? 100 :
|
|
|
|
(p > (INT_MAX/100) ?
|
|
|
|
p / (view->s.st_size / 100) :
|
|
|
|
p * 100 / view->s.st_size);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
percent = view->s.st_size == 0 ? 100 :
|
|
|
|
(view->last_byte == view->last ? 100 :
|
|
|
|
(p)*100 / view->s.st_size);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
widget_move (view, view->have_frame, w - 5);
|
1999-04-06 19:00:16 +00:00
|
|
|
printw ("%3d%%", percent);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
2002-08-27 19:10:54 +00:00
|
|
|
static void
|
1999-02-26 07:26:40 +00:00
|
|
|
view_status (WView *view, gboolean update_gui)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
1999-04-06 19:00:16 +00:00
|
|
|
static int i18n_adjust=0;
|
|
|
|
static char *file_label;
|
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
int w = view->widget.cols - (view->have_frame * 2);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
attrset (SELECTED_COLOR);
|
|
|
|
widget_move (view, view->have_frame, view->have_frame);
|
|
|
|
hline (' ', w);
|
1999-04-06 19:00:16 +00:00
|
|
|
|
|
|
|
if (!i18n_adjust) {
|
|
|
|
file_label = _("File: %s");
|
|
|
|
i18n_adjust = strlen(file_label) - 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (w < i18n_adjust + 6)
|
2001-06-25 11:24:49 +00:00
|
|
|
addstr (name_trunc (view->filename ? view->filename:
|
|
|
|
view->command ? view->command:"", w));
|
1999-04-06 19:00:16 +00:00
|
|
|
else{
|
|
|
|
i = (w > 22 ? 22 : w ) - i18n_adjust ;
|
|
|
|
printw (file_label, name_trunc (view->filename ? view->filename:
|
1998-02-27 04:54:42 +00:00
|
|
|
view->command ? view->command:"", i));
|
1999-04-06 19:00:16 +00:00
|
|
|
if (w > 46){
|
|
|
|
widget_move (view, view->have_frame, 24 + view->have_frame );
|
1998-02-27 04:54:42 +00:00
|
|
|
if (view->hex_mode)
|
1998-03-25 05:16:00 +00:00
|
|
|
printw (_("Offset 0x%08x"), view->edit_cursor);
|
1998-02-27 04:54:42 +00:00
|
|
|
else
|
1998-03-25 05:16:00 +00:00
|
|
|
printw (_("Col %d"), -view->start_col);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
1999-04-06 19:00:16 +00:00
|
|
|
if (w > 62){
|
|
|
|
widget_move (view, view->have_frame, 43 + view->have_frame);
|
1998-03-25 05:16:00 +00:00
|
|
|
printw (_("%s bytes"), size_trunc (view->s.st_size));
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
if (w > 70){
|
|
|
|
printw (" ");
|
|
|
|
if (view->growing_buffer)
|
1998-03-25 05:16:00 +00:00
|
|
|
addstr (_(" [grow]"));
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
1999-05-03 18:57:48 +00:00
|
|
|
if (w > 26) {
|
2000-11-20 17:25:43 +00:00
|
|
|
view_percent (view,
|
|
|
|
view->hex_mode ? view->edit_cursor : view->start_display,
|
|
|
|
view->widget.cols - view->have_frame + 1,
|
|
|
|
update_gui);
|
1999-05-03 18:57:48 +00:00
|
|
|
}
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
attrset (SELECTED_COLOR);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
1998-03-12 03:29:45 +00:00
|
|
|
view_display_clean (WView *view, int height, int width)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
|
|
|
/* FIXME: Should I use widget_erase only and repaint the box? */
|
|
|
|
if (view->have_frame){
|
|
|
|
int i;
|
|
|
|
|
|
|
|
draw_double_box (view->widget.parent, view->widget.y, view->widget.x,
|
|
|
|
view->widget.lines, view->widget.cols);
|
|
|
|
for (i = 1; i < height; i++){
|
|
|
|
widget_move (view, i, 1);
|
|
|
|
printw ("%*s", width-1, "");
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
widget_erase ((Widget *) view);
|
|
|
|
}
|
|
|
|
|
1998-03-12 03:29:45 +00:00
|
|
|
#define view_add_character(view,c) addch (c)
|
1998-12-02 05:18:20 +00:00
|
|
|
#define view_add_one_vline() one_vline()
|
1998-03-12 03:29:45 +00:00
|
|
|
#define view_add_string(view,s) addstr (s)
|
|
|
|
#define view_gotoyx(v,r,c) widget_move (v,r,c)
|
|
|
|
|
2001-09-16 01:10:09 +00:00
|
|
|
#define view_freeze(view)
|
|
|
|
#define view_thaw(view)
|
1998-02-27 04:54:42 +00:00
|
|
|
|
2001-09-16 01:10:09 +00:00
|
|
|
#define STATUS_LINES 1
|
1998-03-14 00:42:23 +00:00
|
|
|
|
2002-08-18 20:18:04 +00:00
|
|
|
typedef enum {
|
|
|
|
MARK_NORMAL = 0,
|
|
|
|
MARK_SELECTED = 1,
|
|
|
|
MARK_CURSOR = 2,
|
|
|
|
MARK_CHANGED = 3
|
|
|
|
} mark_t;
|
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
/* Shows the file pointed to by *start_display on view_win */
|
|
|
|
static long
|
2002-10-07 18:09:50 +00:00
|
|
|
display (WView *view)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
|
|
|
const int frame_shift = view->have_frame;
|
|
|
|
int col = 0 + frame_shift;
|
1998-03-12 03:29:45 +00:00
|
|
|
int row = STATUS_LINES + frame_shift;
|
1998-02-27 04:54:42 +00:00
|
|
|
int height, width;
|
1999-04-16 23:28:50 +00:00
|
|
|
unsigned long from;
|
1998-02-27 04:54:42 +00:00
|
|
|
int c;
|
2002-08-18 20:18:04 +00:00
|
|
|
mark_t boldflag = MARK_NORMAL;
|
1998-02-27 04:54:42 +00:00
|
|
|
struct hexedit_change_node *curr = view->change_list;
|
2002-07-26 17:17:41 +00:00
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
height = view->widget.lines - frame_shift;
|
|
|
|
width = view->widget.cols - frame_shift;
|
|
|
|
from = view->start_display;
|
2002-08-14 07:41:01 +00:00
|
|
|
attrset (NORMAL_COLOR);
|
1998-02-27 04:54:42 +00:00
|
|
|
|
1998-03-12 03:29:45 +00:00
|
|
|
view_freeze (view);
|
|
|
|
view_display_clean (view, height, width);
|
1998-02-27 04:54:42 +00:00
|
|
|
|
|
|
|
/* Optionally, display a ruler */
|
2002-07-26 17:17:41 +00:00
|
|
|
if ((!view->hex_mode) && (ruler)) {
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
char r_buff[10];
|
1998-02-27 04:54:42 +00:00
|
|
|
int cl;
|
2002-07-26 17:17:41 +00:00
|
|
|
|
2002-08-14 07:41:01 +00:00
|
|
|
attrset (MARKED_COLOR);
|
1998-02-27 04:54:42 +00:00
|
|
|
for (c = frame_shift; c < width; c++) {
|
2002-07-26 17:17:41 +00:00
|
|
|
cl = c - view->start_col;
|
1998-02-27 04:54:42 +00:00
|
|
|
if (ruler == 1)
|
|
|
|
view_gotoyx (view, row, c);
|
|
|
|
else
|
2002-07-26 17:17:41 +00:00
|
|
|
view_gotoyx (view, row + height - 2, c);
|
1998-02-27 04:54:42 +00:00
|
|
|
r_buff[0] = '-';
|
|
|
|
if ((cl % 10) == 0)
|
2002-07-26 17:17:41 +00:00
|
|
|
r_buff[0] = '|';
|
|
|
|
else if ((cl % 5) == 0)
|
|
|
|
r_buff[0] = '*';
|
1998-03-12 03:29:45 +00:00
|
|
|
view_add_character (view, r_buff[0]);
|
2002-07-26 17:17:41 +00:00
|
|
|
if ((cl != 0) && (cl % 10) == 0) {
|
|
|
|
g_snprintf (r_buff, sizeof (r_buff), "%03d", cl);
|
2001-06-15 00:24:14 +00:00
|
|
|
if (ruler == 1) {
|
1998-02-27 04:54:42 +00:00
|
|
|
widget_move (view, row + 1, c - 1);
|
2001-06-15 00:24:14 +00:00
|
|
|
} else {
|
1998-02-27 04:54:42 +00:00
|
|
|
widget_move (view, row + height - 3, c - 1);
|
2001-06-15 00:24:14 +00:00
|
|
|
}
|
2002-07-26 17:17:41 +00:00
|
|
|
view_add_string (view, r_buff);
|
|
|
|
}
|
|
|
|
}
|
2002-08-14 07:41:01 +00:00
|
|
|
attrset (NORMAL_COLOR);
|
2002-07-26 17:17:41 +00:00
|
|
|
if (ruler == 1)
|
1998-02-27 04:54:42 +00:00
|
|
|
row += 2;
|
|
|
|
else
|
2002-07-26 17:17:41 +00:00
|
|
|
height -= 2;
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
2000-11-20 17:25:43 +00:00
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
/* Find the first displayable changed byte */
|
2000-11-20 17:25:43 +00:00
|
|
|
while (curr && (curr->offset < from)) {
|
2002-07-26 17:17:41 +00:00
|
|
|
curr = curr->next;
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
2002-07-26 17:17:41 +00:00
|
|
|
if (view->hex_mode) {
|
|
|
|
char hex_buff[10]; /* A temporary buffer for sprintf and mvwaddstr */
|
|
|
|
int bytes; /* Number of bytes already printed on the line */
|
2000-11-20 17:25:43 +00:00
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
/* Start of text column */
|
2002-07-26 17:17:41 +00:00
|
|
|
int text_start = width - view->bytes_per_line - 1 + frame_shift;
|
1999-06-22 10:29:29 +00:00
|
|
|
|
2002-07-26 17:17:41 +00:00
|
|
|
for (; row < height && from < view->last_byte; row++) {
|
|
|
|
/* Print the hex offset */
|
2002-08-14 07:41:01 +00:00
|
|
|
attrset (MARKED_COLOR);
|
2002-07-26 17:17:41 +00:00
|
|
|
g_snprintf (hex_buff, sizeof (hex_buff), "%08X",
|
|
|
|
(int) (from - view->first));
|
1999-06-22 10:29:29 +00:00
|
|
|
view_gotoyx (view, row, frame_shift);
|
2002-07-26 17:17:41 +00:00
|
|
|
view_add_string (view, hex_buff);
|
2002-08-14 07:41:01 +00:00
|
|
|
attrset (NORMAL_COLOR);
|
2002-07-26 17:17:41 +00:00
|
|
|
|
|
|
|
/* Hex dump starts from column nine */
|
2002-10-07 18:09:50 +00:00
|
|
|
if (view->have_frame)
|
|
|
|
col = 10;
|
|
|
|
else
|
|
|
|
col = 9;
|
2002-07-26 17:17:41 +00:00
|
|
|
|
|
|
|
/* Each hex number is two digits */
|
|
|
|
hex_buff[2] = 0;
|
|
|
|
for (bytes = 0;
|
|
|
|
bytes < view->bytes_per_line && from < view->last_byte;
|
|
|
|
bytes++, from++) {
|
|
|
|
/* Display and mark changed bytes */
|
|
|
|
if (curr && from == curr->offset) {
|
|
|
|
c = curr->value;
|
|
|
|
curr = curr->next;
|
2002-08-18 20:18:04 +00:00
|
|
|
boldflag = MARK_CHANGED;
|
2002-08-14 07:41:01 +00:00
|
|
|
attrset (VIEW_UNDERLINED_COLOR);
|
2002-07-26 17:17:41 +00:00
|
|
|
} else
|
|
|
|
c = (unsigned char) get_byte (view, from);
|
|
|
|
|
|
|
|
if (view->found_len && from >= view->search_start
|
|
|
|
&& from < view->search_start + view->found_len) {
|
2002-08-18 20:18:04 +00:00
|
|
|
boldflag = MARK_SELECTED;
|
2002-08-14 07:41:01 +00:00
|
|
|
attrset (MARKED_COLOR);
|
2002-07-26 17:17:41 +00:00
|
|
|
}
|
|
|
|
/* Display the navigation cursor */
|
|
|
|
if (from == view->edit_cursor) {
|
|
|
|
if (view->view_side == view_side_left) {
|
1998-02-27 04:54:42 +00:00
|
|
|
view->cursor_row = row;
|
|
|
|
view->cursor_col = col;
|
|
|
|
}
|
2002-08-18 20:18:04 +00:00
|
|
|
boldflag = MARK_CURSOR;
|
2002-08-14 07:41:01 +00:00
|
|
|
attrset (view->view_side ==
|
|
|
|
view_side_left ? VIEW_UNDERLINED_COLOR :
|
|
|
|
MARKED_SELECTED_COLOR);
|
2002-07-26 17:17:41 +00:00
|
|
|
}
|
1998-02-27 04:54:42 +00:00
|
|
|
|
2002-07-26 17:17:41 +00:00
|
|
|
/* Print a hex number (sprintf is too slow) */
|
|
|
|
hex_buff[0] = hex_char[(c >> 4)];
|
|
|
|
hex_buff[1] = hex_char[c & 15];
|
1998-02-27 04:54:42 +00:00
|
|
|
view_gotoyx (view, row, col);
|
2002-07-26 17:17:41 +00:00
|
|
|
view_add_string (view, hex_buff);
|
|
|
|
col += 3;
|
|
|
|
/* Turn off the cursor or changed byte highlighting here */
|
2002-08-18 20:18:04 +00:00
|
|
|
if (boldflag == MARK_CURSOR || boldflag == MARK_CHANGED)
|
2002-08-14 07:41:01 +00:00
|
|
|
attrset (NORMAL_COLOR);
|
2002-07-26 17:17:41 +00:00
|
|
|
if ((bytes & 3) == 3 && bytes + 1 < view->bytes_per_line) {
|
|
|
|
/* Turn off the search highlighting */
|
2002-08-18 20:18:04 +00:00
|
|
|
if (boldflag == MARK_SELECTED
|
2002-07-26 17:17:41 +00:00
|
|
|
&& from ==
|
|
|
|
view->search_start + view->found_len - 1)
|
2002-08-14 07:41:01 +00:00
|
|
|
attrset (NORMAL_COLOR);
|
2002-07-26 17:17:41 +00:00
|
|
|
|
|
|
|
/* Hex numbers are printed in the groups of four */
|
|
|
|
/* Groups are separated by a vline */
|
|
|
|
|
|
|
|
view_gotoyx (view, row, col - 1);
|
|
|
|
view_add_character (view, ' ');
|
|
|
|
view_gotoyx (view, row, col);
|
2002-10-07 18:09:50 +00:00
|
|
|
if ((view->have_frame && view->widget.cols < 82) ||
|
|
|
|
view->widget.cols < 80)
|
|
|
|
col += 1;
|
|
|
|
else {
|
|
|
|
view_add_one_vline ();
|
|
|
|
col += 2;
|
|
|
|
}
|
2002-07-26 17:17:41 +00:00
|
|
|
|
2002-08-18 20:18:04 +00:00
|
|
|
if (boldflag != MARK_NORMAL
|
2002-07-26 17:17:41 +00:00
|
|
|
&& from ==
|
|
|
|
view->search_start + view->found_len - 1)
|
2002-08-14 07:41:01 +00:00
|
|
|
attrset (MARKED_COLOR);
|
2002-07-26 17:17:41 +00:00
|
|
|
|
|
|
|
}
|
2002-08-18 20:18:04 +00:00
|
|
|
if (boldflag != MARK_NORMAL
|
2002-07-26 17:17:41 +00:00
|
|
|
&& from < view->search_start + view->found_len - 1
|
|
|
|
&& bytes != view->bytes_per_line - 1) {
|
|
|
|
view_gotoyx (view, row, col);
|
|
|
|
view_add_character (view, ' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print the corresponding ascii character */
|
1998-02-27 04:54:42 +00:00
|
|
|
view_gotoyx (view, row, text_start + bytes);
|
2002-07-26 17:17:41 +00:00
|
|
|
|
2001-06-05 22:49:15 +00:00
|
|
|
#ifdef HAVE_CHARSET
|
2002-07-26 17:17:41 +00:00
|
|
|
c = conv_displ[c];
|
2001-06-05 22:49:15 +00:00
|
|
|
#endif
|
|
|
|
|
2002-07-26 17:17:41 +00:00
|
|
|
if (!is_printable (c))
|
|
|
|
c = '.';
|
|
|
|
switch (boldflag) {
|
2002-08-18 20:18:04 +00:00
|
|
|
case MARK_NORMAL:
|
2002-07-26 17:17:41 +00:00
|
|
|
break;
|
2002-08-18 20:18:04 +00:00
|
|
|
case MARK_SELECTED:
|
2002-08-14 07:41:01 +00:00
|
|
|
attrset (MARKED_COLOR);
|
2002-08-18 20:18:04 +00:00
|
|
|
break;
|
|
|
|
case MARK_CURSOR:
|
2002-07-26 17:17:41 +00:00
|
|
|
if (view->view_side == view_side_right) {
|
2002-08-18 20:18:04 +00:00
|
|
|
/* Our side is active */
|
1998-02-27 04:54:42 +00:00
|
|
|
view->cursor_col = text_start + bytes;
|
|
|
|
view->cursor_row = row;
|
2002-08-18 20:18:04 +00:00
|
|
|
attrset (VIEW_UNDERLINED_COLOR);
|
|
|
|
} else {
|
|
|
|
/* Other side is active */
|
|
|
|
attrset (MARKED_SELECTED_COLOR);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
2002-08-18 20:18:04 +00:00
|
|
|
break;
|
|
|
|
case MARK_CHANGED:
|
|
|
|
attrset (VIEW_UNDERLINED_COLOR);
|
|
|
|
break;
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
1998-03-12 03:29:45 +00:00
|
|
|
view_add_character (view, c);
|
2002-07-26 17:17:41 +00:00
|
|
|
|
2002-08-18 20:18:04 +00:00
|
|
|
if (boldflag != MARK_NORMAL) {
|
|
|
|
boldflag = MARK_NORMAL;
|
2002-08-14 07:41:01 +00:00
|
|
|
attrset (NORMAL_COLOR);
|
2002-07-26 17:17:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-02-27 04:54:42 +00:00
|
|
|
} else {
|
2002-07-26 17:17:41 +00:00
|
|
|
if (view->growing_buffer && from == view->last_byte)
|
|
|
|
get_byte (view, from);
|
|
|
|
for (; row < height && from < view->last_byte; from++) {
|
1998-02-27 04:54:42 +00:00
|
|
|
c = get_byte (view, from);
|
2002-09-24 04:20:16 +00:00
|
|
|
if ((c == '\n') || (col >= width && view->wrap_mode)) {
|
2002-07-26 17:17:41 +00:00
|
|
|
col = frame_shift;
|
|
|
|
row++;
|
1998-02-27 04:54:42 +00:00
|
|
|
if (c == '\n' || row >= height)
|
|
|
|
continue;
|
2002-07-26 17:17:41 +00:00
|
|
|
}
|
1998-02-27 04:54:42 +00:00
|
|
|
if (c == '\r')
|
|
|
|
continue;
|
2002-07-26 17:17:41 +00:00
|
|
|
if (c == '\t') {
|
|
|
|
col = ((col - frame_shift) / 8) * 8 + 8 + frame_shift;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (view->viewer_nroff_flag && c == '\b') {
|
|
|
|
int c_prev;
|
|
|
|
int c_next;
|
|
|
|
|
|
|
|
if (from + 1 < view->last_byte
|
|
|
|
&& is_printable ((c_next = get_byte (view, from + 1)))
|
|
|
|
&& from > view->first
|
|
|
|
&& is_printable ((c_prev = get_byte (view, from - 1)))
|
|
|
|
&& (c_prev == c_next || c_prev == '_')) {
|
|
|
|
if (col <= frame_shift) {
|
|
|
|
/* So it has to be wrap_mode - do not need to check for it */
|
|
|
|
if (row == 1 + frame_shift) {
|
|
|
|
from++;
|
|
|
|
continue; /* There had to be a bold character on the rightmost position
|
|
|
|
of the previous undisplayed line */
|
|
|
|
}
|
|
|
|
row--;
|
|
|
|
col = width;
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
col--;
|
2002-08-18 20:18:04 +00:00
|
|
|
boldflag = MARK_SELECTED;
|
2002-07-26 17:17:41 +00:00
|
|
|
if (c_prev == '_' && c_next != '_')
|
2002-08-14 07:41:01 +00:00
|
|
|
attrset (VIEW_UNDERLINED_COLOR);
|
1998-02-27 04:54:42 +00:00
|
|
|
else
|
2002-08-14 07:41:01 +00:00
|
|
|
attrset (MARKED_COLOR);
|
1998-02-27 04:54:42 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (view->found_len && from >= view->search_start
|
2002-07-26 17:17:41 +00:00
|
|
|
&& from < view->search_start + view->found_len) {
|
2002-08-18 20:18:04 +00:00
|
|
|
boldflag = MARK_SELECTED;
|
2002-08-14 07:41:01 +00:00
|
|
|
attrset (SELECTED_COLOR);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
2002-07-26 17:17:41 +00:00
|
|
|
if (col >= frame_shift - view->start_col
|
|
|
|
&& col < width - view->start_col) {
|
|
|
|
view_gotoyx (view, row, col + view->start_col);
|
2001-06-05 22:49:15 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CHARSET
|
2002-07-26 17:17:41 +00:00
|
|
|
c = conv_displ[c];
|
2001-06-05 22:49:15 +00:00
|
|
|
#endif
|
|
|
|
|
2002-07-26 17:17:41 +00:00
|
|
|
if (!is_printable (c))
|
1998-02-27 04:54:42 +00:00
|
|
|
c = '.';
|
|
|
|
|
1998-03-12 03:29:45 +00:00
|
|
|
view_add_character (view, c);
|
2002-07-26 17:17:41 +00:00
|
|
|
}
|
1998-02-27 04:54:42 +00:00
|
|
|
col++;
|
2002-08-18 20:18:04 +00:00
|
|
|
if (boldflag != MARK_NORMAL) {
|
|
|
|
boldflag = MARK_NORMAL;
|
2002-08-14 07:41:01 +00:00
|
|
|
attrset (NORMAL_COLOR);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Very last thing */
|
2002-07-26 17:17:41 +00:00
|
|
|
if (view->growing_buffer && from + 1 == view->last_byte)
|
|
|
|
get_byte (view, from + 1);
|
|
|
|
}
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
view->last = from;
|
1998-03-12 03:29:45 +00:00
|
|
|
view_thaw (view);
|
1998-02-27 04:54:42 +00:00
|
|
|
return from;
|
|
|
|
}
|
|
|
|
|
1998-12-02 21:27:27 +00:00
|
|
|
static void
|
1998-02-27 04:54:42 +00:00
|
|
|
view_place_cursor (WView *view)
|
|
|
|
{
|
|
|
|
int shift;
|
|
|
|
|
|
|
|
if (view->view_side == view_side_left)
|
|
|
|
shift = view->nib_shift;
|
|
|
|
else
|
|
|
|
shift = 0;
|
|
|
|
|
|
|
|
widget_move (&view->widget, view->cursor_row, view->cursor_col + shift);
|
|
|
|
}
|
|
|
|
|
2002-08-27 19:10:54 +00:00
|
|
|
static void
|
1999-02-26 07:26:40 +00:00
|
|
|
view_update (WView *view, gboolean update_gui)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
|
|
|
static int dirt_limit = 1;
|
|
|
|
|
|
|
|
if (view->dirty > dirt_limit){
|
|
|
|
/* Too many updates skipped -> force a update */
|
|
|
|
display (view);
|
1999-02-26 07:26:40 +00:00
|
|
|
view_status (view, update_gui);
|
1998-02-27 04:54:42 +00:00
|
|
|
view->dirty = 0;
|
|
|
|
/* Raise the update skipping limit */
|
|
|
|
dirt_limit++;
|
|
|
|
if (dirt_limit > max_dirt_limit)
|
|
|
|
dirt_limit = max_dirt_limit;
|
|
|
|
}
|
|
|
|
if (view->dirty){
|
|
|
|
if (is_idle ()){
|
|
|
|
/* We have time to update the screen properly */
|
|
|
|
display (view);
|
1999-02-26 07:26:40 +00:00
|
|
|
view_status (view, update_gui);
|
1998-02-27 04:54:42 +00:00
|
|
|
view->dirty = 0;
|
|
|
|
if (dirt_limit > 1)
|
|
|
|
dirt_limit--;
|
|
|
|
} else {
|
|
|
|
/* We are busy -> skipping full update,
|
|
|
|
only the status line is updated */
|
1999-02-26 07:26:40 +00:00
|
|
|
view_status (view, update_gui);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
/* Here we had a refresh, if fast scrolling does not work
|
|
|
|
restore the refresh, although this should not happen */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
my_define (Dlg_head *h, int idx, char *text,
|
|
|
|
void (*fn)(WView *), WView *view)
|
|
|
|
{
|
|
|
|
define_label_data (h, (Widget *) view, idx, text, (buttonbarfn) fn, view);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
/* {{{ Movement functions */
|
|
|
|
/* If the last parameter is nonzero, it means we want get the count of lines
|
|
|
|
from current up to the the upto position inclusive */
|
|
|
|
static long
|
|
|
|
move_forward2 (WView *view, long current, int lines, long upto)
|
|
|
|
{
|
1999-04-16 23:28:50 +00:00
|
|
|
unsigned long q, p;
|
1998-02-27 04:54:42 +00:00
|
|
|
int line;
|
|
|
|
int col = 0;
|
|
|
|
|
|
|
|
if (view->hex_mode){
|
|
|
|
p = current + lines * view->bytes_per_line;
|
|
|
|
p = (p >= view->last_byte) ? current : p;
|
|
|
|
if (lines == 1) {
|
|
|
|
q = view->edit_cursor + view->bytes_per_line;
|
|
|
|
line = q / view->bytes_per_line;
|
|
|
|
col = (view->last_byte-1) / view->bytes_per_line;
|
|
|
|
view->edit_cursor = (line > col) ? view->edit_cursor : q;
|
|
|
|
view->edit_cursor = (view->edit_cursor < view->last_byte) ?
|
|
|
|
view->edit_cursor : view->last_byte-1;
|
|
|
|
q = current + ((LINES-2) * view->bytes_per_line);
|
|
|
|
p = (view->edit_cursor < q) ? current : p;
|
|
|
|
} else {
|
|
|
|
view->edit_cursor = (view->edit_cursor < p) ?
|
|
|
|
p : view->edit_cursor;
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
} else {
|
|
|
|
if (upto){
|
|
|
|
lines = -1;
|
|
|
|
q = upto;
|
|
|
|
} else
|
|
|
|
q = view->last_byte;
|
I improved the movement keys of the internal viewer a little bit.
Now in wrap mode the End key and cursor up key behave much better
(e.g. when viewing binary files with lots of wrapped lines).
It's not perfekt but it's better than it used to be.
Tue Apr 28 06:52:24 1998 Norbert Warmuth <k3190@fh-sw.de>
* gnome/gcmd.c (gnome_open_terminal): Changed my_system(1,...) to
my_system(EXECUTE_AS_SHELL,...)
Tue Apr 28 06:06:03 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/extfs.c (extfs_open, extfs_close): Changed my_system(1,...)
to my_system(EXECUTE_AS_SHELL,...), this fixes the broken copyin and
copyout in 4.1.32.
Tue Apr 28 06:11:08 1998 Norbert Warmuth <k3190@fh-sw.de>
* view.c (toggle_wrap_mode, toggle_hex_mode): Force recalculation
of bottom_first (we mustn't use an already calculated and cached
value because it is invalid for the new mode and the End key would
not move to the end of the file).
* configure.in: Renamed the option `--with-our-slang' to
`--with-included-slang' (this one looks better because we also
have an `--with-included-gettext').
Make the option `--with-ext2undel' recognice a given path.
* cmd.c (view_file_at_line): In plain view (F13) set the default
magic flag to zero in order to view the file content unprocessed
(esp. don't uncompress files if they are compressed). The
view_simple_cmd got broken when the default magic flag in view.c
was changed from 0 to 1.
* view.c (do_view_init, goto_line): Set wrap mode temporary off
to make goto line number work, i.e. `line number' now always means
line number in file and not line number on screen (in wrap mode
one long line wrapped once is displayed in two lines on the screen).
That's important when the viewer is invoked from the find file
dialog to display even in wrap mode approxiamtly the part of the
file where we found the content we searched for.
(move_forward2): In wrap mode lines were sometimes counted wrong
causing cursor up to move more than one line.
(move_backward2): Fixed the movement in wrap mode.
(change_viewer): Always re-init viewer when we have a filename,
i. e. if the viewer is invoked with simple_view_cmd then we can switch
with the F8 key between unprocessed file content und uncompressed
file content.
(view_init): re-init view also when magic flag was altered
1998-04-28 14:19:48 +00:00
|
|
|
if (get_byte (view, q) != '\n')
|
|
|
|
q++;
|
1998-02-27 04:54:42 +00:00
|
|
|
for (line = col = 0, p = current; p < q; p++){
|
|
|
|
int c;
|
|
|
|
|
|
|
|
if (lines != -1 && line >= lines)
|
|
|
|
return p;
|
|
|
|
|
|
|
|
c = get_byte (view, p);
|
|
|
|
|
1998-03-14 00:42:23 +00:00
|
|
|
if (view->wrap_mode){
|
1998-02-27 04:54:42 +00:00
|
|
|
if (c == '\r')
|
|
|
|
continue; /* This characters is never displayed */
|
|
|
|
else if (c == '\t')
|
|
|
|
col = ((col - view->have_frame)/8)*8 +8+ view->have_frame;
|
|
|
|
else
|
|
|
|
col++;
|
|
|
|
if (view->viewer_nroff_flag && c == '\b'){
|
|
|
|
if (p + 1 < view->last_byte
|
|
|
|
&& is_printable (get_byte (view, p + 1))
|
|
|
|
&& p > view->first
|
|
|
|
&& is_printable (get_byte (view, p - 1)))
|
|
|
|
col -= 2;
|
|
|
|
} else if (col == vwidth){
|
|
|
|
/* FIXME: the c in is_printable was a p, that is a bug,
|
|
|
|
I suspect I got that fix from Jakub, same applies
|
|
|
|
for d. */
|
|
|
|
int d = get_byte (view, p+2);
|
|
|
|
|
|
|
|
if (p + 2 >= view->last_byte || !is_printable (c) ||
|
|
|
|
!view->viewer_nroff_flag || get_byte (view, p + 1) != '\b' ||
|
|
|
|
!is_printable (d)){
|
|
|
|
col = 0;
|
|
|
|
|
|
|
|
if (c == '\n' || get_byte (view, p+1) != '\n')
|
|
|
|
line++;
|
|
|
|
}
|
|
|
|
} else if (c == '\n'){
|
|
|
|
line++;
|
|
|
|
col = 0;
|
|
|
|
}
|
|
|
|
} else if (c == '\n')
|
|
|
|
line++;
|
|
|
|
}
|
|
|
|
if (upto)
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
return current;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns the new current pointer */
|
|
|
|
/* Cause even the forward routine became very complex, we in the wrap_mode
|
|
|
|
just find the nearest '\n', use move_forward2(p, 0, q) to get the count
|
|
|
|
of lines up to there and then use move_forward2(p, something, 0), which we
|
|
|
|
return */
|
|
|
|
static long
|
1999-04-16 23:28:50 +00:00
|
|
|
move_backward2 (WView *view, unsigned long current, int lines)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
I improved the movement keys of the internal viewer a little bit.
Now in wrap mode the End key and cursor up key behave much better
(e.g. when viewing binary files with lots of wrapped lines).
It's not perfekt but it's better than it used to be.
Tue Apr 28 06:52:24 1998 Norbert Warmuth <k3190@fh-sw.de>
* gnome/gcmd.c (gnome_open_terminal): Changed my_system(1,...) to
my_system(EXECUTE_AS_SHELL,...)
Tue Apr 28 06:06:03 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/extfs.c (extfs_open, extfs_close): Changed my_system(1,...)
to my_system(EXECUTE_AS_SHELL,...), this fixes the broken copyin and
copyout in 4.1.32.
Tue Apr 28 06:11:08 1998 Norbert Warmuth <k3190@fh-sw.de>
* view.c (toggle_wrap_mode, toggle_hex_mode): Force recalculation
of bottom_first (we mustn't use an already calculated and cached
value because it is invalid for the new mode and the End key would
not move to the end of the file).
* configure.in: Renamed the option `--with-our-slang' to
`--with-included-slang' (this one looks better because we also
have an `--with-included-gettext').
Make the option `--with-ext2undel' recognice a given path.
* cmd.c (view_file_at_line): In plain view (F13) set the default
magic flag to zero in order to view the file content unprocessed
(esp. don't uncompress files if they are compressed). The
view_simple_cmd got broken when the default magic flag in view.c
was changed from 0 to 1.
* view.c (do_view_init, goto_line): Set wrap mode temporary off
to make goto line number work, i.e. `line number' now always means
line number in file and not line number on screen (in wrap mode
one long line wrapped once is displayed in two lines on the screen).
That's important when the viewer is invoked from the find file
dialog to display even in wrap mode approxiamtly the part of the
file where we found the content we searched for.
(move_forward2): In wrap mode lines were sometimes counted wrong
causing cursor up to move more than one line.
(move_backward2): Fixed the movement in wrap mode.
(change_viewer): Always re-init viewer when we have a filename,
i. e. if the viewer is invoked with simple_view_cmd then we can switch
with the F8 key between unprocessed file content und uncompressed
file content.
(view_init): re-init view also when magic flag was altered
1998-04-28 14:19:48 +00:00
|
|
|
long p, q, pm;
|
1998-02-27 04:54:42 +00:00
|
|
|
int line;
|
|
|
|
|
|
|
|
if (!view->hex_mode && current == view->first)
|
|
|
|
return current;
|
|
|
|
|
|
|
|
if (view->hex_mode){
|
|
|
|
p = current - lines * view->bytes_per_line;
|
|
|
|
p = (p < view->first) ? view->first : p;
|
|
|
|
if (lines == 1) {
|
|
|
|
q = view->edit_cursor - view->bytes_per_line;
|
|
|
|
view->edit_cursor = (q < view->first) ? view->edit_cursor : q;
|
|
|
|
p = (view->edit_cursor >= current) ? current : p;
|
|
|
|
} else {
|
|
|
|
q = p + ((LINES-2) * view->bytes_per_line);
|
|
|
|
view->edit_cursor = (view->edit_cursor >= q) ?
|
|
|
|
p : view->edit_cursor;
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
} else {
|
|
|
|
if (current == view->last_byte
|
|
|
|
&& get_byte (view, current - 1) != '\n')
|
|
|
|
/* There is one virtual '\n' at the end,
|
|
|
|
so that the last line is shown */
|
|
|
|
line = 1;
|
|
|
|
else
|
|
|
|
line = 0;
|
I improved the movement keys of the internal viewer a little bit.
Now in wrap mode the End key and cursor up key behave much better
(e.g. when viewing binary files with lots of wrapped lines).
It's not perfekt but it's better than it used to be.
Tue Apr 28 06:52:24 1998 Norbert Warmuth <k3190@fh-sw.de>
* gnome/gcmd.c (gnome_open_terminal): Changed my_system(1,...) to
my_system(EXECUTE_AS_SHELL,...)
Tue Apr 28 06:06:03 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/extfs.c (extfs_open, extfs_close): Changed my_system(1,...)
to my_system(EXECUTE_AS_SHELL,...), this fixes the broken copyin and
copyout in 4.1.32.
Tue Apr 28 06:11:08 1998 Norbert Warmuth <k3190@fh-sw.de>
* view.c (toggle_wrap_mode, toggle_hex_mode): Force recalculation
of bottom_first (we mustn't use an already calculated and cached
value because it is invalid for the new mode and the End key would
not move to the end of the file).
* configure.in: Renamed the option `--with-our-slang' to
`--with-included-slang' (this one looks better because we also
have an `--with-included-gettext').
Make the option `--with-ext2undel' recognice a given path.
* cmd.c (view_file_at_line): In plain view (F13) set the default
magic flag to zero in order to view the file content unprocessed
(esp. don't uncompress files if they are compressed). The
view_simple_cmd got broken when the default magic flag in view.c
was changed from 0 to 1.
* view.c (do_view_init, goto_line): Set wrap mode temporary off
to make goto line number work, i.e. `line number' now always means
line number in file and not line number on screen (in wrap mode
one long line wrapped once is displayed in two lines on the screen).
That's important when the viewer is invoked from the find file
dialog to display even in wrap mode approxiamtly the part of the
file where we found the content we searched for.
(move_forward2): In wrap mode lines were sometimes counted wrong
causing cursor up to move more than one line.
(move_backward2): Fixed the movement in wrap mode.
(change_viewer): Always re-init viewer when we have a filename,
i. e. if the viewer is invoked with simple_view_cmd then we can switch
with the F8 key between unprocessed file content und uncompressed
file content.
(view_init): re-init view also when magic flag was altered
1998-04-28 14:19:48 +00:00
|
|
|
for (q = p = current - 1; p >= view->first; p--)
|
|
|
|
if (get_byte (view, p) == '\n' || p == view->first) {
|
|
|
|
pm = p > view->first ? p + 1 : view->first;
|
1998-03-14 00:42:23 +00:00
|
|
|
if (!view->wrap_mode){
|
1998-02-27 04:54:42 +00:00
|
|
|
if (line == lines)
|
I improved the movement keys of the internal viewer a little bit.
Now in wrap mode the End key and cursor up key behave much better
(e.g. when viewing binary files with lots of wrapped lines).
It's not perfekt but it's better than it used to be.
Tue Apr 28 06:52:24 1998 Norbert Warmuth <k3190@fh-sw.de>
* gnome/gcmd.c (gnome_open_terminal): Changed my_system(1,...) to
my_system(EXECUTE_AS_SHELL,...)
Tue Apr 28 06:06:03 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/extfs.c (extfs_open, extfs_close): Changed my_system(1,...)
to my_system(EXECUTE_AS_SHELL,...), this fixes the broken copyin and
copyout in 4.1.32.
Tue Apr 28 06:11:08 1998 Norbert Warmuth <k3190@fh-sw.de>
* view.c (toggle_wrap_mode, toggle_hex_mode): Force recalculation
of bottom_first (we mustn't use an already calculated and cached
value because it is invalid for the new mode and the End key would
not move to the end of the file).
* configure.in: Renamed the option `--with-our-slang' to
`--with-included-slang' (this one looks better because we also
have an `--with-included-gettext').
Make the option `--with-ext2undel' recognice a given path.
* cmd.c (view_file_at_line): In plain view (F13) set the default
magic flag to zero in order to view the file content unprocessed
(esp. don't uncompress files if they are compressed). The
view_simple_cmd got broken when the default magic flag in view.c
was changed from 0 to 1.
* view.c (do_view_init, goto_line): Set wrap mode temporary off
to make goto line number work, i.e. `line number' now always means
line number in file and not line number on screen (in wrap mode
one long line wrapped once is displayed in two lines on the screen).
That's important when the viewer is invoked from the find file
dialog to display even in wrap mode approxiamtly the part of the
file where we found the content we searched for.
(move_forward2): In wrap mode lines were sometimes counted wrong
causing cursor up to move more than one line.
(move_backward2): Fixed the movement in wrap mode.
(change_viewer): Always re-init viewer when we have a filename,
i. e. if the viewer is invoked with simple_view_cmd then we can switch
with the F8 key between unprocessed file content und uncompressed
file content.
(view_init): re-init view also when magic flag was altered
1998-04-28 14:19:48 +00:00
|
|
|
return pm;
|
1998-02-27 04:54:42 +00:00
|
|
|
line++;
|
|
|
|
} else {
|
I improved the movement keys of the internal viewer a little bit.
Now in wrap mode the End key and cursor up key behave much better
(e.g. when viewing binary files with lots of wrapped lines).
It's not perfekt but it's better than it used to be.
Tue Apr 28 06:52:24 1998 Norbert Warmuth <k3190@fh-sw.de>
* gnome/gcmd.c (gnome_open_terminal): Changed my_system(1,...) to
my_system(EXECUTE_AS_SHELL,...)
Tue Apr 28 06:06:03 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/extfs.c (extfs_open, extfs_close): Changed my_system(1,...)
to my_system(EXECUTE_AS_SHELL,...), this fixes the broken copyin and
copyout in 4.1.32.
Tue Apr 28 06:11:08 1998 Norbert Warmuth <k3190@fh-sw.de>
* view.c (toggle_wrap_mode, toggle_hex_mode): Force recalculation
of bottom_first (we mustn't use an already calculated and cached
value because it is invalid for the new mode and the End key would
not move to the end of the file).
* configure.in: Renamed the option `--with-our-slang' to
`--with-included-slang' (this one looks better because we also
have an `--with-included-gettext').
Make the option `--with-ext2undel' recognice a given path.
* cmd.c (view_file_at_line): In plain view (F13) set the default
magic flag to zero in order to view the file content unprocessed
(esp. don't uncompress files if they are compressed). The
view_simple_cmd got broken when the default magic flag in view.c
was changed from 0 to 1.
* view.c (do_view_init, goto_line): Set wrap mode temporary off
to make goto line number work, i.e. `line number' now always means
line number in file and not line number on screen (in wrap mode
one long line wrapped once is displayed in two lines on the screen).
That's important when the viewer is invoked from the find file
dialog to display even in wrap mode approxiamtly the part of the
file where we found the content we searched for.
(move_forward2): In wrap mode lines were sometimes counted wrong
causing cursor up to move more than one line.
(move_backward2): Fixed the movement in wrap mode.
(change_viewer): Always re-init viewer when we have a filename,
i. e. if the viewer is invoked with simple_view_cmd then we can switch
with the F8 key between unprocessed file content und uncompressed
file content.
(view_init): re-init view also when magic flag was altered
1998-04-28 14:19:48 +00:00
|
|
|
line += move_forward2 (view, pm, 0, q);
|
1998-02-27 04:54:42 +00:00
|
|
|
if (line >= lines){
|
|
|
|
if (line == lines)
|
I improved the movement keys of the internal viewer a little bit.
Now in wrap mode the End key and cursor up key behave much better
(e.g. when viewing binary files with lots of wrapped lines).
It's not perfekt but it's better than it used to be.
Tue Apr 28 06:52:24 1998 Norbert Warmuth <k3190@fh-sw.de>
* gnome/gcmd.c (gnome_open_terminal): Changed my_system(1,...) to
my_system(EXECUTE_AS_SHELL,...)
Tue Apr 28 06:06:03 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/extfs.c (extfs_open, extfs_close): Changed my_system(1,...)
to my_system(EXECUTE_AS_SHELL,...), this fixes the broken copyin and
copyout in 4.1.32.
Tue Apr 28 06:11:08 1998 Norbert Warmuth <k3190@fh-sw.de>
* view.c (toggle_wrap_mode, toggle_hex_mode): Force recalculation
of bottom_first (we mustn't use an already calculated and cached
value because it is invalid for the new mode and the End key would
not move to the end of the file).
* configure.in: Renamed the option `--with-our-slang' to
`--with-included-slang' (this one looks better because we also
have an `--with-included-gettext').
Make the option `--with-ext2undel' recognice a given path.
* cmd.c (view_file_at_line): In plain view (F13) set the default
magic flag to zero in order to view the file content unprocessed
(esp. don't uncompress files if they are compressed). The
view_simple_cmd got broken when the default magic flag in view.c
was changed from 0 to 1.
* view.c (do_view_init, goto_line): Set wrap mode temporary off
to make goto line number work, i.e. `line number' now always means
line number in file and not line number on screen (in wrap mode
one long line wrapped once is displayed in two lines on the screen).
That's important when the viewer is invoked from the find file
dialog to display even in wrap mode approxiamtly the part of the
file where we found the content we searched for.
(move_forward2): In wrap mode lines were sometimes counted wrong
causing cursor up to move more than one line.
(move_backward2): Fixed the movement in wrap mode.
(change_viewer): Always re-init viewer when we have a filename,
i. e. if the viewer is invoked with simple_view_cmd then we can switch
with the F8 key between unprocessed file content und uncompressed
file content.
(view_init): re-init view also when magic flag was altered
1998-04-28 14:19:48 +00:00
|
|
|
return pm;
|
1998-02-27 04:54:42 +00:00
|
|
|
else
|
I improved the movement keys of the internal viewer a little bit.
Now in wrap mode the End key and cursor up key behave much better
(e.g. when viewing binary files with lots of wrapped lines).
It's not perfekt but it's better than it used to be.
Tue Apr 28 06:52:24 1998 Norbert Warmuth <k3190@fh-sw.de>
* gnome/gcmd.c (gnome_open_terminal): Changed my_system(1,...) to
my_system(EXECUTE_AS_SHELL,...)
Tue Apr 28 06:06:03 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/extfs.c (extfs_open, extfs_close): Changed my_system(1,...)
to my_system(EXECUTE_AS_SHELL,...), this fixes the broken copyin and
copyout in 4.1.32.
Tue Apr 28 06:11:08 1998 Norbert Warmuth <k3190@fh-sw.de>
* view.c (toggle_wrap_mode, toggle_hex_mode): Force recalculation
of bottom_first (we mustn't use an already calculated and cached
value because it is invalid for the new mode and the End key would
not move to the end of the file).
* configure.in: Renamed the option `--with-our-slang' to
`--with-included-slang' (this one looks better because we also
have an `--with-included-gettext').
Make the option `--with-ext2undel' recognice a given path.
* cmd.c (view_file_at_line): In plain view (F13) set the default
magic flag to zero in order to view the file content unprocessed
(esp. don't uncompress files if they are compressed). The
view_simple_cmd got broken when the default magic flag in view.c
was changed from 0 to 1.
* view.c (do_view_init, goto_line): Set wrap mode temporary off
to make goto line number work, i.e. `line number' now always means
line number in file and not line number on screen (in wrap mode
one long line wrapped once is displayed in two lines on the screen).
That's important when the viewer is invoked from the find file
dialog to display even in wrap mode approxiamtly the part of the
file where we found the content we searched for.
(move_forward2): In wrap mode lines were sometimes counted wrong
causing cursor up to move more than one line.
(move_backward2): Fixed the movement in wrap mode.
(change_viewer): Always re-init viewer when we have a filename,
i. e. if the viewer is invoked with simple_view_cmd then we can switch
with the F8 key between unprocessed file content und uncompressed
file content.
(view_init): re-init view also when magic flag was altered
1998-04-28 14:19:48 +00:00
|
|
|
return move_forward2 (view, pm, line - lines, 0);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
q = p + 1;
|
|
|
|
}
|
I improved the movement keys of the internal viewer a little bit.
Now in wrap mode the End key and cursor up key behave much better
(e.g. when viewing binary files with lots of wrapped lines).
It's not perfekt but it's better than it used to be.
Tue Apr 28 06:52:24 1998 Norbert Warmuth <k3190@fh-sw.de>
* gnome/gcmd.c (gnome_open_terminal): Changed my_system(1,...) to
my_system(EXECUTE_AS_SHELL,...)
Tue Apr 28 06:06:03 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/extfs.c (extfs_open, extfs_close): Changed my_system(1,...)
to my_system(EXECUTE_AS_SHELL,...), this fixes the broken copyin and
copyout in 4.1.32.
Tue Apr 28 06:11:08 1998 Norbert Warmuth <k3190@fh-sw.de>
* view.c (toggle_wrap_mode, toggle_hex_mode): Force recalculation
of bottom_first (we mustn't use an already calculated and cached
value because it is invalid for the new mode and the End key would
not move to the end of the file).
* configure.in: Renamed the option `--with-our-slang' to
`--with-included-slang' (this one looks better because we also
have an `--with-included-gettext').
Make the option `--with-ext2undel' recognice a given path.
* cmd.c (view_file_at_line): In plain view (F13) set the default
magic flag to zero in order to view the file content unprocessed
(esp. don't uncompress files if they are compressed). The
view_simple_cmd got broken when the default magic flag in view.c
was changed from 0 to 1.
* view.c (do_view_init, goto_line): Set wrap mode temporary off
to make goto line number work, i.e. `line number' now always means
line number in file and not line number on screen (in wrap mode
one long line wrapped once is displayed in two lines on the screen).
That's important when the viewer is invoked from the find file
dialog to display even in wrap mode approxiamtly the part of the
file where we found the content we searched for.
(move_forward2): In wrap mode lines were sometimes counted wrong
causing cursor up to move more than one line.
(move_backward2): Fixed the movement in wrap mode.
(change_viewer): Always re-init viewer when we have a filename,
i. e. if the viewer is invoked with simple_view_cmd then we can switch
with the F8 key between unprocessed file content und uncompressed
file content.
(view_init): re-init view also when magic flag was altered
1998-04-28 14:19:48 +00:00
|
|
|
}
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
I improved the movement keys of the internal viewer a little bit.
Now in wrap mode the End key and cursor up key behave much better
(e.g. when viewing binary files with lots of wrapped lines).
It's not perfekt but it's better than it used to be.
Tue Apr 28 06:52:24 1998 Norbert Warmuth <k3190@fh-sw.de>
* gnome/gcmd.c (gnome_open_terminal): Changed my_system(1,...) to
my_system(EXECUTE_AS_SHELL,...)
Tue Apr 28 06:06:03 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/extfs.c (extfs_open, extfs_close): Changed my_system(1,...)
to my_system(EXECUTE_AS_SHELL,...), this fixes the broken copyin and
copyout in 4.1.32.
Tue Apr 28 06:11:08 1998 Norbert Warmuth <k3190@fh-sw.de>
* view.c (toggle_wrap_mode, toggle_hex_mode): Force recalculation
of bottom_first (we mustn't use an already calculated and cached
value because it is invalid for the new mode and the End key would
not move to the end of the file).
* configure.in: Renamed the option `--with-our-slang' to
`--with-included-slang' (this one looks better because we also
have an `--with-included-gettext').
Make the option `--with-ext2undel' recognice a given path.
* cmd.c (view_file_at_line): In plain view (F13) set the default
magic flag to zero in order to view the file content unprocessed
(esp. don't uncompress files if they are compressed). The
view_simple_cmd got broken when the default magic flag in view.c
was changed from 0 to 1.
* view.c (do_view_init, goto_line): Set wrap mode temporary off
to make goto line number work, i.e. `line number' now always means
line number in file and not line number on screen (in wrap mode
one long line wrapped once is displayed in two lines on the screen).
That's important when the viewer is invoked from the find file
dialog to display even in wrap mode approxiamtly the part of the
file where we found the content we searched for.
(move_forward2): In wrap mode lines were sometimes counted wrong
causing cursor up to move more than one line.
(move_backward2): Fixed the movement in wrap mode.
(change_viewer): Always re-init viewer when we have a filename,
i. e. if the viewer is invoked with simple_view_cmd then we can switch
with the F8 key between unprocessed file content und uncompressed
file content.
(view_init): re-init view also when magic flag was altered
1998-04-28 14:19:48 +00:00
|
|
|
return p > view->first ? p : view->first;
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
2002-08-27 19:10:54 +00:00
|
|
|
static void
|
1998-04-16 02:45:53 +00:00
|
|
|
view_move_backward (WView *view, int i)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
|
|
|
view->search_start = view->start_display =
|
|
|
|
move_backward2 (view, view->start_display, i);
|
|
|
|
view->found_len = 0;
|
|
|
|
view->last = view->first + ((LINES-2) * view->bytes_per_line);
|
|
|
|
view->dirty++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static long
|
|
|
|
get_bottom_first (WView *view, int do_not_cache, int really)
|
|
|
|
{
|
|
|
|
int bottom_first;
|
|
|
|
|
|
|
|
if (!have_fast_cpu && !really)
|
|
|
|
return INT_MAX;
|
|
|
|
|
|
|
|
if (!do_not_cache && view->bottom_first != -1)
|
|
|
|
return view->bottom_first;
|
|
|
|
|
|
|
|
/* Force loading */
|
|
|
|
if (view->growing_buffer){
|
|
|
|
int old_last_byte;
|
|
|
|
|
|
|
|
old_last_byte = -1;
|
|
|
|
while (old_last_byte != view->last_byte){
|
|
|
|
old_last_byte = view->last_byte;
|
|
|
|
get_byte (view, view->last_byte+VIEW_PAGE_SIZE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bottom_first = move_backward2 (view, view->last_byte, vheight - 1);
|
|
|
|
|
|
|
|
if (view->hex_mode)
|
|
|
|
bottom_first = (bottom_first + view->bytes_per_line - 1)
|
|
|
|
/ view->bytes_per_line * view->bytes_per_line;
|
|
|
|
view->bottom_first = bottom_first;
|
|
|
|
|
|
|
|
return view->bottom_first;
|
|
|
|
}
|
|
|
|
|
2002-08-27 19:10:54 +00:00
|
|
|
static void
|
1998-04-16 02:45:53 +00:00
|
|
|
view_move_forward (WView *view, int i)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
|
|
|
view->start_display = move_forward2 (view, view->start_display, i, 0);
|
|
|
|
if (!view->reading_pipe && view->start_display > get_bottom_first (view, 0, 0))
|
|
|
|
view->start_display = view->bottom_first;
|
|
|
|
view->search_start = view->start_display;
|
|
|
|
view->found_len = 0;
|
|
|
|
view->last = view->first + ((LINES-2) * view->bytes_per_line);
|
|
|
|
view->dirty++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
move_to_top (WView *view)
|
|
|
|
{
|
|
|
|
view->search_start = view->start_display = view->first;
|
|
|
|
view->found_len = 0;
|
|
|
|
view->last = view->first + ((LINES-2) * view->bytes_per_line);
|
|
|
|
view->nib_shift = 0;
|
|
|
|
view->edit_cursor = view->start_display;
|
|
|
|
view->dirty++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
move_to_bottom (WView *view)
|
|
|
|
{
|
|
|
|
view->search_start = view->start_display = get_bottom_first (view, 0, 1);
|
|
|
|
view->found_len = 0;
|
|
|
|
view->last = view->first + ((LINES-2) * view->bytes_per_line);
|
|
|
|
view->edit_cursor = (view->edit_cursor < view->start_display) ?
|
|
|
|
view->start_display : view->edit_cursor;
|
|
|
|
view->dirty++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Scroll left/right the view panel functions */
|
|
|
|
static void
|
|
|
|
move_right (WView *view)
|
|
|
|
{
|
1998-03-14 00:42:23 +00:00
|
|
|
if (view->wrap_mode && !view->hex_mode)
|
1998-02-27 04:54:42 +00:00
|
|
|
return;
|
|
|
|
if (view->hex_mode) {
|
|
|
|
view->last = view->first + ((LINES-2) * view->bytes_per_line);
|
|
|
|
|
|
|
|
if (view->hex_mode && view->view_side == view_side_left) {
|
|
|
|
view->nib_shift = 1 - view->nib_shift;
|
|
|
|
if (view->nib_shift == 1)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
view->edit_cursor = (++view->edit_cursor < view->last_byte) ?
|
|
|
|
view->edit_cursor : view->last_byte - 1;
|
|
|
|
if (view->edit_cursor >= view->last) {
|
|
|
|
view->edit_cursor -= view->bytes_per_line;
|
1998-04-16 02:45:53 +00:00
|
|
|
view_move_forward(view, 1);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
if (--view->start_col > 0)
|
|
|
|
view->start_col = 0;
|
|
|
|
view->dirty++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
move_left (WView *view)
|
|
|
|
{
|
1998-03-14 00:42:23 +00:00
|
|
|
if (view->wrap_mode && !view->hex_mode)
|
1998-02-27 04:54:42 +00:00
|
|
|
return;
|
|
|
|
if (view->hex_mode) {
|
|
|
|
if (view->hex_mode && view->view_side == view_side_left) {
|
|
|
|
view->nib_shift = 1 - view->nib_shift;
|
|
|
|
if (view->nib_shift == 0)
|
|
|
|
return;
|
|
|
|
}
|
1999-12-10 16:04:35 +00:00
|
|
|
if (view->edit_cursor > view->first)
|
|
|
|
--view->edit_cursor;
|
1998-02-27 04:54:42 +00:00
|
|
|
if (view->edit_cursor < view->start_display) {
|
|
|
|
view->edit_cursor += view->bytes_per_line;
|
1998-04-16 02:45:53 +00:00
|
|
|
view_move_backward(view, 1);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
if (++view->start_col > 0)
|
|
|
|
view->start_col = 0;
|
|
|
|
view->dirty++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
/* {{{ Search routines */
|
|
|
|
|
|
|
|
/* Case insensitive search of text in data */
|
|
|
|
static int
|
|
|
|
icase_search_p (WView *view, char *text, char *data, int nothing)
|
|
|
|
{
|
|
|
|
char *q;
|
2000-11-20 17:25:43 +00:00
|
|
|
int lng;
|
1998-02-27 04:54:42 +00:00
|
|
|
|
2000-11-20 17:25:43 +00:00
|
|
|
if ((q = _icase_search (text, data, &lng)) != 0) {
|
1998-02-27 04:54:42 +00:00
|
|
|
view->found_len = lng;
|
2000-11-20 17:25:43 +00:00
|
|
|
view->search_start = q - data - lng;
|
|
|
|
return 1;
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
2000-11-20 17:25:43 +00:00
|
|
|
return 0;
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
grow_string_buffer (char *text, int *size)
|
|
|
|
{
|
|
|
|
char *new;
|
|
|
|
|
|
|
|
/* The grow steps */
|
|
|
|
*size += 160;
|
2000-11-20 17:25:43 +00:00
|
|
|
new = g_realloc (text, *size);
|
|
|
|
if (!text){
|
1998-02-27 04:54:42 +00:00
|
|
|
*new = 0;
|
|
|
|
}
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2000-11-20 17:25:43 +00:00
|
|
|
get_line_at (WView *view, unsigned long *p, unsigned long *skipped)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
|
|
|
char *buffer = 0;
|
2001-04-24 14:39:38 +00:00
|
|
|
int buffer_size = 0;
|
|
|
|
int usable_size = 0;
|
|
|
|
int ch;
|
|
|
|
int direction = view->direction;
|
1999-04-16 23:28:50 +00:00
|
|
|
unsigned long pos = *p;
|
2000-11-20 17:25:43 +00:00
|
|
|
long i = 0;
|
2001-04-24 14:39:38 +00:00
|
|
|
int prev = 0;
|
|
|
|
|
|
|
|
/* skip over all the possible zeros in the file */
|
|
|
|
while ((ch = get_byte (view, pos)) == 0) {
|
|
|
|
pos += direction; i++;
|
|
|
|
}
|
|
|
|
*skipped = i;
|
|
|
|
|
|
|
|
if (pos) {
|
|
|
|
prev = get_byte (view, pos - 1);
|
|
|
|
if ((prev == -1) || (prev == '\n'))
|
|
|
|
prev = 0;
|
|
|
|
}
|
|
|
|
|
2001-04-24 21:28:17 +00:00
|
|
|
for (i = 0; ch != -1; ch = get_byte (view, pos)){
|
1998-02-27 04:54:42 +00:00
|
|
|
|
|
|
|
if (i == usable_size){
|
|
|
|
buffer = grow_string_buffer (buffer, &buffer_size);
|
|
|
|
usable_size = buffer_size - 2;
|
|
|
|
}
|
2000-11-20 17:25:43 +00:00
|
|
|
|
|
|
|
pos += direction; i++;
|
|
|
|
|
2001-04-24 21:28:17 +00:00
|
|
|
if (ch == '\n' || !ch){
|
1998-02-27 04:54:42 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-04-24 14:39:38 +00:00
|
|
|
buffer [i] = ch;
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
if (buffer){
|
2000-11-20 17:25:43 +00:00
|
|
|
buffer [0] = prev;
|
|
|
|
buffer [i] = 0;
|
2001-04-24 14:39:38 +00:00
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
/* If we are searching backwards, reverse the string */
|
2001-04-24 14:39:38 +00:00
|
|
|
if (direction < 0) {
|
|
|
|
reverse_string (buffer + 1);
|
|
|
|
}
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*p = pos;
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Search status optmizations **/
|
|
|
|
|
|
|
|
/* The number of bytes between percent increments */
|
2002-08-27 19:10:54 +00:00
|
|
|
static int update_steps;
|
1998-02-27 04:54:42 +00:00
|
|
|
|
|
|
|
/* Last point where we updated the status */
|
2002-08-27 19:10:54 +00:00
|
|
|
static long update_activate;
|
1998-02-27 04:54:42 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
search_update_steps (WView *view)
|
|
|
|
{
|
|
|
|
if (view->s.st_size)
|
|
|
|
update_steps = 40000;
|
|
|
|
else
|
|
|
|
update_steps = view->last_byte / 100;
|
|
|
|
|
|
|
|
/* Do not update the percent display but every 20 ks */
|
|
|
|
if (update_steps < 20000)
|
|
|
|
update_steps = 20000;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
search (WView *view, char *text, int (*search)(WView *, char *, char *, int))
|
|
|
|
{
|
1999-06-18 22:25:24 +00:00
|
|
|
int w = view->widget.cols - view->have_frame + 1;
|
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
char *s = NULL; /* The line we read from the view buffer */
|
|
|
|
long p, beginning;
|
|
|
|
int found_len, search_start;
|
|
|
|
int search_status;
|
2001-06-02 01:01:30 +00:00
|
|
|
Dlg_head *d = 0;
|
1999-02-10 01:16:42 +00:00
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
/* Used to keep track of where the line starts, when looking forward */
|
|
|
|
/* is the index before transfering the line; the reverse case uses */
|
|
|
|
/* the position returned after the line has been read */
|
|
|
|
long forward_line_start;
|
|
|
|
long reverse_line_start;
|
|
|
|
long t;
|
|
|
|
/* Clear interrupt status */
|
|
|
|
got_interrupt ();
|
1999-02-10 01:16:42 +00:00
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
if (verbose){
|
1998-03-25 05:16:00 +00:00
|
|
|
d = message (D_INSERT, _(" Search "), _("Searching %s"), text);
|
1998-02-27 04:54:42 +00:00
|
|
|
mc_refresh ();
|
|
|
|
}
|
2000-11-20 17:25:43 +00:00
|
|
|
|
|
|
|
found_len = view->found_len;
|
|
|
|
search_start = view->search_start;
|
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
if (view->direction == 1){
|
2000-11-20 17:25:43 +00:00
|
|
|
p = found_len ? search_start + 1 : search_start;
|
1998-02-27 04:54:42 +00:00
|
|
|
} else {
|
2000-11-20 17:25:43 +00:00
|
|
|
p = (found_len ? search_start : view->last) - 1;
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
beginning = p;
|
|
|
|
|
|
|
|
/* Compute the percent steps */
|
|
|
|
search_update_steps (view);
|
|
|
|
update_activate = 0;
|
|
|
|
|
2000-11-20 17:25:43 +00:00
|
|
|
for (; ; g_free (s)){
|
1998-02-27 04:54:42 +00:00
|
|
|
if (p >= update_activate){
|
|
|
|
update_activate += update_steps;
|
|
|
|
if (verbose){
|
1999-02-26 07:26:40 +00:00
|
|
|
view_percent (view, p, w, TRUE);
|
1998-02-27 04:54:42 +00:00
|
|
|
mc_refresh ();
|
|
|
|
}
|
|
|
|
if (got_interrupt ())
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
forward_line_start = p;
|
|
|
|
disable_interrupt_key ();
|
2000-11-20 17:25:43 +00:00
|
|
|
s = get_line_at (view, &p, &t);
|
1998-02-27 04:54:42 +00:00
|
|
|
reverse_line_start = p;
|
|
|
|
enable_interrupt_key ();
|
2000-11-20 17:25:43 +00:00
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
if (!s)
|
|
|
|
break;
|
2000-11-20 17:25:43 +00:00
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
search_status = (*search) (view, text, s + 1, match_normal);
|
2000-11-20 17:25:43 +00:00
|
|
|
if (search_status < 0){
|
|
|
|
g_free (s);
|
1998-02-27 04:54:42 +00:00
|
|
|
break;
|
2000-11-20 17:25:43 +00:00
|
|
|
}
|
1998-02-27 04:54:42 +00:00
|
|
|
|
|
|
|
if (search_status == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* We found the string */
|
|
|
|
|
2000-11-20 17:25:43 +00:00
|
|
|
if (*s && !view->search_start && (search == regexp_view_search) && (*text == '^')){
|
1998-02-27 04:54:42 +00:00
|
|
|
|
|
|
|
/* We do not want to match a
|
|
|
|
* ^ regexp when not at the real
|
|
|
|
* beginning of some line
|
|
|
|
*/
|
2000-11-20 17:25:43 +00:00
|
|
|
continue;
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
/* Record the position used to continue the search */
|
|
|
|
if (view->direction == 1)
|
2000-11-20 17:25:43 +00:00
|
|
|
t += forward_line_start;
|
1998-02-27 04:54:42 +00:00
|
|
|
else
|
2000-11-20 17:25:43 +00:00
|
|
|
t += reverse_line_start ? reverse_line_start + 3 : 0;
|
1998-02-27 04:54:42 +00:00
|
|
|
view->search_start += t;
|
|
|
|
|
|
|
|
if (t != beginning){
|
|
|
|
if (t > get_bottom_first (view, 0, 0))
|
|
|
|
view->start_display = view->bottom_first;
|
|
|
|
else
|
|
|
|
view->start_display = t;
|
|
|
|
}
|
2000-11-20 17:25:43 +00:00
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
g_free (s);
|
1998-02-27 04:54:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
disable_interrupt_key ();
|
2001-09-16 01:22:12 +00:00
|
|
|
if (verbose) {
|
1998-02-27 04:54:42 +00:00
|
|
|
dlg_run_done (d);
|
|
|
|
destroy_dlg (d);
|
|
|
|
}
|
2001-09-16 01:22:12 +00:00
|
|
|
if (!s) {
|
1998-03-25 05:16:00 +00:00
|
|
|
message (0, _(" Search "), _(" Search string not found "));
|
1998-02-27 04:54:42 +00:00
|
|
|
view->found_len = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Search buffer (it's size is len) in the complete buffer */
|
|
|
|
/* returns the position where the block was found or -1 if not found */
|
|
|
|
static long
|
|
|
|
block_search (WView *view, char *buffer, int len)
|
|
|
|
{
|
1999-06-18 22:25:24 +00:00
|
|
|
int w = view->widget.cols - view->have_frame + 1;
|
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
char *d = buffer, b;
|
1999-04-16 23:28:50 +00:00
|
|
|
unsigned long e;
|
1998-02-27 04:54:42 +00:00
|
|
|
|
|
|
|
/* clear interrupt status */
|
|
|
|
got_interrupt ();
|
|
|
|
enable_interrupt_key ();
|
|
|
|
e = view->found_len ? view->search_start + 1 : view->search_start;
|
|
|
|
|
|
|
|
search_update_steps (view);
|
|
|
|
update_activate = 0;
|
|
|
|
|
2001-08-06 15:33:38 +00:00
|
|
|
while (e < view->last_byte){
|
1998-02-27 04:54:42 +00:00
|
|
|
if (e >= update_activate){
|
|
|
|
update_activate += update_steps;
|
|
|
|
if (verbose){
|
1999-02-26 07:26:40 +00:00
|
|
|
view_percent (view, e, w, TRUE);
|
1998-02-27 04:54:42 +00:00
|
|
|
mc_refresh ();
|
|
|
|
}
|
|
|
|
if (got_interrupt ())
|
|
|
|
break;
|
|
|
|
}
|
2001-08-06 15:33:38 +00:00
|
|
|
b = get_byte (view, e++);
|
1998-02-27 04:54:42 +00:00
|
|
|
|
|
|
|
if (*d == b){
|
|
|
|
d++;
|
2001-08-06 15:33:38 +00:00
|
|
|
if (d - buffer == len){
|
|
|
|
disable_interrupt_key ();
|
|
|
|
return e - len;
|
|
|
|
}
|
1998-02-27 04:54:42 +00:00
|
|
|
} else {
|
|
|
|
e -= d - buffer;
|
|
|
|
d = buffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
disable_interrupt_key ();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2001-07-09 23:19:23 +00:00
|
|
|
/*
|
|
|
|
* Search in the hex mode. Supported input:
|
|
|
|
* - numbers (oct, dec, hex). Each of them matches one byte.
|
|
|
|
* - strings in double quotes. Matches exactly without quotes.
|
|
|
|
*/
|
1998-02-27 04:54:42 +00:00
|
|
|
static void
|
|
|
|
hex_search (WView *view, char *text)
|
|
|
|
{
|
2001-09-02 20:34:44 +00:00
|
|
|
char *buffer; /* Parsed search string */
|
|
|
|
char *cur; /* Current position in it */
|
|
|
|
int block_len; /* Length of the search string */
|
|
|
|
long pos; /* Position of the string in the file */
|
2001-07-09 23:19:23 +00:00
|
|
|
int parse_error = 0;
|
1998-02-27 04:54:42 +00:00
|
|
|
|
2001-07-10 17:42:25 +00:00
|
|
|
if (!*text) {
|
|
|
|
view->found_len = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-07-09 23:19:23 +00:00
|
|
|
/* buffer will never be longer that text */
|
|
|
|
buffer = g_new (char, strlen (text));
|
2001-09-02 20:34:44 +00:00
|
|
|
cur = buffer;
|
2001-07-09 23:19:23 +00:00
|
|
|
|
|
|
|
/* First convert the string to a stream of bytes */
|
2001-07-10 17:42:25 +00:00
|
|
|
while (*text) {
|
2001-07-09 23:19:23 +00:00
|
|
|
int val;
|
|
|
|
int ptr;
|
|
|
|
|
2001-09-02 20:34:44 +00:00
|
|
|
/* Skip leading spaces */
|
|
|
|
if (*text == ' ' || *text == '\t') {
|
|
|
|
text++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2001-07-09 23:19:23 +00:00
|
|
|
/* %i matches octal, decimal, and hexadecimal numbers */
|
2001-07-10 17:42:25 +00:00
|
|
|
if (sscanf (text, "%i%n", &val, &ptr) > 0) {
|
2001-07-09 23:19:23 +00:00
|
|
|
/* Allow signed and unsigned char in the user input */
|
|
|
|
if (val < -128 || val > 255) {
|
|
|
|
parse_error = 1;
|
1998-02-27 04:54:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-09-02 20:34:44 +00:00
|
|
|
*cur++ = (char) val;
|
2001-07-10 17:42:25 +00:00
|
|
|
text += ptr;
|
2001-07-09 23:19:23 +00:00
|
|
|
continue;
|
|
|
|
}
|
1998-02-27 04:54:42 +00:00
|
|
|
|
2001-07-09 23:19:23 +00:00
|
|
|
/* Try quoted string, strip quotes */
|
2001-09-02 20:34:44 +00:00
|
|
|
if (*text == '"') {
|
|
|
|
char *next_quote;
|
|
|
|
|
|
|
|
text++;
|
|
|
|
next_quote = strchr (text, '"');
|
|
|
|
if (next_quote) {
|
|
|
|
memcpy (cur, text, next_quote - text);
|
|
|
|
cur += next_quote - text;
|
|
|
|
text = next_quote + 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* fall through */
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
2001-07-09 23:19:23 +00:00
|
|
|
|
|
|
|
parse_error = 1;
|
|
|
|
break;
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
2001-07-09 23:19:23 +00:00
|
|
|
|
2001-09-02 20:34:44 +00:00
|
|
|
block_len = cur - buffer;
|
|
|
|
|
2001-07-09 23:19:23 +00:00
|
|
|
/* No valid bytes in the user input */
|
|
|
|
if (block_len <= 0 || parse_error) {
|
2001-07-10 17:42:25 +00:00
|
|
|
message (0, _(" Search "), _("Invalid hex search expression"));
|
2001-07-09 23:19:23 +00:00
|
|
|
g_free (buffer);
|
|
|
|
view->found_len = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
/* Then start the search */
|
|
|
|
pos = block_search (view, buffer, block_len);
|
2001-07-09 23:19:23 +00:00
|
|
|
|
2001-07-10 17:42:25 +00:00
|
|
|
g_free (buffer);
|
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
if (pos == -1){
|
1998-03-25 05:16:00 +00:00
|
|
|
message (0, _(" Search "), _(" Search string not found "));
|
1998-02-27 04:54:42 +00:00
|
|
|
view->found_len = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-08-06 15:33:38 +00:00
|
|
|
view->search_start = pos;
|
1998-02-27 04:54:42 +00:00
|
|
|
view->found_len = block_len;
|
|
|
|
/* Set the edit cursor to the search position, left nibble */
|
|
|
|
view->edit_cursor = view->search_start;
|
|
|
|
view->nib_shift = 0;
|
|
|
|
|
|
|
|
/* Adjust the file offset */
|
|
|
|
view->start_display = (pos & (~(view->bytes_per_line-1)));
|
|
|
|
if (view->start_display > get_bottom_first (view, 0, 0))
|
|
|
|
view->start_display = view->bottom_first;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int regexp_view_search (WView *view, char *pattern, char *string, int match_type)
|
|
|
|
{
|
|
|
|
static regex_t r;
|
|
|
|
static char *old_pattern = NULL;
|
|
|
|
static int old_type;
|
|
|
|
regmatch_t pmatch[1];
|
|
|
|
int i, flags = REG_ICASE;
|
|
|
|
|
|
|
|
if (!old_pattern || strcmp (old_pattern, pattern) || old_type != match_type){
|
|
|
|
if (old_pattern){
|
|
|
|
regfree (&r);
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
g_free (old_pattern);
|
1998-02-27 04:54:42 +00:00
|
|
|
old_pattern = 0;
|
|
|
|
}
|
|
|
|
for (i = 0; pattern[i] != 0; i++){
|
|
|
|
if (isupper ((unsigned char) pattern[i])){
|
|
|
|
flags = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
flags |= REG_EXTENDED;
|
|
|
|
if (regcomp (&r, pattern, flags)){
|
1998-03-25 05:16:00 +00:00
|
|
|
message (1, MSG_ERROR, _(" Invalid regular expression "));
|
1998-02-27 04:54:42 +00:00
|
|
|
return -1;
|
|
|
|
}
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
old_pattern = g_strdup (pattern);
|
1998-02-27 04:54:42 +00:00
|
|
|
old_type = match_type;
|
|
|
|
}
|
|
|
|
if (regexec (&r, string, 1, pmatch, 0) != 0)
|
|
|
|
return 0;
|
|
|
|
view->found_len = pmatch[0].rm_eo - pmatch[0].rm_so;
|
|
|
|
view->search_start = pmatch[0].rm_so;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_regexp_search (void *xview, char *regexp)
|
|
|
|
{
|
|
|
|
WView *view = (WView *) xview;
|
|
|
|
|
|
|
|
view->search_exp = regexp;
|
|
|
|
search (view, regexp, regexp_view_search);
|
|
|
|
/* Had a refresh here */
|
|
|
|
view->dirty++;
|
1999-02-26 07:26:40 +00:00
|
|
|
view_update (view, TRUE);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void do_normal_search (void *xview, char *text)
|
|
|
|
{
|
|
|
|
WView *view = (WView *) xview;
|
|
|
|
|
|
|
|
view->search_exp = text;
|
|
|
|
if (view->hex_mode)
|
|
|
|
hex_search (view, text);
|
|
|
|
else
|
|
|
|
search (view, text, icase_search_p);
|
|
|
|
/* Had a refresh here */
|
|
|
|
view->dirty++;
|
1999-02-26 07:26:40 +00:00
|
|
|
view_update (view, TRUE);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
/* {{{ Mouse and keyboard handling */
|
|
|
|
|
|
|
|
/* Real view only */
|
2001-08-07 16:53:55 +00:00
|
|
|
static void view_help_cmd (void)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
2001-06-09 07:13:46 +00:00
|
|
|
interactive_display (NULL, "[Internal File Viewer]");
|
1998-02-27 04:54:42 +00:00
|
|
|
/*
|
|
|
|
view_refresh (0);
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Both views */
|
2002-08-27 19:10:54 +00:00
|
|
|
static void toggle_wrap_mode (WView *view)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
|
|
|
if (view->hex_mode) {
|
|
|
|
if (view->growing_buffer != 0) {
|
|
|
|
return;
|
|
|
|
}
|
I improved the movement keys of the internal viewer a little bit.
Now in wrap mode the End key and cursor up key behave much better
(e.g. when viewing binary files with lots of wrapped lines).
It's not perfekt but it's better than it used to be.
Tue Apr 28 06:52:24 1998 Norbert Warmuth <k3190@fh-sw.de>
* gnome/gcmd.c (gnome_open_terminal): Changed my_system(1,...) to
my_system(EXECUTE_AS_SHELL,...)
Tue Apr 28 06:06:03 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/extfs.c (extfs_open, extfs_close): Changed my_system(1,...)
to my_system(EXECUTE_AS_SHELL,...), this fixes the broken copyin and
copyout in 4.1.32.
Tue Apr 28 06:11:08 1998 Norbert Warmuth <k3190@fh-sw.de>
* view.c (toggle_wrap_mode, toggle_hex_mode): Force recalculation
of bottom_first (we mustn't use an already calculated and cached
value because it is invalid for the new mode and the End key would
not move to the end of the file).
* configure.in: Renamed the option `--with-our-slang' to
`--with-included-slang' (this one looks better because we also
have an `--with-included-gettext').
Make the option `--with-ext2undel' recognice a given path.
* cmd.c (view_file_at_line): In plain view (F13) set the default
magic flag to zero in order to view the file content unprocessed
(esp. don't uncompress files if they are compressed). The
view_simple_cmd got broken when the default magic flag in view.c
was changed from 0 to 1.
* view.c (do_view_init, goto_line): Set wrap mode temporary off
to make goto line number work, i.e. `line number' now always means
line number in file and not line number on screen (in wrap mode
one long line wrapped once is displayed in two lines on the screen).
That's important when the viewer is invoked from the find file
dialog to display even in wrap mode approxiamtly the part of the
file where we found the content we searched for.
(move_forward2): In wrap mode lines were sometimes counted wrong
causing cursor up to move more than one line.
(move_backward2): Fixed the movement in wrap mode.
(change_viewer): Always re-init viewer when we have a filename,
i. e. if the viewer is invoked with simple_view_cmd then we can switch
with the F8 key between unprocessed file content und uncompressed
file content.
(view_init): re-init view also when magic flag was altered
1998-04-28 14:19:48 +00:00
|
|
|
get_bottom_first (view, 1, 1);
|
1998-02-27 04:54:42 +00:00
|
|
|
if (view->hexedit_mode) {
|
|
|
|
view->view_side = 1 - view->view_side;
|
|
|
|
} else {
|
|
|
|
view->hexedit_mode = 1 - view->hexedit_mode;
|
|
|
|
}
|
|
|
|
view_labels (view);
|
|
|
|
view->dirty++;
|
1999-02-26 07:26:40 +00:00
|
|
|
view_update (view, TRUE);
|
1998-02-27 04:54:42 +00:00
|
|
|
return;
|
|
|
|
}
|
1998-03-14 00:42:23 +00:00
|
|
|
view->wrap_mode = 1 - view->wrap_mode;
|
I improved the movement keys of the internal viewer a little bit.
Now in wrap mode the End key and cursor up key behave much better
(e.g. when viewing binary files with lots of wrapped lines).
It's not perfekt but it's better than it used to be.
Tue Apr 28 06:52:24 1998 Norbert Warmuth <k3190@fh-sw.de>
* gnome/gcmd.c (gnome_open_terminal): Changed my_system(1,...) to
my_system(EXECUTE_AS_SHELL,...)
Tue Apr 28 06:06:03 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/extfs.c (extfs_open, extfs_close): Changed my_system(1,...)
to my_system(EXECUTE_AS_SHELL,...), this fixes the broken copyin and
copyout in 4.1.32.
Tue Apr 28 06:11:08 1998 Norbert Warmuth <k3190@fh-sw.de>
* view.c (toggle_wrap_mode, toggle_hex_mode): Force recalculation
of bottom_first (we mustn't use an already calculated and cached
value because it is invalid for the new mode and the End key would
not move to the end of the file).
* configure.in: Renamed the option `--with-our-slang' to
`--with-included-slang' (this one looks better because we also
have an `--with-included-gettext').
Make the option `--with-ext2undel' recognice a given path.
* cmd.c (view_file_at_line): In plain view (F13) set the default
magic flag to zero in order to view the file content unprocessed
(esp. don't uncompress files if they are compressed). The
view_simple_cmd got broken when the default magic flag in view.c
was changed from 0 to 1.
* view.c (do_view_init, goto_line): Set wrap mode temporary off
to make goto line number work, i.e. `line number' now always means
line number in file and not line number on screen (in wrap mode
one long line wrapped once is displayed in two lines on the screen).
That's important when the viewer is invoked from the find file
dialog to display even in wrap mode approxiamtly the part of the
file where we found the content we searched for.
(move_forward2): In wrap mode lines were sometimes counted wrong
causing cursor up to move more than one line.
(move_backward2): Fixed the movement in wrap mode.
(change_viewer): Always re-init viewer when we have a filename,
i. e. if the viewer is invoked with simple_view_cmd then we can switch
with the F8 key between unprocessed file content und uncompressed
file content.
(view_init): re-init view also when magic flag was altered
1998-04-28 14:19:48 +00:00
|
|
|
get_bottom_first (view, 1, 1);
|
1998-03-14 00:42:23 +00:00
|
|
|
if (view->wrap_mode)
|
1998-02-27 04:54:42 +00:00
|
|
|
view->start_col = 0;
|
|
|
|
else {
|
|
|
|
if (have_fast_cpu){
|
|
|
|
if (view->bottom_first < view->start_display)
|
|
|
|
view->search_start = view->start_display = view->bottom_first;
|
|
|
|
view->found_len = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
view_labels (view);
|
|
|
|
view->dirty++;
|
1999-02-26 07:26:40 +00:00
|
|
|
view_update (view, TRUE);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Both views */
|
2002-08-27 19:10:54 +00:00
|
|
|
static void
|
1998-02-27 04:54:42 +00:00
|
|
|
toggle_hex_mode (WView *view)
|
|
|
|
{
|
|
|
|
view->hex_mode = 1 - view->hex_mode;
|
|
|
|
|
|
|
|
if (view->hex_mode){
|
|
|
|
/* Shift the line start to 0x____0 on entry, restore it for Ascii */
|
|
|
|
view->start_save = view->start_display;
|
|
|
|
view->start_display -= view->start_display % view->bytes_per_line;
|
|
|
|
view->edit_cursor = view->start_display;
|
|
|
|
view->widget.options |= W_WANT_CURSOR;
|
2002-08-22 15:34:25 +00:00
|
|
|
view->widget.parent->flags |= DLG_WANT_TAB;
|
1998-02-27 04:54:42 +00:00
|
|
|
} else {
|
|
|
|
view->start_display = view->start_save;
|
2002-08-22 15:34:25 +00:00
|
|
|
view->widget.parent->flags &= ~DLG_WANT_TAB;
|
1998-02-27 04:54:42 +00:00
|
|
|
view->widget.options &= ~W_WANT_CURSOR;
|
|
|
|
}
|
|
|
|
altered_hex_mode = 1;
|
I improved the movement keys of the internal viewer a little bit.
Now in wrap mode the End key and cursor up key behave much better
(e.g. when viewing binary files with lots of wrapped lines).
It's not perfekt but it's better than it used to be.
Tue Apr 28 06:52:24 1998 Norbert Warmuth <k3190@fh-sw.de>
* gnome/gcmd.c (gnome_open_terminal): Changed my_system(1,...) to
my_system(EXECUTE_AS_SHELL,...)
Tue Apr 28 06:06:03 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/extfs.c (extfs_open, extfs_close): Changed my_system(1,...)
to my_system(EXECUTE_AS_SHELL,...), this fixes the broken copyin and
copyout in 4.1.32.
Tue Apr 28 06:11:08 1998 Norbert Warmuth <k3190@fh-sw.de>
* view.c (toggle_wrap_mode, toggle_hex_mode): Force recalculation
of bottom_first (we mustn't use an already calculated and cached
value because it is invalid for the new mode and the End key would
not move to the end of the file).
* configure.in: Renamed the option `--with-our-slang' to
`--with-included-slang' (this one looks better because we also
have an `--with-included-gettext').
Make the option `--with-ext2undel' recognice a given path.
* cmd.c (view_file_at_line): In plain view (F13) set the default
magic flag to zero in order to view the file content unprocessed
(esp. don't uncompress files if they are compressed). The
view_simple_cmd got broken when the default magic flag in view.c
was changed from 0 to 1.
* view.c (do_view_init, goto_line): Set wrap mode temporary off
to make goto line number work, i.e. `line number' now always means
line number in file and not line number on screen (in wrap mode
one long line wrapped once is displayed in two lines on the screen).
That's important when the viewer is invoked from the find file
dialog to display even in wrap mode approxiamtly the part of the
file where we found the content we searched for.
(move_forward2): In wrap mode lines were sometimes counted wrong
causing cursor up to move more than one line.
(move_backward2): Fixed the movement in wrap mode.
(change_viewer): Always re-init viewer when we have a filename,
i. e. if the viewer is invoked with simple_view_cmd then we can switch
with the F8 key between unprocessed file content und uncompressed
file content.
(view_init): re-init view also when magic flag was altered
1998-04-28 14:19:48 +00:00
|
|
|
get_bottom_first (view, 1, 1);
|
1998-02-27 04:54:42 +00:00
|
|
|
view_labels (view);
|
|
|
|
view->dirty++;
|
1999-02-26 07:26:40 +00:00
|
|
|
view_update (view, TRUE);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
1999-06-24 21:53:40 +00:00
|
|
|
/* Ascii view */
|
2002-08-27 19:10:54 +00:00
|
|
|
static void
|
1998-02-27 04:54:42 +00:00
|
|
|
goto_line (WView *view)
|
|
|
|
{
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
char *line, prompt [BUF_SMALL];
|
1999-04-16 23:28:50 +00:00
|
|
|
int oldline = 1;
|
I improved the movement keys of the internal viewer a little bit.
Now in wrap mode the End key and cursor up key behave much better
(e.g. when viewing binary files with lots of wrapped lines).
It's not perfekt but it's better than it used to be.
Tue Apr 28 06:52:24 1998 Norbert Warmuth <k3190@fh-sw.de>
* gnome/gcmd.c (gnome_open_terminal): Changed my_system(1,...) to
my_system(EXECUTE_AS_SHELL,...)
Tue Apr 28 06:06:03 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/extfs.c (extfs_open, extfs_close): Changed my_system(1,...)
to my_system(EXECUTE_AS_SHELL,...), this fixes the broken copyin and
copyout in 4.1.32.
Tue Apr 28 06:11:08 1998 Norbert Warmuth <k3190@fh-sw.de>
* view.c (toggle_wrap_mode, toggle_hex_mode): Force recalculation
of bottom_first (we mustn't use an already calculated and cached
value because it is invalid for the new mode and the End key would
not move to the end of the file).
* configure.in: Renamed the option `--with-our-slang' to
`--with-included-slang' (this one looks better because we also
have an `--with-included-gettext').
Make the option `--with-ext2undel' recognice a given path.
* cmd.c (view_file_at_line): In plain view (F13) set the default
magic flag to zero in order to view the file content unprocessed
(esp. don't uncompress files if they are compressed). The
view_simple_cmd got broken when the default magic flag in view.c
was changed from 0 to 1.
* view.c (do_view_init, goto_line): Set wrap mode temporary off
to make goto line number work, i.e. `line number' now always means
line number in file and not line number on screen (in wrap mode
one long line wrapped once is displayed in two lines on the screen).
That's important when the viewer is invoked from the find file
dialog to display even in wrap mode approxiamtly the part of the
file where we found the content we searched for.
(move_forward2): In wrap mode lines were sometimes counted wrong
causing cursor up to move more than one line.
(move_backward2): Fixed the movement in wrap mode.
(change_viewer): Always re-init viewer when we have a filename,
i. e. if the viewer is invoked with simple_view_cmd then we can switch
with the F8 key between unprocessed file content und uncompressed
file content.
(view_init): re-init view also when magic flag was altered
1998-04-28 14:19:48 +00:00
|
|
|
int saved_wrap_mode = view->wrap_mode;
|
1999-04-16 23:28:50 +00:00
|
|
|
unsigned long i;
|
1998-02-27 04:54:42 +00:00
|
|
|
|
I improved the movement keys of the internal viewer a little bit.
Now in wrap mode the End key and cursor up key behave much better
(e.g. when viewing binary files with lots of wrapped lines).
It's not perfekt but it's better than it used to be.
Tue Apr 28 06:52:24 1998 Norbert Warmuth <k3190@fh-sw.de>
* gnome/gcmd.c (gnome_open_terminal): Changed my_system(1,...) to
my_system(EXECUTE_AS_SHELL,...)
Tue Apr 28 06:06:03 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/extfs.c (extfs_open, extfs_close): Changed my_system(1,...)
to my_system(EXECUTE_AS_SHELL,...), this fixes the broken copyin and
copyout in 4.1.32.
Tue Apr 28 06:11:08 1998 Norbert Warmuth <k3190@fh-sw.de>
* view.c (toggle_wrap_mode, toggle_hex_mode): Force recalculation
of bottom_first (we mustn't use an already calculated and cached
value because it is invalid for the new mode and the End key would
not move to the end of the file).
* configure.in: Renamed the option `--with-our-slang' to
`--with-included-slang' (this one looks better because we also
have an `--with-included-gettext').
Make the option `--with-ext2undel' recognice a given path.
* cmd.c (view_file_at_line): In plain view (F13) set the default
magic flag to zero in order to view the file content unprocessed
(esp. don't uncompress files if they are compressed). The
view_simple_cmd got broken when the default magic flag in view.c
was changed from 0 to 1.
* view.c (do_view_init, goto_line): Set wrap mode temporary off
to make goto line number work, i.e. `line number' now always means
line number in file and not line number on screen (in wrap mode
one long line wrapped once is displayed in two lines on the screen).
That's important when the viewer is invoked from the find file
dialog to display even in wrap mode approxiamtly the part of the
file where we found the content we searched for.
(move_forward2): In wrap mode lines were sometimes counted wrong
causing cursor up to move more than one line.
(move_backward2): Fixed the movement in wrap mode.
(change_viewer): Always re-init viewer when we have a filename,
i. e. if the viewer is invoked with simple_view_cmd then we can switch
with the F8 key between unprocessed file content und uncompressed
file content.
(view_init): re-init view also when magic flag was altered
1998-04-28 14:19:48 +00:00
|
|
|
view->wrap_mode = 0;
|
1998-02-27 04:54:42 +00:00
|
|
|
for (i = view->first; i < view->start_display; i++)
|
|
|
|
if (get_byte (view, i) == '\n')
|
|
|
|
oldline ++;
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
g_snprintf (prompt, sizeof (prompt), _(" The current line number is %d.\n"
|
1998-03-25 05:16:00 +00:00
|
|
|
" Enter the new line number:"), oldline);
|
|
|
|
line = input_dialog (_(" Goto line "), prompt, "");
|
1998-02-27 04:54:42 +00:00
|
|
|
if (line){
|
|
|
|
if (*line){
|
|
|
|
move_to_top (view);
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
view_move_forward (view, atol (line) - 1);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
g_free (line);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
view->dirty++;
|
I improved the movement keys of the internal viewer a little bit.
Now in wrap mode the End key and cursor up key behave much better
(e.g. when viewing binary files with lots of wrapped lines).
It's not perfekt but it's better than it used to be.
Tue Apr 28 06:52:24 1998 Norbert Warmuth <k3190@fh-sw.de>
* gnome/gcmd.c (gnome_open_terminal): Changed my_system(1,...) to
my_system(EXECUTE_AS_SHELL,...)
Tue Apr 28 06:06:03 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/extfs.c (extfs_open, extfs_close): Changed my_system(1,...)
to my_system(EXECUTE_AS_SHELL,...), this fixes the broken copyin and
copyout in 4.1.32.
Tue Apr 28 06:11:08 1998 Norbert Warmuth <k3190@fh-sw.de>
* view.c (toggle_wrap_mode, toggle_hex_mode): Force recalculation
of bottom_first (we mustn't use an already calculated and cached
value because it is invalid for the new mode and the End key would
not move to the end of the file).
* configure.in: Renamed the option `--with-our-slang' to
`--with-included-slang' (this one looks better because we also
have an `--with-included-gettext').
Make the option `--with-ext2undel' recognice a given path.
* cmd.c (view_file_at_line): In plain view (F13) set the default
magic flag to zero in order to view the file content unprocessed
(esp. don't uncompress files if they are compressed). The
view_simple_cmd got broken when the default magic flag in view.c
was changed from 0 to 1.
* view.c (do_view_init, goto_line): Set wrap mode temporary off
to make goto line number work, i.e. `line number' now always means
line number in file and not line number on screen (in wrap mode
one long line wrapped once is displayed in two lines on the screen).
That's important when the viewer is invoked from the find file
dialog to display even in wrap mode approxiamtly the part of the
file where we found the content we searched for.
(move_forward2): In wrap mode lines were sometimes counted wrong
causing cursor up to move more than one line.
(move_backward2): Fixed the movement in wrap mode.
(change_viewer): Always re-init viewer when we have a filename,
i. e. if the viewer is invoked with simple_view_cmd then we can switch
with the F8 key between unprocessed file content und uncompressed
file content.
(view_init): re-init view also when magic flag was altered
1998-04-28 14:19:48 +00:00
|
|
|
view->wrap_mode = saved_wrap_mode;
|
1999-02-26 07:26:40 +00:00
|
|
|
view_update (view, TRUE);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
1999-06-24 21:53:40 +00:00
|
|
|
/* Hex view */
|
2001-06-14 22:33:00 +00:00
|
|
|
static void
|
1999-06-24 21:53:40 +00:00
|
|
|
goto_addr (WView *view)
|
|
|
|
{
|
|
|
|
char *line, *error, prompt [BUF_SMALL];
|
|
|
|
unsigned long addr;
|
|
|
|
|
|
|
|
g_snprintf (prompt, sizeof (prompt), _(" The current address is 0x%lx.\n"
|
|
|
|
" Enter the new address:"), view->edit_cursor);
|
|
|
|
line = input_dialog (_(" Goto Address "), prompt, "");
|
|
|
|
if (line){
|
|
|
|
if (*line) {
|
|
|
|
addr = strtol (line, &error, 0);
|
|
|
|
if ((*error == '\0') && (addr <= view->last_byte)) {
|
|
|
|
move_to_top (view);
|
|
|
|
view_move_forward (view, addr/view->bytes_per_line);
|
|
|
|
view->edit_cursor = addr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free (line);
|
|
|
|
}
|
|
|
|
view->dirty++;
|
|
|
|
view_update (view, TRUE);
|
|
|
|
}
|
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
/* Both views */
|
1998-12-02 21:27:27 +00:00
|
|
|
static void
|
1998-02-27 04:54:42 +00:00
|
|
|
regexp_search (WView *view, int direction)
|
|
|
|
{
|
|
|
|
char *regexp = "";
|
|
|
|
static char *old = 0;
|
|
|
|
|
|
|
|
/* This is really an F6 key handler */
|
|
|
|
if (view->hex_mode){
|
|
|
|
/* Save it without a confirmation prompt */
|
2002-05-30 13:12:56 +00:00
|
|
|
if (view->change_list)
|
|
|
|
save_edit_changes(view);
|
1998-02-27 04:54:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
regexp = old ? old : regexp;
|
1998-03-25 05:16:00 +00:00
|
|
|
regexp = input_dialog (_(" Search "), _(" Enter regexp:"), regexp);
|
2000-11-20 17:25:43 +00:00
|
|
|
if ((!regexp)){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((!*regexp)){
|
|
|
|
g_free (regexp);
|
1998-02-27 04:54:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (old)
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
g_free (old);
|
1998-02-27 04:54:42 +00:00
|
|
|
old = regexp;
|
|
|
|
#if 0
|
|
|
|
/* Mhm, do we really need to load all the file in the core? */
|
|
|
|
if (view->bytes_read < view->last_byte)
|
|
|
|
get_byte (view, view->last_byte-1);/* Get the whole file in to memory */
|
|
|
|
#endif
|
|
|
|
view->direction = direction;
|
|
|
|
do_regexp_search (view, regexp);
|
|
|
|
|
|
|
|
view->last_search = do_regexp_search;
|
|
|
|
}
|
|
|
|
|
2002-08-27 19:10:54 +00:00
|
|
|
static void
|
1998-02-27 04:54:42 +00:00
|
|
|
regexp_search_cmd (WView *view)
|
|
|
|
{
|
|
|
|
regexp_search (view, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Both views */
|
1998-12-02 21:27:27 +00:00
|
|
|
static void
|
1998-02-27 04:54:42 +00:00
|
|
|
normal_search (WView *view, int direction)
|
|
|
|
{
|
|
|
|
static char *old;
|
|
|
|
char *exp = "";
|
|
|
|
|
|
|
|
exp = old ? old : exp;
|
2001-06-05 22:49:15 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CHARSET
|
2001-06-25 11:24:49 +00:00
|
|
|
if ( *exp )
|
2001-06-05 22:49:15 +00:00
|
|
|
convert_to_display( exp );
|
|
|
|
#endif
|
|
|
|
|
1998-03-25 05:16:00 +00:00
|
|
|
exp = input_dialog (_(" Search "), _(" Enter search string:"), exp);
|
2000-11-20 17:25:43 +00:00
|
|
|
if ((!exp)){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((!*exp)){
|
|
|
|
g_free (exp);
|
1998-02-27 04:54:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (old)
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
g_free (old);
|
1998-02-27 04:54:42 +00:00
|
|
|
old = exp;
|
|
|
|
|
2001-06-05 22:49:15 +00:00
|
|
|
#ifdef HAVE_CHARSET
|
|
|
|
convert_from_input( exp );
|
|
|
|
#endif
|
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
view->direction = direction;
|
|
|
|
do_normal_search (view, exp);
|
|
|
|
view->last_search = do_normal_search;
|
|
|
|
}
|
|
|
|
|
2002-08-27 19:10:54 +00:00
|
|
|
static void
|
1998-02-27 04:54:42 +00:00
|
|
|
normal_search_cmd (WView *view)
|
|
|
|
{
|
|
|
|
normal_search (view, 1);
|
|
|
|
}
|
|
|
|
|
1998-12-02 21:27:27 +00:00
|
|
|
static void
|
1998-02-27 04:54:42 +00:00
|
|
|
change_viewer (WView *view)
|
|
|
|
{
|
I improved the movement keys of the internal viewer a little bit.
Now in wrap mode the End key and cursor up key behave much better
(e.g. when viewing binary files with lots of wrapped lines).
It's not perfekt but it's better than it used to be.
Tue Apr 28 06:52:24 1998 Norbert Warmuth <k3190@fh-sw.de>
* gnome/gcmd.c (gnome_open_terminal): Changed my_system(1,...) to
my_system(EXECUTE_AS_SHELL,...)
Tue Apr 28 06:06:03 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/extfs.c (extfs_open, extfs_close): Changed my_system(1,...)
to my_system(EXECUTE_AS_SHELL,...), this fixes the broken copyin and
copyout in 4.1.32.
Tue Apr 28 06:11:08 1998 Norbert Warmuth <k3190@fh-sw.de>
* view.c (toggle_wrap_mode, toggle_hex_mode): Force recalculation
of bottom_first (we mustn't use an already calculated and cached
value because it is invalid for the new mode and the End key would
not move to the end of the file).
* configure.in: Renamed the option `--with-our-slang' to
`--with-included-slang' (this one looks better because we also
have an `--with-included-gettext').
Make the option `--with-ext2undel' recognice a given path.
* cmd.c (view_file_at_line): In plain view (F13) set the default
magic flag to zero in order to view the file content unprocessed
(esp. don't uncompress files if they are compressed). The
view_simple_cmd got broken when the default magic flag in view.c
was changed from 0 to 1.
* view.c (do_view_init, goto_line): Set wrap mode temporary off
to make goto line number work, i.e. `line number' now always means
line number in file and not line number on screen (in wrap mode
one long line wrapped once is displayed in two lines on the screen).
That's important when the viewer is invoked from the find file
dialog to display even in wrap mode approxiamtly the part of the
file where we found the content we searched for.
(move_forward2): In wrap mode lines were sometimes counted wrong
causing cursor up to move more than one line.
(move_backward2): Fixed the movement in wrap mode.
(change_viewer): Always re-init viewer when we have a filename,
i. e. if the viewer is invoked with simple_view_cmd then we can switch
with the F8 key between unprocessed file content und uncompressed
file content.
(view_init): re-init view also when magic flag was altered
1998-04-28 14:19:48 +00:00
|
|
|
char *s;
|
|
|
|
char *t;
|
1998-02-27 04:54:42 +00:00
|
|
|
|
|
|
|
|
I improved the movement keys of the internal viewer a little bit.
Now in wrap mode the End key and cursor up key behave much better
(e.g. when viewing binary files with lots of wrapped lines).
It's not perfekt but it's better than it used to be.
Tue Apr 28 06:52:24 1998 Norbert Warmuth <k3190@fh-sw.de>
* gnome/gcmd.c (gnome_open_terminal): Changed my_system(1,...) to
my_system(EXECUTE_AS_SHELL,...)
Tue Apr 28 06:06:03 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/extfs.c (extfs_open, extfs_close): Changed my_system(1,...)
to my_system(EXECUTE_AS_SHELL,...), this fixes the broken copyin and
copyout in 4.1.32.
Tue Apr 28 06:11:08 1998 Norbert Warmuth <k3190@fh-sw.de>
* view.c (toggle_wrap_mode, toggle_hex_mode): Force recalculation
of bottom_first (we mustn't use an already calculated and cached
value because it is invalid for the new mode and the End key would
not move to the end of the file).
* configure.in: Renamed the option `--with-our-slang' to
`--with-included-slang' (this one looks better because we also
have an `--with-included-gettext').
Make the option `--with-ext2undel' recognice a given path.
* cmd.c (view_file_at_line): In plain view (F13) set the default
magic flag to zero in order to view the file content unprocessed
(esp. don't uncompress files if they are compressed). The
view_simple_cmd got broken when the default magic flag in view.c
was changed from 0 to 1.
* view.c (do_view_init, goto_line): Set wrap mode temporary off
to make goto line number work, i.e. `line number' now always means
line number in file and not line number on screen (in wrap mode
one long line wrapped once is displayed in two lines on the screen).
That's important when the viewer is invoked from the find file
dialog to display even in wrap mode approxiamtly the part of the
file where we found the content we searched for.
(move_forward2): In wrap mode lines were sometimes counted wrong
causing cursor up to move more than one line.
(move_backward2): Fixed the movement in wrap mode.
(change_viewer): Always re-init viewer when we have a filename,
i. e. if the viewer is invoked with simple_view_cmd then we can switch
with the F8 key between unprocessed file content und uncompressed
file content.
(view_init): re-init view also when magic flag was altered
1998-04-28 14:19:48 +00:00
|
|
|
if (*view->filename) {
|
|
|
|
altered_magic_flag = 1;
|
|
|
|
view->viewer_magic_flag = !view->viewer_magic_flag;
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
s = g_strdup (view->filename);
|
I improved the movement keys of the internal viewer a little bit.
Now in wrap mode the End key and cursor up key behave much better
(e.g. when viewing binary files with lots of wrapped lines).
It's not perfekt but it's better than it used to be.
Tue Apr 28 06:52:24 1998 Norbert Warmuth <k3190@fh-sw.de>
* gnome/gcmd.c (gnome_open_terminal): Changed my_system(1,...) to
my_system(EXECUTE_AS_SHELL,...)
Tue Apr 28 06:06:03 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/extfs.c (extfs_open, extfs_close): Changed my_system(1,...)
to my_system(EXECUTE_AS_SHELL,...), this fixes the broken copyin and
copyout in 4.1.32.
Tue Apr 28 06:11:08 1998 Norbert Warmuth <k3190@fh-sw.de>
* view.c (toggle_wrap_mode, toggle_hex_mode): Force recalculation
of bottom_first (we mustn't use an already calculated and cached
value because it is invalid for the new mode and the End key would
not move to the end of the file).
* configure.in: Renamed the option `--with-our-slang' to
`--with-included-slang' (this one looks better because we also
have an `--with-included-gettext').
Make the option `--with-ext2undel' recognice a given path.
* cmd.c (view_file_at_line): In plain view (F13) set the default
magic flag to zero in order to view the file content unprocessed
(esp. don't uncompress files if they are compressed). The
view_simple_cmd got broken when the default magic flag in view.c
was changed from 0 to 1.
* view.c (do_view_init, goto_line): Set wrap mode temporary off
to make goto line number work, i.e. `line number' now always means
line number in file and not line number on screen (in wrap mode
one long line wrapped once is displayed in two lines on the screen).
That's important when the viewer is invoked from the find file
dialog to display even in wrap mode approxiamtly the part of the
file where we found the content we searched for.
(move_forward2): In wrap mode lines were sometimes counted wrong
causing cursor up to move more than one line.
(move_backward2): Fixed the movement in wrap mode.
(change_viewer): Always re-init viewer when we have a filename,
i. e. if the viewer is invoked with simple_view_cmd then we can switch
with the F8 key between unprocessed file content und uncompressed
file content.
(view_init): re-init view also when magic flag was altered
1998-04-28 14:19:48 +00:00
|
|
|
if (view->command)
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
t = g_strdup (view->command);
|
I improved the movement keys of the internal viewer a little bit.
Now in wrap mode the End key and cursor up key behave much better
(e.g. when viewing binary files with lots of wrapped lines).
It's not perfekt but it's better than it used to be.
Tue Apr 28 06:52:24 1998 Norbert Warmuth <k3190@fh-sw.de>
* gnome/gcmd.c (gnome_open_terminal): Changed my_system(1,...) to
my_system(EXECUTE_AS_SHELL,...)
Tue Apr 28 06:06:03 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/extfs.c (extfs_open, extfs_close): Changed my_system(1,...)
to my_system(EXECUTE_AS_SHELL,...), this fixes the broken copyin and
copyout in 4.1.32.
Tue Apr 28 06:11:08 1998 Norbert Warmuth <k3190@fh-sw.de>
* view.c (toggle_wrap_mode, toggle_hex_mode): Force recalculation
of bottom_first (we mustn't use an already calculated and cached
value because it is invalid for the new mode and the End key would
not move to the end of the file).
* configure.in: Renamed the option `--with-our-slang' to
`--with-included-slang' (this one looks better because we also
have an `--with-included-gettext').
Make the option `--with-ext2undel' recognice a given path.
* cmd.c (view_file_at_line): In plain view (F13) set the default
magic flag to zero in order to view the file content unprocessed
(esp. don't uncompress files if they are compressed). The
view_simple_cmd got broken when the default magic flag in view.c
was changed from 0 to 1.
* view.c (do_view_init, goto_line): Set wrap mode temporary off
to make goto line number work, i.e. `line number' now always means
line number in file and not line number on screen (in wrap mode
one long line wrapped once is displayed in two lines on the screen).
That's important when the viewer is invoked from the find file
dialog to display even in wrap mode approxiamtly the part of the
file where we found the content we searched for.
(move_forward2): In wrap mode lines were sometimes counted wrong
causing cursor up to move more than one line.
(move_backward2): Fixed the movement in wrap mode.
(change_viewer): Always re-init viewer when we have a filename,
i. e. if the viewer is invoked with simple_view_cmd then we can switch
with the F8 key between unprocessed file content und uncompressed
file content.
(view_init): re-init view also when magic flag was altered
1998-04-28 14:19:48 +00:00
|
|
|
else
|
|
|
|
t = 0;
|
|
|
|
|
|
|
|
view_done (view);
|
1998-02-27 04:54:42 +00:00
|
|
|
view_init (view, t, s, 0);
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
g_free (s);
|
I improved the movement keys of the internal viewer a little bit.
Now in wrap mode the End key and cursor up key behave much better
(e.g. when viewing binary files with lots of wrapped lines).
It's not perfekt but it's better than it used to be.
Tue Apr 28 06:52:24 1998 Norbert Warmuth <k3190@fh-sw.de>
* gnome/gcmd.c (gnome_open_terminal): Changed my_system(1,...) to
my_system(EXECUTE_AS_SHELL,...)
Tue Apr 28 06:06:03 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/extfs.c (extfs_open, extfs_close): Changed my_system(1,...)
to my_system(EXECUTE_AS_SHELL,...), this fixes the broken copyin and
copyout in 4.1.32.
Tue Apr 28 06:11:08 1998 Norbert Warmuth <k3190@fh-sw.de>
* view.c (toggle_wrap_mode, toggle_hex_mode): Force recalculation
of bottom_first (we mustn't use an already calculated and cached
value because it is invalid for the new mode and the End key would
not move to the end of the file).
* configure.in: Renamed the option `--with-our-slang' to
`--with-included-slang' (this one looks better because we also
have an `--with-included-gettext').
Make the option `--with-ext2undel' recognice a given path.
* cmd.c (view_file_at_line): In plain view (F13) set the default
magic flag to zero in order to view the file content unprocessed
(esp. don't uncompress files if they are compressed). The
view_simple_cmd got broken when the default magic flag in view.c
was changed from 0 to 1.
* view.c (do_view_init, goto_line): Set wrap mode temporary off
to make goto line number work, i.e. `line number' now always means
line number in file and not line number on screen (in wrap mode
one long line wrapped once is displayed in two lines on the screen).
That's important when the viewer is invoked from the find file
dialog to display even in wrap mode approxiamtly the part of the
file where we found the content we searched for.
(move_forward2): In wrap mode lines were sometimes counted wrong
causing cursor up to move more than one line.
(move_backward2): Fixed the movement in wrap mode.
(change_viewer): Always re-init viewer when we have a filename,
i. e. if the viewer is invoked with simple_view_cmd then we can switch
with the F8 key between unprocessed file content und uncompressed
file content.
(view_init): re-init view also when magic flag was altered
1998-04-28 14:19:48 +00:00
|
|
|
if (t)
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
g_free (t);
|
I improved the movement keys of the internal viewer a little bit.
Now in wrap mode the End key and cursor up key behave much better
(e.g. when viewing binary files with lots of wrapped lines).
It's not perfekt but it's better than it used to be.
Tue Apr 28 06:52:24 1998 Norbert Warmuth <k3190@fh-sw.de>
* gnome/gcmd.c (gnome_open_terminal): Changed my_system(1,...) to
my_system(EXECUTE_AS_SHELL,...)
Tue Apr 28 06:06:03 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/extfs.c (extfs_open, extfs_close): Changed my_system(1,...)
to my_system(EXECUTE_AS_SHELL,...), this fixes the broken copyin and
copyout in 4.1.32.
Tue Apr 28 06:11:08 1998 Norbert Warmuth <k3190@fh-sw.de>
* view.c (toggle_wrap_mode, toggle_hex_mode): Force recalculation
of bottom_first (we mustn't use an already calculated and cached
value because it is invalid for the new mode and the End key would
not move to the end of the file).
* configure.in: Renamed the option `--with-our-slang' to
`--with-included-slang' (this one looks better because we also
have an `--with-included-gettext').
Make the option `--with-ext2undel' recognice a given path.
* cmd.c (view_file_at_line): In plain view (F13) set the default
magic flag to zero in order to view the file content unprocessed
(esp. don't uncompress files if they are compressed). The
view_simple_cmd got broken when the default magic flag in view.c
was changed from 0 to 1.
* view.c (do_view_init, goto_line): Set wrap mode temporary off
to make goto line number work, i.e. `line number' now always means
line number in file and not line number on screen (in wrap mode
one long line wrapped once is displayed in two lines on the screen).
That's important when the viewer is invoked from the find file
dialog to display even in wrap mode approxiamtly the part of the
file where we found the content we searched for.
(move_forward2): In wrap mode lines were sometimes counted wrong
causing cursor up to move more than one line.
(move_backward2): Fixed the movement in wrap mode.
(change_viewer): Always re-init viewer when we have a filename,
i. e. if the viewer is invoked with simple_view_cmd then we can switch
with the F8 key between unprocessed file content und uncompressed
file content.
(view_init): re-init view also when magic flag was altered
1998-04-28 14:19:48 +00:00
|
|
|
view_labels (view);
|
|
|
|
view->dirty++;
|
1999-02-26 07:26:40 +00:00
|
|
|
view_update (view, TRUE);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-27 19:10:54 +00:00
|
|
|
static void
|
1998-02-27 04:54:42 +00:00
|
|
|
change_nroff (WView *view)
|
|
|
|
{
|
|
|
|
view->viewer_nroff_flag = !view->viewer_nroff_flag;
|
|
|
|
altered_nroff_flag = 1;
|
|
|
|
view_labels (view);
|
|
|
|
view->dirty++;
|
1999-02-26 07:26:40 +00:00
|
|
|
view_update (view, TRUE);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Real view only */
|
|
|
|
static void
|
1998-03-13 03:44:54 +00:00
|
|
|
view_quit_cmd (WView *view)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
|
|
|
if (view_ok_to_quit (view))
|
1998-05-05 06:18:55 +00:00
|
|
|
dlg_stop (view->widget.parent);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Both views */
|
2002-08-27 19:10:54 +00:00
|
|
|
static void
|
1998-02-27 04:54:42 +00:00
|
|
|
view_labels (WView *view)
|
|
|
|
{
|
|
|
|
Dlg_head *h = view->widget.parent;
|
|
|
|
|
2001-08-07 16:53:55 +00:00
|
|
|
define_label (h, (Widget *) view, 1, _("Help"), view_help_cmd);
|
1998-02-27 04:54:42 +00:00
|
|
|
|
1998-03-25 05:16:00 +00:00
|
|
|
my_define (h, 10, _("Quit"), view_quit_cmd, view);
|
|
|
|
my_define (h, 4, view->hex_mode ? _("Ascii"): _("Hex"), toggle_hex_mode, view);
|
1999-06-24 21:53:40 +00:00
|
|
|
my_define (h, 5, view->hex_mode ? _("Goto") : _("Line"),
|
|
|
|
view->hex_mode ? goto_addr : goto_line,
|
|
|
|
view);
|
1998-03-25 05:16:00 +00:00
|
|
|
my_define (h, 6, view->hex_mode ? _("Save") : _("RxSrch"), regexp_search_cmd, view);
|
1998-02-27 04:54:42 +00:00
|
|
|
|
|
|
|
my_define (h, 2, view->hex_mode ? view->hexedit_mode ?
|
1998-03-25 05:16:00 +00:00
|
|
|
view->view_side == view_side_left ? _("EdText") : _("EdHex") :
|
|
|
|
view->growing_buffer ? "" : _("Edit") :
|
|
|
|
view->wrap_mode ? _("UnWrap") : _("Wrap"),
|
1998-02-27 04:54:42 +00:00
|
|
|
toggle_wrap_mode, view);
|
|
|
|
|
1998-03-25 05:16:00 +00:00
|
|
|
my_define (h, 7, view->hex_mode ? _("HxSrch") : _("Search"),
|
1998-02-27 04:54:42 +00:00
|
|
|
normal_search_cmd, view);
|
|
|
|
|
1998-03-25 05:16:00 +00:00
|
|
|
my_define (h, 8, view->viewer_magic_flag ? _("Raw") : _("Parse"),
|
1998-02-27 04:54:42 +00:00
|
|
|
change_viewer, view);
|
|
|
|
|
|
|
|
if (!view->have_frame){
|
1998-03-25 05:16:00 +00:00
|
|
|
my_define (h, 9, view->viewer_nroff_flag ? _("Unform") : _("Format"),
|
1998-02-27 04:54:42 +00:00
|
|
|
change_nroff, view);
|
1998-03-25 05:16:00 +00:00
|
|
|
my_define (h, 3, _("Quit"), view_quit_cmd, view);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
redraw_labels (h, (Widget *) view);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Both views */
|
|
|
|
static int
|
|
|
|
check_left_right_keys (WView *view, int c)
|
|
|
|
{
|
|
|
|
if (c == KEY_LEFT)
|
|
|
|
move_left (view);
|
|
|
|
else if (c == KEY_RIGHT)
|
|
|
|
move_right (view);
|
|
|
|
else return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-08-27 19:10:54 +00:00
|
|
|
static void
|
1998-02-27 04:54:42 +00:00
|
|
|
set_monitor (WView *view, int set_on)
|
|
|
|
{
|
|
|
|
int old = view->monitor;
|
|
|
|
|
|
|
|
view->monitor = set_on;
|
|
|
|
|
|
|
|
if (view->monitor){
|
|
|
|
move_to_bottom (view);
|
|
|
|
view->bottom_first = -1;
|
|
|
|
set_idle_proc (view->widget.parent, 1);
|
|
|
|
} else {
|
|
|
|
if (old)
|
|
|
|
set_idle_proc (view->widget.parent, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-27 19:10:54 +00:00
|
|
|
static void
|
1998-03-14 00:42:23 +00:00
|
|
|
continue_search (WView *view)
|
|
|
|
{
|
|
|
|
if (view->last_search){
|
|
|
|
(*view->last_search)(view, view->search_exp);
|
|
|
|
} else {
|
|
|
|
/* if not... then ask for an expression */
|
|
|
|
normal_search (view, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
/* Both views */
|
|
|
|
static int
|
|
|
|
view_handle_key (WView *view, int c)
|
|
|
|
{
|
|
|
|
int prev_monitor = view->monitor;
|
|
|
|
|
|
|
|
set_monitor (view, off);
|
2001-06-05 22:49:15 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CHARSET
|
|
|
|
if (c >= 128 && c <= 255) {
|
2001-08-19 17:41:38 +00:00
|
|
|
c = conv_input[ c ];
|
2001-06-05 22:49:15 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
if (view->hex_mode) {
|
|
|
|
switch (c) {
|
|
|
|
case 0x09: /* Tab key */
|
|
|
|
view->view_side = 1 - view->view_side;
|
|
|
|
view->dirty++;
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case XCTRL('a'): /* Beginning of line */
|
|
|
|
view->edit_cursor -= view->edit_cursor % view->bytes_per_line;
|
|
|
|
view->dirty++;
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case XCTRL('b'): /* Character back */
|
|
|
|
move_left(view);
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case XCTRL('e'): /* End of line */
|
|
|
|
view->edit_cursor -= view->edit_cursor % view->bytes_per_line;
|
|
|
|
view->edit_cursor += view->bytes_per_line - 1;
|
|
|
|
view->dirty++;
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case XCTRL('f'): /* Character forward */
|
|
|
|
move_right(view);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Trap 0-9,A-F,a-f for left side data entry (hex editing) */
|
|
|
|
if (view->view_side == view_side_left){
|
|
|
|
if ((c >= '0' && c <= '9') ||
|
|
|
|
(c >= 'A' && c <= 'F') ||
|
|
|
|
(c >= 'a' && c <= 'f')){
|
|
|
|
|
|
|
|
put_editkey (view, c);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Trap all printable characters for right side data entry */
|
|
|
|
/* Also enter the value of the Enter key */
|
|
|
|
if (view->view_side == view_side_right){
|
|
|
|
if (c < 256 && (is_printable (c) || (c == '\n'))){
|
|
|
|
put_editkey(view, c);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (check_left_right_keys (view, c))
|
|
|
|
return 1;
|
|
|
|
|
1998-04-16 02:45:53 +00:00
|
|
|
if (check_movement_keys (c, 1, vheight, view, (movefn) view_move_backward, (movefn) view_move_forward,
|
1998-02-27 04:54:42 +00:00
|
|
|
(movefn) move_to_top, (movefn) move_to_bottom)){
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
switch (c){
|
|
|
|
|
|
|
|
case '?':
|
|
|
|
regexp_search (view, -1);
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case '/':
|
|
|
|
regexp_search (view, 1);
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* Continue search */
|
|
|
|
case XCTRL('s'):
|
|
|
|
case 'n':
|
|
|
|
case KEY_F(17):
|
1998-03-14 00:42:23 +00:00
|
|
|
continue_search (view);
|
1998-02-27 04:54:42 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
case XCTRL('r'):
|
|
|
|
if (view->last_search){
|
|
|
|
(*view->last_search)(view, view->search_exp);
|
|
|
|
} else {
|
|
|
|
normal_search (view, -1);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* toggle ruler */
|
|
|
|
case ALT('r'):
|
|
|
|
switch (ruler){
|
|
|
|
case 0:
|
|
|
|
ruler = 1; break;
|
|
|
|
case 1:
|
|
|
|
ruler = 2; break;
|
|
|
|
default:
|
|
|
|
ruler = 0; break;
|
|
|
|
}
|
|
|
|
view->dirty++;
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case 'h':
|
|
|
|
move_left (view);
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case 'j':
|
|
|
|
case '\n':
|
|
|
|
case 'e':
|
1998-04-16 02:45:53 +00:00
|
|
|
view_move_forward (view, 1);
|
1998-02-27 04:54:42 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
case 'd':
|
1998-04-16 02:45:53 +00:00
|
|
|
view_move_forward (view, vheight / 2);
|
1998-02-27 04:54:42 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
case 'u':
|
1998-04-16 02:45:53 +00:00
|
|
|
view_move_backward (view, vheight / 2);
|
1998-02-27 04:54:42 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
case 'k':
|
|
|
|
case 'y':
|
1998-04-16 02:45:53 +00:00
|
|
|
view_move_backward (view, 1);
|
1998-02-27 04:54:42 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
case 'l':
|
|
|
|
move_right (view);
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case ' ':
|
|
|
|
case 'f':
|
1998-04-16 02:45:53 +00:00
|
|
|
view_move_forward (view, vheight - 1);
|
1998-02-27 04:54:42 +00:00
|
|
|
return 1;
|
|
|
|
|
2001-08-07 16:32:22 +00:00
|
|
|
case XCTRL('o'):
|
|
|
|
view_other_cmd ();
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* Unlike Ctrl-O, run a new shell if the subshell is not running. */
|
1998-02-27 04:54:42 +00:00
|
|
|
case '!':
|
|
|
|
exec_shell ();
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case 'F':
|
|
|
|
set_monitor (view, on);
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case 'b':
|
1998-04-16 02:45:53 +00:00
|
|
|
view_move_backward (view, vheight - 1);
|
1998-02-27 04:54:42 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
case KEY_IC:
|
1998-04-16 02:45:53 +00:00
|
|
|
view_move_backward (view, 2);
|
1998-02-27 04:54:42 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
case KEY_DC:
|
1998-04-16 02:45:53 +00:00
|
|
|
view_move_forward (view, 2);
|
1998-02-27 04:54:42 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
case 'm':
|
|
|
|
view->marks [view->marker] = view->start_display;
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case 'r':
|
|
|
|
view->start_display = view->marks [view->marker];
|
|
|
|
view->dirty++;
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* Use to indicate parent that we want to see the next/previous file */
|
|
|
|
/* Only works on full screen mode */
|
|
|
|
case XCTRL('f'):
|
|
|
|
case XCTRL('b'):
|
|
|
|
if (!view->have_frame)
|
|
|
|
view->move_dir = c == XCTRL('f') ? 1 : -1;
|
|
|
|
/* fall */
|
|
|
|
|
|
|
|
case 'q':
|
|
|
|
case XCTRL('g'):
|
|
|
|
case ESC_CHAR:
|
|
|
|
if (view_ok_to_quit (view))
|
|
|
|
view->view_quit = 1;
|
|
|
|
return 1;
|
|
|
|
|
2001-06-05 22:49:15 +00:00
|
|
|
#ifdef HAVE_CHARSET
|
|
|
|
case XCTRL('t'):
|
|
|
|
do_select_codepage();
|
|
|
|
view->dirty++;
|
|
|
|
view_update( view, TRUE );
|
|
|
|
return 1;
|
2001-09-16 01:22:12 +00:00
|
|
|
#endif /* HAVE_CHARSET */
|
2001-06-05 22:49:15 +00:00
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
if (c >= '0' && c <= '9')
|
|
|
|
view->marker = c - '0';
|
|
|
|
|
|
|
|
/* Restore the monitor status */
|
|
|
|
set_monitor (view, prev_monitor);
|
|
|
|
|
|
|
|
/* Key not used */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Both views */
|
2002-08-27 19:10:54 +00:00
|
|
|
static int
|
2002-09-21 05:46:19 +00:00
|
|
|
view_event (WView * view, Gpm_Event * event, int *result)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
|
|
|
*result = MOU_NORMAL;
|
2002-09-21 05:46:19 +00:00
|
|
|
|
|
|
|
/* We are not interested in the release events */
|
|
|
|
if (!(event->type & (GPM_DOWN | GPM_DRAG)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Wheel events */
|
|
|
|
if ((event->buttons & GPM_B_UP) && (event->type & GPM_DOWN)) {
|
|
|
|
view_move_backward (view, 2);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if ((event->buttons & GPM_B_DOWN) && (event->type & GPM_DOWN)) {
|
|
|
|
view_move_forward (view, 2);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Scrolling left and right */
|
|
|
|
if (!view->wrap_mode) {
|
|
|
|
if (event->x < view->widget.cols / 4) {
|
|
|
|
move_left (view);
|
|
|
|
goto processed;
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
2002-09-21 05:46:19 +00:00
|
|
|
if (event->x > 3 * vwidth / 4) {
|
|
|
|
move_right (view);
|
|
|
|
goto processed;
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
}
|
2002-09-21 05:46:19 +00:00
|
|
|
|
|
|
|
/* Scrolling up and down */
|
|
|
|
if (event->y < view->widget.lines / 3) {
|
|
|
|
if (mouse_move_pages_viewer)
|
|
|
|
view_move_backward (view, view->widget.lines / 2 - 1);
|
|
|
|
else
|
|
|
|
view_move_backward (view, 1);
|
|
|
|
goto processed;
|
|
|
|
} else if (event->y > 2 * vheight / 3) {
|
|
|
|
if (mouse_move_pages_viewer)
|
|
|
|
view_move_forward (view, vheight / 2 - 1);
|
|
|
|
else
|
|
|
|
view_move_forward (view, 1);
|
|
|
|
goto processed;
|
|
|
|
}
|
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
return 0;
|
2002-09-21 05:46:19 +00:00
|
|
|
|
|
|
|
processed:
|
|
|
|
*result = MOU_REPEAT;
|
|
|
|
return 1;
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Real view only */
|
1998-12-02 21:27:27 +00:00
|
|
|
static int
|
1998-02-27 04:54:42 +00:00
|
|
|
real_view_event (Gpm_Event *event, void *x)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
if (view_event ((WView *) x, event, &result))
|
1999-02-26 07:26:40 +00:00
|
|
|
view_update ((WView *) x, TRUE);
|
1998-02-27 04:54:42 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
/* {{{ Window creation, destruction and a driver stub for real view */
|
|
|
|
|
2002-10-07 18:50:27 +00:00
|
|
|
static void
|
1998-02-27 04:54:42 +00:00
|
|
|
view_adjust_size (Dlg_head *h)
|
|
|
|
{
|
|
|
|
WView *view;
|
|
|
|
WButtonBar *bar;
|
|
|
|
|
|
|
|
/* Look up the viewer and the buttonbar, we assume only two widgets here */
|
|
|
|
view = (WView *) find_widget_type (h, (callback_fn) view_callback);
|
|
|
|
bar = (WButtonBar *) view->widget.parent->current->next->widget;
|
|
|
|
widget_set_size (&view->widget, 0, 0, LINES-1, COLS);
|
|
|
|
widget_set_size (&bar->widget, LINES-1, 0, 1, COLS);
|
1999-04-06 19:00:16 +00:00
|
|
|
|
|
|
|
view_update_bytes_per_line(view);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
2002-09-24 03:56:08 +00:00
|
|
|
/* Callback for the view dialog */
|
|
|
|
static int
|
|
|
|
view_dialog_callback (Dlg_head * h, int id, int msg)
|
|
|
|
{
|
|
|
|
switch (msg) {
|
|
|
|
case DLG_RESIZE:
|
|
|
|
view_adjust_size (h);
|
|
|
|
return MSG_HANDLED;
|
|
|
|
}
|
|
|
|
return default_dlg_callback (h, id, msg);
|
|
|
|
}
|
1998-03-12 03:29:45 +00:00
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
/* Real view only */
|
|
|
|
int
|
2000-04-18 08:58:42 +00:00
|
|
|
view (char *_command, const char *_file, int *move_dir_p, int start_line)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
WView *wview;
|
|
|
|
WButtonBar *bar;
|
2002-09-24 03:56:08 +00:00
|
|
|
Dlg_head *view_dlg;
|
2002-09-03 20:19:22 +00:00
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
/* Create dialog and widgets, put them on the dialog */
|
2002-09-24 03:56:08 +00:00
|
|
|
view_dlg =
|
|
|
|
create_dlg (0, 0, LINES, COLS, NULL, view_dialog_callback,
|
2002-09-03 20:19:22 +00:00
|
|
|
"[Internal File Viewer]", NULL, DLG_NONE);
|
1998-02-27 04:54:42 +00:00
|
|
|
|
2002-09-03 20:19:22 +00:00
|
|
|
wview = view_new (0, 0, COLS, LINES - 1, 0);
|
1998-02-27 04:54:42 +00:00
|
|
|
|
2002-09-03 20:19:22 +00:00
|
|
|
bar = buttonbar_new (1);
|
1998-02-27 04:54:42 +00:00
|
|
|
|
2002-09-24 03:56:08 +00:00
|
|
|
add_widget (view_dlg, wview);
|
|
|
|
add_widget (view_dlg, bar);
|
1998-02-27 04:54:42 +00:00
|
|
|
|
|
|
|
error = view_init (wview, _command, _file, start_line);
|
|
|
|
if (move_dir_p)
|
|
|
|
*move_dir_p = 0;
|
|
|
|
|
|
|
|
/* Please note that if you add another widget,
|
|
|
|
* you have to modify view_adjust_size to
|
|
|
|
* be aware of it
|
|
|
|
*/
|
2002-09-03 20:19:22 +00:00
|
|
|
if (!error) {
|
2002-09-24 03:56:08 +00:00
|
|
|
run_dlg (view_dlg);
|
1998-02-27 04:54:42 +00:00
|
|
|
if (move_dir_p)
|
|
|
|
*move_dir_p = wview->move_dir;
|
|
|
|
}
|
2002-09-24 03:56:08 +00:00
|
|
|
destroy_dlg (view_dlg);
|
2002-09-03 20:19:22 +00:00
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
return !error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
view_hook (void *v)
|
|
|
|
{
|
|
|
|
WView *view = (WView *) v;
|
|
|
|
WPanel *panel;
|
|
|
|
|
|
|
|
/* If the user is busy typing, wait until he finishes to update the
|
|
|
|
screen */
|
|
|
|
if (!is_idle ()){
|
|
|
|
if (!hook_present (idle_hook, view_hook))
|
|
|
|
add_hook (&idle_hook, view_hook, v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete_hook (&idle_hook, view_hook);
|
|
|
|
|
|
|
|
if (get_current_type () == view_listing)
|
|
|
|
panel = cpanel;
|
|
|
|
else if (get_other_type () == view_listing)
|
|
|
|
panel = other_panel;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
view_init (view, 0, panel->dir.list [panel->selected].fname, 0);
|
|
|
|
display (view);
|
1999-02-26 07:26:40 +00:00
|
|
|
view_status (view, TRUE);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-04-18 08:58:42 +00:00
|
|
|
view_callback (Dlg_head *h, WView *view, int msg, int par)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
|
|
|
int i;
|
2002-10-07 18:50:27 +00:00
|
|
|
|
|
|
|
switch (msg) {
|
1998-02-27 04:54:42 +00:00
|
|
|
case WIDGET_INIT:
|
2002-10-07 18:50:27 +00:00
|
|
|
view_update_bytes_per_line (view);
|
1998-02-27 04:54:42 +00:00
|
|
|
if (view->have_frame)
|
|
|
|
add_hook (&select_file_hook, view_hook, view);
|
|
|
|
else
|
|
|
|
view_labels (view);
|
|
|
|
break;
|
2002-10-07 18:50:27 +00:00
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
case WIDGET_DRAW:
|
|
|
|
display (view);
|
1999-02-26 07:26:40 +00:00
|
|
|
view_status (view, TRUE);
|
1998-02-27 04:54:42 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WIDGET_CURSOR:
|
|
|
|
if (view->hex_mode)
|
|
|
|
view_place_cursor (view);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WIDGET_KEY:
|
2002-10-07 18:50:27 +00:00
|
|
|
i = view_handle_key ((WView *) view, par);
|
1998-02-27 04:54:42 +00:00
|
|
|
if (view->view_quit)
|
1998-03-14 00:42:23 +00:00
|
|
|
dlg_stop (h);
|
1998-02-27 04:54:42 +00:00
|
|
|
else {
|
1999-02-26 07:26:40 +00:00
|
|
|
view_update (view, TRUE);
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
return i;
|
|
|
|
|
|
|
|
case WIDGET_IDLE:
|
|
|
|
/* This event is generated when the user is using the 'F' flag */
|
|
|
|
view->bottom_first = -1;
|
|
|
|
move_to_bottom (view);
|
|
|
|
display (view);
|
1999-02-26 07:26:40 +00:00
|
|
|
view_status (view, TRUE);
|
1998-02-27 04:54:42 +00:00
|
|
|
sleep (1);
|
|
|
|
return 1;
|
2002-10-07 18:50:27 +00:00
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
case WIDGET_FOCUS:
|
|
|
|
view_labels (view);
|
|
|
|
return 1;
|
2002-10-07 18:50:27 +00:00
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
return default_proc (h, msg, par);
|
|
|
|
}
|
|
|
|
|
|
|
|
WView *
|
|
|
|
view_new (int y, int x, int cols, int lines, int is_panel)
|
|
|
|
{
|
2001-06-25 11:24:49 +00:00
|
|
|
WView *view = g_new0 (WView, 1);
|
1998-02-27 04:54:42 +00:00
|
|
|
|
|
|
|
init_widget (&view->widget, y, x, lines, cols,
|
|
|
|
(callback_fn) view_callback,
|
|
|
|
(destroy_fn) view_destroy,
|
|
|
|
(mouse_h) real_view_event, NULL);
|
|
|
|
|
|
|
|
view->hex_mode = default_hex_mode;
|
|
|
|
view->hexedit_mode = default_hexedit_mode;
|
|
|
|
view->viewer_magic_flag = default_magic_flag;
|
|
|
|
view->viewer_nroff_flag = default_nroff_flag;
|
|
|
|
view->have_frame = is_panel;
|
|
|
|
view->last_byte = -1;
|
1998-03-14 00:42:23 +00:00
|
|
|
view->wrap_mode = global_wrap_mode;
|
1998-03-12 03:29:45 +00:00
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
widget_want_cursor (view->widget, 0);
|
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
/* {{{ Emacs local variables */
|
|
|
|
/*
|
|
|
|
Cause emacs to enter folding mode for this file:
|
|
|
|
Local variables:
|
|
|
|
end:
|
|
|
|
*/
|
|
|
|
/* }}} */
|