From ec02d5d9b4b2e28ddae3dee8273ee1d7d52bed8f Mon Sep 17 00:00:00 2001 From: Mark Nudelman Date: Mon, 22 Apr 1996 17:32:16 +0000 Subject: [PATCH] Initial port of Windows support. --- Makefile.aut | 6 +- Makefile.dsb | 8 +- Makefile.dsu | 8 +- Makefile.in | 8 -- Makefile.o9u | 2 +- NEWS.VER | 6 +- README.VER | 33 ++++- ch.c | 12 +- cmdbuf.c | 4 +- command.c | 18 ++- defines.ds | 7 +- defines.o2 | 7 +- defines.o9 | 20 ++- filename.c | 32 +++-- less.h | 5 +- less.hlp.old | 8 +- lesskey.nro.VER | 2 +- main.c | 6 - output.c | 16 ++- screen.c | 317 ++++++++++++++++++++++++++++++++++++------------ search.c | 2 +- ttyin.c | 8 ++ version.c | 3 +- 23 files changed, 388 insertions(+), 150 deletions(-) diff --git a/Makefile.aut b/Makefile.aut index ebe12a1f..0f3edae2 100644 --- a/Makefile.aut +++ b/Makefile.aut @@ -16,9 +16,10 @@ DISTFILES = ${SRC} regexp.c regexp.h \ cmd.h funcs.h less.h lesskey.h option.h position.h \ install.sh defines.h.in defines.h.top mkinstalldirs \ less.nro lesskey.nro less.man lesskey.man less.hlp \ - Makefile.dos Makefile.bcc defines.dos doscreen.c \ + Makefile.dos Makefile.bcc defines.dos screen.c \ Makefile.os2 defines.os2 \ - Makefile.osk defines.osk + Makefile.os9 defines.os9 \ + Makefile.w32 defines.w32 all: help.c funcs.h ${srcdir}/configure @@ -35,6 +36,7 @@ ${srcdir}/configure: ${srcdir}/configure.in funcs.h: ${SRC:%=${srcdir}/%} mv -f ${srcdir}/funcs.h ${srcdir}/funcs.h.old awk -f ${srcdir}/mkfuncs.awk ${SRC:%=${srcdir}/%} >${srcdir}/funcs.h + if cmp -s funcs.h funcs.h.old; then mv funcs.h.old funcs.h; fi lint: lint -I. ${CPPFLAGS} ${SRC} diff --git a/Makefile.dsb b/Makefile.dsb index 8f5a0caf..cbc6bd60 100644 --- a/Makefile.dsb +++ b/Makefile.dsb @@ -18,13 +18,7 @@ EXT = .EXE .c.obj: $(CC) -c -I. $(CPPFLAGS) $(CFLAGS) $< -SRC = main.c doscreen.c brac.c ch.c charset.c cmdbuf.c command.c \ - decode.c edit.c filename.c forwback.c help.c ifile.c \ - input.c jump.c line.c linenum.c lsystem.c \ - mark.c optfunc.c option.c opttbl.c os.c output.c \ - position.c prompt.c search.c signal.c tags.c \ - ttyin.c version.c -OBJ = main.obj doscreen.obj brac.obj ch.obj charset.obj cmdbuf.obj command.obj \ +OBJ = main.obj screen.obj brac.obj ch.obj charset.obj cmdbuf.obj command.obj \ decode.obj edit.obj filename.obj forwback.obj help.obj ifile.obj \ input.obj jump.obj line.obj linenum.obj lsystem.obj \ mark.obj optfunc.obj option.obj opttbl.obj os.obj output.obj \ diff --git a/Makefile.dsu b/Makefile.dsu index fb7f59a9..8c8bdf11 100644 --- a/Makefile.dsu +++ b/Makefile.dsu @@ -17,13 +17,7 @@ LIBS = $(LIBDIR)\llibce.lib $(LIBDIR)\graphics.lib .c.obj: $(CC) -c -I. $(CPPFLAGS) $(CFLAGS) $< -SRC = main.c doscreen.c brac.c ch.c charset.c cmdbuf.c command.c \ - decode.c edit.c filename.c forwback.c help.c ifile.c \ - input.c jump.c line.c linenum.c lsystem.c \ - mark.c optfunc.c option.c opttbl.c os.c output.c \ - position.c prompt.c search.c signal.c tags.c \ - ttyin.c version.c -OBJ = main.obj doscreen.obj brac.obj ch.obj charset.obj cmdbuf.obj command.obj \ +OBJ = main.obj screen.obj brac.obj ch.obj charset.obj cmdbuf.obj command.obj \ decode.obj edit.obj filename.obj forwback.obj help.obj ifile.obj \ input.obj jump.obj line.obj linenum.obj lsystem.obj \ mark.obj optfunc.obj option.obj opttbl.obj os.obj output.obj \ diff --git a/Makefile.in b/Makefile.in index 0990b9f3..054fa79b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -37,12 +37,6 @@ SHELL = /bin/sh .c.o: ${CC} -I. ${CFLAGS_COMPILE_ONLY} ${CPPFLAGS} ${CFLAGS} $< -SRC = main.c screen.c brac.c ch.c charset.c cmdbuf.c \ - command.c decode.c edit.c filename.c forwback.c \ - help.c ifile.c input.c jump.c line.c linenum.c \ - lsystem.c mark.c optfunc.c option.c opttbl.c os.c \ - output.c position.c prompt.c search.c signal.c \ - tags.c ttyin.c version.c OBJ = main.${O} screen.${O} brac.${O} ch.${O} charset.${O} cmdbuf.${O} \ command.${O} decode.${O} edit.${O} filename.${O} forwback.${O} \ help.${O} ifile.${O} input.${O} jump.${O} line.${O} linenum.${O} \ @@ -96,8 +90,6 @@ config.status: ${srcdir}/configure ${srcdir}/configure: ${srcdir}/configure.in cd ${srcdir}; autoheader; autoconf -lint: - lint -I. ${CPPFLAGS} ${SRC} clean: rm -f *.${O} core less lesskey diff --git a/Makefile.o9u b/Makefile.o9u index ce6c1b5d..cc685726 100644 --- a/Makefile.o9u +++ b/Makefile.o9u @@ -4,7 +4,7 @@ #### Start of system configuration section. #### CC = cc -CFLAGS = -D_OSK -v=. +CFLAGS = -v=. CFLAGS_COMPILE_ONLY = -eas LDFLAGS = -olM=24k LIBS = -ltermlib.l -lsys_clib.l -lunix.l diff --git a/NEWS.VER b/NEWS.VER index bd64a41e..3bfaf019 100644 --- a/NEWS.VER +++ b/NEWS.VER @@ -40,10 +40,14 @@ * Added -Ph to change the prompt for the help text. Added -Ps to change the default short prompt (same as plain -P). -* Ported to Borland C compiler for MS-DOS. +* Ported to the Borland C compiler for MS-DOS. + +* Ported to Windows 95 & Windows NT. * Ported to OS-9. +* Ported to GNU Hurd. + ====================================================================== diff --git a/README.VER b/README.VER index b3ebf316..74a346b3 100644 --- a/README.VER +++ b/README.VER @@ -31,7 +31,7 @@ INSTALLATION (Unix systems only): If you choose not to include some features in your version, you may wish to edit the manual page "less.nro" and the help page "less.hlp" to remove the descriptions of the features which you are removing. - If you edit less.hlp, you should run "make -f Makefile.author help.c". + If you edit less.hlp, you should run "make -f Makefile.aut help.c". 4. Type "make" and watch the fun. @@ -91,6 +91,32 @@ INSTALLATION (MS-DOS systems only) +======================================================================= +INSTALLATION (Windows-95 and Windows-NT systems only) + +1. Move the distributed source to its own directory. + +2. Rename Makefile.w32 to Makefile. + +3. Check the Makefile to make sure the definitions look ok. + +4. If you wish, you may edit defines.w32 to remove some optional features. + If you choose not to include some features in your version, you may + wish to edit the manual page less.man and the help page help.c + to remove the descriptions of the features which you are removing. + +5. Type "make" and watch the fun. + +6. If the make succeeds, it will generate a program "less" + in your current directory. Test the generated program. + +7. When satisfied that it works, if you wish to install it + in a public place, type "make install". + See step 6 of the Unix installation instructions for details + on how to change the default installation directories. + + + ======================================================================= INSTALLATION (OS/2 systems only) @@ -126,12 +152,11 @@ INSTALLATION (OS-9 systems only) 1. Move the distributed source to its own directory. -2. If you are using gcc, rename Makefile.gcc.os9 to Makefile. - If you are using Ultra C, rename Makefile.ult.os9 to Makefile. +2. Rename Makefile.os9 to Makefile. 3. Check the Makefile to make sure the definitions look ok. -4. If you wish, you may edit defines.osk to remove some optional features. +4. If you wish, you may edit defines.os9 to remove some optional features. If you choose not to include some features in your version, you may wish to edit the manual page less.man and the help page help.c to remove the descriptions of the features which you are removing. diff --git a/ch.c b/ch.c index 80a954c2..27e3cfa5 100644 --- a/ch.c +++ b/ch.c @@ -32,6 +32,9 @@ */ #include "less.h" +#if MSDOS_COMPILER==WIN32C +#include "errno.h" +#endif public int ignore_eoi; @@ -207,8 +210,13 @@ fch_get() return (EOI); if (n < 0) { - error("read error", NULL_PARG); - clear_eol(); +#if MSDOS_COMPILER==WIN32C + if (errno != EPIPE) +#endif + { + error("read error", NULL_PARG); + clear_eol(); + } n = 0; } diff --git a/cmdbuf.c b/cmdbuf.c index 2e3dd552..9d971194 100644 --- a/cmdbuf.c +++ b/cmdbuf.c @@ -153,7 +153,8 @@ len_cmdbuf() * Then position the cursor just after the char old_cp (a pointer into cmdbuf). */ static void -cmd_repaint(char *old_cp) +cmd_repaint(old_cp) + char *old_cp; { char *p; @@ -305,7 +306,6 @@ cmd_ichar(c) int c; { int col; - char *p; char *s; if (strlen(cmdbuf) >= sizeof(cmdbuf)-2) diff --git a/command.c b/command.c index c3d8fe5e..d43ea20a 100644 --- a/command.c +++ b/command.c @@ -127,18 +127,15 @@ mca_search() if (search_type & SRCH_NO_MATCH) cmd_putstr("Non-match "); - if (search_type & SRCH_PAST_EOF) - cmd_putstr("EOF-skip "); if (search_type & SRCH_FIRST_FILE) cmd_putstr("First-file "); + if (search_type & SRCH_PAST_EOF) + cmd_putstr("EOF-ignore "); if (search_type & SRCH_NO_MOVE) cmd_putstr("Keep-pos "); if (search_type & SRCH_NO_REGEX) cmd_putstr("Regex-off "); - if (search_type & ~(SRCH_FORW | SRCH_BACK)) - cmd_putstr(" "); - if (search_type & SRCH_FORW) cmd_putstr("/"); else @@ -1026,6 +1023,17 @@ commands() /* * Exit. */ + if (curr_ifile != NULL_IFILE && + ch_getflags() & CH_HELPFILE) + { + /* + * Quit while viewing the help file + * just means return to viewing the + * previous file. + */ + if (edit_prev(1) == 0) + break; + } quit(QUIT_OK); break; diff --git a/defines.ds b/defines.ds index 501e9300..2a479b70 100644 --- a/defines.ds +++ b/defines.ds @@ -147,6 +147,11 @@ */ #define HAVE_SYS_TYPES_H 1 +/* + * Define if you have the header file. + */ +#define HAVE_SGSTAT_H 0 + /* * HAVE_STAT is 1 if your system has the stat() call. */ @@ -245,9 +250,9 @@ #define HAVE_SYS_ERRLIST 1 /* Define HAVE_OSPEED if your termcap library has the ospeed variable */ -#define HAVE_OSPEED 0 /* Define MUST_DEFINE_OSPEED if you have ospeed but it is not defined * in termcap.h. */ +#define HAVE_OSPEED 0 #define MUST_DEFINE_OSPEED 0 /* Define HAVE_LOCALE if you have locale.h and setlocale. */ diff --git a/defines.o2 b/defines.o2 index 72ed10b8..4bcd241f 100644 --- a/defines.o2 +++ b/defines.o2 @@ -137,6 +137,11 @@ */ #define HAVE_SYS_TYPES_H 1 +/* + * Define if you have the header file. + */ +#define HAVE_SGSTAT_H 0 + /* * HAVE_STAT is 1 if your system has the stat() call. */ @@ -218,9 +223,9 @@ #define HAVE_FILENO 1 /* Define HAVE_ERRNO if you have the errno variable */ -#define HAVE_ERRNO 1 /* 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 /* Define HAVE_SYS_ERRLIST if you have the sys_errlist[] variable */ diff --git a/defines.o9 b/defines.o9 index f69643e7..aa506eac 100644 --- a/defines.o9 +++ b/defines.o9 @@ -25,6 +25,11 @@ */ /* OS/9 definition file for less. */ +/* + * This file has 2 sections: + * User preferences. + * Settings always true for OS-9 systems. + */ /* User preferences. */ @@ -123,13 +128,21 @@ #define DEF_LESSKEYINFILE ".lesskey" -/* Settings always true on Unix. */ +/* Settings always true for OS-9. */ + +/* This is not needed; it is defined by the compiler. */ +/* #define _OSK 1 */ /* * HAVE_SYS_TYPES_H is 1 if your system has . */ #undef HAVE_SYS_TYPES_H +/* + * Define if you have the header file. + */ +#define HAVE_SGSTAT_H 1 + /* * HAVE_STAT is 1 if your system has the stat() call. */ @@ -211,18 +224,18 @@ #define HAVE_FILENO 1 /* Define HAVE_ERRNO if you have the errno variable */ -#define HAVE_ERRNO 1 /* Define MUST_DEFINE_ERRNO if you have errno but it is not define * in errno.h */ +#define HAVE_ERRNO 1 #undef MUST_DEFINE_ERRNO /* Define HAVE_SYS_ERRLIST if you have the sys_errlist[] variable */ #undef HAVE_SYS_ERRLIST /* Define HAVE_OSPEED if your termcap library has the ospeed variable */ -#undef HAVE_OSPEED /* Define MUST_DEFINE_OSPEED if you have ospeed but it is not defined * in termcap.h. */ +#undef HAVE_OSPEED #undef MUST_DEFINE_OSPEED /* Define HAVE_LOCALE if you have locale.h and setlocale. */ @@ -293,4 +306,3 @@ /* Define if you have the header file. */ #undef HAVE_VALUES_H - diff --git a/filename.c b/filename.c index f2804f46..6644d680 100644 --- a/filename.c +++ b/filename.c @@ -33,6 +33,9 @@ #include "less.h" #if MSDOS_COMPILER #include +#if MSDOS_COMPILER==WIN32C +#include +#endif #endif #ifdef _OSK #include @@ -542,26 +545,41 @@ lglob(filename) register char *p; register int len; register int n; + +#if MSDOS_COMPILER==WIN32C +#define FIND_FIRST(filename,fndp) findfirst(filename, fndp, ~0) +#define FIND_NEXT(fndp) findnext(fndp) +#define FND_NAME ff_name + struct ffblk fnd; + char drive[MAXDRIVE]; + char dir[MAXDIR]; + char fname[MAXFILE]; + char ext[MAXEXT]; +#else +#define FIND_FIRST(filename,fndp) _dos_findfirst(filename, ~0, fndp) +#define FIND_NEXT(fndp) _dos_findnext(fndp) +#define FND_NAME name struct find_t fnd; char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char ext[_MAX_EXT]; +#endif filename = fexpand(filename); if (secure) return (filename); - if (_dos_findfirst(filename, ~0, &fnd) != 0) + if (FIND_FIRST(filename, &fnd) != 0) return (filename); - + _splitpath(filename, drive, dir, fname, ext); len = 100; gfilename = (char *) ecalloc(len, sizeof(char)); p = gfilename; do { - n = strlen(drive) + strlen(dir) + strlen(fnd.name); + n = strlen(drive) + strlen(dir) + strlen(fnd.FND_NAME); while (p - gfilename + n+2 >= len) { len *= 2; @@ -572,15 +590,15 @@ lglob(filename) gfilename = p; p = gfilename + strlen(gfilename); } - sprintf(p, "%s%s%s", drive, dir, fnd.name); + sprintf(p, "%s%s%s", drive, dir, fnd.FND_NAME); p += n; *p++ = ' '; - } while (_dos_findnext(&fnd) == 0); - + } while (FIND_NEXT(&fnd) == 0); + *--p = '\0'; return (gfilename); } - + public char * open_altfile(filename) char *filename; diff --git a/less.h b/less.h index 15677484..1c33f1bc 100644 --- a/less.h +++ b/less.h @@ -47,8 +47,9 @@ /* * Defines for MSDOS_COMPILER. */ -#define MSOFTC 1 -#define BORLANDC 2 +#define MSOFTC 1 /* Microsoft C */ +#define BORLANDC 2 /* Borland C */ +#define WIN32C 3 /* Windows (Borland C) */ /* * Language details. diff --git a/less.hlp.old b/less.hlp.old index 485f1f20..7cb030eb 100644 --- a/less.hlp.old +++ b/less.hlp.old @@ -10,10 +10,10 @@ e ^E j ^N CR * Forward one line (or _N lines). y ^Y k ^K ^P * Backward one line (or _N lines). f ^F ^V SPACE * Forward one window (or _N lines). - ESC-SPACE * Like SPACE, but don't stop at end-of-file. b ^B ESC-v * Backward one window (or _N lines). z * Forward one window (and set window to _N). w * Backward one window (and set window to _N). + ESC-SPACE * Forward one window, but don't stop at end-of-file. d ^D * Forward one half-window (and set half-window to _N). u ^U * Backward one half-window (and set half-window to _N). F Forward forever; like "tail -f". @@ -86,8 +86,8 @@ -d Dumb terminal. -e -E Quit at end of file. -f Force open non-regular files. - -g Don't highlight matches for previous search pattern. - -G Highlight ALL matches for previous search pattern. + -g Highlight only last match for searches. + -G Don't highlight any matches for searches. -h [_N] Backward scroll limit. -i Ignore case in searches. -I Ignore case in searches and in search patterns. @@ -130,7 +130,7 @@ DELETE ESC-x Delete char under cursor. CNTL-BACKSPACE ESC-BACKSPACE Delete word to left of cursor. CNTL-DELETE ESC-DELETE ESC-X Delete word under cursor. - CNTL-U (Unix only) ESC (MS-DOS only) Delete entire line. + CNTL-U ESC (MS-DOS only) Delete entire line. UpArrow ESC-k Retrieve previous command line. DownArrow ESC-j Retrieve next command line. TAB Complete filename & cycle. diff --git a/lesskey.nro.VER b/lesskey.nro.VER index 9580317f..29f39f1d 100644 --- a/lesskey.nro.VER +++ b/lesskey.nro.VER @@ -24,7 +24,7 @@ and the environment variable LESSKEY is set, the value of LESSKEY is used as the name of the output file. Otherwise, a standard filename is used as the name of the output file, which depends on the system being used: -On Unix systems, $HOME/.less is used; +On Unix and OS-9 systems, $HOME/.less is used; on MS-DOS systems, $HOME/_less is used; and on OS/2 systems, $HOME/less.ini is used, or $INIT/less.ini if $HOME is undefined. diff --git a/main.c b/main.c index 8bf7df3c..ac2f690d 100644 --- a/main.c +++ b/main.c @@ -330,12 +330,6 @@ quit(status) { static int save_status; - if (curr_ifile != NULL_IFILE && ch_getflags() & CH_HELPFILE) - { - if (edit_prev(1) == 0) - return; - } - /* * Put cursor at bottom left corner, clear the line, * reset the terminal modes, and exit. diff --git a/output.c b/output.c index 79d0ac62..4e920c91 100644 --- a/output.c +++ b/output.c @@ -30,6 +30,9 @@ */ #include "less.h" +#if MSDOS_COMPILER==WIN32C +#include "windows.h" +#endif public int errmsgs; /* Count of messages displayed by error() */ public int need_clr; @@ -129,15 +132,21 @@ flush() register int n; register int fd; +#if MSDOS_COMPILER==WIN32C + { + DWORD nwritten = 0; + extern HANDLE con_out; + *ob = '\0'; + WriteConsole(con_out, obuf, strlen(obuf), &nwritten, NULL); + } +#else #if MSDOS_COMPILER==MSOFTC *ob = '\0'; _outtext(obuf); - ob = obuf; #else #if MSDOS_COMPILER==BORLANDC *ob = '\0'; cputs(obuf); - ob = obuf; #else n = ob - obuf; if (n == 0) @@ -145,9 +154,10 @@ flush() fd = (any_display) ? 1 : 2; if (write(fd, obuf, n) != n) screen_trashed = 1; - ob = obuf; #endif #endif +#endif + ob = obuf; } /* diff --git a/screen.c b/screen.c index 5a2760e6..52916798 100644 --- a/screen.c +++ b/screen.c @@ -28,8 +28,6 @@ /* * Routines which deal with the characteristics of the terminal. * Uses termcap to be as terminal-independent as possible. - * - * {{ Maybe someday this should be rewritten to use curses or terminfo. }} */ #include "less.h" @@ -41,6 +39,10 @@ #else #if MSDOS_COMPILER==BORLANDC #include +#else +#if MSDOS_COMPILER==WIN32C +#include +#endif #endif #endif #include @@ -56,7 +58,7 @@ #if HAVE_TERMIO_H #include #else -#ifdef _OSK +#if HAVE_SGSTAT_H #include #else #include @@ -66,6 +68,7 @@ #endif #endif #endif + #if HAVE_TERMCAP_H #include #endif @@ -104,31 +107,46 @@ static int flash_created = 0; static int videopages; static long msec_loops; +#define SETCOLORS(fg,bg) _settextcolor(fg); _setbkcolor(bg); #endif #if MSDOS_COMPILER==BORLANDC static unsigned short *whitescreen; #define _settextposition(y,x) gotoxy(x,y) -#define _settextcolor(c) textcolor(c) -#define _setbkcolor(c) textbackground(c) #define _clearscreen(m) clrscr() #define _outtext(s) cputs(s) +#define SETCOLORS(fg,bg) textcolor(fg); textbackground(bg); +#endif + +#if MSDOS_COMPILER==WIN32C +static WORD curr_attr; +static int pending_scancode = 0; +static WORD *whitescreen; +static constant COORD TOPLEFT = {0, 0}; +#define FG_COLORS (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY) +#define BG_COLORS (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY) +HANDLE con_in; +HANDLE con_out; +#define SETCOLORS(fg,bg) curr_attr = (fg) | (bg); \ + SetConsoleTextAttribute(con_out, curr_attr); #endif #if MSDOS_COMPILER -public int nm_fg_color = 7; /* Color of normal text */ -public int nm_bg_color = 0; -public int bo_fg_color = 15; /* Color of bold text */ -public int bo_bg_color = 0; -public int ul_fg_color = 9; /* Color of underlined text */ -public int ul_bg_color = 0; -public int so_fg_color = 0; /* Color of standout text */ -public int so_bg_color = 7; -public int bl_fg_color = 12; /* Color of blinking text */ -public int bl_bg_color = 0; -static int sy_fg_color; +public int nm_fg_color; /* Color of normal text */ +public int nm_bg_color; +public int bo_fg_color; /* Color of bold text */ +public int bo_bg_color; +public int ul_fg_color; /* Color of underlined text */ +public int ul_bg_color; +public int so_fg_color; /* Color of standout text */ +public int so_bg_color; +public int bl_fg_color; /* Color of blinking text */ +public int bl_bg_color; +static int sy_fg_color; /* Color of system text (before less) */ static int sy_bg_color; + #else + /* * Strings passed to tputs() to do various terminal functions. */ @@ -299,7 +317,7 @@ raw_mode(on) #ifdef VWERASE werase_char = s.c_cc[VWERASE]; #else - werase_char = 0; + werase_char = CONTROL('W'); #endif /* @@ -418,7 +436,7 @@ raw_mode(on) #ifdef VWERASE werase_char = s.c_cc[VWERASE]; #else - werase_char = 0; + werase_char = CONTROL('W'); #endif /* @@ -460,7 +478,7 @@ raw_mode(on) #endif erase_char = s.sg_erase; kill_char = s.sg_kill; - werase_char = 0; + werase_char = CONTROL('W'); /* * Set the modes to the way we want them. @@ -495,7 +513,7 @@ raw_mode(on) save_term = s; erase_char = s.sg_bspch; kill_char = s.sg_dlnch; - werase_char = 0; + werase_char = CONTROL('W'); /* * Set the modes to the way we want them. @@ -520,7 +538,8 @@ raw_mode(on) LSIGNAL(SIGINT, SIG_IGN); #endif erase_char = '\b'; - kill_char = '\033'; + kill_char = '\033'; /* ESC */ + werase_char = CONTROL('W'); #endif #endif #endif @@ -589,6 +608,14 @@ scrsize() sc_width = w.screenwidth; } #else +#if MSDOS_COMPILER==WIN32C + { + CONSOLE_SCREEN_BUFFER_INFO scr; + GetConsoleScreenBufferInfo(con_out, &scr); + sc_height = scr.dwSize.Y; + sc_width = scr.dwSize.X; + } +#else #if OS2 { int s[2]; @@ -624,6 +651,7 @@ scrsize() #endif #endif #endif +#endif #endif if (sc_height > 0) ; @@ -918,14 +946,60 @@ get_term() #if MSDOS_COMPILER auto_wrap = 1; ignaw = 0; + can_goto_line = 1; /* - * We could set the *_s_width, *_e_width, and *_color variables - * here, but they're all initialized statically. + * Set up default colors. + * The xx_s_width and xx_e_width variables are initialized to 0. */ + nm_fg_color = 7; + nm_bg_color = 0; + bo_fg_color = 15; + bo_bg_color = 0; + ul_fg_color = 9; + ul_bg_color = 0; + so_fg_color = 0; + so_bg_color = 7; + bl_fg_color = 12; + bl_bg_color = 0; #if MSDOS_COMPILER==MSOFTC + sy_bg_color = _getbkcolor(); + sy_fg_color = _gettextcolor(); get_clock(); -#endif #else +#if MSDOS_COMPILER==BORLANDC + struct text_info w; + gettextinfo(&w); + sy_bg_color = (w.attribute >> 4) & 0x0F; + sy_fg_color = (w.attribute >> 0) & 0x0F; +#else +#if MSDOS_COMPILER==WIN32C + WORD attr; + DWORD nread; + CONSOLE_SCREEN_BUFFER_INFO scr; + + GetConsoleScreenBufferInfo(con_out, &scr); + ReadConsoleOutputAttribute(con_out, &attr, 1, scr.dwCursorPosition, &nread); + sy_bg_color = attr & BG_COLORS; + sy_fg_color = attr & FG_COLORS; + curr_attr = sy_bg_color | sy_fg_color; + con_in = GetStdHandle(STD_INPUT_HANDLE); + con_out = GetStdHandle(STD_OUTPUT_HANDLE); + + /* Can't use default bg colors in Windows? */ + nm_bg_color = sy_bg_color; + bo_bg_color = sy_bg_color; + ul_bg_color = sy_bg_color; + bl_bg_color = sy_bg_color; + /* Make standout = inverse video. */ + so_fg_color = sy_bg_color; + so_bg_color = sy_fg_color; +#endif +#endif +#endif +#endif + +#else /* !MSDOS_COMPILER */ + char *sp; register char *t1, *t2; char *term; @@ -1243,22 +1317,31 @@ cheaper(t1, t2, def) #if MSDOS_COMPILER + +#if MSDOS_COMPILER==WIN32C + static void +_settextposition(int row, int col) +{ + COORD cpos; + cpos.X = col-1; + cpos.Y = row-1; + SetConsoleCursorPosition(con_out, cpos); +} +#endif + /* * Initialize the screen to the correct color at startup. */ static void initcolor() { - _settextcolor(nm_fg_color); - _setbkcolor(nm_bg_color); + SETCOLORS(nm_fg_color, nm_bg_color); #if 0 /* * This clears the screen at startup. This is different from * the behavior of other versions of less. Disable it for now. */ - int height; - int width; char *blanks; int row; int col; @@ -1266,14 +1349,12 @@ initcolor() /* * Create a complete, blank screen using "normal" colors. */ - _settextcolor(nm_fg_color); - _setbkcolor(nm_bg_color); - scrsize(&height, &width); + SETCOLORS(nm_fg_color, nm_bg_color); blanks = (char *) ecalloc(width+1, sizeof(char)); - for (col = 0; col < width; col++) + for (col = 0; col < sc_width; col++) blanks[col] = ' '; - blanks[width] = '\0'; - for (row = 0; row < height; row++) + blanks[sc_width] = '\0'; + for (row = 0; row < sc_height; row++) _outtext(blanks); free(blanks); #endif @@ -1292,17 +1373,6 @@ init() tputs(sc_init, sc_height, putchr); tputs(sc_s_keypad, sc_height, putchr); #else -#if MSDOS_COMPILER==MSOFTC - sy_bg_color = _getbkcolor(); - sy_fg_color = _gettextcolor(); -#else -#if MSDOS_COMPILER==BORLANDC - struct text_info w; - gettextinfo(&w); - sy_bg_color = (w.attribute >> 4) & 0x0F; - sy_fg_color = (w.attribute >> 0) & 0x0F; -#endif -#endif initcolor(); flush(); #endif @@ -1323,8 +1393,7 @@ deinit() tputs(sc_e_keypad, sc_height, putchr); tputs(sc_deinit, sc_height, putchr); #else - _setbkcolor(sy_bg_color); - _settextcolor(sy_fg_color); + SETCOLORS(sy_fg_color, sy_bg_color); putstr("\n"); #endif init_done = 0; @@ -1354,6 +1423,7 @@ add_line() #if !MSDOS_COMPILER tputs(sc_addline, sc_height, putchr); #else + flush(); #if MSDOS_COMPILER==MSOFTC _scrolltextwindow(_GSCROLLDOWN); _settextposition(1,1); @@ -1362,6 +1432,25 @@ add_line() movetext(1,1, sc_width,sc_height-1, 1,2); gotoxy(1,1); clreol(); +#else +#if MSDOS_COMPILER==WIN32C + CHAR_INFO fillchar; + SMALL_RECT rcSrc, rcClip; + COORD new_org = {0, 1}; + + rcClip.Left = 0; + rcClip.Top = 0; + rcClip.Right = sc_width - 1; + rcClip.Bottom = sc_height - 1; + rcSrc.Left = 0; + rcSrc.Top = 0; + rcSrc.Right = sc_width - 1; + rcSrc.Bottom = sc_height - 2; + fillchar.Char.AsciiChar = ' '; + fillchar.Attributes = curr_attr; + ScrollConsoleScreenBuffer(con_out, &rcSrc, &rcClip, new_org, &fillchar); + _settextposition(1,1); +#endif #endif #endif #endif @@ -1441,6 +1530,18 @@ create_flash() return; for (n = 0; n < sc_width * sc_height; n++) whitescreen[n] = 0x7020; +#else +#if MSDOS_COMPILER==WIN32C + register int n; + + whitescreen = (WORD *) + malloc(sc_height * sc_width * sizeof(WORD)); + if (whitescreen == NULL) + return; + /* Invert the standard colors. */ + for (n = 0; n < sc_width * sc_height; n++) + whitescreen[n] = (sy_fg_color << 4) | (sy_bg_color >> 4); +#endif #endif #endif flash_created = 1; @@ -1459,20 +1560,15 @@ vbell() tputs(sc_visual_bell, sc_height, putchr); #else #if MSDOS_COMPILER==MSOFTC + /* + * Create a flash screen on the second video page. + * Switch to that page, then switch back. + */ if (!flash_created) - /* - * Create a "flash" on the second video page. - */ create_flash(); if (videopages < 2) - /* - * There is no "second video page". - */ return; _setvisualpage(1); - /* - * Leave it displayed for 100 msec. - */ delay(100); _setvisualpage(0); #else @@ -1481,24 +1577,44 @@ vbell() /* * Get a copy of the current screen. - * Display an all white screen. + * Display the flash screen. * Then restore the old screen. */ if (!flash_created) create_flash(); - + if (whitescreen == NULL) + return; currscreen = (unsigned short *) malloc(sc_width * sc_height * sizeof(short)); - if (currscreen == NULL || whitescreen == NULL) - { - beep(); + if (currscreen == NULL) return; - } gettext(1, 1, sc_width, sc_height, currscreen); puttext(1, 1, sc_width, sc_height, whitescreen); delay(100); puttext(1, 1, sc_width, sc_height, currscreen); free(currscreen); +#else +#if MSDOS_COMPILER==WIN32C + WORD *currscreen; + DWORD nread; + + if (!flash_created) + create_flash(); + if (whitescreen == NULL) + return; + currscreen = (WORD *) + malloc(sc_width * sc_height * sizeof(WORD)); + if (currscreen == NULL) + return; + ReadConsoleOutputAttribute(con_out, currscreen, + sc_height * sc_width, TOPLEFT, &nread); + WriteConsoleOutputAttribute(con_out, whitescreen, + sc_height * sc_width, TOPLEFT, &nread); + delay(100); + WriteConsoleOutputAttribute(con_out, currscreen, + sc_height * sc_width, cpos, &nread); + free(currscreen); +#endif #endif #endif #endif @@ -1512,9 +1628,13 @@ beep() { #if !MSDOS_COMPILER putchr('\7'); +#else +#if MSDOS_COMPILER==WIN32C + MessageBeep(0); #else write(1, "\7", 1); #endif +#endif } /* @@ -1539,8 +1659,16 @@ clear() tputs(sc_clear, sc_height, putchr); #else flush(); +#if MSDOS_COMPILER==WIN32C + DWORD nchars; + FillConsoleOutputCharacter(con_out, ' ', + sc_width * sc_height, TOPLEFT, &nchars); + FillConsoleOutputAttribute(con_out, curr_attr, + sc_width * sc_height, TOPLEFT, &nchars); +#else _clearscreen(_GCLEARSCREEN); #endif +#endif } /* @@ -1580,6 +1708,22 @@ clear_eol() #if MSDOS_COMPILER==BORLANDC flush(); clreol(); +#else +#if MSDOS_COMPILER==WIN32C + DWORD nchars; + COORD cpos; + CONSOLE_SCREEN_BUFFER_INFO scr; + + flush(); + GetConsoleScreenBufferInfo(con_out, &scr); + cpos.X = scr.dwCursorPosition.X; + cpos.Y = scr.dwCursorPosition.Y; + curr_attr = scr.wAttributes; + FillConsoleOutputCharacter(con_out, ' ', + sc_width - cpos.X, cpos, &nchars); + FillConsoleOutputAttribute(con_out, curr_attr, + sc_width - cpos.X, cpos, &nchars); +#endif #endif #endif #endif @@ -1613,8 +1757,7 @@ so_enter() tputs(sc_s_in, 1, putchr); #else flush(); - _setbkcolor(so_bg_color); - _settextcolor(so_fg_color); + SETCOLORS(so_fg_color, so_bg_color); #endif } @@ -1628,8 +1771,7 @@ so_exit() tputs(sc_s_out, 1, putchr); #else flush(); - _setbkcolor(nm_bg_color); - _settextcolor(nm_fg_color); + SETCOLORS(nm_fg_color, nm_bg_color); #endif } @@ -1644,8 +1786,7 @@ ul_enter() tputs(sc_u_in, 1, putchr); #else flush(); - _setbkcolor(ul_bg_color); - _settextcolor(ul_fg_color); + SETCOLORS(ul_fg_color, ul_bg_color); #endif } @@ -1659,8 +1800,7 @@ ul_exit() tputs(sc_u_out, 1, putchr); #else flush(); - _setbkcolor(nm_bg_color); - _settextcolor(nm_fg_color); + SETCOLORS(nm_fg_color, nm_bg_color); #endif } @@ -1674,8 +1814,7 @@ bo_enter() tputs(sc_b_in, 1, putchr); #else flush(); - _setbkcolor(bo_bg_color); - _settextcolor(bo_fg_color); + SETCOLORS(bo_fg_color, bo_bg_color); #endif } @@ -1689,8 +1828,7 @@ bo_exit() tputs(sc_b_out, 1, putchr); #else flush(); - _setbkcolor(nm_bg_color); - _settextcolor(nm_fg_color); + SETCOLORS(nm_fg_color, nm_bg_color); #endif } @@ -1704,8 +1842,7 @@ bl_enter() tputs(sc_bl_in, 1, putchr); #else flush(); - _setbkcolor(bl_bg_color); - _settextcolor(bl_fg_color); + SETCOLORS(bl_fg_color, bl_bg_color); #endif } @@ -1719,8 +1856,7 @@ bl_exit() tputs(sc_bl_out, 1, putchr); #else flush(); - _setbkcolor(nm_bg_color); - _settextcolor(nm_fg_color); + SETCOLORS(nm_fg_color, nm_bg_color); #endif } @@ -1752,6 +1888,21 @@ backspace() #else #if MSDOS_COMPILER==BORLANDC cputs("\b"); +#else +#if MSDOS_COMPILER==WIN32C + COORD cpos; + CONSOLE_SCREEN_BUFFER_INFO scr; + + flush(); + GetConsoleScreenBufferInfo(con_out, &scr); + cpos.X = scr.dwCursorPosition.X; + cpos.Y = scr.dwCursorPosition.Y; + if (cpos.X <= 0) + return; + _settextposition(cpos.Y, cpos.X-1); + putch(' '); + _settextposition(cpos.Y, cpos.X-1); +#endif #endif #endif #endif @@ -1772,7 +1923,6 @@ putbs() { #if MSDOS_COMPILER==MSOFTC struct rccoord tpos; - tpos = _gettextposition(); row = tpos.row; col = tpos.col; @@ -1780,11 +1930,18 @@ putbs() #if MSDOS_COMPILER==BORLANDC row = wherey(); col = wherex(); +#else +#if MSDOS_COMPILER==WIN32C + CONSOLE_SCREEN_BUFFER_INFO scr; + GetConsoleScreenBufferInfo(con_out, &scr); + row = scr.dwCursorPosition.Y + 1; + col = scr.dwCursorPosition.X + 1; +#endif #endif #endif } if (col <= 1) return; _settextposition(row, col-1); -#endif +#endif /* MSDOS_COMPILER */ } diff --git a/search.c b/search.c index be05f201..03167bdc 100644 --- a/search.c +++ b/search.c @@ -297,7 +297,7 @@ compile_pattern(pattern, search_type) if (last_pattern != NULL) free(last_pattern); - last_pattern = calloc(1, strlen(pattern)+1); + last_pattern = (char *) calloc(1, strlen(pattern)+1); if (last_pattern != NULL) strcpy(last_pattern, pattern); diff --git a/ttyin.c b/ttyin.c index a2f15883..e54e88a9 100644 --- a/ttyin.c +++ b/ttyin.c @@ -30,6 +30,10 @@ */ #include "less.h" +#if MSDOS_COMPILER==WIN32C +#include "windows.h" +extern HANDLE hConIn; +#endif static int tty; @@ -77,7 +81,11 @@ getchr() * In raw read, we don't see ^C so look here for it. */ flush(); +#if MSDOS_COMPILER==WIN32C + c = WIN32getch(); +#else c = getch(); +#endif result = 1; if (c == '\003') return (READ_INTR); diff --git a/version.c b/version.c index c5954539..0310d44b 100644 --- a/version.c +++ b/version.c @@ -535,6 +535,7 @@ v307 3/25/96 Allow cmd line arg "--"; fix DOS & OS/2 defines.h. v308 4/4/96 Port to OS-9 (thanks to Boisy Pitre); fix -d. v309 4/9/96 Fix OS-9 version; fix tags bug with "$". v310 4/10/96 Get rid of HELPFILE. +v311 4/22/96 Add Windows32 support; merge doscreen.c into screen.c. */ -char version[] = "310"; +char version[] = "311";