home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 September / PCO_0998.ISO / filesbbs / dos / sbbs230b.exe / EXEC.LZH / FILE_IO.SRC < prev    next >
Encoding:
Text File  |  1995-09-05  |  2.7 KB  |  179 lines

  1. # FILE_IO.SRC
  2.  
  3. # Baja module for performing various i/o operations on a single file
  4.  
  5. !include file_io.inc
  6.  
  7. # Variables
  8. int file
  9. int len
  10. int pos
  11. int time
  12. int int
  13. str buf
  14. str name
  15.  
  16. # Get filename to open
  17. print "\r\nFilename: "
  18. getstr
  19. copy name str
  20. fopen file O_RDWR|O_CREAT|O_DENYNONE str
  21. if_false
  22.     printf "Failed to open %s\r\n" name
  23.     return
  24.     end_if
  25.  
  26. cmd_home
  27. fget_length file len
  28. fget_pos    file pos
  29.  
  30. crlf
  31. printf "Filename=%s\r\n" name
  32. fget_time file time
  33. time_str str time
  34. printf "Buf=%s\r\nInt=%ld  Pos=%ld  Len=%ld  Time=%s\r\n" buf int pos len str
  35. feof file
  36. if_true
  37.     print "At EOF\r\n"
  38.     end_if
  39. crlf
  40. print "[R] Read buf       [W] Write buf\r\n"
  41. print "[G] Get int        [P] Put int\r\n"
  42. print "[S] Seek           [B] Rewind\r\n"
  43. print "[L] Lock           [U] Unlock\r\n"
  44. print "[F] Fprintf        [C] Change len\r\n"
  45. print "[D] Change date    [Z] End of file\r\n"
  46. print "[E] ETX Char\r\n"
  47. crlf
  48. print "Which or [Q]uit: "
  49. getkey
  50. printkey
  51. crlf
  52.  
  53. cmdkey Q
  54.     print "Close: "
  55.     fclose file
  56.     call success
  57.     cmdpop
  58.     return
  59.     end_cmd
  60.  
  61. cmdkey S
  62.     print "Seek to: "
  63.     getstr
  64.     copy pos str
  65.     fset_pos file pos
  66.     call success
  67.     end_cmd
  68.  
  69. cmdkey B
  70.     print "Rewinding...\r\n"
  71.     fset_pos file 0
  72.     call success
  73.     end_cmd
  74.  
  75.  
  76. cmdkey Z
  77.     print "Seeking to End of File...\r\n"
  78.     fset_pos file 0 SEEK_END
  79.     call success
  80.         end_cmd
  81.  
  82. cmdkey R
  83.     print "Length to read: "
  84.     getstr
  85.     copy len str
  86.     fread file buf len
  87.     call success
  88.     end_cmd
  89.  
  90. cmdkey G
  91.     print "Length to read: "
  92.     getstr
  93.     copy len str
  94.     fread file int len
  95.     call success
  96.     end_cmd
  97.  
  98. cmdkey P
  99.     print "Length to write: "
  100.     getstr
  101.     copy len str
  102.     print "Int: "
  103.     getstr
  104.     copy int str
  105.     fwrite file int len
  106.     call success
  107.     end_cmd
  108.  
  109. cmdkey W    
  110.     print "Length to write: "
  111.     getstr
  112.     copy len str
  113.     print "String: "
  114.     getstr
  115.     fwrite file str len
  116.     call success
  117.     end_cmd
  118.  
  119. cmdkey F
  120.     print "String: "
  121.     getstr
  122.     fprintf file "%s" str
  123.     call success
  124.     end_cmd
  125.  
  126. cmdkey L
  127.     print "Length to lock: "
  128.     getstr
  129.     copy len str
  130.     flock file len
  131.     call success
  132.     end_cmd
  133.  
  134. cmdkey U
  135.     print "Length to unlock: "
  136.     getstr
  137.     copy len str
  138.     funlock file len
  139.     call success
  140.     end_cmd
  141.  
  142. cmdkey C
  143.     print "New length of file: "
  144.     getstr
  145.     copy len str
  146.     fset_length file len
  147.     call success
  148.     end_cmd
  149.  
  150. cmdkey E
  151.     yes_no "Use ETX (3) instead of NULL (0) for terminating text"
  152.     if_true
  153.         fset_etx 3
  154.     else
  155.         fset_etx 0
  156.         end_if
  157.     end_cmd
  158.  
  159. cmdkey D
  160.     print "New file date (MM/DD/YY): "
  161.     getstr
  162.     date_int time str
  163.     fset_time file time
  164.     call success
  165.     end_cmd    
  166.  
  167. end_cmd
  168.  
  169.  
  170. # Print "Successful" or "Unsuccessful" based on the current logic state
  171. :success
  172. if_true
  173.     print "Successful\r\n"
  174. else
  175.     print "Unsuccessful\r\n"
  176.     end_if
  177. return
  178.  
  179.