|
|
1.1 root 1: #ifndef lint
2: static char sccsid[] = "@(#)selsub.c 4.2 (Berkeley) 4/25/83";
3: #endif not lint
4:
5: #include "stdio.h"
6: #include "sys/types.h"
7: #include "sys/stat.h"
8: #include "lrnref.h"
9:
10: selsub(argc,argv)
11: char *argv[];
12: {
13: char ans1[100];
14: static char ans2[30];
15: static char dirname[20];
16: static char subname[20];
17: struct stat statbuf;
18:
19: if (argc > 1 && argv[1][0] == '-') {
20: direct = argv[1]+1;
21: argc--;
22: argv++;
23: }
24: if (chdir(direct) != 0) {
25: perror(direct);
26: fprintf(stderr, "Selsub: couldn't cd to non-standard directory\n");
27: exit(1);
28: }
29: sname = argc > 1 ? argv[1] : 0;
30: if (argc > 2) {
31: strcpy (level=ans2, argv[2]);
32: if (strcmp(level, "-") == 0) /* no lesson name is - */
33: ask = 1;
34: else
35: again = 1; /* treat as if "again lesson" */
36: }
37: else
38: level = 0;
39: if (argc > 3 )
40: speed = atoi(argv[3]);
41: if (!sname) {
42: printf("These are the available courses -\n");
43: list("Linfo");
44: printf("If you want more information about the courses,\n");
45: printf("or if you have never used 'learn' before,\n");
46: printf("press RETURN; otherwise type the name of\n");
47: printf("the course you want, followed by RETURN.\n");
48: fflush(stdout);
49: gets(sname=subname);
50: if (sname[0] == '\0') {
51: list("Xinfo");
52: do {
1.1.1.2 ! root 53: rewind(stdin);
1.1 root 54: printf("\nWhich subject? ");
55: fflush(stdout);
56: gets(sname=subname);
57: } while (sname[0] == '\0');
58: }
59: }
60: chknam(sname);
61: stat(sname, &statbuf);
62: total = statbuf.st_size / 16 - 2; /* size/dirsize-(.+..) */
63: if (!level) {
64: printf("If you were in the middle of this subject\n");
65: printf("and want to start where you left off, type\n");
66: printf("the last lesson number the computer printed.\n");
67: printf("If you don't know the number, type in a word\n");
68: printf("you think might appear in the lesson you want,\n");
69: printf("and I will look for the first lesson containing it.\n");
70: printf("To start at the beginning, just hit RETURN.\n");
71: fflush(stdout);
72: gets(ans2);
73: if (ans2[0]==0)
74: strcpy(ans2,"0");
75: level=ans2;
76: }
77:
78: /* make new directory for user to play in */
79: if (chdir("/tmp") != 0) {
80: perror("/tmp");
81: fprintf(stderr, "Selsub: couldn't cd to public directory\n");
82: exit(1);
83: }
84: sprintf(dir=dirname, "pl%da", getpid());
85: sprintf(ans1, "mkdir %s", dir);
86: system(ans1);
87: if (chdir(dir) < 0) {
88: perror(dir);
89: fprintf(stderr, "Selsub: couldn't make play directory with %s.\nBye.\n", ans1);
90: exit(1);
91: }
92: /* after this point, we have a working directory. */
93: /* have to call wrapup to clean up */
94: if (access(sprintf(ans1, "%s/%s/Init", direct, sname), 04)==0)
95: if (system(sprintf(ans1, "%s/%s/Init %s", direct, sname, level)) != 0) {
96: printf("Leaving learn.\n");
97: wrapup(1);
98: }
99: }
100:
101: chknam(name)
102: char *name;
103: {
104: if (access(name, 05) < 0) {
105: printf("Sorry, there is no subject or lesson named %s.\nBye.\n", name);
106: exit(1);
107: }
108: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.