virtualcomputer: unix-like operation system [WIP]

Former-commit-id: 68bb33337b78c7357d16a5a3ca47ad5f834f3d08
Former-commit-id: 6c8931a114682d2b1414414484597f5e0d0ca095
This commit is contained in:
Song Minjae
2016-10-02 01:18:58 +09:00
parent 3f34286b3f
commit 81958709ee
25 changed files with 650 additions and 193 deletions

View File

@@ -18,6 +18,9 @@ import java.util.*
* media/hda/ -> .../computers/<uuid for the hda>/
*
* Created by minjaesong on 16-09-17.
*
*
* NOTE: Don't convert '\' to '/'! Rev-slash is used for escape character in sh, and we're sh-compatible!
*/
internal class Filesystem(globals: Globals, computer: BaseTerrarumComputer) {
@@ -102,8 +105,6 @@ internal class Filesystem(globals: Globals, computer: BaseTerrarumComputer) {
// remove first '/' in path
var path = luapath.checkIBM437()
if (path.startsWith('/')) path = path.substring(1)
// replace '\' with '/'
path.replace('\\', '/')
if (path.startsWith("media/")) {
val device = path.substring(6, 9)
@@ -116,7 +117,7 @@ internal class Filesystem(globals: Globals, computer: BaseTerrarumComputer) {
}
fun combinePath(base: String, local: String) : String {
return "$base$local".replace("//", "/").replace("\\\\", "\\")
return "$base$local".replace("//", "/")
}
}
@@ -355,11 +356,11 @@ internal class Filesystem(globals: Globals, computer: BaseTerrarumComputer) {
var pathSB = StringBuilder(path.checkIBM437())
// backward travel, drop chars until '/' has encountered
while (!pathSB.endsWith('/') && !pathSB.endsWith('\\'))
while (!pathSB.endsWith('/'))
pathSB.deleteCharAt(pathSB.lastIndex - 1)
// drop trailing '/'
if (pathSB.endsWith('/') || pathSB.endsWith('\\'))
if (pathSB.endsWith('/'))
pathSB.deleteCharAt(pathSB.lastIndex - 1)
return LuaValue.valueOf(pathSB.toString())

View File

@@ -24,29 +24,17 @@ class WorldInformationProvider(globals: Globals) {
companion object {
fun getWorldTimeInLuaFormat() : LuaTable {
val t = LuaTable()
if (Terrarum.gameStarted) {
val time = Terrarum.ingame.world.time
val time = if (Terrarum.gameStarted) Terrarum.ingame.world.time else WorldTime()
// int Terrarum World Time format
t["hour"] = time.hours
t["min"] = time.minutes
t["wday"] = time.dayOfWeek
t["year"] = time.years
t["yday"] = time.yearlyDays
t["month"] = time.months
t["sec"] = time.seconds
t["day"] = time.days
}
else {
t["hour"] = 0
t["min"] = 0
t["wday"] = 1
t["year"] = 0
t["yday"] = 1
t["month"] = 1
t["sec"] = 0
t["day"] = 1
}
// int Terrarum World Time format
t["hour"] = time.hours
t["min"] = time.minutes
t["wday"] = time.dayOfWeek
t["year"] = time.years
t["yday"] = time.yearlyDays
t["month"] = time.months
t["sec"] = time.seconds
t["day"] = time.days
return t
}
@@ -55,52 +43,27 @@ class WorldInformationProvider(globals: Globals) {
/** evaluate single C date format */
fun String.evalAsDate(): String {
if (Terrarum.gameStarted) {
val time = Terrarum.ingame.world.time
return when (this) {
"%a" -> time.getDayNameShort()
"%A" -> time.getDayNameFull()
"%b" -> time.getMonthNameShort()
"%B" -> time.getMonthNameFull()
"%c" -> "%x".evalAsDate() + " " + "%X".evalAsDate()
"%d" -> time.days.toString()
"%H" -> time.hours.toString()
"%I" -> throw IllegalArgumentException("%I: AM/PM concept does not exists.")
"%M" -> time.minutes.toString()
"%m" -> time.months.toString()
"%p" -> throw IllegalArgumentException("%p: AM/PM concept does not exists.")
"%S" -> time.seconds.toString()
"%w" -> time.dayOfWeek.toString()
"%x" -> "${String.format("%02d", time.years)}-${String.format("%02d", time.months)}-${String.format("%02d", time.days)}"
"%X" -> "${String.format("%02d", time.hours)}:${String.format("%02d", time.minutes)}:${String.format("%02d", time.seconds)}"
"%Y" -> time.years.toString()
"%y" -> time.years.mod(100).toString()
"%%" -> "%"
else -> throw IllegalArgumentException("Unknown format string: $this")
}
}
else {
return when (this) {
"%a" -> "---"
"%A" -> "------"
"%b" -> "----"
"%B" -> "--------"
"%c" -> "%x".evalAsDate() + " " + "%X".evalAsDate()
"%d" -> "0"
"%H" -> "0"
"%I" -> throw IllegalArgumentException("%I: AM/PM concept does not exists.")
"%M" -> "0"
"%m" -> "0"
"%p" -> throw IllegalArgumentException("%p: AM/PM concept does not exists.")
"%S" -> "0"
"%w" -> "0"
"%x" -> "00-00-00"
"%X" -> "00:00:00"
"%Y" -> "0"
"%y" -> "00"
"%%" -> "%"
else -> throw IllegalArgumentException("Unknown format string: $this")
}
val time = if (Terrarum.gameStarted) Terrarum.ingame.world.time else WorldTime()
return when (this) {
"%a" -> time.getDayNameShort()
"%A" -> time.getDayNameFull()
"%b" -> time.getMonthNameShort()
"%B" -> time.getMonthNameFull()
"%c" -> "%x".evalAsDate() + " " + "%X".evalAsDate()
"%d" -> time.days.toString()
"%H" -> time.hours.toString()
"%I" -> throw IllegalArgumentException("%I: AM/PM concept does not exists.")
"%M" -> time.minutes.toString()
"%m" -> time.months.toString()
"%p" -> throw IllegalArgumentException("%p: AM/PM concept does not exists.")
"%S" -> time.seconds.toString()
"%w" -> time.dayOfWeek.toString()
"%x" -> "${String.format("%02d", time.years)}-${String.format("%02d", time.months)}-${String.format("%02d", time.days)}"
"%X" -> "${String.format("%02d", time.hours)}:${String.format("%02d", time.minutes)}:${String.format("%02d", time.seconds)}"
"%Y" -> time.years.toString()
"%y" -> time.years.mod(100).toString()
"%%" -> "%"
else -> throw IllegalArgumentException("Unknown format string: $this")
}
}