xref: /original-bsd/usr.bin/learn/learn/learn.c (revision 3fe78f58)
1 #ifndef lint
2 static char sccsid[] = "@(#)learn.c	4.6	(Berkeley)	03/01/91";
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 extern void hangup(), intrpt();
33 
34 main(argc,argv)
35 int argc;
36 char *argv[];
37 {
38 	extern char * getlogin(), *malloc();
39 
40 	speed = 0;
41 	more = 1;
42 	pwline = getlogin();
43 #ifndef BSD4_2
44 	setbuf(stdout, malloc(BUFSIZ));
45 	setbuf(stderr, malloc(BUFSIZ));
46 #endif
47 	selsub(argc, argv);
48 	chgenv();
49 	signal(SIGHUP, hangup);
50 	signal(SIGINT, intrpt);
51 	while (more) {
52 		selunit();
53 		dounit();
54 		whatnow();
55 	}
56 	wrapup(0);
57 }
58 
59 void
60 hangup()
61 {
62 	wrapup(1);
63 }
64 
65 void
66 intrpt()
67 {
68 	char response[20], *p;
69 
70 	signal(SIGINT, hangup);
71 	write(2, "\nInterrupt.\nWant to go on?  ", 28);
72 	p = response;
73 	*p = 'n';
74 	while (read(0, p, 1) == 1 && *p != '\n')
75 		p++;
76 	if (response[0] != 'y')
77 		wrapup(0);
78 	ungetc('\n', stdin);
79 	signal(SIGINT, intrpt);
80 }
81