From bd648e890b37f51b1f6b0c83e048f74eab3df086 Mon Sep 17 00:00:00 2001 From: Mark Nudelman Date: Wed, 12 Dec 2001 03:37:07 +0000 Subject: [PATCH] Fixes for OS/2. --- Makefile.o2e | 9 ++++--- NEWS.VER | 6 +++-- defines.o2 | 35 +++++++++++++------------ filename.c | 12 +++++++++ less.h | 4 +-- less.nro.VER | 5 ++-- lsystem.c | 5 ++++ main.c | 2 +- screen.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++-- ttyin.c | 36 +++++++------------------- version.c | 3 ++- 11 files changed, 135 insertions(+), 55 deletions(-) diff --git a/Makefile.o2e b/Makefile.o2e index 2dcfa7cc..3ff51b34 100644 --- a/Makefile.o2e +++ b/Makefile.o2e @@ -4,8 +4,8 @@ #### Start of system configuration section. #### CC = gcc -Zomf -CFLAGS = -I. -O -LDFLAGS = -s -Zcrtdll -Zstack 512 +CFLAGS = -I. -O2 -Wall +LDFLAGS = -s -Zcrtdll LIBS = -ltermcap O = obj @@ -25,7 +25,7 @@ OBJ = main.${O} screen.${O} brac.${O} ch.${O} charset.${O} cmdbuf.${O} \ output.${O} position.${O} prompt.${O} search.${O} signal.${O} \ tags.${O} ttyin.${O} version.${O} regexp.${O} -all: less.exe lesskey.exe +all: less.exe lesskey.exe scrsize.exe less.exe: ${OBJ} ${CC} ${OBJ} -o $@ ${LDFLAGS} ${LIBS} @@ -33,6 +33,9 @@ less.exe: ${OBJ} lesskey.exe: lesskey.${O} version.${O} ${CC} lesskey.${O} version.${O} -o $@ ${LDFLAGS} +scrsize.exe: scrsize.c + ${CC} ${CFLAGS} -D__ST_MT_ERRNO__ -s -Zmtd -lX11 $< + ${OBJ}: defines.h less.h defines.h: defines.o2 diff --git a/NEWS.VER b/NEWS.VER index c84b27ad..38100eef 100644 --- a/NEWS.VER +++ b/NEWS.VER @@ -35,7 +35,7 @@ * Windows version sets window title. -* Default LESSCHARSET for MS-DOS versions is "dos". +* Default LESSCHARSET for MS-DOS versions is now "dos". * Fix problems when viewing files with very long lines. @@ -43,10 +43,12 @@ * Improve horizontal shifting of text using -R option with ANSI color. -* Eliminate some 32-bit file offset dependencies. +* Eliminate some dependencies on file offets being 32 bits. * Some fixes for EBCDIC systems. +* Some fixes for OS/2 systems. + ====================================================================== Major changes between "less" versions 354 and 358 diff --git a/defines.o2 b/defines.o2 index 627db775..92c8742d 100644 --- a/defines.o2 +++ b/defines.o2 @@ -60,7 +60,7 @@ * EDIT_PGM is the name of the (default) editor to be invoked. */ #define EDITOR (!SECURE) -#define EDIT_PGM "me" +#define EDIT_PGM "vi" /* * TAGS is 1 if you wish to support tag files. @@ -201,7 +201,7 @@ #define HAVE_CONST 1 /* Define HAVE_TIME_T if your system supports the "time_t" type. */ -#define HAVE_TIME_T 0 +#define HAVE_TIME_T 1 /* Define HAVE_STRERROR if you have the strerror() function. */ #define HAVE_STRERROR 1 @@ -213,22 +213,22 @@ /* Define MUST_DEFINE_ERRNO if you have errno but it is not define * in errno.h */ #define HAVE_ERRNO 1 -#define MUST_DEFINE_ERRNO 1 +/* #undef MUST_DEFINE_ERRNO */ /* Define HAVE_SYS_ERRLIST if you have the sys_errlist[] variable */ #define HAVE_SYS_ERRLIST 1 /* Define HAVE_OSPEED if your termcap library has the ospeed variable */ -#define HAVE_OSPEED 0 +#define HAVE_OSPEED 1 /* Define MUST_DEFINE_OSPEED if you have ospeed but it is not defined * in termcap.h. */ #define MUST_DEFINE_OSPEED 0 /* Define HAVE_LOCALE if you have locale.h and setlocale. */ -#define HAVE_LOCALE 0 +#define HAVE_LOCALE 1 /* Define HAVE_TERMIOS_FUNCS if you have tcgetattr/tcsetattr */ -#define HAVE_TERMIOS_FUNCS 0 +#define HAVE_TERMIOS_FUNCS 1 /* Define HAVE_UPPER_LOWER if you have isupper, islower, toupper, tolower */ #define HAVE_UPPER_LOWER 1 @@ -240,17 +240,17 @@ #define HAVE_MEMCPY 1 /* Define if you have the popen function. */ -#define HAVE_POPEN 0 +#define HAVE_POPEN 1 /* Define if you have the sigsetmask function. */ #define HAVE_SIGSETMASK 0 /* Define if you have the sigprocmask function. */ -#define HAVE_SIGPROCMASK 0 +#define HAVE_SIGPROCMASK 1 /* Define if you have the sigset_t type and sigemptyset macro */ -#define HAVE_SIGSET_T 0 -#define HAVE_SIGEMPTYSET 0 +#define HAVE_SIGSET_T 1 +#define HAVE_SIGEMPTYSET 1 /* Define if you have the stat function. */ #define HAVE_STAT 1 @@ -258,6 +258,9 @@ /* Define if you have the strchr function. */ #define HAVE_STRCHR 1 +/* Define if you have the strstr function. */ +#define HAVE_STRSTR 1 + /* Define if you have the system function. */ #define HAVE_SYSTEM 1 @@ -265,13 +268,13 @@ #define HAVE_CTYPE_H 1 /* Define if you have the header file. */ -#define HAVE_ERRNO_H 0 +#define HAVE_ERRNO_H 1 /* Define if you have the header file. */ #define HAVE_FCNTL_H 1 /* Define if you have the header file. */ -#define HAVE_LIMITS_H 0 +#define HAVE_LIMITS_H 1 /* Define if you have the header file. */ #define HAVE_STDIO_H 1 @@ -283,7 +286,7 @@ #define HAVE_STRING_H 1 /* Define if you have the header file. */ -#define HAVE_SYS_IOCTL_H 0 +#define HAVE_SYS_IOCTL_H 1 /* Define if you have the header file. */ #define HAVE_SYS_PTEM_H 0 @@ -292,13 +295,13 @@ #define HAVE_SYS_STREAM_H 0 /* Define if you have the header file. */ -#define HAVE_TERMCAP_H 0 +#define HAVE_TERMCAP_H 1 /* Define if you have the header file. */ -#define HAVE_TERMIO_H 0 +#define HAVE_TERMIO_H 1 /* Define if you have the header file. */ -#define HAVE_TERMIOS_H 0 +#define HAVE_TERMIOS_H 1 /* Define if you have the header file. */ #define HAVE_TIME_H 1 diff --git a/filename.c b/filename.c index c88e8e4c..ccb86c56 100644 --- a/filename.c +++ b/filename.c @@ -33,6 +33,9 @@ #include #endif #endif +#if OS2 +#include +#endif #if HAVE_STAT #include @@ -877,7 +880,16 @@ close_altfile(altfilename, filename, pipefd) if (secure) return; if (pipefd != NULL) + { +#if OS2 + /* + * The pclose function of OS/2 emx sometimes fails. + * Send SIGINT to the piped process before closing it. + */ + kill(((FILE*)pipefd)->_pid, SIGINT); +#endif pclose((FILE*) pipefd); + } if ((lessclose = lgetenv("LESSCLOSE")) == NULL) return; gfilename = esc_metachars(filename); diff --git a/less.h b/less.h index 35229e77..5769cdce 100644 --- a/less.h +++ b/less.h @@ -83,7 +83,7 @@ #include #include #endif -#if MSDOS_COMPILER==WIN32C +#if MSDOS_COMPILER==WIN32C || OS2 #include #endif #if MSDOS_COMPILER==DJGPPC @@ -190,7 +190,7 @@ typedef off_t POSITION; #if MSDOS_COMPILER==MSOFTC #define SET_BINARY(f) _setmode(f, _O_BINARY); #else -#if MSDOS_COMPILER +#if MSDOS_COMPILER || OS2 #define SET_BINARY(f) setmode(f, O_BINARY) #else #define SET_BINARY(f) diff --git a/less.nro.VER b/less.nro.VER index 225d4519..9c253323 100644 --- a/less.nro.VER +++ b/less.nro.VER @@ -882,7 +882,7 @@ Like, TAB, but cycles in the reverse direction thru the matching filenames. Complete the partial filename to the left of the cursor. If it matches more than one filename, all matches are entered into the command line (if they fit). -.IP "^U (Unix) or ESC (MS-DOS)" +.IP "^U (Unix and OS/2) or ESC (MS-DOS)" Delete the entire command line, or cancel the command if the command line is empty. If you have changed your line-kill character in Unix to something @@ -1411,7 +1411,8 @@ LINES and COLUMNS environment variables.) .IP EDITOR The name of the editor (used for the v command). .IP HOME -Name of the user's home directory (used to find a lesskey file on Unix systems). +Name of the user's home directory +(used to find a lesskey file on Unix and OS/2 systems). .IP "HOMEDRIVE, HOMEPATH" Concatenation of the HOMEDRIVE and HOMEPATH environment variables is the name of the user's home directory if the HOME variable is not set diff --git a/lsystem.c b/lsystem.c index 07d9ab1c..1fd578d7 100644 --- a/lsystem.c +++ b/lsystem.c @@ -107,7 +107,12 @@ lsystem(cmd, donemsg) */ inp = dup(0); close(0); +#if OS2 + /* The __open() system call translates "/dev/tty" to "con". */ + if (__open("/dev/tty", OPEN_READ) < 0) +#else if (open("/dev/tty", OPEN_READ) < 0) +#endif dup(inp); #endif diff --git a/main.c b/main.c index 51e4065b..6e37f5a7 100644 --- a/main.c +++ b/main.c @@ -162,7 +162,7 @@ main(argc, argv) ifile = get_ifile(FAKE_HELPFILE, ifile); while (argc-- > 0) { -#if (MSDOS_COMPILER && MSDOS_COMPILER != DJGPPC) || OS2 +#if (MSDOS_COMPILER && MSDOS_COMPILER != DJGPPC) /* * Because the "shell" doesn't expand filename patterns, * treat each argument as a filename pattern rather than diff --git a/screen.c b/screen.c index 8521e95d..19d36408 100644 --- a/screen.c +++ b/screen.c @@ -66,6 +66,7 @@ extern int fd0; #endif #if OS2 #include +#include "pckeys.h" #endif #if HAVE_SYS_STREAM_H #include @@ -88,6 +89,7 @@ extern int fd0; #if OS2 #define DEFAULT_TERM "ansi" +static char *windowid; #else #define DEFAULT_TERM "unknown" #endif @@ -712,6 +714,27 @@ scrsize() _scrsize(s); sys_width = s[0]; sys_height = s[1]; + /* + * When using terminal emulators for XFree86/OS2, the + * _scrsize function does not work well. + * Call the scrsize.exe program to get the window size. + */ + windowid = getenv("WINDOWID"); + if (windowid != NULL) + { + FILE *fd = popen("scrsize", "rt"); + if (fd != NULL) + { + int w, h; + fscanf(fd, "%i %i", &w, &h); + if (w > 0 && h > 0) + { + sys_width = w; + sys_height = h; + } + pclose(fd); + } + } } #else #ifdef TIOCGWINSZ @@ -835,7 +858,7 @@ special_key_str(key) { static char tbuf[40]; char *s; -#if MSDOS_COMPILER +#if MSDOS_COMPILER || OS2 static char k_right[] = { '\340', PCK_RIGHT, 0 }; static char k_left[] = { '\340', PCK_LEFT, 0 }; static char k_ctl_right[] = { '\340', PCK_CTL_RIGHT, 0 }; @@ -852,12 +875,56 @@ special_key_str(key) static char k_pagedown[] = { '\340', PCK_PAGEDOWN, 0 }; static char k_pageup[] = { '\340', PCK_PAGEUP, 0 }; static char k_f1[] = { '\340', PCK_F1, 0 }; -#else +#endif +#if !MSDOS_COMPILER char *sp = tbuf; #endif switch (key) { +#if OS2 + /* + * If windowid is not NULL, assume less is executed in + * the XFree86 environment. + */ + case SK_RIGHT_ARROW: + s = windowid ? ltgetstr("kr", &sp) : k_right; + break; + case SK_LEFT_ARROW: + s = windowid ? ltgetstr("kl", &sp) : k_left; + break; + case SK_UP_ARROW: + s = windowid ? ltgetstr("ku", &sp) : k_up; + break; + case SK_DOWN_ARROW: + s = windowid ? ltgetstr("kd", &sp) : k_down; + break; + case SK_PAGE_UP: + s = windowid ? ltgetstr("kP", &sp) : k_pageup; + break; + case SK_PAGE_DOWN: + s = windowid ? ltgetstr("kN", &sp) : k_pagedown; + break; + case SK_HOME: + s = windowid ? ltgetstr("kh", &sp) : k_home; + break; + case SK_END: + s = windowid ? ltgetstr("@7", &sp) : k_end; + break; + case SK_DELETE: + if (windowid) + { + s = ltgetstr("kD", &sp); + if (s == NULL) + { + tbuf[0] = '\177'; + tbuf[1] = '\0'; + s = tbuf; + } + } else + s = k_delete; + break; +#endif #if MSDOS_COMPILER case SK_RIGHT_ARROW: s = k_right; @@ -886,6 +953,8 @@ special_key_str(key) case SK_DELETE: s = k_delete; break; +#endif +#if MSDOS_COMPILER || OS2 case SK_INSERT: s = k_insert; break; diff --git a/ttyin.c b/ttyin.c index 7b97916b..d2c7c52d 100644 --- a/ttyin.c +++ b/ttyin.c @@ -14,6 +14,10 @@ */ #include "less.h" +#if OS2 +#include "cmd.h" +#include "pckeys.h" +#endif #if MSDOS_COMPILER==WIN32C #include "windows.h" extern char WIN32getch(); @@ -42,7 +46,7 @@ open_getchr() /* Make sure we get Ctrl+C events. */ SetConsoleMode((HANDLE)tty, ENABLE_PROCESSED_INPUT); #else -#if MSDOS_COMPILER || OS2 +#if MSDOS_COMPILER extern int fd0; /* * Open a new handle to CON: in binary mode @@ -65,7 +69,12 @@ open_getchr() * which in Unix is usually attached to the screen, * but also usually lets you read from the keyboard. */ +#if OS2 + /* The __open() system call translates "/dev/tty" to "con". */ + tty = __open("/dev/tty", OPEN_READ); +#else tty = open("/dev/tty", OPEN_READ); +#endif if (tty < 0) tty = 2; #endif @@ -110,30 +119,6 @@ getchr() result = 1; if (c == '\003') return (READ_INTR); -#else -#if OS2 - { - static int scan = -1; - flush(); - if (scan >= 0) - { - c = scan; - scan = -1; - } else - { - if ((c = _read_kbd(0, 1, 0)) == -1) - return (READ_INTR); - if (c == '\0') - { - /* - * Zero is usually followed by another byte, - * since certain keys send two bytes. - */ - scan = _read_kbd(0, 0, 0); - } - } - result = 1; - } #else result = iread(tty, &c, sizeof(char)); if (result == READ_INTR) @@ -146,7 +131,6 @@ getchr() */ quit(QUIT_ERROR); } -#endif #endif /* * Various parts of the program cannot handle diff --git a/version.c b/version.c index 60663715..b46d5b2a 100644 --- a/version.c +++ b/version.c @@ -615,7 +615,8 @@ v364 12/10/01 Better handling of very long lines in input; v365 12/11/01 Fix overstriking of tabs; Add support for global(1) and multiple tag matches (thanks to Shigio Yamaguchi and Tim Vanderhoek). +v366 12/11/01 Fixes for OS/2 (thanks to Kyosuke Tokoro). */ -char version[] = "365"; +char version[] = "366";