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 #include <stdio.h>
72 #include <dos.h>
73 #include <ws.h>
74 #include <cat.h>
75 #include <wsmincap.h>
76 #include "wstdefs.h"
77 #include "wsttype.h"
78 #include "wstglob.h"
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100 byteshift (number, high, low)
101 int number;
102 byte *high,
103 *low;
104
105 {
106 if (number < MAX_8_BIT_VALUE) {
107 *high = 0;
108 *low = number;
109 }
110 else {
111 *high = number / MAX_8_BIT_VALUE;
112 *low = number % MAX_8_BIT_VALUE;
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 catstr (target, add_on, add_on_size, target_name, target_size)
140 char *target,
141 *add_on,
142 target_name [];
143 int add_on_size,
144 target_size;
145 {
146 register int old_length;
147
148 old_length = strlen(target);
149
150 if (old_length + add_on_size > target_size - 1) {
151
152 put_screen_str ("Program error: A string size overflow has been detected in ");
153 put_screen_str (target_name);
154
155 exit (1);
156 }
157
158 movmem (add_on, &target [strlen (target)], add_on_size);
159 target [ old_length + add_on_size] = NUL_TERMINATOR;
160 return;
161 }
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181 clear_screen ()
182
183 {
184 clear_window();
185
186 screen.curcol = CURSOR_HOME_COL;
187 screen.curlin = CURSOR_HOME_ROW;
188 screen.EOP_ct = 0;
189 ds.ccol = 0;
190 ds.lct = 0;
191 ds.splct [0] = NUL;
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 emit_msg(msg,msgl,pstr_sw)
221 char msg[];
222 int msgl, pstr_sw;
223 {
224 char *msg_ptr;
225
226 msg_ptr = msg;
227
228
229 while (msgl > 20) {
230 emit_msg_2(msg_ptr, 20, pstr_sw);
231 msg_ptr += 20;
232 msgl -= 20;
233 }
234 emit_msg_2(msg_ptr,msgl,pstr_sw);
235
236
237 if (screen.curcol < 1 || pstr_sw) {
238 ds.pstrl = 0;
239 setmem (ds.pstr, sizeof (ds.pstr), NUL);
240 kb.pos [0] = NUL;
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 emit_msg_2 (msg, msgl, pstr_sw)
268 char msg [];
269 int msgl,
270 pstr_sw;
271
272 {
273 int curc, curl,
274 ipstr,
275 newc, newl,
276 tab_width;
277 register int i;
278 char msg_line [256],
279 tab_space [12];
280
281
282
283
284
285
286
287 ipstr = 0;
288 setmem (msg_line, sizeof (msg_line), NUL);
289
290 curc = screen.curcol;
291 curl = screen.curlin;
292
293
294
295 for (i = 0; i < msgl; i++) {
296
297 if (checkkey() == ALT_B)
298 return;
299
300 switch (msg [i]) {
301 case 'A':
302 catstr (msg_line, &msg [i], 1, "msg_line-3",
303 sizeof (msg_line));
304
305 if (ds.do_ctl) {
306 curl -= max (newl, 1);
307 ds.do_ctl = OFF;
308 }
309 else
310 curc++;
311 break;
312
313 case 'B':
314 catstr (msg_line, &msg [i], 1, "msg_line-3",
315 sizeof (msg_line));
316
317 if (ds.do_ctl) {
318 curl += max (newl, 1);
319 ds.do_ctl = OFF;
320 }
321 else
322 curc++;
323 break;
324
325 case BEL:
326 catstr (msg_line, &msg [i], 1, "msg_line",
327 sizeof (msg_line));
328 break;
329
330 case BSP:
331 if (curc > 0) {
332 catstr (msg_line, &msg [i], 1,
333 "msg_line", sizeof (msg_line));
334 curc = max (curc - 1, 0);
335 }
336 break;
337
338 case 'C':
339 catstr (msg_line, &msg [i], 1, "msg_line-3",
340 sizeof (msg_line));
341
342 if (ds.do_ctl) {
343 curl += max (newl, 1);
344 ds.do_ctl = OFF;
345 }
346 else
347 curc++;
348 break;
349
350 case CR:
351 if (strlen (msg_line) > 0) {
352 catstr (msg_line, &msg [i], 1,
353 "msg_line", sizeof (msg_line));
354
355 putscr (msg_line, strlen (msg_line));
356 setmem (msg_line, sizeof (msg_line), NUL);
357 }
358
359 cursor_move (curl, 0);
360 curc = 0;
361
362 ds.pstrl = 0;
363 setmem (ds.pstr, sizeof (ds.pstr), NUL);
364 ipstr = i + 1;
365 break;
366
367 case 'D':
368 catstr (msg_line, &msg [i], 1, "msg_line-3",
369 sizeof (msg_line));
370
371 if (ds.do_ctl) {
372 curc -= max (newl, 1);
373 ds.do_ctl = OFF;
374 }
375 else
376 curc++;
377 break;
378
379 case ESC:
380 if (strlen (msg_line) > 0) {
381
382 putscr (msg_line, strlen (msg_line));
383 setmem (msg_line, sizeof (msg_line), NUL);
384 }
385
386 catstr (msg_line, &msg [i], 1, "msg_line-2",
387 sizeof (msg_line));
388 newc = 0;
389 newl = 0;
390 ds.do_ctl = ON;
391 break;
392
393 case 'G':
394 catstr (msg_line, &msg [i], 1, "msg_line-3",
395 sizeof (msg_line));
396
397 if (ds.do_ctl) {
398 curc = max (newc - 1, 0);
399 kb.pos [0] = curc;
400 ds.do_col = OFF;
401 ds.do_ctl = OFF;
402 ds.pstrl = 0;
403 setmem (ds.pstr, sizeof (ds.pstr), NUL);
404 ipstr = i + 1;
405
406 }
407 else
408 curc++;
409 break;
410
411 case 'H':
412 catstr (msg_line, &msg [i], 1, "msg_line-3",
413 sizeof (msg_line));
414
415 if (ds.do_ctl) {
416 curl = max (newl - 1, 0);
417 curc = max (newc - 1, 0);
418 kb.pos [0] = curc;
419 ds.do_col = OFF;
420 ds.do_ctl = OFF;
421 ds.pstrl = 0;
422 setmem (ds.pstr, sizeof (ds.pstr), NUL);
423 ipstr = i + 1;
424
425 }
426 else
427 curc++;
428 break;
429
430 case HT:
431 tab_width = next_tab (curc);
432 curc += tab_width;
433 catstr (msg_line, strncpy (tab_space,
434 spaces, tab_width), tab_width, "msg_line-4", sizeof (msg_line));
435 break;
436
437 case 'J':
438 catstr (msg_line, &msg [i], 1, "msg_line-5",
439 sizeof (msg_line));
440
441 if (ds.do_ctl) {
442 curl = 0;
443 curc = 0;
444 kb.pos [0] = 0;
445 ds.do_col = OFF;
446 ds.do_ctl = OFF;
447 bk_msg_showing = OFF;
448 fg_msg_showing = OFF;
449 }
450 else
451 curc++;
452 break;
453
454 case NL:
455 if (strlen (msg_line) > 0) {
456
457 putscr (msg_line, strlen (msg_line));
458 setmem (msg_line, sizeof (msg_line), NUL);
459 }
460
461 scroll ();
462 curl = screen.curlin;
463
464 if (local_action == 'b')
465 return;
466
467 curc = 0;
468 ds.pstrl = 0;
469 setmem (ds.pstr, sizeof (ds.pstr), NUL);
470 ipstr = i + 1;
471 break;
472
473 case ';':
474 catstr (msg_line, &msg [i], 1, "msg_line-6",
475 sizeof (msg_line));
476
477 if (ds.do_ctl)
478 ds.do_col = ON;
479 else
480 curc++;
481 break;
482
483 case '[':
484 catstr (msg_line, &msg [i], 1, "msg_line-7",
485 sizeof (msg_line));
486
487 if (ds.do_ctl)
488 ;
489 else
490 curc++;
491 break;
492
493 default:
494
495 NOTE
496
497 if (ds.do_ctl) {
498 catstr (msg_line, &msg [i], 1,
499 "msg_line-8", sizeof (msg_line));
500
501 if (isdigit (msg [i])) {
502 if (ds.do_col)
503 newc = 10 * newc + (int) msg [i] -
504 060;
505 else
506 newl = 10 * newl + (int) msg [i] -
507 060;
508 }
509 else {
510 ds.do_col = OFF;
511 ds.do_ctl = OFF;
512 }
513 }
514 else if (isprint (msg [i])) {
515 catstr (msg_line, &msg [i], 1,
516 "msg_line-9", sizeof (msg_line));
517 curc++;
518 }
519 break;
520 }
521
522
523
524 if (screen.maxcol > 0 && curc == screen.maxcol) {
525
526
527 if (mowse_active) {
528 if (~sync) {
529
530 putscr (msg_line,
531 strlen (msg_line));
532 setmem (msg_line, sizeof (msg_line),
533 NUL);
534
535 scroll ();
536 curl = screen.curlin;
537
538 if (local_action == 'b')
539 return;
540
541 setmem (msg_line, sizeof (msg_line),
542 NUL);
543 catstr (msg_line,
544 "\\c", 2, "wrap flag",
545 sizeof (msg_line));
546 curc = 2;
547 ipstr = i;
548 }
549 }
550
551
552
553
554
555 else {
556 catstr (msg_line, bs_str,
557 1, "msg_line", sizeof (msg_line));
558 curc--;
559 }
560 }
561 }
562
563
564
565 if (strlen (msg_line) > 0) {
566 putscr (msg_line, strlen (msg_line));
567 setmem (msg_line, sizeof (msg_line), NUL);
568 }
569
570
571
572
573 if (curc > 0 && ~pstr_sw) {
574 i -= ipstr;
575
576 if (ds.pstrl + i < MAX_SCREEN_COL) {
577 catstr (ds.pstr, &msg [ipstr], i, "ds.pstr",
578 sizeof (ds.pstr));
579 ds.pstrl += i;
580 kb.pos [0] = curc;
581 }
582
583 }
584
585 screen.curlin = curl;
586 screen.curcol = curc;
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 local_esc (scan_code)
612 int scan_code;
613 {
614 register int i;
615
616
617
618 local_action = tolower (kb.chr [0]);
619
620 switch (scan_code) {
621
622 case Q_KEY_CODE:
623
624 if (read_active) {
625 term_read = ON;
626 send_msg (nul_str, 0);
627 }
628
629 local_action = QUIT;
630 break;
631
632 case S_KEY_CODE:
633 wst_freeze = !wst_freeze;
634 update_status();
635 if (wst_freeze) {
636 wait_for_key();
637 wst_freeze = FALSE;
638 update_status();
639 }
640 break;
641
642
643 case E_KEY_CODE:
644 if (mowse_active)
645 status_err_msg("Cannot toggle edit in packet mode. <any key>-resume");
646
647 else if (wst_edit_mode) {
648 if (edlin.length > 0)
649 status_err_msg("Line not sent, enter or kill line first. <any key>-resume");
650
651 else {
652 wst_edit_mode = FALSE;
653
654 glass_edit_mode = FALSE;
655 kb.echo = FALSE;
656 }
657 }
658 else if (mowse_active && kb.cndx > 0)
659 status_err_msg("Line not sent, enter or kill line first. <any key>-resume");
660
661 else {
662 wst_edit_mode = ON;
663
664 glass_edit_mode = TRUE;
665 kb.echo = TRUE;
666 }
667 update_status();
668 break;
669
670
671 case O_KEY_CODE:
672 wst_paging = !wst_paging;
673 update_status();
674 break;
675
676 case F_KEY_CODE:
677 wst_f_audit = !wst_f_audit;
678 if (wst_f_audit) {
679 if (begin_file_audit() < 0)
680 wst_f_audit = OFF;
681 }
682 else
683 end_file_audit();
684 update_status();
685 break;
686
687 case P_KEY_CODE:
688 wst_p_audit = !wst_p_audit;
689 if (wst_p_audit) {
690 if (begin_printer_audit() < 0)
691 wst_p_audit = OFF;
692 }
693 else
694 end_printer_audit();
695 update_status();
696 break;
697
698 case M_KEY_CODE:
699
700 display_bkmsg ();
701 break;
702
703 case B_KEY_CODE:
704
705
706
707 kb.cndx = 0;
708 kb.endx = 0;
709 kb.klin [0] = NUL;
710
711 if (wst_edit_mode && !sync) {
712 cursor_eol(&edlin);
713 screen.curlin = edlin.cur_row;
714 screen.curcol = edlin.cur_col;
715 }
716
717 edlin.index = 0;
718 edlin.length = 0;
719
720 flush_dos_keys();
721
722 if (mowse_active) {
723 put_to_screen(CR);
724 put_to_screen(LF);
725 screen.curlin = wst_fg_screen.cursor_row;
726 screen.curcol = wst_fg_screen.cursor_col;
727 ds.ccol = 0;
728 ds.lct = 0;
729 ds.lndx = 0;
730 setmem(ds.dlin,sizeof(ds.dlin),NUL);
731 ds.pstrl = 0;
732 ds.pstr[0] = 0;
733 ds.splct[0] = 0;
734 screen.EOP_ct = 0;
735 }
736
737 puttdata (FG_BREAK, NUL, 0);
738 break_sent = mowse_active;
739 break;
740
741 case C_KEY_CODE:
742
743 clear_screen ();
744 cursor_move (CURSOR_HOME_ROW, 60);
745 putscr("WSTERM Vers ",12);
746 putscr(version,strlen(version));
747 cursor_move (CURSOR_HOME_ROW,CURSOR_HOME_COL);
748
749 if (ds.pstrl > 0)
750 emit_msg (ds.pstr, ds.pstrl, PSTR);
751 else if (wst_edit_mode) {
752 edlin.orig_row = edlin.cur_row = edlin.max_row = CURSOR_HOME_ROW;
753 edlin.orig_col = edlin.cur_col = edlin.cur_row = CURSOR_HOME_COL;
754 redraw_edit_line(&edlin);
755 }
756
757 break;
758
759 case zero_KEY_CODE:
760 case 129:
761
762 if (mowse_active)
763 send_msg (nul_str, 1);
764 else
765 puttdata (FG_TERMINAL_DATA, nul_str, 1);
766 break;
767
768 case D_KEY_CODE:
769
770 if (~fg_msg_showing) {
771 status_err_msg("No foreground messages. <any key>-resume");
772 update_status();
773 }
774 else {
775 if (wst_edit_mode || (mowse_active && ~sync)) {
776
777 erase_edit_line(&edlin);
778 emit_msg(fg_msg.text,fg_msg_len,~PSTR);
779 fg_msg_len = 0;
780 signal_fg(OFF);
781 fg_msg_showing = OFF;
782 cursor_pos(&edlin.cur_row,&edlin.cur_col);
783 edlin.orig_row = edlin.cur_row;
784 edlin.orig_col = edlin.cur_col;
785 redraw_edit_line(&edlin);
786 }
787 }
788 break;
789
790 case H_KEY_CODE:
791 help(GENERAL_HELP);
792 update_status();
793 break;
794
795 case V_KEY_CODE:
796 if (wst_edit_mode) {
797 history_screen(&wst_fg_screen);
798 update_status();
799 }
800 else {
801 status_err_msg("History functions available only in edit mode. <any key>-resume");
802 update_status();
803 }
804 break;
805
806 default:
807 status_err_msg("Unrecognized WSTERM request, enter ALT-H for help. <any key>-resume");
808 update_status();
809 break;
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 putscr(str,strl)
840 char *str;
841 int strl;
842 {
843 int ch;
844 int i;
845
846
847 for (i = 0; i < strl; i++) {
848
849 if (checkkey() == ALT_S) {
850 wait_for_key();
851 wst_freeze = !wst_freeze;
852 update_status();
853 }
854
855 if (wst_freeze) {
856 wait_for_key();
857 wst_freeze = FALSE;
858 update_status();
859 }
860
861 ch = *str++;
862
863
864
865
866
867
868
869 if (clr_index == 0) {
870
871 if (ch == ESC)
872
873 clr_index++;
874
875 else
876 put_to_screen(ch);
877 }
878
879
880 else if (clr_index == 1) {
881
882
883 if (ch == '[')
884 clr_index++;
885
886
887 else if (is_esc[ch]) {
888 clr_index = 0;
889 put_to_screen(ESC);
890 put_to_screen(ch);
891
892
893 if (ch == 'c')
894 wst_reset();
895 }
896
897 else {
898 clr_index = 0;
899 put_to_screen(ch);
900 }
901 }
902
903
904 else if (clr_index == 2) {
905
906
907 if (ch == 'J') {
908 clear_eow();
909 clr_index = 0;
910 }
911
912
913 else if (ch == '2')
914 clr_index++;
915
916
917 else {
918 put_to_screen(ESC);
919 put_to_screen('[');
920 put_to_screen(ch);
921 clr_index = 0;
922 }
923 }
924
925
926 else if (clr_index == 3) {
927 if (ch == 'J') {
928 clear_window();
929 clr_index = 0;
930 }
931
932
933 else {
934 put_to_screen(ESC);
935 put_to_screen('[');
936 put_to_screen('2');
937 put_to_screen(ch);
938 clr_index = 0;
939 }
940 }
941
942
943 else {
944 clr_index = 0;
945 put_to_screen(ch);
946 }
947 }
948 }
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969 clear_eow()
970 {
971 union REGS reg, outreg;
972 int row, col;
973
974 cursor_pos(&row,&col);
975 if (row < 24) {
976
977 put_screen_str(EL);
978
979 if (row+1 < SCREEN_LINES) {
980
981 reg.h.ah = VIDEO_SCROLL_UP_FUNC;
982 reg.h.al = 0;
983 reg.h.ch = row+1;
984 reg.h.cl = 0;
985 reg.h.dh = SCREEN_LINES-1;
986 reg.h.dl = SCREEN_COLS-1;
987 reg.h.bh = wst_fg_screen.attr;
988 int86(BIOS_VIDEO,®,&outreg);
989
990 }
991 }
992 cursor_move(row,col);
993 }
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013 clear_window()
1014 {
1015 union REGS reg, outreg;
1016
1017 reg.h.ah = VIDEO_SCROLL_UP_FUNC;
1018 reg.h.al = 0;
1019 reg.x.cx = 0;
1020 reg.h.dh = SCREEN_LINES-1;
1021 reg.h.dl = SCREEN_COLS-1;
1022 reg.h.bh = wst_fg_screen.attr;
1023
1024 int86(BIOS_VIDEO,®,&outreg);
1025 cursor_move(CURSOR_HOME_ROW,CURSOR_HOME_COL);
1026 screen.curcol = CURSOR_HOME_COL;
1027 screen.curlin = CURSOR_HOME_ROW;
1028 }
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047 scroll ()
1048
1049 {
1050 union regs_struct regs, outregs;
1051
1052
1053
1054
1055
1056
1057
1058 if (screen.curlin >= MAX_SCREEN_LINE) {
1059 wst_scroll();
1060
1061 regs.hreg.ah = SET_CURSOR_POS;
1062 regs.hreg.bh = get_active_page();
1063 regs.xreg.dx = LINE24_COL0;
1064 int86 (BIOS_VIDEO, ®s, &outregs);
1065
1066 }
1067
1068
1069 else {
1070 putscr (nl, 2);
1071 screen.curlin++;
1072 screen.curcol = 0;
1073
1074 }
1075
1076 if (mowse_active && wst_paging)
1077 screen.EOP_ct++;
1078 ds.pstrl = 0;
1079 setmem (ds.pstr, sizeof (ds.pstr), NUL);
1080
1081
1082
1083 if (mowse_active) {
1084 if (screen.EOP_ct == screen.maxlin && screen.maxlin > 0) {
1085 putscr ("EOP", 3);
1086
1087
1088 screen.EOP_ct = 0;
1089 while (checkkey() < 0);
1090 if (checkkey() == ALT_B || checkkey() == BREAK_KEY)
1091 return;
1092 getkey(BLOCK);
1093 put_to_screen(CR);
1094 put_to_screen(LF);
1095 }
1096 }
1097 }
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116 flush_dos_keys()
1117 {
1118 union REGS r, outr;
1119
1120 r.h.ah = BIOS_KB_STATUS;
1121
1122
1123
1124 while (!(int86(BIOS_KB,&r,&outr) & Z_FLAG_MASK)) {
1125 r.h.ah = BIOS_KB_READ;
1126 int86(BIOS_KB,&r,&outr);
1127 r.h.ah = BIOS_KB_STATUS;
1128 }
1129 }
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150 status_err_msg(msg)
1151 char *msg;
1152 {
1153 int row, col;
1154
1155 cursor_pos(&row,&col);
1156 cursor_move(HIDE_CURSOR_ROW,HIDE_CURSOR_COL);
1157 status_line(msg);
1158 wait_for_key();
1159 cursor_move(row,col);
1160 }
1161
1162
1163