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

1.1     ! root        1: #ifndef lint
        !             2: static char sccsid[] = "@(#)start.c    4.2     (Berkeley)      4/25/83";
        !             3: #endif not lint
        !             4: 
        !             5: #include "stdio.h"
        !             6: #include "lrnref.h"
        !             7: #include <sys/types.h>
        !             8: #include <sys/dir.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);               /* clean up play directory */
        !            19:        n = read(f, dv, ND*sizeof(*dp));
        !            20:        n /= sizeof(*dp);
        !            21:        if (n==ND)
        !            22:                fprintf(stderr, "Start:  play directory 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/%s/L%s", direct, sname, lesson);
        !            37:        if (access(where, 04)==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: }

unix.superglobalmegacorp.com

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