|
|
1.1 root 1: /*
2: * Copyright (c) 1985 University of Alberta *
3: *
4: * 'impv' impress (i.e. canon) previewer for a SUN workstation.
5: * impv [-p##] [-s] [job# | -n name]
6: * where job# is the job number of the troff/dimp processed output suitable
7: * for the canon imagen printer. This can be found by executing 'ipq'. The
8: * -p## argument sets the number of pages the user will be allowed to
9: * backup. The -n name option will cause the users most recent job to
10: * be displayed.The human interface for this proram leaves something to be
11: * desired ( skip pages, print page number 'n', etc.).
12: * The algorithm for crunching glyphs could be improved from the straight
13: * forward method used.
14: #ifdef COLOR
15: * The -s option will cause the output to be sent to the color monitor. Troff
16: * Macros .CC and .BG set the background and current color. This option is
17: * intended for slide production.
18: #endif COLOR
19: *
20: * This program requires that a 'file server' (used very loosely)
21: * exist on the remote host UNIX system. See the code for impvserv.
22: *
23: * history:
24: *
25: * The program was written in desparation by:
26: * Steven Sutphen
27: * University of Alberta
28: * Department of Computing Science
29: * Edmonton, Alberta T6G 2H1
30: * ihnp4!alberta!steve
31: * November 20, 1982
32: *
33: * Revised for Sun Work Station:
34: * January 1, 1984 Ted Bentley
35: * Revised for Color SUN displays:
36: * January 1985 Martin Dubetz
37: */
38: #ifndef lint
39: static char *rcsid_impv_c = "$Header: impv.c,v 10.7 86/11/19 19:27:39 jg Rel $";
40: #endif
41:
42: #ifdef XWIND
43: #include <X/Xlib.h>
44: #include <X/Xkeyboard.h>
45: #include <sys/types.h>
46: #include <strings.h>
47: #define min(a,b) ((a) < (b) ? (a) : (b))
48: #define CHUNKSIZE 2048
49: #else XWIND
50: #include <pixrect/pixrect_hs.h>
51: /* pixrect_hs.h includes sys/types.h */
52: #include <sys/socket.h>
53: #endif XWIND
54: #include <sys/stat.h>
55: #include <sys/file.h>
56: #include <stdio.h>
57: #include <signal.h>
58: #include <netdb.h>
59: #include <netinet/in.h>
60: #include <sgtty.h>
61:
62: #include "site.h"
63: #include "imPdefs.h"
64: #include "imPcodes.h"
65: #include "impv.h"
66:
67:
68: char map8_4[256] = { /* map 8 bits to 4bits for pixel compression */
69: 00, 01, 01, 01, 02, 03, 03, 03, 02, 03, 03, 03, 02, 03, 03, 03,
70: 04, 05, 05, 05, 06, 07, 07, 07, 06, 07, 07, 07, 06, 07, 07, 07,
71: 04, 05, 05, 05, 06, 07, 07, 07, 06, 07, 07, 07, 06, 07, 07, 07,
72: 04, 05, 05, 05, 06, 07, 07, 07, 06, 07, 07, 07, 06, 07, 07, 07,
73: 010, 011, 011, 011, 012, 013, 013, 013, 012, 013, 013, 013, 012, 013, 013, 013,
74: 014, 015, 015, 015, 016, 017, 017, 017, 016, 017, 017, 017, 016, 017, 017, 017,
75: 014, 015, 015, 015, 016, 017, 017, 017, 016, 017, 017, 017, 016, 017, 017, 017,
76: 014, 015, 015, 015, 016, 017, 017, 017, 016, 017, 017, 017, 016, 017, 017, 017,
77: 010, 011, 011, 011, 012, 013, 013, 013, 012, 013, 013, 013, 012, 013, 013, 013,
78: 014, 015, 015, 015, 016, 017, 017, 017, 016, 017, 017, 017, 016, 017, 017, 017,
79: 014, 015, 015, 015, 016, 017, 017, 017, 016, 017, 017, 017, 016, 017, 017, 017,
80: 014, 015, 015, 015, 016, 017, 017, 017, 016, 017, 017, 017, 016, 017, 017, 017,
81: 010, 011, 011, 011, 012, 013, 013, 013, 012, 013, 013, 013, 012, 013, 013, 013,
82: 014, 015, 015, 015, 016, 017, 017, 017, 016, 017, 017, 017, 016, 017, 017, 017,
83: 014, 015, 015, 015, 016, 017, 017, 017, 016, 017, 017, 017, 016, 017, 017, 017,
84: 014, 015, 015, 015, 016, 017, 017, 017, 016, 017, 017, 017, 016, 017, 017, 017,
85: };
86:
87: #ifdef XWIND
88: int Select_mask, maxplus1;
89: int forepix, backpix;
90: OpaqueFrame win;
91: Window Win; /* our window */
92: #define impv_width 15
93: #define impv_height 15
94: static short impv_bits[] = {
95: 0x0080, 0x01c0, 0x03e0, 0x06b0,
96: 0x0c98, 0x188c, 0x3086, 0x7fff,
97: 0x3086, 0x188c, 0x0c98, 0x06b0,
98: 0x03e0, 0x01c0, 0x0080};
99: #else XWIND
100: struct pixrect *picon, *ptube, *side;
101: #endif XWIND
102:
103: int diameter = 1;
104: short pages = SAVE_PAGES;
105: char screen_file[32];
106: unsigned char in_buf[512], *in_bufp;
107: int ptubew, ptubeh; /* screen window dimensions */
108: struct sgttyb cbreak; /* tty mode bits */
109: int s = 0; /* socket or input file descriptor */
110: int tty; /* tty file descriptor */
111: int screens; /* screen store file descriptor */
112:
113: main(argc, argv)
114: char **argv;
115: {
116: struct sockaddr_in sin;
117: #ifdef XWIND
118: char *display = NULL;
119: char *option;
120: int reverse = 0;
121: int bwidth = 2;
122: char *fore_color;
123: char *back_color;
124: char *brdr_color;
125: char *mous_color;
126: char *geometry = NULL, def[32];
127: int backmap, bdrmap, mouspix;
128: Color cdef;
129: #else XWIND
130: #ifdef COLOR
131: unsigned char r[216],b[216],g[216],tmp[6];
132: register short i,j,k;
133: int l;
134: register unsigned char *z;
135: unsigned char setcolor();
136: #endif COLOR
137: extern struct pixrect *pr_open();
138: #endif XWIND
139: int pipes[2], id_num = 0, rq;
140: char string[100], buf[28];
141: struct hostent *hp;
142: struct servent *sp;
143: struct stat stat1;
144: char *prog = argv[0];
145:
146: extern get_out();
147:
148: #ifdef XWIND
149: if ((option = XGetDefault(argv[0], "ReverseVideo")) &&
150: strcmp(option, "on") == 0)
151: reverse = 1;
152: if (option = XGetDefault(argv[0], "BorderWidth"))
153: bwidth = atoi(option);
154: fore_color = XGetDefault(argv[0], "ForeGround");
155: back_color = XGetDefault(argv[0], "BackGround");
156: brdr_color = XGetDefault(argv[0], "Border");
157: mous_color = XGetDefault(argv[0], "Mouse");
158: #else XWIND
159: /* set up the keyboard input */
160: (void)gtty(0, &cbreak);
161: cbreak.sg_flags &= ~ECHO;
162: cbreak.sg_flags |= CBREAK;
163: (void)stty(0, &cbreak);
164: cbreak.sg_flags &= ~CBREAK;
165: cbreak.sg_flags |= ECHO;
166: #endif XWIND
167: signal(SIGINT, get_out);
168: signal(SIGQUIT, get_out);
169: signal(SIGHUP, get_out);
170: signal(SIGIOT, get_out);
171:
172: scr_x = MAXx / 2; /* number of dots on a screen page */
173: wide = (7 + MAXx/2) / 8; /* rounded up to byte for pixrect */
174: scr_y = MAXy / 2;
175: scr_d = 1;
176: /* calculate the screen size in bytes 2::1 compression */
177: scr_size = (((scr_x + 7) / 8) * scr_y);
178:
179: for (argv++; --argc; argv++) {
180: if (**argv == '-'){
181: switch (argv[0][1]){
182: #ifndef NOSPOOL
183: case 'n':
184: if (pipe(pipes)) {
185: fprintf(stderr, "pipe mistake\n");
186: get_out();
187: }
188: if (fork() == 0){
189: /*child*/
190: (void)close(1);
191: (void)dup(pipes[1]);
192: (void)sprintf(string, "echo `ipq | grep %s | awk ' {print $3}'| sort -rn | head -1 `", *++argv);
193: (void)system(string);
194: exit(0);
195: }
196: /* parent */
197: while (read(pipes[0], buf, 20) <= 0);
198: id_num = atoi(buf);
199: argv++;
200: argc--;
201: break;
202: case 'r':
203: rq = 1;
204: break;
205: #endif NOSPOOL
206: case 'p':
207: pages = atoi( &argv[0][2] );
208: if (pages < 0) pages = 0;
209: break;
210: #ifdef COLOR
211: case 's':
212: slide = 1;
213: scr_x = MAXx / 3;
214: scr_y = MAXy / 3;
215: scr_d = 8;
216: scr_size = scr_x * scr_y;
217: bc.red = 0;
218: bc.blue = 255;
219: bc.green = 0;
220: cc.red = 255;
221: cc.blue = 255;
222: cc.green = 255;
223: break;
224: #endif COLOR
225: default:
226: #ifdef XWIND
227: if (strcmp(*argv, "-rv") == 0) {
228: reverse = 1;
229: break;
230: } else if (strcmp(*argv, "-fg") == 0 && argc) {
231: argv++;
232: argc--;
233: fore_color = *argv;
234: break;
235: } else if (strcmp(*argv, "-bg") == 0 && argc) {
236: argv++;
237: argc--;
238: back_color = *argv;
239: break;
240: } else if (strcmp(*argv, "-bd") == 0 && argc) {
241: argv++;
242: argc--;
243: brdr_color = *argv;
244: break;
245: } else if (strcmp(*argv, "-ms") == 0 && argc) {
246: argv++;
247: argc--;
248: mous_color = *argv;
249: break;
250: }
251: #endif XWIND
252: (void)usage();
253: get_out();
254: }
255: }
256: else {
257: #ifdef XWIND
258: if (index(*argv, ':') != NULL)
259: display = *argv;
260: else if (argv[0][0] == '=') {
261: geometry = argv[0];
262: }
263:
264: else
265: #endif XWIND
266: #ifdef NOSPOOL
267: if((s = open(*argv, O_RDONLY)) <= 0){
268: fprintf(stderr,"can't open file\n");
269: exit(0);
270: }
271: #else NOSPOOL
272: id_num = atoi(*argv);
273: #endif NOSPOOL
274: }
275: }
276: #ifdef NOSPOOL
277: /* set up tty for piped input situation*/
278: if(s == 0) {
279: s = dup(0);
280: close(0);
281: tty = open("/dev/tty",O_RDONLY);
282: fstat(s, &stat1);
283: if( (stat1.st_mode>>12) == 02 )
284: (void)usage();
285: }
286: #else NOSPOOL
287: if(id_num == 0) (void)usage();
288: #endif NOSPOOL
289:
290: /* get the file for screen pages */
291: if (pages) {
292: strcpy(screen_file, SCREEN_FILE);
293: mktemp(screen_file);
294: if ((screens = creat(screen_file, 0666)) <= 0){
295: fprintf(stderr, "couldn't create: %s\n", screen_file);
296: get_out();
297: }
298: (void)close(screens);
299: if ((screens = open(screen_file, 2)) <= 0){
300: fprintf(stderr, "couldn't reopen: %s\n", screen_file);
301: get_out();
302: }
303: }
304:
305: #ifndef NOSPOOL
306: /*open up the network to get file from remote host */
307: sp = getservbyname(P_SERV, "tcp");
308: hp = gethostbyname(REMOTE_HOST);
309: if (hp == NULL) {
310: fprintf(stderr, "impv: nohost - %s\n", REMOTE_HOST);
311: get_out();
312: }
313: bzero((char *)&sin, sizeof (sin));
314: bcopy(hp->h_addr, (char *)&sin.sin_addr, hp->h_length);
315: sin.sin_family = hp->h_addrtype;
316: sin.sin_port = sp->s_port;
317: s = socket(AF_INET, SOCK_STREAM, 0);
318: if (s < 0) {
319: perror("impv: socket");
320: get_out();
321: }
322: (void)setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
323: if (connect(s, (char *)&sin, sizeof (sin)) < 0) {
324: perror("impv: connect");
325: get_out();
326: }
327: /* write the ipd file name to remote_host */
328: (void)sprintf(string, "P%c%03d", rq ? 'r' : 'n', id_num);
329: (void)write(s, string, strlen(string));
330: #endif NOSPOOL
331:
332: in_bufp = in_buf;
333: family[0] = font0;
334: inicodes();
335:
336: #ifdef XWIND
337: if (!XOpenDisplay(display)) {
338: fprintf(stderr, "%s: Can't open display '%s'\n",
339: prog, XDisplayName(display));
340: exit(1);
341: }
342: if (reverse) {
343: forepix = WhitePixel;
344: backpix = BlackPixel;
345: backmap = BlackPixmap;
346: bdrmap = WhitePixmap;
347: mouspix = WhitePixel;
348: } else {
349: forepix = BlackPixel;
350: backpix = WhitePixel;
351: backmap = WhitePixmap;
352: bdrmap = BlackPixmap;
353: mouspix = BlackPixel;
354: }
355: if (DisplayCells() > 2) {
356: if (fore_color && XParseColor(fore_color, &cdef) &&
357: XGetHardwareColor(&cdef))
358: forepix = cdef.pixel;
359: if (back_color && XParseColor(back_color, &cdef) &&
360: XGetHardwareColor(&cdef)) {
361: backpix = cdef.pixel;
362: backmap = XMakeTile(backpix);
363: }
364: if (brdr_color && XParseColor(brdr_color, &cdef) &&
365: XGetHardwareColor(&cdef))
366: bdrmap = XMakeTile(cdef.pixel);
367: if (mous_color && XParseColor(mous_color, &cdef) &&
368: XGetHardwareColor(&cdef))
369: mouspix = cdef.pixel;
370: }
371: win.bdrwidth = bwidth;
372: win.border = bdrmap;
373: win.background = backmap;
374:
375: sprintf(def, "=%dx%d+0+0", DisplayWidth() - (bwidth << 1),
376: DisplayHeight() - (bwidth << 1));
377: Win = XCreate (
378: "Imagen Previewer", argv[0], geometry, def, &win, 200, 200);
379: XSetResizeHint(Win, 100, 100, 1, 1);
380: XMapWindow (Win);
381: ptubew = win.width;
382: /* crock around crock */
383: if ((DisplayType() == XDEV_QDSS) && (bwidth < 4))
384: ptubew &= ~7;
385: if (ptubew > scr_x)
386: ptubew = scr_x;
387: ptubeh = win.height;
388: if (ptubeh > scr_y)
389: ptubeh = scr_y;
390:
391: XSelectInput (Win, KeyPressed|ButtonPressed|ExposeRegion|ExposeCopy);
392: XDefineCursor(Win,
393: XCreateCursor(impv_width, impv_height, impv_bits, impv_bits,
394: 7, 7, mouspix, backpix, GXcopy));
395: XSync(0);
396: Select_mask = 1 << dpyno();
397: maxplus1 = 1 + dpyno();
398: #else XWIND
399: /* set up the raster pixrect functions */
400: if( slide ) {
401: #ifdef COLOR
402: ptube = pr_open("/dev/cgone0");
403: tmp[0] = 0;
404: tmp[1] = 130;
405: tmp[2] = 180;
406: tmp[3] = 210;
407: tmp[4] = 235;
408: tmp[5] = 255;
409: l = 0;
410: for( i = 0; i < 6; i++ )
411: for( j = 0; j < 6; j++ )
412: for( k = 0; k < 6; k++ ) {
413: r[l] = tmp[i];
414: g[l] = tmp[j];
415: b[l++] = tmp[k];
416: }
417:
418: pr_putcolormap(ptube,0,216,r,g,b);
419: #endif COLOR
420: }
421: else
422: ptube = pr_open("/dev/fb");
423: pscreen = mem_create(scr_x, scr_y, scr_d);
424: #ifdef COLOR
425: if( slide ) {
426: backcolor = setcolor(0);
427: z = (unsigned char *)(mpr_d(pscreen)->md_image);
428: for (l = scr_size; l--; ) *z++ = backcolor;
429: }
430: #endif COLOR
431: picon = mem_create(46, 53, scr_d);
432: side = mem_create(ptubew-scr_x, ptubeh, scr_d);
433: ptubew = ptube->pr_size.x;
434: ptubeh = ptube->pr_size.y;
435: #endif XWIND
436:
437: dofile();
438: (void)write(s, string, strlen(string));
439: get_out();
440: }
441:
442: #ifdef XWIND
443: unsigned char rot8[] = {
444: 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
445: 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
446: 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
447: 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
448: 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
449: 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
450: 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
451: 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
452: 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
453: 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
454: 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
455: 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
456: 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
457: 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
458: 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
459: 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
460: 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
461: 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
462: 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
463: 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
464: 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
465: 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
466: 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
467: 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
468: 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
469: 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
470: 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
471: 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
472: 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
473: 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
474: 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
475: 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
476: };
477:
478: static short current_page = -1;
479: static short current_x = -1;
480: #endif XWIND
481:
482: ppause()
483: {
484: short y = 0;
485: short x;
486: register int c, i;
487: register unsigned char *z, *scptr;
488: #ifdef COLOR
489: unsigned char setcolor();
490: #endif COLOR
491:
492: #ifdef XWIND
493: short current_y = 0;
494: int select_mask;
495: XEvent event;
496: scptr = pscreen;
497: for (i = sizeof pscreen; i--; scptr++) *scptr = rot8[*scptr];
498: winker();
499: scptr = pscreen;
500: winker();
501: #else XWIND
502: scptr = (unsigned char *)(mpr_d(pscreen)->md_image);
503: #endif XWIND
504: if (current_x < 0)
505: if((current_x = (scr_x - ptubew)/2) < 0) current_x = 0;
506: x = current_x;
507: /*write the screen */
508: while(1) {
509: #ifdef XWIND
510: if (page == current_page && x == current_x &&
511: y < current_y && y + ptubeh > current_y) {
512: int delta = current_y - y;
513: XMoveArea(Win, 0, 0, 0, delta, ptubew, ptubeh - delta);
514: BitsPut(x, y, 0, 0, ptubew, delta);
515: } else if (page == current_page && x == current_x &&
516: y > current_y && current_y + ptubeh > y) {
517: int delta = y - current_y;
518: XMoveArea(Win, 0, delta, 0, 0, ptubew, ptubeh - delta);
519: BitsPut(x, y + ptubeh - delta, 0, ptubeh - delta,
520: ptubew, delta);
521: } else if (page == current_page && y == current_y &&
522: x < current_x && x + ptubew > current_x) {
523: int delta = current_x - x;
524: XMoveArea(Win, 0, 0, delta, 0, ptubew - delta, ptubeh);
525: BitsPut(x, y, 0, 0, delta, ptubeh);
526: } else if (page == current_page && y == current_y &&
527: x > current_x && current_x + ptubew > x) {
528: int delta = x - current_x;
529: XMoveArea(Win, delta, 0, 0, 0, ptubew - delta, ptubeh);
530: BitsPut(x + ptubew - delta, y, ptubew - delta, 0,
531: delta, ptubeh);
532: } else if (y != current_y || x != current_x ||
533: page != current_page)
534: BitsPut(x, y, 0, 0, min(scr_x - x, ptubew),
535: min(scr_y - y, ptubeh));
536: current_y = y;
537: current_x = x;
538: current_page = page;
539: XFlush();
540: select_mask = Select_mask;
541: if (select(maxplus1, &select_mask, NULL, NULL, 0) < 0) exit(1);
542: if (!(select_mask & Select_mask)) continue;
543: XPending();
544: do {
545: XNextEvent (&event);
546: switch (event.type) {
547: case ExposeWindow:
548: ptubeh = ((XExposeEvent *)(&event))->height;
549: ptubew = ((XExposeEvent *)(&event))->width;
550: case ExposeRegion: {
551: short ex = ((XExposeEvent *)(&event))->x;
552: short ew = ((XExposeEvent *)(&event))->width;
553: short ey = ((XExposeEvent *)(&event))->y;
554: short eh = ((XExposeEvent *)(&event))->height;
555: BitsPut(x + ex, y + ey, ex, ey,
556: min(scr_x - (x + ex), ew),
557: min(scr_y - (y + ey), eh));
558: continue;
559: }
560: case ExposeCopy:
561: continue;
562: case ButtonPressed:
563: {
564: short detail = ((XButtonPressedEvent *) (&event))->detail;
565: switch (detail & ValueMask) {
566: case LeftButton: if (detail & ShiftMask)
567: c = 'l';
568: else
569: c = 'u';
570: break;
571: case MiddleButton: if (detail & ShiftMask) {
572: if (x < scr_x - (x + ptubew))
573: c = '6';
574: else
575: c = '4';
576: } else {
577: if (y < scr_y - (y + ptubeh))
578: c = '3';
579: else
580: c = '9';
581: }
582: break;
583: case RightButton: if (detail & ShiftMask)
584: c = 'r';
585: else
586: c = 'd';
587: break;
588: }
589: break;
590: }
591: case KeyPressed:
592: switch ((((XKeyPressedEvent *) (&event))->detail) & ValueMask) {
593: case KC_E5: c = '-'; break; /* prev screen */
594: case KC_E6: c = '+'; break; /* next screen */
595: case KC_CURSOR_UP: c = 'u'; break; /* prev screen */
596: case KC_CURSOR_DOWN: c = 'd'; break; /* next screen */
597: case KC_CURSOR_LEFT: c = '<'; break; /* left screen */
598: case KC_CURSOR_RIGHT: c = '>'; break; /* right screen */
599: case KC_KEYPAD_0: c = '0'; break; /* R0 */
600: case KC_KEYPAD_PERIOD: c = '.'; break; /* R. */
601: case KC_KEYPAD_COMMA: c = ','; break; /* R, */
602: case KC_KEYPAD_1: c = '1'; break; /* R1 */
603: case KC_KEYPAD_2: c = '2'; break; /* R2 */
604: case KC_KEYPAD_3: c = '3'; break; /* R3 */
605: case KC_KEYPAD_4: c = '4'; break; /* R4 */
606: case KC_KEYPAD_5: c = '5'; break; /* R5 */
607: case KC_KEYPAD_6: c = '6'; break; /* R6 */
608: case KC_KEYPAD_7: c = '7'; break; /* R7 */
609: case KC_KEYPAD_8: c = '8'; break; /* R8 */
610: case KC_KEYPAD_9: c = '9'; break; /* R9 */
611: case KC_KEYPAD_MINUS: c = '-'; break; /* R- */
612:
613: default:
614: {
615: char *string;
616: int nbytes;
617: string = XLookupMapping (&event, &nbytes);
618: if (nbytes == 1)
619: c = *string;
620: else
621: continue;
622: }
623: }
624: }
625: #else XWIND
626: /* adjust place of page on screen so it is centered */
627: /* will clip the edges of imagen300 pages */
628: pr_rop(ptube, 0, 0, ptubew, ptubeh, PIX_SRC, pscreen, x, y);
629: if( !slide ) {
630: pr_rop(ptube, scr_x, 0, 4, ptubeh, PIX_NOT(PIX_SRC),
631: side, 0, 0);
632: page_icon(y);
633: }
634: /* have a look */
635: c = getchar();
636: if( c == 033 ){ /* fixup for SUN 120 keypad */
637: c = getchar();
638: if(c == '[') c = getchar();
639: if(c == '2') c = getchar();
640: if(c == '2'){
641: c = getchar() + 1;
642: (void) getchar();
643: }
644: else if(c == '1'){
645: c = getchar() + 3;
646: (void) getchar();
647: }
648: }
649: #endif XWIND
650: switch(c){
651: case 04:
652: case 03:
653: return(-1); /* quit on EOF or ^C */
654: case '1':
655: y++;
656: break;
657: case '7':
658: y--;
659: break;
660: case 0102:
661: case '2':
662: y += 65;
663: break;
664: case 0101:
665: case '8':
666: y -= 65;
667: break;
668: case '3':
669: y = scr_y - ptubeh -1;
670: break;
671: case '9':
672: y = 0;
673: break;
674: case '4':
675: x = 0;
676: break;
677: case '5':
678: if((x = (scr_x - ptubew)/2) < 0) x = 0;
679: break;
680: case '6':
681: if((x = scr_x - ptubew) < 0) x = 0;
682: break;
683: case '<':
684: x -= 65;
685: break;
686: case '>':
687: x += 65;
688: break;
689: case 'l':
690: x -= ptubew;
691: break;
692: case 'r':
693: x += ptubew;
694: break;
695: case 'd':
696: if (y < scr_y - 1 - ptubeh) {
697: y += ptubeh;
698: break;
699: }
700: /* falls into */
701: case '.':
702: if (pages && page != finish) {
703: page = (page +1)%pages;
704: (void)lseek(screens, scr_size * page, 0);
705: (void)read(screens, scptr, scr_size);
706: y = 0;
707: break;
708: }
709: /* falls into */
710: case '+':
711: case ',':
712: if (pages && page == finish) {
713: (void)lseek(screens, scr_size * page, 0);
714: (void)write(screens, scptr, scr_size);
715: }
716: if (pages){
717: page = finish = (finish +1)%pages;
718: if(start == finish) start = (start + 1)%pages;
719: }
720: /*blank the memory where screen image is built*/
721: z=scptr;
722: for (i=scr_size;i--;) *z++ = backcolor;
723: return(0);
724: case 'u':
725: if (y > 0) {
726: y -= ptubeh;
727: break;
728: }
729: /* falls into */
730: case '-':
731: if (pages == 0 || page == start) {
732: #ifndef XWIND
733: if (y == 0)
734: fprintf(stderr, "can not back up more\n");
735: #endif XWIND
736: y = 0;
737: }else{
738: if(page == finish) {
739: (void)lseek(screens, scr_size * page, 0);
740: (void)write(screens, scptr, scr_size);
741: }
742: page = (page==0? (pages-1):(page -1))%pages;
743: (void)lseek(screens, scr_size * page, 0);
744: (void)read(screens, scptr, scr_size);
745: if (c == '-')
746: y = 0;
747: else
748: y = scr_y - 1 - ptubeh;
749: }
750: break;
751: default:
752: break;
753: }
754: if (x < 0) x = 0;
755: else if (x >= scr_x - ptubew) x = scr_x - 1 - ptubew;
756: if (y < 0) y = 0;
757: else if (y >= scr_y - ptubeh) y = scr_y - 1 - ptubeh;
758: #ifdef XWIND
759: } while (QLength() > 0);
760: #endif
761: }
762: }
763:
764: /* get a character from the input file */
765: gc()
766: {
767: static int len = 0;
768:
769: if(macro_on == TRUE) {
770: /* macro in effect read from its code*/
771: if(macro_length == macro_count+1) macro_on = FALSE;
772: return(mp[macro_count++]);
773: }
774: else {
775: /*read from the input file */
776: if(in_bufp <= &in_buf[len-1]) {
777: return(*in_bufp++);
778: }
779: len = read(s, in_buf, 512);
780: if(len == 0) {
781: fprintf(stderr,"No such job\n");
782: (void)fflush(stderr);
783: get_out();
784: }
785: else if(len < 0) {
786: perror("impv: read failed");
787: get_out();
788: }
789:
790: in_bufp = in_buf;
791: winker();
792: return(*in_bufp++);
793: }
794: }
795:
796: get_out()
797: {
798: /*reset keyboard*/
799: #ifdef XWIND
800: XDestroyWindow (Win);
801: #else XWIND
802: (void)stty(0, &cbreak);
803: if(pscreen != NULL) pr_close(pscreen);
804: if(ptube != NULL) pr_close(ptube);
805: printf("\n");
806: #endif XWIND
807: if(big || little)
808: printf("%d pixels/glyphs/lines would be off the page\n",
809: big + little);
810: if (screens && unlink(screen_file) < 0)
811: printf("%s not removed\n", screen_file);
812: exit(0);
813: }
814:
815: winker()
816: {
817: #ifdef XWIND
818: XPixFill(Win, ptubew / 2 - 8, ptubeh - 50, 16, 16, 0, NULL, GXinvert, 1);
819: XFlush();
820: #else XWIND
821: pr_rop(ptube, 450, 780, 16, 16, PIX_NOT(PIX_SRC), NULL, 0, 0);
822: #endif XWIND
823: }
824:
825: #ifdef XWIND
826: unsigned char outbuf[CHUNKSIZE];
827:
828: BitsPut (srcx, srcy, dstx, dsty, width, height)
829: int srcx, srcy, dstx, dsty, width, height;
830: {
831: register unsigned char *data, *ptr;
832: register int i, per, delta;
833: int linesize;
834:
835: linesize = (scr_x + 7) >> 3;
836: dstx -= (srcx & 7);
837: width += (srcx & 7);
838: srcx &= ~7;
839: data = &pscreen[(srcy*linesize) + (srcx>>3)];
840:
841: per = BitmapSize(width, 1);
842: delta = CHUNKSIZE / per;
843:
844: while (height) {
845: if (height < delta)
846: delta = height;
847: for (ptr = outbuf, i = delta;
848: --i >= 0;
849: data += linesize, ptr += per)
850: bcopy(data, ptr, per);
851: XBitmapBitsPut(Win, dstx, dsty, width, delta, outbuf,
852: forepix, backpix, NULL, GXcopy, AllPlanes);
853: dsty += delta;
854: height -= delta;
855: }
856: }
857: #endif XWIND
858:
859: #ifndef XWIND
860: page_icon(y)
861: int y;
862: {
863: int h, i;
864:
865: i = 43 * ptubeh / scr_y;
866: pr_rop(picon, 0 , 0, 46, 53, PIX_NOT(PIX_SRC), NULL, 0, 0);
867: pr_rop(picon, 2 , 2, 42, 49, PIX_CLR, NULL, 0, 0);
868: pr_rop(picon, 6 , 4, 34, 45, PIX_NOT(PIX_SRC), NULL, 0, 0);
869: h = 44 * y / scr_y;
870: pr_rop(picon, 5, 5+h, 36, i, PIX_NOT(PIX_SRC), picon, 5, 5+h);
871: pr_rop(ptube, ptubew-46, ptubeh/2, 46, 53, PIX_SRC, picon, 0, 0);
872: }
873: #endif
874:
875: #ifdef COLOR
876: /*
877: set color
878: */
879: unsigned char
880: setcolor(code)
881: register short int code;
882: {
883: register unsigned char color;
884: register float c1,c2;
885:
886: c1 = (float)(5 - code) / 255.;
887: c2 = (float)code / 255.;
888: color = 36 * ((int)(bc.red * c1 + .5) + (int)(cc.red * c2 + .5))
889: + 6 * ((int)(bc.green * c1 + .5) + (int)(cc.green * c2 + .5))
890: + ((int)(bc.blue * c1 + .5) + (int)(cc.blue * c2 + .5));
891: return(color);
892: }
893: #endif COLOR
894:
895: usage()
896: {
897: #ifdef NOSPOOL
898: #ifdef COLOR
899: printf("usage: impv [-p#] [-s] [file]\n");
900: #else COLOR
901: #ifdef XWIND
902: printf("usage: ximpv [=<geometry>] [-p#] [-rv] [-fg <color>] [-bg <color>] [-bd <color>] [-ms <color>] [host:display] [file]\n");
903: #else XWIND
904: printf("usage: impv [-p#] [file]\n");
905: #endif XWIND
906: #endif COLOR
907: (void)fflush(stdout);
908: exit(0);
909: #else NOSPOOL
910: #ifdef COLOR
911: printf("usage: impv [-p#] [-s] [-r] [idnumber | -n name]\n");
912: #else COLOR
913: printf("usage: impv [-p#] [-r] [idnumber | -n name]\n");
914: #endif COLOR
915: (void)fflush(stdout);
916: get_out();
917: #endif NOSPOOL
918: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.