Exemple #1
0
/*
 * Return the (numeric) option id.
 * Numeric options look like
 *	li#80
 * i.e. the option string is separated from the numeric value by
 * a # character.  If the option is not found we return -1.
 * Note that we handle octal numbers beginning with 0.
 */
static int
tgetnum(char *id)
{
	int i, base;
	char *bp = tbuf;

	for (;;) {
		bp = tskip(bp);
		if (*bp == 0)
			return (-1);
		if (*bp++ != id[0] || *bp == 0 || *bp++ != id[1])
			continue;
		if (*bp == '@')
			return(-1);
		if (*bp != '#')
			continue;
		bp++;
		base = 10;
		if (*bp == '0')
			base = 8;
		i = 0;
		while (isdigit(*bp))
			i *= base, i += *bp++ - '0';
		return (i);
	}
}
Exemple #2
0
/*
 * Return the (numeric) option id.
 * Numeric options look like
 *	li#80
 * i.e. the option string is separated from the numeric value by
 * a # character.  If the option is not found we return -1.
 * Note that we handle octal numbers beginning with 0.
 *
 * Slip in implicit knowledge here that li/co are window geometry,
 * and that FD 0 is the place whose geometry concerns us.
 */
int
tgetnum(char *id)
{
	int i, base, rows, cols;
	char *bp = tbuf;

	if (!strcmp(id, "li")) {
		if (ttysize(&rows, &cols) >= 0) {
			return(rows);
		}
	} else if (!strcmp(id, "co")) {
		if (ttysize(&rows, &cols) >= 0) {
			return(cols);
		}
	}
	for (;;) {
		bp = tskip(bp);
		if (*bp == 0)
			return (-1);
		if (*bp++ != id[0] || *bp == 0 || *bp++ != id[1])
			continue;
		if (*bp == '@')
			return(-1);
		if (*bp != '#')
			continue;
		bp++;
		base = 10;
		if (*bp == '0')
			base = 8;
		i = 0;
		while (isdigit(*bp))
			i *= base, i += *bp++ - '0';
		return (i);
	}
}
Exemple #3
0
/*
 * Handle a flag option.
 * 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
 * not given.
 */
int tgetflag(char *id)
{
   register char *bp = tbuf;
   
   for (;;) {
      bp = tskip(bp);
      if (!*bp)
	 return 0;
      if (*bp++ == id[0] && *bp != 0 && *bp++ == id[1]) {
	 if (!*bp || *bp == ':')
	    return 1;
	 else if (*bp == '@')
	    return 0;
      }
   }
}
/*
 * Handle a flag option.
 * 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
 * not given.
 */
int
tgetflag(char *id)
{
	char *bp = tbuf;

	for (;;) {
		bp = tskip(bp);
		if (!*bp)
			return (0);
		if (*bp++ == id[0] && *bp != 0 && *bp++ == id[1]) {
			if (!*bp || *bp == ':')
				return (1);
			else if (*bp == '@')
				return(0);
		}
	}
}
Exemple #5
0
/*
 * Handle a flag option.
 * 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
 * not given.
 */
int
tgetflag(char *id)
{
    char *bp = tbuf;

    for (;;) {
        bp = tskip(bp);
        if (!*bp)
            return (0);
        if (strncmp(bp, id, strlen(id)) == 0) {
            bp += strlen(id);
            if (!*bp || *bp == ':')
                return (1);
            else if (*bp == '@')
                return (0);
        }
    }
}
Exemple #6
0
/*
 * 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(char *id, char **area) 
{
  register char *bp = tbuf;

  for (;;) {
    bp = tskip(bp);
    if (!*bp)
      return (0);
    if (*bp++ != id[0] || *bp == 0 || *bp++ != id[1])
      continue;
    if (*bp == '@')
      return(0);
    if (*bp != '=')
      continue;
    bp++;
    return (tdecode(bp, area));
  }
}
Exemple #7
0
/*
 * 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(char *id, char **area)
{
    char *bp = tbuf;

    for (;;) {
        bp = tskip(bp);
        if (!*bp)
            return (0);
        if (strncmp(bp, id, strlen(id)) != 0)
            continue;
        bp += strlen(id);
        if (*bp == '@')
            return (0);
        if (*bp != '=')
            continue;
        bp++;
        return (tdecode(bp, area));
    }
}
Exemple #8
0
/*
 * 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(char *id, char **area)
{
	register char *bp = tbuf, *i;
	register int eq;

	for (;;) {
		bp = tskip(bp);
		if (!*bp)
			return 0;
		eq=1;
		for (i=id; *i;)
			if (*i++!=*bp++) { eq=0; break; }
		if (!eq)
			continue;
		if (*bp == '@')
			return 0;
		if (*bp != '=')
			continue;
		bp++;
		return tdecode(bp, area);
	}
}
Exemple #9
0
char *
tgetstr(char *id, char **area)
{
   register char *bp;

   char name[2];

   if (!tbuf)
      return NULL;
   bp = tbuf;
   for (;;)
   {
      bp = tskip(bp);
      if (!bp[0] || !bp[1])
	 break;
      if (bp[0] == ':' || bp[1] == ':')
	 continue;
      name[0] = *bp++;
      name[1] = *bp++;
      if (id[0] != name[0] || id[1] != name[1])
	 continue;
      if (*bp == '@')
	 continue;

      switch (*bp)
      {
      case '#':
      case ':':
      case 0:
	 break;
      default:
	 if (*bp != '=')
	    continue;
	 bp++;
	 return tdecode(bp, area);
      }
   }
   return NULL;
}
Exemple #10
0
int
tgetflag(const char *id)
{
   register char *bp;

   char name[2];

   if (!tbuf)
      return 0;
   bp = tbuf;
   for (;;)
   {
      bp = tskip(bp);
      if (!bp[0] || !bp[1])
	 break;
      if (bp[0] == ':' || bp[1] == ':')
	 continue;
      name[0] = *bp++;
      name[1] = *bp++;
      if (id[0] != name[0] || id[1] != name[1])
	 continue;
      if (*bp == '@')
	 continue;

      switch (*bp)
      {
      case '#':
      default:
	 continue;
      case ':':
	 return 1;
      case 0:
	 return 0;
      }
   }
   return 0;
}
Exemple #11
0
void
checktermcap()
{
	char *tbuf = bp;
	enum { tbool, tnum, tstr, tcancel, tunknown } type;

	for (;;) {
		tbuf = tskip(tbuf);
		while (*tbuf == '\t' || *tbuf == ' ' || *tbuf == ':')
			tbuf++;

		if (*tbuf == 0)
			return;

		/* commented out entry? */
		if (*tbuf == '.') {
			if (verbose)
				(void) fprintf(trace, "termcap string '%c%c' "
				    "commented out.\n", tbuf[1], tbuf[2]);
			if (!capsearch(boolcodes, oboolcodes, tbuf + 1) &&
			    !capsearch(numcodes, onumcodes, tbuf + 1) &&
			    !capsearch(strcodes, ostrcodes, tbuf + 1))
				(void) fprintf(stderr,
				    "%s: TERM=%s: commented out code '%.2s' "
				    "is unknown.\n", progname, term_name,
				    tbuf+1);
			continue;
		}

		if (verbose)
			(void) fprintf(trace, "looking at termcap string "
			    "'%.2s'.\n", tbuf);

		switch (tbuf[2]) {
			case ':': case '\0':	type = tbool;	break;
			case '#':			type = tnum;	break;
			case '=':			type = tstr;	break;
			case '@':			type = tcancel;	break;
			default:
				(void) fprintf(stderr,
				    "%s: TERM=%s: unknown type given for the "
				    "termcap code '%.2s'.\n", progname,
				    term_name, tbuf);
				type = tunknown;
		}

		if (verbose > 1)
			(void) fprintf(trace, "type of '%.2s' is %s.\n", tbuf,
			    (type == tbool) ? "boolean" :
			    (type == tnum) ? "numeric" :
			    (type = tstr) ? "string" :
			    (type = tcancel) ? "canceled" : "unknown");

		/* look for the name in bools */
		if (capsearch(boolcodes, oboolcodes, tbuf)) {
			if (type != tbool && type != tcancel)
				(void) fprintf(stderr,
				    "%s: TERM=%s: wrong type given for the "
				    "boolean termcap code '%.2s'.\n", progname,
				    term_name, tbuf);
			continue;
		}

		/* look for the name in nums */
		if (capsearch(numcodes, onumcodes, tbuf)) {
			if (type != tnum && type != tcancel)
				(void) fprintf(stderr,
				    "%s: TERM=%s: wrong type given for the "
				    "numeric termcap code '%.2s'.\n", progname,
				    term_name, tbuf);
			continue;
		}

		/* look for the name in strs */
		if (capsearch(strcodes, ostrcodes, tbuf)) {
			if (type != tstr && type != tcancel)
				(void) fprintf(stderr,
				    "%s: TERM=%s: wrong type given for the "
				    "string termcap code '%.2s'.\n", progname,
				    term_name, tbuf);
			continue;
		}

		(void) fprintf(stderr,
		    "%s: TERM=%s: the %s termcap code '%.2s' is not a valid "
		    "name.\n", progname, term_name,
		    (type == tbool) ? "boolean" :
		    (type == tnum) ? "numeric" :
		    (type = tstr) ? "string" :
		    (type = tcancel) ? "canceled" : "(unknown type)", tbuf);
	}
}