Skip to content

Commit

Permalink
Fix 32 bit dependencies.
Browse files Browse the repository at this point in the history
Fix UTF-8 overstriking.
Fix EBCDIC host support.
  • Loading branch information
gwsw committed Dec 5, 2001
1 parent 11b59ae commit 28fd281
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 74 deletions.
6 changes: 6 additions & 0 deletions NEWS.VER
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@

* Default LESSCHARSET for MS-DOS versions is "dos".

* Fix overstriking in UTF-8 mode.

* Some fixes to eliminate 32-bit file offset dependencies.

* Some fixes for EBCDIC systems.

======================================================================

Major changes between "less" versions 354 and 358
Expand Down
28 changes: 14 additions & 14 deletions ch.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <windows.h>
#endif

typedef POSITION BLOCKNUM;

public int ignore_eoi;

/*
Expand All @@ -32,7 +34,7 @@ public int ignore_eoi;
#define LBUFSIZE 1024
struct buf {
struct buf *next, *prev; /* Must be first to match struct filestate */
long block;
BLOCKNUM block;
unsigned int datasize;
unsigned char data[LBUFSIZE];
};
Expand All @@ -44,13 +46,13 @@ struct buf {
struct filestate {
/* -- Following members must match struct buf */
struct buf *buf_next, *buf_prev;
long buf_block;
BLOCKNUM buf_block;
/* -- End of struct buf copy */
int file;
int flags;
POSITION fpos;
int nbufs;
long block;
BLOCKNUM block;
unsigned int offset;
POSITION fsize;
};
Expand Down Expand Up @@ -125,7 +127,7 @@ fch_get()
* If the LRU buffer has data in it,
* then maybe allocate a new buffer.
*/
if (ch_buftail == END_OF_CHAIN || ch_buftail->block != (long)(-1))
if (ch_buftail == END_OF_CHAIN || ch_buftail->block != -1)
{
/*
* There is no empty buffer to use.
Expand Down Expand Up @@ -318,8 +320,8 @@ sync_logfile()
{
register struct buf *bp;
int warned = FALSE;
long block;
long nblocks;
BLOCKNUM block;
BLOCKNUM nblocks;

nblocks = (ch_fpos + LBUFSIZE - 1) / LBUFSIZE;
for (block = 0; block < nblocks; block++)
Expand Down Expand Up @@ -352,7 +354,7 @@ sync_logfile()
*/
static int
buffered(block)
long block;
BLOCKNUM block;
{
register struct buf *bp;

Expand All @@ -370,7 +372,7 @@ buffered(block)
ch_seek(pos)
register POSITION pos;
{
long new_block;
BLOCKNUM new_block;
POSITION len;

len = ch_length();
Expand Down Expand Up @@ -470,12 +472,10 @@ ch_length()
/*
* Return the current position in the file.
*/
#define tellpos(blk,off) ((POSITION)((((long)(blk)) * LBUFSIZE) + (off)))

public POSITION
ch_tell()
{
return (tellpos(ch_block, ch_offset));
return (ch_block * LBUFSIZE) + ch_offset;
}

/*
Expand Down Expand Up @@ -570,7 +570,7 @@ ch_flush()
* Initialize all the buffers.
*/
for (bp = ch_bufhead; bp != END_OF_CHAIN; bp = bp->next)
bp->block = (long)(-1);
bp->block = -1;

/*
* Figure out the size of the file, if we can.
Expand Down Expand Up @@ -626,7 +626,7 @@ ch_addbuf()
if (bp == NULL)
return (1);
ch_nbufs++;
bp->block = (long)(-1);
bp->block = -1;
bp->next = END_OF_CHAIN;
bp->prev = ch_buftail;
ch_buftail->next = bp;
Expand Down Expand Up @@ -693,7 +693,7 @@ ch_init(f, flags)
thisfile = (struct filestate *)
calloc(1, sizeof(struct filestate));
thisfile->buf_next = thisfile->buf_prev = END_OF_CHAIN;
thisfile->buf_block = (long)(-1);
thisfile->buf_block = -1;
thisfile->nbufs = 0;
thisfile->flags = 0;
thisfile->fpos = 0;
Expand Down
19 changes: 17 additions & 2 deletions charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct charset {
{ "ascii", NULL, "8bcccbcc18b95.b" },
{ "dos", NULL, "8bcccbcc12bc5b223.b" },
{ "ebcdic", NULL, "5bc6bcc7bcc41b.9b7.9b5.b..8b6.10b6.b9.7b9.8b8.17b3.3b9.7b9.8b8.6b10.b.b.b." },
{ "IBM-1047", NULL, "4cbcbc3b9cbccbccbb4c6bcc5b3cbbc4bc4bccbc191.b" },
{ "iso8859", NULL, "8bcccbcc18b95.33b." },
{ "koi8-r", NULL, "8bcccbcc18b95.b128." },
{ "latin1", NULL, "8bcccbcc18b95.33b." },
Expand Down Expand Up @@ -293,8 +294,22 @@ prchar(c)
sprintf(buf, "%c", c);
else if (c == ESC)
sprintf(buf, "ESC");
else if (c < 128 && !control_char(c ^ 0100))
sprintf(buf, "^%c", c ^ 0100);
#if IS_EBCDIC_HOST
else if (!binary_char(c) && c < 64)
sprintf(buf, "^%c",
/*
* This array roughly inverts CONTROL() #defined in less.h,
* and should be kept in sync with CONTROL() and IBM-1047.
*/
"@ABC.I.?...KLMNO"
"PQRS.JH.XY.."
"\\]^_"
"......W[.....EFG"
"..V....D....TU.Z"[c]);
#else
else if (c < 128 && !control_char(c ^ 0100))
sprintf(buf, "^%c", c ^ 0100);
#endif
else
sprintf(buf, binfmt, c);
return (buf);
Expand Down
1 change: 0 additions & 1 deletion filename.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#if MSDOS_COMPILER==DJGPPC
#include <glob.h>
#include <dir.h>
#include <limits.h>
#define _MAX_PATH PATH_MAX
#endif
#endif
Expand Down
21 changes: 18 additions & 3 deletions less.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
#if HAVE_CTYPE_H
#include <ctype.h>
#endif
#if HAVE_LIMITS_H
#include <limits.h>
#endif
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
Expand Down Expand Up @@ -136,13 +139,21 @@ void free();

#define BAD_LSEEK ((off_t)-1)

#ifndef CHAR_BIT
#define CHAR_BIT 8
#endif

/*
* Upper bound on the string length of an integer converted to string.
* 302 / 1000 is ceil (log10 (2.0)). Subtract 1 for the sign bit;
* add 1 for integer division truncation; add 1 more for a minus sign.
*/
#define INT_STRLEN_BOUND(t) ((sizeof(t) * CHAR_BIT - 1) * 302 / 1000 + 1 + 1)

/*
* Special types and constants.
*/
typedef off_t POSITION;
#define PR_POSITION "%ld"
#define MAX_PRINT_POSITION 20
#define MAX_PRINT_INT 10

#define NULL_POSITION ((POSITION)(-1))

Expand Down Expand Up @@ -283,6 +294,10 @@ struct textlist
#define AT_INVIS (4)
#define AT_STANDOUT (5)

#if '0' == 240
#define IS_EBCDIC_HOST 1
#endif

#if IS_EBCDIC_HOST
/*
* Long definition for EBCDIC.
Expand Down
8 changes: 8 additions & 0 deletions less.nro.VER
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,11 @@ Same as iso8859.
Selects a character set appropriate for MS-DOS.
.IP ebcdic
Selects an EBCDIC character set.
.IP IBM-1047
Selects an EBCDIC character set used by OS/390 Unix Services.
This is the EBCDIC analogue of latin1. You get similar results
by setting either LESSCHARSET=IBM-1047 or LC_CTYPE=en_US
in your environment.
.IP koi8-r
Selects a Russian character set.
.IP next
Expand Down Expand Up @@ -1116,6 +1121,9 @@ to each of the possible values for LESSCHARSET:
ebcdic 5bc6bcc7bcc41b.9b7.9b5.b..8b6.10b6.b9.7b
.br
\ \ \ \ \ \ 9.8b8.17b3.3b9.7b9.8b8.6b10.b.b.b.
.br
IBM-1047 4cbcbc3b9cbccbccbb4c6bcc5b3cbbc4bc4bccbc
\ \ \ \ \ \ 191.b
.br
iso8859 8bcccbcc18b95.33b.
.br
Expand Down
33 changes: 29 additions & 4 deletions line.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,12 +471,37 @@ do_append(c, pos)
* bold (if an identical character is overstruck),
* or just deletion of the character in the buffer.
*/
overstrike = 0;
if ((char)c == linebuf[curr])
overstrike--;
if (utf_mode && curr > 1 && (char)c == linebuf[curr-2])
{
backc();
backc();
overstrike = 2;
} else if (utf_mode && curr > 0 && (char)c == linebuf[curr-1])
{
backc();
STOREC(linebuf[curr], AT_BOLD);
else if (c == '_')
overstrike = 1;
} else if ((char)c == linebuf[curr])
{
STOREC(linebuf[curr], AT_BOLD);
} else if (c == '_')
{
if (utf_mode)
{
if (curr > 0 && IS_CONT(linebuf[curr]))
attr[curr-1] = AT_UNDERLINE;
if (curr > 1 && IS_CONT(linebuf[curr-1]))
attr[curr-2] = AT_UNDERLINE;
if (curr > 2 && IS_CONT(linebuf[curr-2]))
attr[curr-3] = AT_UNDERLINE;
if (curr > 3 && IS_CONT(linebuf[curr-3]))
attr[curr-4] = AT_UNDERLINE;
if (curr > 4 && IS_CONT(linebuf[curr-4]))
attr[curr-5] = AT_UNDERLINE;
}
STOREC(linebuf[curr], AT_UNDERLINE);
else if (linebuf[curr] == '_')
} else if (linebuf[curr] == '_')
STOREC(c, AT_UNDERLINE);
else if (control_char(c))
goto do_control_char;
Expand Down
2 changes: 1 addition & 1 deletion lsystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* Necessarily very OS dependent.
*/

#include <signal.h>
#include "less.h"
#include <signal.h>
#include "position.h"

#if MSDOS_COMPILER
Expand Down
9 changes: 5 additions & 4 deletions option.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,12 @@ scan_option(s)
* EVERY input file.
*/
plusoption = TRUE;
if (*s == '+')
every_first_cmd = save(++s);
else
ungetsc(s);
str = s;
s = optstring(s, propt('+'));
if (*str == '+')
every_first_cmd = save(++str);
else
ungetsc(str);
continue;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
Expand Down
48 changes: 10 additions & 38 deletions os.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
#if HAVE_VALUES_H
#include <values.h>
#endif
#if HAVE_LIMITS_H
#include <limits.h>
#endif

#if HAVE_TIME_T
#define time_type time_t
Expand Down Expand Up @@ -232,36 +229,6 @@ errno_message(filename)
return (m);
}

/*
* Return the largest possible number that can fit in a long.
*/
static long
get_maxlong()
{
#ifdef LONG_MAX
return (LONG_MAX);
#else
#ifdef MAXLONG
return (MAXLONG);
#else
long n, n2;

/*
* Keep doubling n until we overflow.
* {{ This actually only returns the largest power of two that
* can fit in a long, but percentage() doesn't really need
* it any more accurate than that. }}
*/
n2 = 128; /* Hopefully no maxlong is less than 128! */
do {
n = n2;
n2 *= 2;
} while (n2 / 2 == n);
return (n);
#endif
#endif
}

/*
* Return the ratio of two POSITIONS, as a percentage.
* {{ Assumes a POSITION is a long int. }}
Expand All @@ -270,23 +237,28 @@ get_maxlong()
percentage(num, den)
POSITION num, den;
{
if (num <= get_maxlong() / 100)
return ((100 * num) / den);
POSITION num100 = num * 100;

if (num100 / 100 == num)
return (num100 / den);
else
return (num / (den / 100));
}

/*
* Return the specified percentage of a POSITION.
* {{ Assumes a POSITION is a long int. }}
*/
public POSITION
percent_pos(pos, percent)
POSITION pos;
int percent;
{
if (pos <= get_maxlong() / 100)
return ((percent * pos) / 100);
POSITION result100;

if (percent == 0)
return (0);
else if ((result100 = pos * percent) / percent == pos)
return (result100 / 100);
else
return (percent * (pos / 100));
}
Expand Down
2 changes: 1 addition & 1 deletion output.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ iprintnum(num, radix)
register char *s;
int r;
int neg;
char buf[10];
char buf[INT_STRLEN_BOUND(num)];

neg = (num < 0);
if (neg)
Expand Down
Loading

0 comments on commit 28fd281

Please sign in to comment.