diff --git a/4coder_API.html b/4coder_API.html index 7f07b17b..2489973c 100644 --- a/4coder_API.html +++ b/4coder_API.html @@ -1,102 +1,102 @@ 4coder API Docs

4cpp Lexing Library

Table of Contents

-

§1 Introduction

This is the documentation for alpha 4.0.11 The documentation is still under construction so some of the links are linking to sections that have not been written yet. What is here should be correct and I suspect useful even without some of the other sections.

If you have questions or discover errors please contact editor@4coder.net or to get help from community members you can post on the 4coder forums hosted on handmade.network at 4coder.handmade.network

+

§1 Introduction

This is the documentation for alpha 4.0.12 The documentation is still under construction so some of the links are linking to sections that have not been written yet. What is here should be correct and I suspect useful even without some of the other sections.

If you have questions or discover errors please contact editor@4coder.net or to get help from community members you can post on the 4coder forums hosted on handmade.network at 4coder.handmade.network

§2 4coder Systems

Coming Soon
-

§3 Types and Functions

§3.1 Function List

§3.2 Type List

§3.3 Function Descriptions

§3.3.1: exec_command

bool32 app->exec_command(
Application_Links *app,
Command_ID command_id
)
Parameters
command_id
The command_id parameter specifies which internal command to execute.
Return
This call returns non-zero if command_id named a valid internal command.
Description
A call to exec_command executes an internal command. -If command_id is invalid a warning is posted to *messages*.

See Also
Command_ID

§3.3.2: exec_system_command

bool32 app->exec_system_command(
Application_Links *app,
View_Summary *view,
Buffer_Identifier buffer,
char *path,
int32_t path_len,
char *command,
int32_t command_len,
Command_Line_Interface_Flag flags
)
Parameters
view
If the view parameter is non-null it specifies a view to display the command's output buffer.
buffer
The buffer the command will output to is specified by the buffer parameter. +

§3 Types and Functions

§3.1 Function List

§3.2 Type List

§3.3 Function Descriptions

§3.3.1: exec_command

bool32 exec_command(
Application_Links *app,
Command_ID command_id
)
Parameters
command_id
The command_id parameter specifies which internal command to execute.
Return
This call returns non-zero if command_id named a valid internal command.
Description
A call to exec_command executes an internal command. +If command_id is invalid a warning is posted to *messages*.

See Also

§3.3.2: exec_system_command

bool32 exec_system_command(
Application_Links *app,
View_Summary *view,
Buffer_Identifier buffer,
char *path,
int32_t path_len,
char *command,
int32_t command_len,
Command_Line_Interface_Flag flags
)
Parameters
view
If the view parameter is non-null it specifies a view to display the command's output buffer.
buffer
The buffer the command will output to is specified by the buffer parameter. See Buffer_Identifier for information on how this type specifies a buffer.
path
The path parameter specifies the path in which the command shall be executed. The string need not be null terminated.
path_len
The parameter path_len specifies the length of the path string.
command
The command parameter specifies the command that shall be executed. The string need not be null terminated.
command_len
The parameter command_len specifies the length of the command string.
flags
Flags for the behavior of the call are specified in the flags parameter.
Return
This call returns non-zero on success.
Description
A call to exec_system_command executes a command as if called from the command line, and sends the output to a buffer. The buffer identifier can either name a new buffer that does not exist, name a buffer that does exist, or provide the id of a buffer that does exist.

If the buffer is not already in an open view and the view parameter is not NULL, then the provided view will display the output buffer.

-If the view parameter is NULL, no view will switch to the output.

See Also

§3.3.3: clipboard_post

void app->clipboard_post(
Application_Links *app,
int32_t clipboard_id,
char *str,
int32_t len
)
Parameters
clipboard_id
This parameter is set up to prepare for future features, it should always be 0 for now.
str
The str parameter specifies the string to be posted to the clipboard, it need not be null terminated.
len
The len parameter specifies the length of the str string.
Description
Stores the string str in the clipboard initially with index 0. +If the view parameter is NULL, no view will switch to the output.

See Also

§3.3.3: clipboard_post

void clipboard_post(
Application_Links *app,
int32_t clipboard_id,
char *str,
int32_t len
)
Parameters
clipboard_id
This parameter is set up to prepare for future features, it should always be 0 for now.
str
The str parameter specifies the string to be posted to the clipboard, it need not be null terminated.
len
The len parameter specifies the length of the str string.
Description
Stores the string str in the clipboard initially with index 0. Also reports the copy to the operating system, so that it may -be pasted into other applications.

See Also

§3.3.4: clipboard_count

int32_t app->clipboard_count(
Application_Links *app,
int32_t clipboard_id
)
Parameters
clipboard_id
This parameter is set up to prepare for future features, it should always be 0 for now.
Description
This call returns the number of items in the clipboard.

See Also

§3.3.5: clipboard_index

int32_t app->clipboard_index(
Application_Links *app,
int32_t clipboard_id,
int32_t item_index,
char *out,
int32_t len
)
Parameters
clipboard_id
This parameter is set up to prepare for future features, it should always be 0 for now.
item_index
This parameter specifies which item to read, 0 is the most recent copy, 1 is the second most recent copy, etc.
out
This parameter provides a buffer where the clipboard contents are written. This parameter may be NULL.
len
This parameter specifies the length of the out buffer.
Return
This call returns the size of the item associated with item_index.
Description
This function always returns the size of the item even if the output buffer is NULL. +be pasted into other applications.

See Also

§3.3.4: clipboard_count

int32_t clipboard_count(
Application_Links *app,
int32_t clipboard_id
)
Parameters
clipboard_id
This parameter is set up to prepare for future features, it should always be 0 for now.
Description
This call returns the number of items in the clipboard.

See Also

§3.3.5: clipboard_index

int32_t clipboard_index(
Application_Links *app,
int32_t clipboard_id,
int32_t item_index,
char *out,
int32_t len
)
Parameters
clipboard_id
This parameter is set up to prepare for future features, it should always be 0 for now.
item_index
This parameter specifies which item to read, 0 is the most recent copy, 1 is the second most recent copy, etc.
out
This parameter provides a buffer where the clipboard contents are written. This parameter may be NULL.
len
This parameter specifies the length of the out buffer.
Return
This call returns the size of the item associated with item_index.
Description
This function always returns the size of the item even if the output buffer is NULL. If the output buffer is too small to contain the whole string, it is filled with the -first len character of the clipboard contents. The output string is not null terminated.

See Also

§3.3.6: get_buffer_count

int32_t app->get_buffer_count(
Application_Links *app
)
Description
TODO


§3.3.7: get_buffer_first

Buffer_Summary app->get_buffer_first(
Application_Links *app,
Access_Flag access
)
Parameters
access
The access parameter determines what levels of protection this call can access.
Return
This call returns the summary of the first buffer in a buffer loop.
Description
This call begins a loop across all the buffers.

+first len character of the clipboard contents. The output string is not null terminated.

See Also

§3.3.6: get_buffer_count

int32_t get_buffer_count(
Application_Links *app
)
Description
TODO


§3.3.7: get_buffer_first

Buffer_Summary get_buffer_first(
Application_Links *app,
Access_Flag access
)
Parameters
access
The access parameter determines what levels of protection this call can access.
Return
This call returns the summary of the first buffer in a buffer loop.
Description
This call begins a loop across all the buffers.

If the buffer returned does not exist, the loop is finished. -Buffers should not be killed durring a buffer loop.

See Also

§3.3.8: get_buffer_next

void app->get_buffer_next(
Application_Links *app,
Buffer_Summary *buffer,
Access_Flag access
)
Parameters
buffer
The Buffer_Summary pointed to by buffer is iterated to the next buffer or to a null summary if this is the last buffer.
access
The access parameter determines what levels of protection this call can access. The buffer outputted will be the next buffer that is accessible.
Description
This call steps a Buffer_Summary to the next buffer in the global buffer order. +Buffers should not be killed durring a buffer loop.

See Also

§3.3.8: get_buffer_next

void get_buffer_next(
Application_Links *app,
Buffer_Summary *buffer,
Access_Flag access
)
Parameters
buffer
The Buffer_Summary pointed to by buffer is iterated to the next buffer or to a null summary if this is the last buffer.
access
The access parameter determines what levels of protection this call can access. The buffer outputted will be the next buffer that is accessible.
Description
This call steps a Buffer_Summary to the next buffer in the global buffer order. The global buffer order is kept roughly in the order of most recently used to least recently used.

If the buffer outputted does not exist, the loop is finished. -Buffers should not be killed or created durring a buffer loop.

See Also

§3.3.9: get_buffer

Buffer_Summary app->get_buffer(
Application_Links *app,
Buffer_ID buffer_id,
Access_Flag access
)
Parameters
buffer_id
The parameter buffer_id specifies which buffer to try to get.
access
The access parameter determines what levels of protection this call can access.
Return
This call returns a summary that describes the indicated buffer if it exists and is accessible.
See Also

§3.3.10: get_buffer_by_name

Buffer_Summary app->get_buffer_by_name(
Application_Links *app,
char *name,
int32_t len,
Access_Flag access
)
Parameters
name
The name parameter specifies the buffer name to try to get. The string need not be null terminated.
len
The len parameter specifies the length of the name string.
access
The access parameter determines what levels of protection this call can access.
Return
This call returns a summary that describes the indicated buffer if it exists and is accessible.
See Also

§3.3.11: buffer_read_range

bool32 app->buffer_read_range(
Application_Links *app,
Buffer_Summary *buffer,
int32_t start,
int32_t end,
char *out
)
Parameters
buffer
This parameter specifies the buffer to read.
start
This parameter specifies absolute position of the first character in the read range.
end
This parameter specifies the absolute position of the the character one past the end of the read range.
out
This paramter provides the output character buffer to fill with the result of the read.
Return
This call returns non-zero if the read succeeds.
Description
The output buffer must have a capacity of at least (end - start). +Buffers should not be killed or created durring a buffer loop.

See Also

§3.3.9: get_buffer

Buffer_Summary get_buffer(
Application_Links *app,
Buffer_ID buffer_id,
Access_Flag access
)
Parameters
buffer_id
The parameter buffer_id specifies which buffer to try to get.
access
The access parameter determines what levels of protection this call can access.
Return
This call returns a summary that describes the indicated buffer if it exists and is accessible.
See Also

§3.3.10: get_buffer_by_name

Buffer_Summary get_buffer_by_name(
Application_Links *app,
char *name,
int32_t len,
Access_Flag access
)
Parameters
name
The name parameter specifies the buffer name to try to get. The string need not be null terminated.
len
The len parameter specifies the length of the name string.
access
The access parameter determines what levels of protection this call can access.
Return
This call returns a summary that describes the indicated buffer if it exists and is accessible.
See Also

§3.3.11: buffer_read_range

bool32 buffer_read_range(
Application_Links *app,
Buffer_Summary *buffer,
int32_t start,
int32_t end,
char *out
)
Parameters
buffer
This parameter specifies the buffer to read.
start
This parameter specifies absolute position of the first character in the read range.
end
This parameter specifies the absolute position of the the character one past the end of the read range.
out
This paramter provides the output character buffer to fill with the result of the read.
Return
This call returns non-zero if the read succeeds.
Description
The output buffer must have a capacity of at least (end - start). The output is not null terminated.

This call fails if the buffer does not exist, -or if the read range is not within the bounds of the buffer.

See Also

§3.3.12: buffer_replace_range

bool32 app->buffer_replace_range(
Application_Links *app,
Buffer_Summary *buffer,
int32_t start,
int32_t end,
char *str,
int32_t len
)
Parameters
buffer
This parameter specifies the buffer to edit.
start
This parameter specifies absolute position of the first character in the replace range.
end
This parameter specifies the absolute position of the the character one past the end of the replace range.
str
This parameter specifies the the string to write into the range; it need not be null terminated.
len
This parameter specifies the length of the str string.
Return
This call returns non-zero if the replacement succeeds.
Description
If this call succeeds it deletes the range from start to end +or if the read range is not within the bounds of the buffer.

See Also

§3.3.12: buffer_replace_range

bool32 buffer_replace_range(
Application_Links *app,
Buffer_Summary *buffer,
int32_t start,
int32_t end,
char *str,
int32_t len
)
Parameters
buffer
This parameter specifies the buffer to edit.
start
This parameter specifies absolute position of the first character in the replace range.
end
This parameter specifies the absolute position of the the character one past the end of the replace range.
str
This parameter specifies the the string to write into the range; it need not be null terminated.
len
This parameter specifies the length of the str string.
Return
This call returns non-zero if the replacement succeeds.
Description
If this call succeeds it deletes the range from start to end and writes str in the same position. If end == start then this call is equivalent to inserting the string at start. If len == 0 this call is equivalent to deleteing the range from start to end.

This call fails if the buffer does not exist, or if the replace -range is not within the bounds of the buffer.

See Also

§3.3.13: buffer_compute_cursor

bool32 app->buffer_compute_cursor(
Application_Links *app,
Buffer_Summary *buffer,
Buffer_Seek seek,
Partial_Cursor *cursor_out
)
Parameters
buffer
The buffer parameter specifies the buffer on which to run the cursor computation.
seek
The seek parameter specifies the target position for the seek.
cursor_out
On success this struct is filled with the result of the seek.
Return
This call returns non-zero on success. This call can fail if the buffer summary provided +range is not within the bounds of the buffer.

See Also

§3.3.13: buffer_compute_cursor

bool32 buffer_compute_cursor(
Application_Links *app,
Buffer_Summary *buffer,
Buffer_Seek seek,
Partial_Cursor *cursor_out
)
Parameters
buffer
The buffer parameter specifies the buffer on which to run the cursor computation.
seek
The seek parameter specifies the target position for the seek.
cursor_out
On success this struct is filled with the result of the seek.
Return
This call returns non-zero on success. This call can fail if the buffer summary provided does not summarize an actual buffer in 4coder, or if the provided seek format is invalid. The valid seek types are seek_pos and seek_line_char.
Description
Computes a Partial_Cursor for the given seek position with no side effects. The seek position must be one of the types supported by Partial_Cursor. Those -types are absolute position and line,column position.

See Also

§3.3.14: buffer_batch_edit

bool32 app->buffer_batch_edit(
Application_Links *app,
Buffer_Summary *buffer,
char *str,
int32_t str_len,
Buffer_Edit *edits,
int32_t edit_count,
Buffer_Batch_Edit_Type type
)
Parameters
str
This parameter provides all of the source string for the edits in the batch.
str_len
This parameter specifies the length of the str string.
edits
This parameter provides about the source string and destination range of each edit as an array.
edit_count
This parameter specifies the number of Buffer_Edit structs in edits.
type
This prameter specifies what type of batch edit to execute.
Return
This call returns non-zero if the batch edit succeeds. This call can fail if the provided -buffer summary does not refer to an actual buffer in 4coder.
Description
TODO

See Also

§3.3.15: buffer_set_setting

bool32 app->buffer_set_setting(
Application_Links *app,
Buffer_Summary *buffer,
Buffer_Setting_ID setting,
int32_t value
)
Parameters
buffer
The buffer parameter specifies the buffer on which to set a setting.
setting
The setting parameter identifies the setting that shall be changed.
value
The value parameter specifies the value to which the setting shall be changed.
See Also

§3.3.16: buffer_token_count

int32_t app->buffer_token_count(
Application_Links *app,
Buffer_Summary *buffer
)
Parameters
buffer
Specifies the buffer from which to read the token count.
Return
If tokens are available for the buffer, the number of tokens on the buffer is returned. -If the buffer does not exist or if it is not a lexed buffer, the return is zero.

§3.3.17: buffer_read_tokens

bool32 app->buffer_read_tokens(
Application_Links *app,
Buffer_Summary *buffer,
int32_t start_token,
int32_t end_token,
Cpp_Token *tokens_out
)
Parameters
buffer
Specifies the buffer from which to read tokens.
first_token
Specifies the index of the first token to read.
end_token
Specifies the token to stop reading at.
tokens_out
The memory that will store the tokens read from the buffer.
Return
Returns non-zero on success. This call can fail if the buffer doesn't -exist or doesn't have tokens ready, or if either the first or last index is out of bounds.
Description
Puts the data for the tokens with the indices [first_token,last_token


§3.3.18: buffer_get_token_index

bool32 app->buffer_get_token_index(
Application_Links *app,
Buffer_Summary *buffer,
int32_t pos,
Cpp_Get_Token_Result *get_result
)
Parameters
buffer
The buffer from which to get a token.
pos
The position in the buffer in absolute coordinates.
get_result
The output struct specifying which token contains pos.
Return
Returns non-zero on success. This call can fail if the buffer doesn't exist, +types are absolute position and line,column position.

See Also

§3.3.14: buffer_batch_edit

bool32 buffer_batch_edit(
Application_Links *app,
Buffer_Summary *buffer,
char *str,
int32_t str_len,
Buffer_Edit *edits,
int32_t edit_count,
Buffer_Batch_Edit_Type type
)
Parameters
str
This parameter provides all of the source string for the edits in the batch.
str_len
This parameter specifies the length of the str string.
edits
This parameter provides about the source string and destination range of each edit as an array.
edit_count
This parameter specifies the number of Buffer_Edit structs in edits.
type
This prameter specifies what type of batch edit to execute.
Return
This call returns non-zero if the batch edit succeeds. This call can fail if the provided +buffer summary does not refer to an actual buffer in 4coder.
Description
TODO

See Also

§3.3.15: buffer_set_setting

bool32 buffer_set_setting(
Application_Links *app,
Buffer_Summary *buffer,
Buffer_Setting_ID setting,
int32_t value
)
Parameters
buffer
The buffer parameter specifies the buffer on which to set a setting.
setting
The setting parameter identifies the setting that shall be changed.
value
The value parameter specifies the value to which the setting shall be changed.
See Also

§3.3.16: buffer_token_count

int32_t buffer_token_count(
Application_Links *app,
Buffer_Summary *buffer
)
Parameters
buffer
Specifies the buffer from which to read the token count.
Return
If tokens are available for the buffer, the number of tokens on the buffer is returned. +If the buffer does not exist or if it is not a lexed buffer, the return is zero.

§3.3.17: buffer_read_tokens

bool32 buffer_read_tokens(
Application_Links *app,
Buffer_Summary *buffer,
int32_t start_token,
int32_t end_token,
Cpp_Token *tokens_out
)
Parameters
buffer
Specifies the buffer from which to read tokens.
first_token
Specifies the index of the first token to read.
end_token
Specifies the token to stop reading at.
tokens_out
The memory that will store the tokens read from the buffer.
Return
Returns non-zero on success. This call can fail if the buffer doesn't +exist or doesn't have tokens ready, or if either the first or last index is out of bounds.
Description
Puts the data for the tokens with the indices [first_token,last_token


§3.3.18: buffer_get_token_index

bool32 buffer_get_token_index(
Application_Links *app,
Buffer_Summary *buffer,
int32_t pos,
Cpp_Get_Token_Result *get_result
)
Parameters
buffer
The buffer from which to get a token.
pos
The position in the buffer in absolute coordinates.
get_result
The output struct specifying which token contains pos.
Return
Returns non-zero on success. This call can fail if the buffer doesn't exist, or if the buffer doesn't have tokens ready.
Description
This call finds the token that contains a particular position, or if the position is in between -tokens it finds the index of the token to the left of the position.

See Also

§3.3.19: create_buffer

Buffer_Summary app->create_buffer(
Application_Links *app,
char *filename,
int32_t filename_len,
Buffer_Create_Flag flags
)
Parameters
filename
The filename parameter specifies the name of the file to be opened or created; +tokens it finds the index of the token to the left of the position.

See Also

§3.3.19: create_buffer

Buffer_Summary create_buffer(
Application_Links *app,
char *filename,
int32_t filename_len,
Buffer_Create_Flag flags
)
Parameters
filename
The filename parameter specifies the name of the file to be opened or created; it need not be null terminated.
filename_len
The filename_len parameter spcifies the length of the filename string.
flags
The flags parameter specifies behaviors for buffer creation.
Return
This call returns the summary of the created buffer.
Description
Tries to create a new buffer and associate it to the given filename. If such a buffer already exists the existing buffer is returned in the Buffer_Summary and no new buffer is created. If the buffer does not exist a new buffer is created and named after the given filename. If the filename corresponds to a file on the disk that file is loaded and put into -buffer, if the filename does not correspond to a file on disk the buffer is created empty.

See Also

§3.3.20: save_buffer

bool32 app->save_buffer(
Application_Links *app,
Buffer_Summary *buffer,
char *filename,
int32_t filename_len,
uint32_t flags
)
Parameters
buffer
The buffer parameter specifies the buffer to save to a file.
filename
The filename parameter specifies the name of the file to associated to the buffer; it need not be null terminated.
filename_len
The filename_len parameter specifies the length of the filename string.
flags
This parameter is not currently used and should be set to 0 for now.
Return
This call returns non-zero on success.

§3.3.21: kill_buffer

bool32 app->kill_buffer(
Application_Links *app,
Buffer_Identifier buffer,
View_ID view_id,
Buffer_Kill_Flag flags
)
Parameters
buffer
The buffer parameter specifies the buffer to try to kill.
view_id
The view_id parameter specifies the view that will contain the "are you sure" dialogue if the buffer is dirty.
flags
The flags parameter specifies behaviors for the buffer kill.
Return
This call returns non-zero if the buffer is killed.
Description
Tries to kill the idenfied buffer. If the buffer is dirty and the "are you sure" +buffer, if the filename does not correspond to a file on disk the buffer is created empty.

See Also

§3.3.20: save_buffer

bool32 save_buffer(
Application_Links *app,
Buffer_Summary *buffer,
char *filename,
int32_t filename_len,
uint32_t flags
)
Parameters
buffer
The buffer parameter specifies the buffer to save to a file.
filename
The filename parameter specifies the name of the file to associated to the buffer; it need not be null terminated.
filename_len
The filename_len parameter specifies the length of the filename string.
flags
This parameter is not currently used and should be set to 0 for now.
Return
This call returns non-zero on success.

§3.3.21: kill_buffer

bool32 kill_buffer(
Application_Links *app,
Buffer_Identifier buffer,
View_ID view_id,
Buffer_Kill_Flag flags
)
Parameters
buffer
The buffer parameter specifies the buffer to try to kill.
view_id
The view_id parameter specifies the view that will contain the "are you sure" dialogue if the buffer is dirty.
flags
The flags parameter specifies behaviors for the buffer kill.
Return
This call returns non-zero if the buffer is killed.
Description
Tries to kill the idenfied buffer. If the buffer is dirty and the "are you sure" dialogue needs to be displayed the provided view is used to show the dialogue. -If the view is not open the kill fails.

See Also

§3.3.22: get_view_first

View_Summary app->get_view_first(
Application_Links *app,
Access_Flag access
)
Parameters
access
The access parameter determines what levels of protection this call can access.
Return
This call returns the summary of the first view in a view loop.
Description
This call begins a loop across all the open views.

+If the view is not open the kill fails.

See Also

§3.3.22: get_view_first

View_Summary get_view_first(
Application_Links *app,
Access_Flag access
)
Parameters
access
The access parameter determines what levels of protection this call can access.
Return
This call returns the summary of the first view in a view loop.
Description
This call begins a loop across all the open views.

If the View_Summary returned is a null summary, the loop is finished. -Views should not be closed or opened durring a view loop.

See Also

§3.3.23: get_view_next

void app->get_view_next(
Application_Links *app,
View_Summary *view,
Access_Flag access
)
Parameters
view
The View_Summary pointed to by view is iterated to the next view or to a null summary if this is the last view.
access
The access parameter determines what levels of protection this call can access. The view outputted will be the next view that is accessible.
Description
This call steps a View_Summary to the next view in the global view order.

+Views should not be closed or opened durring a view loop.

See Also

§3.3.23: get_view_next

void get_view_next(
Application_Links *app,
View_Summary *view,
Access_Flag access
)
Parameters
view
The View_Summary pointed to by view is iterated to the next view or to a null summary if this is the last view.
access
The access parameter determines what levels of protection this call can access. The view outputted will be the next view that is accessible.
Description
This call steps a View_Summary to the next view in the global view order.

If the view outputted does not exist, the loop is finished. -Views should not be closed or opened durring a view loop.

See Also

§3.3.24: get_view

View_Summary app->get_view(
Application_Links *app,
View_ID view_id,
Access_Flag access
)
Parameters
view_id
The view_id specifies the view to try to get.
access
The access parameter determines what levels of protection this call can access.
Return
This call returns a summary that describes the indicated view if it is open and accessible.
See Also

§3.3.25: get_active_view

View_Summary app->get_active_view(
Application_Links *app,
Access_Flag access
)
Parameters
access
The access parameter determines what levels of protection this call can access.
Return
This call returns a summary that describes the active view.
See Also

§3.3.26: open_view

View_Summary app->open_view(
Application_Links *app,
View_Summary *view_location,
View_Split_Position position
)
Parameters
view_location
The view_location parameter specifies the view to split to open the new view.
position
The position parameter specifies how to split the view and where to place the new view.
Return
If this call succeeds it returns a View_Summary describing the newly created view, if it fails it -returns a null summary.
Description
4coder is built with a limit of 16 views. If 16 views are already open when this is called the call will fail.

See Also

§3.3.27: close_view

bool32 app->close_view(
Application_Links *app,
View_Summary *view
)
Parameters
view
The view parameter specifies which view to close.
Return
This call returns non-zero on success.
Description
If the given view is open and is not the last view, it will be closed. +Views should not be closed or opened durring a view loop.

See Also

§3.3.24: get_view

View_Summary get_view(
Application_Links *app,
View_ID view_id,
Access_Flag access
)
Parameters
view_id
The view_id specifies the view to try to get.
access
The access parameter determines what levels of protection this call can access.
Return
This call returns a summary that describes the indicated view if it is open and accessible.
See Also

§3.3.25: get_active_view

View_Summary get_active_view(
Application_Links *app,
Access_Flag access
)
Parameters
access
The access parameter determines what levels of protection this call can access.
Return
This call returns a summary that describes the active view.
See Also

§3.3.26: open_view

View_Summary open_view(
Application_Links *app,
View_Summary *view_location,
View_Split_Position position
)
Parameters
view_location
The view_location parameter specifies the view to split to open the new view.
position
The position parameter specifies how to split the view and where to place the new view.
Return
If this call succeeds it returns a View_Summary describing the newly created view, if it fails it +returns a null summary.
Description
4coder is built with a limit of 16 views. If 16 views are already open when this is called the call will fail.

See Also

§3.3.27: close_view

bool32 close_view(
Application_Links *app,
View_Summary *view
)
Parameters
view
The view parameter specifies which view to close.
Return
This call returns non-zero on success.
Description
If the given view is open and is not the last view, it will be closed. If the given view is the active view, the next active view in the global order of view will be made active. If the given view is the last open view -in the system, the call will fail.


§3.3.28: set_active_view

bool32 app->set_active_view(
Application_Links *app,
View_Summary *view
)
Parameters
view
The view parameter specifies which view to make active.
Return
This call returns non-zero on success.
Description
If the given view is open, it is set as the +in the system, the call will fail.


§3.3.28: set_active_view

bool32 set_active_view(
Application_Links *app,
View_Summary *view
)
Parameters
view
The view parameter specifies which view to make active.
Return
This call returns non-zero on success.
Description
If the given view is open, it is set as the active view, and takes subsequent commands and is returned -from get_active_view.

See Also

§3.3.29: view_set_setting

bool32 app->view_set_setting(
Application_Links *app,
View_Summary *view,
View_Setting_ID setting,
int32_t value
)
Parameters
view
The view parameter specifies the view on which to set a setting.
setting
The setting parameter identifies the setting that shall be changed.
value
The value parameter specifies the value to which the setting shall be changed.
Return
This call returns non-zero on success.
See Also

§3.3.30: view_set_split_proportion

bool32 app->view_set_split_proportion(
Application_Links *app,
View_Summary *view,
float t
)
Parameters
view
The view parameter specifies which view shall have it's size adjusted.
t
The t parameter specifies the proportion of the containing box that the view should occupy. t should be in [0,1].
Return
This call returns non-zero on success.

§3.3.31: view_compute_cursor

bool32 app->view_compute_cursor(
Application_Links *app,
View_Summary *view,
Buffer_Seek seek,
Full_Cursor *cursor_out
)
Parameters
view
The view parameter specifies the view on which to run the cursor computation.
seek
The seek parameter specifies the target position for the seek.
cursor_out
On success this struct is filled with the result of the seek.
Return
This call returns non-zero on success.
Description
Computes a Full_Cursor for the given seek position with no side effects.

See Also

§3.3.32: view_set_cursor

bool32 app->view_set_cursor(
Application_Links *app,
View_Summary *view,
Buffer_Seek seek,
bool32 set_preferred_x
)
Parameters
view
The view parameter specifies the view in which to set the cursor.
seek
The seek parameter specifies the target position for the seek.
set_preferred_x
If this parameter is true the preferred x is updated to match the new cursor x.
Return
This call returns non-zero on success.
Description
This call sets the the view's cursor position. set_preferred_x should usually be true +from get_active_view.

See Also

§3.3.29: view_set_setting

bool32 view_set_setting(
Application_Links *app,
View_Summary *view,
View_Setting_ID setting,
int32_t value
)
Parameters
view
The view parameter specifies the view on which to set a setting.
setting
The setting parameter identifies the setting that shall be changed.
value
The value parameter specifies the value to which the setting shall be changed.
Return
This call returns non-zero on success.
See Also

§3.3.30: view_set_split_proportion

bool32 view_set_split_proportion(
Application_Links *app,
View_Summary *view,
float t
)
Parameters
view
The view parameter specifies which view shall have it's size adjusted.
t
The t parameter specifies the proportion of the containing box that the view should occupy. t should be in [0,1].
Return
This call returns non-zero on success.

§3.3.31: view_compute_cursor

bool32 view_compute_cursor(
Application_Links *app,
View_Summary *view,
Buffer_Seek seek,
Full_Cursor *cursor_out
)
Parameters
view
The view parameter specifies the view on which to run the cursor computation.
seek
The seek parameter specifies the target position for the seek.
cursor_out
On success this struct is filled with the result of the seek.
Return
This call returns non-zero on success.
Description
Computes a Full_Cursor for the given seek position with no side effects.

See Also

§3.3.32: view_set_cursor

bool32 view_set_cursor(
Application_Links *app,
View_Summary *view,
Buffer_Seek seek,
bool32 set_preferred_x
)
Parameters
view
The view parameter specifies the view in which to set the cursor.
seek
The seek parameter specifies the target position for the seek.
set_preferred_x
If this parameter is true the preferred x is updated to match the new cursor x.
Return
This call returns non-zero on success.
Description
This call sets the the view's cursor position. set_preferred_x should usually be true unless the change in cursor position is is a vertical motion that tries to keep the -cursor in the same column or x position.

See Also

§3.3.33: view_set_scroll

bool32 app->view_set_scroll(
Application_Links *app,
View_Summary *view,
GUI_Scroll_Vars scroll
)
Description
TODO

See Also

§3.3.34: view_set_mark

bool32 app->view_set_mark(
Application_Links *app,
View_Summary *view,
Buffer_Seek seek
)
Parameters
view
The view parameter specifies the view in which to set the mark.
seek
The seek parameter specifies the target position for the seek.
Return
This call returns non-zero on success.
Description
This call sets the the view's mark position.

See Also

§3.3.35: view_set_highlight

bool32 app->view_set_highlight(
Application_Links *app,
View_Summary *view,
int32_t start,
int32_t end,
bool32 turn_on
)
Parameters
view
The view parameter specifies the view in which to set the highlight.
start
This parameter specifies the absolute position of the first character of the highlight range.
end
This parameter specifies the absolute position of the character one past the end of the highlight range.
turn_on
This parameter indicates whether the highlight is being turned on or off.
Return
This call returns non-zero on success.
Description
The highlight is mutually exclusive to the cursor. When the turn_on parameter +cursor in the same column or x position.

See Also

§3.3.33: view_set_scroll

bool32 view_set_scroll(
Application_Links *app,
View_Summary *view,
GUI_Scroll_Vars scroll
)
Description
TODO

See Also

§3.3.34: view_set_mark

bool32 view_set_mark(
Application_Links *app,
View_Summary *view,
Buffer_Seek seek
)
Parameters
view
The view parameter specifies the view in which to set the mark.
seek
The seek parameter specifies the target position for the seek.
Return
This call returns non-zero on success.
Description
This call sets the the view's mark position.

See Also

§3.3.35: view_set_highlight

bool32 view_set_highlight(
Application_Links *app,
View_Summary *view,
int32_t start,
int32_t end,
bool32 turn_on
)
Parameters
view
The view parameter specifies the view in which to set the highlight.
start
This parameter specifies the absolute position of the first character of the highlight range.
end
This parameter specifies the absolute position of the character one past the end of the highlight range.
turn_on
This parameter indicates whether the highlight is being turned on or off.
Return
This call returns non-zero on success.
Description
The highlight is mutually exclusive to the cursor. When the turn_on parameter is set to true the highlight will be shown and the cursor will be hidden. After that either setting the cursor with view_set_cursor or calling view_set_highlight -and the turn_on set to false, will switch back to showing the cursor.


§3.3.36: view_set_buffer

bool32 app->view_set_buffer(
Application_Links *app,
View_Summary *view,
Buffer_ID buffer_id,
Set_Buffer_Flag flags
)
Parameters
view
The view parameter specifies the view in which to display the buffer.
buffer_id
The buffer_id parameter specifies which buffer to show in the view.
flags
The flags parameter specifies behaviors for setting the buffer.
Return
This call returns non-zero on success.
Description
On success view_set_buffer sets the specified view's current buffer and -cancels and dialogue shown in the view and displays the file.

See Also

§3.3.37: view_post_fade

bool32 app->view_post_fade(
Application_Links *app,
View_Summary *view,
float seconds,
int32_t start,
int32_t end,
int_color color
)
Parameters
view
The view parameter specifies the view onto which the fade effect shall be posted.
seconds
This parameter specifies the number of seconds the fade effect should last.
start
This parameter specifies the absolute position of the first character of the fade range.
end
This parameter specifies the absolute position of the character one past the end of the fdae range.
color
The color parameter specifies the initial color of the text before it fades to it's natural color.
Return
This call returns non-zero on success.
See Also

§3.3.38: get_user_input

User_Input app->get_user_input(
Application_Links *app,
Input_Type_Flag get_type,
Input_Type_Flag abort_type
)
Parameters
get_type
The get_type parameter specifies the set of input types that should be returned.
abort_type
The get_type parameter specifies the set of input types that should trigger an abort signal.
Return
This call returns a User_Input that describes a user input event.
Description
This call preempts the command. The command is resumed if either a get or abort condition +and the turn_on set to false, will switch back to showing the cursor.


§3.3.36: view_set_buffer

bool32 view_set_buffer(
Application_Links *app,
View_Summary *view,
Buffer_ID buffer_id,
Set_Buffer_Flag flags
)
Parameters
view
The view parameter specifies the view in which to display the buffer.
buffer_id
The buffer_id parameter specifies which buffer to show in the view.
flags
The flags parameter specifies behaviors for setting the buffer.
Return
This call returns non-zero on success.
Description
On success view_set_buffer sets the specified view's current buffer and +cancels and dialogue shown in the view and displays the file.

See Also

§3.3.37: view_post_fade

bool32 view_post_fade(
Application_Links *app,
View_Summary *view,
float seconds,
int32_t start,
int32_t end,
int_color color
)
Parameters
view
The view parameter specifies the view onto which the fade effect shall be posted.
seconds
This parameter specifies the number of seconds the fade effect should last.
start
This parameter specifies the absolute position of the first character of the fade range.
end
This parameter specifies the absolute position of the character one past the end of the fdae range.
color
The color parameter specifies the initial color of the text before it fades to it's natural color.
Return
This call returns non-zero on success.
See Also

§3.3.38: get_user_input

User_Input get_user_input(
Application_Links *app,
Input_Type_Flag get_type,
Input_Type_Flag abort_type
)
Parameters
get_type
The get_type parameter specifies the set of input types that should be returned.
abort_type
The get_type parameter specifies the set of input types that should trigger an abort signal.
Return
This call returns a User_Input that describes a user input event.
Description
This call preempts the command. The command is resumed if either a get or abort condition is met, or if another command is executed. If either the abort condition is met or another command is executed an abort signal is returned. If an abort signal is ever returned the command should finish execution without any more calls that preempt the command. -If a get condition is met the user input is returned.

See Also

§3.3.39: get_command_input

User_Input app->get_command_input(
Application_Links *app
)
Return
This call returns the input that triggered the currently executing command.
See Also

§3.3.40: get_mouse_state

Mouse_State app->get_mouse_state(
Application_Links *app
)
Return
This call returns the current mouse state as of the beginning of the frame.
See Also

§3.3.41: start_query_bar

bool32 app->start_query_bar(
Application_Links *app,
Query_Bar *bar,
uint32_t flags
)
Parameters
bar
This parameter provides a Query_Bar that should remain in valid memory +If a get condition is met the user input is returned.

See Also

§3.3.39: get_command_input

User_Input get_command_input(
Application_Links *app
)
Return
This call returns the input that triggered the currently executing command.
See Also

§3.3.40: get_mouse_state

Mouse_State get_mouse_state(
Application_Links *app
)
Return
This call returns the current mouse state as of the beginning of the frame.
See Also

§3.3.41: start_query_bar

bool32 start_query_bar(
Application_Links *app,
Query_Bar *bar,
uint32_t flags
)
Parameters
bar
This parameter provides a Query_Bar that should remain in valid memory until end_query_bar or the end of the command. It is commonly a good idea to make this a pointer to a Query_Bar stored on the stack.
flags
This parameter is not currently used and should be 0 for now.
Return
This call returns non-zero on success.
Description
This call tells the active view to begin displaying a "Query_Bar" which is a small GUI element that can overlap a buffer or other 4coder GUI. The contents of the bar can be changed after the call to start_query_bar and the query bar shown by 4coder will reflect the change. Since the bar stops showing when the command exits the -only use for this call is in an interactive command that makes calls to get_user_input.


§3.3.42: end_query_bar

void app->end_query_bar(
Application_Links *app,
Query_Bar *bar,
uint32_t flags
)
Parameters
bar
This parameter should be a bar pointer of a currently active query bar.
flags
This parameter is not currently used and should be 0 for now.
Description
Stops showing the particular query bar specified by the bar parameter.



§3.3.44: change_theme

void app->change_theme(
Application_Links *app,
char *name,
int32_t len
)
Parameters
name
The name parameter specifies the name of the theme to begin using; it need not be null terminated.
len
The len parameter specifies the length of the name string.
Description
This call changes 4coder's color pallet to one of the built in themes.


§3.3.45: change_font

void app->change_font(
Application_Links *app,
char *name,
int32_t len,
bool32 apply_to_all_files
)
Parameters
name
The name parameter specifies the name of the font to begin using; it need not be null terminated.
len
The len parameter specifies the length of the name string.
apply_to_all_files
If this is set all open files change to this font. Usually this should be true -durring the start hook because several files already exist at that time.
Description
This call changes 4coder's default font to one of the built in fonts.


§3.3.46: buffer_set_font

void app->buffer_set_font(
Application_Links *app,
Buffer_Summary *buffer,
char *name,
int32_t len
)
Parameters
buffer
This parameter the buffer that shall have it's font changed
name
The name parameter specifies the name of the font to begin using; it need not be null terminated.
len
The len parameter specifies the length of the name string.
Description
This call sets the display font of a particular buffer.


§3.3.47: set_theme_colors

void app->set_theme_colors(
Application_Links *app,
Theme_Color *colors,
int32_t count
)
Parameters
colors
The colors pointer provides an array of color structs pairing differet style tags to color codes.
count
The count parameter specifies the number of Theme_Color structs in the colors array.
Description
For each struct in the array, the slot in the main color pallet specified by the +only use for this call is in an interactive command that makes calls to get_user_input.


§3.3.42: end_query_bar

void end_query_bar(
Application_Links *app,
Query_Bar *bar,
uint32_t flags
)
Parameters
bar
This parameter should be a bar pointer of a currently active query bar.
flags
This parameter is not currently used and should be 0 for now.
Description
Stops showing the particular query bar specified by the bar parameter.



§3.3.44: change_theme

void change_theme(
Application_Links *app,
char *name,
int32_t len
)
Parameters
name
The name parameter specifies the name of the theme to begin using; it need not be null terminated.
len
The len parameter specifies the length of the name string.
Description
This call changes 4coder's color pallet to one of the built in themes.


§3.3.45: change_font

void change_font(
Application_Links *app,
char *name,
int32_t len,
bool32 apply_to_all_files
)
Parameters
name
The name parameter specifies the name of the font to begin using; it need not be null terminated.
len
The len parameter specifies the length of the name string.
apply_to_all_files
If this is set all open files change to this font. Usually this should be true +durring the start hook because several files already exist at that time.
Description
This call changes 4coder's default font to one of the built in fonts.


§3.3.46: buffer_set_font

void buffer_set_font(
Application_Links *app,
Buffer_Summary *buffer,
char *name,
int32_t len
)
Parameters
buffer
This parameter the buffer that shall have it's font changed
name
The name parameter specifies the name of the font to begin using; it need not be null terminated.
len
The len parameter specifies the length of the name string.
Description
This call sets the display font of a particular buffer.


§3.3.47: set_theme_colors

void set_theme_colors(
Application_Links *app,
Theme_Color *colors,
int32_t count
)
Parameters
colors
The colors pointer provides an array of color structs pairing differet style tags to color codes.
count
The count parameter specifies the number of Theme_Color structs in the colors array.
Description
For each struct in the array, the slot in the main color pallet specified by the struct's tag is set to the color code in the struct. If the tag value is invalid -no change is made to the color pallet.


§3.3.48: get_theme_colors

void app->get_theme_colors(
Application_Links *app,
Theme_Color *colors,
int32_t count
)
Parameters
colors
an array of color structs listing style tags to get color values for
count
the number of color structs in the colors array
Description
For each struct in the array, the color field of the struct is filled with the +no change is made to the color pallet.


§3.3.48: get_theme_colors

void get_theme_colors(
Application_Links *app,
Theme_Color *colors,
int32_t count
)
Parameters
colors
an array of color structs listing style tags to get color values for
count
the number of color structs in the colors array
Description
For each struct in the array, the color field of the struct is filled with the color from the slot in the main color pallet specified by the tag. If the tag -value is invalid the color is filled with black.


§3.3.49: directory_get_hot

int32_t app->directory_get_hot(
Application_Links *app,
char *out,
int32_t capacity
)
Parameters
out
This parameter provides a character buffer that receives the 4coder 'hot directory'.
capacity
This parameter specifies the maximum size to be output to the out buffer.
Return
This call returns the size of the string written into the buffer.
Description
4coder has a concept of a 'hot directory' which is the directory most recently +value is invalid the color is filled with black.


§3.3.49: directory_get_hot

int32_t directory_get_hot(
Application_Links *app,
char *out,
int32_t capacity
)
Parameters
out
This parameter provides a character buffer that receives the 4coder 'hot directory'.
capacity
This parameter specifies the maximum size to be output to the out buffer.
Return
This call returns the size of the string written into the buffer.
Description
4coder has a concept of a 'hot directory' which is the directory most recently accessed in the GUI. Whenever the GUI is opened it shows the hot directory.

In the future this will be deprecated and eliminated in favor of more flexible -directories controlled on the custom side.


§3.3.50: get_file_list

File_List app->get_file_list(
Application_Links *app,
char *dir,
int32_t len
)
Parameters
dir
This parameter specifies the directory whose files will be enumerated in the returned list; it need not be null terminated.
len
This parameter the length of the dir string.
Return
This call returns a File_List struct containing pointers to the names of the files in +directories controlled on the custom side.


§3.3.50: get_file_list

File_List get_file_list(
Application_Links *app,
char *dir,
int32_t len
)
Parameters
dir
This parameter specifies the directory whose files will be enumerated in the returned list; it need not be null terminated.
len
This parameter the length of the dir string.
Return
This call returns a File_List struct containing pointers to the names of the files in the specified directory. The File_List returned should be passed to free_file_list -when it is no longer in use.

§3.3.51: free_file_list

void app->free_file_list(
Application_Links *app,
File_List list
)
Parameters
list
This parameter provides the file list to be freed.
Description
After this call the file list passed in should not be read or written to.


§3.3.52: memory_allocate

void* app->memory_allocate(
Application_Links *app,
int32_t size
)
Parameters
size
The size in bytes of the block that should be returned.
Description
This calls to a low level OS allocator which means it is best used +when it is no longer in use.

§3.3.51: free_file_list

void free_file_list(
Application_Links *app,
File_List list
)
Parameters
list
This parameter provides the file list to be freed.
Description
After this call the file list passed in should not be read or written to.


§3.3.52: memory_allocate

void* memory_allocate(
Application_Links *app,
int32_t size
)
Parameters
size
The size in bytes of the block that should be returned.
Description
This calls to a low level OS allocator which means it is best used for infrequent, large allocations. The size of the block must be remembered -if it will be freed or if it's mem protection status will be changed.

See Also

§3.3.53: memory_set_protection

bool32 app->memory_set_protection(
Application_Links *app,
void *ptr,
int32_t size,
Memory_Protect_Flags flags
)
Parameters
ptr
The base of the block on which to set memory protection flags.
size
The size that was originally used to allocate this block.
flags
The new memory protection flags.
Description
This call sets the memory protection flags of a block of memory that was previously -allocate by memory_allocate.

See Also

§3.3.54: memory_free

void app->memory_free(
Application_Links *app,
void *ptr,
int32_t size
)
Parameters
mem
The base of a block to free.
size
The size that was originally used to allocate this block.
Description
This call frees a block of memory that was previously allocated by -memory_allocate.

See Also

§3.3.55: file_exists

bool32 app->file_exists(
Application_Links *app,
char *filename,
int32_t len
)
Parameters
filename
This parameter specifies the full path to a file; it need not be null terminated.
len
This parameter specifies the length of the filename string.
Return
This call returns non-zero if and only if the file exists.

§3.3.56: directory_cd

bool32 app->directory_cd(
Application_Links *app,
char *dir,
int32_t *len,
int32_t capacity,
char *rel_path,
int32_t rel_len
)
Parameters
dir
This parameter provides a character buffer that stores a directory; it need not be null terminated.
len
This parameter specifies the length of the dir string.
capacity
This parameter specifies the maximum size of the dir string.
rel_path
This parameter specifies the path to change to, may include '.' or '..'; it need not be null terminated.
rel_len
This parameter specifies the length of the rel_path string.
Return
This call returns non-zero if the call succeeds.
Description
This call succeeds if the new directory exists and the it fits inside the +if it will be freed or if it's mem protection status will be changed.

See Also

§3.3.53: memory_set_protection

bool32 memory_set_protection(
Application_Links *app,
void *ptr,
int32_t size,
Memory_Protect_Flags flags
)
Parameters
ptr
The base of the block on which to set memory protection flags.
size
The size that was originally used to allocate this block.
flags
The new memory protection flags.
Description
This call sets the memory protection flags of a block of memory that was previously +allocate by memory_allocate.

See Also

§3.3.54: memory_free

void memory_free(
Application_Links *app,
void *ptr,
int32_t size
)
Parameters
mem
The base of a block to free.
size
The size that was originally used to allocate this block.
Description
This call frees a block of memory that was previously allocated by +memory_allocate.

See Also

§3.3.55: file_exists

bool32 file_exists(
Application_Links *app,
char *filename,
int32_t len
)
Parameters
filename
This parameter specifies the full path to a file; it need not be null terminated.
len
This parameter specifies the length of the filename string.
Return
This call returns non-zero if and only if the file exists.

§3.3.56: directory_cd

bool32 directory_cd(
Application_Links *app,
char *dir,
int32_t *len,
int32_t capacity,
char *rel_path,
int32_t rel_len
)
Parameters
dir
This parameter provides a character buffer that stores a directory; it need not be null terminated.
len
This parameter specifies the length of the dir string.
capacity
This parameter specifies the maximum size of the dir string.
rel_path
This parameter specifies the path to change to, may include '.' or '..'; it need not be null terminated.
rel_len
This parameter specifies the length of the rel_path string.
Return
This call returns non-zero if the call succeeds.
Description
This call succeeds if the new directory exists and the it fits inside the dir buffer. If the call succeeds the dir buffer is filled with the new directory and len is overwritten with the length of the new string in the buffer.

For instance if dir contains "C:/Users/MySelf" and rel is "Documents" the buffer will contain "C:/Users/MySelf/Documents" and len will contain the length of that string. This call can also be used with rel set to ".." to traverse to parent -folders.


§3.3.57: get_4ed_path

bool32 app->get_4ed_path(
Application_Links *app,
char *out,
int32_t capacity
)
Parameters
out
This parameter provides a character buffer that receives the path to the 4ed executable file.
capacity
This parameter specifies the maximum capacity of the out buffer.
Return
This call returns non-zero on success.

§3.3.58: show_mouse_cursor

void app->show_mouse_cursor(
Application_Links *app,
Mouse_Cursor_Show_Type show
)
Parameters
show
This parameter specifies the new state of the mouse cursor.
See Also

§3.3.59: toggle_fullscreen

void app->toggle_fullscreen(
Application_Links *app
)
Description
This call tells 4coder to switch into or out of full screen mode. +folders.


§3.3.57: get_4ed_path

bool32 get_4ed_path(
Application_Links *app,
char *out,
int32_t capacity
)
Parameters
out
This parameter provides a character buffer that receives the path to the 4ed executable file.
capacity
This parameter specifies the maximum capacity of the out buffer.
Return
This call returns non-zero on success.

§3.3.58: show_mouse_cursor

void show_mouse_cursor(
Application_Links *app,
Mouse_Cursor_Show_Type show
)
Parameters
show
This parameter specifies the new state of the mouse cursor.
See Also

§3.3.59: toggle_fullscreen

void toggle_fullscreen(
Application_Links *app
)
Description
This call tells 4coder to switch into or out of full screen mode. The changes of full screen mode do not take effect until the end of the current frame. On Windows this call will not work unless 4coder was started in "stream mode". -Stream mode can be enabled with -S or -F flags on the command line to 4ed.


§3.3.60: is_fullscreen

bool32 app->is_fullscreen(
Application_Links *app
)
Description
This call returns true if the 4coder is in full screen mode. This call +Stream mode can be enabled with -S or -F flags on the command line to 4ed.


§3.3.60: is_fullscreen

bool32 is_fullscreen(
Application_Links *app
)
Description
This call returns true if the 4coder is in full screen mode. This call takes toggles that have already occured this frame into account. So it may return true even though the frame has not ended and actually put 4coder into full screen. If it returns true though, 4coder will definitely be full screen by the beginning of the next -frame if the state is not changed.


§3.3.61: send_exit_signal

void app->send_exit_signal(
Application_Links *app
)
Description
This call sends a signal to 4coder to attempt to exit. If there are unsaved +frame if the state is not changed.


§3.3.61: send_exit_signal

void send_exit_signal(
Application_Links *app
)
Description
This call sends a signal to 4coder to attempt to exit. If there are unsaved files this triggers a dialogue ensuring you're okay with closing.


§3.4 Type Descriptions

§3.4.1: bool32

typedef int32_t bool32;
Description
bool32 is an alias name to signal that an integer parameter or field is for true/false vales.


§3.4.2: int_color

typedef uint32_t int_color;
Description
int_color is an alias name to signal that an integer parameter or field is for a color value, colors are specified as 24 bit integers in 3 channels: 0xRRGGBB.


§3.4.3: Key_Code

typedef unsigned char Key_Code;
Description
Key_Code is the alias for key codes including raw codes and codes translated @@ -292,7 +292,7 @@ It should point at the String in the first element of the array.
count
The count parameter specifies the number of elements in the str_set array.
str
The str parameter specifies the string to match against the str_set.
match_index
If this call succeeds match_index is filled with the index into str_set where the match occurred.
Description
This call tries to see if str matches any of the strings in str_set. If there is a match the call succeeds and returns non-zero. The matching rule is equivalent to the matching rule for match.

See Also

§4.3.116: string_set_match

fstr_bool string_set_match(
String *str_set,
int32_t count,
String str,
int32_t *match_index
)
Parameters
str_set
The str_set parameter is an array of String structs specifying matchable strings.
count
The count parameter specifies the number of String structs in the str_set array.
str
The str parameter specifies the string to match against the str_set.
match_index
If this call succeeds match_index is filled with the index into str_set where the match occurred.
Description
This call tries to see if str matches any of the strings in str_set. If there is a match the call succeeds and returns non-zero. The matching rule is equivalent to the matching rule for match.

See Also

-

§5 Lexer Library

§5.1 Lexer Intro

The 4cpp lexer system provides a polished, fast, flexible system that takes in C/C++ and outputs a tokenization of the text data. There are two API levels. One level is setup to let you easily get a tokenization of the file. This level manages memory for you with malloc to make it as fast as possible to start getting your tokens. The second level enables deep integration by allowing control over allocation, data chunking, and output rate control.

To use the quick setup API you simply include 4cpp_lexer.h and read the documentation at cpp_lex_file.

To use the the fancier API include 4cpp_lexer.h and read the documentation at cpp_lex_step. If you want to be absolutely sure you are not including malloc into your program you can define FCPP_FORBID_MALLOC before the include and the "step" API will continue to work.

There are a few more features in 4cpp that are not documented yet. You are free to try to use these, but I am not totally sure they are ready yet, and when they are they will be documented.

§5.2 Lexer Function List

§5.3 Lexer Types List

§5.4 Lexer Function Descriptions

§5.4.1: cpp_get_token

Cpp_Get_Token_Result cpp_get_token(
Cpp_Token_Array *token_array_in,
int32_t pos
)
Parameters
token_array
The array of tokens from which to get a token.
pos
The position, measured in bytes, to get the token for.
Return
A Cpp_Get_Token_Result struct is returned containing the index +

§5 Lexer Library

§5.1 Lexer Intro

The 4cpp lexer system provides a polished, fast, flexible system that takes in C/C++ and outputs a tokenization of the text data. There are two API levels. One level is setup to let you easily get a tokenization of the file. This level manages memory for you with malloc to make it as fast as possible to start getting your tokens. The second level enables deep integration by allowing control over allocation, data chunking, and output rate control.

To use the quick setup API you simply include 4cpp_lexer.h and read the documentation at cpp_lex_file.

To use the the fancier API include 4cpp_lexer.h and read the documentation at cpp_lex_step. If you want to be absolutely sure you are not including malloc into your program you can define FCPP_FORBID_MALLOC before the include and the "step" API will continue to work.

There are a few more features in 4cpp that are not documented yet. You are free to try to use these, but I am not totally sure they are ready yet, and when they are they will be documented.

§5.2 Lexer Function List

§5.3 Lexer Types List

§5.4 Lexer Function Descriptions

§5.4.1: cpp_get_token

Cpp_Get_Token_Result cpp_get_token(
Cpp_Token_Array *token_array_in,
int32_t pos
)
Parameters
token_array
The array of tokens from which to get a token.
pos
The position, measured in bytes, to get the token for.
Return
A Cpp_Get_Token_Result struct is returned containing the index of a token and a flag indicating whether the pos is contained in the token or in whitespace after the token.
Description
This call performs a binary search over all of the tokens looking for the token that contains the specified position. If the position @@ -339,11 +339,11 @@ to free the temp buffer that was originally used to make the lex state. This cal a new temp buffer when you are ready to resume lexing.

However the new buffer needs to have the same contents the old buffer had. To ensure this you have to use cpp_lex_data_temp_size and cpp_lex_data_temp_read to get the relevant contents of the temp buffer -before you free it.

See Also

§5.4.7: cpp_make_token_array

Cpp_Token_Array cpp_make_token_array(
int32_t starting_max
)
Parameters
starting_max
The number of tokens to initialize the array with.
Return
An empty Cpp_Token_Array with memory malloc'd for storing tokens.
Description
This call allocates a Cpp_Token_Array with malloc for use in other +before you free it.

See Also

§5.4.7: cpp_relex_init

Cpp_Relex_Data cpp_relex_init(
Cpp_Token_Array *array,
int32_t start_pos,
int32_t end_pos,
int32_t character_shift_amount,
char *spare
)
No documentation generated for this function.

§5.4.8: cpp_relex_step

Cpp_Lex_Result cpp_relex_step(
Cpp_Relex_Data *S_ptr,
char *chunk,
int32_t chunk_size,
int32_t full_size,
Cpp_Token_Array *array,
Cpp_Token_Array *relex_array
)
No documentation generated for this function.

§5.4.9: cpp_relex_get_new_count

int32_t cpp_relex_get_new_count(
Cpp_Relex_Data *S_ptr,
int32_t current_count,
Cpp_Token_Array *relex_array
)
No documentation generated for this function.

§5.4.10: cpp_relex_complete

void cpp_relex_complete(
Cpp_Relex_Data *S_ptr,
Cpp_Token_Array *array,
Cpp_Token_Array *relex_array
)
No documentation generated for this function.

§5.4.11: cpp_relex_abort

void cpp_relex_abort(
Cpp_Relex_Data *S_ptr,
Cpp_Token_Array *array
)
No documentation generated for this function.

§5.4.12: cpp_make_token_array

Cpp_Token_Array cpp_make_token_array(
int32_t starting_max
)
Parameters
starting_max
The number of tokens to initialize the array with.
Return
An empty Cpp_Token_Array with memory malloc'd for storing tokens.
Description
This call allocates a Cpp_Token_Array with malloc for use in other convenience functions. Stacks that are not allocated this way should not be -used in the convenience functions.


§5.4.8: cpp_free_token_array

void cpp_free_token_array(
Cpp_Token_Array token_array
)
Parameters
token_array
An array previously allocated by cpp_make_token_array
Description
This call frees a Cpp_Token_Array.

See Also

§5.4.9: cpp_resize_token_array

void cpp_resize_token_array(
Cpp_Token_Array *token_array,
int32_t new_max
)
Parameters
token_array
An array previously allocated by cpp_make_token_array.
new_max
The new maximum size the array should support. If this is not greater +used in the convenience functions.


§5.4.13: cpp_free_token_array

void cpp_free_token_array(
Cpp_Token_Array token_array
)
Parameters
token_array
An array previously allocated by cpp_make_token_array
Description
This call frees a Cpp_Token_Array.

See Also

§5.4.14: cpp_resize_token_array

void cpp_resize_token_array(
Cpp_Token_Array *token_array,
int32_t new_max
)
Parameters
token_array
An array previously allocated by cpp_make_token_array.
new_max
The new maximum size the array should support. If this is not greater than the current size of the array the operation is ignored.
Description
This call allocates a new memory chunk and moves the existing tokens in the array -over to the new chunk.

See Also

§5.4.10: cpp_lex_file

void cpp_lex_file(
char *data,
int32_t size,
Cpp_Token_Array *token_array_out
)
Parameters
data
The file data to be lexed in a single contiguous block.
size
The number of bytes in data.
token_array_out
The token array where the output tokens will be pushed. +over to the new chunk.

See Also

§5.4.15: cpp_lex_file

void cpp_lex_file(
char *data,
int32_t size,
Cpp_Token_Array *token_array_out
)
Parameters
data
The file data to be lexed in a single contiguous block.
size
The number of bytes in data.
token_array_out
The token array where the output tokens will be pushed. This token array must be previously allocated with cpp_make_token_array
Description
Lexes an entire file and manages the interaction with the lexer system so that it is quick and convenient to lex files.



Cpp_Token_Array lex_file(char *file_name){
    File_Data file = read_whole_file(file_name);
    
    // This array will be automatically grown if it runs
    // out of memory.
    Cpp_Token_Array array = cpp_make_token_array(100);
    
    cpp_lex_file(file.data, file.size, &array);
    
    return(array);
}
See Also

§5.5 Lexer Type Descriptions

§5.5.1: Cpp_Token_Type

enum Cpp_Token_Type;
Description
A Cpp_Token_Type classifies a token to make parsing easier. Some types are not @@ -365,9 +365,9 @@ point to a block of memory with a size equal to max_count*sizeof(Cpp_Token) and the count should be initialized to zero.

Fields
tokens
The tokens field points to the memory used to store the array of tokens.

count
The count field counts how many tokens in the array are currently used.

max_count
The max_count field specifies the maximum size the count field may grow to before the tokens array is out of space.


§5.5.5: Cpp_Get_Token_Result

struct Cpp_Get_Token_Result {
int32_t token_index;
int32_t in_whitespace;
};
Description
Cpp_Get_Token_Result is the return result of the cpp_get_token call.

Fields
token_index
The token_index field indicates which token answers the query. To get the token from the source array

array.tokens[result.token_index]
in_whitespace
The in_whitespace field is true when the query position was actually in whitespace - after the result token.

See Also

§5.5.6: Cpp_Lex_Data

struct Cpp_Lex_Data { /* non-public internals */ } ;
Description
Cpp_Lex_Data represents the state of the lexer so that the system may be resumable + after the result token.

See Also

§5.5.6: Cpp_Relex_Range

struct Cpp_Relex_Range { /* non-public internals */ } ;

§5.5.7: Cpp_Lex_Data

struct Cpp_Lex_Data { /* non-public internals */ } ;
Description
Cpp_Lex_Data represents the state of the lexer so that the system may be resumable and the user can manage the lexer state and decide when to resume lexing with it. To create a new lexer state that has not begun doing any lexing work call cpp_lex_data_init.

-The internals of the lex state should not be treated as a part of the public API.

See Also

§5.5.7: Cpp_Lex_Result

enum Cpp_Lex_Result;
Description
Cpp_Lex_Result is returned from the lexing engine to indicate why it stopped lexing.

Values
LexResult_Finished = 0
This indicates that the system got to the end of the file and will not accept more input.

LexResult_NeedChunk = 1
This indicates that the system got to the end of an input chunk and is ready to receive the +The internals of the lex state should not be treated as a part of the public API.

See Also

§5.5.8: Cpp_Lex_Result

enum Cpp_Lex_Result;
Description
Cpp_Lex_Result is returned from the lexing engine to indicate why it stopped lexing.

Values
LexResult_Finished = 0
This indicates that the system got to the end of the file and will not accept more input.

LexResult_NeedChunk = 1
This indicates that the system got to the end of an input chunk and is ready to receive the next input chunk.

LexResult_NeedTokenMemory = 2
This indicates that the output array ran out of space to store tokens and needs to be - replaced or expanded before continuing.

LexResult_HitTokenLimit = 3
This indicates that the maximum number of output tokens as specified by the user was hit.


\ No newline at end of file + replaced or expanded before continuing.

LexResult_HitTokenLimit = 3
This indicates that the maximum number of output tokens as specified by the user was hit.


§5.5.9: Cpp_Relex_Data

struct Cpp_Relex_Data { /* non-public internals */ } ;

\ No newline at end of file diff --git a/4cpp_lexer.h b/4cpp_lexer.h index 1ce4134d..3e102fca 100644 --- a/4cpp_lexer.h +++ b/4cpp_lexer.h @@ -266,6 +266,7 @@ cpp_pp_directive_to_state(Cpp_Token_Type type){ return(result); } +// duff-routine defines #define DrCase(PC) case PC: goto resumespot_##PC #define DrYield(PC, n) { \ @@ -1094,18 +1095,43 @@ DOC_SEE(cpp_lex_data_temp_read) lex_data->tb = new_buffer; } -// TODO(allen): Get the relex system ready to work in chunks. +FCPP_INTERNAL char +cpp_token_get_pp_state(uint16_t bitfield){ + return (char)(bitfield); +} + +FCPP_INTERNAL void +cpp_shift_token_starts(Cpp_Token_Array *array, int32_t from_token_i, int32_t shift_amount){ + Cpp_Token *token = array->tokens + from_token_i; + int32_t count = array->count, i = 0; + for (i = from_token_i; i < count; ++i, ++token){ + token->start += shift_amount; + } +} + +FCPP_INTERNAL Cpp_Token +cpp_index_array(Cpp_Token_Array *array, int32_t file_size, int32_t index){ + Cpp_Token result; + if (index < array->count){ + result = array->tokens[index]; + } + else{ + result.start = file_size; + result.size = 0; + result.type = CPP_TOKEN_EOF; + result.flags = 0; + result.state_flags = 0; + } + return(result); +} + +#if 0 FCPP_INTERNAL Cpp_Relex_State -cpp_relex_nonalloc_start(char *data, int32_t size, Cpp_Token_Array *array, - int32_t start, int32_t end, int32_t amount, int32_t tolerance){ +cpp_relex_nonalloc_start(Cpp_Token_Array *array, int32_t start, int32_t end, int32_t tolerance){ Cpp_Relex_State state; - state.data = data; - state.size = size; state.array = array; state.start = start; state.end = end; - state.amount = amount; - state.tolerance = tolerance; Cpp_Get_Token_Result result = cpp_get_token(array, start); @@ -1133,70 +1159,222 @@ cpp_relex_nonalloc_start(char *data, int32_t size, Cpp_Token_Array *array, return(state); } +#endif -FCPP_INTERNAL char -cpp_token_get_pp_state(uint16_t bitfield){ - return (char)(bitfield); +FCPP_INTERNAL Cpp_Relex_Range +cpp_get_relex_range(Cpp_Token_Array *array, int32_t start_pos, int32_t end_pos){ + Cpp_Relex_Range range = {0}; + Cpp_Get_Token_Result get_result = {0}; + + get_result = cpp_get_token(array, start_pos); + range.start_token_index = get_result.token_index-1; + if (range.start_token_index < 0){ + range.start_token_index = 0; + } + + get_result = cpp_get_token(array, end_pos); + range.end_token_index = get_result.token_index; + if (end_pos > array->tokens[range.end_token_index].start){ + ++range.end_token_index; + } + if (range.end_token_index < 0){ + range.end_token_index = 0; + } + + return(range); } -// TODO(allen): Eliminate this once we actually store the EOF token -// in the token stack. -FCPP_INTERNAL Cpp_Token -cpp_index_array(Cpp_Token_Array *array, int32_t file_size, int32_t index){ - Cpp_Token result; - if (index < array->count){ - result = array->tokens[index]; +FCPP_LINK Cpp_Relex_Data +cpp_relex_init(Cpp_Token_Array *array, int32_t start_pos, int32_t end_pos, int32_t character_shift_amount, char *spare){ + Cpp_Relex_Data state = {0}; + + Cpp_Relex_Range range = cpp_get_relex_range(array, start_pos, end_pos); + state.start_token_index = range.start_token_index; + state.end_token_index = range.end_token_index; + state.original_end_token_index = range.end_token_index; + + state.relex_start_position = array->tokens[state.start_token_index].start; + if (start_pos < state.relex_start_position){ + state.relex_start_position = start_pos; } - else{ - result.start = file_size; - result.size = 0; - result.type = CPP_TOKEN_EOF; - result.flags = 0; - result.state_flags = 0; + + state.character_shift_amount = character_shift_amount; + + state.lex = cpp_lex_data_init(spare); + state.lex.pp_state = cpp_token_get_pp_state(array->tokens[state.start_token_index].state_flags); + state.lex.pos = state.relex_start_position; + + return(state); +} + +// duff-routine defines +#define DrCase(PC) case PC: goto resumespot_##PC + +#define DrYield(PC, n) { \ + S_ptr->result_state = n; \ + *S_ptr = S; S_ptr->__pc__ = PC; return(n); resumespot_##PC:; } + +#define DrReturn(n) { \ + S_ptr->result_state = n; \ + *S_ptr = S; S_ptr->__pc__ = -1; return(n); } + +FCPP_LINK Cpp_Lex_Result +cpp_relex_step(Cpp_Relex_Data *S_ptr, char *chunk, int32_t chunk_size, int32_t full_size, + Cpp_Token_Array *array, Cpp_Token_Array *relex_array){ + + Cpp_Relex_Data S = *S_ptr; + + switch (S.__pc__){ + DrCase(1); + DrCase(2); } + + cpp_shift_token_starts(array, S.end_token_index, S.character_shift_amount); + S.end_token = cpp_index_array(array, full_size, S.end_token_index); + + if (S.relex_start_position < full_size){ + // TODO(allen): This can be better I suspect. + for (;;){ + Cpp_Lex_Result step_result = + cpp_lex_nonalloc_no_null_out_limit(&S.lex, chunk, chunk_size, full_size, + relex_array, 1); + + switch (step_result){ + case LexResult_HitTokenLimit: + { + Cpp_Token token = relex_array->tokens[relex_array->count-1]; + if (token.type == S.end_token.type && + token.start == S.end_token.start && + token.size == S.end_token.size && + token.flags == S.end_token.flags && + token.state_flags == S.end_token.state_flags){ + --relex_array->count; + goto double_break; + } + + while (S.lex.pos > S.end_token.start && S.end_token_index < array->count){ + ++S.end_token_index; + S.end_token = cpp_index_array(array, full_size, S.end_token_index); + } + } + break; + + case LexResult_NeedChunk: DrYield(1, LexResult_NeedChunk); break; + + case LexResult_NeedTokenMemory: DrYield(2, LexResult_NeedTokenMemory); break; + + case LexResult_Finished: goto double_break; + } + } + } + double_break:; + + DrReturn(LexResult_Finished); +} + +#undef DrYield +#undef DrReturn +#undef DrCase + +FCPP_LINK int32_t +cpp_relex_get_new_count(Cpp_Relex_Data *S_ptr, int32_t current_count, Cpp_Token_Array *relex_array){ + int32_t result = -1; + + if (S_ptr->result_state == LexResult_Finished){ + int32_t delete_amount = S_ptr->end_token_index - S_ptr->start_token_index; + int32_t shift_amount = relex_array->count - delete_amount; + result = current_count + shift_amount; + } + return(result); } +#if !defined(FCPP_FORBID_MEMCPY) +#include +#endif + FCPP_INTERNAL void -cpp_shift_token_starts(Cpp_Token_Array *array, int32_t from_token_i, int32_t shift_amount){ - Cpp_Token *token = array->tokens + from_token_i; - int32_t count = array->count, i = 0; - - for (i = from_token_i; i < count; ++i, ++token){ - token->start += shift_amount; +cpp__block_move(void *dst, void *src, int32_t size){ +#if !defined(FCPP_FORBID_MEMCPY) + memmove(dst, src, size); +#else + // TODO(allen): find a way to write a fast one of these. + uint8_t *d = (uint8_t*)dst, *s = (uint8_t*)src; + if (d < s || d >= s + size){ + for (; size > 0; --size){ + *(d++) = *(s++); + } } + else{ + d += size - 1; + s += size - 1; + for (; size > 0; --size){ + *(d--) = *(s--); + } + } +#endif } -// TODO(allen): This relex system is a little bit broken. It doesn't allow for the -// data chunks and it doesn't actually set up the state mid-data stream properly. -FCPP_INTERNAL int32_t -cpp_relex_nonalloc_main(Cpp_Relex_State *state, +FCPP_LINK void +cpp_relex_complete(Cpp_Relex_Data *S_ptr, Cpp_Token_Array *array, Cpp_Token_Array *relex_array){ + int32_t delete_amount = S_ptr->end_token_index - S_ptr->start_token_index; + int32_t shift_amount = relex_array->count - delete_amount; + + if (shift_amount != 0){ + int32_t shift_size = array->count - S_ptr->end_token_index; + if (shift_size > 0){ + Cpp_Token *old_base = array->tokens + S_ptr->end_token_index; + cpp__block_move(old_base + shift_amount, old_base, sizeof(Cpp_Token)*shift_size); + } + array->count += shift_amount; + } + + cpp__block_move(array->tokens + S_ptr->start_token_index, relex_array->tokens, + sizeof(Cpp_Token)*relex_array->count); +} + +FCPP_LINK void +cpp_relex_abort(Cpp_Relex_Data *S_ptr, Cpp_Token_Array *array){ + cpp_shift_token_starts(array, S_ptr->original_end_token_index, -S_ptr->character_shift_amount); +} + +#if 0 +// TODO(allen): rename shift_amount to character_shift_amount +FCPP_INTERNAL Cpp_Lex_Result +cpp_relex_nonalloc_main(Cpp_Relex_Data *S_ptr, + + Cpp_Relex_Range range, int32_t shift_amount, + + char *chunk, int32_t chunk_size, int32_t size, + + Cpp_Token_Array *array, + Cpp_Token_Array *relex_array, - int32_t *relex_end, + int32_t *relex_end_out, + char *spare){ - Cpp_Token_Array *array = state->array; - Cpp_Token *tokens = array->tokens; - cpp_shift_token_starts(array, state->end_token_i, state->amount); - - int32_t relex_end_i = state->end_token_i; - Cpp_Token match_token = cpp_index_array(array, state->size, relex_end_i); + cpp_shift_token_starts(array, range.end_token_index, shift_amount); + Cpp_Token match_token = cpp_index_array(array, size, range.end_token_index); Cpp_Token end_token = match_token; - int32_t went_too_far = false; - if (state->relex_start < state->size){ + Cpp_Relex_State result = LexResult_Finished; + + Cpp_Token *tokens = array->tokens; + int32_t relex_end_index = range.end_token_index; + + if (state->relex_start < size){ Cpp_Lex_Data lex = cpp_lex_data_init(spare); lex.pp_state = cpp_token_get_pp_state(tokens[state->start_token_i].state_flags); lex.pos = state->relex_start; // TODO(allen): This can be better I suspect. for (;;){ - int32_t result = - cpp_lex_nonalloc_no_null_out_limit(&lex, state->data, - state->size, state->size, + int32_t step_result = + cpp_lex_nonalloc_no_null_out_limit(&lex, data, size, size, relex_array, 1); - switch (result){ + switch (step_result){ case LexResult_HitTokenLimit: { Cpp_Token token = relex_array->tokens[relex_array->count-1]; @@ -1210,7 +1388,7 @@ cpp_relex_nonalloc_main(Cpp_Relex_State *state, while (lex.pos > end_token.start && relex_end_i < array->count){ ++relex_end_i; - end_token = cpp_index_array(array, state->size, relex_end_i); + end_token = cpp_index_array(array, size, relex_end_i); } } break; @@ -1218,7 +1396,7 @@ cpp_relex_nonalloc_main(Cpp_Relex_State *state, case LexResult_NeedChunk: Assert(!"Invalid path"); break; case LexResult_NeedTokenMemory: - went_too_far = true; + result = LexResult_NeedTokenMemory; goto double_break; case LexResult_Finished: @@ -1228,16 +1406,23 @@ cpp_relex_nonalloc_main(Cpp_Relex_State *state, double_break:; } - if (!went_too_far){ - *relex_end = relex_end_i; - } - else{ - cpp_shift_token_starts(array, state->end_token_i, -state->amount); + switch (result){ + case LexResult_Finished: + { + *relex_end_out = relex_end_i; + }break; + + case LexResult_NeedTokenMemory: + { + cpp_shift_token_starts(array, state->end_token_i, -shift_amount); + }break; + + default: Assert(!"Invalid path"); } - return(went_too_far); + return(result); } - +#endif #if !defined(FCPP_FORBID_MALLOC) diff --git a/4cpp_lexer_types.h b/4cpp_lexer_types.h index fae2b8b4..65927458 100644 --- a/4cpp_lexer_types.h +++ b/4cpp_lexer_types.h @@ -305,18 +305,21 @@ struct Cpp_Get_Token_Result{ int32_t in_whitespace; }; +#if 0 struct_internal Cpp_Relex_State{ - char *data; - int32_t size; - Cpp_Token_Array *array; - int32_t start, end, amount; + int32_t start, end; int32_t start_token_i; int32_t end_token_i; int32_t relex_start; - int32_t tolerance; int32_t space_request; }; +#endif + +struct Cpp_Relex_Range{ + int32_t start_token_index; + int32_t end_token_index; +}; struct_internal Cpp_Lex_FSM{ uint8_t state; @@ -370,6 +373,23 @@ ENUM(int32_t, Cpp_Lex_Result){ LexResult_HitTokenLimit = 3, }; +struct Cpp_Relex_Data{ + Cpp_Lex_Data lex; + + Cpp_Token end_token; + + int32_t relex_start_position; + int32_t start_token_index; + int32_t end_token_index; + int32_t original_end_token_index; + + int32_t character_shift_amount; + + Cpp_Lex_Result result_state; + + int32_t __pc__; +}; + ENUM_INTERNAL(uint16_t, Cpp_Preprocessor_State){ CPP_LEX_PP_DEFAULT, CPP_LEX_PP_IDENTIFIER, diff --git a/4ed.cpp b/4ed.cpp index f8f8fce2..50ae88ee 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -2553,7 +2553,7 @@ App_Step_Sig(app_step){ "-mouse release events in customization system\n" "\n" "New in alpha 4.0.10:\n" - "- list all locations of a string across all open buffers\n" + "- list all locations of a string across all open buffers\n" "-Build now finds build.sh and Makefile on Linux\n" "- goes to the next error if the *compilation* buffer is open\n" "- goes to the previous error\n" diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index ab0549a7..10b49062 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -1248,7 +1248,7 @@ file_first_lex_parallel(System_Functions *system, internal b32 file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *file, - i32 start_i, i32 end_i, i32 amount){ + i32 start_i, i32 end_i, i32 shift_amount){ General_Memory *general = &mem->general; Partition *part = &mem->part; @@ -1260,27 +1260,61 @@ file_relex_parallel(System_Functions *system, b32 result = true; b32 inline_lex = !file->state.still_lexing; if (inline_lex){ - char *data = file->state.buffer.data; - i32 size = file->state.buffer.size; + i32 extra_tolerance = 100; Cpp_Token_Array *array = &file->state.token_array; + Cpp_Relex_Range relex_range = + cpp_get_relex_range(array, start_i, end_i); - Cpp_Relex_State state = - cpp_relex_nonalloc_start(data, size, array, - start_i, end_i, amount, 100); + i32 relex_space_size = + relex_range.end_token_index - relex_range.start_token_index + extra_tolerance; Temp_Memory temp = begin_temp_memory(part); - i32 relex_end; - Cpp_Token_Array relex_space; - relex_space.count = 0; - relex_space.max_count = state.space_request; - relex_space.tokens = push_array(part, Cpp_Token, relex_space.max_count); + Cpp_Token_Array relex_array; + relex_array.count = 0; + relex_array.max_count = relex_space_size; + relex_array.tokens = push_array(part, Cpp_Token, relex_array.max_count); - char *spare = push_array(part, char, size+1); - if (cpp_relex_nonalloc_main(&state, &relex_space, &relex_end, spare)){ - inline_lex = 0; + i32 size = file->state.buffer.size; + char *spare = push_array(part, char, size); + + Cpp_Relex_Data state = cpp_relex_init(array, start_i, end_i, shift_amount, spare); + + char *chunk = file->state.buffer.data; + i32 chunk_size = size; + for(;;){ + Cpp_Lex_Result lex_result = + cpp_relex_step(&state, chunk, chunk_size, size, array, &relex_array); + + switch (lex_result){ + case LexResult_NeedChunk: + Assert(!"There is only one chunk in the current system."); + break; + + case LexResult_NeedTokenMemory: + inline_lex = 0; + goto doublebreak; + + case LexResult_Finished: + goto doublebreak; + } } - else{ + doublebreak:; + + if (inline_lex){ + i32 new_count = cpp_relex_get_new_count(&state, array->count, &relex_array); + if (new_count > array->max_count){ + i32 new_max = LargeRoundUp(new_count, Kbytes(1)); + array->tokens = (Cpp_Token*) + general_memory_reallocate(general, array->tokens, + array->count*sizeof(Cpp_Token), + new_max*sizeof(Cpp_Token)); + array->max_count = new_max; + } + + cpp_relex_complete(&state, array, &relex_array); + +#if 0 i32 delete_amount = relex_end - state.start_token_i; i32 shift_amount = relex_space.count - delete_amount; @@ -1307,6 +1341,10 @@ file_relex_parallel(System_Functions *system, memcpy(state.array->tokens + state.start_token_i, relex_space.tokens, sizeof(Cpp_Token)*relex_space.count); +#endif + } + else{ + cpp_relex_abort(&state, array); } end_temp_memory(temp); @@ -1324,12 +1362,12 @@ file_relex_parallel(System_Functions *system, ++end_token_i; } - cpp_shift_token_starts(array, end_token_i, amount); + cpp_shift_token_starts(array, end_token_i, shift_amount); --end_token_i; if (end_token_i >= 0){ Cpp_Token *token = array->tokens + end_token_i; if (token->start < end_i && token->start + token->size > end_i){ - token->size += amount; + token->size += shift_amount; } } diff --git a/4ed_metagen.cpp b/4ed_metagen.cpp index f64c2137..cdb26f85 100644 --- a/4ed_metagen.cpp +++ b/4ed_metagen.cpp @@ -3099,7 +3099,7 @@ generate_custom_headers(){ append_ss (&out, name); append_sc (&out, "
"); - print_function_html(&out, &used_links, item->cpp_name, item->ret, "app->", name, item->breakdown); + print_function_html(&out, &used_links, item->cpp_name, item->ret, "", name, item->breakdown); append_sc(&out, "
"); print_function_docs(&out, part, name, item->doc_string); diff --git a/TODO.txt b/TODO.txt index 9be1606a..0508e6f1 100644 --- a/TODO.txt +++ b/TODO.txt @@ -131,6 +131,7 @@ ; [X] expose dirty flags ; [X] why are command line files not loading any more? ; [X] use strange theme +; [X] cuber's return to previous buffer idea ; [X] tokens in the custom API ; [X] token seeking on custom side @@ -141,8 +142,7 @@ ; [] more built in options for auto indenting ; -; [] binary buffers -; [] commands for resizing panels +; [] miblo's various number editors ; [] user file bar string ; [] API docs as text file ; [] read only files @@ -151,9 +151,6 @@ ; [] control over how mouse effects panel focus ; [] option to not open *messages* every startup ; -; [] support full length unicode file names -; [] switch based word complete -; ; [] query buffer font info ; [] break buffer name ties by adding parent directories instead of <#> ; [] undo groups @@ -168,6 +165,11 @@ ; [] multi-cursor editing ; +; buffer behavior cleanup +; [] show all characters as \# if they can't be rendered +; [] support full length unicode file names +; [] binary buffers + ; meta programming system ; [X] condense system into single meta compiler ; [] formalize the rewriter for the 4coder_string.h so it can be used for other single header libs @@ -225,10 +227,8 @@ ; [] fancy code presentation mode ; -; [X] cuber's return to previous buffer idea -; [] miblo's various number editors -; -; [] keep copy of unedited orignal, somewhere (compressed? restore by history?) +; [] switch based word complete +; [] keep copy of unedited orignal maybe? (compressed? restore by history?) ; ; [] diff ; [] cloc @@ -271,14 +271,6 @@ ; ; -; FANCY-PANTS IDEAS -; [] pass messages to 'jobs' to try to avoid cancelling them -; if the job still thinks it should be cancelled it will say so -; but otherwise the job can try to incorporate the new info -; without throwing away the progress it has made so far. -; -; - ; PORTING TODOS ; [X] command line parameters