Skip to content

Instantly share code, notes, and snippets.

@olegchir
Created July 16, 2018 12:31
Show Gist options
  • Save olegchir/5f3de372452e71fa03eec86409ef69c9 to your computer and use it in GitHub Desktop.
Save olegchir/5f3de372452e71fa03eec86409ef69c9 to your computer and use it in GitHub Desktop.
object Config {
var width: Int = 10
private set
init {
val file = fopen("config.txt", "r")
if (file != null) {
try {
val buffer = ByteArray(2 * 1024)
while (true) {
val nextLine = fgets(buffer.refTo(0), buffer.size, file)?.toKString()
if (nextLine == null || nextLine.isEmpty()) break
val records = nextLine.split('=')
if (records.size != 2) continue
val key = records[0].trim()
val value = records[1].trim()
when (key) {
"width" -> width = value.toInt()
}
}
}
} finally {
fclose(file)
}
}
}
@vlsi
Copy link

vlsi commented Jul 17, 2018

-> в 18-ой строке

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment