BSD 4_3_Tahoe release
[unix-history] / usr / src / usr.bin / learn / selsub.c
index 91f39bb..6a7d3c4 100644 (file)
@@ -1,9 +1,10 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)selsub.c   4.3     (Berkeley)      5/15/86";
+static char sccsid[] = "@(#)selsub.c   4.5     (Berkeley)      10/22/87";
 #endif not lint
 
 #include "stdio.h"
 #include "sys/types.h"
 #endif not lint
 
 #include "stdio.h"
 #include "sys/types.h"
+#include "sys/file.h"
 #include "sys/stat.h"
 #include "lrnref.h"
 
 #include "sys/stat.h"
 #include "lrnref.h"
 
@@ -73,13 +74,15 @@ char *argv[];
                printf("press RETURN; otherwise type the name of\n");
                printf("the course you want, followed by RETURN.\n");
                fflush(stdout);
                printf("press RETURN; otherwise type the name of\n");
                printf("the course you want, followed by RETURN.\n");
                fflush(stdout);
-               gets(sname=subname);
+               if (gets(sname=subname) == NULL)
+                       exit(0);
                if (sname[0] == '\0') {
                        list("Xinfo");
                        do {
                                printf("\nWhich subject?  ");
                                fflush(stdout);
                if (sname[0] == '\0') {
                        list("Xinfo");
                        do {
                                printf("\nWhich subject?  ");
                                fflush(stdout);
-                               gets(sname=subname);
+                               if (gets(sname=subname) == NULL)
+                                       exit(0);
                        } while (sname[0] == '\0');
                }
        }
                        } while (sname[0] == '\0');
                }
        }
@@ -94,7 +97,8 @@ char *argv[];
                printf("and I will look for the first lesson containing it.\n");
                printf("To start at the beginning, just hit RETURN.\n");
                fflush(stdout);
                printf("and I will look for the first lesson containing it.\n");
                printf("To start at the beginning, just hit RETURN.\n");
                fflush(stdout);
-               gets(ans2);
+               if (gets(ans2) == NULL)
+                       exit(0);
                if (ans2[0]==0)
                        strcpy(ans2,"0");
                else
                if (ans2[0]==0)
                        strcpy(ans2,"0");
                else
@@ -119,11 +123,14 @@ char *argv[];
        }
        /* after this point, we have a working directory. */
        /* have to call wrapup to clean up */
        }
        /* after this point, we have a working directory. */
        /* have to call wrapup to clean up */
-       if (access(sprintf(ans1, "%s/%s/Init", direct, sname), 04)==0)
-               if (system(sprintf(ans1, "%s/%s/Init %s", direct, sname, level)) != 0) {
+       (void)sprintf(ans1, "%s/%s/Init", direct, sname);
+       if (access(ans1, R_OK)==0) {
+               (void)sprintf(ans1, "%s/%s/Init %s", direct, sname, level);
+               if (system(ans1) != 0) {
                        printf("Leaving learn.\n");
                        wrapup(1);
                }
                        printf("Leaving learn.\n");
                        wrapup(1);
                }
+       }
 }
 
 chknam(name)
 }
 
 chknam(name)