View | Details | Raw Unified
Collapse All | Expand All

(-) slang-1.4.9/src/sldisply.c.orig (-5 / +535 lines)
 Lines 23-26    Link Here 
# include <memory.h>
# include <memory.h>
#endif
#endif
#define UTF8 1
#ifdef UTF8
#include <wchar.h>
#include <limits.h>
#endif /* UTF8 */
#endif				       /* _SLANG_INCLUDE_H_ */
#endif				       /* _SLANG_INCLUDE_H_ */
 Lines 1239-1248    Link Here 
extern int SLtt_Msdos_Cheap_Video;
extern int SLtt_Msdos_Cheap_Video;
#endif
#endif
#define UTF8 1
#ifdef UTF8
typedef int SLsmg_Char_Type;
#define SLSMG_EXTRACT_CHAR(x) ((x) & 0xFFFFFF)
#define SLSMG_EXTRACT_COLOR(x) (((x)>>24)&0xFF)
#define SLSMG_BUILD_CHAR(ch,color) (((SLsmg_Char_Type)(wchar_t)(ch))|((color)<<24))
#define SLSMG_NOCHAR 1
#else
typedef unsigned short SLsmg_Char_Type;
typedef unsigned short SLsmg_Char_Type;
#define SLSMG_EXTRACT_CHAR(x) ((x) & 0xFF)
#define SLSMG_EXTRACT_CHAR(x) ((x) & 0xFF)
#define SLSMG_EXTRACT_COLOR(x) (((x)>>8)&0xFF)
#define SLSMG_EXTRACT_COLOR(x) (((x)>>8)&0xFF)
#define SLSMG_BUILD_CHAR(ch,color) (((SLsmg_Char_Type)(unsigned char)(ch))|((color)<<8))
#define SLSMG_BUILD_CHAR(ch,color) (((SLsmg_Char_Type)(unsigned char)(ch))|((color)<<8))
#endif /* UTF8 */
extern int SLtt_flush_output (void);
extern int SLtt_flush_output (void);
extern void SLtt_set_scroll_region(int, int);
extern void SLtt_set_scroll_region(int, int);
 Lines 1334-1340    Link Here 
/*{{{ SLsmg Screen Management Functions */
/*{{{ SLsmg Screen Management Functions */
#ifdef UTF8
extern void SLsmg_fill_region (int, int, unsigned int, unsigned int, wchar_t);
#else
extern void SLsmg_fill_region (int, int, unsigned int, unsigned int, unsigned char);
extern void SLsmg_fill_region (int, int, unsigned int, unsigned int, unsigned char);
#endif /* UTF8 */
extern void SLsmg_set_char_set (int);
extern void SLsmg_set_char_set (int);
#ifndef IBMPC_SYSTEM
#ifndef IBMPC_SYSTEM
extern int SLsmg_Scroll_Hash_Border;
extern int SLsmg_Scroll_Hash_Border;
 Lines 1351-1357    Link Here 
extern void SLsmg_vprintf (char *, va_list);
extern void SLsmg_vprintf (char *, va_list);
extern void SLsmg_write_string (char *);
extern void SLsmg_write_string (char *);
extern void SLsmg_write_nstring (char *, unsigned int);
extern void SLsmg_write_nstring (char *, unsigned int);
#ifdef UTF8
extern void SLsmg_write_char (wchar_t);
extern void SLsmg_write_nwchars (wchar_t *, unsigned int);
#else
extern void SLsmg_write_char (char);
extern void SLsmg_write_char (char);
#endif /* UTF8 */
extern void SLsmg_write_nchars (char *, unsigned int);
extern void SLsmg_write_nchars (char *, unsigned int);
extern void SLsmg_write_wrapped_string (char *, int, int, unsigned int, unsigned int, int);
extern void SLsmg_write_wrapped_string (char *, int, int, unsigned int, unsigned int, int);
extern void SLsmg_cls (void);
extern void SLsmg_cls (void);
 Lines 440-459    Link Here 
static int do_newline (SLcurses_Window_Type *w)
static int do_newline (SLcurses_Window_Type *w)
{
{
   w->_curx = 0;
   /* w->_curx = 0; */
   w->_cury += 1;
   w->_cury += 1;
   if (w->_cury >= w->scroll_max)
   if (w->_cury >= w->scroll_max)
     {
     {
	w->_cury = w->scroll_max - 1;
	w->_cury = w->scroll_max - 1;
	if (w->scroll_ok)
	if (w->scroll_ok) {
	  w->_curx = 0;
	  SLcurses_wscrl (w, 1);
	  SLcurses_wscrl (w, 1);
	}
     }
     }
   else
     w->_curx = 0;
   
   return 0;
}
#ifdef UTF8
static int SLcurses_waddch1 (SLcurses_Window_Type *win,
			     wchar_t ch, int color)
{
   SLsmg_Char_Type *b, *bmin, *bmax, *c;
   int k;
   if (win == NULL) return -1;
   if (win->_cury >= win->nrows)
     {
	/* Curses seems to move current postion to top of window. */
	win->_cury = win->_curx = 0;
	return -1;
     }
   win->modified = 1;
   if (ch < ' ')
     {
	if (ch == '\n')
	  {
	     SLcurses_wclrtoeol (win);
	     return do_newline (win);
	  }
	if (ch == '\r')
	  {
	     win->_curx = 0;
	     return 0;
	  }
	if (ch == '\b')
	  {
	     if (win->_curx > 0)
	       win->_curx--;
	     return 0;
	  }
	/* HACK HACK!!!! */
	if (ch == '\t') ch = ' ';
     }
   k = wcwidth(ch);
   if (!k)
     return 0; /* ignore combining characters for now */
   if (k > win->ncols)
     return 0; /* character wider than window */
   if (win->_curx + k > win->ncols) {
     if (win->_curx < win->ncols)
       SLcurses_wclrtoeol(win);
     do_newline (win);
   }
   bmin = win->lines[win->_cury];
   b = bmin + win->_curx;
   bmax = bmin + win->ncols;
   /* Remove overwritten chars to left */
   if (*b == SLSMG_NOCHAR) {
     for (c = b - 1; c >= bmin && *c == SLSMG_NOCHAR; c--)
       *c = SLSMG_BUILD_CHAR(' ',SLSMG_EXTRACT_COLOR(*c));
     if (c >= bmin)
       *c = SLSMG_BUILD_CHAR(' ',SLSMG_EXTRACT_COLOR(*c));
   }
   *b = SLSMG_BUILD_CHAR(ch,color);
   win->_curx += k;
   while (--k > 0)
     *++b = SLSMG_NOCHAR;
   /* Remove overwritten chars to right */
   for (c = b + 1; c < bmax && *c == SLSMG_NOCHAR; c++)
     *c = SLSMG_BUILD_CHAR(' ',SLSMG_EXTRACT_COLOR(*c));
   return 0;
   return 0;
}
}
int SLcurses_waddch (SLcurses_Window_Type *win, SLtt_Char_Type attr)
int SLcurses_waddch (SLcurses_Window_Type *win, SLtt_Char_Type attr)
{
{
   SLsmg_Char_Type ch, color;
   if (win == NULL) return -1;
   ch = SLSMG_EXTRACT_CHAR(attr);
   if (attr == ch)
     color = win->color;
   else
     {
	/* hack to pick up the default color for graphics chars */
	if (((attr & A_COLOR) == 0) && ((attr & A_ALTCHARSET) != 0))
	  {
	     /* FIXME: priority=medium: Use SLSMG_?? instead of << */
	     attr |= win->color << 8;
	  }
	color = map_attr_to_object (attr);
     }
   return SLcurses_waddch1 (win, ch, color);
}
#else
int SLcurses_waddch (SLcurses_Window_Type *win, SLtt_Char_Type attr)
{
   SLsmg_Char_Type *b, ch;
   SLsmg_Char_Type *b, ch;
   SLsmg_Char_Type color;
   SLsmg_Char_Type color;
 Lines 518-523    Link Here 
   return 0;
   return 0;
}
}
#endif /* UTF8 */
int SLcurses_wnoutrefresh (SLcurses_Window_Type *w)
int SLcurses_wnoutrefresh (SLcurses_Window_Type *w)
{
{
 Lines 577-583    Link Here 
int SLcurses_wclrtoeol (SLcurses_Window_Type *w)
int SLcurses_wclrtoeol (SLcurses_Window_Type *w)
{
{
#ifdef UTF8
   SLsmg_Char_Type *b, *bmin, *bmax, *c;
#else
   SLsmg_Char_Type *b, *bmax;
   SLsmg_Char_Type *b, *bmax;
#endif /* UTF8 */
   SLsmg_Char_Type blank;
   SLsmg_Char_Type blank;
   if (w == NULL) return -1;
   if (w == NULL) return -1;
 Lines 588-596    Link Here 
   blank = SLSMG_BUILD_CHAR(' ',w->color);
   blank = SLSMG_BUILD_CHAR(' ',w->color);
#ifdef UTF8
   bmin = w->lines[w->_cury];
   b = bmin + w->_curx;
   bmax = bmin + w->ncols;
   /* Remove overwritten chars to left */
   if (b < bmax && *b == SLSMG_NOCHAR) {
     for (c = b - 1; c >= bmin && *c == SLSMG_NOCHAR; c--)
       *c = SLSMG_BUILD_CHAR(' ',SLSMG_EXTRACT_COLOR(*c));
     if (c >= bmin) 
       *c = SLSMG_BUILD_CHAR(' ',SLSMG_EXTRACT_COLOR(*c));
   }
#else
   b = w->lines[w->_cury];
   b = w->lines[w->_cury];
   bmax = b + w->ncols;
   bmax = b + w->ncols;
   b += w->_curx;
   b += w->_curx;
#endif /* UTF8 */
   while (b < bmax) *b++ = blank;
   while (b < bmax) *b++ = blank;
   return 0;
   return 0;
 Lines 677-682    Link Here 
   return 0;
   return 0;
}
}
#ifdef UTF8
/* Note: if len is < 0, entire string will be used.
 */
int SLcurses_waddnstr (SLcurses_Window_Type *w, char *str, int len)
{
   size_t k;
   wchar_t wc;
   mbstate_t mbstate;
   if ((w == NULL)
       || (str == NULL))
     return -1;
   if (len < 0)
     len = (char *)(-1) - str;
   memset (&mbstate, 0, sizeof (mbstate));
   while ((k = mbrtowc (&wc, str, len, &mbstate)) &&
	  k != (size_t)(-1) &&
	  k != (size_t)(-2))
     {
	SLcurses_waddch1 (w, wc, w->color);
	str += k;
	len -= k;
     }
   return k;
}
#else
/* Note: if len is < 0, entire string will be used.
/* Note: if len is < 0, entire string will be used.
 */
 */
int SLcurses_waddnstr (SLcurses_Window_Type *w, char *str, int len)
int SLcurses_waddnstr (SLcurses_Window_Type *w, char *str, int len)
 Lines 758-763    Link Here 
   return 0;
   return 0;
}
}
#endif /* UTF8 */
/* This routine IS NOT CORRECT.  It needs to compute the proper overlap
/* This routine IS NOT CORRECT.  It needs to compute the proper overlap
 * and copy accordingly.  Here, I just assume windows are same size.
 * and copy accordingly.  Here, I just assume windows are same size.
 Lines 852-863    Link Here 
int SLcurses_wdelch (SLcurses_Window_Type *w)
int SLcurses_wdelch (SLcurses_Window_Type *w)
{
{
#ifdef UTF8
   SLsmg_Char_Type *p, *p1, *pmin, *pmax, *q;
#else
   SLsmg_Char_Type *p, *p1, *pmax;
   SLsmg_Char_Type *p, *p1, *pmax;
#endif /* UTF8 */
#ifdef UTF8
   pmin = w->lines[w->_cury];
   p = pmin + w->_curx;
   pmax = pmin + w->ncols;
   /* Remove overwritten chars to left */
   if (p < pmax && *p == SLSMG_NOCHAR) {
     for (q = p - 1; q >= pmin && *q == SLSMG_NOCHAR; q--)
       *q = SLSMG_BUILD_CHAR(' ',SLSMG_EXTRACT_COLOR(*q));
     if (q >= pmin)
       *q = SLSMG_BUILD_CHAR(' ',SLSMG_EXTRACT_COLOR(*q));
   }
   /* Remove overwritten chars to right */
   for (q = p + 1; q < pmax && *q == SLSMG_NOCHAR; q++)
     *q = SLSMG_BUILD_CHAR(' ',SLSMG_EXTRACT_COLOR(*q));
 
   p1 = p + 1;
#else
   p = w->lines[w->_cury];
   p = w->lines[w->_cury];
   pmax = p + w->ncols;
   pmax = p + w->ncols;
   p += w->_curx;
   p += w->_curx;
   p1 = p + 1;
   p1 = p + 1;
#endif /* UTF8 */
   while (p1 < pmax)
   while (p1 < pmax)
     {
     {
 Lines 884-895    Link Here 
   while (pmax > p)
   while (pmax > p)
     {
     {
	*pmax = *p1;
	*pmax = *p1; /* Doesn't this assign beyond the end of the line? */
	pmax = p1;
	pmax = p1;
	p1--;
	p1--;
     }
     }
   if (p < pmax)
   if (p < pmax) /* How could it be? */
     *p = SLSMG_BUILD_CHAR(ch, w->color);
     *p = SLSMG_BUILD_CHAR(ch, w->color);
   w->modified = 1;
   w->modified = 1;
 Lines 225-230    Link Here 
   SLsmg_write_nchars (str, strlen (str));
   SLsmg_write_nchars (str, strlen (str));
}
}
#ifdef UTF8
void SLsmg_write_nstring (char *str, unsigned int n)
{
   char blank = ' ';
   mbstate_t mbstate;
   /* Avoid a problem if a user accidently passes a negative value */
   if ((int) n < 0)
     return;
   if (str != NULL)
     {
	wchar_t wc;
	size_t k;
	int w;
	memset (&mbstate, 0, sizeof (mbstate));
        while ((k = mbrtowc (&wc, str, MB_LEN_MAX, &mbstate)) &&
	       k != (size_t)(-1) &&
	       k != (size_t)(-2))
	  {
	     w = wcwidth(wc);
	     if (w < 0 || w > n)
	       break;
	     SLsmg_write_nwchars (&wc, 1);
	     str += k;
	     n -= w;
	  }
     }
   while (n-- > 0) SLsmg_write_nchars (&blank, 1);
}
#else
void SLsmg_write_nstring (char *str, unsigned int n)
void SLsmg_write_nstring (char *str, unsigned int n)
{
{
   unsigned int width;
   unsigned int width;
 Lines 243-249    Link Here 
     }
     }
   while (width++ < n) SLsmg_write_nchars (&blank, 1);
   while (width++ < n) SLsmg_write_nchars (&blank, 1);
}
}
#endif /* UTF8 */
#ifdef UTF8
/* FIXME: This function not UTF8'd yet - Edmund */
#endif /* UTF8 */
void SLsmg_write_wrapped_string (char *s, int r, int c,
void SLsmg_write_wrapped_string (char *s, int r, int c,
				 unsigned int dr, unsigned int dc,
				 unsigned int dr, unsigned int dc,
				 int fill)
				 int fill)
 Lines 302-307    Link Here 
int SLsmg_Display_Eight_Bit = 128;
int SLsmg_Display_Eight_Bit = 128;
#endif
#endif
#ifdef UTF8
void SLsmg_write_nwchars (wchar_t *str, unsigned int n)
{
  SLsmg_Char_Type *p, *prev, *q;
  int len, max_len, w, i;
  wchar_t ch;
#ifndef IBMPC_SYSTEM
   int alt_char_set_flag;
   alt_char_set_flag = ((This_Color & ALT_CHAR_FLAG)
			&& ((tt_Use_Blink_For_ACS == NULL)
			    || (*tt_Use_Blink_For_ACS == 0)));
#endif
  if (Smg_Inited == 0)
    return;
  if (This_Row < Start_Row || This_Row >= Start_Row + Screen_Rows)
    return;
  max_len = Start_Col + Screen_Cols;
  len = This_Col;
  p = SL_Screen[This_Row - Start_Row].neew + len - Start_Col;
  prev = 0;
  for (i = 0; i < n; i++, str) {
    ch = *str++;
#ifndef IBMPC_SYSTEM
    if (alt_char_set_flag)
      ch = Alt_Char_Set[ch & 0x7F];
#endif
    w = wcwidth(ch);
    if (w > 0) {
      if (len + w <= max_len) {
	if (!prev) {
	  for (q = p; *q == SLSMG_NOCHAR; q--)
	    *q = SLSMG_BUILD_CHAR(' ', SLSMG_EXTRACT_COLOR(*q));
	  *q = SLSMG_BUILD_CHAR(' ', SLSMG_EXTRACT_COLOR(*q));
	}
	prev = p;
	*p++ = SLSMG_BUILD_CHAR(ch, This_Color), ++len;
	for (; --w; len++, p++)
	  *p = SLSMG_NOCHAR;
      }
      else if (len < max_len) {
	for (; len < max_len; len++, p++)
	  *p = SLSMG_BUILD_CHAR(' ', SLSMG_EXTRACT_COLOR(*p));
	prev = 0;
      }
    }
    else if (ch == '\n' &&
	     SLsmg_Newline_Behavior != SLSMG_NEWLINE_PRINTABLE) {
      SL_Screen[This_Row - Start_Row].flags |= TOUCHED;
      for (; len < max_len && *p == SLSMG_NOCHAR; len++, p++)
	*p = SLSMG_BUILD_CHAR(' ', SLSMG_EXTRACT_COLOR(*p));
      if (!SLsmg_Newline_Behavior)
	break;
      ++This_Row;
      len = 0;
      if (This_Row == Start_Row + Screen_Rows) {
	if (SLsmg_Newline_Behavior == SLSMG_NEWLINE_SCROLLS)
	  scroll_up();
	else
	  break;
      }
      p = SL_Screen[This_Row - Start_Row].neew;
      prev = 0;
    }
    else if (ch == '\t' && (SLsmg_Tab_Width > 0)) {
      while (len < max_len) {
	*p = SLSMG_BUILD_CHAR(' ', SLSMG_EXTRACT_COLOR(*p));
	++p, ++len;
	if (len % SLsmg_Tab_Width == 0)
	  break;
      }
    }
    else if ((ch == 0x8) && SLsmg_Backspace_Moves) {
      /* not implemented */
    }
    else if (!w && ch) {
      /* we could handle combining characters here, using prev */
    }
    else {
      /* we should convert control characters to printable form here */
    }
  }
  This_Col = len;
  if (i == n) {
    SL_Screen[This_Row - Start_Row].flags |= TOUCHED;
    for (; len < max_len && *p == SLSMG_NOCHAR; len++, p++)
      *p = SLSMG_BUILD_CHAR(' ', SLSMG_EXTRACT_COLOR(*p));
  }
}
void SLsmg_write_char (wchar_t wc)
{
   SLsmg_write_nwchars (&wc, 1);
}
void SLsmg_write_nchars (char *str, unsigned int n)
{
   wchar_t wc;
   size_t k;
   mbstate_t mbstate;
   memset (&mbstate, 0, sizeof (mbstate));
   while ((k = mbrtowc (&wc, str, n, &mbstate)) &&
	  k != (size_t)(-1) &&
	  k != (size_t)(-2))
     {
        SLsmg_write_nwchars (&wc, 1);
	str += k;
	n -= k;
     }
}
#else
void SLsmg_write_nchars (char *str, unsigned int n)
void SLsmg_write_nchars (char *str, unsigned int n)
{
{
   register SLsmg_Char_Type *p, old, neew, color;
   register SLsmg_Char_Type *p, old, neew, color;
 Lines 475-480    Link Here 
{
{
   SLsmg_write_nchars (&ch, 1);
   SLsmg_write_nchars (&ch, 1);
}
}
#endif /* UTF8 */
static int Cls_Flag;
static int Cls_Flag;
 Lines 891-896    Link Here 
	     This_Color = color;
	     This_Color = color;
	  }
	  }
#ifdef UTF8
	/* FIXME: We should convert broken wide characters to spaces
	   before calling smart_puts */
#endif /* UTF8 */
	SL_Screen[i].old[Screen_Cols] = 0;
	SL_Screen[i].old[Screen_Cols] = 0;
	SL_Screen[i].neew[Screen_Cols] = 0;
	SL_Screen[i].neew[Screen_Cols] = 0;
 Lines 1334-1342    Link Here 
   This_Row = r; This_Col = c;
   This_Row = r; This_Col = c;
}
}
#ifdef UTF8
void SLsmg_fill_region (int r, int c, unsigned int dr, unsigned int dc, wchar_t ch)
{
   static wchar_t hbuf[16];
   int i;
#else
void SLsmg_fill_region (int r, int c, unsigned int dr, unsigned int dc, unsigned char ch)
void SLsmg_fill_region (int r, int c, unsigned int dr, unsigned int dc, unsigned char ch)
{
{
   static unsigned char hbuf[16];
   static unsigned char hbuf[16];
#endif /* UTF8 */
   int count;
   int count;
   int dcmax, rmax;
   int dcmax, rmax;
 Lines 1357-1372    Link Here 
#if 0
#if 0
   ch = Alt_Char_Set[ch];
   ch = Alt_Char_Set[ch];
#endif
#endif
#ifdef UTF8
   if (ch != hbuf[0])
     for (i = 0; i < 16; i++)
       hbuf[i] = ch;
#else
   if (ch != hbuf[0]) SLMEMSET ((char *) hbuf, (char) ch, 16);
   if (ch != hbuf[0]) SLMEMSET ((char *) hbuf, (char) ch, 16);
#endif /* UTF8 */
   for (This_Row = r; This_Row < rmax; This_Row++)
   for (This_Row = r; This_Row < rmax; This_Row++)
     {
     {
	This_Col = c;
	This_Col = c;
	count = dc / 16;
	count = dc / 16;
#ifdef UTF8
	SLsmg_write_nwchars (hbuf, dc % 16);
#else
	SLsmg_write_nchars ((char *) hbuf, dc % 16);
	SLsmg_write_nchars ((char *) hbuf, dc % 16);
#endif /* UTF8 */
	while (count-- > 0)
	while (count-- > 0)
	  {
	  {
#ifdef UTF8
	     SLsmg_write_nwchars (hbuf, 16);
#else
	     SLsmg_write_nchars ((char *) hbuf, 16);
	     SLsmg_write_nchars ((char *) hbuf, 16);
#endif /* UTF8 */
	  }
	  }
     }
     }
 Lines 1381-1394    Link Here 
void SLsmg_write_color_chars (SLsmg_Char_Type *s, unsigned int len)
void SLsmg_write_color_chars (SLsmg_Char_Type *s, unsigned int len)
{
{
   SLsmg_Char_Type *smax, sh;
   SLsmg_Char_Type *smax, sh;
#ifdef UTF8
   wchar_t buf[32], *b, *bmax;
#else
   char buf[32], *b, *bmax;
   char buf[32], *b, *bmax;
#endif /* UTF8 */
   int color, save_color;
   int color, save_color;
   if (Smg_Inited == 0) return;
   if (Smg_Inited == 0) return;
   smax = s + len;
   smax = s + len;
   b = buf;
   b = buf;
#ifdef UTF8
   bmax = b + sizeof (buf) / sizeof (SLsmg_Char_Type);
#else
   bmax = b + sizeof (buf);
   bmax = b + sizeof (buf);
#endif /* UTF8 */
   save_color = This_Color;
   save_color = This_Color;
 Lines 1412-1427    Link Here 
	  {
	  {
	     if (b != buf)
	     if (b != buf)
	       {
	       {
#ifdef UTF8
		  SLsmg_write_nwchars (buf, (int) (b - buf));
#else
		  SLsmg_write_nchars (buf, (int) (b - buf));
		  SLsmg_write_nchars (buf, (int) (b - buf));
#endif /* UTF8 */
		  b = buf;
		  b = buf;
	       }
	       }
	     This_Color = color;
	     This_Color = color;
	  }
	  }
#ifdef UTF8
	*b++ = SLSMG_EXTRACT_CHAR(sh);
#else
	*b++ = (char) SLSMG_EXTRACT_CHAR(sh);
	*b++ = (char) SLSMG_EXTRACT_CHAR(sh);
#endif /* UTF8 */
     }
     }
   if (b != buf)
   if (b != buf)
#ifdef UTF8
     SLsmg_write_nwchars (buf, (unsigned int) (b - buf));
#else
     SLsmg_write_nchars (buf, (unsigned int) (b - buf));
     SLsmg_write_nchars (buf, (unsigned int) (b - buf));
#endif /* UTF8 */
   This_Color = save_color;
   This_Color = save_color;
}
}
 Lines 1473-1479    Link Here 
SLsmg_set_color_in_region (int color, int r, int c, unsigned int dr, unsigned int dc)
SLsmg_set_color_in_region (int color, int r, int c, unsigned int dr, unsigned int dc)
{
{
   int cmax, rmax;
   int cmax, rmax;
#ifdef UTF8
   int color_mask;
#else
   SLsmg_Char_Type char_mask;
   SLsmg_Char_Type char_mask;
#endif /* UTF8 */
   if (Smg_Inited == 0) return;
   if (Smg_Inited == 0) return;
 Lines 1498-1511    Link Here 
	  color = ((color & 0x7F) + Bce_Color_Offset) & 0x7F;
	  color = ((color & 0x7F) + Bce_Color_Offset) & 0x7F;
     }
     }
#endif
#endif
#ifdef UTF8
   color_mask = 0;
#else
   color = color << 8;
   color = color << 8;
   char_mask = 0xFF;
   char_mask = 0xFF;
#endif /* UTF8 */
#ifndef IBMPC_SYSTEM
#ifndef IBMPC_SYSTEM
   if ((tt_Use_Blink_For_ACS == NULL)
   if ((tt_Use_Blink_For_ACS == NULL)
       || (0 == *tt_Use_Blink_For_ACS))
       || (0 == *tt_Use_Blink_For_ACS))
#ifdef UTF8
     color_mask = 0x80;
#else
     char_mask = 0x80FF;
     char_mask = 0x80FF;
#endif /* UTF8 */
#endif
#endif
   while (r < rmax)
   while (r < rmax)
 Lines 1519-1525    Link Here 
	while (s < smax)
	while (s < smax)
	  {
	  {
#ifdef UTF8
	     *s = SLSMG_BUILD_CHAR(SLSMG_EXTRACT_CHAR(*s),
				   (SLSMG_EXTRACT_COLOR(*s) & color_mask)
				   | color);
#else
	     *s = (*s & char_mask) | color;
	     *s = (*s & char_mask) | color;
#endif /* UTF8 */
	     s++;
	     s++;
	  }
	  }
	r++;
	r++;
 Lines 9-14    Link Here 
#include <time.h>
#include <time.h>
#include <ctype.h>
#include <ctype.h>
#include <limits.h>
#if !defined(VMS) || (__VMS_VER >= 70000000)
#if !defined(VMS) || (__VMS_VER >= 70000000)
# include <sys/time.h>
# include <sys/time.h>
 Lines 1426-1439    Link Here 
/* Highest bit represents the character set. */
/* Highest bit represents the character set. */
#define COLOR_MASK 0x7F00
#define COLOR_MASK 0x7F00
#ifdef UTF8
# define COLOR_OF(x) (SLSMG_EXTRACT_COLOR(x) & 0x7F)
#else
#define COLOR_OF(x) (((x)&COLOR_MASK)>>8)
#define COLOR_OF(x) (((x)&COLOR_MASK)>>8)
#endif
#define CHAR_OF(x) ((x)&0x80FF)
#define CHAR_OF(x) ((x)&0x80FF)
#if SLTT_HAS_NON_BCE_SUPPORT
#if SLTT_HAS_NON_BCE_SUPPORT
#ifdef UTF8
static int bce_color_eqs (SLsmg_Char_Type a, SLsmg_Char_Type b)
{
   a = SLSMG_EXTRACT_COLOR(a) & 0x7F;
   b = SLSMG_EXTRACT_COLOR(b) & 0x7F;
#else
static int bce_color_eqs (unsigned int a, unsigned int b)
static int bce_color_eqs (unsigned int a, unsigned int b)
{
{
   a = COLOR_OF(a);
   a = COLOR_OF(a);
   b = COLOR_OF(b);
   b = COLOR_OF(b);
#endif
   
   
   if (a == b)
   if (a == b)
     return 1;
     return 1;
 Lines 1459-1466    Link Here 
    :  (Ansi_Color_Map[COLOR_OF(a)].mono == Ansi_Color_Map[COLOR_OF(b)].mono))
    :  (Ansi_Color_Map[COLOR_OF(a)].mono == Ansi_Color_Map[COLOR_OF(b)].mono))
#endif
#endif
#ifdef UTF8
#define CHAR_EQS(a, b) ((a) == (b)\
			|| (SLSMG_EXTRACT_CHAR(a) == SLSMG_EXTRACT_CHAR(b)\
			    && COLOR_EQS((a), (b))))
#else
#define CHAR_EQS(a, b) (((a) == (b))\
#define CHAR_EQS(a, b) (((a) == (b))\
			|| ((CHAR_OF(a)==CHAR_OF(b)) && COLOR_EQS(a,b)))
			|| ((CHAR_OF(a)==CHAR_OF(b)) && COLOR_EQS(a,b)))
#endif
/* The whole point of this routine is to prevent writing to the last column
/* The whole point of this routine is to prevent writing to the last column
 * and last row on terminals with automatic margins.
 * and last row on terminals with automatic margins.
 Lines 1488-1496    Link Here 
   tt_write (str, len);
   tt_write (str, len);
}
}
#ifdef UTF8
/* FIXME: This duplicates the function above
 */
static void write_wstring_with_care (SLsmg_Char_Type *str, unsigned int len)
{
   mbstate_t mbstate;
   if (str == NULL) return;
   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;
		  while (len > 0 && str[len] == SLSMG_NOCHAR)
		    --len;
	       }
	     else len = 0;
	  }
     }
   memset (&mbstate, 0, sizeof (mbstate));
   while (len--)
     {
        SLsmg_Char_Type c = *str++;
	char buf[MB_LEN_MAX];
	size_t n;
	if (c == SLSMG_NOCHAR)
	  continue;
	n = wcrtomb (buf, c, &mbstate);
	if (n == (size_t)(-1))
	  break;
	tt_write(buf, n);
     }
}
#endif /* UTF8 */
static void send_attr_str (SLsmg_Char_Type *s)
static void send_attr_str (SLsmg_Char_Type *s)
{
{
#ifdef UTF8
   SLsmg_Char_Type out[SLTT_MAX_SCREEN_COLS], ch, *p;
#else
   unsigned char out[SLTT_MAX_SCREEN_COLS], ch, *p;
   unsigned char out[SLTT_MAX_SCREEN_COLS], ch, *p;
#endif /* UTF8 */
   register SLtt_Char_Type attr;
   register SLtt_Char_Type attr;
   register SLsmg_Char_Type sh;
   register SLsmg_Char_Type sh;
   int color, last_color = -1;
   int color, last_color = -1;
 Lines 1498-1505    Link Here 
   p = out;
   p = out;
   while (0 != (sh = *s++))
   while (0 != (sh = *s++))
     {
     {
#ifdef UTF8
	ch = SLSMG_EXTRACT_CHAR(sh);
	color = SLSMG_EXTRACT_COLOR(sh);
#else
	ch = sh & 0xFF;
	ch = sh & 0xFF;
	color = ((int) sh & 0xFF00) >> 8;
	color = ((int) sh & 0xFF00) >> 8;
#endif
#if SLTT_HAS_NON_BCE_SUPPORT
#if SLTT_HAS_NON_BCE_SUPPORT
	if (Bce_Color_Offset
	if (Bce_Color_Offset
 Lines 1511-1518    Link Here 
	  {
	  {
	     if (SLtt_Use_Ansi_Colors) attr = Ansi_Color_Map[color & 0x7F].fgbg;
	     if (SLtt_Use_Ansi_Colors) attr = Ansi_Color_Map[color & 0x7F].fgbg;
	     else attr = Ansi_Color_Map[color & 0x7F].mono;
	     else attr = Ansi_Color_Map[color & 0x7F].mono;
 
#ifdef UTF8
	     if (SLSMG_EXTRACT_COLOR(sh) & 0x80) /* alternate char set */
#else
	     if (sh & 0x8000) /* alternate char set */
	     if (sh & 0x8000) /* alternate char set */
#endif
	       {
	       {
		  if (SLtt_Use_Blink_For_ACS)
		  if (SLtt_Use_Blink_For_ACS)
		    {
		    {
 Lines 1534-1541    Link Here 
		    {
		    {
		       if (p != out)
		       if (p != out)
			 {
			 {
#ifdef UTF8
			    write_wstring_with_care (out, p-out);
#else
			    *p = 0;
			    *p = 0;
			    write_string_with_care ((char *) out);
			    write_string_with_care ((char *) out);
#endif
			    Cursor_c += (int) (p - out);
			    Cursor_c += (int) (p - out);
			    p = out;
			    p = out;
			 }
			 }
 Lines 1558-1565    Link Here 
	  }
	  }
	*p++ = ch;
	*p++ = ch;
     }
     }
#ifdef UTF8
   if (p != out) write_wstring_with_care (out, p-out);
#else
   *p = 0;
   *p = 0;
   if (p != out) write_string_with_care ((char *) out);
   if (p != out) write_string_with_care ((char *) out);
#endif
   Cursor_c += (int) (p - out);
   Cursor_c += (int) (p - out);
}
}
 Lines 1686-1692    Link Here 
	while (qq < qmax)
	while (qq < qmax)
	  {
	  {
#ifdef UTF8
	     if (SLSMG_EXTRACT_COLOR(*qq))
#else
	     if (*qq & 0xFF00)
	     if (*qq & 0xFF00)
#endif
	       {
	       {
		  SLtt_normal_video ();
		  SLtt_normal_video ();
		  SLtt_del_eol ();
		  SLtt_del_eol ();
 Lines 1701-1707    Link Here 
   /* Find where the last non-blank character on old/new screen is */
   /* Find where the last non-blank character on old/new screen is */
   space_char = ' ';
   space_char = ' ';
#ifdef UTF8
   if (SLSMG_EXTRACT_CHAR(*(pmax-1)) == ' ')
#else
   if (CHAR_EQS(*(pmax-1), ' '))
   if (CHAR_EQS(*(pmax-1), ' '))
#endif
     {
     {
	/* If we get here, then we can erase to the end of the line to create
	/* If we get here, then we can erase to the end of the line to create
	 * the final space.  However, this will only work _if_ erasing will 
	 * the final space.  However, this will only work _if_ erasing will 
 Lines 1752-1758    Link Here 
     {
     {
#endif
#endif
	/* Try use use erase to bol if possible */
	/* Try use use erase to bol if possible */
#ifdef UTF8
	if ((Del_Bol_Str != NULL) && (SLSMG_EXTRACT_CHAR(*neww) == ' '))
#else
	if ((Del_Bol_Str != NULL) && (CHAR_OF(*neww) == ' '))
	if ((Del_Bol_Str != NULL) && (CHAR_OF(*neww) == ' '))
#endif
	  {
	  {
	     SLsmg_Char_Type *p1;
	     SLsmg_Char_Type *p1;
	     SLsmg_Char_Type blank;
	     SLsmg_Char_Type blank;
 Lines 1781-1787    Link Here 
		  q = oldd + ofs;
		  q = oldd + ofs;
		  p = p1;
		  p = p1;
		  SLtt_goto_rc (row, ofs - 1);
		  SLtt_goto_rc (row, ofs - 1);
#ifdef UTF8
		  SLtt_reverse_video (SLSMG_EXTRACT_COLOR (blank));
#else
		  SLtt_reverse_video (COLOR_OF(blank));
		  SLtt_reverse_video (COLOR_OF(blank));
#endif
		  tt_write_string (Del_Bol_Str);
		  tt_write_string (Del_Bol_Str);
		  tt_write (" ", 1);
		  tt_write (" ", 1);
		  Cursor_c += 1;
		  Cursor_c += 1;
 Lines 1978-1984    Link Here 
   if (q < qmax) 
   if (q < qmax) 
     {
     {
#ifdef UTF8
	SLtt_reverse_video (SLSMG_EXTRACT_COLOR (space_char));
#else
	SLtt_reverse_video (COLOR_OF(space_char));
	SLtt_reverse_video (COLOR_OF(space_char));
#endif
	del_eol ();
	del_eol ();
     }
     }