Compare commits

..
2 Commits
Author SHA1 Message Date
simonkellet 3b1e0cb3f0 better bash script 2026-09-11 14:40:23 +01:00
simonkellet 59d6016296 added debug with mem tracker 2026-09-11 14:40:07 +01:00
2 changed files with 97 additions and 10 deletions
+41 -10
View File
@@ -1,8 +1,9 @@
#+vet explicit-allocators //#+vet explicit-allocators
package main package main
import "core:fmt" import "core:fmt"
import vmem "core:mem/virtual" import vmem "core:mem/virtual"
import "core:mem"
import "core:os" import "core:os"
import "core:strings" import "core:strings"
import "core:time" import "core:time"
@@ -58,10 +59,36 @@ main :: proc() {
arena_err := vmem.arena_init_growing(&arena) arena_err := vmem.arena_init_growing(&arena)
ensure(arena_err == nil) ensure(arena_err == nil)
arena_alloc := vmem.arena_allocator(&arena) arena_alloc := vmem.arena_allocator(&arena)
context.allocator = arena_alloc
defer vmem.arena_destroy(&arena) //clean up everything! defer vmem.arena_destroy(&arena) //clean up everything!
fleg.init_custom_allocator(arena_alloc) when ODIN_DEBUG {
defer fleg.destroy() total_size: int
track: mem.Tracking_Allocator
mem.tracking_allocator_init(&track, 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 needede when we free the alloc' anyway
directory: string directory: string
output_dir: string output_dir: string
@@ -72,30 +99,34 @@ main :: proc() {
start := time.tick_now() //start timer for footer start := time.tick_now() //start timer for footer
// First generate the blog index MARKDOWN file // First generate the blog index MARKDOWN file
generate_blog_index_md_file(directory, arena_alloc) generate_blog_index_md_file(directory, context.allocator)
// Walk directory and collect .md files // Walk directory and collect .md files
md_files := walk_tree_and_get_md_names(directory, arena_alloc) md_files := walk_tree_and_get_md_names(directory, context.allocator)
// ************* MAIN LOOP ************ // ************* MAIN LOOP ************
for file, _ in md_files { for file, _ in md_files {
if file == ".DS_Store" { continue } //Ignore annoying MacOS (TODO: clean up proc?) if file == ".DS_Store" { continue } //Ignore annoying MacOS (TODO: clean up proc?)
md_filename := strings.split(file, directory, arena_alloc) md_filename := strings.split(file, directory, context.allocator)
trimmed_filename := strings.trim_right(md_filename[1], ".md") trimmed_filename := strings.trim_right(md_filename[1], ".md")
// sck: I am not sure if changing dir's is needed but I am now relying on it lol // sck: I am not sure if changing dir's is needed but I am now relying on it lol
os.change_directory(directory) os.change_directory(directory)
// turn all .md files into parsed .html files! // turn all .md files into parsed .html files!
html_content, parse_err := parse_file_md_to_html(file, arena_alloc) html_content, parse_err := parse_file_md_to_html(file, context.allocator)
if parse_err != nil { if parse_err != nil {
fmt.eprintfln("ERROR: Could not parse file %s: %s", file, os.error_string(parse_err)) fmt.eprintfln("ERROR: Could not parse file %s: %s", file, os.error_string(parse_err))
} }
final_html_file, html_file_err := create_html_file(file, directory, output_dir, arena_alloc)
final_html_file, html_file_err := create_html_file(file, directory, output_dir, context.allocator)
if html_file_err != nil {
fmt.eprintfln("ERROR: Could not create file %s: %s", file, os.error_string(html_file_err))
}
write_prefixs_to_html_file(final_html_file) write_prefixs_to_html_file(final_html_file)
os.write_string(final_html_file, html_content) //WRITE PAGE os.write_string(final_html_file, html_content) //WRITE PAGE
defer write_footer_and_timings(trimmed_filename, final_html_file, start, arena_alloc) defer write_footer_and_timings(trimmed_filename, final_html_file, start, context.allocator)
} }
free_all(arena_alloc) defer free_all(context.allocator)
} }
Executable
+56
View File
@@ -0,0 +1,56 @@
#!/bin/bash
set -e
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
RESET='\033[0m'
DEBUG=false
UPLOAD=false
CLEAN=false
usage() {
echo "Usage: $(basename "$0") [-d] [-u] [-c] [-h]"
echo ""
echo "Options:"
echo " -d Debug build (adds -debug flag to odin)"
echo " -u Upload HTML to webserver after build"
echo " -c Clean old HTML files before generating"
echo " -h Show this help message"
exit 0
}
while getopts "duch" opt; do
case $opt in
d) DEBUG=true ;;
u) UPLOAD=true ;;
c) CLEAN=true ;;
h) usage ;;
*) usage ;;
esac
done
if $CLEAN; then
echo -e "${YELLOW}[INFO]${RESET} Removing old HTML files..."
find /Users/simon/website_backup/NEW/HTML -type f -name "*.html" -delete
echo -e "${GREEN}[ OK ]${RESET} Old HTML removed"
fi
if $DEBUG; then
echo -e "${CYAN}[INFO]${RESET} Debug build"
odin build . -debug
else
echo -e "${CYAN}[INFO]${RESET} Release build"
odin build . -o:speed
fi
echo -e "${GREEN}[ OK ]${RESET} Build complete"
./cm -dir="/Users/simon/website_backup/NEW/" -out="/Users/simon/website_backup/NEW/HTML"
echo -e "${GREEN}[ OK ]${RESET} HTML generated"
if $UPLOAD; then
echo -e "${YELLOW}[INFO]${RESET} Uploading to server..."
rsync -aP /Users/simon/website_backup/NEW/HTML/* root@www.simonkellet.xyz:/var/www/cabin/
echo -e "${GREEN}[ OK ]${RESET} Upload complete"
fi