1
1

* sldisply.c (SLtt_initialize): Fix typo. Change Is_Bg_BGR

to Is_Fg_BGR.  (SLtt_goto_rc): Disable cursor movement optimizations
        for qansi-m consoles. Needed on QNX Neutrino. (SLtt_initialize): Init
        QANSI_Console variable. (SLtt_erase_line): Use tt_write() instead
        tt_write_string(). (SLtt_cls): Use tt_write() instead tt_write_string().
        (SLtt_tgetstr): Fix warning.
        * slmisc.c: Trimmed down for use in GNU Midnight Commander.
        * sltermin.c (_pSLtt_tigetent): Avoid strncpy, home_ti is 1K long and
        obody really needs it whole cleared. Fix possible off-by-one error.
        * include/slang.h: Define __unix__ if __MACH__, __NetBSD__,  _AIX is
        defined.
Этот коммит содержится в:
Andrew V. Samoilov 2006-01-13 19:49:23 +00:00
родитель adc2d181c7
Коммит 5c83819e50
5 изменённых файлов: 52 добавлений и 642 удалений

@ -1,3 +1,17 @@
2006-01-14 Pavel Shirshov <me@pavelsh.pp.ru>
* sldisply.c (SLtt_initialize): Fix typo. Change Is_Bg_BGR
to Is_Fg_BGR. (SLtt_goto_rc): Disable cursor movement optimizations
for qansi-m consoles. Needed on QNX Neutrino. (SLtt_initialize): Init
QANSI_Console variable. (SLtt_erase_line): Use tt_write() instead
tt_write_string(). (SLtt_cls): Use tt_write() instead tt_write_string().
(SLtt_tgetstr): Fix warning.
* slmisc.c: Trimmed down for use in GNU Midnight Commander.
* sltermin.c (_pSLtt_tigetent): Avoid strncpy, home_ti is 1K long and
obody really needs it whole cleared. Fix possible off-by-one error.
* include/slang.h: Define __unix__ if __MACH__, __NetBSD__, _AIX is
defined.
2005-11-28 Pavel Roskin <proski@gnu.org>
* slvideo.c: Remove, it's only used by the obsolete PC port.

@ -43,7 +43,7 @@ USA.
# endif
#endif /* __watcomc__ */
#if defined(unix) || defined(__unix)
#if defined(unix) || defined(__unix) || defined (_AIX) || defined(__NetBSD__) || defined(__MACH__)
# ifndef __unix__
# define __unix__ 1
# endif

@ -134,6 +134,7 @@ static char *Reset_Color_String;
static int Is_Color_Terminal = 0;
static int Linux_Console;
static int QANSI_Console;
static int Mouse_Mode = -1;
/* The following comment is nolonger valid, but is here in case there are
@ -734,12 +735,25 @@ void SLtt_goto_rc(int r, int c)
if (Cursor_c == c) return;
if (Cursor_c == c + 1)
{
s = buf;
*s++ = '\b'; *s = 0;
s = buf;
/* cursor movement optimizations, like backspace
doesn't work as needed on qansi-m consoles when
current table is not a G0, so we'll disable it. */
if (!QANSI_Console)
{
s = buf;
*s++ = '\b'; *s = 0;
s = buf;
}
else
{
/* do the generic cursor positioning,
without an optimization */
s = NULL;
}
}
}
else if (c == 0)
else if ((c == 0) && (!QANSI_Console)) /* the same things
for the qansi-m console limitation */
{
s = buf;
if ((Cursor_Set != 1) || (Cursor_c != 0)) *s++ = '\r';
@ -753,8 +767,9 @@ void SLtt_goto_rc(int r, int c)
}
/* Will fail on VMS */
#ifndef VMS
else if (SLtt_Newline_Ok && (Cursor_Set == 1) &&
(Cursor_c >= c) && (c + 3 > Cursor_c))
else if ((SLtt_Newline_Ok && (Cursor_Set == 1) &&
(Cursor_c >= c) && (c + 3 > Cursor_c)) &&
(!QANSI_Console))
{
s = buf;
while (n--) *s++ = '\n';
@ -794,7 +809,7 @@ void SLtt_erase_line (void)
Cursor_Set = 1; Cursor_c = 0;
SLtt_del_eol();
/* Put the cursor back at the beginning of the line */
tt_write_string("\r");
tt_write ("\r", 1);
Cursor_Set = 1; Cursor_c = 0;
}
@ -865,7 +880,7 @@ void SLtt_cls (void)
if (Reset_Color_String != NULL)
tt_write_string (Reset_Color_String);
else
tt_write_string ("\033[0m\033[m");
tt_write ("\033[0m\033[m", 7);
}
SLtt_normal_video();
@ -2172,7 +2187,7 @@ char *SLtt_tgetstr (char *cap)
return NULL;
#ifdef USE_TERMCAP
tmp_area = &Termcap_String_Buf;
tmp_area = (char*) &Termcap_String_Buf;
s = tgetstr (cap, &tmp_area);
#else
s = _pSLtt_tigetstr (Terminfo, cap);
@ -2302,6 +2317,8 @@ int SLtt_initialize (char *term)
# endif
);
QANSI_Console = !strncmp (term, "qansi-m", 7);
t = term;
if (strcmp(t, "vt52") && (*t++ == 'v') && (*t++ == 't')
@ -2519,7 +2536,7 @@ int SLtt_initialize (char *term)
if (Color_Bg_Str == NULL)
{
Color_Bg_Str = SLtt_tgetstr ("Sb"); /* setb */
Is_Fg_BGR = (Color_Bg_Str != NULL);
Is_Bg_BGR = (Color_Bg_Str != NULL);
}
if ((Max_Terminfo_Colors = SLtt_tgetnum ("Co")) < 0)

@ -3,6 +3,8 @@ Copyright (C) 2004, 2005 John E. Davis
This file is part of the S-Lang Library.
Trimmed down for use in GNU Midnight Commander.
The S-Lang Library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
@ -22,63 +24,9 @@ USA.
#define _GNU_SOURCE
#include "slinclud.h"
#include <ctype.h>
#include "slang.h"
#include "_slang.h"
char *SLmake_string(char *str)
{
return SLmake_nstring(str, strlen (str));
}
char *SLmake_nstring (char *str, unsigned int n)
{
char *ptr;
if (NULL == (ptr = SLmalloc(n + 1)))
{
return NULL;
}
SLMEMCPY (ptr, str, n);
ptr[n] = 0;
return(ptr);
}
void SLmake_lut (unsigned char *lut, unsigned char *range, unsigned char reverse)
{
/* register unsigned char *l = lut, *lmax = lut + 256; */
int i, r1, r2;
memset ((char *)lut, reverse, 256);
/* while (l < lmax) *l++ = reverse; */
reverse = !reverse;
r1 = *range++;
while (r1)
{
r2 = *range++;
if ((r2 == '-') && (*range != 0))
{
r2 = *range++;
for (i = r1; i <= r2; i++) lut[i] = reverse;
r1 = *range++;
continue;
}
lut[r1] = reverse;
r1 = r2;
}
}
char *_pSLskip_whitespace (char *s)
{
while (isspace (*s))
s++;
return s;
}
int SLang_Version = SLANG_VERSION;
/*
* This function assumes that the initial \ char has been removed.
@ -179,575 +127,3 @@ char *_pSLexpand_escaped_char(char *p, SLwchar_Type *ch, int *isunicodep)
*ch = num;
return p;
}
/* s and t could represent the same space. Note: the space for s is
* assumed to be at least tmax-t bytes.
*/
int SLexpand_escaped_string (char *s, char *t, char *tmax, int utf8_encode)
{
if (utf8_encode == -1)
utf8_encode = _pSLinterp_UTF8_Mode;
while (t < tmax)
{
SLwchar_Type wch;
char *s1;
int isunicode;
char ch = *t++;
if (ch != '\\')
{
*s++ = ch;
continue;
}
if (NULL == (t = _pSLexpand_escaped_char (t, &wch, &isunicode)))
{
*s = 0;
return -1;
}
/* As discussed above, the escaped representation is larger than the
* encoding.
*/
if ((isunicode == 0)
#if 0
&& ((wch < 127)
|| (utf8_encode == 0))
#endif
)
{
*s++ = (char) wch;
continue;
}
s1 = (char *)SLutf8_encode (wch, (SLuchar_Type *)s, 6);
if (s1 == NULL)
{
SLang_verror (SL_INVALID_UTF8, "Unable to UTF-8 encode 0x%lX\n", (unsigned long)wch);
*s = 0;
return -1;
}
s = s1;
}
*s = 0;
return 0;
}
int SLextract_list_element (char *list, unsigned int nth, char delim,
char *elem, unsigned int buflen)
{
char *el, *elmax;
char ch;
while (nth > 0)
{
while ((0 != (ch = *list)) && (ch != delim))
list++;
if (ch == 0) return -1;
list++;
nth--;
}
el = elem;
elmax = el + (buflen - 1);
while ((0 != (ch = *list)) && (ch != delim) && (el < elmax))
*el++ = *list++;
*el = 0;
return 0;
}
int SLvsnprintf (char *buf, unsigned int buflen, char *fmt, va_list ap)
{
#ifdef HAVE_VSNPRINTF
int status;
status = vsnprintf(buf, buflen, fmt, ap);
if ((unsigned int)status >= buflen)
status = -1;
return status;
#else
unsigned int len;
/* On some systems vsprintf returns useless information. So, punt */
vsprintf (buf, fmt, ap);
len = strlen (buf);
if (len >= buflen)
{
SLang_exit_error ("\
Your system lacks the vsnprintf system call and vsprintf overflowed a buffer.\n\
The integrity of this program has been violated.\n");
return EOF; /* NOT reached */
}
return (int)len;
#endif
}
int SLsnprintf (char *buf, unsigned int buflen, char *fmt, ...)
{
int status;
va_list ap;
va_start (ap, fmt);
status = SLvsnprintf (buf, buflen, fmt, ap);
va_end (ap);
return status;
}
typedef struct _Cleanup_Function_Type
{
struct _Cleanup_Function_Type *next;
void (*f)(void);
}
Cleanup_Function_Type;
static Cleanup_Function_Type *Cleanup_Function_List;
static void cleanup_slang (void)
{
while (Cleanup_Function_List != NULL)
{
Cleanup_Function_Type *next = Cleanup_Function_List->next;
(*Cleanup_Function_List->f)();
SLfree ((char *) Cleanup_Function_List);
Cleanup_Function_List = next;
}
}
#ifndef HAVE_ATEXIT
# ifdef HAVE_ON_EXIT
static void on_exit_cleanup_slang (int arg_unused)
{
(void) arg_unused;
cleanup_slang ();
}
# endif
#endif
int SLang_add_cleanup_function (void (*f)(void))
{
Cleanup_Function_Type *l;
l = (Cleanup_Function_Type *) SLmalloc (sizeof (Cleanup_Function_Type));
if (l == NULL)
return -1;
l->f = f;
l->next = Cleanup_Function_List;
if (Cleanup_Function_List == NULL)
{
#ifdef HAVE_ATEXIT
(void) atexit (cleanup_slang);
#else
# ifdef HAVE_ON_EXIT
(void) on_exit (on_exit_cleanup_slang, 0);
# endif
#endif
}
Cleanup_Function_List = l;
return 0;
}
int SLang_guess_type (char *t)
{
char *p;
register char ch;
int modifier;
#define MODIFIER_H 0x01
#define MODIFIER_L 0x02
#define MODIFIER_U 0x04
#define MODIFIER_LL 0x08
#define MODIFIER_SIZE_MASK 0x0F
#define MODIFIER_HEX 0x10
modifier = 0;
if (*t == '-') t++;
p = t;
#if SLANG_HAS_FLOAT
if (*p != '.')
{
#endif
while ((*p >= '0') && (*p <= '9')) p++;
if (t == p) return (SLANG_STRING_TYPE);
if ((*p == 'x') && (p == t + 1)) /* 0x?? */
{
modifier |= MODIFIER_HEX;
p++;
while (ch = *p,
((ch >= '0') && (ch <= '9'))
|| (((ch | 0x20) >= 'a') && ((ch | 0x20) <= 'f'))) p++;
}
/* Now look for U, H, L, LL, UH, UL, ULL, modifiers */
ch = *p | 0x20;
if (ch == 'u')
{
modifier |= MODIFIER_U;
p++;
ch = *p | 0x20;
}
if (ch == 'h')
{
modifier |= MODIFIER_H;
p++;
ch = *p | 0x20;
}
else if (ch == 'l')
{
p++;
ch = *p | 0x20;
if (ch == 'l')
{
modifier |= MODIFIER_LL;
p++;
ch = *p | 0x20;
}
else
modifier |= MODIFIER_L;
}
if ((ch == 'u') && (0 == (modifier & MODIFIER_U)))
{
modifier |= MODIFIER_U;
p++;
}
if (*p == 0) switch (modifier & MODIFIER_SIZE_MASK)
{
case 0:
return SLANG_INT_TYPE;
case MODIFIER_H:
return SLANG_SHORT_TYPE;
case MODIFIER_L:
return SLANG_LONG_TYPE;
case MODIFIER_U:
return SLANG_UINT_TYPE;
case MODIFIER_U|MODIFIER_H:
return SLANG_USHORT_TYPE;
case MODIFIER_U|MODIFIER_L:
return SLANG_ULONG_TYPE;
case MODIFIER_LL:
return SLANG_LLONG_TYPE;
case MODIFIER_U|MODIFIER_LL:
return SLANG_ULLONG_TYPE;
default:
return SLANG_STRING_TYPE;
}
if (modifier)
return SLANG_STRING_TYPE;
#if SLANG_HAS_FLOAT
}
/* now down to double case */
if (*p == '.')
{
p++;
while ((*p >= '0') && (*p <= '9')) p++;
}
if (*p == 0) return(SLANG_DOUBLE_TYPE);
if ((*p != 'e') && (*p != 'E'))
{
# if SLANG_HAS_COMPLEX
if (((*p == 'i') || (*p == 'j'))
&& (p[1] == 0))
return SLANG_COMPLEX_TYPE;
# endif
if (((*p | 0x20) == 'f') && (p[1] == 0))
return SLANG_FLOAT_TYPE;
return SLANG_STRING_TYPE;
}
p++;
if ((*p == '-') || (*p == '+')) p++;
while ((*p >= '0') && (*p <= '9')) p++;
if (*p != 0)
{
# if SLANG_HAS_COMPLEX
if (((*p == 'i') || (*p == 'j'))
&& (p[1] == 0))
return SLANG_COMPLEX_TYPE;
# endif
if (((*p | 0x20) == 'f') && (p[1] == 0))
return SLANG_FLOAT_TYPE;
return SLANG_STRING_TYPE;
}
return SLANG_DOUBLE_TYPE;
#else
return SLANG_STRING_TYPE;
#endif /* SLANG_HAS_FLOAT */
}
static int hex_atoul (unsigned char *s, unsigned long *ul)
{
unsigned char ch;
unsigned long value;
int base;
unsigned int num_processed;
num_processed = 0;
if (*s != '0')
base = 10;
else
{
s++; /* skip the leading 0 */
/* look for 'x' which indicates hex */
if ((*s | 0x20) == 'x')
{
base = 16;
s++;
if (*s == 0)
{
SLang_set_error (SL_SYNTAX_ERROR);
return -1;
}
}
else
{
base = 8;
num_processed++;
}
}
value = 0;
while ((ch = *s++) != 0)
{
char ch1 = ch | 0x20;
switch (ch1)
{
default:
SLang_set_error (SL_SYNTAX_ERROR);
return -1;
case 'u':
case 'l':
case 'h':
if (num_processed == 0)
{
SLang_set_error (SL_SYNTAX_ERROR);
return -1;
}
*ul = value;
return 0;
case '8':
case '9':
if (base == 8)
{
SLang_verror (SL_SYNTAX_ERROR, "8 or 9 are not permitted in an octal number");
return -1;
}
/* drop */
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
ch1 -= '0';
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
if (base != 16)
{
SLang_verror (SL_SYNTAX_ERROR, "Only digits may appear in an octal or decimal number");
return -1;
}
ch1 = (ch1 - 'a') + 10;
break;
}
value = value * base + ch1;
num_processed++;
}
*ul = value;
return 0;
}
#ifdef HAVE_LONG_LONG
static int hex_atoull (unsigned char *s, unsigned long long *ul)
{
unsigned char ch;
unsigned long long value;
int base;
if (*s != '0')
base = 10;
else
{
s++; /* skip the leading 0 */
/* look for 'x' which indicates hex */
if ((*s | 0x20) == 'x')
{
base = 16;
s++;
if (*s == 0)
{
SLang_set_error (SL_SYNTAX_ERROR);
return -1;
}
}
else base = 8;
}
value = 0;
while ((ch = *s++) != 0)
{
char ch1 = ch | 0x20;
switch (ch1)
{
default:
SLang_set_error (SL_SYNTAX_ERROR);
return -1;
case 'u':
case 'l':
*ul = value;
return 0;
case '8':
case '9':
if (base == 8)
{
SLang_verror (SL_SYNTAX_ERROR, "8 or 9 are not permitted in an octal number");
return -1;
}
/* drop */
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
ch1 -= '0';
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
if (base != 16)
{
SLang_verror (SL_SYNTAX_ERROR, "Only digits may appear in an octal or decimal number");
return -1;
}
ch1 = (ch1 - 'a') + 10;
break;
}
value = value * base + ch1;
}
*ul = value;
return 0;
}
#endif /* HAVE_LONG_LONG */
/* Note: These routines do not check integer overflow. I would use the C
* library functions atol and atoul but some implementations check overflow
* and some do not. The following implementations provide a consistent
* behavior.
*/
static unsigned char *get_sign (unsigned char *s, int *signp)
{
s = (unsigned char *) _pSLskip_whitespace ((char *)s);
if (*s == '-')
{
*signp = -1;
s++;
}
else
{
*signp = 1;
if (*s == '+') s++;
}
return s;
}
unsigned long SLatoul (unsigned char *s)
{
int sign;
unsigned long value;
s = get_sign (s, &sign);
if (-1 == hex_atoul (s, &value))
return (unsigned long) -1;
if (sign == -1)
value = (unsigned long)-1L * value;
return value;
}
long SLatol (unsigned char *s)
{
int sign;
unsigned long value;
s = get_sign (s, &sign);
if (-1 == hex_atoul (s, &value))
return -1L;
if (sign == -1)
return (long)(-1L * value);
return (long) value;
}
int SLatoi (unsigned char *s)
{
return (int) SLatol (s);
}
#if HAVE_LONG_LONG
long long SLatoll (unsigned char *s)
{
int sign;
unsigned long long value;
s = get_sign (s, &sign);
if (-1 == hex_atoull (s, &value))
return -1LL;
if (sign == -1)
return (long long)(-1LL * value);
return (long long) value;
}
unsigned long long SLatoull (unsigned char *s)
{
int sign;
unsigned long long value;
s = get_sign (s, &sign);
if (-1 == hex_atoull (s, &value))
return (unsigned long long) -1;
if (sign == -1)
return (unsigned long long)(-1LL * value);
return value;
}
#endif

@ -285,9 +285,12 @@ SLterminfo_Type *_pSLtt_tigetent (char *term)
if (NULL != (home = _pSLsecure_getenv ("HOME")))
{
strncpy (home_ti, home, sizeof (home_ti) - 11);
home_ti [sizeof(home_ti) - 11] = 0;
strcat (home_ti, "/.terminfo");
size_t len = strlen (home);
if (len > sizeof (home_ti) - sizeof ("/.terminfo"))
len = sizeof (home_ti) - sizeof ("/.terminfo");
memcpy (home_ti, home, len);
memcpy (home_ti + len, "/.terminfo", sizeof ("/.terminfo"));
Terminfo_Dirs [0] = home_ti;
}
@ -301,7 +304,7 @@ SLterminfo_Type *_pSLtt_tigetent (char *term)
if (*tidir == 0)
break; /* last one */
if (sizeof (file) > strlen (tidir) + 4 + strlen (term))
if (sizeof (file) >= strlen (tidir) + 4 + strlen (term))
{
sprintf (file, "%s/%c/%s", tidir, *term, term);
if (NULL != (fp = open_terminfo (file, ti)))