This repository has been archived by the owner on Jul 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.c
5238 lines (4787 loc) · 141 KB
/
main.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
/* $XTermId: main.c,v 1.716 2013/02/03 23:10:05 tom Exp $ */
/*
* Copyright 2002-2012,2013 by Thomas E. Dickey
*
* All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name(s) of the above copyright
* holders shall not be used in advertising or otherwise to promote the
* sale, use or other dealings in this Software without prior written
* authorization.
*
* Copyright 1987, 1988 The Open Group
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of The Open Group shall not be
* used in advertising or otherwise to promote the sale, use or other dealings
* in this Software without prior written authorization from The Open Group.
*
* Copyright 1987, 1988 by Digital Equipment Corporation, Maynard.
*
* All Rights Reserved
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of Digital not be used in
* advertising or publicity pertaining to distribution of the software
* without specific, written prior permission.
*
* DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
* DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
* ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
/*
* W A R N I N G
*
* If you think you know what all of this code is doing, you are
* probably very mistaken. There be serious and nasty dragons here.
*
* This client is *not* to be taken as an example of how to write X
* Toolkit applications. It is in need of a substantial rewrite,
* ideally to create a generic tty widget with several different parsing
* widgets so that you can plug 'em together any way you want. Don't
* hold your breath, though....
*/
/* main.c */
#define RES_OFFSET(field) XtOffsetOf(XTERM_RESOURCE, field)
#include <xterm.h>
#include <version.h>
#include <X11/cursorfont.h>
#include <X11/Xlocale.h>
#if OPT_TOOLBAR
#if defined(HAVE_LIB_XAW)
#include <X11/Xaw/Form.h>
#elif defined(HAVE_LIB_XAW3D)
#include <X11/Xaw3d/Form.h>
#elif defined(HAVE_LIB_NEXTAW)
#include <X11/neXtaw/Form.h>
#elif defined(HAVE_LIB_XAWPLUS)
#include <X11/XawPlus/Form.h>
#endif
#endif /* OPT_TOOLBAR */
#include <pwd.h>
#include <ctype.h>
#include <data.h>
#include <error.h>
#include <menu.h>
#include <main.h>
#include <xstrings.h>
#include <xtermcap.h>
#include <xterm_io.h>
#if OPT_WIDE_CHARS
#include <charclass.h>
#endif
#ifdef __osf__
#define USE_SYSV_SIGNALS
#define WTMP
#include <pty.h> /* openpty() */
#endif
#ifdef __sgi
#include <grp.h> /* initgroups() */
#endif
static void Syntax(char *) GCC_NORETURN;
static void HsSysError(int) GCC_NORETURN;
#if defined(__SCO__) || defined(SVR4) || defined(_POSIX_SOURCE)
#define USE_POSIX_SIGNALS
#endif
#if defined(SYSV) && !defined(SVR4) && !defined(ISC22) && !defined(ISC30)
/* older SYSV systems cannot ignore SIGHUP.
Shell hangs, or you get extra shells, or something like that */
#define USE_SYSV_SIGHUP
#endif
#if defined(sony) && defined(bsd43) && !defined(KANJI)
#define KANJI
#endif
#ifdef linux
#define USE_SYSV_PGRP
#define USE_SYSV_SIGNALS
#define WTMP
#ifdef __GLIBC__
#if (__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 1))
#include <pty.h>
#endif
#endif
#endif
#ifdef __MVS__
#define USE_SYSV_PGRP
#define USE_SYSV_SIGNALS
#endif
#ifdef __CYGWIN__
#define WTMP
#endif
#ifdef __SCO__
#ifndef _SVID3
#define _SVID3
#endif
#endif
#if defined(__GLIBC__) && !defined(linux)
#define USE_SYSV_PGRP
#define WTMP
#define HAS_BSD_GROUPS
#endif
#if defined(USE_TTY_GROUP) || defined(USE_UTMP_SETGID)
#include <grp.h>
#endif
#ifndef TTY_GROUP_NAME
#define TTY_GROUP_NAME "tty"
#endif
#include <sys/stat.h>
#ifdef Lynx
#ifndef BSDLY
#define BSDLY 0
#endif
#ifndef VTDLY
#define VTDLY 0
#endif
#ifndef FFDLY
#define FFDLY 0
#endif
#endif
#ifdef SYSV /* { */
#ifdef USE_USG_PTYS /* AT&T SYSV has no ptyio.h */
#include <sys/stropts.h> /* for I_PUSH */
#include <poll.h> /* for POLLIN */
#endif /* USE_USG_PTYS */
#define USE_SYSV_SIGNALS
#define USE_SYSV_PGRP
#if !defined(TIOCSWINSZ) || defined(__SCO__) || defined(__UNIXWARE__)
#define USE_SYSV_ENVVARS /* COLUMNS/LINES vs. TERMCAP */
#endif
/*
* now get system-specific includes
*/
#ifdef CRAY
#define HAS_BSD_GROUPS
#endif
#ifdef macII
#define HAS_BSD_GROUPS
#include <sys/ttychars.h>
#undef USE_SYSV_ENVVARS
#undef FIOCLEX
#undef FIONCLEX
#define setpgrp2 setpgrp
#include <sgtty.h>
#include <sys/resource.h>
#endif
#ifdef __hpux
#define HAS_BSD_GROUPS
#include <sys/ptyio.h>
#endif /* __hpux */
#ifdef __osf__
#define HAS_BSD_GROUPS
#undef USE_SYSV_PGRP
#define setpgrp setpgid
#endif
#ifdef __sgi
#define HAS_BSD_GROUPS
#include <sys/sysmacros.h>
#endif /* __sgi */
#ifdef sun
#include <sys/strredir.h>
#endif
#else /* } !SYSV { */ /* BSD systems */
#ifdef __QNX__
#ifndef __QNXNTO__
#define ttyslot() 1
#else
#define USE_SYSV_PGRP
extern __inline__
int
ttyslot(void)
{
return 1; /* yuk */
}
#endif
#else
#if defined(__INTERIX) || defined(__APPLE__)
#define setpgrp setpgid
#endif
#ifndef linux
#ifndef VMS
#ifndef USE_POSIX_TERMIOS
#ifndef USE_ANY_SYSV_TERMIO
#include <sgtty.h>
#endif
#endif /* USE_POSIX_TERMIOS */
#ifdef Lynx
#include <resource.h>
#else
#include <sys/resource.h>
#endif
#ifndef __INTERIX
#define HAS_BSD_GROUPS
#endif
#endif /* !VMS */
#endif /* !linux */
#endif /* __QNX__ */
#endif /* } !SYSV */
/* Xpoll.h and <sys/param.h> on glibc 2.1 systems have colliding NBBY's */
#if defined(__GLIBC__) && ((__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 1)))
#ifndef NOFILE
#define NOFILE OPEN_MAX
#endif
#elif !(defined(VMS) || defined(WIN32) || defined(Lynx) || defined(__GNU__) || defined(__MVS__))
#include <sys/param.h> /* for NOFILE */
#endif
#if defined(BSD) && (BSD >= 199103)
#define WTMP
#endif
#include <stdio.h>
#ifdef __hpux
#include <sys/utsname.h>
#endif /* __hpux */
#if defined(apollo) && (OSMAJORVERSION == 10) && (OSMINORVERSION < 4)
#define ttyslot() 1
#endif /* apollo */
#if defined(UTMPX_FOR_UTMP)
#define UTMP_STR utmpx
#else
#define UTMP_STR utmp
#endif
#if defined(USE_UTEMPTER)
#include <utempter.h>
#endif
#if defined(UTMPX_FOR_UTMP)
#include <utmpx.h>
#define call_endutent endutxent
#define call_getutid getutxid
#define call_pututline pututxline
#define call_setutent setutxent
#define call_updwtmp updwtmpx
#elif defined(HAVE_UTMP)
#include <utmp.h>
#if defined(_CRAY) && (OSMAJORVERSION < 8)
extern struct utmp *getutid __((struct utmp * _Id));
#endif
#define call_endutent endutent
#define call_getutid getutid
#define call_pututline pututline
#define call_setutent setutent
#define call_updwtmp updwtmp
#endif
#if defined(USE_LASTLOG) && defined(HAVE_LASTLOG_H)
#include <lastlog.h> /* caution: glibc includes utmp.h here */
#endif
#ifndef USE_LASTLOGX
#if defined(_NETBSD_SOURCE) && defined(_PATH_LASTLOGX)
#define USE_LASTLOGX 1
#endif
#endif
#ifdef PUCC_PTYD
#include <local/openpty.h>
#endif /* PUCC_PTYD */
#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
#include <util.h> /* openpty() */
#endif
#if defined(__FreeBSD__) || defined(__DragonFly__)
#include <libutil.h> /* openpty() */
#endif
#if !defined(UTMP_FILENAME)
#if defined(UTMP_FILE)
#define UTMP_FILENAME UTMP_FILE
#elif defined(_PATH_UTMP)
#define UTMP_FILENAME _PATH_UTMP
#else
#define UTMP_FILENAME "/etc/utmp"
#endif
#endif
#ifndef LASTLOG_FILENAME
#ifdef _PATH_LASTLOG
#define LASTLOG_FILENAME _PATH_LASTLOG
#else
#define LASTLOG_FILENAME "/usr/adm/lastlog" /* only on BSD systems */
#endif
#endif
#if !defined(WTMP_FILENAME)
#if defined(WTMP_FILE)
#define WTMP_FILENAME WTMP_FILE
#elif defined(_PATH_WTMP)
#define WTMP_FILENAME _PATH_WTMP
#elif defined(SYSV)
#define WTMP_FILENAME "/etc/wtmp"
#else
#define WTMP_FILENAME "/usr/adm/wtmp"
#endif
#endif
#include <signal.h>
#if defined(__SCO__) || (defined(ISC) && !defined(_POSIX_SOURCE))
#undef SIGTSTP /* defined, but not the BSD way */
#endif
#ifdef SIGTSTP
#include <sys/wait.h>
#endif
#if defined(__SCO__) || defined(__UNIXWARE__)
#undef ECHOKE
#undef ECHOCTL
#endif
#if defined(HAVE_SYS_TTYDEFAULTS_H) && !defined(CEOF)
#include <sys/ttydefaults.h>
#endif
#ifdef X_NOT_POSIX
extern long lseek();
#if defined(USG) || defined(SVR4)
extern unsigned sleep();
#else
extern void sleep();
#endif
extern char *ttyname();
#endif
#if defined(SYSV) && defined(DECL_PTSNAME)
extern char *ptsname(int);
#endif
#ifndef VMS
static void reapchild(int /* n */ );
static int spawnXTerm(XtermWidget /* xw */ );
static void remove_termcap_entry(char *, const char *);
#ifdef USE_PTY_SEARCH
static int pty_search(int * /* pty */ );
#endif
#endif /* ! VMS */
static int get_pty(int *pty, char *from);
static void resize_termcap(XtermWidget xw);
static void set_owner(char *device, uid_t uid, gid_t gid, mode_t mode);
static Bool added_utmp_entry = False;
#ifdef HAVE_POSIX_SAVED_IDS
static uid_t save_euid;
static gid_t save_egid;
#endif
static uid_t save_ruid;
static gid_t save_rgid;
#if defined(USE_UTMP_SETGID)
static int really_get_pty(int *pty, char *from);
#endif
#if defined(USE_SYSV_UTMP) && !defined(USE_UTEMPTER)
static Bool xterm_exiting = False;
#endif
static char *explicit_shname = NULL;
/*
** Ordinarily it should be okay to omit the assignment in the following
** statement. Apparently the c89 compiler on AIX 4.1.3 has a bug, or does
** it? Without the assignment though the compiler will init command_to_exec
** to 0xffffffff instead of NULL; and subsequent usage, e.g. in spawnXTerm() to
** SEGV.
*/
static char **command_to_exec = NULL;
#if OPT_LUIT_PROG
static char **command_to_exec_with_luit = NULL;
static unsigned command_length_with_luit = 0;
#endif
#define TERMCAP_ERASE "kb"
#define VAL_INITIAL_ERASE A2E(8)
/* choose a nice default value for speed - if we make it too low, users who
* mistakenly use $TERM set to vt100 will get padding delays. Setting it to a
* higher value is not useful since legacy applications (termcap) that care
* about padding generally store the code in a short, which does not have
* enough bits for the extended values.
*/
#ifdef B38400 /* everyone should define this */
#define VAL_LINE_SPEED B38400
#else /* ...but xterm's used this for a long time */
#define VAL_LINE_SPEED B9600
#endif
/*
* Allow use of system default characters if defined and reasonable.
* These are based on the BSD ttydefaults.h
*/
#ifndef CBRK
#define CBRK 0xff /* was 0 */
#endif
#ifndef CDISCARD
#define CDISCARD CONTROL('O')
#endif
#ifndef CDSUSP
#define CDSUSP CONTROL('Y')
#endif
#ifndef CEOF
#define CEOF CONTROL('D')
#endif
#ifndef CEOL
#define CEOL 0xff /* was 0 */
#endif
#ifndef CERASE
#define CERASE 0177
#endif
#ifndef CERASE2
#define CERASE2 CONTROL('H')
#endif
#ifndef CFLUSH
#define CFLUSH CONTROL('O')
#endif
#ifndef CINTR
#define CINTR CONTROL('C')
#endif
#ifndef CKILL
#define CKILL CONTROL('U') /* was '@' */
#endif
#ifndef CLNEXT
#define CLNEXT CONTROL('V')
#endif
#ifndef CNUL
#define CNUL 0
#endif
#ifndef CQUIT
#define CQUIT CONTROL('\\')
#endif
#ifndef CRPRNT
#define CRPRNT CONTROL('R')
#endif
#ifndef CREPRINT
#define CREPRINT CRPRNT
#endif
#ifndef CSTART
#define CSTART CONTROL('Q')
#endif
#ifndef CSTATUS
#define CSTATUS CONTROL('T')
#endif
#ifndef CSTOP
#define CSTOP CONTROL('S')
#endif
#ifndef CSUSP
#define CSUSP CONTROL('Z')
#endif
#ifndef CSWTCH
#define CSWTCH 0
#endif
#ifndef CWERASE
#define CWERASE CONTROL('W')
#endif
#ifdef USE_ANY_SYSV_TERMIO
#define TERMIO_STRUCT struct termio
#define ttySetAttr(fd, datap) ioctl(fd, TCSETA, datap)
#define ttyGetAttr(fd, datap) ioctl(fd, TCGETA, datap)
#define ttyFlush(fd) ioctl(fd, TCFLSH, 1)
#elif defined(USE_POSIX_TERMIOS)
#define TERMIO_STRUCT struct termios
#define ttySetAttr(fd, datap) tcsetattr(fd, TCSANOW, datap)
#define ttyGetAttr(fd, datap) tcgetattr(fd, datap)
#define ttyFlush(fd) tcflush(fd, TCOFLUSH)
#endif /* USE_ANY_SYSV_TERMIO */
#ifndef VMS
#ifdef TERMIO_STRUCT
/* The following structures are initialized in main() in order
** to eliminate any assumptions about the internal order of their
** contents.
*/
static TERMIO_STRUCT d_tio;
#ifdef HAS_LTCHARS
static struct ltchars d_ltc;
#endif /* HAS_LTCHARS */
#ifdef TIOCLSET
static unsigned int d_lmode;
#endif /* TIOCLSET */
#else /* !TERMIO_STRUCT */
static struct sgttyb d_sg =
{
0, 0, 0177, CKILL, (EVENP | ODDP | ECHO | XTABS | CRMOD)
};
static struct tchars d_tc =
{
CINTR, CQUIT, CSTART,
CSTOP, CEOF, CBRK
};
static struct ltchars d_ltc =
{
CSUSP, CDSUSP, CRPRNT,
CFLUSH, CWERASE, CLNEXT
};
static int d_disipline = NTTYDISC;
static long int d_lmode = LCRTBS | LCRTERA | LCRTKIL | LCTLECH;
#ifdef sony
static long int d_jmode = KM_SYSSJIS | KM_ASCII;
static struct jtchars d_jtc =
{
'J', 'B'
};
#endif /* sony */
#endif /* TERMIO_STRUCT */
#endif /* ! VMS */
/*
* SYSV has the termio.c_cc[V] and ltchars; BSD has tchars and ltchars;
* SVR4 has only termio.c_cc, but it includes everything from ltchars.
* POSIX termios has termios.c_cc, which is similar to SVR4.
*/
#define TTYMODE(name) { name, sizeof(name)-1, 0, 0 }
static Boolean override_tty_modes = False;
/* *INDENT-OFF* */
static struct _xttymodes {
const char *name;
size_t len;
int set;
int value;
} ttymodelist[] = {
TTYMODE("intr"), /* tchars.t_intrc ; VINTR */
#define XTTYMODE_intr 0
TTYMODE("quit"), /* tchars.t_quitc ; VQUIT */
#define XTTYMODE_quit 1
TTYMODE("erase"), /* sgttyb.sg_erase ; VERASE */
#define XTTYMODE_erase 2
TTYMODE("kill"), /* sgttyb.sg_kill ; VKILL */
#define XTTYMODE_kill 3
TTYMODE("eof"), /* tchars.t_eofc ; VEOF */
#define XTTYMODE_eof 4
TTYMODE("eol"), /* VEOL */
#define XTTYMODE_eol 5
TTYMODE("swtch"), /* VSWTCH */
#define XTTYMODE_swtch 6
TTYMODE("start"), /* tchars.t_startc ; VSTART */
#define XTTYMODE_start 7
TTYMODE("stop"), /* tchars.t_stopc ; VSTOP */
#define XTTYMODE_stop 8
TTYMODE("brk"), /* tchars.t_brkc */
#define XTTYMODE_brk 9
TTYMODE("susp"), /* ltchars.t_suspc ; VSUSP */
#define XTTYMODE_susp 10
TTYMODE("dsusp"), /* ltchars.t_dsuspc ; VDSUSP */
#define XTTYMODE_dsusp 11
TTYMODE("rprnt"), /* ltchars.t_rprntc ; VREPRINT */
#define XTTYMODE_rprnt 12
TTYMODE("flush"), /* ltchars.t_flushc ; VDISCARD */
#define XTTYMODE_flush 13
TTYMODE("weras"), /* ltchars.t_werasc ; VWERASE */
#define XTTYMODE_weras 14
TTYMODE("lnext"), /* ltchars.t_lnextc ; VLNEXT */
#define XTTYMODE_lnext 15
TTYMODE("status"), /* VSTATUS */
#define XTTYMODE_status 16
TTYMODE("erase2"), /* VERASE2 */
#define XTTYMODE_erase2 17
TTYMODE("eol2"), /* VEOL2 */
#define XTTYMODE_eol2 18
{ NULL, 0, 0, '\0' }, /* end of data */
};
#define validTtyChar(data, n) \
(known_ttyChars[n].sysMode >= 0 && \
known_ttyChars[n].sysMode < (int) XtNumber(data.c_cc))
static const struct {
int sysMode;
int myMode;
int myDefault;
} known_ttyChars[] = {
#ifdef VINTR
{ VINTR, XTTYMODE_intr, CINTR },
#endif
#ifdef VQUIT
{ VQUIT, XTTYMODE_quit, CQUIT },
#endif
#ifdef VERASE
{ VERASE, XTTYMODE_erase, CERASE },
#endif
#ifdef VKILL
{ VKILL, XTTYMODE_kill, CKILL },
#endif
#ifdef VEOF
{ VEOF, XTTYMODE_eof, CEOF },
#endif
#ifdef VEOL
{ VEOL, XTTYMODE_eol, CEOL },
#endif
#ifdef VSWTCH
{ VSWTCH, XTTYMODE_swtch, CNUL },
#endif
#ifdef VSTART
{ VSTART, XTTYMODE_start, CSTART },
#endif
#ifdef VSTOP
{ VSTOP, XTTYMODE_stop, CSTOP },
#endif
#ifdef VSUSP
{ VSUSP, XTTYMODE_susp, CSUSP },
#endif
#ifdef VDSUSP
{ VDSUSP, XTTYMODE_dsusp, CDSUSP },
#endif
#ifdef VREPRINT
{ VREPRINT, XTTYMODE_rprnt, CREPRINT },
#endif
#ifdef VDISCARD
{ VDISCARD, XTTYMODE_flush, CDISCARD },
#endif
#ifdef VWERASE
{ VWERASE, XTTYMODE_weras, CWERASE },
#endif
#ifdef VLNEXT
{ VLNEXT, XTTYMODE_lnext, CLNEXT },
#endif
#ifdef VSTATUS
{ VSTATUS, XTTYMODE_status, CSTATUS },
#endif
#ifdef VERASE2
{ VERASE2, XTTYMODE_erase2, CERASE2 },
#endif
#ifdef VEOL2
{ VEOL2, XTTYMODE_eol2, CNUL },
#endif
};
/* *INDENT-ON* */
#define TMODE(ind,var) if (ttymodelist[ind].set) var = (cc_t) ttymodelist[ind].value
static int parse_tty_modes(char *s, struct _xttymodes *modelist);
#ifndef USE_UTEMPTER
#ifdef USE_SYSV_UTMP
#if (defined(AIXV3) && (OSMAJORVERSION < 4)) && !(defined(getutid))
extern struct utmp *getutid();
#endif /* AIXV3 */
#else /* not USE_SYSV_UTMP */
static char etc_utmp[] = UTMP_FILENAME;
#endif /* USE_SYSV_UTMP */
#if defined(USE_LASTLOG) && defined(USE_STRUCT_LASTLOG)
static char etc_lastlog[] = LASTLOG_FILENAME;
#else
#undef USE_LASTLOG
#endif
#ifdef WTMP
static char etc_wtmp[] = WTMP_FILENAME;
#endif
#endif /* !USE_UTEMPTER */
/*
* Some people with 4.3bsd /bin/login seem to like to use login -p -f user
* to implement xterm -ls. They can turn on USE_LOGIN_DASH_P and turn off
* WTMP and USE_LASTLOG.
*/
#ifdef USE_LOGIN_DASH_P
#ifndef LOGIN_FILENAME
#define LOGIN_FILENAME "/bin/login"
#endif
static char bin_login[] = LOGIN_FILENAME;
#endif
static char passedPty[PTYCHARLEN + 1]; /* name if pty if slave */
#if defined(TIOCCONS) || defined(SRIOCSREDIR)
static int Console;
#include <X11/Xmu/SysUtil.h> /* XmuGetHostname */
#define MIT_CONSOLE_LEN 12
#define MIT_CONSOLE "MIT_CONSOLE_"
static char mit_console_name[255 + MIT_CONSOLE_LEN + 1] = MIT_CONSOLE;
static Atom mit_console;
#endif /* TIOCCONS */
#ifndef USE_SYSV_UTMP
static int tslot;
#endif /* USE_SYSV_UTMP */
static sigjmp_buf env;
#define SetUtmpHost(dst, screen) \
{ \
char host[sizeof(dst) + 1]; \
strncpy(host, DisplayString(screen->display), sizeof(host)); \
TRACE(("DisplayString(%s)\n", host)); \
if (!resource.utmpDisplayId) { \
char *endptr = strrchr(host, ':'); \
if (endptr) { \
TRACE(("trimming display-id '%s'\n", host)); \
*endptr = '\0'; \
} \
} \
strncpy(dst, host, sizeof(dst)); \
}
#ifdef HAVE_UTMP_UT_SYSLEN
# define SetUtmpSysLen(utmp) \
{ \
utmp.ut_host[sizeof(utmp.ut_host)-1] = '\0'; \
utmp.ut_syslen = strlen(utmp.ut_host) + 1; \
}
#endif
/* used by VT (charproc.c) */
static XtResource application_resources[] =
{
Sres("iconGeometry", "IconGeometry", icon_geometry, NULL),
Sres(XtNtitle, XtCTitle, title, NULL),
Sres(XtNiconHint, XtCIconHint, icon_hint, NULL),
Sres(XtNiconName, XtCIconName, icon_name, NULL),
Sres("termName", "TermName", term_name, NULL),
Sres("ttyModes", "TtyModes", tty_modes, NULL),
Bres("hold", "Hold", hold_screen, False),
Bres("utmpInhibit", "UtmpInhibit", utmpInhibit, False),
Bres("utmpDisplayId", "UtmpDisplayId", utmpDisplayId, True),
Bres("messages", "Messages", messages, True),
Ires("minBufSize", "MinBufSize", minBufSize, 4096),
Ires("maxBufSize", "MaxBufSize", maxBufSize, 32768),
Sres("menuLocale", "MenuLocale", menuLocale, DEF_MENU_LOCALE),
Sres("omitTranslation", "OmitTranslation", omitTranslation, NULL),
Sres("keyboardType", "KeyboardType", keyboardType, "unknown"),
#if OPT_PRINT_ON_EXIT
Ires("printModeImmediate", "PrintModeImmediate", printModeNow, 0),
Ires("printOptsImmediate", "PrintOptsImmediate", printOptsNow, 9),
Sres("printFileImmediate", "PrintFileImmediate", printFileNow, NULL),
Ires("printModeOnXError", "PrintModeOnXError", printModeOnXError, 0),
Ires("printOptsOnXError", "PrintOptsOnXError", printOptsOnXError, 9),
Sres("printFileOnXError", "PrintFileOnXError", printFileOnXError, NULL),
#endif
#if OPT_SUNPC_KBD
Bres("sunKeyboard", "SunKeyboard", sunKeyboard, False),
#endif
#if OPT_HP_FUNC_KEYS
Bres("hpFunctionKeys", "HpFunctionKeys", hpFunctionKeys, False),
#endif
#if OPT_SCO_FUNC_KEYS
Bres("scoFunctionKeys", "ScoFunctionKeys", scoFunctionKeys, False),
#endif
#if OPT_SUN_FUNC_KEYS
Bres("sunFunctionKeys", "SunFunctionKeys", sunFunctionKeys, False),
#endif
#if OPT_TCAP_FKEYS
Bres("tcapFunctionKeys", "TcapFunctionKeys", termcapKeys, False),
#endif
#if OPT_INITIAL_ERASE
Bres("ptyInitialErase", "PtyInitialErase", ptyInitialErase, DEF_INITIAL_ERASE),
Bres("backarrowKeyIsErase", "BackarrowKeyIsErase", backarrow_is_erase, DEF_BACKARO_ERASE),
#endif
Bres("useInsertMode", "UseInsertMode", useInsertMode, False),
#if OPT_ZICONBEEP
Ires("zIconBeep", "ZIconBeep", zIconBeep, 0),
Sres("zIconTitleFormat", "ZIconTitleFormat", zIconFormat, "*** %s"),
#endif
#if OPT_PTY_HANDSHAKE
Bres("waitForMap", "WaitForMap", wait_for_map, False),
Bres("ptyHandshake", "PtyHandshake", ptyHandshake, True),
Bres("ptySttySize", "PtySttySize", ptySttySize, DEF_PTY_STTY_SIZE),
#endif
#if OPT_SAME_NAME
Bres("sameName", "SameName", sameName, True),
#endif
#if OPT_SESSION_MGT
Bres("sessionMgt", "SessionMgt", sessionMgt, True),
#endif
#if OPT_TOOLBAR
Bres(XtNtoolBar, XtCToolBar, toolBar, True),
#endif
#if OPT_MAXIMIZE
Bres(XtNmaximized, XtCMaximized, maximized, False),
Sres(XtNfullscreen, XtCFullscreen, fullscreen_s, "off"),
#endif
};
static String fallback_resources[] =
{
#if OPT_TOOLBAR
"*toolBar: false",
#endif
"*SimpleMenu*menuLabel.vertSpace: 100",
"*SimpleMenu*HorizontalMargins: 16",
"*SimpleMenu*Sme.height: 16",
"*SimpleMenu*Cursor: left_ptr",
"*mainMenu.Label: Main Options (no app-defaults)",
"*vtMenu.Label: VT Options (no app-defaults)",
"*fontMenu.Label: VT Fonts (no app-defaults)",
#if OPT_TEK4014
"*tekMenu.Label: Tek Options (no app-defaults)",
#endif
NULL
};
/* Command line options table. Only resources are entered here...there is a
pass over the remaining options after XrmParseCommand is let loose. */
/* *INDENT-OFF* */
static XrmOptionDescRec optionDescList[] = {
{"-geometry", "*vt100.geometry",XrmoptionSepArg, (XPointer) NULL},
{"-132", "*c132", XrmoptionNoArg, (XPointer) "on"},
{"+132", "*c132", XrmoptionNoArg, (XPointer) "off"},
{"-ah", "*alwaysHighlight", XrmoptionNoArg, (XPointer) "on"},
{"+ah", "*alwaysHighlight", XrmoptionNoArg, (XPointer) "off"},
{"-aw", "*autoWrap", XrmoptionNoArg, (XPointer) "on"},
{"+aw", "*autoWrap", XrmoptionNoArg, (XPointer) "off"},
#ifndef NO_ACTIVE_ICON
{"-ai", "*activeIcon", XrmoptionNoArg, (XPointer) "off"},
{"+ai", "*activeIcon", XrmoptionNoArg, (XPointer) "on"},
#endif /* NO_ACTIVE_ICON */
{"-b", "*internalBorder",XrmoptionSepArg, (XPointer) NULL},
{"-bc", "*cursorBlink", XrmoptionNoArg, (XPointer) "on"},
{"+bc", "*cursorBlink", XrmoptionNoArg, (XPointer) "off"},
{"-bcf", "*cursorOffTime",XrmoptionSepArg, (XPointer) NULL},
{"-bcn", "*cursorOnTime",XrmoptionSepArg, (XPointer) NULL},
{"-bdc", "*colorBDMode", XrmoptionNoArg, (XPointer) "off"},
{"+bdc", "*colorBDMode", XrmoptionNoArg, (XPointer) "on"},
{"-cb", "*cutToBeginningOfLine", XrmoptionNoArg, (XPointer) "off"},
{"+cb", "*cutToBeginningOfLine", XrmoptionNoArg, (XPointer) "on"},
{"-cc", "*charClass", XrmoptionSepArg, (XPointer) NULL},
{"-cm", "*colorMode", XrmoptionNoArg, (XPointer) "off"},
{"+cm", "*colorMode", XrmoptionNoArg, (XPointer) "on"},
{"-cn", "*cutNewline", XrmoptionNoArg, (XPointer) "off"},
{"+cn", "*cutNewline", XrmoptionNoArg, (XPointer) "on"},
{"-cr", "*cursorColor", XrmoptionSepArg, (XPointer) NULL},
{"-cu", "*curses", XrmoptionNoArg, (XPointer) "on"},
{"+cu", "*curses", XrmoptionNoArg, (XPointer) "off"},
{"-dc", "*dynamicColors",XrmoptionNoArg, (XPointer) "off"},
{"+dc", "*dynamicColors",XrmoptionNoArg, (XPointer) "on"},
{"-fb", "*boldFont", XrmoptionSepArg, (XPointer) NULL},
{"-fbb", "*freeBoldBox", XrmoptionNoArg, (XPointer)"off"},
{"+fbb", "*freeBoldBox", XrmoptionNoArg, (XPointer)"on"},
{"-fbx", "*forceBoxChars", XrmoptionNoArg, (XPointer)"off"},
{"+fbx", "*forceBoxChars", XrmoptionNoArg, (XPointer)"on"},
#ifndef NO_ACTIVE_ICON
{"-fi", "*iconFont", XrmoptionSepArg, (XPointer) NULL},
#endif /* NO_ACTIVE_ICON */
#if OPT_RENDERFONT
{"-fa", "*faceName", XrmoptionSepArg, (XPointer) NULL},
{"-fd", "*faceNameDoublesize", XrmoptionSepArg, (XPointer) NULL},
{"-fs", "*faceSize", XrmoptionSepArg, (XPointer) NULL},
#endif
#if OPT_WIDE_CHARS
{"-fw", "*wideFont", XrmoptionSepArg, (XPointer) NULL},
{"-fwb", "*wideBoldFont", XrmoptionSepArg, (XPointer) NULL},
#endif
#if OPT_INPUT_METHOD
{"-fx", "*ximFont", XrmoptionSepArg, (XPointer) NULL},
#endif
#if OPT_HIGHLIGHT_COLOR
{"-hc", "*highlightColor", XrmoptionSepArg, (XPointer) NULL},
{"-hm", "*highlightColorMode", XrmoptionNoArg, (XPointer) "on"},
{"+hm", "*highlightColorMode", XrmoptionNoArg, (XPointer) "off"},
{"-selfg", "*highlightTextColor", XrmoptionSepArg, (XPointer) NULL},
{"-selbg", "*highlightColor", XrmoptionSepArg, (XPointer) NULL},
#endif
#if OPT_HP_FUNC_KEYS
{"-hf", "*hpFunctionKeys",XrmoptionNoArg, (XPointer) "on"},
{"+hf", "*hpFunctionKeys",XrmoptionNoArg, (XPointer) "off"},
#endif
{"-hold", "*hold", XrmoptionNoArg, (XPointer) "on"},
{"+hold", "*hold", XrmoptionNoArg, (XPointer) "off"},
#if OPT_INITIAL_ERASE
{"-ie", "*ptyInitialErase", XrmoptionNoArg, (XPointer) "on"},
{"+ie", "*ptyInitialErase", XrmoptionNoArg, (XPointer) "off"},
#endif
{"-j", "*jumpScroll", XrmoptionNoArg, (XPointer) "on"},
{"+j", "*jumpScroll", XrmoptionNoArg, (XPointer) "off"},
#if OPT_C1_PRINT
{"-k8", "*allowC1Printable", XrmoptionNoArg, (XPointer) "on"},
{"+k8", "*allowC1Printable", XrmoptionNoArg, (XPointer) "off"},
#endif
{"-kt", "*keyboardType", XrmoptionSepArg, (XPointer) NULL},
/* parse logging options anyway for compatibility */
{"-l", "*logging", XrmoptionNoArg, (XPointer) "on"},
{"+l", "*logging", XrmoptionNoArg, (XPointer) "off"},
{"-lf", "*logFile", XrmoptionSepArg, (XPointer) NULL},