|
|
1.1 ! root 1: /* ! 2: * Line printer queue ! 3: */ ! 4: ! 5: #include <sys/types.h> ! 6: #include <dir.h> ! 7: #include <stat.h> ! 8: #include <stdio.h> ! 9: ! 10: #define MAXJOBS 100 ! 11: ! 12: struct dir dirent; ! 13: struct stat stbuf; ! 14: char lpddir[] = "/usr/spool/lpd"; ! 15: int nextflag; ! 16: int linecnt; ! 17: FILE *df; ! 18: FILE *jf; ! 19: char line[100]; ! 20: char username[10]; ! 21: int cnt; ! 22: int isdown; ! 23: ! 24: main() ! 25: { ! 26: ! 27: if (access("/usr/bin/lpr", 1) && access("/bin/lpr", 1) ! 28: && access("/usr/ucb/lpr", 1)) ! 29: isdown++; ! 30: if (chdir(lpddir) < 0) { ! 31: perror(lpddir); ! 32: exit(1); ! 33: } ! 34: oloop: ! 35: df = fopen(".", "r"); ! 36: if (df == NULL) { ! 37: perror(lpddir); ! 38: exit(1); ! 39: } ! 40: loop: ! 41: fseek(df, 0l, 0); ! 42: linecnt = 0; ! 43: cnt = 0; ! 44: while (fread(&dirent, sizeof dirent, 1, df) == 1) { ! 45: if (dirent.d_ino == 0) ! 46: continue; ! 47: if (dirent.d_name[0] != 'd') ! 48: continue; ! 49: if (dirent.d_name[1] != 'f') ! 50: continue; ! 51: if (stat(dirent.d_name, &stbuf) < 0) ! 52: continue; ! 53: if (cnt == 0) ! 54: printf("Owner\t Id Chars Filename\n"); ! 55: cnt++; ! 56: process(); ! 57: } ! 58: if (cnt == 0) { ! 59: if (isdown) ! 60: printf("Line printer is down.\n"); ! 61: else ! 62: printf("Line printer queue is empty.\n"); ! 63: } ! 64: exit(0); ! 65: } ! 66: ! 67: process() ! 68: { ! 69: ! 70: jf = fopen(dirent.d_name, "r"); ! 71: if (jf == NULL) ! 72: return; ! 73: while (getline()) { ! 74: switch (line[0]) { ! 75: ! 76: case 'L': ! 77: strcpy(username, line+1); ! 78: break; ! 79: ! 80: case 'B': ! 81: case 'F': ! 82: if (stat(line+1, &stbuf) < 0) ! 83: stbuf.st_size = 0; ! 84: printf("%-10s%5s%8d %s\n", username, dirent.d_name+3, ! 85: stbuf.st_size, line+1); ! 86: break; ! 87: } ! 88: } ! 89: close(jf); ! 90: } ! 91: ! 92: getline() ! 93: { ! 94: register int i, c; ! 95: ! 96: i = 0; ! 97: while ((c = getc(jf)) != '\n') { ! 98: if (c <= 0) ! 99: return(0); ! 100: if (i < 100) ! 101: line[i++] = c; ! 102: } ! 103: line[i++] = 0; ! 104: return (1); ! 105: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.