Annotation of 42BSD/bin/tp/tp1.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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