-
Notifications
You must be signed in to change notification settings - Fork 0
/
output_format.odin
68 lines (62 loc) · 1.74 KB
/
output_format.odin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import "core:fmt"
import "core:os"
import "core:strings"
import "core:path/filepath"
/*
Available variables:
%(file)
%(file-short)
%(total)
%(code)
%(blank)
%(comment)
*/
output_formatted :: proc(format_string : string, h: os.Handle, result: ^OutputResult, sb: ^strings.Builder) -> string {
using strings
fi, err_fi := os.fstat(h)
fullpath := strings.trim_prefix(fi.fullpath, "\\\\?\\")
shortpath := filepath.base(fullpath)
var := false
begin, idx := 0,0
for idx < len(format_string) {
if format_string[idx] == '%' {
if end_idx := index_byte(format_string[idx:], ')'); end_idx != -1 {
var_name := format_string[idx:idx+end_idx+1]
if var_name == "%(file)" {
if config.color do write_string(sb, "\033[43m")
write_string(sb, fullpath)
if config.color do write_string(sb, "\033[49m")
idx += end_idx+1
} else if var_name == "%(file-short)" {
if config.color do write_string(sb, "\033[43m")
write_string(sb, shortpath)
if config.color do write_string(sb, "\033[49m")
idx += end_idx+1
} else if var_name == "%(total)" {
write_i64(sb, cast(i64)result.total)
idx += end_idx+1
} else if var_name == "%(code)" {
write_i64(sb, cast(i64)result.code)
idx += end_idx+1
} else if var_name == "%(blank)" {
write_i64(sb, cast(i64)result.blank)
idx += end_idx+1
} else if var_name == "%(comment)" {
write_i64(sb, cast(i64)result.comment)
idx += end_idx+1
} else {
write_byte(sb, format_string[idx])
idx += 1
}
} else {
write_byte(sb, format_string[idx])
idx += 1
}
} else {
write_byte(sb, format_string[idx])
idx += 1
}
}
return to_string(sb^)
}