mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-08 08:38:51 +00:00
ran odinfmt on source
This commit is contained in:
@@ -27,7 +27,7 @@ Flag :: struct {
|
||||
}
|
||||
|
||||
Flag_Context :: struct {
|
||||
seen_flags: map [string] Flag,
|
||||
seen_flags: map[string]Flag,
|
||||
}
|
||||
|
||||
parse_args :: proc(ctx: ^Flag_Context, args: []string) -> Flag_Error {
|
||||
@@ -86,10 +86,10 @@ parse_args :: proc(ctx: ^Flag_Context, args: []string) -> Flag_Error {
|
||||
mem.copy(flag.data, &tmp, flag.type.size);
|
||||
flag.parsed = true;
|
||||
continue;
|
||||
}
|
||||
} else
|
||||
|
||||
//must be in the next argument
|
||||
else if value == "" {
|
||||
if value == "" {
|
||||
|
||||
if len(args) == 0 {
|
||||
return .Arg_Error;
|
||||
@@ -99,12 +99,11 @@ parse_args :: proc(ctx: ^Flag_Context, args: []string) -> Flag_Error {
|
||||
args = args[1:];
|
||||
}
|
||||
|
||||
#partial switch in flag.type.variant {
|
||||
#partial switch _ in flag.type.variant {
|
||||
case Type_Info_Integer:
|
||||
if v, ok := strconv.parse_int(value); ok {
|
||||
mem.copy(flag.data, &v, flag.type.size);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return .Value_Parse_Error;
|
||||
}
|
||||
case Type_Info_String:
|
||||
@@ -116,15 +115,13 @@ parse_args :: proc(ctx: ^Flag_Context, args: []string) -> Flag_Error {
|
||||
case 32:
|
||||
if v, ok := strconv.parse_f32(value); ok {
|
||||
mem.copy(flag.data, &v, flag.type.size);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return .Value_Parse_Error;
|
||||
}
|
||||
case 64:
|
||||
if v, ok := strconv.parse_f64(value); ok {
|
||||
mem.copy(flag.data, &v, flag.type.size);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return .Value_Parse_Error;
|
||||
}
|
||||
}
|
||||
@@ -133,8 +130,6 @@ parse_args :: proc(ctx: ^Flag_Context, args: []string) -> Flag_Error {
|
||||
flag.parsed = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return .None;
|
||||
}
|
||||
|
||||
@@ -162,15 +157,12 @@ reflect_args_structure :: proc(ctx: ^Flag_Context, v: any) -> Flag_Error {
|
||||
flag.optional = true;
|
||||
flag.tag_ptr = rawptr(uintptr(union_type.tag_offset) + uintptr(v.data) + uintptr(offsets[i]));
|
||||
type = union_type.variants[0];
|
||||
}
|
||||
|
||||
else {
|
||||
} else {
|
||||
return .Arg_Unsupported_Field_Type;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#partial switch in type.variant {
|
||||
#partial switch _ in type.variant {
|
||||
case Type_Info_Integer, Type_Info_String, Type_Info_Boolean, Type_Info_Float:
|
||||
flag.type = type;
|
||||
flag.data = rawptr(uintptr(v.data) + uintptr(offsets[i]));
|
||||
@@ -182,9 +174,7 @@ reflect_args_structure :: proc(ctx: ^Flag_Context, v: any) -> Flag_Error {
|
||||
|
||||
if value, ok := reflect.struct_tag_lookup(tags[i], "flag"); ok {
|
||||
flag_name = cast(string)value;
|
||||
}
|
||||
|
||||
else {
|
||||
} else {
|
||||
return .Tag_Error;
|
||||
}
|
||||
|
||||
@@ -214,14 +204,11 @@ parse :: proc(v: any, args: []string) -> Flag_Error {
|
||||
for k, v in ctx.seen_flags {
|
||||
|
||||
if v.optional && v.parsed {
|
||||
tag_value : i32 = 1;
|
||||
tag_value: i32 = 1;
|
||||
mem.copy(v.tag_ptr, &tag_value, 4); //4 constant is probably not portable, but it works for me currently
|
||||
}
|
||||
|
||||
else if !v.parsed && !v.optional {
|
||||
} else if !v.parsed && !v.optional {
|
||||
return .Arg_Non_Optional;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return .None;
|
||||
|
||||
+10
-31
@@ -15,26 +15,22 @@ Args :: struct {
|
||||
}
|
||||
|
||||
print_help :: proc() {
|
||||
|
||||
}
|
||||
|
||||
print_arg_error :: proc(error: flag.Flag_Error) {
|
||||
fmt.println(error);
|
||||
}
|
||||
|
||||
format_file :: proc(filepath: string) -> ([] u8, bool) {
|
||||
format_file :: proc(filepath: string) -> ([]u8, bool) {
|
||||
|
||||
if data, ok := os.read_entire_file(filepath); ok {
|
||||
return format.format(data, format.default_style);
|
||||
}
|
||||
|
||||
else {
|
||||
} else {
|
||||
return {}, false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
files: [dynamic] string;
|
||||
files: [dynamic]string;
|
||||
|
||||
walk_files :: proc(info: os.File_Info, in_err: os.Errno) -> (err: os.Errno, skip_dir: bool) {
|
||||
|
||||
@@ -62,12 +58,12 @@ main :: proc() {
|
||||
os.exit(1);
|
||||
}
|
||||
|
||||
if res := flag.parse(args, os.args[1:len(os.args)-1]); res != .None {
|
||||
if res := flag.parse(args, os.args[1:len(os.args) - 1]); res != .None {
|
||||
print_arg_error(res);
|
||||
os.exit(1);
|
||||
}
|
||||
|
||||
path := os.args[len(os.args)-1];
|
||||
path := os.args[len(os.args) - 1];
|
||||
|
||||
tick_time := time.tick_now();
|
||||
|
||||
@@ -84,26 +80,16 @@ main :: proc() {
|
||||
if os.write_entire_file(path, data) {
|
||||
os.remove(backup_path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
} else {
|
||||
fmt.eprintf("failed to write %v", path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
} else {
|
||||
|
||||
if data, ok := format_file(path); ok {
|
||||
fmt.println(transmute(string)data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else if os.is_dir(path) {
|
||||
} else if os.is_dir(path) {
|
||||
|
||||
filepath.walk(path, walk_files);
|
||||
|
||||
@@ -121,13 +107,9 @@ main :: proc() {
|
||||
if os.write_entire_file(file, data) {
|
||||
os.remove(backup_path);
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
} else {
|
||||
fmt.println(transmute(string)data);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
fmt.eprintf("failed to format %v", file);
|
||||
}
|
||||
@@ -136,10 +118,7 @@ main :: proc() {
|
||||
}
|
||||
|
||||
fmt.printf("formatted %v files in %vms", len(files), time.duration_milliseconds(time.tick_lap_time(&tick_time)));
|
||||
|
||||
}
|
||||
|
||||
else{
|
||||
} else {
|
||||
fmt.eprintf("%v is neither a directory nor a file \n", path);
|
||||
os.exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user