home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / a293_1 / !AForth_Docs_Semantics_File < prev    next >
Encoding:
Text File  |  1993-04-08  |  7.7 KB  |  162 lines

  1.  
  2. Semantics for File Access and Extension Word Sets
  3.  
  4.  
  5. The File Access word set provides an interface to the filing system of the host operating system. Below follows a general introduction and some guidelines for the usage of the File Access word set.
  6.  
  7. Some words take a string as input to describe a filename. The string is decribed by the address of the string, c-addr, and its length, u. The string must be null-terminated, ie. the byte at address ( c-addr + u ) must be zero. This is automatically done, when using the word S" in interpretation mode.
  8.  
  9. A File identifier (fid) is a file handle allocated by the operating system.
  10.  
  11. An I/O result code (ior) is the result of a file operation. If it is zero it means that the operation was succesful, otherwise it was unsuccessful, signifying an error occurred. Reaching the end of a file (eof) is considered a successful operation, and thus returns a zero ior. The ior code is actually a pointer to a standard RISCOS error block and can be THROWn, if so desired (see the file 'Docs.Semantics.Error' for a thorough explanation of errors and error handling).
  12.  
  13. A file access method is any of read-only, write-only and read/write. These are used when opening and creating files.
  14.  
  15. All reading from and writing to a file results in the file's file position to be advanced by the number of characters actually read or written.
  16.  
  17. The word WRITE-LINE writes the line terminator as ASCII 10. When reading a line from a file, either by READ-LINE, INCLUDED or INCLUDE-FILE, the ASCII characters 0, 10 and 13 are all recognized as line terminators.
  18.  
  19. See the 'Examples' directory for examples of the File Access words.
  20.  
  21.  
  22. File Access Word Set __________________________________________________________
  23.  
  24. SOURCE-FILE  File
  25. ( -- 0 ) or ( -- -1 ) or ( -- fid )
  26. Identifies the source of non-block input stream, ie. when contents of BLK is zero.
  27.  
  28. SOURCE-FILE     input stream source
  29. --------------------------------------------------
  30.      0          keyboard
  31.     -1          string via EVALUATE
  32.     fid         text file indentified by fid
  33. --------------------------------------------------
  34.  
  35.  
  36. R/O  File
  37. ( -- w )
  38. Stack the file access method code for read-only.
  39.  
  40.  
  41. R/W  File
  42. ( -- w )
  43. Stack the file access method code for read/write.
  44.  
  45.  
  46. W/O  File
  47. ( -- w )
  48. Stack the file access method code for write-only.
  49. In the Archimedes implementation this code is the same as R/W, as RISC-OS does not support write-only file access.
  50.  
  51.  
  52. CREATE-FILE  File
  53. ( c-addr u w1 -- fid ior )
  54. Create a file with the name described by c-addr and u and open it with the file access method w1, ie. either R/O, R/W or W/O. If a file of the same name already exists then recreate it as an empty file.
  55.  
  56. If ior is zero the file was successfully created and opened and the file has been positioned to the start of the file. If ior is non-zero, fid is an unspecified value.
  57.  
  58.  
  59. OPEN-FILE  File
  60. ( c-addr u w1 -- w2 ior )
  61. Open the file with the name described by c-addr and u and file access method w1.
  62.  
  63. If ior is zero the file was successfully created and opened and the file has been positioned to the start of the file. If ior is non-zero, fid is an unspecified value.
  64.  
  65.  
  66. CLOSE-FILE  File
  67. ( fid -- ior )
  68. Close the file identified by fid. The I/O result code, ior, is zero if the file was succesfully closed, otherwise it is non-zero.
  69.  
  70.  
  71. INCLUDE-FILE  File
  72. ( i*w fid -- j*w )
  73. Interpret the file identified by fid. Each line of the file is read and interpreted seperately. When the end of file is reached the file is closed. If an error occurs, the file may not be closed.
  74.  
  75. AForth restricts the line length to 128 characters including the line terminator. This corresponds to the minimum required to comply with the ANS standard.
  76.  
  77. RISC-OS supports (in release 2.0) 256 open files at one time. AForth imposes a limit of 127 files being open and interpreted by INCLUDE-FILE or INCLUDED (This should though be of no concern! :-)
  78.  
  79. AForth release 0.70 and above features a special Aforth Fast Include Format (AFIF) which enables very fast loading and dynamic linking of files containing Forth definitions. See the file 'Docs.Internals' for explanation on how to create your own fast-loading libraries.
  80.  
  81.  
  82. INCLUDED  File
  83. ( i*w c-addr u -- j*w )
  84. This is similar to INCLUDE-FILE, though this takes a file name described by c-addr and u as input. The file identified by name c-addr u is opened and interpreting commences in the way described under INCLUDE-FILE.
  85.  
  86.  
  87. READ-FILE  File
  88. ( c-addr u1 fid -- u2 ior )
  89. Read u1 characters (bytes) to the address c-addr from the file identified by fid. The read is initiated at the current file position of the file. u2 is the number of characters actually read and ior is the I/O result code.
  90.  
  91. If the end of file is reached before all u1 characters have been read, ior is zero and u2 is the number of characters actually read. Also, when the the operation is initiated when end-of-file has already been reached, u2=0 and ior=0. Thus when u2<u1 and ior=0, end-of-file has been reached successfully.
  92.  
  93. If an error occurs, ior is non-zero and u2 is the number of characters read before the error occurred.
  94.  
  95.  
  96. WRITE-FILE  File
  97. ( c-addr u fid -- ior )
  98. Write u characters (bytes) from the address c-addr to the file identified by fid. The write is initiated at the current file position of the file. ior is zero if the write completed successfully.
  99.  
  100.  
  101. READ-LINE  File
  102. ( c-addr u1 fid -- u2 flag ior )
  103. Read the next line from the file identified by fid to the address c-addr. At most u1 characters are read. The line-terminator, if any, is not put at the end of the line at c-addr. The buffer pointed by c-addr should be at least u1+2 characters long.
  104.  
  105. If the operation succeeded, flag is true and ior is zero. u2 is the number of characters actually read, exclusive the line terminator. That is, if u1=u2, the line terminator has yet to be reached.
  106.  
  107. If the read was initiated when the file position was at the end of file, flag is false, u2=0 and ior=0, ie. flag acts as an end of file indicator, being false when end-of-file has been reached (ior=0 on reaching the end of a file because this is considered a successful completion).
  108.  
  109. If ior is always non-zero an error occurred during the read.
  110.  
  111.  
  112. WRITE-LINE  File
  113. ( c-addr u fid -- ior )
  114. Write u characters (bytes) at address c-addr followed by a line terminator to the file identified by fid. The line terminator is written as ASCII 10.
  115.  
  116.  
  117. FILE-POSITION  File
  118. ( fid -- ud ior )
  119. Return the double number file position of the file identified by fid.
  120.  
  121.  
  122. FILE-SIZE  File
  123. ( fid -- ud ior )
  124. Return the double number file size of the file identified by fid.
  125.  
  126.  
  127. REPOSITION-FILE  File
  128. ( ud fid -- ior )
  129. Reposition the file identified by fid to the file position described by
  130. the double number ud.
  131.  
  132.  
  133. RESIZE-FILE  File
  134. ( ud fid -- ior )
  135. Resize the file identified by fid to the file size described by the double
  136. number ud.
  137.  
  138.  
  139. DELETE-FILE  File
  140. ( c-addr u -- ior )
  141. Delete the file with the name described by c-addr u.
  142.  
  143.  
  144. BLOCK-FID  File
  145. ( -- a-addr )
  146. This word is used in the defininition of some words of the Block word set when this is built upon the File Access word set. Even though the ANS standard requires the Block word set to be present if the File Access word set is, it has not been included and thus the word BLOCK-FID has become obsolescent.
  147.  
  148.  
  149. File Access Extensions Word Set _______________________________________________
  150.  
  151. The following words belong to the File Access Extensions and have not been implemented in the current implementation.
  152.  
  153. FILE-BLOCK  ( u fid -- a-addr )  FileExt
  154. FILE-BUFFER  ( u fid -- a-addr )  FileExt
  155. FLUSH-FILE  ( fid -- ior )  FileExt
  156. LOAD-FILE  ( i*w u fid -- j*w )  FileExt
  157.  
  158. FILE-STATUS  ( c-addr u -- w ior )  FileExt
  159. RENAME-FILE  ( c-addr u1 c-addr2 u2 -- ior )  FileExt
  160. RESTORE-INPUT  ( w1 w2 w3 -- flag )  FileExt
  161. SAVE-INPUT  ( -- w1 w2 w3 )  FileExt
  162.