void SLsmg_write_char (SLwchar_Type ch) { unsigned char u[SLUTF8_MAX_MBLEN]; unsigned char *umax; if ((ch < 0x80) || (UTF8_Mode == 0)) { u[0] = (unsigned char) ch; SLsmg_write_chars (u, u+1); return; } if (NULL == (umax = SLutf8_encode (ch, u, SLUTF8_MAX_MBLEN))) return; SLsmg_write_chars (u, umax); }
static unsigned char *write_using_color (unsigned char *p, unsigned char *pmax, int color) { if ((color == 0) && (Jed_Highlight_WS & HIGHLIGHT_WS_TAB)) { unsigned char *p1 = p; while (p1 < pmax) { if (*p1 != '\t') { p1++; continue; } if (p1 != p) { SLsmg_set_color (0); SLsmg_write_nchars ((char *)p, (unsigned int)(p1-p)); p = p1; } while ((p1 < pmax) && (*p1 == '\t')) p1++; SLsmg_set_color (JTAB_COLOR); SLsmg_write_nchars ((char *)p, (unsigned int)(p1-p)); p = p1; } } /* drop */ SLsmg_set_color (color); SLsmg_write_chars (p, pmax); SLsmg_set_color (0); return pmax; }
void SLsmg_printf (SLFUTURE_CONST char *fmt, ...) { va_list ap; SLFUTURE_CONST char *f; if (Smg_Inited == 0) return; va_start(ap, fmt); f = fmt; while (*f && (*f != '%')) f++; if (f != fmt) SLsmg_write_chars ((SLuchar_Type *)fmt, (SLuchar_Type *)f); if (*f != 0) SLsmg_vprintf (f, ap); va_end (ap); }
void SLsmg_write_wrapped_string (SLuchar_Type *u, int r, int c, unsigned int dr, unsigned int dc, int fill) { int maxc = (int) dc; unsigned char *p, *pmax; int utf8_mode = UTF8_Mode; unsigned char display_8bit = (unsigned char) SLsmg_Display_Eight_Bit; if (utf8_mode) display_8bit = 0xA0; if ((dr == 0) || (dc == 0)) return; if (u == NULL) u = (unsigned char *)""; p = u; pmax = u + strlen ((char *)u); dc = 0; while (1) { SLwchar_Type wc; unsigned int nconsumed; unsigned char ch = *p; unsigned int ddc; if ((ch == 0) || (ch == '\n')) { int diff; diff = maxc - (int) dc; SLsmg_gotorc (r, c); SLsmg_write_chars (u, p); if (fill && (diff > 0)) { unsigned char *blank = (unsigned char *)" "; while (diff--) SLsmg_write_chars (blank, blank+1); } if ((ch == 0) || (dr == 1)) break; r++; dc = 0; dr--; p++; u = p; continue; } /* If the width of the characters buffered so far extend to or beyond * the width of the box, then write them out and goto the * next line. Note that dc > maxc if the displayable width of * the last character to be written is greater than the width * of the box. This will be the case if (maxc<ddc) -- see below */ if ((int) dc >= maxc) goto write_chars_and_reset; nconsumed = 1; if (ch < 0x80) { p++; if ((ch >= 0x20) && (ch != 0x7F)) { dc++; continue; } /* Otherwise display as ^X */ dc += 2; continue; } nconsumed = 1; if ((utf8_mode == 0) || (NULL == SLutf8_decode (p, pmax, &wc, &nconsumed))) { if ((utf8_mode == 0) && (display_8bit && (*p >= display_8bit))) { dc++; p += nconsumed; continue; } ddc = 4*nconsumed; /* <XX> */ } else if (wc < (SLwchar_Type)display_8bit) ddc = 4; /* displays as <XX> */ else ddc = SLwchar_wcwidth (wc); dc += ddc; if (((int)dc > maxc) && (maxc > (int)ddc)) { dc -= ddc; goto write_chars_and_reset; } p += nconsumed; continue; write_chars_and_reset: SLsmg_gotorc (r, c); SLsmg_write_chars (u, p); while ((int)dc < maxc) { SLsmg_write_char (' '); dc++; } if (dr == 1) break; r++; dc = 0; dr--; u = p; } }
void SLsmg_write_string (SLFUTURE_CONST char *str) { SLsmg_write_chars ((unsigned char *)str, (unsigned char *)str + strlen (str)); }
void SLsmg_write_nchars (SLFUTURE_CONST char *str, unsigned int len) { SLsmg_write_chars ((unsigned char *) str, (unsigned char *)str + len); }
void SLsmg_fill_region (int r, int c, unsigned int dr, unsigned int dc, SLwchar_Type wch) { static unsigned char buf[16]; unsigned char ubuf[16*SLUTF8_MAX_MBLEN]; unsigned char *b, *bmax; int count; int dcmax, rmax; unsigned int wchlen; if (Smg_Inited == 0) return; SLsmg_gotorc (r, c); r = This_Row; c = This_Col; dcmax = Screen_Cols - This_Col; if (dcmax < 0) return; if (dc > (unsigned int) dcmax) dc = (unsigned int) dcmax; rmax = This_Row + (int)dr; if (rmax > (int)Screen_Rows) rmax = (int)Screen_Rows; if ((wch < 0x80) || (UTF8_Mode == 0)) { if (buf[0] != (unsigned char) wch) memset ((char *) buf, (unsigned char) wch, sizeof(buf)); b = buf; bmax = buf + sizeof (buf); wchlen = 1; } else { unsigned int i; b = ubuf; bmax = SLutf8_encode (wch, b, SLUTF8_MAX_MBLEN); if (bmax == NULL) { bmax = ubuf; *bmax++ = '?'; } wchlen = (unsigned int) (bmax - b); for (i = 1; i < 16; i++) { memcpy (bmax, b, wchlen); bmax += wchlen; } } for (This_Row = r; This_Row < rmax; This_Row++) { This_Col = c; count = dc / 16; SLsmg_write_chars (b, b + wchlen * (dc % 16)); while (count-- > 0) { SLsmg_write_chars (b, bmax); } } This_Row = r; }