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
; {
46 if ((av
= readoptions(argv
)) == (char **) 0 ||
47 initialize(*av
? 1 : 0)) {
55 " [-c] [-u] [-n] [-q] [-number] [+command] [file ... ]\n");
61 execve("/bin/cat", av
, (char *) 0);
63 else processfiles(argc
-(av
-argv
), av
);
71 * Open temporary file for reading and writing.
75 static char indexfile
[30], tempfile
[30];
83 f
= i
? mktemp(indexfile
) : mktemp(tempfile
);
84 # if BSD4_2_OPEN || USG_OPEN || POSIX_OPEN
85 if ((fildes
= open(f
,O_RDWR
|O_TRUNC
|O_CREAT
,0600)) < 0) {
87 if ((fildes
= creat(f
,0600)) <= 0 || close(fildes
) < 0 ||
88 (fildes
= open(f
,2)) < 0) {
90 panic("Couldn't open temporary file");
97 * Collect initializing stuff here.
110 stdf
= dup(0); /* Duplicate file descriptor of input */
111 if (no_tty
) return 0;
113 * Make sure standard input is from the terminal.
116 # if BSD4_2_OPEN || USG_OPEN || POSIX_OPEN
117 if (open("/dev/tty",O_RDONLY
,0) != 0) {
119 if (open("/dev/tty",0) != 0) {
121 putline("Couldn't open terminal\n");
126 if (no_tty
) return 0;
127 (VOID
) strcpy(tempfile
,"/usr/tmp/yap_XXXXXX");
128 (VOID
) strcpy(indexfile
,"/usr/tmp/yap-XXXXXX");
131 * Catch QUIT, DELETE and ^Z
133 (VOID
) signal(SIGQUIT
,SIG_IGN
);
134 (VOID
) signal(SIGINT
, catchdel
);
137 if (signal(SIGTSTP
,SIG_IGN
) == SIG_DFL
) {
138 (VOID
) signal(SIGTSTP
,suspsig
);
141 (VOID
) signal(SIGQUIT
,quit
);
147 (VOID
) signal(SIGINT
, catchdel
);
154 * We had a SIGTSTP signal.
155 * Suspend, by a call to this routine.
163 (VOID
) signal(SIGTSTP
,SIG_DFL
);
165 sigsetmask(sigblock(0)&~(1 << (SIGTSTP
- 1)));
167 (VOID
) kill(0, SIGTSTP
);
169 * We are not here anymore ...
173 * But we arive here ...
178 (VOID
) signal(SIGTSTP
,suspsig
);
182 * SIGTSTP signal handler.
183 * Just indicate that we had one, ignore further ones and return.
190 if (DoneSetJmp
) longjmp(SetJmpBuf
, 1);
195 * quit : called on exit.
196 * I bet you guessed that much.
209 * Exit, but nonvoluntarily.
210 * At least tell the user why.
216 putline("\007\007\007\r\n");