less5 - 2 fixes and an enhancement...
Julian Perry
jules at zen.co.uk
Wed Sep 21 01:45:25 AEST 1988
THIS IS AN UNOFFICIAL PATCH! -- Can it be made official and correctly
integrated with the rest of the less
distribution?
This patch (apply using `patch') solves 2 problems and adds one feature:
1) Bug if you have a SHELL variable and set globbing....calloc() was
not being passed a second paramter, and the first parameter was
wrong anyway.
2) Screen updating was wrong on HP terminals (where have I heard that
before?) because the off-screen memory was not being cleared at the
right times. The fix included is NOT the best way of solving the
problem, but it does work.
**** NEW FEATURE ****
Not wishing to be accused of creeping featurism......I think it's
really useful:
less can now display `compress'ed, `pack'ed and `compact'ed files
without the user needing to uncompress them. This only works for
files specified on the command line. It has been implemented
so that it can be expanded to cope with other forms of encoding.
The filename of the compressed file must be specified WITH the .Z
suffix (or .z or .C).
I hope this is as useful to you as it is to me ...
less is wonderful....thanks,
Jules
IN-REAL-LIFE: Julian Perry
E-MAIL: jules at zen.co.uk || ...!uunet!mcvax!ukc!zen.co.uk!jules
PHONE: +44 532 489048 ext 217
ADDRESS: Zengrange Limited, Greenfield Road, Leeds, England, LS9 8DB
*** SAFE/funcs.h Tue Sep 20 12:17:13 1988
--- funcs.h Tue Sep 20 12:24:12 1988
***************
*** 54,59
public void vbell ();
public void clear ();
public void clear_eol ();
public void so_enter ();
public void so_exit ();
public void ul_enter ();
--- 54,60 -----
public void vbell ();
public void clear ();
public void clear_eol ();
+ public void clear_eos ();
public void so_enter ();
public void so_exit ();
public void ul_enter ();
*** SAFE/command.c Tue Sep 20 12:17:13 1988
--- command.c Tue Sep 20 12:23:57 1988
***************
*** 699,705
* Help.
*/
lower_left();
! clear_eol();
putstr("help");
cmd_exec();
help();
--- 699,705 -----
* Help.
*/
lower_left();
! clear_eos();
putstr("help");
cmd_exec();
help();
*** SAFE/main.c Tue Sep 20 12:17:15 1988
--- main.c Tue Sep 20 15:42:47 1988
***************
*** 55,60
register char *m;
POSITION initial_pos;
char message[100];
static int didpipe;
initial_pos = NULL_POSITION;
--- 55,61 -----
register char *m;
POSITION initial_pos;
char message[100];
+ int new_file_ispipe = 0;
static int didpipe;
initial_pos = NULL_POSITION;
***************
*** 89,94
return;
}
f = 0;
} else if ((m = bad_file(filename, message, sizeof(message))) != NULL)
{
error(m);
--- 90,96 -----
return;
}
f = 0;
+ new_file_ispipe = 1;
} else if ((m = bad_file(filename, message, sizeof(message))) != NULL)
{
error(m);
***************
*** 100,105
free(filename);
return;
}
if (isatty(f))
{
--- 102,108 -----
free(filename);
return;
}
+ #ifndef NO_JULES_HACKS
/* These are for the machines that I have.... */
# define COMPRESS /* Everyone has compress - don't they? */
***************
*** 101,106
return;
}
if (isatty(f))
{
/*
--- 104,210 -----
}
#ifndef NO_JULES_HACKS
+ /* These are for the machines that I have.... */
+ # define COMPRESS /* Everyone has compress - don't they? */
+ # ifdef hpux
+ # define PACK
+ # if defined(hp9000s300) || defined(hp9000s500)
+ # define COMPACT /* Why doesn't the Specky have compact ??? */
+ # endif
+ # endif
+
+ /* Let's check for a compressed file and uncompress it for display */
+ else
+ {
+ /* This table defines which program to run given the magic number
+ at the start if the file */
+ static struct
+ {
+ int magic_length;
+ unsigned char bytes[4];
+ int filename_needed;
+ char *program_name;
+ } programs[] = {
+ # ifdef COMPRESS
+ { 2, 0x1f, 0x9d, 0x0, 0x0, 0, "uncompress" },
+ # endif
+ # ifdef PACK
+ { 2, 0x1f, 0x1e, 0x0, 0x0, 1, "pcat" },
+ # endif
+ # ifdef COMPACT
+ { 2, 0xff, 0x1f, 0x0, 0x0, 0, "uncompact" },
+ # endif
+ { 0, 0x0, 0x0, 0x0, 0x0, 0, NULL }
+ };
+ unsigned char magic[4];
+ int loop;
+ int b;
+ int fd[2];
+ int pid;
+
+ if ( read(f,magic,sizeof(magic)) <= 0 )
+ lseek(f,0L,0);
+ else
+ {
+ lseek(f,0L,0);
+
+ for ( loop = 0 ; programs[loop].magic_length ; ++loop )
+ {
+ for ( b = 0 ;
+ (b < programs[loop].magic_length) &&
+ (programs[loop].bytes[b] == magic[b]) ;
+ ++b )
+ ;
+ if ( b == programs[loop].magic_length )
+ break;
+ }
+
+ if ( programs[loop].magic_length )
+ {
+ if ( pipe(fd) < 0 )
+ {
+ error(errno_message(filename, message, sizeof(message)));
+ free(filename);
+ return;
+ }
+
+ /* Vfork() might be allowed - but let's not chance it */
+ if ( (pid = fork()) < 0 )
+ {
+ error(errno_message(filename, message, sizeof(message)));
+ free(filename);
+ close(f);
+ close(fd[0]);
+ close(fd[1]);
+ return;
+ }
+
+ if ( !pid )
+ {
+ close(0);
+ dup(f);
+ close(f);
+ close(1);
+ dup(fd[1]);
+ close(fd[0]);
+ if ( programs[loop].filename_needed )
+ execlp(programs[loop].program_name,
+ programs[loop].program_name,filename,0);
+ else
+ execlp(programs[loop].program_name,
+ programs[loop].program_name,0);
+ _exit(127);
+ }
+
+ close(fd[1]);
+ close(f);
+ f = fd[0];
+ new_file_ispipe = 2;
+ }
+ }
+ }
+ #endif
+
if (isatty(f))
{
/*
***************
*** 133,140
previous_file = current_file;
current_file = filename;
prev_pos = position(TOP);
! ispipe = (f == 0);
! if (ispipe)
didpipe = 1;
file = f;
ch_init(cbufs, 0);
--- 237,244 -----
previous_file = current_file;
current_file = filename;
prev_pos = position(TOP);
! ispipe = new_file_ispipe;
! if (f == 0)
didpipe = 1;
file = f;
ch_init(cbufs, 0);
***************
*** 446,452
end_logfile();
#endif
lower_left();
! clear_eol();
deinit();
flush();
raw_mode(0);
--- 550,556 -----
end_logfile();
#endif
lower_left();
! clear_eos();
deinit();
flush();
raw_mode(0);
*** SAFE/os.c Tue Sep 20 12:17:15 1988
--- os.c Tue Sep 20 16:16:28 1988
***************
*** 44,50
else
{
lower_left();
! clear_eol();
putstr("!");
putstr(cmd);
putstr("\n");
--- 44,50 -----
else
{
lower_left();
! clear_eos();
putstr("!");
putstr(cmd);
putstr("\n");
***************
*** 201,207
/*
* Read the output of <$SHELL -c "echo filename">.
*/
! cmd = calloc(strlen(p)+12);
if (cmd == NULL)
return (filename);
sprintf(cmd, "%s -c \"echo %s\"", p, filename);
--- 201,207 -----
/*
* Read the output of <$SHELL -c "echo filename">.
*/
! cmd = calloc(strlen(p)+strlen(filename)+12, sizeof(char));
if (cmd == NULL)
return (filename);
sprintf(cmd, "%s -c \"echo %s\"", p, filename);
*** SAFE/prim.c Tue Sep 20 12:17:16 1988
--- prim.c Tue Sep 20 12:25:49 1988
***************
*** 116,122
} else
{
lower_left();
! clear_eol();
}
if (pos != position(BOTTOM_PLUS_ONE))
--- 116,122 -----
} else
{
lower_left();
! clear_eos();
}
if (pos != position(BOTTOM_PLUS_ONE))
*** SAFE/prompt.c Tue Sep 20 12:17:16 1988
--- prompt.c Tue Sep 20 14:41:07 1988
***************
*** 129,135
case 'e': /* At end of file? */
return (hit_eof);
case 'f': /* Filename known? */
! return (!ispipe);
case 'l': /* Line number known? */
return (linenums);
case 'm': /* More than one file? */
--- 129,135 -----
case 'e': /* At end of file? */
return (hit_eof);
case 'f': /* Filename known? */
! return (ispipe != 1);
case 'l': /* Line number known? */
return (linenums);
case 'm': /* More than one file? */
*** SAFE/screen.c Tue Sep 20 12:17:17 1988
--- screen.c Tue Sep 20 12:22:04 1988
***************
*** 42,47
*sc_move, /* General cursor positioning */
*sc_clear, /* Clear screen */
*sc_eol_clear, /* Clear to end of line */
*sc_s_in, /* Enter standout (highlighted) mode */
*sc_s_out, /* Exit standout mode */
*sc_u_in, /* Enter underline mode */
--- 42,48 -----
*sc_move, /* General cursor positioning */
*sc_clear, /* Clear screen */
*sc_eol_clear, /* Clear to end of line */
+ *sc_eos_clear, /* Clear to end of screen */
*sc_s_in, /* Enter standout (highlighted) mode */
*sc_s_out, /* Exit standout mode */
*sc_u_in, /* Enter underline mode */
***************
*** 279,284
sc_eol_clear = "";
}
sc_clear = tgetstr("cl", &sp);
if (hard || sc_clear == NULL || *sc_clear == '\0')
{
--- 280,292 -----
sc_eol_clear = "";
}
+ sc_eos_clear = tgetstr("cd", &sp);
+ if (hard || sc_eos_clear == NULL || *sc_eos_clear == '\0')
+ {
+ cannot("clear to end of screen");
+ sc_eos_clear = "";
+ }
+
sc_clear = tgetstr("cl", &sp);
if (hard || sc_clear == NULL || *sc_clear == '\0')
{
***************
*** 493,498
clear_eol()
{
tputs(sc_eol_clear, 1, putchr);
}
/*
--- 501,516 -----
clear_eol()
{
tputs(sc_eol_clear, 1, putchr);
+ }
+
+ /*
+ * Clear from the cursor to the end of the screen (memory).
+ * {{ This must not move the cursor. }}
+ */
+ public void
+ clear_eos()
+ {
+ tputs(sc_eos_clear, 1, putchr);
}
/*
*** SAFE/signal.c Tue Sep 20 12:17:17 1988
--- signal.c Tue Sep 20 12:26:16 1988
***************
*** 166,172
SIGNAL(SIGTTOU, SIG_IGN);
#endif
lower_left();
! clear_eol();
deinit();
flush();
raw_mode(0);
--- 166,172 -----
SIGNAL(SIGTTOU, SIG_IGN);
#endif
lower_left();
! clear_eos();
deinit();
flush();
raw_mode(0);
--
IN-REAL-LIFE: Julian Perry
E-MAIL: jules at zen.co.uk || ...!uunet!mcvax!ukc!zen.co.uk!jules
PHONE: +44 532 489048 ext 217
ADDRESS: Zengrange Limited, Greenfield Road, Leeds, England, LS9 8DB
More information about the Comp.sources.bugs
mailing list