Include private header.

Make capability parser more generic (it is now also used by colour routines).
Note that the termcap file we use contains terminfo % escapes, which are
not always compatible with the termcap ones.  We'll lose in those cases.
This commit is contained in:
jdc 2000-04-12 21:37:15 +00:00
parent 725597b1c6
commit d236276259
1 changed files with 115 additions and 12 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: tscroll.c,v 1.5 1999/04/13 14:08:19 mrg Exp $ */
/* $NetBSD: tscroll.c,v 1.6 2000/04/12 21:37:15 jdc Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
@ -34,20 +34,31 @@
*/
#include <sys/cdefs.h>
#include <stdarg.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)tscroll.c 8.4 (Berkeley) 7/27/94";
#else
__RCSID("$NetBSD: tscroll.c,v 1.5 1999/04/13 14:08:19 mrg Exp $");
__RCSID("$NetBSD: tscroll.c,v 1.6 2000/04/12 21:37:15 jdc Exp $");
#endif
#endif /* not lint */
#include "curses.h"
#include "curses_private.h"
#define MAXRETURNSIZE 64
char *
__tscroll(cap, n1, n2)
const char *cap;
int n1, n2;
{
return (__parse_cap(cap, n1, n2));
}
/*
* Routine to perform scrolling. Derived from tgoto.c in termcap(3)
* Routines to parse capabilities. Derived from tgoto.c in termcap(3)
* library. Cap is a string containing printf type escapes to allow
* scrolling. The following escapes are defined for substituting n:
*
@ -66,71 +77,161 @@ __RCSID("$NetBSD: tscroll.c,v 1.5 1999/04/13 14:08:19 mrg Exp $");
* %D Delta Data (backwards bcd)
*
* all other characters are ``self-inserting''.
*
* XXX:
* %r reverse order of two parameters
* is also defined but we don't support it (yet).
*/
char *
__tscroll(cap, n1, n2)
const char *cap;
int n1, n2;
char *
#if __STDC__
__parse_cap (char const *cap, ...)
#else
__parse_cap (cap, va_alist)
const char *cap;
va_dcl
#endif
{
va_list ap;
static char result[MAXRETURNSIZE];
int c, n;
char *dp;
int have_input;
#if __STDC__
va_start (ap, cap);
#else
va_start(ap);
#endif
if (cap == NULL)
goto err;
for (n = n1, dp = result; (c = *cap++) != '\0';) {
#ifdef DEBUG
__CTRACE ("__parse_cap: cap = %s\n", cap);
#endif
have_input = 0;
for (dp = result; (c = *cap++) != '\0';) {
if (c != '%') {
*dp++ = c;
continue;
}
switch (c = *cap++) {
case 'n':
if (!have_input) {
n = va_arg (ap, int);
have_input = 1;
#ifdef DEBUG
__CTRACE ("__parse_cap: %%n, val = %d\n", n);
#endif
}
n ^= 0140;
continue;
case 'd':
if (!have_input) {
n = va_arg (ap, int);
have_input = 1;
#ifdef DEBUG
__CTRACE ("__parse_cap: %%d, val = %d\n", n);
#endif
}
if (n < 10)
goto one;
if (n < 100)
goto two;
/* FALLTHROUGH */
case '3':
if (!have_input) {
n = va_arg (ap, int);
have_input = 1;
#ifdef DEBUG
__CTRACE ("__parse_cap: %%3, val = %d\n", n);
#endif
}
*dp++ = (n / 100) | '0';
n %= 100;
/* FALLTHROUGH */
case '2':
if (!have_input) {
n = va_arg (ap, int);
have_input = 1;
#ifdef DEBUG
__CTRACE ("__parse_cap: %%2, val = %d\n", n);
#endif
}
two: *dp++ = n / 10 | '0';
one: *dp++ = n % 10 | '0';
n = n2;
have_input = 0;
continue;
case '>':
if (!have_input) {
n = va_arg (ap, int);
have_input = 1;
#ifdef DEBUG
__CTRACE ("__parse_cap: %%>, val = %d\n", n);
#endif
}
if (n > *cap++)
n += *cap++;
else
cap++;
continue;
case '+':
if (!have_input) {
n = va_arg (ap, int);
have_input = 1;
#ifdef DEBUG
__CTRACE ("__parse_cap: %%+, val = %d\n", n);
#endif
}
n += *cap++;
/* FALLTHROUGH */
case '.':
if (!have_input) {
n = va_arg (ap, int);
have_input = 1;
#ifdef DEBUG
__CTRACE ("__parse_cap: %%., val = %d\n", n);
#endif
}
*dp++ = n;
have_input = 0;
continue;
case 'i':
if (!have_input) {
n = va_arg (ap, int);
have_input = 1;
#ifdef DEBUG
__CTRACE ("__parse_cap: %%i, val = %d\n", n);
#endif
}
n++;
continue;
case '%':
*dp++ = c;
continue;
case 'B':
if (!have_input) {
n = va_arg (ap, int);
have_input = 1;
#ifdef DEBUG
__CTRACE ("__parse_cap: %%B, val = %d\n", n);
#endif
}
n = (n / 10 << 4) + n % 10;
continue;
case 'D':
if (!have_input) {
n = va_arg (ap, int);
have_input = 1;
#ifdef DEBUG
__CTRACE ("__parse_cap: %%D, val = %d\n", n);
#endif
}
n = n - 2 * (n % 16);
continue;
/*
* XXX
* System V terminfo files have lots of extra gunk.
* The only one we've seen in scrolling strings is
* %pN, and it seems to work okay if we ignore it.
* The only other one we've seen in capability strings
* is %pN, and it seems to work okay if we ignore it.
*/
case 'p':
++cap;
@ -140,7 +241,9 @@ __tscroll(cap, n1, n2)
}
}
*dp = '\0';
va_end (ap);
return (result);
err: return ("curses: __tscroll failed");
err: va_end (ap);
return ("\0");
}