Annotation of 43BSDReno/old/tp/tp1.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char sccsid[] = "@(#)tp1.c      4.2 6/28/84";
                      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:        (*command)();
                     67: }
                     68: 
                     69: optap()
                     70: {
                     71:        extern cmr();
                     72: 
                     73:        if ((flags & flm) == 0) {       /*  DECTAPE */
                     74:                tapsiz = TCSIZ;
                     75:                ndirent = TCDIRS;
                     76:                fio =open(tc,2);
                     77:        } else {                        /* MAGTAPE */
                     78:                tapsiz = MTSIZ;
                     79:                ndirent = MDIRENT;
                     80:                if(command == cmr) {
                     81:                        fio = open(tname,1);
                     82:                        if (fio < 0) fio = creat(tname,0666);
                     83:                } else
                     84:                        fio = open(tname,0);
                     85:        }
                     86:        if (fio < 0)  {
                     87:                printf("Tape open error\n");
                     88:                done();
                     89:        }
                     90:        ndentb = ndirent/TPB;
                     91:        edir = &dir[ndirent];
                     92: }
                     93: 
                     94: setcom(newcom)
                     95: int (*newcom)();
                     96: {
                     97:        extern cmr();
                     98: 
                     99:        if (command != cmr)     useerr();
                    100:        command = newcom;
                    101: }
                    102: 
                    103: useerr()
                    104: {
                    105:        printf("Bad usage\n");
                    106:        done();
                    107: }
                    108: 
                    109: /*/* COMMANDS */
                    110: 
                    111: cmd()
                    112: {
                    113:        extern delete();
                    114: 
                    115:        if (flags & (flm|flc))  useerr();
                    116:        if (narg <= 2)                  useerr();
                    117:        rddir();
                    118:        gettape(delete);
                    119:        wrdir();
                    120:        check();
                    121: }
                    122: 
                    123: cmr()
                    124: {
                    125:        if (flags & (flc|flm))          clrdir();
                    126:        else                            rddir();
                    127:        getfiles();
                    128:        update();
                    129:        check();
                    130: }
                    131: 
                    132: cmt()
                    133: {
                    134:        extern taboc();
                    135: 
                    136:        if (flags & (flc|flw))  useerr();
                    137:        rddir();
                    138:        if (flags & flv)
                    139:                printf("   mode    uid gid tapa    size   date    time name\n");
                    140:        gettape(taboc);
                    141:        check();
                    142: }
                    143: 
                    144: cmx()
                    145: {
                    146:        extern extract();
                    147: 
                    148:        if (flags & (flc))              useerr();
                    149:        rddir();
                    150:        gettape(extract);
                    151:        done();
                    152: }
                    153: 
                    154: check()
                    155: {
                    156:        usage();
                    157:        done();
                    158: }
                    159: 
                    160: done()
                    161: {
                    162:        printf("End\n");
                    163:        exit(0);
                    164: }
                    165: 
                    166: encode(pname,dptr)     /* pname points to the pathname
                    167:                         * dptr points to the dir entry            */
                    168: char   *pname;
                    169: struct dent *dptr;
                    170: {
                    171:        register  char *np;
                    172:        register n;
                    173:        extern char *malloc();
                    174: 
                    175:        if((n=strlen(pname)) > NAMELEN) {
                    176:                printf("Pathname too long - %s\nFile ignored\n",pname);
                    177:                clrent(dptr);
                    178:        }
                    179:        else {
                    180:                dptr->d_namep = np = malloc(n + 1);
                    181:                if (np == 0) {
                    182:                        printf("Out of core\n");
                    183:                        done();
                    184:                }
                    185:                strcpy(np, pname);
                    186:        }
                    187: }
                    188: 
                    189: decode(pname,dptr)     /* dptr points to the dir entry
                    190:                         * name is placed in pname[] */
                    191: char   *pname;
                    192: struct dent *dptr;
                    193: {
                    194: 
                    195:        strcpy(pname, dptr->d_namep);
                    196: }

unix.superglobalmegacorp.com

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