From e6f9b4fb11285c5ceea3b3cc7cee26aa9f5ae3d2 Mon Sep 17 00:00:00 2001 From: Kevin Watters Date: Mon, 25 Mar 2019 09:23:46 -0400 Subject: [PATCH 1/6] Fix some -vet warnings; change import to core:math/bits --- core/encoding/json/marshal.odin | 2 +- core/encoding/json/tokenizer.odin | 4 ++-- core/encoding/json/types.odin | 2 -- core/strconv/strconv.odin | 4 ++-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/core/encoding/json/marshal.odin b/core/encoding/json/marshal.odin index d25758275..4f5ee6880 100644 --- a/core/encoding/json/marshal.odin +++ b/core/encoding/json/marshal.odin @@ -1,7 +1,7 @@ package json import "core:mem" -import "core:bits" +import "core:math/bits" import "core:runtime" import "core:strconv" import "core:strings" diff --git a/core/encoding/json/tokenizer.odin b/core/encoding/json/tokenizer.odin index dd1704ba7..f9da8437e 100644 --- a/core/encoding/json/tokenizer.odin +++ b/core/encoding/json/tokenizer.odin @@ -436,8 +436,8 @@ is_valid_string_literal :: proc(s: string, spec: Specification) -> bool { i += 5; for j := 0; j < 4; j += 1 { - c := hex[j]; - switch c { + c2 := hex[j]; + switch c2 { case '0'..'9', 'a'..'z', 'A'..'Z': // Okay case: diff --git a/core/encoding/json/types.odin b/core/encoding/json/types.odin index 6973d3dc5..036fe50b4 100644 --- a/core/encoding/json/types.odin +++ b/core/encoding/json/types.odin @@ -1,7 +1,5 @@ package json -import "core:strconv" - Specification :: enum { JSON, JSON5, diff --git a/core/strconv/strconv.odin b/core/strconv/strconv.odin index 0b1f10f6c..0a48ce68b 100644 --- a/core/strconv/strconv.odin +++ b/core/strconv/strconv.odin @@ -230,8 +230,8 @@ quote :: proc(buf: []byte, s: string) -> string { write_byte(buf, &i, digits[s[0]>>4]); write_byte(buf, &i, digits[s[0]&0xf]); } - s := quote_rune(buf[i:], r); - i += len(s); + s2 := quote_rune(buf[i:], r); + i += len(s2); } write_byte(buf, &i, c); return string(buf[:i]); From 76a2807b56a9c0a40c66915d5b77cf537ad376f2 Mon Sep 17 00:00:00 2001 From: Kevin Watters Date: Tue, 26 Mar 2019 11:20:49 -0400 Subject: [PATCH 2/6] Remove unused import from demo.odin. --- examples/demo/demo.odin | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/demo/demo.odin b/examples/demo/demo.odin index efce9299a..dd7590d01 100644 --- a/examples/demo/demo.odin +++ b/examples/demo/demo.odin @@ -5,7 +5,6 @@ import "core:mem" import "core:os" when os.OS == "windows" { - import "core:runtime" import "core:thread" } From a730b04bf1cb01f54452342b1cdd8550dd3b9179 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Fri, 5 Apr 2019 13:02:49 +0200 Subject: [PATCH 3/6] Add helpers to launch process and open website. --- core/sys/win32/helpers.odin | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 core/sys/win32/helpers.odin diff --git a/core/sys/win32/helpers.odin b/core/sys/win32/helpers.odin new file mode 100644 index 000000000..8b46dea42 --- /dev/null +++ b/core/sys/win32/helpers.odin @@ -0,0 +1,35 @@ +// +build windows +package win32 + +import "core:strings"; + +call_external_process :: proc(program, command_line: string) -> bool { + + si := Startup_Info{}; + pi := Process_Information{}; + si.cb = size_of(si); + + p := utf8_to_wstring(program); + c := utf8_to_wstring(command_line); + + ret := create_process_w( + p, + c, + nil, + nil, + Bool(false), + u32(0x10), // Create New Console + nil, + nil, + &si, + &pi + ); + return cast(bool)ret; +} + +open_website :: proc(url: string) -> bool { + p :: "C:\\Windows\\System32\\cmd.exe"; + arg := []string{"/C", "start", url}; + args := strings.join(arg, " ", context.temp_allocator); + return call_external_process(p, args); +} \ No newline at end of file From 155b138aa43421489f37f6e76393d1fb8e56480e Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Fri, 5 Apr 2019 13:18:50 +0200 Subject: [PATCH 4/6] call_external_process cleanup --- core/sys/win32/helpers.odin | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/core/sys/win32/helpers.odin b/core/sys/win32/helpers.odin index 8b46dea42..fd8b7c3c5 100644 --- a/core/sys/win32/helpers.odin +++ b/core/sys/win32/helpers.odin @@ -4,27 +4,21 @@ package win32 import "core:strings"; call_external_process :: proc(program, command_line: string) -> bool { + si := Startup_Info{ cb=size_of(Startup_Info) }; + pi := Process_Information{}; - si := Startup_Info{}; - pi := Process_Information{}; - si.cb = size_of(si); - - p := utf8_to_wstring(program); - c := utf8_to_wstring(command_line); - - ret := create_process_w( - p, - c, - nil, - nil, - Bool(false), - u32(0x10), // Create New Console - nil, - nil, - &si, - &pi - ); - return cast(bool)ret; + return cast(bool)create_process_w( + utf8_to_wstring(program), + utf8_to_wstring(command_line), + nil, + nil, + Bool(false), + u32(0x10), + nil, + nil, + &si, + &pi + ); } open_website :: proc(url: string) -> bool { From 62f5eb5bca8810a622491179039bc7c382b33995 Mon Sep 17 00:00:00 2001 From: Kevin Watters Date: Sat, 6 Apr 2019 09:19:09 -0400 Subject: [PATCH 5/6] Fix som JSON parsing bugs. - Single digit integer keys `{"a": 5}` ` Negative float keys `{"b": -42.0}` --- core/encoding/json/tokenizer.odin | 38 ++++++++++++++++--------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/core/encoding/json/tokenizer.odin b/core/encoding/json/tokenizer.odin index f9da8437e..48cbb22c0 100644 --- a/core/encoding/json/tokenizer.odin +++ b/core/encoding/json/tokenizer.odin @@ -68,12 +68,12 @@ next_rune :: proc(t: ^Tokenizer) -> rune #no_bounds_check { get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) { skip_digits :: proc(t: ^Tokenizer) { for t.offset < len(t.data) { - next_rune(t); if '0' <= t.r && t.r <= '9' { // Okay } else { return; } + next_rune(t); } } skip_hex_digits :: proc(t: ^Tokenizer) { @@ -158,6 +158,7 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) { skip_whitespace(t); token.pos = t.pos; + token.kind = Kind.Invalid; curr_rune := t.r; @@ -213,23 +214,6 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) { } fallthrough; - case '.': - err = Error.Illegal_Character; - if t.spec == Specification.JSON5 { // Allow leading decimal point - skip_digits(t); - if t.r == 'e' || t.r == 'E' { - switch r := next_rune(t); r { - case '+', '-': - next_rune(t); - } - skip_digits(t); - } - str := string(t.data[token.offset:t.offset]); - if !is_valid_number(str, t.spec) { - err = Error.Invalid_Number; - } - } - case '0'..'9': token.kind = Kind.Integer; if t.spec == Specification.JSON5 { // Hexadecimal Numbers @@ -241,6 +225,7 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) { } skip_digits(t); + if t.r == '.' { token.kind = Kind.Float; next_rune(t); @@ -259,6 +244,23 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) { err = Error.Invalid_Number; } + case '.': + err = Error.Illegal_Character; + if t.spec == Specification.JSON5 { // Allow leading decimal point + skip_digits(t); + if t.r == 'e' || t.r == 'E' { + switch r := next_rune(t); r { + case '+', '-': + next_rune(t); + } + skip_digits(t); + } + str := string(t.data[token.offset:t.offset]); + if !is_valid_number(str, t.spec) { + err = Error.Invalid_Number; + } + } + case '\'': err = Error.Illegal_Character; From 88e1b93786f5c57d07882f16301ff120e9f3cf27 Mon Sep 17 00:00:00 2001 From: Kevin Watters Date: Sat, 6 Apr 2019 09:19:09 -0400 Subject: [PATCH 6/6] Fix som JSON parsing bugs. - Single digit integer keys `{"a": 5}` ` Negative float keys `{"b": -42.0}` --- core/encoding/json/tokenizer.odin | 38 ++++++++++++++++--------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/core/encoding/json/tokenizer.odin b/core/encoding/json/tokenizer.odin index dd1704ba7..6fbc33d8d 100644 --- a/core/encoding/json/tokenizer.odin +++ b/core/encoding/json/tokenizer.odin @@ -68,12 +68,12 @@ next_rune :: proc(t: ^Tokenizer) -> rune #no_bounds_check { get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) { skip_digits :: proc(t: ^Tokenizer) { for t.offset < len(t.data) { - next_rune(t); if '0' <= t.r && t.r <= '9' { // Okay } else { return; } + next_rune(t); } } skip_hex_digits :: proc(t: ^Tokenizer) { @@ -158,6 +158,7 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) { skip_whitespace(t); token.pos = t.pos; + token.kind = Kind.Invalid; curr_rune := t.r; @@ -213,23 +214,6 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) { } fallthrough; - case '.': - err = Error.Illegal_Character; - if t.spec == Specification.JSON5 { // Allow leading decimal point - skip_digits(t); - if t.r == 'e' || t.r == 'E' { - switch r := next_rune(t); r { - case '+', '-': - next_rune(t); - } - skip_digits(t); - } - str := string(t.data[token.offset:t.offset]); - if !is_valid_number(str, t.spec) { - err = Error.Invalid_Number; - } - } - case '0'..'9': token.kind = Kind.Integer; if t.spec == Specification.JSON5 { // Hexadecimal Numbers @@ -241,6 +225,7 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) { } skip_digits(t); + if t.r == '.' { token.kind = Kind.Float; next_rune(t); @@ -259,6 +244,23 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) { err = Error.Invalid_Number; } + case '.': + err = Error.Illegal_Character; + if t.spec == Specification.JSON5 { // Allow leading decimal point + skip_digits(t); + if t.r == 'e' || t.r == 'E' { + switch r := next_rune(t); r { + case '+', '-': + next_rune(t); + } + skip_digits(t); + } + str := string(t.data[token.offset:t.offset]); + if !is_valid_number(str, t.spec) { + err = Error.Invalid_Number; + } + } + case '\'': err = Error.Illegal_Character;