xref: /original-bsd/usr.bin/learn/learn/learn.c (revision 87febec0)
1 #ifndef lint
2 static char sccsid[] = "@(#)learn.c	4.5	(Berkeley)	05/10/89";
3 #endif not lint
4 
5 #include <sys/signal.h>
6 #include <stdio.h>
7 #include "lrnref.h"
8 #include "pathnames.h"
9 
10 char	*direct	= _PATH_LEARN;
11 int	more;
12 char	*level;
13 int	speed;
14 char	*sname;
15 char	*todo;
16 FILE	*incopy	= NULL;
17 int	didok;
18 int	sequence	= 1;
19 int	comfile	= -1;
20 int	status;
21 int	wrong;
22 char	*pwline;
23 char	*dir;
24 FILE	*scrin;
25 int	logging	= 1;	/* set to 0 to turn off logging */
26 int	ask;
27 int	again;
28 int	skip;
29 int	teed;
30 int	total;
31 
32 main(argc,argv)
33 int argc;
34 char *argv[];
35 {
36 	extern hangup(), intrpt();
37 	extern char * getlogin(), *malloc();
38 
39 	speed = 0;
40 	more = 1;
41 	pwline = getlogin();
42 #ifndef BSD4_2
43 	setbuf(stdout, malloc(BUFSIZ));
44 	setbuf(stderr, malloc(BUFSIZ));
45 #endif
46 	selsub(argc, argv);
47 	chgenv();
48 	signal(SIGHUP, hangup);
49 	signal(SIGINT, intrpt);
50 	while (more) {
51 		selunit();
52 		dounit();
53 		whatnow();
54 	}
55 	wrapup(0);
56 }
57 
58 hangup()
59 {
60 	wrapup(1);
61 }
62 
63 intrpt()
64 {
65 	char response[20], *p;
66 
67 	signal(SIGINT, hangup);
68 	write(2, "\nInterrupt.\nWant to go on?  ", 28);
69 	p = response;
70 	*p = 'n';
71 	while (read(0, p, 1) == 1 && *p != '\n')
72 		p++;
73 	if (response[0] != 'y')
74 		wrapup(0);
75 	ungetc('\n', stdin);
76 	signal(SIGINT, intrpt);
77 }
78