From 2080118568b3d83ddfefa184ba51248a76c04b48 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Tue, 26 Aug 2025 14:27:39 +0100 Subject: [PATCH] progress with conversion functionality --- dotscape.mlb | 2 ++ imperative-shell/converter.sml | 45 ++++++++++++++++++++++++++++++++++ imperative-shell/shell.sml | 2 +- 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 imperative-shell/converter.sml diff --git a/dotscape.mlb b/dotscape.mlb index d67cfd6..d47fd5e 100644 --- a/dotscape.mlb +++ b/dotscape.mlb @@ -73,4 +73,6 @@ imperative-shell/file-thread.sml imperative-shell/draw-thread.sml imperative-shell/init-glfw.sml +imperative-shell/converter.sml + imperative-shell/shell.sml diff --git a/imperative-shell/converter.sml b/imperative-shell/converter.sml new file mode 100644 index 0000000..22476b5 --- /dev/null +++ b/imperative-shell/converter.sml @@ -0,0 +1,45 @@ +structure Converter = +struct + fun endsWithDsc str = + if String.size str >= 4 then + let + val size = String.size str + val expectedExtension = String.substring (str, size - 4, 4) + in + expectedExtension = ".dsc" + end + else + false + + fun convertFile path = () + + fun loop (dir, rootPath) = + case OS.FileSys.readDir dir of + SOME path => + let + val folderPath = String.concat [rootPath, "/", path] + in + if OS.FileSys.isDir folderPath then + (* handle folder *) + let val newDir = OS.fileSys.openDir folderPath + in loop (newDir, folderPath) + end + else if OS.FileSys.isLink folderPath then + (* continue looping and ignore *) + loop (dir, rootPath) + else + (* handle file, if file has ".dsc" at the end *) + let val () = if endsWithDsc path then convertFile folderPath else () + in loop (dir, rootPath) + end + end + | NONE => OS.FileSys.closeDir dir + + fun main () = + let + val path = OS.FileSys.getDir () + val dir = OS.FileSys.openDir path + in + loop (dir, path) + end +end diff --git a/imperative-shell/shell.sml b/imperative-shell/shell.sml index af2fcfa..fea114e 100644 --- a/imperative-shell/shell.sml +++ b/imperative-shell/shell.sml @@ -2,7 +2,7 @@ structure Shell = struct fun main () = case CommandLine.arguments () of - ["-r"] => (print "todo: convert dsc files to sml file\n") + ["-r"] => Converter.main () | [] => InitGlfw.main () | args => let