home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 3 / Meeting_Pearls_III.iso / Pearls / dev / Localization / CatCompMO / ioSet.mod < prev    next >
Encoding:
Text File  |  1994-03-24  |  4.8 KB  |  223 lines

  1. (****** ioSet/--AMOK-Header-- ***********************************************
  2.  
  3. :Program.    ioSet.mod
  4. :Contents.   redirection of in- and output-channels for io.mod
  5. :Author.     Oliver Knorr
  6. :Copyright.  Public Domain
  7. :Language.   Oberon-2
  8. :Translator. Amiga Oberon v3.11
  9. :History.    v1.1 [olk] 24-Mar-94
  10. :Support.    idea taken from M2Amiga's InOut.mod
  11. :Version.    $VER: ioSet.mod 1.1 (24.3.94)
  12.  
  13. *****************************************************************************
  14. *
  15. *)
  16.  
  17. MODULE ioSet;
  18.  
  19. (****** ioSet/--background-- ************************************************
  20. *
  21. *       Two of the most important standard modules for text in- and
  22. *       output coming with the Amiga Oberon Compiler are io.mod and
  23. *       FileSystem.mod. While FileSystem.mod gives you the ability to
  24. *       work with files, it does not feature the many options for
  25. *       formatted in- and output of io.mod. While io.mod normally
  26. *       operates only on standard input and standard output, you can
  27. *       redirect it to any file with its global variables out and in.
  28. *       This Module, ioSet, gives you easy access to this redirection
  29. *       feature of io.mod.
  30. *
  31. *****************************************************************************
  32. *
  33. *)
  34.  
  35. IMPORT io, SecureDos, Dos;
  36.  
  37. VAR
  38.  
  39.   in, out, oldOut, oldIn : Dos.FileHandlePtr;
  40.  
  41.  
  42. (****** ioSet/CloseInput ****************************************************
  43. *
  44. *   NAME
  45. *       CloseInput -- remove redirection of the io.mod input channel
  46. *
  47. *   SYNOPSIS
  48. *       CloseInput
  49. *
  50. *   FUNCTION
  51. *       Removes the redirection of the input channel of io.mod
  52. *       started with SetInput() and closes the redirection file.
  53. *
  54. *   INPUTS
  55. *
  56. *   RESULT
  57. *
  58. *   EXAMPLE
  59. *
  60. *   NOTES
  61. *
  62. *   BUGS
  63. *
  64. *   SEE ALSO
  65. *       SetInput(), CloseOutput()
  66. *
  67. *****************************************************************************
  68. *
  69. *)
  70.  
  71. PROCEDURE CloseInput *;
  72. BEGIN
  73.   IF in # NIL THEN
  74.     io.in := oldIn;
  75.     SecureDos.Close(in);
  76.     in := NIL
  77.   END;
  78. END CloseInput;
  79.  
  80.  
  81. (****** ioSet/CloseOutput ***************************************************
  82. *
  83. *   NAME
  84. *       CloseOutput -- remove redirection of the io.mod output channel
  85. *
  86. *   SYNOPSIS
  87. *       CloseOutput
  88. *
  89. *   FUNCTION
  90. *       Removes the redirection of the output channel of io.mod
  91. *       started with SetOutput() and closes the redirection file.
  92. *
  93. *   INPUTS
  94. *
  95. *   RESULT
  96. *
  97. *   EXAMPLE
  98. *
  99. *   NOTES
  100. *
  101. *   BUGS
  102. *
  103. *   SEE ALSO
  104. *       SetOutput(), CloseInput()
  105. *
  106. *****************************************************************************
  107. *
  108. *)
  109.  
  110. PROCEDURE CloseOutput *;
  111. BEGIN
  112.   IF out # NIL THEN
  113.     io.out := oldOut;
  114.     SecureDos.Close(out);
  115.     out := NIL
  116.   END
  117. END CloseOutput;
  118.  
  119.  
  120. (****** ioSet/SetInput ******************************************************
  121. *
  122. *   NAME
  123. *       SetInput -- redirect input channel of io.mod
  124. *
  125. *   SYNOPSIS
  126. *       SetInput (name: ARRAY OF CHAR): BOOLEAN
  127. *
  128. *   FUNCTION
  129. *       Redirects the input channel of io.mod to the given file.
  130. *       Any subsequent calls to the Read... procedures of io.mod
  131. *       will operare on this file instead of the standard input
  132. *       until CloseInput() is called.
  133. *
  134. *   INPUTS
  135. *       name - name of the file the input channel of io.mod shall be
  136. *              redirected to
  137. *
  138. *   RESULT
  139. *       TRUE: redirection enabled
  140. *       FALSE: file could not be opened
  141. *
  142. *   EXAMPLE
  143. *
  144. *   NOTES
  145. *
  146. *   BUGS
  147. *
  148. *   SEE ALSO
  149. *       CloseInput(), SetOutput()
  150. *
  151. *****************************************************************************
  152. *
  153. *)
  154.  
  155. PROCEDURE SetInput * (name: ARRAY OF CHAR): BOOLEAN;
  156. BEGIN
  157.   IF in # NIL THEN CloseInput END;
  158.   in := SecureDos.Open(name, Dos.oldFile);
  159.   IF in # NIL THEN io.in := in END;
  160.   RETURN in # NIL
  161. END SetInput;
  162.  
  163.  
  164. (****** ioSet/SetOutput *****************************************************
  165. *
  166. *   NAME
  167. *       SetOutput -- redirect output channel of io.mod
  168. *
  169. *   SYNOPSIS
  170. *       SetOutput (name: ARRAY OF CHAR): BOOLEAN
  171. *
  172. *   FUNCTION
  173. *       Redirects the output channel of io.mod to the given file.
  174. *       Any subsequent calls to the Write... procedures of io.mod
  175. *       will operare on this file instead of the standard output
  176. *       until CloseOutput() is called.
  177. *
  178. *   INPUTS
  179. *       name - name of the file the output channel of io.mod shall be
  180. *              redirected to
  181. *
  182. *   RESULT
  183. *       TRUE: redirection enabled
  184. *       FALSE: file could not be opened
  185. *
  186. *   EXAMPLE
  187. *
  188. *   NOTES
  189. *
  190. *   BUGS
  191. *
  192. *   SEE ALSO
  193. *       CloseOutput(), SetInput()
  194. *
  195. *****************************************************************************
  196. *
  197. *)
  198.  
  199. PROCEDURE SetOutput * (name: ARRAY OF CHAR): BOOLEAN;
  200. BEGIN
  201.   IF out # NIL THEN CloseOutput END;
  202.   out := SecureDos.Open(name, Dos.newFile);
  203.   IF out # NIL THEN io.out := out END;
  204.   RETURN out # NIL
  205. END SetOutput;
  206.  
  207.  
  208. BEGIN
  209.  
  210.   oldOut := io.out;
  211.   oldIn := io.in;
  212.   out := NIL;
  213.   in := NIL;
  214.  
  215.  
  216. CLOSE
  217.  
  218.   io.out := oldOut;
  219.   io.in := oldIn;
  220.  
  221.  
  222. END ioSet.
  223.