home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Tex / Dvi / dvieps.arc / PRTPAGE.H < prev    next >
Text File  |  1988-10-16  |  8KB  |  300 lines

  1. /* -*-C-*- prtpage.h */
  2. /*-->prtpage*/
  3. /**********************************************************************/
  4. /****************************** prtpage *******************************/
  5. /**********************************************************************/
  6.  
  7. void
  8. prtpage(bytepos)        /* print page whose BOP is at bytepos */
  9. long bytepos;
  10.  
  11. {
  12.     struct stack_entry
  13.     {
  14.     INT32 h;
  15.     COORDINATE hh;
  16.     INT32 v;
  17.     COORDINATE vv;
  18.     INT32 w, x, y, z;    /* what's on stack */
  19.     };
  20.     register BYTE command;  /* current command                */
  21.     register INT16 i;        /* command parameter; loop index        */
  22.     char tc;            /* temporary character            */
  23.     UNSIGN32 ht_rule;        /* rule height                              */
  24.     UNSIGN32 wd_rule;        /* rule width                               */
  25.     INT32 k,m;            /* temporary parameter            */
  26.     BOOLEAN seen_bop;        /* flag for noting processing of BOP    */
  27.     register INT16 sp;        /* stack pointer                */
  28.     struct stack_entry stack[STACKSIZE];    /* stack            */
  29.     char specstr[MAXSPECIAL+1];        /* \special{} string        */
  30.     INT32 w;            /* current horizontal spacing        */
  31.     INT32 x;            /* current horizontal spacing        */
  32.     INT32 y;            /* current vertical spacing            */
  33.     INT32 z;            /* current vertical spacing            */
  34.  
  35. /***********************************************************************
  36. Process all commands  between the  BOP at bytepos  and the  next BOP  or
  37. POST.  The page is  printed when the  EOP is met,  but font changes  can
  38. also happen between EOP and BOP, so we have to keep going after EOP.
  39. ***********************************************************************/
  40.  
  41.     seen_bop = FALSE;            /* this is first time through */
  42.     (void) FSEEK(dvifp,bytepos,0);    /* start at the desired position */
  43.  
  44.     for (;;)    /* "infinite" loop - exits when POST or second BOP met */
  45.     {
  46. #if    BBNBITGRAPH
  47.     /* If the test here on every byte proves to carry objectionable
  48.        overhead, it can be moved into the default, PUTx, and SETx
  49.        command sections. The goal is to give the user instant
  50.        response in page screen positioning, without having to wait
  51.        for the entire screen to be painted when it is just going
  52.        to be moved anyway.  This is the sort of display algorithm
  53.        that EMACS uses. */
  54.     if (kbinput() > 0)    /* user has typed something */
  55.         command = EOP;    /* so set for end-of-page action */
  56.     else
  57. #endif
  58.     command = (BYTE)nosignex(dvifp,(BYTE)1);
  59.     switch (command)
  60.     {
  61.  
  62.     case SET1:
  63.     case SET2:
  64.     case SET3:
  65.     case SET4:
  66.         (void)setchar((BYTE)nosignex(dvifp,(BYTE)(command-SET1+1)),TRUE);
  67.         break;
  68.  
  69.     case SET_RULE:
  70.         ht_rule = nosignex(dvifp,(BYTE)4);
  71.         wd_rule = nosignex(dvifp,(BYTE)4);
  72.         (void)setrule(ht_rule,wd_rule,TRUE);
  73.         break;
  74.  
  75.     case PUT1:
  76.     case PUT2:
  77.     case PUT3:
  78.     case PUT4:
  79.         (void)setchar((BYTE)nosignex(dvifp,(BYTE)(command-PUT1+1)),FALSE);
  80.         break;
  81.  
  82.     case PUT_RULE:
  83.         ht_rule = nosignex(dvifp,(BYTE)4);
  84.         wd_rule = nosignex(dvifp,(BYTE)4);
  85.         (void)setrule(ht_rule,wd_rule,FALSE);
  86.         break;
  87.  
  88.     case NOP:
  89.         break;
  90.  
  91.     case BOP:
  92.         if (seen_bop)
  93.         return;            /* we have been here already */
  94.         seen_bop = TRUE;
  95.  
  96.         for (i=0; i<=9; i++)
  97.         tex_counter[i] = (INT32)signex(dvifp,(BYTE)4);
  98.  
  99. #if    BBNBITGRAPH
  100.         (void)bopact();        /* display menu at top of page */
  101. #else /* not BBNBITGRAPH */
  102.  
  103. #if    (CANON_A2 | HPJETPLUS | IMPRESS | POSTSCRIPT)
  104.         (void)bopact();
  105. #else /* NOT (CANON_A2 | HPJETPLUS | IMPRESS | POSTSCRIPT) */
  106.         (void)clrbmap();
  107. #endif /* (CANON_A2 | HPJETPLUS | IMPRESS | POSTSCRIPT) */
  108.  
  109.         if (!quiet)
  110.             (void)fprintf(stderr,"{%s}",tctos()); /* TeX page counters */
  111.         (void) nosignex(dvifp,(BYTE)4);    /* skip prev. page ptr */
  112. #endif /* BBNBITGRAPH */
  113.  
  114.         h = v = w = x = y = z = 0;
  115.         hh = lmargin;
  116.         vv = tmargin;
  117.         sp = 0;
  118.         fontptr = (struct font_entry*)NULL;
  119.         break;
  120.  
  121.     case EOP:
  122.  
  123. #if    (BBNBITGRAPH | CANON_A2 | HPJETPLUS | IMPRESS | POSTSCRIPT)
  124.         (void)eopact();
  125. #else
  126.         (void)prtbmap();
  127. #endif /* (BBNBITGRAPH | CANON_A2 | HPJETPLUS | IMPRESS | POSTSCRIPT) */
  128.  
  129.         return;
  130.  
  131.     case PUSH:
  132.         if (sp >= STACKSIZE)
  133.         (void)fatal("prtpage():  stack overflow");
  134.         stack[sp].h = h;
  135.         stack[sp].hh = hh;
  136.         stack[sp].v = v;
  137.         stack[sp].vv = vv;
  138.         stack[sp].w = w;
  139.         stack[sp].x = x;
  140.         stack[sp].y = y;
  141.         stack[sp].z = z;
  142.         sp++;
  143.         break;
  144.  
  145.     case POP:
  146.         --sp;
  147.         if (sp < 0)
  148.         (void)fatal("prtpage():  stack underflow");
  149.         h = stack[sp].h;
  150.         hh = stack[sp].hh;
  151.         v = stack[sp].v;
  152.         vv = stack[sp].vv;
  153.         w = stack[sp].w;
  154.         x = stack[sp].x;
  155.         y = stack[sp].y;
  156.         z = stack[sp].z;
  157.         break;
  158.  
  159.     case RIGHT1:
  160.     case RIGHT2:
  161.     case RIGHT3:
  162.     case RIGHT4:
  163.         (void)moveover(signex(dvifp,(BYTE)(command-RIGHT1+1)));
  164.         break;
  165.  
  166.     case W0:
  167.         (void)moveover(w);
  168.         break;
  169.  
  170.     case W1:
  171.     case W2:
  172.     case W3:
  173.     case W4:
  174.         w = (INT32)signex(dvifp,(BYTE)(command-W1+1));
  175.         (void)moveover(w);
  176.         break;
  177.  
  178.     case X0:
  179.         (void)moveover(x);
  180.         break;
  181.  
  182.     case X1:
  183.     case X2:
  184.     case X3:
  185.     case X4:
  186.         x = (INT32)signex(dvifp,(BYTE)(command-X1+1));
  187.         (void)moveover(x);
  188.         break;
  189.  
  190.     case DOWN1:
  191.     case DOWN2:
  192.     case DOWN3:
  193.     case DOWN4:
  194.         (void)movedown(signex(dvifp,(BYTE)(command-DOWN1+1)));
  195.         break;
  196.  
  197.     case Y0:
  198.         (void)movedown(y);
  199.         break;
  200.  
  201.     case Y1:
  202.     case Y2:
  203.     case Y3:
  204.     case Y4:
  205.         y = signex(dvifp,(BYTE)(command-Y1+1));
  206.         (void)movedown(y);
  207.         break;
  208.  
  209.     case Z0:
  210.         (void)movedown(z);
  211.         break;
  212.  
  213.     case Z1:
  214.     case Z2:
  215.     case Z3:
  216.     case Z4:
  217.         z = signex(dvifp,(BYTE)(command-Z1+1));
  218.         (void)movedown(z);
  219.         break;
  220.  
  221.     case FNT1:
  222.     case FNT2:
  223.     case FNT3:
  224.     case FNT4:
  225.         (void)setfntnm((INT32)nosignex(dvifp,
  226.         (BYTE)(command-FNT1+1)));
  227.         break;
  228.  
  229.     case XXX1:
  230.     case XXX2:
  231.     case XXX3:
  232.     case XXX4:
  233.         k = (INT32)nosignex(dvifp,(BYTE)(command-XXX1+1));
  234.         if (k > MAXSPECIAL)
  235.         {
  236.         (void)sprintf(message,
  237.             "prtpage():  \\special{} string of %d characters longer \
  238. than DVI driver limit of %d -- truncated.",
  239.         k,MAXSPECIAL);
  240.         (void)warning(message);
  241.         }
  242.         m = 0;
  243.         while (k--)
  244.         {
  245.          tc = (char)nosignex(dvifp,(BYTE)1);
  246.          if (m < MAXSPECIAL)
  247.              specstr[m++] = tc;
  248.         }
  249.         specstr[m] = '\0';
  250.          (void) special(specstr);
  251.         break;
  252.  
  253.     case FNT_DEF1:
  254.     case FNT_DEF2:
  255.     case FNT_DEF3:
  256.     case FNT_DEF4:
  257.         if (preload)
  258.         (void)skipfont ((INT32) nosignex(dvifp,
  259.             (BYTE)(command-FNT_DEF1+1)));
  260.         else
  261.         (void)readfont ((INT32) nosignex(dvifp,
  262.             (BYTE)(command-FNT_DEF1+1)));
  263.         break;
  264.  
  265.     case PRE:
  266.         (void)fatal("prtpage():  PRE occurs within file");
  267.         break;
  268.  
  269.     case POST:
  270.         (void)devterm();        /* terminate device output */
  271.         (void)dviterm();        /* terminate DVI file processing */
  272.         (void)alldone();        /* this will never return */
  273.         break;
  274.  
  275.     case POST_POST:
  276.         (void)fatal("prtpage():  POST_POST with no preceding POST");
  277.         break;
  278.  
  279.     default:
  280.         if (command >= FONT_00 && command <= FONT_63)
  281.         (void)setfntnm((INT32)(command - FONT_00));
  282.         else if (command >= SETC_000 && command <= SETC_127)
  283.  
  284. #if    (HPJETPLUS | POSTSCRIPT | IMPRESS | CANON_A2)
  285.         (void)setstr((BYTE)command); /* this sets several chars */
  286. #else
  287.         (void)setchar((BYTE)(command-SETC_000), TRUE);
  288. #endif /* (HPJETPLUS | POSTSCRIPT | IMPRESS | CANON_A2) */
  289.  
  290.         else
  291.         {
  292.         (void)sprintf(message,"prtpage():  %d is an undefined command",
  293.             command);
  294.         (void)fatal(message);
  295.         }
  296.         break;
  297.     }
  298.     }
  299. }
  300.