Annotation of researchv10no/cmd/learn/selsub.c, revision 1.1

1.1     ! root        1: #include "stdio.h"
        !             2: #include "lrnref"
        !             3: 
        !             4: selsub(argc,argv)
        !             5: char *argv[];
        !             6: {
        !             7:        char ans1[100], *cp;
        !             8:        static char ans2[30];
        !             9:        static char dirname[20];
        !            10:        static char subname[20];
        !            11: 
        !            12:        if (argc > 1 && argv[1][0] == '-') {
        !            13:                direct = argv[1]+1;
        !            14:                argc--;
        !            15:                argv++;
        !            16:        }
        !            17:        chknam(direct);
        !            18:        if (chdir(direct) != 0) {
        !            19:                fprintf(stderr, "can't cd to %s\,", direct);
        !            20:                exit(1);
        !            21:        }
        !            22:        sname = argc > 1 ? argv[1] : 0;
        !            23:        if (argc > 2)
        !            24:                strcpy (level=ans2, argv[2]);
        !            25:        else
        !            26:                level = 0;
        !            27:        if (argc > 3 )
        !            28:                speed = atoi(argv[3]);
        !            29:        if (!sname) {
        !            30:                printf("These are the available courses -\n");
        !            31:                list("Linfo");
        !            32:                printf("If you want more information about the courses,\n");
        !            33:                printf("or if you have never used 'learn' before,\n");
        !            34:                printf("type 'return'; otherwise type the name of\n");
        !            35:                printf("the course you want, followed by 'return'.\n");
        !            36:                fflush(stdout);
        !            37:                fgets((sname=subname), 20, stdin);
        !            38:                if (sname[0] == '\0') {
        !            39:                        list("Xinfo");
        !            40:                        do {
        !            41:                                printf("\nWhich subject?  ");
        !            42:                                fflush(stdout);
        !            43:                                fgets((sname=subname), 20, stdin);
        !            44:                        } while (sname[0] == '\0');
        !            45:                }
        !            46:        }
        !            47:        chknam(sname);
        !            48:        if (!level) {
        !            49:                printf("If you were in the middle of this subject\n");
        !            50:                printf("and want to start where you left off, type\n");
        !            51:                printf("the last lesson number the computer printed.\n");
        !            52:                printf("To start at the beginning, just hit return.\n");
        !            53:                fflush(stdout);
        !            54:                fgets(ans2, 30, stdin);
        !            55:                if (ans2[0]==0)
        !            56:                        strcpy(ans2,"0");
        !            57:                for (cp=ans2; *cp; cp++)
        !            58:                        if (*cp == '(' || *cp == ' ')
        !            59:                                *cp= 0;
        !            60:                level=ans2;
        !            61:        }
        !            62: 
        !            63:        /* make new directory for user to play in */
        !            64:        if (chdir("play") != 0) {
        !            65:                fprintf(stderr, "can't cd to playpen\n");
        !            66:                exit(1);
        !            67:        }
        !            68:        sprintf(dir=dirname, "pl%da", getpid());
        !            69:        sprintf(ans1, "mkdir %s", dir);
        !            70:        system(ans1);
        !            71:        if (chdir(dir) < 0) {
        !            72:                fprintf(stderr, "Couldn't create working directory.\nBye.\n");
        !            73:                exit(1);
        !            74:        }
        !            75:        /* after this point, we have a working directory. */
        !            76:        /* have to call wrapup to clean up */
        !            77:        if (access(sprintf(ans1, "%s/%s/Init", direct, sname), 04)==0)
        !            78:                if (system(sprintf(ans1, "%s/%s/Init %s", direct,sname, level)) != 0) {
        !            79:                        printf("Leaving learn.\n");
        !            80:                        wrapup(1);
        !            81:                }
        !            82:        if (level[0] == '-')    /* no lesson names start with - */
        !            83:                ask = 1;
        !            84:        start(level);
        !            85: }
        !            86: 
        !            87: chknam(name)
        !            88: char *name;
        !            89: {
        !            90:        if (access(name, 05) < 0) {
        !            91:                printf("Sorry, there is no subject or lesson named %s.\nBye.\n", name);
        !            92:                exit(1);
        !            93:        }
        !            94: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.