Identation of some source files.
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
Этот коммит содержится в:
родитель
cd8b350b6d
Коммит
5354d59337
@ -19,7 +19,8 @@
|
||||
extern gboolean use_colors;
|
||||
extern gboolean mc_tty_color_disable;
|
||||
|
||||
typedef struct mc_color_pair_struct {
|
||||
typedef struct mc_color_pair_struct
|
||||
{
|
||||
const char *cfg;
|
||||
const char *cbg;
|
||||
int ifg;
|
||||
@ -28,12 +29,14 @@ typedef struct mc_color_pair_struct {
|
||||
gboolean is_temp;
|
||||
} tty_color_pair_t;
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
typedef enum {
|
||||
SPEC_A_REVERSE = -100,
|
||||
SPEC_A_BOLD = -101,
|
||||
SPEC_A_BOLD_REVERSE = -102,
|
||||
SPEC_A_UNDERLINE = -103
|
||||
} tty_special_color_t;
|
||||
/* *INDENT-ON* */
|
||||
|
||||
const char *tty_color_get_valid_name (const char *);
|
||||
int tty_color_get_index_by_name (const char *);
|
||||
|
@ -1,13 +1,13 @@
|
||||
/* Color setup.
|
||||
Interface functions.
|
||||
Interface functions.
|
||||
|
||||
Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
|
||||
2007, 2008, 2009 Free Software Foundation, Inc.
|
||||
|
||||
|
||||
Written by:
|
||||
Andrew Borodin <aborodin@vmail.ru>, 2009.
|
||||
Slava Zanko <slavazanko@gmail.com>, 2009.
|
||||
|
||||
|
||||
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
|
||||
@ -96,7 +96,7 @@ static void
|
||||
tty_color_free_all (gboolean is_temp_color)
|
||||
{
|
||||
g_hash_table_foreach_remove (mc_tty_color__hashtable, tty_color_free_condition_cb,
|
||||
(is_temp_color)? (gpointer) 1 : NULL);
|
||||
(is_temp_color) ? (gpointer) 1 : NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -125,7 +125,8 @@ tty_color_get_next__color_pair_number ()
|
||||
size_t cp_count = g_hash_table_size (mc_tty_color__hashtable);
|
||||
size_t cp = 0;
|
||||
|
||||
for (cp = 0; cp < cp_count; cp++) {
|
||||
for (cp = 0; cp < cp_count; cp++)
|
||||
{
|
||||
if (g_hash_table_find (mc_tty_color__hashtable, tty_color_get_next_cpn_cb, (gpointer) cp) ==
|
||||
NULL)
|
||||
return cp;
|
||||
@ -178,7 +179,8 @@ tty_try_alloc_color_pair2 (const char *fg, const char *bg, gboolean is_temp_colo
|
||||
if (fg == NULL)
|
||||
fg = tty_color_defaults__fg;
|
||||
|
||||
if (bg == NULL) {
|
||||
if (bg == NULL)
|
||||
{
|
||||
bg = tty_color_defaults__bg;
|
||||
}
|
||||
c_fg = tty_color_get_valid_name (fg);
|
||||
@ -191,13 +193,15 @@ tty_try_alloc_color_pair2 (const char *fg, const char *bg, gboolean is_temp_colo
|
||||
mc_color_pair =
|
||||
(tty_color_pair_t *) g_hash_table_lookup (mc_tty_color__hashtable, (gpointer) color_pair);
|
||||
|
||||
if (mc_color_pair != NULL) {
|
||||
if (mc_color_pair != NULL)
|
||||
{
|
||||
g_free (color_pair);
|
||||
return mc_color_pair->pair_index;
|
||||
}
|
||||
|
||||
mc_color_pair = g_try_new0 (tty_color_pair_t, 1);
|
||||
if (mc_color_pair == NULL) {
|
||||
if (mc_color_pair == NULL)
|
||||
{
|
||||
g_free (color_pair);
|
||||
return 0;
|
||||
}
|
||||
|
1498
lib/util.c
1498
lib/util.c
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -5,18 +5,18 @@
|
||||
|
||||
Parts of this program were taken from the lsdel.c and dump.c files
|
||||
written by Ted Ts'o (tytso@mit.edu) for the ext2fs package.
|
||||
|
||||
|
||||
Copyright (C) 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
||||
2005, 2007 Free Software Foundation, Inc.
|
||||
Written by: 1995 Miguel de Icaza.
|
||||
1997 Norbert Warmuth.
|
||||
2000 Pavel Machek
|
||||
|
||||
1997 Norbert Warmuth.
|
||||
2000 Pavel Machek
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library 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
|
||||
@ -37,7 +37,7 @@
|
||||
* because we would have to provide an io_manager for the ext2fs tools,
|
||||
* and I don't think it would be too useful to undelete files
|
||||
*/
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
@ -57,35 +57,37 @@
|
||||
#include <ctype.h>
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "src/wtools.h" /* message() */
|
||||
#include "src/main.h" /* print_vfs_message */
|
||||
#include "src/wtools.h" /* message() */
|
||||
#include "src/main.h" /* print_vfs_message */
|
||||
#include "utilvfs.h"
|
||||
#include "vfs.h"
|
||||
#include "vfs-impl.h"
|
||||
|
||||
struct deleted_info {
|
||||
ext2_ino_t ino;
|
||||
struct deleted_info
|
||||
{
|
||||
ext2_ino_t ino;
|
||||
unsigned short mode;
|
||||
unsigned short uid;
|
||||
unsigned short gid;
|
||||
unsigned long size;
|
||||
time_t dtime;
|
||||
int num_blocks;
|
||||
int free_blocks;
|
||||
time_t dtime;
|
||||
int num_blocks;
|
||||
int free_blocks;
|
||||
};
|
||||
|
||||
struct lsdel_struct {
|
||||
ext2_ino_t inode;
|
||||
int num_blocks;
|
||||
int free_blocks;
|
||||
int bad_blocks;
|
||||
struct lsdel_struct
|
||||
{
|
||||
ext2_ino_t inode;
|
||||
int num_blocks;
|
||||
int free_blocks;
|
||||
int bad_blocks;
|
||||
};
|
||||
|
||||
/* We only allow one opened ext2fs */
|
||||
static char *ext2_fname;
|
||||
static ext2_filsys fs = NULL;
|
||||
static struct lsdel_struct lsd;
|
||||
static struct deleted_info *delarray;
|
||||
static struct lsdel_struct lsd;
|
||||
static struct deleted_info *delarray;
|
||||
static int num_delarray, max_delarray;
|
||||
static char *block_buf;
|
||||
static const char *undelfserr = N_(" undelfs: error ");
|
||||
@ -100,7 +102,7 @@ static void
|
||||
undelfs_shutdown (void)
|
||||
{
|
||||
if (fs)
|
||||
ext2fs_close (fs);
|
||||
ext2fs_close (fs);
|
||||
fs = NULL;
|
||||
g_free (ext2_fname);
|
||||
ext2_fname = NULL;
|
||||
@ -118,39 +120,41 @@ undelfs_get_path (const char *dirname, char **fsname, char **file)
|
||||
/* To look like filesystem, we have virtual directories
|
||||
/#undel:XXX, which have no subdirectories. XXX is replaced with
|
||||
hda5, sdb8 etc, which is assumed to live under /dev.
|
||||
-- pavel@ucw.cz */
|
||||
-- pavel@ucw.cz */
|
||||
|
||||
*fsname = NULL;
|
||||
|
||||
if (strncmp (dirname, "/#undel:", 8))
|
||||
return;
|
||||
return;
|
||||
|
||||
dirname += 8;
|
||||
|
||||
/* Since we don't allow subdirectories, it's easy to get a filename,
|
||||
* just scan backwards for a slash */
|
||||
if (*dirname == 0)
|
||||
return;
|
||||
|
||||
return;
|
||||
|
||||
p = dirname + strlen (dirname);
|
||||
#if 0
|
||||
/* Strip trailing ./
|
||||
*/
|
||||
if (p - dirname > 2 && *(p-1) == '/' && *(p-2) == '.')
|
||||
*(p = p-2) = 0;
|
||||
if (p - dirname > 2 && *(p - 1) == '/' && *(p - 2) == '.')
|
||||
*(p = p - 2) = 0;
|
||||
#endif
|
||||
|
||||
while (p > dirname){
|
||||
if (*p == '/'){
|
||||
char *tmp;
|
||||
|
||||
*file = g_strdup (p+1);
|
||||
tmp = g_strndup (dirname, p - dirname);
|
||||
*fsname = g_strconcat ("/dev/", tmp, (char *) NULL);
|
||||
g_free (tmp);
|
||||
return;
|
||||
}
|
||||
p--;
|
||||
while (p > dirname)
|
||||
{
|
||||
if (*p == '/')
|
||||
{
|
||||
char *tmp;
|
||||
|
||||
*file = g_strdup (p + 1);
|
||||
tmp = g_strndup (dirname, p - dirname);
|
||||
*fsname = g_strconcat ("/dev/", tmp, (char *) NULL);
|
||||
g_free (tmp);
|
||||
return;
|
||||
}
|
||||
p--;
|
||||
}
|
||||
*file = g_strdup ("");
|
||||
*fsname = g_strconcat ("/dev/", dirname, (char *) NULL);
|
||||
@ -158,21 +162,21 @@ undelfs_get_path (const char *dirname, char **fsname, char **file)
|
||||
}
|
||||
|
||||
static int
|
||||
undelfs_lsdel_proc(ext2_filsys _fs, blk_t *block_nr, int blockcnt, void *private)
|
||||
undelfs_lsdel_proc (ext2_filsys _fs, blk_t * block_nr, int blockcnt, void *private)
|
||||
{
|
||||
struct lsdel_struct *_lsd = (struct lsdel_struct *) private;
|
||||
(void) blockcnt;
|
||||
_lsd->num_blocks++;
|
||||
|
||||
if (*block_nr < _fs->super->s_first_data_block ||
|
||||
*block_nr >= _fs->super->s_blocks_count) {
|
||||
_lsd->bad_blocks++;
|
||||
return BLOCK_ABORT;
|
||||
|
||||
if (*block_nr < _fs->super->s_first_data_block || *block_nr >= _fs->super->s_blocks_count)
|
||||
{
|
||||
_lsd->bad_blocks++;
|
||||
return BLOCK_ABORT;
|
||||
}
|
||||
|
||||
if (!ext2fs_test_block_bitmap(_fs->block_map,*block_nr))
|
||||
_lsd->free_blocks++;
|
||||
|
||||
|
||||
if (!ext2fs_test_block_bitmap (_fs->block_map, *block_nr))
|
||||
_lsd->free_blocks++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -191,84 +195,84 @@ undelfs_loaddel (void)
|
||||
max_delarray = 100;
|
||||
num_delarray = 0;
|
||||
delarray = g_try_malloc (sizeof (struct deleted_info) * max_delarray);
|
||||
if (!delarray) {
|
||||
message (D_ERROR, undelfserr, _(" not enough memory "));
|
||||
return 0;
|
||||
if (!delarray)
|
||||
{
|
||||
message (D_ERROR, undelfserr, _(" not enough memory "));
|
||||
return 0;
|
||||
}
|
||||
block_buf = g_try_malloc (fs->blocksize * 3);
|
||||
if (!block_buf) {
|
||||
message (D_ERROR, undelfserr, _(" while allocating block buffer "));
|
||||
goto free_delarray;
|
||||
if (!block_buf)
|
||||
{
|
||||
message (D_ERROR, undelfserr, _(" while allocating block buffer "));
|
||||
goto free_delarray;
|
||||
}
|
||||
if ((retval = ext2fs_open_inode_scan (fs, 0, &scan))) {
|
||||
message (D_ERROR, undelfserr, _(" open_inode_scan: %d "), retval);
|
||||
goto free_block_buf;
|
||||
if ((retval = ext2fs_open_inode_scan (fs, 0, &scan)))
|
||||
{
|
||||
message (D_ERROR, undelfserr, _(" open_inode_scan: %d "), retval);
|
||||
goto free_block_buf;
|
||||
}
|
||||
if ((retval = ext2fs_get_next_inode (scan, &ino, &inode))) {
|
||||
message (D_ERROR, undelfserr, _(" while starting inode scan %d "),
|
||||
retval);
|
||||
goto error_out;
|
||||
if ((retval = ext2fs_get_next_inode (scan, &ino, &inode)))
|
||||
{
|
||||
message (D_ERROR, undelfserr, _(" while starting inode scan %d "), retval);
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
count = 0;
|
||||
while (ino) {
|
||||
if ((count++ % 1024) == 0)
|
||||
print_vfs_message (_
|
||||
("undelfs: loading deleted files information %d inodes"),
|
||||
count);
|
||||
if (inode.i_dtime == 0)
|
||||
goto next;
|
||||
while (ino)
|
||||
{
|
||||
if ((count++ % 1024) == 0)
|
||||
print_vfs_message (_("undelfs: loading deleted files information %d inodes"), count);
|
||||
if (inode.i_dtime == 0)
|
||||
goto next;
|
||||
|
||||
if (S_ISDIR (inode.i_mode))
|
||||
goto next;
|
||||
if (S_ISDIR (inode.i_mode))
|
||||
goto next;
|
||||
|
||||
lsd.inode = ino;
|
||||
lsd.num_blocks = 0;
|
||||
lsd.free_blocks = 0;
|
||||
lsd.bad_blocks = 0;
|
||||
lsd.inode = ino;
|
||||
lsd.num_blocks = 0;
|
||||
lsd.free_blocks = 0;
|
||||
lsd.bad_blocks = 0;
|
||||
|
||||
retval =
|
||||
ext2fs_block_iterate (fs, ino, 0, block_buf,
|
||||
undelfs_lsdel_proc, &lsd);
|
||||
if (retval) {
|
||||
message (D_ERROR, undelfserr,
|
||||
_(" while calling ext2_block_iterate %d "), retval);
|
||||
goto next;
|
||||
}
|
||||
if (lsd.free_blocks && !lsd.bad_blocks) {
|
||||
if (num_delarray >= max_delarray) {
|
||||
struct deleted_info *delarray_new =
|
||||
g_try_realloc (delarray,
|
||||
sizeof (struct deleted_info) *
|
||||
(max_delarray + 50));
|
||||
if (!delarray_new) {
|
||||
message (D_ERROR, undelfserr,
|
||||
_
|
||||
(" no more memory while reallocating array "));
|
||||
goto error_out;
|
||||
}
|
||||
delarray = delarray_new;
|
||||
max_delarray += 50;
|
||||
}
|
||||
retval = ext2fs_block_iterate (fs, ino, 0, block_buf, undelfs_lsdel_proc, &lsd);
|
||||
if (retval)
|
||||
{
|
||||
message (D_ERROR, undelfserr, _(" while calling ext2_block_iterate %d "), retval);
|
||||
goto next;
|
||||
}
|
||||
if (lsd.free_blocks && !lsd.bad_blocks)
|
||||
{
|
||||
if (num_delarray >= max_delarray)
|
||||
{
|
||||
struct deleted_info *delarray_new = g_try_realloc (delarray,
|
||||
sizeof (struct deleted_info) *
|
||||
(max_delarray + 50));
|
||||
if (!delarray_new)
|
||||
{
|
||||
message (D_ERROR, undelfserr, _(" no more memory while reallocating array "));
|
||||
goto error_out;
|
||||
}
|
||||
delarray = delarray_new;
|
||||
max_delarray += 50;
|
||||
}
|
||||
|
||||
delarray[num_delarray].ino = ino;
|
||||
delarray[num_delarray].mode = inode.i_mode;
|
||||
delarray[num_delarray].uid = inode.i_uid;
|
||||
delarray[num_delarray].gid = inode.i_gid;
|
||||
delarray[num_delarray].size = inode.i_size;
|
||||
delarray[num_delarray].dtime = inode.i_dtime;
|
||||
delarray[num_delarray].num_blocks = lsd.num_blocks;
|
||||
delarray[num_delarray].free_blocks = lsd.free_blocks;
|
||||
num_delarray++;
|
||||
}
|
||||
delarray[num_delarray].ino = ino;
|
||||
delarray[num_delarray].mode = inode.i_mode;
|
||||
delarray[num_delarray].uid = inode.i_uid;
|
||||
delarray[num_delarray].gid = inode.i_gid;
|
||||
delarray[num_delarray].size = inode.i_size;
|
||||
delarray[num_delarray].dtime = inode.i_dtime;
|
||||
delarray[num_delarray].num_blocks = lsd.num_blocks;
|
||||
delarray[num_delarray].free_blocks = lsd.free_blocks;
|
||||
num_delarray++;
|
||||
}
|
||||
|
||||
next:
|
||||
retval = ext2fs_get_next_inode (scan, &ino, &inode);
|
||||
if (retval) {
|
||||
message (D_ERROR, undelfserr, _(" while doing inode scan %d "),
|
||||
retval);
|
||||
goto error_out;
|
||||
}
|
||||
retval = ext2fs_get_next_inode (scan, &ino, &inode);
|
||||
if (retval)
|
||||
{
|
||||
message (D_ERROR, undelfserr, _(" while doing inode scan %d "), retval);
|
||||
goto error_out;
|
||||
}
|
||||
}
|
||||
readdir_ptr = READDIR_PTR_INIT;
|
||||
ext2fs_close_inode_scan (scan);
|
||||
@ -300,8 +304,7 @@ com_err (const char *whoami, long err_code, const char *fmt, ...)
|
||||
str = g_strdup_vprintf (fmt, ap);
|
||||
va_end (ap);
|
||||
|
||||
message (D_ERROR, _(" Ext2lib error "), " %s (%s: %ld) ", str, whoami,
|
||||
err_code);
|
||||
message (D_ERROR, _(" Ext2lib error "), " %s (%s: %ld) ", str, whoami, err_code);
|
||||
g_free (str);
|
||||
}
|
||||
|
||||
@ -309,46 +312,50 @@ static void *
|
||||
undelfs_opendir (struct vfs_class *me, const char *dirname)
|
||||
{
|
||||
char *file, *f;
|
||||
|
||||
|
||||
undelfs_get_path (dirname, &file, &f);
|
||||
if (!file)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
/* We don't use the file name */
|
||||
g_free (f);
|
||||
|
||||
if (!ext2_fname || strcmp (ext2_fname, file)){
|
||||
undelfs_shutdown ();
|
||||
ext2_fname = file;
|
||||
} else {
|
||||
/* To avoid expensive re-scannings */
|
||||
readdir_ptr = READDIR_PTR_INIT;
|
||||
g_free (file);
|
||||
return fs;
|
||||
|
||||
if (!ext2_fname || strcmp (ext2_fname, file))
|
||||
{
|
||||
undelfs_shutdown ();
|
||||
ext2_fname = file;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* To avoid expensive re-scannings */
|
||||
readdir_ptr = READDIR_PTR_INIT;
|
||||
g_free (file);
|
||||
return fs;
|
||||
}
|
||||
|
||||
if (ext2fs_open (ext2_fname, 0, 0, 0, unix_io_manager, &fs)){
|
||||
message (D_ERROR, undelfserr, _(" Cannot open file %s "), ext2_fname);
|
||||
return 0;
|
||||
if (ext2fs_open (ext2_fname, 0, 0, 0, unix_io_manager, &fs))
|
||||
{
|
||||
message (D_ERROR, undelfserr, _(" Cannot open file %s "), ext2_fname);
|
||||
return 0;
|
||||
}
|
||||
print_vfs_message (_("undelfs: reading inode bitmap..."));
|
||||
if (ext2fs_read_inode_bitmap (fs)){
|
||||
message (D_ERROR, undelfserr,
|
||||
_(" Cannot load inode bitmap from: \n %s \n"), ext2_fname);
|
||||
goto quit_opendir;
|
||||
if (ext2fs_read_inode_bitmap (fs))
|
||||
{
|
||||
message (D_ERROR, undelfserr, _(" Cannot load inode bitmap from: \n %s \n"), ext2_fname);
|
||||
goto quit_opendir;
|
||||
}
|
||||
print_vfs_message (_("undelfs: reading block bitmap..."));
|
||||
if (ext2fs_read_block_bitmap (fs)){
|
||||
message (D_ERROR, undelfserr,
|
||||
_(" Cannot load block bitmap from: \n %s \n"), ext2_fname);
|
||||
goto quit_opendir;
|
||||
if (ext2fs_read_block_bitmap (fs))
|
||||
{
|
||||
message (D_ERROR, undelfserr, _(" Cannot load block bitmap from: \n %s \n"), ext2_fname);
|
||||
goto quit_opendir;
|
||||
}
|
||||
/* Now load the deleted information */
|
||||
if (!undelfs_loaddel ())
|
||||
goto quit_opendir;
|
||||
goto quit_opendir;
|
||||
print_vfs_message (_("%s: done."), me->name);
|
||||
return fs;
|
||||
quit_opendir:
|
||||
quit_opendir:
|
||||
print_vfs_message (_("%s: failure"), me->name);
|
||||
ext2fs_close (fs);
|
||||
fs = NULL;
|
||||
@ -357,26 +364,26 @@ quit_opendir:
|
||||
|
||||
|
||||
static void *
|
||||
undelfs_readdir(void *vfs_info)
|
||||
undelfs_readdir (void *vfs_info)
|
||||
{
|
||||
static union vfs_dirent undelfs_readdir_data;
|
||||
static char *const dirent_dest = undelfs_readdir_data.dent.d_name;
|
||||
|
||||
if (vfs_info != fs) {
|
||||
message (D_ERROR, undelfserr, _(" vfs_info is not fs! "));
|
||||
return NULL;
|
||||
if (vfs_info != fs)
|
||||
{
|
||||
message (D_ERROR, undelfserr, _(" vfs_info is not fs! "));
|
||||
return NULL;
|
||||
}
|
||||
if (readdir_ptr == num_delarray)
|
||||
return NULL;
|
||||
return NULL;
|
||||
if (readdir_ptr < 0)
|
||||
strcpy (dirent_dest, readdir_ptr == -2 ? "." : "..");
|
||||
strcpy (dirent_dest, readdir_ptr == -2 ? "." : "..");
|
||||
else
|
||||
g_snprintf(dirent_dest, MC_MAXPATHLEN, "%ld:%d",
|
||||
(long) delarray[readdir_ptr].ino,
|
||||
delarray[readdir_ptr].num_blocks);
|
||||
g_snprintf (dirent_dest, MC_MAXPATHLEN, "%ld:%d",
|
||||
(long) delarray[readdir_ptr].ino, delarray[readdir_ptr].num_blocks);
|
||||
readdir_ptr++;
|
||||
|
||||
compute_namelen(&undelfs_readdir_data.dent);
|
||||
compute_namelen (&undelfs_readdir_data.dent);
|
||||
|
||||
return &undelfs_readdir_data;
|
||||
}
|
||||
@ -388,20 +395,21 @@ undelfs_closedir (void *vfs_info)
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
int f_index; /* file index into delarray */
|
||||
typedef struct
|
||||
{
|
||||
int f_index; /* file index into delarray */
|
||||
char *buf;
|
||||
int error_code; /* */
|
||||
int pos; /* file position */
|
||||
int current; /* used to determine current position in itereate */
|
||||
int finished;
|
||||
int error_code; /* */
|
||||
int pos; /* file position */
|
||||
int current; /* used to determine current position in itereate */
|
||||
int finished;
|
||||
ext2_ino_t inode;
|
||||
int bytes_read;
|
||||
int bytes_read;
|
||||
long size;
|
||||
|
||||
|
||||
/* Used by undelfs_read: */
|
||||
char *dest_buffer; /* destination buffer */
|
||||
int count; /* bytes to read */
|
||||
char *dest_buffer; /* destination buffer */
|
||||
int count; /* bytes to read */
|
||||
} undelfs_file;
|
||||
|
||||
/* We do not support lseek */
|
||||
@ -418,42 +426,45 @@ undelfs_open (struct vfs_class *me, const char *fname, int flags, int mode)
|
||||
/* Only allow reads on this file system */
|
||||
undelfs_get_path (fname, &file, &f);
|
||||
if (!file)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
if (!ext2_fname || strcmp (ext2_fname, file)) {
|
||||
message (D_ERROR, undelfserr,
|
||||
_(" You have to chdir to extract files first "));
|
||||
g_free (file);
|
||||
g_free (f);
|
||||
return 0;
|
||||
if (!ext2_fname || strcmp (ext2_fname, file))
|
||||
{
|
||||
message (D_ERROR, undelfserr, _(" You have to chdir to extract files first "));
|
||||
g_free (file);
|
||||
g_free (f);
|
||||
return 0;
|
||||
}
|
||||
inode = atol (f);
|
||||
|
||||
/* Search the file into delarray */
|
||||
for (i = 0; i < (ext2_ino_t) num_delarray; i++) {
|
||||
if (inode != delarray[i].ino)
|
||||
continue;
|
||||
for (i = 0; i < (ext2_ino_t) num_delarray; i++)
|
||||
{
|
||||
if (inode != delarray[i].ino)
|
||||
continue;
|
||||
|
||||
/* Found: setup all the structures needed by read */
|
||||
p = (undelfs_file *) g_try_malloc (((gsize) sizeof (undelfs_file)));
|
||||
if (!p) {
|
||||
g_free (file);
|
||||
g_free (f);
|
||||
return 0;
|
||||
}
|
||||
p->buf = g_try_malloc (fs->blocksize);
|
||||
if (!p->buf) {
|
||||
g_free (p);
|
||||
g_free (file);
|
||||
g_free (f);
|
||||
return 0;
|
||||
}
|
||||
p->inode = inode;
|
||||
p->finished = 0;
|
||||
p->f_index = i;
|
||||
p->error_code = 0;
|
||||
p->pos = 0;
|
||||
p->size = delarray[i].size;
|
||||
/* Found: setup all the structures needed by read */
|
||||
p = (undelfs_file *) g_try_malloc (((gsize) sizeof (undelfs_file)));
|
||||
if (!p)
|
||||
{
|
||||
g_free (file);
|
||||
g_free (f);
|
||||
return 0;
|
||||
}
|
||||
p->buf = g_try_malloc (fs->blocksize);
|
||||
if (!p->buf)
|
||||
{
|
||||
g_free (p);
|
||||
g_free (file);
|
||||
g_free (f);
|
||||
return 0;
|
||||
}
|
||||
p->inode = inode;
|
||||
p->finished = 0;
|
||||
p->f_index = i;
|
||||
p->error_code = 0;
|
||||
p->pos = 0;
|
||||
p->size = delarray[i].size;
|
||||
}
|
||||
g_free (file);
|
||||
g_free (f);
|
||||
@ -461,7 +472,7 @@ undelfs_open (struct vfs_class *me, const char *fname, int flags, int mode)
|
||||
return p;
|
||||
}
|
||||
|
||||
static int
|
||||
static int
|
||||
undelfs_close (void *vfs_info)
|
||||
{
|
||||
undelfs_file *p = vfs_info;
|
||||
@ -472,58 +483,71 @@ undelfs_close (void *vfs_info)
|
||||
}
|
||||
|
||||
static int
|
||||
undelfs_dump_read(ext2_filsys param_fs, blk_t *blocknr, int blockcnt, void *private)
|
||||
undelfs_dump_read (ext2_filsys param_fs, blk_t * blocknr, int blockcnt, void *private)
|
||||
{
|
||||
int copy_count;
|
||||
int copy_count;
|
||||
undelfs_file *p = (undelfs_file *) private;
|
||||
|
||||
if (blockcnt < 0)
|
||||
return 0;
|
||||
|
||||
if (*blocknr) {
|
||||
p->error_code = io_channel_read_blk(param_fs->io, *blocknr,
|
||||
1, p->buf);
|
||||
if (p->error_code)
|
||||
return BLOCK_ABORT;
|
||||
} else
|
||||
memset(p->buf, 0, param_fs->blocksize);
|
||||
|
||||
if (p->pos + p->count < p->current){
|
||||
p->finished = 1;
|
||||
return BLOCK_ABORT;
|
||||
if (blockcnt < 0)
|
||||
return 0;
|
||||
|
||||
if (*blocknr)
|
||||
{
|
||||
p->error_code = io_channel_read_blk (param_fs->io, *blocknr, 1, p->buf);
|
||||
if (p->error_code)
|
||||
return BLOCK_ABORT;
|
||||
}
|
||||
if ((size_t) p->pos > p->current + param_fs->blocksize){
|
||||
p->current += param_fs->blocksize;
|
||||
return 0; /* we have not arrived yet */
|
||||
else
|
||||
memset (p->buf, 0, param_fs->blocksize);
|
||||
|
||||
if (p->pos + p->count < p->current)
|
||||
{
|
||||
p->finished = 1;
|
||||
return BLOCK_ABORT;
|
||||
}
|
||||
if ((size_t) p->pos > p->current + param_fs->blocksize)
|
||||
{
|
||||
p->current += param_fs->blocksize;
|
||||
return 0; /* we have not arrived yet */
|
||||
}
|
||||
|
||||
/* Now, we know we have to extract some data */
|
||||
if (p->pos >= p->current){
|
||||
if (p->pos >= p->current)
|
||||
{
|
||||
|
||||
/* First case: starting pointer inside this block */
|
||||
if ( (size_t)(p->pos + p->count) <= p->current + param_fs->blocksize){
|
||||
/* Fully contained */
|
||||
copy_count = p->count;
|
||||
p->finished = p->count;
|
||||
} else {
|
||||
/* Still some more data */
|
||||
copy_count = param_fs->blocksize-(p->pos-p->current);
|
||||
}
|
||||
memcpy (p->dest_buffer, p->buf + (p->pos-p->current), copy_count);
|
||||
} else {
|
||||
/* Second case: we already have passed p->pos */
|
||||
if ((size_t) (p->pos + p->count) < p->current+param_fs->blocksize){
|
||||
copy_count = (p->pos + p->count) - p->current;
|
||||
p->finished = p->count;
|
||||
} else {
|
||||
copy_count = param_fs->blocksize;
|
||||
}
|
||||
memcpy (p->dest_buffer, p->buf, copy_count);
|
||||
/* First case: starting pointer inside this block */
|
||||
if ((size_t) (p->pos + p->count) <= p->current + param_fs->blocksize)
|
||||
{
|
||||
/* Fully contained */
|
||||
copy_count = p->count;
|
||||
p->finished = p->count;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Still some more data */
|
||||
copy_count = param_fs->blocksize - (p->pos - p->current);
|
||||
}
|
||||
memcpy (p->dest_buffer, p->buf + (p->pos - p->current), copy_count);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Second case: we already have passed p->pos */
|
||||
if ((size_t) (p->pos + p->count) < p->current + param_fs->blocksize)
|
||||
{
|
||||
copy_count = (p->pos + p->count) - p->current;
|
||||
p->finished = p->count;
|
||||
}
|
||||
else
|
||||
{
|
||||
copy_count = param_fs->blocksize;
|
||||
}
|
||||
memcpy (p->dest_buffer, p->buf, copy_count);
|
||||
}
|
||||
p->dest_buffer += copy_count;
|
||||
p->current += param_fs->blocksize;
|
||||
if (p->finished){
|
||||
return BLOCK_ABORT;
|
||||
if (p->finished)
|
||||
{
|
||||
return BLOCK_ABORT;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -535,21 +559,22 @@ undelfs_read (void *vfs_info, char *buffer, int count)
|
||||
int retval;
|
||||
|
||||
p->dest_buffer = buffer;
|
||||
p->current = 0;
|
||||
p->finished = 0;
|
||||
p->count = count;
|
||||
p->current = 0;
|
||||
p->finished = 0;
|
||||
p->count = count;
|
||||
|
||||
if (p->pos + p->count > p->size){
|
||||
p->count = p->size - p->pos;
|
||||
if (p->pos + p->count > p->size)
|
||||
{
|
||||
p->count = p->size - p->pos;
|
||||
}
|
||||
retval = ext2fs_block_iterate(fs, p->inode, 0, NULL,
|
||||
undelfs_dump_read, p);
|
||||
if (retval){
|
||||
message (D_ERROR, undelfserr, _(" while iterating over blocks "));
|
||||
return -1;
|
||||
retval = ext2fs_block_iterate (fs, p->inode, 0, NULL, undelfs_dump_read, p);
|
||||
if (retval)
|
||||
{
|
||||
message (D_ERROR, undelfserr, _(" while iterating over blocks "));
|
||||
return -1;
|
||||
}
|
||||
if (p->error_code && !p->finished)
|
||||
return 0;
|
||||
return 0;
|
||||
p->pos = p->pos + (p->dest_buffer - buffer);
|
||||
return p->dest_buffer - buffer;
|
||||
}
|
||||
@ -560,9 +585,10 @@ undelfs_getindex (char *path)
|
||||
ext2_ino_t inode = atol (path);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < num_delarray; i++){
|
||||
if (delarray [i].ino == inode)
|
||||
return i;
|
||||
for (i = 0; i < num_delarray; i++)
|
||||
{
|
||||
if (delarray[i].ino == inode)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@ -570,16 +596,16 @@ undelfs_getindex (char *path)
|
||||
static int
|
||||
undelfs_stat_int (int inode_index, struct stat *buf)
|
||||
{
|
||||
buf->st_dev = 0;
|
||||
buf->st_ino = delarray [inode_index].ino;
|
||||
buf->st_mode = delarray [inode_index].mode;
|
||||
buf->st_dev = 0;
|
||||
buf->st_ino = delarray[inode_index].ino;
|
||||
buf->st_mode = delarray[inode_index].mode;
|
||||
buf->st_nlink = 1;
|
||||
buf->st_uid = delarray [inode_index].uid;
|
||||
buf->st_gid = delarray [inode_index].gid;
|
||||
buf->st_size = delarray [inode_index].size;
|
||||
buf->st_atime = delarray [inode_index].dtime;
|
||||
buf->st_ctime = delarray [inode_index].dtime;
|
||||
buf->st_mtime = delarray [inode_index].dtime;
|
||||
buf->st_uid = delarray[inode_index].uid;
|
||||
buf->st_gid = delarray[inode_index].gid;
|
||||
buf->st_size = delarray[inode_index].size;
|
||||
buf->st_atime = delarray[inode_index].dtime;
|
||||
buf->st_ctime = delarray[inode_index].dtime;
|
||||
buf->st_mtime = delarray[inode_index].dtime;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -592,32 +618,34 @@ undelfs_lstat (struct vfs_class *me, const char *path, struct stat *buf)
|
||||
|
||||
undelfs_get_path (path, &file, &f);
|
||||
if (!file)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
/* When called from save_cwd_stats we get an incorrect file and f here:
|
||||
e.g. incorrect correct
|
||||
path = "undel:/dev/sda1" path="undel:/dev/sda1/401:1"
|
||||
file = "/dev" file="/dev/sda1"
|
||||
f = "sda1" f ="401:1"
|
||||
path = "undel:/dev/sda1" path="undel:/dev/sda1/401:1"
|
||||
file = "/dev" file="/dev/sda1"
|
||||
f = "sda1" f ="401:1"
|
||||
If the first char in f is no digit -> return error */
|
||||
if (!isdigit (*f)) {
|
||||
g_free (file);
|
||||
g_free (f);
|
||||
return -1;
|
||||
if (!isdigit (*f))
|
||||
{
|
||||
g_free (file);
|
||||
g_free (f);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!ext2_fname || strcmp (ext2_fname, file)){
|
||||
message (D_ERROR, undelfserr, _(" You have to chdir to extract files first "));
|
||||
g_free (file);
|
||||
g_free (f);
|
||||
return 0;
|
||||
|
||||
if (!ext2_fname || strcmp (ext2_fname, file))
|
||||
{
|
||||
message (D_ERROR, undelfserr, _(" You have to chdir to extract files first "));
|
||||
g_free (file);
|
||||
g_free (f);
|
||||
return 0;
|
||||
}
|
||||
inode_index = undelfs_getindex (f);
|
||||
g_free (file);
|
||||
g_free (f);
|
||||
|
||||
if (inode_index == -1)
|
||||
return -1;
|
||||
return -1;
|
||||
|
||||
return undelfs_stat_int (inode_index, buf);
|
||||
}
|
||||
@ -628,12 +656,12 @@ static int
|
||||
undelfs_fstat (void *vfs_info, struct stat *buf)
|
||||
{
|
||||
undelfs_file *p = vfs_info;
|
||||
|
||||
|
||||
return undelfs_stat_int (p->f_index, buf);
|
||||
}
|
||||
|
||||
static int
|
||||
undelfs_chdir(struct vfs_class *me, const char *path)
|
||||
undelfs_chdir (struct vfs_class *me, const char *path)
|
||||
{
|
||||
char *file, *f;
|
||||
int fd;
|
||||
@ -641,16 +669,17 @@ undelfs_chdir(struct vfs_class *me, const char *path)
|
||||
|
||||
undelfs_get_path (path, &file, &f);
|
||||
if (!file)
|
||||
return -1;
|
||||
return -1;
|
||||
|
||||
/* We may use access because ext2 file systems are local */
|
||||
/* this could be fixed by making an ext2fs io manager to use */
|
||||
/* our vfs, but that is left as an excercise for the reader */
|
||||
if ((fd = open (file, O_RDONLY)) == -1){
|
||||
message (D_ERROR, undelfserr, _(" Cannot open file %s "), file);
|
||||
g_free (f);
|
||||
g_free (file);
|
||||
return -1;
|
||||
if ((fd = open (file, O_RDONLY)) == -1)
|
||||
{
|
||||
message (D_ERROR, undelfserr, _(" Cannot open file %s "), file);
|
||||
g_free (f);
|
||||
g_free (file);
|
||||
return -1;
|
||||
}
|
||||
close (fd);
|
||||
g_free (f);
|
||||
@ -660,7 +689,7 @@ undelfs_chdir(struct vfs_class *me, const char *path)
|
||||
|
||||
/* this has to stay here for now: vfs layer does not know how to emulate it */
|
||||
static off_t
|
||||
undelfs_lseek(void *vfs_info, off_t offset, int whence)
|
||||
undelfs_lseek (void *vfs_info, off_t offset, int whence)
|
||||
{
|
||||
(void) vfs_info;
|
||||
(void) offset;
|
||||
@ -678,14 +707,14 @@ undelfs_getid (struct vfs_class *me, const char *path)
|
||||
undelfs_get_path (path, &fsname, &fname);
|
||||
|
||||
if (!fsname)
|
||||
return NULL;
|
||||
return NULL;
|
||||
g_free (fname);
|
||||
g_free (fsname);
|
||||
return (vfsid) fs;
|
||||
}
|
||||
|
||||
static int
|
||||
undelfs_nothingisopen(vfsid id)
|
||||
undelfs_nothingisopen (vfsid id)
|
||||
{
|
||||
(void) id;
|
||||
|
||||
@ -693,7 +722,7 @@ undelfs_nothingisopen(vfsid id)
|
||||
}
|
||||
|
||||
static void
|
||||
undelfs_free(vfsid id)
|
||||
undelfs_free (vfsid id)
|
||||
{
|
||||
(void) id;
|
||||
|
||||
@ -702,7 +731,8 @@ undelfs_free(vfsid id)
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
static int
|
||||
undelfs_init(struct vfs_class *me) {
|
||||
undelfs_init (struct vfs_class *me)
|
||||
{
|
||||
(void) me;
|
||||
|
||||
undelfserr = _(undelfserr);
|
||||
|
256
src/chown.c
256
src/chown.c
@ -44,12 +44,12 @@
|
||||
|
||||
/* Needed for the extern declarations of integer parameters */
|
||||
#include "dir.h"
|
||||
#include "panel.h" /* Needed for the externs */
|
||||
#include "panel.h" /* Needed for the externs */
|
||||
#include "chmod.h"
|
||||
#include "main.h" /* update_panels() */
|
||||
#include "layout.h" /* repaint_screen() */
|
||||
#include "main.h" /* update_panels() */
|
||||
#include "layout.h" /* repaint_screen() */
|
||||
#include "chown.h"
|
||||
#include "wtools.h" /* For init_box_colors */
|
||||
#include "wtools.h" /* For init_box_colors */
|
||||
|
||||
#define UX 5
|
||||
#define UY 2
|
||||
@ -74,6 +74,7 @@ static int current_file;
|
||||
static int single_set;
|
||||
static WListbox *l_user, *l_group;
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
static struct {
|
||||
int ret_cmd, flags, y, x;
|
||||
const char *text;
|
||||
@ -96,9 +97,10 @@ static struct {
|
||||
{ TY+8, TX+2, NULL },
|
||||
{ TY+10,TX+2, NULL }
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
|
||||
static void
|
||||
chown_refresh (Dlg_head *h)
|
||||
chown_refresh (Dlg_head * h)
|
||||
{
|
||||
common_dialog_repaint (h);
|
||||
|
||||
@ -118,7 +120,7 @@ chown_refresh (Dlg_head *h)
|
||||
tty_print_string (_(" Size "));
|
||||
dlg_move (h, TY + 9, TX + 1);
|
||||
tty_print_string (_(" Permission "));
|
||||
|
||||
|
||||
tty_setcolor (COLOR_HOT_NORMAL);
|
||||
dlg_move (h, UY, UX + 1);
|
||||
tty_print_string (_(" User name "));
|
||||
@ -132,22 +134,22 @@ static char *
|
||||
next_file (void)
|
||||
{
|
||||
while (!current_panel->dir.list[current_file].f.marked)
|
||||
current_file++;
|
||||
current_file++;
|
||||
|
||||
return current_panel->dir.list[current_file].fname;
|
||||
}
|
||||
|
||||
static cb_ret_t
|
||||
chown_callback (Dlg_head *h, Widget *sender,
|
||||
dlg_msg_t msg, int parm, void *data)
|
||||
chown_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
{
|
||||
switch (msg) {
|
||||
switch (msg)
|
||||
{
|
||||
case DLG_DRAW:
|
||||
chown_refresh (h);
|
||||
return MSG_HANDLED;
|
||||
chown_refresh (h);
|
||||
return MSG_HANDLED;
|
||||
|
||||
default:
|
||||
return default_dlg_callback (h, sender, msg, parm, data);
|
||||
return default_dlg_callback (h, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,20 +166,19 @@ init_chown (void)
|
||||
single_set = (current_panel->marked < 2) ? 3 : 0;
|
||||
|
||||
ch_dlg =
|
||||
create_dlg (0, 0, 18, 74, dialog_colors, chown_callback, "[Chown]",
|
||||
_(" Chown command "), DLG_CENTER | DLG_REVERSE);
|
||||
create_dlg (0, 0, 18, 74, dialog_colors, chown_callback, "[Chown]",
|
||||
_(" Chown command "), DLG_CENTER | DLG_REVERSE);
|
||||
|
||||
for (i = 0; i < BUTTONS - single_set; i++)
|
||||
add_widget (ch_dlg,
|
||||
button_new (BY + chown_but[i].y, BX + chown_but[i].x,
|
||||
chown_but[i].ret_cmd, chown_but[i].flags,
|
||||
_(chown_but[i].text), 0));
|
||||
add_widget (ch_dlg,
|
||||
button_new (BY + chown_but[i].y, BX + chown_but[i].x,
|
||||
chown_but[i].ret_cmd, chown_but[i].flags, _(chown_but[i].text), 0));
|
||||
|
||||
/* Add the widgets for the file information */
|
||||
for (i = 0; i < LABELS; i++) {
|
||||
chown_label[i].l =
|
||||
label_new (chown_label[i].y, chown_label[i].x, "");
|
||||
add_widget (ch_dlg, chown_label[i].l);
|
||||
for (i = 0; i < LABELS; i++)
|
||||
{
|
||||
chown_label[i].l = label_new (chown_label[i].y, chown_label[i].x, "");
|
||||
add_widget (ch_dlg, chown_label[i].l);
|
||||
}
|
||||
|
||||
/* get new listboxes */
|
||||
@ -190,15 +191,17 @@ init_chown (void)
|
||||
|
||||
/* get and put user names in the listbox */
|
||||
setpwent ();
|
||||
while ((l_pass = getpwent ())) {
|
||||
listbox_add_item (l_user, LISTBOX_APPEND_SORTED, 0, l_pass->pw_name, NULL);
|
||||
while ((l_pass = getpwent ()))
|
||||
{
|
||||
listbox_add_item (l_user, LISTBOX_APPEND_SORTED, 0, l_pass->pw_name, NULL);
|
||||
}
|
||||
endpwent ();
|
||||
|
||||
/* get and put group names in the listbox */
|
||||
setgrent ();
|
||||
while ((l_grp = getgrent ())) {
|
||||
listbox_add_item (l_group, LISTBOX_APPEND_SORTED, 0, l_grp->gr_name, NULL);
|
||||
while ((l_grp = getgrent ()))
|
||||
{
|
||||
listbox_add_item (l_group, LISTBOX_APPEND_SORTED, 0, l_grp->gr_name, NULL);
|
||||
}
|
||||
endgrent ();
|
||||
|
||||
@ -213,16 +216,16 @@ static void
|
||||
chown_done (void)
|
||||
{
|
||||
if (need_update)
|
||||
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
|
||||
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
|
||||
repaint_screen ();
|
||||
}
|
||||
|
||||
static void
|
||||
do_chown (uid_t u, gid_t g)
|
||||
{
|
||||
if (mc_chown (current_panel->dir.list [current_file].fname, u, g) == -1)
|
||||
message (D_ERROR, MSG_ERROR, _(" Cannot chown \"%s\" \n %s "),
|
||||
current_panel->dir.list [current_file].fname, unix_error_string (errno));
|
||||
if (mc_chown (current_panel->dir.list[current_file].fname, u, g) == -1)
|
||||
message (D_ERROR, MSG_ERROR, _(" Cannot chown \"%s\" \n %s "),
|
||||
current_panel->dir.list[current_file].fname, unix_error_string (errno));
|
||||
|
||||
do_file_mark (current_panel, current_file, 0);
|
||||
}
|
||||
@ -231,15 +234,17 @@ static void
|
||||
apply_chowns (uid_t u, gid_t g)
|
||||
{
|
||||
char *fname;
|
||||
|
||||
|
||||
need_update = end_chown = 1;
|
||||
do_chown (u,g);
|
||||
|
||||
do {
|
||||
fname = next_file ();
|
||||
|
||||
do_chown (u,g);
|
||||
} while (current_panel->marked);
|
||||
do_chown (u, g);
|
||||
|
||||
do
|
||||
{
|
||||
fname = next_file ();
|
||||
|
||||
do_chown (u, g);
|
||||
}
|
||||
while (current_panel->marked);
|
||||
}
|
||||
|
||||
#define chown_label(n,txt) label_set_text (chown_label [n].l, txt)
|
||||
@ -252,96 +257,105 @@ chown_cmd (void)
|
||||
Dlg_head *ch_dlg;
|
||||
uid_t new_user;
|
||||
gid_t new_group;
|
||||
char buffer [BUF_TINY];
|
||||
char buffer[BUF_TINY];
|
||||
|
||||
do { /* do while any files remaining */
|
||||
ch_dlg = init_chown ();
|
||||
new_user = new_group = -1;
|
||||
do
|
||||
{ /* do while any files remaining */
|
||||
ch_dlg = init_chown ();
|
||||
new_user = new_group = -1;
|
||||
|
||||
if (current_panel->marked)
|
||||
fname = next_file (); /* next marked file */
|
||||
else
|
||||
fname = selection (current_panel)->fname; /* single file */
|
||||
|
||||
if (mc_stat (fname, &sf_stat) != 0) { /* get status of file */
|
||||
destroy_dlg (ch_dlg);
|
||||
break;
|
||||
}
|
||||
|
||||
/* select in listboxes */
|
||||
listbox_select_entry (l_user, listbox_search_text (l_user, get_owner(sf_stat.st_uid)));
|
||||
listbox_select_entry (l_group, listbox_search_text (l_group, get_group(sf_stat.st_gid)));
|
||||
if (current_panel->marked)
|
||||
fname = next_file (); /* next marked file */
|
||||
else
|
||||
fname = selection (current_panel)->fname; /* single file */
|
||||
|
||||
chown_label (0, str_trunc (fname, 15));
|
||||
chown_label (1, str_trunc (get_owner (sf_stat.st_uid), 15));
|
||||
chown_label (2, str_trunc (get_group (sf_stat.st_gid), 15));
|
||||
size_trunc_len (buffer, 15, sf_stat.st_size, 0);
|
||||
chown_label (3, buffer);
|
||||
chown_label (4, string_perm (sf_stat.st_mode));
|
||||
if (mc_stat (fname, &sf_stat) != 0)
|
||||
{ /* get status of file */
|
||||
destroy_dlg (ch_dlg);
|
||||
break;
|
||||
}
|
||||
|
||||
switch (run_dlg (ch_dlg)) {
|
||||
case B_CANCEL:
|
||||
end_chown = 1;
|
||||
break;
|
||||
/* select in listboxes */
|
||||
listbox_select_entry (l_user, listbox_search_text (l_user, get_owner (sf_stat.st_uid)));
|
||||
listbox_select_entry (l_group, listbox_search_text (l_group, get_group (sf_stat.st_gid)));
|
||||
|
||||
case B_SETUSR:
|
||||
{
|
||||
struct passwd *user;
|
||||
char *text;
|
||||
chown_label (0, str_trunc (fname, 15));
|
||||
chown_label (1, str_trunc (get_owner (sf_stat.st_uid), 15));
|
||||
chown_label (2, str_trunc (get_group (sf_stat.st_gid), 15));
|
||||
size_trunc_len (buffer, 15, sf_stat.st_size, 0);
|
||||
chown_label (3, buffer);
|
||||
chown_label (4, string_perm (sf_stat.st_mode));
|
||||
|
||||
listbox_get_current (l_user, &text, NULL);
|
||||
user = getpwnam (text);
|
||||
if (user){
|
||||
new_user = user->pw_uid;
|
||||
apply_chowns (new_user, new_group);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case B_SETGRP:
|
||||
{
|
||||
struct group *grp;
|
||||
char *text;
|
||||
switch (run_dlg (ch_dlg))
|
||||
{
|
||||
case B_CANCEL:
|
||||
end_chown = 1;
|
||||
break;
|
||||
|
||||
listbox_get_current (l_group, &text, NULL);
|
||||
grp = getgrnam (text);
|
||||
if (grp){
|
||||
new_group = grp->gr_gid;
|
||||
apply_chowns (new_user, new_group);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case B_SETALL:
|
||||
case B_ENTER:
|
||||
{
|
||||
struct group *grp;
|
||||
struct passwd *user;
|
||||
char *text;
|
||||
case B_SETUSR:
|
||||
{
|
||||
struct passwd *user;
|
||||
char *text;
|
||||
|
||||
listbox_get_current (l_group, &text, NULL);
|
||||
grp = getgrnam (text);
|
||||
if (grp)
|
||||
new_group = grp->gr_gid;
|
||||
listbox_get_current (l_user, &text, NULL);
|
||||
user = getpwnam (text);
|
||||
if (user)
|
||||
new_user = user->pw_uid;
|
||||
if (ch_dlg->ret_value == B_ENTER) {
|
||||
need_update = 1;
|
||||
if (mc_chown (fname, new_user, new_group) == -1)
|
||||
message (D_ERROR, MSG_ERROR, _(" Cannot chown \"%s\" \n %s "),
|
||||
fname, unix_error_string (errno));
|
||||
} else
|
||||
apply_chowns (new_user, new_group);
|
||||
break;
|
||||
}
|
||||
} /* switch */
|
||||
listbox_get_current (l_user, &text, NULL);
|
||||
user = getpwnam (text);
|
||||
if (user)
|
||||
{
|
||||
new_user = user->pw_uid;
|
||||
apply_chowns (new_user, new_group);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case B_SETGRP:
|
||||
{
|
||||
struct group *grp;
|
||||
char *text;
|
||||
|
||||
listbox_get_current (l_group, &text, NULL);
|
||||
grp = getgrnam (text);
|
||||
if (grp)
|
||||
{
|
||||
new_group = grp->gr_gid;
|
||||
apply_chowns (new_user, new_group);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case B_SETALL:
|
||||
case B_ENTER:
|
||||
{
|
||||
struct group *grp;
|
||||
struct passwd *user;
|
||||
char *text;
|
||||
|
||||
listbox_get_current (l_group, &text, NULL);
|
||||
grp = getgrnam (text);
|
||||
if (grp)
|
||||
new_group = grp->gr_gid;
|
||||
listbox_get_current (l_user, &text, NULL);
|
||||
user = getpwnam (text);
|
||||
if (user)
|
||||
new_user = user->pw_uid;
|
||||
if (ch_dlg->ret_value == B_ENTER)
|
||||
{
|
||||
need_update = 1;
|
||||
if (mc_chown (fname, new_user, new_group) == -1)
|
||||
message (D_ERROR, MSG_ERROR, _(" Cannot chown \"%s\" \n %s "),
|
||||
fname, unix_error_string (errno));
|
||||
}
|
||||
else
|
||||
apply_chowns (new_user, new_group);
|
||||
break;
|
||||
}
|
||||
} /* switch */
|
||||
|
||||
if (current_panel->marked && ch_dlg->ret_value != B_CANCEL)
|
||||
{
|
||||
do_file_mark (current_panel, current_file, 0);
|
||||
need_update = 1;
|
||||
}
|
||||
destroy_dlg (ch_dlg);
|
||||
}
|
||||
while (current_panel->marked && !end_chown);
|
||||
|
||||
if (current_panel->marked && ch_dlg->ret_value != B_CANCEL){
|
||||
do_file_mark (current_panel, current_file, 0);
|
||||
need_update = 1;
|
||||
}
|
||||
destroy_dlg (ch_dlg);
|
||||
} while (current_panel->marked && !end_chown);
|
||||
|
||||
chown_done ();
|
||||
}
|
||||
|
3202
src/editor/editcmd.c
3202
src/editor/editcmd.c
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -28,7 +28,7 @@
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "lib/tty/tty.h"
|
||||
#include "lib/skin.h" /* INPUT_COLOR */
|
||||
#include "lib/skin.h" /* INPUT_COLOR */
|
||||
#include "lib/tty/key.h"
|
||||
#include "lib/search.h"
|
||||
#include "lib/strutil.h"
|
||||
@ -47,8 +47,7 @@
|
||||
|
||||
/*** global variables **************************************************/
|
||||
|
||||
edit_search_options_t edit_search_options =
|
||||
{
|
||||
edit_search_options_t edit_search_options = {
|
||||
.type = MC_SEARCH_T_NORMAL,
|
||||
.case_sens = FALSE,
|
||||
.backwards = FALSE,
|
||||
@ -74,10 +73,11 @@ edit_search_options_t edit_search_options =
|
||||
/*** file scope functions **********************************************/
|
||||
|
||||
static cb_ret_t
|
||||
editcmd_dialog_raw_key_query_cb (struct Dlg_head *h, Widget *sender,
|
||||
dlg_msg_t msg, int parm, void *data)
|
||||
editcmd_dialog_raw_key_query_cb (struct Dlg_head *h, Widget * sender,
|
||||
dlg_msg_t msg, int parm, void *data)
|
||||
{
|
||||
switch (msg) {
|
||||
switch (msg)
|
||||
{
|
||||
case DLG_KEY:
|
||||
h->ret_value = parm;
|
||||
dlg_stop (h);
|
||||
@ -97,52 +97,61 @@ editcmd_dialog_replace_show (WEdit * edit, const char *search_default, const cha
|
||||
search_default = INPUT_LAST_TEXT;
|
||||
|
||||
{
|
||||
size_t num_of_types;
|
||||
gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types);
|
||||
int REPLACE_DLG_HEIGHT = REPLACE_DLG_MIN_HEIGHT + num_of_types - REPLACE_DLG_HEIGHT_SUPPLY;
|
||||
size_t num_of_types;
|
||||
gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types);
|
||||
int REPLACE_DLG_HEIGHT = REPLACE_DLG_MIN_HEIGHT + num_of_types - REPLACE_DLG_HEIGHT_SUPPLY;
|
||||
|
||||
QuickWidget quick_widgets[] =
|
||||
{
|
||||
/* 0 */ QUICK_BUTTON (6, 10, 13, REPLACE_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL),
|
||||
/* 1 */ QUICK_BUTTON (2, 10, 13, REPLACE_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL),
|
||||
QuickWidget quick_widgets[] = {
|
||||
/* 0 */ QUICK_BUTTON (6, 10, 13, REPLACE_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL),
|
||||
/* 1 */ QUICK_BUTTON (2, 10, 13, REPLACE_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL),
|
||||
#ifdef HAVE_CHARSET
|
||||
/* 2 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 11, REPLACE_DLG_HEIGHT, N_("All charsets"),
|
||||
&edit_search_options.all_codepages),
|
||||
/* 2 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 11, REPLACE_DLG_HEIGHT,
|
||||
N_("All charsets"),
|
||||
&edit_search_options.all_codepages),
|
||||
#endif
|
||||
/* 3 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 10, REPLACE_DLG_HEIGHT, N_("&Whole words"),
|
||||
&edit_search_options.whole_words),
|
||||
/* 4 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 9, REPLACE_DLG_HEIGHT, N_("In se&lection"),
|
||||
&edit_search_options.only_in_selection),
|
||||
/* 5 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 8, REPLACE_DLG_HEIGHT, N_("&Backwards"),
|
||||
&edit_search_options.backwards),
|
||||
/* 6 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT, N_("case &Sensitive"),
|
||||
&edit_search_options.case_sens),
|
||||
/* 7 */ QUICK_RADIO (3, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT,
|
||||
num_of_types, (const char **) list_of_types,
|
||||
(int *) &edit_search_options.type),
|
||||
/* 8 */ QUICK_LABEL (2, REPLACE_DLG_WIDTH, 4, REPLACE_DLG_HEIGHT, N_(" Enter replacement string:")),
|
||||
/* 9 */ QUICK_INPUT (3, REPLACE_DLG_WIDTH, 5, REPLACE_DLG_HEIGHT,
|
||||
replace_default, REPLACE_DLG_WIDTH - 6, 0, "replace", replace_text),
|
||||
/* 10 */ QUICK_LABEL (2, REPLACE_DLG_WIDTH, 2, REPLACE_DLG_HEIGHT, N_(" Enter search string:")),
|
||||
/* 11 */ QUICK_INPUT (3, REPLACE_DLG_WIDTH, 3, REPLACE_DLG_HEIGHT,
|
||||
search_default, REPLACE_DLG_WIDTH - 6, 0, MC_HISTORY_SHARED_SEARCH, search_text),
|
||||
QUICK_END
|
||||
};
|
||||
/* 3 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 10, REPLACE_DLG_HEIGHT,
|
||||
N_("&Whole words"),
|
||||
&edit_search_options.whole_words),
|
||||
/* 4 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 9, REPLACE_DLG_HEIGHT,
|
||||
N_("In se&lection"),
|
||||
&edit_search_options.only_in_selection),
|
||||
/* 5 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 8, REPLACE_DLG_HEIGHT, N_("&Backwards"),
|
||||
&edit_search_options.backwards),
|
||||
/* 6 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT,
|
||||
N_("case &Sensitive"),
|
||||
&edit_search_options.case_sens),
|
||||
/* 7 */ QUICK_RADIO (3, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT,
|
||||
num_of_types, (const char **) list_of_types,
|
||||
(int *) &edit_search_options.type),
|
||||
/* 8 */ QUICK_LABEL (2, REPLACE_DLG_WIDTH, 4, REPLACE_DLG_HEIGHT,
|
||||
N_(" Enter replacement string:")),
|
||||
/* 9 */ QUICK_INPUT (3, REPLACE_DLG_WIDTH, 5, REPLACE_DLG_HEIGHT,
|
||||
replace_default, REPLACE_DLG_WIDTH - 6, 0, "replace",
|
||||
replace_text),
|
||||
/* 10 */ QUICK_LABEL (2, REPLACE_DLG_WIDTH, 2, REPLACE_DLG_HEIGHT,
|
||||
N_(" Enter search string:")),
|
||||
/* 11 */ QUICK_INPUT (3, REPLACE_DLG_WIDTH, 3, REPLACE_DLG_HEIGHT,
|
||||
search_default, REPLACE_DLG_WIDTH - 6, 0,
|
||||
MC_HISTORY_SHARED_SEARCH, search_text),
|
||||
QUICK_END
|
||||
};
|
||||
|
||||
QuickDialog Quick_input =
|
||||
{
|
||||
REPLACE_DLG_WIDTH, REPLACE_DLG_HEIGHT, -1, -1, N_(" Replace "),
|
||||
"[Input Line Keys]", quick_widgets, FALSE
|
||||
};
|
||||
QuickDialog Quick_input = {
|
||||
REPLACE_DLG_WIDTH, REPLACE_DLG_HEIGHT, -1, -1, N_(" Replace "),
|
||||
"[Input Line Keys]", quick_widgets, FALSE
|
||||
};
|
||||
|
||||
if (quick_dialog (&Quick_input) != B_CANCEL) {
|
||||
edit->replace_mode = 0;
|
||||
} else {
|
||||
*replace_text = NULL;
|
||||
*search_text = NULL;
|
||||
}
|
||||
if (quick_dialog (&Quick_input) != B_CANCEL)
|
||||
{
|
||||
edit->replace_mode = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
*replace_text = NULL;
|
||||
*search_text = NULL;
|
||||
}
|
||||
|
||||
g_strfreev (list_of_types);
|
||||
g_strfreev (list_of_types);
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,139 +166,138 @@ editcmd_dialog_search_show (WEdit * edit, char **search_text)
|
||||
*search_text = INPUT_LAST_TEXT;
|
||||
|
||||
{
|
||||
size_t num_of_types;
|
||||
gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types);
|
||||
int SEARCH_DLG_HEIGHT = SEARCH_DLG_MIN_HEIGHT + num_of_types - SEARCH_DLG_HEIGHT_SUPPLY;
|
||||
size_t i;
|
||||
size_t num_of_types;
|
||||
gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types);
|
||||
int SEARCH_DLG_HEIGHT = SEARCH_DLG_MIN_HEIGHT + num_of_types - SEARCH_DLG_HEIGHT_SUPPLY;
|
||||
size_t i;
|
||||
|
||||
int dialog_result;
|
||||
int dialog_result;
|
||||
|
||||
QuickWidget quick_widgets[] =
|
||||
{
|
||||
/* 0 */
|
||||
QUICK_BUTTON (6, 10, 11, SEARCH_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL),
|
||||
/* 1 */
|
||||
QUICK_BUTTON (4, 10, 11, SEARCH_DLG_HEIGHT, N_("&Find all"), B_USER, NULL),
|
||||
/* 2 */
|
||||
QUICK_BUTTON (2, 10, 11, SEARCH_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL),
|
||||
QuickWidget quick_widgets[] = {
|
||||
/* 0 */
|
||||
QUICK_BUTTON (6, 10, 11, SEARCH_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL),
|
||||
/* 1 */
|
||||
QUICK_BUTTON (4, 10, 11, SEARCH_DLG_HEIGHT, N_("&Find all"), B_USER, NULL),
|
||||
/* 2 */
|
||||
QUICK_BUTTON (2, 10, 11, SEARCH_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL),
|
||||
#ifdef HAVE_CHARSET
|
||||
/* 3 */
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 9, SEARCH_DLG_HEIGHT, N_("All charsets"),
|
||||
&edit_search_options.all_codepages),
|
||||
/* 3 */
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 9, SEARCH_DLG_HEIGHT, N_("All charsets"),
|
||||
&edit_search_options.all_codepages),
|
||||
#endif
|
||||
/* 4 */
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 8, SEARCH_DLG_HEIGHT, N_("&Whole words"),
|
||||
&edit_search_options.whole_words),
|
||||
/* 5 */
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT, N_("In se&lection"),
|
||||
&edit_search_options.only_in_selection),
|
||||
/* 6 */
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT, N_("&Backwards"),
|
||||
&edit_search_options.backwards),
|
||||
/* 7 */
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, N_("case &Sensitive"),
|
||||
&edit_search_options.case_sens),
|
||||
/* 8 */
|
||||
QUICK_RADIO ( 3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT,
|
||||
num_of_types, (const char **) list_of_types,
|
||||
(int *) &edit_search_options.type),
|
||||
/* 9 */
|
||||
QUICK_INPUT (3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT,
|
||||
*search_text, SEARCH_DLG_WIDTH - 6, 0,
|
||||
MC_HISTORY_SHARED_SEARCH, search_text),
|
||||
/* 10 */
|
||||
QUICK_LABEL (2, SEARCH_DLG_WIDTH, 2, SEARCH_DLG_HEIGHT, N_(" Enter search string:")),
|
||||
QUICK_END
|
||||
};
|
||||
/* 4 */
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 8, SEARCH_DLG_HEIGHT, N_("&Whole words"),
|
||||
&edit_search_options.whole_words),
|
||||
/* 5 */
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT, N_("In se&lection"),
|
||||
&edit_search_options.only_in_selection),
|
||||
/* 6 */
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT, N_("&Backwards"),
|
||||
&edit_search_options.backwards),
|
||||
/* 7 */
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, N_("case &Sensitive"),
|
||||
&edit_search_options.case_sens),
|
||||
/* 8 */
|
||||
QUICK_RADIO (3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT,
|
||||
num_of_types, (const char **) list_of_types,
|
||||
(int *) &edit_search_options.type),
|
||||
/* 9 */
|
||||
QUICK_INPUT (3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT,
|
||||
*search_text, SEARCH_DLG_WIDTH - 6, 0,
|
||||
MC_HISTORY_SHARED_SEARCH, search_text),
|
||||
/* 10 */
|
||||
QUICK_LABEL (2, SEARCH_DLG_WIDTH, 2, SEARCH_DLG_HEIGHT, N_(" Enter search string:")),
|
||||
QUICK_END
|
||||
};
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
size_t last_checkbox = 7;
|
||||
size_t last_checkbox = 7;
|
||||
#else
|
||||
size_t last_checkbox = 6;
|
||||
size_t last_checkbox = 6;
|
||||
#endif
|
||||
|
||||
QuickDialog Quick_input =
|
||||
{
|
||||
SEARCH_DLG_WIDTH, SEARCH_DLG_HEIGHT, -1, -1, N_("Search"),
|
||||
"[Input Line Keys]", quick_widgets, TRUE
|
||||
};
|
||||
QuickDialog Quick_input = {
|
||||
SEARCH_DLG_WIDTH, SEARCH_DLG_HEIGHT, -1, -1, N_("Search"),
|
||||
"[Input Line Keys]", quick_widgets, TRUE
|
||||
};
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
char **list_of_types_nls;
|
||||
char **list_of_types_nls;
|
||||
|
||||
/* header title */
|
||||
Quick_input.title = _(Quick_input.title);
|
||||
/* buttons */
|
||||
for (i = 0; i < 3; i++)
|
||||
quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
|
||||
/* checkboxes */
|
||||
for (i = 3; i <= last_checkbox; i++)
|
||||
quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
|
||||
/* label */
|
||||
quick_widgets[10].u.label.text = _(quick_widgets[10].u.label.text);
|
||||
/* header title */
|
||||
Quick_input.title = _(Quick_input.title);
|
||||
/* buttons */
|
||||
for (i = 0; i < 3; i++)
|
||||
quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
|
||||
/* checkboxes */
|
||||
for (i = 3; i <= last_checkbox; i++)
|
||||
quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
|
||||
/* label */
|
||||
quick_widgets[10].u.label.text = _(quick_widgets[10].u.label.text);
|
||||
|
||||
/* radiobuttons */
|
||||
/* create copy of radio items to avoid memory leak */
|
||||
list_of_types_nls = g_new0 (char *, num_of_types + 1);
|
||||
for (i = 0; i < num_of_types; i++)
|
||||
list_of_types_nls[i] = g_strdup (_(list_of_types[i]));
|
||||
g_strfreev (list_of_types);
|
||||
list_of_types = list_of_types_nls;
|
||||
quick_widgets[last_checkbox + 1].u.radio.items = (const char **) list_of_types;
|
||||
/* radiobuttons */
|
||||
/* create copy of radio items to avoid memory leak */
|
||||
list_of_types_nls = g_new0 (char *, num_of_types + 1);
|
||||
for (i = 0; i < num_of_types; i++)
|
||||
list_of_types_nls[i] = g_strdup (_(list_of_types[i]));
|
||||
g_strfreev (list_of_types);
|
||||
list_of_types = list_of_types_nls;
|
||||
quick_widgets[last_checkbox + 1].u.radio.items = (const char **) list_of_types;
|
||||
#endif
|
||||
|
||||
/* calculate widget coordinates */
|
||||
{
|
||||
int len = 0;
|
||||
int dlg_width;
|
||||
gchar **radio = list_of_types;
|
||||
int b0_len, b1_len, b2_len;
|
||||
const int button_gap = 2;
|
||||
/* calculate widget coordinates */
|
||||
{
|
||||
int len = 0;
|
||||
int dlg_width;
|
||||
gchar **radio = list_of_types;
|
||||
int b0_len, b1_len, b2_len;
|
||||
const int button_gap = 2;
|
||||
|
||||
/* length of radiobuttons */
|
||||
while (*radio != NULL) {
|
||||
len = max (len, str_term_width1 (*radio));
|
||||
radio++;
|
||||
}
|
||||
/* length of checkboxes */
|
||||
for (i = 3; i <= last_checkbox; i++)
|
||||
len = max (len, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);
|
||||
/* length of radiobuttons */
|
||||
while (*radio != NULL)
|
||||
{
|
||||
len = max (len, str_term_width1 (*radio));
|
||||
radio++;
|
||||
}
|
||||
/* length of checkboxes */
|
||||
for (i = 3; i <= last_checkbox; i++)
|
||||
len = max (len, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);
|
||||
|
||||
/* preliminary dialog width */
|
||||
dlg_width = max (len * 2, str_term_width1 (Quick_input.title)) + 4;
|
||||
/* preliminary dialog width */
|
||||
dlg_width = max (len * 2, str_term_width1 (Quick_input.title)) + 4;
|
||||
|
||||
/* length of buttons */
|
||||
b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3;
|
||||
b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 3;
|
||||
b2_len = str_term_width1 (quick_widgets[2].u.button.text) + 5; /* default button */
|
||||
len = b0_len + b1_len + b2_len + button_gap * 2;
|
||||
/* length of buttons */
|
||||
b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3;
|
||||
b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 3;
|
||||
b2_len = str_term_width1 (quick_widgets[2].u.button.text) + 5; /* default button */
|
||||
len = b0_len + b1_len + b2_len + button_gap * 2;
|
||||
|
||||
/* dialog width */
|
||||
Quick_input.xlen = max (SEARCH_DLG_WIDTH, max (dlg_width, len + 6));
|
||||
/* dialog width */
|
||||
Quick_input.xlen = max (SEARCH_DLG_WIDTH, max (dlg_width, len + 6));
|
||||
|
||||
/* correct widget coordinates */
|
||||
for (i = 0; i < sizeof (quick_widgets)/sizeof (quick_widgets[0]); i++)
|
||||
quick_widgets[i].x_divisions = Quick_input.xlen;
|
||||
/* correct widget coordinates */
|
||||
for (i = 0; i < sizeof (quick_widgets) / sizeof (quick_widgets[0]); i++)
|
||||
quick_widgets[i].x_divisions = Quick_input.xlen;
|
||||
|
||||
/* checkbox positions */
|
||||
for (i = 3; i <= last_checkbox; i++)
|
||||
quick_widgets[i].relative_x = Quick_input.xlen/2 + 2;
|
||||
/* input length */
|
||||
quick_widgets[last_checkbox + 2].u.input.len = Quick_input.xlen - 6;
|
||||
/* button positions */
|
||||
quick_widgets[2].relative_x = Quick_input.xlen/2 - len/2;
|
||||
quick_widgets[1].relative_x = quick_widgets[2].relative_x + b2_len + button_gap;
|
||||
quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + button_gap;
|
||||
}
|
||||
/* checkbox positions */
|
||||
for (i = 3; i <= last_checkbox; i++)
|
||||
quick_widgets[i].relative_x = Quick_input.xlen / 2 + 2;
|
||||
/* input length */
|
||||
quick_widgets[last_checkbox + 2].u.input.len = Quick_input.xlen - 6;
|
||||
/* button positions */
|
||||
quick_widgets[2].relative_x = Quick_input.xlen / 2 - len / 2;
|
||||
quick_widgets[1].relative_x = quick_widgets[2].relative_x + b2_len + button_gap;
|
||||
quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + button_gap;
|
||||
}
|
||||
|
||||
dialog_result = quick_dialog (&Quick_input);
|
||||
dialog_result = quick_dialog (&Quick_input);
|
||||
|
||||
g_strfreev (list_of_types);
|
||||
g_strfreev (list_of_types);
|
||||
|
||||
if (dialog_result == B_CANCEL)
|
||||
*search_text = NULL;
|
||||
else if (dialog_result == B_USER)
|
||||
search_create_bookmark = 1;
|
||||
if (dialog_result == B_CANCEL)
|
||||
*search_text = NULL;
|
||||
else if (dialog_result == B_USER)
|
||||
search_create_bookmark = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -314,7 +322,8 @@ editcmd_dialog_raw_key_query (const char *heading, const char *query, int cancel
|
||||
add_widget (raw_dlg, button_new (4, w / 2 - 5, B_CANCEL, NORMAL_BUTTON, _("Cancel"), 0));
|
||||
w = run_dlg (raw_dlg);
|
||||
destroy_dlg (raw_dlg);
|
||||
if (cancel) {
|
||||
if (cancel)
|
||||
{
|
||||
if (w == XCTRL ('g') || w == XCTRL ('c') || w == ESC_CHAR || w == B_CANCEL)
|
||||
return 0;
|
||||
}
|
||||
@ -341,7 +350,7 @@ editcmd_dialog_completion_show (WEdit * edit, int max_len, int word_len,
|
||||
compl_dlg_h = num_compl + 2;
|
||||
compl_dlg_w = max_len + 4;
|
||||
start_x = edit->curs_col + edit->start_col - (compl_dlg_w / 2) +
|
||||
EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
|
||||
EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
|
||||
start_y = edit->curs_row + EDIT_TEXT_VERTICAL_OFFSET + 1;
|
||||
|
||||
if (start_x < 0)
|
||||
@ -370,30 +379,33 @@ editcmd_dialog_completion_show (WEdit * edit, int max_len, int word_len,
|
||||
add_widget (compl_dlg, compl_list);
|
||||
|
||||
/* fill the listbox with the completions */
|
||||
for (i = num_compl - 1; i >= 0; i--) /* reverse order */
|
||||
for (i = num_compl - 1; i >= 0; i--) /* reverse order */
|
||||
listbox_add_item (compl_list, LISTBOX_APPEND_AT_END, 0, (char *) compl[i].text, NULL);
|
||||
|
||||
/* pop up the dialog and apply the choosen completion */
|
||||
if (run_dlg (compl_dlg) == B_ENTER) {
|
||||
if (run_dlg (compl_dlg) == B_ENTER)
|
||||
{
|
||||
listbox_get_current (compl_list, &curr, NULL);
|
||||
if (curr) {
|
||||
if (curr)
|
||||
{
|
||||
#ifdef HAVE_CHARSET
|
||||
GString *temp, *temp2;
|
||||
temp = g_string_new("");
|
||||
for (curr += word_len; *curr; curr++)
|
||||
g_string_append_c(temp, *curr);
|
||||
GString *temp, *temp2;
|
||||
temp = g_string_new ("");
|
||||
for (curr += word_len; *curr; curr++)
|
||||
g_string_append_c (temp, *curr);
|
||||
|
||||
temp2 = str_convert_to_input (temp->str);
|
||||
temp2 = str_convert_to_input (temp->str);
|
||||
|
||||
if (temp2 && temp2->len){
|
||||
g_string_free(temp, TRUE);
|
||||
temp = temp2;
|
||||
}
|
||||
else
|
||||
g_string_free(temp2, TRUE);
|
||||
for (curr = temp->str; *curr; curr++)
|
||||
edit_insert (edit, *curr);
|
||||
g_string_free(temp, TRUE);
|
||||
if (temp2 && temp2->len)
|
||||
{
|
||||
g_string_free (temp, TRUE);
|
||||
temp = temp2;
|
||||
}
|
||||
else
|
||||
g_string_free (temp2, TRUE);
|
||||
for (curr = temp->str; *curr; curr++)
|
||||
edit_insert (edit, *curr);
|
||||
g_string_free (temp, TRUE);
|
||||
#else
|
||||
for (curr += word_len; *curr; curr++)
|
||||
edit_insert (edit, *curr);
|
||||
@ -427,7 +439,7 @@ editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_l
|
||||
def_dlg_h = num_lines + 2;
|
||||
def_dlg_w = max_len + 4;
|
||||
start_x = edit->curs_col + edit->start_col - (def_dlg_w / 2) +
|
||||
EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
|
||||
EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
|
||||
start_y = edit->curs_row + EDIT_TEXT_VERTICAL_OFFSET + 1;
|
||||
|
||||
if (start_x < 0)
|
||||
@ -455,7 +467,8 @@ editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_l
|
||||
add_widget (def_dlg, def_list);
|
||||
|
||||
/* fill the listbox with the completions */
|
||||
for (i = 0; i < num_lines; i++) {
|
||||
for (i = 0; i < num_lines; i++)
|
||||
{
|
||||
label_def =
|
||||
g_strdup_printf ("%s -> %s:%ld", def_hash[i].short_define, def_hash[i].filename,
|
||||
def_hash[i].line);
|
||||
@ -464,31 +477,41 @@ editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_l
|
||||
}
|
||||
|
||||
/* pop up the dialog and apply the choosen completion */
|
||||
if (run_dlg (def_dlg) == B_ENTER) {
|
||||
if (run_dlg (def_dlg) == B_ENTER)
|
||||
{
|
||||
char *tmp_curr_def = (char *) curr_def;
|
||||
int do_moveto = 0;
|
||||
|
||||
listbox_get_current (def_list, &curr, (void **) &tmp_curr_def);
|
||||
curr_def = (etags_hash_t *) tmp_curr_def;
|
||||
if (edit->modified) {
|
||||
if (edit->modified)
|
||||
{
|
||||
if (!edit_query_dialog2
|
||||
(_("Warning"),
|
||||
_(" Current text was modified without a file save. \n"
|
||||
" Continue discards these changes. "), _("C&ontinue"), _("&Cancel"))) {
|
||||
" Continue discards these changes. "), _("C&ontinue"), _("&Cancel")))
|
||||
{
|
||||
edit->force |= REDRAW_COMPLETELY;
|
||||
do_moveto = 1;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
do_moveto = 1;
|
||||
}
|
||||
|
||||
if (curr && do_moveto) {
|
||||
if (edit_stack_iterator + 1 < MAX_HISTORY_MOVETO) {
|
||||
if (curr && do_moveto)
|
||||
{
|
||||
if (edit_stack_iterator + 1 < MAX_HISTORY_MOVETO)
|
||||
{
|
||||
g_free (edit_history_moveto[edit_stack_iterator].filename);
|
||||
if (edit->dir) {
|
||||
if (edit->dir)
|
||||
{
|
||||
edit_history_moveto[edit_stack_iterator].filename =
|
||||
g_strdup_printf ("%s/%s", edit->dir, edit->filename);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
edit_history_moveto[edit_stack_iterator].filename = g_strdup (edit->filename);
|
||||
}
|
||||
edit_history_moveto[edit_stack_iterator].line = edit->start_line +
|
||||
@ -505,7 +528,8 @@ editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_l
|
||||
}
|
||||
|
||||
/* clear definition hash */
|
||||
for (i = 0; i < MAX_DEFINITIONS; i++) {
|
||||
for (i = 0; i < MAX_DEFINITIONS; i++)
|
||||
{
|
||||
g_free (def_hash[i].filename);
|
||||
}
|
||||
|
||||
@ -516,7 +540,8 @@ editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_l
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
editcmd_dialog_replace_prompt_show (WEdit * edit, char *from_text, char *to_text, int xpos, int ypos)
|
||||
editcmd_dialog_replace_prompt_show (WEdit * edit, char *from_text, char *to_text, int xpos,
|
||||
int ypos)
|
||||
{
|
||||
/* dialog sizes */
|
||||
int dlg_height = 9;
|
||||
@ -527,75 +552,74 @@ editcmd_dialog_replace_prompt_show (WEdit * edit, char *from_text, char *to_text
|
||||
int btn_pos;
|
||||
|
||||
char *repl_from, *repl_to;
|
||||
char tmp [BUF_MEDIUM];
|
||||
char tmp[BUF_MEDIUM];
|
||||
|
||||
QuickWidget quick_widgets[] =
|
||||
{
|
||||
/* 0 */ QUICK_BUTTON (44, dlg_width, 6, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
|
||||
/* 1 */ QUICK_BUTTON (29, dlg_width, 6, dlg_height, N_("&Skip"), B_SKIP_REPLACE, NULL),
|
||||
/* 2 */ QUICK_BUTTON (21, dlg_width, 6, dlg_height, N_("A&ll"), B_REPLACE_ALL, NULL),
|
||||
/* 3 */ QUICK_BUTTON ( 4, dlg_width, 6, dlg_height, N_("&Replace"), B_ENTER, NULL),
|
||||
/* 4 */ QUICK_LABEL ( 3, dlg_width, 2, dlg_height, NULL),
|
||||
/* 5 */ QUICK_LABEL ( 2, dlg_width, 3, dlg_height, N_(" Replace with: ")),
|
||||
/* 6 */ QUICK_LABEL ( 3, dlg_width, 4, dlg_height, NULL),
|
||||
QUICK_END
|
||||
QuickWidget quick_widgets[] = {
|
||||
/* 0 */ QUICK_BUTTON (44, dlg_width, 6, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
|
||||
/* 1 */ QUICK_BUTTON (29, dlg_width, 6, dlg_height, N_("&Skip"), B_SKIP_REPLACE, NULL),
|
||||
/* 2 */ QUICK_BUTTON (21, dlg_width, 6, dlg_height, N_("A&ll"), B_REPLACE_ALL, NULL),
|
||||
/* 3 */ QUICK_BUTTON (4, dlg_width, 6, dlg_height, N_("&Replace"), B_ENTER, NULL),
|
||||
/* 4 */ QUICK_LABEL (3, dlg_width, 2, dlg_height, NULL),
|
||||
/* 5 */ QUICK_LABEL (2, dlg_width, 3, dlg_height, N_(" Replace with: ")),
|
||||
/* 6 */ QUICK_LABEL (3, dlg_width, 4, dlg_height, NULL),
|
||||
QUICK_END
|
||||
};
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
for (i = 0; i < 4; i++)
|
||||
quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
|
||||
for (i = 0; i < 4; i++)
|
||||
quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
|
||||
#endif
|
||||
|
||||
/* calculate button positions */
|
||||
btn_pos = 4;
|
||||
|
||||
for (i = 3; i > -1; i--) {
|
||||
for (i = 3; i > -1; i--)
|
||||
{
|
||||
quick_widgets[i].relative_x = btn_pos;
|
||||
btn_pos += str_term_width1 (quick_widgets[i].u.button.text) + 5;
|
||||
if (i == 3) /* default button */
|
||||
if (i == 3) /* default button */
|
||||
btn_pos += 2;
|
||||
}
|
||||
|
||||
dlg_width = btn_pos + 2;
|
||||
|
||||
/* correct widget coordinates */
|
||||
for (i = 0; i < 7; i++)
|
||||
quick_widgets[i].x_divisions = dlg_width;
|
||||
for (i = 0; i < 7; i++)
|
||||
quick_widgets[i].x_divisions = dlg_width;
|
||||
|
||||
g_snprintf (tmp, sizeof (tmp), " '%s'", from_text);
|
||||
repl_from = g_strdup (str_fit_to_term (tmp, dlg_width - 7, J_LEFT));
|
||||
|
||||
g_snprintf (tmp, sizeof (tmp), " '%s'", to_text);
|
||||
repl_to = g_strdup (str_fit_to_term (tmp, dlg_width - 7, J_LEFT));
|
||||
repl_to = g_strdup (str_fit_to_term (tmp, dlg_width - 7, J_LEFT));
|
||||
|
||||
quick_widgets[4].u.label.text = repl_from;
|
||||
quick_widgets[6].u.label.text = repl_to;
|
||||
|
||||
if (xpos == -1)
|
||||
xpos = (edit->num_widget_columns - dlg_width) / 2;
|
||||
xpos = (edit->num_widget_columns - dlg_width) / 2;
|
||||
|
||||
if (ypos == -1)
|
||||
ypos = edit->num_widget_lines * 2 / 3;
|
||||
ypos = edit->num_widget_lines * 2 / 3;
|
||||
|
||||
{
|
||||
QuickDialog Quick_input =
|
||||
{
|
||||
dlg_width, dlg_height, 0, 0, N_ (" Confirm replace "),
|
||||
"[Input Line Keys]", quick_widgets, FALSE
|
||||
};
|
||||
QuickDialog Quick_input = {
|
||||
dlg_width, dlg_height, 0, 0, N_(" Confirm replace "),
|
||||
"[Input Line Keys]", quick_widgets, FALSE
|
||||
};
|
||||
|
||||
/* Sometimes menu can hide replaced text. I don't like it */
|
||||
if ((edit->curs_row >= ypos - 1) && (edit->curs_row <= ypos + dlg_height - 1))
|
||||
ypos -= dlg_height;
|
||||
/* Sometimes menu can hide replaced text. I don't like it */
|
||||
if ((edit->curs_row >= ypos - 1) && (edit->curs_row <= ypos + dlg_height - 1))
|
||||
ypos -= dlg_height;
|
||||
|
||||
Quick_input.ypos = ypos;
|
||||
Quick_input.xpos = xpos;
|
||||
Quick_input.ypos = ypos;
|
||||
Quick_input.xpos = xpos;
|
||||
|
||||
retval = quick_dialog (&Quick_input);
|
||||
g_free (repl_from);
|
||||
g_free (repl_to);
|
||||
retval = quick_dialog (&Quick_input);
|
||||
g_free (repl_from);
|
||||
g_free (repl_to);
|
||||
|
||||
return retval;
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
|
||||
|
889
src/filegui.c
889
src/filegui.c
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -4,7 +4,7 @@
|
||||
Free Software Foundation, Inc.
|
||||
|
||||
Authors: Federico Mena <federico@nuclecu.unam.mx>
|
||||
Miguel de Icaza <miguel@nuclecu.unam.mx>
|
||||
Miguel de Icaza <miguel@nuclecu.unam.mx>
|
||||
|
||||
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
|
||||
@ -75,14 +75,14 @@ file_op_context_new (FileOperation op)
|
||||
* it exists.
|
||||
*/
|
||||
void
|
||||
file_op_context_destroy (FileOpContext *ctx)
|
||||
file_op_context_destroy (FileOpContext * ctx)
|
||||
{
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->ui)
|
||||
file_op_context_destroy_ui (ctx);
|
||||
file_op_context_destroy_ui (ctx);
|
||||
|
||||
mc_search_free(ctx->search_handle);
|
||||
mc_search_free (ctx->search_handle);
|
||||
|
||||
/** \todo FIXME: do we need to free ctx->dest_mask? */
|
||||
|
||||
@ -100,7 +100,7 @@ file_op_total_context_new (void)
|
||||
}
|
||||
|
||||
void
|
||||
file_op_total_context_destroy (FileOpTotalContext *tctx)
|
||||
file_op_total_context_destroy (FileOpTotalContext * tctx)
|
||||
{
|
||||
g_return_if_fail (tctx != NULL);
|
||||
g_free (tctx);
|
||||
|
3158
src/screen.c
3158
src/screen.c
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
675
src/setup.c
675
src/setup.c
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -6,16 +6,16 @@
|
||||
2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
|
||||
|
||||
Written by: 1994, 1995, 1998 Miguel de Icaza
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009 Ilia Maslakov <il.smind@gmail.com>
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009 Ilia Maslakov <il.smind@gmail.com>
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
@ -36,12 +36,12 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
The functions in this section can be bound to hotkeys. They are all
|
||||
of the same type (taking a pointer to mcview_t as parameter and
|
||||
returning void). TODO: In the not-too-distant future, these commands
|
||||
will become fully configurable, like they already are in the
|
||||
internal editor. By convention, all the function names end in
|
||||
"_cmd".
|
||||
The functions in this section can be bound to hotkeys. They are all
|
||||
of the same type (taking a pointer to mcview_t as parameter and
|
||||
returning void). TODO: In the not-too-distant future, these commands
|
||||
will become fully configurable, like they already are in the
|
||||
internal editor. By convention, all the function names end in
|
||||
"_cmd".
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
@ -54,7 +54,7 @@
|
||||
#include "lib/tty/tty.h"
|
||||
#include "lib/tty/key.h"
|
||||
|
||||
#include "src/dialog.h" /* cb_ret_t */
|
||||
#include "src/dialog.h" /* cb_ret_t */
|
||||
#include "src/panel.h"
|
||||
#include "src/layout.h"
|
||||
#include "src/wtools.h"
|
||||
@ -64,7 +64,7 @@
|
||||
#include "src/execute.h"
|
||||
#include "src/help.h"
|
||||
#include "src/keybind.h"
|
||||
#include "src/cmddef.h" /* CK_ cmd name const */
|
||||
#include "src/cmddef.h" /* CK_ cmd name const */
|
||||
|
||||
#include "internal.h"
|
||||
#include "mcviewer.h"
|
||||
@ -81,7 +81,7 @@
|
||||
|
||||
/* Both views */
|
||||
static void
|
||||
mcview_search (mcview_t *view)
|
||||
mcview_search (mcview_t * view)
|
||||
{
|
||||
if (mcview_dialog_search (view))
|
||||
mcview_do_search (view);
|
||||
@ -92,14 +92,18 @@ mcview_search (mcview_t *view)
|
||||
static void
|
||||
mcview_continue_search_cmd (mcview_t * view)
|
||||
{
|
||||
if (view->last_search_string != NULL) {
|
||||
if (view->last_search_string != NULL)
|
||||
{
|
||||
mcview_do_search (view);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* find last search string in history */
|
||||
GList *history;
|
||||
history = history_get (MC_HISTORY_SHARED_SEARCH);
|
||||
if (history != NULL && history->data != NULL) {
|
||||
view->last_search_string = (gchar *) g_strdup(history->data);
|
||||
if (history != NULL && history->data != NULL)
|
||||
{
|
||||
view->last_search_string = (gchar *) g_strdup (history->data);
|
||||
history = g_list_first (history);
|
||||
g_list_foreach (history, (GFunc) g_free, NULL);
|
||||
g_list_free (history);
|
||||
@ -107,12 +111,15 @@ mcview_continue_search_cmd (mcview_t * view)
|
||||
view->search = mc_search_new (view->last_search_string, -1);
|
||||
view->search_nroff_seq = mcview_nroff_seq_new (view);
|
||||
|
||||
if (!view->search) {
|
||||
if (!view->search)
|
||||
{
|
||||
/* if not... then ask for an expression */
|
||||
g_free(view->last_search_string);
|
||||
g_free (view->last_search_string);
|
||||
view->last_search_string = NULL;
|
||||
mcview_search (view);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
view->search->search_type = mcview_search_options.type;
|
||||
view->search->is_all_charsets = mcview_search_options.all_codepages;
|
||||
view->search->is_case_sentitive = mcview_search_options.case_sens;
|
||||
@ -122,9 +129,11 @@ mcview_continue_search_cmd (mcview_t * view)
|
||||
|
||||
mcview_do_search (view);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* if not... then ask for an expression */
|
||||
g_free(view->last_search_string);
|
||||
g_free (view->last_search_string);
|
||||
view->last_search_string = NULL;
|
||||
mcview_search (view);
|
||||
}
|
||||
@ -137,12 +146,14 @@ mcview_continue_search_cmd (mcview_t * view)
|
||||
static cb_ret_t
|
||||
mcview_check_left_right_keys (mcview_t * view, int c)
|
||||
{
|
||||
if (c == KEY_LEFT) {
|
||||
if (c == KEY_LEFT)
|
||||
{
|
||||
mcview_move_left (view, 1);
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
|
||||
if (c == KEY_RIGHT) {
|
||||
if (c == KEY_RIGHT)
|
||||
{
|
||||
mcview_move_right (view, 1);
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
@ -151,7 +162,8 @@ mcview_check_left_right_keys (mcview_t * view, int c)
|
||||
if (view->hex_mode || view->text_wrap_mode)
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
if (c == (KEY_M_CTRL | KEY_LEFT)) {
|
||||
if (c == (KEY_M_CTRL | KEY_LEFT))
|
||||
{
|
||||
if (view->dpy_text_column >= 10)
|
||||
view->dpy_text_column -= 10;
|
||||
else
|
||||
@ -160,7 +172,8 @@ mcview_check_left_right_keys (mcview_t * view, int c)
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
|
||||
if (c == (KEY_M_CTRL | KEY_RIGHT)) {
|
||||
if (c == (KEY_M_CTRL | KEY_RIGHT))
|
||||
{
|
||||
if (view->dpy_text_column <= OFFSETTYPE_MAX - 10)
|
||||
view->dpy_text_column += 10;
|
||||
else
|
||||
@ -216,7 +229,8 @@ mcview_hook (void *v)
|
||||
|
||||
/* If the user is busy typing, wait until he finishes to update the
|
||||
screen */
|
||||
if (!is_idle ()) {
|
||||
if (!is_idle ())
|
||||
{
|
||||
if (!hook_present (idle_hook, mcview_hook))
|
||||
add_hook (&idle_hook, mcview_hook, v);
|
||||
return;
|
||||
@ -247,12 +261,15 @@ mcview_handle_editkey (mcview_t * view, int key)
|
||||
while (node && (node->offset != view->hex_cursor))
|
||||
node = node->next;
|
||||
|
||||
if (!view->hexview_in_text) {
|
||||
if (!view->hexview_in_text)
|
||||
{
|
||||
/* Hex editing */
|
||||
unsigned int hexvalue = 0;
|
||||
if (key >= '0' && key <= '9') {
|
||||
if (key >= '0' && key <= '9')
|
||||
{
|
||||
hexvalue = 0 + (key - '0');
|
||||
} else if (key >= 'A' && key <= 'F')
|
||||
}
|
||||
else if (key >= 'A' && key <= 'F')
|
||||
hexvalue = 10 + (key - 'A');
|
||||
else if (key >= 'a' && key <= 'f')
|
||||
hexvalue = 10 + (key - 'a');
|
||||
@ -264,24 +281,32 @@ mcview_handle_editkey (mcview_t * view, int key)
|
||||
else
|
||||
mcview_get_byte (view, view->hex_cursor, &byte_val);
|
||||
|
||||
if (view->hexedit_lownibble) {
|
||||
if (view->hexedit_lownibble)
|
||||
{
|
||||
byte_val = (byte_val & 0xf0) | (hexvalue);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
byte_val = (byte_val & 0x0f) | (hexvalue << 4);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Text editing */
|
||||
if (key < 256 && ((key == '\n') || is_printable (key)))
|
||||
byte_val = key;
|
||||
else
|
||||
return MSG_NOT_HANDLED;
|
||||
}
|
||||
if (!node) {
|
||||
if (!node)
|
||||
{
|
||||
node = g_new (struct hexedit_change_node, 1);
|
||||
node->offset = view->hex_cursor;
|
||||
node->value = byte_val;
|
||||
mcview_enqueue_change (&view->change_list, node);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
node->value = byte_val;
|
||||
}
|
||||
view->dirty++;
|
||||
@ -292,11 +317,12 @@ mcview_handle_editkey (mcview_t * view, int key)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
mcview_execute_cmd (mcview_t *view, unsigned long command)
|
||||
mcview_execute_cmd (mcview_t * view, unsigned long command)
|
||||
{
|
||||
int res = MSG_HANDLED;
|
||||
|
||||
switch (command) {
|
||||
switch (command)
|
||||
{
|
||||
case CK_ViewHelp:
|
||||
interactive_display (NULL, "[Internal File Viewer]");
|
||||
break;
|
||||
@ -316,19 +342,21 @@ mcview_execute_cmd (mcview_t *view, unsigned long command)
|
||||
view->dirty++;
|
||||
break;
|
||||
case CK_ViewGoto:
|
||||
{
|
||||
off_t addr;
|
||||
{
|
||||
off_t addr;
|
||||
|
||||
if (mcview_dialog_goto (view, &addr)) {
|
||||
if (addr >= 0)
|
||||
mcview_moveto_offset (view, addr);
|
||||
else {
|
||||
message (D_ERROR, _("Warning"), _("Invalid value"));
|
||||
view->dirty++;
|
||||
if (mcview_dialog_goto (view, &addr))
|
||||
{
|
||||
if (addr >= 0)
|
||||
mcview_moveto_offset (view, addr);
|
||||
else
|
||||
{
|
||||
message (D_ERROR, _("Warning"), _("Invalid value"));
|
||||
view->dirty++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CK_ViewHexEditSave:
|
||||
mcview_hexedit_save_changes (view);
|
||||
break;
|
||||
@ -387,12 +415,12 @@ mcview_execute_cmd (mcview_t *view, unsigned long command)
|
||||
case CK_ShowCommandLine:
|
||||
view_other_cmd ();
|
||||
break;
|
||||
/*
|
||||
// Unlike Ctrl-O, run a new shell if the subshell is not running
|
||||
case '!':
|
||||
exec_shell ();
|
||||
return MSG_HANDLED;
|
||||
*/
|
||||
/*
|
||||
// Unlike Ctrl-O, run a new shell if the subshell is not running
|
||||
case '!':
|
||||
exec_shell ();
|
||||
return MSG_HANDLED;
|
||||
*/
|
||||
case CK_ViewGotoBookmark:
|
||||
view->marks[view->marker] = view->dpy_start;
|
||||
break;
|
||||
@ -415,7 +443,7 @@ mcview_execute_cmd (mcview_t *view, unsigned long command)
|
||||
if (mcview_ok_to_quit (view))
|
||||
view->want_to_quit = TRUE;
|
||||
break;
|
||||
default :
|
||||
default:
|
||||
res = MSG_NOT_HANDLED;
|
||||
}
|
||||
return res;
|
||||
@ -429,21 +457,19 @@ mcview_handle_key (mcview_t * view, int key)
|
||||
|
||||
key = convert_from_input_c (key);
|
||||
|
||||
if (view->hex_mode) {
|
||||
if (view->hexedit_mode
|
||||
&& (mcview_handle_editkey (view, key) == MSG_HANDLED))
|
||||
return MSG_HANDLED;
|
||||
if (view->hex_mode)
|
||||
{
|
||||
if (view->hexedit_mode && (mcview_handle_editkey (view, key) == MSG_HANDLED))
|
||||
return MSG_HANDLED;
|
||||
|
||||
command = lookup_keymap_command (view->hex_map, key);
|
||||
if ((command != CK_Ignore_Key)
|
||||
&& (mcview_execute_cmd (view, command) == MSG_HANDLED))
|
||||
return MSG_HANDLED;
|
||||
if ((command != CK_Ignore_Key) && (mcview_execute_cmd (view, command) == MSG_HANDLED))
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
|
||||
command = lookup_keymap_command (view->plain_map, key);
|
||||
if ((command != CK_Ignore_Key)
|
||||
&& (mcview_execute_cmd (view, command) == MSG_HANDLED))
|
||||
return MSG_HANDLED;
|
||||
if ((command != CK_Ignore_Key) && (mcview_execute_cmd (view, command) == MSG_HANDLED))
|
||||
return MSG_HANDLED;
|
||||
|
||||
if (mcview_check_left_right_keys (view, key))
|
||||
return MSG_HANDLED;
|
||||
@ -454,7 +480,8 @@ mcview_handle_key (mcview_t * view, int key)
|
||||
return MSG_HANDLED;
|
||||
|
||||
#ifdef MC_ENABLE_DEBUGGING_CODE
|
||||
if (c == 't') { /* mnemonic: "test" */
|
||||
if (c == 't')
|
||||
{ /* mnemonic: "test" */
|
||||
mcview_ccache_dump (view);
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
@ -470,7 +497,7 @@ mcview_handle_key (mcview_t * view, int key)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline void
|
||||
mcview_adjust_size (Dlg_head *h)
|
||||
mcview_adjust_size (Dlg_head * h)
|
||||
{
|
||||
mcview_t *view;
|
||||
WButtonBar *b;
|
||||
@ -480,7 +507,7 @@ mcview_adjust_size (Dlg_head *h)
|
||||
b = find_buttonbar (h);
|
||||
|
||||
widget_set_size (&view->widget, 0, 0, LINES - 1, COLS);
|
||||
widget_set_size (&b->widget , LINES - 1, 0, 1, COLS);
|
||||
widget_set_size (&b->widget, LINES - 1, 0, 1, COLS);
|
||||
|
||||
mcview_compute_areas (view);
|
||||
mcview_update_bytes_per_line (view);
|
||||
@ -503,7 +530,8 @@ mcview_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
mcview_compute_areas (view);
|
||||
mcview_update_bytes_per_line (view);
|
||||
|
||||
switch (msg) {
|
||||
switch (msg)
|
||||
{
|
||||
case WIDGET_INIT:
|
||||
if (mcview_is_in_panel (view))
|
||||
add_hook (&select_file_hook, mcview_hook, view);
|
||||
@ -555,12 +583,12 @@ mcview_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
cb_ret_t
|
||||
mcview_dialog_callback (Dlg_head *h, Widget *sender,
|
||||
dlg_msg_t msg, int parm, void *data)
|
||||
mcview_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
{
|
||||
mcview_t *view = data;
|
||||
|
||||
switch (msg) {
|
||||
switch (msg)
|
||||
{
|
||||
case DLG_RESIZE:
|
||||
mcview_adjust_size (h);
|
||||
return MSG_HANDLED;
|
||||
|
@ -6,16 +6,16 @@
|
||||
2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
|
||||
|
||||
Written by: 1994, 1995, 1998 Miguel de Icaza
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009 Ilia Maslakov <il.smind@gmail.com>
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009 Ilia Maslakov <il.smind@gmail.com>
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
@ -47,11 +47,11 @@
|
||||
neighbor entries. The algorithm used for determining the line/column
|
||||
for a specific offset needs to be kept synchronized with the one used
|
||||
in display().
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <string.h> /* for g_memmove() */
|
||||
#include <string.h> /* for g_memmove() */
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "lib/tty/tty.h"
|
||||
@ -66,8 +66,7 @@
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
typedef gboolean (*cmp_func_t) (const coord_cache_entry_t *a,
|
||||
const coord_cache_entry_t *b);
|
||||
typedef gboolean (*cmp_func_t) (const coord_cache_entry_t * a, const coord_cache_entry_t * b);
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
@ -77,39 +76,36 @@ typedef gboolean (*cmp_func_t) (const coord_cache_entry_t *a,
|
||||
|
||||
/* insert new cache entry into the cache */
|
||||
static void
|
||||
mcview_ccache_add_entry (coord_cache_t *cache,
|
||||
size_t pos, const coord_cache_entry_t *entry)
|
||||
mcview_ccache_add_entry (coord_cache_t * cache, size_t pos, const coord_cache_entry_t * entry)
|
||||
{
|
||||
if ((cache == NULL) || (entry == NULL))
|
||||
return;
|
||||
return;
|
||||
|
||||
pos = min (pos, cache->size);
|
||||
|
||||
/* increase cache capacity if needed */
|
||||
if (cache->size == cache->capacity) {
|
||||
cache->capacity += CACHE_CAPACITY_DELTA;
|
||||
cache->cache = g_realloc (cache->cache,
|
||||
cache->capacity * sizeof (coord_cache_entry_t *));
|
||||
if (cache->size == cache->capacity)
|
||||
{
|
||||
cache->capacity += CACHE_CAPACITY_DELTA;
|
||||
cache->cache = g_realloc (cache->cache, cache->capacity * sizeof (coord_cache_entry_t *));
|
||||
}
|
||||
|
||||
/* insert new entry */
|
||||
if (pos != cache->size)
|
||||
g_memmove (cache->cache[pos + 1], cache->cache[pos],
|
||||
(cache->size - pos) * sizeof (coord_cache_entry_t *));
|
||||
g_memmove (cache->cache[pos + 1], cache->cache[pos],
|
||||
(cache->size - pos) * sizeof (coord_cache_entry_t *));
|
||||
cache->cache[pos] = g_memdup (entry, sizeof (coord_cache_entry_t));
|
||||
cache->size++;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
mcview_coord_cache_entry_less_offset (const coord_cache_entry_t *a,
|
||||
const coord_cache_entry_t *b)
|
||||
mcview_coord_cache_entry_less_offset (const coord_cache_entry_t * a, const coord_cache_entry_t * b)
|
||||
{
|
||||
return (a->cc_offset < b->cc_offset);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
mcview_coord_cache_entry_less_plain (const coord_cache_entry_t *a,
|
||||
const coord_cache_entry_t *b)
|
||||
mcview_coord_cache_entry_less_plain (const coord_cache_entry_t * a, const coord_cache_entry_t * b)
|
||||
{
|
||||
if (a->cc_line < b->cc_line)
|
||||
return TRUE;
|
||||
@ -122,8 +118,7 @@ mcview_coord_cache_entry_less_plain (const coord_cache_entry_t *a,
|
||||
|
||||
|
||||
static gboolean
|
||||
mcview_coord_cache_entry_less_nroff (const coord_cache_entry_t *a,
|
||||
const coord_cache_entry_t *b)
|
||||
mcview_coord_cache_entry_less_nroff (const coord_cache_entry_t * a, const coord_cache_entry_t * b)
|
||||
{
|
||||
if (a->cc_line < b->cc_line)
|
||||
return TRUE;
|
||||
@ -138,21 +133,24 @@ mcview_coord_cache_entry_less_nroff (const coord_cache_entry_t *a,
|
||||
/* Find and return the index of the last cache entry that is
|
||||
* smaller than ''coord'', according to the criterion ''sort_by''. */
|
||||
static inline size_t
|
||||
mcview_ccache_find (mcview_t *view, const coord_cache_entry_t *coord,
|
||||
cmp_func_t cmp_func)
|
||||
mcview_ccache_find (mcview_t * view, const coord_cache_entry_t * coord, cmp_func_t cmp_func)
|
||||
{
|
||||
size_t base = 0;
|
||||
size_t limit = view->coord_cache->size;
|
||||
|
||||
assert (limit != 0);
|
||||
|
||||
while (limit > 1) {
|
||||
while (limit > 1)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = base + limit / 2;
|
||||
if (cmp_func (coord, view->coord_cache->cache[i])) {
|
||||
if (cmp_func (coord, view->coord_cache->cache[i]))
|
||||
{
|
||||
/* continue the search in the lower half of the cache */
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* continue the search in the upper half of the cache */
|
||||
base = i;
|
||||
}
|
||||
@ -183,16 +181,17 @@ coord_cache_new (void)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
coord_cache_free (coord_cache_t *cache)
|
||||
coord_cache_free (coord_cache_t * cache)
|
||||
{
|
||||
if (cache != NULL) {
|
||||
size_t i;
|
||||
if (cache != NULL)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < cache->size; i++)
|
||||
g_free (cache->cache[i]);
|
||||
for (i = 0; i < cache->size; i++)
|
||||
g_free (cache->cache[i]);
|
||||
|
||||
g_free (cache->cache);
|
||||
g_free (cache);
|
||||
g_free (cache->cache);
|
||||
g_free (cache);
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,7 +217,8 @@ mcview_ccache_dump (mcview_t * view)
|
||||
(void) setvbuf (f, NULL, _IONBF, 0);
|
||||
|
||||
/* cache entries */
|
||||
for (i = 0; i < view->coord_cache->size; i++) {
|
||||
for (i = 0; i < view->coord_cache->size; i++)
|
||||
{
|
||||
(void) fprintf (f,
|
||||
"entry %8u "
|
||||
"offset %8" OFFSETTYPE_PRId " "
|
||||
@ -231,7 +231,8 @@ mcview_ccache_dump (mcview_t * view)
|
||||
(void) fprintf (f, "\n");
|
||||
|
||||
/* offset -> line/column translation */
|
||||
for (offset = 0; offset < filesize; offset++) {
|
||||
for (offset = 0; offset < filesize; offset++)
|
||||
{
|
||||
mcview_offset_to_coord (view, &line, &column, offset);
|
||||
(void) fprintf (f,
|
||||
"offset %8" OFFSETTYPE_PRId " "
|
||||
@ -240,11 +241,13 @@ mcview_ccache_dump (mcview_t * view)
|
||||
}
|
||||
|
||||
/* line/column -> offset translation */
|
||||
for (line = 0; TRUE; line++) {
|
||||
for (line = 0; TRUE; line++)
|
||||
{
|
||||
mcview_coord_to_offset (view, &nextline_offset, line + 1, 0);
|
||||
(void) fprintf (f, "nextline_offset %8" OFFSETTYPE_PRId "\n", nextline_offset);
|
||||
|
||||
for (column = 0; TRUE; column++) {
|
||||
for (column = 0; TRUE; column++)
|
||||
{
|
||||
mcview_coord_to_offset (view, &offset, line, column);
|
||||
if (offset >= nextline_offset)
|
||||
break;
|
||||
@ -270,8 +273,7 @@ mcview_ccache_dump (mcview_t * view)
|
||||
* matches the existing components of ''coord''.
|
||||
*/
|
||||
void
|
||||
mcview_ccache_lookup (mcview_t * view, coord_cache_entry_t *coord,
|
||||
enum ccache_type lookup_what)
|
||||
mcview_ccache_lookup (mcview_t * view, coord_cache_entry_t * coord, enum ccache_type lookup_what)
|
||||
{
|
||||
size_t i;
|
||||
coord_cache_t *cache;
|
||||
@ -280,7 +282,8 @@ mcview_ccache_lookup (mcview_t * view, coord_cache_entry_t *coord,
|
||||
off_t limit;
|
||||
cmp_func_t cmp_func;
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
NROFF_START,
|
||||
NROFF_BACKSPACE,
|
||||
NROFF_CONTINUATION
|
||||
@ -291,7 +294,8 @@ mcview_ccache_lookup (mcview_t * view, coord_cache_entry_t *coord,
|
||||
|
||||
cache = view->coord_cache;
|
||||
|
||||
if (cache->size == 0) {
|
||||
if (cache->size == 0)
|
||||
{
|
||||
current.cc_offset = 0;
|
||||
current.cc_line = 0;
|
||||
current.cc_column = 0;
|
||||
@ -324,17 +328,21 @@ mcview_ccache_lookup (mcview_t * view, coord_cache_entry_t *coord,
|
||||
|
||||
entry = current;
|
||||
nroff_state = NROFF_START;
|
||||
for (; current.cc_offset < limit; current = next) {
|
||||
for (; current.cc_offset < limit; current = next)
|
||||
{
|
||||
int c, nextc;
|
||||
|
||||
if (! mcview_get_byte (view, current.cc_offset, &c))
|
||||
if (!mcview_get_byte (view, current.cc_offset, &c))
|
||||
break;
|
||||
|
||||
if (!cmp_func (¤t, coord)) {
|
||||
if (lookup_what == CCACHE_OFFSET
|
||||
&& view->text_nroff_mode && nroff_state != NROFF_START) {
|
||||
if (!cmp_func (¤t, coord))
|
||||
{
|
||||
if (lookup_what == CCACHE_OFFSET && view->text_nroff_mode && nroff_state != NROFF_START)
|
||||
{
|
||||
/* don't break here */
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -346,43 +354,56 @@ mcview_ccache_lookup (mcview_t * view, coord_cache_entry_t *coord,
|
||||
next.cc_nroff_column = current.cc_nroff_column + 1;
|
||||
|
||||
/* and override some of them as necessary. */
|
||||
if (c == '\r') {
|
||||
if (c == '\r')
|
||||
{
|
||||
mcview_get_byte_indexed (view, current.cc_offset, 1, &nextc);
|
||||
|
||||
/* Ignore '\r' if it is followed by '\r' or '\n'. If it is
|
||||
* followed by anything else, it is a Mac line ending and
|
||||
* produces a line break.
|
||||
*/
|
||||
if (nextc == '\r' || nextc == '\n') {
|
||||
if (nextc == '\r' || nextc == '\n')
|
||||
{
|
||||
next.cc_column = current.cc_column;
|
||||
next.cc_nroff_column = current.cc_nroff_column;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
next.cc_line = current.cc_line + 1;
|
||||
next.cc_column = 0;
|
||||
next.cc_nroff_column = 0;
|
||||
}
|
||||
|
||||
} else if (nroff_state == NROFF_BACKSPACE) {
|
||||
}
|
||||
else if (nroff_state == NROFF_BACKSPACE)
|
||||
{
|
||||
next.cc_nroff_column = current.cc_nroff_column - 1;
|
||||
|
||||
} else if (c == '\t') {
|
||||
}
|
||||
else if (c == '\t')
|
||||
{
|
||||
next.cc_column = mcview_offset_rounddown (current.cc_column, 8) + 8;
|
||||
next.cc_nroff_column = mcview_offset_rounddown (current.cc_nroff_column, 8) + 8;
|
||||
|
||||
} else if (c == '\n') {
|
||||
}
|
||||
else if (c == '\n')
|
||||
{
|
||||
next.cc_line = current.cc_line + 1;
|
||||
next.cc_column = 0;
|
||||
next.cc_nroff_column = 0;
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Use all default values from above */
|
||||
}
|
||||
|
||||
switch (nroff_state) {
|
||||
switch (nroff_state)
|
||||
{
|
||||
case NROFF_START:
|
||||
case NROFF_CONTINUATION:
|
||||
nroff_state = mcview_is_nroff_sequence (view, current.cc_offset)
|
||||
? NROFF_BACKSPACE : NROFF_START;
|
||||
? NROFF_BACKSPACE : NROFF_START;
|
||||
break;
|
||||
case NROFF_BACKSPACE:
|
||||
nroff_state = NROFF_CONTINUATION;
|
||||
@ -397,7 +418,8 @@ mcview_ccache_lookup (mcview_t * view, coord_cache_entry_t *coord,
|
||||
entry = next;
|
||||
}
|
||||
|
||||
if (i + 1 == cache->size && entry.cc_offset != cache->cache[i]->cc_offset) {
|
||||
if (i + 1 == cache->size && entry.cc_offset != cache->cache[i]->cc_offset)
|
||||
{
|
||||
mcview_ccache_add_entry (cache, cache->size, &entry);
|
||||
|
||||
if (!tty_got_interrupt ())
|
||||
@ -406,9 +428,12 @@ mcview_ccache_lookup (mcview_t * view, coord_cache_entry_t *coord,
|
||||
|
||||
tty_disable_interrupt_key ();
|
||||
|
||||
if (lookup_what == CCACHE_OFFSET) {
|
||||
if (lookup_what == CCACHE_OFFSET)
|
||||
{
|
||||
coord->cc_offset = current.cc_offset;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
coord->cc_line = current.cc_line;
|
||||
coord->cc_column = current.cc_column;
|
||||
coord->cc_nroff_column = current.cc_nroff_column;
|
||||
|
@ -6,16 +6,16 @@
|
||||
2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
|
||||
|
||||
Written by: 1994, 1995, 1998 Miguel de Icaza
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009 Ilia Maslakov <il.smind@gmail.com>
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009 Ilia Maslakov <il.smind@gmail.com>
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
@ -36,22 +36,22 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
The data source provides the viewer with data from either a file, a
|
||||
string or the output of a command. The mcview_get_byte() function can be
|
||||
used to get the value of a byte at a specific offset. If the offset
|
||||
is out of range, -1 is returned. The function mcview_get_byte_indexed(a,b)
|
||||
returns the byte at the offset a+b, or -1 if a+b is out of range.
|
||||
The data source provides the viewer with data from either a file, a
|
||||
string or the output of a command. The mcview_get_byte() function can be
|
||||
used to get the value of a byte at a specific offset. If the offset
|
||||
is out of range, -1 is returned. The function mcview_get_byte_indexed(a,b)
|
||||
returns the byte at the offset a+b, or -1 if a+b is out of range.
|
||||
|
||||
The mcview_set_byte() function has the effect that later calls to
|
||||
mcview_get_byte() will return the specified byte for this offset. This
|
||||
function is designed only for use by the hexedit component after
|
||||
saving its changes. Inspect the source before you want to use it for
|
||||
other purposes.
|
||||
The mcview_set_byte() function has the effect that later calls to
|
||||
mcview_get_byte() will return the specified byte for this offset. This
|
||||
function is designed only for use by the hexedit component after
|
||||
saving its changes. Inspect the source before you want to use it for
|
||||
other purposes.
|
||||
|
||||
The mcview_get_filesize() function returns the current size of the
|
||||
data source. If the growing buffer is used, this size may increase
|
||||
later on. Use the mcview_may_still_grow() function when you want to
|
||||
know if the size can change later.
|
||||
The mcview_get_filesize() function returns the current size of the
|
||||
data source. If the growing buffer is used, this size may increase
|
||||
later on. Use the mcview_may_still_grow() function when you want to
|
||||
know if the size can change later.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
@ -99,7 +99,8 @@ mcview_set_datasource_none (mcview_t * view)
|
||||
off_t
|
||||
mcview_get_filesize (mcview_t * view)
|
||||
{
|
||||
switch (view->datasource) {
|
||||
switch (view->datasource)
|
||||
{
|
||||
case DS_NONE:
|
||||
return 0;
|
||||
case DS_STDIO_PIPE:
|
||||
@ -120,7 +121,8 @@ mcview_get_filesize (mcview_t * view)
|
||||
void
|
||||
mcview_update_filesize (mcview_t * view)
|
||||
{
|
||||
if (view->datasource == DS_FILE) {
|
||||
if (view->datasource == DS_FILE)
|
||||
{
|
||||
struct stat st;
|
||||
if (mc_fstat (view->ds_file_fd, &st) != -1)
|
||||
view->ds_file_filesize = st.st_size;
|
||||
@ -164,7 +166,8 @@ mcview_get_utf (mcview_t * view, off_t byte_index, int *char_width, gboolean * r
|
||||
|
||||
*result = TRUE;
|
||||
|
||||
switch (view->datasource) {
|
||||
switch (view->datasource)
|
||||
{
|
||||
case DS_STDIO_PIPE:
|
||||
case DS_VFS_PIPE:
|
||||
str = mcview_get_ptr_growing_buffer (view, byte_index);
|
||||
@ -179,7 +182,8 @@ mcview_get_utf (mcview_t * view, off_t byte_index, int *char_width, gboolean * r
|
||||
break;
|
||||
}
|
||||
|
||||
if (str == NULL) {
|
||||
if (str == NULL)
|
||||
{
|
||||
*result = FALSE;
|
||||
width = 0;
|
||||
return 0;
|
||||
@ -187,16 +191,22 @@ mcview_get_utf (mcview_t * view, off_t byte_index, int *char_width, gboolean * r
|
||||
|
||||
res = g_utf8_get_char_validated (str, -1);
|
||||
|
||||
if (res < 0) {
|
||||
if (res < 0)
|
||||
{
|
||||
ch = *str;
|
||||
width = 0;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
ch = res;
|
||||
/* Calculate UTF-8 char width */
|
||||
next_ch = g_utf8_next_char (str);
|
||||
if (next_ch) {
|
||||
if (next_ch)
|
||||
{
|
||||
width = next_ch - str;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
ch = 0;
|
||||
width = 0;
|
||||
}
|
||||
@ -211,7 +221,8 @@ gboolean
|
||||
mcview_get_byte_string (mcview_t * view, off_t byte_index, int *retval)
|
||||
{
|
||||
assert (view->datasource == DS_STRING);
|
||||
if (byte_index < (off_t) view->ds_string_len) {
|
||||
if (byte_index < (off_t) view->ds_string_len)
|
||||
{
|
||||
if (retval)
|
||||
*retval = view->ds_string_data[byte_index];
|
||||
return TRUE;
|
||||
@ -247,7 +258,7 @@ mcview_set_byte (mcview_t * view, off_t offset, byte b)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/*static*/
|
||||
/*static */
|
||||
void
|
||||
mcview_file_load_data (mcview_t * view, off_t byte_index)
|
||||
{
|
||||
@ -268,7 +279,8 @@ mcview_file_load_data (mcview_t * view, off_t byte_index)
|
||||
goto error;
|
||||
|
||||
bytes_read = 0;
|
||||
while (bytes_read < view->ds_file_datasize) {
|
||||
while (bytes_read < view->ds_file_datasize)
|
||||
{
|
||||
res =
|
||||
mc_read (view->ds_file_fd, view->ds_file_data + bytes_read,
|
||||
view->ds_file_datasize - bytes_read);
|
||||
@ -279,10 +291,13 @@ mcview_file_load_data (mcview_t * view, off_t byte_index)
|
||||
bytes_read += (size_t) res;
|
||||
}
|
||||
view->ds_file_offset = blockoffset;
|
||||
if ((off_t) bytes_read > view->ds_file_filesize - view->ds_file_offset) {
|
||||
if ((off_t) bytes_read > view->ds_file_filesize - view->ds_file_offset)
|
||||
{
|
||||
/* the file has grown in the meantime -- stick to the old size */
|
||||
view->ds_file_datalen = view->ds_file_filesize - view->ds_file_offset;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
view->ds_file_datalen = bytes_read;
|
||||
}
|
||||
return;
|
||||
@ -296,11 +311,13 @@ mcview_file_load_data (mcview_t * view, off_t byte_index)
|
||||
void
|
||||
mcview_close_datasource (mcview_t * view)
|
||||
{
|
||||
switch (view->datasource) {
|
||||
switch (view->datasource)
|
||||
{
|
||||
case DS_NONE:
|
||||
break;
|
||||
case DS_STDIO_PIPE:
|
||||
if (view->ds_stdio_pipe != NULL) {
|
||||
if (view->ds_stdio_pipe != NULL)
|
||||
{
|
||||
(void) pclose (view->ds_stdio_pipe);
|
||||
mcview_display (view);
|
||||
close_error_pipe (D_NORMAL, NULL);
|
||||
@ -309,7 +326,8 @@ mcview_close_datasource (mcview_t * view)
|
||||
mcview_growbuf_free (view);
|
||||
break;
|
||||
case DS_VFS_PIPE:
|
||||
if (view->ds_vfs_pipe != -1) {
|
||||
if (view->ds_vfs_pipe != -1)
|
||||
{
|
||||
(void) mc_close (view->ds_vfs_pipe);
|
||||
view->ds_vfs_pipe = -1;
|
||||
}
|
||||
@ -355,7 +373,8 @@ mcview_load_command_output (mcview_t * view, const char *command)
|
||||
mcview_close_datasource (view);
|
||||
|
||||
open_error_pipe ();
|
||||
if ((fp = popen (command, "r")) == NULL) {
|
||||
if ((fp = popen (command, "r")) == NULL)
|
||||
{
|
||||
/* Avoid two messages. Message from stderr has priority. */
|
||||
mcview_display (view);
|
||||
if (!close_error_pipe (mcview_is_in_panel (view) ? -1 : D_ERROR, NULL))
|
||||
@ -365,7 +384,8 @@ mcview_load_command_output (mcview_t * view, const char *command)
|
||||
|
||||
/* First, check if filter produced any output */
|
||||
mcview_set_datasource_stdio_pipe (view, fp);
|
||||
if (! mcview_get_byte (view, 0, NULL)) {
|
||||
if (!mcview_get_byte (view, 0, NULL))
|
||||
{
|
||||
mcview_close_datasource (view);
|
||||
|
||||
/* Avoid two messages. Message from stderr has priority. */
|
||||
@ -373,7 +393,9 @@ mcview_load_command_output (mcview_t * view, const char *command)
|
||||
if (!close_error_pipe (mcview_is_in_panel (view) ? -1 : D_ERROR, NULL))
|
||||
mcview_show_error (view, _("Empty output from child filter"));
|
||||
return FALSE;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* At least something was read correctly. Close stderr and let
|
||||
* program die if it will try to write something there.
|
||||
|
@ -6,16 +6,16 @@
|
||||
2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
|
||||
|
||||
Written by: 1994, 1995, 1998 Miguel de Icaza
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009 Ilia Maslakov <il.smind@gmail.com>
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009 Ilia Maslakov <il.smind@gmail.com>
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
@ -52,8 +52,7 @@
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
mcview_search_options_t mcview_search_options =
|
||||
{
|
||||
mcview_search_options_t mcview_search_options = {
|
||||
.type = MC_SEARCH_T_NORMAL,
|
||||
.case_sens = FALSE,
|
||||
.backwards = FALSE,
|
||||
@ -87,52 +86,53 @@ mcview_dialog_search (mcview_t * view)
|
||||
gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types);
|
||||
int SEARCH_DLG_HEIGHT = SEARCH_DLG_MIN_HEIGHT + num_of_types - SEARCH_DLG_HEIGHT_SUPPLY;
|
||||
|
||||
QuickWidget quick_widgets[] =
|
||||
{
|
||||
QUICK_BUTTON (6, 10, SEARCH_DLG_HEIGHT - 3, SEARCH_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL),
|
||||
QUICK_BUTTON (2, 10, SEARCH_DLG_HEIGHT - 3, SEARCH_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL),
|
||||
QuickWidget quick_widgets[] = {
|
||||
QUICK_BUTTON (6, 10, SEARCH_DLG_HEIGHT - 3, SEARCH_DLG_HEIGHT, N_("&Cancel"), B_CANCEL,
|
||||
NULL),
|
||||
QUICK_BUTTON (2, 10, SEARCH_DLG_HEIGHT - 3, SEARCH_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL),
|
||||
#ifdef HAVE_CHARSET
|
||||
QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 8, SEARCH_DLG_HEIGHT,
|
||||
N_("All charsets"), &mcview_search_options.all_codepages),
|
||||
QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 8, SEARCH_DLG_HEIGHT,
|
||||
N_("All charsets"), &mcview_search_options.all_codepages),
|
||||
#endif
|
||||
QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT,
|
||||
N_("&Whole words"), &mcview_search_options.whole_words),
|
||||
QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT,
|
||||
N_("&Backwards"), &mcview_search_options.backwards),
|
||||
QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT,
|
||||
N_("case &Sensitive"), &mcview_search_options.case_sens),
|
||||
QUICK_RADIO (3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT,
|
||||
num_of_types, (const char **) list_of_types,
|
||||
(int *) &mcview_search_options.type),
|
||||
QUICK_INPUT (3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT,
|
||||
INPUT_LAST_TEXT, SEARCH_DLG_WIDTH - 6, 0, MC_HISTORY_SHARED_SEARCH, &exp),
|
||||
QUICK_LABEL (2, SEARCH_DLG_WIDTH, 2, SEARCH_DLG_HEIGHT, N_(" Enter search string:")),
|
||||
QUICK_END
|
||||
QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT,
|
||||
N_("&Whole words"), &mcview_search_options.whole_words),
|
||||
QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT,
|
||||
N_("&Backwards"), &mcview_search_options.backwards),
|
||||
QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT,
|
||||
N_("case &Sensitive"), &mcview_search_options.case_sens),
|
||||
QUICK_RADIO (3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT,
|
||||
num_of_types, (const char **) list_of_types,
|
||||
(int *) &mcview_search_options.type),
|
||||
QUICK_INPUT (3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT,
|
||||
INPUT_LAST_TEXT, SEARCH_DLG_WIDTH - 6, 0, MC_HISTORY_SHARED_SEARCH, &exp),
|
||||
QUICK_LABEL (2, SEARCH_DLG_WIDTH, 2, SEARCH_DLG_HEIGHT, N_(" Enter search string:")),
|
||||
QUICK_END
|
||||
};
|
||||
|
||||
QuickDialog Quick_input =
|
||||
{
|
||||
SEARCH_DLG_WIDTH, SEARCH_DLG_HEIGHT, -1, -1,
|
||||
N_("Search"), "[Input Line Keys]",
|
||||
quick_widgets, FALSE
|
||||
QuickDialog Quick_input = {
|
||||
SEARCH_DLG_WIDTH, SEARCH_DLG_HEIGHT, -1, -1,
|
||||
N_("Search"), "[Input Line Keys]",
|
||||
quick_widgets, FALSE
|
||||
};
|
||||
|
||||
qd_result = quick_dialog (&Quick_input);
|
||||
g_strfreev (list_of_types);
|
||||
|
||||
if ((qd_result == B_CANCEL) || (exp == NULL) || (exp[0] == '\0')) {
|
||||
if ((qd_result == B_CANCEL) || (exp == NULL) || (exp[0] == '\0'))
|
||||
{
|
||||
g_free (exp);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
{
|
||||
GString *tmp = str_convert_to_input (exp);
|
||||
GString *tmp = str_convert_to_input (exp);
|
||||
|
||||
if (tmp) {
|
||||
g_free (exp);
|
||||
exp = g_string_free (tmp, FALSE);
|
||||
}
|
||||
if (tmp)
|
||||
{
|
||||
g_free (exp);
|
||||
exp = g_string_free (tmp, FALSE);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -147,13 +147,14 @@ mcview_dialog_search (mcview_t * view)
|
||||
|
||||
view->search = mc_search_new (view->last_search_string, -1);
|
||||
view->search_nroff_seq = mcview_nroff_seq_new (view);
|
||||
if (view->search != NULL) {
|
||||
view->search->search_type = mcview_search_options.type;
|
||||
view->search->is_all_charsets = mcview_search_options.all_codepages;
|
||||
view->search->is_case_sentitive = mcview_search_options.case_sens;
|
||||
view->search->whole_words = mcview_search_options.whole_words;
|
||||
view->search->search_fn = mcview_search_cmd_callback;
|
||||
view->search->update_fn = mcview_search_update_cmd_callback;
|
||||
if (view->search != NULL)
|
||||
{
|
||||
view->search->search_type = mcview_search_options.type;
|
||||
view->search->is_all_charsets = mcview_search_options.all_codepages;
|
||||
view->search->is_case_sentitive = mcview_search_options.case_sens;
|
||||
view->search->whole_words = mcview_search_options.whole_words;
|
||||
view->search->search_fn = mcview_search_cmd_callback;
|
||||
view->search->update_fn = mcview_search_update_cmd_callback;
|
||||
}
|
||||
|
||||
return (view->search != NULL);
|
||||
@ -162,21 +163,21 @@ mcview_dialog_search (mcview_t * view)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
gboolean
|
||||
mcview_dialog_goto (mcview_t *view, off_t *offset)
|
||||
mcview_dialog_goto (mcview_t * view, off_t * offset)
|
||||
{
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
MC_VIEW_GOTO_LINENUM = 0,
|
||||
MC_VIEW_GOTO_PERCENT = 1,
|
||||
MC_VIEW_GOTO_OFFSET_DEC = 2,
|
||||
MC_VIEW_GOTO_OFFSET_HEX = 3
|
||||
} mcview_goto_type_t;
|
||||
|
||||
const char *mc_view_goto_str[] =
|
||||
{
|
||||
N_("&Line number (decimal)"),
|
||||
N_("Pe&rcents"),
|
||||
N_("&Decimal offset"),
|
||||
N_("He&xadecimal offset")
|
||||
const char *mc_view_goto_str[] = {
|
||||
N_("&Line number (decimal)"),
|
||||
N_("Pe&rcents"),
|
||||
N_("&Decimal offset"),
|
||||
N_("He&xadecimal offset")
|
||||
};
|
||||
|
||||
const int goto_dlg_height = 12;
|
||||
@ -186,32 +187,30 @@ mcview_dialog_goto (mcview_t *view, off_t *offset)
|
||||
|
||||
size_t i;
|
||||
|
||||
size_t num_of_types = sizeof (mc_view_goto_str) /sizeof (mc_view_goto_str[0]);
|
||||
size_t num_of_types = sizeof (mc_view_goto_str) / sizeof (mc_view_goto_str[0]);
|
||||
char *exp = NULL;
|
||||
int qd_result;
|
||||
gboolean res = FALSE;
|
||||
|
||||
QuickWidget quick_widgets[] =
|
||||
{
|
||||
QUICK_BUTTON (6, 10, goto_dlg_height - 3, goto_dlg_height, N_("&Cancel"), B_CANCEL, NULL),
|
||||
QUICK_BUTTON (2, 10, goto_dlg_height - 3, goto_dlg_height, N_("&OK"), B_ENTER, NULL),
|
||||
QUICK_RADIO (3, goto_dlg_width, 4, goto_dlg_height,
|
||||
num_of_types, (const char **) mc_view_goto_str, (int *) ¤t_goto_type),
|
||||
QUICK_INPUT (3, goto_dlg_width, 2, goto_dlg_height,
|
||||
INPUT_LAST_TEXT, goto_dlg_width - 6, 0, MC_HISTORY_VIEW_GOTO, &exp),
|
||||
QUICK_END
|
||||
QuickWidget quick_widgets[] = {
|
||||
QUICK_BUTTON (6, 10, goto_dlg_height - 3, goto_dlg_height, N_("&Cancel"), B_CANCEL, NULL),
|
||||
QUICK_BUTTON (2, 10, goto_dlg_height - 3, goto_dlg_height, N_("&OK"), B_ENTER, NULL),
|
||||
QUICK_RADIO (3, goto_dlg_width, 4, goto_dlg_height,
|
||||
num_of_types, (const char **) mc_view_goto_str, (int *) ¤t_goto_type),
|
||||
QUICK_INPUT (3, goto_dlg_width, 2, goto_dlg_height,
|
||||
INPUT_LAST_TEXT, goto_dlg_width - 6, 0, MC_HISTORY_VIEW_GOTO, &exp),
|
||||
QUICK_END
|
||||
};
|
||||
|
||||
QuickDialog Quick_input =
|
||||
{
|
||||
goto_dlg_width, goto_dlg_height, -1, -1,
|
||||
N_("Goto"), "[Input Line Keys]",
|
||||
quick_widgets, FALSE
|
||||
QuickDialog Quick_input = {
|
||||
goto_dlg_width, goto_dlg_height, -1, -1,
|
||||
N_("Goto"), "[Input Line Keys]",
|
||||
quick_widgets, FALSE
|
||||
};
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
for (i = 0; i < num_of_types; i++)
|
||||
mc_view_goto_str [i] = _(mc_view_goto_str [i]);
|
||||
mc_view_goto_str[i] = _(mc_view_goto_str[i]);
|
||||
|
||||
quick_widgets[0].u.button.text = _(quick_widgets[0].u.button.text);
|
||||
quick_widgets[1].u.button.text = _(quick_widgets[1].u.button.text);
|
||||
@ -219,71 +218,74 @@ mcview_dialog_goto (mcview_t *view, off_t *offset)
|
||||
|
||||
/* calculate widget coordinates */
|
||||
{
|
||||
int b0_len, b1_len, len;
|
||||
const int button_gap = 2;
|
||||
int b0_len, b1_len, len;
|
||||
const int button_gap = 2;
|
||||
|
||||
/* preliminary dialog width */
|
||||
goto_dlg_width = max (goto_dlg_width, str_term_width1 (Quick_input.title) + 4);
|
||||
/* preliminary dialog width */
|
||||
goto_dlg_width = max (goto_dlg_width, str_term_width1 (Quick_input.title) + 4);
|
||||
|
||||
/* length of radiobuttons */
|
||||
for (i = 0; i < num_of_types; i++)
|
||||
goto_dlg_width = max (goto_dlg_width, str_term_width1 (mc_view_goto_str [i]) + 10);
|
||||
/* length of radiobuttons */
|
||||
for (i = 0; i < num_of_types; i++)
|
||||
goto_dlg_width = max (goto_dlg_width, str_term_width1 (mc_view_goto_str[i]) + 10);
|
||||
|
||||
/* length of buttons */
|
||||
b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3;
|
||||
b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 5; /* default button */
|
||||
len = b0_len + b1_len + button_gap * 2;
|
||||
/* length of buttons */
|
||||
b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3;
|
||||
b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 5; /* default button */
|
||||
len = b0_len + b1_len + button_gap * 2;
|
||||
|
||||
/* dialog width */
|
||||
Quick_input.xlen = max (goto_dlg_width, len + 6);
|
||||
/* dialog width */
|
||||
Quick_input.xlen = max (goto_dlg_width, len + 6);
|
||||
|
||||
/* correct widget coordinates */
|
||||
for (i = sizeof (quick_widgets)/sizeof (quick_widgets[0]); i > 0; i--)
|
||||
quick_widgets[i - 1].x_divisions = Quick_input.xlen;
|
||||
/* correct widget coordinates */
|
||||
for (i = sizeof (quick_widgets) / sizeof (quick_widgets[0]); i > 0; i--)
|
||||
quick_widgets[i - 1].x_divisions = Quick_input.xlen;
|
||||
|
||||
/* input length */
|
||||
quick_widgets[3].u.input.len = Quick_input.xlen - 6;
|
||||
/* input length */
|
||||
quick_widgets[3].u.input.len = Quick_input.xlen - 6;
|
||||
|
||||
/* button positions */
|
||||
quick_widgets[1].relative_x = Quick_input.xlen/2 - len/2;
|
||||
/* button positions */
|
||||
quick_widgets[1].relative_x = Quick_input.xlen / 2 - len / 2;
|
||||
quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + button_gap;
|
||||
}
|
||||
|
||||
/* run dialog*/
|
||||
/* run dialog */
|
||||
qd_result = quick_dialog (&Quick_input);
|
||||
|
||||
*offset = -1;
|
||||
|
||||
/* check input line value */
|
||||
if ((qd_result != B_CANCEL) && (exp != NULL) && (exp[0] != '\0')) {
|
||||
int base = (current_goto_type == MC_VIEW_GOTO_OFFSET_HEX) ? 16 : 10;
|
||||
off_t addr;
|
||||
char *error;
|
||||
if ((qd_result != B_CANCEL) && (exp != NULL) && (exp[0] != '\0'))
|
||||
{
|
||||
int base = (current_goto_type == MC_VIEW_GOTO_OFFSET_HEX) ? 16 : 10;
|
||||
off_t addr;
|
||||
char *error;
|
||||
|
||||
res = TRUE;
|
||||
res = TRUE;
|
||||
|
||||
addr = strtoll (exp, &error, base);
|
||||
if ((*error == '\0') && (addr >= 0)) {
|
||||
switch (current_goto_type) {
|
||||
case MC_VIEW_GOTO_LINENUM:
|
||||
mcview_coord_to_offset (view, offset, addr, 0);
|
||||
break;
|
||||
case MC_VIEW_GOTO_PERCENT:
|
||||
if (addr > 100)
|
||||
addr = 100;
|
||||
*offset = addr * mcview_get_filesize (view) / 100;
|
||||
break;
|
||||
case MC_VIEW_GOTO_OFFSET_DEC:
|
||||
*offset = addr;
|
||||
break;
|
||||
case MC_VIEW_GOTO_OFFSET_HEX:
|
||||
*offset = addr;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
*offset = mcview_bol (view, *offset);
|
||||
}
|
||||
addr = strtoll (exp, &error, base);
|
||||
if ((*error == '\0') && (addr >= 0))
|
||||
{
|
||||
switch (current_goto_type)
|
||||
{
|
||||
case MC_VIEW_GOTO_LINENUM:
|
||||
mcview_coord_to_offset (view, offset, addr, 0);
|
||||
break;
|
||||
case MC_VIEW_GOTO_PERCENT:
|
||||
if (addr > 100)
|
||||
addr = 100;
|
||||
*offset = addr * mcview_get_filesize (view) / 100;
|
||||
break;
|
||||
case MC_VIEW_GOTO_OFFSET_DEC:
|
||||
*offset = addr;
|
||||
break;
|
||||
case MC_VIEW_GOTO_OFFSET_HEX:
|
||||
*offset = addr;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
*offset = mcview_bol (view, *offset);
|
||||
}
|
||||
}
|
||||
|
||||
g_free (exp);
|
||||
|
@ -6,16 +6,16 @@
|
||||
2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
|
||||
|
||||
Written by: 1994, 1995, 1998 Miguel de Icaza
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009, 2010 Ilia Maslakov <il.smind@gmail.com>
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009, 2010 Ilia Maslakov <il.smind@gmail.com>
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
@ -44,9 +44,9 @@
|
||||
#include "lib/strutil.h"
|
||||
|
||||
#include "src/main.h"
|
||||
#include "src/dialog.h" /* Dlg_head */
|
||||
#include "src/dialog.h" /* Dlg_head */
|
||||
#include "src/charsets.h"
|
||||
#include "src/widget.h" /* WButtonBar */
|
||||
#include "src/widget.h" /* WButtonBar */
|
||||
|
||||
#include "internal.h"
|
||||
#include "mcviewer.h"
|
||||
@ -60,7 +60,8 @@
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/* If set, show a ruler */
|
||||
static enum ruler_type {
|
||||
static enum ruler_type
|
||||
{
|
||||
RULER_NONE,
|
||||
RULER_TOP,
|
||||
RULER_BOTTOM
|
||||
@ -72,7 +73,7 @@ static enum ruler_type {
|
||||
|
||||
/* Define labels and handlers for functional keys */
|
||||
static void
|
||||
mcview_set_buttonbar (mcview_t *view)
|
||||
mcview_set_buttonbar (mcview_t * view)
|
||||
{
|
||||
Dlg_head *h = view->widget.parent;
|
||||
WButtonBar *b = find_buttonbar (h);
|
||||
@ -80,22 +81,24 @@ mcview_set_buttonbar (mcview_t *view)
|
||||
|
||||
buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), keymap, (Widget *) view);
|
||||
|
||||
if (view->hex_mode) {
|
||||
if (view->hexedit_mode)
|
||||
if (view->hex_mode)
|
||||
{
|
||||
if (view->hexedit_mode)
|
||||
buttonbar_set_label (b, 2, Q_ ("ButtonBar|View"), keymap, (Widget *) view);
|
||||
else if (view->datasource == DS_FILE)
|
||||
else if (view->datasource == DS_FILE)
|
||||
buttonbar_set_label (b, 2, Q_ ("ButtonBar|Edit"), keymap, (Widget *) view);
|
||||
else
|
||||
else
|
||||
buttonbar_set_label (b, 2, "", keymap, (Widget *) view);
|
||||
|
||||
buttonbar_set_label (b, 4, Q_ ("ButtonBar|Ascii"), keymap, (Widget *) view);
|
||||
buttonbar_set_label (b, 6, Q_ ("ButtonBar|Save"), keymap, (Widget *) view);
|
||||
buttonbar_set_label (b, 7, Q_ ("ButtonBar|HxSrch"), keymap, (Widget *) view);
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
buttonbar_set_label (b, 2, view->text_wrap_mode ? Q_ ("ButtonBar|UnWrap")
|
||||
: Q_ ("ButtonBar|Wrap"),
|
||||
keymap, (Widget *) view);
|
||||
: Q_ ("ButtonBar|Wrap"), keymap, (Widget *) view);
|
||||
buttonbar_set_label (b, 4, Q_ ("ButtonBar|Hex"), keymap, (Widget *) view);
|
||||
buttonbar_set_label (b, 6, "", keymap, (Widget *) view);
|
||||
buttonbar_set_label (b, 7, Q_ ("ButtonBar|Search"), keymap, (Widget *) view);
|
||||
@ -103,17 +106,16 @@ mcview_set_buttonbar (mcview_t *view)
|
||||
|
||||
buttonbar_set_label (b, 5, Q_ ("ButtonBar|Goto"), keymap, (Widget *) view);
|
||||
buttonbar_set_label (b, 8, view->magic_mode ? Q_ ("ButtonBar|Raw")
|
||||
: Q_ ("ButtonBar|Parse"),
|
||||
keymap, (Widget *) view);
|
||||
: Q_ ("ButtonBar|Parse"), keymap, (Widget *) view);
|
||||
|
||||
if (mcview_is_in_panel (view))
|
||||
buttonbar_set_label (b, 10, "", keymap, (Widget *) view);
|
||||
else {
|
||||
else
|
||||
{
|
||||
/* don't override some panel buttonbar keys */
|
||||
buttonbar_set_label (b, 3, Q_ ("ButtonBar|Quit"), keymap, (Widget *) view);
|
||||
buttonbar_set_label (b, 9, view->text_nroff_mode ? Q_ ("ButtonBar|Unform")
|
||||
: Q_ ("ButtonBar|Format"),
|
||||
keymap, (Widget *) view);
|
||||
: Q_ ("ButtonBar|Format"), keymap, (Widget *) view);
|
||||
buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), keymap, (Widget *) view);
|
||||
}
|
||||
}
|
||||
@ -140,22 +142,25 @@ mcview_display_status (mcview_t * view)
|
||||
|
||||
file_label = view->filename ? view->filename : view->command ? view->command : "";
|
||||
file_label_width = str_term_width1 (file_label) - 2;
|
||||
if (width > 40) {
|
||||
char buffer [BUF_TINY];
|
||||
if (width > 40)
|
||||
{
|
||||
char buffer[BUF_TINY];
|
||||
widget_move (view, top, width - 32);
|
||||
if (view->hex_mode) {
|
||||
if (view->hex_mode)
|
||||
{
|
||||
tty_printf ("0x%08lx", (unsigned long) view->hex_cursor);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
size_trunc_len (buffer, 5, mcview_get_filesize (view), 0);
|
||||
tty_printf ("%9lli/%s%s %s", view->dpy_end,
|
||||
buffer,
|
||||
mcview_may_still_grow (view) ? "+" : " ",
|
||||
buffer, mcview_may_still_grow (view) ? "+" : " ",
|
||||
#ifdef HAVE_CHARSET
|
||||
source_codepage >= 0 ? get_codepage_id (source_codepage) : ""
|
||||
#else
|
||||
""
|
||||
#endif
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
widget_move (view, top, left);
|
||||
@ -178,13 +183,15 @@ mcview_update (mcview_t * view)
|
||||
{
|
||||
static int dirt_limit = 1;
|
||||
|
||||
if (view->dpy_bbar_dirty) {
|
||||
if (view->dpy_bbar_dirty)
|
||||
{
|
||||
view->dpy_bbar_dirty = FALSE;
|
||||
mcview_set_buttonbar (view);
|
||||
buttonbar_redraw (find_buttonbar (view->widget.parent));
|
||||
}
|
||||
|
||||
if (view->dirty > dirt_limit) {
|
||||
if (view->dirty > dirt_limit)
|
||||
{
|
||||
/* Too many updates skipped -> force a update */
|
||||
mcview_display (view);
|
||||
view->dirty = 0;
|
||||
@ -192,14 +199,19 @@ mcview_update (mcview_t * view)
|
||||
dirt_limit++;
|
||||
if (dirt_limit > mcview_max_dirt_limit)
|
||||
dirt_limit = mcview_max_dirt_limit;
|
||||
} else if (view->dirty > 0) {
|
||||
if (is_idle ()) {
|
||||
}
|
||||
else if (view->dirty > 0)
|
||||
{
|
||||
if (is_idle ())
|
||||
{
|
||||
/* We have time to update the screen properly */
|
||||
mcview_display (view);
|
||||
view->dirty = 0;
|
||||
if (dirt_limit > 1)
|
||||
dirt_limit--;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* We are busy -> skipping full update,
|
||||
only the status line is updated */
|
||||
mcview_display_status (view);
|
||||
@ -215,11 +227,16 @@ mcview_update (mcview_t * view)
|
||||
void
|
||||
mcview_display (mcview_t * view)
|
||||
{
|
||||
if (view->hex_mode) {
|
||||
if (view->hex_mode)
|
||||
{
|
||||
mcview_display_hex (view);
|
||||
} else if (view->text_nroff_mode) {
|
||||
}
|
||||
else if (view->text_nroff_mode)
|
||||
{
|
||||
mcview_display_nroff (view);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
mcview_display_text (view);
|
||||
}
|
||||
mcview_display_status (view);
|
||||
@ -267,7 +284,8 @@ mcview_compute_areas (mcview_t * view)
|
||||
view->status_area.top = y;
|
||||
y += view->status_area.height;
|
||||
|
||||
if (ruler == RULER_TOP) {
|
||||
if (ruler == RULER_TOP)
|
||||
{
|
||||
view->ruler_area.top = y;
|
||||
y += view->ruler_area.height;
|
||||
}
|
||||
@ -302,7 +320,8 @@ mcview_update_bytes_per_line (mcview_t * view)
|
||||
void
|
||||
mcview_display_toggle_ruler (mcview_t * view)
|
||||
{
|
||||
static const enum ruler_type next[3] = {
|
||||
static const enum ruler_type next[3] =
|
||||
{
|
||||
RULER_TOP,
|
||||
RULER_BOTTOM,
|
||||
RULER_NONE
|
||||
@ -320,10 +339,11 @@ mcview_display_clean (mcview_t * view)
|
||||
{
|
||||
tty_setcolor (NORMAL_COLOR);
|
||||
widget_erase ((Widget *) view);
|
||||
if (view->dpy_frame_size != 0) {
|
||||
if (view->dpy_frame_size != 0)
|
||||
{
|
||||
tty_draw_box (view->widget.y, view->widget.x, view->widget.lines, view->widget.cols);
|
||||
/* draw_double_box (view->widget.parent, view->widget.y,
|
||||
view->widget.x, view->widget.lines, view->widget.cols);*/
|
||||
/* draw_double_box (view->widget.parent, view->widget.y,
|
||||
view->widget.x, view->widget.lines, view->widget.cols); */
|
||||
}
|
||||
}
|
||||
|
||||
@ -348,16 +368,20 @@ mcview_display_ruler (mcview_t * view)
|
||||
return;
|
||||
|
||||
tty_setcolor (MARKED_COLOR);
|
||||
for (c = 0; c < width; c++) {
|
||||
for (c = 0; c < width; c++)
|
||||
{
|
||||
cl = view->dpy_text_column + c;
|
||||
if (line_row < height) {
|
||||
if (line_row < height)
|
||||
{
|
||||
widget_move (view, top + line_row, left + c);
|
||||
tty_print_char (ruler_chars[cl % 10]);
|
||||
}
|
||||
|
||||
if ((cl != 0) && (cl % 10) == 0) {
|
||||
if ((cl != 0) && (cl % 10) == 0)
|
||||
{
|
||||
g_snprintf (r_buff, sizeof (r_buff), "%" OFFSETTYPE_PRId, (long unsigned int) cl);
|
||||
if (nums_row < height) {
|
||||
if (nums_row < height)
|
||||
{
|
||||
widget_move (view, top + nums_row, left + c - 1);
|
||||
tty_print_string (r_buff);
|
||||
}
|
||||
|
@ -6,16 +6,16 @@
|
||||
2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
|
||||
|
||||
Written by: 1994, 1995, 1998 Miguel de Icaza
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009 Ilia Maslakov <il.smind@gmail.com>
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009 Ilia Maslakov <il.smind@gmail.com>
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
@ -118,8 +118,10 @@ mcview_growbuf_read_until (mcview_t * view, off_t ofs)
|
||||
return;
|
||||
|
||||
short_read = FALSE;
|
||||
while (mcview_growbuf_filesize (view) < ofs || short_read) {
|
||||
if (view->growbuf_lastindex == VIEW_PAGE_SIZE) {
|
||||
while (mcview_growbuf_filesize (view) < ofs || short_read)
|
||||
{
|
||||
if (view->growbuf_lastindex == VIEW_PAGE_SIZE)
|
||||
{
|
||||
/* Append a new block to the growing buffer */
|
||||
byte *newblock = g_try_malloc (VIEW_PAGE_SIZE);
|
||||
if (newblock == NULL)
|
||||
@ -128,16 +130,16 @@ mcview_growbuf_read_until (mcview_t * view, off_t ofs)
|
||||
g_ptr_array_add (view->growbuf_blockptr, newblock);
|
||||
view->growbuf_lastindex = 0;
|
||||
}
|
||||
p = g_ptr_array_index(
|
||||
view->growbuf_blockptr,
|
||||
view->growbuf_blockptr->len - 1)
|
||||
+ view->growbuf_lastindex;
|
||||
p = g_ptr_array_index (view->growbuf_blockptr,
|
||||
view->growbuf_blockptr->len - 1) + view->growbuf_lastindex;
|
||||
|
||||
bytesfree = VIEW_PAGE_SIZE - view->growbuf_lastindex;
|
||||
|
||||
if (view->datasource == DS_STDIO_PIPE) {
|
||||
if (view->datasource == DS_STDIO_PIPE)
|
||||
{
|
||||
nread = fread (p, 1, bytesfree, view->ds_stdio_pipe);
|
||||
if (nread == 0) {
|
||||
if (nread == 0)
|
||||
{
|
||||
view->growbuf_finished = TRUE;
|
||||
(void) pclose (view->ds_stdio_pipe);
|
||||
mcview_display (view);
|
||||
@ -145,12 +147,17 @@ mcview_growbuf_read_until (mcview_t * view, off_t ofs)
|
||||
view->ds_stdio_pipe = NULL;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
assert (view->datasource == DS_VFS_PIPE);
|
||||
do {
|
||||
}
|
||||
else
|
||||
{
|
||||
assert (view->datasource == DS_VFS_PIPE);
|
||||
do
|
||||
{
|
||||
nread = mc_read (view->ds_vfs_pipe, p, bytesfree);
|
||||
} while (nread == -1 && errno == EINTR);
|
||||
if (nread == -1 || nread == 0) {
|
||||
}
|
||||
while (nread == -1 && errno == EINTR);
|
||||
if (nread == -1 || nread == 0)
|
||||
{
|
||||
view->growbuf_finished = TRUE;
|
||||
(void) mc_close (view->ds_vfs_pipe);
|
||||
view->ds_vfs_pipe = -1;
|
||||
@ -184,14 +191,16 @@ mcview_get_byte_growing_buffer (mcview_t * view, off_t byte_index, int *retval)
|
||||
mcview_growbuf_read_until (view, byte_index + 1);
|
||||
if (view->growbuf_blockptr->len == 0)
|
||||
return FALSE;
|
||||
if (pageno < view->growbuf_blockptr->len - 1) {
|
||||
if (pageno < view->growbuf_blockptr->len - 1)
|
||||
{
|
||||
if (retval)
|
||||
*retval = *((byte *) (g_ptr_array_index(view->growbuf_blockptr, pageno) + pageindex));
|
||||
*retval = *((byte *) (g_ptr_array_index (view->growbuf_blockptr, pageno) + pageindex));
|
||||
return TRUE;
|
||||
}
|
||||
if (pageno == view->growbuf_blockptr->len - 1 && pageindex < (off_t) view->growbuf_lastindex) {
|
||||
if (pageno == view->growbuf_blockptr->len - 1 && pageindex < (off_t) view->growbuf_lastindex)
|
||||
{
|
||||
if (retval)
|
||||
*retval = *((byte *) (g_ptr_array_index(view->growbuf_blockptr, pageno) + pageindex));
|
||||
*retval = *((byte *) (g_ptr_array_index (view->growbuf_blockptr, pageno) + pageindex));
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
@ -214,9 +223,9 @@ mcview_get_ptr_growing_buffer (mcview_t * view, off_t byte_index)
|
||||
if (view->growbuf_blockptr->len == 0)
|
||||
return NULL;
|
||||
if (pageno < view->growbuf_blockptr->len - 1)
|
||||
return (char *) (g_ptr_array_index(view->growbuf_blockptr, pageno) + pageindex);
|
||||
return (char *) (g_ptr_array_index (view->growbuf_blockptr, pageno) + pageindex);
|
||||
if (pageno == view->growbuf_blockptr->len - 1 && pageindex < (off_t) view->growbuf_lastindex)
|
||||
return (char *) (g_ptr_array_index(view->growbuf_blockptr, pageno) + pageindex);
|
||||
return (char *) (g_ptr_array_index (view->growbuf_blockptr, pageno) + pageindex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
108
src/viewer/hex.c
108
src/viewer/hex.c
@ -6,16 +6,16 @@
|
||||
2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
|
||||
|
||||
Written by: 1994, 1995, 1998 Miguel de Icaza
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009 Ilia Maslakov <il.smind@gmail.com>
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009 Ilia Maslakov <il.smind@gmail.com>
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
@ -57,7 +57,8 @@
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
MARK_NORMAL,
|
||||
MARK_SELECTED,
|
||||
MARK_CURSOR,
|
||||
@ -104,11 +105,13 @@ mcview_display_hex (mcview_t * view)
|
||||
|
||||
/* Find the first displayable changed byte */
|
||||
from = view->dpy_start;
|
||||
while (curr && (curr->offset < from)) {
|
||||
while (curr && (curr->offset < from))
|
||||
{
|
||||
curr = curr->next;
|
||||
}
|
||||
|
||||
for (row = 0; mcview_get_byte (view, from, NULL) == TRUE && row < height; row++) {
|
||||
for (row = 0; mcview_get_byte (view, from, NULL) == TRUE && row < height; row++)
|
||||
{
|
||||
col = 0;
|
||||
|
||||
/* Print the hex offset */
|
||||
@ -116,17 +119,20 @@ mcview_display_hex (mcview_t * view)
|
||||
(long unsigned int) from);
|
||||
widget_move (view, top + row, left);
|
||||
tty_setcolor (MARKED_COLOR);
|
||||
for (i = 0; col < width && hex_buff[i] != '\0'; i++) {
|
||||
for (i = 0; col < width && hex_buff[i] != '\0'; i++)
|
||||
{
|
||||
tty_print_char (hex_buff[i]);
|
||||
/* tty_print_char(hex_buff[i]);*/
|
||||
/* tty_print_char(hex_buff[i]); */
|
||||
col += 1;
|
||||
}
|
||||
tty_setcolor (NORMAL_COLOR);
|
||||
|
||||
for (bytes = 0; bytes < view->bytes_per_line; bytes++, from++) {
|
||||
for (bytes = 0; bytes < view->bytes_per_line; bytes++, from++)
|
||||
{
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
if (view->utf8) {
|
||||
if (view->utf8)
|
||||
{
|
||||
int cw = 1;
|
||||
gboolean read_res = TRUE;
|
||||
ch = mcview_get_utf (view, from, &cw, &read_res);
|
||||
@ -134,11 +140,12 @@ mcview_display_hex (mcview_t * view)
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
if (! mcview_get_byte (view, from, &c))
|
||||
if (!mcview_get_byte (view, from, &c))
|
||||
break;
|
||||
|
||||
/* Save the cursor position for mcview_place_cursor() */
|
||||
if (from == view->hex_cursor && !view->hexview_in_text) {
|
||||
if (from == view->hex_cursor && !view->hexview_in_text)
|
||||
{
|
||||
view->cursor_row = row;
|
||||
view->cursor_col = col;
|
||||
}
|
||||
@ -151,7 +158,8 @@ mcview_display_hex (mcview_t * view)
|
||||
from < view->search_end) ? MARK_SELECTED : MARK_NORMAL;
|
||||
|
||||
/* Determine the value of the current byte */
|
||||
if (curr != NULL && from == curr->offset) {
|
||||
if (curr != NULL && from == curr->offset)
|
||||
{
|
||||
c = curr->value;
|
||||
curr = curr->next;
|
||||
}
|
||||
@ -165,30 +173,37 @@ mcview_display_hex (mcview_t * view)
|
||||
|
||||
/* Print the hex number */
|
||||
widget_move (view, top + row, left + col);
|
||||
if (col < width) {
|
||||
if (col < width)
|
||||
{
|
||||
tty_print_char (hex_char[c / 16]);
|
||||
col += 1;
|
||||
}
|
||||
if (col < width) {
|
||||
if (col < width)
|
||||
{
|
||||
tty_print_char (hex_char[c % 16]);
|
||||
col += 1;
|
||||
}
|
||||
|
||||
/* Print the separator */
|
||||
tty_setcolor (NORMAL_COLOR);
|
||||
if (bytes != view->bytes_per_line - 1) {
|
||||
if (col < width) {
|
||||
if (bytes != view->bytes_per_line - 1)
|
||||
{
|
||||
if (col < width)
|
||||
{
|
||||
tty_print_char (' ');
|
||||
col += 1;
|
||||
}
|
||||
|
||||
/* After every four bytes, print a group separator */
|
||||
if (bytes % 4 == 3) {
|
||||
if (view->data_area.width >= 80 && col < width) {
|
||||
if (bytes % 4 == 3)
|
||||
{
|
||||
if (view->data_area.width >= 80 && col < width)
|
||||
{
|
||||
tty_print_one_vline ();
|
||||
col += 1;
|
||||
}
|
||||
if (col < width) {
|
||||
if (col < width)
|
||||
{
|
||||
tty_print_char (' ');
|
||||
col += 1;
|
||||
}
|
||||
@ -204,16 +219,23 @@ mcview_display_hex (mcview_t * view)
|
||||
view->hexview_in_text ? VIEW_UNDERLINED_COLOR : MARKED_SELECTED_COLOR);
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
if (utf8_display) {
|
||||
if (!view->utf8) {
|
||||
if (utf8_display)
|
||||
{
|
||||
if (!view->utf8)
|
||||
{
|
||||
ch = convert_from_8bit_to_utf_c ((unsigned char) ch, view->converter);
|
||||
}
|
||||
if (!g_unichar_isprint (ch))
|
||||
ch = '.';
|
||||
} else {
|
||||
if (view->utf8) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (view->utf8)
|
||||
{
|
||||
ch = convert_from_utf_to_current_c (ch, view->converter);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif
|
||||
ch = convert_to_display_c (ch);
|
||||
#ifdef HAVE_CHARSET
|
||||
@ -225,17 +247,22 @@ mcview_display_hex (mcview_t * view)
|
||||
c = '.';
|
||||
|
||||
/* Print corresponding character on the text side */
|
||||
if (text_start + bytes < width) {
|
||||
if (text_start + bytes < width)
|
||||
{
|
||||
widget_move (view, top + row, left + text_start + bytes);
|
||||
if (!view->utf8) {
|
||||
if (!view->utf8)
|
||||
{
|
||||
tty_print_char (c);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
tty_print_anychar (ch);
|
||||
}
|
||||
}
|
||||
|
||||
/* Save the cursor position for mcview_place_cursor() */
|
||||
if (from == view->hex_cursor && view->hexview_in_text) {
|
||||
if (from == view->hex_cursor && view->hexview_in_text)
|
||||
{
|
||||
view->cursor_row = row;
|
||||
view->cursor_col = text_start + bytes;
|
||||
}
|
||||
@ -267,7 +294,8 @@ mcview_hexedit_save_changes (mcview_t * view)
|
||||
if (fp == -1)
|
||||
goto save_error;
|
||||
|
||||
for (curr = view->change_list; curr != NULL; curr = next) {
|
||||
for (curr = view->change_list; curr != NULL; curr = next)
|
||||
{
|
||||
next = curr->next;
|
||||
|
||||
if (mc_lseek (fp, curr->offset, SEEK_SET) == -1 || mc_write (fp, &(curr->value), 1) != 1)
|
||||
@ -280,7 +308,8 @@ mcview_hexedit_save_changes (mcview_t * view)
|
||||
g_free (curr);
|
||||
}
|
||||
|
||||
if (mc_close (fp) == -1) {
|
||||
if (mc_close (fp) == -1)
|
||||
{
|
||||
error = g_strdup (unix_error_string (errno));
|
||||
message (D_ERROR, _(" Save file "),
|
||||
_(" Error while closing the file: \n %s \n"
|
||||
@ -321,7 +350,8 @@ mcview_hexedit_free_change_list (mcview_t * view)
|
||||
{
|
||||
struct hexedit_change_node *curr, *next;
|
||||
|
||||
for (curr = view->change_list; curr != NULL; curr = next) {
|
||||
for (curr = view->change_list; curr != NULL; curr = next)
|
||||
{
|
||||
next = curr->next;
|
||||
g_free (curr);
|
||||
}
|
||||
|
@ -81,7 +81,8 @@ mcview_get_byte_file (mcview_t * view, off_t byte_index, int *retval)
|
||||
assert (view->datasource == DS_FILE);
|
||||
|
||||
mcview_file_load_data (view, byte_index);
|
||||
if (mcview_already_loaded (view->ds_file_offset, byte_index, view->ds_file_datalen)) {
|
||||
if (mcview_already_loaded (view->ds_file_offset, byte_index, view->ds_file_datalen))
|
||||
{
|
||||
if (retval)
|
||||
*retval = view->ds_file_data[byte_index - view->ds_file_offset];
|
||||
return TRUE;
|
||||
@ -96,7 +97,8 @@ mcview_get_byte_file (mcview_t * view, off_t byte_index, int *retval)
|
||||
static inline gboolean
|
||||
mcview_get_byte (mcview_t * view, off_t offset, int *retval)
|
||||
{
|
||||
switch (view->datasource) {
|
||||
switch (view->datasource)
|
||||
{
|
||||
case DS_STDIO_PIPE:
|
||||
case DS_VFS_PIPE:
|
||||
return mcview_get_byte_growing_buffer (view, offset, retval);
|
||||
@ -116,7 +118,8 @@ mcview_get_byte (mcview_t * view, off_t offset, int *retval)
|
||||
static inline gboolean
|
||||
mcview_get_byte_indexed (mcview_t * view, off_t base, off_t ofs, int *retval)
|
||||
{
|
||||
if (base <= OFFSETTYPE_MAX - ofs) {
|
||||
if (base <= OFFSETTYPE_MAX - ofs)
|
||||
{
|
||||
return mcview_get_byte (view, base + ofs, retval);
|
||||
}
|
||||
if (retval)
|
||||
@ -146,13 +149,13 @@ mcview_is_nroff_sequence (mcview_t * view, off_t offset)
|
||||
|
||||
/* The following commands are ordered to speed up the calculation. */
|
||||
|
||||
if (! mcview_get_byte_indexed (view, offset, 1, &c1) || c1 != '\b')
|
||||
if (!mcview_get_byte_indexed (view, offset, 1, &c1) || c1 != '\b')
|
||||
return FALSE;
|
||||
|
||||
if (! mcview_get_byte_indexed (view, offset, 0, &c0) || !g_ascii_isprint (c0))
|
||||
if (!mcview_get_byte_indexed (view, offset, 0, &c0) || !g_ascii_isprint (c0))
|
||||
return FALSE;
|
||||
|
||||
if (! mcview_get_byte_indexed (view, offset, 2, &c2) || !g_ascii_isprint (c2))
|
||||
if (!mcview_get_byte_indexed (view, offset, 2, &c2) || !g_ascii_isprint (c2))
|
||||
return FALSE;
|
||||
|
||||
return (c0 == c2 || c0 == '_' || (c0 == '+' && c2 == 'o'));
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
#include "src/dialog.h"
|
||||
#include "src/widget.h"
|
||||
#include "src/keybind.h" /* global_keymap_t */
|
||||
#include "src/keybind.h" /* global_keymap_t */
|
||||
|
||||
/*** typedefs(not structures) and defined constants ********************/
|
||||
|
||||
@ -30,7 +30,8 @@ extern const off_t OFFSETTYPE_MAX;
|
||||
/*** enums *************************************************************/
|
||||
|
||||
/* data sources of the view */
|
||||
enum view_ds {
|
||||
enum view_ds
|
||||
{
|
||||
DS_NONE, /* No data available */
|
||||
DS_STDIO_PIPE, /* Data comes from a pipe using popen/pclose */
|
||||
DS_VFS_PIPE, /* Data comes from a piped-in VFS file */
|
||||
@ -38,12 +39,14 @@ enum view_ds {
|
||||
DS_STRING /* Data comes from a string in memory */
|
||||
};
|
||||
|
||||
enum ccache_type {
|
||||
enum ccache_type
|
||||
{
|
||||
CCACHE_OFFSET,
|
||||
CCACHE_LINECOL
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
NROFF_TYPE_NONE = 0,
|
||||
NROFF_TYPE_BOLD = 1,
|
||||
NROFF_TYPE_UNDERLINE = 2
|
||||
@ -52,13 +55,15 @@ typedef enum {
|
||||
/*** structures declarations (and typedefs of structures)***************/
|
||||
|
||||
/* A node for building a change list on change_list */
|
||||
struct hexedit_change_node {
|
||||
struct hexedit_change_node
|
||||
{
|
||||
struct hexedit_change_node *next;
|
||||
off_t offset;
|
||||
byte value;
|
||||
};
|
||||
|
||||
struct area {
|
||||
struct area
|
||||
{
|
||||
screen_dimen top, left;
|
||||
screen_dimen height, width;
|
||||
};
|
||||
@ -68,14 +73,16 @@ struct area {
|
||||
* line and column of that cache entry. cc_nroff_column is the column
|
||||
* corresponding to cc_offset in nroff mode.
|
||||
*/
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
off_t cc_offset;
|
||||
off_t cc_line;
|
||||
off_t cc_column;
|
||||
off_t cc_nroff_column;
|
||||
} coord_cache_entry_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
size_t size;
|
||||
size_t capacity;
|
||||
coord_cache_entry_t **cache;
|
||||
@ -83,7 +90,8 @@ typedef struct {
|
||||
|
||||
struct mcview_nroff_struct;
|
||||
|
||||
typedef struct mcview_struct {
|
||||
typedef struct mcview_struct
|
||||
{
|
||||
Widget widget;
|
||||
|
||||
char *filename; /* Name of the file */
|
||||
@ -111,7 +119,7 @@ typedef struct mcview_struct {
|
||||
|
||||
/* Growing buffers information */
|
||||
gboolean growbuf_in_use; /* Use the growing buffers? */
|
||||
GPtrArray *growbuf_blockptr; /* Pointer to the block pointers */
|
||||
GPtrArray *growbuf_blockptr; /* Pointer to the block pointers */
|
||||
size_t growbuf_lastindex; /* Number of bytes in the last page of the
|
||||
growing buffer */
|
||||
gboolean growbuf_finished; /* TRUE when all data has been read. */
|
||||
@ -185,7 +193,8 @@ typedef struct mcview_struct {
|
||||
int search_numNeedSkipChar;
|
||||
} mcview_t;
|
||||
|
||||
typedef struct mcview_nroff_struct {
|
||||
typedef struct mcview_nroff_struct
|
||||
{
|
||||
mcview_t *view;
|
||||
off_t index;
|
||||
int char_width;
|
||||
@ -194,7 +203,8 @@ typedef struct mcview_nroff_struct {
|
||||
nroff_type_t prev_type;
|
||||
} mcview_nroff_t;
|
||||
|
||||
typedef struct mcview_search_options_t {
|
||||
typedef struct mcview_search_options_t
|
||||
{
|
||||
mc_search_type_t type;
|
||||
gboolean case_sens;
|
||||
gboolean backwards;
|
||||
@ -209,20 +219,20 @@ extern mcview_search_options_t mcview_search_options;
|
||||
/*** declarations of public functions **********************************/
|
||||
|
||||
/* actions_cmd.c: */
|
||||
cb_ret_t mcview_callback (Widget *w, widget_msg_t msg, int parm);
|
||||
cb_ret_t mcview_dialog_callback (Dlg_head *h, Widget *sender,
|
||||
dlg_msg_t msg, int parm, void *data);
|
||||
cb_ret_t mcview_callback (Widget * w, widget_msg_t msg, int parm);
|
||||
cb_ret_t mcview_dialog_callback (Dlg_head * h, Widget * sender,
|
||||
dlg_msg_t msg, int parm, void *data);
|
||||
|
||||
/* coord_cache.c: */
|
||||
coord_cache_t *coord_cache_new (void);
|
||||
void coord_cache_free (coord_cache_t *cache);
|
||||
void coord_cache_free (coord_cache_t * cache);
|
||||
|
||||
#ifdef MC_ENABLE_DEBUGGING_CODE
|
||||
void mcview_ccache_dump (mcview_t *view);
|
||||
void mcview_ccache_dump (mcview_t * view);
|
||||
#endif
|
||||
|
||||
void mcview_ccache_lookup (mcview_t *view, coord_cache_entry_t *coord,
|
||||
enum ccache_type lookup_what);
|
||||
void mcview_ccache_lookup (mcview_t * view, coord_cache_entry_t * coord,
|
||||
enum ccache_type lookup_what);
|
||||
|
||||
/* datasource.c: */
|
||||
void mcview_set_datasource_none (mcview_t *);
|
||||
@ -242,46 +252,46 @@ void mcview_set_datasource_vfs_pipe (mcview_t *, int);
|
||||
void mcview_set_datasource_string (mcview_t *, const char *);
|
||||
|
||||
/* dialog.c: */
|
||||
gboolean mcview_dialog_search (mcview_t *view);
|
||||
gboolean mcview_dialog_goto (mcview_t *view, off_t *offset);
|
||||
gboolean mcview_dialog_search (mcview_t * view);
|
||||
gboolean mcview_dialog_goto (mcview_t * view, off_t * offset);
|
||||
|
||||
/* display.c: */
|
||||
void mcview_update (mcview_t *view);
|
||||
void mcview_display (mcview_t *view);
|
||||
void mcview_compute_areas (mcview_t *view);
|
||||
void mcview_update_bytes_per_line (mcview_t *view);
|
||||
void mcview_display_toggle_ruler (mcview_t *view);
|
||||
void mcview_display_clean (mcview_t *view);
|
||||
void mcview_display_ruler (mcview_t *view);
|
||||
void mcview_percent (mcview_t *view, off_t p);
|
||||
void mcview_update (mcview_t * view);
|
||||
void mcview_display (mcview_t * view);
|
||||
void mcview_compute_areas (mcview_t * view);
|
||||
void mcview_update_bytes_per_line (mcview_t * view);
|
||||
void mcview_display_toggle_ruler (mcview_t * view);
|
||||
void mcview_display_clean (mcview_t * view);
|
||||
void mcview_display_ruler (mcview_t * view);
|
||||
void mcview_percent (mcview_t * view, off_t p);
|
||||
|
||||
/* growbuf.c: */
|
||||
void mcview_growbuf_init (mcview_t *view);
|
||||
void mcview_growbuf_free (mcview_t *view);
|
||||
off_t mcview_growbuf_filesize (mcview_t *view);
|
||||
void mcview_growbuf_read_until (mcview_t *view, off_t p);
|
||||
gboolean mcview_get_byte_growing_buffer (mcview_t *view, off_t p, int *);
|
||||
char *mcview_get_ptr_growing_buffer (mcview_t *view, off_t p);
|
||||
void mcview_growbuf_init (mcview_t * view);
|
||||
void mcview_growbuf_free (mcview_t * view);
|
||||
off_t mcview_growbuf_filesize (mcview_t * view);
|
||||
void mcview_growbuf_read_until (mcview_t * view, off_t p);
|
||||
gboolean mcview_get_byte_growing_buffer (mcview_t * view, off_t p, int *);
|
||||
char *mcview_get_ptr_growing_buffer (mcview_t * view, off_t p);
|
||||
|
||||
/* hex.c: */
|
||||
void mcview_display_hex (mcview_t *view);
|
||||
gboolean mcview_hexedit_save_changes (mcview_t *view);
|
||||
void mcview_toggle_hexedit_mode (mcview_t *view);
|
||||
void mcview_hexedit_free_change_list (mcview_t *view);
|
||||
void mcview_display_hex (mcview_t * view);
|
||||
gboolean mcview_hexedit_save_changes (mcview_t * view);
|
||||
void mcview_toggle_hexedit_mode (mcview_t * view);
|
||||
void mcview_hexedit_free_change_list (mcview_t * view);
|
||||
void mcview_enqueue_change (struct hexedit_change_node **, struct hexedit_change_node *);
|
||||
|
||||
/* lib.c: */
|
||||
void mcview_toggle_magic_mode (mcview_t *view);
|
||||
void mcview_toggle_wrap_mode (mcview_t *view);
|
||||
void mcview_toggle_nroff_mode (mcview_t *view);
|
||||
void mcview_toggle_hex_mode (mcview_t *view);
|
||||
gboolean mcview_ok_to_quit (mcview_t *view);
|
||||
void mcview_done (mcview_t *view);
|
||||
void mcview_select_encoding (mcview_t *view);
|
||||
void mcview_set_codeset (mcview_t *view);
|
||||
void mcview_show_error (mcview_t *view, const char *error);
|
||||
off_t mcview_bol (mcview_t *view, off_t current);
|
||||
off_t mcview_eol (mcview_t *view, off_t current);
|
||||
void mcview_toggle_magic_mode (mcview_t * view);
|
||||
void mcview_toggle_wrap_mode (mcview_t * view);
|
||||
void mcview_toggle_nroff_mode (mcview_t * view);
|
||||
void mcview_toggle_hex_mode (mcview_t * view);
|
||||
gboolean mcview_ok_to_quit (mcview_t * view);
|
||||
void mcview_done (mcview_t * view);
|
||||
void mcview_select_encoding (mcview_t * view);
|
||||
void mcview_set_codeset (mcview_t * view);
|
||||
void mcview_show_error (mcview_t * view, const char *error);
|
||||
off_t mcview_bol (mcview_t * view, off_t current);
|
||||
off_t mcview_eol (mcview_t * view, off_t current);
|
||||
|
||||
/* move.c */
|
||||
void mcview_move_up (mcview_t *, off_t);
|
||||
@ -301,10 +311,10 @@ void mcview_place_cursor (mcview_t *);
|
||||
void mcview_moveto_match (mcview_t *);
|
||||
|
||||
/* nroff.c: */
|
||||
void mcview_display_nroff (mcview_t *view);
|
||||
int mcview__get_nroff_real_len (mcview_t *view, off_t, off_t p);
|
||||
void mcview_display_nroff (mcview_t * view);
|
||||
int mcview__get_nroff_real_len (mcview_t * view, off_t, off_t p);
|
||||
|
||||
mcview_nroff_t *mcview_nroff_seq_new_num (mcview_t *view, off_t p);
|
||||
mcview_nroff_t *mcview_nroff_seq_new_num (mcview_t * view, off_t p);
|
||||
mcview_nroff_t *mcview_nroff_seq_new (mcview_t * view);
|
||||
void mcview_nroff_seq_free (mcview_nroff_t **);
|
||||
nroff_type_t mcview_nroff_seq_info (mcview_nroff_t *);
|
||||
@ -316,11 +326,11 @@ void mcview_display_text (mcview_t *);
|
||||
/* search.c: */
|
||||
int mcview_search_cmd_callback (const void *user_data, gsize char_offset);
|
||||
int mcview_search_update_cmd_callback (const void *, gsize);
|
||||
void mcview_do_search (mcview_t *view);
|
||||
void mcview_do_search (mcview_t * view);
|
||||
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
#include "inlines.h"
|
||||
|
||||
#endif /* MC_VIEWER_INTERNAL_H */
|
||||
#endif /* MC_VIEWER_INTERNAL_H */
|
||||
|
@ -6,16 +6,16 @@
|
||||
2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
|
||||
|
||||
Written by: 1994, 1995, 1998 Miguel de Icaza
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009 Ilia Maslakov <il.smind@gmail.com>
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009 Ilia Maslakov <il.smind@gmail.com>
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
@ -115,11 +115,14 @@ mcview_toggle_hex_mode (mcview_t * view)
|
||||
{
|
||||
view->hex_mode = !view->hex_mode;
|
||||
|
||||
if (view->hex_mode) {
|
||||
if (view->hex_mode)
|
||||
{
|
||||
view->hex_cursor = view->dpy_start;
|
||||
view->dpy_start = mcview_offset_rounddown (view->dpy_start, view->bytes_per_line);
|
||||
view->widget.options |= W_WANT_CURSOR;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
view->dpy_start = view->hex_cursor;
|
||||
mcview_moveto_bol (view);
|
||||
view->widget.options &= ~W_WANT_CURSOR;
|
||||
@ -143,7 +146,8 @@ mcview_ok_to_quit (mcview_t * view)
|
||||
_(" File was modified, Save with exit? "), D_NORMAL, 3,
|
||||
_("&Cancel quit"), _("&Yes"), _("&No"));
|
||||
|
||||
switch (r) {
|
||||
switch (r)
|
||||
{
|
||||
case 1:
|
||||
return mcview_hexedit_save_changes (view);
|
||||
case 2:
|
||||
@ -160,7 +164,8 @@ void
|
||||
mcview_done (mcview_t * view)
|
||||
{
|
||||
/* Save current file position */
|
||||
if (mcview_remember_file_position && view->filename != NULL) {
|
||||
if (mcview_remember_file_position && view->filename != NULL)
|
||||
{
|
||||
char *canon_fname;
|
||||
canon_fname = vfs_canon (view->filename);
|
||||
save_file_position (canon_fname, -1, 0, view->dpy_start);
|
||||
@ -185,7 +190,8 @@ mcview_done (mcview_t * view)
|
||||
|
||||
coord_cache_free (view->coord_cache), view->coord_cache = NULL;
|
||||
|
||||
if (!(view->converter == INVALID_CONV || view->converter != str_cnv_from_term)) {
|
||||
if (!(view->converter == INVALID_CONV || view->converter != str_cnv_from_term))
|
||||
{
|
||||
str_close_conv (view->converter);
|
||||
view->converter = str_cnv_from_term;
|
||||
}
|
||||
@ -203,10 +209,12 @@ mcview_set_codeset (mcview_t * view)
|
||||
|
||||
view->utf8 = TRUE;
|
||||
cp_id = get_codepage_id (source_codepage >= 0 ? source_codepage : display_codepage);
|
||||
if (cp_id != NULL) {
|
||||
if (cp_id != NULL)
|
||||
{
|
||||
GIConv conv;
|
||||
conv = str_crt_conv_from (cp_id);
|
||||
if (conv != INVALID_CONV) {
|
||||
if (conv != INVALID_CONV)
|
||||
{
|
||||
if (view->converter != str_cnv_from_term)
|
||||
str_close_conv (view->converter);
|
||||
view->converter = conv;
|
||||
@ -224,7 +232,8 @@ void
|
||||
mcview_select_encoding (mcview_t * view)
|
||||
{
|
||||
#ifdef HAVE_CHARSET
|
||||
if (do_select_codepage ()) {
|
||||
if (do_select_codepage ())
|
||||
{
|
||||
mcview_set_codeset (view);
|
||||
}
|
||||
#else
|
||||
@ -238,9 +247,12 @@ void
|
||||
mcview_show_error (mcview_t * view, const char *msg)
|
||||
{
|
||||
mcview_close_datasource (view);
|
||||
if (mcview_is_in_panel (view)) {
|
||||
if (mcview_is_in_panel (view))
|
||||
{
|
||||
mcview_set_datasource_string (view, msg);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR, "%s", msg);
|
||||
}
|
||||
}
|
||||
@ -261,13 +273,15 @@ mcview_bol (mcview_t * view, off_t current)
|
||||
return filesize;
|
||||
if (!mcview_get_byte (view, current, &c))
|
||||
return current;
|
||||
if (c == '\n') {
|
||||
if (c == '\n')
|
||||
{
|
||||
if (!mcview_get_byte (view, current - 1, &c))
|
||||
return current;
|
||||
if (c == '\r')
|
||||
current--;
|
||||
}
|
||||
while (current > 0) {
|
||||
while (current > 0)
|
||||
{
|
||||
if (!mcview_get_byte (view, current - 1, &c))
|
||||
break;
|
||||
if (c == '\r' || c == '\n')
|
||||
@ -289,13 +303,17 @@ mcview_eol (mcview_t * view, off_t current)
|
||||
return 0;
|
||||
if (current >= filesize)
|
||||
return filesize;
|
||||
while (current < filesize) {
|
||||
while (current < filesize)
|
||||
{
|
||||
if (!mcview_get_byte (view, current, &c))
|
||||
break;
|
||||
if (c == '\n') {
|
||||
if (c == '\n')
|
||||
{
|
||||
current++;
|
||||
break;
|
||||
} else if (prev_ch == '\r') {
|
||||
}
|
||||
else if (prev_ch == '\r')
|
||||
{
|
||||
break;
|
||||
}
|
||||
current++;
|
||||
|
@ -6,16 +6,16 @@
|
||||
2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
|
||||
|
||||
Written by: 1994, 1995, 1998 Miguel de Icaza
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009 Ilia Maslakov <il.smind@gmail.com>
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009 Ilia Maslakov <il.smind@gmail.com>
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
@ -46,8 +46,8 @@
|
||||
|
||||
#include "src/main.h"
|
||||
#include "src/charsets.h"
|
||||
#include "src/main-widgets.h" /* the_menubar */
|
||||
#include "src/menu.h" /* menubar_visible */
|
||||
#include "src/main-widgets.h" /* the_menubar */
|
||||
#include "src/menu.h" /* menubar_visible */
|
||||
#include "src/widget.h"
|
||||
|
||||
#include "internal.h"
|
||||
@ -88,18 +88,18 @@ char *mcview_show_eof = NULL;
|
||||
|
||||
/* Both views */
|
||||
static int
|
||||
mcview_event (mcview_t *view, Gpm_Event *event, int *result)
|
||||
mcview_event (mcview_t * view, Gpm_Event * event, int *result)
|
||||
{
|
||||
screen_dimen y, x;
|
||||
|
||||
*result = MOU_NORMAL;
|
||||
|
||||
/* rest of the upper frame, the menu is invisible - call menu */
|
||||
if (mcview_is_in_panel (view) && (event->type & GPM_DOWN)
|
||||
&& event->y == 1 && !menubar_visible) {
|
||||
event->x += view->widget.x;
|
||||
*result = the_menubar->widget.mouse (event, the_menubar);
|
||||
return 0; /* don't draw viewer over menu */
|
||||
if (mcview_is_in_panel (view) && (event->type & GPM_DOWN) && event->y == 1 && !menubar_visible)
|
||||
{
|
||||
event->x += view->widget.x;
|
||||
*result = the_menubar->widget.mouse (event, the_menubar);
|
||||
return 0; /* don't draw viewer over menu */
|
||||
}
|
||||
|
||||
/* We are not interested in the release events */
|
||||
@ -107,11 +107,13 @@ mcview_event (mcview_t *view, Gpm_Event *event, int *result)
|
||||
return 0;
|
||||
|
||||
/* Wheel events */
|
||||
if ((event->buttons & GPM_B_UP) && (event->type & GPM_DOWN)) {
|
||||
if ((event->buttons & GPM_B_UP) && (event->type & GPM_DOWN))
|
||||
{
|
||||
mcview_move_up (view, 2);
|
||||
return 1;
|
||||
}
|
||||
if ((event->buttons & GPM_B_DOWN) && (event->type & GPM_DOWN)) {
|
||||
if ((event->buttons & GPM_B_DOWN) && (event->type & GPM_DOWN))
|
||||
{
|
||||
mcview_move_down (view, 2);
|
||||
return 1;
|
||||
}
|
||||
@ -120,28 +122,39 @@ mcview_event (mcview_t *view, Gpm_Event *event, int *result)
|
||||
y = event->y;
|
||||
|
||||
/* Scrolling left and right */
|
||||
if (!view->text_wrap_mode) {
|
||||
if (x < view->data_area.width * 1 / 4) {
|
||||
if (!view->text_wrap_mode)
|
||||
{
|
||||
if (x < view->data_area.width * 1 / 4)
|
||||
{
|
||||
mcview_move_left (view, 1);
|
||||
goto processed;
|
||||
} else if (x < view->data_area.width * 3 / 4) {
|
||||
}
|
||||
else if (x < view->data_area.width * 3 / 4)
|
||||
{
|
||||
/* ignore the click */
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
mcview_move_right (view, 1);
|
||||
goto processed;
|
||||
}
|
||||
}
|
||||
|
||||
/* Scrolling up and down */
|
||||
if (y < view->data_area.top + view->data_area.height * 1 / 3) {
|
||||
if (y < view->data_area.top + view->data_area.height * 1 / 3)
|
||||
{
|
||||
if (mcview_mouse_move_pages)
|
||||
mcview_move_up (view, view->data_area.height / 2);
|
||||
else
|
||||
mcview_move_up (view, 1);
|
||||
goto processed;
|
||||
} else if (y < view->data_area.top + view->data_area.height * 2 / 3) {
|
||||
}
|
||||
else if (y < view->data_area.top + view->data_area.height * 2 / 3)
|
||||
{
|
||||
/* ignore the click */
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mcview_mouse_move_pages)
|
||||
mcview_move_down (view, view->data_area.height / 2);
|
||||
else
|
||||
@ -270,7 +283,7 @@ mcview_viewer (const char *command, const char *file, int *move_dir_p, int start
|
||||
|
||||
/* Create dialog and widgets, put them on the dialog */
|
||||
view_dlg = create_dlg (0, 0, LINES, COLS, NULL, mcview_dialog_callback,
|
||||
"[Internal File Viewer]", NULL, DLG_WANT_TAB);
|
||||
"[Internal File Viewer]", NULL, DLG_WANT_TAB);
|
||||
|
||||
lc_mcview = mcview_new (0, 0, LINES - 1, COLS, 0);
|
||||
add_widget (view_dlg, lc_mcview);
|
||||
@ -278,11 +291,14 @@ mcview_viewer (const char *command, const char *file, int *move_dir_p, int start
|
||||
add_widget (view_dlg, buttonbar_new (TRUE));
|
||||
|
||||
succeeded = mcview_load (lc_mcview, command, file, start_line);
|
||||
if (succeeded) {
|
||||
if (succeeded)
|
||||
{
|
||||
run_dlg (view_dlg);
|
||||
if (move_dir_p)
|
||||
*move_dir_p = lc_mcview->move_dir;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (move_dir_p)
|
||||
*move_dir_p = 0;
|
||||
}
|
||||
@ -319,15 +335,20 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l
|
||||
for (i = 0; i < 10; i++)
|
||||
view->marks[i] = 0;
|
||||
|
||||
if (!mcview_is_in_panel (view)) {
|
||||
if (!mcview_is_in_panel (view))
|
||||
{
|
||||
view->dpy_text_column = 0;
|
||||
}
|
||||
|
||||
if (command && (view->magic_mode || file == NULL || file[0] == '\0')) {
|
||||
if (command && (view->magic_mode || file == NULL || file[0] == '\0'))
|
||||
{
|
||||
retval = mcview_load_command_output (view, command);
|
||||
} else if (file != NULL && file[0] != '\0') {
|
||||
}
|
||||
else if (file != NULL && file[0] != '\0')
|
||||
{
|
||||
/* Open the file */
|
||||
if ((fd = mc_open (file, O_RDONLY | O_NONBLOCK)) == -1) {
|
||||
if ((fd = mc_open (file, O_RDONLY | O_NONBLOCK)) == -1)
|
||||
{
|
||||
g_snprintf (tmp, sizeof (tmp), _(" Cannot open \"%s\"\n %s "),
|
||||
file, unix_error_string (errno));
|
||||
mcview_show_error (view, tmp);
|
||||
@ -337,7 +358,8 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l
|
||||
}
|
||||
|
||||
/* Make sure we are working with a regular file */
|
||||
if (mc_fstat (fd, &st) == -1) {
|
||||
if (mc_fstat (fd, &st) == -1)
|
||||
{
|
||||
mc_close (fd);
|
||||
g_snprintf (tmp, sizeof (tmp), _(" Cannot stat \"%s\"\n %s "),
|
||||
file, unix_error_string (errno));
|
||||
@ -347,7 +369,8 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (!S_ISREG (st.st_mode)) {
|
||||
if (!S_ISREG (st.st_mode))
|
||||
{
|
||||
mc_close (fd);
|
||||
mcview_show_error (view, _(" Cannot view: not a regular file "));
|
||||
g_free (view->filename);
|
||||
@ -355,13 +378,17 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (st.st_size == 0 || mc_lseek (fd, 0, SEEK_SET) == -1) {
|
||||
if (st.st_size == 0 || mc_lseek (fd, 0, SEEK_SET) == -1)
|
||||
{
|
||||
/* Must be one of those nice files that grow (/proc) */
|
||||
mcview_set_datasource_vfs_pipe (view, fd);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
type = get_compression_type (fd, file);
|
||||
|
||||
if (view->magic_mode && (type != COMPRESSION_NONE)) {
|
||||
if (view->magic_mode && (type != COMPRESSION_NONE))
|
||||
{
|
||||
g_free (view->filename);
|
||||
view->filename = g_strconcat (file, decompress_extension (type), (char *) NULL);
|
||||
}
|
||||
@ -380,7 +407,8 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l
|
||||
mcview_compute_areas (view);
|
||||
mcview_update_bytes_per_line (view);
|
||||
|
||||
if (mcview_remember_file_position && view->filename != NULL && start_line == 0) {
|
||||
if (mcview_remember_file_position && view->filename != NULL && start_line == 0)
|
||||
{
|
||||
long line, col;
|
||||
off_t new_offset;
|
||||
canon_fname = vfs_canon (view->filename);
|
||||
@ -388,7 +416,9 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l
|
||||
new_offset = min (new_offset, mcview_get_filesize (view));
|
||||
view->dpy_start = mcview_bol (view, new_offset);
|
||||
g_free (canon_fname);
|
||||
} else if (start_line > 0) {
|
||||
}
|
||||
else if (start_line > 0)
|
||||
{
|
||||
mcview_moveto (view, start_line - 1, 0);
|
||||
}
|
||||
|
||||
|
@ -43,8 +43,7 @@ extern struct mcview_struct *mcview_new (int y, int x, int lines, int cols, int
|
||||
* point to a variable that will receive the direction in which the user
|
||||
* wants to move (-1 = previous file, 1 = next file, 0 = do nothing).
|
||||
*/
|
||||
extern int mcview_viewer (const char *command, const char *file,
|
||||
int *move_dir_p, int start_line);
|
||||
extern int mcview_viewer (const char *command, const char *file, int *move_dir_p, int start_line);
|
||||
|
||||
extern gboolean mcview_load (struct mcview_struct *, const char *, const char *, int);
|
||||
|
||||
|
@ -6,16 +6,16 @@
|
||||
2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
|
||||
|
||||
Written by: 1994, 1995, 1998 Miguel de Icaza
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009, 2010 Ilia Maslakov <il.smind@gmail.com>
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009, 2010 Ilia Maslakov <il.smind@gmail.com>
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
@ -71,7 +71,8 @@ static void
|
||||
mcview_movement_fixups (mcview_t * view, gboolean reset_search)
|
||||
{
|
||||
mcview_scroll_to_cursor (view);
|
||||
if (reset_search) {
|
||||
if (reset_search)
|
||||
{
|
||||
view->search_start = view->dpy_start;
|
||||
view->search_end = view->dpy_start;
|
||||
}
|
||||
@ -88,18 +89,25 @@ void
|
||||
mcview_move_up (mcview_t * view, off_t lines)
|
||||
{
|
||||
off_t new_offset;
|
||||
if (view->hex_mode) {
|
||||
if (view->hex_mode)
|
||||
{
|
||||
off_t bytes = lines * view->bytes_per_line;
|
||||
if (view->hex_cursor >= bytes) {
|
||||
if (view->hex_cursor >= bytes)
|
||||
{
|
||||
view->hex_cursor -= bytes;
|
||||
if (view->hex_cursor < view->dpy_start)
|
||||
view->dpy_start = mcview_offset_doz (view->dpy_start, bytes);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
view->hex_cursor %= view->bytes_per_line;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
off_t i;
|
||||
for (i = 0; i < lines; i++) {
|
||||
for (i = 0; i < lines; i++)
|
||||
{
|
||||
new_offset = mcview_bol (view, view->dpy_start);
|
||||
if (new_offset > 0)
|
||||
new_offset--;
|
||||
@ -119,21 +127,26 @@ mcview_move_down (mcview_t * view, off_t lines)
|
||||
{
|
||||
off_t last_byte;
|
||||
last_byte = mcview_get_filesize (view);
|
||||
if (view->hex_mode) {
|
||||
if (view->hex_mode)
|
||||
{
|
||||
off_t i, limit;
|
||||
|
||||
if (last_byte >= (off_t) view->bytes_per_line)
|
||||
limit = last_byte - view->bytes_per_line;
|
||||
else
|
||||
limit = 0;
|
||||
for (i = 0; i < lines && view->hex_cursor < limit; i++) {
|
||||
for (i = 0; i < lines && view->hex_cursor < limit; i++)
|
||||
{
|
||||
view->hex_cursor += view->bytes_per_line;
|
||||
if (lines != 1)
|
||||
view->dpy_start += view->bytes_per_line;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
off_t i;
|
||||
for (i = 0; i < lines; i++) {
|
||||
for (i = 0; i < lines; i++)
|
||||
{
|
||||
off_t new_offset;
|
||||
new_offset = mcview_eol (view, view->dpy_start);
|
||||
view->dpy_start = new_offset;
|
||||
@ -147,19 +160,25 @@ mcview_move_down (mcview_t * view, off_t lines)
|
||||
void
|
||||
mcview_move_left (mcview_t * view, off_t columns)
|
||||
{
|
||||
if (view->hex_mode) {
|
||||
if (view->hex_mode)
|
||||
{
|
||||
off_t old_cursor = view->hex_cursor;
|
||||
assert (columns == 1);
|
||||
if (view->hexview_in_text || !view->hexedit_lownibble) {
|
||||
if (view->hexview_in_text || !view->hexedit_lownibble)
|
||||
{
|
||||
if (view->hex_cursor > 0)
|
||||
view->hex_cursor--;
|
||||
}
|
||||
if (!view->hexview_in_text)
|
||||
if (old_cursor > 0 || view->hexedit_lownibble)
|
||||
view->hexedit_lownibble = !view->hexedit_lownibble;
|
||||
} else if (view->text_wrap_mode) {
|
||||
}
|
||||
else if (view->text_wrap_mode)
|
||||
{
|
||||
/* nothing to do */
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (view->dpy_text_column >= columns)
|
||||
view->dpy_text_column -= columns;
|
||||
else
|
||||
@ -173,21 +192,27 @@ mcview_move_left (mcview_t * view, off_t columns)
|
||||
void
|
||||
mcview_move_right (mcview_t * view, off_t columns)
|
||||
{
|
||||
if (view->hex_mode) {
|
||||
if (view->hex_mode)
|
||||
{
|
||||
off_t last_byte;
|
||||
off_t old_cursor = view->hex_cursor;
|
||||
last_byte = mcview_offset_doz(mcview_get_filesize (view), 1);
|
||||
last_byte = mcview_offset_doz (mcview_get_filesize (view), 1);
|
||||
assert (columns == 1);
|
||||
if (view->hexview_in_text || view->hexedit_lownibble) {
|
||||
if (view->hexview_in_text || view->hexedit_lownibble)
|
||||
{
|
||||
if (view->hex_cursor < last_byte)
|
||||
view->hex_cursor++;
|
||||
}
|
||||
if (!view->hexview_in_text)
|
||||
if (old_cursor < last_byte || !view->hexedit_lownibble)
|
||||
view->hexedit_lownibble = !view->hexedit_lownibble;
|
||||
} else if (view->text_wrap_mode) {
|
||||
}
|
||||
else if (view->text_wrap_mode)
|
||||
{
|
||||
/* nothing to do */
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
view->dpy_text_column += columns;
|
||||
}
|
||||
mcview_movement_fixups (view, FALSE);
|
||||
@ -198,15 +223,15 @@ mcview_move_right (mcview_t * view, off_t columns)
|
||||
void
|
||||
mcview_scroll_to_cursor (mcview_t * view)
|
||||
{
|
||||
if (view->hex_mode) {
|
||||
if (view->hex_mode)
|
||||
{
|
||||
const off_t bytes = view->bytes_per_line;
|
||||
const off_t displaysize = view->data_area.height * bytes;
|
||||
const off_t cursor = view->hex_cursor;
|
||||
off_t topleft = view->dpy_start;
|
||||
|
||||
if (topleft + displaysize <= cursor)
|
||||
topleft = mcview_offset_rounddown (cursor, bytes)
|
||||
- (displaysize - bytes);
|
||||
topleft = mcview_offset_rounddown (cursor, bytes) - (displaysize - bytes);
|
||||
if (cursor < topleft)
|
||||
topleft = mcview_offset_rounddown (cursor, bytes);
|
||||
view->dpy_start = topleft;
|
||||
@ -240,12 +265,15 @@ mcview_moveto_bottom (mcview_t * view)
|
||||
datalines = view->data_area.height;
|
||||
lines_up = mcview_offset_doz (datalines, 1);
|
||||
|
||||
if (view->hex_mode) {
|
||||
if (view->hex_mode)
|
||||
{
|
||||
last_offset = mcview_offset_doz (filesize, 1);
|
||||
view->hex_cursor = filesize;
|
||||
mcview_move_up (view, lines_up);
|
||||
view->hex_cursor = last_offset;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
view->dpy_start = filesize;
|
||||
mcview_move_up (view, 1);
|
||||
}
|
||||
@ -256,9 +284,12 @@ mcview_moveto_bottom (mcview_t * view)
|
||||
void
|
||||
mcview_moveto_bol (mcview_t * view)
|
||||
{
|
||||
if (view->hex_mode) {
|
||||
if (view->hex_mode)
|
||||
{
|
||||
view->hex_cursor -= view->hex_cursor % view->bytes_per_line;
|
||||
} else if (!view->text_wrap_mode) {
|
||||
}
|
||||
else if (!view->text_wrap_mode)
|
||||
{
|
||||
view->dpy_start = mcview_bol (view, view->dpy_start);
|
||||
}
|
||||
mcview_movement_fixups (view, TRUE);
|
||||
@ -269,13 +300,17 @@ mcview_moveto_bol (mcview_t * view)
|
||||
void
|
||||
mcview_moveto_eol (mcview_t * view)
|
||||
{
|
||||
if (view->hex_mode) {
|
||||
if (view->hex_mode)
|
||||
{
|
||||
off_t filesize, bol;
|
||||
|
||||
bol = mcview_offset_rounddown (view->hex_cursor, view->bytes_per_line);
|
||||
if (mcview_get_byte_indexed (view, bol, view->bytes_per_line - 1, NULL) == TRUE) {
|
||||
if (mcview_get_byte_indexed (view, bol, view->bytes_per_line - 1, NULL) == TRUE)
|
||||
{
|
||||
view->hex_cursor = bol + view->bytes_per_line - 1;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
filesize = mcview_get_filesize (view);
|
||||
view->hex_cursor = mcview_offset_doz (filesize, 1);
|
||||
}
|
||||
@ -288,10 +323,13 @@ mcview_moveto_eol (mcview_t * view)
|
||||
void
|
||||
mcview_moveto_offset (mcview_t * view, off_t offset)
|
||||
{
|
||||
if (view->hex_mode) {
|
||||
if (view->hex_mode)
|
||||
{
|
||||
view->hex_cursor = offset;
|
||||
view->dpy_start = offset - offset % view->bytes_per_line;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
view->dpy_start = offset;
|
||||
}
|
||||
mcview_movement_fixups (view, TRUE);
|
||||
@ -333,8 +371,7 @@ mcview_offset_to_coord (mcview_t * view, off_t * ret_line, off_t * ret_column, o
|
||||
mcview_ccache_lookup (view, &coord, CCACHE_LINECOL);
|
||||
|
||||
*ret_line = coord.cc_line;
|
||||
*ret_column = (view->text_nroff_mode)
|
||||
? coord.cc_nroff_column : coord.cc_column;
|
||||
*ret_column = (view->text_nroff_mode) ? coord.cc_nroff_column : coord.cc_column;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -362,10 +399,13 @@ mcview_moveto_match (mcview_t * view)
|
||||
|
||||
offset = view->search_start;
|
||||
|
||||
if (view->hex_mode) {
|
||||
if (view->hex_mode)
|
||||
{
|
||||
view->hex_cursor = offset;
|
||||
view->dpy_start = offset - offset % view->bytes_per_line;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
view->dpy_start = mcview_bol (view, offset);
|
||||
}
|
||||
|
||||
|
@ -6,16 +6,16 @@
|
||||
2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
|
||||
|
||||
Written by: 1994, 1995, 1998 Miguel de Icaza
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009 Ilia Maslakov <il.smind@gmail.com>
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009 Ilia Maslakov <il.smind@gmail.com>
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
@ -79,37 +79,46 @@ mcview_display_nroff (mcview_t * view)
|
||||
|
||||
/* Find the first displayable changed byte */
|
||||
from = view->dpy_start;
|
||||
while (curr && (curr->offset < from)) {
|
||||
while (curr && (curr->offset < from))
|
||||
{
|
||||
curr = curr->next;
|
||||
}
|
||||
|
||||
tty_setcolor (NORMAL_COLOR);
|
||||
for (row = 0, col = 0; row < height;) {
|
||||
for (row = 0, col = 0; row < height;)
|
||||
{
|
||||
#ifdef HAVE_CHARSET
|
||||
if (view->utf8) {
|
||||
if (view->utf8)
|
||||
{
|
||||
gboolean read_res = TRUE;
|
||||
c = mcview_get_utf (view, from, &cw, &read_res);
|
||||
if (!read_res)
|
||||
break;
|
||||
} else
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if (! mcview_get_byte (view, from, &c))
|
||||
if (!mcview_get_byte (view, from, &c))
|
||||
break;
|
||||
}
|
||||
from++;
|
||||
if (cw > 1)
|
||||
from += cw - 1;
|
||||
|
||||
if (c == '\b') {
|
||||
if (from > 1) {
|
||||
if (c == '\b')
|
||||
{
|
||||
if (from > 1)
|
||||
{
|
||||
mcview_get_byte (view, from - 2, &c_prev);
|
||||
mcview_get_byte (view, from, &c_next);
|
||||
}
|
||||
if (g_ascii_isprint (c_prev) && g_ascii_isprint (c_prev)
|
||||
&& (c_prev == c_next || c_prev == '_' || (c_prev == '+' && c_next == 'o'))) {
|
||||
if (col == 0) {
|
||||
if (row == 0) {
|
||||
&& (c_prev == c_next || c_prev == '_' || (c_prev == '+' && c_next == 'o')))
|
||||
{
|
||||
if (col == 0)
|
||||
{
|
||||
if (row == 0)
|
||||
{
|
||||
/* We're inside an nroff character sequence at the
|
||||
* beginning of the screen -- just skip the
|
||||
* backspace and continue with the next character. */
|
||||
@ -128,14 +137,16 @@ mcview_display_nroff (mcview_t * view)
|
||||
}
|
||||
}
|
||||
|
||||
if ((c == '\n') || (col >= width && view->text_wrap_mode)) {
|
||||
if ((c == '\n') || (col >= width && view->text_wrap_mode))
|
||||
{
|
||||
col = 0;
|
||||
row++;
|
||||
if (c == '\n' || row >= height)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c == '\r') {
|
||||
if (c == '\r')
|
||||
{
|
||||
mcview_get_byte_indexed (view, from, 1, &c);
|
||||
if (c == '\r' || c == '\n')
|
||||
continue;
|
||||
@ -144,34 +155,45 @@ mcview_display_nroff (mcview_t * view)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c == '\t') {
|
||||
if (c == '\t')
|
||||
{
|
||||
off_t line, column;
|
||||
mcview_offset_to_coord (view, &line, &column, from);
|
||||
col += (option_tab_spacing - col % option_tab_spacing);
|
||||
if (view->text_wrap_mode && col >= width && width != 0) {
|
||||
if (view->text_wrap_mode && col >= width && width != 0)
|
||||
{
|
||||
row += col / width;
|
||||
col %= width;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (view->search_start <= from && from < view->search_end) {
|
||||
if (view->search_start <= from && from < view->search_end)
|
||||
{
|
||||
tty_setcolor (SELECTED_COLOR);
|
||||
}
|
||||
|
||||
if (col >= view->dpy_text_column && col - view->dpy_text_column < width) {
|
||||
if (col >= view->dpy_text_column && col - view->dpy_text_column < width)
|
||||
{
|
||||
widget_move (view, top + row, left + (col - view->dpy_text_column));
|
||||
#ifdef HAVE_CHARSET
|
||||
if (utf8_display) {
|
||||
if (!view->utf8) {
|
||||
if (utf8_display)
|
||||
{
|
||||
if (!view->utf8)
|
||||
{
|
||||
c = convert_from_8bit_to_utf_c ((unsigned char) c, view->converter);
|
||||
}
|
||||
if (!g_unichar_isprint (c))
|
||||
c = '.';
|
||||
} else {
|
||||
if (view->utf8) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (view->utf8)
|
||||
{
|
||||
c = convert_from_utf_to_current_c (c, view->converter);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif
|
||||
c = convert_to_display_c (c);
|
||||
#ifdef HAVE_CHARSET
|
||||
@ -182,10 +204,11 @@ mcview_display_nroff (mcview_t * view)
|
||||
}
|
||||
col++;
|
||||
#ifdef HAVE_CHARSET
|
||||
if (view->utf8) {
|
||||
if (g_unichar_iswide(c))
|
||||
if (view->utf8)
|
||||
{
|
||||
if (g_unichar_iswide (c))
|
||||
col++;
|
||||
else if (g_unichar_iszerowidth(c))
|
||||
else if (g_unichar_iszerowidth (c))
|
||||
col--;
|
||||
}
|
||||
#endif
|
||||
@ -207,8 +230,10 @@ mcview__get_nroff_real_len (mcview_t * view, off_t start, off_t length)
|
||||
if (nroff == NULL)
|
||||
return 0;
|
||||
|
||||
while (i < length) {
|
||||
if (nroff->type != NROFF_TYPE_NONE) {
|
||||
while (i < length)
|
||||
{
|
||||
if (nroff->type != NROFF_TYPE_NONE)
|
||||
{
|
||||
ret += 2;
|
||||
}
|
||||
i++;
|
||||
@ -227,10 +252,11 @@ mcview_nroff_seq_new_num (mcview_t * view, off_t lc_index)
|
||||
mcview_nroff_t *nroff;
|
||||
|
||||
nroff = g_try_malloc0 (sizeof (mcview_nroff_t));
|
||||
if (nroff != NULL) {
|
||||
nroff->index = lc_index;
|
||||
nroff->view = view;
|
||||
mcview_nroff_seq_info (nroff);
|
||||
if (nroff != NULL)
|
||||
{
|
||||
nroff->index = lc_index;
|
||||
nroff->view = view;
|
||||
mcview_nroff_seq_info (nroff);
|
||||
}
|
||||
return nroff;
|
||||
}
|
||||
@ -266,29 +292,34 @@ mcview_nroff_seq_info (mcview_nroff_t * nroff)
|
||||
return NROFF_TYPE_NONE;
|
||||
nroff->type = NROFF_TYPE_NONE;
|
||||
|
||||
if (! mcview_get_byte (nroff->view, nroff->index, &nroff->current_char)
|
||||
|| !g_ascii_isprint (nroff->current_char)) /* FIXME: utf-8 and g_ascii_isprint */
|
||||
if (!mcview_get_byte (nroff->view, nroff->index, &nroff->current_char) || !g_ascii_isprint (nroff->current_char)) /* FIXME: utf-8 and g_ascii_isprint */
|
||||
return nroff->type;
|
||||
|
||||
nroff->char_width = 1;
|
||||
|
||||
if (! mcview_get_byte (nroff->view, nroff->index + 1, &next) || next != '\b')
|
||||
if (!mcview_get_byte (nroff->view, nroff->index + 1, &next) || next != '\b')
|
||||
return nroff->type;
|
||||
|
||||
if (! mcview_get_byte (nroff->view, nroff->index + 2, &next2)
|
||||
|| !g_ascii_isprint (next2)) /* FIXME: utf-8 and g_ascii_isprint */
|
||||
if (!mcview_get_byte (nroff->view, nroff->index + 2, &next2) || !g_ascii_isprint (next2)) /* FIXME: utf-8 and g_ascii_isprint */
|
||||
return nroff->type;
|
||||
|
||||
if (nroff->current_char == '_' && next2 == '_') {
|
||||
if (nroff->current_char == '_' && next2 == '_')
|
||||
{
|
||||
nroff->type = (nroff->prev_type == NROFF_TYPE_BOLD)
|
||||
? NROFF_TYPE_BOLD : NROFF_TYPE_UNDERLINE;
|
||||
|
||||
} else if (nroff->current_char == next2) {
|
||||
}
|
||||
else if (nroff->current_char == next2)
|
||||
{
|
||||
nroff->type = NROFF_TYPE_BOLD;
|
||||
} else if (nroff->current_char == '_') {
|
||||
}
|
||||
else if (nroff->current_char == '_')
|
||||
{
|
||||
nroff->current_char = next2;
|
||||
nroff->type = NROFF_TYPE_UNDERLINE;
|
||||
} else if (nroff->current_char == '+' && next2 == 'o') {
|
||||
}
|
||||
else if (nroff->current_char == '+' && next2 == 'o')
|
||||
{
|
||||
/* ??? */
|
||||
}
|
||||
|
||||
|
@ -6,17 +6,17 @@
|
||||
2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
|
||||
|
||||
Written by: 1994, 1995, 1998 Miguel de Icaza
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009 Ilia Maslakov <il.smind@gmail.com>
|
||||
2010 Andrew Borodin <aborodin@vmail.ru>
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009 Ilia Maslakov <il.smind@gmail.com>
|
||||
2010 Andrew Borodin <aborodin@vmail.ru>
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
@ -45,7 +45,7 @@
|
||||
#include "lib/global.h"
|
||||
#include "src/main.h"
|
||||
#include "src/charsets.h"
|
||||
#include "mcviewer.h" /* mcview_show_eof */
|
||||
#include "mcviewer.h" /* mcview_show_eof */
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
@ -85,30 +85,34 @@ mcview_display_text (mcview_t * view)
|
||||
while ((curr != NULL) && (curr->offset < from))
|
||||
curr = curr->next;
|
||||
|
||||
while (TRUE) {
|
||||
while (TRUE)
|
||||
{
|
||||
tty_setcolor (NORMAL_COLOR);
|
||||
|
||||
if (row >= height)
|
||||
break;
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
if (view->utf8) {
|
||||
if (view->utf8)
|
||||
{
|
||||
gboolean read_res = TRUE;
|
||||
|
||||
c = mcview_get_utf (view, from, &cw, &read_res);
|
||||
if (!read_res)
|
||||
break;
|
||||
} else
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (!mcview_get_byte (view, from, &c))
|
||||
break;
|
||||
if (!mcview_get_byte (view, from, &c))
|
||||
break;
|
||||
|
||||
last_row = FALSE;
|
||||
from++;
|
||||
if (cw > 1)
|
||||
from += cw - 1;
|
||||
|
||||
if (c != '\n' && prev_ch == '\r') {
|
||||
if (c != '\n' && prev_ch == '\r')
|
||||
{
|
||||
if (++row >= height)
|
||||
break;
|
||||
|
||||
@ -120,21 +124,25 @@ mcview_display_text (mcview_t * view)
|
||||
if (c == '\r')
|
||||
continue;
|
||||
|
||||
if (c == '\n') {
|
||||
if (c == '\n')
|
||||
{
|
||||
col = 0;
|
||||
row++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (col >= width && view->text_wrap_mode) {
|
||||
if (col >= width && view->text_wrap_mode)
|
||||
{
|
||||
col = 0;
|
||||
if (++row >= height)
|
||||
break;
|
||||
}
|
||||
|
||||
if (c == '\t') {
|
||||
if (c == '\t')
|
||||
{
|
||||
col += (option_tab_spacing - col % option_tab_spacing);
|
||||
if (view->text_wrap_mode && col >= width && width != 0) {
|
||||
if (view->text_wrap_mode && col >= width && width != 0)
|
||||
{
|
||||
row += col / width;
|
||||
col %= width;
|
||||
}
|
||||
@ -144,15 +152,18 @@ mcview_display_text (mcview_t * view)
|
||||
if (view->search_start <= from && from < view->search_end)
|
||||
tty_setcolor (SELECTED_COLOR);
|
||||
|
||||
if ((col >= view->dpy_text_column) && (col - view->dpy_text_column < width)) {
|
||||
if ((col >= view->dpy_text_column) && (col - view->dpy_text_column < width))
|
||||
{
|
||||
widget_move (view, top + row, left + (col - view->dpy_text_column));
|
||||
#ifdef HAVE_CHARSET
|
||||
if (utf8_display) {
|
||||
if (utf8_display)
|
||||
{
|
||||
if (!view->utf8)
|
||||
c = convert_from_8bit_to_utf_c ((unsigned char) c, view->converter);
|
||||
if (!g_unichar_isprint (c))
|
||||
c = '.';
|
||||
} else if (view->utf8)
|
||||
}
|
||||
else if (view->utf8)
|
||||
c = convert_from_utf_to_current_c (c, view->converter);
|
||||
else
|
||||
#endif
|
||||
@ -169,7 +180,8 @@ mcview_display_text (mcview_t * view)
|
||||
col++;
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
if (view->utf8) {
|
||||
if (view->utf8)
|
||||
{
|
||||
if (g_unichar_iswide (c))
|
||||
col++;
|
||||
else if (g_unichar_iszerowidth (c))
|
||||
@ -179,11 +191,13 @@ mcview_display_text (mcview_t * view)
|
||||
}
|
||||
|
||||
view->dpy_end = from;
|
||||
if (mcview_show_eof != NULL && mcview_show_eof[0] != '\0') {
|
||||
if (mcview_show_eof != NULL && mcview_show_eof[0] != '\0')
|
||||
{
|
||||
if (last_row && mcview_get_byte (view, from - 1, &c))
|
||||
if (c != '\n')
|
||||
row--;
|
||||
while (++row < height) {
|
||||
while (++row < height)
|
||||
{
|
||||
widget_move (view, top + row, left);
|
||||
tty_print_string (mcview_show_eof);
|
||||
}
|
||||
|
@ -6,16 +6,16 @@
|
||||
2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
|
||||
|
||||
Written by: 1994, 1995, 1998 Miguel de Icaza
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009 Ilia Maslakov <il.smind@gmail.com>
|
||||
1994, 1995 Janne Kukonlehto
|
||||
1995 Jakub Jelinek
|
||||
1996 Joseph M. Hinkle
|
||||
1997 Norbert Warmuth
|
||||
1998 Pavel Machek
|
||||
2004 Roland Illig <roland.illig@gmx.de>
|
||||
2005 Roland Illig <roland.illig@gmx.de>
|
||||
2009 Slava Zanko <slavazanko@google.com>
|
||||
2009 Andrew Borodin <aborodin@vmail.ru>
|
||||
2009 Ilia Maslakov <il.smind@gmail.com>
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
@ -78,9 +78,11 @@ mcview_find (mcview_t * view, gsize search_start, gsize * len)
|
||||
|
||||
view->search_numNeedSkipChar = 0;
|
||||
|
||||
if (mcview_search_options.backwards) {
|
||||
if (mcview_search_options.backwards)
|
||||
{
|
||||
search_end = mcview_get_filesize (view);
|
||||
while ((int) search_start >= 0) {
|
||||
while ((int) search_start >= 0)
|
||||
{
|
||||
view->search_nroff_seq->index = search_start;
|
||||
mcview_nroff_seq_info (view->search_nroff_seq);
|
||||
|
||||
@ -107,35 +109,36 @@ mcview_find (mcview_t * view, gsize search_start, gsize * len)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
mcview_search_show_result(mcview_t * view, Dlg_head **d, size_t match_len)
|
||||
mcview_search_show_result (mcview_t * view, Dlg_head ** d, size_t match_len)
|
||||
{
|
||||
|
||||
view->search_start = view->search->normal_offset +
|
||||
mcview__get_nroff_real_len (view,
|
||||
view->search->start_buffer,
|
||||
view->search->normal_offset -
|
||||
view->search->start_buffer);
|
||||
view->search_start = view->search->normal_offset +
|
||||
mcview__get_nroff_real_len (view,
|
||||
view->search->start_buffer,
|
||||
view->search->normal_offset - view->search->start_buffer);
|
||||
|
||||
if (!view->hex_mode)
|
||||
view->search_start++;
|
||||
if (!view->hex_mode)
|
||||
view->search_start++;
|
||||
|
||||
view->search_end = view->search_start + match_len +
|
||||
mcview__get_nroff_real_len (view, view->search_start - 1, match_len);
|
||||
view->search_end = view->search_start + match_len +
|
||||
mcview__get_nroff_real_len (view, view->search_start - 1, match_len);
|
||||
|
||||
if (view->hex_mode) {
|
||||
view->hex_cursor = view->search_start;
|
||||
view->hexedit_lownibble = FALSE;
|
||||
view->dpy_start = view->search_start - view->search_start % view->bytes_per_line;
|
||||
view->dpy_end = view->search_end - view->search_end % view->bytes_per_line;
|
||||
}
|
||||
if (view->hex_mode)
|
||||
{
|
||||
view->hex_cursor = view->search_start;
|
||||
view->hexedit_lownibble = FALSE;
|
||||
view->dpy_start = view->search_start - view->search_start % view->bytes_per_line;
|
||||
view->dpy_end = view->search_end - view->search_end % view->bytes_per_line;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
dlg_run_done (*d);
|
||||
destroy_dlg (*d);
|
||||
*d = create_message (D_NORMAL, _("Search"), _("Seeking to search result"));
|
||||
tty_refresh ();
|
||||
}
|
||||
mcview_moveto_match (view);
|
||||
if (verbose)
|
||||
{
|
||||
dlg_run_done (*d);
|
||||
destroy_dlg (*d);
|
||||
*d = create_message (D_NORMAL, _("Search"), _("Seeking to search result"));
|
||||
tty_refresh ();
|
||||
}
|
||||
mcview_moveto_match (view);
|
||||
|
||||
}
|
||||
|
||||
@ -152,14 +155,16 @@ mcview_search_cmd_callback (const void *user_data, gsize char_offset)
|
||||
mcview_t *view = (mcview_t *) user_data;
|
||||
|
||||
/* view_read_continue (view, &view->search_onechar_info); *//* AB:FIXME */
|
||||
if (!view->text_nroff_mode) {
|
||||
if (! mcview_get_byte (view, char_offset, &lc_byte))
|
||||
if (!view->text_nroff_mode)
|
||||
{
|
||||
if (!mcview_get_byte (view, char_offset, &lc_byte))
|
||||
return MC_SEARCH_CB_INVALID;
|
||||
|
||||
return lc_byte;
|
||||
}
|
||||
|
||||
if (view->search_numNeedSkipChar) {
|
||||
if (view->search_numNeedSkipChar)
|
||||
{
|
||||
view->search_numNeedSkipChar--;
|
||||
return MC_SEARCH_CB_SKIP;
|
||||
}
|
||||
@ -184,9 +189,11 @@ mcview_search_update_cmd_callback (const void *user_data, gsize char_offset)
|
||||
{
|
||||
mcview_t *view = (mcview_t *) user_data;
|
||||
|
||||
if (char_offset >= (gsize) view->update_activate) {
|
||||
if (char_offset >= (gsize) view->update_activate)
|
||||
{
|
||||
view->update_activate += view->update_steps;
|
||||
if (verbose) {
|
||||
if (verbose)
|
||||
{
|
||||
mcview_percent (view, char_offset);
|
||||
tty_refresh ();
|
||||
}
|
||||
@ -212,18 +219,22 @@ mcview_do_search (mcview_t * view)
|
||||
|
||||
size_t match_len;
|
||||
|
||||
if (verbose) {
|
||||
if (verbose)
|
||||
{
|
||||
d = create_message (D_NORMAL, _("Search"), _("Searching %s"), view->last_search_string);
|
||||
tty_refresh ();
|
||||
}
|
||||
|
||||
/*for avoid infinite search loop we need to increase or decrease start offset of search */
|
||||
|
||||
if (view->search_start) {
|
||||
if (view->search_start)
|
||||
{
|
||||
search_start = (mcview_search_options.backwards) ? -2 : 2;
|
||||
search_start = view->search_start + search_start +
|
||||
mcview__get_nroff_real_len (view, view->search_start, 2) * search_start;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
search_start = view->search_start;
|
||||
}
|
||||
|
||||
@ -236,19 +247,22 @@ mcview_do_search (mcview_t * view)
|
||||
|
||||
tty_enable_interrupt_key ();
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
if (view->growbuf_in_use)
|
||||
growbufsize = mcview_growbuf_filesize (view);
|
||||
else
|
||||
growbufsize = view->search->original_len;
|
||||
|
||||
if (! mcview_find (view, search_start, &match_len)) {
|
||||
if (!mcview_find (view, search_start, &match_len))
|
||||
{
|
||||
|
||||
if (view->search->error_str == NULL)
|
||||
break;
|
||||
|
||||
search_start = growbufsize - view->search->original_len;
|
||||
if ( search_start <= 0 ) {
|
||||
if (search_start <= 0)
|
||||
{
|
||||
search_start = 0;
|
||||
break;
|
||||
}
|
||||
@ -256,32 +270,40 @@ mcview_do_search (mcview_t * view)
|
||||
continue;
|
||||
}
|
||||
|
||||
mcview_search_show_result(view, &d, match_len);
|
||||
mcview_search_show_result (view, &d, match_len);
|
||||
need_search_again = FALSE;
|
||||
isFound = TRUE;
|
||||
break;
|
||||
} while (mcview_may_still_grow (view));
|
||||
}
|
||||
while (mcview_may_still_grow (view));
|
||||
|
||||
if (!isFound && need_search_again && !mcview_search_options.backwards) {
|
||||
if (!isFound && need_search_again && !mcview_search_options.backwards)
|
||||
{
|
||||
int result;
|
||||
mcview_update (view);
|
||||
|
||||
result =
|
||||
query_dialog (_("Search done"), _("Continue from begining?"), D_NORMAL, 2, _("&Yes"), _("&No"));
|
||||
query_dialog (_("Search done"), _("Continue from begining?"), D_NORMAL, 2, _("&Yes"),
|
||||
_("&No"));
|
||||
|
||||
if (result != 0) {
|
||||
isFound=TRUE;
|
||||
} else {
|
||||
if (result != 0)
|
||||
{
|
||||
isFound = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
search_start = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isFound && view->search->error_str != NULL && mcview_find (view, search_start, &match_len)) {
|
||||
mcview_search_show_result(view, &d, match_len);
|
||||
if (!isFound && view->search->error_str != NULL && mcview_find (view, search_start, &match_len))
|
||||
{
|
||||
mcview_search_show_result (view, &d, match_len);
|
||||
isFound = TRUE;
|
||||
}
|
||||
|
||||
if (!isFound) {
|
||||
if (!isFound)
|
||||
{
|
||||
if (view->search->error_str)
|
||||
message (D_NORMAL, _("Search"), "%s", view->search->error_str);
|
||||
}
|
||||
@ -290,7 +312,8 @@ mcview_do_search (mcview_t * view)
|
||||
mcview_update (view);
|
||||
|
||||
tty_disable_interrupt_key ();
|
||||
if (verbose) {
|
||||
if (verbose)
|
||||
{
|
||||
dlg_run_done (d);
|
||||
destroy_dlg (d);
|
||||
}
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user