|
|
1.1 ! root 1: /* scanning program for ricoh scanner: ! 2: OPTIONS: ! 3: -rN resolution, N : (NOT TESTED) ! 4: 0 - 200x200 ! 5: 1 - 200x100 ! 6: 2 - 300x300 (default) ! 7: 3 - 240x240 ! 8: -D dither ! 9: -t trace stages ! 10: -d detailed debugging ! 11: 16 Jan 89 (hsb): WINDOW=0 0 wid hgt changed: ! 12: 1. wid pixels, not; 2. hgt is calculated at 11.7 inches (still in pixels) ! 13: */ ! 14: #include <stdio.h> ! 15: #include "rcocmd.h" ! 16: /* don't change this number - hardware puts out some number ! 17: of lines +- 5% - this makes sure we never ! 18: overrun the mapping registers */ ! 19: #define MAX 1200000 ! 20: #define IOALIGN 4*512 ! 21: #define IMAX MAX + IOALIGN ! 22: char Buf[IMAX]; ! 23: int cmdstat[] = {0, 0, 0}; ! 24: int *cs = cmdstat; ! 25: char *resolution[]={ ! 26: "200 200", "200 100", "300 300", "240 240" }; ! 27: int width[]={ /* in bytes, not pixels */ ! 28: 216, 216, 324, 260 }; ! 29: int height[]={ /* 11.7 inches high */ ! 30: 2340, 1170, 3510, 2808 }; ! 31: char *ares = "300 300"; ! 32: int wid = 324; /* in bytes, not pixels */ ! 33: int ht = 3510; ! 34: int dither = 0; ! 35: int resol = 0; ! 36: int trace = 0; ! 37: int debug = 0; ! 38: ! 39: char *device = "/dev/ricoh"; ! 40: ! 41: main(argc, argv) ! 42: char **argv; ! 43: { ! 44: int scanner, i, outp, count; ! 45: char *arg, *ptr, *b; ! 46: ! 47: argv++; ! 48: while(--argc > 0){ ! 49: if(**argv == '-'){ ! 50: arg = *argv++; ! 51: switch(*++arg){ ! 52: case 't': ! 53: trace = 1; ! 54: break; ! 55: case 'd': ! 56: debug = 1; ! 57: break; ! 58: case 'D': ! 59: dither = 0; ! 60: break; ! 61: case 'r': ! 62: resol = *++arg; ! 63: resol -= '0'; ! 64: if(resol <0 || resol > 3) ! 65: fprintf(stderr,"strange resolution %d using default\n",resol); ! 66: ares = resolution[resol]; ! 67: wid = width[resol]; ! 68: ht = height[resol]; ! 69: break; ! 70: ! 71: case 'f': ! 72: device = ++arg; ! 73: break; ! 74: default: ! 75: fprintf(stderr,"unknown flag %s\n",arg); ! 76: exit(1); ! 77: } ! 78: } ! 79: else break; ! 80: } ! 81: if((scanner = open(device, 2)) == -1){ ! 82: fprintf(stderr,"Can't open %s\n", device); ! 83: exit(1); ! 84: } ! 85: if(trace) fprintf(stderr,"opened ricoh\n"); ! 86: if(argc != 0){ ! 87: if((outp = creat(*argv,0666)) == -1){ ! 88: fprintf(stderr,"Can't create output file %s\n",*argv); ! 89: exit(1); ! 90: } ! 91: } ! 92: else if((outp = creat("Junk", 0666)) == -1){ ! 93: fprintf(stderr,"Can't create default output file junk\n"); ! 94: exit(1); ! 95: } ! 96: if(trace) fprintf(stderr,"created output file\n"); ! 97: sprintf(Buf, ! 98: "TYPE=binary\nWINDOW=0 0 %d %d\nRES=%s\n\n", ! 99: wid*8,ht,ares); ! 100: for(b=Buf; ;b++){ ! 101: if(*b == '\n' && *(b+1) == '\n'){ ! 102: count = b - Buf +2; ! 103: break; ! 104: } ! 105: } ! 106: if(write(outp, Buf, count) != count){ ! 107: fprintf(stderr,"error while writing header\n"); ! 108: exit(1); ! 109: } ! 110: if(dither){ ! 111: *cs = dither; ! 112: if((i=ioctl(scanner,RCODITHER,cmdstat)) != 0){ ! 113: fprintf(stderr,"ioctl error setting dither\n"); ! 114: exit(1); ! 115: } ! 116: } ! 117: if(resol){ ! 118: *cs = resol; ! 119: if((i=ioctl(scanner,RCORES,cmdstat)) != 0){ ! 120: fprintf(stderr,"ioctl error setting resolution\n"); ! 121: exit(1); ! 122: } ! 123: } ! 124: if(trace) fprintf(stderr,"about to read\n"); ! 125: ptr = (char *)(((int)(Buf + IOALIGN-1)) & ~(IOALIGN-1)); ! 126: if((i=read(scanner, ptr, MAX)) != MAX){ ! 127: fprintf(stderr,"read error on scanner %d\n",i); ! 128: exit(1); ! 129: } ! 130: if(trace) fprintf(stderr,"returned from read\n"); ! 131: if((ioctl(scanner, RCOHACK, cmdstat)) == 0) { /* obsolete */ ! 132: fprintf(stderr, "offset %d, base = 0x%x\n", cmdstat[0], ptr); ! 133: ptr += cmdstat[0]; ! 134: } ! 135: if((i=write(outp, ptr, MAX))!= MAX){ ! 136: fprintf(stderr,"write error on output file\n"); ! 137: exit(1); ! 138: } ! 139: close(scanner); ! 140: exit(0); ! 141: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.