From 56ba3ed4b3b719c8a735dd1ef470c0c73efc95f4 Mon Sep 17 00:00:00 2001 From: Leonard den Ottolander Date: Wed, 15 Feb 2006 15:10:55 +0000 Subject: [PATCH] * slcommon.c, sldisplay.c, slerr.c, slgetkey.c, slmisc.c, slsignal.c, slsmg.c, slstring.c, sltermin.c, slutty.c, include/_slang.h, include/slang.h: Patch to slang-2.0.6 leaving local patches intact. --- slang/ChangeLog | 15 ++++++++ slang/include/_slang.h | 2 +- slang/include/slang.h | 6 ++-- slang/slcommon.c | 4 +-- slang/sldisply.c | 79 ++++++++++++++++++++++++++++++++---------- slang/slerr.c | 2 +- slang/slgetkey.c | 2 +- slang/slmisc.c | 23 +++++++++--- slang/slsignal.c | 2 +- slang/slsmg.c | 4 +-- slang/slstring.c | 2 +- slang/sltermin.c | 2 +- slang/slutty.c | 2 +- 13 files changed, 106 insertions(+), 39 deletions(-) diff --git a/slang/ChangeLog b/slang/ChangeLog index c606a417c..2d97b6f4b 100644 --- a/slang/ChangeLog +++ b/slang/ChangeLog @@ -1,3 +1,18 @@ +2006-02-15 Leonard den Ottolander + + * slcommon.c: Patch to slang-2.0.6 leaving local patches intact. + * sldisply.c: Likewise. + * slerr.c: Likewise. + * slgetkey.c: Likewise. + * slmisc.c: Likewise. + * slsignal.c: Likewise. + * slsmg.c: Likewise. + * slstring.c: Likewise. + * sltermin.c: Likewise. + * slutty.c: Likewise. + * include/_slang.h: Likewise. + * include/slang.h: Likewise. + 2006-02-01 Vladimir Nadvorknik * slcommon.c (utf8_enable_function): Use '==' instead of '=' for diff --git a/slang/include/_slang.h b/slang/include/_slang.h index 73fe28687..b92f24413 100644 --- a/slang/include/_slang.h +++ b/slang/include/_slang.h @@ -3,7 +3,7 @@ /* header file for S-Lang internal structures that users do not (should not) need. Use slang.h for that purpose. */ /* -Copyright (C) 2004, 2005 John E. Davis +Copyright (C) 2004, 2005, 2006 John E. Davis This file is part of the S-Lang Library. diff --git a/slang/include/slang.h b/slang/include/slang.h index a1b00796d..e9b72e4fe 100644 --- a/slang/include/slang.h +++ b/slang/include/slang.h @@ -2,7 +2,7 @@ #define DAVIS_SLANG_H_ /* -*- mode: C; mode: fold; -*- */ /* -Copyright (C) 2004, 2005 John E. Davis +Copyright (C) 2004, 2005, 2006 John E. Davis This file is part of the S-Lang Library. @@ -22,8 +22,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#define SLANG_VERSION 20005 -#define SLANG_VERSION_STRING "2.0.5" +#define SLANG_VERSION 20006 +#define SLANG_VERSION_STRING "2.0.6" /* #ifdef __DATE__ */ /* # define SLANG_VERSION_STRING SLANG_VERSION_STRING0 " " __DATE__ */ /* #else */ diff --git a/slang/slcommon.c b/slang/slcommon.c index f34f8992a..2ccd6131b 100644 --- a/slang/slcommon.c +++ b/slang/slcommon.c @@ -2,7 +2,7 @@ * links to the library. */ /* -Copyright (C) 2004, 2005 John E. Davis +Copyright (C) 2004, 2005, 2006 John E. Davis This file is part of the S-Lang Library. @@ -87,7 +87,7 @@ static int utf8_enable (int mode) (void) setlocale (LC_ALL, ""); -#ifdef HAVE_NL_LANGINFO +#ifdef HAVE_NL_LANGINFO_CODESET locale = nl_langinfo (CODESET); if ((locale != NULL) && (*locale)) { diff --git a/slang/sldisply.c b/slang/sldisply.c index 38fa1601f..909ef8739 100644 --- a/slang/sldisply.c +++ b/slang/sldisply.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2004, 2005 John E. Davis +Copyright (C) 2004, 2005, 2006 John E. Davis This file is part of the S-Lang Library. @@ -159,7 +159,7 @@ Brush_Info_Type; static Brush_Info_Type Brush_Table[JMAX_COLORS]; /* 0 if least significant bit is blue, not red */ -static int Is_Fg_BGR = 0; +/* static int Is_Fg_BGR = 0; */ static int Is_Bg_BGR = 0; #define COLOR_ARG(color, is_bgr) ((is_bgr) ? RGB_to_BGR[(color)&0x7] : (color)) static SLCONST int RGB_to_BGR[] = @@ -1508,16 +1508,35 @@ static void write_string_with_care (char *str) len = strlen (str); if (Automatic_Margins && (Cursor_r + 1 == SLtt_Screen_Rows)) { - if (len + (unsigned int) Cursor_c >= (unsigned int) SLtt_Screen_Cols) - { - /* For now, just do not write there. Later, something more - * sophisticated will be implemented. - */ - if (SLtt_Screen_Cols > Cursor_c) - len = SLtt_Screen_Cols - Cursor_c - 1; - else - len = 0; - } + if (_pSLtt_UTF8_Mode == 0) + { + if (len + (unsigned int) Cursor_c >= (unsigned int) SLtt_Screen_Cols) + { + /* For now, just do not write there. Later, something more + * sophisticated will be implemented. + */ + if (SLtt_Screen_Cols > Cursor_c) + len = SLtt_Screen_Cols - Cursor_c - 1; + else + len = 0; + } + } + else + { + unsigned int nchars = SLutf8_strlen((SLuchar_Type *)str, 1); + if (nchars + (unsigned int) Cursor_c >= (unsigned int) SLtt_Screen_Cols) + { + if (SLtt_Screen_Cols > Cursor_c) + { + char *p; + nchars = SLtt_Screen_Cols - Cursor_c - 1; + p = (char *)SLutf8_skip_chars((SLuchar_Type *) str, (SLuchar_Type *)(str + len), nchars, NULL, 1); + len = p - str; + } + else + len = 0; + } + } } tt_write (str, len); } @@ -2126,10 +2145,11 @@ static void get_color_info (void) static int Termcap_Initalized = 0; +/* #define USE_TERMCAP 1 */ #ifdef USE_TERMCAP /* Termcap based system */ static char Termcap_Buf[4096]; -static char Termcap_String_Buf[4096]; +/* static char Termcap_String_Buf[4096]; */ /* static char *Termcap_String_Ptr; */ extern char *tgetstr(char *, char **); extern int tgetent(char *, char *); @@ -2181,14 +2201,22 @@ char *SLtt_tgetstr (char *cap) { char *s; #ifdef USE_TERMCAP - char *tmp_area; + char area_buf[4096]; + char *area; #endif if (Termcap_Initalized == 0) return NULL; #ifdef USE_TERMCAP - tmp_area = (char*) &Termcap_String_Buf; - s = tgetstr (cap, &tmp_area); + /* tmp_area = &Termcap_String_Buf; */ + area = area_buf; + s = tgetstr (cap, &area); + if (area > area_buf + sizeof(area_buf)) + { + SLang_exit_error ("\ +The termcap tgetstr appears to have overflowed a buffer.\n\ +The integrity of this program has been violated.\n"); + } #else s = _pSLtt_tigetstr (Terminfo, cap); #endif @@ -2200,7 +2228,20 @@ char *SLtt_tgetstr (char *cap) if (0 == strcmp (cap, "ac")) return s; - return fixup_tgetstr (s); + s = fixup_tgetstr (s); +#ifdef USE_TERMCAP + if ((s >= area_buf) && (s < area_buf + sizeof(area_buf))) + { + /* It looks like tgetstr placed the object in the buffer and + * returned a pointer to that buffer. So, we have to make a + * copy of it. + * + * Yes, this introduces a leak... + */ + s = SLmake_string (s); + } +#endif + return s; } int SLtt_tgetnum (char *s) @@ -2530,13 +2571,13 @@ int SLtt_initialize (char *term) if (Color_Fg_Str == NULL) { Color_Fg_Str = SLtt_tgetstr ("Sf"); /* setf */ - Is_Fg_BGR = (Color_Fg_Str != NULL); + /* Is_Fg_BGR = (Color_Fg_Str != NULL); */ } Color_Bg_Str = SLtt_tgetstr ("AB"); /* ANSI setbf */ if (Color_Bg_Str == NULL) { Color_Bg_Str = SLtt_tgetstr ("Sb"); /* setb */ - Is_Bg_BGR = (Color_Bg_Str != NULL); + /* Is_Fg_BGR = (Color_Bg_Str != NULL); */ } if ((Max_Terminfo_Colors = SLtt_tgetnum ("Co")) < 0) diff --git a/slang/slerr.c b/slang/slerr.c index fcf4aa208..c1ea2f00c 100644 --- a/slang/slerr.c +++ b/slang/slerr.c @@ -1,6 +1,6 @@ /* error handling common to all routines. */ /* -Copyright (C) 2004, 2005 John E. Davis +Copyright (C) 2004, 2005, 2006 John E. Davis This file is part of the S-Lang Library. diff --git a/slang/slgetkey.c b/slang/slgetkey.c index 58773c9fc..48ae3e1fb 100644 --- a/slang/slgetkey.c +++ b/slang/slgetkey.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2004, 2005 John E. Davis +Copyright (C) 2004, 2005, 2006 John E. Davis This file is part of the S-Lang Library. diff --git a/slang/slmisc.c b/slang/slmisc.c index 307c7ddcc..bdfac34a5 100644 --- a/slang/slmisc.c +++ b/slang/slmisc.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2004, 2005 John E. Davis +Copyright (C) 2004, 2005, 2006 John E. Davis This file is part of the S-Lang Library. @@ -39,9 +39,11 @@ char *_pSLexpand_escaped_char(char *p, SLwchar_Type *ch, int *isunicodep) SLwchar_Type num, base = 0; SLwchar_Type ch1; int isunicode; + int needs_brace; ch1 = *p++; isunicode = 0; + needs_brace = 0; switch (ch1) { @@ -70,6 +72,9 @@ char *_pSLexpand_escaped_char(char *p, SLwchar_Type *ch, int *isunicodep) num = 0; break; + case 'u': + isunicode = 1; + /* drop */ case 'x': /* hex */ base = 16; max = '9'; @@ -84,10 +89,18 @@ char *_pSLexpand_escaped_char(char *p, SLwchar_Type *ch, int *isunicodep) i++; if (p[i] != '}') { - SLang_verror (SL_UNICODE_ERROR, "Escaped unicode character missing closing }."); + SLang_verror (SL_SYNTAX_ERROR, "Escaped character missing closing }."); return NULL; } - isunicode = 1; + /* The meaning of \x{...} is mode dependent. If in UTF-8 mode, then + * \x{...} always generates a unicode character. Otherwise, the + * meaning of \x{...} depends upon the number of characters enclosed + * by the brace. If there are less than 3, then assume no unicode. + * If greater than or equal to 3, then assume unicode. + */ + if (isunicode == 0) /* \x... */ + isunicode = _pSLinterp_UTF8_Mode || (i > 2); + needs_brace = 1; } break; } @@ -112,11 +125,11 @@ char *_pSLexpand_escaped_char(char *p, SLwchar_Type *ch, int *isunicodep) p++; } - if (isunicode) + if (needs_brace) { if (*p != '}') { - SLang_verror (SL_UNICODE_ERROR, "Malformed Escaped unicode character."); + SLang_verror (SL_SYNTAX_ERROR, "Malformed escaped character."); return NULL; } p++; diff --git a/slang/slsignal.c b/slang/slsignal.c index e87fdb37c..276d6bbd6 100644 --- a/slang/slsignal.c +++ b/slang/slsignal.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2004, 2005 John E. Davis +Copyright (C) 2004, 2005, 2006 John E. Davis This file is part of the S-Lang Library. diff --git a/slang/slsmg.c b/slang/slsmg.c index 253ae9f42..b8f38e268 100644 --- a/slang/slsmg.c +++ b/slang/slsmg.c @@ -21,7 +21,7 @@ Screen_Type; #define TRASHED 0x2 static int Screen_Trashed; -Screen_Type SL_Screen[SLTT_MAX_SCREEN_ROWS]; +static Screen_Type SL_Screen[SLTT_MAX_SCREEN_ROWS]; static int Start_Col, Start_Row; static unsigned int Screen_Cols, Screen_Rows; static int This_Row, This_Col; @@ -1614,7 +1614,6 @@ void SLsmg_draw_object (int r, int c, SLwchar_Type object) void SLsmg_draw_hline (unsigned int n) { static unsigned char hbuf[16]; - int count; int cmin, cmax; int final_col = This_Col + (int) n; int save_color; @@ -1630,7 +1629,6 @@ void SLsmg_draw_hline (unsigned int n) } n = (unsigned int)(cmax - cmin); - count = n / 16; save_color = This_Color; This_Color |= SLSMG_ACS_MASK; diff --git a/slang/slstring.c b/slang/slstring.c index ae8dd4af9..67b57523f 100644 --- a/slang/slstring.c +++ b/slang/slstring.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2004, 2005 John E. Davis +Copyright (C) 2004, 2005, 2006 John E. Davis This file is part of the S-Lang Library. diff --git a/slang/sltermin.c b/slang/sltermin.c index 72362dc40..4ecf7baa8 100644 --- a/slang/sltermin.c +++ b/slang/sltermin.c @@ -3,7 +3,7 @@ */ /* -Copyright (C) 2004, 2005 John E. Davis +Copyright (C) 2004, 2005, 2006 John E. Davis This file is part of the S-Lang Library. diff --git a/slang/slutty.c b/slang/slutty.c index f96628e0d..da07d9851 100644 --- a/slang/slutty.c +++ b/slang/slutty.c @@ -1,6 +1,6 @@ /* slutty.c --- Unix Low level terminal (tty) functions for S-Lang */ /* -Copyright (C) 2004, 2005 John E. Davis +Copyright (C) 2004, 2005, 2006 John E. Davis This file is part of the S-Lang Library.