goutput.red 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. module goutput; % GENTRAN Code Formatting & Printing and Error Handler
  2. %% Author: Barbara L. Gates %%
  3. %% December 1986 %%
  4. % Entry Points: FormatC, FormatFort, FormatRat, GentranErr, FormatPasc
  5. % All format routines moved to individual language modules
  6. % JHD December 1987
  7. symbolic$
  8. fluid '(!*errcont)$
  9. % GENTRAN Global Variables %
  10. global '(!*errchan!* !*outchanl!* gentranlang!*
  11. !*posn!* !*stdin!* !*stdout!* !$eol!$)$
  12. !*errchan!* := nil$ %error channel number
  13. !*posn!* := 0$ %current position on output line
  14. %% %%
  15. %% General Printing Functions %%
  16. %% %%
  17. % Pprin2 and pterpri changed by F.Kako.
  18. % Original did not work in SLISP/370, since output must be buffered.
  19. global '(!*pprinbuf!*);
  20. procedure pprin2 arg;
  21. begin
  22. !*pprinbuf!* := arg . !*pprinbuf!*;
  23. !*posn!* := !*posn!* + length explode2 arg;
  24. end$
  25. procedure pterpri;
  26. begin
  27. scalar ch,pbuf;
  28. ch := wrs nil;
  29. pbuf := reversip !*pprinbuf!*;
  30. for each c in !*outchanl!* do
  31. <<wrs c;
  32. for each a in pbuf do
  33. if gentranlang!* eq 'fortran then fprin2 a else prin2 a;
  34. terpri()>>;
  35. !*posn!* := 0;
  36. !*pprinbuf!* := nil;
  37. wrs ch
  38. end$
  39. %% %%
  40. %% Error Handler %%
  41. %% %%
  42. %% Error & Warning Message Printing Routine %%
  43. symbolic procedure gentranerr(msgtype, exp, msg1, msg2);
  44. % Added check for !*errcont to aid graceful recovery from errors
  45. % occurring in templates MCD 11.4.94
  46. begin scalar holdich, holdoch, resp;
  47. holdich := rds !*errchan!*;
  48. holdoch := wrs !*errchan!*;
  49. terpri();
  50. if exp then prettyprint exp;
  51. if (msgtype eq 'e) and not !*errcont then
  52. <<
  53. rds cdr !*stdin!*;
  54. wrs cdr !*stdout!*;
  55. rederr msg1
  56. >>;
  57. prin2 "*** ";
  58. prin2t msg1;
  59. if msg2 then resp := yesp msg2;
  60. wrs holdoch;
  61. rds holdich;
  62. if not(resp or !*errcont) then error1()
  63. end$
  64. %% %%
  65. %% Misc. Functions %%
  66. %% %%
  67. procedure min0(n1, n2);
  68. max(min(n1, n2), 0)$
  69. procedure nspaces n;
  70. % Note n is assumed > 0 here.
  71. begin scalar s;
  72. for i := 1:n do s := ('!! . '! . s);
  73. return intern compress s
  74. end$
  75. endmodule;
  76. end;