diff --git a/dsc b/dsc index 05eb6bf..d536d5d 100755 Binary files a/dsc and b/dsc differ diff --git a/fcore/app-init.sml b/fcore/app-init.sml index 7a6e8a1..a72e12d 100644 --- a/fcore/app-init.sml +++ b/fcore/app-init.sml @@ -1,6 +1,7 @@ signature APP_INIT = sig - val fromWindowWidthAndHeight: int * int * int * int -> AppType.app_type + val fromWindowWidthAndHeight: int * int * int * int * string + -> AppType.app_type end structure AppInit :> APP_INIT = @@ -16,6 +17,7 @@ struct , hFinish , canvasWidth , canvasHeight + , filepath ) : app_type = let val (xClickPoints, yClickPoints) = @@ -38,7 +40,7 @@ struct , showGraph = true , arrowX = 0 , arrowY = 0 - , openFilePath = "" + , openFilePath = filepath , r = 0 , g = 0 , b = 0 @@ -50,7 +52,7 @@ struct end fun fromWindowWidthAndHeight - (windowWidth, windowHeight, canvasWidth, canvasHeight) = + (windowWidth, windowHeight, canvasWidth, canvasHeight, filepath) = if windowWidth > windowHeight then let val difference = windowWidth - windowHeight @@ -66,6 +68,7 @@ struct , windowHeight , canvasWidth , canvasHeight + , filepath ) end else @@ -83,6 +86,7 @@ struct , hFinish , canvasWidth , canvasHeight + , filepath ) end end diff --git a/fcore/quad-tree.sml b/fcore/quad-tree.sml index 2a949f4..30717ce 100644 --- a/fcore/quad-tree.sml +++ b/fcore/quad-tree.sml @@ -1,13 +1,22 @@ structure CollisionTree = struct - local - fun findLastDot (str, pos) = - if pos < 0 then ~1 - else if String.sub (str, pos) = #"." then pos - else findLastDot (str, pos - 1) + fun findLastChr (str, pos, findChr) = + if pos < 0 then ~1 + else if String.sub (str, pos) = findChr then pos + else findLastChr (str, pos - 1, findChr) + 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 = - 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) end @@ -16,18 +25,25 @@ struct in String.implode acc end + (* convert from kebab-case or snake_case to PascalCase *) fun loop (#"-" :: chr :: tl, acc) = let val acc = Char.toUpper chr :: acc in loop (tl, acc) 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 (chr :: tl, acc) = loop (tl, chr :: acc) | loop ([], acc) = finish acc in - fun kebabCaseToPascalCase str = + fun filenameToStructureName str = let val str = removeFileExtension str + val str = extractFileName str in (* capitalise first character in string *) case String.explode str of diff --git a/imperative-shell/init-glfw.sml b/imperative-shell/init-glfw.sml index 7c7fbe9..29a9332 100644 --- a/imperative-shell/init-glfw.sml +++ b/imperative-shell/init-glfw.sml @@ -2,7 +2,7 @@ structure InitGlfw = struct open CML - fun init () = + fun init path () = let (* Set up GLFW. *) val _ = Glfw.init () @@ -20,6 +20,7 @@ struct , Constants.windowHeight , Constants.initialWidthClickPoints , Constants.initialHeightClickPoints + , path ) val graphLines = GraphLines.generate initialModel @@ -59,6 +60,6 @@ struct () end - fun main () = - (RunCML.doit (init, NONE); ()) + fun main path = + (RunCML.doit (init path, NONE); ()) end diff --git a/imperative-shell/shell.sml b/imperative-shell/shell.sml index fea114e..f39b4fe 100644 --- a/imperative-shell/shell.sml +++ b/imperative-shell/shell.sml @@ -3,7 +3,8 @@ struct fun main () = case CommandLine.arguments () of ["-r"] => Converter.main () - | [] => InitGlfw.main () + | [filename] => InitGlfw.main filename + | [] => print "error: no arguments\n" | args => let val args = String.concatWith "" args