help.red 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. %
  2. % HELP.RED - User assistance and documentation
  3. %
  4. % Author: Eric Benson and Martin Griss
  5. % Symbolic Computation Group
  6. % Computer Science Dept.
  7. % University of Utah
  8. % Date: 23 October 1981
  9. % Copyright (c) 1981 University of Utah
  10. %
  11. % 30 Dec, 1982, MLG
  12. % Move IF_SYSTEM to the Build file
  13. % <PSL.UTIL.NEWVERSIONS>HELP.RED, 30-Nov-82 16:31, Edit by GALWAY
  14. % Changed "FLAG" to "SWITCH" to avoid confusion with flags on property
  15. % lists and to bring terminology in line with PSL manual.
  16. % <PSL.UTIL>HELP.RED.3, 1-Dec-82 16:16:39, Edit by BENSON
  17. % Added if_system(HP9836, ... )
  18. % <PSL.UTIL>HELP.RED.4, 10-Aug-82 00:54:26, Edit by BENSON
  19. % Changed ReadCh to ReadChar in DisplayHelpFile
  20. % <PSL.INTERP>HELP.RED.5, 31-May-82 11:50:48, Edit by GRISS
  21. % Make it LAPIN Help.Tbl
  22. % Changed: to use PH:
  23. % Display help texts, invoke interactive HELPs or print default values
  24. % Place a HELP function on topic name under 'HelpFunction
  25. % Or HELP file on topic name under 'HelpFile
  26. % Or even a short string under 'HelpString (this may be removed)
  27. fluid '(TopLoopRead!*
  28. TopLoopPrint!*
  29. TopLoopEval!*
  30. TopLoopName!*
  31. HelpFileFormat!*
  32. Options!*
  33. !*Echo
  34. HelpIn!*
  35. HelpOut!*
  36. !*Lower
  37. !*ReloadHelpTable
  38. HelpTable!*
  39. );
  40. !*ReloadHelpTable := T;
  41. lisp procedure ReloadHelpTable();
  42. % Set !*ReloadHelpTable to T to cause a fresh help table to be loaded
  43. if !*ReloadHelpTable then
  44. << LapIn HelpTable!*;
  45. !*ReloadHelpTable := NIL >>;
  46. lisp procedure DisplayHelpFile F;
  47. % Type help file about 'F'
  48. begin scalar NewIn, C, !*Echo;
  49. (lambda(!*Lower);
  50. F := BldMsg(HelpFileFormat!*, F))(T);
  51. NewIn := ErrorSet(list('Open, MkQuote F, '(quote Input)), NIL, NIL);
  52. if not PairP NewIn then
  53. ErrorPrintF("*** Couldn't find help file %r", F)
  54. else
  55. << NewIn := car NewIn;
  56. while not ((C := ChannelReadChar NewIn) = char EOF) do WriteChar C;
  57. Close NewIn >>;
  58. end;
  59. fexpr procedure Help U;
  60. % Look for Help on topics U
  61. begin scalar OldOut;
  62. OldOut := WRS HelpOut!*;
  63. ReloadHelpTable(); % Conditional Reload
  64. HelpTopicList U;
  65. WRS OldOut;
  66. end;
  67. lisp procedure HelpTopicList U;
  68. % Auxilliary function to prind help for each topic in list U
  69. if null U then HelpHelp()
  70. else for each X in U do
  71. begin scalar F;
  72. if F := get(X, 'HelpFunction) then Apply(F, NIL)
  73. else if F := get(X, 'HelpFile) then DisplayHelpFile F
  74. else if F := get(X, 'HelpString) then Prin2T F
  75. else DisplayHelpFile X; % Perhaps a File Exists.
  76. end;
  77. lisp procedure HelpHelp();
  78. % HELPFUNCTION: for help itself
  79. << DisplayHelpFile 'Help;
  80. FindHelpTopics();
  81. PrintF("%nOptional modules now loaded:%n%l%n",Options!*);
  82. >>;
  83. lisp procedure FindHelpTopics();
  84. % Scan the ID HAST TABLE for loaded HELP info
  85. << PrintF("Help is available on the following topics:%n");
  86. MapObl Function TestHelpTopic;
  87. TerPri();
  88. PrintF("The files in the help directory can be read using Help.%n") >>;
  89. lisp procedure TestHelpTopic X;
  90. % auxilliary function applied to each ID to see if
  91. % some help info exists
  92. if get(X, 'HelpFunction) or get(X, 'HelpFile) or get(X, 'HelpString) then
  93. << Prin2 '! ;
  94. Prin1 X >>;
  95. lisp procedure HelpTopLoop();
  96. % HELPFUNCTION: for TopLoop, show READER/WRITERS
  97. << DisplayHelpFile 'Top!-Loop;
  98. if TopLoopName!* then
  99. << PrintF("%nCurrently inside %w top loop%n", TopLoopName!*);
  100. PrintF("Reader: %p, Evaluator: %p, Printer: %p%n",
  101. TopLoopRead!*, TopLoopEval!*, TopLoopPrint!*) >>
  102. else PrintF("%nNot currently inside top loop%n") >>;
  103. % Switch and global help - record and display all switches and globals.
  104. lisp procedure DefineSwitch(Name, Info);
  105. % Define important switch
  106. % Name does Not have the !*, Info should be a string.
  107. %
  108. << put(Name, 'SwitchInfo, Info);
  109. Name >>;
  110. lisp procedure Show1Switch(Name);
  111. % Display a single switch
  112. begin scalar X;
  113. Prin1 Name;
  114. Tab 15;
  115. Prin1 Eval Intern Concat("*", ID2String Name);
  116. If (X := Get(Name, 'SwitchInfo)) then
  117. << Tab 25;
  118. Prin2 X >>;
  119. TerPri();
  120. end;
  121. lisp procedure ShowSwitches L;
  122. % Display all switches in a list
  123. << if not PairP L then MapObl function TestShowSwitch;
  124. for each X in L do Show1Switch X >>;
  125. lisp procedure TestShowSwitch X;
  126. % Support function for 1 switch display
  127. if get(X, 'SwitchInfo) then Show1Switch X;
  128. lisp procedure DefineGlobal(Name, Info);
  129. % Define important global
  130. % Name is an ID, Info should be a string.
  131. %
  132. << put(Name, 'GlobalInfo, Info);
  133. Name >>;
  134. lisp procedure Show1Global Name;
  135. % Display a Single Global
  136. begin scalar X;
  137. Prin1 Name;
  138. Tab 15;
  139. Prin1 Eval Name;
  140. If (X := get(Name, 'GlobalInfo)) then
  141. << Tab 25;
  142. Prin2 X >>;
  143. TerPri();
  144. end;
  145. lisp procedure TestShowGlobal X;
  146. % Support for GLOBAL info
  147. if get(X, 'GlobalInfo) then Show1Global X;
  148. lisp procedure Show1State Name;
  149. % Display a single switch or global
  150. << if get(Name, 'GlobalInfo) then Show1Global Name;
  151. if get(Name, 'SwitchInfo) then Show1Switch Name >>;
  152. lisp procedure ShowGlobals L;
  153. % Display all globals in a list
  154. << if not PairP L then MapObl Function TestShowGlobal;
  155. for each X in L do Show1Global X >>;
  156. lisp procedure ShowState L;
  157. % Display all globals in a list
  158. << if not PairP L then MapObl function TestShowState;
  159. for each X in L do Show1State X >>;
  160. lisp procedure TestShowState X;
  161. % Support for a Global
  162. if get(X, 'SwitchInfo) or get(X, 'GlobalInfo) then Show1State X;
  163. END;