home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / CMTEX330 / SOURCE / TEXEXT.C < prev    next >
C/C++ Source or Header  |  1992-02-19  |  8KB  |  546 lines

  1.  
  2. /*
  3.  * %Y%:%M%:%I%:%Q%
  4.  *
  5.  * Copyright 1987,1988,1991 Pat J Monardo
  6.  *
  7.  * Redistribution of this file is permitted through
  8.  * the specifications in the file COPYING.
  9.  *
  10.  *
  11.  */
  12.  
  13. #ifndef lint
  14. static char *sccsid = "%A%";
  15. #endif
  16.  
  17. #include "tex.h"
  18.  
  19. file    write_file[16];
  20. bool    write_open[18];
  21.  
  22. sym    write_cs;
  23.  
  24. void
  25. do_extension ()
  26. {
  27.     switch (cur_chr) {
  28.     case OPEN_NODE: do_open(); break;
  29.     case WRITE_NODE: do_write(); break;
  30.     case CLOSE_NODE: do_close(); break;
  31.     case SPECIAL_NODE: do_special(); break;
  32.     case IMMEDIATE_CODE: do_immediate(); break;
  33.     case SET_LANGUAGE_CODE: do_set_language(); break;
  34.     default: confusion("ext1");
  35.     }
  36. }
  37.  
  38. void
  39. do_immediate ()
  40. {
  41.     ptr    p;
  42.  
  43.     get_x_token();
  44.     if (cur_cmd == EXTENSION && cur_chr <= CLOSE_NODE) {
  45.         p = tail;
  46.         do_extension();
  47.         out_whatsit(tail);
  48.         flush_node_list(tail);
  49.         tail = p;
  50.         link(p) = null;
  51.     } else {
  52.         back_input();
  53.     }
  54. }
  55.  
  56. void
  57. show_whatsit (p)
  58.     ptr    p;
  59. {
  60.     switch (subtype(p)) {
  61.     case OPEN_NODE: show_open(p); break;
  62.     case WRITE_NODE: show_write(p); break;
  63.     case CLOSE_NODE: show_close(p); break;
  64.     case SPECIAL_NODE: show_special(p); break;
  65.     case LANGUAGE_NODE: show_language(p); break;
  66.     default:print("whatsit?");break;
  67.     }
  68. }
  69.  
  70. ptr
  71. copy_whatsit (p)
  72.     ptr    p;
  73. {
  74.     switch (subtype(p)) {
  75.     case OPEN_NODE: return(copy_open(p));
  76.     case WRITE_NODE: return(copy_write(p));
  77.     case CLOSE_NODE: return(copy_close(p));
  78.     case SPECIAL_NODE: return(copy_special(p));
  79.     case LANGUAGE_NODE: return(copy_language(p));
  80.     default:confusion("ext2");
  81.     }
  82.     /*NOTREACHED*/
  83. }
  84.  
  85. void
  86. free_whatsit (p)
  87.     ptr    p;
  88. {
  89.     switch (subtype(p)) {
  90.     case OPEN_NODE: free_open(p); break;
  91.     case WRITE_NODE: free_write(p); break;
  92.     case CLOSE_NODE: free_close(p); break;
  93.     case SPECIAL_NODE: free_special(p); break;
  94.     case LANGUAGE_NODE: free_language(p); break;
  95.     default:confusion("ext3");
  96.     }
  97. }
  98.  
  99. #define adv_past(P) \
  100. {    if (subtype(P) == LANGUAGE_NODE) { \
  101.         cur_lang = what_lang(P); \
  102.         l_hyf = what_lhm(P); \
  103.         r_hyf = what_rhm(P); \
  104.     } \
  105. }
  106.  
  107. void
  108. line_break_whatsit (p)
  109.     ptr    p;
  110. {
  111.     adv_past(p);
  112. }
  113.  
  114. void
  115. try_hyph_whatsit (p)
  116.     ptr    p;
  117. {
  118.     adv_past(p);
  119. }
  120.  
  121. void
  122. out_whatsit (p)
  123.     ptr    p;
  124. {
  125.     switch (subtype(p)) {
  126.     case OPEN_NODE: out_open(p); break;
  127.     case WRITE_NODE: out_write(p); break;
  128.     case CLOSE_NODE: out_close(p); break;
  129.     case SPECIAL_NODE: out_special(p); break;
  130.     case LANGUAGE_NODE:  out_language(p); break;
  131.     default: confusion("ext4");
  132.     }
  133. }
  134.  
  135. void
  136. append_whatsit (s, w)
  137.     int    s;
  138.     int    w;
  139. {
  140.     ptr    p;
  141.  
  142.     p = new_node(w);
  143.     type(p) = WHATSIT_NODE;
  144.     subtype(p) = s;
  145.     tail_append(p);
  146. }
  147.  
  148. void
  149. do_open ()
  150. {
  151.     append_whatsit(cur_chr, OPEN_NODE_SIZE);
  152.     scan_four_bit_int();
  153.     open_stream(tail) = cur_val;
  154.     scan_optional_equals();
  155.     scan_file_name();
  156.     open_name(tail) = cur_name;
  157.     open_area(tail) = cur_area;
  158.     open_ext(tail) = cur_ext;
  159. }
  160.  
  161. void
  162. show_open (p)
  163.     ptr    p;
  164. {
  165.     print_esc("openout");
  166.     if (open_stream(p) < 16) {
  167.         print_int(open_stream(p));
  168.     } else if (open_stream(p) == 16) {
  169.         print("*");
  170.     } else {
  171.         print("-");
  172.     }
  173.     print("=");
  174.     print_file_name(open_name(p), open_area(p), open_ext(p));
  175. }
  176.  
  177. ptr
  178. copy_open (p)
  179.     ptr    p;
  180. {
  181.     ptr    q;
  182.  
  183.     q = new_node(OPEN_NODE_SIZE);
  184.     memcpy((void *) q, (void *) p, OPEN_NODE_SIZE);
  185.  
  186.     return q;
  187. }
  188.  
  189. void
  190. free_open (p)
  191. {
  192.     free_node(p, OPEN_NODE_SIZE);
  193. }
  194.  
  195. void
  196. out_open (p)
  197.     ptr    p;
  198. {
  199.     int    j;
  200.  
  201.     if (doing_leaders)
  202.         return;
  203.     j = open_stream(p);
  204.     cur_name = open_name(p);
  205.     cur_area = open_area(p);
  206.     cur_ext = open_ext(p);
  207.     if (cur_ext == null_str) {
  208.         cur_ext = str_tex;
  209.     }
  210.     if (cur_area == null_str) {
  211.         cur_area = job_area;
  212.     }
  213.     pack_cur_name();
  214.     if ((write_file[j] = a_open_out()) == null_file) {
  215.         cur_area = null_str;
  216.         pack_cur_name();
  217.         while ((write_file[j] = a_open_out()) == null_file) {
  218.             prompt_file_name("output file name", str_tex);
  219.         }
  220.     }
  221.     write_open[j] = TRUE;
  222. }
  223.  
  224. void
  225. do_write ()
  226. {
  227.     sym    s;
  228.  
  229.     s = cur_cs;
  230.     append_whatsit(cur_chr, WRITE_NODE_SIZE);
  231.     scan_int();
  232.     if (cur_val < 0) {
  233.         cur_val = 17;
  234.     } else if (cur_val > 15) {
  235.         cur_val = 16;
  236.     }
  237.     write_stream(tail) = cur_val;
  238.     cur_cs = s;
  239.     scan_toks(FALSE, FALSE);
  240.     write_toks(tail) = def_ref;
  241. }
  242.  
  243. void
  244. show_write (p)
  245.     ptr    p;
  246. {
  247.     print_esc("write");
  248.     if (write_stream(p) < 16) {
  249.         print_int(write_stream(p));
  250.     } else if (write_stream(p) == 16) {
  251.         print("*");
  252.     } else {
  253.         print("-");
  254.     }
  255.     print_mark(write_toks(p));
  256. }
  257.  
  258. ptr
  259. copy_write (p)
  260. {
  261.     ptr    q;
  262.  
  263.     q = new_node(WRITE_NODE_SIZE);
  264.     memcpy((void *) q, (void *) p, WRITE_NODE_SIZE);
  265.     add_token_ref(write_toks(p));
  266.  
  267.     return    q;
  268. }
  269.  
  270. void
  271. free_write (p)
  272. {
  273.     delete_token_ref(write_toks(p));
  274.     free_node(p, WRITE_NODE_SIZE);
  275. }
  276.  
  277. void
  278. out_write (p)
  279.     ptr    p;
  280. {
  281.     int    j;
  282.     ptr    q;
  283.     ptr    r;
  284.     int    old_mode;
  285.     int    old_setting;
  286.  
  287.     if (doing_leaders) {
  288.         return;
  289.     }
  290.     q = new_token();
  291.     token(q) = RIGHT_BRACE_TOKEN + '}';
  292.     r = new_token();
  293.     token_link(q) = r;
  294.     token(r) = END_WRITE_TOKEN;
  295.     ins_list(q);
  296.     begin_token_list(write_toks(p), WRITE_TEXT);
  297.     q = new_token();
  298.     token(q) = LEFT_BRACE_TOKEN + '{';
  299.     ins_list(q);
  300.     old_mode = mode;
  301.     mode = 0;
  302.     cur_cs = write_cs;
  303.     scan_toks(FALSE, TRUE);
  304.     get_token();
  305.     if (cur_tok != END_WRITE_TOKEN) {
  306.         print_err("Unbalanced write command");
  307.         help_unbal_write();
  308.         error();
  309.         do get_token();
  310.         while (cur_tok != END_WRITE_TOKEN);
  311.     }
  312.     mode = old_mode;
  313.     end_token_list();
  314.     old_setting = selector;
  315.     j = write_stream(p);
  316.     if (write_open[j]) {
  317.         selector = j;
  318.     } else {
  319.         if (j == 17 && selector == TERM_AND_LOG)
  320.             selector = LOG_ONLY;
  321.         print_nl(null_str);
  322.     }
  323.     token_show(def_ref);
  324.     print_ln();
  325.     flush_list(def_ref);
  326.     selector = old_setting;
  327. }
  328.  
  329. void
  330. do_close ()
  331. {
  332.     append_whatsit(cur_chr, CLOSE_NODE_SIZE);
  333.     scan_int();
  334.     if (cur_val < 0) {
  335.         cur_val = 17;
  336.     } else if (cur_val > 15) {
  337.         cur_val = 16;
  338.     }
  339.     write_stream(tail) = cur_val;
  340. }
  341.  
  342. void
  343. show_close (p)
  344.     ptr    p;
  345. {
  346.     print_esc("closeout");
  347.     if (write_stream(p) < 16) {
  348.         print_int(write_stream(p));
  349.     } else if (write_stream(p) == 16) {
  350.         print("*");
  351.     } else {
  352.         print("-");
  353.     }
  354. }
  355.  
  356. ptr
  357. copy_close (p)
  358.     ptr    p;
  359. {
  360.     ptr    q;
  361.  
  362.     q = new_node(CLOSE_NODE_SIZE);
  363.     memcpy((void *) q, (void *) p, CLOSE_NODE_SIZE);
  364.  
  365.     return    q;
  366. }
  367.  
  368. void
  369. free_close (p)
  370.     ptr    p;
  371. {
  372.     free_node(p, CLOSE_NODE_SIZE);
  373. }
  374.  
  375. void
  376. out_close (p)
  377.     ptr    p;
  378. {
  379.     int    j;
  380.  
  381.     if (!doing_leaders) {
  382.         j = write_stream(p);
  383.         if (write_open[j]) {
  384.             a_close(write_file[j]);
  385.             write_open[j] = FALSE;
  386.         }
  387.     }
  388. }
  389.  
  390. void
  391. do_special ()
  392. {
  393.     append_whatsit(SPECIAL_NODE, SPECIAL_NODE_SIZE);
  394.     scan_toks(FALSE, TRUE);
  395.     special_toks(tail) = def_ref;
  396. }
  397.  
  398. void
  399. show_special (p)
  400.     ptr    p;
  401. {
  402.     print_esc("special");
  403.     print_mark(special_toks(p));
  404. }
  405.  
  406. ptr
  407. copy_special (p)
  408.     ptr    p;
  409. {
  410.     ptr    q;
  411.  
  412.     q = new_node(SPECIAL_NODE_SIZE);
  413.     memcpy((void *)q, (void *)p, SPECIAL_NODE_SIZE);
  414.     add_token_ref(special_toks(p));
  415.  
  416.     return q;
  417. }
  418.  
  419. void
  420. free_special (p)
  421.     ptr    p;
  422. {
  423.     delete_token_ref(special_toks(p));
  424.     free_node(p, SPECIAL_NODE_SIZE);
  425. }
  426.  
  427. void
  428. out_special (p)
  429.     ptr    p;
  430. {
  431.     str    s;
  432.     int    old_setting;
  433.  
  434.     synch_h();
  435.     synch_v();
  436.     old_setting = selector;
  437.     selector = NEW_STRING;
  438.     show_token_list(token_link(special_toks(p)), null, MAX_STR_SIZE);
  439.     selector = old_setting;
  440.     if (cur_length() < 256) {
  441.         dvi_out(XXX1);
  442.         dvi_out(cur_length());
  443.     } else {
  444.         dvi_out(XXX4);
  445.         dvi_four(cur_length());
  446.     }
  447.     for (s = cur_str; s < cur_str_ptr; incr(s)) {
  448.         dvi_out(*s);
  449.     }
  450.     flush_str();
  451. }
  452.  
  453. void
  454. do_set_language ()
  455. {
  456.     if (abs(mode) != HMODE) {
  457.         report_illegal_case();
  458.         return;
  459.     }
  460.     scan_int();
  461.     if (cur_val <= 0 || cur_val > 255) {
  462.         clang = 0;
  463.     } else {
  464.         clang = cur_val;
  465.     }
  466.     append_whatsit(LANGUAGE_NODE, LANGUAGE_NODE_SIZE);
  467.     what_lang(tail) = clang;
  468.     what_lhm(tail) = norm_min(left_hyphen_min);
  469.     what_rhm(tail) = norm_min(right_hyphen_min);
  470. }        
  471.  
  472. void
  473. show_language (p)
  474.     ptr    p;
  475. {
  476.     print_esc("setlanguage");
  477.     print_int(what_lang(p));
  478.     print(" (hyphenmin ");
  479.     print_int(what_lhm(p));
  480.     print(",");
  481.     print_int(what_rhm(p));
  482.     print(")");
  483. }
  484.  
  485. ptr
  486. copy_language (p)
  487.     ptr    p;
  488. {
  489.     ptr    q;
  490.  
  491.     q = new_node(SMALL_NODE_SIZE);
  492.     memcpy((void *) q, (void *) p, SMALL_NODE_SIZE);
  493.  
  494.     return q;
  495. }
  496.  
  497. void
  498. free_language (p)
  499. {
  500.     free_node(p, SMALL_NODE_SIZE);
  501. }
  502.  
  503. void
  504. out_language (p)
  505. {
  506.     return;
  507. }
  508.  
  509. void
  510. fix_language ()
  511. {
  512.     int    l;
  513.  
  514.     if (language <= 0 || language > 255) {
  515.         l = 0;
  516.     } else {
  517.         l = language;
  518.     }
  519.     if (l != clang) {
  520.         append_whatsit(LANGUAGE_NODE, SMALL_NODE_SIZE);
  521.         what_lang(tail) = clang = l;
  522.         what_lhm(tail) = norm_min(left_hyphen_min);
  523.         what_rhm(tail) = norm_min(right_hyphen_min);
  524.     }
  525. }
  526.  
  527. void
  528. _texext_init ()
  529. {
  530. }
  531.  
  532. void
  533. _texext_init_once ()
  534. {
  535. }
  536.  
  537. /*
  538. **    Help text
  539. */
  540.  
  541. help_unbal_write ()
  542. {
  543.     help2("On this page there's a \\write with fewer real {'s than }'s.",
  544.     "I can't handle that very well; good luck.");
  545. }
  546.