Example #1
0
/*
 * tfindent - reads through the list of files in pathvec as if they were one
 * continuous file searching for terminal entries along the way.  It will
 * participate in indirect recursion if the call to tnchktc() finds a tc=
 * field, which is only searched for in the current file and files ocurring
 * after it in pathvec.  The usable part of this vector is kept in the global
 * variable pvec.  Terminal entries may not be broken across files.  Parse is
 * very rudimentary; we just notice escaped newlines.
 */
int
tfindent(char *bp, char *name)
{
	register char *cp;
	register int c;
	register int i, cnt;
	char ibuf[BUFSIZ];
	int opencnt = 0;
	int tf;

	tbuf = bp;
nextfile:
	i = cnt = 0;
	while (*pvec && (tf = open(*pvec, O_READ)) < 0) {
		pvec++;
	}
	if (!*pvec) {
		return (opencnt ? 0 : -1);
	}
	opencnt++;
	for (;;) {
		cp = bp;
		for (;;) {
			if (i == cnt) {
				cnt = read(tf, ibuf, BUFSIZ);
				if (cnt <= 0) {
					close(tf);
					pvec++;
					goto nextfile;
				}
				i = 0;
			}
			c = ibuf[i++];
			if (c == '\n') {
				if (cp > bp && cp[-1] == '\\'){
					cp--;
					continue;
				}
				break;
			}
			if (cp >= bp+BUFSIZ) {
				write(2,"Termcap entry too long\n", 23);
				break;
			} else {
				*cp++ = c;
			}
		}
		*cp = 0;

		/*
		 * The real work for the match.
		 */
		if (tnamatch(name)) {
			close(tf);
			return(tnchktc());
		}
	}
}
Example #2
0
/*
 * Get an entry for terminal name in buffer bp,
 * from the termcap file.  Parse is very rudimentary;
 * we just notice escaped newlines.
 */
int
tgetent(char *bp, char *name, char *file)
{
	char *cp;
	int c;
	int i = 0, cnt = 0;
	char ibuf[BUFSIZ];
	char *cp2;
	int tf;

	tbuf = bp;
	tf = 0;
	filename = file;
	tf = open(filename, 0);
	if (tf < 0)
		return (-1);
	for (;;) {
		cp = bp;
		for (;;) {
			if (i == cnt) {
				cnt = read(tf, ibuf, BUFSIZ);
				if (cnt <= 0) {
					close(tf);
					return (0);
				}
				i = 0;
			}
			c = ibuf[i++];
			if (c == '\n') {
				if (cp > bp && cp[-1] == '\\'){
					cp--;
					continue;
				}
				break;
			}
			if (cp >= bp+BUFSIZ) {
				vgrind_msg = gettext("Vgrind entry too long\n");
				write(2, vgrind_msg, strlen(vgrind_msg));
				break;
			} else
				*cp++ = c;
		}
		*cp = 0;

		/*
		 * The real work for the match.
		 */
		if (tnamatch(name)) {
			close(tf);
			return(tnchktc());
		}
	}
}
Example #3
0
/*
 * Get an entry for terminal name in buffer bp,
 * from the termcap file.  Parse is very rudimentary;
 * we just notice escaped newlines.
 */
int
tgetent(char *bp, char *name, char *file)
{
	register char *cp;
	register int c;
	register int i = 0, cnt = 0;
	char ibuf[BUFSIZ];
	int tf;

	tbuf = bp;
	tf = 0;
	filename = file;
	tf = open(filename, O_RDONLY);
	if (tf < 0)
		return (-1);
	for (;;) {
		cp = bp;
		for (;;) {
			if (i == cnt) {
				cnt = read(tf, ibuf, BUFSIZ);
				if (cnt <= 0) {
					close(tf);
					return (0);
				}
				i = 0;
			}
			c = ibuf[i++];
			if (c == '\n') {
				if (cp > bp && cp[-1] == '\\'){
					cp--;
					continue;
				}
				break;
			}
			if (cp >= bp+BUFSIZ) {
				write(STDERR_FILENO, "Vgrind entry too long\n", 23);
				break;
			} else
				*cp++ = c;
		}
		*cp = 0;

		/*
		 * The real work for the match.
		 */
		if (tnamatch(name)) {
			close(tf);
			return(tnchktc());
		}
	}
}
Example #4
0
/*
 * Get an entry for terminal name in buffer @bp@,
 * from the termcap file.  Parse is very rudimentary;
 * we just notice escaped newlines.
 */
int tgetent(char *bp, char *name, char *file)
{
   register char *cp;
   register char c;        /* 30.7.96 -- tryal [sic] */
   register int i = 0, cnt = 0;
   char ibuf[BUFFERSIZE];
   FILE *tf;
   
   tbuf = bp;
   tf = 0;
   filename = file;
   tf = fopen(filename, "rt");
   if (tf == NULL)
      return -1;
   for (;;) {
      cp = bp;
      for (;;) {
	 if (i == cnt) {
	    cnt = fread(ibuf, 1, BUFFERSIZE, tf);
	    if (cnt <= 0) {
	       fclose(tf);
	       return 0;
		}
		i = 0;
	 }
	 c = ibuf[i++];
	 if (c == '\n') {
		if (cp > bp && cp[-1] == '\\'){
		   cp--;
		   continue;
		}
		break;
	 }
	 if (cp >= bp+BUFFERSIZE) {
		fprintf(stderr, "LGrind entry too long\n");
		break;
	 } else
		*cp++ = c;
	  }
	  *cp = '\0';

	  /*
	   * The real work for the match.
	   */
	  if (tnamatch(name)) {
	 fclose(tf);
	 return tnchktc();
	  }
   }
}
Example #5
0
int
getent(char *bp, char *name, char *cp)
{
    int c;
    int i = 0, cnt = 0;
    char ibuf[BUFSIZ];
    int tf;

    tbuf = bp;
    tf = 0;
    /*
     * TERMCAP can have one of two things in it. It can be the
     * name of a file to use instead of /etc/termcap. In this
     * case it better start with a "/". Or it can be an entry to
     * use so we don't have to read the file. In this case it
     * has to already have the newlines crunched out.
     */
    if (cp && *cp) {
        tf = open(RM = cp, O_RDONLY);
    }
    if (tf < 0) {
        syslog(LOG_INFO,
               "<%s> open: %s", __func__, strerror(errno));
        return (-2);
    }
    for (;;) {
        cp = bp;
        for (;;) {
            if (i == cnt) {
                cnt = read(tf, ibuf, BUFSIZ);
                if (cnt <= 0) {
                    close(tf);
                    return (0);
                }
                i = 0;
            }
            c = ibuf[i++];
            if (c == '\n') {
                if (cp > bp && cp[-1] == '\\') {
                    cp--;
                    continue;
                }
                break;
            }
            if (cp >= bp+BUFSIZ) {
                write(2,"Remcap entry too long\n", 23);
                break;
            } else
                *cp++ = c;
        }
        *cp = 0;

        /*
         * The real work for the match.
         */
        if (tnamatch(name)) {
            close(tf);
            return (tnchktc());
        }
    }
}
Example #6
0
/*
 * Get an entry for terminal name in buffer bp,
 * from the termcap file.  Parse is very rudimentary;
 * we just notice escaped newlines.
 */
int tgetent(char *bp, char *name)
{
  register char *cp;
  register int c;
  register int i = 0, cnt = 0;
  char ibuf[BUFSIZ];
#ifndef __HELIOS
  char *cp2;
#endif  
  int tf;

  tbuf = bp;
  tf = 0;
#ifndef V6
  cp = getenv("TERMCAP");
  /*
   * TERMCAP can have one of two things in it. It can be the
   * name of a file to use instead of /etc/termcap. In this
   * case it better start with a "/". Or it can be an entry to
   * use so we don't have to read the file. In this case it
   * has to already have the newlines crunched out.
   */
  if (cp && *cp) {
    if (*cp!='/') {
      cp2 = getenv("TERM");
      if (cp2==(char *) 0 || strcmp(name,cp2)==0) {
        strcpy(bp,cp);
        return(tnchktc());
      } else {
        tf = open(E_TERMCAP, 0);
      }
    } else
      tf = open(cp, 0);
  }
  if (tf==0)
    tf = open(E_TERMCAP, 0);
#else

#ifndef __HELIOS
  tf = open(E_TERMCAP, 0);
#else
  tf = open(E_TERMCAP, O_RDONLY);
#endif
  
#endif
  if (tf < 0)
    return (-1);
  for (;;) {
    cp = bp;
    for (;;) {
      if (i == cnt) {
        cnt = read(tf, ibuf, BUFSIZ);
        if (cnt <= 0) {
          close(tf);
          return (0);
        }
        i = 0;
      }
      c = ibuf[i++];
#ifndef __HELIOS
      if (c == '\n') {
        if (cp > bp && cp[-1] == '\\'){
          cp--;
          continue;
        }
        break;
      }
#else
      if (c == '\n') 
      {
        if (cp > bp) 
        {
          if (cp[-1] == '\\')
          {
            cp -- ;
            continue ;
          } else
          if (cp[-2] == '\\')
          {
            cp -= 2 ;
            continue;
          }
        }
        break;
      }
#endif      

      if (cp >= bp+BUFSIZ) {
        write(2,"Termcap entry too long\n", 23);
        break;
      } else
        *cp++ = c;
    }
    *cp = 0;

    /*
     * The real work for the match.
     */
    if (tnamatch(name)) {
      close(tf);
      return(tnchktc());
    }
  }
}
Example #7
0
static int
tgetent(char *bp, char *name, int beg)
{
   int j;

   int c;

   int tf = -1;

   char *cp = 0;

   char ibuf[TBUFSIZE];

   int i = 0;

   int cnt = 0;

   if (beg >= fnum)
      return 0;

   tbuf = bp;

   for (j = beg; j < fnum; ++j)
   {
      char *termcap = fnames[j];

      tf = open(termcap, 0);
      if (tf < 0)
	 continue;
      i = 0;
      cnt = 0;
      for (;;)
      {
	 cp = bp;
	 for (;;)
	 {
	    if (i == cnt)
	    {
	       cnt = read(tf, ibuf, TBUFSIZE);
	       if (cnt <= 0)
		  goto nextf;
	       i = 0;
	    }
	    c = ibuf[i++];
	    if (c == '\n')
	    {
	       if (cp > bp && cp[-1] == '\\')
	       {
		  cp--;
		  continue;
	       }
	       break;
	    }
	    if (cp >= bp + TBUFSIZE)
	    {
	       err("Termcap entry too long");
	       break;
	    }
	    else
	       *cp++ = c;
	 }
	 *cp = 0;

	 /* The real work for the match. */
	 if (tnamatch(name))
	 {
	    ++match_count;
	    close(tf);
	    return tnchktc(name, j);
	 }
      }
    nextf:
      close(tf);
   }
   return -1;
}
Example #8
0
static int
_tgetent(char *bp, char *name, char *termcap)
{
   int c;

   int tf = -1;

   char *cp = envtermcap;

   char *ibuf;

   int i = 0;

   int cnt = 0;

   tbuf = bp;

   /* TERMCAP can have one of two things in it. It can be the */
   /* name of a file to use instead of /etc/termcap. In this */
   /* case it must start with a "/". Or it can be an entry to */
   /* use so we don't have to read the file. In this case it */
   /* has to already have the newlines crunched out. */
   if (cp && *cp)
   {
      envtermcap = "";
      tbuf = cp;
      c = tnamatch(name);
      tbuf = bp;
      if (c)
      {
	 strcpy(bp, cp);
	 return (tnchktc());
      }
   }
   if (tf < 0)
      tf = open(termcap, 0);
   if (tf < 0)
      return (0);
   ibuf = (char *) malloc(BUFSIZE);
   i = 0;
   cnt = 0;
   for (;;)
   {
      cp = bp;
      for (;;)
      {
	 if (i == cnt)
	 {
	    cnt = read(tf, ibuf, BUFSIZE);
	    if (cnt <= 0)
	    {
	       close(tf);
	       free(ibuf);
	       return (0);
	    }
	    i = 0;
	 }
	 c = ibuf[i++];
	 if (c == '\n')
	 {
	    if (cp > bp && cp[-1] == '\\')
	    {
	       cp--;
	       continue;
	    }
	    break;
	 }
	 if (cp >= bp + BUFSIZE)
	 {
	    errexit("Termcap entry too long");
	    break;
	 }
	 else
	    *cp++ = c;
      }
      *cp = 0;

      /* The real work for the match. */
      if (tnamatch(name))
      {
	 close(tf);
	 free(ibuf);
	 return (tnchktc());
      }
   }
   return -1;
}
Example #9
0
int
getent(char *bp, char *name, char *cp, int len)
{
	int c;
	int i = 0, cnt = 0;
	char ibuf[BUFSIZ], *cp2;
	int tf;
	int safe = 1; /* reset only when we open the user's $REMOTE */

	tbuf = bp;
	tf = 0;
	/*
	 * TERMCAP can have one of two things in it. It can be the
	 * name of a file to use instead of /etc/termcap. In this
	 * case it better start with a "/". Or it can be an entry to
	 * use so we don't have to read the file. In this case it
	 * has to already have the newlines crunched out.
	 */
	if (cp && *cp) {
		if (*cp != '/') {
			cp2 = getenv(V_TERM);
			if (cp2 == (char *)0 || strcmp(name, cp2) == 0) {
				if (strstr(cp, "dv=") != 0)
					trusted_device = 0;
				(void) strncpy(bp, cp, len-1);
				bp[len-1] = '\0';
				return (tnchktc());
			} else
				tf = open(E_TERMCAP, O_RDONLY);
		} else {
			/* open SYSREMOTE as uucp, other files as user */
			safe = strcmp(cp, SYSREMOTE) == 0;
			if (!safe)
				userperm();
			tf = open(RM = cp, O_RDONLY);
			if (!safe)
				myperm();
		}
	}
	if (tf == 0)
		tf = open(E_TERMCAP, O_RDONLY);
	if (tf < 0)
		return (-1);
	for (;;) {
		cp = bp;
		for (;;) {
			if (i == cnt) {
				cnt = read(tf, ibuf, BUFSIZ);
				if (cnt <= 0) {
					(void) close(tf);
					return (0);
				}
				i = 0;
			}
			c = ibuf[i++];
			if (c == '\n') {
				if (cp > bp && cp[-1] == '\\') {
					cp--;
					continue;
				}
				break;
			}
			if (cp >= bp+len) {
				(void) write(2, "Remcap entry too long\n", 23);
				break;
			} else
				*cp++ = c;
		}
		*cp = 0;

		/*
		 * The real work for the match.
		 */
		if (tnamatch(name)) {
			/*
			 * if a dv= entry is obtained from $REMOTE,
			 * switch off trusted_device status
			 */
			if (!safe && strstr(bp, "dv=") != 0)
				trusted_device = 0;
			(void) close(tf);
			return (tnchktc());
		}
	}
}
Example #10
0
/*
 * Get an entry for terminal name in buffer bp from the termcap file.
 */
int
tgetent(char *bp, char *name)
{
	register char *p;
	register char *cp;
	register int c;
	char *term;
	char **fname = pathvec;

	/*
	 * Get environment values once.  We contact the server and
	 * cache into a malloc()'ed area, so we don't want to do
	 * this on every call.
	 */
	if (termcap == 0) {
		termcap = getenv("TERMCAP");
		if (termcap == 0) {
			termcap = _PATH_TERMCAP;
		}
		termpath = getenv("TERMPATH");
		home = getenv("HOME");
	}
	pvec = pathvec;
	tbuf = bp;
	p = pathbuf;

	/*
	 * TERMCAP can have one of two things in it. It can be the
	 * name of a file to use instead of /etc/termcap. In this
	 * case it better start with a "/". Or it can be an entry to
	 * use so we don't have to read the file. In this case it
	 * has to already have the newlines crunched out.  If TERMCAP
	 * does not hold a file name then a path of names is searched
	 * instead.  The path is found in the TERMPATH variable, or
	 * becomes "$HOME/.termcap /etc/termcap" if no TERMPATH exists.
	 */
	cp = termcap;
	if (!cp || *cp != '/') {	/* no TERMCAP or it holds an entry */
		if (termpath) {
			strncpy(pathbuf, termpath, PBUFSIZ);
		} else {
			if (home) {	/* set up default */
				p += strlen(home);	/* path, looking in */
				strcpy(pathbuf, home);	/* $HOME first */
				*p++ = '/';
			}	/* if no $HOME look in current directory */
			strncpy(p, _PATH_TERMCAP, PBUFSIZ - (p - pathbuf));
		}
	} else {		/* user-defined name in TERMCAP */
		strncpy(pathbuf, cp, PBUFSIZ);	/* still can be tokenized */
	}

	*fname++ = pathbuf;	/* tokenize path into vector of names */
	while (*++p)
		if (*p == ' ' || *p == ':') {
			*p = '\0';
			while (*++p)
				if (*p != ' ' && *p != ':')
					break;
			if (*p == '\0')
				break;
			*fname++ = p;
			if (fname >= pathvec + PVECSIZ) {
				fname--;
				break;
			}
		}
	*fname = (char *) 0;			/* mark end of vector */
	if (cp && *cp && *cp != '/') {
		tbuf = cp;
		c = tnamatch(name);
		tbuf = bp;
		if (c) {
			strcpy(bp,cp);
			return (tnchktc());
		}
	}
	return (tfindent(bp, name));	/* find terminal entry in path */
}