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

  1.  
  2. /*
  3.  * @(#)error.c 2.6 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 "tokenstack.h"
  15. #include "token.h"
  16. #include "file.h"
  17.  
  18. int     OK_to_interrupt;
  19. bool    deletions_allowed;
  20. int     error_count;
  21. chrs    help_line[6];
  22. ptr     help_ptr;
  23. int     history;
  24. int     interaction;
  25. int     interrupt;
  26. int     old_setting;
  27. bool    use_err_help;
  28.  
  29. jump_out ()
  30. {
  31.     close_files_and_terminate(FALSE);
  32. }
  33.  
  34. begin_diagnostic ()
  35. {
  36.     old_setting = selector;
  37.     if (tracing_online <= 0 && selector == TERM_AND_LOG) {
  38.         decr(selector);
  39.         if (history == SPOTLESS)
  40.             history = WARNING_ISSUED;
  41.     }
  42. }
  43.  
  44. end_diagnostic (blank_line)
  45.     bool    blank_line;
  46. {
  47.     print_nl("");
  48.     if (blank_line) print_ln();
  49.     selector = old_setting;
  50. }
  51.  
  52. print_err (msg)
  53.     chrs    msg;
  54. {
  55.     if (interaction == ERROR_STOP_MODE) 
  56.         wake_up_terminal(); 
  57.     print_nl("! ");
  58.     print(msg);
  59. }
  60.  
  61. error ()
  62. {
  63.     ascii   c;
  64.     int     hx;
  65.     hword   s1;
  66.     hword   s2;
  67.     hword   s3;
  68.     val     s4;
  69.  
  70.     if (history < ERROR_MESSAGE_ISSUED)
  71.         history = ERROR_MESSAGE_ISSUED;
  72.     print_char('.');
  73.     show_context();
  74.     if (interaction == ERROR_STOP_MODE) {
  75.         loop {
  76.             clear_for_error_prompt();
  77.             prompt_input("? ");
  78.             if (last == first)
  79.                 return;
  80.             c = buffer[first];
  81.             if (c >= 'a')
  82.                 c -= 'a' - 'A';
  83.             switch (c)
  84.             {
  85.             case '1': case '2': case '3':
  86.             case '4': case '5': case '6':
  87.             case '7': case '8': case '9':
  88.                 if (! deletions_allowed)
  89.                     continue;
  90.                 s1 = cur_tok;
  91.                 s2 = cur_cmd;
  92.                 s3 = cur_chr;
  93.                 s4 = align_state;
  94.                 align_state = 1000000;
  95.                 OK_to_interrupt = FALSE;
  96.                 if (last > first + 1 &&
  97.                     buffer[first + 1] >= '0' &&
  98.                     buffer[first + 1] <= '9')
  99.                     c = c * 10 + buffer[first + 1] - '0' * 11;
  100.                 else c -= '0';
  101.                 while (c > 0) {
  102.                     get_token();
  103.                     decr(c);
  104.                 }
  105.                 cur_tok = s1;
  106.                 cur_cmd = s2;
  107.                 cur_chr = s3;
  108.                 align_state = s4;
  109.                 OK_to_interrupt = TRUE;
  110.                 help_delete_text();
  111.                 show_context();
  112.                 continue;
  113.             
  114.             case 'H':
  115.                 if (use_err_help)  {
  116.                     give_err_help();
  117.                     use_err_help = FALSE;
  118.                 } else {
  119.                     if (help_ptr == 0)
  120.                         help_no_help();
  121.                     else for (hx = 0; hx < help_ptr; incr(hx)) {
  122.                         print(help_line[hx]);
  123.                         print_ln();
  124.                     }
  125.                     help_help();
  126.                 }
  127.                 continue;
  128.                 
  129.             case 'I':
  130.                 begin_file_reading();
  131.                 if (last > first + 1) {
  132.                     loc = first + 1;
  133.                     buffer[first] = ' ';
  134.                 } else {
  135.                     prompt_input("insert>");
  136.                     loc = first;
  137.                 }
  138.                 first = last;
  139.                 limit = last - 1;
  140.                 return;
  141.             
  142.             case 'Q':
  143.             case 'R':
  144.             case 'S':
  145.                 error_count = 0;
  146.                 interaction = BATCH_MODE + c - 'Q';
  147.                 print("OK, entering ");
  148.                 switch (c)
  149.                 {
  150.                 case 'Q':
  151.                     print_esc("batchmode");
  152.                     decr(selector);
  153.                     break;
  154.                 
  155.                 case 'R':
  156.                     print_esc("nonstopmode");
  157.                     break;
  158.                 
  159.                 case 'S':
  160.                     print_esc("scrollmode");
  161.                     break;
  162.                 }
  163.                 print("...");
  164.                 print_ln();
  165.                 update_terminal();
  166.                 return;
  167.             
  168.             case 'E':
  169.                 if (base_ptr > 0)
  170.                     close_files_and_terminate(TRUE);
  171.                 break;
  172.  
  173.             case 'X':
  174.                 interaction = SCROLL_MODE;
  175.                 jump_out();
  176.                 break;
  177.  
  178.             default:
  179.                 print_menu();
  180.                 continue;
  181.             }
  182.         }
  183.     }
  184.     incr(error_count);
  185.     if (error_count == 100) {
  186.         print_nl("(That makes 100 errors; please try again.)");
  187.         history = FATAL_ERROR_STOP;
  188.         jump_out();
  189.     }
  190.     if (interaction > BATCH_MODE)
  191.         decr(selector);
  192.     if (use_err_help) {
  193.         print_ln();
  194.         give_err_help();
  195.     } else for (hx = 0; hx < help_ptr; incr(hx)) {
  196.         print_nl(help_line[hx]);
  197.     }
  198.     help_ptr = 0;
  199.     print_ln();
  200.     if (interaction > BATCH_MODE)
  201.         incr(selector);
  202.     print_ln();
  203. }
  204.  
  205. print_menu ()
  206. {
  207.     print("Type <return> to proceed, S to scroll future error messages,");
  208.     print_nl("R to run without stopping, Q to run quietly,");
  209.     print_nl("I to insert something, ");
  210.     if (base_ptr > 0)
  211.         print("E to edit your file,");
  212.     if (deletions_allowed)
  213.         print_nl("1 or ... or 9 to ignore the next 1 to 9 tokens of input");
  214.     print_nl("H for help, X to quit.");
  215. }
  216.  
  217. int_error (v)
  218.     val     v;
  219. {
  220.     print(" (");
  221.     print_val(v);
  222.     print_char(')');
  223.     error();
  224. }
  225.  
  226. normalize_selector ()
  227. {
  228.     if (job_name > 0)
  229.         selector = TERM_AND_LOG;
  230.     else selector = TERM_ONLY;
  231.     if (job_name == 0)
  232.         open_log_file();
  233.     if (interaction == BATCH_MODE)
  234.         decr(selector);
  235. }
  236.  
  237. fatal_error (s)
  238.     chrs    s;
  239. {
  240.     normalize_selector();
  241.     print_err("Emergency stop");
  242.     help1(s);
  243.     succumb();
  244. }
  245.  
  246. overflow (s, n)
  247.     chrs    s;
  248.     int     n;
  249. {
  250.     normalize_selector();
  251.     print_err("TeX capacity exceeded, sorry [");
  252.     print(s);
  253.     print_char('=');
  254.     print_int(n);
  255.     print_char(']');
  256.     help_capacity();
  257.     succumb();
  258. }
  259.  
  260. confusion (s)
  261.     chrs    s;
  262. {
  263.     normalize_selector();
  264.     if (history < ERROR_MESSAGE_ISSUED) {
  265.         print_err("This can't happen (");
  266.         print(s);
  267.         print_char(')');
  268.         help_broken();
  269.     } else {
  270.         print_err("I can't go on meeting you like this");
  271.         help_wounded();
  272.     }
  273.     succumb();
  274. }
  275.  
  276. pause_for_instructions ()
  277. {
  278.     if (OK_to_interrupt) {
  279.         interaction = ERROR_STOP_MODE;
  280.         if (selector == LOG_ONLY || selector == NO_PRINT)
  281.             incr(selector);
  282.         print_err("Interruption");
  283.         help_interrupt();
  284.         deletions_allowed = FALSE;
  285.         error();
  286.         deletions_allowed = TRUE;
  287.         interrupt = 0;
  288.     }
  289. }
  290.  
  291. init_error ()
  292. {
  293.     OK_to_interrupt = TRUE;
  294.     deletions_allowed = TRUE;
  295.     interaction = ERROR_STOP_MODE;
  296.     use_err_help = FALSE;
  297. }
  298.  
  299. /*
  300.  *  Help text
  301.  */
  302.  
  303. help_delete_text () 
  304. {
  305.     help2("I have just deleted some text, as you asked.", 
  306.     "You can now delete more, or insert, or whatever.");
  307. }
  308.  
  309. help_no_help () 
  310. {
  311.     help2("Sorry, I don't know how to help in this situation.",
  312.     "Maybe you should try asking a human?");
  313. }
  314.  
  315. help_help () 
  316. {
  317.     help4("Sorry, I already gave what help I could...",
  318.     "Maybe you should try asking a human?", 
  319.     "An error might have occurred before I noticed any problems.",
  320.     "``If all else fails, read the instructions.''");
  321. }
  322.  
  323. help_capacity () 
  324. {
  325.     help2("If you really absolutely need more capacity,",
  326.     "you can ask a wizard to enlarge me.");
  327. }
  328.  
  329. help_broken () 
  330. {
  331.     help1("I'm broken. Please show this to someone who can fix can fix");
  332. }
  333.  
  334. help_wounded () 
  335. {
  336.     help2("One of your faux pas seems to have wounded me deeply...",
  337.     "in fact, I'm barely conscious. Please fix it and try again.");
  338. }
  339.  
  340. help_interrupt () 
  341. {
  342.     help3("You rang?",
  343.     "Try to insert some instructions for me (e.g., `I\\showlists),",
  344.     "unless you just want to quit by typing `X'.");
  345. }
  346.