Annotation of researchv10no/cmd/mt.c, revision 1.1.1.1

1.1       root        1: static char *sccsid = "@(#)mt.c        4.2 (Berkeley) 81/07/05";
                      2: 
                      3: /*
                      4:  * mt
                      5:  */
                      6: 
                      7: #include <stdio.h>
                      8: #include <ctype.h>
                      9: #include <sys/types.h>
                     10: #include <sys/mtio.h>
                     11: 
                     12: struct commands {
                     13:        char *c_name;
                     14:        int c_code;
                     15:        int c_ronly;
                     16: } com[] = {
                     17:        "eof",  MTWEOF, 0,
                     18:        "fsf",  MTFSF,  1,
                     19:        "bsf",  MTBSF,  1,
                     20:        "fsr",  MTFSR,  1,
                     21:        "bsr",  MTBSR,  1,
                     22:        "rewind",       MTREW,  1,
                     23:        "offline",      MTOFFL, 1,
                     24:        "reset",        MTRST,  1,
                     25:        0,0
                     26: };
                     27: 
                     28: int mtfd;
                     29: struct mtop mt_com;
                     30: char *tape;
                     31: 
                     32: main(argc, argv)
                     33: char **argv;
                     34: {
                     35:        char line[80], *getenv();
                     36:        register char *cp;
                     37:        register struct commands *comp;
                     38: 
                     39:        if (argc < 2) {
                     40:                fprintf(stderr, "usage: mt [ -t tape ] command [ count ]\n");
                     41:                exit(1);
                     42:        }
                     43:        if ((strcmp(argv[1], "-t") == 0) && argc > 2) {
                     44:                argc -= 2;
                     45:                tape = argv[2];
                     46:                argv += 2;
                     47:        } else
                     48:                if ((tape = getenv("TAPE")) == NULL)
                     49:                        tape = "/dev/nrmt1";
                     50:        cp = argv[1];
                     51:        for (comp = com; comp->c_name != NULL; comp++)
                     52:                if (strncmp(cp, comp->c_name, strlen(cp)) == 0)
                     53:                        break;
                     54:        if (comp->c_name == NULL) {
                     55:                fprintf(stderr, "mt: don't grok \"%s\"\n", cp);
                     56:                exit(1);
                     57:        }
                     58:        if ((mtfd = open(tape, comp->c_ronly ? 0 : 2)) < 0) {
                     59:                perror(tape);
                     60:                exit(1);
                     61:        }
                     62:        mt_com.mt_count = (argc > 2 ? atoi(argv[2]) : 1);
                     63:        mt_com.mt_op = comp->c_code;
                     64:        if (ioctl(mtfd, MTIOCTOP, &mt_com) < 0) {
                     65:                fprintf(stderr, "%s %d ", comp->c_name, mt_com.mt_count);
                     66:                perror("failed");
                     67:        }
                     68: }

unix.superglobalmegacorp.com

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