Commit | Line | Data |
---|---|---|
48330703 | 1 | #ifndef lint |
e804469b | 2 | static char sccsid[] = "@(#)start.c 4.1 (Berkeley) 2/24/83"; |
48330703 KM |
3 | #endif not lint |
4 | ||
5 | #include "stdio.h" | |
6 | #include <sys/types.h> | |
7 | #include <sys/dir.h> | |
8 | #include "lrnref.h" | |
9 | #define ND 64 | |
10 | ||
11 | start(lesson) | |
12 | char *lesson; | |
13 | { | |
14 | struct direct dv[ND], *dm, *dp; | |
15 | int f, c, n; | |
16 | char where [100]; | |
17 | ||
18 | f = open(".", 0); | |
19 | n = read(f, dv, ND*sizeof(*dp)); | |
20 | n /= sizeof(*dp); | |
21 | if (n==ND) | |
22 | fprintf(stderr, "lesson too long\n"); | |
23 | dm = dv+n; | |
24 | for(dp=dv; dp<dm; dp++) | |
25 | if (dp->d_ino) { | |
26 | n = strlen(dp->d_name); | |
27 | if (dp->d_name[n-2] == '.' && dp->d_name[n-1] == 'c') | |
28 | continue; | |
29 | c = dp->d_name[0]; | |
30 | if (c>='a' && c<= 'z') | |
31 | unlink(dp->d_name); | |
32 | } | |
33 | close(f); | |
34 | if (ask) | |
35 | return; | |
36 | sprintf(where, "../../%s/L%s", sname, lesson); | |
37 | if (access(where, 04)==0) /* there is a file */ | |
38 | return; | |
39 | fprintf(stderr, "No lesson %s\n",lesson); | |
40 | wrapup(1); | |
41 | } | |
42 | ||
43 | fcopy(new,old) | |
44 | char *new, *old; | |
45 | { | |
46 | char b[BUFSIZ]; | |
47 | int n, fn, fo; | |
48 | fn = creat(new, 0666); | |
49 | fo = open(old,0); | |
50 | if (fo<0) return; | |
51 | if (fn<0) return; | |
52 | while ( (n=read(fo, b, BUFSIZ)) > 0) | |
53 | write(fn, b, n); | |
54 | close(fn); | |
55 | close(fo); | |
56 | } |