Annotation of 42BSD/usr.bin/learn/dounit.c, revision 1.1

1.1     ! root        1: #ifndef lint
        !             2: static char sccsid[] = "@(#)dounit.c   4.2     (Berkeley)      4/25/83";
        !             3: #endif not lint
        !             4: 
        !             5: #include "stdio.h"
        !             6: #include "lrnref.h"
        !             7: 
        !             8: int    remind = 2;             /* to remind user of "again" and "bye" */
        !             9: extern int     noclobber;
        !            10: 
        !            11: dounit()
        !            12: {
        !            13:        char tbuff[100];
        !            14: 
        !            15:        if (todo == 0)
        !            16:                return;
        !            17:        wrong = 0;
        !            18: retry:
        !            19:        if (!noclobber)
        !            20:                start(todo);            /* clean up play directory */
        !            21:        sprintf(tbuff, "%s/%s/L%s", direct, sname, todo); /* script = lesson */
        !            22:        scrin = fopen(tbuff, "r");
        !            23:        if (scrin == NULL) {
        !            24:                perror(tbuff);
        !            25:                fprintf(stderr, "Dounit:  no lesson %s.\n", tbuff);
        !            26:                wrapup(1);
        !            27:        }
        !            28: 
        !            29:        copy(0, scrin);                 /* print lesson, usually */
        !            30:        if (more == 0)
        !            31:                return;
        !            32:        copy(1, stdin);                 /* user takes over */
        !            33:        if (skip)
        !            34:                setdid(todo, sequence++);
        !            35:        if (again || skip)              /* if "again" or "skip" */
        !            36:                return;
        !            37:        if (more == 0)
        !            38:                return;
        !            39:        copy(0, scrin);                 /* evaluate user's response */
        !            40: 
        !            41:        if (comfile >= 0)
        !            42:                close(comfile);
        !            43:        wait(&didok);
        !            44:        didok = (status == 0);
        !            45:        if (!didok) {
        !            46:                wrong++;
        !            47:                printf("\nSorry, that's %snot right.  Do you want to try again?  ",
        !            48:                        wrong > 1 ? "still " : "");
        !            49:                fflush(stdout);
        !            50:                for(;;) {
        !            51:                        gets(tbuff);
        !            52:                        if (tbuff[0] == 'y') {
        !            53:                                printf("Try the problem again.\n");
        !            54:                                if (remind--) {
        !            55:                                        printf("[ Whenever you want to re-read the lesson, type \"again\".\n");
        !            56:                                        printf("  You can always leave learn by typing \"bye\". ]\n");
        !            57:                                }
        !            58:                                goto retry;
        !            59:                        } else if (strcmp(tbuff, "bye") == 0) {
        !            60:                                wrapup(0);
        !            61:                        } else if (tbuff[0] == 'n') {
        !            62:                                wrong = 0;
        !            63:                                printf("\nOK.  That was lesson %s.\n", todo);
        !            64:                                printf("Skipping to next lesson.\n\n");
        !            65:                                fflush(stdout);
        !            66:                                break;
        !            67:                        } else {
        !            68:                                printf("Please type yes, no or bye:  ");
        !            69:                                fflush(stdout);
        !            70:                        }
        !            71:                }
        !            72:        }
        !            73:        setdid(todo, sequence++);
        !            74: }
        !            75: 

unix.superglobalmegacorp.com

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