4coder API Docs

Table of Contents

§1 Introduction

This is the documentation for alpha 4.0.21. 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 members of the 4coder and handmade network community you can post on the 4coder forums hosted 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: global_set_setting

bool32 global_set_setting(
Application_Links *app,
Global_Setting_ID setting,
int32_t value
)
Parameters
setting
Which setting to change.
value
The new value to set ont he specified setting.
See Also
Global_Setting_ID

§3.3.2: 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
Command_ID

§3.3.3: 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, otherwise the command will still work but if there is a buffer capturing the output it will not automatically be displayed.
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. The command will cause a crash if no buffer is specified.
path
The path parameter specifies the current working directory 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 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
Buffer_Identifier
Command_Line_Interface_Flag

§3.3.4: 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
The_4coder_Clipboard

§3.3.5: 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
The_4coder_Clipboard

§3.3.6: 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
The_4coder_Clipboard

§3.3.7: create_parse_context

Parse_Context_ID create_parse_context(
Application_Links *app,
Parser_String_And_Type *kw,
uint32_t kw_count,
Parser_String_And_Type *pp,
uint32_t pp_count
)
Parameters
kw
The list of keywords and type of each.
kw_count
The number of keywords in the list.
pp
The list of preprocessor directives and the type of each.
pp_count
The number of preprocessor directives in the list.
Return
On success returns an id for the new parse context. If id == 0, then the maximum number of parse contexts has been reached.

§3.3.8: get_buffer_count

int32_t get_buffer_count(Application_Links *app)
Description
Gives the total number of buffers in the application.


§3.3.9: 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
Buffer_Summary
Access_Flag
get_buffer_next

§3.3.10: 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
Buffer_Summary
Access_Flag
get_buffer_first

§3.3.11: 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
Buffer_Summary
Access_Flag
Buffer_ID

§3.3.12: 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
Buffer_Summary
Access_Flag

§3.3.13: 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
4coder_Buffer_Positioning_System

§3.3.14: 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
4coder_Buffer_Positioning_System

§3.3.15: 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
Buffer_Seek
Partial_Cursor

§3.3.16: 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
buffer
The buffer on which to apply the batch of edits.
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
Buffer_Edit
Buffer_Batch_Edit_Type

§3.3.17: buffer_add_markers

Marker_Handle buffer_add_markers(
Application_Links *app,
Buffer_Summary *buffer,
uint32_t marker_count
)
Parameters
buffer
The buffer on which to add the new markers.
marker_count
How many markers to be stored in the new marker array.
Return
If this call succeeds it returns a handle to the new markers. If it fails it returns a null handle.
Description
This call makes an allocation of markers for the specified buffer. The newly allocated markers are not immediately activated. To activate a marker use buffer_set_markers to give the marker a value. The markers will remain allocated on the buffer until buffer_remove_markers is called or until the buffer is killed.

See Also
Marker

§3.3.18: get_buffer_by_marker_handle

Buffer_Summary get_buffer_by_marker_handle(
Application_Links *app,
Marker_Handle marker,
Access_Flag access
)
Parameters
marker
The marker handle to query.
access
The access parameter determines what levels of protection this call can access.
See Also
Marker

§3.3.19: buffer_set_markers

bool32 buffer_set_markers(
Application_Links *app,
Buffer_Summary *buffer,
Marker_Handle marker,
uint32_t first_marker_index,
uint32_t marker_count,
Marker *source_markers
)
Parameters
buffer
The buffer on which the specified markers are attached.
marker
The marker handle refering to the markers to be set.
first_marker_index
The index of the first marker to be set by this call.
marker_count
The number of markers to be set by this call.
source_markers
An array of marker_count Markers to specify the values to set to the markers specified.
Return
On success returns non-zero, on failure returns zero.
Description
This call sets the value of a Marker, eliminating whatever value was there before. Any markers that are set become active if they were not active before. If a marker of lower index than first_marker_index was not active before this call, it will be cleared to zero and made active as well, so that all markers between 0 and first_marker_index + marker_count - 1 are active after this call. If first_marker_index + marker_count exceeds the originally allocated size of the marker array, this call will fail.

See Also
Marker

§3.3.20: buffer_get_markers

bool32 buffer_get_markers(
Application_Links *app,
Buffer_Summary *buffer,
Marker_Handle marker,
uint32_t first_marker_index,
uint32_t marker_count,
Marker *markers_out
)
Parameters
buffer
The buffer on which the specified markers are attached.
marker
The marker handle refering to the markers to be read.
first_marker_index
The index of the first marker to be read by this call.
marker_count
The number of markers to be read by this call.
markers_out
An array of marker_count Markers to be filled by the result of the read.
Return
On success returns non-zero, on failure returns zero.
Description
When the range specified by first_marker_index and marker_count is a range of active markers in the array specified by the marker handle, this call succeeds and fills the markers_out buffer with the current values of the specified markers.

See Also
Marker

§3.3.21: buffer_remove_markers

bool32 buffer_remove_markers(
Application_Links *app,
Buffer_Summary *buffer,
Marker_Handle marker
)
Parameters
buffer
The buffer on which the specified markers are attached.
marker
The marker handle refering to the markers to be detached from the buffer.
Return
On success returns non-zero, on failure returns zero.
Description
Deactivates the entire range of markers specified by the marker handle and frees the memory used to store the markers internally.

See Also
buffer_add_markers

§3.3.22: buffer_get_setting

bool32 buffer_get_setting(
Application_Links *app,
Buffer_Summary *buffer,
Buffer_Setting_ID setting,
int32_t *value_out
)
Parameters
buffer
the buffer from which to read a setting
setting
the setting to read from the buffer
value_out
address to write the setting value on success
Return
returns non-zero on success

§3.3.23: 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
Buffer_Setting_ID

§3.3.24: 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.25: 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.26: 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. The returned index can be -1 if the position is before the first token.

See Also
Cpp_Get_Token_Result
cpp_get_token

§3.3.27: buffer_send_end_signal

bool32 buffer_send_end_signal(
Application_Links *app,
Buffer_Summary *buffer
)
Parameters
buffer
The buffer to which to send the end signal.
Return
Returns non-zero on success. This call can fail if the buffer doesn't exist.
Description
Whenever a buffer is killed an end signal is sent which triggers the end file hook. This call sends the end signal to the buffer without killing the buffer. This is useful in cases such as clearing a buffer and refilling it with new contents.


§3.3.28: begin_buffer_creation

bool32 begin_buffer_creation(
Application_Links *app,
Buffer_Creation_Data *data,
Buffer_Create_Flag flags
)
Parameters
data
a local user handle for the buffer creation process
flags
flags defining the buffer creation behavior
Description
Begins a buffer creation by initializing a Buffer_Creation_Data struct. The buffer is not actually created until end_buffer_creation is called.

See Also
buffer_creation_name
end_buffer_creation
Buffer_Creation_Data
Buffer_Create_Flag

§3.3.29: buffer_creation_name

bool32 buffer_creation_name(
Application_Links *app,
Buffer_Creation_Data *data,
char *filename,
int32_t filename_len,
uint32_t flags
)
Parameters
data
a local user handle for buffer creation that has already been initialized by begin_buffer_creation
filename
the name to associate to the buffer; This string need not be null terminated.
filename_len
the length of the filename string
flags
not currently used this should be 0
Description
This call sets the name associated to the buffer. If the name is a filename, that filename will be used for loading and saving with the disk, and the buffer name will be extracted from the filename. If the name is not a filename it will be an unassociated buffer and the buffer name will be exactly set to filename.

See Also
begin_buffer_creation
end_buffer_creation

§3.3.30: end_buffer_creation

Buffer_Summary end_buffer_creation(
Application_Links *app,
Buffer_Creation_Data *data
)
Parameters
data
a local user handle for buffer creation that has already been initialized by begin_buffer_creation and used in subsequent buffer creation flags
Return
returns a summary of the newly created buffer or of the existing buffer that already has the specified name. If there is not enough creation data to make the buffer the returned summary will be null.
See Also
begin_buffer_creation

§3.3.31: 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 write with the contents of 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.
Description
Often it will make sense to set filename and filename_len to buffer.filename and buffer.filename_len


§3.3.32: 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
Buffer_Kill_Flag
Buffer_Identifier

§3.3.33: 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
Access_Flag
get_view_next

§3.3.34: 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
Access_Flag
get_view_first

§3.3.35: 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
Access_Flag

§3.3.36: 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
set_active_view
Access_Flag

§3.3.37: 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
View_Split_Position

§3.3.38: 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.39: 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
get_active_view

§3.3.40: view_get_setting

bool32 view_get_setting(
Application_Links *app,
View_Summary *view,
View_Setting_ID setting,
int32_t *value_out
)
Parameters
view
the view from which to read a setting
setting
the view setting to read
value_out
address to write the setting value on success
Return
returns non-zero on success

§3.3.41: 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
View_Setting_ID

§3.3.42: 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.43: 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
Buffer_Seek
Full_Cursor

§3.3.44: 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
Buffer_Seek

§3.3.45: view_set_scroll

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

See Also
GUI_Scroll_Vars

§3.3.46: 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
Buffer_Seek

§3.3.47: 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.48: 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
Set_Buffer_Flag

§3.3.49: 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
int_color

§3.3.50: 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
Input_Type_Flag
User_Input

§3.3.51: 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
User_Input

§3.3.52: 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
Mouse_State

§3.3.53: 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.54: 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.56: create_theme

void create_theme(
Application_Links *app,
Theme *theme,
char *name,
int32_t len
)
Parameters
theme
The color data of the new theme.
name
The name of the new theme. This string need not be null terminated.
len
The length of the name string.
Description
This call creates a new theme. If the given name is already the name of a string, the old string will be replaced with the new one. This call does not set the current theme.


§3.3.57: 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.58: 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.59: 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.60: buffer_get_font

bool32 buffer_get_font(
Application_Links *app,
Buffer_Summary *buffer,
char *name_out,
int32_t name_max
)
Parameters
buffer
the buffer from which to get the font name
name_out
a character array in which to write the name of the font
name_max
the capacity of name_out
Return
returns non-zero on success

§3.3.61: 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.

See Also
Theme_Color

§3.3.62: 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.

See Also
Theme_Color

§3.3.63: 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.

See Also
directory_set_hot

§3.3.64: directory_set_hot

bool32 directory_set_hot(
Application_Links *app,
char *str,
int32_t len
)
Parameters
str
The new value of the hot directory. This does not need to be a null terminated string.
len
The length of str in bytes.
Return
Returns non-zero on success.
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.

See Also
directory_get_hot

§3.3.65: 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.
See Also
File_List

§3.3.66: 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.

See Also
File_List

§3.3.67: set_gui_up_down_keys

void set_gui_up_down_keys(
Application_Links *app,
Key_Code up_key,
Key_Modifier up_key_modifier,
Key_Code down_key,
Key_Modifier down_key_modifier
)
Parameters
up_key
the code of the key that should be interpreted as an up key
up_key_modifier
the modifier for the key that should be interpreted as an up key
down_key
the code of the key that should be interpreted as a down key
down_key_modifier
the modifier for the key that should be interpreted as a down key
Description
This is a temporary ad-hoc solution to allow some customization of the behavior of the built in GUI. There is a high chance that it will be removed and not replaced at some point, so it is not recommended that it be heavily used.


§3.3.68: 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
memory_free

§3.3.69: 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
memory_allocate
Memory_Protect_Flags

§3.3.70: 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
memory_allocate

§3.3.71: 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.72: 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.73: get_4ed_path

int32_t 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.74: 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
Mouse_Cursor_Show_Type

§3.3.75: 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.76: 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.77: 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 values.


§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 32 bit integers (8 bit + 24 bit) with 3 channels: 0x**RRGGBB.


§3.4.3: Parse_Context_ID

typedef uint32_t Parse_Context_ID;
Description
Parse_Context_ID identifies a parse context, which is a guiding rule for the parser. Each buffer sets which parse context to use when it is parsed.


§3.4.4: Buffer_ID

typedef int32_t Buffer_ID;
Description
Buffer_ID is used to name a 4coder buffer. Each buffer has a unique id but when a buffer is closed it's id may be recycled by future, different buffers.


§3.4.5: View_ID

typedef int32_t View_ID;
Description
View_ID is used to name a 4coder view. Each view has a unique id in the interval [1,16].


§3.4.6: Key_Modifier_Index

enum Key_Modifier_Index;
Description
A Key_Modifier_Index acts as an index for specifying modifiers in arrays.

Values
MDFR_SHIFT_INDEX
MDFR_CONTROL_INDEX
MDFR_ALT_INDEX
MDFR_CAPS_INDEX
MDFR_HOLD_INDEX
MDFR_INDEX_COUNT
MDFR_INDEX_COUNT is used to specify the number of modifiers supported.


§3.4.7: Key_Modifier_Flag

enum Key_Modifier_Flag;
Description
A Key_Modifier_Flag field is used to specify a specific state of modifiers. Flags can be combined with bit or to specify a state with multiple modifiers.

Values
MDFR_NONE = 0x0
MDFR_NONE specifies that no modifiers are pressed.

MDFR_CTRL = 0x1
MDFR_ALT = 0x2
MDFR_SHIFT = 0x4

§3.4.8: Command_ID

enum Command_ID;
Description
A Command_ID is used as a name for commands implemented internally in 4coder.

Values
cmdid_null
cmdid_null is set aside to always be zero and is not associated with any command.

cmdid_undo
cmdid_undo performs a standard undo behavior.

cmdid_redo
cmdid_redo reperforms an edit that was undone.

cmdid_interactive_new
cmdid_interactive_new begins an interactive dialogue to create a new buffer.

cmdid_interactive_open
cmdid_interactive_open begins an interactive dialogue to open a file into a buffer.

cmdid_interactive_open_or_new
cmdid_interactive_open_or_new begins an interactive dialogue to open a file into a buffer, if the name specified does not match any existing buffer, a new buffer is created instead.

cmdid_save_as
cmdid_save_as does not currently work and is likely to be removed rather that fixed.

cmdid_interactive_switch_buffer
cmdid_interactive_switch_buffer begins an interactive dialogue to choose an open buffer to swap into the active view.

cmdid_interactive_kill_buffer
cmdid_interactive_kill_buffer begins an interactive dialogue to choose an open buffer to kill.

cmdid_reopen
cmdid_reopen reloads the active buffer's associated file and discards the old buffer contents for the reloaded file.

cmdid_save
cmdid_save saves the buffer's contents into the associated file.

cmdid_kill_buffer
cmdid_kill_buffer tries to kill the active buffer.

cmdid_open_color_tweaker
cmdid_open_color_tweaker opens the theme editing GUI.

cmdid_open_debug
cmdid_open_debug opens the debug information viewer mode.

cmdid_count

§3.4.9: Memory_Protect_Flags

enum Memory_Protect_Flags;
Description
Flags for describing the memory protection status of pages that come back from memory allocate. Some combinations may not be available on some platforms, but you are gauranteed to get back a page with at least the permissions you requested. For example if you request just write permission, you may get back a page with read and write permission, but you will never get back a page that doesn't have write permission.

Values
MemProtect_Read = 0x1
Allows the page to be read.

MemProtect_Write = 0x2
Allows the page to be written.

MemProtect_Execute = 0x4
Allows the page to be executed.


§3.4.10: User_Input_Type_ID

enum User_Input_Type_ID;
Description
User_Input_Type_ID specifies a type of user input event.

Values
UserInputNone
UserInputNone indicates that no event has occurred.

UserInputKey
UserInputKey indicates an event which can be described by a Key_Event_Data struct.

UserInputMouse
UserInputMouse indicates an event which can be described by a Mouse_State struct.


§3.4.11: Wrap_Indicator_Mode

enum Wrap_Indicator_Mode;
Description
A Wrap_Indicator_Mode is used in the buffer setting BufferSetting_WrapIndicator to specify how to indicate that line has been wrapped.

Values
WrapIndicator_Hide
WrapIndicator_Hide tells the buffer rendering system not to put any indicator on wrapped lines.

WrapIndicator_Show_After_Line
WrapIndicator_Show_After_Line tells the buffer rendering system to put a backslash indicator on wrapped lines right after the last character of the line.

WrapIndicator_Show_At_Wrap_Edge
WrapIndicator_Show_At_Wrap_Edge tells the buffer rendering system to put a backslash indicator on wrapped lines aligned with the wrap position for that line.


§3.4.12: Global_Setting_ID

enum Global_Setting_ID;
Description
A Global_Setting_ID names a setting.

Values
GlobalSetting_Null
GlobalSetting_Null is not a valid setting, it is reserved to detect errors.

GlobalSetting_LAltLCtrlIsAltGr
When GlobalSetting_LAltLCtrlIsAltGr is enabled, keyboard layouts with AltGr will also interpret the left alt and control keys as AltGr. If you do not use a keyboard with AltGr you should have this turned off. This setting is only relevant on Windows and has no effect on other systems.


§3.4.13: Buffer_Setting_ID

enum Buffer_Setting_ID;
Description
A Buffer_Setting_ID names a setting in a buffer.

Values
BufferSetting_Null
BufferSetting_Null is not a valid setting, it is reserved to detect errors.

BufferSetting_Lex
The BufferSetting_Lex setting is used to determine whether to store C++ tokens from with the buffer.

BufferSetting_LexWithoutStrings
The BufferSetting_LexWithoutStrings tells the system to treat string and character marks as identifiers instead of strings. This settings does nothing if the buffer does not have lexing turned on.

BufferSetting_ParserContext
The BufferSetting_ParserContext setting determines the parser context that guides the parser for the contents of this buffer. By default the value is 0, which represents the default C++ context.

BufferSetting_WrapLine
The BufferSetting_WrapLine setting is used to determine whether a buffer prefers to be viewed with wrapped lines, individual views can be set to override this value after being tied to the buffer.

BufferSetting_WrapPosition
The BufferSetting_WrapPosition setting determines after how many pixels a line will wrap. A view set's this value from the global default value when the view is created. This value cannot be set to less than 48, any value passed below 48 will cause the position to be set to 48. This is a potentially expensive operation because the wrap positions of the file have to be reindexed. For best behavior try to only set this setting once per frame, if possible.

BufferSetting_MinimumBaseWrapPosition
The BufferSetting_MinimumBaseWrapPosition setting is used to increase the with in pixels allotted to a line for wrapping, by setting a minimum position away from the base of the line. The base of a line is always 0, or the left hand side of the view, in text files. In code files the base of a line is the amount the line is shifted to the right due to brace nesting. This setting allows for deeply nested code to remain readable by ensuring lines deep in the nesting get some minimum base width which may be more wrapping space than the non base adjusted wrap position would have allowed. In any case where the (default wrapping position) is greater than (the base + minimum base position), the larger

BufferSetting_WrapIndicator
The BufferSetting_WrapIndicator setting is used to specify how wrapped lines should be marked so the user can see that they have been wrapped. The value should be one of the values in the Wrap_Indicator_Mode enum.

BufferSetting_MapID
The BufferSetting_MapID setting specifies the id of the command map that should be active when a buffer is active.

BufferSetting_Eol
The BufferSetting_Eol setting specifies how line ends should be saved to the backing file. A 1 indicates dos endings "\r\n" and a 0 indicates nix endings "\n".

BufferSetting_Unimportant
The BufferSetting_Unimportant setting marks a buffer so that its dirty state will be forced to stay at DirtyState_UpToDate when the buffer is edited or when the buffer's paired file, if it has one, is edited.

BufferSetting_ReadOnly
The BufferSetting_ReadOnly setting marks a buffer so that it can only be returned from buffer access calls that include an AccessProtected flag. By convention this means that edit commands that should not be applied to read only buffers will not edit this buffer.

BufferSetting_VirtualWhitespace
The BufferSetting_VirtualWhitespace setting enables virtual whitespace on a buffer. Text buffers with virtual whitespace will set the indentation of every line to zero. Buffers with lexing enabled will use virtual white space to present the code with appealing indentation.


§3.4.14: View_Setting_ID

enum View_Setting_ID;
Description
A View_Setting_ID names an adjustable setting in a view.

Values
ViewSetting_Null
ViewSetting_Null is not a valid setting, it is reserved to detect errors.

ViewSetting_ShowWhitespace
The ViewSetting_ShowWhitespace setting determines whether the view highlights whitespace in a file. Whenever the view switches to a new buffer this setting is turned off.

ViewSetting_ShowScrollbar
The ViewSetting_ShowScrollbar setting determines whether a scroll bar is attached to a view in it's scrollable section.

ViewSetting_ShowFileBar
The ViewSetting_ShowFileBar settings determines whether to show the file bar.


§3.4.15: Buffer_Create_Flag

enum Buffer_Create_Flag;
Description
A Buffer_Create_Flag field specifies how a buffer should be created.

Values
BufferCreate_Background = 0x1
BufferCreate_Background is not currently implemented.

BufferCreate_AlwaysNew = 0x2
When BufferCreate_AlwaysNew is set it indicates the buffer should be cleared to empty even if it's associated file already has content.

BufferCreate_NeverNew = 0x4
When BufferCreate_NeverNew is set it indicates that the buffer should only be created if it is an existing file or if a buffer with the given name is already open.


§3.4.16: Buffer_Creation_Data

struct Buffer_Creation_Data { /* non-public internals */ } ;
Description
Buffer_Creation_Data is a struct used as a local handle for the creation of a buffer.


§3.4.17: Buffer_Kill_Flag

enum Buffer_Kill_Flag;
Description
A Buffer_Kill_Flag field specifies how a buffer should be killed.

Values
BufferKill_Background = 0x1
BufferKill_Background is not currently implemented.

BufferKill_AlwaysKill = 0x2
When BufferKill_AlwaysKill is set it indicates the buffer should be killed without asking, even when the buffer is dirty.


§3.4.18: Access_Flag

enum Access_Flag;
Description
An Access_Flag field specifies what sort of permission you grant to an access call. An access call is usually one the returns a summary struct. If a 4coder object has a particular protection flag set and the corresponding bit is not set in the access field, that 4coder object is hidden. On the other hand if a protection flag is set in the access parameter and the object does not have that protection flag, the object is still returned from the access call.

Values
AccessOpen = 0x0
AccessOpen does not include any bits, it indicates that the access should only return objects that have no protection flags set.

AccessProtected = 0x1
AccessProtected is set on buffers and views that are "read only" such as the output from an exec_system_command call into *build*. This is to prevent the user from accidentally editing output that they might prefer to keep in tact.

AccessHidden = 0x2
AccessHidden is set on any view that is not currently showing it's file, for instance because it is navigating the file system to open a file.

AccessAll = 0xFF
AccessAll is a catchall access for cases where an access call should always return an object no matter what it's protection flags are.


§3.4.19: Dirty_State

enum Dirty_State;
Description
A Dirty_State value describes whether changes have been made to a buffer or to an underlying file since the last sync time between the two. Saving a buffer to it's file or loading the buffer from the file both act as sync points.

Values
DirtyState_UpToDate = 0
DirtyState_UpToDate indicates that there are no unsaved changes and the underlying system file still agrees with the buffer's state.

DirtyState_UnsavedChanges = 1
DirtyState_UnsavedChanges indicates that there have been changes in the buffer since the last sync point.

DirtyState_UnloadedChanges = 2
DirtyState_UnsavedChanges indicates that the underlying file has been edited since the last sync point with the buffer.


§3.4.20: Seek_Boundary_Flag

enum Seek_Boundary_Flag;
Description
A Seek_Boundary_Flag field specifies a set of "boundary" types used in seeks for the beginning or end of different types of words.

Values
BoundaryWhitespace = 0x1
BoundaryToken = 0x2
BoundaryAlphanumeric = 0x4
BoundaryCamelCase = 0x8

§3.4.21: Command_Line_Interface_Flag

enum Command_Line_Interface_Flag;
Description
A Command_Line_Interface_Flag field specifies the behavior of a call to a command line interface.

Values
CLI_OverlapWithConflict = 0x1
If CLI_OverlapWithConflict is set if output buffer of the new command is already in use by another command which is still executing, the older command relinquishes control of the buffer and both operate simultaneously with only the newer command outputting to the buffer.

CLI_AlwaysBindToView = 0x2
If CLI_AlwaysBindToView is set the output buffer will always be set in the active view even if it is already set in another open view.

CLI_CursorAtEnd = 0x4
If CLI_CursorAtEnd is set the cursor will be kept at the end of the output buffer, otherwise the cursor is kept at the beginning.


§3.4.22: Auto_Indent_Flag

enum Auto_Indent_Flag;
Description
An Auto_Indent_Flag field specifies the behavior of an auto indentation operation.

Values
AutoIndent_ClearLine = 0x1
If AutoIndent_ClearLine is set, then any line that is only whitespace will be cleared to contain nothing at all. otherwise the line is filled with whitespace to match the nearby indentation.

AutoIndent_UseTab = 0x2
If AutoIndent_UseTab is set, then when putting in leading whitespace to align code, as many tabs will be used as possible until the fine grained control of spaces is needed to finish the alignment.

AutoIndent_ExactAlignBlock = 0x4
If AutoIndent_ExactAlignBlock is set, then block comments are indented by putting the first non-whitespace character of the line in line with the beginning of the comment.

AutoIndent_FullTokens = 0x8
If AutoIndent_FullTokens is set, then the set of lines that are indented is automatically expanded so that any token spanning multiple lines gets entirely indented.


§3.4.23: Set_Buffer_Flag

enum Set_Buffer_Flag;
Description
A Set_Buffer_Flag field specifies the behavior of an operation that sets the buffer of a view.

Values
SetBuffer_KeepOriginalGUI = 0x1
If SetBuffer_KeepOriginalGUI then when the file is set, the view will not switch to it if some other GUI was currently up, otherwise any GUI that is up is closed and the view switches to the file.


§3.4.24: Input_Type_Flag

enum Input_Type_Flag;
Description
A Input_Type_Flag field specifies a set of input event types.

Values
EventOnAnyKey = 0x1
If EventOnAnyKey is set, all keyboard events are included in the set.

EventOnEsc = 0x2
If EventOnEsc is set, any press of the escape key is included in the set.

EventOnLeftButton = 0x4
If EventOnLeftButton is set, left clicks are included in the set.

EventOnRightButton = 0x8
If EventOnRightButton is set, right clicks are included in the set.

EventOnWheel = 0x10
If EventOnWheel is set, any wheel movement is included in the set.

EventOnMouseMove = 0x20
This is not totally implemented yet.

EventOnButton = (EventOnLeftButton | EventOnRightButton | EventOnWheel)
If EventOnButton is set, all mouse button events are included in the set.

EventOnMouse = (EventOnButton | EventOnMouseMove)
This is not totally implemented yet.

EventAll = 0xFF
EventAll is a catch all name for including all possible events in the set.


§3.4.25: Mouse_Cursor_Show_Type

enum Mouse_Cursor_Show_Type;
Description
A Mouse_Cursor_Show_Type value specifes a mode for 4coder to handle the mouse cursor.

Values
MouseCursorShow_Never
The MouseCursorShow_Never mode never shows the cursor.

MouseCursorShow_Always
The MouseCursorShow_Never mode always shows the cursor.


§3.4.26: View_Split_Position

enum View_Split_Position;
Description
A View_Split_Position specifies where a new view should be placed as a result of a view split operation.

Values
ViewSplit_Top
This value indicates that the new view should be above the existing view.

ViewSplit_Bottom
This value indicates that the new view should be below the existing view.

ViewSplit_Left
This value indicates that the new view should be left of the existing view.

ViewSplit_Right
This value indicates that the new view should be right of the existing view.


§3.4.27: Key_Code

typedef uint32_t Key_Code;
Description
Key_Code is the alias for key codes including raw codes and codes translated to textual input that takes modifiers into account.


§3.4.28: Key_Modifier

typedef uint8_t Key_Modifier;
Description
Key_Modifier is the alias for flags that represent keyboard modifiers, ctrl, alt, shift, etc.

See Also
Key_Modifier_Flag

§3.4.29: Key_Event_Data

struct Key_Event_Data {
Key_Code keycode;
Key_Code character;
Key_Code character_no_caps_lock;
int8_t modifiers[MDFR_INDEX_COUNT];
};
Description
Key_Event_Data describes a key event, including the translation to a character, the translation to a character ignoring the state of caps lock, and an array of all the modifiers that were pressed at the time of the event.

Fields
keycode
This field is the raw keycode which is always non-zero in valid key events.

character
This field is the keycode after translation to a character, this is 0 if there is no translation.

character_no_caps_lock
This field is like the field character, except that the state of caps lock is ignored in the translation.

modifiers
This field is an array indicating the state of modifiers at the time of the key press. The array is indexed using the values of Key_Modifier_Index. 1 indicates that the corresponding modifier was held, and a 0 indicates that it was not held.


§3.4.30: Mouse_State

struct Mouse_State {
char l;
char r;
char press_l;
char press_r;
char release_l;
char release_r;
char wheel;
char out_of_window;
int32_t x;
int32_t y;
};
Description
Mouse_State describes an entire mouse state complete with the position, left and right button states, the wheel state, and whether or not the mouse if in the window.

Fields
l
This field indicates that the left button is held.

r
This field indicates that the right button is held.

press_l
This field indicates that the left button was pressed this frame.

press_r
This field indicates that the right button was pressed this frame.

release_l
This field indicates that the left button was released this frame.

release_r
This field indicates that the right button was released this frame.

wheel
This field is 0 when the wheel has not moved, it is 1 for a downward motion and -1 for an upward motion.

out_of_window
This field indicates that the mouse is outside of the window.

x
This field contains the x position of the mouse relative to the window where the left side is 0.

y
This field contains the y position of the mouse relative to the window where the top side is 0.


§3.4.31: Range

union Range {
struct {
int32_t min;
int32_t max;
};
struct {
int32_t start;
int32_t end;
};
};
Description
Range describes an integer range typically used for ranges within a buffer. Ranges tend are usually not passed as a Range struct into the API, but this struct is used to return ranges.

Throughout the API ranges are thought of in the form [min,max

Fields
min
This is the smaller value in the range, it is also the 'start'.

max
This is the larger value in the range, it is also the 'end'.

start
This is the start of the range, it is also the 'min'.

end
This is the end of the range, it is also the 'max'.


§3.4.32: Parser_String_And_Type

struct Parser_String_And_Type {
char * str;
uint32_t length;
uint32_t type;
};
Description
Parser_String_And_Type contains a string and type integer used to specify information about keywords to the parser.

Fields
str
The string specified by the pair, it need not be null terminated.

length
The number of bytes in the string str.

type
The type integer.


§3.4.33: File_Info

struct File_Info {
char * filename;
int32_t filename_len;
bool32 folder;
};
Description
File_Info describes the name and type of a file.

Fields
filename
This field is a null terminated string specifying the name of the file.

filename_len
This field specifies the length of the filename string not counting the null terminator.

folder
This field indicates that the description is for a folder not a file.

See Also
File_List

§3.4.34: File_List

struct File_List {
void * block;
File_Info * infos;
uint32_t count;
uint32_t block_size;
};
Description
File_List is a list of File_Info structs.

Fields
block
This field is for inernal use.

infos
This field is an array of File_Info structs.

count
This field specifies the number of struts in the info array.

block_size
This field is for internal use.

See Also
File_Info

§3.4.35: Buffer_Identifier

struct Buffer_Identifier {
char * name;
int32_t name_len;
Buffer_ID id;
};
Description
Buffer_Identifier acts as a loosely typed description of a buffer that can either be a name or an id.

Fields
name
This field is the name of the buffer; it need not be null terminated. If id is specified this pointer should be NULL.

name_len
This field specifies the length of the name string.

id
This field is the id of the buffer. If name is specified this should be 0.


§3.4.36: GUI_Scroll_Vars

struct GUI_Scroll_Vars {
float scroll_y;
int32_t target_y;
int32_t prev_target_y;
float scroll_x;
int32_t target_x;
int32_t prev_target_x;
};
Description
Describes the various coordinate locations associated with the view's scroll position within it's buffer.

Fields
scroll_y
The current actual y position of the view scroll.

target_y
The target y position to which the view is moving. If scroll_y is not the same value, then it is still sliding to the target by the smooth scroll rule.

prev_target_y
The previous value of target y. This value should be ignored as it is the "vestigial" remain of a system that will not be around much longer.

scroll_x
The current actual x position of the view scroll.

target_x
The target x position to which the view is moving. If scroll_x is not the same value, then it is still sliding to the target by the smooth scroll rule.

prev_target_x
The previous value of target x. This value should be ignored as it is the "vestigial" remain of a system that will not be around much longer.


§3.4.37: Buffer_Seek_Type

enum Buffer_Seek_Type;
Description
The Buffer_Seek_Type is is used in a Buffer_Seek to identify which coordinates are suppose to be used for the seek.

Values
buffer_seek_pos
This value indicates absolute byte index positioning where positions are measured as the number of bytes from the start of the file.

buffer_seek_character_pos
This value indicates apparent character index positioning where positions are measured as the number of apparent characters from the starts of the file.

buffer_seek_wrapped_xy
This value indicates xy positioning with wrapped lines where the x and y values are in pixels.

buffer_seek_unwrapped_xy
This value indicates xy positioning with unwrapped lines where the x and y values are in pixels.

buffer_seek_line_char
This value indicates line-character positioning. These coordinates are 1 based to match standard line numbering.

See Also
Buffer_Seek
4coder_Buffer_Positioning_System

§3.4.38: Buffer_Seek

struct Buffer_Seek {
Buffer_Seek_Type type;
union {
struct {
int32_t pos;
};
struct {
bool32 round_down;
float x;
float y;
};
struct {
int32_t line;
int32_t character;
};
};
};
Description
Buffer_Seek describes the destination of a seek operation. There are helpers for concisely creating Buffer_Seek structs. They can be found in 4coder_buffer_types.h.

Fields
type
The type field determines the coordinate system of the seek operation.

pos
The pos field specified the pos when the seek is in absolute position.

round_down
For xy coordinate seeks, rounding down means that any x in the box of the character lands on that character. For instance when clicking rounding down is the user's expected behavior. Not rounding down means that the right hand portion of the character's box, which is closer to the next character, will land on that next character. The unrounded behavior is the expected behavior when moving vertically and keeping the preferred x.

x
The x coordinate for xy type seeks.

y
The y coordinate for xy type seeks.

line
The line number of a line-character type seek.

character
The character number of a line-character type seek.

See Also
Buffer_Seek_Type
4coder_Buffer_Positioning_System

§3.4.39: Full_Cursor

struct Full_Cursor {
int32_t pos;
int32_t character_pos;
int32_t line;
int32_t character;
int32_t wrap_line;
float unwrapped_x;
float unwrapped_y;
float wrapped_x;
float wrapped_y;
};
Description
Full_Cursor describes the position of a cursor in every buffer coordinate system supported by 4coder. This cursor type requires that the buffer is associated with a view to give the x/y values meaning.

Fields
pos
This field contains the cursor's position in absolute byte index positioning.

character_pos
This field contains the cursor's position in apparent character index positioning.

line
This field contains the number of the line where the cursor is located. This field is one based.

character
This field contains the number of the character from the beginninf of the line where the cursor is located. This field is one based.

wrap_line
This field contains the number of the line where the cursor is located, taking the line wrapping into account. This field is one based.

unwrapped_x
This field contains the x position measured with unwrapped lines.

unwrapped_y
This field contains the y position measured with unwrapped lines.

wrapped_x
This field contains the x position measured with wrapped lines.

wrapped_y
This field contains the y position measured with wrapped lines.

See Also
4coder_Buffer_Positioning_System

§3.4.40: Partial_Cursor

struct Partial_Cursor {
int32_t pos;
int32_t line;
int32_t character;
};
Description
Partial_Cursor describes the position of a cursor in all of the coordinate systems that a invariant to the View. In other words the coordinate systems available here can be used on a buffer that is not currently associated with a View.

Fields
pos
This field contains the cursor's position in absolute byte index positioning.

line
This field contains the number of the character from the beginninf of the line where the cursor is located. This field is one based.

character
This field contains the number of the column where the cursor is located. This field is one based.

See Also
4coder_Buffer_Positioning_System

§3.4.41: Buffer_Edit

struct Buffer_Edit {
int32_t str_start;
int32_t len;
int32_t start;
int32_t end;
};
Description
Buffer_Edit describes a range of a buffer and string to replace that range. A Buffer_Edit has to be paired with a string that contains the actual text that will be replaced into the buffer.

Fields
str_start
The str_start field specifies the first character in the accompanying string that corresponds with this edit.

len
The len field specifies the length of the string being written into the buffer.

start
The start field specifies the start of the range in the buffer to replace in absolute position.

end
The end field specifies one past the end of the range in the buffer to replace in absolute position.


§3.4.42: Buffer_Summary

struct Buffer_Summary {
bool32 exists;
bool32 ready;
int32_t buffer_id;
Access_Flag lock_flags;
int32_t size;
int32_t line_count;
char * file_name;
int32_t file_name_len;
char * buffer_name;
int32_t buffer_name_len;
Dirty_State dirty;
bool32 is_lexed;
bool32 tokens_are_ready;
int32_t map_id;
bool32 unwrapped_lines;
};
Description
Buffer_Summary acts as a handle to a buffer and describes the state of the buffer.

Fields
exists
This field indicates whether the Buffer_Summary describes a buffer that is open in 4coder. When this field is false the summary is referred to as a "null summary".

ready
If this is not a null summary, this field indicates whether the buffer has finished loading.

buffer_id
If this is not a null summary this field is the id of the associated buffer. If this is a null summary then buffer_id is 0.

lock_flags
If this is not a null summary, this field contains flags describing the protection status of the buffer.

size
If this is not a null summary, this field specifies the size of the text in the buffer.

line_count
If this is not a null summary, this field specifies the number of lines in the buffer.

file_name
If this is not a null summary, this field specifies the file name associated to this buffer.

file_name_len
This field specifies the length of the file_name string.

buffer_name
If this is not a null summary, this field specifies the name of the buffer.

buffer_name_len
This field specifies the length of the buffer_name string.

dirty
This field indicates the dirty state of the buffer.

is_lexed
If this is not a null summary, this field indicates whether the buffer is set to lex tokens.

tokens_are_ready
If this is not a null summary, this field indicates whether the buffer has up to date tokens available. If this field is false, it may simply mean the tokens are still being generated in a background task and will be available later. If that is the case, is_lexed will be true to indicate that the buffer is trying to get it's tokens up to date.

map_id
If this is not a null summary, this field specifies the id of the command map for this buffer.

unwrapped_lines
If this is not a null summary, this field indicates whether the buffer 'prefers' wrapped lines.

See Also
Access_Flag
Dirty_State

§3.4.43: Marker

struct Marker {
int32_t pos;
bool32 lean_right;
};
Description
A markers is a location in a buffer that, once placed, is effected by edits the same way characters are effected. In particular if an edit occurs in a location in the buffer before a marker, the marker is shifted forward or backward so that it remains on the same character.

Fields
pos
The current position of the marker measure in absolute byte positioning coordinates.

lean_right
When a marker is inside a range that gets edited, by default the marker 'leans_left' which means it goes to the beginning of the edited range. If the field lean_right is set to true, the marker will lean right with edits and will go to the end of edited range.

See Also
buffer_add_markers

§3.4.44: Marker_Handle

typedef void* Marker_Handle;
Description
A handle to an internally held array of markers.

See Also
Marker
buffer_add_markers

§3.4.45: i32_Rect

struct i32_Rect {
int32_t x0;
int32_t y0;
int32_t x1;
int32_t y1;
};
Description
A four corner axis aligned rectangle, with integer coordinates.

Fields
x0
y0
x1
y1

§3.4.46: f32_Rect

struct f32_Rect {
float x0;
float y0;
float x1;
float y1;
};
Description
A four corner axis aligned rectangle, with floating point coordinates.

Fields
x0
y0
x1
y1

§3.4.47: View_Summary

struct View_Summary {
bool32 exists;
int32_t view_id;
int32_t buffer_id;
Access_Flag lock_flags;
Full_Cursor cursor;
Full_Cursor mark;
float preferred_x;
float line_height;
bool32 unwrapped_lines;
bool32 show_whitespace;
i32_Rect view_region;
i32_Rect file_region;
GUI_Scroll_Vars scroll_vars;
};
Description
View_Summary acts as a handle to a view and describes the state of the view.

Fields
exists
This field indicates whether the View_Summary describes a view that is open in 4coder. When this field is false the summary is referred to as a "null summary".

view_id
This field is the id of the associated view. If this is a null summary then view_id is 0.

buffer_id
Then this is the id of the buffer this view currently sees.

lock_flags
This field contains flags describing the protection status of the view.

cursor
This describes the position of the cursor.

mark
This describes the position of the mark.

preferred_x
This is the x position that is maintained in vertical navigation.

line_height
This specifies the height of a line rendered in the view.

unwrapped_lines
This indicates that the view is set to render with unwrapped lines.

show_whitespace
This indicates that the view is set to highlight white space.

view_region
This describes the screen position in which this view is displayed.

file_region
This describes the screen position in which this view's buffer is displayed. This is different from view_region, because it does not include any fixed height GUI at the top of the view.

scroll_vars
This describes the scrolling position inside the view.

See Also
Access_Flag
Full_Cursor

§3.4.48: Query_Bar

struct Query_Bar {
String prompt;
String string;
};
Description
Query_Bar is a struct used to store information in the user's control that will be displayed as a drop down bar durring an interactive command.

Fields
prompt
This specifies the prompt portion of the drop down bar.

string
This specifies the main string portion of the drop down bar.


§3.4.49: Event_Message

struct Event_Message {
int32_t type;
};
Description
This feature is not implemented.

Fields
type
This feature is not implemented.


§3.4.50: Theme_Color

struct Theme_Color {
Style_Tag tag;
int_color color;
};
Description
Theme_Color stores a style tag/color pair, for the purpose of setting and getting colors in the theme.

Fields
tag
The style slot in the style palette.

color
The color in the slot.

See Also
Style_Tag
int_color

§3.4.51: Theme

struct Theme {
int_color colors[Stag_COUNT];
};
Description
Theme lists ever color that makes up a standard color scheme.

Fields
colors
The colors array. Every style tag, beginning with "Stag", is an index into it's corresponding color in the array.

See Also
int_color

§3.4.52: Buffer_Batch_Edit_Type

enum Buffer_Batch_Edit_Type;
Description
A Buffer_Batch_Edit_Type is a type of batch operation.

Values
BatchEdit_Normal
The BatchEdit_Normal operation is always correct but does the most work if there are tokens to correct.

BatchEdit_PreserveTokens
The BatchEdit_PreserveTokens operation is one in which none of the edits add, delete, or change any tokens. This usually applies when whitespace is being replaced with whitespace.


§3.4.53: Buffer_Batch_Edit

struct Buffer_Batch_Edit {
char * str;
int32_t str_len;
Buffer_Edit * edits;
int32_t edit_count;
};
Description
This struct is used to bundle the parameters of the buffer_batch_edit function. It is convenient for a few functions that return a batch edit to the user.

Fields
str
The pointer to the edit string buffer.

str_len
The length of the edit string buffer.

edits
The array of edits to be applied.

edit_count
The number of edits in the array.

See Also
buffer_batch_edit

§3.4.54: app

typedef void Custom_Command_Function(struct Application_Links * app;
Description
Custom_Command_Function is a function type which matches the signature used for commands. To declare a command use CUSTOM_COMMAND_SIG.

See Also
CUSTOM_COMMAND_SIG

§3.4.55: Generic_Command

union Generic_Command {
Command_ID cmdid;
Custom_Command_Function * command;
};
Description
Generic_Command acts as a name for a command, and can name an internal command or a custom command.

Fields
cmdid
If this Generic_Command represents an internal command the cmdid field will have a value less than cmdid_count, and this field is the command id for the command.

command
If this Generic_Command does not represent an internal command the command field is the pointer to the custom command..


§3.4.56: User_Input

struct User_Input {
User_Input_Type_ID type;
bool32 abort;
union {
Key_Event_Data key;
Mouse_State mouse;
};
Generic_Command command;
};
Description
User_Input describes a user input event which can be either a key press or mouse event.

Fields
type
This field specifies whether the event was a key press or mouse event.

abort
This field indicates that an abort event has occurred and the command needs to shut down.

key
This field describes a key press event.

mouse
This field describes a mouse input event.

command
If this event would trigger a command, this field specifies what the command would be.

See Also
User_Input_Type_ID
Generic_Command

§3.4.57: Hook_ID

enum Hook_ID;
Description
Hook_IDs name the various hooks into 4coder, these hooks use the Hook_Function signature.

Values
hook_file_out_of_sync
TODO

hook_exit
TODO

hook_view_size_change
TODO

hook_type_count
See Also
Hook_Function

§3.4.58: Special_Hook_ID

enum Special_Hook_ID;
Description
Special_Hook_IDs name special hooks that use specialized signatures.

Values
special_hook_scroll_rule = hook_type_count
TODO

special_hook_new_file
TODO

special_hook_open_file
TODO

special_hook_save_file
TODO

special_hook_end_file
TODO

special_hook_command_caller
TODO

special_hook_input_filter
TODO

special_hook_start
TODO


§3.4.59: Binding_Unit_Type

enum Binding_Unit_Type;
Description
Values for the type field in the discriminated union Binding_Unit.

Values
unit_header
unit_map_begin
unit_binding
unit_callback
unit_inherit
unit_hook
See Also
Binding_Unit

§3.4.60: Map_ID

enum Map_ID;
Description
Values for built in command maps.

Values
mapid_global = (1 << 24)
mapid_file
mapid_nomap

§3.4.61: Binding_Unit

struct Binding_Unit {
Binding_Unit_Type type;
union {
struct {
int32_t total_size;
int32_t user_map_count;
int32_t error;
};
struct {
int32_t mapid;
int32_t replace;
int32_t bind_count;
};
struct {
int32_t mapid;
};
struct {
Key_Code code;
uint8_t modifiers;
int32_t command_id;
};
struct {
Key_Code code;
uint8_t modifiers;
Custom_Command_Function * func;
};
struct {
int32_t hook_id;
void * func;
};
};
};
Description
Describes a unit of information for setting up key bindings. A unit can set a key binding, switch the active map, set the inherited map, or set a hook.

Fields
type
total_size
user_map_count
error
mapid
replace
bind_count
mapid
code
modifiers
command_id
code
modifiers
func
hook_id
func

§4 String Library

§4.1 String Library Intro

Coming Soon

§4.2 String Function List

§4.3 String Function Descriptions

§4.3.1: char_is_slash

FSTRING_INLINE b32_4tech char_is_slash(char c)
Description
This call returns non-zero if c is \ or /.


§4.3.2: char_is_upper

FSTRING_INLINE b32_4tech char_is_upper(char c)
Description
If c is an uppercase letter this call returns true.


§4.3.3: char_is_upper_utf8

FSTRING_INLINE b32_4tech char_is_upper_utf8(char c)
Description
If c is an uppercase letter this call returns true.


§4.3.4: char_is_lower

FSTRING_INLINE b32_4tech char_is_lower(char c)
Description
If c is a lower letter this call returns true.


§4.3.5: char_is_lower_utf8

FSTRING_INLINE b32_4tech char_is_lower_utf8(u8_4tech c)
Description
If c is a lower letter this call returns true.


§4.3.6: char_to_upper

FSTRING_INLINE char char_to_upper(char c)
Description
If c is a lowercase letter this call returns the uppercase equivalent, otherwise it returns c.


§4.3.7: char_to_lower

FSTRING_INLINE char char_to_lower(char c)
Description
If c is an uppercase letter this call returns the lowercase equivalent, otherwise it returns c.


§4.3.8: char_is_whitespace

FSTRING_INLINE b32_4tech char_is_whitespace(char c)
Description
This call returns non-zero if c is whitespace.


§4.3.9: char_is_alpha_numeric

FSTRING_INLINE b32_4tech char_is_alpha_numeric(char c)
Description
This call returns non-zero if c is any alphanumeric character including underscore.


§4.3.10: char_is_alpha_numeric_utf8

FSTRING_INLINE b32_4tech char_is_alpha_numeric_utf8(u8_4tech c)
Description
This call returns non-zero if c is any alphanumeric character including underscore, or is a part of a UTF8 sequence outside of ASCII.


§4.3.11: char_is_alpha_numeric_true

FSTRING_INLINE b32_4tech char_is_alpha_numeric_true(char c)
Description
This call returns non-zero if c is any alphanumeric character no including underscore.


§4.3.12: char_is_alpha_numeric_true_utf8

FSTRING_INLINE b32_4tech char_is_alpha_numeric_true_utf8(u8_4tech c)
Description
This call returns non-zero if c is any alphanumeric character no including underscore.


§4.3.13: char_is_alpha

FSTRING_INLINE b32_4tech char_is_alpha(char c)
Description
This call returns non-zero if c is any alphabetic character including underscore.


§4.3.14: char_is_alpha_utf8

FSTRING_INLINE b32_4tech char_is_alpha_utf8(u8_4tech c)
Description
This call returns non-zero if c is any alphabetic character including underscore, or is a part of a UTF8 sequence outside of ASCII.


§4.3.15: char_is_alpha_true

FSTRING_INLINE b32_4tech char_is_alpha_true(char c)
Description
This call returns non-zero if c is any alphabetic character.


§4.3.16: char_is_alpha_true_utf8

FSTRING_INLINE b32_4tech char_is_alpha_true_utf8(u8_4tech c)
Description
This call returns non-zero if c is any alphabetic character, or is a part of a UTF8 sequence outside of ASCII.


§4.3.17: char_is_hex

FSTRING_INLINE b32_4tech char_is_hex(char c)
Description
This call returns non-zero if c is any valid hexadecimal digit.


§4.3.18: char_is_hex_utf8

FSTRING_INLINE b32_4tech char_is_hex_utf8(u8_4tech c)
Description
This call returns non-zero if c is any valid hexadecimal digit, or is a part of a UTF8 sequence outside of ASCII.


§4.3.19: char_is_numeric

FSTRING_INLINE b32_4tech char_is_numeric(char c)
Description
This call returns non-zero if c is any valid decimal digit.


§4.3.20: char_is_numeric_utf8

FSTRING_INLINE b32_4tech char_is_numeric_utf8(u8_4tech c)
Description
This call returns non-zero if c is any valid decimal digit, or is a part of a UTF8 sequence outside of ASCII.


§4.3.21: make_string_cap

FSTRING_INLINE String make_string_cap(
void *str,
i32_4tech size,
i32_4tech mem_size
)
Parameters
str
The str parameter provides the of memory with which the string shall operate.
size
The size parameter expresses the initial size of the string. If the memory does not already contain a useful string this should be zero.
mem_size
The mem_size parameter expresses the full size of the memory provided by str.
Description
This call returns the String created from the parameters.


§4.3.22: make_string

FSTRING_INLINE String make_string(
void *str,
i32_4tech size
)
Parameters
str
The str parameter provides the of memory with which the string shall operate.
size
The size parameter expresses the initial size of the string. If the memory does not already contain a useful string this should be zero. Since this version does not specify the size of the memory it is also assumed that this size is the maximum size of the memory.
Description
This call returns the String created from the parameters.


§4.3.23: make_lit_string

#define make_lit_string(s)
Description
This macro takes a literal string in quotes and uses it to create a String with the correct size and memory size. Strings created this way should usually not be mutated.


§4.3.24: make_fixed_width_string

#define make_fixed_width_string(s)
Description
This macro takes a local char array with a fixed width and uses it to create an empty String with the correct size and memory size to operate on the array.


§4.3.25: expand_str

#define expand_str(s)
Description
This macro is a helper for any calls that take a char*,integer pair to specify a string. This macro expands to both of those parameters from one String struct.


§4.3.26: str_size

FSTRING_LINK i32_4tech str_size(char *str)
Description
This call returns the number of bytes before a null terminator starting at str.


§4.3.27: make_string_slowly

FSTRING_INLINE String make_string_slowly(void *str)
Description
This call makes a string by counting the number of bytes before a null terminator and treating that as the size and memory size of the string.


§4.3.28: substr_tail

FSTRING_INLINE String substr_tail(
String str,
i32_4tech start
)
Description
This call creates a substring of str that starts with an offset from str's base. The new string uses the same underlying memory so both strings will see changes. Usually strings created this way should only go through immutable calls.


§4.3.29: substr

FSTRING_INLINE String substr(
String str,
i32_4tech start,
i32_4tech size
)
Description
This call creates a substring of str that starts with an offset from str's base, and has a fixed size. The new string uses the same underlying memory so both strings will see changes. Usually strings created this way should only go through immutable calls.


§4.3.30: skip_whitespace

FSTRING_LINK String skip_whitespace(String str)
Description
This call creates a substring that starts with the first non-whitespace character of str. Like other substr calls, the new string uses the underlying memory and so should usually be considered immutable.

See Also

§4.3.31: skip_whitespace_measure

FSTRING_LINK String skip_whitespace_measure(
String str,
i32_4tech *skip_length
)
Description
This call creates a substring that starts with the first non-whitespace character of str. Like other substr calls, the new string uses the underlying memory and so should usually be considered immutable.

See Also

§4.3.32: chop_whitespace

FSTRING_LINK String chop_whitespace(String str)
Description
This call creates a substring that ends with the last non-whitespace character of str. Like other substr calls, the new string uses the underlying memory and so should usually be considered immutable.

See Also

§4.3.33: skip_chop_whitespace

FSTRING_LINK String skip_chop_whitespace(String str)
Description
This call is equivalent to calling skip_whitespace and chop_whitespace together.

See Also

§4.3.34: skip_chop_whitespace_measure

FSTRING_LINK String skip_chop_whitespace_measure(
String str,
i32_4tech *skip_length
)
Description
This call is equivalent to calling skip_whitespace and chop_whitespace together.

See Also

§4.3.35: tailstr

FSTRING_INLINE String tailstr(String str)
Description
This call returns an empty String with underlying memory taken from the portion of str's memory that is not used.


§4.3.36: match_cc

FSTRING_LINK b32_4tech match_cc(
char *a,
char *b
)
Description
This call returns non-zero if a and b are equivalent.


§4.3.37: match_sc

FSTRING_LINK b32_4tech match_sc(
String a,
char *b
)
Description
This call returns non-zero if a and b are equivalent.


§4.3.38: match_cs

FSTRING_INLINE b32_4tech match_cs(
char *a,
String b
)
Description
This call returns non-zero if a and b are equivalent.


§4.3.39: match_ss

FSTRING_LINK b32_4tech match_ss(
String a,
String b
)
Description
This call returns non-zero if a and b are equivalent.


§4.3.40: match_part_ccl

FSTRING_LINK b32_4tech match_part_ccl(
char *a,
char *b,
i32_4tech *len
)
Parameters
len
If this call returns non-zero this parameter is used to output the length of b.
Description
This call is similar to a match call, except that it is permitted for a to be longer than b. In other words this call returns non-zero if b is a prefix of a.


§4.3.41: match_part_scl

FSTRING_LINK b32_4tech match_part_scl(
String a,
char *b,
i32_4tech *len
)
Parameters
len
If this call returns non-zero this parameter is used to output the length of b.
Description
This call is similar to a match call, except that it is permitted for a to be longer than b. In other words this call returns non-zero if b is a prefix of a.


§4.3.42: match_part_cc

FSTRING_INLINE b32_4tech match_part_cc(
char *a,
char *b
)
Parameters
len
If this call returns non-zero this parameter is used to output the length of b.
Description
This call is similar to a match call, except that it is permitted for a to be longer than b. In other words this call returns non-zero if b is a prefix of a.


§4.3.43: match_part_sc

FSTRING_INLINE b32_4tech match_part_sc(
String a,
char *b
)
Description
This call is similar to a match call, except that it is permitted for a to be longer than b. In other words this call returns non-zero if b is a prefix of a.


§4.3.44: match_part_cs

FSTRING_LINK b32_4tech match_part_cs(
char *a,
String b
)
Description
This call is similar to a match call, except that it is permitted for a to be longer than b. In other words this call returns non-zero if b is a prefix of a.


§4.3.45: match_part_ss

FSTRING_LINK b32_4tech match_part_ss(
String a,
String b
)
Description
This call is similar to a match call, except that it is permitted for a to be longer than b. In other words this call returns non-zero if b is a prefix of a.


§4.3.46: match_insensitive_cc

FSTRING_LINK b32_4tech match_insensitive_cc(
char *a,
char *b
)
Description
This call returns non-zero if a and b are equivalent under case insensitive comparison.


§4.3.47: match_insensitive_sc

FSTRING_LINK b32_4tech match_insensitive_sc(
String a,
char *b
)
Description
This call returns non-zero if a and b are equivalent under case insensitive comparison.


§4.3.48: match_insensitive_cs

FSTRING_INLINE b32_4tech match_insensitive_cs(
char *a,
String b
)
Description
This call returns non-zero if a and b are equivalent under case insensitive comparison.


§4.3.49: match_insensitive_ss

FSTRING_LINK b32_4tech match_insensitive_ss(
String a,
String b
)
Description
This call returns non-zero if a and b are equivalent under case insensitive comparison.


§4.3.50: match_part_insensitive_ccl

FSTRING_LINK b32_4tech match_part_insensitive_ccl(
char *a,
char *b,
i32_4tech *len
)
Parameters
len
If this call returns non-zero this parameter is used to output the length of b.
Description
This call performs the same partial matching rule as match_part under case insensitive comparison.

See Also

§4.3.51: match_part_insensitive_scl

FSTRING_LINK b32_4tech match_part_insensitive_scl(
String a,
char *b,
i32_4tech *len
)
Parameters
len
If this call returns non-zero this parameter is used to output the length of b.
Description
This call performs the same partial matching rule as match_part under case insensitive comparison.

See Also

§4.3.52: match_part_insensitive_cc

FSTRING_INLINE b32_4tech match_part_insensitive_cc(
char *a,
char *b
)
Description
This call performs the same partial matching rule as match_part under case insensitive comparison.

See Also

§4.3.53: match_part_insensitive_sc

FSTRING_INLINE b32_4tech match_part_insensitive_sc(
String a,
char *b
)
Description
This call performs the same partial matching rule as match_part under case insensitive comparison.

See Also

§4.3.54: match_part_insensitive_cs

FSTRING_LINK b32_4tech match_part_insensitive_cs(
char *a,
String b
)
Description
This call performs the same partial matching rule as match_part under case insensitive comparison.

See Also

§4.3.55: match_part_insensitive_ss

FSTRING_LINK b32_4tech match_part_insensitive_ss(
String a,
String b
)
Description
This call performs the same partial matching rule as match_part under case insensitive comparison.

See Also

§4.3.56: compare_cc

FSTRING_LINK i32_4tech compare_cc(
char *a,
char *b
)
Description
This call returns zero if a and b are equivalent, it returns negative if a sorts before b alphabetically, and positive if a sorts after b alphabetically.


§4.3.57: compare_sc

FSTRING_LINK i32_4tech compare_sc(
String a,
char *b
)
Description
This call returns zero if a and b are equivalent, it returns negative if a sorts before b alphabetically, and positive if a sorts after b alphabetically.


§4.3.58: compare_cs

FSTRING_INLINE i32_4tech compare_cs(
char *a,
String b
)
Description
This call returns zero if a and b are equivalent, it returns negative if a sorts before b alphabetically, and positive if a sorts after b alphabetically.


§4.3.59: compare_ss

FSTRING_LINK i32_4tech compare_ss(
String a,
String b
)
Description
This call returns zero if a and b are equivalent, it returns negative if a sorts before b alphabetically, and positive if a sorts after b alphabetically.


§4.3.60: find_c_char

FSTRING_LINK i32_4tech find_c_char(
char *str,
i32_4tech start,
char character
)
Parameters
str
The str parameter provides a null terminated string to search.
start
The start parameter provides the index of the first character in str to search.
character
The character parameter provides the character for which to search.
Description
This call returns the index of the first occurance of character, or the size of the string if the character is not found.


§4.3.61: find_s_char

FSTRING_LINK i32_4tech find_s_char(
String str,
i32_4tech start,
char character
)
Parameters
str
The str parameter provides a string to search.
start
The start parameter provides the index of the first character in str to search.
character
The character parameter provides the character for which to search.
Description
This call returns the index of the first occurance of character, or the size of the string if the character is not found.


§4.3.62: rfind_s_char

FSTRING_LINK i32_4tech rfind_s_char(
String str,
i32_4tech start,
char character
)
Parameters
str
The str parameter provides a string to search.
start
The start parameter provides the index of the first character in str to search.
character
The character parameter provides the character for which to search.
Description
This call looks for the largest index less than or equal to the start position where the given character occurs. If the index is found it is returned otherwise -1 is returned.


§4.3.63: find_c_chars

FSTRING_LINK i32_4tech find_c_chars(
char *str,
i32_4tech start,
char *characters
)
Parameters
str
The str parameter provides a null terminated string to search.
start
The start parameter provides the index of the first character in str to search.
character
The characters parameter provides a null terminated array of characters for which to search.
Description
This call returns the index of the first occurance of a character in the characters array, or the size of the string if no such character is not found.


§4.3.64: find_s_chars

FSTRING_LINK i32_4tech find_s_chars(
String str,
i32_4tech start,
char *characters
)
Parameters
str
The str parameter provides a string to search.
start
The start parameter provides the index of the first character in str to search.
character
The characters parameter provides a null terminated array of characters for which to search.
Description
This call returns the index of the first occurance of a character in the characters array, or the size of the string if no such character is not found.


§4.3.65: find_substr_c

FSTRING_LINK i32_4tech find_substr_c(
char *str,
i32_4tech start,
String seek
)
Parameters
str
The str parameter provides a null terminated string to search.
start
The start parameter provides the index of the first character in str to search.
seek
The seek parameter provides a string to find in str.
Description
This call returns the index of the first occurance of the seek substring in str or the size of str if no such substring in str is found.


§4.3.66: find_substr_s

FSTRING_LINK i32_4tech find_substr_s(
String str,
i32_4tech start,
String seek
)
Parameters
str
The str parameter provides a string to search.
start
The start parameter provides the index of the first character in str to search.
seek
The seek parameter provides a string to find in str.
Description
This call returns the index of the first occurance of the seek substring in str or the size of str if no such substring in str is found.


§4.3.67: rfind_substr_s

FSTRING_LINK i32_4tech rfind_substr_s(
String str,
i32_4tech start,
String seek
)
Parameters
str
The str parameter provides a string to search.
start
The start parameter provides the index of the first character in str to search.
seek
The seek parameter provides a string to find in str.
Description
This call returns the index of the last occurance of the seek substring in str or -1 if no such substring in str is found.


§4.3.68: find_substr_insensitive_c

FSTRING_LINK i32_4tech find_substr_insensitive_c(
char *str,
i32_4tech start,
String seek
)
Parameters
str
The str parameter provides a null terminated string to search.
start
The start parameter provides the index of the first character in str to search.
seek
The seek parameter provides a string to find in str.
Description
This call acts as find_substr under case insensitive comparison.

See Also

§4.3.69: find_substr_insensitive_s

FSTRING_LINK i32_4tech find_substr_insensitive_s(
String str,
i32_4tech start,
String seek
)
Parameters
str
The str parameter provides a string to search.
start
The start parameter provides the index of the first character in str to search.
seek
The seek parameter provides a string to find in str.
Description
This call acts as find_substr under case insensitive comparison.

See Also

§4.3.70: has_substr_c

FSTRING_INLINE b32_4tech has_substr_c(
char *s,
String seek
)
Description
This call returns non-zero if the string s contains a substring equivalent to seek.


§4.3.71: has_substr_s

FSTRING_INLINE b32_4tech has_substr_s(
String s,
String seek
)
Description
This call returns non-zero if the string s contains a substring equivalent to seek.


§4.3.72: has_substr_insensitive_c

FSTRING_INLINE b32_4tech has_substr_insensitive_c(
char *s,
String seek
)
Description
This call returns non-zero if the string s contains a substring equivalent to seek under case insensitive comparison.


§4.3.73: has_substr_insensitive_s

FSTRING_INLINE b32_4tech has_substr_insensitive_s(
String s,
String seek
)
Description
This call returns non-zero if the string s contains a substring equivalent to seek under case insensitive comparison.


§4.3.74: copy_fast_unsafe_cc

FSTRING_LINK i32_4tech copy_fast_unsafe_cc(
char *dest,
char *src
)
Description
This call performs a copy from the src buffer to the dest buffer. The copy does not stop until a null terminator is found in src. There is no safety against overrun so dest must be large enough to contain src. The null terminator is not written to dest. This call returns the number of bytes coppied to dest.


§4.3.75: copy_fast_unsafe_cs

FSTRING_LINK i32_4tech copy_fast_unsafe_cs(
char *dest,
String src
)
Description
This call performs a copy from the src string to the dest buffer. The copy does not stop until src.size characters are coppied. There is no safety against overrun so dest must be large enough to contain src. The null terminator is not written to dest. This call returns the number of bytes coppied to dest.


§4.3.76: copy_checked_ss

FSTRING_LINK b32_4tech copy_checked_ss(
String *dest,
String src
)
Description
This call performs a copy from the src string to the dest string. The memory_size of dest is checked before any coppying is done. This call returns non-zero on a successful copy.


§4.3.77: copy_checked_cs

FSTRING_LINK b32_4tech copy_checked_cs(
char *dest,
i32_4tech dest_cap,
String src
)
Description
This call performs a copy from the src string to the dest string. The value dest_cap is checked before any coppying is done. This call returns non-zero on a successful copy.


§4.3.78: copy_partial_sc

FSTRING_LINK b32_4tech copy_partial_sc(
String *dest,
char *src
)
Description
This call performs a copy from the src buffer to the dest string. The memory_size of dest is checked if the entire copy cannot be performed, as many bytes as possible are coppied to dest. This call returns non-zero if the entire string is coppied to dest.


§4.3.79: copy_partial_ss

FSTRING_LINK b32_4tech copy_partial_ss(
String *dest,
String src
)
Description
This call performs a copy from the src string to the dest string. The memory_size of dest is checked. If the entire copy cannot be performed, as many bytes as possible are coppied to dest. This call returns non-zero if the entire string is coppied to dest.


§4.3.80: copy_partial_cs

FSTRING_LINK b32_4tech copy_partial_cs(
char *dest,
i32_4tech dest_cap,
String src
)
Description
This call performs a copy from the src string to the dest string. The value dest_cap is checked. If the entire copy cannot be performed, as many bytes as possible are coppied to dest. This call returns non-zero if the entire string is coppied to dest.


§4.3.81: copy_cc

FSTRING_INLINE i32_4tech copy_cc(
char *dest,
char *src
)
Description
This call performs a copy from src to dest equivalent to copy_fast_unsafe.

See Also

§4.3.82: copy_ss

FSTRING_INLINE void copy_ss(
String *dest,
String src
)
Description
This call performs a copy from src to dest equivalent to copy_checked.

See Also

§4.3.83: copy_sc

FSTRING_INLINE void copy_sc(
String *dest,
char *src
)
Description
This call performs a copy from src to dest equivalent to copy_partial.

See Also

§4.3.84: append_checked_ss

FSTRING_LINK b32_4tech append_checked_ss(
String *dest,
String src
)
Description
This call checks if there is enough space in dest's underlying memory to append src onto dest. If there is src is appended and the call returns non-zero.


§4.3.85: append_partial_sc

FSTRING_LINK b32_4tech append_partial_sc(
String *dest,
char *src
)
Description
This call attemps to append as much of src into the space in dest's underlying memory as possible. If the entire string is appended the call returns non-zero.


§4.3.86: append_partial_ss

FSTRING_LINK b32_4tech append_partial_ss(
String *dest,
String src
)
Description
This call attemps to append as much of src into the space in dest's underlying memory as possible. If the entire string is appended the call returns non-zero.


§4.3.87: append_s_char

FSTRING_LINK b32_4tech append_s_char(
String *dest,
char c
)
Description
This call attemps to append c onto dest. If there is space left in dest's underlying memory the character is appended and the call returns non-zero.


§4.3.88: append_ss

FSTRING_INLINE b32_4tech append_ss(
String *dest,
String src
)
Description
This call is equivalent to append_partial.

See Also

§4.3.89: append_sc

FSTRING_INLINE b32_4tech append_sc(
String *dest,
char *src
)
Description
This call is equivalent to append_partial.

See Also

§4.3.90: terminate_with_null

FSTRING_LINK b32_4tech terminate_with_null(String *str)
Description
This call attemps to append a null terminator onto str without effecting the size of str. This is usually called when the time comes to pass the the string to an API that requires a null terminator. This call returns non-zero if there was a spare byte in the strings underlying memory.


§4.3.91: append_padding

FSTRING_LINK b32_4tech append_padding(
String *dest,
char c,
i32_4tech target_size
)
Description
This call pads out dest so that it has a size of target_size by appending the padding character c until the target size is achieved. This call returns non-zero if dest does not run out of space in the underlying memory.


§4.3.92: replace_char

FSTRING_LINK void replace_char(
String *str,
char replace,
char with
)
Parameters
str
The str parameter provides the string in which replacement shall be performed.
replace
The replace character specifies which character should be replaced.
with
The with character specifies what to write into the positions where replacement occurs.
Description
This call replaces all occurances of character in str with another character.


§4.3.93: to_lower_cc

FSTRING_LINK void to_lower_cc(
char *src,
char *dst
)
Parameters
src
The source string to conver to lowercase. This string must be null terminated.
dst
The destination buffer to receive the converted string. This must be large enough to contain all of src and a null terminator.
Description
Rewrites the string in src into dst with all letters lowercased. src and dst should not overlap with the exception that src and dst may be exactly equal in order to convert the string in place.


§4.3.94: to_lower_ss

FSTRING_LINK void to_lower_ss(
String *dst,
String src
)
Parameters
dst
The destination buffer to receive the converted string. This must have a capacity of at least the size of src.
src
The source string to conver to lowercase.
Description
Rewrites the string in src into dst. src and dst should not overlap with the exception that src and dst may be exactly equal in order to convert the string in place.


§4.3.95: to_lower_s

FSTRING_LINK void to_lower_s(String *str)
Parameters
str
The string to be converted to all lowercase.
Description
This version of to_lower converts str to lowercase in place.


§4.3.96: to_upper_cc

FSTRING_LINK void to_upper_cc(
char *src,
char *dst
)
Parameters
src
The source string to convert to uppercase. This string must be null terminated.
dst
The destination buffer to receive the converted string. This must be large enough to contain all of src and a null terminator.
Description
Rewrites the string in src into dst. src and dst should not overlap with the exception that src and dst may be exactly equal in order to convert the string in place.


§4.3.97: to_upper_ss

FSTRING_LINK void to_upper_ss(
String *dst,
String src
)
Parameters
dst
The destination buffer to receive the converted string. This must have a capacity of at least the size of src.
src
The source string to convert to uppercase.
Description
Rewrites the string in src into dst. src and dst should not overlap with the exception that src and dst may be exactly equal in order to convert the string in place.


§4.3.98: to_upper_s

FSTRING_LINK void to_upper_s(String *str)
Parameters
str
The string to be converted to all uppercase.
Description
This version of to_upper converts str to uppercase in place.


§4.3.99: to_camel_cc

FSTRING_LINK void to_camel_cc(
char *src,
char *dst
)
Parameters
src
The source string to convert to camel case.
dst
The destination buffer to receive the converted string. This must be large enough to contain all of src and a null terminator.
Description
Rewrites the string in src into dst. src and dst should not overlap with the exception that src and dst may be exactly equal in order to convert the string in place.


§4.3.100: int_to_str_size

FSTRING_LINK i32_4tech int_to_str_size(i32_4tech x)
Description
This call returns the number of bytes required to represent x as a string.


§4.3.101: int_to_str

FSTRING_LINK b32_4tech int_to_str(
String *dest,
i32_4tech x
)
Description
This call writes a string representation of x into dest. If there is enough space in dest this call returns non-zero.


§4.3.102: append_int_to_str

FSTRING_LINK b32_4tech append_int_to_str(
String *dest,
i32_4tech x
)
Description
This call appends a string representation of x onto dest. If there is enough space in dest this call returns non-zero.


§4.3.103: u64_to_str_size

FSTRING_LINK i32_4tech u64_to_str_size(uint64_t x)
Description
This call returns the number of bytes required to represent x as a string.


§4.3.104: u64_to_str

FSTRING_LINK b32_4tech u64_to_str(
String *dest,
uint64_t x
)
Description
This call writes a string representation of x into dest. If there is enough space in dest this call returns non-zero.


§4.3.105: append_u64_to_str

FSTRING_LINK b32_4tech append_u64_to_str(
String *dest,
uint64_t x
)
Description
This call appends a string representation of x onto dest. If there is enough space in dest this call returns non-zero.


§4.3.106: float_to_str_size

FSTRING_LINK i32_4tech float_to_str_size(float x)
Description
This call returns the number of bytes required to represent x as a string.


§4.3.107: append_float_to_str

FSTRING_LINK b32_4tech append_float_to_str(
String *dest,
float x
)
Description
This call writes a string representation of x into dest. If there is enough space in dest this call returns non-zero.


§4.3.108: float_to_str

FSTRING_LINK b32_4tech float_to_str(
String *dest,
float x
)
Description
This call appends a string representation of x onto dest. If there is enough space in dest this call returns non-zero.


§4.3.109: str_is_int_c

FSTRING_LINK i32_4tech str_is_int_c(char *str)
Description
If str is a valid string representation of an integer, this call returns non-zero


§4.3.110: str_is_int_s

FSTRING_LINK b32_4tech str_is_int_s(String str)
Description
If str is a valid string representation of an integer, this call returns non-zero.


§4.3.111: str_to_int_c

FSTRING_LINK i32_4tech str_to_int_c(char *str)
Description
If str is a valid string representation of an integer, this call will return the integer represented by the string. Otherwise this call returns zero.


§4.3.112: str_to_int_s

FSTRING_LINK i32_4tech str_to_int_s(String str)
Description
If str represents a valid string representation of an integer, this call will return the integer represented by the string. Otherwise this call returns zero.


§4.3.113: hexchar_to_int

FSTRING_LINK i32_4tech hexchar_to_int(char c)
Description
If c is a valid hexadecimal digit [0-9a-fA-F] this call returns the value of the integer value of the digit. Otherwise the return is some nonsense value.


§4.3.114: int_to_hexchar

FSTRING_LINK char int_to_hexchar(i32_4tech x)
Description
If x is in the range [0,15] this call returns the equivalent lowercase hexadecimal digit. Otherwise the return is some nonsense value.


§4.3.115: hexstr_to_int

FSTRING_LINK u32_4tech hexstr_to_int(String str)
Description
This call interprets str has a hexadecimal representation of an integer and returns the represented integer value.


§4.3.116: color_to_hexstr

FSTRING_LINK b32_4tech color_to_hexstr(
String *s,
u32_4tech color
)
Description
This call fills s with the hexadecimal representation of the color. If there is enough memory in s to represent the color this call returns non-zero.


§4.3.117: hexstr_to_color

FSTRING_LINK b32_4tech hexstr_to_color(
String s,
u32_4tech *out
)
Description
This call interprets s as a color and writes the 32-bit integer representation into out.


§4.3.118: reverse_seek_slash_pos

FSTRING_LINK i32_4tech reverse_seek_slash_pos(
String str,
i32_4tech pos
)
Description
This call searches for a slash in str by starting pos bytes from the end and going backwards.


§4.3.119: reverse_seek_slash

FSTRING_INLINE i32_4tech reverse_seek_slash(String str)
Description
This call searches for a slash in str by starting at the end and going backwards.


§4.3.120: front_of_directory

FSTRING_INLINE String front_of_directory(String dir)
Description
This call returns a substring of dir containing only the file name or folder name furthest to the right in the directory.

See Also

§4.3.121: path_of_directory

FSTRING_INLINE String path_of_directory(String dir)
Description
This call returns a substring of dir containing the whole path except for the final file or folder name.

See Also

§4.3.122: set_last_folder_sc

FSTRING_LINK b32_4tech set_last_folder_sc(
String *dir,
char *folder_name,
char slash
)
Parameters
dir
The dir parameter is the directory string in which to set the last folder in the directory.
folder_name
The folder_name parameter is a null terminated string specifying the name to set at the end of the directory.
slash
The slash parameter specifies what slash to use between names in the directory.
Description
This call deletes the last file name or folder name in the dir string and appends the new provided one. If there is enough memory in dir this call returns non-zero.


§4.3.123: set_last_folder_ss

FSTRING_LINK b32_4tech set_last_folder_ss(
String *dir,
String folder_name,
char slash
)
Parameters
dir
The dir parameter is the directory string in which to set the last folder in the directory.
folder_name
The folder_name parameter is a string specifying the name to set at the end of the directory.
slash
The slash parameter specifies what slash to use between names in the directory.
Description
This call deletes the last file name or folder name in the dir string and appends the new provided one. If there is enough memory in dir this call returns non-zero.


§4.3.124: file_extension

FSTRING_LINK String file_extension(String str)
Description
This call returns a substring containing only the file extension of the provided filename.

See Also

§4.3.125: remove_extension

FSTRING_LINK b32_4tech remove_extension(String *str)
Description
This call attemps to delete a file extension off the end of a filename. This call returns non-zero on success.


§4.3.126: remove_last_folder

FSTRING_LINK b32_4tech remove_last_folder(String *str)
Description
This call attemps to delete a folder or filename off the end of a path string. This call returns non-zero on success.


§4.3.127: string_set_match_table

FSTRING_LINK b32_4tech string_set_match_table(
void *str_set,
i32_4tech item_size,
i32_4tech count,
String str,
i32_4tech *match_index
)
Parameters
str_set
The str_set parameter may be an array of any type. It should point at the String in the first element of the array.
count
The item_size parameter should describe the "stride" from one String to the next, in other words it should be the size of one 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.128: string_set_match

FSTRING_LINK b32_4tech string_set_match(
String *str_set,
i32_4tech count,
String str,
i32_4tech *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

§4.3.129: get_first_double_line

FSTRING_LINK String get_first_double_line(String source)
Parameters
source
the source string accross which a 'double line' iteration will occur
Return
The returned value is the first 'double line' in the source string.
Description
A 'double line' is a string of characters delimited by two new line characters. This call begins an iteration over all the double lines in the given source string.

See Also

§4.3.130: get_next_double_line

FSTRING_LINK String get_next_double_line(
String source,
String line
)
Parameters
source
the source string accross which the 'double line' iteration is occurring
line
the value returned from the previous call of get_first_double_line or get_next_double_line
Return
The returned value is the first 'double line' in the source string.
See Also

§4.3.131: get_next_word

FSTRING_LINK String get_next_word(
String source,
String prev_word
)
Parameters
source
the source string accross which the 'word' iteration is occurring
line
the value returned from the previous call of get_first_word or get_next_word
Return
The returned value is the first 'word' in the source string.
See Also

§4.3.132: get_first_word

FSTRING_LINK String get_first_word(String source)
Parameters
source
the source string accross which a 'word' iteration will occur
Return
The returned value is the first 'word' in the source string.
Description
A 'word' is a string of characters delimited by whitespace or parentheses. This call begins an iteration over all the double lines in the given source string.

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 Type List

§5.4 Lexer Function Descriptions

§5.4.1: cpp_get_table_memory_size_null_terminated

FCPP_LINK umem_4tech cpp_get_table_memory_size_null_terminated(
char **str_array,
u32_4tech str_count
)
Parameters
str_array
An array of null terminated strings that specifies every string that will be put in the table.
str_count
The number of strings in str_array.
Return
Returns the memory size, in bytes, needed to allocate a table for the given strings.

§5.4.2: cpp_get_table_memory_size_string_lengths

FCPP_LINK umem_4tech cpp_get_table_memory_size_string_lengths(
u32_4tech *str_len,
u32_4tech byte_stride,
u32_4tech str_count
)
Parameters
str_len
An array specifying the length of every string that will be put in the table.
byte_stride
The distance in bytes between each length element.
str_count
The number of length elements in the array.
Return
Returns the memory size, in bytes, needed to allocate a table for the given strings.

§5.4.3: cpp_make_table

FCPP_LINK Cpp_Keyword_Table cpp_make_table(
char **str_array,
u32_4tech str_stride,
u32_4tech *len_array,
u32_4tech len_stride,
u32_4tech *type_array,
u32_4tech type_stride,
u32_4tech str_count,
void *memory,
umem_4tech memsize
)
Parameters
str_array
An array of strings to be put in the new table.
str_stride
The number of bytes separating each string pointer in the array.
len_array
An optional array of string lengths. If this array is specified it should have the same number of elements as str_array. If this is not specified the strings in str_array should be null terminated.
len_stride
If len_array is specified this indicates the number of bytes separating each length element in the array.
type_array
An optional array of type values. If this array is specified it should have the same number of elements as str_array. If this is not specified the value of each keyword type integer will default to CPP_TOKEN_KEY_OTHER.
type_stride
If type_array is specified this indicates the number of bytes separating each type integer element in the array.
str_count
Specifies the number of strings in str_array, and any of the used optional arrays.
memory
A chunk of memory set aside for this table. This should have at least as much memory as returned by one of the cpp_get_table_memory_size functions.
memsize
The number of bytes reserved at the memory address for the keyword table.
Return
On success returns a keyword table struct built on the memory chunk.
Description
This call reads in an array of strings, either null terminated or not, and optionally an array of types, and constructs a compact list of the strings and types, and a hashed lookup table. As long as the table will be in use by the lexer the memory chunk passed in is used by the table. The memory may be free or otherwise recycled if the table will not be used again.

See Also

§5.4.4: cpp_get_table_memory_size_default

FCPP_LINK umem_4tech cpp_get_table_memory_size_default(Cpp_Word_Table_Type type)
Parameters
type
Specifies for which slot of the parser context to get a default result.
Return
Returns the memory size, in bytes, needed to allocate a table for the given default slot.
See Also

§5.4.5: cpp_make_table_default

FCPP_LINK Cpp_Keyword_Table cpp_make_table_default(
Cpp_Word_Table_Type type,
void *memory,
umem_4tech memsize
)
Parameters
type
Specifies for which slot of the parser context to get a default result.
memory
A chunk of memory set aside for this table. This should have at least as much memory as returned by one of the cpp_get_table_memory_size functions.
memsize
The number of bytes reserved at the memory address for the keyword table.
Return
On success returns a keyword table struct built on the memory chunk.
Description
Works as cpp_make_table for a default C++ keyword set.

See Also

§5.4.6: cpp_get_token

FCPP_LINK Cpp_Get_Token_Result cpp_get_token(
Cpp_Token_Array array,
i32_4tech pos
)
Parameters
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 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. The returned index can be -1 if the position is before the first token.

See Also

§5.4.7: cpp_lex_step

FCPP_LINK Cpp_Lex_Result cpp_lex_step(
Cpp_Lex_Data *S_ptr,
char *chunk,
i32_4tech size,
i32_4tech full_size,
Cpp_Token_Array *token_array_out,
i32_4tech max_tokens_out
)
Parameters
S_ptr
The lexer state. Go to the Cpp_Lex_Data section to see how to initialize the state.
chunk
The first or next chunk of the file being lexed.
size
The number of bytes in the chunk including the null terminator if the chunk ends in a null terminator. If the chunk ends in a null terminator the system will interpret it as the end of the file.
full_size
If the final chunk is not null terminated this parameter should specify the length of the file in bytes. To rely on an eventual null terminator use HAS_NULL_TERM for this parameter.
token_array_out
The token array structure that will receive the tokens output by the lexer.
max_tokens_out
The maximum number of tokens to be output to the token array. To rely on the max built into the token array pass NO_OUT_LIMIT here.
Description
This call is the primary interface of the lexing system. It is quite general so it can be used in a lot of different ways. I will explain the general rules first, and then give some examples of common ways it might be used.

First a lexing state, Cpp_Lex_Data, must be initialized. The file to lex must be read into N contiguous chunks of memory. An output Cpp_Token_Array must be allocated and initialized with the appropriate count and max_count values. Then each chunk of the file must be passed to cpp_lex_step in order using the same lexing state for each call. Every time a call to cpp_lex_step returns LexResult_NeedChunk, the next call to cpp_lex_step should use the next chunk. If the return is some other value, the lexer hasn't finished with the current chunk and it sopped for some other reason, so the same chunk should be used again in the next call.

If the file chunks contain a null terminator the lexer will return LexResult_Finished when it finds this character. At this point calling the lexer again with the same state will result in an error. If you do not have a null terminated chunk to end the file, you may instead pass the exact size in bytes of the entire file to the full_size parameter and it will automatically handle the termination of the lexing state when it has read that many bytes. If a full_size is specified and the system terminates for having seen that many bytes, it will return LexResult_Finished. If a full_size is specified and a null character is read before the total number of bytes have been read the system will still terminate as usual and return LexResult_Finished.

If the system has filled the entire output array it will return LexResult_NeedTokenMemory. When this happens if you want to continue lexing the file you can grow the token array, or switch to a new output array and then call cpp_lex_step again with the chunk that was being lexed and the new output. You can also specify a max_tokens_out which is limits how many new tokens will be added to the token array. Even if token_array_out still had more space to hold tokens, if the max_tokens_out limit is hit, the lexer will stop and return LexResult_HitTokenLimit. If this happens there is still space left in the token array, so you can resume simply by calling cpp_lex_step again with the same chunk and the same output array. Also note that, unlike the chunks which must only be replaced when the system says it needs a chunk. You may switch to or modify the output array in between calls as much as you like.

The most basic use of this system is to get it all done in one big chunk and try to allocate a nearly "infinite" output array so that it will not run out of memory. This way you can get the entire job done in one call and then just assert to make sure it returns LexResult_Finished to you:



Cpp_Token_Array lex_file(char *file_name){
File_Data file = read_whole_file(file_name);

Cpp_Lex_Data lex_state = cpp_lex_data_init(false);

Cpp_Token_Array array = {0};
array.tokens = (Cpp_Token*)malloc(1 << 20); // hopefully big enough
array.max_count = (1 << 20)/sizeof(Cpp_Token);

Cpp_Lex_Result result = cpp_lex_step(&lex_state, file.data, file.size, file.size, &array, NO_OUT_LIMIT);
Assert(result == LexResult_Finished);

return(array);
}
See Also

§5.4.8: cpp_lex_data_init

FCPP_LINK Cpp_Lex_Data cpp_lex_data_init(
b32_4tech ignore_string_delims,
Cpp_Keyword_Table keywords,
Cpp_Keyword_Table preprocessor_words
)
Parameters
ignore_string_delims
TODO
keywords
TODO
preprocessor_words
TODO
Return
A brand new lex state setup to lex from the beginning of the file.
Description
Creates a new lex state in the form of a Cpp_Lex_Data struct and returns the struct.


§5.4.9: cpp_rebase_tables

FCPP_LINK void cpp_rebase_tables(
Cpp_Lex_Data *data,
void *old_base,
void *new_base
)
Parameters
data
The lex data in which to perform the rebase.
old_base
The old base memory address in which the tables were stored.
new_base
The new base memory address in which the tables are or will be stored.
Description
Updates the base address pointers for the all the tables in the lex data as if the data in the original memory chunk old_base was copied to new_base.


§5.4.10: cpp_get_relex_range

FCPP_LINK Cpp_Relex_Range cpp_get_relex_range(
Cpp_Token_Array *array,
i32_4tech start_pos,
i32_4tech end_pos
)
Parameters
array
A pointer to the token array that will be modified by the relex, this array should already contain the tokens for the previous state of the file.
start_pos
The start position of the edited region of the file. The start and end points are based on the edited region of the file before the edit.
end_pos
The end position of the edited region of the file. In particular, end_pos is the first character after the edited region not effected by the edit. Thus if the edited region contained one character end_pos - start_pos should equal 1. The start and end points are based on the edited region of the file before the edit.

§5.4.11: cpp_relex_init

FCPP_LINK Cpp_Relex_Data cpp_relex_init(
Cpp_Token_Array *array,
i32_4tech start_pos,
i32_4tech end_pos,
i32_4tech character_shift_amount,
b32_4tech ignore_string_delims,
Cpp_Keyword_Table keywords,
Cpp_Keyword_Table preprocessor_words
)
Parameters
array
A pointer to the token array that will be modified by the relex, this array should already contain the tokens for the previous state of the file.
start_pos
The start position of the edited region of the file. The start and end points are based on the edited region of the file before the edit.
end_pos
The end position of the edited region of the file. In particular, end_pos is the first character after the edited region not effected by the edit. Thus if the edited region contained one character end_pos - start_pos should equal 1. The start and end points are based on the edited region of the file before the edit.
character_shift_amount
The shift in the characters after the edited region.
ignore_string_delims
TODO
keywords
TODO
preprocessor_words
TODO
Return
Returns a partially initialized relex state.
Description
This call does the first setup step of initializing a relex state. To finish initializing the relex state you must tell the state about the positioning of the first chunk it will be fed. There are two methods of doing this, the direct method is with cpp_relex_declare_first_chunk_position, the method that is often more convenient is with cpp_relex_is_start_chunk. If the file is not chunked the second step of initialization can be skipped.

See Also

§5.4.12: cpp_relex_start_position

FCPP_LINK i32_4tech cpp_relex_start_position(Cpp_Relex_Data *S_ptr)
Parameters
S_ptr
Return
Returns the first position in the file the relexer wants to read. This is usually a position slightly earlier than the start_pos provided as the edit range.
Description
After doing the first stage of initialization this call is useful for figuring out what chunk of the file to feed to the lexer first. It should be a chunk that contains the position returned by this call.

See Also

§5.4.13: cpp_relex_declare_first_chunk_position

FCPP_LINK void cpp_relex_declare_first_chunk_position(
Cpp_Relex_Data *S_ptr,
i32_4tech position
)
Parameters
S_ptr
position
The start position of the first chunk that will be fed to the relex process.
Description
To initialize the relex system completely, the system needs to know how the characters in the first file line up with the file's absolute layout. This call declares where the first chunk's start position is in the absolute file layout, and the system infers the alignment from that. For this method to work the starting position of the relexing needs to be inside the first chunk. To get the relexers starting position call cpp_relex_start_position.

See Also

§5.4.14: cpp_relex_is_start_chunk

FCPP_LINK i32_4tech cpp_relex_is_start_chunk(
Cpp_Relex_Data *S_ptr,
char *chunk,
i32_4tech chunk_size
)
Parameters
S_ptr
chunk
The chunk to check.
chunk_size
The size of the chunk to check.
Return
Returns non-zero if the passed in chunk should be used as the first chunk for lexing.
Description
With this method, once a state is initialized, each chunk can be fed in one after the other in the order they appear in the absolute file layout. When this call returns non-zero it means that the chunk that was passed in on that call should be used in the first call to cpp_relex_step. If, after trying all of the chunks, they all return zero, pass in NULL for chunk and 0 for chunk_size to tell the system that all possible chunks have already been tried, and then use those values again in the one and only call to cpp_relex_step.

See Also

§5.4.15: cpp_relex_step

FCPP_LINK Cpp_Lex_Result cpp_relex_step(
Cpp_Relex_Data *S_ptr,
char *chunk,
i32_4tech chunk_size,
i32_4tech full_size,
Cpp_Token_Array *array,
Cpp_Token_Array *relex_array
)
Parameters
S_ptr
A pointer to a fully initiazed relex state.
chunk
A chunk of the edited file being relexed.
chunk_size
The size of the current chunk.
full_size
The full size of the edited file.
array
A pointer to a token array that contained the original tokens before the edit.
relex_array
A pointer to a token array for spare space. The capacity of the relex_array determines how far the relex process can go. If it runs out, the process can be continued if the same relex_array is extended without losing the tokens it contains. To get an appropriate capacity for relex_array, you can get the range of tokens that the relex operation is likely to traverse by looking at the result from cpp_get_relex_range.
Description
When a file has already been lexed, and then it is edited in a small local way, rather than lexing the new file all over again, cpp_relex_step can try to find just the range of tokens that need to be updated and fix them in.

First the lex state must be initialized (cpp_relex_init). Then one or more calls to cpp_relex_step will start editing the array and filling out the relex_array. The return value of cpp_relex_step indicates whether the relex was successful or was interrupted and if it was interrupted, what the system needs to resume.

LexResult_Finished indicates that the relex engine finished successfully.

LexResult_NeedChunk indicates that the system needs the next chunk of the file.

LexResult_NeedTokenMemory indicates that the relex_array has reached capacity, and that it needs to be extended if it is going to continue. Sometimes in this case it is better to stop and just lex the entire file normally, because there are a few cases where a small local change effects a long range of the lexers output.

The relex operation can be closed in one of two ways. If the LexResult_Finished value has been returned by this call, then to complete the edits to the array make sure the original array has enough capacity to store the final result by calling cpp_relex_get_new_count. Then the operation can be finished successfully by calling cpp_relex_complete.

Whether or not the relex process finished with LexResult_Finished the process can be finished by calling cpp_relex_abort, which puts the array back into it's original state. No close is necessary if getting the original array state back is not necessary.

See Also

§5.4.16: cpp_relex_get_new_count

FCPP_LINK i32_4tech cpp_relex_get_new_count(
Cpp_Relex_Data *S_ptr,
i32_4tech current_count,
Cpp_Token_Array *relex_array
)
Parameters
S_ptr
A pointer to a state that has gone through cpp_relex_step with a LexResult_Finished return.
current_count
The count of tokens in the original array before the edit.
relex_array
The relex_array that was used in the cpp_relex_step call/calls.
Description
After getting a LexResult_Finished from cpp_relex_step, this call can be used to get the size the new array will have. If the original array doesn't have enough capacity to store the new array, it's capacity should be increased before passing to cpp_relex_complete.


§5.4.17: cpp_relex_complete

FCPP_LINK void cpp_relex_complete(
Cpp_Relex_Data *S_ptr,
Cpp_Token_Array *array,
Cpp_Token_Array *relex_array
)
Parameters
S_ptr
A pointer to a state that has gone through cpp_relex_step with a LexResult_Finished return.
array
The original array being edited by cpp_relex_step calls.
relex_array
The relex_array that was filled by cpp_relex_step.
Description
After getting a LexResult_Finished from cpp_relex_step, and ensuring that array has a large enough capacity by calling cpp_relex_get_new_count, this call does the necessary replacement of tokens in the array to make it match the new file.


§5.4.18: cpp_relex_abort

FCPP_LINK void cpp_relex_abort(
Cpp_Relex_Data *S_ptr,
Cpp_Token_Array *array
)
Parameters
S_ptr
A pointer to a state that has gone through at least one cpp_relex_step.
array
The original array that went through cpp_relex_step to be edited.
Description
After the first call to cpp_relex_step, the array's contents may have been changed, this call assures the array is in it's original state. After this call the relex state is dead.


§5.4.19: cpp_make_token_array

FCPP_LINK Cpp_Token_Array cpp_make_token_array(i32_4tech 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.20: cpp_free_token_array

FCPP_LINK 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.21: cpp_resize_token_array

FCPP_LINK void cpp_resize_token_array(
Cpp_Token_Array *token_array,
i32_4tech 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.22: cpp_alloc_make_table_default

FCPP_LINK Cpp_Keyword_Table cpp_alloc_make_table_default(Cpp_Word_Table_Type type)
Parameters
type
Specifies for which slot of the parser context to get a default result.
Return
On success returns a keyword table struct built on a memory chunk created by malloc.
Description
Works as cpp_make_table for a default keyword list but takes the further liberty of using malloc and getting the memory it needs itself.

See Also

§5.4.23: cpp_free_table

FCPP_LINK void cpp_free_table(Cpp_Keyword_Table table)
Parameters
table
A table previously allocated by cpp_alloc_make_table_default.
Description
Frees the memory allocated in a cpp_alloc_make_table call.


§5.4.24: cpp_lex_file

FCPP_LINK void cpp_lex_file(
char *data,
i32_4tech 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_Word_Table_Type

enum Cpp_Word_Table_Type;
Description
A Cpp_Word_Table_Type names one of the keyword table slots in a parse context.

Values
CPP_TABLE_KEYWORDS
The Cpp_Keyword_Table used to list the typical keywords.

CPP_TABLE_PREPROCESSOR_DIRECTIVES
The Cpp_Keyword_Table used to list preprocessor directives.


§5.5.2: Cpp_Token_Type

enum Cpp_Token_Type;
Description
A Cpp_Token_Type classifies a token to make parsing easier. Some types are not actually output by the lexer, but exist because parsers will also make use of token types in their own output.

Values
CPP_TOKEN_JUNK = 0
CPP_TOKEN_COMMENT = 1
CPP_PP_INCLUDE = 2
CPP_PP_VERSION = 3
CPP_PP_DEFINE = 4
CPP_PP_UNDEF = 5
CPP_PP_IF = 6
CPP_PP_IFDEF = 7
CPP_PP_IFNDEF = 8
CPP_PP_ELSE = 9
CPP_PP_ELIF = 10
CPP_PP_ENDIF = 11
CPP_PP_ERROR = 12
CPP_PP_IMPORT = 13
CPP_PP_USING = 14
CPP_PP_LINE = 15
CPP_PP_PRAGMA = 16
CPP_PP_STRINGIFY = 17
CPP_PP_CONCAT = 18
CPP_PP_UNKNOWN = 19
CPP_PP_DEFINED = 20
CPP_PP_INCLUDE_FILE = 21
CPP_PP_ERROR_MESSAGE = 22
CPP_TOKEN_KEY_TYPE = 23
CPP_TOKEN_KEY_MODIFIER = 24
CPP_TOKEN_KEY_QUALIFIER = 25
CPP_TOKEN_KEY_OPERATOR = 26
This type is not stored in token output from the lexer.

CPP_TOKEN_KEY_CONTROL_FLOW = 27
CPP_TOKEN_KEY_CAST = 28
CPP_TOKEN_KEY_TYPE_DECLARATION = 29
CPP_TOKEN_KEY_ACCESS = 30
CPP_TOKEN_KEY_LINKAGE = 31
CPP_TOKEN_KEY_OTHER = 32
CPP_TOKEN_IDENTIFIER = 33
CPP_TOKEN_INTEGER_CONSTANT = 34
CPP_TOKEN_CHARACTER_CONSTANT = 35
CPP_TOKEN_FLOATING_CONSTANT = 36
CPP_TOKEN_STRING_CONSTANT = 37
CPP_TOKEN_BOOLEAN_CONSTANT = 38
CPP_TOKEN_STATIC_ASSERT = 39
CPP_TOKEN_BRACKET_OPEN = 40
CPP_TOKEN_BRACKET_CLOSE = 41
CPP_TOKEN_PARENTHESE_OPEN = 42
CPP_TOKEN_PARENTHESE_CLOSE = 43
CPP_TOKEN_BRACE_OPEN = 44
CPP_TOKEN_BRACE_CLOSE = 45
CPP_TOKEN_SEMICOLON = 46
CPP_TOKEN_ELLIPSIS = 47
CPP_TOKEN_STAR = 48
This is an 'ambiguous' token type because it requires parsing to determine the full nature of the token.

CPP_TOKEN_AMPERSAND = 49
This is an 'ambiguous' token type because it requires parsing to determine the full nature of the token.

CPP_TOKEN_TILDE = 50
This is an 'ambiguous' token type because it requires parsing to determine the full nature of the token.

CPP_TOKEN_PLUS = 51
This is an 'ambiguous' token type because it requires parsing to determine the full nature of the token.

CPP_TOKEN_MINUS = 52
This is an 'ambiguous' token type because it requires parsing to determine the full nature of the token.

CPP_TOKEN_INCREMENT = 53
This is an 'ambiguous' token type because it requires parsing to determine the full nature of the token.

CPP_TOKEN_DECREMENT = 54
This is an 'ambiguous' token type because it requires parsing to determine the full nature of the token.

CPP_TOKEN_SCOPE = 55
CPP_TOKEN_POSTINC = 56
This type is for parser use, it is not output by the lexer.

CPP_TOKEN_POSTDEC = 57
This type is for parser use, it is not output by the lexer.

CPP_TOKEN_FUNC_STYLE_CAST = 58
This type is for parser use, it is not output by the lexer.

CPP_TOKEN_CPP_STYLE_CAST = 59
CPP_TOKEN_CALL = 60
This type is for parser use, it is not output by the lexer.

CPP_TOKEN_INDEX = 61
This type is for parser use, it is not output by the lexer.

CPP_TOKEN_DOT = 62
CPP_TOKEN_ARROW = 63
CPP_TOKEN_PREINC = 64
This token is for parser use, it is not output by the lexer.

CPP_TOKEN_PREDEC = 65
This token is for parser use, it is not output by the lexer.

CPP_TOKEN_POSITIVE = 66
This token is for parser use, it is not output by the lexer.

CPP_TOKEN_NEGAITVE = 67
This token is for parser use, it is not output by the lexer.

CPP_TOKEN_NOT = 68
CPP_TOKEN_BIT_NOT = 69
This type is for parser use, it is not output by the lexer.

CPP_TOKEN_CAST = 70
This type is for parser use, it is not output by the lexer.

CPP_TOKEN_DEREF = 71
This type is for parser use, it is not output by the lexer.

CPP_TOKEN_TYPE_PTR = 72
This type is for parser use, it is not output by the lexer.

CPP_TOKEN_ADDRESS = 73
This type is for parser use, it is not output by the lexer.

CPP_TOKEN_TYPE_REF = 74
This type is for parser use, it is not output by the lexer.

CPP_TOKEN_SIZEOF = 75
CPP_TOKEN_ALIGNOF = 76
CPP_TOKEN_DECLTYPE = 77
CPP_TOKEN_TYPEID = 78
CPP_TOKEN_NEW = 79
CPP_TOKEN_DELETE = 80
CPP_TOKEN_NEW_ARRAY = 81
This type is for parser use, it is not output by the lexer.

CPP_TOKEN_DELETE_ARRAY = 82
This type is for parser use, it is not output by the lexer.

CPP_TOKEN_PTRDOT = 83
CPP_TOKEN_PTRARROW = 84
CPP_TOKEN_MUL = 85
This type is for parser use, it is not output by the lexer.

CPP_TOKEN_DIV = 86
CPP_TOKEN_MOD = 87
CPP_TOKEN_ADD = 88
This type is for parser use, it is not output by the lexer.

CPP_TOKEN_SUB = 89
This type is for parser use, it is not output by the lexer.

CPP_TOKEN_LSHIFT = 90
CPP_TOKEN_RSHIFT = 91
CPP_TOKEN_LESS = 92
CPP_TOKEN_GRTR = 93
CPP_TOKEN_GRTREQ = 94
CPP_TOKEN_LESSEQ = 95
CPP_TOKEN_EQEQ = 96
CPP_TOKEN_NOTEQ = 97
CPP_TOKEN_BIT_AND = 98
This type is for parser use, it is not output by the lexer.

CPP_TOKEN_BIT_XOR = 99
CPP_TOKEN_BIT_OR = 100
CPP_TOKEN_AND = 101
CPP_TOKEN_OR = 102
CPP_TOKEN_TERNARY_QMARK = 103
CPP_TOKEN_COLON = 104
CPP_TOKEN_THROW = 105
CPP_TOKEN_EQ = 106
CPP_TOKEN_ADDEQ = 107
CPP_TOKEN_SUBEQ = 108
CPP_TOKEN_MULEQ = 109
CPP_TOKEN_DIVEQ = 110
CPP_TOKEN_MODEQ = 111
CPP_TOKEN_LSHIFTEQ = 112
CPP_TOKEN_RSHIFTEQ = 113
CPP_TOKEN_ANDEQ = 114
CPP_TOKEN_OREQ = 115
CPP_TOKEN_XOREQ = 116
CPP_TOKEN_COMMA = 117
CPP_TOKEN_EOF = 118
This type is for parser use, it is not output by the lexer.

CPP_TOKEN_TYPE_COUNT = 119

§5.5.3: Cpp_Token

struct Cpp_Token {
Cpp_Token_Type type;
int32_t start;
int32_t size;
uint16_t state_flags;
uint16_t flags;
};
Description
Cpp_Token represents a single lexed token. It is the primary output of the lexing system.

Fields
type
The type field indicates the type of the token. All tokens have a type no matter the circumstances.

start
The start field indicates the index of the first character of this token's lexeme.

size
The size field indicates the number of bytes in this token's lexeme.

state_flags
The state_flags should not be used outside of the lexer's implementation.

flags
The flags field contains extra useful information about the token.

See Also

§5.5.4: Cpp_Token_Flag

enum Cpp_Token_Flag;
Description
The Cpp_Token_Flags are used to mark up tokens with additional information.

Values
CPP_TFLAG_PP_DIRECTIVE = 0x1
Indicates that the token is a preprocessor directive.

CPP_TFLAG_PP_BODY = 0x2
Indicates that the token is on the line of a preprocessor directive.

CPP_TFLAG_MULTILINE = 0x4
Indicates that the token spans across multiple lines. This can show up on line comments and string literals with back slash line continuation.

CPP_TFLAG_IS_OPERATOR = 0x8
Indicates that the token is some kind of operator or punctuation like braces.

CPP_TFLAG_IS_KEYWORD = 0x10
Indicates that the token is a keyword.


§5.5.5: Cpp_Token_Array

struct Cpp_Token_Array {
Cpp_Token * tokens;
int32_t count;
int32_t max_count;
};
Description
Cpp_Token_Array is used to bundle together the common elements of a growing array of Cpp_Tokens. To initialize it the tokens field should 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.6: Cpp_Get_Token_Result

struct Cpp_Get_Token_Result {
int32_t token_index;
int32_t in_whitespace;
int32_t token_start;
int32_t token_end;
};
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.

token_start
If the token_index refers to an actual token, this is the start value of the token. Otherwise this is zero.

token_end
If the token_index refers to an actual token, this is the start+size value of the token. Otherwise this is zero.

See Also

§5.5.7: Cpp_Relex_Range

struct Cpp_Relex_Range {
int32_t start_token_index;
int32_t end_token_index;
};
Description
Cpp_Relex_Range is the return result of the cpp_get_relex_range call.

Fields
start_token_index
The index of the first token in the unedited array that needs to be relexed.

end_token_index
The index of the first token in the unedited array after the edited range that may not need to be relexed. Sometimes a relex operation has to lex past this position to find a token that is not effected by the edit.

See Also

§5.5.8: Cpp_Keyword_Table

struct Cpp_Keyword_Table { /* non-public internals */ } ;
Description
A Cpp_Keyword_Table contains a list of keywords and a hashed lookup table for the keywords. They are used to setup a parse context.

See Also

§5.5.9: 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 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.10: 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.


§5.5.11: Cpp_Relex_Data

struct Cpp_Relex_Data { /* non-public internals */ } ;
Description
Cpp_Relex_Data represents the state of the relexer so that the system may be resumable. To create a new relex state call cpp_relex_init.

See Also