forked from MidnightCommander/mc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathslsmg.c
1185 lines (981 loc) · 23.7 KB
/
slsmg.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* SLang Screen management routines */
/* Copyright (c) 1992, 1995 John E. Davis
* All rights reserved.
*
* You may distribute under the terms of either the GNU General Public
* License or the Perl Artistic License.
*/
#include "config.h"
#include <stdio.h>
#include <string.h>
#include "_slang.h"
typedef struct Screen_Type
{
int n; /* number of chars written last time */
int flags; /* line untouched, etc... */
unsigned short *old, *neew;
#ifndef pc_system
unsigned long old_hash, new_hash;
#endif
}
Screen_Type;
#define TOUCHED 0x1
#define TRASHED 0x2
#ifndef pc_system
#define MAX_SCREEN_SIZE 120
#else
#define MAX_SCREEN_SIZE 75
#endif
Screen_Type SL_Screen[MAX_SCREEN_SIZE];
static int Start_Col, Start_Row;
static int Screen_Cols, Screen_Rows;
static int This_Row, This_Col;
static int This_Color; /* only the first 8 bits of this
* are used. The highest bit is used
* to indicate an alternate character
* set. This leaves 127 userdefineable
* color combination.
*/
#ifndef pc_system
#define ALT_CHAR_FLAG 0x80
#else
#define ALT_CHAR_FLAG 0x00
#endif
int SLsmg_Newline_Moves = 0;
int SLsmg_Backspace_Moves = 0;
static void blank_line (unsigned short *p, int n, unsigned char ch)
{
register unsigned short *pmax = p + n;
register unsigned short color_ch;
color_ch = (This_Color << 8) | (unsigned short) ch;
while (p < pmax)
{
*p++ = color_ch;
}
}
static void clear_region (int row, int n)
{
int i;
int imax = row + n;
if (imax > Screen_Rows) imax = Screen_Rows;
for (i = row; i < imax; i++)
{
if (i >= 0)
{
blank_line (SL_Screen[i].neew, Screen_Cols, ' ');
SL_Screen[i].flags |= TOUCHED;
}
}
}
void SLsmg_erase_eol (void)
{
int r, c;
c = This_Col - Start_Col;
r = This_Row - Start_Row;
if ((r < 0) || (r >= Screen_Rows)) return;
if (c < 0) c = 0; else if (c >= Screen_Cols) return;
blank_line (SL_Screen[This_Row].neew + c , Screen_Cols - c, ' ');
SL_Screen[This_Row].flags |= TOUCHED;
}
static void scroll_up (void)
{
unsigned int i, imax;
unsigned short *neew;
neew = SL_Screen[0].neew;
imax = Screen_Rows - 1;
for (i = 0; i < imax; i++)
{
SL_Screen[i].neew = SL_Screen[i + 1].neew;
SL_Screen[i].flags |= TOUCHED;
}
SL_Screen[i].neew = neew;
SL_Screen[i].flags |= TOUCHED;
blank_line (neew, Screen_Cols, ' ');
This_Row--;
}
void SLsmg_gotorc (int r, int c)
{
This_Row = r;
This_Col = c;
}
int SLsmg_get_row (void)
{
return This_Row;
}
int SLsmg_get_column (void)
{
return This_Col;
}
void SLsmg_erase_eos (void)
{
SLsmg_erase_eol ();
clear_region (This_Row + 1, Screen_Rows);
}
static int This_Alt_Char;
#ifndef pc_system
void SLsmg_set_char_set (int i)
{
if (SLtt_Use_Blink_For_ACS) return; /* alt chars not used and the alt bit
* is used to indicate a blink.
*/
if (i) This_Alt_Char = ALT_CHAR_FLAG;
else This_Alt_Char = 0;
This_Color &= 0x7F;
This_Color |= This_Alt_Char;
}
#endif
void SLsmg_set_color (int color)
{
if (color < 0) return;
This_Color = color | This_Alt_Char;
}
void SLsmg_reverse_video (void)
{
SLsmg_set_color (1);
}
void SLsmg_normal_video (void)
{
This_Color = This_Alt_Char; /* reset video but NOT char set. */
}
static int point_visible (int col_too)
{
return ((This_Row >= Start_Row) && (This_Row < Start_Row + Screen_Rows)
&& ((col_too == 0)
|| ((This_Col >= Start_Col)
&& (This_Col < Start_Col + Screen_Cols))));
}
void SLsmg_printf (char *fmt, ...)
{
char p[1000];
va_list ap;
va_start(ap, fmt);
(void) g_vsnprintf(p, sizeof (p), fmt, ap);
va_end(ap);
SLsmg_write_string (p);
}
void SLsmg_write_string (char *str)
{
SLsmg_write_nchars (str, strlen (str));
}
void SLsmg_write_nstring (char *str, int n)
{
int width;
char blank = ' ';
if (str == NULL) width = 0;
else
{
width = strlen (str);
if (width > n) width = n;
SLsmg_write_nchars (str, width);
}
while (width++ < n) SLsmg_write_nchars (&blank, 1);
}
void SLsmg_write_wrapped_string (char *s, int r, int c, int dr, int dc, int fill)
{
register char ch, *p;
int maxc = dc;
if ((dr == 0) || (dc == 0)) return;
p = s;
dc = 0;
while (1)
{
ch = *p++;
if ((ch == 0) || (ch == '\n'))
{
int diff;
diff = maxc - dc;
SLsmg_gotorc (r, c);
SLsmg_write_nchars (s, dc);
if (fill && (diff > 0))
{
while (diff--) SLsmg_write_char (' ');
}
if ((ch == 0) || (dr == 1)) break;
r++;
dc = 0;
dr--;
s = p;
}
else if (dc == maxc)
{
SLsmg_gotorc (r, c);
SLsmg_write_nchars (s, dc + 1);
if (dr == 1) break;
r++;
dc = 0;
dr--;
s = p;
}
else dc++;
}
}
int SLsmg_Tab_Width = 8;
/* Minimum value for which eight bit char is displayed as is. */
#ifndef pc_system
int SLsmg_Display_Eight_Bit = 160;
static unsigned char Alt_Char_Set[129];/* 129th is used as a flag */
#else
int SLsmg_Display_Eight_Bit = 128;
#endif
void SLsmg_write_nchars (char *str, int n)
{
register unsigned short *p, old, neew, color;
unsigned char ch;
unsigned int flags;
int len, start_len, max_len;
char *str_max;
int newline_flag;
#ifndef pc_system
int alt_char_set_flag;
alt_char_set_flag = ((SLtt_Use_Blink_For_ACS == 0)
&& (This_Color & ALT_CHAR_FLAG));
#endif
str_max = str + n;
color = This_Color << 8;
top: /* get here only on newline */
newline_flag = 0;
start_len = Start_Col;
if (point_visible (0) == 0) return;
len = This_Col;
max_len = start_len + Screen_Cols;
p = SL_Screen[This_Row].neew;
if (len > start_len) p += (len - start_len);
flags = SL_Screen[This_Row].flags;
while ((len < max_len) && (str < str_max))
{
ch = (unsigned char) *str++;
#ifndef pc_system
if (alt_char_set_flag)
ch = Alt_Char_Set [ch & 0x7F];
#endif
if (((ch >= ' ') && (ch < 127))
|| (ch >= (unsigned char) SLsmg_Display_Eight_Bit)
#ifndef pc_system
|| alt_char_set_flag
#endif
)
{
len += 1;
if (len > start_len)
{
old = *p;
neew = color | (unsigned short) ch;
if (old != neew)
{
flags |= TOUCHED;
*p = neew;
}
p++;
}
}
else if ((ch == '\t') && (SLsmg_Tab_Width > 0))
{
n = len;
n += SLsmg_Tab_Width;
n = SLsmg_Tab_Width - (n % SLsmg_Tab_Width);
if (len + n > max_len) n = max_len - len;
neew = color | (unsigned short) ' ';
while (n--)
{
len += 1;
if (len > start_len)
{
if (*p != neew)
{
flags |= TOUCHED;
*p = neew;
}
p++;
}
}
}
else if (ch == '\n')
{
newline_flag = 1;
break;
}
else if ((ch == 0x8) && SLsmg_Backspace_Moves)
{
if (len != 0) len--;
}
else
{
if (ch & 0x80)
{
neew = color | (unsigned short) '~';
len += 1;
if (len > start_len)
{
if (*p != neew)
{
*p = neew;
flags |= TOUCHED;
}
p++;
if (len == max_len) break;
ch &= 0x7F;
}
}
len += 1;
if (len > start_len)
{
neew = color | (unsigned short) '^';
if (*p != neew)
{
*p = neew;
flags |= TOUCHED;
}
p++;
if (len == max_len) break;
}
if (ch == 127) ch = '?'; else ch = ch + '@';
len++;
if (len > start_len)
{
neew = color | (unsigned short) ch;
if (*p != neew)
{
*p = neew;
flags |= TOUCHED;
}
p++;
}
}
}
SL_Screen[This_Row].flags = flags;
This_Col = len;
if (SLsmg_Newline_Moves == 0)
return;
if (newline_flag == 0)
{
while (str < str_max)
{
if (*str == '\n') break;
str++;
}
if (str == str_max) return;
str++;
}
This_Row++;
This_Col = 0;
if (This_Row == Start_Row + Screen_Rows)
{
if (SLsmg_Newline_Moves > 0) scroll_up ();
}
goto top;
}
void SLsmg_write_char (char ch)
{
SLsmg_write_nchars (&ch, 1);
}
static int Cls_Flag;
void SLsmg_cls (void)
{
This_Color = 0;
clear_region (0, Screen_Rows);
This_Color = This_Alt_Char;
Cls_Flag = 1;
}
#if 0
static void do_copy (unsigned short *a, unsigned short *b)
{
unsigned short *amax = a + Screen_Cols;
while (a < amax) *a++ = *b++;
}
#endif
#ifndef pc_system
int SLsmg_Scroll_Hash_Border = 0;
static unsigned long compute_hash (unsigned short *s, int n)
{
register unsigned long h = 0, g;
register unsigned long sum = 0;
register unsigned short *smax, ch;
int is_blank = 2;
s += SLsmg_Scroll_Hash_Border;
smax = s + (n - SLsmg_Scroll_Hash_Border);
while (s < smax)
{
ch = *s++;
if (is_blank && ((ch & 0xFF) != 32)) is_blank--;
sum += ch;
h = sum + (h << 3);
if ((g = h & 0xE0000000UL) != 0)
{
h = h ^ (g >> 24);
h = h ^ g;
}
}
if (is_blank) return 0;
return h;
}
static unsigned long Blank_Hash;
static void try_scroll (void)
{
int i, j, di, r1, r2, rmin, rmax;
unsigned long hash;
int color, did_scroll = 0;
unsigned short *tmp;
int ignore;
/* find region limits. */
for (rmax = Screen_Rows - 1; rmax > 0; rmax--)
{
if (SL_Screen[rmax].new_hash != SL_Screen[rmax].old_hash)
{
r1 = rmax - 1;
if ((r1 == 0)
|| (SL_Screen[r1].new_hash != SL_Screen[r1].old_hash))
break;
rmax = r1;
}
}
for (rmin = 0; rmin < rmax; rmin++)
{
if (SL_Screen[rmin].new_hash != SL_Screen[rmin].old_hash)
{
r1 = rmin + 1;
if ((r1 == rmax)
|| (SL_Screen[r1].new_hash != SL_Screen[r1].old_hash))
break;
rmin = r1;
}
}
for (i = rmax; i > rmin; i--)
{
hash = SL_Screen[i].new_hash;
if (hash == Blank_Hash) continue;
if ((hash == SL_Screen[i].old_hash)
|| ((i + 1 < Screen_Rows) && (hash == SL_Screen[i + 1].old_hash))
|| ((i - 1 > rmin) && (SL_Screen[i].old_hash == SL_Screen[i - 1].new_hash)))
continue;
for (j = i - 1; j >= rmin; j--)
{
if (hash == SL_Screen[j].old_hash) break;
}
if (j < rmin) continue;
r2 = i; /* end scroll region */
di = i - j;
j--;
ignore = 0;
while ((j >= rmin) && (SL_Screen[j].old_hash == SL_Screen[j + di].new_hash))
{
if (SL_Screen[j].old_hash == Blank_Hash) ignore++;
j--;
}
r1 = j + 1;
/* If this scroll only scrolls this line into place, don't do it.
*/
if ((di > 1) && (r1 + di + ignore == r2)) continue;
/* If there is anything in the scrolling region that is ok, abort the
* scroll.
*/
for (j = r1; j <= r2; j++)
{
if ((SL_Screen[j].old_hash != Blank_Hash)
&& (SL_Screen[j].old_hash == SL_Screen[j].new_hash))
{
/* See if the scroll is happens to scroll this one into place. */
if ((j + di > r2) || (SL_Screen[j].old_hash != SL_Screen[j + di].new_hash))
break;
}
}
if (j <= r2) continue;
color = This_Color; This_Color = 0;
did_scroll = 1;
SLtt_normal_video ();
SLtt_set_scroll_region (r1, r2);
SLtt_goto_rc (0, 0);
SLtt_reverse_index (di);
SLtt_reset_scroll_region ();
/* Now we have a hole in the screen. Make the virtual screen look
* like it.
*/
for (j = r1; j <= r2; j++) SL_Screen[j].flags = TOUCHED;
while (di--)
{
tmp = SL_Screen[r2].old;
for (j = r2; j > r1; j--)
{
SL_Screen[j].old = SL_Screen[j - 1].old;
SL_Screen[j].old_hash = SL_Screen[j - 1].old_hash;
}
SL_Screen[r1].old = tmp;
blank_line (SL_Screen[r1].old, Screen_Cols, ' ');
SL_Screen[r1].old_hash = Blank_Hash;
r1++;
}
This_Color = color;
}
if (did_scroll) return;
/* Try other direction */
for (i = rmin; i < rmax; i++)
{
hash = SL_Screen[i].new_hash;
if (hash == Blank_Hash) continue;
if (hash == SL_Screen[i].old_hash) continue;
/* find a match further down screen */
for (j = i + 1; j <= rmax; j++)
{
if (hash == SL_Screen[j].old_hash) break;
}
if (j > rmax) continue;
r1 = i; /* beg scroll region */
di = j - i; /* number of lines to scroll */
j++; /* since we know this is a match */
/* find end of scroll region */
ignore = 0;
while ((j <= rmax) && (SL_Screen[j].old_hash == SL_Screen[j - di].new_hash))
{
if (SL_Screen[j].old_hash == Blank_Hash) ignore++;
j++;
}
r2 = j - 1; /* end of scroll region */
/* If this scroll only scrolls this line into place, don't do it.
*/
if ((di > 1) && (r1 + di + ignore == r2)) continue;
/* If there is anything in the scrolling region that is ok, abort the
* scroll.
*/
for (j = r1; j <= r2; j++)
{
if ((SL_Screen[j].old_hash != Blank_Hash)
&& (SL_Screen[j].old_hash == SL_Screen[j].new_hash))
{
if ((j - di < r1) || (SL_Screen[j].old_hash != SL_Screen[j - di].new_hash))
break;
}
}
if (j <= r2) continue;
color = This_Color; This_Color = 0;
SLtt_normal_video ();
SLtt_set_scroll_region (r1, r2);
SLtt_goto_rc (0, 0); /* relative to scroll region */
SLtt_delete_nlines (di);
SLtt_reset_scroll_region ();
/* Now we have a hole in the screen. Make the virtual screen look
* like it.
*/
for (j = r1; j <= r2; j++) SL_Screen[j].flags = TOUCHED;
while (di--)
{
tmp = SL_Screen[r1].old;
for (j = r1; j < r2; j++)
{
SL_Screen[j].old = SL_Screen[j + 1].old;
SL_Screen[j].old_hash = SL_Screen[j + 1].old_hash;
}
SL_Screen[r2].old = tmp;
blank_line (SL_Screen[r2].old, Screen_Cols, ' ');
SL_Screen[r2].old_hash = Blank_Hash;
r2--;
}
This_Color = color;
}
}
#endif /* NOT pc_system */
static int Smg_Inited;
void SLsmg_refresh (void)
{
int i;
if (Smg_Inited == 0) return;
#ifndef pc_system
for (i = 0; i < Screen_Rows; i++)
{
if (SL_Screen[i].flags == 0) continue;
SL_Screen[i].new_hash = compute_hash (SL_Screen[i].neew, Screen_Cols);
}
#endif
if (Cls_Flag)
{
SLtt_normal_video (); SLtt_cls ();
}
#ifndef pc_system
else if (SLtt_Term_Cannot_Scroll == 0) try_scroll ();
#endif
for (i = 0; i < Screen_Rows; i++)
{
int trashed;
if (SL_Screen[i].flags == 0) continue;
if (SL_Screen[i].flags & TRASHED)
{
SLtt_goto_rc (i, -1); /* Force cursor to move */
SLtt_goto_rc (i, 0);
if (Cls_Flag == 0) SLtt_del_eol ();
trashed = 1;
}
else trashed = 0;
if (Cls_Flag || trashed)
{
int color = This_Color;
This_Color = 0;
blank_line (SL_Screen[i].old, Screen_Cols, ' ');
This_Color = color;
}
SL_Screen[i].old[Screen_Cols] = 0;
SL_Screen[i].neew[Screen_Cols] = 0;
SLtt_smart_puts (SL_Screen[i].neew, SL_Screen[i].old, Screen_Cols, i);
SLMEMCPY ((char *) SL_Screen[i].old, (char *) SL_Screen[i].neew,
Screen_Cols * sizeof (short));
SL_Screen[i].flags = 0;
#ifndef pc_system
SL_Screen[i].old_hash = SL_Screen[i].new_hash;
#endif
}
if (point_visible (1)) SLtt_goto_rc (This_Row - Start_Row, This_Col - Start_Col);
SLtt_flush_output ();
Cls_Flag = 0;
}
static int compute_clip (int row, int n, int box_start, int box_end,
int *rmin, int *rmax)
{
int row_max;
if (n < 0) return 0;
if (row >= box_end) return 0;
row_max = row + n;
if (row_max <= box_start) return 0;
if (row < box_start) row = box_start;
if (row_max >= box_end) row_max = box_end;
*rmin = row;
*rmax = row_max;
return 1;
}
void SLsmg_touch_lines (int row, int n)
{
int i;
int r1, r2;
if (0 == compute_clip (row, n, Start_Row, Start_Row + Screen_Rows, &r1, &r2))
return;
r1 -= Start_Row;
r2 -= Start_Row;
for (i = r1; i < r2; i++)
{
SL_Screen[i].flags |= TRASHED;
}
}
#ifndef pc_system
static const char Fake_Alt_Char_Pairs [] = "a:j+k+l+m+q-t+u+v+w+x|n+`+f\\g#~o,<+>.v-^h#0#";
static void init_alt_char_set (void)
{
int i;
const unsigned char *p, *pmax;
unsigned char ch;
if (Alt_Char_Set[128] == 128) return;
i = 32;
memset ((char *)Alt_Char_Set, ' ', i);
while (i <= 128)
{
Alt_Char_Set [i] = i;
i++;
}
/* Map to VT100 */
if (SLtt_Has_Alt_Charset)
{
p = (unsigned char *) SLtt_Graphics_Char_Pairs;
if (p == NULL) return;
}
else p = (unsigned char *) Fake_Alt_Char_Pairs;
pmax = p + strlen ((char *) p);
/* Some systems have messed up entries for this */
while (p < pmax)
{
ch = *p++;
ch &= 0x7F; /* should be unnecessary */
Alt_Char_Set [ch] = *p;
p++;
}
}
#endif
#ifndef pc_system
# define BLOCK_SIGNALS SLsig_block_signals ();
# define UNBLOCK_SIGNALS SLsig_unblock_signals ();
#else
# define BLOCK_SIGNALS
# define UNBLOCK_SIGNALS
#endif
static int Smg_Suspended;
void SLsmg_suspend_smg (void)
{
BLOCK_SIGNALS
if (Smg_Suspended == 0)
{
SLtt_reset_video ();
Smg_Suspended = 1;
}
UNBLOCK_SIGNALS
}
void SLsmg_resume_smg (void)
{
int i;
BLOCK_SIGNALS
if (Smg_Suspended == 0)
{
UNBLOCK_SIGNALS
return;
}
Smg_Suspended = 0;
SLtt_init_video ();
Cls_Flag = 1;
for (i = 0; i < Screen_Rows; i++)
SL_Screen[i].flags |= TRASHED;
SLsmg_refresh ();
UNBLOCK_SIGNALS
}
int SLsmg_init_smg (void)
{
int i, len;
unsigned short *old, *neew;
BLOCK_SIGNALS
if (Smg_Inited) SLsmg_reset_smg ();
SLtt_init_video ();
Screen_Cols = SLtt_Screen_Cols;
Screen_Rows = SLtt_Screen_Rows;
This_Col = This_Row = Start_Col = Start_Row = 0;
This_Color = 0;
This_Alt_Char = 0;
Cls_Flag = 1;
#ifndef pc_system
init_alt_char_set ();
#endif
len = Screen_Cols + 3;
for (i = 0; i < Screen_Rows; i++)
{
if ((NULL == (old = (unsigned short *) SLMALLOC (sizeof(short) * len)))
|| ((NULL == (neew = (unsigned short *) SLMALLOC (sizeof(short) * len)))))
{
SLang_Error = SL_MALLOC_ERROR;
UNBLOCK_SIGNALS
return 0;
}
blank_line (old, len, ' ');
blank_line (neew, len, ' ');
SL_Screen[i].old = old;
SL_Screen[i].neew = neew;
SL_Screen[i].flags = 0;
#ifndef pc_system
Blank_Hash = compute_hash (old, Screen_Cols);
SL_Screen[i].new_hash = SL_Screen[i].old_hash = Blank_Hash;
#endif
}
Smg_Inited = 1;
UNBLOCK_SIGNALS
return 1;
}
void SLsmg_reset_smg (void)
{
int i;
BLOCK_SIGNALS
if (Smg_Inited == 0)
{
UNBLOCK_SIGNALS
return;
}
for (i = 0; i < Screen_Rows; i++)
{
if (SL_Screen[i].old != NULL) SLFREE (SL_Screen[i].old);
if (SL_Screen[i].neew != NULL) SLFREE (SL_Screen[i].neew);
SL_Screen[i].old = SL_Screen[i].neew = NULL;
}
SLtt_reset_video ();
This_Alt_Char = This_Color = 0;
Smg_Inited = 0;
UNBLOCK_SIGNALS
}
unsigned short SLsmg_char_at (void)
{
if (point_visible (1))
{
return SL_Screen[This_Row - Start_Row].neew[This_Col - Start_Col];
}
return 0;
}
void SLsmg_vprintf (char *fmt, va_list ap)
{
char p[1000];
(void) g_vsnprintf(p, sizeof (p), fmt, ap);
SLsmg_write_string (p);
}
void SLsmg_set_screen_start (int *r, int *c)
{
int or = Start_Row, oc = Start_Col;
if (c == NULL) Start_Col = 0;
else
{
Start_Col = *c;
*c = oc;
}
if (r == NULL) Start_Row = 0;
else
{
Start_Row = *r;
*r = or;
}
}
void SLsmg_draw_object (int r, int c, unsigned char object)
{
This_Row = r; This_Col = c;
if (point_visible (1))
{
int color = This_Color;
This_Color |= ALT_CHAR_FLAG;
SLsmg_write_char (object);
This_Color = color;
}
This_Col = c + 1;
}
void SLsmg_draw_hline (int n)
{
static unsigned char hbuf[16];
int count;
int cmin, cmax;
int final_col = This_Col + n;
int save_color;
if ((This_Row < Start_Row) || (This_Row >= Start_Row + Screen_Rows)
|| (0 == compute_clip (This_Col, n, Start_Col, Start_Col + Screen_Cols,
&cmin, &cmax)))
{
This_Col = final_col;