home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / computervision / kermit.text-file-io < prev    next >
Text File  |  2020-01-01  |  10KB  |  301 lines

  1. ; 18 aug 85 esj replaces s.e.fm.error.uil with kerdef
  2. * 18 jly 85 ESJ CREATED FOR kermit
  3. *
  4. *-----------------------------  text-file-io  -------------------------
  5.    E:F A:S(NWLS , STKARG)
  6. *-----------------------------------------------------------------------
  7. *
  8. * PURPOSE
  9. *
  10. * INPUT
  11.    I'R FD(*)            ; file descriptor block
  12. *
  13. * OUTPUT
  14. *)
  15. *
  16. * GLOBALS DEFINITIONS
  17. *  none
  18. *
  19. * LOCAL DEFINITIONS
  20.    I'R NEWNAME(42)      ; dest name field
  21.    I'R PACKNAME(42)     ; temp for packed filename
  22.    I'R OPENMODE         ; open mode temp
  23.    I'R TEMPMODE         ; open mode temp
  24.    I'R OTSPC(9)         ;
  25.    I'R STATUS(1)        ; FM error code
  26.    I'R WRSPEC(3)        ; inspecs field for write call
  27.  
  28.  
  29. * SUBROUTINES CALLED
  30. *
  31. * INSERTS
  32. /INCLUDE BYU.PROG.KERMIT.SYM.EQU.KERDEF
  33. /INCLUDE SYM.EQU.FM.OPEN
  34. /INCLUDE SYM.EQU.FM.BASIC
  35. /INCLUDE SYM.EQU.FM.READ
  36.  
  37. *--- put equates for the FD block here till ready to move to sym file---
  38.  
  39.       EQU   FD&CHAN = 0          ; channel number of the file once it's
  40.                                  ; open
  41.  
  42.       EQU   FD&MAX  = 1          ; maximum length of the text record which
  43.                                  ; can be handled by this FD. It is also
  44.                                  ; the size of the FD&TXTB field.
  45.  
  46.       EQU   FD&NDX  = 2          ; index for next char to be read from TXTB
  47.  
  48.       EQU   FD&MODE = 3          ; mode of how the file was opened
  49.  
  50.       EQU   FD&LNPOS= 4          ; number of current line being read. 0 based
  51.  
  52.       EQU   FD&TXTC = 5          ; text count. The length of the text record
  53.                                  ; currently in this FD
  54.  
  55.       EQU   FD&TXTB = FD&TXTC+1  ; text buffer
  56.  
  57. *-----------------------------------------------------------------------
  58. *
  59. * STATIC DATA INITIALIZATION
  60.       V'S TXTSPEC =  03,
  61. 1                    %CATLOG,%%SEARCH,
  62. 1                    %FORMAT , %%TEXT,
  63. 1                    %RTNERR
  64.  
  65.       V'S BCDNAME = 4,$&BCD$
  66. *
  67. * RESTRICTIONS
  68. *
  69. * ERROR INDICATIONS
  70. *
  71. * METHOD
  72. *
  73. *
  74. *---------------------------- START OF CODE ----------------------------
  75. *  HOW TO USE
  76. *     opentext is part of a simplified interface for manipulating
  77. *     text files with the new file manager.  opentext is used to
  78. *     open a text file for stream io.
  79. *     opentext takes four arguments:
  80. *     1) FD is a buffer that contains information about the file and
  81. *        the record being manipulated.  the information in FD is to be
  82. *        hidden from the user so that information can be added,deleted
  83. *        or changed without the need to support existing structures.
  84. *        The size of FD is defined by FD&SIZE. The buffer will need to
  85. *        be created by an ALLOC call because the buffer is larger than a
  86. *        local data section.
  87. *     2) FILENAME is a string in kermit or cv format.  opentext will
  88. *        make a copy of the file name and add an &bcd level to the name
  89. *        and stick an ! on the end, if needed converting the file name
  90. *        to a proper text file name.
  91. *     3) TEXTMODE is a two character descripter for the open mode for
  92. *        a text file.  The only modes supported are, RD for read,
  93. *        MO for modify, and SU for supercede.
  94. *
  95. *     4) NAMETYPE defines the type of string in filename.  CV is a cv type
  96. *        of string.  KM is a kermit type of string.
  97. *
  98.       E'O OPENTEXT.( FILENAME, TEXTMODE, NAMETYPE, FD)
  99.  
  100. #     E'E TYPE.(2,NAMETYPE)
  101.       ; convert filename to &bcd type and put ! on end
  102.       W'R NAMETYPE .E. $KM$
  103. #        E'E HEXDMPP.(1,41,1,FILENAME)
  104.          E'E PACK.(FILENAME, PACKNAME )
  105. #        E'E HEXDMP.(2,42,2,PACKNAME)
  106.          E'E FMEXPNM.(PACKNAME,BCDNAME,NEWNAME)
  107.       O'E
  108.          E'E FMEXPNM.(FILENAME,BCDNAME,NEWNAME)
  109.       E'L
  110.  
  111.  
  112.       W'R LDCHRT.(NEWNAME(1),NEWNAME-1) .NE. $!$
  113.          E'E STCHRT.($!$,NEWNAME(1),NEWNAME)
  114.          NEWNAME(0) = NEWNAME(0) + 1
  115.       E'L
  116.  
  117. #     E'E TYPEMSG.($THIS SHOULD BE THE &BCD NAME!$)
  118. #     E'E HEXDMP.(0,NEWNAME,0,NEWNAME)
  119.  
  120.       ; convert textmode to open file mode
  121.       ; convert char string to cv char type and lower case
  122.       TEMPMODE = TEXTMODE .LOR. 'A0A0'
  123.  
  124. #     E'E HEXDMP.(TEMPMODE,TEMPMODE,TEMPMODE,TEMPMODE)
  125.       W'R TEMPMODE .E. $rd$
  126.          ; read mode
  127.          OPENMODE = %OREAD
  128. *
  129.       O'R TEMPMODE .E. $mo$
  130.          ; modify mode
  131.          OPENMODE = %OMODIFY
  132. *
  133.       O'R TEMPMODE .E. $su$
  134.          ; supercede mode
  135.          OPENMODE = %OSUPR
  136.  
  137.       O'E
  138.          ; force openmode error
  139.          OPENMODE = -1
  140.  
  141.       E'L
  142. *
  143. *  Set to no error
  144.       STATUS = STATUS(1) = FM%NOERR
  145.  
  146.       ; call the fm and try to open
  147.       E'E F&OPEN.(OPENMODE,
  148. 1                 %IDFILNM,
  149. 1                 NEWNAME ,
  150. 1                 TXTSPEC ,
  151. 1                 FD(FD&CHAN),
  152. 1                 OTSPC   ,
  153. 1                 STATUS  )
  154.  
  155. #     E'E HEXDMP.(1,1,1,STATUS)
  156. *
  157.       FD(FD&NDX)   = 0            ; make text buffer empty
  158.       FD(FD&TXTC)  = 0
  159.       FD(FD&MODE)  = OPENMODE     ; set up access protection
  160.       FD(FD&LNPOS) = 0
  161.  
  162.       F:N STATUS
  163.  
  164.  
  165. *------------  end of opentext  -------------------------------------
  166. *------------  start of dgetch  --------------------------------------
  167. *     dgetch is part of a simplified interface for Manipulating
  168. *     text files with the new file manager.  dgetch is used to
  169. *     read characters from a text file for stream io.
  170. *     dgetch takes two arguments:
  171. *     1) CHAR is a single char from the file described in FD.  The
  172. *        character is in kermit format.  When end of file is reached,
  173. *        CHAR will equal -1.  End of line is indicated by CR.
  174. *     2) FD is a buffer that contains information about the file and
  175. *        the record being manipulated.  the information in FD is to be
  176. *        hidden from the user so that information can be added,deleted
  177. *        or changed without the need to support existing structures.
  178. *        The size of FD is defined by FD&SIZE. The buffer will need to
  179. *        be created by an ALLOC call because the buffer is larger than a
  180. *        local data section.
  181. *
  182.    V'S RDSPC = 02,
  183. 1              %RTNERR,
  184. 1              %RETURN,1,
  185. 1                     %%BYTCNT
  186.  
  187.       E'O DGETCH.(CHAR, FD)
  188.  
  189.       STATUS = STATUS(1) = 0
  190.  
  191.       ;if char index = 0 read in line and stick cr at end
  192.       W'R FD(FD&NDX) .E. 0
  193.  
  194.          E'E F&READ.(FD(FD&CHAN),
  195. 1                    1           ,
  196. 1                    FD(FD&TXTB) ,
  197. 1                    RDSPC       ,
  198. 1                    OTSPC       ,
  199. 1                    STATUS      )
  200.  
  201.          W'R STATUS .GE. FM%NOERR
  202.             FD(FD&TXTC) = OTSPC(3)
  203.             E'E STBYTT.('8D', FD(FD&TXTB), FD(FD&TXTC))
  204.             FD(FD&TXTC) = FD(FD&TXTC) + 1
  205.          E'L
  206.  
  207.       E'L
  208.  
  209.       W'R STATUS .GE.FM%NOERR
  210.          ; get a char from the input stream
  211.          CHAR = LDBYTT.(FD(FD&TXTB), FD(FD&NDX)) .LAND. '7F'
  212.  
  213.          W'R CHAR .E. '000D'
  214.             FD(FD&NDX) = 0
  215.             FD(FD&LNPOS) = FD(FD&LNPOS) + 1
  216.          O'E
  217.             FD(FD&NDX) = FD(FD&NDX) + 1
  218.          E'L
  219.  
  220.       O'R STATUS .E. UL%RDEOF
  221.          ; if at eof set char = -1
  222.          CHAR = -1
  223.  
  224.       E'L
  225.  
  226.       F'N STATUS
  227.  
  228. *-------------- end of dgetch  -----------------------------------------
  229. *-------------- start of dputch  ---------------------------------------
  230. *     dputch is part of a simplified interface for manipulating
  231. *     text files with the new file manager.  dputch is used to
  232. *     write a stream of characters to a text file.
  233. *     dputch takes two arguments:
  234. *     1) CHAR is a single char from the file described in FD.  The
  235. *        character is in kermit format.  The end of line is indicated by
  236. *        the symbol CR.
  237. *     1) FD is a buffer that contains information about the file and
  238. *        the record being manipulated.  the information in FD is to be
  239. *        hidden from the user so that information can be added,deleted
  240. *        or changed without the need to support existing structures.
  241. *        The size of FD is defined by FD&SIZE. The buffer will need to
  242. *        be created by an ALLOC call because the buffer is larger than a
  243. *        local data section.
  244.  
  245.       E'O DPUTCH.(CHAR, FD)
  246.  
  247.       STATUS = 0
  248. #     E'E HEXDMP.(0,0,0,CHAR)
  249. #     E'E HEXDMP.(1,50,1,FD(FD&TXTC))
  250.       W'R CHAR .NE. '000D'
  251.          W'R CHAR .E. '000A' .AND. FD(FD&TXTC) .E. 0 , T:O EXITPCH
  252.          FD(FD&NDX) = FD(FD&NDX) + 1
  253.          W'R PACKLINE.((CHAR), FD(FD&TXTC)) .NE. -1, T:O EXITPCH
  254.       E'L
  255.       WRSPEC(0) = 2
  256.       WRSPEC(1) = %RECLEN
  257.       WRSPEC(2) = FD(FD&TXTC)
  258.       WRSPEC(3) = %RTNERR
  259.       E'E F&WRITE.(FD(FD&CHAN), 1, FD(FD&TXTB), WRSPEC, OTSPC, STATUS)
  260.  
  261.       FD(FD&TXTC)  = FD(FD&NDX) = 0
  262.       FD(FD&LNPOS) = FD(FD&LNPOS) + 1
  263.  
  264. EXITPCH C'E
  265.       F'N STATUS
  266.  
  267.  
  268. *-------------- end of dputch  -----------------------------------------
  269. *-------------- start of closstrm -------------------------------------
  270. *     closstrm is part of a simplified interface for manipulating
  271. *     text files with the new file manager.  closstrm is used to
  272. *     close a text file used for stream io.
  273. *     closstrm takes one argument:
  274. *     1) FD is a buffer that contains information about the file and
  275. *        the record being manipulated.  the information in FD is to be
  276. *        hidden from the user so that information can be added,deleted
  277. *        or changed without the need to support existing structures.
  278. *        The size of FD is defined by FD&SIZE. The buffer will need to
  279. *        be created by an ALLOC call because the buffer is larger than a
  280. *        local data section.
  281. *
  282.       V'S CLOSPC = 1,
  283. 1                  %RTNERR
  284.  
  285.       E'O CLOSTEXT.(FD)
  286.  
  287. #     E'E TYPEMSG.($ CLOSSTRM!$)
  288. #     E'E HEXDMP.(0,0,0,FD(FD&TXTC))
  289.       W'R FD(FD&TXTC) .NE. 0
  290.          ;  the line buffer is not empty, so flush the line to disk
  291.          E'E DPUTCH.('000D', FD)
  292.       E'L
  293.  
  294.       E'E F&CLOSE.(FD(FD&CHAN),CLOSPC, STATUS)
  295.  
  296.       F'N STATUS
  297.  
  298. *-------------- end of clostext -------------------------------------
  299. *
  300.       E:N
  301.