Added command-line parsing, checks for valid files and the output folder

This commit is contained in:
AIR 2024-10-14 18:49:24 -04:00
parent d09c2ef7ef
commit 3764318445

View File

@ -4,9 +4,24 @@ $header
Function main(argc as int, argv as pchar ptr)
dim as JSON_Object Ptr root1, root2
dim as string filename1, filename2
if argc != 3 then
fprint stderr, "Usage: ", Appexename$, " <file1.db> <file2.db>"
end = 1
else
filename1 = command$(1)
filename2 = command$(2)
end if
checkFileName(filename1)
checkFileName(filename2)
if not exist("output") then mkpath("output")
root1 = loadJson(filename1)
root2 = loadJson(filename2)
root1 = loadJson("db.json")
root2 = loadJson("mac_db.json")
if root1 and root2 then
addFolderName(root1)
addFolderName(root2)
@ -20,6 +35,13 @@ Function main(argc as int, argv as pchar ptr)
End Function
Sub checkFileName(filename as string)
if not exist(filename) then
fprint stderr, "ERROR: Could not load ", filename
end = 1
end if
End Sub
Function loadJson(filename as string) as JSON_Object Ptr
dim as JSON_Value Ptr root