To: [email protected]
Subject: patch 5.5a.7
Fcc: outbox
From: Bram Moolenaar <[email protected]>
------------

Patch 5.5a.7
Problem:    When using "cat | vim -" in an xterm, the xterm version reply
           would end up in the file.
Solution:   Read the file from stdin before switching the terminal to RAW
           mode.  Should also avoid problems with programs that use a
           specific terminal setting.
           Also: when using the GUI, print "Reading from stdin..." in the GUI
           window, to give a hint why it doesn't do anything.
Files:      src/main.c, src/fileio.c


*** ../vim-5.5a.6/src/main.c    Mon Aug 30 10:40:49 1999
--- src/main.c  Wed Sep  1 20:41:17 1999
***************
*** 915,922 ****
      * Don't call msg_start() if the GUI is expected to start, it switches the
      * cursor off.  Only need to avoid it when want_full_screen could not have
      * been reset above.
      */
!     if (full_screen
 #if defined(USE_GUI) && !defined(ALWAYS_USE_GUI) && !defined(USE_GUI_X11)
           && !gui.starting
 #endif
--- 915,924 ----
      * Don't call msg_start() if the GUI is expected to start, it switches the
      * cursor off.  Only need to avoid it when want_full_screen could not have
      * been reset above.
+      * Also don't do it when reading from stdin (the program writing to the
+      * pipe might use the cursor).
      */
!     if (full_screen && edit_type != EDIT_STDIN
 #if defined(USE_GUI) && !defined(ALWAYS_USE_GUI) && !defined(USE_GUI_X11)
           && !gui.starting
 #endif
***************
*** 1158,1163 ****
--- 1160,1198 ----
 #endif

     /*
+      * If "-" argument given: Read file from stdin.
+      * Do this before starting Raw mode, because it may change things that the
+      * writing end of the pipe doesn't like, e.g., in case stdin and stderr
+      * are the same terminal: "cat | vim -".
+      * Using autocommands here may cause trouble...
+      */
+     if (edit_type == EDIT_STDIN && !recoverymode)
+     {
+ #if defined(GUI_DIALOG) || defined(CON_DIALOG)
+       /* When getting the ATTENTION prompt here, use a dialog */
+       swap_exists_action = SEA_DIALOG;
+ #endif
+       no_wait_return = TRUE;
+       i = msg_didany;
+       (void)open_buffer(TRUE);        /* create memfile and read file */
+       no_wait_return = FALSE;
+       msg_didany = i;
+ #if defined(GUI_DIALOG) || defined(CON_DIALOG)
+       check_swap_exists_action();
+       swap_exists_action = SEA_NONE;
+ #endif
+ #if !(defined(AMIGA) || defined(macintosh))
+       /*
+        * Close stdin and dup it from stderr.  Required for GPM to work
+        * properly, and for running external commands.
+        * Is there any other system that cannot do this?
+        */
+       close(0);
+       dup(2);
+ #endif
+     }
+
+     /*
      * When done something that is not allowed or error message call
      * wait_return.  This must be done before starttermcap(), because it may
      * switch to another screen. It must be done after settmode(TMODE_RAW),
***************
*** 1229,1266 ****
       /* When getting the ATTENTION prompt here, use a dialog */
       swap_exists_action = SEA_DIALOG;
 #endif
-       /*
-        * If "-" argument given: read file from stdin.
-        * Need to stop Raw mode for terminal in case stdin and stderr are the
-        * same terminal: "cat | vim -".  Not needed for GUI-only versions.
-        */
-       if (edit_type == EDIT_STDIN)
-       {
- #ifndef ALWAYS_USE_GUI
-           stoptermcap();
-           settmode(TMODE_COOK);       /* set to normal mode */
- #endif
-           (void)open_buffer(TRUE);    /* create memfile and read file */
- #if defined(GUI_DIALOG) || defined(CON_DIALOG)
-           check_swap_exists_action();
- #endif
- #ifndef ALWAYS_USE_GUI
-           if (!termcap_active)        /* if readfile() didn't do it already */
-           {
-               settmode(TMODE_RAW);    /* set to raw mode */
-               starttermcap();
-           }
- #endif
- #if !(defined(AMIGA) || defined(macintosh))
-           /*
-            * Close stdin and dup it from stderr.  Required for GPM to work
-            * properly, and for running external commands.
-            * Is there any other system that cannot do this?
-            */
-           close(0);
-           dup(2);
- #endif
-       }

       /*
        * Open a buffer for windows that don't have one yet.
--- 1264,1269 ----
*** ../vim-5.5a.6/src/fileio.c  Mon Aug 30 10:40:51 1999
--- src/fileio.c        Wed Sep  1 20:48:50 1999
***************
*** 457,463 ****
       if (read_stdin)
       {
           mch_msg("Vim: Reading from stdin...\n");
!           cursor_on();    /* just in case */
       }
       else
 #endif
--- 457,467 ----
       if (read_stdin)
       {
           mch_msg("Vim: Reading from stdin...\n");
! # ifdef USE_GUI
!           /* Also write a message in the GUI window, if there is one. */
!           if (gui.in_use)
!               gui_write("Reading from stdin...", 21);
! # endif
       }
       else
 #endif
***************
*** 928,934 ****
           if (msg_add_fileformat(fileformat))
               c = TRUE;
           msg_add_lines(c, (long)linecnt, filesize);
!           msg_trunc_attr(IObuff, FALSE, 0);
       }

       if (error && newfile)   /* with errors we should not write the file */
--- 932,943 ----
           if (msg_add_fileformat(fileformat))
               c = TRUE;
           msg_add_lines(c, (long)linecnt, filesize);
!           /* When reading from stdin, the screen will be cleared next; keep
!            * the message to repeat it later. */
!           keep_msg = msg_trunc_attr(IObuff, FALSE, 0);
!           keep_msg_attr = 0;
!           if (!read_stdin)
!               keep_msg = NULL;
       }

       if (error && newfile)   /* with errors we should not write the file */
*** ../vim-5.5a.6/src/version.c Wed Sep  1 20:50:39 1999
--- src/version.c       Wed Sep  1 20:50:01 1999
***************
*** 420,420 ****
--- 420,421 ----
 {   /* Add new patch number below this line */
+     7,

--
DENNIS:  Listen -- strange women lying in ponds distributing swords is no
        basis for a system of government.  Supreme executive power derives
        from a mandate from the masses, not from some farcical aquatic
        ceremony.
                                 The Quest for the Holy Grail (Monty Python)

--/-/---- Bram Moolenaar ---- [email protected] ---- [email protected] ---\-\--
 \ \    www.vim.org/iccf      www.moolenaar.net       www.vim.org    / /