Subject: Re: ncurses/termcap, just won't clear the screen?
From: [email-masked] ("Mikey")

21 May 1997 08:23:08 -0700
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: multipart/mixed;
	boundary="----=_NextPart_000_01BC6452.A7FB6E60"
X-Mailer: Microsoft Outlook Express 4.71.0544.0
Original-To: <[email-masked]>
Original-Cc: "cygnus gnu-win32 mailing list" <[email-masked]>
X-Priority: 3
X-MSMail-Priority: Normal
X-MimeOLE: Produced By Microsoft MimeOLE Engine V4.71.0544.0
Original-Sender: [email-masked]

This is a multi-part message in MIME format.

------=_NextPart_000_01BC6452.A7FB6E60
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

Yeah, here it is. but use ansi, or w32ansi for less elvis info etc, the linux termcap/info is (at least on my system) broken for
full screen access.

It keeps putting ^M at the end of every wrapped screen line so an extra empty line is inserted, and the cursor shows up on the
wrong line, and I can't figure out where it is coming from.

In fact if you could confirm for me that it's working the same way for you I would appreciate it ;^)

This will also allow texinfo, and the info reader to compile and work with the above TERM's, it does break using "|lesspipe.sh"
though, don't yet know why.

If you havn't downloaded cdk.tgz yet mail me and I'll send you a copy of the dll, it's 320k, so I don't want to include it for the
list.

The ATT6whatever below is actually stripdll in outlook express disguise, it automates stripping dll's, I thought you might find it
usefull ;^)

([email-masked])
       the return address for this message is anti spammed
       remove * from the above address to reply.
       Mikey>> You must have missed my post the other day, \E[J & \E0[J are broken.
>> clear.exe uses this to clear the screen.
>>
>ah, ok.  That makes things kinda difficult.  If you build any
>programs, they won't be clearing the screen...  Do you happen to know
>if anyone is working on a fix for this?
>
>Thanks
>

------=_NextPart_000_01BC6452.A7FB6E60
Content-Type: application/octet-stream;
	name="current.dif"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="current.dif"

--- Makefile.in	1997/05/12 23:37:39	18.0
+++ Makefile.in	1997/05/12 20:06:55
@@ -38,6 +38,7 @@
 INSTALL = @INSTALL@
 INSTALL_DATA = @INSTALL_DATA@
 INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_DIRS = @INSTALL@ -d
 
 CC = @CC@
 # FIXME: Which is it, CC or CC_FOR_TARGET?
@@ -74,7 +75,8 @@
 	AR="$(AR)" \
 	RANLIB="$(RANLIB)" \
 	LD="$(LD)" \
-	DLLTOOL="$(DLLTOOL)"
+	DLLTOOL="$(DLLTOOL)" \
+	prefix="$(prefix)"

 # This is the final name of the cygwin.dll.
@@ -152,10 +154,12 @@
 readme.info:$(srcdir)/doc/readme.texinfo
 	$(MAKEINFO) -I$(srcdir)/doc  $<
 
-install: $(THEIRLIBS) $(LIBNAME) new-$(DLLNAME) real-headers
+install-theirlibs: $(THEIRLIBS) $(LIBNAME)
 	for i in $(THEIRLIBS) $(LIBNAME); do \
 		$(INSTALL_DATA) $$i $(tooldir)/lib/$$i ; \
 	done
+
+install-dll: new-$(DLLNAME)
 	for i in $(DLLNAME); do \
 	  $(INSTALL_DATA) new-$$i $(tooldir)/lib/$$i ; \
 	  binname=`t='$(program_transform_name)'; echo "$$i" | sed -e $$t` ; \
@@ -163,16 +167,23 @@
 	  rm -f $(bindir)/$$binname ; \
 	  ln $(tooldir)/lib/$$i $(bindir)/$$binname >/dev/null 2>&1 || $(INSTALL_DATA) new-$$i $(bindir)/$$binname ; \
 	done
+	for i in $(DLLNAME);do stripdll $(bindir)/$$i;done
+
+install-real-headers: real-headers
 	for sub in include include/arpa include/asm include/Windows32 \
 	   include/cygwin32 include/net include/netinet include/sys ; do \
+		$(INSTALL_DIRS) $(tooldir)/$$sub; \
 		for i in $(srcdir)/$$sub/*.h ; do \
 		  $(INSTALL_DATA) $$i $(tooldir)/$$sub/`basename $$i` ; \
 		done ; \
 	done
+
+install-utils:
 	rootme=`pwd` ; export rootme ; \
 	rootsrc=`(cd $(srcdir) ; pwd)` ; export rootsrc ; \
 	cd utils; $(MAKE) install $(FLAGS_TO_PASS)
 
+install: install-theirlibs install-dll install-real-headers install-utils
 	# this will only work if you've maked stmp_ms_include below.
 	#	if [ -e ms_include/windows.h ] ; then  \
 	#		for i in ms_include/*.h ; do \
@@ -293,6 +304,13 @@
 
 clean:
 	-rm -f *.o *.dll *.a *.exp junk *.base
+	$(MAKE) -C glob $@
+	$(MAKE) -C utils $@
+
+distclean: clean
+	-rm -f Makefile config.status config.cache config.log cygwin.def
+	$(MAKE) -C glob $@
+	$(MAKE) -C utils $@
 
 maintainer-clean realclean: clean 
 	@echo "This command is intended for maintainers to use;"
@@ -321,7 +339,7 @@
 # which contains the headers (My linux machine is dual boot, and C: is under
 # /dosc, so this works for me)
 
-SDK_H=/dosc/mstools/h
+SDK_H=/dos/m/msdn/include
 
 real-headers: # $(srcdir)/mspatches/*.patch
 	if [ -f $(SDK_H)/windows.h ] ; then 	\
--- console.cc	1997/05/12 23:37:39	18.0
+++ console.cc	1997/05/13 21:19:09
@@ -452,10 +452,10 @@
 }
 
 void
-fhandler_console::clear_screen ()
+fhandler_console::clear_screen (int x, int y)
 {
   CONSOLE_SCREEN_BUFFER_INFO info;
-  COORD tlc = {0,0};
+  COORD tlc = {x,y};
   DWORD done;
   GetConsoleScreenBufferInfo (get_output_handle (), &info);
   FillConsoleOutputCharacterA (get_output_handle (), ' ',
@@ -530,9 +530,15 @@
   *x = info.dwCursorPosition.X;
 }
 
+void
+fhandler_console::switchCP(int CP)
+{ /* FIXME code to actually switch goes here */
+}
+
 #define BAK 1
 #define ESC 2
 #define NOR 0
+#define EOT 3 /* delete forward <delete> */
 #define IGN 4
 #define ERR 5
 #define DWN 6
@@ -543,7 +549,7 @@
 
 static const char base_chars[256] =
 {
-/*00 01 02 03 04 05 06 07 */ IGN, ERR, ERR, NOR, NOR, NOR, NOR, BEL, 
+/*00 01 02 03 04 05 06 07 */ IGN, ERR, ERR, NOR, EOT, NOR, NOR, BEL, 
 /*08 09 0A 0B 0C 0D 0E 0F */ BAK, TAB, DWN, ERR, ERR, CR,  ERR, IGN,
 /*10 11 12 13 14 15 16 17 */ NOR, NOR, ERR, ERR, ERR, ERR, ERR, ERR, 
 /*18 19 1A 1B 1C 1D 1E 1F */ NOR, NOR, ERR, ESC, ERR, ERR, ERR, ERR, 
@@ -585,6 +591,7 @@
 {
   static int fg=7,bg=0,bold=0;
   int x, y;
+  DWORD done;
   char buf[40];
 
   switch (c)
@@ -620,6 +627,9 @@
                bg=BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED;
                bold=0;
                break;
+	     case 8:    /* invis */
+	       bg=0;
+	       bold=0;
              case 30:        /* BLACK foreground */
                fg = 0;
                break;
@@ -685,12 +695,19 @@
 	{
 	case 0:				/* Clear to end of screen */
 	  cursor_get(&x, &y);
-	  scroll_screen(get_output_handle(), 0, y, -1, -1, -1, -1);
-	  scroll_screen(get_output_handle(), -1, -1, -1, -1, 0, y);
-	  clear_to_eol();
+	  clear_screen(x,y);
+	  break;
+        case 1: /* erase from start to cursor */
+          cursor_get(&savex, &savey);
+          scroll_screen (get_output_handle (), x, y, -1, y, 0, y);
+          scroll_screen (get_output_handle (), 0, y, -1, y, x, y);
+          for (y = 0;y < savey;y++) {
+            cursor_set(0, y);
+            clear_to_eol (); }
+          cursor_set(savex, savey); 
 	  break;
 	case 2:				/* Clear screen */
-	  clear_screen ();
+	  clear_screen (0,0);
 	  cursor_set (0,0);
 	  break;
 	default:
@@ -815,8 +832,7 @@
       break;
     default:
 bad_escape:
-      small_printf("Bad escape %d, %d %d (%c)\n", args_[0], args_[1], c,c);
-      sleep (1);
+      small_printf("Bad escape %d, %d %d (%c). Please check TERM environment variable.\n", args_[0], args_[1], c,c);
       break;
     }
 }
@@ -854,12 +870,19 @@
 	  break;
 	case ESC:
 	  state_ = gotesc;
+          debug_printf("\nESCAPE is %s\n", src);
 	  break;
 	case DWN:		/* WriteFile("\n") always adds CR... */
 	  cursor_get(&x, &y);
-	  WriteFile (get_output_handle (), "\n", 1, &done, 0);
-	  if (get_w_binary ())
-	    cursor_rel (x, 0);
+	  if (get_w_binary ()) /* this must come first. */
+	    cursor_rel (0, 1);
+	  else
+	    WriteFile (get_output_handle (), "\r\n", 2, &done, 0);
+	  break;
+	case EOT: /* delete forward */
+          cursor_get(&x, &y);
+          scroll_screen(get_output_handle(), x+1, y, -1, y, x, y);
+          scroll_screen(get_output_handle(), x, y, -1, y, x+1, y);
 	  break;
 	case BAK:
 	  cursor_rel (-1, 0);
@@ -875,7 +898,8 @@
           cursor_set(8*(x/8+1), y);
           break;
 	case ERR:
-	  small_printf ("Got %d\n", *src);
+         if (!is_tty())
+           WriteFile (get_output_handle (), src, 1, &done, 0);
 	  break;
 	}
       src ++;
@@ -917,7 +941,7 @@
 	    }
 	  else if (*src == 'c')		/* Reset Linux terminal */
 	    {
-	      clear_screen();
+	      clear_screen(0,0);
 	      cursor_set(0, 0);
 	      state_ = normal;
 	    }
@@ -937,9 +961,34 @@
 	      state_ = normal;
 	  else
 	    {
-	      small_printf ("Bad escape %d (%c)\n", *src,*src);
-	      sleep (1);
 	      state_ = normal;
+              int CP = 4;
+              switch (*src)
+                {
+                  case '(': CP = 0; /* ASCII */
+                            break;
+                  case ')': CP = 1;
+                            break;
+                  case '*': CP = 2;
+                            break;
+                  case '+': CP = 3;
+                            break;
+                  default:
+                            break;
+                }
+              if (CP != 4) 
+		{ 
+		  src++; 
+	          if (*src != 'B') 
+	            { 
+	              src--;
+	              small_printf ("Bad escape %d (%c) Please check TERM environment variable\n", *src, *src);
+	            } 
+	          else 
+	            { 
+	               switchCP(CP); 
+		    } 
+	         }
 	    }
 	  src++;
 	  break;
@@ -1024,18 +1073,19 @@
 
   /* if things are special, just do what we used to */
   if ((!res) || (ov != 0))
-    {
       return ReadFile (hndl, pv, lenin, done, ov);
-    }
   if (flags & ENABLE_LINE_INPUT)
     {
-      FlushConsoleInputBuffer (hndl);
+	  FlushConsoleInputBuffer(hndl);
       return ReadFile (hndl, pv, lenin, done, ov);
     }
 
   /* otherwise, do something that works */
   unsigned int num_events = 0, ne2, st;
 
+  if(ndelay_set == 1)
+      need_chars=0;
+
   st = GetNumberOfConsoleInputEvents (hndl, &num_events);
 
   debug_printf ("FakeReadFile, GetNumberOfConsoleInputEvents returned = %d\n", st);
@@ -1054,6 +1104,15 @@
       need_chars = 1;
     } 
 
+    if(ndelay_set == 1)
+       {
+       need_chars = 0;
+       }
+      else
+       {
+       need_chars = 1;
+       }
+
   INPUT_RECORD input_rec;
   
   buf = (char*)pv;
@@ -1172,7 +1231,19 @@
       need_chars = 0;    
     }
   *done = copied_chars;
-  return 1;			/* success == true */
+
+  /* if we haven't got anything of interest, and we don't want to wait for
+       anything (O_NDELAY is set) force the calling read to error (ret 0) */
+
+  if (copied_chars == 0 && need_chars == 0)
+    {
+      return 0;
+    }
+  else
+    {
+      return 1;
+    }                  /* success == true */
+
 }
 
 int
--- fcntl.cc	1997/05/12 23:37:39	18.0
+++ fcntl.cc	1997/05/12 06:49:25
@@ -20,6 +20,8 @@
 #include <stdarg.h>
 #include "winsup.h"
 
+int ndelay_set;
+
 extern "C"
 int
 _fcntl (int fd, int cmd,...)
@@ -88,6 +90,10 @@
  	res |= O_WRONLY;
        if (this_procinfo ()->hmap[fd].h->get_access () & GENERIC_ALL)
  	res |= O_RDWR;
+       if (ndelay_set)
+	  res |= O_NDELAY;
+	syscall_printf ("fcntl (F_GETFL, %d);\n", res);  
+
        goto done;
 
     case F_SETFL:
@@ -101,6 +107,14 @@
  	  temp |= GENERIC_READ;
  	if (arg & O_WRONLY)
  	  temp |= GENERIC_WRITE;
+	if (arg & O_NDELAY)
+	  {
+	    ndelay_set = 1;
+	  }
+	else  
+	  {
+	    ndelay_set = 0;
+	  }
 
 	syscall_printf ("fcntl (%d, F_SETFL, %d);\n", arg);  
 
--- fhandler.h	1997/05/12 23:37:39	18.0
+++ fhandler.h	1997/05/12 11:14:55
@@ -21,6 +21,8 @@
 
 #include <sys/types.h>
 
+extern int ndelay_set; /* for fcntl O_NDELAY in FakeReadFile */
+
 /* Classes
 
    fhandler_base		normal I/O
@@ -237,7 +239,7 @@
 
 /* Output calls */
 
-  void clear_screen ();
+  void clear_screen (int x, int y);
   void cursor_set (int x, int y);
   void cursor_get (int *x, int *y);
   void clear_to_eol ();
@@ -246,6 +248,7 @@
   const unsigned char * write_normal (unsigned const char*, unsigned const char *);
   void char_command (char);
   int output_tcsetattr (int a, const struct termios *t);
+  void switchCP (int CP);
 
 /* Input state */
   /* Bits are..
--- signal.cc	1997/05/13 21:11:43	1.1
+++ signal.cc	1997/05/13 21:13:59
@@ -54,8 +54,8 @@
 sleep (unsigned int seconds)
 {
   syscall_printf ("sleep (%d);\n", seconds);
-  Sleep (seconds * 1000);
-  syscall_printf ("0 = sleep (%d);\n", seconds);
+  WaitForSingleObject (u->signal_arrived, seconds * 1000);
+  syscall_printf ("0 = sleep (%d)\n", seconds);
   return 0;
 }
 
@@ -64,7 +64,7 @@
 usleep (unsigned int useconds)
 {
   syscall_printf ("usleep (%d)\n", useconds);
-  Sleep ((useconds + 500) / 1000);
+  WaitForSingleObject (u->signal_arrived, (useconds + 500) / 1000);
   syscall_printf ("0 = usleep (%d)\n", useconds);
   return 0;
 }
--- termcap	1997/05/12 20:02:05	1.1
+++ utils/termcap	1997/05/13 11:23:03
@@ -69,13 +69,13 @@
 	:..sa=\E[0;10%?%p1%t;7%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;%?%p6%t;1%;%?%p7%t;8%;%?%p8%t;11%;%?%p9%t;12%;m:\
 	:se=\E[m:sf=^J:so=\E[7m:st=\EH:ta=^I:ue=\E[m:up=\E[A:\
 	:us=\E[4m:
-pcansi-mono25|ansi25|ibm-pc terminal programs with 25 lines (mono mode):\
+pcansi-mono25|ansi25-m|ibm-pc terminal programs with 25 lines (mono mode):\
 	:li#25:\
 	:tc=pcansi-mono:
-pcansi-mono33|ansi33|ibm-pc terminal programs with 33 lines (mono mode):\
+pcansi-mono33|ansi33-m|ibm-pc terminal programs with 33 lines (mono mode):\
 	:li#33:\
 	:tc=pcansi-mono:
-pcansi-mono43|ansi43|ibm-pc terminal programs with 43 lines (mono mode):\
+pcansi-mono43|ansi43-m|ibm-pc terminal programs with 43 lines (mono mode):\
 	:li#43:\
 	:tc=pcansi-mono:
 # The color versions.  All PC emulators do color...
@@ -116,6 +116,12 @@
 ansi|ansi/pc-term compatible with color:\
 	:u6=\E[%d;%dR:u7=\E[6n:..u8=\E[?%[;0123456789]c:\
 	:u9=\E[c:tc=ansi-pc-color:tc=ansi-mono:
+
+w32ansi|ansi console window w/function keys under cygwin32:\
+	:li=#50:k1=\E[[A:k2=\E[[B:k3=\E[[C:k4=\E[[D:\
+	:k5=\E[[E:k6=\E[17~:k7=\E[18~:k8=\E[19~:k9=\E[20~:k;=\E[21~:kI=\E[2~:\
+	:kh=\E[1~:kD=\E[3~:@7=\E[4~:kP=\E[5~:kN=\E[6~:\
+	:K1=\E[1~:K3=\E[5~:K4=\E[4~:K5=\E[6~:st@:ct@:tc=ansi:
 
 #
 # ANSI.SYS entries

------=_NextPart_000_01BC6452.A7FB6E60
Content-Type: application/octet-stream
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment

#!/bin/sh=0A=
#set -xv #debuging=0A=
# this assumes .text .bss .data .edata .idata .stab .stabstr .reloc .rsrc=0A=
# order for sections, which has been true for all the ones I've seen=0A=
# and according to Mr. Noer this will be needed until B18+ comes out=0A=
SECTION=3D.reloc=0A=
if [ x"$1" =3D x"" -o x"$2" !=3D x"" ];then=0A=
  echo usage $0 dllname.dll 1>&2 # errors to stderr=0A=
  exit 1;=0A=
elif ! { DUMP=3D`objdump --headers $1` && echo $DUMP |grep pei-i386 =
&>/dev/null ;};then=0A=
  echo $0: not an object file 1>&2=0A=
  exit 1; # not an exe dll .a or .o file =0A=
elif ! echo $DUMP|grep "5 ." &>/dev/null ;then=0A=
  exit 0; # already striped static=0A=
elif echo $DUMP|grep "5 .reloc " &>/dev/null ;then=0A=
  exit 0; # already striped .reloc=0A=
elif echo $DUMP|grep ".rsrc" &>/dev/null ;then=0A=
  if echo $DUMP|grep "7 .reloc " &>/dev/null ;then=0A=
    echo $0: Please adjust .rsrc VMA by hand map is in `dirname =
$1`/stripmap.$$ 1>&2=0A=
    objdump --headers $1 &>  `dirname $1`/stripmap.$$=0A=
  else=0A=
    SECTION=3D.rsrc=0A=
  fi=0A=
fi=0A=
if ! echo $DUMP|grep "7 .reloc " &>/dev/null ;then=0A=
  if echo $DUMP|grep "5 .stab " &>/dev/null ;then=0A=
    strip $1 # static .dll=0A=
    exit 0;=0A=
  else=0A=
    echo $0: unknown Error 1>&2=0A=
    exit 1; # no clue=0A=
  fi=0A=
else=0A=
  NEWVMA=3D`objdump --headers $1|grep "5 .stab "|gawk --traditional =
'{print $4}'`=0A=
  if [ x"$NEWVMA" !=3D x"" ];then=0A=
    objcopy -S --adjust-section-vma $SECTION=3D0x$NEWVMA $1;=0A=
    exit 0;=0A=
  else=0A=
    echo $0: unknown Error 1>&2=0A=
    exit 1; # no clue=0A=
  fi=0A=
fi=0A=
[ -f `dirname $1`/stripmap.$$ ] && cat stripmap.$$ && --objdump =
--headers $1 && echo objcopy -S --adjust-section-vma .rsrc=3D0xNEWVMA $1=0A=

------=_NextPart_000_01BC6452.A7FB6E60--

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".