[BACK]Return to ttyin.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / less

Diff for /src/usr.bin/less/ttyin.c between version 1.2 and 1.3

version 1.2, 2001/01/29 01:58:04 version 1.3, 2003/04/13 18:26:26
Line 1 
Line 1 
 /*      $OpenBSD$       */  
   
 /*  /*
  * Copyright (c) 1984,1985,1989,1994,1995  Mark Nudelman   * Copyright (C) 1984-2002  Mark Nudelman
  * All rights reserved.  
  *   *
  * Redistribution and use in source and binary forms, with or without   * You may distribute under the terms of either the GNU General Public
  * modification, are permitted provided that the following conditions   * License or the Less License, as specified in the README file.
  * are met:  
  * 1. Redistributions of source code must retain the above copyright  
  *    notice, this list of conditions and the following disclaimer.  
  * 2. Redistributions in binary form must reproduce the above copyright  
  *    notice in the documentation and/or other materials provided with  
  *    the distribution.  
  *   *
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY   * For more information about less, or for information on how to
  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE   * contact the author, see the README file.
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR  
  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE  
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR  
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  
  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR  
  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,  
  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE  
  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN  
  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
  */   */
   
   
Line 32 
Line 14 
  */   */
   
 #include "less.h"  #include "less.h"
   #if OS2
   #include "cmd.h"
   #include "pckeys.h"
   #endif
   #if MSDOS_COMPILER==WIN32C
   #include "windows.h"
   extern char WIN32getch();
   static DWORD console_mode;
   #endif
   
 static int tty;  public int tty;
   extern int sigs;
   
 /*  /*
  * Open keyboard for input.   * Open keyboard for input.
Line 41 
Line 33 
         public void          public void
 open_getchr()  open_getchr()
 {  {
 #if MSOFTC || OS2  #if MSDOS_COMPILER==WIN32C
           /* Need this to let child processes inherit our console handle */
           SECURITY_ATTRIBUTES sa;
           memset(&sa, 0, sizeof(SECURITY_ATTRIBUTES));
           sa.nLength = sizeof(SECURITY_ATTRIBUTES);
           sa.bInheritHandle = TRUE;
           tty = (int) CreateFile("CONIN$", GENERIC_READ,
                           FILE_SHARE_READ, &sa,
                           OPEN_EXISTING, 0L, NULL);
           GetConsoleMode((HANDLE)tty, &console_mode);
           /* Make sure we get Ctrl+C events. */
           SetConsoleMode((HANDLE)tty, ENABLE_PROCESSED_INPUT);
   #else
   #if MSDOS_COMPILER
         extern int fd0;          extern int fd0;
         /*          /*
          * Open a new handle to CON: in binary mode           * Open a new handle to CON: in binary mode
Line 49 
Line 54 
          */           */
          fd0 = dup(0);           fd0 = dup(0);
          close(0);           close(0);
          tty = OPEN_TTYIN();           tty = open("CON", OPEN_READ);
   #if MSDOS_COMPILER==DJGPPC
           /*
            * Setting stdin to binary causes Ctrl-C to not
            * raise SIGINT.  We must undo that side-effect.
            */
           (void) __djgpp_set_ctrl_c(1);
   #endif
 #else  #else
         /*          /*
          * Try /dev/tty.           * Try /dev/tty.
Line 57 
Line 69 
          * which in Unix is usually attached to the screen,           * which in Unix is usually attached to the screen,
          * but also usually lets you read from the keyboard.           * but also usually lets you read from the keyboard.
          */           */
         tty = OPEN_TTYIN();  #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)          if (tty < 0)
                 tty = 2;                  tty = 2;
 #endif  #endif
   #endif
 }  }
   
 /*  /*
    * Close the keyboard.
    */
           public void
   close_getchr()
   {
   #if MSDOS_COMPILER==WIN32C
           SetConsoleMode((HANDLE)tty, console_mode);
           CloseHandle((HANDLE)tty);
   #endif
   }
   
   /*
  * Get a character from the keyboard.   * Get a character from the keyboard.
  */   */
         public int          public int
Line 74 
Line 104 
   
         do          do
         {          {
 #if MSOFTC  #if MSDOS_COMPILER && MSDOS_COMPILER != DJGPPC
                 /*                  /*
                  * In raw read, we don't see ^C so look here for it.                   * In raw read, we don't see ^C so look here for it.
                  */                   */
                 flush();                  flush();
   #if MSDOS_COMPILER==WIN32C
                   if (ABORT_SIGS())
                           return (READ_INTR);
                   c = WIN32getch(tty);
   #else
                 c = getch();                  c = getch();
   #endif
                 result = 1;                  result = 1;
                 if (c == '\003')                  if (c == '\003')
                         return (READ_INTR);                          return (READ_INTR);
 #else  #else
 #if OS2  
                 flush();  
                 while (_read_kbd(0, 0, 0) != -1)  
                         continue;  
                 if ((c = _read_kbd(0, 1, 0)) == -1)  
                         return (READ_INTR);  
                 result = 1;  
 #else  
                 result = iread(tty, &c, sizeof(char));                  result = iread(tty, &c, sizeof(char));
                 if (result == READ_INTR)                  if (result == READ_INTR)
                         return (READ_INTR);                          return (READ_INTR);
Line 103 
Line 131 
                          */                           */
                         quit(QUIT_ERROR);                          quit(QUIT_ERROR);
                 }                  }
 #endif  
 #endif  #endif
                 /*                  /*
                  * Various parts of the program cannot handle                   * Various parts of the program cannot handle

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3