Guest User

Untitled

a guest
Jul 16th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. object Config {
  2. var width: Int = 10
  3. private set
  4. init {
  5. val file = fopen("config.txt", "r")
  6. if (file != null) {
  7. try {
  8. val buffer = ByteArray(2 * 1024)
  9. while (true) {
  10. val nextLine = fgets(buffer.refTo(0), buffer.size, file)?.toKString()
  11. if (nextLine == null || nextLine.isEmpty()) break
  12. val records = nextLine.split('=')
  13. if (records.size != 2) continue
  14. val key = records[0].trim()
  15. val value = records[1].trim()
  16. when (key) {
  17. "width" -> width = value.toInt()
  18. }
  19. }
  20. }
  21. } finally {
  22. fclose(file)
  23. }
  24. }
  25. }
Add Comment
Please, Sign In to add comment