initialise app with a file path, for the functionality of loading different files from the terminal

This commit is contained in:
2025-08-26 15:56:52 +01:00
parent a98ca50cf5
commit dcd3c3117e
5 changed files with 36 additions and 14 deletions

BIN
dsc

Binary file not shown.

View File

@@ -1,6 +1,7 @@
signature APP_INIT = signature APP_INIT =
sig sig
val fromWindowWidthAndHeight: int * int * int * int -> AppType.app_type val fromWindowWidthAndHeight: int * int * int * int * string
-> AppType.app_type
end end
structure AppInit :> APP_INIT = structure AppInit :> APP_INIT =
@@ -16,6 +17,7 @@ struct
, hFinish , hFinish
, canvasWidth , canvasWidth
, canvasHeight , canvasHeight
, filepath
) : app_type = ) : app_type =
let let
val (xClickPoints, yClickPoints) = val (xClickPoints, yClickPoints) =
@@ -38,7 +40,7 @@ struct
, showGraph = true , showGraph = true
, arrowX = 0 , arrowX = 0
, arrowY = 0 , arrowY = 0
, openFilePath = "" , openFilePath = filepath
, r = 0 , r = 0
, g = 0 , g = 0
, b = 0 , b = 0
@@ -50,7 +52,7 @@ struct
end end
fun fromWindowWidthAndHeight fun fromWindowWidthAndHeight
(windowWidth, windowHeight, canvasWidth, canvasHeight) = (windowWidth, windowHeight, canvasWidth, canvasHeight, filepath) =
if windowWidth > windowHeight then if windowWidth > windowHeight then
let let
val difference = windowWidth - windowHeight val difference = windowWidth - windowHeight
@@ -66,6 +68,7 @@ struct
, windowHeight , windowHeight
, canvasWidth , canvasWidth
, canvasHeight , canvasHeight
, filepath
) )
end end
else else
@@ -83,6 +86,7 @@ struct
, hFinish , hFinish
, canvasWidth , canvasWidth
, canvasHeight , canvasHeight
, filepath
) )
end end
end end

View File

@@ -1,13 +1,22 @@
structure CollisionTree = structure CollisionTree =
struct struct
local fun findLastChr (str, pos, findChr) =
fun findLastDot (str, pos) = if pos < 0 then ~1
if pos < 0 then ~1 else if String.sub (str, pos) = findChr then pos
else if String.sub (str, pos) = #"." then pos else findLastChr (str, pos - 1, findChr)
else findLastDot (str, pos - 1)
fun extractFileName str =
let
val lastSlash = findLastChr (str, String.size str - 1, #"/")
val strStart = lastSlash + 1
in
if lastSlash = ~1 then str
else String.substring (str, strStart, String.size str - strStart)
end
local
fun removeFileExtension str = fun removeFileExtension str =
let val lastDot = findLastDot (str, String.size str - 1) let val lastDot = findLastChr (str, String.size str - 1, #".")
in if lastDot = ~1 then str else String.substring (str, 0, lastDot) in if lastDot = ~1 then str else String.substring (str, 0, lastDot)
end end
@@ -16,18 +25,25 @@ struct
in String.implode acc in String.implode acc
end end
(* convert from kebab-case or snake_case to PascalCase *)
fun loop (#"-" :: chr :: tl, acc) = fun loop (#"-" :: chr :: tl, acc) =
let val acc = Char.toUpper chr :: acc let val acc = Char.toUpper chr :: acc
in loop (tl, acc) in loop (tl, acc)
end end
| loop (#"_" :: chr :: tl, acc) =
let val acc = Char.toUpper chr :: acc
in loop (tl, acc)
end
| loop ([#"-"], acc) = finish acc | loop ([#"-"], acc) = finish acc
| loop ([#"_"], acc) = finish acc
| loop (chr :: tl, acc) = | loop (chr :: tl, acc) =
loop (tl, chr :: acc) loop (tl, chr :: acc)
| loop ([], acc) = finish acc | loop ([], acc) = finish acc
in in
fun kebabCaseToPascalCase str = fun filenameToStructureName str =
let let
val str = removeFileExtension str val str = removeFileExtension str
val str = extractFileName str
in in
(* capitalise first character in string *) (* capitalise first character in string *)
case String.explode str of case String.explode str of

View File

@@ -2,7 +2,7 @@ structure InitGlfw =
struct struct
open CML open CML
fun init () = fun init path () =
let let
(* Set up GLFW. *) (* Set up GLFW. *)
val _ = Glfw.init () val _ = Glfw.init ()
@@ -20,6 +20,7 @@ struct
, Constants.windowHeight , Constants.windowHeight
, Constants.initialWidthClickPoints , Constants.initialWidthClickPoints
, Constants.initialHeightClickPoints , Constants.initialHeightClickPoints
, path
) )
val graphLines = GraphLines.generate initialModel val graphLines = GraphLines.generate initialModel
@@ -59,6 +60,6 @@ struct
() ()
end end
fun main () = fun main path =
(RunCML.doit (init, NONE); ()) (RunCML.doit (init path, NONE); ())
end end

View File

@@ -3,7 +3,8 @@ struct
fun main () = fun main () =
case CommandLine.arguments () of case CommandLine.arguments () of
["-r"] => Converter.main () ["-r"] => Converter.main ()
| [] => InitGlfw.main () | [filename] => InitGlfw.main filename
| [] => print "error: no arguments\n"
| args => | args =>
let let
val args = String.concatWith "" args val args = String.concatWith "" args