Annotation of 40BSD/cmd/tp/tp1.c, revision 1.1

1.1     ! root        1: #include "tp.h"
        !             2: 
        !             3: main(argc,argv)
        !             4: char **argv;
        !             5: {
        !             6:        register char c,*ptr;
        !             7:        extern cmd(), cmr(),cmx(), cmt();
        !             8: 
        !             9:        tname = tc;
        !            10:        command = cmr;
        !            11:        if ((narg = rnarg = argc) < 2)  narg = 2;
        !            12:        else {
        !            13:                ptr = argv[1];  /* get first argument */
        !            14:                parg = &argv[2];        /* pointer to second argument */
        !            15:                while (c = *ptr++) switch(c)  {
        !            16:                        case '0':
        !            17:                        case '1':
        !            18:                        case '2':
        !            19:                        case '3':
        !            20:                        case '4':
        !            21:                        case '5':
        !            22:                        case '6':
        !            23:                        case '7':
        !            24:                                tc[8] = c;
        !            25:                                mt[8] = c;
        !            26:                                continue;
        !            27: 
        !            28:                        case 'f':
        !            29:                                tname = *parg++;
        !            30:                                flags |= flm;
        !            31:                                narg--; rnarg--;
        !            32:                                continue;
        !            33:                        case 'c':
        !            34:                                flags |= flc;  continue;
        !            35:                        case 'd':
        !            36:                                setcom(cmd);  continue;
        !            37:                        case 'i':
        !            38:                                flags |= fli;  continue;
        !            39:                        case 'm':
        !            40:                                tname = mt;
        !            41:                                flags |= flm;
        !            42:                                continue;
        !            43:                        case 'r':
        !            44:                                flags &= ~flu;  setcom(cmr);  continue;
        !            45:                        case 's':
        !            46:                                flags |= fls; continue;
        !            47:                        case 't':
        !            48:                                setcom(cmt);  continue;
        !            49:                        case 'u':
        !            50:                                flags |= flu;  setcom(cmr);  continue;
        !            51:                        case 'v':
        !            52:                                flags |= flv;  continue;
        !            53:                        case 'w':
        !            54:                                flags |= flw;  continue;
        !            55:                        case 'x':
        !            56:                                setcom(cmx);  continue;
        !            57:                        default:
        !            58:                                useerr();
        !            59:                }
        !            60:        }
        !            61:        optap();
        !            62:        top = nptr = nameblk = sbrk(0);
        !            63:        (*command)();
        !            64: }
        !            65: 
        !            66: optap()
        !            67: {
        !            68:        extern cmr();
        !            69: 
        !            70:        if ((flags & flm) == 0) {       /*  DECTAPE */
        !            71:                tapsiz = TCSIZ;
        !            72:                ndirent = TCDIRS;
        !            73:                fio =open(tc,2);
        !            74:        } else {                        /* MAGTAPE */
        !            75:                tapsiz = MTSIZ;
        !            76:                ndirent = MDIRENT;
        !            77:                if(command == cmr) {
        !            78:                        fio = open(tname,1);
        !            79:                        if (fio < 0) fio = creat(tname,0666);
        !            80:                } else
        !            81:                        fio = open(tname,0);
        !            82:        }
        !            83:        if (fio < 0)  {
        !            84:                printf("Tape open error\n");
        !            85:                done();
        !            86:        }
        !            87:        ndentb = ndirent/TPB;
        !            88:        edir = &dir[ndirent];
        !            89: }
        !            90: 
        !            91: setcom(newcom)
        !            92: int (*newcom)();
        !            93: {
        !            94:        extern cmr();
        !            95: 
        !            96:        if (command != cmr)     useerr();
        !            97:        command = newcom;
        !            98: }
        !            99: 
        !           100: useerr()
        !           101: {
        !           102:        printf("Bad usage\n");
        !           103:        done();
        !           104: }
        !           105: 
        !           106: /*/* COMMANDS */
        !           107: 
        !           108: cmd()
        !           109: {
        !           110:        extern delete();
        !           111: 
        !           112:        if (flags & (flm|flc))  useerr();
        !           113:        if (narg <= 2)                  useerr();
        !           114:        rddir();
        !           115:        gettape(delete);
        !           116:        wrdir();
        !           117:        check();
        !           118: }
        !           119: 
        !           120: cmr()
        !           121: {
        !           122:        if (flags & (flc|flm))          clrdir();
        !           123:        else                            rddir();
        !           124:        getfiles();
        !           125:        update();
        !           126:        check();
        !           127: }
        !           128: 
        !           129: cmt()
        !           130: {
        !           131:        extern taboc();
        !           132: 
        !           133:        if (flags & (flc|flw))  useerr();
        !           134:        rddir();
        !           135:        if (flags & flv)
        !           136:                printf("   mode    uid gid tapa    size   date    time name\n");
        !           137:        gettape(taboc);
        !           138:        check();
        !           139: }
        !           140: 
        !           141: cmx()
        !           142: {
        !           143:        extern extract();
        !           144: 
        !           145:        if (flags & (flc))              useerr();
        !           146:        rddir();
        !           147:        gettape(extract);
        !           148:        done();
        !           149: }
        !           150: 
        !           151: check()
        !           152: {
        !           153:        usage();
        !           154:        done();
        !           155: }
        !           156: 
        !           157: done()
        !           158: {
        !           159:        printf("End\n");
        !           160:        exit(0);
        !           161: }
        !           162: 
        !           163: encode(pname,dptr)     /* pname points to the pathname
        !           164:                         * nptr points to next location in nameblk
        !           165:                         * dptr points to the dir entry            */
        !           166: char   *pname;
        !           167: struct dent *dptr;
        !           168: {
        !           169:        register  char *np;
        !           170:        register n;
        !           171: 
        !           172:        dptr->d_namep = np = nptr;
        !           173:        if (np > top - NAMELEN)  {
        !           174:                if(sbrk(BRKINCR) == (char *)-1) {
        !           175:                        printf("Out of core\n");
        !           176:                        done();
        !           177:                } else
        !           178:                        top += BRKINCR;
        !           179:        }
        !           180:        if((n=strlen(pname)) > NAMELEN) {
        !           181:                printf("Pathname too long - %s\nFile ignored\n",pname);
        !           182:                clrent(dptr);
        !           183:        }
        !           184:        else {
        !           185:                nptr += n+1;
        !           186:                strcpy(np, pname);
        !           187:        }
        !           188: }
        !           189: 
        !           190: decode(pname,dptr)     /* dptr points to the dir entry
        !           191:                         * name is placed in pname[] */
        !           192: char   *pname;
        !           193: struct dent *dptr;
        !           194: {
        !           195: 
        !           196:        strcpy(pname, dptr->d_namep);
        !           197: }

unix.superglobalmegacorp.com

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