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

Diff for /src/usr.bin/less/os.c between version 1.1.1.1 and 1.1.1.2

version 1.1.1.1, 1996/09/21 05:39:43 version 1.1.1.2, 2003/04/13 18:21:21
Line 1 
Line 1 
 /*  /*
  * 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 75 
Line 59 
   
 static jmp_buf read_label;  static jmp_buf read_label;
   
   extern int sigs;
   
 /*  /*
  * Like read() system call, but is deliberately interruptible.   * Like read() system call, but is deliberately interruptible.
  * A call to intread() from a signal handler will interrupt   * A call to intread() from a signal handler will interrupt
Line 88 
Line 74 
 {  {
         register int n;          register int n;
   
 #if MSOFTC  #if MSDOS_COMPILER==WIN32C
           if (ABORT_SIGS())
                   return (READ_INTR);
   #else
   #if MSDOS_COMPILER && MSDOS_COMPILER != DJGPPC
         if (kbhit())          if (kbhit())
         {          {
                 int c;                  int c;
Line 99 
Line 89 
                 ungetch(c);                  ungetch(c);
         }          }
 #endif  #endif
   #endif
         if (SET_JUMP(read_label))          if (SET_JUMP(read_label))
         {          {
                 /*                  /*
                  * We jumped here from intread.                   * We jumped here from intread.
                  */                   */
                 reading = 0;                  reading = 0;
   #if HAVE_SIGPROCMASK
                   {
                     sigset_t mask;
                     sigemptyset(&mask);
                     sigprocmask(SIG_SETMASK, &mask, NULL);
                   }
   #else
 #if HAVE_SIGSETMASK  #if HAVE_SIGSETMASK
                 sigsetmask(0);                  sigsetmask(0);
   #else
   #ifdef _OSK
                   sigmask(~0);
 #endif  #endif
   #endif
   #endif
                 return (READ_INTR);                  return (READ_INTR);
         }          }
   
         flush();          flush();
         reading = 1;          reading = 1;
   #if MSDOS_COMPILER==DJGPPC
           if (isatty(fd))
           {
                   /*
                    * Don't try reading from a TTY until a character is
                    * available, because that makes some background programs
                    * believe DOS is busy in a way that prevents those
                    * programs from working while "less" waits.
                    */
                   fd_set readfds;
   
                   FD_ZERO(&readfds);
                   FD_SET(fd, &readfds);
                   if (select(fd+1, &readfds, 0, 0, 0) == -1)
                           return (-1);
           }
   #endif
         n = read(fd, buf, len);          n = read(fd, buf, len);
   #if 1
           /*
            * This is a kludge to workaround a problem on some systems
            * where terminating a remote tty connection causes read() to
            * start returning 0 forever, instead of -1.
            */
           {
                   extern int ignore_eoi;
                   if (!ignore_eoi)
                   {
                           static int consecutive_nulls = 0;
                           if (n == 0)
                                   consecutive_nulls++;
                           else
                                   consecutive_nulls = 0;
                           if (consecutive_nulls > 20)
                                   quit(QUIT_ERROR);
                   }
           }
   #endif
         reading = 0;          reading = 0;
         if (n < 0)          if (n < 0)
                 return (-1);                  return (-1);
Line 177 
Line 217 
         register char *p;          register char *p;
         register char *m;          register char *m;
 #if HAVE_ERRNO  #if HAVE_ERRNO
   #if MUST_DEFINE_ERRNO
         extern int errno;          extern int errno;
   #endif
         p = strerror(errno);          p = strerror(errno);
 #else  #else
         p = "cannot open";          p = "cannot open";
Line 188 
Line 230 
 }  }
   
 /*  /*
  * Return the largest possible number that can fit in a long.   * Return the ratio of two POSITIONS, as a percentage.
    * {{ Assumes a POSITION is a long int. }}
  */   */
 #ifdef MAXLONG          public int
         static long  percentage(num, den)
 get_maxlong()          POSITION num, den;
 {  {
         return (MAXLONG);          POSITION num100 = num * 100;
   
           if (num100 / 100 == num)
                   return (num100 / den);
           else
                   return (num / (den / 100));
 }  }
 #else  
         static long  /*
 get_maxlong()   * Return the specified percentage of a POSITION.
    */
           public POSITION
   percent_pos(pos, percent)
           POSITION pos;
           int percent;
 {  {
         long n, n2;          POSITION result100;
   
         /*          if (percent == 0)
          * Keep doubling n until we overflow.                  return (0);
          * {{ This actually only returns the largest power of two that          else if ((result100 = pos * percent) / percent == pos)
          *    can fit in a long, but percentage() doesn't really need                  return (result100 / 100);
          *    it any more accurate than that. }}          else
          */                  return (percent * (pos / 100));
         n2 = 128;  /* Hopefully no maxlong is less than 128! */  
         do {  
                 n = n2;  
                 n2 *= 2;  
         } while (n2 / 2 == n);  
         return (n);  
 }  }
   
   #if !HAVE_STRCHR
   /*
    * strchr is used by regexp.c.
    */
           char *
   strchr(s, c)
           char *s;
           int c;
   {
           for ( ;  *s != '\0';  s++)
                   if (*s == c)
                           return (s);
           if (c == '\0')
                   return (s);
           return (NULL);
   }
 #endif  #endif
   
   #if !HAVE_MEMCPY
           VOID_POINTER
   memcpy(dst, src, len)
           VOID_POINTER dst;
           VOID_POINTER src;
           int len;
   {
           char *dstp = (char *) dst;
           char *srcp = (char *) src;
           int i;
   
           for (i = 0;  i < len;  i++)
                   dstp[i] = srcp[i];
           return (dst);
   }
   #endif
   
   #ifdef _OSK_MWC32
   
 /*  /*
  * Return the ratio of two longs, as a percentage.   * This implements an ANSI-style intercept setup for Microware C 3.2
  */   */
         public int          public int
 percentage(num, den)  os9_signal(type, handler)
         long num, den;          int type;
           RETSIGTYPE (*handler)();
 {  {
         static long maxlong100 = 0;          intercept(handler);
   
         if (maxlong100 == 0)  
                 maxlong100 = get_maxlong() / 100;  
         if (num > maxlong100)  
                 return (num / (den/100));  
         else  
                 return (100*num / den);  
 }  }
   
   #include <sgstat.h>
   
           int
   isatty(f)
           int f;
   {
           struct sgbuf sgbuf;
   
           if (_gs_opt(f, &sgbuf) < 0)
                   return -1;
           return (sgbuf.sg_class == 0);
   }
   
   #endif

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.2