1 /* Copyright (c) 1985 Ceriel J.H. Jacobs */
4 static char rcsid
[] = "$Header$";
14 # include <sys/file.h>
17 # include <sys/types.h>
25 # include "commands.h"
31 STATIC
int initialize();
37 main(argc
,argv
) register char ** argv
; {
40 char *empty_envp
[] = { (char *) 0 };
47 if ((av
= readoptions(argv
)) == (char **) 0 ||
48 initialize(*av
? 1 : 0)) {
56 " [-c] [-u] [-n] [-q] [-number] [+command] [file ... ]\n");
62 execve("/bin/cat", av
, &empty_envp
);
64 else processfiles(argc
-(av
-argv
), av
);
72 * Open temporary file for reading and writing.
76 static char indexfile
[30], tempfile
[30];
84 f
= i
? mktemp(indexfile
) : mktemp(tempfile
);
85 # if BSD4_2_OPEN || USG_OPEN || POSIX_OPEN
86 if ((fildes
= open(f
,O_RDWR
|O_TRUNC
|O_CREAT
,0600)) < 0) {
88 if ((fildes
= creat(f
,0600)) <= 0 || close(fildes
) < 0 ||
89 (fildes
= open(f
,2)) < 0) {
91 panic("Couldn't open temporary file");
98 * Collect initializing stuff here.
111 stdf
= dup(0); /* Duplicate file descriptor of input */
112 if (no_tty
) return 0;
114 * Make sure standard input is from the terminal.
117 # if BSD4_2_OPEN || USG_OPEN || POSIX_OPEN
118 if (open("/dev/tty",O_RDONLY
,0) != 0) {
120 if (open("/dev/tty",0) != 0) {
122 putline("Couldn't open terminal\n");
127 if (no_tty
) return 0;
128 (VOID
) strcpy(tempfile
,"/usr/tmp/yap_XXXXXX");
129 (VOID
) strcpy(indexfile
,"/usr/tmp/yap-XXXXXX");
132 * Catch QUIT, DELETE and ^Z
134 (VOID
) signal(SIGQUIT
,SIG_IGN
);
135 (VOID
) signal(SIGINT
, catchdel
);
138 if (signal(SIGTSTP
,SIG_IGN
) == SIG_DFL
) {
139 (VOID
) signal(SIGTSTP
,suspsig
);
142 (VOID
) signal(SIGQUIT
,quit
);
148 (VOID
) signal(SIGINT
, catchdel
);
155 * We had a SIGTSTP signal.
156 * Suspend, by a call to this routine.
164 (VOID
) signal(SIGTSTP
,SIG_DFL
);
166 sigsetmask(sigblock(0)&~(1 << (SIGTSTP
- 1)));
168 (VOID
) kill(0, SIGTSTP
);
170 * We are not here anymore ...
174 * But we arive here ...
179 (VOID
) signal(SIGTSTP
,suspsig
);
183 * SIGTSTP signal handler.
184 * Just indicate that we had one, ignore further ones and return.
191 if (DoneSetJmp
) longjmp(SetJmpBuf
, 1);
196 * quit : called on exit.
197 * I bet you guessed that much.
210 * Exit, but nonvoluntarily.
211 * At least tell the user why.
217 putline("\007\007\007\r\n");