package odin_html_docs
import doc "core:odin/doc-format"
import "core:fmt"
import "core:io"
import "core:os"
import "core:strings"
import "core:path/slashpath"
import "core:sort"
import "core:slice"
GITHUB_LICENSE_URL :: "https://github.com/odin-lang/Odin/tree/master/LICENSE"
GITHUB_CORE_URL :: "https://github.com/odin-lang/Odin/tree/master/core"
BASE_CORE_URL :: "/core"
header: ^doc.Header
files: []doc.File
pkgs: []doc.Pkg
entities: []doc.Entity
types: []doc.Type
pkgs_to_use: map[string]^doc.Pkg // trimmed path
pkg_to_path: map[^doc.Pkg]string // trimmed path
array :: proc(a: $A/doc.Array($T)) -> []T {
return doc.from_array(header, a)
}
str :: proc(s: $A/doc.String) -> string {
return doc.from_string(header, s)
}
errorf :: proc(format: string, args: ..any) -> ! {
fmt.eprintf("%s ", os.args[0])
fmt.eprintf(format, ..args)
fmt.eprintln()
os.exit(1)
}
base_type :: proc(t: doc.Type) -> doc.Type {
t := t
for {
if t.kind != .Named {
break
}
t = types[array(t.types)[0]]
}
return t
}
is_type_untyped :: proc(type: doc.Type) -> bool {
if type.kind == .Basic {
flags := transmute(doc.Type_Flags_Basic)type.flags
return .Untyped in flags
}
return false
}
common_prefix :: proc(strs: []string) -> string {
if len(strs) == 0 {
return ""
}
n := max(int)
for str in strs {
n = min(n, len(str))
}
prefix := strs[0][:n]
for str in strs[1:] {
for len(prefix) != 0 && str[:len(prefix)] != prefix {
prefix = prefix[:len(prefix)-1]
}
if len(prefix) == 0 {
break
}
}
return prefix
}
recursive_make_directory :: proc(path: string, prefix := "") {
head, _, tail := strings.partition(path, "/")
path_to_make := head
if prefix != "" {
path_to_make = fmt.tprintf("%s/%s", prefix, head)
}
os.make_directory(path_to_make, 0)
if tail != "" {
recursive_make_directory(tail, path_to_make)
}
}
write_html_header :: proc(w: io.Writer, title: string) {
fmt.wprintf(w, string(#load("header.txt.html")), title)
io.write(w, #load("header-lower.txt.html"))
}
write_html_footer :: proc(w: io.Writer, include_directory_js: bool) {
fmt.wprintf(w, "\n")
io.write(w, #load("footer.txt.html"))
if false && include_directory_js {
io.write_string(w, `
`)
}
fmt.wprintf(w, "