BSD 4_2 release
[unix-history] / usr / src / usr.bin / learn / dounit.c
index bec7ef0..3434d3e 100644 (file)
@@ -1,10 +1,13 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)dounit.c   4.1     (Berkeley)      2/24/83";
+static char sccsid[] = "@(#)dounit.c   4.2     (Berkeley)      4/25/83";
 #endif not lint
 
 #include "stdio.h"
 #include "lrnref.h"
 
 #endif not lint
 
 #include "stdio.h"
 #include "lrnref.h"
 
+int    remind = 2;             /* to remind user of "again" and "bye" */
+extern int     noclobber;
+
 dounit()
 {
        char tbuff[100];
 dounit()
 {
        char tbuff[100];
@@ -13,21 +16,27 @@ dounit()
                return;
        wrong = 0;
 retry:
                return;
        wrong = 0;
 retry:
-       start(todo);
-       sprintf(tbuff, "../../%s/L%s", sname, todo);    /* script = lesson */
+       if (!noclobber)
+               start(todo);            /* clean up play directory */
+       sprintf(tbuff, "%s/%s/L%s", direct, sname, todo); /* script = lesson */
        scrin = fopen(tbuff, "r");
        if (scrin == NULL) {
        scrin = fopen(tbuff, "r");
        if (scrin == NULL) {
-               fprintf(stderr, "No script.\n");
+               perror(tbuff);
+               fprintf(stderr, "Dounit:  no lesson %s.\n", tbuff);
                wrapup(1);
        }
 
                wrapup(1);
        }
 
-       copy(0, scrin);
+       copy(0, scrin);                 /* print lesson, usually */
        if (more == 0)
                return;
        if (more == 0)
                return;
-       copy(1, stdin);
+       copy(1, stdin);                 /* user takes over */
+       if (skip)
+               setdid(todo, sequence++);
+       if (again || skip)              /* if "again" or "skip" */
+               return;
        if (more == 0)
                return;
        if (more == 0)
                return;
-       copy(0, scrin);
+       copy(0, scrin);                 /* evaluate user's response */
 
        if (comfile >= 0)
                close(comfile);
 
        if (comfile >= 0)
                close(comfile);
@@ -42,13 +51,16 @@ retry:
                        gets(tbuff);
                        if (tbuff[0] == 'y') {
                                printf("Try the problem again.\n");
                        gets(tbuff);
                        if (tbuff[0] == 'y') {
                                printf("Try the problem again.\n");
-                               fflush(stdout);
+                               if (remind--) {
+                                       printf("[ Whenever you want to re-read the lesson, type \"again\".\n");
+                                       printf("  You can always leave learn by typing \"bye\". ]\n");
+                               }
                                goto retry;
                        } else if (strcmp(tbuff, "bye") == 0) {
                                goto retry;
                        } else if (strcmp(tbuff, "bye") == 0) {
-                               wrapup(1);
+                               wrapup(0);
                        } else if (tbuff[0] == 'n') {
                                wrong = 0;
                        } else if (tbuff[0] == 'n') {
                                wrong = 0;
-                               printf("\nOK.  Lesson %s (%d)\n", todo, speed);
+                               printf("\nOK.  That was lesson %s.\n", todo);
                                printf("Skipping to next lesson.\n\n");
                                fflush(stdout);
                                break;
                                printf("Skipping to next lesson.\n\n");
                                fflush(stdout);
                                break;