Annotation of 40BSD/cmd/vpr/vpq.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Varian and Versatec queue
        !             3:  */
        !             4: 
        !             5: #include <sys/types.h>
        !             6: #include <dir.h>
        !             7: #include <stat.h>
        !             8: #include <stdio.h>
        !             9: #include <errno.h>
        !            10: #define        MAXJOBS 100
        !            11: 
        !            12: struct dir dirent;
        !            13: struct stat stbuf;
        !            14: int    nextflag;
        !            15: int    linecnt;
        !            16: FILE   *df;
        !            17: FILE   *jf;
        !            18: char   line[100];
        !            19: char   username[10];
        !            20: int    cnt;
        !            21: extern int errno;
        !            22: extern char _sobuf[];
        !            23: 
        !            24: main(argc, argv)
        !            25: int argc;
        !            26: char **argv;
        !            27: {
        !            28:        int varian = 1;
        !            29:        int versatec = 1;
        !            30: 
        !            31:        setbuf(stdout, _sobuf);
        !            32: 
        !            33:        argc--, argv++;
        !            34:        while (argc > 0 && argv[0][0] == '-') {
        !            35:                switch (argv[0][1]) {
        !            36: 
        !            37:                case 'W':               /* Wide: the versatec. */
        !            38:                        varian = 0;
        !            39:                        versatec++;
        !            40:                        break;
        !            41: 
        !            42:                case 'b':
        !            43:                        varian++;
        !            44:                        versatec++;
        !            45:                        break;
        !            46: 
        !            47:                default:
        !            48:                        fprintf(stderr, "usage: vpq [ -W ] [ -b ]\n");
        !            49:                        exit(1);
        !            50:                }
        !            51:                argc--, argv++;
        !            52:        }
        !            53:        if (varian)
        !            54:                queue("/dev/va0", "Varian", "/usr/spool/vad", "/usr/lib/vad");
        !            55:        if (versatec)
        !            56:                queue("/dev/vp0", "Versatec", "/usr/spool/vpd", "/usr/lib/vpd");
        !            57:        exit(0);
        !            58: }
        !            59: 
        !            60: 
        !            61: queue(device, devname, spooldir, daemon)
        !            62: char *device, *devname, *spooldir, *daemon;
        !            63: {
        !            64:        FILE *vc;
        !            65: 
        !            66:        printf("%s: ", devname);
        !            67:        vc = fopen(device, "w");
        !            68:        if (vc == NULL) {
        !            69:                if (errno == EIO)
        !            70:                        printf("offline\n");
        !            71:                else if (errno == ENXIO)
        !            72:                        printf("in use\n");
        !            73:                else
        !            74:                        printf("not available\n");
        !            75:        } else {
        !            76:                printf("ready and idle.\n");
        !            77:                fclose(vc);
        !            78:        }
        !            79:        if (access(daemon, 1))
        !            80:                printf("Daemon is disabled.\n");
        !            81:        if (chdir(spooldir) < 0) {
        !            82:                perror(spooldir);
        !            83:                return;
        !            84:        }
        !            85: oloop:
        !            86:        df = fopen(".", "r");
        !            87:        if (df == NULL) {
        !            88:                perror(spooldir);
        !            89:                return;
        !            90:        }
        !            91: loop:
        !            92:        fseek(df, 0l, 0);
        !            93:        linecnt = 0;
        !            94:        cnt = 0;
        !            95:        while (fread(&dirent, sizeof dirent, 1, df) == 1) {
        !            96:                if (dirent.d_ino == 0)
        !            97:                        continue;
        !            98:                if (dirent.d_name[0] != 'd')
        !            99:                        continue;
        !           100:                if (dirent.d_name[1] != 'f')
        !           101:                        continue;
        !           102:                if (stat(dirent.d_name, &stbuf) < 0)
        !           103:                        continue;
        !           104:                if (cnt == 0)
        !           105:                        printf("Owner\t  Id      Chars  Filename\n");
        !           106:                cnt++;
        !           107:                process();
        !           108:        }
        !           109:        if (cnt == 0)
        !           110:                printf("Queue is empty.\n");
        !           111:        printf("\n");
        !           112: }
        !           113: 
        !           114: process()
        !           115: {
        !           116: 
        !           117:        jf = fopen(dirent.d_name, "r");
        !           118:        if (jf == NULL)
        !           119:                return;
        !           120:        while (getline()) {
        !           121:                switch (line[0]) {
        !           122: 
        !           123:                case 'L':
        !           124:                        strcpy(username, line+1);
        !           125:                        break;
        !           126: 
        !           127:                case 'B':
        !           128:                case 'F':
        !           129:                case 'G':
        !           130:                case 'P':
        !           131:                case 'T':
        !           132:                        if (stat(line+1, &stbuf) < 0)
        !           133:                                stbuf.st_size = 0;
        !           134:                        printf("%-10s%5s%8d  %s\n", username, dirent.d_name+3,
        !           135:                            stbuf.st_size, line+1);
        !           136:                        break;
        !           137:                }
        !           138:        }
        !           139:        fclose(jf);
        !           140: }
        !           141: 
        !           142: getline()
        !           143: {
        !           144:        register int i, c;
        !           145: 
        !           146:        i = 0;
        !           147:        while ((c = getc(jf)) != '\n') {
        !           148:                if (c <= 0)
        !           149:                        return(0);
        !           150:                if (i < 100)
        !           151:                        line[i++] = c;
        !           152:        }
        !           153:        line[i++] = 0;
        !           154:        return (1);
        !           155: }

unix.superglobalmegacorp.com

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