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

Defined functions

BitsPut defined in line 826; used 6 times
gc defined in line 763; used 24 times
get_out defined in line 794; used 16 times
main defined in line 113; never used
page_icon defined in line 858; used 1 times
ppause defined in line 480; used 1 times
setcolor defined in line 877; used 9 times
usage defined in line 893; used 3 times
winker defined in line 813; used 3 times

Defined variables

Select_mask defined in line 88; used 3 times
Win defined in line 91; used 12 times
backpix defined in line 89; used 6 times
cbreak defined in line 108; used 7 times
current_page defined in line 476; used 6 times
current_x defined in line 477; used 14 times
diameter defined in line 103; never used
forepix defined in line 89; used 4 times
impv_bits defined in line 94; used 2 times
  • in line 391(2)
in_buf defined in line 106; used 4 times
in_bufp defined in line 106; used 5 times
map8_4 defined in line 68; never used
maxplus1 defined in line 88; used 2 times
outbuf defined in line 824; used 2 times
pages defined in line 104; used 13 times
picon defined in line 100; used 7 times
ptube defined in line 100; used 11 times
ptubeh defined in line 107; used 30 times
ptubew defined in line 107; used 29 times
rcsid_impv_c defined in line 39; never used
rot8 defined in line 441; used 1 times
s defined in line 109; used 11 times
screen_file defined in line 105; used 8 times
screens defined in line 111; used 12 times
side defined in line 100; used 2 times
tty defined in line 110; used 1 times
win defined in line 90; used 6 times

Defined macros

CHUNKSIZE defined in line 48; used 2 times
impv_height defined in line 93; used 1 times
impv_width defined in line 92; used 1 times
min defined in line 47; used 4 times
Last modified: 1986-01-08
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2593
Valid CSS Valid XHTML 1.0 Strict