~ubuntu-branches/ubuntu/lucid/mc/lucid

« back to all changes in this revision

Viewing changes to slang/sldisply.c

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Winnertz
  • Date: 2008-09-16 10:38:59 UTC
  • mfrom: (3.1.6 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080916103859-2uwn8w61xk5mbxxq
Tags: 2:4.6.2~git20080311-4
Corrected fix for odt2txt issue (Closes: #492019) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 1992, 1999, 2001, 2002, 2003 John E. Davis
2
 
 * This file is part of the S-Lang library.
3
 
 *
4
 
 * You may distribute under the terms of either the GNU General Public
5
 
 * License or the Perl Artistic License.
6
 
 */
 
1
/*
 
2
Copyright (C) 2004, 2005, 2006 John E. Davis
 
3
 
 
4
This file is part of the S-Lang Library.
 
5
 
 
6
The S-Lang Library is free software; you can redistribute it and/or
 
7
modify it under the terms of the GNU General Public License as
 
8
published by the Free Software Foundation; either version 2 of the
 
9
License, or (at your option) any later version.
 
10
 
 
11
The S-Lang Library is distributed in the hope that it will be useful,
 
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
General Public License for more details.
 
15
 
 
16
You should have received a copy of the GNU General Public License
 
17
along with this library; if not, write to the Free Software
 
18
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 
19
USA.  
 
20
*/
7
21
 
8
22
#include "slinclud.h"
9
23
 
77
91
 * not include this attribute.
78
92
 */
79
93
 
80
 
#define GET_FG(color) ((color & FG_MASK) >> 8)
81
 
#define GET_BG(color) ((color & BG_MASK) >> 16)
 
94
#define GET_FG(fgbg) (((fgbg) & FG_MASK) >> 8)
 
95
#define GET_BG(fgbg) (((fgbg) & BG_MASK) >> 16)
82
96
#define MAKE_COLOR(fg, bg) (((fg) | ((bg) << 8)) << 8)
83
97
 
84
 
int SLtt_Screen_Cols;
85
 
int SLtt_Screen_Rows;
 
98
int SLtt_Screen_Cols = 80;
 
99
int SLtt_Screen_Rows = 24;
86
100
int SLtt_Term_Cannot_Insert;
87
101
int SLtt_Term_Cannot_Scroll;
88
102
int SLtt_Use_Ansi_Colors;
89
 
int SLtt_Blink_Mode = 1;
 
103
int SLtt_Blink_Mode = 0;
90
104
int SLtt_Use_Blink_For_ACS = 0;
91
105
int SLtt_Newline_Ok = 0;
92
106
int SLtt_Has_Alt_Charset = 0;
93
107
int SLtt_Force_Keypad_Init = 0;
94
108
 
95
 
void (*_SLtt_color_changed_hook)(void);
 
109
/* static int UTF8_Mode = -1; */
 
110
 
 
111
void (*_pSLtt_color_changed_hook)(void);
96
112
 
97
113
#if SLTT_HAS_NON_BCE_SUPPORT
98
114
static int Bce_Color_Offset = 0;
119
135
 
120
136
static int Linux_Console;
121
137
static int QANSI_Console;
 
138
static int Mouse_Mode = -1;
122
139
 
123
 
/* It is crucial that JMAX_COLORS must be less than 128 since the high bit
 
140
/* The following comment is nolonger valid, but is here in case there are
 
141
 * some apps that use SLtt_Use_Blink_For_ACS and still need porting to v2.
 
142
 * -------
 
143
 * It is crucial that JMAX_COLORS must be less than 128 since the high bit
124
144
 * is used to indicate a character from the ACS (alt char set).  The exception
125
145
 * to this rule is if SLtt_Use_Blink_For_ACS is true.  This means that of
126
146
 * the highbit is set, we interpret that as a blink character.  This is
127
147
 * exploited by DOSemu.
128
148
 */
129
 
#define JMAX_COLORS 256
 
149
#define JMAX_COLORS 512
130
150
#define JNORMAL_COLOR 0
131
151
 
132
152
typedef struct
133
153
{
134
154
   SLtt_Char_Type fgbg;
135
155
   SLtt_Char_Type mono;
136
 
   char *custom_esc;
137
156
}
138
 
Ansi_Color_Type;
139
 
 
140
 
#define RGB1(r, g, b)   ((r) | ((g) << 1) | ((b) << 2))
141
 
#define RGB(r, g, b, br, bg, bb)  ((RGB1(r, g, b) << 8) | (RGB1(br, bg, bb) << 16))
142
 
 
143
 
static Ansi_Color_Type Ansi_Color_Map[JMAX_COLORS] =
144
 
{
145
 
     {RGB(1, 1, 1, 0, 0, 0), 0x00000000, NULL},   /* white/black */
146
 
     {RGB(0, 1, 0, 0, 0, 0), SLTT_REV_MASK, NULL},   /* green/black */
147
 
     {RGB(1, 0, 1, 0, 0, 0), SLTT_REV_MASK, NULL},   /* magenta/black */
148
 
     {RGB(0, 1, 1, 0, 0, 0), SLTT_REV_MASK, NULL},   /* cyan/black */
149
 
     {RGB(1, 0, 0, 0, 0, 0), SLTT_REV_MASK, NULL},
150
 
     {RGB(0, 1, 0, 0, 0, 1), SLTT_REV_MASK, NULL},
151
 
     {RGB(1, 0, 0, 0, 0, 1), SLTT_REV_MASK, NULL},
152
 
     {RGB(1, 0, 0, 0, 1, 0), SLTT_REV_MASK, NULL},
153
 
     {RGB(0, 0, 1, 1, 0, 0), SLTT_REV_MASK, NULL},
154
 
     {RGB(0, 1, 0, 1, 0, 0), SLTT_REV_MASK, NULL},
155
 
     {RGB(0, 1, 1, 1, 1, 1), SLTT_REV_MASK, NULL},
156
 
     {RGB(1, 1, 0, 1, 1, 1), SLTT_REV_MASK, NULL},
157
 
     {RGB(1, 0, 1, 1, 1, 1), SLTT_REV_MASK, NULL},
158
 
     {RGB(0, 0, 0, 0, 1, 1), SLTT_REV_MASK, NULL},
159
 
     {RGB(0, 1, 0, 1, 1, 1), SLTT_REV_MASK, NULL},
160
 
     {RGB(0, 1, 0, 1, 1, 1), SLTT_REV_MASK, NULL},
161
 
     {RGB(0, 1, 0, 1, 1, 1), SLTT_REV_MASK, NULL},
162
 
     {RGB(0, 1, 0, 1, 1, 1), SLTT_REV_MASK, NULL}
163
 
};
 
157
Brush_Info_Type;
 
158
 
 
159
static Brush_Info_Type Brush_Table[JMAX_COLORS];
164
160
 
165
161
/* 0 if least significant bit is blue, not red */
166
 
static int Is_Fg_BGR = 0;
 
162
/* static int Is_Fg_BGR = 0; */
167
163
static int Is_Bg_BGR = 0;
168
164
#define COLOR_ARG(color, is_bgr) ((is_bgr) ? RGB_to_BGR[(color)&0x7] : (color))
169
 
static const int RGB_to_BGR[] =
 
165
static SLCONST int RGB_to_BGR[] =
170
166
{
171
167
     0, 4, 2, 6, 1, 5, 3, 7
172
168
};
247
243
 
248
244
unsigned long SLtt_Num_Chars_Output;
249
245
 
250
 
int _SLusleep (unsigned long usecs)
 
246
int _pSLusleep (unsigned long usecs)
251
247
{
252
248
#if !defined(VMS) || (__VMS_VER >= 70000000)
253
249
   struct timeval tv;
277
273
#ifdef EAGAIN
278
274
             if (errno == EAGAIN)
279
275
               {
280
 
                  _SLusleep (100000);   /* 1/10 sec */
 
276
                  _pSLusleep (100000);   /* 1/10 sec */
281
277
                  continue;
282
278
               }
283
279
#endif
284
280
#ifdef EWOULDBLOCK
285
281
             if (errno == EWOULDBLOCK)
286
282
               {
287
 
                  _SLusleep (100000);
 
283
                  _pSLusleep (100000);
288
284
                  continue;
289
285
               }
290
286
#endif
503
499
             else if (zero_pad && (field_width == 3))
504
500
               *b++ = '0';
505
501
 
 
502
             if (b == bmax) break;
506
503
             if (z >= 10)
507
504
               {
508
505
                  *b++ = z / 10 + '0';
741
738
                       /* cursor movement optimizations, like backspace
742
739
                          doesn't work as needed on qansi-m consoles when 
743
740
                          current table is not a G0, so we'll disable it. */
744
 
                       if (!QANSI_Console)
745
 
                       {
746
 
                          s = "\b";
747
 
                       }
748
 
                       else
749
 
                       {
 
741
                       if (!QANSI_Console)
 
742
                       {
 
743
                         s = buf;
 
744
                         *s++ = '\b'; *s = 0;
 
745
                         s = buf;
 
746
                       }
 
747
                       else
 
748
                       {
750
749
                          /* do the generic cursor positioning,
751
 
                             without an optimization */
752
 
                          s = NULL;
753
 
                       }
 
750
                             without an optimization */
 
751
                         s = NULL;
 
752
                       }
754
753
                    }
755
754
               }
756
 
             else if ((c == 0) && (!QANSI_Console)) /* the same things 
757
 
                                    for the qansi-m console limitation */
 
755
             else if ((c == 0) && (!QANSI_Console)) /* the same things
 
756
                                    for the qansi-m console limitation */
758
757
               {
759
758
                  s = buf;
760
759
                  if ((Cursor_Set != 1) || (Cursor_c != 0)) *s++ = '\r';
824
823
   SLtt_del_eol ();
825
824
}
826
825
 
827
 
void SLtt_delete_nlines (int n)
 
826
void SLtt_delete_nlines (int nn)
828
827
{
829
828
   int r1, curs;
830
 
   char buf[132];
831
 
 
832
 
   if (n <= 0) return;
 
829
   unsigned int n;
 
830
 
 
831
   if (nn <= 0) return;
 
832
   n = (unsigned int) nn;
 
833
 
833
834
   SLtt_normal_video ();
834
835
 
835
836
   if (Scroll_r1 == Scroll_r2)
838
839
        return;
839
840
     }
840
841
 
841
 
   if (Del_N_Lines_Str != NULL) tt_printf(Del_N_Lines_Str,n, 0);
 
842
   if (Del_N_Lines_Str != NULL) tt_printf(Del_N_Lines_Str, n, 0);
842
843
   else
843
844
   /* get a new terminal */
844
845
     {
845
 
        int t = n;
 
846
        char buf[80];
 
847
        unsigned int dn = n;
 
848
 
 
849
        if (dn > sizeof (buf))
 
850
          dn = sizeof (buf);
 
851
 
 
852
        SLMEMSET (buf, '\n', dn);
 
853
        while (n > dn)
 
854
          {
 
855
             tt_write (buf, dn);
 
856
             n -= dn;
 
857
          }
 
858
        tt_write (buf, n);
 
859
 
846
860
        r1 = Scroll_r1;
847
861
        curs = Cursor_r;
848
 
 
849
862
        SLtt_set_scroll_region(curs, Scroll_r2);
850
863
        SLtt_goto_rc(Scroll_r2 - Scroll_r1, 0);
851
 
        if (n > sizeof (buf))
852
 
            t = sizeof (buf);
853
 
        SLMEMSET (buf, '\n', t);
854
 
        do {
855
 
            tt_write (buf, (n < t) ? n : t);
856
 
            n -= t;
857
 
        } while (n > 0);
 
864
        SLMEMSET(buf, '\n', (unsigned int) n);
 
865
        tt_write(buf, (unsigned int) n);
858
866
        /* while (n--) tt_putchar('\n'); */
859
867
        SLtt_set_scroll_region(r1, Scroll_r2);
860
868
        SLtt_goto_rc(curs, 0);
914
922
          {
915
923
             tt_write ("\033[?5h", 5);
916
924
             SLtt_flush_output ();
917
 
             _SLusleep (50000);
 
925
             _pSLusleep (50000);
918
926
             tt_write ("\033[?5l", 5);
919
927
          }
920
928
#endif
969
977
   del_eol ();
970
978
}
971
979
 
972
 
typedef const struct
 
980
typedef SLCONST struct
973
981
{
974
982
   char *name;
975
983
   SLtt_Char_Type color;
999
1007
     {"default",                SLSMG_COLOR_DEFAULT}
1000
1008
};
1001
1009
 
1002
 
void SLtt_set_mono (int obj, char *what, SLtt_Char_Type mask)
 
1010
static int Brushes_Initialized = 0;
 
1011
 
 
1012
static int initialize_brushes (void)
1003
1013
{
1004
 
   (void) what;
1005
 
   if ((obj < 0) || (obj >= JMAX_COLORS))
 
1014
   int fg, bg;
 
1015
   Brush_Info_Type *b, *bmax;
 
1016
 
 
1017
   b = Brush_Table;
 
1018
   bmax = b + JMAX_COLORS;
 
1019
 
 
1020
   bg = 0;
 
1021
   while (b < bmax)
1006
1022
     {
1007
 
        return;
 
1023
        fg = 7;
 
1024
        while (b < bmax)
 
1025
          {
 
1026
             if (fg != bg)
 
1027
               {
 
1028
                  b->fgbg = MAKE_COLOR(fg,bg);
 
1029
                  b->mono = SLTT_REV_MASK;
 
1030
                  b++;
 
1031
               }
 
1032
             if (fg == 0)
 
1033
               break;
 
1034
             fg--;
 
1035
          }
 
1036
        bg++;
 
1037
        if (bg == 8)
 
1038
          bg = 0;
1008
1039
     }
1009
 
   Ansi_Color_Map[obj].mono = mask & ATTR_MASK;
 
1040
 
 
1041
   Brush_Table[0].mono = 0;
 
1042
   Brushes_Initialized = 1;
 
1043
   return 0;
 
1044
}
 
1045
   
 
1046
   
 
1047
static Brush_Info_Type *get_brush_info (unsigned int color)
 
1048
{
 
1049
   if (Brushes_Initialized == 0)
 
1050
     initialize_brushes ();
 
1051
 
 
1052
   color &= SLSMG_COLOR_MASK;
 
1053
 
 
1054
   if (color >= JMAX_COLORS)
 
1055
     color = 0;
 
1056
 
 
1057
   return Brush_Table + color;
 
1058
}
 
1059
 
 
1060
static SLtt_Char_Type get_brush_attr (unsigned int color)
 
1061
{
 
1062
   Brush_Info_Type *b;
 
1063
   
 
1064
   if (NULL == (b = get_brush_info (color)))
 
1065
     return (SLtt_Char_Type)-1;
 
1066
   
 
1067
   if (SLtt_Use_Ansi_Colors)
 
1068
     return b->fgbg;
 
1069
   
 
1070
   return b->mono;
 
1071
}
 
1072
 
 
1073
static SLtt_Char_Type get_brush_fgbg (unsigned int color)
 
1074
{
 
1075
   return get_brush_info(color)->fgbg;
 
1076
}
 
1077
 
 
1078
int SLtt_set_mono (int obj, char *what, SLtt_Char_Type mask)
 
1079
{
 
1080
   Brush_Info_Type *b;
 
1081
 
 
1082
   (void) what;
 
1083
   if (NULL == (b = get_brush_info (obj)))
 
1084
     return -1;
 
1085
   
 
1086
   b->mono = mask & ATTR_MASK;
 
1087
   return 0;
1010
1088
}
1011
1089
 
1012
1090
static char *check_color_for_digit_form (char *color)
1095
1173
   return 0;
1096
1174
}
1097
1175
 
1098
 
static unsigned char FgBg_Stats[JMAX_COLORS];
1099
 
 
1100
1176
static int Color_0_Modified = 0;
1101
1177
 
1102
 
void SLtt_set_color_object (int obj, SLtt_Char_Type attr)
 
1178
int SLtt_set_color_object (int obj, SLtt_Char_Type attr)
1103
1179
{
1104
 
   char *cust_esc;
1105
 
 
1106
 
   if ((obj < 0) || (obj >= JMAX_COLORS)) return;
1107
 
 
1108
 
   cust_esc = Ansi_Color_Map[obj].custom_esc;
1109
 
   if (cust_esc != NULL)
1110
 
     {
1111
 
        SLfree (cust_esc);
1112
 
        FgBg_Stats[(Ansi_Color_Map[obj].fgbg >> 8) & 0x7F] -= 1;
1113
 
        Ansi_Color_Map[obj].custom_esc = NULL;
1114
 
     }
1115
 
 
1116
 
   Ansi_Color_Map[obj].fgbg = attr;
 
1180
   Brush_Info_Type *b;
 
1181
   
 
1182
   if (NULL == (b = get_brush_info (obj)))
 
1183
     return -1;
 
1184
 
 
1185
   b->fgbg = attr;
1117
1186
   if (obj == 0) Color_0_Modified = 1;
1118
1187
 
1119
 
   if (_SLtt_color_changed_hook != NULL)
1120
 
     (*_SLtt_color_changed_hook)();
 
1188
   if (_pSLtt_color_changed_hook != NULL)
 
1189
     (*_pSLtt_color_changed_hook)();
 
1190
   
 
1191
   return 0;
1121
1192
}
1122
1193
 
1123
1194
SLtt_Char_Type SLtt_get_color_object (int obj)
1124
1195
{
1125
 
   if ((obj < 0) || (obj >= JMAX_COLORS)) return 0;
1126
 
   return Ansi_Color_Map[obj].fgbg;
 
1196
   return get_brush_fgbg (obj);
1127
1197
}
1128
1198
 
1129
 
void SLtt_add_color_attribute (int obj, SLtt_Char_Type attr)
 
1199
int SLtt_add_color_attribute (int obj, SLtt_Char_Type attr)
1130
1200
{
1131
 
   if ((obj < 0) || (obj >= JMAX_COLORS)) return;
1132
 
 
1133
 
   Ansi_Color_Map[obj].fgbg |= (attr & ATTR_MASK);
 
1201
   Brush_Info_Type *b;
 
1202
   
 
1203
   if (NULL == (b = get_brush_info (obj)))
 
1204
     return -1;
 
1205
 
 
1206
   b->fgbg |= (attr & ATTR_MASK);
 
1207
 
1134
1208
   if (obj == 0) Color_0_Modified = 1;
1135
 
   if (_SLtt_color_changed_hook != NULL)
1136
 
     (*_SLtt_color_changed_hook)();
 
1209
   if (_pSLtt_color_changed_hook != NULL)
 
1210
     (*_pSLtt_color_changed_hook)();
 
1211
   
 
1212
   return 0;
1137
1213
}
1138
1214
 
1139
1215
static SLtt_Char_Type fb_to_fgbg (SLtt_Char_Type f, SLtt_Char_Type b)
1252
1328
   return 0;
1253
1329
}
1254
1330
 
1255
 
void SLtt_set_color (int obj, char *what, char *fg, char *bg)
 
1331
int SLtt_set_color (int obj, char *what, char *fg, char *bg)
1256
1332
{
1257
1333
   SLtt_Char_Type fgbg;
1258
1334
 
1259
1335
   (void) what;
1260
 
   if ((obj < 0) || (obj >= JMAX_COLORS))
1261
 
     return;
1262
 
 
1263
 
   if (-1 != make_color_fgbg (fg, bg, &fgbg))
1264
 
     SLtt_set_color_object (obj, fgbg);
1265
 
}
1266
 
 
1267
 
void SLtt_set_color_fgbg (int obj, SLtt_Char_Type f, SLtt_Char_Type b)
1268
 
{
1269
 
   SLtt_set_color_object (obj, fb_to_fgbg (f, b));
1270
 
}
1271
 
 
1272
 
void SLtt_set_color_esc (int obj, char *esc)
1273
 
{
1274
 
   char *cust_esc;
1275
 
   SLtt_Char_Type fgbg = 0;
1276
 
   int i;
1277
 
 
1278
 
   if ((obj < 0) || (obj >= JMAX_COLORS))
1279
 
     {
1280
 
        return;
1281
 
     }
1282
 
 
1283
 
   cust_esc = Ansi_Color_Map[obj].custom_esc;
1284
 
   if (cust_esc != NULL)
1285
 
     {
1286
 
        SLfree (cust_esc);
1287
 
        FgBg_Stats[(Ansi_Color_Map[obj].fgbg >> 8) & 0x7F] -= 1;
1288
 
     }
1289
 
 
1290
 
   cust_esc = (char *) SLmalloc (strlen(esc) + 1);
1291
 
   if (cust_esc != NULL) strcpy (cust_esc, esc);
1292
 
 
1293
 
   Ansi_Color_Map[obj].custom_esc = cust_esc;
1294
 
   if (cust_esc == NULL) fgbg = 0;
1295
 
   else
1296
 
     {
1297
 
        /* The whole point of this is to generate a unique fgbg */
1298
 
        for (i = 0; i < JMAX_COLORS; i++)
1299
 
          {
1300
 
             if (FgBg_Stats[i] == 0) fgbg = i;
1301
 
 
1302
 
             if (obj == i) continue;
1303
 
             if ((Ansi_Color_Map[i].custom_esc) == NULL) continue;
1304
 
             if (!strcmp (Ansi_Color_Map[i].custom_esc, cust_esc))
1305
 
               {
1306
 
                  fgbg = (Ansi_Color_Map[i].fgbg >> 8) & 0x7F;
1307
 
                  break;
1308
 
               }
1309
 
          }
1310
 
        FgBg_Stats[fgbg] += 1;
1311
 
     }
1312
 
 
1313
 
   fgbg |= 0x80;
1314
 
   Ansi_Color_Map[obj].fgbg = (fgbg | (fgbg << 8)) << 8;
1315
 
   if (obj == 0) Color_0_Modified = 1;
1316
 
   if (_SLtt_color_changed_hook != NULL)
1317
 
     (*_SLtt_color_changed_hook)();
 
1336
   
 
1337
   if (-1 == make_color_fgbg (fg, bg, &fgbg))
 
1338
     return -1;
 
1339
 
 
1340
   return SLtt_set_color_object (obj, fgbg);
 
1341
}
 
1342
 
 
1343
int SLtt_set_color_fgbg (int obj, SLtt_Char_Type f, SLtt_Char_Type b)
 
1344
{
 
1345
   return SLtt_set_color_object (obj, fb_to_fgbg (f, b));
1318
1346
}
1319
1347
 
1320
1348
void SLtt_set_alt_char_set (int i)
1402
1430
void SLtt_reverse_video (int color)
1403
1431
{
1404
1432
   SLtt_Char_Type fgbg;
1405
 
   char *esc;
1406
1433
 
1407
1434
   if (Worthless_Highlight) return;
1408
 
   if ((color < 0) || (color >= JMAX_COLORS)) return;
1409
1435
 
1410
1436
   if (Video_Initialized == 0)
1411
1437
     {
1418
1444
        return;
1419
1445
     }
1420
1446
 
1421
 
   if (SLtt_Use_Ansi_Colors)
1422
 
     {
1423
 
        fgbg = Ansi_Color_Map[color].fgbg;
1424
 
        if ((esc = Ansi_Color_Map[color].custom_esc) != NULL)
1425
 
          {
1426
 
             if (fgbg != Current_Fgbg)
1427
 
               {
1428
 
                  Current_Fgbg = fgbg;
1429
 
                  tt_write_string (esc);
1430
 
                  return;
1431
 
               }
1432
 
          }
1433
 
     }
1434
 
   else fgbg = Ansi_Color_Map[color].mono;
 
1447
  fgbg = get_brush_attr (color);
1435
1448
 
1436
1449
   if (fgbg == Current_Fgbg) return;
1437
1450
   write_attributes (fgbg);
1453
1466
}
1454
1467
 
1455
1468
/* Highest bit represents the character set. */
1456
 
#define COLOR_MASK 0x7F00
1457
 
#define COLOR_OF(x) (((x)&COLOR_MASK)>>8)
1458
 
#define CHAR_OF(x) ((x)&0x80FF)
 
1469
#define COLOR_OF(a) ((a)->color & SLSMG_COLOR_MASK)
1459
1470
 
1460
 
#if SLTT_HAS_NON_BCE_SUPPORT
1461
 
static int bce_color_eqs (unsigned int a, unsigned int b)
 
1471
static int bce_color_eqs (SLsmg_Char_Type *a, SLsmg_Char_Type *b)
1462
1472
{
1463
 
   a = COLOR_OF(a);
1464
 
   b = COLOR_OF(b);
1465
 
   
1466
 
   if (a == b)
 
1473
   SLsmg_Color_Type ca, cb;
 
1474
   Brush_Info_Type *ba, *bb;
 
1475
 
 
1476
   ca = COLOR_OF(a);
 
1477
   cb = COLOR_OF(b);
 
1478
 
 
1479
   if (ca == cb)
1467
1480
     return 1;
1468
1481
 
 
1482
   ba = get_brush_info (ca);
 
1483
   bb = get_brush_info (cb);
 
1484
   
1469
1485
   if (SLtt_Use_Ansi_Colors == 0)
1470
 
     return Ansi_Color_Map[a].mono == Ansi_Color_Map[b].mono;
 
1486
     return ba->mono == bb->mono;
1471
1487
 
1472
1488
   if (Bce_Color_Offset == 0)
1473
 
     return Ansi_Color_Map[a].fgbg == Ansi_Color_Map[b].fgbg;
1474
 
   
 
1489
     return ba->fgbg == bb->fgbg;
 
1490
 
1475
1491
   /* If either are color 0, then we do not know what that means since the
1476
1492
    * terminal does not support BCE */
1477
 
   if ((a == 0) || (b == 0))
 
1493
   if ((ca == 0) || (cb == 0))
1478
1494
     return 0;
1479
 
     
1480
 
   return Ansi_Color_Map[a-1].fgbg == Ansi_Color_Map[b-1].fgbg;
 
1495
   
 
1496
   return get_brush_fgbg (ca-1) == get_brush_fgbg(cb-1);
1481
1497
}
1482
 
#define COLOR_EQS(a,b) bce_color_eqs (a,b)
1483
 
#else
1484
 
# define COLOR_EQS(a, b) \
1485
 
   (SLtt_Use_Ansi_Colors \
1486
 
    ? (Ansi_Color_Map[COLOR_OF(a)].fgbg == Ansi_Color_Map[COLOR_OF(b)].fgbg)\
1487
 
    :  (Ansi_Color_Map[COLOR_OF(a)].mono == Ansi_Color_Map[COLOR_OF(b)].mono))
1488
 
#endif
1489
 
 
1490
 
#define CHAR_EQS(a, b) (((a) == (b))\
1491
 
                        || ((CHAR_OF(a)==CHAR_OF(b)) && COLOR_EQS(a,b)))
1492
1498
 
1493
1499
/* The whole point of this routine is to prevent writing to the last column
1494
1500
 * and last row on terminals with automatic margins.
1502
1508
   len = strlen (str);
1503
1509
   if (Automatic_Margins && (Cursor_r + 1 == SLtt_Screen_Rows))
1504
1510
     {
1505
 
        if (len + (unsigned int) Cursor_c >= (unsigned int) SLtt_Screen_Cols)
1506
 
          {
1507
 
             /* For now, just do not write there.  Later, something more
1508
 
              * sophisticated will be implemented.
1509
 
              */
1510
 
             if (SLtt_Screen_Cols > Cursor_c)
1511
 
               len = SLtt_Screen_Cols - Cursor_c - 1;
1512
 
             else 
1513
 
               len = 0;
1514
 
          }
 
1511
        if (_pSLtt_UTF8_Mode == 0) 
 
1512
         {
 
1513
           if (len + (unsigned int) Cursor_c >= (unsigned int) SLtt_Screen_Cols)
 
1514
             {
 
1515
                /* For now, just do not write there.  Later, something more
 
1516
                * sophisticated will be implemented.
 
1517
                */
 
1518
                if (SLtt_Screen_Cols > Cursor_c)
 
1519
                  len = SLtt_Screen_Cols - Cursor_c - 1;
 
1520
                else 
 
1521
                  len = 0;
 
1522
             }
 
1523
         }
 
1524
       else
 
1525
         {
 
1526
            unsigned int nchars = SLutf8_strlen((SLuchar_Type *)str, 1);
 
1527
            if (nchars + (unsigned int) Cursor_c >= (unsigned int) SLtt_Screen_Cols)
 
1528
             {
 
1529
               if (SLtt_Screen_Cols > Cursor_c)
 
1530
                 {
 
1531
                    char *p;
 
1532
                    nchars = SLtt_Screen_Cols - Cursor_c - 1;
 
1533
                    p = (char *)SLutf8_skip_chars((SLuchar_Type *) str, (SLuchar_Type *)(str + len), nchars, NULL, 1);
 
1534
                    len = p - str;
 
1535
                 }
 
1536
               else
 
1537
                  len = 0; 
 
1538
             }
 
1539
         }
1515
1540
     }
1516
1541
   tt_write (str, len);
1517
1542
}
1518
1543
 
1519
 
static void send_attr_str (SLsmg_Char_Type *s)
 
1544
static void send_attr_str (SLsmg_Char_Type *s, SLsmg_Char_Type *smax)
1520
1545
{
1521
 
   unsigned char out[SLTT_MAX_SCREEN_COLS], ch, *p;
 
1546
   unsigned char out[1+SLUTF8_MAX_MBLEN*SLSMG_MAX_CHARS_PER_CELL*SLTT_MAX_SCREEN_COLS];
 
1547
   unsigned char *p, *pmax;
1522
1548
   register SLtt_Char_Type attr;
1523
 
   register SLsmg_Char_Type sh;
1524
 
   int color, last_color = -1;
 
1549
   SLsmg_Color_Type color, last_color = (SLsmg_Color_Type)-1;
 
1550
   int dcursor_c;
1525
1551
 
1526
1552
   p = out;
1527
 
   while (0 != (sh = *s++))
 
1553
   pmax = p + (sizeof (out)-1);
 
1554
 
 
1555
   dcursor_c = 0;
 
1556
   while (s < smax)
1528
1557
     {
1529
 
        ch = sh & 0xFF;
1530
 
        color = ((int) sh & 0xFF00) >> 8;
 
1558
        SLwchar_Type wch;
 
1559
        unsigned int nchars;
 
1560
 
 
1561
        if (0 == (nchars = s->nchars))
 
1562
          {
 
1563
             /* 2nd element of a char that occupies two columns */
 
1564
             s++;
 
1565
             if (_pSLtt_UTF8_Mode == 0)
 
1566
               *p++ = ' ';
 
1567
             dcursor_c++;
 
1568
             continue;
 
1569
          }
 
1570
 
 
1571
        color = s->color;
1531
1572
 
1532
1573
#if SLTT_HAS_NON_BCE_SUPPORT
1533
1574
        if (Bce_Color_Offset
1535
1576
          color -= Bce_Color_Offset;
1536
1577
#endif
1537
1578
 
 
1579
        wch = s->wchars[0];
 
1580
 
1538
1581
        if (color != last_color)
1539
1582
          {
1540
 
             if (SLtt_Use_Ansi_Colors) attr = Ansi_Color_Map[color & 0x7F].fgbg;
1541
 
             else attr = Ansi_Color_Map[color & 0x7F].mono;
 
1583
             attr = get_brush_attr (color);
1542
1584
 
1543
 
             if (sh & 0x8000) /* alternate char set */
 
1585
             if (color & SLSMG_ACS_MASK) /* alternate char set */
1544
1586
               {
1545
1587
                  if (SLtt_Use_Blink_For_ACS)
1546
1588
                    {
1551
1593
 
1552
1594
             if (attr != Current_Fgbg)
1553
1595
               {
1554
 
                  if ((ch != ' ') ||
 
1596
                  if ((wch != ' ')
 
1597
                      || (nchars > 1)
1555
1598
                      /* it is a space so only consider it different if it
1556
1599
                       * has different attributes.
1557
1600
                       */
1558
 
                      (attr != Current_Fgbg))
1559
 
                    /* The previous line was: */
1560
 
                    /* (attr & BGALL_MASK) != (Current_Fgbg & BGALL_MASK)) */
1561
 
                    /* However, it does not account for ACS */
 
1601
                      || (attr != Current_Fgbg)
 
1602
                      )
1562
1603
                    {
1563
1604
                       if (p != out)
1564
1605
                         {
1565
1606
                            *p = 0;
1566
1607
                            write_string_with_care ((char *) out);
1567
 
                            Cursor_c += (int) (p - out);
1568
1608
                            p = out;
1569
 
                         }
1570
 
 
1571
 
                       if (SLtt_Use_Ansi_Colors && (NULL != Ansi_Color_Map[color & 0x7F].custom_esc))
1572
 
                         {
1573
 
                            tt_write_string (Ansi_Color_Map[color & 0x7F].custom_esc);
1574
 
                            /* Just in case the custom escape sequence screwed up
1575
 
                             * the alt character set state...
1576
 
                             */
1577
 
                            if ((attr & SLTT_ALTC_MASK) != (Current_Fgbg & SLTT_ALTC_MASK))
1578
 
                              SLtt_set_alt_char_set ((int) (attr & SLTT_ALTC_MASK));
1579
 
                            Current_Fgbg = attr;
1580
 
                         }
1581
 
                       else write_attributes (attr);
1582
 
 
 
1609
                            Cursor_c += dcursor_c;
 
1610
                            dcursor_c = 0;
 
1611
                         }
 
1612
                       write_attributes (attr);
1583
1613
                       last_color = color;
1584
1614
                    }
1585
1615
               }
1586
1616
          }
1587
 
        *p++ = ch;
 
1617
        
 
1618
        if ((wch < 0x80) && (nchars == 1))
 
1619
          *p++ = (unsigned char) wch;
 
1620
        else if (_pSLtt_UTF8_Mode == 0)
 
1621
          {
 
1622
             if (wch > 255)
 
1623
               wch = '?';
 
1624
             else if (wch < (SLwchar_Type)SLsmg_Display_Eight_Bit)
 
1625
               wch = '?';
 
1626
             *p++ = (unsigned char) wch;
 
1627
          }
 
1628
        else
 
1629
          {
 
1630
             unsigned int i;
 
1631
             for (i = 0; i < nchars; i++)
 
1632
               {
 
1633
                  if (NULL == (p = SLutf8_encode (s->wchars[i], p, pmax-p)))
 
1634
                    {
 
1635
                       fprintf (stderr, "*** send_attr_str: buffer too small\n");
 
1636
                       return;
 
1637
                    }
 
1638
               }
 
1639
          }
 
1640
        dcursor_c++;
 
1641
        s++;
1588
1642
     }
1589
1643
   *p = 0;
1590
1644
   if (p != out) write_string_with_care ((char *) out);
1591
 
   Cursor_c += (int) (p - out);
 
1645
   Cursor_c += dcursor_c;
1592
1646
}
1593
1647
 
1594
1648
static void forward_cursor (unsigned int n, int row)
1612
1666
   if (n <= 4)
1613
1667
     {
1614
1668
        SLtt_normal_video ();
 
1669
#if 0
 
1670
        if (n >= sizeof (buf))
 
1671
          n = sizeof (buf) - 1;
 
1672
#endif
1615
1673
        SLMEMSET (buf, ' ', n);
1616
1674
        buf[n] = 0;
1617
1675
        write_string_with_care (buf);
1633
1691
 * space character as is assumed below.
1634
1692
 */
1635
1693
 
 
1694
#define COLOR_EQS(a,b) ((COLOR_OF(a)==COLOR_OF(b)) || bce_color_eqs (a,b))
 
1695
#define CHARSET(a) ((a)->color&SLSMG_ACS_MASK)
 
1696
#define CHAR_EQS(a, b) (((a)->nchars==(b)->nchars) \
 
1697
                           && (((a)->nchars == 0) \
 
1698
                                  || ((((a)->wchars[0]==(b)->wchars[0]) \
 
1699
                                         && (0 == memcmp((a)->wchars, (b)->wchars, (a)->nchars*sizeof(SLwchar_Type)))) \
 
1700
                                         && (COLOR_EQS(a,b)) \
 
1701
                                         && (CHARSET(a)==CHARSET(b)))))
 
1702
 
 
1703
#define CHAR_EQS_SPACE(a) (((a)->wchars[0]==' ') && ((a)->color==0) && ((a)->nchars==1))
 
1704
 
1636
1705
void SLtt_smart_puts(SLsmg_Char_Type *neww, SLsmg_Char_Type *oldd, int len, int row)
1637
1706
{
1638
1707
   register SLsmg_Char_Type *p, *q, *qmax, *pmax, *buf;
1642
1711
#ifdef HP_GLITCH_CODE
1643
1712
   int handle_hp_glitch = 0;
1644
1713
#endif
1645
 
   SLsmg_Char_Type space_char;
 
1714
   SLsmg_Char_Type *space_char;
 
1715
   SLsmg_Char_Type space_char_buf;
 
1716
 
1646
1717
#define SLTT_USE_INSERT_HACK 1
1647
1718
#if SLTT_USE_INSERT_HACK
1648
 
   SLsmg_Char_Type insert_hack_prev = 0;
1649
 
   SLsmg_Char_Type insert_hack_char = 0;
 
1719
   SLsmg_Char_Type *insert_hack_prev = NULL;
 
1720
   SLsmg_Char_Type *insert_hack_char = NULL;
1650
1721
 
1651
1722
   if ((row + 1 == SLtt_Screen_Rows)
1652
1723
       && (len == SLtt_Screen_Cols)
1654
1725
       && (SLtt_Term_Cannot_Insert == 0)
1655
1726
       && Automatic_Margins)
1656
1727
     {
1657
 
        insert_hack_char = neww[len-1];
1658
 
        if (oldd[len-1] == insert_hack_char)
1659
 
          insert_hack_char = 0;
 
1728
        SLsmg_Char_Type *a, *b;
 
1729
        insert_hack_char = &neww[len-1];
 
1730
 
 
1731
        a = oldd+(len-1);
 
1732
        b = neww+(len-1);
 
1733
        
 
1734
        if (CHAR_EQS(a,b))
 
1735
          insert_hack_char = NULL;
1660
1736
        else 
1661
 
          insert_hack_prev = neww[len-2];
 
1737
          insert_hack_prev = &neww[len-2];
1662
1738
     }
1663
1739
#endif
1664
1740
     
 
1741
   memset ((char *) &space_char_buf, 0, sizeof (SLsmg_Char_Type));
 
1742
   space_char = &space_char_buf;
 
1743
   space_char->nchars = 1;
 
1744
   space_char->wchars[0] = ' ';
 
1745
 
1665
1746
   if (len > SLTT_MAX_SCREEN_COLS)
1666
1747
     len = SLTT_MAX_SCREEN_COLS;
1667
1748
 
1673
1754
   while (1)
1674
1755
     {
1675
1756
        if (q == qmax) return;
 
1757
 
1676
1758
#if SLANG_HAS_KANJI_SUPPORT
1677
1759
        if (*p & 0x80)
1678
1760
          { /* new is kanji */
1699
1781
             if (*q & 0x80) break; /* old is kanji */
1700
1782
          }
1701
1783
#endif
1702
 
        if (!CHAR_EQS(*q, *p)) break;
 
1784
        if (!CHAR_EQS(q, p)) break;
1703
1785
        q++; p++;
1704
1786
     }
1705
1787
 
1712
1794
 
1713
1795
        while (qq < qmax)
1714
1796
          {
1715
 
             if (*qq & 0xFF00)
 
1797
             if (qq->color)
1716
1798
               {
1717
1799
                  SLtt_normal_video ();
1718
1800
                  SLtt_del_eol ();
1726
1808
#endif
1727
1809
   /* Find where the last non-blank character on old/new screen is */
1728
1810
 
1729
 
   space_char = ' ';
1730
 
   if (CHAR_EQS(*(pmax-1), ' '))
 
1811
   if (CHAR_EQS_SPACE(pmax-1))
1731
1812
     {
1732
1813
        /* If we get here, then we can erase to the end of the line to create
1733
1814
         * the final space.  However, this will only work _if_ erasing will 
1738
1819
         */
1739
1820
        if ((Can_Background_Color_Erase)
1740
1821
            && SLtt_Use_Ansi_Colors)
1741
 
          space_char = *(pmax - 1);
 
1822
          space_char = pmax - 1;
1742
1823
 
1743
1824
        while (pmax > p)
1744
1825
          {
1745
1826
             pmax--;
1746
 
             if (!CHAR_EQS(*pmax, space_char))
 
1827
             if (!CHAR_EQS(pmax, space_char))
1747
1828
               {
1748
1829
                  pmax++;
1749
1830
                  break;
1754
1835
   while (qmax > q)
1755
1836
     {
1756
1837
        qmax--;
1757
 
        if (!CHAR_EQS(*qmax, space_char))
 
1838
        if (!CHAR_EQS(qmax, space_char))
1758
1839
          {
1759
1840
             qmax++;
1760
1841
             break;
1778
1859
     {
1779
1860
#endif
1780
1861
        /* Try use use erase to bol if possible */
1781
 
        if ((Del_Bol_Str != NULL) && (CHAR_OF(*neww) == ' '))
 
1862
        if ((Del_Bol_Str != NULL) && (CHAR_EQS_SPACE(neww)))
1782
1863
          {
1783
1864
             SLsmg_Char_Type *p1;
1784
 
             SLsmg_Char_Type blank;
 
1865
             SLsmg_Color_Type blank_color = 0;
1785
1866
 
1786
1867
             p1 = neww;
1787
1868
             if ((Can_Background_Color_Erase)
1788
1869
                 && SLtt_Use_Ansi_Colors)
1789
 
               blank = *p1;
1790
 
             /* black+white attributes do not support bce */
 
1870
               {
 
1871
                  SLsmg_Char_Type *blank = p1;
 
1872
                  blank_color = COLOR_OF(blank);
 
1873
                  while ((p1 < pmax) && (CHAR_EQS (p1, blank)))
 
1874
                    p1++;
 
1875
               }
1791
1876
             else
1792
 
               blank = ' ';
1793
 
 
1794
 
             while ((p1 < pmax) && (CHAR_EQS (*p1, blank)))
1795
 
               p1++;
1796
 
 
 
1877
               {
 
1878
                  /* black+white attributes do not support bce */
 
1879
                  while ((p1 < pmax) && (CHAR_EQS_SPACE (p1)))
 
1880
                    p1++;
 
1881
               }
 
1882
             
1797
1883
             /* Is this optimization worth it?  Assume Del_Bol_Str is ESC [ 1 K
1798
1884
              * It costs 4 chars + the space needed to properly position the 
1799
1885
              * cursor, e.g., ESC [ 10;10H. So, it costs at least 13 characters.
1807
1893
                  q = oldd + ofs;
1808
1894
                  p = p1;
1809
1895
                  SLtt_goto_rc (row, ofs - 1);
1810
 
                  SLtt_reverse_video (COLOR_OF(blank));
 
1896
                  SLtt_reverse_video (blank_color);
1811
1897
                  tt_write_string (Del_Bol_Str);
1812
1898
                  tt_write (" ", 1);
1813
1899
                  Cursor_c += 1;
1829
1915
        n_spaces = 0;
1830
1916
        while (p < pmax)
1831
1917
          {
1832
 
             if (CHAR_EQS(*q, ' ') && CHAR_EQS(*p, ' '))
 
1918
             if (CHAR_EQS_SPACE(q) && CHAR_EQS_SPACE(p))
1833
1919
               {
1834
1920
                  /* If *q is not a space, we would have to overwrite it.
1835
1921
                   * However, if *q is a space, then while *p is also one,
1838
1924
                  space_match = p;
1839
1925
                  p++; q++;
1840
1926
                  while ((p < pmax)
1841
 
                         && CHAR_EQS(*q, ' ')
1842
 
                         && CHAR_EQS(*p, ' '))
 
1927
                         && CHAR_EQS_SPACE(q)
 
1928
                         && CHAR_EQS_SPACE(p))
1843
1929
                    {
1844
1930
                       p++;
1845
1931
                       q++;
1894
1980
               }
1895
1981
#endif
1896
1982
 
1897
 
             if (CHAR_EQS(*q, *p)) break;
 
1983
             if (CHAR_EQS(q, p)) 
 
1984
               {
 
1985
                  /* Could be the second half of a double width character */
 
1986
                  if (p->nchars || q->nchars)
 
1987
                    break;
 
1988
               }
1898
1989
             *buf++ = *p++;
1899
1990
             q++;
1900
1991
          }
1901
 
        *buf = 0;
1902
1992
 
1903
1993
        /* At this point, the buffer contains characters that do not match */
1904
 
        if (buf != buffer) send_attr_str (buffer);
 
1994
        if (buf != buffer) send_attr_str (buffer, buf);
1905
1995
        buf = buffer;
1906
1996
 
1907
1997
        if (n_spaces 
1908
1998
            && ((p < pmax)             /* erase to eol will achieve this effect*/
1909
 
                || (space_char != ' ')))/* unless space_char is not a simple space */
 
1999
                || (!CHAR_EQS_SPACE(space_char))))/* unless space_char is not a simple space */
1910
2000
          {
1911
2001
             forward_cursor (n_spaces, row);
1912
2002
          }
1917
2007
        
1918
2008
        /* Note that from here on, the buffer will contain matched characters */
1919
2009
#if !SLANG_HAS_KANJI_SUPPORT
1920
 
        while ((p < pmax) && CHAR_EQS(*p, *q))
 
2010
        while ((p < pmax) && CHAR_EQS(p, q))
1921
2011
          {
1922
2012
             *buf++ = *p++;
1923
2013
             q++;
1996
2086
               }
1997
2087
             else
1998
2088
               {
1999
 
                  *buf = 0;
2000
 
                  send_attr_str (buffer);
 
2089
                  send_attr_str (buffer, buf);
2001
2090
               }
2002
2091
          }
2003
2092
     }
2009
2098
     }
2010
2099
   
2011
2100
#if SLTT_USE_INSERT_HACK
2012
 
   else if (insert_hack_char)
 
2101
   else if (insert_hack_char != NULL)
2013
2102
     {
2014
2103
        SLtt_goto_rc (SLtt_Screen_Rows-1, SLtt_Screen_Cols-2);
2015
 
        buffer[0] = insert_hack_char;
2016
 
        buffer[1] = 0;
2017
 
        send_attr_str (buffer);
 
2104
        send_attr_str (insert_hack_char, insert_hack_char+1);
2018
2105
        SLtt_goto_rc (SLtt_Screen_Rows-1, SLtt_Screen_Cols-2);
2019
 
        buffer[0] = insert_hack_prev;
2020
2106
        SLtt_begin_insert ();
2021
 
        send_attr_str (buffer);
 
2107
        send_attr_str (insert_hack_prev, insert_hack_prev+1);
2022
2108
        SLtt_end_insert ();
2023
2109
     }
2024
2110
#endif
2059
2145
 
2060
2146
static int Termcap_Initalized = 0;
2061
2147
 
 
2148
/* #define USE_TERMCAP 1 */
2062
2149
#ifdef USE_TERMCAP
2063
2150
/* Termcap based system */
2064
2151
static char Termcap_Buf[4096];
2065
 
static char Termcap_String_Buf[4096];
2066
 
static char *Termcap_String_Ptr;
 
2152
/* static char Termcap_String_Buf[4096]; */
 
2153
/* static char *Termcap_String_Ptr; */
2067
2154
extern char *tgetstr(char *, char **);
2068
2155
extern int tgetent(char *, char *);
2069
2156
extern int tgetnum(char *);
2113
2200
char *SLtt_tgetstr (char *cap)
2114
2201
{
2115
2202
   char *s;
2116
 
 
 
2203
#ifdef USE_TERMCAP
 
2204
   char area_buf[4096];
 
2205
   char *area;
 
2206
#endif
2117
2207
   if (Termcap_Initalized == 0)
2118
2208
     return NULL;
2119
2209
   
2120
2210
#ifdef USE_TERMCAP
2121
 
   s = tgetstr (cap, &Termcap_String_Ptr);
 
2211
   /* tmp_area = &Termcap_String_Buf; */
 
2212
   area = area_buf;
 
2213
   s = tgetstr (cap, &area);
 
2214
   if (area > area_buf + sizeof(area_buf))
 
2215
     {
 
2216
        SLang_exit_error ("\
 
2217
The termcap tgetstr appears to have overflowed a buffer.\n\
 
2218
The integrity of this program has been violated.\n");
 
2219
     }
2122
2220
#else
2123
 
   s = _SLtt_tigetstr (Terminfo, cap);
 
2221
   s = _pSLtt_tigetstr (Terminfo, cap);
2124
2222
#endif
2125
2223
 
2126
2224
   /* Do not strip pad info for alternate character set.  I need to make
2130
2228
   if (0 == strcmp (cap, "ac"))
2131
2229
     return s;
2132
2230
 
2133
 
   return fixup_tgetstr (s);
 
2231
   s = fixup_tgetstr (s);
 
2232
#ifdef USE_TERMCAP
 
2233
   if ((s >= area_buf) && (s < area_buf + sizeof(area_buf)))
 
2234
     {
 
2235
        /* It looks like tgetstr placed the object in the buffer and
 
2236
         * returned a pointer to that buffer.  So, we have to make a
 
2237
         * copy of it.
 
2238
         * 
 
2239
         * Yes, this introduces a leak...
 
2240
         */
 
2241
        s = SLmake_string (s);
 
2242
     }
 
2243
#endif
 
2244
   return s;
2134
2245
}
2135
2246
 
2136
2247
int SLtt_tgetnum (char *s)
2140
2251
#ifdef USE_TERMCAP
2141
2252
   return tgetnum (s);
2142
2253
#else
2143
 
   return _SLtt_tigetnum (Terminfo, s);
 
2254
   return _pSLtt_tigetnum (Terminfo, s);
2144
2255
#endif
2145
2256
}
2146
2257
 
2151
2262
#ifdef USE_TERMCAP
2152
2263
   return tgetflag (s);
2153
2264
#else
2154
 
   return _SLtt_tigetflag (Terminfo, s);
2155
 
#endif
2156
 
}
 
2265
   return _pSLtt_tigetflag (Terminfo, s);
 
2266
#endif
 
2267
}
 
2268
 
 
2269
#if 0
 
2270
int SLtt_tgetent(char *term)
 
2271
{
 
2272
   return SLtt_initialize(term) == 0;
 
2273
}
 
2274
 
 
2275
int SLtt_tputs(char *str, int affcnt, int (*p)(int))
 
2276
{
 
2277
   while (*str) (*p)(*str++);
 
2278
   return 0;
 
2279
}
 
2280
 
 
2281
 
 
2282
char *SLtt_tgoto(char *cap, int col, int row)
 
2283
{
 
2284
  static char buf[64];
 
2285
 
 
2286
  /* beware of overflows. 2^64 is 20 bytes printed */
 
2287
  if (strlen(cap) > 23)
 
2288
        strcpy(buf, "capability too long");
 
2289
  else
 
2290
        tt_sprintf(buf, cap, row, col);
 
2291
  return buf;
 
2292
}
 
2293
#endif
2157
2294
 
2158
2295
static int Vt100_Like = 0;
2159
2296
 
2195
2332
   int is_xterm;
2196
2333
   int almost_vtxxx;
2197
2334
 
 
2335
   if (_pSLtt_UTF8_Mode == -1)
 
2336
     _pSLtt_UTF8_Mode = _pSLutf8_mode;
 
2337
 
2198
2338
   if (SLang_TT_Write_FD == -1)
2199
2339
     {
2200
2340
        /* Apparantly, this cannot fail according to the man pages. */
2207
2347
        if (term == NULL)
2208
2348
          return -1;
2209
2349
     }
2210
 
#if 0
2211
 
   if (_SLsecure_issetugid ()
 
2350
 
 
2351
   if (_pSLsecure_issetugid ()
2212
2352
       && ((term[0] == '.') || (NULL != strchr(term, '/'))))
2213
2353
     return -1;
2214
 
#endif
 
2354
   
2215
2355
   Linux_Console = (!strncmp (term, "linux", 5)
2216
2356
# ifdef linux
2217
2357
                    || !strncmp(term, "con", 3)
2235
2375
                   || !strcmp (term, "screen"));
2236
2376
 
2237
2377
# ifndef USE_TERMCAP
2238
 
   if (NULL == (Terminfo = _SLtt_tigetent (term)))
 
2378
   if (NULL == (Terminfo = _pSLtt_tigetent (term)))
2239
2379
     {
2240
2380
        if (almost_vtxxx) /* Special cases. */
2241
2381
          {
2251
2391
# else                                 /* USE_TERMCAP */
2252
2392
   if (1 != tgetent(Termcap_Buf, term))
2253
2393
     return -1;
2254
 
   Termcap_String_Ptr = Termcap_String_Buf;
 
2394
   /* Termcap_String_Ptr = Termcap_String_Buf; */
2255
2395
# endif                                /* NOT USE_TERMCAP */
2256
2396
 
2257
2397
   Termcap_Initalized = 1;
2353
2493
    /* aixterm added by willi */
2354
2494
   if (is_xterm || !strncmp (term, "aixterm", 7))
2355
2495
     {
 
2496
#if 0
2356
2497
        Start_Alt_Chars_Str = "\016";
2357
2498
        End_Alt_Chars_Str = "\017";
2358
2499
        Enable_Alt_Char_Set = "\033(B\033)0";
 
2500
#else
 
2501
        Start_Alt_Chars_Str = "\033(0";
 
2502
        End_Alt_Chars_Str = "\033(B";
 
2503
        Enable_Alt_Char_Set = "";
 
2504
#endif
2359
2505
     }
2360
2506
 
2361
2507
   if ((SLtt_Graphics_Char_Pairs == NULL) &&
2425
2571
   if (Color_Fg_Str == NULL)
2426
2572
     {
2427
2573
        Color_Fg_Str = SLtt_tgetstr ("Sf");   /* setf */
2428
 
        Is_Fg_BGR = (Color_Fg_Str != NULL);
 
2574
        /* Is_Fg_BGR = (Color_Fg_Str != NULL); */
2429
2575
     }
2430
2576
   Color_Bg_Str = SLtt_tgetstr ("AB"); /* ANSI setbf */
2431
2577
   if (Color_Bg_Str == NULL)
2432
2578
     {
2433
2579
        Color_Bg_Str = SLtt_tgetstr ("Sb");   /* setb */
2434
 
        Is_Bg_BGR = (Color_Bg_Str != NULL);
 
2580
        /* Is_Fg_BGR = (Color_Bg_Str != NULL); */
2435
2581
     }
2436
2582
 
2437
2583
   if ((Max_Terminfo_Colors = SLtt_tgetnum ("Co")) < 0)
2595
2741
   SLtt_erase_line ();
2596
2742
   tt_write_string (Keypad_Reset_Str);
2597
2743
   tt_write_string (Term_Reset_Str);
 
2744
 
 
2745
   if (Mouse_Mode == 1)
 
2746
     SLtt_set_mouse_mode (0, 1);
 
2747
 
2598
2748
   SLtt_flush_output ();
2599
2749
   Video_Initialized = 0;
2600
2750
   return 0;
2616
2766
          return -1;
2617
2767
     }
2618
2768
 
 
2769
   Mouse_Mode = (mode != 0);
 
2770
 
2619
2771
   if (mode)
2620
2772
     tt_write_string ("\033[?9h");
2621
2773
   else
2708
2860
}
2709
2861
 
2710
2862
#if SLTT_HAS_NON_BCE_SUPPORT
2711
 
int _SLtt_get_bce_color_offset (void)
 
2863
int _pSLtt_get_bce_color_offset (void)
2712
2864
{
2713
2865
   if ((SLtt_Use_Ansi_Colors == 0)
2714
2866
       || Can_Background_Color_Erase
2716
2868
     Bce_Color_Offset = 0;
2717
2869
   else
2718
2870
     {
2719
 
        if (GET_BG(Ansi_Color_Map[0].fgbg) == SLSMG_COLOR_DEFAULT)
 
2871
        SLtt_Char_Type fgbg = get_brush_fgbg (0);
 
2872
        if (GET_BG(fgbg) == SLSMG_COLOR_DEFAULT)
2720
2873
          Bce_Color_Offset = 0;
2721
2874
        else
2722
2875
          Bce_Color_Offset = 1;
2725
2878
   return Bce_Color_Offset;
2726
2879
}
2727
2880
#endif
 
2881
 
 
2882
int SLtt_utf8_enable (int mode)
 
2883
{
 
2884
   if (mode == -1)
 
2885
     mode = _pSLutf8_mode;
 
2886
 
 
2887
   return _pSLtt_UTF8_Mode = mode;
 
2888
}
 
2889
 
 
2890
int SLtt_is_utf8_mode (void)
 
2891
{
 
2892
   int mode = _pSLtt_UTF8_Mode;
 
2893
   if (mode == -1)
 
2894
     mode = _pSLutf8_mode;
 
2895
 
 
2896
   return mode;
 
2897
}