改进程序入口

This commit is contained in:
codeboss 2025-04-04 19:10:08 +08:00
parent e50acdebb7
commit 764e1bbb82
1 changed files with 78 additions and 63 deletions

View File

@ -2,78 +2,93 @@
open HtmlStruct.Content open HtmlStruct.Content
open System.Xml open System.Xml
open HtmlStruct.Assemble open HtmlStruct.Assemble
open HtmlStruct.Content
open HtmlStruct.Present open HtmlStruct.Present
open System.IO open System.IO
open System.Text
open System open System
open System.Diagnostics open System.Diagnostics
let html_generate (file_in:FileInfo) (dir_o:DirectoryInfo) =
let out_dir = Uri(dir_o.FullName)
let doc = XmlDocument()
doc.Load(file_in.FullName)
let prog = Program.GenerateFrom(doc)
let entry = AstVisitEntry(prog)
let visitor = UnitGenerate(prog)
entry.visitWith(visitor) |> ignore
let volume_pages = volume_page_assemble(visitor.contents()) |> List.map<VolumePage, IDomUnit> (fun x->x)
let story_pages = story_page_assemble(visitor.contents()) |> List.map<StoryPage, IDomUnit> (fun x->x)
let point_pages = slice_page_assemble(volume_pages @ story_pages)
volume_pages @ story_pages @ point_pages |> List.iter (fun it -> (it:?>PageAccess).setPageRoot(out_dir))
let makers = volume_pages @ story_pages @ point_pages
|> List.map(fun page_unit ->
match page_unit with
| :? SlicePage as point ->
PageMaker(point) :> PageText
| :? VolumePage as vol ->
PageMaker(vol)
| :? StoryPage as story ->
PageMaker(story)
| _ -> failwith ""
)
let index_page = IndexPage("汇总页面", volume_pages @ story_pages @ point_pages)
index_page.setPageRoot(out_dir)
let content = (index_page :> PageText).getHtmlText()
let href = index_page.pageURL()
File.WriteAllLines(href, [content])
for refs in makers do
let file_path = (refs.bindPage() :?> PageAccess).pageURL()
File.WriteAllLines(file_path, [refs.getHtmlText()])
let graph = StorylineGraphMake("故事线网络", story_pages|> List.map(fun x -> x :?> PageAccess))
let graph_code = graph.getGraphCode()
let stream = new StreamWriter(Path.Combine(dir_o.FullName, "storys_display.dot"), false)
stream.Write(graph_code)
stream.Flush()
Process.Start("dot", $"""-Tsvg -o{Path.Combine(dir_o.FullName, "storys_display.svg")} {Path.Combine(dir_o.FullName, "storys_display.dot")}""") |> ignore
let graph2 = VolumeGraphMake("卷章引用网络", (volume_pages@story_pages)|> List.map(fun d -> d :?> PageAccess))
let graph2_code = graph2.getGraphCode()
let stream2 = new StreamWriter(Path.Combine(dir_o.FullName, "volume_display.dot"), false)
stream2.Write(graph2_code)
stream2.Flush()
Process.Start("dot", $"""-Tsvg -o{Path.Combine(dir_o.FullName, "volume_display.svg")} {Path.Combine(dir_o.FullName, "volume_display.dot")}""") |> ignore
let args = System.Environment.GetCommandLineArgs()|> Array.toList let args = System.Environment.GetCommandLineArgs()|> Array.toList
if args.Length = 2 && args.Item(1) = "--help" then
System.Console.WriteLine("AstConv.exe -file xast文件路径 -odir ") //
match args.Length with
| 2 when args.Item(1) = "--help" ->
printfn "AstConv.exe --file xast文件路径 --html \n\tHTML"
printfn "AstConv.exe --file xast文件路径 --format\n\t"
exit 0 exit 0
if args.Length <> 5 then //
failwith "程序调用参数错误AstConv.exe -file xast文件路径 -odir " | 4 when args.Item(1) = "--file" && args.Item(3) = "--format" ->
printfn ""
let file_in, dir_o = match args.Item(1), args.Item(3) with // html
| "-file","-odir" -> | 5 when args.Item(1) = "--file" && args.Item(3) = "--html" ->
if not(FileInfo(args.Item 2).Exists) then if not(FileInfo(args.Item 2).Exists) then
failwith "xast" printfn "Arguments-Error:xast"
if not(DirectoryInfo(args.Item 4).Exists) then exit 0
failwith "" if not(DirectoryInfo(args.Item 4).Exists) then
FileInfo(args.Item 2), DirectoryInfo(args.Item 4) printfn "Arguments-Error:"
| _ -> failwith "程序调用参数错误AstConv.exe -file xast文件路径 -odir " exit 0
let out_dir = Uri(dir_o.FullName) let xfile, xdir = FileInfo(args.Item 2), DirectoryInfo(args.Item 4)
// html
html_generate xfile xdir
exit 0
let doc = XmlDocument() | _ ->
doc.Load(file_in.FullName) printfn ""
printfn "AstConv.exe --file xast文件路径 --html \n\tHTML"
let prog = Program.GenerateFrom(doc) printfn "AstConv.exe --file xast文件路径 --format\n\t"
let entry = AstVisitEntry(prog) exit 0
let visitor = UnitGenerate(prog)
entry.visitWith(visitor) |> ignore
let volume_pages = volume_page_assemble(visitor.contents()) |> List.map<VolumePage, IDomUnit> (fun x->x)
let story_pages = story_page_assemble(visitor.contents()) |> List.map<StoryPage, IDomUnit> (fun x->x)
let point_pages = slice_page_assemble(volume_pages @ story_pages)
volume_pages @ story_pages @ point_pages |> List.iter (fun it -> (it:?>PageAccess).setPageRoot(out_dir))
let makers = volume_pages @ story_pages @ point_pages
|> List.map(fun page_unit ->
match page_unit with
| :? SlicePage as point ->
PageMaker(point) :> PageText
| :? VolumePage as vol ->
PageMaker(vol)
| :? StoryPage as story ->
PageMaker(story)
| _ -> failwith ""
)
let index_page = IndexPage("汇总页面", volume_pages @ story_pages @ point_pages)
index_page.setPageRoot(out_dir)
let content = (index_page :> PageText).getHtmlText()
let href = index_page.pageURL()
File.WriteAllLines(href, [content])
for refs in makers do
let file_path = (refs.bindPage() :?> PageAccess).pageURL()
File.WriteAllLines(file_path, [refs.getHtmlText()])
let graph = StorylineGraphMake("故事线网络", story_pages|> List.map(fun x -> x :?> PageAccess))
let graph_code = graph.getGraphCode()
let stream = new StreamWriter(Path.Combine(dir_o.FullName, "storys_display.dot"), false)
stream.Write(graph_code)
stream.Flush()
Process.Start("dot", $"""-Tsvg -o{Path.Combine(dir_o.FullName, "storys_display.svg")} {Path.Combine(dir_o.FullName, "storys_display.dot")}""") |> ignore
let graph2 = VolumeGraphMake("卷章引用网络", (volume_pages@story_pages)|> List.map(fun d -> d :?> PageAccess))
let graph2_code = graph2.getGraphCode()
let stream2 = new StreamWriter(Path.Combine(dir_o.FullName, "volume_display.dot"), false)
stream2.Write(graph2_code)
stream2.Flush()
Process.Start("dot", $"""-Tsvg -o{Path.Combine(dir_o.FullName, "volume_display.svg")} {Path.Combine(dir_o.FullName, "volume_display.dot")}""") |> ignore