77 lines
2.3 KiB
Odin
77 lines
2.3 KiB
Odin
#+vet explicit-allocators
|
|
package main
|
|
|
|
import "base:runtime"
|
|
import "core:fmt"
|
|
import vmem "core:mem/virtual"
|
|
import "core:mem"
|
|
import "core:os"
|
|
import "core:strings"
|
|
import "core:time"
|
|
import fleg "flag"
|
|
|
|
/* Order of operations:
|
|
* 1. Generate blog/index.md
|
|
* 2. Parse ALL .md files into .html files
|
|
* 3. Write HTML prefixes into .hmtl files
|
|
* 4. (write fancy timings and footer for main page)
|
|
*/
|
|
|
|
main :: proc() {
|
|
// Arena used for ALL allocations, easier to drop everything at end of execution.
|
|
arena: vmem.Arena
|
|
arena_err := vmem.arena_init_growing(&arena)
|
|
ensure(arena_err == nil)
|
|
arena_alloc := vmem.arena_allocator(&arena)
|
|
context.allocator = arena_alloc
|
|
defer vmem.arena_destroy(&arena) //clean up everything!
|
|
|
|
when ODIN_DEBUG {
|
|
total_size: int
|
|
track: mem.Tracking_Allocator
|
|
mem.tracking_allocator_init(&track, context.allocator, context.allocator)
|
|
context.allocator = mem.tracking_allocator(&track)
|
|
|
|
defer {
|
|
if len(track.allocation_map) > 0 {
|
|
fmt.eprintf("=== %v allocations not freed: ===\n", len(track.allocation_map))
|
|
for _, entry in track.allocation_map {
|
|
fmt.eprintf("- %v bytes @ %v\n", entry.size, entry.location)
|
|
total_size += entry.size
|
|
}
|
|
}
|
|
if len(track.bad_free_array) > 0 {
|
|
fmt.eprintf("=== %v incorrect frees: ===\n", len(track.bad_free_array))
|
|
for entry in track.bad_free_array {
|
|
fmt.eprintf("- %p @ %v\n", entry.memory, entry.location)
|
|
}
|
|
}
|
|
fmt.printfln("[INFO] TOTAL: %v bytes at end of generation!", total_size)
|
|
mem.tracking_allocator_destroy(&track)
|
|
}
|
|
}
|
|
|
|
fleg.init_custom_allocator(context.allocator)
|
|
//defer fleg.destroy() //not needed when we free the alloc' anyway
|
|
|
|
directory: string
|
|
output_dir: string
|
|
fleg.StringVar(&directory, "dir", "", "input directory of .MD files", required = true)
|
|
fleg.StringVar(&output_dir, "out", "", "output directory (html files)", required = true)
|
|
fleg.parse_flags()
|
|
|
|
start := time.tick_now() //start timer for footer
|
|
|
|
// First generate the blog index MARKDOWN file
|
|
generate_blog_index_md_file(directory, context.allocator)
|
|
|
|
// Walk directory and collect .md files
|
|
md_files := walk_tree_and_get_md_names(directory, context.allocator)
|
|
|
|
// Generate all .md files in .html files
|
|
generate_all_md_files_to_html(md_files, directory, output_dir, start, context.allocator)
|
|
|
|
defer free_all(context.allocator)
|
|
|
|
}
|