Files
sml-projects/imperative-shell/file-thread.sml

99 lines
2.9 KiB
Standard ML
Raw Normal View History

signature FILE_THREAD =
sig
val run: FileMessage.t Mailbox.mbox * InputMessage.t Mailbox.mbox -> unit
end
structure FileThread :> FILE_THREAD =
struct
open FileMessage
open InputMessage
2025-07-06 15:06:00 +01:00
datatype parse_result = OK of unit | PARSE_ERROR
val structureName = "Green"
val filename = "green.dsc"
val exportFilename = "green.sml"
fun ndcToLerpX num =
let
val num = (num + 1.0) / 2.0
val num = Real32.toString num
val num =
(* Problem: It seems that Real32.toString may sometimes return a string
* that is recognised as an integer, like "1" instead of "1.0".
* If that happens, we just add a ".0" to the end
* so it's recognised as a real. *)
if String.isSubstring "." num then num
else num ^ ".0"
in
" (((startX * (1.0 - " ^ num ^ ")) + (endX * " ^ num
^ ")) / windowWidth) - 1.0"
end
fun ndcToLerpY num =
let
val num = (num + 1.0) / 2.0
val num = Real32.toString num
val num = if String.isSubstring "." num then num else num ^ ".0"
in
" (((startY * (1.0 - " ^ num ^ ")) + (endY * " ^ num
^ ")) / windowHeight) - 1.0"
end
fun colToString col =
let val col = Real32.toString col
in if String.isSubstring "." col then col else col ^ ".0"
end
2025-07-06 15:06:00 +01:00
fun exportSquares squares = ()
2025-07-06 15:06:00 +01:00
fun parse (io, acc) = ()
2025-07-06 15:06:00 +01:00
fun loadSquares (path, inputMailbox) = ()
2025-07-06 15:06:00 +01:00
fun saveSquares squares = ()
fun getDirList (dir, acc, rootPath) =
case OS.FileSys.readDir dir of
SOME path =>
let
val folderPath = String.concat [rootPath, "/", path]
in
if OS.FileSys.isDir folderPath then
getDirList (dir, AppType.IS_FOLDER path :: acc, rootPath)
else if OS.FileSys.isLink folderPath then
getDirList (dir, acc, rootPath)
else
getDirList (dir, AppType.IS_FILE path :: acc, rootPath)
end
| NONE => let val acc = List.rev acc in Vector.fromList acc end
fun loadFiles (path, inputMailbox) =
let
val path = if String.size path = 0 then OS.FileSys.getDir () else path
val dir = OS.FileSys.openDir path
val dirList = getDirList (dir, [], path)
val _ = OS.FileSys.closeDir dir
2024-09-27 10:06:21 +01:00
val inputMsg = FILE_BROWSER_AND_PATH {fileBrowser = dirList, path = path}
in
2024-09-27 10:06:21 +01:00
Mailbox.send (inputMailbox, inputMsg)
end
fun selectPath (path, inputMailbox) =
if OS.FileSys.isDir path then loadFiles (path, inputMailbox)
2025-07-06 15:06:00 +01:00
else loadSquares (path, inputMailbox)
fun run (fileMailbox, inputMailbox) =
let
val _ =
case Mailbox.recv fileMailbox of
2025-07-06 15:06:00 +01:00
SAVE_SQUARES triangles => saveSquares triangles
| LOAD_SQUARES => loadSquares (filename, inputMailbox)
| EXPORT_SQUARES triangles => exportSquares triangles
| LOAD_FILES path => loadFiles (path, inputMailbox)
| SELECT_PATH path => selectPath (path, inputMailbox)
in
run (fileMailbox, inputMailbox)
end
end