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