aboutsummaryrefslogtreecommitdiff
path: root/src/main.odin
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.odin')
-rw-r--r--src/main.odin110
1 files changed, 89 insertions, 21 deletions
diff --git a/src/main.odin b/src/main.odin
index ec9d70e..e1b72ac 100644
--- a/src/main.odin
+++ b/src/main.odin
@@ -15,15 +15,26 @@ TODO: Simplify pre-allocation. Just allocate a bunch. It's probably fine.
TODO: Drag-n-drop window if no files are specified
*/
+when ODIN_OS == .Windows {
+ SEPARATOR :: "\\"
+} else {
+ SEPARATOR :: "/"
+}
+
+VERSION :: "1.6"
+
+KNEKT := false
+
VERBOSE :: false
INCLUDE_DATE :: false // By default I delete the retarded date field that says what day the report was generated.
-PART_ONE :: #load("parts/start.html", string)
-PART_TWO :: #load("parts/start2.html", string)
+PART_START :: #load("parts/start.html", string)
+PART_KNEKT :: #load("parts/knekt.html", string)
PART_END :: #load("parts/end.html", string)
+PART_FOOTER :: #load("parts/footer.html", string)
HEADER_TEMPLATE :: #load("header_template.txt", string)
-HEADER_FIELDS_PATH :: "info.txt"
+HEADER_FIELDS_FILENAME :: "info.txt"
header_fields_file : string
Device :: enum {
@@ -57,7 +68,8 @@ Report :: struct {
tc_column_index : int,
// Meta
- path : string,
+ dir : string,
+ based_on_csv : bool,
}
CSV :: string
@@ -74,20 +86,30 @@ main :: proc() {
input_file_name : string
if len(os.args) < 2 {
fmt.println("No paths submitted.")
- if os.is_file(HEADER_FIELDS_PATH) {
- fmt.printfln("\"%v\" already exists.", HEADER_FIELDS_PATH)
+ if os.is_file(HEADER_FIELDS_FILENAME) {
+ fmt.printfln("\"%v\" already exists.", HEADER_FIELDS_FILENAME)
} else {
- os.write_entire_file(HEADER_FIELDS_PATH, transmute([]u8)HEADER_TEMPLATE)
- fmt.printfln("Created \"%v\".", HEADER_FIELDS_PATH)
+ os.write_entire_file(HEADER_FIELDS_FILENAME, transmute([]u8)HEADER_TEMPLATE)
+ fmt.printfln("Created \"%v\".", HEADER_FIELDS_FILENAME)
}
return
+ } else if len(os.args) > 2 {
+ for arg in os.args[2:] {
+ if arg=="-knekt" {
+ KNEKT = true
+ }
+ }
+ }
+
+ exe_path, _ := os2.get_executable_directory(context.allocator)
+ exe_local_fields_file := fmt.aprint(exe_path, HEADER_FIELDS_FILENAME, sep=SEPARATOR)
+ fmt.println(exe_local_fields_file)
+ if os.is_file(exe_local_fields_file) {
+ header_fields_file = exe_local_fields_file
}
fmt.printf("Input path: {}\n", os.args[1])
input_file_name = os.args[1]
-
-
-
path_info, error := os.stat(input_file_name)
file_count := 1
@@ -95,6 +117,12 @@ main :: proc() {
if error == os.ERROR_NONE {
if(path_info.is_dir) {
+
+ input_local_fields_file := fmt.aprint(path_info.fullpath, HEADER_FIELDS_FILENAME, sep="")
+ if os.is_file(input_local_fields_file) {
+ header_fields_file = input_local_fields_file
+ }
+
fmt.printf("Directory submitted! Walking directory...\n\n")
fmt.printf("📁 {}\n", path_info.name)
try_os2 := walk_directory(path_info.fullpath, &file_count, 1)
@@ -155,6 +183,7 @@ parse_folder :: proc(paths : Directory) -> (Report, bool) {
// Y8P "Y8888888P" "Y888888 Y88P
output : Report = {}
+ output.dir = filepath.dir(paths[0])
wavs : [dynamic]wav.Wav
@@ -201,7 +230,18 @@ parse_folder :: proc(paths : Directory) -> (Report, bool) {
output.info_lines = make([]Info_Line, 64, context.temp_allocator)
- info_txt, info_txt_ok := os.read_entire_file(HEADER_FIELDS_PATH, context.temp_allocator)
+
+
+ // Header fields
+
+ header_file := header_fields_file
+ local_header_file_path := fmt.tprint(output.dir, HEADER_FIELDS_FILENAME, sep=SEPARATOR)
+ if os.is_file(local_header_file_path) {
+ header_file = local_header_file_path
+ }
+
+ info_txt, info_txt_ok := os.read_entire_file(header_file, context.temp_allocator)
+
if info_txt_ok {
it := string(info_txt)
line_index := 0
@@ -391,7 +431,7 @@ parse_folder :: proc(paths : Directory) -> (Report, bool) {
when VERBOSE do fmt.printf("Struct before output:\n%#v\n", output)
- output.path = fmt.tprintf("{}/{}_Knekt_Lydrapport.html", filepath.dir(paths[0]), output.title)
+ output.dir = filepath.dir(paths[0])
return output, true
}
@@ -408,7 +448,7 @@ parse_file :: proc(path : CSV, device : Device = .UNSET) -> (Report, bool) {
return {}, false
}
file_info, _ := os.lstat(path, context.temp_allocator)
-
+ output.based_on_csv = true
lines := strings.split_lines(string(data), allocator=context.temp_allocator)
@@ -900,7 +940,7 @@ parse_file :: proc(path : CSV, device : Device = .UNSET) -> (Report, bool) {
when VERBOSE do fmt.printf("Struct before output:\n%#v\n", output)
- output.path = fmt.tprintf("{}/{}_Knekt_Lydrapport.html", filepath.dir(path), output.title)
+ output.dir = filepath.dir(path)
return output, true
}
@@ -911,11 +951,19 @@ render :: proc(report : Report) {
builder := strings.builder_make(context.temp_allocator)
- strings.write_string(&builder, PART_ONE)
- strings.write_string(&builder, report.title)
- strings.write_string(&builder, " - Lydrapport")
- strings.write_string(&builder, PART_TWO)
+ strings.write_string(&builder, PART_START)
+
+ title := fmt.tprint(report.title, "- Sound Report")
+ logo := ""
+ if KNEKT {
+ title = fmt.tprint(report.title, "- Lydrapport")
+ logo = PART_KNEKT
+ }
+ strings.builder_replace_all(&builder, "¤¤¤TITLE¤¤¤", title)
+ strings.builder_replace_all(&builder, "¤¤¤LOGO¤¤¤", logo)
+ title_section := fmt.tprintf("<h1 class=\"day-title\">{}</h1>", report.title)
+ strings.write_string(&builder, title_section)
for line, l in report.info_lines[:report.info_line_count] {
strings.write_string(&builder, " <p><b>")
@@ -951,10 +999,30 @@ render :: proc(report : Report) {
strings.write_string(&builder, PART_END)
+ footer := PART_FOOTER
+ if KNEKT {
+ footer = ""
+ }
+ strings.builder_replace_all(&builder, "¤¤¤FOOTER¤¤¤", footer)
+
+ strings.builder_replace_all(&builder, "¤¤¤VERSION¤¤¤", VERSION)
+ if report.based_on_csv {
+ strings.builder_replace_all(&builder, "¤¤¤PROCESS¤¤¤", "Converted from CSV")
+ } else {
+ strings.builder_replace_all(&builder, "¤¤¤PROCESS¤¤¤", "Generated")
+ }
+
+ output_path := ""
+ if KNEKT {
+ output_path = fmt.tprintf("{}{}{}_Knekt_Lydrapport.html", report.dir, SEPARATOR, report.title)
+ } else {
+ output_path = fmt.tprintf("{}{}{}_Sound_Report.html", report.dir, SEPARATOR, report.title)
+ }
+
output_text := strings.to_string(builder)
- os.write_entire_file(report.path, transmute([]u8)output_text)
+ os.write_entire_file(output_path, transmute([]u8)output_text)
- fmt.printf("Output: {}\n", report.path)
+ fmt.printf("Output: {}\n", output_path)
}
indent_by :: proc(i : int) {