home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Tex / Tex29 / StTeXsrc.zoo / src / print.c < prev    next >
C/C++ Source or Header  |  1988-03-13  |  6KB  |  329 lines

  1.  
  2. /*
  3.  * @(#)print.c 2.5 EPA
  4.  *
  5.  * Copyright 1987,1988 Pat J Monardo
  6.  *
  7.  * Redistribution of this file is permitted through
  8.  * the specifications in the file COPYING.
  9.  *
  10.  * 
  11.  */
  12.  
  13. #include "tex.h"
  14. #include "texext.h"
  15.  
  16. alpha_file  log_file;
  17.  
  18. char    dig[23];
  19. int     file_offset;
  20. val     first_count;
  21. int     selector = TERM_ONLY;
  22. val     tally;
  23. int     term_offset;
  24. ascii   trick_buf[ERROR_LINE];
  25. val     trick_count;
  26.  
  27. print_ln ()
  28. {
  29.     switch (selector)
  30.     {
  31.     case TERM_AND_LOG:
  32.         wterm_cr();
  33.         term_offset = 0;
  34.         wlog_cr();
  35.         file_offset = 0;
  36.         break;
  37.  
  38.     case LOG_ONLY:
  39.         wlog_cr();
  40.         file_offset = 0;
  41.         break;
  42.  
  43.     case TERM_ONLY:
  44.         wterm_cr();
  45.         term_offset = 0;
  46.         break;
  47.  
  48.     case NO_PRINT:
  49.     case PSEUDO:
  50.     case NEW_STRING:
  51.         break;
  52.  
  53.     default:
  54.         wfile_cr();
  55.         break;
  56.     }
  57. }   
  58.  
  59. print_char (c)
  60.     ascii   c;
  61. {
  62.     if (c == new_line_char && selector < PSEUDO) {
  63.         print_ln();
  64.         return;
  65.     }
  66.     switch (selector)
  67.     {
  68.     case TERM_AND_LOG:
  69.         wterm(xchr[c]);
  70.         incr(term_offset);
  71.         wlog(xchr[c]);
  72.         incr(file_offset);
  73.         if (term_offset == MAX_PRINT_LINE) {
  74.             wterm_cr();
  75.             term_offset = 0;
  76.         }
  77.         if (file_offset == MAX_PRINT_LINE) {
  78.             wlog_cr();
  79.             file_offset = 0;
  80.         }
  81.         break;
  82.  
  83.     case LOG_ONLY:
  84.         wlog(xchr[c]);
  85.         incr(file_offset);
  86.         if (file_offset == MAX_PRINT_LINE)
  87.             print_ln();
  88.         break;
  89.  
  90.     case TERM_ONLY:
  91.         wterm(xchr[c]);
  92.         incr(term_offset);
  93.         if (term_offset == MAX_PRINT_LINE)
  94.             print_ln();
  95.         break;
  96.  
  97.     case NO_PRINT:
  98.         return;
  99.  
  100.     case PSEUDO:
  101.         if (tally < trick_count) 
  102.             trick_buf[tally % ERROR_LINE] = c;
  103.         break;
  104.  
  105.     case NEW_STRING:
  106.         if (pool_ptr < POOL_SIZE) 
  107.             append_char(c);
  108.         break;
  109.  
  110.     default:
  111.         wfile(xchr[c]);
  112.         break;
  113.     }
  114.     incr(tally);
  115. }
  116.  
  117. print_ASCII (c)
  118.     int      c;
  119. {
  120.     if (c >= 0 && c <= 127) {
  121.         print_str(c);
  122.     } else {
  123.         print_char('[');
  124.         if (c < 0)
  125.             print_int(c);
  126.         else print_hex((val) c);
  127.         print_char(']');
  128.     }
  129. }
  130.  
  131. print_str (s)
  132.     str     s;
  133. {
  134.     int     j;
  135.  
  136.     if (s >= str_ptr) {
  137.         s = make_str_given("???");
  138.     } else if (s < 128) {
  139.         if (s < 0) {
  140.             s = make_str_given("???");
  141.         } else if (s == new_line_char && selector < PSEUDO) {
  142.             print_ln();
  143.             return;
  144.         }
  145.     }
  146.     j = str_start[s];
  147.     while (j < str_start[s + 1]) {
  148.         print_char(str_pool[j]);
  149.         incr(j);
  150.     }
  151. }
  152.  
  153. slow_print (s)
  154.     str     s;
  155. {
  156.     int     j;
  157.  
  158.     if (s >= str_ptr) {
  159.         s = make_str_given("???");
  160.     } else if (s < 128) {
  161.         if (s < 0) {
  162.             s = make_str_given("???");
  163.         } else if (s == new_line_char && selector < PSEUDO) {
  164.             print_ln();
  165.             return;
  166.         }
  167.     }
  168.     j = str_start[s];
  169.     while (j < str_start[s + 1]) {
  170.         print_str(str_pool[j]);
  171.         incr(j);
  172.     }
  173. }
  174.  
  175. print (s)
  176.     chrs    s;
  177. {
  178.     while (*s) { 
  179.         print_char(*s);
  180.         incr(s);
  181.     }
  182. }
  183.  
  184. print_nl (s)
  185.     chrs    s;
  186. {
  187.     if (term_offset > 0 && odd(selector) ||
  188.         file_offset > 0 && selector >= LOG_ONLY)
  189.         print_ln();
  190.     print(s);
  191. }
  192.  
  193. print_esc (s)
  194.     chrs    s;
  195. {
  196.     ascii   c;
  197.  
  198.     c = escape_char;
  199.     if (c >= 0 && c < 128) 
  200.         print_str(c);
  201.     print(s);
  202. }
  203.  
  204. print_int (n)
  205.     int     n;
  206. {
  207.     int     k;
  208.     int     m;
  209.  
  210.     k = 0;
  211.     if (n < 0)  {
  212.         print_char('-');
  213.         negate(n);
  214.     }
  215.     do {
  216.         dig[k] = n % 10;
  217.         n /= 10;
  218.         incr(k);
  219.     } while (n != 0);
  220.     print_the_digs(k);
  221. }
  222.  
  223. print_val (n)
  224.     val     n;
  225. {
  226.     int     k;
  227.     val     m;
  228.  
  229.     k = 0;
  230.     if (n < 0)  {
  231.         print_char('-');
  232.         if (n > -100000000) {
  233.             negate(n);
  234.         } else {
  235.             m = -1 - n;
  236.             n = m / 10;
  237.             m = m % 10 + 1;
  238.             k = 1;
  239.             if (m < 10)
  240.                 dig[0] = m;
  241.             else {
  242.                 dig[0] = 0;
  243.                 incr(n);
  244.             }
  245.         }
  246.     }
  247.     do {
  248.         dig[k] = n % 10;
  249.         n /= 10;
  250.         incr(k);
  251.     } while (n != 0);
  252.     print_the_digs(k);
  253. }
  254.  
  255. print_hex (v)
  256.     val     v;
  257. {
  258.     int     k;
  259.  
  260.     k = 0;
  261.     print_char('"');
  262.     do {
  263.         dig[k] = v&15;
  264.         v >>= 4;
  265.         incr(k);
  266.     } while (v != 0);
  267.     print_the_digs(k);
  268. }
  269.  
  270. print_the_digs (k)
  271.     int      k;
  272. {
  273.     while (k > 0) {
  274.         decr(k);
  275.         if (dig[k] < 10)
  276.             print_char('0' + dig[k]);
  277.         else print_char('A' - 10 + dig[k]);
  278.     }
  279. }
  280.  
  281. print_two (n)
  282.     int     n;
  283. {
  284.     n = abs(n) % 100;
  285.     print_char('0' + n / 10);
  286.     print_char('0' + n % 10);
  287. }
  288.  
  289. print_roman_int (n)
  290.     val     n;
  291. {
  292.     chrs    j = "m2d5c2l5x2v5i";
  293.     chrs    k;
  294.     val     u;
  295.     val     v = 1000;
  296.  
  297.     loop {
  298.         while (n >= v) {
  299.             print_char(*j);
  300.             n -= v;
  301.         }
  302.         if (n <= 0) return;
  303.         k = j + 2;
  304.         u = v / (*(k - 1) - '0');
  305.         if (*(k - 1) == '2')  {
  306.             k += 2;
  307.             u /= *(k - 1) - '0';
  308.         }
  309.         if (n + u >= v)  {
  310.             print_char(*k);
  311.             n += u;
  312.         } else {
  313.             j += 2;
  314.             v /= *(j - 1) - '0';
  315.         }
  316.     }
  317. }
  318.  
  319. print_cur_str ()
  320. {
  321.     int     j;
  322.  
  323.     j = str_start[str_ptr];
  324.     while (j < pool_ptr) {
  325.         print_char(str_pool[j]);
  326.         incr(j);
  327.     }
  328. }
  329.