80 lines
3.4 KiB
Forth
80 lines
3.4 KiB
Forth
open AstAccess.AstImport
|
||
open HtmlStruct.Content
|
||
open System.Xml
|
||
open HtmlStruct.Assemble
|
||
open HtmlStruct.Content
|
||
open HtmlStruct.Present
|
||
open System.IO
|
||
open System.Text
|
||
open System
|
||
open System.Diagnostics
|
||
|
||
let args = System.Environment.GetCommandLineArgs()|> Array.toList
|
||
|
||
if args.Length = 2 && args.Item(1) = "--help" then
|
||
System.Console.WriteLine("AstConv.exe -file xast文件路径 -odir 输出文件夹路径")
|
||
exit 0
|
||
|
||
if args.Length <> 5 then
|
||
failwith "程序调用参数错误:AstConv.exe -file xast文件路径 -odir 输出文件夹路径"
|
||
|
||
let file_in, dir_o = match args.Item(1), args.Item(3) with
|
||
| "-file","-odir" ->
|
||
if not(FileInfo(args.Item 2).Exists) then
|
||
failwith "指定xast文件不存在"
|
||
if not(DirectoryInfo(args.Item 4).Exists) then
|
||
failwith "指定输出文件夹不存在"
|
||
FileInfo(args.Item 2), DirectoryInfo(args.Item 4)
|
||
| _ -> failwith "程序调用参数错误:AstConv.exe -file xast文件路径 -odir 输出文件夹路径"
|
||
|
||
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
|