standardio.bmx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. SuperStrict
  2. Rem
  3. bbdoc: System/StandardIO
  4. End Rem
  5. Module BRL.StandardIO
  6. ModuleInfo "Version: 1.07"
  7. ModuleInfo "Author: Mark Sibly"
  8. ModuleInfo "License: zlib/libpng"
  9. ModuleInfo "Copyright: Blitz Research Ltd"
  10. ModuleInfo "Modserver: BRL"
  11. ModuleInfo "History: 1.07"
  12. ModuleInfo "History: Module is now SuperStrict"
  13. ModuleInfo "History: 1.06"
  14. ModuleInfo "History: Added Eof() method to TCStandardIO"
  15. ModuleInfo "History: 1.05 Release"
  16. ModuleInfo "History: 1.04 Release"
  17. ModuleInfo "History: CStandardIO now goes through a UTF8 textstream"
  18. Import BRL.TextStream
  19. Type TCStandardIO Extends TStream
  20. Method Eof:Int() Override
  21. Return feof_( stdin_ )
  22. End Method
  23. Method Flush() Override
  24. fflush_ stdout_
  25. End Method
  26. Method Read:Long( buf:Byte Ptr,count:Long ) Override
  27. Return fread_( buf,1,count,stdin_ )
  28. End Method
  29. Method Write:Long( buf:Byte Ptr,count:Long ) Override
  30. Return fwrite_( buf,1,count,stdout_ )
  31. End Method
  32. End Type
  33. Type TCStandardErrIO Extends TStream
  34. Method Flush() Override
  35. fflush_ stderr_
  36. End Method
  37. Method Write:Long( buf:Byte Ptr,count:Long ) Override
  38. Return fwrite_( buf,1,count,stderr_ )
  39. End Method
  40. End Type
  41. Rem
  42. bbdoc: BlitzMax Stream object used for Print and Input
  43. about: The #Print and #Input commands can be redirected by setting the @StandardIOStream Global to an alternative Stream Object.
  44. End Rem
  45. Global StandardIOStream:TStream=TTextStream.Create( New TCStandardIO,ETextStreamFormat.UTF8 )
  46. Rem
  47. bbdoc: BlitzMax Stream object used for #ErrPrint
  48. End Rem
  49. Global StandardErrIOStream:TStream=TTextStream.Create( New TCStandardErrIO,ETextStreamFormat.UTF8 )
  50. Rem
  51. bbdoc: Write a string to the standard errIO stream
  52. about: A newline character is also written after @str.
  53. End Rem
  54. Function Print( str:String="" )
  55. StandardIOStream.WriteLine str
  56. StandardIOStream.Flush
  57. End Function
  58. Rem
  59. bbdoc: Write a string to the standard error IO stream
  60. about: A newline character is also written after @str.
  61. End Rem
  62. Function ErrPrint( str:String="" )
  63. StandardErrIOStream.WriteLine str
  64. StandardErrIOStream.Flush
  65. End Function
  66. Rem
  67. bbdoc: Receive a line of text from the standard IO stream
  68. about: The optional @prompt is displayed before input is returned.
  69. End Rem
  70. Function Input:String( prompt:String=">" )
  71. StandardIOStream.WriteString prompt
  72. StandardIOStream.Flush
  73. Return StandardIOStream.ReadLine()
  74. End Function