]>
diplodocus.org Git - nmh/blob - uip/wmh.c
3 * wmh.c -- window front-end to nmh
10 * Pass signals to client during execution
12 * Figure out a way for the user to say how big the Scan/Display
13 * windows should be, and where all the windows should be.
17 #include <h/signals.h>
28 #define ALARM ((unsigned int) 10)
29 #define PAUSE ((unsigned int) 2)
31 #define SZ(a) (sizeof a / sizeof a[0])
33 static struct swit switches
[] = {
35 { "prompt string", 6 },
37 { "vmhproc program", 7 },
47 static int PEERpid
= NOTOK
;
49 static jmp_buf PEERctx
;
53 static int dfd
= NOTOK
;
54 static int twd
= NOTOK
;
55 static char *myprompt
= "(%s) ";
84 struct line
*w_bottom
;
86 char w_buffer
[BUFSIZ
];
92 static WINDOW
*Status
;
93 static WINDOW
*Display
;
94 static WINDOW
*Command
;
98 WINDOW
*windows
[NWIN
+ 1];
103 #ifdef HAVE_TERMIOS_H
104 static struct termios tio
;
105 # define ERASE tio.c_cc[VERASE]
106 # define KILL tio.c_cc[VKILL]
107 # define INTR tio.c_cc[VINTR]
109 # ifdef HAVE_TERMIO_H
110 static struct termio tio
;
111 # define ERASE tio.c_cc[VERASE]
112 # define KILL tio.c_cc[VKILL]
113 # define INTR tio.c_cc[VINTR]
115 static struct sgttyb tio
;
116 static struct tchars tc
;
117 # define ERASE tio.sg_erase
118 # define KILL tio.sg_kill
119 # define INTR tc.t_intrc
120 # define EOFC tc.t_eofc
124 #define WERASC ltc.t_werasc
125 static struct ltchars ltc
;
129 int ALRMser (), PIPEser (), SIGser ();
130 int ADJser (), REFser ();
135 static void adorn(char *, char *, ...);
139 main (int argc
, char **argv
)
141 int vecp
= 1, nprog
= 0;
142 char *cp
, buffer
[BUFSIZ
], **argp
;
143 char **arguments
, *vec
[MAXARGS
];
146 setlocale(LC_ALL
, "");
148 invo_name
= r1bindex (argv
[0], '/');
150 /* read user profile/context */
153 arguments
= getarguments (invo_name
, argc
,argv
, 1);
156 while ((cp
= *argp
++))
158 switch (smatch (++cp
, switches
)) {
160 ambigsw (cp
, switches
);
167 snprintf (buffer
, sizeof(buffer
), "%s [switches for vmhproc]",
169 print_help (buffer
, switches
, 1);
172 print_version(invo_name
);
176 if (!(myprompt
= *argp
++) || *myprompt
== '-')
177 adios (NULL
, "missing argument to %s", argp
[-2]);
181 if (!(vmhproc
= *argp
++) || *vmhproc
== '-')
182 adios (NULL
, "missing argument to %s", argp
[-2]);
192 if (WINinit (nprog
) == NOTOK
) {
195 vec
[0] = r1bindex (vmhproc
, '/');
196 execvp (vmhproc
, vec
);
197 adios (vmhproc
, "unable to exec");
199 PEERinit (vecp
, vec
);
210 char buffer
[BUFSIZ
], prompt
[BUFSIZ
];
213 pLOOP (RC_QRY
, NULL
);
215 snprintf (prompt
, sizeof(prompt
), myprompt
, invo_name
);
217 switch (WINgetstr (Command
, prompt
, buffer
)) {
222 done (0); /* NOTREACHED */
226 pLOOP (RC_CMD
, buffer
);
235 PEERinit (int vecp
, char *vec
[])
237 int pfd0
[2], pfd1
[2];
238 char buf1
[BUFSIZ
], buf2
[BUFSIZ
];
241 SIGNAL (SIGPIPE
, PIPEser
);
243 if (pipe (pfd0
) == NOTOK
|| pipe (pfd1
) == NOTOK
)
244 adios ("pipe", "unable to");
245 switch (PEERpid
= vfork ()) {
247 adios ("vfork", "unable to");/* NOTREACHED */
250 for (w
= windows
; *w
; w
++)
251 if ((*w
)->w_fd
!= NOTOK
)
256 vec
[vecp
++] = "-vmhread";
257 snprintf (buf1
, sizeof(buf1
), "%d", pfd1
[0]);
259 vec
[vecp
++] = "-vmhwrite";
260 snprintf (buf2
, sizeof(buf2
), "%d", pfd0
[1]);
264 SIGNAL (SIGINT
, SIG_DFL
);
265 SIGNAL (SIGQUIT
, SIG_DFL
);
266 SIGNAL (SIGTERM
, SIG_DFL
);
268 vec
[0] = r1bindex (vmhproc
, '/');
269 execvp (vmhproc
, vec
);
271 _exit (-1); /* NOTREACHED */
277 rcinit (pfd0
[0], pfd1
[1]);
287 char *bp
, buffer
[BUFSIZ
];
288 struct record rcs
, *rc
;
294 /* Get buffer ready to go */
296 buflen
= sizeof(buffer
);
298 snprintf (bp
, buflen
, "%d %d", RC_VRSN
, numwins
);
303 for (w
= windows
; *w
; w
++) {
304 snprintf (bp
, buflen
, " %d", (*w
)->w_height
);
310 switch (str2rc (RC_INI
, buffer
, rc
)) {
316 adios (NULL
, "%s", rc
->rc_data
);
318 adios (NULL
, "pINI peer error");
321 adios (NULL
, "%s", rc
->rc_data
);
324 adios (NULL
, "pINI protocol screw-up");
331 pLOOP (char code
, char *str
)
334 struct record rcs
, *rc
;
340 str2peer (code
, str
);
342 switch (peer2rc (rc
)) {
344 if (pTTY () == NOTOK
)
349 if (sscanf (rc
->rc_data
, "%d", &i
) != 1
352 fmt2peer (RC_ERR
, "no such window \"%s\"", rc
->rc_data
);
355 if ((w
= windows
[i
- 1])->w_flags
& W_CMND
) {
356 fmt2peer (RC_ERR
, "not a display window \"%s\"", rc
->rc_data
);
359 if (pWIN (w
) == NOTOK
)
368 adorn (NULL
, "%s", rc
->rc_data
);
370 adorn (NULL
, "pLOOP(%s) peer error",
371 code
== RC_QRY
? "QRY" : "CMD");
376 adorn (NULL
, "%s", rc
->rc_data
);
378 i
= pidwait (PEERpid
, OK
);
383 adios (NULL
, "%s", rc
->rc_data
);
386 adios (NULL
, "pLOOP(%s) protocol screw-up",
387 code
== RC_QRY
? "QRY" : "CMD");
395 SIGNAL_HANDLER hstat
, istat
, qstat
, tstat
;
396 struct record rcs
, *rc
;
401 if (ChangeWindowDepth (dfd
, twd
, 0) == NOTOK
)
402 adios ("failed", "ChangeWindowDepth");
404 /* should block here instead of ignore */
405 hstat
= SIGNAL (SIGHUP
, SIG_IGN
);
406 istat
= SIGNAL (SIGINT
, SIG_IGN
);
407 qstat
= SIGNAL (SIGQUIT
, SIG_IGN
);
408 tstat
= SIGNAL (SIGTERM
, SIG_IGN
);
410 rc2rc (RC_ACK
, 0, NULL
, rc
);
412 SIGNAL (SIGHUP
, hstat
);
413 SIGNAL (SIGINT
, istat
);
414 SIGNAL (SIGQUIT
, qstat
);
415 SIGNAL (SIGTERM
, tstat
);
417 switch (rc
->rc_type
) {
419 rc2peer (RC_ACK
, 0, NULL
);
424 adorn (NULL
, "%s", rc
->rc_data
);
426 adorn (NULL
, "pTTY peer error");
430 adios (NULL
, "%s", rc
->rc_data
);
433 adios (NULL
, "pTTY protocol screw-up");
444 if ((i
= pWINaux (w
)) == OK
)
456 register struct line
*lp
, *mp
;
457 struct record rcs
, *rc
;
462 for (lp
= w
->w_head
; lp
; lp
= mp
) {
467 w
->w_head
= w
->w_top
= w
->w_bottom
= w
->w_tail
= NULL
;
471 switch (rc2rc (RC_ACK
, 0, NULL
, rc
)) {
473 for (bp
= rc
->rc_data
, n
= rc
->rc_len
; n
-- > 0; )
478 rc2peer (RC_ACK
, 0, NULL
);
485 adorn (NULL
, "%s", rc
->rc_data
);
487 adorn (NULL
, "pWIN peer error");
491 adios (NULL
, "%s", rc
->rc_data
);
494 adios (NULL
, "pWIN protocol screw-up");
508 rc2peer (RC_FIN
, 0, NULL
);
511 switch (setjmp (PEERctx
)) {
513 SIGNAL (SIGALRM
, ALRMser
);
516 status
= pidwait (PEERpid
, OK
);
522 kill (PEERpid
, SIGKILL
);
533 /* should dynamically determine all this stuff from gconfig... */
535 #define MyX 20 /* anchored hpos */
536 #define MyY 40 /* .. vpos */
537 #define MyW 800 /* .. width */
538 #define MyH 500 /* .. height */
539 #define MyS 30 /* .. height for Status, about one line */
542 #define MySlop 45 /* slop */
544 #define EWIDTH 25 /* Width of vertical EBAR */
545 #define ESLOP 5 /* .. slop */
548 static intWINinit (nprog
) {
549 short wx
, wy
, wh
, sy
;
552 if (GetGraphicsConfig (fileno (stderr
), &gc
) == NOTOK
)
556 adios (NULL
, "not a window");
558 if ((dfd
= open ("/dev/ttyw0", O_RDWR
)) == NOTOK
)
559 adios ("/dev/ttyw0", "unable to open");
561 if ((twd
= GetTopWindow (dfd
)) == NOTOK
)
562 adios ("failed", "GetTopWindow");
564 BlockRefreshAdjust (1);
568 wx
= gc
.w
- (MyX
+ MyW
+ EWIDTH
+ ESLOP
);
569 Scan
= WINnew (wx
, wy
= MyY
, MyW
, wh
= MyH
* 2 / 3, "Scan", W_EBAR
);
572 Status
= WINnew (wx
, sy
= wy
, MyW
, wh
= MyS
, "Status", W_FAKE
);
575 Display
= WINnew (wx
, wy
, MyW
, MyH
, "Display", W_EBAR
);
577 Command
= WINnew (wx
, sy
, MyW
, MyS
, invo_name
, W_CMND
);
579 windows
[numwins
] = NULL
;
586 WINnew (short wx
, short wy
, short ww
, short wh
, char *name
, int flags
)
590 if ((w
= (WINDOW
*) calloc (1, sizeof *w
)) == NULL
)
591 adios (NULL
, "unable to allocate window");
593 if ((w
->w_flags
= flags
) & W_FAKE
) {
600 if (w
->w_flags
& W_EBAR
)
601 ww
+= EWIDTH
+ ESLOP
;
603 wx
+= EWIDTH
+ ESLOP
;
605 if ((w
->w_fd
= OpenWindow (wx
, wy
, ww
, wh
, name
)) == NOTOK
)
606 adios ("failed", "OpenWindow");
607 if ((w
->w_wd
= GetTopWindow (dfd
)) == NOTOK
)
608 adios ("failed", "GetTopWindow");
609 if (GetWindowState (w
->w_fd
, &w
->w_ws
) == NOTOK
)
610 adios ("failed", "GetWindowState");
611 if (SetLineDisc (w
->w_fd
, TWSDISC
) == NOTOK
)
612 adios ("failed", "SetLineDisc");
614 SetBuf (w
->w_fd
, 1024);
615 SetAdjust (w
->w_fd
, numwins
, ADJser
);
616 SetRefresh (w
->w_fd
, numwins
, REFser
);
618 SetAddressing (w
->w_fd
, VT_ABSOLUTE
);
620 if (w
->w_flags
& W_EBAR
) {
621 w
->w_eb
= CreateElevatorBar (w
->w_fd
, 0, 0, EWIDTH
,
622 w
->w_ws
.height
, VT_Gray50
, 1, EB_VERTICAL
,
623 EB_ARROWS
, w
->w_ebloc
= 0, w
->w_ebsize
= EB_MAX
,
626 adios (NULL
, "CreateElevatorBar failed");
627 RefreshElevatorBar (w
->w_eb
);
630 if ((w
->w_cbase
= CharacterBaseline (w
->w_ws
.font
)) <= 0)
633 if ((w
->w_cheight
= CharacterHeight (w
->w_ws
.font
)) <= 0)
635 w
->w_height
= w
->w_ws
.height
/ w
->w_cheight
;
640 if ((w
->w_cwidth
= CharacterWidth (w
->w_ws
.font
, 'm')) <= 0)
642 w
->w_width
= (w
->w_ws
.width
- (w
->w_eb
? (EWIDTH
+ ESLOP
) : 0))
648 windows
[numwins
++] = w
;
655 WINgetstr (WINDOW
*w
, char *prompt
, char *buffer
)
658 register char *bp
, *ip
;
661 register struct vtseq
*vt
= &vts
;
664 adios (NULL
, "internal error--elevator bar found");
666 if (w
->w_head
== NULL
667 && (w
->w_head
= (struct line
*) calloc (1, sizeof *w
->w_head
))
669 adios (NULL
, "unable to allocate line storage");
670 w
->w_head
->l_buf
= image
;
671 w
->w_top
= w
->w_bottom
= w
->w_tail
= w
->w_head
;
673 if (ChangeWindowDepth (dfd
, w
->w_wd
, 0) == NOTOK
)
674 adios ("failed", "ChangeWindowDepth");
676 strncpy (image
, prompt
, sizeof(image
));
677 bp
= ip
= image
+ strlen (image
);
682 switch (getvtseq (w
->w_fd
, vt
)) {
684 DisplayStatus (w
->w_fd
, "no hardkeys, please");
688 switch (c
= toascii (vt
->u
.ascii
)) {
689 case '\f': /* refresh? */
699 adorn (NULL
, "Interrupt");
728 } while (isspace (*bp
) && bp
> ip
);
732 } while (!isspace (*bp
) && bp
> buffer
);
739 if (c
< ' ' || c
>= '\177')
749 switch (vt
->u
.mouse
.buttons
750 & (VT_MOUSE_LEFT
| VT_MOUSE_MIDDLE
| VT_MOUSE_RIGHT
)) {
752 DisplayStatus (w
->w_fd
, "use middle or right button");
755 #define WPOP "WMH\0Advance\0Burst\0Exit\0EOF\0"
756 case VT_MOUSE_MIDDLE
:
757 SetPosition (w
->w_fd
, vt
->u
.mouse
.x
,
759 switch (DisplayPopUp (w
->w_fd
, WPOP
)) {
760 case 1: /* Advance */
762 strcpy (buffer
, "advance");
766 strcpy (buffer
, "burst");
770 strcpy (buffer
, "exit");
776 default: /* failed or none taken */
788 adios (NULL
, "end-of-file on window");/* NOTREACHED */
791 DisplayStatus (w
->w_fd
, "unknown VT sequence");
798 WINputc (WINDOW
*w
, char c
)
802 register struct line
*lp
;
807 if (WINputc (w
, 'M') == NOTOK
|| WINputc (w
, '-') == NOTOK
)
812 if (c
< ' ' || c
== '\177') {
813 if (WINputc (w
, '^') == NOTOK
)
820 for (i
= 8 - (w
->w_bufpos
& 0x07); i
> 0; i
--)
821 if (WINputc (w
, ' ') == NOTOK
)
835 w
->w_buffer
[w
->w_bufpos
++] = c
;
839 w
->w_buffer
[w
->w_bufpos
] = NULL
;
842 if ((lp
= (struct line
*) calloc (1, sizeof *lp
)) == NULL
)
843 adios (NULL
, "unable to allocate line storage");
845 lp
->l_no
= (w
->w_tail
? w
->w_tail
->l_no
: 0) + 1;
846 lp
->l_buf
= getcpy (w
->w_buffer
);
847 for (cp
= lp
->l_buf
+ strlen (lp
->l_buf
) - 1; cp
>= lp
->l_buf
; cp
--)
853 if (w
->w_head
== NULL
)
855 if (w
->w_top
== NULL
)
857 if (w
->w_bottom
== NULL
)
860 w
->w_tail
->l_next
= lp
;
861 lp
->l_prev
= w
->w_tail
;
870 static char mylineno
[5];
872 static bool cancel
[] = { 1 };
873 static struct choice mychoices
[] = { LABEL
, "cancel", VT_White
};
875 static struct question myquestions
[] = {
876 STRING
, "Line", SZ (mylineno
), (struct choice
*) 0,
878 TOGGLE
, "", SZ (mychoices
), mychoices
881 static struct menu mymenu
= { "Goto", SZ (myquestions
), myquestions
};
883 static int *myanswers
[] = { (int *) mylineno
, (int *) cancel
};
889 int clear
, pos
, forw
, refresh
;
891 register struct vtseq
*vt
= &vts
;
893 if (w
->w_fd
== NOTOK
) {
895 DisplayStatus (dfd
, w
->w_top
->l_buf
);
902 if (ChangeWindowDepth (dfd
, w
->w_wd
, 0) == NOTOK
)
903 adios ("failed", "ChangeWindowDepth");
907 if (w
->w_bottom
== w
->w_tail
)
911 adios (NULL
, "internal error--no elevator bar");
913 for (clear
= refresh
= 0, forw
= 1;;) {
915 RemoveStatus (w
->w_fd
);
923 switch (getvtseq (w
->w_fd
, vt
)) {
926 DisplayStatus (w
->w_fd
, "use the mouse");
931 switch (vt
->u
.mouse
.buttons
932 & (VT_MOUSE_LEFT
| VT_MOUSE_MIDDLE
| VT_MOUSE_RIGHT
)) {
934 if ((pos
= vt
->u
.mouse
.x
) < EWIDTH
) {
935 pos
= w
->w_ebloc
= DoElevatorBar (w
->w_eb
, pos
,
937 refresh
= WINgoto (w
, ((pos
* (w
->w_tail
->l_no
939 / EB_MAX
) + w
->w_head
->l_no
);
943 #define WPOP "Paging\0Next\0Prev\0Left\0Right\0First\0Last\0Goto ...\0Exit\0"
944 case VT_MOUSE_MIDDLE
:
945 SetPosition (w
->w_fd
, vt
->u
.mouse
.x
,
947 switch (DisplayPopUp (w
->w_fd
, WPOP
)) {
950 if (w
->w_bottom
== w
->w_tail
)
952 refresh
= WINgoto (w
, w
->w_bottom
->l_no
+ 1 - PSLOP
);
957 if (w
->w_top
== w
->w_head
)
959 refresh
= WINgoto (w
, w
->w_top
->l_no
960 - w
->w_height
+ PSLOP
);
965 DisplayStatus (w
->w_fd
, "not yet");
971 refresh
= WINgoto (w
, w
->w_head
->l_no
);
976 refresh
= WINgoto (w
, w
->w_tail
->l_no
980 case 7: /* Goto ... */
981 snprintf (mylineno
, sizeof(mylineno
),
982 "%d", w
->w_top
->l_no
);
984 if (PresentMenu (&mymenu
, myanswers
)
987 if (sscanf (mylineno
, "%d", &pos
) != 1) {
988 DisplayStatus (w
->w_fd
, "bad format");
992 if (pos
< w
->w_head
->l_no
993 || pos
> w
->w_tail
->l_no
) {
994 DisplayStatus (w
->w_fd
, "no such line");
998 refresh
= WINgoto (w
, pos
);
1004 default: /* failed or none taken */
1010 case VT_MOUSE_RIGHT
:
1012 if (w
->w_bottom
== w
->w_tail
)
1023 adios (NULL
, "end-of-file on window");/* NOTREACHED */
1026 DisplayStatus (w
->w_fd
, "unknown VT sequence");
1035 WINgoto (WINDOW
*w
, int n
)
1038 register struct line
*lp
;
1040 if (n
> (i
= w
->w_tail
->l_no
- w
->w_height
+ 1))
1042 if (n
< w
->w_head
->l_no
)
1043 n
= w
->w_head
->l_no
;
1045 if ((i
= n
- (lp
= w
->w_head
)->l_no
)
1046 > (j
= abs (n
- w
->w_top
->l_no
)))
1047 i
= j
, lp
= w
->w_top
;
1049 if (i
> (j
= abs (w
->w_tail
->l_no
- n
)))
1050 i
= j
, lp
= w
->w_tail
;
1052 if (n
>= lp
->l_no
) {
1053 for (; lp
; lp
= lp
->l_next
)
1058 for (; lp
; lp
= lp
->l_prev
)
1075 ADJser (int id
, short ww
, short wh
)
1079 if (id
< 0 || id
>= numwins
)
1080 adios (NULL
, "ADJser on bogus window (%d)", id
);
1082 if (w
->w_fd
== NOTOK
)
1083 adios (NULL
, "ADJser on closed window (%d)", id
);
1085 w
->w_ws
.width
= w
->w_ws
.tw
= ww
;
1086 w
->w_ws
.height
= w
->w_ws
.th
= wh
;
1089 DeleteElevatorBar (w
->w_eb
);
1090 w
->w_eb
= CreateElevatorBar (w
->w_fd
, 0, 0, EWIDTH
,
1091 w
->w_ws
.height
, VT_Gray50
, 1, EB_VERTICAL
,
1092 EB_ARROWS
, w
->w_ebloc
= 0, w
->w_ebsize
= EB_MAX
,
1094 if (w
->w_eb
== NULL
)
1095 adios (NULL
, "CreateElevatorBar failed");
1103 REFser (int id
, short wx
, short wy
, short ww
, short wh
)
1105 short cx
, cy
, cw
, ch
;
1108 if (id
< 0 || id
>= numwins
)
1109 adios (NULL
, "REFser on bogus window (%d)", id
);
1111 if (w
->w_fd
== NOTOK
)
1112 adios (NULL
, "REFser on closed window (%d)", id
);
1115 if (GetWindowState (w
->w_fd
, &w
->w_ws
) == NOTOK
)
1116 adios ("failed", "GetWindowState");
1118 GetPermanentClipping (w
->w_fd
, &cx
, &cy
, &cw
, &ch
);
1119 SetPermanentClipping (w
->w_fd
, wx
, wy
, ww
, wh
);
1121 SetPermanentClipping (w
->w_fd
, cx
, cy
, cw
, ch
);
1126 Redisplay (WINDOW
*w
, int doeb
)
1130 register struct line
*lp
;
1132 if (w
->w_fd
== NOTOK
)
1135 sx
= w
->w_eb
? (EWIDTH
+ ESLOP
) : 0;
1136 w
->w_height
= w
->w_ws
.height
/ w
->w_cheight
;
1137 if (w
->w_height
< 1)
1140 w
->w_width
= (w
->w_ws
.width
- (w
->w_eb
? (EWIDTH
+ ESLOP
) : 0))
1145 SetPosition (w
->w_fd
, sx
, 0);
1146 SetColor (w
->w_fd
, VT_White
);
1147 PaintRectangleInterior (w
->w_fd
, w
->w_ws
.width
, w
->w_ws
.height
);
1150 SetColor (w
->w_fd
, VT_Black
);
1151 for (lp
= w
->w_top
, y
= 0;
1152 lp
&& y
< w
->w_height
;
1153 w
->w_bottom
= lp
, lp
= lp
->l_next
, y
++) {
1154 SetPosition (w
->w_fd
, sx
, y
* w
->w_cheight
+ w
->w_cbase
);
1155 PaintString (w
->w_fd
, VT_STREND
, lp
->l_buf
);
1160 if ((y
= EB_LOC (w
)) != w
->w_ebloc
)
1161 MoveElevator (w
->w_eb
, w
->w_ebloc
= y
);
1162 if ((y
= EB_SIZE (w
)) != w
->w_ebsize
)
1163 SizeElevator (w
->w_eb
, w
->w_ebsize
= y
);
1165 RefreshElevatorBar (w
->w_eb
);
1177 if (w
->w_head
== NULL
)
1180 if ((i
= w
->w_tail
->l_no
- w
->w_head
->l_no
) <= 0)
1183 return (((w
->w_bottom
->l_no
- w
->w_top
->l_no
) * EB_MAX
) / i
);
1192 if (w
->w_head
== NULL
)
1195 if ((i
= w
->w_tail
->l_no
- w
->w_head
->l_no
) <= 0)
1198 return (((w
->w_top
->l_no
- w
->w_head
->l_no
) * EB_MAX
) / i
);
1207 if (ioctl (fileno (stdin
), TIOCGETP
, (char *) &tio
) == NOTOK
)
1208 adios ("failed", "ioctl TIOCGETP");
1209 if (ioctl (fileno (stdin
), TIOCGETC
, (char *) &tc
) == NOTOK
)
1210 adios ("failed", "ioctl TIOCGETC");
1211 if (ioctl (fileno (stdin
), TIOCGLTC
, (char *) <c
) == NOTOK
)
1212 adios ("failed", "ioctl TIOCGLTC");
1215 SIGNAL (SIGHUP
, SIGser
);
1216 SIGNAL (SIGINT
, SIGser
);
1217 SIGNAL (SIGQUIT
, SIGser
);
1226 SIGNAL_HANDLER tstat
;
1228 if ((pgrp
= getpgrp (0)) == NOTOK
)
1229 adios ("process group", "unable to determine");
1231 if (ioctl (fileno (stdin
), TIOCGPGRP
, (char *) &tpgrp
) == NOTOK
)
1232 adios ("tty's process group", "unable to determine");
1236 tstat
= SIGNAL (SIGTTIN
, SIG_DFL
);
1238 SIGNAL (SIGTTIN
, tstat
);
1241 SIGNAL (SIGTTIN
, SIG_IGN
);
1242 SIGNAL (SIGTTOU
, SIG_IGN
);
1243 SIGNAL (SIGTSTP
, SIG_IGN
);
1252 SIGNAL (SIGTTIN
, SIG_DFL
);
1253 SIGNAL (SIGTTOU
, SIG_DFL
);
1254 SIGNAL (SIGTSTP
, SIG_DFL
);
1262 longjmp (PEERctx
, DONE
);
1269 #ifndef RELIABLE_SIGNALS
1270 SIGNAL (sig
, SIG_IGN
);
1273 adios (NULL
, "lost peer");
1280 #ifndef RELIABLE_SIGNALS
1281 SIGNAL (sig
, SIG_IGN
);
1297 return 1; /* dead code to satisfy the compiler */
1302 adorn (char *what
, char *fmt
, ...)
1311 advertise (what
, NULL
, fmt
, ap
);
1319 advertise (char *what
, char *tail
, va_list ap
)
1322 char buffer
[BUFSIZ
], err
[BUFSIZ
];
1323 struct iovec iob
[20];
1324 register struct iovec
*iov
= iob
;
1330 iov
->iov_len
= strlen (iov
->iov_base
= invo_name
);
1332 iov
->iov_len
= strlen (iov
->iov_base
= ": ");
1336 vsnprintf (buffer
, sizeof(buffer
), fmt
, ap
);
1337 iov
->iov_len
= strlen (iov
->iov_base
= buffer
);
1341 iov
->iov_len
= strlen (iov
->iov_base
= " ");
1343 iov
->iov_len
= strlen (iov
->iov_base
= what
);
1345 iov
->iov_len
= strlen (iov
->iov_base
= ": ");
1348 if (!(iov
->iov_base
= strerror (eindex
))) {
1349 snprintf (err
, sizeof(err
), "unknown error %d", eindex
);
1350 iov
->iov_base
= err
;
1352 iov
->iov_len
= strlen (iov
->iov_base
);
1355 if (tail
&& *tail
) {
1356 iov
->iov_len
= strlen (iov
->iov_base
= ", ");
1358 iov
->iov_len
= strlen (iov
->iov_base
= tail
);
1361 iov
->iov_len
= strlen (iov
->iov_base
= "\n");
1365 DisplayVector (iob
, iov
- iob
);
1367 writev (fileno (stderr
), iob
, iov
- iob
);
1372 DisplayVector (struct iovec
*iov
, int n
)
1376 char buffer
[BUFSIZ
];
1378 for (i
= 0, cp
= NULL
; i
< n
; i
++, iov
++) {
1379 snprintf (buffer
, sizeof(buffer
), "%*.*s", iov
->iov_len
,
1380 iov
->iov_len
, iov
->iov_base
);
1381 cp
= add (buffer
, cp
);
1384 DisplayStatus (dfd
, cp
);