BSD 4_4 release
[unix-history] / usr / src / usr.bin / learn / learn / start.c
index 6e2a402..1add493 100644 (file)
@@ -1,53 +1,49 @@
+/*-
+ * Copyright (c) 1986, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * This module is believed to contain source code proprietary to AT&T.
+ * Use and redistribution is subject to the Berkeley Software License
+ * Agreement and your Software Agreement with AT&T (Western Electric).
+ */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)start.c    4.4     (Berkeley)      %G%";
-#endif not lint
+static char sccsid[] = "@(#)start.c    8.1 (Berkeley) 6/6/93";
+#endif /* not lint */
 
 #include "stdio.h"
 #include "lrnref.h"
 #include <sys/types.h>
 
 #include "stdio.h"
 #include "lrnref.h"
 #include <sys/types.h>
-#include <sys/dir.h>
-
-#define BSD4_2 1
+#include <dirent.h>
+#include <unistd.h>
 
 
-start(lesson)
+lstart(lesson)
 char *lesson;
 {
 char *lesson;
 {
-       struct direct dbuf;
-       register struct direct *ep = &dbuf;     /* directory entry pointer */
+       register struct dirent *ep;
        int c, n;
        char where [100];
        int c, n;
        char where [100];
-
-#if BSD4_2
        DIR *dp;
        DIR *dp;
-#define OPENDIR(s)     ((dp = opendir(s)) != NULL)
-#define DIRLOOP(s)     for (s = readdir(dp); s != NULL; s = readdir(dp))
-#define PATHSIZE 256
-#define EPSTRLEN       ep->d_namlen
-#define CLOSEDIR       closedir(dp)
-#else
-       int f;
-#define OPENDIR(s)     ((f = open(s, 0)) >= 0)
-#define DIRLOOP(s)     while (read(f, s, sizeof *s) == sizeof *s)
-#define EPSTRLEN       strlen(ep->d_name)
-#define CLOSEDIR       close(f)
-#endif
 
 
-       OPENDIR(".");                           /* clean up play directory */
-       DIRLOOP(ep) {
+       if ((dp = opendir(".")) == NULL) {      /* clean up play directory */
+               perror("Start:  play directory");
+               wrapup(1);
+       }
+       while ((ep = readdir(dp)) != NULL) {
                if (ep->d_ino == 0)
                        continue;
                if (ep->d_ino == 0)
                        continue;
-               n = EPSTRLEN;
-               if (ep->d_name[n-2] == '.' && ep->d_name[n-1] == 'c')
+               n = ep->d_namlen;
+               if (n >= 2 && ep->d_name[n-2] == '.' && ep->d_name[n-1] == 'c')
                        continue;
                c = ep->d_name[0];
                if (c>='a' && c<= 'z')
                        unlink(ep->d_name);
        }
                        continue;
                c = ep->d_name[0];
                if (c>='a' && c<= 'z')
                        unlink(ep->d_name);
        }
-       CLOSEDIR;
+       (void) closedir(dp);
        if (ask)
                return;
        sprintf(where, "%s/%s/L%s", direct, sname, lesson);
        if (ask)
                return;
        sprintf(where, "%s/%s/L%s", direct, sname, lesson);
-       if (access(where, 04)==0)       /* there is a file */
+       if (access(where, R_OK)==0)     /* there is a file */
                return;
        perror(where);
        fprintf(stderr, "Start:  no lesson %s\n",lesson);
                return;
        perror(where);
        fprintf(stderr, "Start:  no lesson %s\n",lesson);