1 #ifndef lint 2 static char sccsid[] = "@(#)start.c 4.7 (Berkeley) 06/24/90"; 3 #endif not lint 4 5 #include "stdio.h" 6 #include "lrnref.h" 7 #include <sys/types.h> 8 #include <dirent.h> 9 #include <unistd.h> 10 11 start(lesson) 12 char *lesson; 13 { 14 register struct dirent *ep; 15 int c, n; 16 char where [100]; 17 DIR *dp; 18 19 if ((dp = opendir(".")) == NULL) { /* clean up play directory */ 20 perror("Start: play directory"); 21 wrapup(1); 22 } 23 while ((ep = readdir(dp)) != NULL) { 24 if (ep->d_ino == 0) 25 continue; 26 n = ep->d_namlen; 27 if (n >= 2 && ep->d_name[n-2] == '.' && ep->d_name[n-1] == 'c') 28 continue; 29 c = ep->d_name[0]; 30 if (c>='a' && c<= 'z') 31 unlink(ep->d_name); 32 } 33 (void) closedir(dp); 34 if (ask) 35 return; 36 sprintf(where, "%s/%s/L%s", direct, sname, lesson); 37 if (access(where, R_OK)==0) /* there is a file */ 38 return; 39 perror(where); 40 fprintf(stderr, "Start: no lesson %s\n",lesson); 41 wrapup(1); 42 } 43 44 fcopy(new,old) 45 char *new, *old; 46 { 47 char b[BUFSIZ]; 48 int n, fn, fo; 49 fn = creat(new, 0666); 50 fo = open(old,0); 51 if (fo<0) return; 52 if (fn<0) return; 53 while ( (n=read(fo, b, BUFSIZ)) > 0) 54 write(fn, b, n); 55 close(fn); 56 close(fo); 57 } 58