2011-05-25  Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	* lesskey.c (main): If LFN support available used ".less" else "_less".
	(parse_args): If LFN support available used ".lesskey" else "_lesskey".

	* lesskey.nro: Add DJGPP specific informations.


2011-05-24  Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	* less.nro: Add DJGPP specific informations.

	* main.c (main): If edit is the used editor change the default prompt.


2011-05-22  Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	* cmdbuf.c (histfile_name) [DJGPPC]: If LFN support is available load
	.lesshst else _lesshst.  If LFN is not available load _lesshst.


2011-05-21  Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	* less.h [MSDOS_COMPILER, DJGPPC]: For DJGPP define DIR_EXISTS and
	FILE_EXISTS.

	* decode.c (init_cmds) [MSDOS_COMPILER, DJGPPC]: If BINDIR exists and
	LFN support is available load .sysless else _sysless.
	If SYSDIR exists load sysless as system wide lesskey file.  If SYSDIR
	does not exist load "c:\\_sysless".
	If LFN support ia available load .less else _less.  If LFN is not
	available load _less.


2011-05-17  Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	* screen.c [DJGPPC]: New function clreol_maybe.  Clear to EOL, but only
	if in the last display line.

	* cmdbuf.c (histfile_name): Use CANONICALIZE_PATH to canonicalize HOME
	and LESSHISTFILE.

	* less.h [MSDOS_COMPILER, DJGPPC]: For DJGPP define CANONICALIZE_PATH,
	STRIP_FULL_PATH_AND_EXTENSION and HAVE_LFN_SUPPORT.  For all others
	the macros are no-ops.

	* main.c (main): Use STRIP_FULL_PATH_AND_EXTENSION for argv[0].
	Use CANONICALIZE_PATH to canonicalize all filenames from command line.

	* line.c [MSDOS_COMPILER, DJGPPC]: For DJGPP make (current shift)
	cshift public.
	(pdone): If the current line is finished, reset the current shift.

	* forwback.c (forw): Ignore any line shift that may still exist from
	the last line of the previous screenful.





diff -aprNU5 less-444.orig/cmdbuf.c less-444/cmdbuf.c
--- less-444.orig/cmdbuf.c	2011-04-11 22:04:22 +0000
+++ less-444/cmdbuf.c	2011-06-24 03:17:54 +0000
@@ -1332,21 +1332,21 @@ histfile_name()
 	char *home;
 	char *name;
 	int len;
 	
 	/* See if filename is explicitly specified by $LESSHISTFILE. */
-	name = lgetenv("LESSHISTFILE");
+	name = CANONICALIZE_PATH(lgetenv("LESSHISTFILE"));
 	if (name != NULL && *name != '\0')
 	{
 		if (strcmp(name, "-") == 0 || strcmp(name, "/dev/null") == 0)
 			/* $LESSHISTFILE == "-" means don't use a history file. */
 			return (NULL);
 		return (save(name));
 	}
 
 	/* Otherwise, file is in $HOME. */
-	home = lgetenv("HOME");
+	home = CANONICALIZE_PATH(lgetenv("HOME"));
 	if (home == NULL || *home == '\0')
 	{
 #if OS2
 		home = lgetenv("INIT");
 		if (home == NULL || *home == '\0')
@@ -1354,10 +1354,14 @@ histfile_name()
 			return (NULL);
 	}
 	len = strlen(home) + strlen(LESSHISTFILE) + 2;
 	name = (char *) ecalloc(len, sizeof(char));
 	SNPRINTF2(name, len, "%s/%s", home, LESSHISTFILE);
+#if defined(MSDOS_COMPILER) && MSDOS_COMPILER == DJGPPC
+	if (HAVE_LFN_SUPPORT(LESSHISTFILE) && !FILE_EXISTS(name))
+		SNPRINTF2(name, len, "%s/%s", home, "_lesshst");
+#endif
 	return (name);
 }
 #endif /* CMD_HISTORY */
 
 /*
diff -aprNU5 less-444.orig/decode.c less-444/decode.c
--- less-444.orig/decode.c	2011-04-11 22:04:22 +0000
+++ less-444/decode.c	2011-06-24 18:24:54 +0000
@@ -300,21 +300,60 @@ init_cmds()
 	/*
 	 * For backwards compatibility,
 	 * try to add tables in the OLD system lesskey file.
 	 */
 #ifdef BINDIR
+#if defined(MSDOS_COMPILER) && MSDOS_COMPILER == DJGPPC
+	if (HAVE_LFN_SUPPORT(".sysless"))
+	{
+	  char file_name[FILENAME_MAX];
+	  strcpy(file_name, BINDIR);
+	  strcat(file_name, "/.sysless");
+	  add_hometable(NULL, FILE_EXISTS(file_name) ? file_name : BINDIR "/_sysless", 1);
+	}
+	else
+	  add_hometable(NULL, BINDIR "/_sysless", 1);
+#else
 	add_hometable(NULL, BINDIR "/.sysless", 1);
 #endif
+#endif
 	/*
 	 * Try to add the tables in the system lesskey file.
 	 */
+#if defined(MSDOS_COMPILER) && MSDOS_COMPILER == DJGPPC
+	if (FILE_EXISTS(LESSKEYFILE_SYS))
+	  add_hometable("LESSKEY_SYSTEM", LESSKEYFILE_SYS, 1);
+	else
+	  add_hometable("LESSKEY_SYSTEM", "c:\\_sysless", 1);
+#else
 	add_hometable("LESSKEY_SYSTEM", LESSKEYFILE_SYS, 1);
+#endif
 	/*
 	 * Try to add the tables in the standard lesskey file "$HOME/.less".
 	 */
+#if defined(MSDOS_COMPILER) && MSDOS_COMPILER == DJGPPC
+	if (HAVE_LFN_SUPPORT(LESSKEYFILE))
+	{
+	  char file_name[FILENAME_MAX];
+	  char *home_path = getenv("HOME");
+	  if (home_path)
+	  {
+	    unsigned int i;
+	    for (i = 0; file_name[i] = home_path[i]; i++)
+	      ;
+	    if (i)
+	      file_name[++i] = '/';
+	  }
+	  strcat(file_name, LESSKEYFILE);
+	  add_hometable("LESSKEY", FILE_EXISTS(file_name) ? LESSKEYFILE : "_less", 0);
+	}
+	else
+	  add_hometable("LESSKEY", "_less", 0);
+#else
 	add_hometable("LESSKEY", LESSKEYFILE, 0);
 #endif
+#endif
 }
 
 /*
  * Add a command table.
  */
diff -aprNU5 less-444.orig/forwback.c less-444/forwback.c
--- less-444.orig/forwback.c	2011-04-11 22:04:22 +0000
+++ less-444/forwback.c	2011-06-24 03:17:54 +0000
@@ -144,10 +144,17 @@ forw(n, pos, force, only_last, nblank)
 	do_repaint = (only_last && n > sc_height-1) || 
 		(forw_scroll >= 0 && n > forw_scroll && n != sc_height-1);
 
 	if (!do_repaint)
 	{
+		/*
+		 * Forget any current line shift we might have (from
+		 * the last line of the previous screenful).
+		 */
+		extern int cshift;
+		cshift = 0;
+
 		if (top_scroll && n >= sc_height - 1 && pos != ch_length())
 		{
 			/*
 			 * Start a new screen.
 			 * {{ This is not really desirable if we happen
diff -aprNU5 less-444.orig/less.h less-444/less.h
--- less-444.orig/less.h	2011-04-11 22:09:46 +0000
+++ less-444/less.h	2011-06-24 03:17:54 +0000
@@ -500,5 +500,45 @@ struct textlist
 
 /* Functions not included in funcs.h */
 void postoa();
 void linenumtoa();
 void inttoa();
+
+#if defined(MSDOS_COMPILER) && MSDOS_COMPILER == DJGPPC
+# undef  IS_DIR_SEPARATOR
+# define IS_DIR_SEPARATOR(c)  ((c) == '/' || (c) == '\\' || (c) == ':')
+# include <libc/unconst.h>
+# define STRIP_FULL_PATH_AND_EXTENSION(file_name)    \
+  ({                                                 \
+      char *_dst, *_src;                             \
+      _dst = _src = unconst((file_name), char *);    \
+      while (*_src++)                                \
+        ;                                            \
+      while ((_src - _dst) && (*--_src != '.'))      \
+        ;                                            \
+      for (*_src = '\0'; (_src - _dst); _src--)      \
+        if (IS_DIR_SEPARATOR(*_src))                 \
+          break;                                     \
+      if (_src - _dst)                               \
+        while ((*_dst++ = *++_src))                  \
+          ;                                          \
+      (file_name);                                   \
+  })
+# define CANONICALIZE_PATH(path)                     \
+  ({                                                 \
+      if ((path))                                    \
+      {                                              \
+        char *_p = unconst((path), char *);          \
+        for (; *_p; _p++)                            \
+          if (*_p == '\\')                           \
+            *_p = '/';                               \
+      }                                              \
+      (path);                                        \
+  })
+# define HAVE_LFN_SUPPORT(name)   ((pathconf((name), _PC_NAME_MAX) > 12) ? TRUE : FALSE)
+# define DIR_EXISTS(path)         (access((path), D_OK) == 0)
+# define FILE_EXISTS(name)        (access((name), F_OK) == 0)
+#else
+# define HAVE_LFN_SUPPORT(name)                    (TRUE)
+# define STRIP_FULL_PATH_AND_EXTENSION(file_name)  (file_name)
+# define CANONICALIZE_PATH(path)                   (path)
+#endif
diff -aprNU5 less-444.orig/less.nro less-444/less.nro
--- less-444.orig/less.nro	2011-06-09 17:19:50 +0000
+++ less-444/less.nro	2011-06-24 18:24:54 +0000
@@ -1008,10 +1008,16 @@ Otherwise,
 .I less
 looks in a standard place for the lesskey file:
 On Unix systems,
 .I less
 looks for a lesskey file called "$HOME/.less".
+On DJGPP systems,
+.I less
+looks for a lesskey file called "$HOME/.less" if LFS support is available,
+and if it is not found there, then looks for a lesskey file called "$HOME/_less".
+If none of both are found there, then looks for a lesskey file called "_less"
+in any directory specified in the PATH environment variable.
 On MS-DOS and Windows systems,
 .I less
 looks for a lesskey file called "$HOME/_less", and if it is not found there,
 then looks for a lesskey file called "_less" in any directory specified
 in the PATH environment variable.
@@ -1039,10 +1045,12 @@ looks in a standard place for the system
 On Unix systems, the system-wide lesskey file is /usr/local/etc/sysless.
 (However, if 
 .I less 
 was built with a different sysconf directory than /usr/local/etc,
 that directory is where the sysless file is found.)
+On DJGPP systems, the system-wide lesskey file is /dev/env/DJDIR/etc/sysless.
+If it is not found there then c:\sysless is used as the system-wide lesskey file.
 On MS-DOS and Windows systems, the system-wide lesskey file is c:\e_sysless.
 On OS/2 systems, the system-wide lesskey file is c:\esysless.ini.
 
 .SH "INPUT PREPROCESSOR"
 You may define an "input preprocessor" for 
diff -aprNU5 less-444.orig/lesskey.c less-444/lesskey.c
--- less-444.orig/lesskey.c	2011-04-11 22:04:22 +0000
+++ less-444/lesskey.c	2011-06-25 15:03:12 +0000
@@ -329,11 +329,11 @@ parse_args(argc, argv)
 	 * Open the input file, or use DEF_LESSKEYINFILE if none specified.
 	 */
 	if (argc > 0)
 		infile = *argv;
 	else
-		infile = homefile(DEF_LESSKEYINFILE);
+		infile = homefile(HAVE_LFN_SUPPORT(DEF_LESSKEYINFILE) ? DEF_LESSKEYINFILE : "_lesskey");
 }
 
 /*
  * Initialize data structures.
  */
@@ -836,11 +836,11 @@ main(argc, argv)
 	}
 
 	if (outfile == NULL)
 		outfile = getenv("LESSKEY");
 	if (outfile == NULL)
-		outfile = homefile(LESSKEYFILE);
+		outfile = homefile(HAVE_LFN_SUPPORT(LESSKEYFILE) ? LESSKEYFILE : "_less");
 	if ((out = fopen(outfile, "wb")) == NULL)
 	{
 #if HAVE_PERROR
 		perror(outfile);
 #else
diff -aprNU5 less-444.orig/lesskey.nro less-444/lesskey.nro
--- less-444.orig/lesskey.nro	2011-06-09 17:19:50 +0000
+++ less-444/lesskey.nro	2011-06-25 15:11:06 +0000
@@ -16,10 +16,12 @@ is used to specify a set of key bindings
 The input file is a text file which describes the key bindings.
 If the input file is "-", standard input is read.
 If no input file is specified, a standard filename is used
 as the name of the input file, which depends on the system being used:
 On Unix systems, $HOME/.lesskey is used;
+on DJGPP systems, $HOME/.lesskey is used
+and if this fails $HOME/_lesskey is used;
 on MS-DOS systems, $HOME/_lesskey is used;
 and on OS/2 systems $HOME/lesskey.ini is used,
 or $INIT/lesskey.ini if $HOME is undefined.
 The output file is a binary file which is used by 
 .I less.
@@ -27,10 +29,12 @@ If no output file is specified,
 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 and OS-9 systems, $HOME/.less is used;
+on DJGPP systems, $HOME/.less is used
+and if this fails $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.
 If the output file already exists,
 .I lesskey
diff -aprNU5 less-444.orig/line.c less-444/line.c
--- less-444.orig/line.c	2011-04-11 22:04:22 +0000
+++ less-444/line.c	2011-06-24 03:17:54 +0000
@@ -20,11 +20,15 @@
 
 static char *linebuf = NULL;	/* Buffer which holds the current output line */
 static char *attr = NULL;	/* Extension of linebuf to hold attributes */
 public int size_linebuf = 0;	/* Size of line buffer (and attr buffer) */
 
+#if defined(MSDOS_COMPILER) && MSDOS_COMPILER == DJGPPC
+public int cshift;		/* Current left-shift of output line buffer */
+#else
 static int cshift;		/* Current left-shift of output line buffer */
+#endif
 public int hshift;		/* Desired left-shift of output line buffer */
 public int tabstops[TABSTOP_MAX] = { 0 }; /* Custom tabstops */
 public int ntabstops = 1;	/* Number of tabstops */
 public int tabdefault = 8;	/* Default repeated tabstops */
 
@@ -149,11 +153,10 @@ is_ascii_char(ch)
 	public void
 prewind()
 {
 	curr = 0;
 	column = 0;
-	cshift = 0;
 	overstrike = 0;
 	last_overstrike = AT_NORMAL;
 	mbc_buf_len = 0;
 	is_null_line = 0;
 	pendc = '\0';
@@ -1060,10 +1063,15 @@ pdone(endline, forw)
 		linebuf[curr] = '\b'; 
 		attr[curr++] = AT_NORMAL;
 	}
 	linebuf[curr] = '\0';
 	attr[curr] = AT_NORMAL;
+	/*
+	 * If we are done with this line, reset the current shift.
+	 */
+	if (endline)
+		cshift = 0;
 }
 
 /*
  *
  */
diff -aprNU5 less-444.orig/main.c less-444/main.c
--- less-444.orig/main.c	2011-04-11 22:04:22 +0000
+++ less-444/main.c	2011-06-24 21:35:36 +0000
@@ -76,10 +76,11 @@ main(argc, argv)
 	_response(&argc, &argv);
 	_wildcard(&argc, &argv);
 #endif
 
 	progname = *argv++;
+	progname = STRIP_FULL_PATH_AND_EXTENSION(progname);
 	argc--;
 
 	secure = 0;
 	s = lgetenv("LESSSECURE");
 	if (s != NULL && *s != '\0')
@@ -170,12 +171,16 @@ main(argc, argv)
 		if (editor == NULL || *editor == '\0')
 			editor = EDIT_PGM;
 	}
 	editproto = lgetenv("LESSEDIT");
 	if (editproto == NULL || *editproto == '\0')
+#if (MSDOS_COMPILER && MSDOS_COMPILER == DJGPPC)
+		editproto = (stricmp(editor, "edit") == 0) ? "%E %f" : "%E ?lm+%lm. %f";
+#else
 		editproto = "%E ?lm+%lm. %f";
 #endif
+#endif
 
 	/*
 	 * Call get_ifile with all the command line filenames
 	 * to "register" them with the ifile system.
 	 */
@@ -207,11 +212,11 @@ main(argc, argv)
 #else
 		filename = shell_quote(*argv);
 		if (filename == NULL)
 			filename = *argv;
 		argv++;
-		(void) get_ifile(filename, ifile);
+		(void) get_ifile(CANONICALIZE_PATH(filename), ifile);
 		ifile = prev_ifile(NULL_IFILE);
 #endif
 	}
 	/*
 	 * Set up terminal, etc.
diff -aprNU5 less-444.orig/screen.c less-444/screen.c
--- less-444.orig/screen.c	2011-04-11 22:04:22 +0000
+++ less-444/screen.c	2011-06-24 03:17:54 +0000
@@ -102,14 +102,33 @@ static int flash_created = 0;
 #if MSDOS_COMPILER==BORLANDC
 static unsigned short *whitescreen;
 static int flash_created = 0;
 #endif
 #if MSDOS_COMPILER==BORLANDC || MSDOS_COMPILER==DJGPPC
+extern int top_scroll;
+	static void
+clreol_maybe()
+{
+	/* Clear to EOL, but only if in the last display line.  This
+	   is a kludgey way to work around display problems when color
+	   is switched at the rightmost column of the last display
+	   line.  The problem is that when the display is scrolled,
+	   the empty line added from below inherits the colors of the
+	   last character on the previous line.  */
+	if (top_scroll != OPT_ON) {
+		int x, y;
+		extern int sc_height;
+		ScreenGetCursor(&x, &y);
+		if (x == sc_height - 1)
+			clreol();
+	}
+}
 #define _settextposition(y,x)   gotoxy(x,y)
 #define _clearscreen(m)         clrscr()
 #define _outtext(s)             cputs(s)
-#define	SETCOLORS(fg,bg)	{ textcolor(fg); textbackground(bg); }
+#define	SETCOLORS(fg,bg)	{ textcolor(fg); textbackground(bg); \
+				  if (bg == nm_bg_color) clreol_maybe(); }
 extern int sc_height;
 #endif
 
 #if MSDOS_COMPILER==WIN32C
 struct keyRecord
