-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecurcvr.c
2186 lines (1880 loc) · 50.7 KB
/
ecurcvr.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
/* #define DEBUG_RAWLOG */
/* #define DEFENSIVE */
/* #define ANSI_DEBUG */
/* #define ANSI_DEBUG_AAS */
/* #define ANSI_DEBUG_TEXT */
/* #define ANSI_DEBUG_SEQ */
/* #define ANSI_DEBUG_NOBUF */
/* #define ANSI_DEBUG_LOGFILE "/dev/tty2f" */
/* #define CURSOR_DEBUG */
#ifndef LIMIT_BELL
#define LIMIT_BELL
#endif
#if defined(WHT) && defined(WHT_CONFUSED)
#define ANSI_DEBUG
#define ANSI_DEBUG_AAS /* show "aas:" accumulation */
#define ANSI_DEBUG_TEXT /** show text */
#define ANSI_DEBUG_SEQ
#define ANSI_DEBUG_NOBUF
#define ANSI_DEBUG_LOGFILE "./ansi.log"
#endif
/*+-------------------------------------------------------------------------
ecurcvr.c - rcvr process + ANSI filter + non-ANSI<->ANSI hoop jumping
wht@wht.net
Defined functions:
accumulate_ansi_sequence(rchar)
ansi_CNL()
ansi_CPL()
ansi_CUB()
ansi_CUD()
ansi_CUF()
ansi_CUP()
ansi_CUU()
ansi_DCH()
ansi_DL()
ansi_DSR()
ansi_ECH()
ansi_ED()
ansi_EL()
ansi_HPA()
ansi_ICH()
ansi_IL()
ansi_SD()
ansi_SGR()
ansi_SU()
ansi_VPA()
is_ansi_terminator(rchar)
lgetc_rcvr()
lgetc_rcvr_raw()
need_rcvr_restart()
process_ansi_sequence()
process_rcvd_char(rchar)
rcvd_ESC()
rcvr()
rcvr_ansi_filter(rchar)
rcvr_ansi_filter_control(on_off, display)
rcvr_conditional_restart(restart_flag, display_flag)
rcvr_log_open()
rcvrdisp(buf, buflen)
rcvrdisp_actual()
rcvrdisp_actual2()
rcvrdisp_p()
rcvrdisp_v()
redisplay_rcvr_screen()
saved_cursor_restore_cursor()
saved_cursor_save_cursor()
spaces(buf, buflen)
spaces_trap(code, buf, buflen)
start_rcvr_process(notify_flag)
xmtr_wfp_debug_hack()
Any perceptible delay will eventually get on your nerves. --Bob Hyers
--------------------------------------------------------------------------*/
/*+:EDITS:*/
/*:04-26-2000-11:15-wht@bob-RELEASE 4.42 */
/*:01-24-1997-02:37-wht@yuriatin-SOURCE RELEASE 4.00 */
/*:09-28-1996-23:52-wht@yuriatin-shmr_notify_xmtr_of_telnet_close */
/*:09-24-1996-15:24-wht@yuriatin-fix rcvrdisp/ff-stderr synch */
/*:09-11-1996-20:00-wht@yuriatin-3.48-major telnet,curses,structural overhaul */
/*:08-11-1996-02:10-wht@kepler-rename ecu_log_event to logevent */
/*:12-12-1995-14:22-wht@kepler-[no line attached] on such rcvr start */
/*:11-23-1995-11:20-wht@kepler-source control 3.37 for tsx-11 */
/*:11-14-1995-10:23-wht@kepler-3.37.80-source control point: SOCKETS */
/*:11-13-1995-12:26-wht@kepler-start_rcvr_process moved ecusighdl.c */
/*:11-13-1995-12:22-wht@kepler-need_rcvr_restart checks Liofd for open line */
/*:11-13-1995-12:21-wht@kepler-need_rcvr_restart was a macro in ecu.h */
/*:11-04-1995-21:02-wht@kepler-if telnet_cmd called, rtn 0 to lgetc caller */
/*:11-03-1995-16:54-wht@wwtp1-use CFG_TelnetOption */
/*:10-09-1995-15:41-wht@kepler-SU newlines were sent to stderr not rcvrdisp */
/*:10-09-1995-15:03-wht@kepler-label ease case in process_ansi_sequence */
/*:09-16-1995-15:06-root@kepler-rename specific ANSI_DEBUG partitions */
/*:01-12-1995-15:19-wht@n4hgf-apply Andrew Chernov 8-bit clean+FreeBSD patch */
/*:05-04-1994-04:39-wht@n4hgf-ECU release 3.30 */
/*:10-03-1993-20:09-wht@n4hgf-document read errors w/fd on screen */
/*:08-18-1993-05:49-wht@n4hgf-rcvr seems ready for release */
/*:08-07-1993-20:38-wht@n4hgf-add xmtr_wfp_debug_hack */
/*:07-23-1993-15:42-wht@n4hgf-detect/ignore ESC = or ESC > VT100 keypad */
/*:07-17-1993-12:36-wht@n4hgf-no more rcvrdisp_actual2_xmtr_buffer junk */
/*:12-31-1992-15:34-wht@n4hgf-handle VT100 save/restore cursor */
/*:12-03-1992-14:24-wht@n4hgf-differentiate between type 5 and other DSR */
/*:09-10-1992-13:58-wht@n4hgf-ECU release 3.20 */
/*:09-06-1992-13:29-wht@n4hgf-add receiver process buffered screen write */
/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
/*:05-29-1992-13:28-wht@n4hgf-no banner - phone numbers are security risk */
/*:11-11-1991-14:25-wht@n4hgf-lzero_length_read_detected code */
/*:11-11-1991-12:45-wht@n4hgf-add LIMIT_BELL code */
/*:08-26-1991-16:39-wht@n4hgf2-SD was still hopelessly manic */
/*:07-25-1991-12:56-wht@n4hgf-ECU release 3.10 */
/*:07-05-1991-06:13-wht@n4hgf-SD was in baaaaadd shape */
/*:01-09-1991-22:31-wht@n4hgf-ISC port */
/*:12-26-1990-14:32-wht@n4hgf-use memset in spaces() */
/*:12-21-1990-21:06-wht@n4hgf-CUF and CUB set non-ansi cursor incorrectly */
/*:12-20-1990-16:27-wht@n4hgf-had SU and SD swapped */
/*:11-30-1990-18:39-wht@n4hgf-non-ansi console rcvr appears to be working */
/*:11-28-1990-14:13-wht@n4hgf-start non-ansi console support */
/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
#include "ecu.h"
#include "ecukey.h"
#if defined(CFG_TelnetOption)
#include <arpa/telnet.h>
#endif /* defined(CFG_TelnetOption) */
#ifdef CFG_SemWithShm
#include <sys/ipc.h>
#include <sys/sem.h>
#endif /* CVRDISP_PV */
extern int errno;
extern char rcvr_log_file[]; /* if rcvr_log!= 0,log filename */
extern int rcvr_log; /* rcvr log active if != 0 */
extern FILE *rcvr_log_fp; /* rcvr log file */
extern int rcvr_log_raw; /* if true, log all, else filter ctl chrs */
extern int rcvr_log_append; /* if true, append, else scratch */
extern int rcvr_log_flusheach; /* if true, flush log on each char */
extern int rcvr_log_gen_title;
extern UINT tcap_LINES; /* terminal line quantity - see ecutcap.c */
extern UINT tcap_COLS; /* terminal column quantity - see ecutcap.c */
extern UINT LINESxCOLS;
static char esc = ESC;
#define MAX_ANSI_LEN 30 /* generous */
char ansibuf[MAX_ANSI_LEN];
char *ansi;
int ansilen = 0;
int in_ansi_accumulation = 0;
int saved_cursor_y;
int saved_cursor_x;
#define RCVR_RDQUAN 250
uchar lgetc_buf[RCVR_RDQUAN];
uchar *lgetc_ptr;
int lgetc_count;
uchar autorz_frame[] =
{SUB, 'B', '0', '0'};
#ifdef ANSI_DEBUG
FILE *wfp = (FILE *) 0;
#endif
/*
* the main purpose of this is to map ruling characters, but as a
* side effect, also map others to reasonable, near, amusing, or
* random printing characters as well
*/
uchar non_multiscreen_hi_map[128] =
{
/* 80 */ 'c', 'u', 'e', 'a', 'a', 'a', 'a', 'c',
/* 88 */ 'e', 'e', 'e', 'i', 'i', 'i', 'a', 'a',
/* 90 */ 'e', 'e', 'a', 'a', 'a', 'o', 'u', 'u',
/* 98 */ 'y', 'o', 'u', 'X', '#', 'Y', 'P', 'f',
/* A0 */ 'a', 'i', 'o', 'u', 'n', 'n', 'a', 'o',
/* A8 */ '?', '-', '-', '%', '%', '|', '<', '>',
/* B0 */ '#', '#', '#', '|', '+', '+', '+', '.',
/* B8 */ '.', '+', '|', '.', '\'', '\'', '\'', '.',
/* C0 */ '`', '+', '+', '+', '-', '+', '+', '+',
/* C8 */ '`', '.', '+', '+', '+', '=', '+', '+',
/* D0 */ '+', '+', '+', '`', '`', '.', '.', '+',
/* D8 */ '+', '\'', '.', '#', '_', '|', '|', '-',
/* E0 */ 'a', 'b', 'F', 'T', 'E', 'o', 'u', 't',
/* E8 */ 'I', '0', 'O', 'o', 'o', 'o', 'e', 'n',
/* F0 */ '=', '+', '>', '<', 'f', 'j', '%', '=',
/* F8 */ 'o', '.', '.', 'V', 'n', '2', '*', ' '
};
/*
* prototypes for ansi filter code gaggled at bottom
* of this module
*/
#if (__STDC__ == 1)
#define pp(s) s
#else
#define pp(s) ()
#endif
#if !defined(CFG_NoAnsiEmulation)
void redisplay_rcvr_screen pp((void));
void spaces_trap pp((int code, uchar * buf, UINT buflen));
void spaces pp((uchar * buf, UINT buflen));
void ansi_SGR pp((void));
void ansi_CUP pp((void));
void ansi_CUU pp((void));
void ansi_CUD pp((void));
void ansi_CUF pp((void));
void ansi_CUB pp((void));
void ansi_DSR pp((void));
void ansi_ED pp((void));
void ansi_EL pp((void));
void ansi_ECH pp((void));
void ansi_SU pp((void));
void ansi_SD pp((void));
void ansi_HPA pp((void));
void ansi_VPA pp((void));
void ansi_IL pp((void));
void ansi_ICH pp((void));
void ansi_DL pp((void));
void ansi_DCH pp((void));
void ansi_CPL pp((void));
void ansi_CNL pp((void));
void saved_cursor_save_cursor pp((void));
void saved_cursor_restore_cursor pp((void));
void rcvd_ESC pp((void));
int is_ansi_terminator pp((UINT rchar));
void accumulate_ansi_sequence pp((UINT rchar));
void process_ansi_sequence pp((void));
int rcvr_ansi_filter pp((int rchar));
#endif /* !defined(CFG_NoAnsiEmulation) */
void rcvrdisp pp((char *buf, int buflen));
void rcvrdisp_actual pp((void));
void rcvrdisp_actual2 pp((void));
void rcvrdisp_p pp((void));
void rcvrdisp_v pp((void));
void rcvr();
void rcvr_notify();
#undef pp
/*+-----------------------------------------------------------------------
start_rcvr_process(notify_flag) - start RCVR process if not extant
------------------------------------------------------------------------*/
void
start_rcvr_process(notify_flag)
int notify_flag;
{
extern UINT32 colors_current;
extern int xmtr_killed_rcvr;
CFG_PidType rcvr_pid;
fflush(so);
fflush(se);
if (shm->Liofd <= 0)
{
UINT32 colors_at_entry = colors_current;
setcolor(colors_notify);
ff(se, "[no line attached]");
setcolor(colors_at_entry);
ff(se, "\r\n");
return;
}
if (shm->rcvr_pid > 0) /* if process already active, just ... */
return;
if (rcvr_log && rcvr_log_file[0] && rcvr_log_fp)
{
fclose(rcvr_log_fp);
rcvr_log_fp = 0;
}
xmtr_killed_rcvr = 0;
rcvr_pid = smart_fork();
if (!rcvr_pid) /* if we are the (spawned) rcvr process */
{
if (notify_flag)
{
char *text = "[interactive mode]";
UINT32 colors_at_entry = colors_current;
setcolor(colors_notify);
rcvrdisp(text, strlen(text));
setcolor(colors_at_entry);
rcvrdisp("\r\n", 2);
rcvrdisp_actual();
}
#if defined(FORK_DEBUG)
vlogevent(getppid(), "RCVR-START pid %d", getpid());
#endif
rcvr(); /* run until killed */
/* NOTREACHED */
}
else if (rcvr_pid > 0) /* we are the father (xmtr) process */
{
shm->rcvr_pid = rcvr_pid;
#if defined(FORK_DEBUG)
sleep(2);
#endif
if (rcvr_log)
rcvr_log_append = 1; /* until next %log -s */
xmtr_signals();
return;
}
shm->rcvr_pid = -1; /* no receiver active */
pprintf("\n\nECU could not fork for receive process\n");
termecu(TERMECU_NO_FORK_FOR_RCVR);
/* NOTREACHED */
} /* end of _start_rcvr_process */
/*+-------------------------------------------------------------------------
rcvr_conditional_restart(restart_flag,display_flag)
This function is called by the XMTR to decide if the receiver
should be restarted (yes if line open, no if not)
--------------------------------------------------------------------------*/
void
rcvr_conditional_restart(restart_flag, display_flag)
int restart_flag;
int display_flag;
{
if (restart_flag)
{
if (shm->Liofd == -1)
{
if (display_flag)
{
UINT32 colors_at_entry = colors_current;
extern UINT32 colors_current;
setcolor(colors_notify);
ff(se, "[no line attached]");
setcolor(colors_at_entry);
ff(se, "\r\n");
}
return;
}
start_rcvr_process(display_flag);
}
} /* end of rcvr_conditional_restart */
/*+-------------------------------------------------------------------------
need_rcvr_restart() - will rcvr need restart?
We want to kill the receiver to get it out of the picture
for a while. If it is already dead, we do not want to
start it up when we are done.
If shm->rcvr_pid == -2, the receiver is not active, but queued restart
has been requested by some function.
We don't want to do it if a procedure is executing or if no line is open.
--------------------------------------------------------------------------*/
int
need_rcvr_restart()
{
return ((shm->rcvr_pid > 0) || ((shm->rcvr_pid == -2) &&
!proc_level)); /* && (shm->Liofd >= 0)); */
} /* end of need_rcvr_restart */
/*+-------------------------------------------------------------------------
rcvrdisp_p() - lock rcvrdisp mechanism
--------------------------------------------------------------------------*/
#ifdef CFG_SemWithShm
void
rcvrdisp_p()
{
int retn;
struct sembuf sembuf;
sembuf.sem_num = 0;
sembuf.sem_op = -1;
sembuf.sem_flg = 0;
while (1)
{
if (((retn = semop(shm->rcvrdisp_semid, &sembuf, 1)) >= 0) ||
(errno != EINTR))
{
break;
}
}
if ((retn < 0) && (errno != EINVAL))
{
strcpy(lopen_err_str, "rcvrdisp_p failed: SysV IPC error");
termecu(TERMECU_IPC_ERROR);
}
} /* end of rcvrdisp_p */
#endif /* CFG_SemWithShm */
/*+-------------------------------------------------------------------------
rcvrdisp_v() - unlock rcvrdisp mechanism
--------------------------------------------------------------------------*/
#ifdef CFG_SemWithShm
void
rcvrdisp_v()
{
int retn;
struct sembuf sembuf;
sembuf.sem_num = 0;
sembuf.sem_op = 1;
sembuf.sem_flg = 0;
while (1)
{
if (((retn = semop(shm->rcvrdisp_semid, &sembuf, 1)) >= 0) ||
(errno != EINTR))
{
break;
}
}
if ((retn < 0) && (errno != EINVAL))
{
strcpy(lopen_err_str, "rcvrdisp_v failed: SysV IPC error");
termecu(TERMECU_IPC_ERROR);
}
} /* end of rcvrdisp_v */
#endif /* CFG_SemWithShm */
/*+-------------------------------------------------------------------------
rcvrdisp_actual() - actual write to screen
--------------------------------------------------------------------------*/
void
rcvrdisp_actual()
{
#ifdef CFG_SemWithShm
rcvrdisp_p();
#endif /* CFG_SemWithShm */
if (shm->rcvrdisp_count)
write(TTYOUT, shm->rcvrdisp_buffer, shm->rcvrdisp_count);
shm->rcvrdisp_ptr = shm->rcvrdisp_buffer;
shm->rcvrdisp_count = 0;
#ifdef CFG_SemWithShm
rcvrdisp_v();
#endif /* CFG_SemWithShm */
} /* end of rcvrdisp_actual */
/*+-------------------------------------------------------------------------
rcvrdisp_actual2() - for tcap, flush only if not receiver
--------------------------------------------------------------------------*/
void
rcvrdisp_actual2()
{
if (getpid() == shm->rcvr_pid)
return;
#ifdef CFG_SemWithShm
rcvrdisp_p();
#endif /* CFG_SemWithShm */
if (shm->rcvrdisp_count)
write(TTYOUT, shm->rcvrdisp_buffer, shm->rcvrdisp_count);
shm->rcvrdisp_ptr = shm->rcvrdisp_buffer;
shm->rcvrdisp_count = 0;
#ifdef CFG_SemWithShm
rcvrdisp_v();
#endif /* CFG_SemWithShm */
} /* end of rcvrdisp_actual2 */
/*+-------------------------------------------------------------------------
rcvrdisp(buf,buflen) - logical write to screen
--------------------------------------------------------------------------*/
void
rcvrdisp(buf, buflen)
char *buf;
int buflen;
{
if ((unsigned)(buflen + shm->rcvrdisp_count) >
(unsigned)sizeof(shm->rcvrdisp_buffer))
{
rcvrdisp_actual();
}
if (((unsigned)buflen + shm->rcvrdisp_count) >
(unsigned)sizeof(shm->rcvrdisp_buffer))
{
write(TTYOUT, buf, buflen);
return;
}
#ifdef CFG_SemWithShm
rcvrdisp_p();
#endif /* CFG_SemWithShm */
memcpy(shm->rcvrdisp_ptr, buf, buflen);
shm->rcvrdisp_ptr += buflen;
shm->rcvrdisp_count += buflen;
#ifdef CFG_SemWithShm
rcvrdisp_v();
#endif /* CFG_SemWithShm */
} /* end of rcvrdisp */
/*+-------------------------------------------------------------------------
lgetc_rcvr_raw() - rcvr_raw version of get char from line
--------------------------------------------------------------------------*/
UINT
lgetc_rcvr_raw()
{
extern int errno;
#ifdef DEBUG_RAWLOG
static int fd_rawlog;
if (!fd_rawlog)
{
char *fnm = "/tmp/ecurcvr_raw.log";
#if 1
fd_rawlog = open(fnm, O_WRONLY | O_APPEND | O_CREAT, 0666);
#else
creat(fnm, 0666);
fd_rawlog = open(fnm, O_WRONLY | O_APPEND, 0);
#endif
}
#endif
if (!lgetc_count)
{
rcvrdisp_actual();
while (lgetc_count <= 0)
{
errno = 0;
if ((lgetc_count =
read(shm->Liofd, lgetc_buf, RCVR_RDQUAN)) < 0)
{
if (errno == EINTR) /* if signal interrupted, ... */
continue;/* ... read again */
termecu(TERMECU_LINE_READ_ERROR);
}
if (!lgetc_count)
{
if (shm->Ltelnet) /* remote reject or disconnect */
shmr_notify_xmtr_of_telnet_close(); /* never return */
lzero_length_read_detected(); /* maybe terminate program
* ... */
continue; /* ... but if not, read again */
}
#ifdef DEBUG_RAWLOG
if (fd_rawlog)
write(fd_rawlog, lgetc_buf, lgetc_count);
#endif
}
shm->rcvd_chars += lgetc_count;
shm->rcvd_chars_this_connect += lgetc_count;
lgetc_ptr = lgetc_buf;
}
lgetc_count--;
return (*lgetc_ptr++);
} /* end of lgetc_rcvr_raw */
/*+-------------------------------------------------------------------------
lgetc_rcvr() - rcvr version of get char from line
--------------------------------------------------------------------------*/
UINT
lgetc_rcvr()
{
UINT char_rtnd = lgetc_rcvr_raw();
#if defined(CFG_TelnetOption)
if ((shm->Ltelnet) && !shm->Ltelnet_raw && (char_rtnd == IAC))
{
telnet_cmd(1);
char_rtnd = 0;
}
#endif /* defined(CFG_TelnetOption) */
if (shm->Lparity)
return (char_rtnd & 0x7F);
else
return (char_rtnd);
} /* end of lgetc_rcvr */
/*+-------------------------------------------------------------------------
rcvr_log_open()
--------------------------------------------------------------------------*/
void
rcvr_log_open()
{
if (rcvr_log) /* if xmtr set us up for logging */
{
rcvr_log_fp = fopen(rcvr_log_file, rcvr_log_append ? "a" : "w");
rcvr_log_append = 1; /* until next %log -s */
if (!rcvr_log_fp)
{
ff(se, "ecu RCVR: Could not open log file: %s\r\n", rcvr_log_file);
ff(se, "recording aborted.\r\n");
rcvr_log = 0;
}
rcvr_log_gen_title = 0;
}
} /* end of rcvr_log_open */
/*+-------------------------------------------------------------------------
process_rcvd_char(rchar) - process a received character
return 0 if char should be written to console, 1 otherwise
--------------------------------------------------------------------------*/
int
process_rcvd_char(rchar)
UINT rchar;
{
register int itmp;
#ifdef LIMIT_BELL
long now;
static long last_bell_time = -1L;
#endif
/*
* automatic ZMODEM frame detection (expensive CPU burners for lazy
* folks)
*/
if (shm->autorz)
{
if ((uchar) rchar == autorz_frame[shm->autorz_pos])
{
itmp = shm->autorz_pos; /* copy to register trying to be quick */
if (++itmp == sizeof(autorz_frame))
{
if (lgetc_count)
{
rcvrdisp(lgetc_ptr, lgetc_count);
lgetc_count = 0;
}
shmr_notify_zmodem_frame();
pause(); /* wait for death */
itmp = 0; /* in case something starts us up */
}
shm->autorz_pos = itmp;
return (!itmp); /* don't try to print ^X */
}
else
shm->autorz_pos = 0;
}
/*
* BEL and alarm-on-incoming-data processing
*/
if (shm->bell_notify_state == 2)
{
shm->bell_notify_state = 1;
bell_notify(XBELL_3T);
}
else if (rchar == BEL)
{
#ifdef LIMIT_BELL
time(&now);
if ((now - last_bell_time) < 2L)
return (1);
last_bell_time = now;
#endif
bell_notify(XBELL_ATTENTION);
return (0);
}
#ifdef TANDEM_ENQ_ACK /* for my friend John Dashner at Tandem */
else if (rchar == ENQ)
{
lputc(ACK);
return (0);
}
#endif
/*
* receiver logging
*/
if (rcvr_log && rcvr_log_fp)
{
/* if raw mode or character not excluded from "cooked" logging */
if (rcvr_log_raw || isprint(rchar) ||
(rchar == NL) || (rchar == TAB))
{
LOGPUTC(rchar, rcvr_log_fp);
}
/* back if log file if not raw and char is backspace */
else if (!rcvr_log_raw && (rchar == BS))
{
long logpos = 0;
if (logpos = ftell(rcvr_log_fp))
fseek(rcvr_log_fp, logpos - 1, 0);
}
if (rcvr_log_flusheach)
fflush(rcvr_log_fp);
}
#if !defined(CFG_NoAnsiEmulation)
if (shm->rcvr_ansi_filter)
return (rcvr_ansi_filter(rchar));
#endif
return (0);
} /* end of process_rcvd_char */
/*+-----------------------------------------------------------------------
rcvr() - copy characters from remote line to screen
------------------------------------------------------------------------*/
void
rcvr()
{
uchar rchar;
uchar nlchar = NL;
char *get_ttyname();
#if defined(ANSI_DEBUG)
char s80[80];
#endif /* ANSI_DEBUG */
#ifdef ANSI_DEBUG
wfp = fopen(ANSI_DEBUG_LOGFILE, "a");
if (ulindex(ANSI_DEBUG_LOGFILE, "/dev/tty") != -1)
{
sprintf(s80, "stty opost ocrnl < %s", ANSI_DEBUG_LOGFILE);
system(s80);
}
#ifdef ANSI_DEBUG_NOBUF
setbuf(wfp, NULL);
#endif /* ANSI_DEBUG_NOBUF */
fprintf(wfp, "******** %s tty_is_multiscreen=%d\n",
get_ttyname(), tty_is_multiscreen);
#endif /* ANSI_DEBUG */
/*
* remember receiver pid
*/
shm->rcvr_pid = getpid();
/*
* reset autorz detector
*/
shm->autorz_pos = 0;
/*
* reset line read function
*/
lgetc_count = 0;
lgetc_ptr = lgetc_buf;
in_ansi_accumulation = 0;
ansi = ansibuf;
*ansi = 0;
ansilen = 0;
shm->rcvrdisp_ptr = shm->rcvrdisp_buffer;
shm->rcvrdisp_count = 0;
/*
* yetch - magic number gretching for lines and columns
*/
if (!tcap_LINES || !tcap_COLS)
{
tcap_LINES = 25;
tcap_COLS = 80;
}
if (tcap_LINES > CFG_ScreenLinesMax)
tcap_LINES = CFG_ScreenLinesMax;
if (tcap_COLS > CFG_ScreenColsMax)
tcap_COLS = CFG_ScreenColsMax;
LINESxCOLS = tcap_LINES * tcap_COLS;
rcvr_signals();
rcvr_log_open();
saved_cursor_y = shm->cursor_y;
saved_cursor_x = shm->cursor_x;
/*
* finally! - the receive loop
*/
while (1)
{
rchar = lgetc_rcvr();
if (!tty_is_multiscreen && (rchar >= 0x80))
rchar = non_multiscreen_hi_map[rchar - 0x80];
if (process_rcvd_char(rchar))
continue;
rcvrdisp((char *)&rchar, 1);
if (shm->Ladd_nl_incoming && (rchar == CRET))
rcvrdisp((char *)&nlchar, 1);
}
/* NOTREACHED */
} /* end of rcvr */
/*+-------------------------------------------------------------------------
xmtr_wfp_debug_hack() - keep xmtr use of rcvr code from bombing
This function is called once by xmtr() before it does much else.
This is a horrible hack only necessary when the chips are down.
If ANSI_DEBUG has wfp open in rcvr, this opens it in the xmtr too.
The function has scope in the production binary only so ecu.c
has no need to know the ANSI debug status. This is the kind of
hack you never find out about in binary programs you buy :->.
--------------------------------------------------------------------------*/
void
xmtr_wfp_debug_hack()
{
#ifdef ANSI_DEBUG
wfp = fopen("/dev/null", "w");
#endif
} /* end of xmtr_wfp_debug_hack */
/*+-------------------------------------------------------------------------
rcvr_ansi_filter_control(on_off,display)
does nothing meaningful if no emulation configured
--------------------------------------------------------------------------*/
void
rcvr_ansi_filter_control(on_off, display)
int on_off;
int display;
{
#if defined(CFG_NoAnsiEmulation)
if (display)
pprintf("ignored ... ANSI filter not configured\n");
#else
if (on_off)
{
spaces((char *)shm->screen, LINESxCOLS);
shm->cursor_y = 0;
shm->cursor_x = 0;
shm->rcvr_ansi_filter = 1;
}
else
{
shm->rcvr_ansi_filter = 0;
}
if (display)
{
int pointless = 0;
if (tty_not_char_special)
pointless = 1;
if (pointless)
pprintf("although pointless, ");
pprintf("ANSI filter set to %s\n",
(shm->rcvr_ansi_filter) ? "ON" : "off");
}
#endif /* ndefined(CFG_NoAnsiEmulation) */
} /* end of rcvr_ansi_filter_control */
/***************************************************************************
* R E C E I V E R A N S I F I L T E R
*
* The code below is included only in versions which have an "ANSI filter"
* (which may or may not be enabled with shm->rcvr_ansi_filter)
***************************************************************************/
#if !defined(CFG_NoAnsiEmulation)
/*+-------------------------------------------------------------------------
redisplay_rcvr_screen() - redisplay logical receiver screen
As of writing, this function is called only by the XMTR process
--------------------------------------------------------------------------*/
void
redisplay_rcvr_screen()
{
UINT y;
extern int tty_not_char_special;
if (!shm->rcvr_ansi_filter || tty_not_char_special)
return;
setcolor(colors_current);
tcap_stand_end();
rcvrdisp_actual();
for (y = 0; y < tcap_LINES; y++)
{
tcap_cursor(y, 0);
fwrite(&shm->screen[y][0],
((y != tcap_LINES - 1) ? tcap_COLS : tcap_COLS - 1), 1, se);
}
tcap_eeol();
tcap_cursor(shm->cursor_y, shm->cursor_x);
rcvrdisp_actual();
} /* end of redisplay_rcvr_screen */
/*+-------------------------------------------------------------------------
spaces_trap(code,buf,buflen)
--------------------------------------------------------------------------*/
#ifdef CURSOR_DEBUG
void
spaces_trap(code, buf, buflen)
int code;
uchar *buf;
UINT buflen;
{
char *xyz = (char *)0x90000000;
ff(se, "rcvr 'spaces trap' code %d: cursor x,y=%d,%d\r\n",
code, shm->cursor_y, shm->cursor_x);
ff(se, "buf=%08lx len=%08lx offs=%08lx\r\n", buf, buflen,
(UINT32) buf - (UINT32) shm->screen);
*xyz = 0;
abort();
} /* end of spaces_trap */
#endif
/*+-------------------------------------------------------------------------
spaces(buf,buflen) - fill with spaces
--------------------------------------------------------------------------*/
void
spaces(buf, buflen)
uchar *buf;
UINT buflen;
{
#ifdef CURSOR_DEBUG
if ((UINT32) buf > (((UINT32) shm->screen) + LINESxCOLS))
spaces_trap(1, buf, buflen);
if ((UINT32) buf < (UINT32) shm->screen)
spaces_trap(2, buf, buflen);
if ((UINT32) (buf + buflen) > (((UINT32) shm->screen) + LINESxCOLS))
spaces_trap(3, buf, buflen);
if ((UINT32) (buf + buflen) < (UINT32) shm->screen)
spaces_trap(4, buf, buflen);
#endif
if (!buflen)
return;
#ifdef DEFENSIVE
if ((UINT32) buf < (UINT32) shm->screen)
{
ff(se,">< defensive 1\r\n");
return;
}
if ((UINT32) (buf + buflen) > (((UINT32) shm->screen) + LINESxCOLS))
{
ff(se,">< defensive 2\r\n");
return;
}
#endif
memset(buf, SPACE, buflen);
} /* end of spaces */
/*+-------------------------------------------------------------------------
ansi_SGR() - Set Graphics Rendition
The DOS ANSI world expects to be able to be able to chain 0,1 and
3x,4x params together with semicolons.
Supported modifiers for non-ansi terminals
0 normal
1 bold
4 underscore
5 blink
7 reverse video
--------------------------------------------------------------------------*/
void
ansi_SGR()
{
int itmp;
char *cp;
char SGRstr[MAX_ANSI_LEN];
char *token;
char *str_token();
#ifdef ANSI_DEBUG_SEQ
if (wfp)
ff(wfp, "SGR\n");