[BACK]Return to tputs.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libterm

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/lib/libterm/Attic/tputs.c between version 1.1.1.2 and 1.21

version 1.1.1.2, 1995/02/27 09:50:27 version 1.21, 2003/08/07 16:44:57
Line 1 
Line 1 
   /*      $NetBSD$        */
   
 /*  /*
  * Copyright (c) 1980, 1993   * Copyright (c) 1980, 1993
  *      The Regents of the University of California.  All rights reserved.   *      The Regents of the University of California.  All rights reserved.
Line 10 
Line 12 
  * 2. Redistributions in binary form must reproduce the above copyright   * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the   *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.   *    documentation and/or other materials provided with the distribution.
  * 3. All advertising materials mentioning features or use of this software   * 3. Neither the name of the University nor the names of its contributors
  *    must display the following acknowledgement:  
  *      This product includes software developed by the University of  
  *      California, Berkeley and its contributors.  
  * 4. Neither the name of the University nor the names of its contributors  
  *    may be used to endorse or promote products derived from this software   *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.   *    without specific prior written permission.
  *   *
Line 31 
Line 29 
  * SUCH DAMAGE.   * SUCH DAMAGE.
  */   */
   
   #include <sys/cdefs.h>
 #ifndef lint  #ifndef lint
   #if 0
 static char sccsid[] = "@(#)tputs.c     8.1 (Berkeley) 6/4/93";  static char sccsid[] = "@(#)tputs.c     8.1 (Berkeley) 6/4/93";
   #else
   __RCSID("$NetBSD$");
   #endif
 #endif /* not lint */  #endif /* not lint */
   
 #include <sgtty.h>  #include <assert.h>
 #include <ctype.h>  #include <ctype.h>
   #include <termcap.h>
   #include <stdio.h>
   #include <stdlib.h>
   #undef ospeed
   
   /* internal functions */
   int _tputs_convert __P((const char **, int));
   
 /*  /*
  * The following array gives the number of tens of milliseconds per   * The following array gives the number of tens of milliseconds per
  * character for each speed as returned by gtty.  Thus since 300   * character for each speed as returned by gtty.  Thus since 300
  * baud returns a 7, there are 33.3 milliseconds per char at 300 baud.   * baud returns a 7, there are 33.3 milliseconds per char at 300 baud.
  */   */
 static  static const
 short   tmspc10[] = {  short   tmspc10[] = {
         0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5          0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5
 };  };
Line 51  short tmspc10[] = {
Line 61  short tmspc10[] = {
 short   ospeed;  short   ospeed;
 char    PC;  char    PC;
   
 /*  int
  * Put the character string cp out, with padding.  _tputs_convert(ptr, affcnt)
  * The number of affected lines is affcnt, and the routine          const char **ptr;
  * used to output one character is outc.  
  */  
 tputs(cp, affcnt, outc)  
         register char *cp;  
         int affcnt;          int affcnt;
         int (*outc)();  
 {  {
         register int i = 0;          int i = 0;
         register int mspc10;  
   
         if (cp == 0)          _DIAGASSERT(ptr != NULL);
                 return;          _DIAGASSERT(*ptr != NULL);
   
         /*          /*
          * Convert the number representing the delay.           * Convert the number representing the delay.
          */           */
         if (isdigit(*cp)) {          if (isdigit(*(const unsigned char *)(*ptr))) {
                 do                  do
                         i = i * 10 + *cp++ - '0';                          i = i * 10 + *(*ptr)++ - '0';
                 while (isdigit(*cp));                  while (isdigit(*(const unsigned char *)(*ptr)));
         }          }
         i *= 10;          i *= 10;
         if (*cp == '.') {          if (*(*ptr) == '.') {
                 cp++;                  (*ptr)++;
                 if (isdigit(*cp))                  if (isdigit(*(const unsigned char *)(*ptr)))
                         i += *cp - '0';                          i += *(*ptr) - '0';
                 /*                  /*
                  * Only one digit to the right of the decimal point.                   * Only one digit to the right of the decimal point.
                  */                   */
                 while (isdigit(*cp))                  while (isdigit(*(const unsigned char *)(*ptr)))
                         cp++;                          (*ptr)++;
         }          }
   
         /*          /*
          * If the delay is followed by a `*', then           * If the delay is followed by a `*', then
          * multiply by the affected lines count.           * multiply by the affected lines count.
          */           */
         if (*cp == '*')          if (*(*ptr) == '*')
                 cp++, i *= affcnt;                  (*ptr)++, i *= affcnt;
   
           return i;
   }
   
   /*
    * Put the character string cp out, with padding.
    * The number of affected lines is affcnt, and the routine
    * used to output one character is outc.
    */
   void
   tputs(cp, affcnt, outc)
           const char *cp;
           int affcnt;
           int (*outc) __P((int));
   {
           int i = 0;
           int mspc10;
   
           _DIAGASSERT(outc != 0);
   
           if (cp == 0)
                   return;
   
           /* scan and convert delay digits (if any) */
           i = _tputs_convert(&cp, affcnt);
   
         /*          /*
          * The guts of the string.           * The guts of the string.
          */           */
         while (*cp)          while (*cp)
                 (*outc)(*cp++);                  (void)(*outc)(*cp++);
   
         /*          /*
          * If no delay needed, or output speed is           * If no delay needed, or output speed is
Line 106  tputs(cp, affcnt, outc)
Line 135  tputs(cp, affcnt, outc)
          */           */
         if (i == 0)          if (i == 0)
                 return;                  return;
         if (ospeed <= 0 || ospeed >= (sizeof tmspc10 / sizeof tmspc10[0]))          if (ospeed <= 0 ||
               (size_t) ospeed >= (sizeof tmspc10 / sizeof tmspc10[0]))
                 return;                  return;
   
         /*          /*
Line 119  tputs(cp, affcnt, outc)
Line 149  tputs(cp, affcnt, outc)
         mspc10 = tmspc10[ospeed];          mspc10 = tmspc10[ospeed];
         i += mspc10 / 2;          i += mspc10 / 2;
         for (i /= mspc10; i > 0; i--)          for (i /= mspc10; i > 0; i--)
                 (*outc)(PC);                  (void)(*outc)(PC);
   }
   
   
   int
   t_puts(info, cp, affcnt, outc, args)
           struct tinfo *info;
           const char *cp;
           int affcnt;
           void (*outc) __P((char, void *));
           void *args;
   {
           int i = 0;
           size_t limit;
           int mspc10;
           char pad[2], *pptr;
           char *pc;
   
           /* XXX: info may be NULL ? */
           /* cp is handled below */
           _DIAGASSERT(outc != NULL);
           _DIAGASSERT(args != NULL);
   
           if (info != NULL) {
                   /*
                    * if we have info then get the pad char from the
                    * termcap entry if it exists, otherwise use the
                    * default NUL char.
                    */
                   pptr = pad;
                   limit = sizeof(pad);
                   pc = t_getstr(info, "pc", &pptr, &limit);
                   if (pc == NULL)
                           pad[0] = '\0';
                   else
                           free(pc);
           }
   
           if (cp == 0)
                   return -1;
   
           /* scan and convert delay digits (if any) */
           i = _tputs_convert(&cp, affcnt);
   
           /*
            * The guts of the string.
            */
           while (*cp)
                   (*outc)(*cp++, args);
   
           /*
            * If no delay needed, or output speed is
            * not comprehensible, then don't try to delay.
            */
           if (i == 0)
                   return 0;
           if (ospeed <= 0 ||
               (size_t) ospeed >= (sizeof tmspc10 / sizeof tmspc10[0]))
                   return 0;
   
           /*
            * Round up by a half a character frame,
            * and then do the delay.
            * Too bad there are no user program accessible programmed delays.
            * Transmitting pad characters slows many
            * terminals down and also loads the system.
            */
           mspc10 = tmspc10[ospeed];
           i += mspc10 / 2;
           for (i /= mspc10; i > 0; i--)
                   (*outc)(pad[0], args);
   
           return 0;
 }  }

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

CVSweb <webmaster@jp.NetBSD.org>