[BACK]Return to termcap.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/termcap.c between version 1.17 and 1.18

version 1.17, 1999/07/02 15:46:05 version 1.18, 1999/08/15 10:59:01
Line 50  __RCSID("$NetBSD$");
Line 50  __RCSID("$NetBSD$");
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
 #include <termcap.h>  #include <termcap.h>
   #include <errno.h>
 #include "pathnames.h"  #include "pathnames.h"
   
   /* internal definition of tinfo structure - just a pointer to the malloc'ed
    * buffer for now.
    */
   struct tinfo
   {
           char *info;
   };
   
 /*  /*
  * termcap - routines for dealing with the terminal capability data base   * termcap - routines for dealing with the terminal capability data base
  *   *
Line 67  __RCSID("$NetBSD$");
Line 76  __RCSID("$NetBSD$");
  */   */
   
 static  char *tbuf;     /* termcap buffer */  static  char *tbuf;     /* termcap buffer */
   static  struct tinfo *fbuf;     /* untruncated termcap buffer */
   
 /*  /*
  * Get an entry for terminal name in buffer bp from the termcap file.   * Get an extended entry for the terminal name.  This differs from
    * tgetent only in a) the buffer is malloc'ed for the caller and
    * b) the termcap entry is not truncated to 1023 characters.
  */   */
   
 int  int
 tgetent(bp, name)  t_getent(bp, name)
         char *bp;          struct tinfo **bp;
         const char *name;          const char *name;
 {  {
         char  *p;          char  *p;
         char  *cp;          char  *cp;
         char  *dummy;  
         char **fname;          char **fname;
         char  *home;          char  *home;
         int    i;          int    i;
Line 86  tgetent(bp, name)
Line 98  tgetent(bp, name)
         char  *pathvec[PVECSIZ];        /* to point to names in pathbuf */          char  *pathvec[PVECSIZ];        /* to point to names in pathbuf */
         char  *termpath;          char  *termpath;
   
           if ((*bp = malloc(sizeof(struct tinfo))) == NULL) return 0;
   
         fname = pathvec;          fname = pathvec;
         tbuf = bp;  
         p = pathbuf;          p = pathbuf;
         cp = getenv("TERMCAP");          cp = getenv("TERMCAP");
         /*          /*
Line 143  tgetent(bp, name)
Line 156  tgetent(bp, name)
          * user had setup name to be built from a path they can not           * user had setup name to be built from a path they can not
          * normally read.           * normally read.
          */           */
         dummy = NULL;          (*bp)->info = NULL;
         i = cgetent(&dummy, pathvec, name);          i = cgetent(&((*bp)->info), pathvec, name);
   
         if (i == 0) {  
                 /*  
                  * If the entry is too long, truncate to the last whole cap.  
                  */  
                 strncpy(bp, dummy, 1024);  
                 if (strlen(dummy) > 1023 && bp[1023] != ':' ) {  
                         for (cp = bp+1022 ; cp > bp && *cp != ':' ; --cp)  
                                 ;  
                         if (cp > bp)  
                                 cp[1] = 0;  
                 }  
                 bp[1023] = '\0';  
         }  
   
         if (dummy)  
                 free(dummy);  
         /* no tc reference loop return code in libterm XXX */          /* no tc reference loop return code in libterm XXX */
         if (i == -3)          if (i == -3)
                 return (-1);                  return (-1);
Line 169  tgetent(bp, name)
Line 166  tgetent(bp, name)
 }  }
   
 /*  /*
    * Get an entry for terminal name in buffer bp from the termcap file.
    */
   int
   tgetent(bp, name)
           char *bp;
           const char *name;
   {
           int i, plen, elen, c;
           char *ptrbuf = NULL;
   
           i = t_getent(&fbuf, name);
   
           if (i == 1) {
                     /* stash the full buffer pointer as the ZZ capability
                        in the termcap buffer passed.
                     */
                   plen = asprintf(&ptrbuf, ":ZZ=%p", fbuf->info);
                   strncpy(bp, fbuf->info, 1024);
                   bp[1023] = '\0';
                   elen = strlen(bp);
                     /* backup over the entry if the addition of the full
                        buffer pointer will overflow the buffer passed.  We
                        want to truncate the termcap entry on a capability
                        boundary.
                     */
                   if ((elen + plen) > 1023) {
                           bp[1023 - plen] = '\0';
                           for (c = (elen - plen); c > 0; c--) {
                                   if (bp[c] == ':') {
                                           bp[c] = '\0';
                                           break;
                                   }
                           }
                   }
   
                   strcat(bp, ptrbuf);
                   tbuf = bp;
           }
   
           return i;
   }
   
   /*
  * Return the (numeric) option id.   * Return the (numeric) option id.
  * Numeric options look like   * Numeric options look like
  *      li#80   *      li#80
Line 177  tgetent(bp, name)
Line 217  tgetent(bp, name)
  * Note that we handle octal numbers beginning with 0.   * Note that we handle octal numbers beginning with 0.
  */   */
 int  int
 tgetnum(id)  
   t_getnum(info, id)
           struct tinfo *info;
         const char *id;          const char *id;
 {  {
         long num;          long num;
   
         if (cgetnum(tbuf, id, &num) == 0)          if (cgetnum(info->info, id, &num) == 0)
                 return (int)(num);                  return (int)(num);
         else          else
                 return (-1);                  return (-1);
 }  }
   
   int
   tgetnum(id)
           const char *id;
   {
           return t_getnum(fbuf, id);
   }
   
 /*  /*
  * Handle a flag option.   * Handle a flag option.
  * Flag options are given "naked", i.e. followed by a : or the end   * Flag options are given "naked", i.e. followed by a : or the end
  * of the buffer.  Return 1 if we find the option, or 0 if it is   * of the buffer.  Return 1 if we find the option, or 0 if it is
  * not given.   * not given.
  */   */
   int t_getflag(info, id)
           struct tinfo *info;
           const char *id;
   {
           return (cgetcap(info->info, id, ':') != NULL);
   }
   
 int  int
 tgetflag(id)  tgetflag(id)
         const char *id;          const char *id;
 {  {
         return (cgetcap(tbuf, id, ':') != NULL);          return t_getflag(fbuf, id);
 }  }
   
 /*  /*
Line 207  tgetflag(id)
Line 263  tgetflag(id)
  *      cl=^Z   *      cl=^Z
  * Much decoding is done on the strings, and the strings are   * Much decoding is done on the strings, and the strings are
  * placed in area, which is a ref parameter which is updated.   * placed in area, which is a ref parameter which is updated.
  * No checking on area overflow.   * limit is the number of characters allowed to be put into
    * area, this is updated.
  */   */
 char *  char *
 tgetstr(id, area)  t_getstr(info, id, area, limit)
           struct tinfo *info;
         const char *id;          const char *id;
         char **area;          char **area;
           int *limit;
 {  {
         char ids[3];          char ids[3];
         char *s;          char *s;
Line 227  tgetstr(id, area)
Line 286  tgetstr(id, area)
         ids[1] = id[1];          ids[1] = id[1];
         ids[2] = '\0';          ids[2] = '\0';
   
         if ((i = cgetstr(tbuf, ids, &s)) < 0)          if ((i = cgetstr(info->info, ids, &s)) < 0) {
                   errno = ENOENT;
                 return NULL;                  return NULL;
           }
   
             /* check if there is room for the new entry to be put into area */
           if (limit != NULL && (*limit < i)) {
                   errno = E2BIG;
                   return NULL;
           }
   
         strcpy(*area, s);          strcpy(*area, s);
         *area += i + 1;          *area += i + 1;
         return (s);          if (limit != NULL) *limit -= i;
   
           return (s);
   }
   
   /*
    * Get a string valued option.
    * These are given as
    *      cl=^Z
    * Much decoding is done on the strings, and the strings are
    * placed in area, which is a ref parameter which is updated.
    * No checking on area overflow.
    */
   char *
   tgetstr(id, area)
           const char *id;
           char **area;
   {
           struct tinfo dummy;
   
           if ((id[0] == 'Z') && (id[1] == 'Z')) {
                   dummy.info = tbuf;
                   return t_getstr(&dummy, id, area, NULL);
           }
           else
                   return t_getstr(fbuf, id, area, NULL);
   }
   
   /*
    * Free the buffer allocated by t_getent
    *
    */
   void
   t_freent(info)
           struct tinfo *info;
   {
           free(info->info);
           free(info);
 }  }

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18

CVSweb <webmaster@jp.NetBSD.org>