]>
diplodocus.org Git - nmh/blob - uip/wmh.c
3 * wmh.c -- window front-end to nmh
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
12 * Pass signals to client during execution
14 * Figure out a way for the user to say how big the Scan/Display
15 * windows should be, and where all the windows should be.
19 #include <h/signals.h>
30 #define ALARM ((unsigned int) 10)
31 #define PAUSE ((unsigned int) 2)
33 #define SZ(a) (sizeof a / sizeof a[0])
35 static struct swit switches
[] = {
37 { "prompt string", 6 },
39 { "vmhproc program", 7 },
49 static int PEERpid
= NOTOK
;
51 static jmp_buf PEERctx
;
55 static int dfd
= NOTOK
;
56 static int twd
= NOTOK
;
57 static char *myprompt
= "(%s) ";
86 struct line
*w_bottom
;
88 char w_buffer
[BUFSIZ
];
94 static WINDOW
*Status
;
95 static WINDOW
*Display
;
96 static WINDOW
*Command
;
100 WINDOW
*windows
[NWIN
+ 1];
105 #ifdef HAVE_TERMIOS_H
106 static struct termios tio
;
107 # define ERASE tio.c_cc[VERASE]
108 # define KILL tio.c_cc[VKILL]
109 # define INTR tio.c_cc[VINTR]
111 # ifdef HAVE_TERMIO_H
112 static struct termio tio
;
113 # define ERASE tio.c_cc[VERASE]
114 # define KILL tio.c_cc[VKILL]
115 # define INTR tio.c_cc[VINTR]
117 static struct sgttyb tio
;
118 static struct tchars tc
;
119 # define ERASE tio.sg_erase
120 # define KILL tio.sg_kill
121 # define INTR tc.t_intrc
122 # define EOFC tc.t_eofc
126 #define WERASC ltc.t_werasc
127 static struct ltchars ltc
;
130 int ALRMser (), PIPEser (), SIGser ();
131 int ADJser (), REFser ();
136 static void adorn(char *, char *, ...);
140 main (int argc
, char **argv
)
142 int vecp
= 1, nprog
= 0;
143 char *cp
, buffer
[BUFSIZ
], **argp
;
144 char **arguments
, *vec
[MAXARGS
];
147 setlocale(LC_ALL
, "");
149 invo_name
= r1bindex (argv
[0], '/');
151 /* read user profile/context */
154 arguments
= getarguments (invo_name
, argc
,argv
, 1);
157 while ((cp
= *argp
++))
159 switch (smatch (++cp
, switches
)) {
161 ambigsw (cp
, switches
);
168 snprintf (buffer
, sizeof(buffer
), "%s [switches for vmhproc]",
170 print_help (buffer
, switches
, 1);
173 print_version(invo_name
);
177 if (!(myprompt
= *argp
++) || *myprompt
== '-')
178 adios (NULL
, "missing argument to %s", argp
[-2]);
182 if (!(vmhproc
= *argp
++) || *vmhproc
== '-')
183 adios (NULL
, "missing argument to %s", argp
[-2]);
193 if (WINinit (nprog
) == NOTOK
) {
196 vec
[0] = r1bindex (vmhproc
, '/');
197 execvp (vmhproc
, vec
);
198 adios (vmhproc
, "unable to exec");
200 PEERinit (vecp
, vec
);
211 char buffer
[BUFSIZ
], prompt
[BUFSIZ
];
214 pLOOP (RC_QRY
, NULL
);
216 snprintf (prompt
, sizeof(prompt
), myprompt
, invo_name
);
218 switch (WINgetstr (Command
, prompt
, buffer
)) {
223 done (0); /* NOTREACHED */
227 pLOOP (RC_CMD
, buffer
);
236 PEERinit (int vecp
, char *vec
[])
238 int pfd0
[2], pfd1
[2];
239 char buf1
[BUFSIZ
], buf2
[BUFSIZ
];
242 SIGNAL (SIGPIPE
, PIPEser
);
244 if (pipe (pfd0
) == NOTOK
|| pipe (pfd1
) == NOTOK
)
245 adios ("pipe", "unable to");
246 switch (PEERpid
= vfork ()) {
248 adios ("vfork", "unable to");/* NOTREACHED */
251 for (w
= windows
; *w
; w
++)
252 if ((*w
)->w_fd
!= NOTOK
)
257 vec
[vecp
++] = "-vmhread";
258 snprintf (buf1
, sizeof(buf1
), "%d", pfd1
[0]);
260 vec
[vecp
++] = "-vmhwrite";
261 snprintf (buf2
, sizeof(buf2
), "%d", pfd0
[1]);
265 SIGNAL (SIGINT
, SIG_DFL
);
266 SIGNAL (SIGQUIT
, SIG_DFL
);
267 SIGNAL (SIGTERM
, SIG_DFL
);
269 vec
[0] = r1bindex (vmhproc
, '/');
270 execvp (vmhproc
, vec
);
272 _exit (-1); /* NOTREACHED */
278 rcinit (pfd0
[0], pfd1
[1]);
288 char *bp
, buffer
[BUFSIZ
];
289 struct record rcs
, *rc
;
295 /* Get buffer ready to go */
297 buflen
= sizeof(buffer
);
299 snprintf (bp
, buflen
, "%d %d", RC_VRSN
, numwins
);
304 for (w
= windows
; *w
; w
++) {
305 snprintf (bp
, buflen
, " %d", (*w
)->w_height
);
311 switch (str2rc (RC_INI
, buffer
, rc
)) {
317 adios (NULL
, "%s", rc
->rc_data
);
319 adios (NULL
, "pINI peer error");
322 adios (NULL
, "%s", rc
->rc_data
);
325 adios (NULL
, "pINI protocol screw-up");
332 pLOOP (char code
, char *str
)
335 struct record rcs
, *rc
;
341 str2peer (code
, str
);
343 switch (peer2rc (rc
)) {
345 if (pTTY () == NOTOK
)
350 if (sscanf (rc
->rc_data
, "%d", &i
) != 1
353 fmt2peer (RC_ERR
, "no such window \"%s\"", rc
->rc_data
);
356 if ((w
= windows
[i
- 1])->w_flags
& W_CMND
) {
357 fmt2peer (RC_ERR
, "not a display window \"%s\"", rc
->rc_data
);
360 if (pWIN (w
) == NOTOK
)
369 adorn (NULL
, "%s", rc
->rc_data
);
371 adorn (NULL
, "pLOOP(%s) peer error",
372 code
== RC_QRY
? "QRY" : "CMD");
377 adorn (NULL
, "%s", rc
->rc_data
);
379 i
= pidwait (PEERpid
, OK
);
384 adios (NULL
, "%s", rc
->rc_data
);
387 adios (NULL
, "pLOOP(%s) protocol screw-up",
388 code
== RC_QRY
? "QRY" : "CMD");
396 SIGNAL_HANDLER hstat
, istat
, qstat
, tstat
;
397 struct record rcs
, *rc
;
402 if (ChangeWindowDepth (dfd
, twd
, 0) == NOTOK
)
403 adios ("failed", "ChangeWindowDepth");
405 /* should block here instead of ignore */
406 hstat
= SIGNAL (SIGHUP
, SIG_IGN
);
407 istat
= SIGNAL (SIGINT
, SIG_IGN
);
408 qstat
= SIGNAL (SIGQUIT
, SIG_IGN
);
409 tstat
= SIGNAL (SIGTERM
, SIG_IGN
);
411 rc2rc (RC_ACK
, 0, NULL
, rc
);
413 SIGNAL (SIGHUP
, hstat
);
414 SIGNAL (SIGINT
, istat
);
415 SIGNAL (SIGQUIT
, qstat
);
416 SIGNAL (SIGTERM
, tstat
);
418 switch (rc
->rc_type
) {
420 rc2peer (RC_ACK
, 0, NULL
);
425 adorn (NULL
, "%s", rc
->rc_data
);
427 adorn (NULL
, "pTTY peer error");
431 adios (NULL
, "%s", rc
->rc_data
);
434 adios (NULL
, "pTTY protocol screw-up");
445 if ((i
= pWINaux (w
)) == OK
)
457 register struct line
*lp
, *mp
;
458 struct record rcs
, *rc
;
463 for (lp
= w
->w_head
; lp
; lp
= mp
) {
468 w
->w_head
= w
->w_top
= w
->w_bottom
= w
->w_tail
= NULL
;
472 switch (rc2rc (RC_ACK
, 0, NULL
, rc
)) {
474 for (bp
= rc
->rc_data
, n
= rc
->rc_len
; n
-- > 0; )
479 rc2peer (RC_ACK
, 0, NULL
);
486 adorn (NULL
, "%s", rc
->rc_data
);
488 adorn (NULL
, "pWIN peer error");
492 adios (NULL
, "%s", rc
->rc_data
);
495 adios (NULL
, "pWIN protocol screw-up");
509 rc2peer (RC_FIN
, 0, NULL
);
512 switch (setjmp (PEERctx
)) {
514 SIGNAL (SIGALRM
, ALRMser
);
517 status
= pidwait (PEERpid
, OK
);
523 kill (PEERpid
, SIGKILL
);
534 /* should dynamically determine all this stuff from gconfig... */
536 #define MyX 20 /* anchored hpos */
537 #define MyY 40 /* .. vpos */
538 #define MyW 800 /* .. width */
539 #define MyH 500 /* .. height */
540 #define MyS 30 /* .. height for Status, about one line */
543 #define MySlop 45 /* slop */
545 #define EWIDTH 25 /* Width of vertical EBAR */
546 #define ESLOP 5 /* .. slop */
549 static intWINinit (nprog
) {
550 short wx
, wy
, wh
, sy
;
553 if (GetGraphicsConfig (fileno (stderr
), &gc
) == NOTOK
)
557 adios (NULL
, "not a window");
559 if ((dfd
= open ("/dev/ttyw0", O_RDWR
)) == NOTOK
)
560 adios ("/dev/ttyw0", "unable to open");
562 if ((twd
= GetTopWindow (dfd
)) == NOTOK
)
563 adios ("failed", "GetTopWindow");
565 BlockRefreshAdjust (1);
569 wx
= gc
.w
- (MyX
+ MyW
+ EWIDTH
+ ESLOP
);
570 Scan
= WINnew (wx
, wy
= MyY
, MyW
, wh
= MyH
* 2 / 3, "Scan", W_EBAR
);
573 Status
= WINnew (wx
, sy
= wy
, MyW
, wh
= MyS
, "Status", W_FAKE
);
576 Display
= WINnew (wx
, wy
, MyW
, MyH
, "Display", W_EBAR
);
578 Command
= WINnew (wx
, sy
, MyW
, MyS
, invo_name
, W_CMND
);
580 windows
[numwins
] = NULL
;
587 WINnew (short wx
, short wy
, short ww
, short wh
, char *name
, int flags
)
591 if ((w
= (WINDOW
*) calloc (1, sizeof *w
)) == NULL
)
592 adios (NULL
, "unable to allocate window");
594 if ((w
->w_flags
= flags
) & W_FAKE
) {
601 if (w
->w_flags
& W_EBAR
)
602 ww
+= EWIDTH
+ ESLOP
;
604 wx
+= EWIDTH
+ ESLOP
;
606 if ((w
->w_fd
= OpenWindow (wx
, wy
, ww
, wh
, name
)) == NOTOK
)
607 adios ("failed", "OpenWindow");
608 if ((w
->w_wd
= GetTopWindow (dfd
)) == NOTOK
)
609 adios ("failed", "GetTopWindow");
610 if (GetWindowState (w
->w_fd
, &w
->w_ws
) == NOTOK
)
611 adios ("failed", "GetWindowState");
612 if (SetLineDisc (w
->w_fd
, TWSDISC
) == NOTOK
)
613 adios ("failed", "SetLineDisc");
615 SetBuf (w
->w_fd
, 1024);
616 SetAdjust (w
->w_fd
, numwins
, ADJser
);
617 SetRefresh (w
->w_fd
, numwins
, REFser
);
619 SetAddressing (w
->w_fd
, VT_ABSOLUTE
);
621 if (w
->w_flags
& W_EBAR
) {
622 w
->w_eb
= CreateElevatorBar (w
->w_fd
, 0, 0, EWIDTH
,
623 w
->w_ws
.height
, VT_Gray50
, 1, EB_VERTICAL
,
624 EB_ARROWS
, w
->w_ebloc
= 0, w
->w_ebsize
= EB_MAX
,
627 adios (NULL
, "CreateElevatorBar failed");
628 RefreshElevatorBar (w
->w_eb
);
631 if ((w
->w_cbase
= CharacterBaseline (w
->w_ws
.font
)) <= 0)
634 if ((w
->w_cheight
= CharacterHeight (w
->w_ws
.font
)) <= 0)
636 w
->w_height
= w
->w_ws
.height
/ w
->w_cheight
;
641 if ((w
->w_cwidth
= CharacterWidth (w
->w_ws
.font
, 'm')) <= 0)
643 w
->w_width
= (w
->w_ws
.width
- (w
->w_eb
? (EWIDTH
+ ESLOP
) : 0))
649 windows
[numwins
++] = w
;
656 WINgetstr (WINDOW
*w
, char *prompt
, char *buffer
)
659 register char *bp
, *ip
;
662 register struct vtseq
*vt
= &vts
;
665 adios (NULL
, "internal error--elevator bar found");
667 if (w
->w_head
== NULL
668 && (w
->w_head
= (struct line
*) calloc (1, sizeof *w
->w_head
))
670 adios (NULL
, "unable to allocate line storage");
671 w
->w_head
->l_buf
= image
;
672 w
->w_top
= w
->w_bottom
= w
->w_tail
= w
->w_head
;
674 if (ChangeWindowDepth (dfd
, w
->w_wd
, 0) == NOTOK
)
675 adios ("failed", "ChangeWindowDepth");
677 strncpy (image
, prompt
, sizeof(image
));
678 bp
= ip
= image
+ strlen (image
);
683 switch (getvtseq (w
->w_fd
, vt
)) {
685 DisplayStatus (w
->w_fd
, "no hardkeys, please");
689 switch (c
= toascii (vt
->u
.ascii
)) {
690 case '\f': /* refresh? */
700 adorn (NULL
, "Interrupt");
729 } while (isspace (*bp
) && bp
> ip
);
733 } while (!isspace (*bp
) && bp
> buffer
);
740 if (c
< ' ' || c
>= '\177')
750 switch (vt
->u
.mouse
.buttons
751 & (VT_MOUSE_LEFT
| VT_MOUSE_MIDDLE
| VT_MOUSE_RIGHT
)) {
753 DisplayStatus (w
->w_fd
, "use middle or right button");
756 #define WPOP "WMH\0Advance\0Burst\0Exit\0EOF\0"
757 case VT_MOUSE_MIDDLE
:
758 SetPosition (w
->w_fd
, vt
->u
.mouse
.x
,
760 switch (DisplayPopUp (w
->w_fd
, WPOP
)) {
761 case 1: /* Advance */
763 strcpy (buffer
, "advance");
767 strcpy (buffer
, "burst");
771 strcpy (buffer
, "exit");
777 default: /* failed or none taken */
789 adios (NULL
, "end-of-file on window");/* NOTREACHED */
792 DisplayStatus (w
->w_fd
, "unknown VT sequence");
799 WINputc (WINDOW
*w
, char c
)
803 register struct line
*lp
;
808 if (WINputc (w
, 'M') == NOTOK
|| WINputc (w
, '-') == NOTOK
)
813 if (c
< ' ' || c
== '\177') {
814 if (WINputc (w
, '^') == NOTOK
)
821 for (i
= 8 - (w
->w_bufpos
& 0x07); i
> 0; i
--)
822 if (WINputc (w
, ' ') == NOTOK
)
836 w
->w_buffer
[w
->w_bufpos
++] = c
;
840 w
->w_buffer
[w
->w_bufpos
] = NULL
;
843 if ((lp
= (struct line
*) calloc (1, sizeof *lp
)) == NULL
)
844 adios (NULL
, "unable to allocate line storage");
846 lp
->l_no
= (w
->w_tail
? w
->w_tail
->l_no
: 0) + 1;
847 lp
->l_buf
= getcpy (w
->w_buffer
);
848 for (cp
= lp
->l_buf
+ strlen (lp
->l_buf
) - 1; cp
>= lp
->l_buf
; cp
--)
854 if (w
->w_head
== NULL
)
856 if (w
->w_top
== NULL
)
858 if (w
->w_bottom
== NULL
)
861 w
->w_tail
->l_next
= lp
;
862 lp
->l_prev
= w
->w_tail
;
871 static char mylineno
[5];
873 static bool cancel
[] = { 1 };
874 static struct choice mychoices
[] = { LABEL
, "cancel", VT_White
};
876 static struct question myquestions
[] = {
877 STRING
, "Line", SZ (mylineno
), (struct choice
*) 0,
879 TOGGLE
, "", SZ (mychoices
), mychoices
882 static struct menu mymenu
= { "Goto", SZ (myquestions
), myquestions
};
884 static int *myanswers
[] = { (int *) mylineno
, (int *) cancel
};
890 int clear
, pos
, forw
, refresh
;
892 register struct vtseq
*vt
= &vts
;
894 if (w
->w_fd
== NOTOK
) {
896 DisplayStatus (dfd
, w
->w_top
->l_buf
);
903 if (ChangeWindowDepth (dfd
, w
->w_wd
, 0) == NOTOK
)
904 adios ("failed", "ChangeWindowDepth");
908 if (w
->w_bottom
== w
->w_tail
)
912 adios (NULL
, "internal error--no elevator bar");
914 for (clear
= refresh
= 0, forw
= 1;;) {
916 RemoveStatus (w
->w_fd
);
924 switch (getvtseq (w
->w_fd
, vt
)) {
927 DisplayStatus (w
->w_fd
, "use the mouse");
932 switch (vt
->u
.mouse
.buttons
933 & (VT_MOUSE_LEFT
| VT_MOUSE_MIDDLE
| VT_MOUSE_RIGHT
)) {
935 if ((pos
= vt
->u
.mouse
.x
) < EWIDTH
) {
936 pos
= w
->w_ebloc
= DoElevatorBar (w
->w_eb
, pos
,
938 refresh
= WINgoto (w
, ((pos
* (w
->w_tail
->l_no
940 / EB_MAX
) + w
->w_head
->l_no
);
944 #define WPOP "Paging\0Next\0Prev\0Left\0Right\0First\0Last\0Goto ...\0Exit\0"
945 case VT_MOUSE_MIDDLE
:
946 SetPosition (w
->w_fd
, vt
->u
.mouse
.x
,
948 switch (DisplayPopUp (w
->w_fd
, WPOP
)) {
951 if (w
->w_bottom
== w
->w_tail
)
953 refresh
= WINgoto (w
, w
->w_bottom
->l_no
+ 1 - PSLOP
);
958 if (w
->w_top
== w
->w_head
)
960 refresh
= WINgoto (w
, w
->w_top
->l_no
961 - w
->w_height
+ PSLOP
);
966 DisplayStatus (w
->w_fd
, "not yet");
972 refresh
= WINgoto (w
, w
->w_head
->l_no
);
977 refresh
= WINgoto (w
, w
->w_tail
->l_no
981 case 7: /* Goto ... */
982 snprintf (mylineno
, sizeof(mylineno
),
983 "%d", w
->w_top
->l_no
);
985 if (PresentMenu (&mymenu
, myanswers
)
988 if (sscanf (mylineno
, "%d", &pos
) != 1) {
989 DisplayStatus (w
->w_fd
, "bad format");
993 if (pos
< w
->w_head
->l_no
994 || pos
> w
->w_tail
->l_no
) {
995 DisplayStatus (w
->w_fd
, "no such line");
999 refresh
= WINgoto (w
, pos
);
1005 default: /* failed or none taken */
1011 case VT_MOUSE_RIGHT
:
1013 if (w
->w_bottom
== w
->w_tail
)
1024 adios (NULL
, "end-of-file on window");/* NOTREACHED */
1027 DisplayStatus (w
->w_fd
, "unknown VT sequence");
1036 WINgoto (WINDOW
*w
, int n
)
1039 register struct line
*lp
;
1041 if (n
> (i
= w
->w_tail
->l_no
- w
->w_height
+ 1))
1043 if (n
< w
->w_head
->l_no
)
1044 n
= w
->w_head
->l_no
;
1046 if ((i
= n
- (lp
= w
->w_head
)->l_no
)
1047 > (j
= abs (n
- w
->w_top
->l_no
)))
1048 i
= j
, lp
= w
->w_top
;
1050 if (i
> (j
= abs (w
->w_tail
->l_no
- n
)))
1051 i
= j
, lp
= w
->w_tail
;
1053 if (n
>= lp
->l_no
) {
1054 for (; lp
; lp
= lp
->l_next
)
1059 for (; lp
; lp
= lp
->l_prev
)
1076 ADJser (int id
, short ww
, short wh
)
1080 if (id
< 0 || id
>= numwins
)
1081 adios (NULL
, "ADJser on bogus window (%d)", id
);
1083 if (w
->w_fd
== NOTOK
)
1084 adios (NULL
, "ADJser on closed window (%d)", id
);
1086 w
->w_ws
.width
= w
->w_ws
.tw
= ww
;
1087 w
->w_ws
.height
= w
->w_ws
.th
= wh
;
1090 DeleteElevatorBar (w
->w_eb
);
1091 w
->w_eb
= CreateElevatorBar (w
->w_fd
, 0, 0, EWIDTH
,
1092 w
->w_ws
.height
, VT_Gray50
, 1, EB_VERTICAL
,
1093 EB_ARROWS
, w
->w_ebloc
= 0, w
->w_ebsize
= EB_MAX
,
1095 if (w
->w_eb
== NULL
)
1096 adios (NULL
, "CreateElevatorBar failed");
1104 REFser (int id
, short wx
, short wy
, short ww
, short wh
)
1106 short cx
, cy
, cw
, ch
;
1109 if (id
< 0 || id
>= numwins
)
1110 adios (NULL
, "REFser on bogus window (%d)", id
);
1112 if (w
->w_fd
== NOTOK
)
1113 adios (NULL
, "REFser on closed window (%d)", id
);
1116 if (GetWindowState (w
->w_fd
, &w
->w_ws
) == NOTOK
)
1117 adios ("failed", "GetWindowState");
1119 GetPermanentClipping (w
->w_fd
, &cx
, &cy
, &cw
, &ch
);
1120 SetPermanentClipping (w
->w_fd
, wx
, wy
, ww
, wh
);
1122 SetPermanentClipping (w
->w_fd
, cx
, cy
, cw
, ch
);
1127 Redisplay (WINDOW
*w
, int doeb
)
1131 register struct line
*lp
;
1133 if (w
->w_fd
== NOTOK
)
1136 sx
= w
->w_eb
? (EWIDTH
+ ESLOP
) : 0;
1137 w
->w_height
= w
->w_ws
.height
/ w
->w_cheight
;
1138 if (w
->w_height
< 1)
1141 w
->w_width
= (w
->w_ws
.width
- (w
->w_eb
? (EWIDTH
+ ESLOP
) : 0))
1146 SetPosition (w
->w_fd
, sx
, 0);
1147 SetColor (w
->w_fd
, VT_White
);
1148 PaintRectangleInterior (w
->w_fd
, w
->w_ws
.width
, w
->w_ws
.height
);
1151 SetColor (w
->w_fd
, VT_Black
);
1152 for (lp
= w
->w_top
, y
= 0;
1153 lp
&& y
< w
->w_height
;
1154 w
->w_bottom
= lp
, lp
= lp
->l_next
, y
++) {
1155 SetPosition (w
->w_fd
, sx
, y
* w
->w_cheight
+ w
->w_cbase
);
1156 PaintString (w
->w_fd
, VT_STREND
, lp
->l_buf
);
1161 if ((y
= EB_LOC (w
)) != w
->w_ebloc
)
1162 MoveElevator (w
->w_eb
, w
->w_ebloc
= y
);
1163 if ((y
= EB_SIZE (w
)) != w
->w_ebsize
)
1164 SizeElevator (w
->w_eb
, w
->w_ebsize
= y
);
1166 RefreshElevatorBar (w
->w_eb
);
1178 if (w
->w_head
== NULL
)
1181 if ((i
= w
->w_tail
->l_no
- w
->w_head
->l_no
) <= 0)
1184 return (((w
->w_bottom
->l_no
- w
->w_top
->l_no
) * EB_MAX
) / i
);
1193 if (w
->w_head
== NULL
)
1196 if ((i
= w
->w_tail
->l_no
- w
->w_head
->l_no
) <= 0)
1199 return (((w
->w_top
->l_no
- w
->w_head
->l_no
) * EB_MAX
) / i
);
1208 if (ioctl (fileno (stdin
), TIOCGETP
, (char *) &tio
) == NOTOK
)
1209 adios ("failed", "ioctl TIOCGETP");
1210 if (ioctl (fileno (stdin
), TIOCGETC
, (char *) &tc
) == NOTOK
)
1211 adios ("failed", "ioctl TIOCGETC");
1212 if (ioctl (fileno (stdin
), TIOCGLTC
, (char *) <c
) == NOTOK
)
1213 adios ("failed", "ioctl TIOCGLTC");
1216 SIGNAL (SIGHUP
, SIGser
);
1217 SIGNAL (SIGINT
, SIGser
);
1218 SIGNAL (SIGQUIT
, SIGser
);
1227 SIGNAL_HANDLER tstat
;
1229 if ((pgrp
= getpgrp (0)) == NOTOK
)
1230 adios ("process group", "unable to determine");
1232 if (ioctl (fileno (stdin
), TIOCGPGRP
, (char *) &tpgrp
) == NOTOK
)
1233 adios ("tty's process group", "unable to determine");
1237 tstat
= SIGNAL (SIGTTIN
, SIG_DFL
);
1239 SIGNAL (SIGTTIN
, tstat
);
1242 SIGNAL (SIGTTIN
, SIG_IGN
);
1243 SIGNAL (SIGTTOU
, SIG_IGN
);
1244 SIGNAL (SIGTSTP
, SIG_IGN
);
1253 SIGNAL (SIGTTIN
, SIG_DFL
);
1254 SIGNAL (SIGTTOU
, SIG_DFL
);
1255 SIGNAL (SIGTSTP
, SIG_DFL
);
1263 longjmp (PEERctx
, DONE
);
1270 #ifndef RELIABLE_SIGNALS
1271 SIGNAL (sig
, SIG_IGN
);
1274 adios (NULL
, "lost peer");
1281 #ifndef RELIABLE_SIGNALS
1282 SIGNAL (sig
, SIG_IGN
);
1298 return 1; /* dead code to satisfy the compiler */
1303 adorn (char *what
, char *fmt
, ...)
1312 advertise (what
, NULL
, fmt
, ap
);
1320 advertise (char *what
, char *tail
, va_list ap
)
1323 char buffer
[BUFSIZ
], err
[BUFSIZ
];
1324 struct iovec iob
[20];
1325 register struct iovec
*iov
= iob
;
1331 iov
->iov_len
= strlen (iov
->iov_base
= invo_name
);
1333 iov
->iov_len
= strlen (iov
->iov_base
= ": ");
1337 vsnprintf (buffer
, sizeof(buffer
), fmt
, ap
);
1338 iov
->iov_len
= strlen (iov
->iov_base
= buffer
);
1342 iov
->iov_len
= strlen (iov
->iov_base
= " ");
1344 iov
->iov_len
= strlen (iov
->iov_base
= what
);
1346 iov
->iov_len
= strlen (iov
->iov_base
= ": ");
1349 if (!(iov
->iov_base
= strerror (eindex
))) {
1350 snprintf (err
, sizeof(err
), "unknown error %d", eindex
);
1351 iov
->iov_base
= err
;
1353 iov
->iov_len
= strlen (iov
->iov_base
);
1356 if (tail
&& *tail
) {
1357 iov
->iov_len
= strlen (iov
->iov_base
= ", ");
1359 iov
->iov_len
= strlen (iov
->iov_base
= tail
);
1362 iov
->iov_len
= strlen (iov
->iov_base
= "\n");
1366 DisplayVector (iob
, iov
- iob
);
1368 writev (fileno (stderr
), iob
, iov
- iob
);
1373 DisplayVector (struct iovec
*iov
, int n
)
1377 char buffer
[BUFSIZ
];
1379 for (i
= 0, cp
= NULL
; i
< n
; i
++, iov
++) {
1380 snprintf (buffer
, sizeof(buffer
), "%*.*s", iov
->iov_len
,
1381 iov
->iov_len
, iov
->iov_base
);
1382 cp
= add (buffer
, cp
);
1385 DisplayStatus (dfd
, cp
);