2018-05-09 07:10:07 +00:00
|
|
|
/*
|
|
|
|
4coder_jumping.cpp - Routines commonly used when writing code to jump to locations and seek through jump lists.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
2019-12-13 23:36:28 +00:00
|
|
|
function b32
|
2019-12-18 03:38:08 +00:00
|
|
|
ms_style_verify(String_Const_u8 line, u64 left_paren_pos, u64 right_paren_pos){
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 result = false;
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 line_part = string_skip(line, right_paren_pos);
|
2020-05-13 00:51:22 +00:00
|
|
|
if (string_match(string_prefix(line_part, 4), string_u8_litexpr(") : ")) ||
|
|
|
|
string_match(string_prefix(line_part, 3), string_u8_litexpr("): "))){
|
2018-05-09 07:10:07 +00:00
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
if (result){
|
2020-05-13 00:51:22 +00:00
|
|
|
String_Const_u8 number = string_skip(string_prefix(line, right_paren_pos), left_paren_pos + 1);
|
2019-06-01 23:58:28 +00:00
|
|
|
if (!string_is_integer(number, 10)){
|
2018-05-09 07:10:07 +00:00
|
|
|
result = false;
|
2019-12-18 03:38:08 +00:00
|
|
|
u64 comma_pos = string_find_first(number, ',');
|
2018-05-09 07:10:07 +00:00
|
|
|
if (comma_pos < number.size){
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 sub_number0 = string_prefix(number, comma_pos);
|
|
|
|
String_Const_u8 sub_number1 = string_skip(number, comma_pos + 1);
|
|
|
|
if (string_is_integer(sub_number0, 10) && string_is_integer(sub_number1, 10)){
|
2018-05-09 07:10:07 +00:00
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-12-18 03:38:08 +00:00
|
|
|
function u64
|
2019-06-01 23:58:28 +00:00
|
|
|
try_skip_rust_arrow(String_Const_u8 line){
|
2019-12-18 03:38:08 +00:00
|
|
|
u64 pos = 0;
|
2019-06-01 23:58:28 +00:00
|
|
|
if (string_match(string_prefix(line, 3), string_u8_litexpr("-->"))){
|
|
|
|
String_Const_u8 sub = string_skip(line, 3);
|
|
|
|
sub = string_skip_chop_whitespace(sub);
|
2019-12-18 03:38:08 +00:00
|
|
|
pos = (u64)(sub.str - line.str);
|
2018-05-09 07:10:07 +00:00
|
|
|
}
|
|
|
|
return(pos);
|
|
|
|
}
|
|
|
|
|
2019-12-13 23:36:28 +00:00
|
|
|
function b32
|
2019-12-18 03:38:08 +00:00
|
|
|
check_is_note(String_Const_u8 line, u64 colon_pos){
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 is_note = false;
|
2019-12-18 03:38:08 +00:00
|
|
|
u64 note_pos = colon_pos + string_find_first(string_skip(line, colon_pos), string_u8_litexpr("note"));
|
2018-11-29 21:17:34 +00:00
|
|
|
if (note_pos < line.size){
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 is_all_whitespace = true;
|
2019-12-18 03:38:08 +00:00
|
|
|
for (u64 i = colon_pos + 1; i < note_pos; i += 1){
|
2019-06-01 23:58:28 +00:00
|
|
|
if (!character_is_whitespace(line.str[i])){
|
2018-11-29 21:17:34 +00:00
|
|
|
is_all_whitespace = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (is_all_whitespace){
|
|
|
|
is_note = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(is_note);
|
|
|
|
}
|
|
|
|
|
2024-03-27 20:49:52 +00:00
|
|
|
/* ERROR EXAMPLES
|
|
|
|
These are the cases that gs_parse_jump_location is designed to parse.
|
|
|
|
|
|
|
|
############################# JAVASCRIPT / NODE ERROR ##########################
|
|
|
|
|
|
|
|
C:\psjr\blackbird\test.js:2
|
|
|
|
console.error("Foo);
|
|
|
|
^^^^^^
|
|
|
|
|
|
|
|
SyntaxError: Invalid or unexpected token
|
|
|
|
at Object.compileFunction (node:vm:352:18)
|
|
|
|
at wrapSafe (node:internal/modules/cjs/loader:1031:15)
|
|
|
|
at Module._compile (node:internal/modules/cjs/loader:1065:27)
|
|
|
|
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
|
|
|
|
at Module.load (node:internal/modules/cjs/loader:981:32)
|
|
|
|
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
|
|
|
|
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
|
|
|
|
at node:internal/main/run_main_module:17:47
|
|
|
|
|
|
|
|
############################# MSVC ERROR #######################################
|
|
|
|
|
|
|
|
test.c(4): error C2632: 'int' followed by 'int' is illegal
|
|
|
|
|
|
|
|
############################# CLANG ERROR ######################################
|
|
|
|
|
|
|
|
test.c:4:1: error: cannot combine with previous 'int' declaration specifier
|
|
|
|
int main(int argc, char** args) {
|
|
|
|
|
|
|
|
############################# JAI ERROR ########################################
|
|
|
|
|
|
|
|
C:/projects/games/atof//src/cards.jai:106,48: Error: Semicolon expected after expression.
|
|
|
|
|
|
|
|
}
|
|
|
|
return card_index, (<< collection)[card_index]
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
function Parsed_Jump
|
|
|
|
gs_parse_jump_location(String_Const_u8 line)
|
|
|
|
{
|
|
|
|
Parsed_Jump jump = {};
|
|
|
|
jump.sub_jump_indented = (string_get_character(line, 0) == ' ');
|
|
|
|
|
|
|
|
String_Const_u8 reduced_line = string_skip_chop_whitespace(line);
|
|
|
|
u64 whitespace_length = (u64)(reduced_line.str - line.str);
|
|
|
|
line = reduced_line;
|
|
|
|
|
|
|
|
String_Const_u8 separators = str8_lit(":(),"); // characters used to separate paths, indices, and notes
|
|
|
|
u64 sep1 = string_find_first_of_set(line, separators);
|
|
|
|
|
|
|
|
// on windows, paths might have a colon in them. ie. C:\some\path\file.cpp
|
|
|
|
// we want to skip this first colon - so check if there's a slash after it
|
|
|
|
// and skip in that case.
|
|
|
|
if (sep1 + 1 < line.size)
|
|
|
|
{
|
|
|
|
if (character_is_slash(string_get_character(line, sep1 + 1))){
|
|
|
|
u64 next_sep = string_find_first_of_set(
|
|
|
|
string_skip(line, sep1 + 1),
|
|
|
|
separators
|
|
|
|
);
|
|
|
|
sep1 = next_sep + sep1 + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 sep2 = string_find_first_of_set(
|
|
|
|
string_skip(line, sep1 + 1),
|
|
|
|
separators
|
|
|
|
) + sep1 + 1;
|
|
|
|
u64 sep3 = string_find_first_of_set(
|
|
|
|
string_skip(line, sep2 + 1),
|
|
|
|
separators
|
|
|
|
) + sep2 + 1;
|
|
|
|
|
|
|
|
// TODO(PS): check_is_note? - seems to be checking for test.c(4): note
|
|
|
|
// ^^^^
|
|
|
|
// and setting jump.sub_jump_note = true. Not sure what this is for yet
|
|
|
|
|
|
|
|
if (sep1 < line.size) {
|
|
|
|
String_Const_u8 file_name = string_prefix(line, sep1);
|
|
|
|
if (file_name.size > 0) {
|
|
|
|
jump.location.file = file_name;
|
|
|
|
|
|
|
|
if (sep2 < line.size) {
|
|
|
|
String_Const_u8 line_number = string_skip(string_prefix(line, sep2), sep1 + 1);
|
|
|
|
if (string_is_integer(line_number, 10)) {
|
|
|
|
jump.location.line = (i32)string_to_integer(line_number, 10);
|
|
|
|
|
|
|
|
// NOTE(PS): we must at least get a line number to consider the line
|
|
|
|
// to contain a valid jump location
|
|
|
|
jump.success = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(PS): columns are optional since MSVC doesn't output them
|
|
|
|
if (sep3 < line.size) {
|
|
|
|
String_Const_u8 column_number = string_skip(string_prefix(line, sep3), sep2 + 1);
|
|
|
|
if (string_is_integer(column_number, 10)) {
|
|
|
|
jump.location.column = (i32)string_to_integer(column_number, 10);
|
|
|
|
}
|
|
|
|
jump.colon_position = (i32)(sep3 + whitespace_length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!jump.success){
|
|
|
|
block_zero_struct(&jump);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
jump.is_sub_jump = (jump.sub_jump_indented || jump.sub_jump_note);
|
|
|
|
}
|
|
|
|
return(jump);
|
|
|
|
}
|
|
|
|
|
2019-12-13 23:36:28 +00:00
|
|
|
function Parsed_Jump
|
2019-06-01 23:58:28 +00:00
|
|
|
parse_jump_location(String_Const_u8 line){
|
2019-04-01 03:50:37 +00:00
|
|
|
Parsed_Jump jump = {};
|
2019-06-01 23:58:28 +00:00
|
|
|
jump.sub_jump_indented = (string_get_character(line, 0) == ' ');
|
2018-05-09 07:10:07 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 reduced_line = string_skip_chop_whitespace(line);
|
2019-12-18 03:38:08 +00:00
|
|
|
u64 whitespace_length = (u64)(reduced_line.str - line.str);
|
2019-06-01 23:58:28 +00:00
|
|
|
line = reduced_line;
|
2018-05-09 07:10:07 +00:00
|
|
|
|
2019-12-18 03:38:08 +00:00
|
|
|
u64 left_paren_pos = string_find_first(line, '(');
|
|
|
|
u64 right_paren_pos = left_paren_pos + string_find_first(string_skip(line, left_paren_pos), ')');
|
2019-04-01 03:50:37 +00:00
|
|
|
for (;!jump.is_ms_style && right_paren_pos < line.size;){
|
2018-05-09 07:10:07 +00:00
|
|
|
if (ms_style_verify(line, left_paren_pos, right_paren_pos)){
|
2019-04-01 03:50:37 +00:00
|
|
|
jump.is_ms_style = true;
|
2019-06-01 23:58:28 +00:00
|
|
|
jump.colon_position = (i32)(right_paren_pos + string_find_first(string_skip(line, right_paren_pos), ':'));
|
2019-04-01 03:50:37 +00:00
|
|
|
if (jump.colon_position < line.size){
|
|
|
|
if (check_is_note(line, jump.colon_position)){
|
|
|
|
jump.sub_jump_note = true;
|
2018-11-29 21:17:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 location_str = string_prefix(line, jump.colon_position);
|
|
|
|
location_str = string_skip_chop_whitespace(location_str);
|
2018-05-09 07:10:07 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
i32 close_pos = (i32)right_paren_pos;
|
|
|
|
i32 open_pos = (i32)left_paren_pos;
|
2018-05-09 07:10:07 +00:00
|
|
|
|
|
|
|
if (0 < open_pos && open_pos < location_str.size){
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 file = SCu8(location_str.str, open_pos);
|
|
|
|
file = string_skip_chop_whitespace(file);
|
2018-05-09 07:10:07 +00:00
|
|
|
|
|
|
|
if (file.size > 0){
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 line_number = string_skip(string_prefix(location_str, close_pos), open_pos + 1);
|
|
|
|
line_number = string_skip_chop_whitespace(line_number);
|
2018-05-09 07:10:07 +00:00
|
|
|
|
|
|
|
if (line_number.size > 0){
|
2019-12-18 03:38:08 +00:00
|
|
|
u64 comma_pos = string_find_first(line_number, ',');
|
2018-05-09 07:10:07 +00:00
|
|
|
if (comma_pos < line_number.size){
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 column_number = string_skip(line_number, comma_pos + 1);
|
|
|
|
line_number = string_prefix(line_number, comma_pos);
|
|
|
|
jump.location.line = (i32)string_to_integer(line_number, 10);
|
|
|
|
jump.location.column = (i32)string_to_integer(column_number, 10);
|
2018-05-09 07:10:07 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-06-01 23:58:28 +00:00
|
|
|
jump.location.line = (i32)string_to_integer(line_number, 10);
|
2019-04-01 03:50:37 +00:00
|
|
|
jump.location.column = 0;
|
2018-05-09 07:10:07 +00:00
|
|
|
}
|
2019-04-01 03:50:37 +00:00
|
|
|
jump.location.file = file;
|
2019-06-01 23:58:28 +00:00
|
|
|
jump.colon_position = jump.colon_position + (i32)whitespace_length;
|
2019-04-01 03:50:37 +00:00
|
|
|
jump.success = true;
|
2018-05-09 07:10:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2019-06-01 23:58:28 +00:00
|
|
|
left_paren_pos = string_find_first(string_skip(line, left_paren_pos + 1), '(') + left_paren_pos + 1;
|
|
|
|
right_paren_pos = string_find_first(string_skip(line, left_paren_pos), ')') + left_paren_pos;
|
2018-05-09 07:10:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-01 03:50:37 +00:00
|
|
|
if (!jump.is_ms_style){
|
2019-06-01 23:58:28 +00:00
|
|
|
i32 start = (i32)try_skip_rust_arrow(line);
|
2019-04-01 03:50:37 +00:00
|
|
|
if (start != 0){
|
|
|
|
jump.has_rust_arrow = true;
|
|
|
|
}
|
2018-05-09 07:10:07 +00:00
|
|
|
|
2019-12-18 03:38:08 +00:00
|
|
|
u64 colon_pos1 = string_find_first(string_skip(line, start), ':') + start;
|
2018-05-09 07:10:07 +00:00
|
|
|
if (line.size > colon_pos1 + 1){
|
2019-06-01 23:58:28 +00:00
|
|
|
if (character_is_slash(string_get_character(line, colon_pos1 + 1))){
|
|
|
|
colon_pos1 = string_find_first(string_skip(line, colon_pos1 + 1), ':') + colon_pos1 + 1;
|
2018-05-09 07:10:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-18 03:38:08 +00:00
|
|
|
u64 colon_pos2 = string_find_first(string_skip(line, colon_pos1 + 1), ':') + colon_pos1 + 1;
|
2024-02-11 03:34:25 +00:00
|
|
|
u64 comma_pos2 = string_find_first(string_skip(line, colon_pos1 + 1), ',') + colon_pos1 + 1;
|
|
|
|
if (comma_pos2 < colon_pos2) {
|
|
|
|
colon_pos2 = comma_pos2;
|
|
|
|
}
|
|
|
|
u64 colon_pos3 = string_find_first(string_skip(line, colon_pos2 + 1), ':') + colon_pos2 + 1;
|
2018-05-09 07:10:07 +00:00
|
|
|
|
2018-11-29 21:17:34 +00:00
|
|
|
if (colon_pos3 < line.size){
|
|
|
|
if (check_is_note(line, colon_pos3)){
|
2019-04-01 03:50:37 +00:00
|
|
|
jump.sub_jump_note = true;
|
2018-11-29 21:17:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 file_name = string_skip(string_prefix(line, colon_pos1), start);
|
|
|
|
String_Const_u8 line_number = string_skip(string_prefix(line, colon_pos2), colon_pos1 + 1);
|
|
|
|
String_Const_u8 column_number = string_skip(string_prefix(line, colon_pos3), colon_pos2 + 1);
|
2018-05-09 07:10:07 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
if (file_name.size > 0 && line_number.size > 0 && column_number.size > 0){
|
|
|
|
jump.location.file = file_name;
|
|
|
|
jump.location.line = (i32)string_to_integer(line_number, 10);
|
|
|
|
jump.location.column = (i32)string_to_integer(column_number, 10);
|
|
|
|
jump.colon_position = (i32)(colon_pos3 + whitespace_length);
|
2019-04-01 03:50:37 +00:00
|
|
|
jump.success = true;
|
2018-05-09 07:10:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2018-11-29 21:17:34 +00:00
|
|
|
if (colon_pos2 < line.size){
|
|
|
|
if (check_is_note(line, colon_pos2)){
|
2019-04-01 03:50:37 +00:00
|
|
|
jump.sub_jump_note = true;
|
2018-11-29 21:17:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 file_name = string_prefix(line, colon_pos1);
|
|
|
|
String_Const_u8 line_number = string_skip(string_prefix(line, colon_pos2), colon_pos1 + 1);
|
2018-05-09 07:10:07 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
if (string_is_integer(line_number, 10)){
|
|
|
|
if (file_name.size > 0 && line_number.size > 0){
|
|
|
|
jump.location.file = file_name;
|
|
|
|
jump.location.line = (i32)string_to_integer(line_number, 10);
|
2019-04-01 03:50:37 +00:00
|
|
|
jump.location.column = 0;
|
2019-06-01 23:58:28 +00:00
|
|
|
jump.colon_position = (i32)(colon_pos3 + whitespace_length);
|
2019-04-01 03:50:37 +00:00
|
|
|
jump.success = true;
|
2018-05-09 07:10:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-01 03:50:37 +00:00
|
|
|
if (!jump.success){
|
2019-09-27 23:56:05 +00:00
|
|
|
block_zero_struct(&jump);
|
2018-05-09 07:10:07 +00:00
|
|
|
}
|
2019-04-01 03:50:37 +00:00
|
|
|
else{
|
|
|
|
jump.is_sub_jump = (jump.sub_jump_indented || jump.sub_jump_note);
|
|
|
|
}
|
|
|
|
return(jump);
|
2018-05-09 07:10:07 +00:00
|
|
|
}
|
|
|
|
|
2019-12-13 23:36:28 +00:00
|
|
|
function Parsed_Jump
|
2019-06-01 23:58:28 +00:00
|
|
|
parse_jump_location(String_Const_u8 line, Jump_Flag flags){
|
2019-04-01 03:50:37 +00:00
|
|
|
Parsed_Jump jump = parse_jump_location(line);
|
2019-06-01 23:58:28 +00:00
|
|
|
if (HasFlag(flags, JumpFlag_SkipSubs) && jump.is_sub_jump){
|
|
|
|
block_zero_struct(&jump);
|
2018-05-09 07:10:07 +00:00
|
|
|
}
|
2019-04-01 03:50:37 +00:00
|
|
|
return(jump);
|
2018-05-09 07:10:07 +00:00
|
|
|
}
|
|
|
|
|
2019-12-13 23:36:28 +00:00
|
|
|
function Parsed_Jump
|
2019-06-20 23:43:27 +00:00
|
|
|
parse_jump_from_buffer_line(Application_Links *app, Arena *arena, Buffer_ID buffer, i64 line, Jump_Flag flags){
|
2019-04-01 03:50:37 +00:00
|
|
|
Parsed_Jump jump = {};
|
2019-06-20 23:43:27 +00:00
|
|
|
String_Const_u8 line_str = push_buffer_line(app, arena, buffer, line);
|
2019-06-01 23:58:28 +00:00
|
|
|
if (line_str.size > 0){
|
|
|
|
jump = parse_jump_location(line_str, flags);
|
2018-05-09 07:10:07 +00:00
|
|
|
}
|
2019-04-01 03:50:37 +00:00
|
|
|
return(jump);
|
2018-05-09 07:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
|
2019-12-13 23:36:28 +00:00
|
|
|
function b32
|
2019-04-04 08:25:16 +00:00
|
|
|
get_jump_buffer(Application_Links *app, Buffer_ID *buffer, Name_Line_Column_Location *location){
|
2019-06-01 23:58:28 +00:00
|
|
|
return(open_file(app, buffer, location->file, false, true));
|
2019-02-12 02:33:11 +00:00
|
|
|
}
|
|
|
|
|
2019-12-13 23:36:28 +00:00
|
|
|
function b32
|
2019-04-04 08:25:16 +00:00
|
|
|
get_jump_buffer(Application_Links *app, Buffer_ID *buffer, ID_Pos_Jump_Location *location, Access_Flag access){
|
|
|
|
*buffer = location->buffer_id;
|
|
|
|
return(buffer_exists(app, *buffer));
|
2018-05-09 07:10:07 +00:00
|
|
|
}
|
|
|
|
|
2019-12-13 23:36:28 +00:00
|
|
|
function b32
|
2019-04-04 08:25:16 +00:00
|
|
|
get_jump_buffer(Application_Links *app, Buffer_ID *buffer, ID_Pos_Jump_Location *location){
|
2019-10-18 02:54:02 +00:00
|
|
|
return(get_jump_buffer(app, buffer, location, Access_Always));
|
2018-05-09 07:10:07 +00:00
|
|
|
}
|
|
|
|
|
2019-12-13 23:36:28 +00:00
|
|
|
function View_ID
|
2019-04-06 19:40:36 +00:00
|
|
|
switch_to_existing_view(Application_Links *app, View_ID view, Buffer_ID buffer){
|
2019-10-18 02:54:02 +00:00
|
|
|
Buffer_ID current_buffer = view_get_buffer(app, view, Access_Always);
|
2019-04-06 19:40:36 +00:00
|
|
|
if (view != 0 || current_buffer != buffer){
|
|
|
|
View_ID existing_view = get_first_view_with_buffer(app, buffer);
|
|
|
|
if (existing_view != 0){
|
|
|
|
view = existing_view;
|
2018-05-09 07:10:07 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-06 19:40:36 +00:00
|
|
|
return(view);
|
2018-05-09 07:10:07 +00:00
|
|
|
}
|
|
|
|
|
2019-12-13 23:36:28 +00:00
|
|
|
function void
|
2019-04-06 19:40:36 +00:00
|
|
|
set_view_to_location(Application_Links *app, View_ID view, Buffer_ID buffer, Buffer_Seek seek){
|
2019-10-18 02:54:02 +00:00
|
|
|
Buffer_ID current_buffer = view_get_buffer(app, view, Access_Always);
|
2019-04-06 19:40:36 +00:00
|
|
|
if (current_buffer != buffer){
|
2019-04-04 08:25:16 +00:00
|
|
|
view_set_buffer(app, view, buffer, 0);
|
2018-05-09 07:10:07 +00:00
|
|
|
}
|
2019-09-02 21:32:52 +00:00
|
|
|
view_set_cursor_and_preferred_x(app, view, seek);
|
2018-05-09 07:10:07 +00:00
|
|
|
}
|
|
|
|
|
2019-12-13 23:36:28 +00:00
|
|
|
function void
|
|
|
|
jump_to_location(Application_Links *app, View_ID view, Buffer_ID buffer, i64 pos){
|
|
|
|
view_set_active(app, view);
|
|
|
|
set_view_to_location(app, view, buffer, seek_pos(pos));
|
|
|
|
if (auto_center_after_jumps){
|
|
|
|
center_view(app);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function void
|
2019-10-20 01:17:44 +00:00
|
|
|
jump_to_location(Application_Links *app, View_ID view, Buffer_ID buffer,
|
|
|
|
Name_Line_Column_Location location){
|
2019-04-06 19:40:36 +00:00
|
|
|
view_set_active(app, view);
|
2019-09-02 18:59:36 +00:00
|
|
|
set_view_to_location(app, view, buffer, seek_line_col(location.line, location.column));
|
2018-05-09 07:10:07 +00:00
|
|
|
if (auto_center_after_jumps){
|
|
|
|
center_view(app);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-13 23:36:28 +00:00
|
|
|
function void
|
2019-10-20 01:17:44 +00:00
|
|
|
jump_to_location(Application_Links *app, View_ID view,
|
|
|
|
Name_Line_Column_Location location){
|
|
|
|
Buffer_ID buffer = 0;
|
|
|
|
if (get_jump_buffer(app, &buffer, &location)){
|
|
|
|
jump_to_location(app, view, buffer, location);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-13 23:36:28 +00:00
|
|
|
function void
|
2019-04-06 19:40:36 +00:00
|
|
|
jump_to_location(Application_Links *app, View_ID view, Buffer_ID buffer, ID_Pos_Jump_Location location){
|
|
|
|
view_set_active(app, view);
|
2018-05-09 07:10:07 +00:00
|
|
|
set_view_to_location(app, view, buffer, seek_pos(location.pos));
|
|
|
|
if (auto_center_after_jumps){
|
|
|
|
center_view(app);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-20 01:17:44 +00:00
|
|
|
function void
|
|
|
|
jump_to_location(Application_Links *app, View_ID view, String_Const_u8 location){
|
|
|
|
Parsed_Jump jump = parse_jump_location(location);
|
|
|
|
if (jump.success){
|
|
|
|
jump_to_location(app, view, jump.location);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-09 07:10:07 +00:00
|
|
|
////////////////////////////////
|
|
|
|
|
2019-06-20 23:43:27 +00:00
|
|
|
// TODO(allen): rewrite
|
2019-04-01 03:50:37 +00:00
|
|
|
static Parsed_Jump
|
2019-06-01 23:58:28 +00:00
|
|
|
seek_next_jump_in_buffer(Application_Links *app, Arena *arena,
|
2019-06-20 23:43:27 +00:00
|
|
|
Buffer_ID buffer, i64 first_line, Jump_Flag flags, Scan_Direction direction,
|
|
|
|
i64 *line_out){
|
2018-05-09 07:10:07 +00:00
|
|
|
Assert(direction == 1 || direction == -1);
|
2019-04-01 03:50:37 +00:00
|
|
|
Parsed_Jump jump = {};
|
2019-06-20 23:43:27 +00:00
|
|
|
i64 line = first_line;
|
2018-05-09 07:10:07 +00:00
|
|
|
for (;;){
|
2019-06-20 23:43:27 +00:00
|
|
|
if (is_valid_line(app, buffer, line)){
|
|
|
|
String_Const_u8 line_str = push_buffer_line(app, arena, buffer, line);
|
2019-06-01 23:58:28 +00:00
|
|
|
jump = parse_jump_location(line_str, flags);
|
2019-04-01 03:50:37 +00:00
|
|
|
if (jump.success){
|
2018-05-09 07:10:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
line += direction;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-04-01 03:50:37 +00:00
|
|
|
if (jump.success){
|
2019-06-01 23:58:28 +00:00
|
|
|
*line_out = clamp_bot(line, 0);
|
2019-04-01 03:50:37 +00:00
|
|
|
}
|
|
|
|
return(jump);
|
2018-05-09 07:10:07 +00:00
|
|
|
}
|
|
|
|
|
2018-08-12 03:45:09 +00:00
|
|
|
static ID_Line_Column_Jump_Location
|
|
|
|
convert_name_based_to_id_based(Application_Links *app, Name_Line_Column_Location loc){
|
2018-11-20 08:18:54 +00:00
|
|
|
ID_Line_Column_Jump_Location result = {};
|
2019-10-18 02:54:02 +00:00
|
|
|
Buffer_ID buffer = get_buffer_by_name(app, loc.file, Access_Always);
|
2019-04-05 02:03:36 +00:00
|
|
|
if (buffer != 0){
|
|
|
|
result.buffer_id = buffer;
|
2018-05-09 07:10:07 +00:00
|
|
|
result.line = loc.line;
|
|
|
|
result.column = loc.column;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-04-01 03:50:37 +00:00
|
|
|
static Parsed_Jump
|
2019-06-20 23:43:27 +00:00
|
|
|
seek_next_jump_in_view(Application_Links *app, Arena *arena, View_ID view, i32 skip_sub_errors, Scan_Direction direction, i64 *line_out){
|
|
|
|
i64 cursor_position = view_get_cursor_pos(app, view);
|
2019-09-02 18:59:36 +00:00
|
|
|
Buffer_Cursor cursor = view_compute_cursor(app, view, seek_pos(cursor_position));
|
2019-06-20 23:43:27 +00:00
|
|
|
i64 line = cursor.line;
|
2019-10-18 02:54:02 +00:00
|
|
|
Buffer_ID buffer = view_get_buffer(app, view, Access_Always);
|
2019-06-01 23:58:28 +00:00
|
|
|
Parsed_Jump jump = seek_next_jump_in_buffer(app, arena, buffer, line + direction, skip_sub_errors, direction, &line);
|
2019-04-01 03:50:37 +00:00
|
|
|
if (jump.success){
|
2018-05-09 07:10:07 +00:00
|
|
|
*line_out = line;
|
|
|
|
}
|
2019-04-01 03:50:37 +00:00
|
|
|
return(jump);
|
2018-05-09 07:10:07 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
static b32
|
2018-08-12 03:45:09 +00:00
|
|
|
skip_this_jump(ID_Line_Column_Jump_Location prev, ID_Line_Column_Jump_Location jump){
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = false;
|
2018-05-09 07:10:07 +00:00
|
|
|
if (prev.buffer_id != 0 && prev.buffer_id == jump.buffer_id && prev.line == jump.line && prev.column <= jump.column){
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-08-24 01:34:42 +00:00
|
|
|
#if 0
|
2019-02-26 23:08:42 +00:00
|
|
|
static b32
|
2019-06-20 23:43:27 +00:00
|
|
|
advance_cursor_in_jump_view(Application_Links *app, View_ID view, b32 skip_repeats, b32 skip_sub_error, Scan_Direction direction, Name_Line_Column_Location *location_out){
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = true;
|
2018-05-09 07:10:07 +00:00
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
Name_Line_Column_Location location = {};
|
|
|
|
ID_Line_Column_Jump_Location jump = {};
|
2019-06-20 23:43:27 +00:00
|
|
|
i64 line = 0;
|
|
|
|
i64 colon_index = 0;
|
2018-05-09 07:10:07 +00:00
|
|
|
|
|
|
|
do{
|
2019-06-01 23:58:28 +00:00
|
|
|
Arena *scratch = context_get_arena(app);
|
|
|
|
Temp_Memory temp = begin_temp(scratch);
|
|
|
|
Parsed_Jump parsed_jump = seek_next_jump_in_view(app, scratch, view, skip_sub_error, direction, &line);
|
2019-04-01 03:50:37 +00:00
|
|
|
if (parsed_jump.success){
|
|
|
|
jump = convert_name_based_to_id_based(app, parsed_jump.location);
|
|
|
|
view_set_cursor(app, view, seek_line_char(line, parsed_jump.colon_position + 1), true);
|
2018-05-09 07:10:07 +00:00
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
jump.buffer_id = 0;
|
|
|
|
result = false;
|
|
|
|
}
|
2019-06-01 23:58:28 +00:00
|
|
|
end_temp(temp);
|
2018-05-09 07:10:07 +00:00
|
|
|
}while(skip_repeats && skip_this_jump(prev_location, jump));
|
|
|
|
|
|
|
|
if (result){
|
|
|
|
*location_out = location;
|
2018-08-12 03:45:09 +00:00
|
|
|
view_set_cursor(app, view, seek_line_char(line, colon_index + 1), true);
|
2018-05-09 07:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
prev_location = jump;
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
static b32
|
2019-08-24 01:34:42 +00:00
|
|
|
seek_jump_(Application_Links *app, b32 skip_repeats, b32 skip_sub_errors, i32 direction){
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = false;
|
2018-05-09 07:10:07 +00:00
|
|
|
|
2019-04-06 19:40:36 +00:00
|
|
|
View_ID view = get_view_for_locked_jump_buffer(app);
|
|
|
|
if (view != 0){
|
2018-11-20 08:18:54 +00:00
|
|
|
Name_Line_Column_Location location = {};
|
2019-06-01 23:58:28 +00:00
|
|
|
if (advance_cursor_in_jump_view(app, view, skip_repeats, skip_sub_errors, direction, &location)){
|
2019-04-04 08:25:16 +00:00
|
|
|
Buffer_ID buffer = {};
|
2018-05-09 07:10:07 +00:00
|
|
|
if (get_jump_buffer(app, &buffer, &location)){
|
2019-10-18 02:54:02 +00:00
|
|
|
View_ID target_view = get_active_view(app, Access_Always);
|
2019-04-06 19:40:36 +00:00
|
|
|
if (target_view == view){
|
2018-05-09 07:10:07 +00:00
|
|
|
change_active_panel(app);
|
2019-10-18 02:54:02 +00:00
|
|
|
target_view = get_active_view(app, Access_Always);
|
2018-05-09 07:10:07 +00:00
|
|
|
}
|
2019-04-06 19:40:36 +00:00
|
|
|
switch_to_existing_view(app, target_view, buffer);
|
|
|
|
jump_to_location(app, target_view, buffer, location);
|
2018-05-09 07:10:07 +00:00
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
2018-05-09 18:58:21 +00:00
|
|
|
#endif
|
|
|
|
|
2018-05-09 07:10:07 +00:00
|
|
|
// BOTTOM
|
|
|
|
|