Better reading to buffer in example.

This commit is contained in:
Nikolay Igotti
2018-07-12 11:12:45 +03:00
parent d20fc12a08
commit faee954d1a
+12 -15
View File
@@ -30,21 +30,18 @@ object Config {
val file = fopen("config.txt", "r") val file = fopen("config.txt", "r")
if (file != null) { if (file != null) {
try { try {
memScoped { val buffer = ByteArray(2 * 1024)
val bufferLength = 2 * 1024 while (true) {
val buffer = allocArray<ByteVar>(bufferLength) val nextLine = fgets(buffer.refTo(0), buffer.size, file)?.toKString()
while (true) { if (nextLine == null || nextLine.isEmpty()) break
val nextLine = fgets(buffer, bufferLength, file)?.toKString() val records = nextLine.split('=')
if (nextLine == null || nextLine.isEmpty()) break if (records.size != 2) continue
val records = nextLine.split('=') val key = records[0].trim()
if (records.size != 2) continue val value = records[1].trim()
val key = records[0].trim() when (key) {
val value = records[1].trim() "width" -> width = value.toInt()
when (key) { "height" -> height = value.toInt()
"width" -> width = value.toInt() "startLevel" -> startLevel = value.toInt()
"height" -> height = value.toInt()
"startLevel" -> startLevel = value.toInt()
}
} }
} }
} finally { } finally {