SforzandoCF

lxoi

Oct 14th, 2025
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.43 KB | None | 0 0
  1. class Reader {
  2. instance char readChar ()
  3.  
  4. instance uChar readUnsignedChar () {
  5. return (uChar) instance.readChar()
  6. }
  7.  
  8. instance char[] readCharArray (int size) {
  9. char[] data = char.new[]
  10. for j = 0, j < size, j++
  11. data[*] = instance.readChar()
  12. return data
  13. }
  14.  
  15. instance word readWord () {
  16. return instance.readChar() << 8 or instance.readChar()
  17. }
  18.  
  19. instance uWord readUnsignedWord () {
  20. return (uWord) instance.readWord()
  21. }
  22.  
  23. instance word[] readWordArray (int size) {
  24. word[] data = word.new[]
  25. for j = 0, j < size, j++
  26. data[*] = instance.readWord()
  27. return data
  28. }
  29.  
  30. instance short readShort () {
  31. return instance.readWord() << 16 or instance.readWord()
  32. }
  33.  
  34. instance uShort readUnsignedShort () {
  35. return (uShort) instance.readShort()
  36. }
  37.  
  38. instance short[] readShortArray (int size) {
  39. short[] data = short.new[]
  40. for j = 0, j < size, j++
  41. data[*] = instance.readShort()
  42. return data
  43. }
  44.  
  45. instance int readInt () {
  46. return instance.readShort() << 32 or instance.readShort()
  47. }
  48.  
  49. instance uInt readUnsignedInt () {
  50. return (uInt) instance.readInt()
  51. }
  52.  
  53. instance int[] readIntArray (int size) {
  54. int[] data = int.new[]
  55. for j = 0, j < size, j++
  56. data[*] = instance.readInt()
  57. return data
  58. }
  59.  
  60. instance long readLong () {
  61. return instance.readInt() << 64 or instance.readInt()
  62. }
  63.  
  64. instance uLong readUnsignedLong () {
  65. return (uLong) instance.readLong()
  66. }
  67.  
  68. instance long[] readLongArray (int size) {
  69. long[] data = long.new[]
  70. for j = 0, j < size, j++
  71. data[*] = instance.readLong()
  72. return data
  73. }
  74.  
  75. instance float readFloat () {
  76. return (float) instance.readUnsignedShort()
  77. }
  78.  
  79. instance float[] readFloatArray (int size) {
  80. float[] data = float.new[]
  81. for j = 0, j < size, j++
  82. data[*] = instance.readFloat()
  83. return data
  84. }
  85.  
  86. instance double readDouble () {
  87. return (double) instance.readUnsignedInt()
  88. }
  89.  
  90. instance double[] readDoubleArray (int size) {
  91. char[] data = char.new[]
  92. for j = 0, j < size, j++
  93. data[*] = instance.readDouble()
  94. return data
  95. }
  96.  
  97. instance qfloat readQFloat () {
  98. return (qfloat) instance.readUnsignedLong()
  99. }
  100.  
  101. instance qfloat[] readQFloatArray (int size) {
  102. qfloat[] data = qfloat.new[]
  103. for j = 0, j < size, j++
  104. data[*] = instance.readQFloat()
  105. return data
  106. }
  107.  
  108. instance boolean readBoolean () {
  109. return instance.readChar() is not 0
  110. }
  111.  
  112. instance boolean[] readPackedBooleanArray (int size) {
  113. int actualSize = (size / 8) + (size % 8).signum()
  114. boolean[] data = boolean.new[]
  115. for j = 0, j < size, j++ {
  116. char read = instance.readChar()
  117. data[*] = (read & 0x80) != 0
  118. data[*] = (read & 0x40) != 0
  119. data[*] = (read & 0x20) != 0
  120. data[*] = (read & 0x10) != 0
  121. data[*] = (read & 0x08) != 0
  122. data[*] = (read & 0x04) != 0
  123. data[*] = (read & 0x02) != 0
  124. data[*] = (read & 0x01) != 0
  125. }
  126. return data
  127. }
  128.  
  129. instance boolean[] readBooleanArray (int size) {
  130. boolean[] data = boolean.new[]
  131. for j = 0, j < size, j++
  132. data[*] = instance.readBoolean()
  133. return data
  134. }
  135.  
  136. instance String readString (int length) {
  137. return new String(this.readCharArray(length))
  138. }
  139.  
  140. instance void skip (int amount)
  141. }
  142.  
  143. class File inherits Reader, Writer, Path {
  144. private NativePointer file
  145. private int offset = 0
  146. private String name
  147. private boolean temp
  148.  
  149. File new ()
  150.  
  151. File new (String path) {
  152. File this = new()
  153. this.file = NativeInterface.cstdio_fopen(path, "rb+")
  154. if (this.file is NativeInterface.cstdio_NULL) throw IOError.new()
  155. this.name = path
  156. return this
  157. }
  158.  
  159. File new (File path) {
  160. return new(path.path)
  161. }
  162.  
  163. File newTemp () {
  164. File this = new()
  165. this.file = NativeInterface.cstdio_tmpfile()
  166. if this.file is NativeInterface.cstdio_NULL
  167. throw IOError.new()
  168. this.name = "?tempfile"
  169. return this
  170. }
  171.  
  172. instance void delete () {
  173. NativeInterface.cstdio_fclose(instance.file)
  174. if instance.temp
  175. NativeInterface.cstdio_remove(instance.path)
  176. instance._delete()
  177. }
  178.  
  179. instance char readChar () {
  180. char read = NativeInterface.cstdio_fgetc(instance.file)
  181. if read is NativeInterface.cstdio_EOF {
  182. if NativeInterface.cstdio_feof(instance.file)
  183. throw EOFError.new()
  184. if NativeInterface.cstdio_ferror(instance.file)
  185. throw IOError.new()
  186. }
  187. instance.offset++
  188. return read
  189. }
  190.  
  191. instance void writeChar (char c) {
  192. char read = NativeInterface.cstdio_fputc(c, instance.file)
  193. if read is NativeInterface.cstdio_EOF
  194. throw IOError.new()
  195. instance.offset++
  196. return read
  197. }
  198.  
  199. instance void skip (int amount) {
  200. if NativeInterface.cstdio_fseek(instance.file, (short) amount, NativeInterface.cstdio_SEEK_SET is not 0)
  201. throw IOError.new()
  202. instance.offset += amount
  203. }
  204.  
  205. instance void setReadOnly () {
  206. instance.file = NativeInterface.freopen(null, "rb", instance.file)
  207. if (instance.file = NativeInterface.cstdio_NULL) throw IOError.new()
  208. if NativeInterface.cstdio_fseek(instance.file, instance.offset, NativeInterface.cstdio_SEEK_SET is not 0)
  209. throw IOError.new()
  210. }
  211.  
  212. instance void setTemporary () {
  213. if instance.name is "?tempfile"
  214. throw IllegalStateError.new()
  215. instance.temp = true
  216. LX01.onExit(() {
  217. NativeInterface.cstdio_remove(instance.path)
  218. })
  219. }
Advertisement
Add Comment
Please, Sign In to add comment