| 1 | /* |
| 2 | * 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 | char vpddir[] = "/usr/vpd"; |
| 15 | int nextflag; |
| 16 | int linecnt; |
| 17 | FILE *df; |
| 18 | FILE *jf; |
| 19 | char line[100]; |
| 20 | char username[10]; |
| 21 | int cnt; |
| 22 | extern int errno; |
| 23 | |
| 24 | main() |
| 25 | { |
| 26 | FILE *vc; |
| 27 | |
| 28 | vc = fopen("/dev/vp0", "w"); |
| 29 | if (vc == NULL) { |
| 30 | if (errno == EIO) |
| 31 | printf("Versatec is OFFLINE.\n"); |
| 32 | else if (errno == ENXIO) |
| 33 | /* printf("Versatec in use.\n") */; |
| 34 | else |
| 35 | printf("Versatec not available.\n"); |
| 36 | } else { |
| 37 | printf("Versatec is ready and idle.\n"); |
| 38 | fclose(vc); |
| 39 | } |
| 40 | if (access("/usr/ucb/vpr", 1)) |
| 41 | printf("Versatec daemon is disabled.\n"); |
| 42 | if (chdir(vpddir) < 0) { |
| 43 | perror(vpddir); |
| 44 | exit(1); |
| 45 | } |
| 46 | oloop: |
| 47 | df = fopen(".", "r"); |
| 48 | if (df == NULL) { |
| 49 | perror(vpddir); |
| 50 | exit(1); |
| 51 | } |
| 52 | loop: |
| 53 | fseek(df, 0l, 0); |
| 54 | linecnt = 0; |
| 55 | cnt = 0; |
| 56 | while (fread(&dirent, sizeof dirent, 1, df) == 1) { |
| 57 | if (dirent.d_ino == 0) |
| 58 | continue; |
| 59 | if (dirent.d_name[0] != 'd') |
| 60 | continue; |
| 61 | if (dirent.d_name[1] != 'f') |
| 62 | continue; |
| 63 | if (stat(dirent.d_name, &stbuf) < 0) |
| 64 | continue; |
| 65 | if (cnt == 0) |
| 66 | printf("Owner\t Id Chars Filename\n"); |
| 67 | cnt++; |
| 68 | process(); |
| 69 | } |
| 70 | if (cnt == 0) |
| 71 | printf("Versatec queue is empty.\n"); |
| 72 | exit(0); |
| 73 | } |
| 74 | |
| 75 | process() |
| 76 | { |
| 77 | |
| 78 | jf = fopen(dirent.d_name, "r"); |
| 79 | if (jf == NULL) |
| 80 | return; |
| 81 | while (getline()) { |
| 82 | switch (line[0]) { |
| 83 | |
| 84 | case 'L': |
| 85 | strcpy(username, line+1); |
| 86 | break; |
| 87 | |
| 88 | case 'B': |
| 89 | case 'F': |
| 90 | case 'P': |
| 91 | case 'T': |
| 92 | if (stat(line+1, &stbuf) < 0) |
| 93 | stbuf.st_size = 0; |
| 94 | printf("%-10s%5s%8d %s\n", username, dirent.d_name+3, |
| 95 | stbuf.st_size, line+1); |
| 96 | break; |
| 97 | } |
| 98 | } |
| 99 | close(jf); |
| 100 | } |
| 101 | |
| 102 | getline() |
| 103 | { |
| 104 | register int i, c; |
| 105 | |
| 106 | i = 0; |
| 107 | while ((c = getc(jf)) != '\n') { |
| 108 | if (c <= 0) |
| 109 | return(0); |
| 110 | if (i < 100) |
| 111 | line[i++] = c; |
| 112 | } |
| 113 | line[i++] = 0; |
| 114 | return (1); |
| 115 | } |