1 #ifndef lint 2 static char sccsid[] = "@(#)start.c 4.4 (Berkeley) 04/02/85"; 3 #endif not lint 4 5 #include "stdio.h" 6 #include "lrnref.h" 7 #include <sys/types.h> 8 #include <sys/dir.h> 9 10 #define BSD4_2 1 11 12 start(lesson) 13 char *lesson; 14 { 15 struct direct dbuf; 16 register struct direct *ep = &dbuf; /* directory entry pointer */ 17 int c, n; 18 char where [100]; 19 20 #if BSD4_2 21 DIR *dp; 22 #define OPENDIR(s) ((dp = opendir(s)) != NULL) 23 #define DIRLOOP(s) for (s = readdir(dp); s != NULL; s = readdir(dp)) 24 #define PATHSIZE 256 25 #define EPSTRLEN ep->d_namlen 26 #define CLOSEDIR closedir(dp) 27 #else 28 int f; 29 #define OPENDIR(s) ((f = open(s, 0)) >= 0) 30 #define DIRLOOP(s) while (read(f, s, sizeof *s) == sizeof *s) 31 #define EPSTRLEN strlen(ep->d_name) 32 #define CLOSEDIR close(f) 33 #endif 34 35 OPENDIR("."); /* clean up play directory */ 36 DIRLOOP(ep) { 37 if (ep->d_ino == 0) 38 continue; 39 n = EPSTRLEN; 40 if (ep->d_name[n-2] == '.' && ep->d_name[n-1] == 'c') 41 continue; 42 c = ep->d_name[0]; 43 if (c>='a' && c<= 'z') 44 unlink(ep->d_name); 45 } 46 CLOSEDIR; 47 if (ask) 48 return; 49 sprintf(where, "%s/%s/L%s", direct, sname, lesson); 50 if (access(where, 04)==0) /* there is a file */ 51 return; 52 perror(where); 53 fprintf(stderr, "Start: no lesson %s\n",lesson); 54 wrapup(1); 55 } 56 57 fcopy(new,old) 58 char *new, *old; 59 { 60 char b[BUFSIZ]; 61 int n, fn, fo; 62 fn = creat(new, 0666); 63 fo = open(old,0); 64 if (fo<0) return; 65 if (fn<0) return; 66 while ( (n=read(fo, b, BUFSIZ)) > 0) 67 write(fn, b, n); 68 close(fn); 69 close(fo); 70 } 71