From 9de2633f516aa1c2511775cbeadbd80ad1c283fd Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sat, 29 Oct 2016 15:51:59 -0400 Subject: [PATCH 1/7] fixed binary search impossible to find' --- 4coder_default_bindings.cpp | 2 +- buffer/4coder_buffer_abstract.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/4coder_default_bindings.cpp b/4coder_default_bindings.cpp index 57de388b..55409c2b 100644 --- a/4coder_default_bindings.cpp +++ b/4coder_default_bindings.cpp @@ -217,7 +217,7 @@ OPEN_FILE_HOOK_SIG(my_file_settings){ buffer_set_setting(app, &buffer, BufferSetting_WrapPosition, default_wrap_width); buffer_set_setting(app, &buffer, BufferSetting_MapID, (treat_as_code)?((int32_t)my_code_map):((int32_t)mapid_file)); - if (treat_as_code && enable_code_wrapping && buffer.size < (1 << 20)){ + if (treat_as_code && enable_code_wrapping && buffer.size < (1 << 18)){ // NOTE(allen|a4.0.12): There is a little bit of grossness going on here. // If we set BufferSetting_Lex to true, it will launch a lexing job. // If a lexing job is active when we set BufferSetting_VirtualWhitespace on diff --git a/buffer/4coder_buffer_abstract.cpp b/buffer/4coder_buffer_abstract.cpp index 8a2ff23f..38cca6d6 100644 --- a/buffer/4coder_buffer_abstract.cpp +++ b/buffer/4coder_buffer_abstract.cpp @@ -599,6 +599,10 @@ binary_search(i32 *array, i32 value, i32 l_bound, i32 u_bound){ i32 start = l_bound, end = u_bound; i32 i = 0; + if (value < 0){ + value = 0; + } + for (;;){ i = (start + end) >> 1; if (array[i] < value){ From de4f320e27f3247e49b11c377cd5c75eb8916884 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Tue, 1 Nov 2016 23:27:51 -0400 Subject: [PATCH 2/7] organized metaprogramming some more, still needs work. Setup the 'site' subproject --- 4coder_API.html | 434 ------ 4coder_custom_api.h | 37 +- 4coder_default_bindings.cpp | 25 +- 4coder_default_include.cpp | 9 +- 4coder_string.h | 590 ++++----- 4coder_types.h | 201 ++- 4cpp_lexer.h | 60 +- 4cpp_lexer_types.h | 18 +- 4ed_api_implementation.cpp | 227 ++-- 4ed_metagen.cpp | 2497 +---------------------------------- build.bat | 2 +- internal_4coder_string.cpp | 251 ++-- meta_parser.cpp | 1368 +++++++++++++++++++ site/4ed_site.ctm | Bin 0 -> 1284 bytes site/build.bat | 22 + site/sitegen.cpp | 1281 ++++++++++++++++++ 16 files changed, 3405 insertions(+), 3617 deletions(-) delete mode 100644 4coder_API.html create mode 100644 meta_parser.cpp create mode 100644 site/4ed_site.ctm create mode 100644 site/build.bat create mode 100644 site/sitegen.cpp diff --git a/4coder_API.html b/4coder_API.html deleted file mode 100644 index d17f8d00..00000000 --- a/4coder_API.html +++ /dev/null @@ -1,434 +0,0 @@ -4coder API Docs -

4coder API

Table of Contents

-

§1 Introduction

This is the documentation for the 4cpp lexer version 1.1. The documentation is the newest piece of this lexer project so it may still have problems. What is here should be correct and mostly complete.

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

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

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

-

§2 4coder Systems

Coming Soon
-

§3 Types and Functions

§3.1 Function List

§3.2 Type List

§3.3 Function Descriptions

§3.3.1: exec_command

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

See Also

§3.3.2: exec_system_command

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

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

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

See Also

§3.3.3: clipboard_post

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

See Also

§3.3.4: clipboard_count

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

See Also

§3.3.5: clipboard_index

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

See Also

§3.3.6: get_buffer_count

int32_t get_buffer_count(
Application_Links *app
)
No documentation generated for this function.

§3.3.7: get_buffer_first

Buffer_Summary get_buffer_first(
Application_Links *app,
Access_Flag access
)
Parameters
access
The access parameter determines what levels of protection this call can access.
Return
This call returns the summary of the first buffer in a buffer loop.
Description
This call begins a loop across all the buffers. -If the buffer returned does not exist, the loop is finished. -Buffers should not be killed durring a buffer loop.

See Also

§3.3.8: get_buffer_next

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

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

See Also

§3.3.9: get_buffer

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

§3.3.10: get_buffer_by_name

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

§3.3.11: buffer_read_range

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

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

See Also

§3.3.12: buffer_replace_range

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

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

See Also

§3.3.13: buffer_compute_cursor

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

See Also

§3.3.14: buffer_batch_edit

bool32 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

§3.3.15: buffer_get_setting

int32_t buffer_get_setting(
Application_Links *app,
Buffer_Summary *buffer,
Buffer_Setting_ID setting
)
No documentation generated for this function.

§3.3.16: buffer_set_setting

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

§3.3.17: 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.18: 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.19: buffer_get_token_index

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

See Also

§3.3.20: begin_buffer_creation

void begin_buffer_creation(
Application_Links *app,
Buffer_Creation_Data *data,
Buffer_Create_Flag flags
)
No documentation generated for this function.

§3.3.21: buffer_creation_name

void buffer_creation_name(
Application_Links *app,
Buffer_Creation_Data *data,
char *filename,
int32_t filename_len,
uint32_t flags
)
No documentation generated for this function.

§3.3.22: end_buffer_creation

Buffer_Summary end_buffer_creation(
Application_Links *app,
Buffer_Creation_Data *data
)
No documentation generated for this function.

§3.3.23: create_buffer_

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

See Also

§3.3.24: save_buffer

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

§3.3.25: kill_buffer

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

See Also

§3.3.26: get_view_first

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

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

See Also

§3.3.27: get_view_next

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

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

See Also

§3.3.28: get_view

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

§3.3.29: get_active_view

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

§3.3.30: open_view

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

See Also

§3.3.31: 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.32: set_active_view

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

See Also

§3.3.33: view_get_setting

int32_t view_get_setting(
Application_Links *app,
View_Summary *view,
View_Setting_ID setting
)
No documentation generated for this function.

§3.3.34: view_set_setting

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

§3.3.35: 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.36: view_compute_cursor

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

See Also

§3.3.37: view_set_cursor

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

See Also

§3.3.38: view_set_scroll

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

See Also

§3.3.39: view_set_mark

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

See Also

§3.3.40: 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.41: view_set_buffer

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

See Also

§3.3.42: view_post_fade

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

§3.3.43: get_user_input

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

See Also

§3.3.44: get_command_input

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

§3.3.45: get_mouse_state

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

§3.3.46: 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.47: 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.49: 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.50: 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.51: 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.52: buffer_get_font

int32_t buffer_get_font(
Application_Links *app,
Buffer_Summary *buffer,
char *name_out,
int32_t name_max
)
No documentation generated for this function.

§3.3.53: set_theme_colors

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


§3.3.54: get_theme_colors

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


§3.3.55: directory_get_hot

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

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


§3.3.56: get_file_list

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

§3.3.57: free_file_list

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


§3.3.58: set_gui_up_down_keys

void set_gui_up_down_keys(
Application_Links *app,
int16_t up_key,
int16_t down_key
)
No documentation generated for this function.

§3.3.59: memory_allocate

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

See Also

§3.3.60: memory_set_protection

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

See Also

§3.3.61: memory_free

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

See Also

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

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

§3.3.65: show_mouse_cursor

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

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

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


§3.4 Type Descriptions

§3.4.1: bool32

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


§3.4.2: int_color

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


§3.4.3: Key_Code

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


§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

enum Key_Modifier;
Description
A Key_Modifier 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_history_backward
cmdid_history_backward performs a step backwards through the file history, which includes previously lost redo branches.

cmdid_history_forward
cmdid_history_forward unperforms the previous cmdid_history_backward step if possible.

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_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_config
cmdid_open_config opens the configuration menu.

cmdid_open_menu
cmdid_open_menu opens the top level menu.

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
TODO

Values
MemProtect_Read = 0x1
TODO

MemProtect_Write = 0x2
TODO

MemProtect_Execute = 0x4
TODO


§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: Event_Message_Type_ID

enum Event_Message_Type_ID;
Description
Event_Message_Type_ID is a part of an unfinished feature.

Values
EventMessage_NoMessage
TODO.

EventMessage_OpenView
TODO.

EventMessage_Frame
TODO.

EventMessage_CloseView
TODO.


§3.4.12: 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.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_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 it's dirty state will be completely - ignored. This means the "dirty" star is hidden and the buffer can be closed without presenting an - "are you sure" dialogue screen.

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 settings 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.


§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
TODO


§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 app->exec_system_command call such as *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: 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.28: Key_Event_Data

struct Key_Event_Data {
Key_Code keycode;
Key_Code character;
Key_Code character_no_caps_lock;
char 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. A 1 indicates that the corresponding - modifier was held, and a 0 indicates that it was not held.


§3.4.29: 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.30: 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.31: File_Info

struct File_Info {
char * filename;
int32_t filename_len;
int32_t 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

§3.4.32: File_List

struct File_List {
void * block;
File_Info * infos;
int32_t count;
int32_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.


§3.4.33: Buffer_Identifier

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

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.34: 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
This struct is a part of an incomplete feature.

Fields
scroll_y
TODO

target_y
TODO

prev_target_y
TODO

scroll_x
TODO

target_x
TODO

prev_target_x
TODO


§3.4.35: 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

§3.4.36: 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

§3.4.37: 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

§3.4.38: 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

§3.4.39: 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.40: 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

§3.4.41: 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 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
If this is not a null summary, this field is the id of the associated view. - If this is a null summary then view_id is 0.

buffer_id
If this is not a null summary, then this is the id of the buffer this view currently sees.

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

cursor
If this is not a null summary, this describes the position of the cursor.

mark
If this is not a null summary, this describes the position of the mark.

preferred_x
If this is not a null summary, this is the x position that is maintained in vertical navigation.

line_height
If this is not a null summary, this specifies the height of a line rendered in the view.

unwrapped_lines
If this is not a null summary, this indicates that the view is set to render with unwrapped lines.

show_whitespace
If this is not a null summary, this indicates that the view is set to highlight white space.

file_region
If this is not a null summary, this describes the screen position in which this view's buffer is displayed.

scroll_vars
If this is not a null summary, this describes the scrolling position inside the view.

See Also

§3.4.42: 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

§3.4.43: 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.44: Event_Message

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

Fields
type
This feature is not implemented.


§3.4.45: 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

§3.4.46: 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.47: 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

-

§4 String Library

§4.1 String Intro

Coming Soon

§4.2 String Function List

§4.3 String Function Descriptions

§4.3.1: char_is_slash

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


§4.3.2: char_is_upper

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


§4.3.3: char_is_lower

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


§4.3.4: char_to_upper

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.5: char_to_lower

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.6: char_is_whitespace

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


§4.3.7: char_is_alpha_numeric

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


§4.3.8: char_is_alpha_numeric_true

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


§4.3.9: char_is_alpha

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


§4.3.10: char_is_alpha_true

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


§4.3.11: char_is_hex

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


§4.3.12: char_is_numeric

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


§4.3.13: make_string_cap

String make_string_cap(
void *str,
int32_t size,
int32_t 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.14: make_string

String make_string(
void *str,
int32_t 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.15: 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.16: 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.17: 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.18: str_size

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


§4.3.19: make_string_slowly

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.20: substr_tail

String substr_tail(
String str,
int32_t 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.21: substr

String substr(
String str,
int32_t start,
int32_t 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.22: skip_whitespace

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.23: chop_whitespace

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.24: skip_chop_whitespace

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

See Also

§4.3.25: tailstr

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.26: match_cc

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


§4.3.27: match_sc

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


§4.3.28: match_cs

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


§4.3.29: match_ss

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


§4.3.30: match_part_ccl

fstr_bool match_part_ccl(
char *a,
char *b,
int32_t *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.31: match_part_scl

fstr_bool match_part_scl(
String a,
char *b,
int32_t *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.32: match_part_cc

fstr_bool 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.33: match_part_sc

fstr_bool 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.34: match_part_cs

fstr_bool 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.35: match_part_ss

fstr_bool 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.36: match_insensitive_cc

fstr_bool 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.37: match_insensitive_sc

fstr_bool 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.38: match_insensitive_cs

fstr_bool 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.39: match_insensitive_ss

fstr_bool 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.40: match_part_insensitive_ccl

fstr_bool match_part_insensitive_ccl(
char *a,
char *b,
int32_t *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.41: match_part_insensitive_scl

fstr_bool match_part_insensitive_scl(
String a,
char *b,
int32_t *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.42: match_part_insensitive_cc

fstr_bool 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.43: match_part_insensitive_sc

fstr_bool 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.44: match_part_insensitive_cs

fstr_bool 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.45: match_part_insensitive_ss

fstr_bool 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.46: compare_cc

int32_t 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.47: compare_sc

int32_t 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.48: compare_cs

int32_t 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.49: compare_ss

int32_t 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.50: find_c_char

int32_t find_c_char(
char *str,
int32_t 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.51: find_s_char

int32_t find_s_char(
String str,
int32_t 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.52: rfind_s_char

int32_t rfind_s_char(
String str,
int32_t 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.53: find_c_chars

int32_t find_c_chars(
char *str,
int32_t 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.54: find_s_chars

int32_t find_s_chars(
String str,
int32_t 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.55: find_substr_c

int32_t find_substr_c(
char *str,
int32_t 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.56: find_substr_s

int32_t find_substr_s(
String str,
int32_t 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.57: rfind_substr_s

int32_t rfind_substr_s(
String str,
int32_t 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.58: find_substr_insensitive_c

int32_t find_substr_insensitive_c(
char *str,
int32_t 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.59: find_substr_insensitive_s

int32_t find_substr_insensitive_s(
String str,
int32_t 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.60: has_substr_c

fstr_bool 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.61: has_substr_s

fstr_bool 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.62: has_substr_insensitive_c

fstr_bool 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.63: has_substr_insensitive_s

fstr_bool 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.64: copy_fast_unsafe_cc

int32_t 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.65: copy_fast_unsafe_cs

int32_t 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.66: copy_checked_ss

fstr_bool 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.67: copy_partial_sc

fstr_bool 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.68: copy_partial_ss

fstr_bool 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.69: copy_cc

int32_t 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.70: copy_ss

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.71: copy_sc

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.72: append_checked_ss

fstr_bool 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.73: append_partial_sc

fstr_bool 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.74: append_partial_ss

fstr_bool 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.75: append_s_char

fstr_bool 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.76: append_ss

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

See Also

§4.3.77: append_sc

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

See Also

§4.3.78: terminate_with_null

fstr_bool 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.79: append_padding

fstr_bool append_padding(
String *dest,
char c,
int32_t 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.80: replace_char

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.81: to_lower_cc

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.82: to_lower_ss

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.83: to_lower_s

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.84: to_upper_cc

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.85: to_upper_ss

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.86: to_upper_s

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.87: to_camel_cc

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.88: int_to_str_size

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


§4.3.89: int_to_str

fstr_bool int_to_str(
String *dest,
int32_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.90: append_int_to_str

fstr_bool append_int_to_str(
String *dest,
int32_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.91: u64_to_str_size

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


§4.3.92: u64_to_str

fstr_bool 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.93: append_u64_to_str

fstr_bool 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.94: float_to_str_size

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


§4.3.95: append_float_to_str

fstr_bool 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.96: float_to_str

fstr_bool 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.97: str_is_int_c

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


§4.3.98: str_is_int_s

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


§4.3.99: str_to_int_c

int32_t 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.100: str_to_int_s

int32_t 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.101: hexchar_to_int

int32_t 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.102: int_to_hexchar

char int_to_hexchar(
int32_t 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.103: hexstr_to_int

uint32_t 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.104: color_to_hexstr

fstr_bool color_to_hexstr(
String *s,
uint32_t 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.105: hexstr_to_color

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


§4.3.106: reverse_seek_slash_pos

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


§4.3.107: reverse_seek_slash

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


§4.3.108: front_of_directory

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.109: path_of_directory

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.110: set_last_folder_sc

fstr_bool 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.111: set_last_folder_ss

fstr_bool 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.112: file_extension

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

See Also

§4.3.113: remove_extension

fstr_bool 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.114: remove_last_folder

fstr_bool 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.115: string_set_match_table

fstr_bool string_set_match_table(
void *str_set,
int32_t item_size,
int32_t count,
String str,
int32_t *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.116: string_set_match

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

See Also

-

§5 Lexer Library

§5.1 Lexer Intro

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

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

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

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

§5.2 Lexer Function List

§5.3 Lexer Types List

§5.4 Lexer Function Descriptions

§5.4.1: cpp_get_token

Cpp_Get_Token_Result cpp_get_token(
Cpp_Token_Array array,
int32_t 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 performs a binary search over all of the tokens looking -for the token that contains the specified position. If the position -is in whitespace between the tokens, the returned token index is the -index of the token immediately before the provided position. The returned -index can be -1 if the position is before the first token.

See Also

§5.4.2: cpp_lex_step

Cpp_Lex_Result cpp_lex_step(
Cpp_Lex_Data *S_ptr,
char *chunk,
int32_t size,
int32_t full_size,
Cpp_Token_Array *token_array_out,
int32_t 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);
    
    char *temp = (char*)malloc(4096); // hopefully big enough
    Cpp_Lex_Data lex_state = cpp_lex_data_init(temp);
    
    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);
    
    free(temp);
    
    return(array);
}
See Also

§5.4.3: cpp_lex_data_init

Cpp_Lex_Data cpp_lex_data_init(

)
Return
A brand new lex state ready to begin lexing a file from the beginning.
Description
Creates a new lex state in the form of a Cpp_Lex_Data struct and returns the struct. -The system needs a temporary buffer that is as long as the longest token. 4096 is usually -enough but the buffer is not checked, so to be 100% bullet proof it has to be the same length -as the file being lexed.


§5.4.4: cpp_lex_data_temp_size

int32_t cpp_lex_data_temp_size(
Cpp_Lex_Data *lex_data
)
Parameters
lex_data
The lex state from which to get the temporary buffer size.
Description
This call gets the current size of the temporary buffer in the lexer state so -that you can move to a new temporary buffer by copying the data over.

See Also

§5.4.5: cpp_lex_data_temp_read

void cpp_lex_data_temp_read(
Cpp_Lex_Data *lex_data,
char *out_buffer
)
Parameters
lex_data
The lex state from which to read the temporary buffer.
out_buffer
The buffer into which the contents of the temporary buffer will be written. -The size of the buffer must be at least the size as returned by cpp_lex_data_temp_size.
Description
This call reads the current contents of the temporary buffer.

See Also

§5.4.6: cpp_lex_data_new_temp_DEP

void cpp_lex_data_new_temp_DEP(
Cpp_Lex_Data *lex_data,
char *new_buffer
)

§5.4.7: cpp_get_relex_range

Cpp_Relex_Range cpp_get_relex_range(
Cpp_Token_Array *array,
int32_t start_pos,
int32_t 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.8: cpp_relex_init

Cpp_Relex_Data cpp_relex_init(
Cpp_Token_Array *array,
int32_t start_pos,
int32_t end_pos,
int32_t character_shift_amount
)
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.
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.9: cpp_relex_start_position

int32_t 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.10: cpp_relex_declare_first_chunk_position

void cpp_relex_declare_first_chunk_position(
Cpp_Relex_Data *S_ptr,
int32_t 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.11: cpp_relex_is_start_chunk

int32_t cpp_relex_is_start_chunk(
Cpp_Relex_Data *S_ptr,
char *chunk,
int32_t 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.12: cpp_relex_step

Cpp_Lex_Result cpp_relex_step(
Cpp_Relex_Data *S_ptr,
char *chunk,
int32_t chunk_size,
int32_t full_size,
Cpp_Token_Array *array,
Cpp_Token_Array *relex_array
)
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.13: cpp_relex_get_new_count

int32_t cpp_relex_get_new_count(
Cpp_Relex_Data *S_ptr,
int32_t current_count,
Cpp_Token_Array *relex_array
)
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.14: cpp_relex_complete

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.15: cpp_relex_abort

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.16: cpp_make_token_array

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


§5.4.17: cpp_free_token_array

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

See Also

§5.4.18: cpp_resize_token_array

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

See Also

§5.4.19: cpp_lex_file

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

-

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

§5.5 Lexer Type Descriptions

§5.5.1: Cpp_Token_Type

enum Cpp_Token_Type;
Description
A Cpp_Token_Type classifies a token to make parsing easier. Some types are not 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_DEFINE = 3
CPP_PP_UNDEF = 4
CPP_PP_IF = 5
CPP_PP_IFDEF = 6
CPP_PP_IFNDEF = 7
CPP_PP_ELSE = 8
CPP_PP_ELIF = 9
CPP_PP_ENDIF = 10
CPP_PP_ERROR = 11
CPP_PP_IMPORT = 12
CPP_PP_USING = 13
CPP_PP_LINE = 14
CPP_PP_PRAGMA = 15
CPP_PP_STRINGIFY = 16
CPP_PP_CONCAT = 17
CPP_PP_UNKNOWN = 18
CPP_PP_DEFINED = 19
CPP_PP_INCLUDE_FILE = 20
CPP_PP_ERROR_MESSAGE = 21
CPP_TOKEN_KEY_TYPE = 22
CPP_TOKEN_KEY_MODIFIER = 23
CPP_TOKEN_KEY_QUALIFIER = 24
CPP_TOKEN_KEY_OPERATOR = 25
This type is not stored in token output from the lexer.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

CPP_TOKEN_TYPE_COUNT = 118

§5.5.2: 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.3: 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.4: 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.5: 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.6: 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.7: Cpp_Lex_Data

struct Cpp_Lex_Data { /* non-public internals */ } ;
Description
Cpp_Lex_Data represents the state of the lexer so that the system may be resumable -and the user can manage the lexer state and decide when to resume lexing with it. To create -a new lexer state 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.8: Cpp_Lex_Result

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

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

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

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

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


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

\ No newline at end of file diff --git a/4coder_custom_api.h b/4coder_custom_api.h index 8bcfdd38..836bae9f 100644 --- a/4coder_custom_api.h +++ b/4coder_custom_api.h @@ -12,15 +12,14 @@ #define BUFFER_REPLACE_RANGE_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, int32_t start, int32_t end, char *str, int32_t len) #define BUFFER_COMPUTE_CURSOR_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, Buffer_Seek seek, Partial_Cursor *cursor_out) #define BUFFER_BATCH_EDIT_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, char *str, int32_t str_len, Buffer_Edit *edits, int32_t edit_count, Buffer_Batch_Edit_Type type) -#define BUFFER_GET_SETTING_SIG(n) int32_t n(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting) +#define BUFFER_GET_SETTING_SIG(n) int32_t n(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t *value_out) #define BUFFER_SET_SETTING_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t value) #define BUFFER_TOKEN_COUNT_SIG(n) int32_t n(Application_Links *app, Buffer_Summary *buffer) #define BUFFER_READ_TOKENS_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, int32_t start_token, int32_t end_token, Cpp_Token *tokens_out) #define BUFFER_GET_TOKEN_INDEX_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, int32_t pos, Cpp_Get_Token_Result *get_result) -#define BEGIN_BUFFER_CREATION_SIG(n) void n(Application_Links *app, Buffer_Creation_Data *data, Buffer_Create_Flag flags) -#define BUFFER_CREATION_NAME_SIG(n) void n(Application_Links *app, Buffer_Creation_Data *data, char *filename, int32_t filename_len, uint32_t flags) +#define BEGIN_BUFFER_CREATION_SIG(n) bool32 n(Application_Links *app, Buffer_Creation_Data *data, Buffer_Create_Flag flags) +#define BUFFER_CREATION_NAME_SIG(n) bool32 n(Application_Links *app, Buffer_Creation_Data *data, char *filename, int32_t filename_len, uint32_t flags) #define END_BUFFER_CREATION_SIG(n) Buffer_Summary n(Application_Links *app, Buffer_Creation_Data *data) -#define CREATE_BUFFER__SIG(n) Buffer_Summary n(Application_Links *app, char *filename, int32_t filename_len, Buffer_Create_Flag flags) #define SAVE_BUFFER_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, char *filename, int32_t filename_len, uint32_t flags) #define KILL_BUFFER_SIG(n) bool32 n(Application_Links *app, Buffer_Identifier buffer, View_ID view_id, Buffer_Kill_Flag flags) #define GET_VIEW_FIRST_SIG(n) View_Summary n(Application_Links *app, Access_Flag access) @@ -30,7 +29,7 @@ #define OPEN_VIEW_SIG(n) View_Summary n(Application_Links *app, View_Summary *view_location, View_Split_Position position) #define CLOSE_VIEW_SIG(n) bool32 n(Application_Links *app, View_Summary *view) #define SET_ACTIVE_VIEW_SIG(n) bool32 n(Application_Links *app, View_Summary *view) -#define VIEW_GET_SETTING_SIG(n) int32_t n(Application_Links *app, View_Summary *view, View_Setting_ID setting) +#define VIEW_GET_SETTING_SIG(n) bool32 n(Application_Links *app, View_Summary *view, View_Setting_ID setting, int32_t *value_out) #define VIEW_SET_SETTING_SIG(n) bool32 n(Application_Links *app, View_Summary *view, View_Setting_ID setting, int32_t value) #define VIEW_SET_SPLIT_PROPORTION_SIG(n) bool32 n(Application_Links *app, View_Summary *view, float t) #define VIEW_COMPUTE_CURSOR_SIG(n) bool32 n(Application_Links *app, View_Summary *view, Buffer_Seek seek, Full_Cursor *cursor_out) @@ -49,7 +48,7 @@ #define CHANGE_THEME_SIG(n) void n(Application_Links *app, char *name, int32_t len) #define CHANGE_FONT_SIG(n) void n(Application_Links *app, char *name, int32_t len, bool32 apply_to_all_files) #define BUFFER_SET_FONT_SIG(n) void n(Application_Links *app, Buffer_Summary *buffer, char *name, int32_t len) -#define BUFFER_GET_FONT_SIG(n) int32_t n(Application_Links *app, Buffer_Summary *buffer, char *name_out, int32_t name_max) +#define BUFFER_GET_FONT_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, char *name_out, int32_t name_max) #define SET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, int32_t count) #define GET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, int32_t count) #define DIRECTORY_GET_HOT_SIG(n) int32_t n(Application_Links *app, char *out, int32_t capacity) @@ -88,7 +87,6 @@ typedef BUFFER_GET_TOKEN_INDEX_SIG(Buffer_Get_Token_Index_Function); typedef BEGIN_BUFFER_CREATION_SIG(Begin_Buffer_Creation_Function); typedef BUFFER_CREATION_NAME_SIG(Buffer_Creation_Name_Function); typedef END_BUFFER_CREATION_SIG(End_Buffer_Creation_Function); -typedef CREATE_BUFFER__SIG(Create_Buffer__Function); typedef SAVE_BUFFER_SIG(Save_Buffer_Function); typedef KILL_BUFFER_SIG(Kill_Buffer_Function); typedef GET_VIEW_FIRST_SIG(Get_View_First_Function); @@ -158,7 +156,6 @@ Buffer_Get_Token_Index_Function *buffer_get_token_index; Begin_Buffer_Creation_Function *begin_buffer_creation; Buffer_Creation_Name_Function *buffer_creation_name; End_Buffer_Creation_Function *end_buffer_creation; -Create_Buffer__Function *create_buffer_; Save_Buffer_Function *save_buffer; Kill_Buffer_Function *kill_buffer; Get_View_First_Function *get_view_first; @@ -227,7 +224,6 @@ Buffer_Get_Token_Index_Function *buffer_get_token_index_; Begin_Buffer_Creation_Function *begin_buffer_creation_; Buffer_Creation_Name_Function *buffer_creation_name_; End_Buffer_Creation_Function *end_buffer_creation_; -Create_Buffer__Function *create_buffer__; Save_Buffer_Function *save_buffer_; Kill_Buffer_Function *kill_buffer_; Get_View_First_Function *get_view_first_; @@ -304,7 +300,6 @@ app_links->buffer_get_token_index_ = Buffer_Get_Token_Index;\ app_links->begin_buffer_creation_ = Begin_Buffer_Creation;\ app_links->buffer_creation_name_ = Buffer_Creation_Name;\ app_links->end_buffer_creation_ = End_Buffer_Creation;\ -app_links->create_buffer__ = Create_Buffer_;\ app_links->save_buffer_ = Save_Buffer;\ app_links->kill_buffer_ = Kill_Buffer;\ app_links->get_view_first_ = Get_View_First;\ @@ -365,15 +360,14 @@ static inline bool32 buffer_read_range(Application_Links *app, Buffer_Summary *b static inline bool32 buffer_replace_range(Application_Links *app, Buffer_Summary *buffer, int32_t start, int32_t end, char *str, int32_t len){return(app->buffer_replace_range(app, buffer, start, end, str, len));} static inline bool32 buffer_compute_cursor(Application_Links *app, Buffer_Summary *buffer, Buffer_Seek seek, Partial_Cursor *cursor_out){return(app->buffer_compute_cursor(app, buffer, seek, cursor_out));} static inline 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){return(app->buffer_batch_edit(app, buffer, str, str_len, edits, edit_count, type));} -static inline int32_t buffer_get_setting(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting){return(app->buffer_get_setting(app, buffer, setting));} +static inline int32_t buffer_get_setting(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t *value_out){return(app->buffer_get_setting(app, buffer, setting, value_out));} static inline bool32 buffer_set_setting(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t value){return(app->buffer_set_setting(app, buffer, setting, value));} static inline int32_t buffer_token_count(Application_Links *app, Buffer_Summary *buffer){return(app->buffer_token_count(app, buffer));} static inline bool32 buffer_read_tokens(Application_Links *app, Buffer_Summary *buffer, int32_t start_token, int32_t end_token, Cpp_Token *tokens_out){return(app->buffer_read_tokens(app, buffer, start_token, end_token, tokens_out));} static inline bool32 buffer_get_token_index(Application_Links *app, Buffer_Summary *buffer, int32_t pos, Cpp_Get_Token_Result *get_result){return(app->buffer_get_token_index(app, buffer, pos, get_result));} -static inline void begin_buffer_creation(Application_Links *app, Buffer_Creation_Data *data, Buffer_Create_Flag flags){(app->begin_buffer_creation(app, data, flags));} -static inline void buffer_creation_name(Application_Links *app, Buffer_Creation_Data *data, char *filename, int32_t filename_len, uint32_t flags){(app->buffer_creation_name(app, data, filename, filename_len, flags));} +static inline bool32 begin_buffer_creation(Application_Links *app, Buffer_Creation_Data *data, Buffer_Create_Flag flags){return(app->begin_buffer_creation(app, data, flags));} +static inline bool32 buffer_creation_name(Application_Links *app, Buffer_Creation_Data *data, char *filename, int32_t filename_len, uint32_t flags){return(app->buffer_creation_name(app, data, filename, filename_len, flags));} static inline Buffer_Summary end_buffer_creation(Application_Links *app, Buffer_Creation_Data *data){return(app->end_buffer_creation(app, data));} -static inline Buffer_Summary create_buffer_(Application_Links *app, char *filename, int32_t filename_len, Buffer_Create_Flag flags){return(app->create_buffer_(app, filename, filename_len, flags));} static inline bool32 save_buffer(Application_Links *app, Buffer_Summary *buffer, char *filename, int32_t filename_len, uint32_t flags){return(app->save_buffer(app, buffer, filename, filename_len, flags));} static inline bool32 kill_buffer(Application_Links *app, Buffer_Identifier buffer, View_ID view_id, Buffer_Kill_Flag flags){return(app->kill_buffer(app, buffer, view_id, flags));} static inline View_Summary get_view_first(Application_Links *app, Access_Flag access){return(app->get_view_first(app, access));} @@ -383,7 +377,7 @@ static inline View_Summary get_active_view(Application_Links *app, Access_Flag a static inline View_Summary open_view(Application_Links *app, View_Summary *view_location, View_Split_Position position){return(app->open_view(app, view_location, position));} static inline bool32 close_view(Application_Links *app, View_Summary *view){return(app->close_view(app, view));} static inline bool32 set_active_view(Application_Links *app, View_Summary *view){return(app->set_active_view(app, view));} -static inline int32_t view_get_setting(Application_Links *app, View_Summary *view, View_Setting_ID setting){return(app->view_get_setting(app, view, setting));} +static inline bool32 view_get_setting(Application_Links *app, View_Summary *view, View_Setting_ID setting, int32_t *value_out){return(app->view_get_setting(app, view, setting, value_out));} static inline bool32 view_set_setting(Application_Links *app, View_Summary *view, View_Setting_ID setting, int32_t value){return(app->view_set_setting(app, view, setting, value));} static inline bool32 view_set_split_proportion(Application_Links *app, View_Summary *view, float t){return(app->view_set_split_proportion(app, view, t));} static inline bool32 view_compute_cursor(Application_Links *app, View_Summary *view, Buffer_Seek seek, Full_Cursor *cursor_out){return(app->view_compute_cursor(app, view, seek, cursor_out));} @@ -402,7 +396,7 @@ static inline void print_message(Application_Links *app, char *str, int32_t len) static inline void change_theme(Application_Links *app, char *name, int32_t len){(app->change_theme(app, name, len));} static inline void change_font(Application_Links *app, char *name, int32_t len, bool32 apply_to_all_files){(app->change_font(app, name, len, apply_to_all_files));} static inline void buffer_set_font(Application_Links *app, Buffer_Summary *buffer, char *name, int32_t len){(app->buffer_set_font(app, buffer, name, len));} -static inline int32_t buffer_get_font(Application_Links *app, Buffer_Summary *buffer, char *name_out, int32_t name_max){return(app->buffer_get_font(app, buffer, name_out, name_max));} +static inline bool32 buffer_get_font(Application_Links *app, Buffer_Summary *buffer, char *name_out, int32_t name_max){return(app->buffer_get_font(app, buffer, name_out, name_max));} static inline void set_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->set_theme_colors(app, colors, count));} static inline void get_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->get_theme_colors(app, colors, count));} static inline int32_t directory_get_hot(Application_Links *app, char *out, int32_t capacity){return(app->directory_get_hot(app, out, capacity));} @@ -434,15 +428,14 @@ static inline bool32 buffer_read_range(Application_Links *app, Buffer_Summary *b static inline bool32 buffer_replace_range(Application_Links *app, Buffer_Summary *buffer, int32_t start, int32_t end, char *str, int32_t len){return(app->buffer_replace_range_(app, buffer, start, end, str, len));} static inline bool32 buffer_compute_cursor(Application_Links *app, Buffer_Summary *buffer, Buffer_Seek seek, Partial_Cursor *cursor_out){return(app->buffer_compute_cursor_(app, buffer, seek, cursor_out));} static inline 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){return(app->buffer_batch_edit_(app, buffer, str, str_len, edits, edit_count, type));} -static inline int32_t buffer_get_setting(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting){return(app->buffer_get_setting_(app, buffer, setting));} +static inline int32_t buffer_get_setting(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t *value_out){return(app->buffer_get_setting_(app, buffer, setting, value_out));} static inline bool32 buffer_set_setting(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t value){return(app->buffer_set_setting_(app, buffer, setting, value));} static inline int32_t buffer_token_count(Application_Links *app, Buffer_Summary *buffer){return(app->buffer_token_count_(app, buffer));} static inline bool32 buffer_read_tokens(Application_Links *app, Buffer_Summary *buffer, int32_t start_token, int32_t end_token, Cpp_Token *tokens_out){return(app->buffer_read_tokens_(app, buffer, start_token, end_token, tokens_out));} static inline bool32 buffer_get_token_index(Application_Links *app, Buffer_Summary *buffer, int32_t pos, Cpp_Get_Token_Result *get_result){return(app->buffer_get_token_index_(app, buffer, pos, get_result));} -static inline void begin_buffer_creation(Application_Links *app, Buffer_Creation_Data *data, Buffer_Create_Flag flags){(app->begin_buffer_creation_(app, data, flags));} -static inline void buffer_creation_name(Application_Links *app, Buffer_Creation_Data *data, char *filename, int32_t filename_len, uint32_t flags){(app->buffer_creation_name_(app, data, filename, filename_len, flags));} +static inline bool32 begin_buffer_creation(Application_Links *app, Buffer_Creation_Data *data, Buffer_Create_Flag flags){return(app->begin_buffer_creation_(app, data, flags));} +static inline bool32 buffer_creation_name(Application_Links *app, Buffer_Creation_Data *data, char *filename, int32_t filename_len, uint32_t flags){return(app->buffer_creation_name_(app, data, filename, filename_len, flags));} static inline Buffer_Summary end_buffer_creation(Application_Links *app, Buffer_Creation_Data *data){return(app->end_buffer_creation_(app, data));} -static inline Buffer_Summary create_buffer_(Application_Links *app, char *filename, int32_t filename_len, Buffer_Create_Flag flags){return(app->create_buffer__(app, filename, filename_len, flags));} static inline bool32 save_buffer(Application_Links *app, Buffer_Summary *buffer, char *filename, int32_t filename_len, uint32_t flags){return(app->save_buffer_(app, buffer, filename, filename_len, flags));} static inline bool32 kill_buffer(Application_Links *app, Buffer_Identifier buffer, View_ID view_id, Buffer_Kill_Flag flags){return(app->kill_buffer_(app, buffer, view_id, flags));} static inline View_Summary get_view_first(Application_Links *app, Access_Flag access){return(app->get_view_first_(app, access));} @@ -452,7 +445,7 @@ static inline View_Summary get_active_view(Application_Links *app, Access_Flag a static inline View_Summary open_view(Application_Links *app, View_Summary *view_location, View_Split_Position position){return(app->open_view_(app, view_location, position));} static inline bool32 close_view(Application_Links *app, View_Summary *view){return(app->close_view_(app, view));} static inline bool32 set_active_view(Application_Links *app, View_Summary *view){return(app->set_active_view_(app, view));} -static inline int32_t view_get_setting(Application_Links *app, View_Summary *view, View_Setting_ID setting){return(app->view_get_setting_(app, view, setting));} +static inline bool32 view_get_setting(Application_Links *app, View_Summary *view, View_Setting_ID setting, int32_t *value_out){return(app->view_get_setting_(app, view, setting, value_out));} static inline bool32 view_set_setting(Application_Links *app, View_Summary *view, View_Setting_ID setting, int32_t value){return(app->view_set_setting_(app, view, setting, value));} static inline bool32 view_set_split_proportion(Application_Links *app, View_Summary *view, float t){return(app->view_set_split_proportion_(app, view, t));} static inline bool32 view_compute_cursor(Application_Links *app, View_Summary *view, Buffer_Seek seek, Full_Cursor *cursor_out){return(app->view_compute_cursor_(app, view, seek, cursor_out));} @@ -471,7 +464,7 @@ static inline void print_message(Application_Links *app, char *str, int32_t len) static inline void change_theme(Application_Links *app, char *name, int32_t len){(app->change_theme_(app, name, len));} static inline void change_font(Application_Links *app, char *name, int32_t len, bool32 apply_to_all_files){(app->change_font_(app, name, len, apply_to_all_files));} static inline void buffer_set_font(Application_Links *app, Buffer_Summary *buffer, char *name, int32_t len){(app->buffer_set_font_(app, buffer, name, len));} -static inline int32_t buffer_get_font(Application_Links *app, Buffer_Summary *buffer, char *name_out, int32_t name_max){return(app->buffer_get_font_(app, buffer, name_out, name_max));} +static inline bool32 buffer_get_font(Application_Links *app, Buffer_Summary *buffer, char *name_out, int32_t name_max){return(app->buffer_get_font_(app, buffer, name_out, name_max));} static inline void set_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->set_theme_colors_(app, colors, count));} static inline void get_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->get_theme_colors_(app, colors, count));} static inline int32_t directory_get_hot(Application_Links *app, char *out, int32_t capacity){return(app->directory_get_hot_(app, out, capacity));} diff --git a/4coder_default_bindings.cpp b/4coder_default_bindings.cpp index 55409c2b..4f6cbc22 100644 --- a/4coder_default_bindings.cpp +++ b/4coder_default_bindings.cpp @@ -158,8 +158,30 @@ HOOK_SIG(my_start){ HOOK_SIG(my_exit){ // if this returns zero it cancels the exit. return(1); -} + } + // TODO(allen): delete this + CUSTOM_COMMAND_SIG(weird_buffer_test){ + for (Buffer_Summary buffer = get_buffer_first(app, AccessAll); + buffer.exists; + get_buffer_next(app, &buffer, AccessAll)){ + print_message(app, literal("filename:")); + if (buffer.file_name){ + print_message(app, buffer.file_name, buffer.file_name_len); + } + else{ + print_message(app, literal("*NULL*")); + } + print_message(app, literal("buffername:")); + if (buffer.buffer_name){ + print_message(app, buffer.buffer_name, buffer.buffer_name_len); + } + else{ + print_message(app, literal("*NULL*")); + } + } + } + // NOTE(allen|a4.0.12): This is for testing it may be removed and replaced with a better test for the buffer_get_font when you eventally read this and wonder what it's about. CUSTOM_COMMAND_SIG(write_name_of_font){ View_Summary view = get_active_view(app, AccessOpen); @@ -314,6 +336,7 @@ default_keys(Bind_Helper *context){ bind(context, key_f2, MDFR_NONE, toggle_mouse); bind(context, key_page_up, MDFR_CTRL, toggle_fullscreen); bind(context, 'E', MDFR_ALT, exit_4coder); + bind(context, 'K', MDFR_ALT, weird_buffer_test); end_map(context); diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index af64de74..b3777521 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -2661,7 +2661,8 @@ CUSTOM_COMMAND_SIG(increase_line_wrap){ View_Summary view = get_active_view(app, AccessProtected); Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessProtected); - int32_t wrap = buffer_get_setting(app, &buffer, BufferSetting_WrapPosition); + int32_t wrap = 0; + buffer_get_setting(app, &buffer, BufferSetting_WrapPosition, &wrap); buffer_set_setting(app, &buffer, BufferSetting_WrapPosition, wrap + 10); } @@ -2669,7 +2670,8 @@ CUSTOM_COMMAND_SIG(decrease_line_wrap){ View_Summary view = get_active_view(app, AccessProtected); Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessProtected); - int32_t wrap = buffer_get_setting(app, &buffer, BufferSetting_WrapPosition); + int32_t wrap = 0; + buffer_get_setting(app, &buffer, BufferSetting_WrapPosition, &wrap); buffer_set_setting(app, &buffer, BufferSetting_WrapPosition, wrap - 10); } @@ -2677,7 +2679,8 @@ CUSTOM_COMMAND_SIG(toggle_virtual_whitespace){ View_Summary view = get_active_view(app, AccessProtected); Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessProtected); - int32_t vwhite = buffer_get_setting(app, &buffer, BufferSetting_VirtualWhitespace); + int32_t vwhite = 0; + buffer_get_setting(app, &buffer, BufferSetting_VirtualWhitespace, &vwhite); buffer_set_setting(app, &buffer, BufferSetting_VirtualWhitespace, !vwhite); } diff --git a/4coder_string.h b/4coder_string.h index 04ded501..5fc78e27 100644 --- a/4coder_string.h +++ b/4coder_string.h @@ -47,20 +47,20 @@ typedef struct Offset_String{ #if !defined(FCODER_STRING_H) #define FCODER_STRING_H -FSTRING_INLINE fstr_bool char_is_slash(char c); -FSTRING_INLINE fstr_bool char_is_upper(char c); -FSTRING_INLINE fstr_bool char_is_lower(char c); -FSTRING_INLINE char char_to_upper(char c); -FSTRING_INLINE char char_to_lower(char c); -FSTRING_INLINE fstr_bool char_is_whitespace(char c); -FSTRING_INLINE fstr_bool char_is_alpha_numeric(char c); -FSTRING_INLINE fstr_bool char_is_alpha_numeric_true(char c); -FSTRING_INLINE fstr_bool char_is_alpha(char c); -FSTRING_INLINE fstr_bool char_is_alpha_true(char c); -FSTRING_INLINE fstr_bool char_is_hex(char c); -FSTRING_INLINE fstr_bool char_is_numeric(char c); -FSTRING_INLINE String make_string_cap(void *str, int32_t size, int32_t mem_size); -FSTRING_INLINE String make_string(void *str, int32_t size); +FSTRING_INLINE fstr_bool char_is_slash(char c); +FSTRING_INLINE fstr_bool char_is_upper(char c); +FSTRING_INLINE fstr_bool char_is_lower(char c); +FSTRING_INLINE char char_to_upper(char c); +FSTRING_INLINE char char_to_lower(char c); +FSTRING_INLINE fstr_bool char_is_whitespace(char c); +FSTRING_INLINE fstr_bool char_is_alpha_numeric(char c); +FSTRING_INLINE fstr_bool char_is_alpha_numeric_true(char c); +FSTRING_INLINE fstr_bool char_is_alpha(char c); +FSTRING_INLINE fstr_bool char_is_alpha_true(char c); +FSTRING_INLINE fstr_bool char_is_hex(char c); +FSTRING_INLINE fstr_bool char_is_numeric(char c); +FSTRING_INLINE String make_string_cap(void *str, int32_t size, int32_t mem_size); +FSTRING_INLINE String make_string(void *str, int32_t size); #ifndef make_lit_string # define make_lit_string(s) (make_string_cap((char*)(s), sizeof(s)-1, sizeof(s))) #endif @@ -70,179 +70,179 @@ FSTRING_INLINE String make_string(void *str, int32_t size); #ifndef expand_str # define expand_str(s) ((s).str), ((s).size) #endif -FSTRING_LINK int32_t str_size(char *str); -FSTRING_INLINE String make_string_slowly(void *str); -FSTRING_INLINE String substr_tail(String str, int32_t start); -FSTRING_INLINE String substr(String str, int32_t start, int32_t size); -FSTRING_LINK String skip_whitespace(String str); -FSTRING_LINK String chop_whitespace(String str); -FSTRING_LINK String skip_chop_whitespace(String str); -FSTRING_INLINE String tailstr(String str); -FSTRING_LINK fstr_bool match_cc(char *a, char *b); -FSTRING_LINK fstr_bool match_sc(String a, char *b); -FSTRING_INLINE fstr_bool match_cs(char *a, String b); -FSTRING_LINK fstr_bool match_ss(String a, String b); -FSTRING_LINK fstr_bool match_part_ccl(char *a, char *b, int32_t *len); -FSTRING_LINK fstr_bool match_part_scl(String a, char *b, int32_t *len); -FSTRING_INLINE fstr_bool match_part_cc(char *a, char *b); -FSTRING_INLINE fstr_bool match_part_sc(String a, char *b); -FSTRING_LINK fstr_bool match_part_cs(char *a, String b); -FSTRING_LINK fstr_bool match_part_ss(String a, String b); -FSTRING_LINK fstr_bool match_insensitive_cc(char *a, char *b); -FSTRING_LINK fstr_bool match_insensitive_sc(String a, char *b); -FSTRING_INLINE fstr_bool match_insensitive_cs(char *a, String b); -FSTRING_LINK fstr_bool match_insensitive_ss(String a, String b); -FSTRING_LINK fstr_bool match_part_insensitive_ccl(char *a, char *b, int32_t *len); -FSTRING_LINK fstr_bool match_part_insensitive_scl(String a, char *b, int32_t *len); -FSTRING_INLINE fstr_bool match_part_insensitive_cc(char *a, char *b); -FSTRING_INLINE fstr_bool match_part_insensitive_sc(String a, char *b); -FSTRING_LINK fstr_bool match_part_insensitive_cs(char *a, String b); -FSTRING_LINK fstr_bool match_part_insensitive_ss(String a, String b); -FSTRING_LINK int32_t compare_cc(char *a, char *b); -FSTRING_LINK int32_t compare_sc(String a, char *b); -FSTRING_INLINE int32_t compare_cs(char *a, String b); -FSTRING_LINK int32_t compare_ss(String a, String b); -FSTRING_LINK int32_t find_c_char(char *str, int32_t start, char character); -FSTRING_LINK int32_t find_s_char(String str, int32_t start, char character); -FSTRING_LINK int32_t rfind_s_char(String str, int32_t start, char character); -FSTRING_LINK int32_t find_c_chars(char *str, int32_t start, char *characters); -FSTRING_LINK int32_t find_s_chars(String str, int32_t start, char *characters); -FSTRING_LINK int32_t find_substr_c(char *str, int32_t start, String seek); -FSTRING_LINK int32_t find_substr_s(String str, int32_t start, String seek); -FSTRING_LINK int32_t rfind_substr_s(String str, int32_t start, String seek); -FSTRING_LINK int32_t find_substr_insensitive_c(char *str, int32_t start, String seek); -FSTRING_LINK int32_t find_substr_insensitive_s(String str, int32_t start, String seek); -FSTRING_INLINE fstr_bool has_substr_c(char *s, String seek); -FSTRING_INLINE fstr_bool has_substr_s(String s, String seek); -FSTRING_INLINE fstr_bool has_substr_insensitive_c(char *s, String seek); -FSTRING_INLINE fstr_bool has_substr_insensitive_s(String s, String seek); -FSTRING_LINK int32_t copy_fast_unsafe_cc(char *dest, char *src); -FSTRING_LINK int32_t copy_fast_unsafe_cs(char *dest, String src); -FSTRING_LINK fstr_bool copy_checked_ss(String *dest, String src); -FSTRING_LINK fstr_bool copy_partial_sc(String *dest, char *src); -FSTRING_LINK fstr_bool copy_partial_ss(String *dest, String src); -FSTRING_INLINE int32_t copy_cc(char *dest, char *src); -FSTRING_INLINE void copy_ss(String *dest, String src); -FSTRING_INLINE void copy_sc(String *dest, char *src); -FSTRING_LINK fstr_bool append_checked_ss(String *dest, String src); -FSTRING_LINK fstr_bool append_partial_sc(String *dest, char *src); -FSTRING_LINK fstr_bool append_partial_ss(String *dest, String src); -FSTRING_LINK fstr_bool append_s_char(String *dest, char c); -FSTRING_INLINE fstr_bool append_ss(String *dest, String src); -FSTRING_INLINE fstr_bool append_sc(String *dest, char *src); -FSTRING_LINK fstr_bool terminate_with_null(String *str); -FSTRING_LINK fstr_bool append_padding(String *dest, char c, int32_t target_size); -FSTRING_LINK void replace_char(String *str, char replace, char with); -FSTRING_LINK void to_lower_cc(char *src, char *dst); -FSTRING_LINK void to_lower_ss(String *dst, String src); -FSTRING_LINK void to_lower_s(String *str); -FSTRING_LINK void to_upper_cc(char *src, char *dst); -FSTRING_LINK void to_upper_ss(String *dst, String src); -FSTRING_LINK void to_upper_s(String *str); -FSTRING_LINK void to_camel_cc(char *src, char *dst); -FSTRING_LINK int32_t int_to_str_size(int32_t x); -FSTRING_LINK fstr_bool int_to_str(String *dest, int32_t x); -FSTRING_LINK fstr_bool append_int_to_str(String *dest, int32_t x); -FSTRING_LINK int32_t u64_to_str_size(uint64_t x); -FSTRING_LINK fstr_bool u64_to_str(String *dest, uint64_t x); -FSTRING_LINK fstr_bool append_u64_to_str(String *dest, uint64_t x); -FSTRING_LINK int32_t float_to_str_size(float x); -FSTRING_LINK fstr_bool append_float_to_str(String *dest, float x); -FSTRING_LINK fstr_bool float_to_str(String *dest, float x); -FSTRING_LINK int32_t str_is_int_c(char *str); -FSTRING_LINK fstr_bool str_is_int_s(String str); -FSTRING_LINK int32_t str_to_int_c(char *str); -FSTRING_LINK int32_t str_to_int_s(String str); -FSTRING_LINK int32_t hexchar_to_int(char c); -FSTRING_LINK char int_to_hexchar(int32_t x); -FSTRING_LINK uint32_t hexstr_to_int(String str); -FSTRING_LINK fstr_bool color_to_hexstr(String *s, uint32_t color); -FSTRING_LINK fstr_bool hexstr_to_color(String s, uint32_t *out); -FSTRING_LINK int32_t reverse_seek_slash_pos(String str, int32_t pos); -FSTRING_INLINE int32_t reverse_seek_slash(String str); -FSTRING_INLINE String front_of_directory(String dir); -FSTRING_INLINE String path_of_directory(String dir); -FSTRING_LINK fstr_bool set_last_folder_sc(String *dir, char *folder_name, char slash); -FSTRING_LINK fstr_bool set_last_folder_ss(String *dir, String folder_name, char slash); -FSTRING_LINK String file_extension(String str); -FSTRING_LINK fstr_bool remove_extension(String *str); -FSTRING_LINK fstr_bool remove_last_folder(String *str); -FSTRING_LINK fstr_bool string_set_match_table(void *str_set, int32_t item_size, int32_t count, String str, int32_t *match_index); -FSTRING_LINK fstr_bool string_set_match(String *str_set, int32_t count, String str, int32_t *match_index); +FSTRING_LINK int32_t str_size(char *str); +FSTRING_INLINE String make_string_slowly(void *str); +FSTRING_INLINE String substr_tail(String str, int32_t start); +FSTRING_INLINE String substr(String str, int32_t start, int32_t size); +FSTRING_LINK String skip_whitespace(String str); +FSTRING_LINK String chop_whitespace(String str); +FSTRING_LINK String skip_chop_whitespace(String str); +FSTRING_INLINE String tailstr(String str); +FSTRING_LINK fstr_bool match_cc(char *a, char *b); +FSTRING_LINK fstr_bool match_sc(String a, char *b); +FSTRING_INLINE fstr_bool match_cs(char *a, String b); +FSTRING_LINK fstr_bool match_ss(String a, String b); +FSTRING_LINK fstr_bool match_part_ccl(char *a, char *b, int32_t *len); +FSTRING_LINK fstr_bool match_part_scl(String a, char *b, int32_t *len); +FSTRING_INLINE fstr_bool match_part_cc(char *a, char *b); +FSTRING_INLINE fstr_bool match_part_sc(String a, char *b); +FSTRING_LINK fstr_bool match_part_cs(char *a, String b); +FSTRING_LINK fstr_bool match_part_ss(String a, String b); +FSTRING_LINK fstr_bool match_insensitive_cc(char *a, char *b); +FSTRING_LINK fstr_bool match_insensitive_sc(String a, char *b); +FSTRING_INLINE fstr_bool match_insensitive_cs(char *a, String b); +FSTRING_LINK fstr_bool match_insensitive_ss(String a, String b); +FSTRING_LINK fstr_bool match_part_insensitive_ccl(char *a, char *b, int32_t *len); +FSTRING_LINK fstr_bool match_part_insensitive_scl(String a, char *b, int32_t *len); +FSTRING_INLINE fstr_bool match_part_insensitive_cc(char *a, char *b); +FSTRING_INLINE fstr_bool match_part_insensitive_sc(String a, char *b); +FSTRING_LINK fstr_bool match_part_insensitive_cs(char *a, String b); +FSTRING_LINK fstr_bool match_part_insensitive_ss(String a, String b); +FSTRING_LINK int32_t compare_cc(char *a, char *b); +FSTRING_LINK int32_t compare_sc(String a, char *b); +FSTRING_INLINE int32_t compare_cs(char *a, String b); +FSTRING_LINK int32_t compare_ss(String a, String b); +FSTRING_LINK int32_t find_c_char(char *str, int32_t start, char character); +FSTRING_LINK int32_t find_s_char(String str, int32_t start, char character); +FSTRING_LINK int32_t rfind_s_char(String str, int32_t start, char character); +FSTRING_LINK int32_t find_c_chars(char *str, int32_t start, char *characters); +FSTRING_LINK int32_t find_s_chars(String str, int32_t start, char *characters); +FSTRING_LINK int32_t find_substr_c(char *str, int32_t start, String seek); +FSTRING_LINK int32_t find_substr_s(String str, int32_t start, String seek); +FSTRING_LINK int32_t rfind_substr_s(String str, int32_t start, String seek); +FSTRING_LINK int32_t find_substr_insensitive_c(char *str, int32_t start, String seek); +FSTRING_LINK int32_t find_substr_insensitive_s(String str, int32_t start, String seek); +FSTRING_INLINE fstr_bool has_substr_c(char *s, String seek); +FSTRING_INLINE fstr_bool has_substr_s(String s, String seek); +FSTRING_INLINE fstr_bool has_substr_insensitive_c(char *s, String seek); +FSTRING_INLINE fstr_bool has_substr_insensitive_s(String s, String seek); +FSTRING_LINK int32_t copy_fast_unsafe_cc(char *dest, char *src); +FSTRING_LINK int32_t copy_fast_unsafe_cs(char *dest, String src); +FSTRING_LINK fstr_bool copy_checked_ss(String *dest, String src); +FSTRING_LINK fstr_bool copy_partial_sc(String *dest, char *src); +FSTRING_LINK fstr_bool copy_partial_ss(String *dest, String src); +FSTRING_INLINE int32_t copy_cc(char *dest, char *src); +FSTRING_INLINE void copy_ss(String *dest, String src); +FSTRING_INLINE void copy_sc(String *dest, char *src); +FSTRING_LINK fstr_bool append_checked_ss(String *dest, String src); +FSTRING_LINK fstr_bool append_partial_sc(String *dest, char *src); +FSTRING_LINK fstr_bool append_partial_ss(String *dest, String src); +FSTRING_LINK fstr_bool append_s_char(String *dest, char c); +FSTRING_INLINE fstr_bool append_ss(String *dest, String src); +FSTRING_INLINE fstr_bool append_sc(String *dest, char *src); +FSTRING_LINK fstr_bool terminate_with_null(String *str); +FSTRING_LINK fstr_bool append_padding(String *dest, char c, int32_t target_size); +FSTRING_LINK void replace_char(String *str, char replace, char with); +FSTRING_LINK void to_lower_cc(char *src, char *dst); +FSTRING_LINK void to_lower_ss(String *dst, String src); +FSTRING_LINK void to_lower_s(String *str); +FSTRING_LINK void to_upper_cc(char *src, char *dst); +FSTRING_LINK void to_upper_ss(String *dst, String src); +FSTRING_LINK void to_upper_s(String *str); +FSTRING_LINK void to_camel_cc(char *src, char *dst); +FSTRING_LINK int32_t int_to_str_size(int32_t x); +FSTRING_LINK fstr_bool int_to_str(String *dest, int32_t x); +FSTRING_LINK fstr_bool append_int_to_str(String *dest, int32_t x); +FSTRING_LINK int32_t u64_to_str_size(uint64_t x); +FSTRING_LINK fstr_bool u64_to_str(String *dest, uint64_t x); +FSTRING_LINK fstr_bool append_u64_to_str(String *dest, uint64_t x); +FSTRING_LINK int32_t float_to_str_size(float x); +FSTRING_LINK fstr_bool append_float_to_str(String *dest, float x); +FSTRING_LINK fstr_bool float_to_str(String *dest, float x); +FSTRING_LINK int32_t str_is_int_c(char *str); +FSTRING_LINK fstr_bool str_is_int_s(String str); +FSTRING_LINK int32_t str_to_int_c(char *str); +FSTRING_LINK int32_t str_to_int_s(String str); +FSTRING_LINK int32_t hexchar_to_int(char c); +FSTRING_LINK char int_to_hexchar(int32_t x); +FSTRING_LINK uint32_t hexstr_to_int(String str); +FSTRING_LINK fstr_bool color_to_hexstr(String *s, uint32_t color); +FSTRING_LINK fstr_bool hexstr_to_color(String s, uint32_t *out); +FSTRING_LINK int32_t reverse_seek_slash_pos(String str, int32_t pos); +FSTRING_INLINE int32_t reverse_seek_slash(String str); +FSTRING_INLINE String front_of_directory(String dir); +FSTRING_INLINE String path_of_directory(String dir); +FSTRING_LINK fstr_bool set_last_folder_sc(String *dir, char *folder_name, char slash); +FSTRING_LINK fstr_bool set_last_folder_ss(String *dir, String folder_name, char slash); +FSTRING_LINK String file_extension(String str); +FSTRING_LINK fstr_bool remove_extension(String *str); +FSTRING_LINK fstr_bool remove_last_folder(String *str); +FSTRING_LINK fstr_bool string_set_match_table(void *str_set, int32_t item_size, int32_t count, String str, int32_t *match_index); +FSTRING_LINK fstr_bool string_set_match(String *str_set, int32_t count, String str, int32_t *match_index); #endif #if !defined(FSTRING_C) && !defined(FSTRING_GUARD) -FSTRING_INLINE String make_string(void *str, int32_t size, int32_t mem_size){return(make_string_cap(str,size,mem_size));} -FSTRING_INLINE String substr(String str, int32_t start){return(substr_tail(str,start));} -FSTRING_INLINE fstr_bool match(char *a, char *b){return(match_cc(a,b));} -FSTRING_INLINE fstr_bool match(String a, char *b){return(match_sc(a,b));} -FSTRING_INLINE fstr_bool match(char *a, String b){return(match_cs(a,b));} -FSTRING_INLINE fstr_bool match(String a, String b){return(match_ss(a,b));} -FSTRING_INLINE fstr_bool match_part(char *a, char *b, int32_t *len){return(match_part_ccl(a,b,len));} -FSTRING_INLINE fstr_bool match_part(String a, char *b, int32_t *len){return(match_part_scl(a,b,len));} -FSTRING_INLINE fstr_bool match_part(char *a, char *b){return(match_part_cc(a,b));} -FSTRING_INLINE fstr_bool match_part(String a, char *b){return(match_part_sc(a,b));} -FSTRING_INLINE fstr_bool match_part(char *a, String b){return(match_part_cs(a,b));} -FSTRING_INLINE fstr_bool match_part(String a, String b){return(match_part_ss(a,b));} -FSTRING_INLINE fstr_bool match_insensitive(char *a, char *b){return(match_insensitive_cc(a,b));} -FSTRING_INLINE fstr_bool match_insensitive(String a, char *b){return(match_insensitive_sc(a,b));} -FSTRING_INLINE fstr_bool match_insensitive(char *a, String b){return(match_insensitive_cs(a,b));} -FSTRING_INLINE fstr_bool match_insensitive(String a, String b){return(match_insensitive_ss(a,b));} -FSTRING_INLINE fstr_bool match_part_insensitive(char *a, char *b, int32_t *len){return(match_part_insensitive_ccl(a,b,len));} -FSTRING_INLINE fstr_bool match_part_insensitive(String a, char *b, int32_t *len){return(match_part_insensitive_scl(a,b,len));} -FSTRING_INLINE fstr_bool match_part_insensitive(char *a, char *b){return(match_part_insensitive_cc(a,b));} -FSTRING_INLINE fstr_bool match_part_insensitive(String a, char *b){return(match_part_insensitive_sc(a,b));} -FSTRING_INLINE fstr_bool match_part_insensitive(char *a, String b){return(match_part_insensitive_cs(a,b));} -FSTRING_INLINE fstr_bool match_part_insensitive(String a, String b){return(match_part_insensitive_ss(a,b));} -FSTRING_INLINE int32_t compare(char *a, char *b){return(compare_cc(a,b));} -FSTRING_INLINE int32_t compare(String a, char *b){return(compare_sc(a,b));} -FSTRING_INLINE int32_t compare(char *a, String b){return(compare_cs(a,b));} -FSTRING_INLINE int32_t compare(String a, String b){return(compare_ss(a,b));} -FSTRING_INLINE int32_t find(char *str, int32_t start, char character){return(find_c_char(str,start,character));} -FSTRING_INLINE int32_t find(String str, int32_t start, char character){return(find_s_char(str,start,character));} -FSTRING_INLINE int32_t rfind(String str, int32_t start, char character){return(rfind_s_char(str,start,character));} -FSTRING_INLINE int32_t find(char *str, int32_t start, char *characters){return(find_c_chars(str,start,characters));} -FSTRING_INLINE int32_t find(String str, int32_t start, char *characters){return(find_s_chars(str,start,characters));} -FSTRING_INLINE int32_t find_substr(char *str, int32_t start, String seek){return(find_substr_c(str,start,seek));} -FSTRING_INLINE int32_t find_substr(String str, int32_t start, String seek){return(find_substr_s(str,start,seek));} -FSTRING_INLINE int32_t rfind_substr(String str, int32_t start, String seek){return(rfind_substr_s(str,start,seek));} -FSTRING_INLINE int32_t find_substr_insensitive(char *str, int32_t start, String seek){return(find_substr_insensitive_c(str,start,seek));} -FSTRING_INLINE int32_t find_substr_insensitive(String str, int32_t start, String seek){return(find_substr_insensitive_s(str,start,seek));} -FSTRING_INLINE fstr_bool has_substr(char *s, String seek){return(has_substr_c(s,seek));} -FSTRING_INLINE fstr_bool has_substr(String s, String seek){return(has_substr_s(s,seek));} -FSTRING_INLINE fstr_bool has_substr_insensitive(char *s, String seek){return(has_substr_insensitive_c(s,seek));} -FSTRING_INLINE fstr_bool has_substr_insensitive(String s, String seek){return(has_substr_insensitive_s(s,seek));} -FSTRING_INLINE int32_t copy_fast_unsafe(char *dest, char *src){return(copy_fast_unsafe_cc(dest,src));} -FSTRING_INLINE int32_t copy_fast_unsafe(char *dest, String src){return(copy_fast_unsafe_cs(dest,src));} -FSTRING_INLINE fstr_bool copy_checked(String *dest, String src){return(copy_checked_ss(dest,src));} -FSTRING_INLINE fstr_bool copy_partial(String *dest, char *src){return(copy_partial_sc(dest,src));} -FSTRING_INLINE fstr_bool copy_partial(String *dest, String src){return(copy_partial_ss(dest,src));} -FSTRING_INLINE int32_t copy(char *dest, char *src){return(copy_cc(dest,src));} -FSTRING_INLINE void copy(String *dest, String src){(copy_ss(dest,src));} -FSTRING_INLINE void copy(String *dest, char *src){(copy_sc(dest,src));} -FSTRING_INLINE fstr_bool append_checked(String *dest, String src){return(append_checked_ss(dest,src));} -FSTRING_INLINE fstr_bool append_partial(String *dest, char *src){return(append_partial_sc(dest,src));} -FSTRING_INLINE fstr_bool append_partial(String *dest, String src){return(append_partial_ss(dest,src));} -FSTRING_INLINE fstr_bool append(String *dest, char c){return(append_s_char(dest,c));} -FSTRING_INLINE fstr_bool append(String *dest, String src){return(append_ss(dest,src));} -FSTRING_INLINE fstr_bool append(String *dest, char *src){return(append_sc(dest,src));} -FSTRING_INLINE void to_lower(char *src, char *dst){(to_lower_cc(src,dst));} -FSTRING_INLINE void to_lower(String *dst, String src){(to_lower_ss(dst,src));} -FSTRING_INLINE void to_lower(String *str){(to_lower_s(str));} -FSTRING_INLINE void to_upper(char *src, char *dst){(to_upper_cc(src,dst));} -FSTRING_INLINE void to_upper(String *dst, String src){(to_upper_ss(dst,src));} -FSTRING_INLINE void to_upper(String *str){(to_upper_s(str));} -FSTRING_INLINE void to_camel(char *src, char *dst){(to_camel_cc(src,dst));} -FSTRING_INLINE int32_t str_is_int(char *str){return(str_is_int_c(str));} -FSTRING_INLINE fstr_bool str_is_int(String str){return(str_is_int_s(str));} -FSTRING_INLINE int32_t str_to_int(char *str){return(str_to_int_c(str));} -FSTRING_INLINE int32_t str_to_int(String str){return(str_to_int_s(str));} -FSTRING_INLINE int32_t reverse_seek_slash(String str, int32_t pos){return(reverse_seek_slash_pos(str,pos));} -FSTRING_INLINE fstr_bool set_last_folder(String *dir, char *folder_name, char slash){return(set_last_folder_sc(dir,folder_name,slash));} -FSTRING_INLINE fstr_bool set_last_folder(String *dir, String folder_name, char slash){return(set_last_folder_ss(dir,folder_name,slash));} -FSTRING_INLINE fstr_bool string_set_match(void *str_set, int32_t item_size, int32_t count, String str, int32_t *match_index){return(string_set_match_table(str_set,item_size,count,str,match_index));} +FSTRING_INLINE String make_string(void *str, int32_t size, int32_t mem_size){return(make_string_cap(str,size,mem_size));} +FSTRING_INLINE String substr(String str, int32_t start){return(substr_tail(str,start));} +FSTRING_LINK fstr_bool match(char *a, char *b){return(match_cc(a,b));} +FSTRING_LINK fstr_bool match(String a, char *b){return(match_sc(a,b));} +FSTRING_INLINE fstr_bool match(char *a, String b){return(match_cs(a,b));} +FSTRING_LINK fstr_bool match(String a, String b){return(match_ss(a,b));} +FSTRING_LINK fstr_bool match_part(char *a, char *b, int32_t *len){return(match_part_ccl(a,b,len));} +FSTRING_LINK fstr_bool match_part(String a, char *b, int32_t *len){return(match_part_scl(a,b,len));} +FSTRING_INLINE fstr_bool match_part(char *a, char *b){return(match_part_cc(a,b));} +FSTRING_INLINE fstr_bool match_part(String a, char *b){return(match_part_sc(a,b));} +FSTRING_LINK fstr_bool match_part(char *a, String b){return(match_part_cs(a,b));} +FSTRING_LINK fstr_bool match_part(String a, String b){return(match_part_ss(a,b));} +FSTRING_LINK fstr_bool match_insensitive(char *a, char *b){return(match_insensitive_cc(a,b));} +FSTRING_LINK fstr_bool match_insensitive(String a, char *b){return(match_insensitive_sc(a,b));} +FSTRING_INLINE fstr_bool match_insensitive(char *a, String b){return(match_insensitive_cs(a,b));} +FSTRING_LINK fstr_bool match_insensitive(String a, String b){return(match_insensitive_ss(a,b));} +FSTRING_LINK fstr_bool match_part_insensitive(char *a, char *b, int32_t *len){return(match_part_insensitive_ccl(a,b,len));} +FSTRING_LINK fstr_bool match_part_insensitive(String a, char *b, int32_t *len){return(match_part_insensitive_scl(a,b,len));} +FSTRING_INLINE fstr_bool match_part_insensitive(char *a, char *b){return(match_part_insensitive_cc(a,b));} +FSTRING_INLINE fstr_bool match_part_insensitive(String a, char *b){return(match_part_insensitive_sc(a,b));} +FSTRING_LINK fstr_bool match_part_insensitive(char *a, String b){return(match_part_insensitive_cs(a,b));} +FSTRING_LINK fstr_bool match_part_insensitive(String a, String b){return(match_part_insensitive_ss(a,b));} +FSTRING_LINK int32_t compare(char *a, char *b){return(compare_cc(a,b));} +FSTRING_LINK int32_t compare(String a, char *b){return(compare_sc(a,b));} +FSTRING_INLINE int32_t compare(char *a, String b){return(compare_cs(a,b));} +FSTRING_LINK int32_t compare(String a, String b){return(compare_ss(a,b));} +FSTRING_LINK int32_t find(char *str, int32_t start, char character){return(find_c_char(str,start,character));} +FSTRING_LINK int32_t find(String str, int32_t start, char character){return(find_s_char(str,start,character));} +FSTRING_LINK int32_t rfind(String str, int32_t start, char character){return(rfind_s_char(str,start,character));} +FSTRING_LINK int32_t find(char *str, int32_t start, char *characters){return(find_c_chars(str,start,characters));} +FSTRING_LINK int32_t find(String str, int32_t start, char *characters){return(find_s_chars(str,start,characters));} +FSTRING_LINK int32_t find_substr(char *str, int32_t start, String seek){return(find_substr_c(str,start,seek));} +FSTRING_LINK int32_t find_substr(String str, int32_t start, String seek){return(find_substr_s(str,start,seek));} +FSTRING_LINK int32_t rfind_substr(String str, int32_t start, String seek){return(rfind_substr_s(str,start,seek));} +FSTRING_LINK int32_t find_substr_insensitive(char *str, int32_t start, String seek){return(find_substr_insensitive_c(str,start,seek));} +FSTRING_LINK int32_t find_substr_insensitive(String str, int32_t start, String seek){return(find_substr_insensitive_s(str,start,seek));} +FSTRING_INLINE fstr_bool has_substr(char *s, String seek){return(has_substr_c(s,seek));} +FSTRING_INLINE fstr_bool has_substr(String s, String seek){return(has_substr_s(s,seek));} +FSTRING_INLINE fstr_bool has_substr_insensitive(char *s, String seek){return(has_substr_insensitive_c(s,seek));} +FSTRING_INLINE fstr_bool has_substr_insensitive(String s, String seek){return(has_substr_insensitive_s(s,seek));} +FSTRING_LINK int32_t copy_fast_unsafe(char *dest, char *src){return(copy_fast_unsafe_cc(dest,src));} +FSTRING_LINK int32_t copy_fast_unsafe(char *dest, String src){return(copy_fast_unsafe_cs(dest,src));} +FSTRING_LINK fstr_bool copy_checked(String *dest, String src){return(copy_checked_ss(dest,src));} +FSTRING_LINK fstr_bool copy_partial(String *dest, char *src){return(copy_partial_sc(dest,src));} +FSTRING_LINK fstr_bool copy_partial(String *dest, String src){return(copy_partial_ss(dest,src));} +FSTRING_INLINE int32_t copy(char *dest, char *src){return(copy_cc(dest,src));} +FSTRING_INLINE void copy(String *dest, String src){return(copy_ss(dest,src));} +FSTRING_INLINE void copy(String *dest, char *src){return(copy_sc(dest,src));} +FSTRING_LINK fstr_bool append_checked(String *dest, String src){return(append_checked_ss(dest,src));} +FSTRING_LINK fstr_bool append_partial(String *dest, char *src){return(append_partial_sc(dest,src));} +FSTRING_LINK fstr_bool append_partial(String *dest, String src){return(append_partial_ss(dest,src));} +FSTRING_LINK fstr_bool append(String *dest, char c){return(append_s_char(dest,c));} +FSTRING_INLINE fstr_bool append(String *dest, String src){return(append_ss(dest,src));} +FSTRING_INLINE fstr_bool append(String *dest, char *src){return(append_sc(dest,src));} +FSTRING_LINK void to_lower(char *src, char *dst){return(to_lower_cc(src,dst));} +FSTRING_LINK void to_lower(String *dst, String src){return(to_lower_ss(dst,src));} +FSTRING_LINK void to_lower(String *str){return(to_lower_s(str));} +FSTRING_LINK void to_upper(char *src, char *dst){return(to_upper_cc(src,dst));} +FSTRING_LINK void to_upper(String *dst, String src){return(to_upper_ss(dst,src));} +FSTRING_LINK void to_upper(String *str){return(to_upper_s(str));} +FSTRING_LINK void to_camel(char *src, char *dst){return(to_camel_cc(src,dst));} +FSTRING_LINK int32_t str_is_int(char *str){return(str_is_int_c(str));} +FSTRING_LINK fstr_bool str_is_int(String str){return(str_is_int_s(str));} +FSTRING_LINK int32_t str_to_int(char *str){return(str_to_int_c(str));} +FSTRING_LINK int32_t str_to_int(String str){return(str_to_int_s(str));} +FSTRING_LINK int32_t reverse_seek_slash(String str, int32_t pos){return(reverse_seek_slash_pos(str,pos));} +FSTRING_LINK fstr_bool set_last_folder(String *dir, char *folder_name, char slash){return(set_last_folder_sc(dir,folder_name,slash));} +FSTRING_LINK fstr_bool set_last_folder(String *dir, String folder_name, char slash){return(set_last_folder_ss(dir,folder_name,slash));} +FSTRING_LINK fstr_bool string_set_match(void *str_set, int32_t item_size, int32_t count, String str, int32_t *match_index){return(string_set_match_table(str_set,item_size,count,str,match_index));} #endif @@ -256,7 +256,7 @@ static String null_string = {0}; // #if !defined(FSTRING_GUARD) -FSTRING_INLINE fstr_bool + FSTRING_INLINE fstr_bool char_is_slash(char c) { return (c == '\\' || c == '/'); @@ -264,7 +264,7 @@ char_is_slash(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE fstr_bool + FSTRING_INLINE fstr_bool char_is_upper(char c) { return (c >= 'A' && c <= 'Z'); @@ -272,7 +272,7 @@ char_is_upper(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE fstr_bool + FSTRING_INLINE fstr_bool char_is_lower(char c) { return (c >= 'a' && c <= 'z'); @@ -280,7 +280,7 @@ char_is_lower(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE char + FSTRING_INLINE char char_to_upper(char c) { return (c >= 'a' && c <= 'z') ? c + (char)('A' - 'a') : c; @@ -288,7 +288,7 @@ char_to_upper(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE char + FSTRING_INLINE char char_to_lower(char c) { return (c >= 'A' && c <= 'Z') ? c - (char)('A' - 'a') : c; @@ -296,7 +296,7 @@ char_to_lower(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE fstr_bool + FSTRING_INLINE fstr_bool char_is_whitespace(char c) { return (c == ' ' || c == '\n' || c == '\r' || c == '\t'); @@ -304,7 +304,7 @@ char_is_whitespace(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE fstr_bool + FSTRING_INLINE fstr_bool char_is_alpha_numeric(char c) { return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '_'); @@ -312,7 +312,7 @@ char_is_alpha_numeric(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE fstr_bool + FSTRING_INLINE fstr_bool char_is_alpha_numeric_true(char c) { return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9'); @@ -320,7 +320,7 @@ char_is_alpha_numeric_true(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE fstr_bool + FSTRING_INLINE fstr_bool char_is_alpha(char c) { return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c == '_'); @@ -328,7 +328,7 @@ char_is_alpha(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE fstr_bool + FSTRING_INLINE fstr_bool char_is_alpha_true(char c) { return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'); @@ -336,7 +336,7 @@ char_is_alpha_true(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE fstr_bool + FSTRING_INLINE fstr_bool char_is_hex(char c) { return (c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f'); @@ -344,7 +344,7 @@ char_is_hex(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE fstr_bool + FSTRING_INLINE fstr_bool char_is_numeric(char c) { return (c >= '0' && c <= '9'); @@ -358,7 +358,7 @@ char_is_numeric(char c) #if !defined(FSTRING_GUARD) -FSTRING_INLINE String + FSTRING_INLINE String make_string_cap(void *str, int32_t size, int32_t mem_size){ String result; result.str = (char*)str; @@ -369,7 +369,7 @@ make_string_cap(void *str, int32_t size, int32_t mem_size){ #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE String + FSTRING_INLINE String make_string(void *str, int32_t size){ String result; result.str = (char*)str; @@ -380,7 +380,7 @@ make_string(void *str, int32_t size){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK int32_t + FSTRING_LINK int32_t str_size(char *str) { int32_t i = 0; @@ -390,7 +390,7 @@ str_size(char *str) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE String + FSTRING_INLINE String make_string_slowly(void *str) { String result; @@ -403,7 +403,7 @@ make_string_slowly(void *str) #if !defined(FSTRING_GUARD) -FSTRING_INLINE String + FSTRING_INLINE String substr_tail(String str, int32_t start) { String result; @@ -415,7 +415,7 @@ substr_tail(String str, int32_t start) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE String + FSTRING_INLINE String substr(String str, int32_t start, int32_t size) { String result; @@ -430,7 +430,7 @@ substr(String str, int32_t start, int32_t size) #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String + FSTRING_LINK String skip_whitespace(String str) { String result = {0}; @@ -442,7 +442,7 @@ skip_whitespace(String str) #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String + FSTRING_LINK String chop_whitespace(String str) { String result = {0}; @@ -454,7 +454,7 @@ chop_whitespace(String str) #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String + FSTRING_LINK String skip_chop_whitespace(String str) { str = skip_whitespace(str); @@ -464,7 +464,7 @@ skip_chop_whitespace(String str) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE String + FSTRING_INLINE String tailstr(String str) { String result; @@ -482,7 +482,7 @@ tailstr(String str) #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool match_cc(char *a, char *b){ for (int32_t i = 0;; ++i){ if (a[i] != b[i]){ @@ -497,7 +497,7 @@ match_cc(char *a, char *b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool match_sc(String a, char *b){ int32_t i = 0; for (; i < a.size; ++i){ @@ -514,7 +514,7 @@ match_sc(String a, char *b){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE fstr_bool + FSTRING_INLINE fstr_bool match_cs(char *a, String b){ return(match_sc(b,a)); } @@ -522,7 +522,7 @@ match_cs(char *a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool match_ss(String a, String b){ if (a.size != b.size){ return 0; @@ -538,7 +538,7 @@ match_ss(String a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool match_part_ccl(char *a, char *b, int32_t *len){ int32_t i; for (i = 0; b[i] != 0; ++i){ @@ -553,7 +553,7 @@ match_part_ccl(char *a, char *b, int32_t *len){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool match_part_scl(String a, char *b, int32_t *len){ int32_t i; for (i = 0; b[i] != 0; ++i){ @@ -568,7 +568,7 @@ match_part_scl(String a, char *b, int32_t *len){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE fstr_bool + FSTRING_INLINE fstr_bool match_part_cc(char *a, char *b){ int32_t x; return match_part_ccl(a,b,&x); @@ -577,7 +577,7 @@ match_part_cc(char *a, char *b){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE fstr_bool + FSTRING_INLINE fstr_bool match_part_sc(String a, char *b){ int32_t x; return match_part_scl(a,b,&x); @@ -586,7 +586,7 @@ match_part_sc(String a, char *b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool match_part_cs(char *a, String b){ for (int32_t i = 0; i != b.size; ++i){ if (a[i] != b.str[i]){ @@ -599,7 +599,7 @@ match_part_cs(char *a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool match_part_ss(String a, String b){ if (a.size < b.size){ return 0; @@ -615,7 +615,7 @@ match_part_ss(String a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool match_insensitive_cc(char *a, char *b){ for (int32_t i = 0;; ++i){ if (char_to_upper(a[i]) != @@ -631,7 +631,7 @@ match_insensitive_cc(char *a, char *b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool match_insensitive_sc(String a, char *b){ int32_t i = 0; for (; i < a.size; ++i){ @@ -649,7 +649,7 @@ match_insensitive_sc(String a, char *b){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE fstr_bool + FSTRING_INLINE fstr_bool match_insensitive_cs(char *a, String b){ return match_insensitive_sc(b,a); } @@ -657,7 +657,7 @@ match_insensitive_cs(char *a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool match_insensitive_ss(String a, String b){ if (a.size != b.size){ return 0; @@ -674,7 +674,7 @@ match_insensitive_ss(String a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool match_part_insensitive_ccl(char *a, char *b, int32_t *len){ int32_t i; for (i = 0; b[i] != 0; ++i){ @@ -689,7 +689,7 @@ match_part_insensitive_ccl(char *a, char *b, int32_t *len){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool match_part_insensitive_scl(String a, char *b, int32_t *len){ int32_t i; for (i = 0; b[i] != 0; ++i){ @@ -705,7 +705,7 @@ match_part_insensitive_scl(String a, char *b, int32_t *len){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE fstr_bool + FSTRING_INLINE fstr_bool match_part_insensitive_cc(char *a, char *b){ int32_t x; return match_part_insensitive_ccl(a,b,&x); @@ -714,7 +714,7 @@ match_part_insensitive_cc(char *a, char *b){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE fstr_bool + FSTRING_INLINE fstr_bool match_part_insensitive_sc(String a, char *b){ int32_t x; return match_part_insensitive_scl(a,b,&x); @@ -723,7 +723,7 @@ match_part_insensitive_sc(String a, char *b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool match_part_insensitive_cs(char *a, String b){ for (int32_t i = 0; i != b.size; ++i){ if (char_to_upper(a[i]) != char_to_upper(b.str[i])){ @@ -736,7 +736,7 @@ match_part_insensitive_cs(char *a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool match_part_insensitive_ss(String a, String b){ if (a.size < b.size){ return(0); @@ -752,7 +752,7 @@ match_part_insensitive_ss(String a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK int32_t + FSTRING_LINK int32_t compare_cc(char *a, char *b){ int32_t i = 0, r = 0; while (a[i] == b[i] && a[i] != 0){ @@ -765,7 +765,7 @@ compare_cc(char *a, char *b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK int32_t + FSTRING_LINK int32_t compare_sc(String a, char *b){ int32_t i = 0, r = 0; while (i < a.size && a.str[i] == b[i]){ @@ -788,7 +788,7 @@ compare_sc(String a, char *b){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE int32_t + FSTRING_INLINE int32_t compare_cs(char *a, String b){ int32_t r = -compare_sc(b,a); return(r); @@ -797,7 +797,7 @@ compare_cs(char *a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK int32_t + FSTRING_LINK int32_t compare_ss(String a, String b){ int32_t i = 0, r = 0; int32_t m = a.size; @@ -825,7 +825,7 @@ compare_ss(String a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK int32_t + FSTRING_LINK int32_t find_c_char(char *str, int32_t start, char character){ int32_t i = start; while (str[i] != character && str[i] != 0) ++i; @@ -835,7 +835,7 @@ find_c_char(char *str, int32_t start, char character){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK int32_t + FSTRING_LINK int32_t find_s_char(String str, int32_t start, char character){ int32_t i = start; while (i < str.size && str.str[i] != character) ++i; @@ -845,7 +845,7 @@ find_s_char(String str, int32_t start, char character){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK int32_t + FSTRING_LINK int32_t rfind_s_char(String str, int32_t start, char character){ int32_t i = start; while (i >= 0 && str.str[i] != character) --i; @@ -855,7 +855,7 @@ rfind_s_char(String str, int32_t start, char character){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK int32_t + FSTRING_LINK int32_t find_c_chars(char *str, int32_t start, char *characters){ int32_t i = start, j; while (str[i] != 0){ @@ -872,7 +872,7 @@ find_c_chars(char *str, int32_t start, char *characters){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK int32_t + FSTRING_LINK int32_t find_s_chars(String str, int32_t start, char *characters){ int32_t i = start, j; while (i < str.size){ @@ -889,7 +889,7 @@ find_s_chars(String str, int32_t start, char *characters){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK int32_t + FSTRING_LINK int32_t find_substr_c(char *str, int32_t start, String seek){ int32_t i, j, k; fstr_bool hit; @@ -918,7 +918,7 @@ find_substr_c(char *str, int32_t start, String seek){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK int32_t + FSTRING_LINK int32_t find_substr_s(String str, int32_t start, String seek){ int32_t stop_at, i, j, k; fstr_bool hit; @@ -947,7 +947,7 @@ find_substr_s(String str, int32_t start, String seek){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK int32_t + FSTRING_LINK int32_t rfind_substr_s(String str, int32_t start, String seek){ int32_t i, j, k; fstr_bool hit; @@ -978,7 +978,7 @@ rfind_substr_s(String str, int32_t start, String seek){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK int32_t + FSTRING_LINK int32_t find_substr_insensitive_c(char *str, int32_t start, String seek){ int32_t i, j, k; fstr_bool hit; @@ -1009,7 +1009,7 @@ find_substr_insensitive_c(char *str, int32_t start, String seek){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK int32_t + FSTRING_LINK int32_t find_substr_insensitive_s(String str, int32_t start, String seek){ int32_t i, j, k; int32_t stop_at; @@ -1042,7 +1042,7 @@ find_substr_insensitive_s(String str, int32_t start, String seek){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE fstr_bool + FSTRING_INLINE fstr_bool has_substr_c(char *s, String seek){ return (s[find_substr_c(s, 0, seek)] != 0); } @@ -1050,7 +1050,7 @@ has_substr_c(char *s, String seek){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE fstr_bool + FSTRING_INLINE fstr_bool has_substr_s(String s, String seek){ return (find_substr_s(s, 0, seek) < s.size); } @@ -1058,7 +1058,7 @@ has_substr_s(String s, String seek){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE fstr_bool + FSTRING_INLINE fstr_bool has_substr_insensitive_c(char *s, String seek){ return (s[find_substr_insensitive_c(s, 0, seek)] != 0); } @@ -1066,7 +1066,7 @@ has_substr_insensitive_c(char *s, String seek){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE fstr_bool + FSTRING_INLINE fstr_bool has_substr_insensitive_s(String s, String seek){ return (find_substr_insensitive_s(s, 0, seek) < s.size); } @@ -1078,7 +1078,7 @@ has_substr_insensitive_s(String s, String seek){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK int32_t + FSTRING_LINK int32_t copy_fast_unsafe_cc(char *dest, char *src){ char *start = dest; while (*src != 0){ @@ -1092,7 +1092,7 @@ copy_fast_unsafe_cc(char *dest, char *src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK int32_t + FSTRING_LINK int32_t copy_fast_unsafe_cs(char *dest, String src){ int32_t i = 0; while (i != src.size){ @@ -1105,7 +1105,7 @@ copy_fast_unsafe_cs(char *dest, String src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool copy_checked_ss(String *dest, String src){ char *dest_str; int32_t i; @@ -1123,7 +1123,7 @@ copy_checked_ss(String *dest, String src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool copy_partial_sc(String *dest, char *src){ int32_t i = 0; int32_t memory_size = dest->memory_size; @@ -1142,7 +1142,7 @@ copy_partial_sc(String *dest, char *src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool copy_partial_ss(String *dest, String src){ char *dest_str = dest->str; int32_t memory_size = dest->memory_size; @@ -1161,7 +1161,7 @@ copy_partial_ss(String *dest, String src){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE int32_t + FSTRING_INLINE int32_t copy_cc(char *dest, char *src){ return copy_fast_unsafe_cc(dest, src); } @@ -1169,7 +1169,7 @@ copy_cc(char *dest, char *src){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE void + FSTRING_INLINE void copy_ss(String *dest, String src){ copy_checked_ss(dest, src); } @@ -1177,7 +1177,7 @@ copy_ss(String *dest, String src){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE void + FSTRING_INLINE void copy_sc(String *dest, char *src){ copy_partial_sc(dest, src); } @@ -1185,7 +1185,7 @@ copy_sc(String *dest, char *src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool append_checked_ss(String *dest, String src){ String end; end = tailstr(*dest); @@ -1199,7 +1199,7 @@ append_checked_ss(String *dest, String src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool append_partial_sc(String *dest, char *src){ String end = tailstr(*dest); fstr_bool result = copy_partial_sc(&end, src); @@ -1210,7 +1210,7 @@ append_partial_sc(String *dest, char *src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool append_partial_ss(String *dest, String src){ String end = tailstr(*dest); fstr_bool result = copy_partial_ss(&end, src); @@ -1221,7 +1221,7 @@ append_partial_ss(String *dest, String src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool append_s_char(String *dest, char c){ fstr_bool result = 0; if (dest->size < dest->memory_size){ @@ -1234,7 +1234,7 @@ append_s_char(String *dest, char c){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE fstr_bool + FSTRING_INLINE fstr_bool append_ss(String *dest, String src){ return append_partial_ss(dest, src); } @@ -1242,14 +1242,14 @@ append_ss(String *dest, String src){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE fstr_bool + FSTRING_INLINE fstr_bool append_sc(String *dest, char *src){ return append_partial_sc(dest, src); } #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool terminate_with_null(String *str){ fstr_bool result = 0; if (str->size < str->memory_size){ @@ -1261,7 +1261,7 @@ terminate_with_null(String *str){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool append_padding(String *dest, char c, int32_t target_size){ fstr_bool result = 1; int32_t offset = target_size - dest->size; @@ -1284,7 +1284,7 @@ append_padding(String *dest, char c, int32_t target_size){ // #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void + FSTRING_LINK void replace_char(String *str, char replace, char with){ char *s = str->str; int32_t i = 0; @@ -1296,7 +1296,7 @@ replace_char(String *str, char replace, char with){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void + FSTRING_LINK void to_lower_cc(char *src, char *dst){ for (; *src != 0; ++src){ *dst++ = char_to_lower(*src); @@ -1307,7 +1307,7 @@ to_lower_cc(char *src, char *dst){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void + FSTRING_LINK void to_lower_ss(String *dst, String src){ int32_t i = 0; int32_t size = src.size; @@ -1325,7 +1325,7 @@ to_lower_ss(String *dst, String src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void + FSTRING_LINK void to_lower_s(String *str){ int32_t i = 0; int32_t size = str->size; @@ -1338,7 +1338,7 @@ to_lower_s(String *str){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void + FSTRING_LINK void to_upper_cc(char *src, char *dst){ for (; *src != 0; ++src){ *dst++ = char_to_upper(*src); @@ -1349,7 +1349,7 @@ to_upper_cc(char *src, char *dst){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void + FSTRING_LINK void to_upper_ss(String *dst, String src){ int32_t i = 0; int32_t size = src.size; @@ -1367,7 +1367,7 @@ to_upper_ss(String *dst, String src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void + FSTRING_LINK void to_upper_s(String *str){ int32_t i = 0; int32_t size = str->size; @@ -1380,7 +1380,7 @@ to_upper_s(String *str){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void + FSTRING_LINK void to_camel_cc(char *src, char *dst){ char *c, ch; int32_t is_first = 1; @@ -1410,7 +1410,7 @@ to_camel_cc(char *src, char *dst){ // #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK int32_t + FSTRING_LINK int32_t int_to_str_size(int32_t x){ int32_t size = 1; if (x < 0){ @@ -1426,7 +1426,7 @@ int_to_str_size(int32_t x){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool int_to_str(String *dest, int32_t x){ fstr_bool result = 1; char *str = dest->str; @@ -1474,7 +1474,7 @@ int_to_str(String *dest, int32_t x){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool append_int_to_str(String *dest, int32_t x){ String last_part = tailstr(*dest); fstr_bool result = int_to_str(&last_part, x); @@ -1486,7 +1486,7 @@ append_int_to_str(String *dest, int32_t x){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK int32_t + FSTRING_LINK int32_t u64_to_str_size(uint64_t x){ int32_t size; if (x < 0){ @@ -1505,7 +1505,7 @@ u64_to_str_size(uint64_t x){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool u64_to_str(String *dest, uint64_t x){ fstr_bool result = 1; char *str = dest->str; @@ -1544,7 +1544,7 @@ u64_to_str(String *dest, uint64_t x){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool append_u64_to_str(String *dest, uint64_t x){ String last_part = tailstr(*dest); fstr_bool result = u64_to_str(&last_part, x); @@ -1579,7 +1579,7 @@ get_float_vars(float x){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK int32_t + FSTRING_LINK int32_t float_to_str_size(float x){ Float_To_Str_Variables vars = get_float_vars(x); int32_t size = @@ -1589,7 +1589,7 @@ float_to_str_size(float x){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool append_float_to_str(String *dest, float x){ fstr_bool result = 1; Float_To_Str_Variables vars = get_float_vars(x); @@ -1607,7 +1607,7 @@ append_float_to_str(String *dest, float x){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool float_to_str(String *dest, float x){ fstr_bool result = 1; dest->size = 0; @@ -1618,7 +1618,7 @@ float_to_str(String *dest, float x){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK int32_t + FSTRING_LINK int32_t str_is_int_c(char *str){ fstr_bool result = 1; for (; *str; ++str){ @@ -1633,7 +1633,7 @@ str_is_int_c(char *str){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool str_is_int_s(String str){ fstr_bool result = 1; for (int32_t i = 0; i < str.size; ++i){ @@ -1648,7 +1648,7 @@ str_is_int_s(String str){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK int32_t + FSTRING_LINK int32_t str_to_int_c(char *str){ int32_t x = 0; for (; *str; ++str){ @@ -1667,7 +1667,7 @@ str_to_int_c(char *str){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK int32_t + FSTRING_LINK int32_t str_to_int_s(String str){ int32_t x, i; if (str.size == 0){ @@ -1685,7 +1685,7 @@ str_to_int_s(String str){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK int32_t + FSTRING_LINK int32_t hexchar_to_int(char c){ int32_t x = 0; if (c >= '0' && c <= '9'){ @@ -1702,14 +1702,14 @@ hexchar_to_int(char c){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK char + FSTRING_LINK char int_to_hexchar(int32_t x){ return (x<10)?((char)x+'0'):((char)x+'a'-10); } #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK uint32_t + FSTRING_LINK uint32_t hexstr_to_int(String str){ uint32_t x; int32_t i; @@ -1728,7 +1728,7 @@ hexstr_to_int(String str){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool color_to_hexstr(String *s, uint32_t color){ fstr_bool result = 0; int32_t i; @@ -1757,7 +1757,7 @@ color_to_hexstr(String *s, uint32_t color){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool hexstr_to_color(String s, uint32_t *out){ fstr_bool result = 0; uint32_t color = 0; @@ -1782,7 +1782,7 @@ hexstr_to_color(String s, uint32_t *out){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK int32_t + FSTRING_LINK int32_t reverse_seek_slash_pos(String str, int32_t pos){ int32_t i = str.size - 1 - pos; while (i >= 0 && !char_is_slash(str.str[i])){ @@ -1793,21 +1793,21 @@ reverse_seek_slash_pos(String str, int32_t pos){ #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE int32_t + FSTRING_INLINE int32_t reverse_seek_slash(String str){ return(reverse_seek_slash_pos(str, 0)); } #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE String + FSTRING_INLINE String front_of_directory(String dir){ return substr_tail(dir, reverse_seek_slash(dir) + 1); } #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE String + FSTRING_INLINE String path_of_directory(String dir){ return substr(dir, 0, reverse_seek_slash(dir) + 1); } @@ -1815,7 +1815,7 @@ path_of_directory(String dir){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool set_last_folder_sc(String *dir, char *folder_name, char slash){ fstr_bool result = 0; int32_t size = reverse_seek_slash(*dir) + 1; @@ -1834,7 +1834,7 @@ set_last_folder_sc(String *dir, char *folder_name, char slash){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool set_last_folder_ss(String *dir, String folder_name, char slash){ fstr_bool result = 0; int32_t size = reverse_seek_slash(*dir) + 1; @@ -1852,7 +1852,7 @@ set_last_folder_ss(String *dir, String folder_name, char slash){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String + FSTRING_LINK String file_extension(String str){ int32_t i; for (i = str.size - 1; i >= 0; --i){ @@ -1864,7 +1864,7 @@ file_extension(String str){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool remove_extension(String *str){ fstr_bool result = 0; int32_t i; @@ -1880,7 +1880,7 @@ remove_extension(String *str){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool remove_last_folder(String *str){ fstr_bool result = 0; int32_t end = reverse_seek_slash_pos(*str, 1); @@ -1895,7 +1895,7 @@ remove_last_folder(String *str){ // TODO(allen): Add hash-table extension to string sets. #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool string_set_match_table(void *str_set, int32_t item_size, int32_t count, String str, int32_t *match_index){ fstr_bool result = 0; int32_t i = 0; @@ -1912,7 +1912,7 @@ string_set_match_table(void *str_set, int32_t item_size, int32_t count, String s #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK fstr_bool + FSTRING_LINK fstr_bool string_set_match(String *str_set, int32_t count, String str, int32_t *match_index){ fstr_bool result = string_set_match_table(str_set, sizeof(String), count, str, match_index); return(result); diff --git a/4coder_types.h b/4coder_types.h index 2a0d0996..8151c727 100644 --- a/4coder_types.h +++ b/4coder_types.h @@ -1,28 +1,41 @@ #ifndef ENUM -#define ENUM(type,name) typedef type name; enum name##_ +# define ENUM(type,name) typedef type name; enum name##_ #endif +#ifndef TYPEDEF +# define TYPEDEF typedef +#endif + +#ifndef STRUCT +# define STRUCT struct +#endif + +#ifndef UNION +# define UNION union +#endif + + /* DOC(bool32 is an alias name to signal that an integer parameter or field is for -true/false vales.) */ -typedef int32_t bool32; +true/false values.) */ +TYPEDEF int32_t bool32; /* DOC(int_color is an alias name to signal that an integer parameter or field is for a color value, colors are specified as 24 bit integers in 3 channels: 0xRRGGBB.) */ -typedef uint32_t int_color; +TYPEDEF uint32_t int_color; /* DOC(Key_Code is the alias for key codes including raw codes and codes translated to textual input that takes modifiers into account.) */ -typedef unsigned char Key_Code; +TYPEDEF unsigned char Key_Code; /* DOC(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.) */ -typedef int32_t Buffer_ID; +TYPEDEF int32_t Buffer_ID; /* DOC(View_ID is used to name a 4coder view. Each view has a unique id in the interval [1,16].) */ -typedef int32_t View_ID; +TYPEDEF int32_t View_ID; /* DOC(A Key_Modifier acts as an index for specifying modifiers in arrays.) */ ENUM(int32_t, Key_Modifier){ @@ -216,9 +229,9 @@ ENUM(uint32_t, Buffer_Create_Flag){ }; -/* DOC(TODO) +/* DOC(Buffer_Creation_Data is a struct used as a local handle for the creation of a buffer. ) HIDE_MEMBERS() */ -struct Buffer_Creation_Data{ + STRUCT Buffer_Creation_Data{ Buffer_Create_Flag flags; char fname_space [256]; int32_t fname_len; @@ -233,12 +246,7 @@ ENUM(uint32_t, Buffer_Kill_Flag){ BufferKill_AlwaysKill = 0x2, }; -/* DOC(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.) */ +/* DOC(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.) */ ENUM(uint32_t, Access_Flag){ /* DOC(AccessOpen does not include any bits, it indicates that the access should only return objects that have no protection flags set.) */ @@ -255,25 +263,19 @@ ENUM(uint32_t, Access_Flag){ AccessAll = 0xFF }; -/* DOC(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.) */ +/* DOC(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.) */ ENUM(uint32_t, Dirty_State){ - /* DOC(DirtyState_UpToDate indicates that there are no unsaved changes and - the underlying system file still agrees with the buffer's state.) */ + /* DOC(DirtyState_UpToDate indicates that there are no unsaved changes and the underlying system file still agrees with the buffer's state.) */ DirtyState_UpToDate = 0, - /* DOC(DirtyState_UnsavedChanges indicates that there have been changes in the - buffer since the last sync point.) */ + /* DOC(DirtyState_UnsavedChanges indicates that there have been changes in the buffer since the last sync point.) */ DirtyState_UnsavedChanges = 1, - /* DOC(DirtyState_UnsavedChanges indicates that the underlying file has been - edited since the last sync point with the buffer.) */ + /* DOC(DirtyState_UnsavedChanges indicates that the underlying file has been edited since the last sync point with the buffer.) */ DirtyState_UnloadedChanges = 2 }; -/* DOC(A Seek_Boundary_Flag field specifies a set of "boundary" types used in seeks for the -beginning or end of different types of words.) */ +/* DOC(A Seek_Boundary_Flag field specifies a set of "boundary" types used in seeks for the beginning or end of different types of words.) */ ENUM(uint32_t, Seek_Boundary_Flag){ BoundaryWhitespace = 0x1, BoundaryToken = 0x2, @@ -283,34 +285,23 @@ ENUM(uint32_t, Seek_Boundary_Flag){ /* DOC(A Command_Line_Interface_Flag field specifies the behavior of a call to a command line interface.) */ ENUM(uint32_t, Command_Line_Interface_Flag){ - /* DOC(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.) */ + /* DOC(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_OverlapWithConflict = 0x1, - /* DOC(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.) */ + /* DOC(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_AlwaysBindToView = 0x2, - /* DOC(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.) */ + /* DOC(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.) */ CLI_CursorAtEnd = 0x4, }; /* DOC(An Auto_Indent_Flag field specifies the behavior of an auto indentation operation.) */ ENUM(uint32_t, Auto_Indent_Flag){ - /* DOC(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.) */ + /* DOC(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_ClearLine = 0x1, - /* DOC(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.) */ + /* DOC(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_UseTab = 0x2, - /* DOC(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.) */ + /* DOC(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_ExactAlignBlock = 0x4, - /* DOC(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.) */ + /* DOC(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.) */ AutoIndent_FullTokens = 0x8, }; @@ -355,8 +346,7 @@ ENUM(int32_t, Mouse_Cursor_Show_Type){ // MouseCursorShow_WhenActive,// TODO(allen): coming soon }; -/* DOC(A View_Split_Position specifies where a new view should be placed as a result of -a view split operation.) */ +/* DOC(A View_Split_Position specifies where a new view should be placed as a result of a view split operation.) */ ENUM(int32_t, View_Split_Position){ /* DOC(This value indicates that the new view should be above the existing view.) */ ViewSplit_Top, @@ -368,52 +358,35 @@ ENUM(int32_t, View_Split_Position){ ViewSplit_Right }; -/* DOC( -Generic_Command acts as a name for a command, and can name an -internal command or a custom command. -)*/ -union Generic_Command{ - /*DOC(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.)*/ +/* DOC(Generic_Command acts as a name for a command, and can name an internal command or a custom command.) */ + UNION Generic_Command{ + /*DOC(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_ID cmdid; /*DOC(If this Generic_Command does not represent an internal command the command field is the pointer to the custom command..)*/ Custom_Command_Function *command; }; -/* DOC( -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. -)*/ -struct Key_Event_Data{ +/* DOC(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.) */ +STRUCT Key_Event_Data{ /* DOC(This field is the raw keycode which is always non-zero in valid key events.) */ Key_Code keycode; /* DOC(This field is the keycode after translation to a character, this is 0 if there is no translation.) */ Key_Code character; - /* DOC( - This field is like the field character, except that the state of caps lock is ignored in the translation. - ) */ + /* DOC(This field is like the field character, except that the state of caps lock is ignored in the translation.) */ Key_Code character_no_caps_lock; - /* DOC( - 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. A 1 indicates that the corresponding - modifier was held, and a 0 indicates that it was not held. - ) + /* DOC(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. A 1 indicates that the corresponding modifier was held, and a 0 indicates that it was not held.) + DOC_SEE(Key_Modifier) */ char modifiers[MDFR_INDEX_COUNT]; }; -/* DOC(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.) */ -struct Mouse_State{ +/* DOC(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.) */ + STRUCT Mouse_State{ /* DOC(This field indicates that the left button is held.) */ char l; /* DOC(This field indicates that the right button is held.) */ @@ -439,21 +412,17 @@ struct Mouse_State{ }; /* DOC( -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. +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) where max is -"one past the end" of the range that is actually read/edited/modified. -) */ -union Range{ - struct{ +Throughout the API ranges are thought of in the form [min,max) where max is "one past the end" of the range that is actually read/edited/modified.) */ +UNION Range{ + STRUCT{ /* DOC(This is the smaller value in the range, it is also the 'start'.) */ int32_t min; /* DOC(This is the larger value in the range, it is also the 'end'.) */ int32_t max; }; - struct{ + STRUCT{ /* DOC(This is the start of the range, it is also the 'min'.) */ int32_t start; /* DOC(This is the end of the range, it is also the 'max'.) */ @@ -465,7 +434,7 @@ union Range{ DOC(File_Info describes the name and type of a file.) DOC_SEE(File_List) */ -struct File_Info{ +STRUCT File_Info{ /* DOC(This field is a null terminated string specifying the name of the file.) */ char *filename; /* DOC(This field specifies the length of the filename string not counting the null terminator.) */ @@ -475,7 +444,7 @@ struct File_Info{ }; /* DOC(File_List is a list of File_Info structs.) */ -struct File_List{ +STRUCT File_List{ /* DOC(This field is for inernal use.) */ void *block; /* DOC(This field is an array of File_Info structs.) */ @@ -486,26 +455,20 @@ struct File_List{ int32_t block_size; }; -/* DOC( -Buffer_Identifier acts as a loosely typed description of a buffer that -can either be a name or an id. If the -) */ -struct Buffer_Identifier{ - /* DOC( - This field is the name of the buffer; it need not be null terminated. - If id is specified this pointer should be NULL. - ) */ +/* DOC(Buffer_Identifier acts as a loosely typed description of a buffer that can either be a name or an id.) */ + STRUCT Buffer_Identifier{ + /* DOC(This field is the name of the buffer; it need not be null terminated. If id is specified this pointer should be NULL.) */ char *name; /* DOC(This field specifies the length of the name string.) */ int32_t name_len; /* DOC(This field is the id of the buffer. If name is specified this should be 0.) */ - int32_t id; + Buffer_ID id; }; /* DOC(This struct is a part of an incomplete feature.) */ -struct GUI_Scroll_Vars{ +STRUCT GUI_Scroll_Vars{ /* DOC(TODO) */ float scroll_y; /* DOC(TODO) */ @@ -542,32 +505,26 @@ ENUM(int32_t, Buffer_Seek_Type){ buffer_seek_line_char }; -/* DOC(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.) +/* DOC(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.) DOC_SEE(Buffer_Seek_Type) -DOC_SEE(4coder_Buffer_Positioning_System)*/ -struct Buffer_Seek{ +DOC_SEE(4coder_Buffer_Positioning_System) */ +STRUCT Buffer_Seek{ /* DOC(The type field determines the coordinate system of the seek operation.) */ Buffer_Seek_Type type; - union{ - struct { + UNION{ + STRUCT { /* DOC(The pos field specified the pos when the seek is in absolute position.) */ int32_t pos; }; - struct { - /* DOC(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.) */ + STRUCT { + /* DOC(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.) */ bool32 round_down; /* DOC(The x coordinate for xy type seeks.) */ float x; /* DOC(The y coordinate for xy type seeks.) */ float y; }; - struct { + STRUCT { /* DOC(The line number of a line-character type seek.) */ int32_t line; /* DOC(The character number of a line-character type seek.) */ @@ -576,11 +533,9 @@ struct Buffer_Seek{ }; }; -/* DOC(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.) +/* DOC(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.) DOC_SEE(4coder_Buffer_Positioning_System) */ -struct Full_Cursor{ +STRUCT Full_Cursor{ /* DOC(This field contains the cursor's position in absolute byte index positioning.) */ int32_t pos; /* DOC(This field contains the cursor's position in apparent character index positioning.) */ @@ -608,7 +563,7 @@ 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.) DOC_SEE(4coder_Buffer_Positioning_System) */ -struct Partial_Cursor{ +STRUCT Partial_Cursor{ /* DOC(This field contains the cursor's position in absolute byte index positioning.) */ int32_t pos; /* DOC(This field contains the number of the character from the beginninf of the line @@ -621,7 +576,7 @@ struct Partial_Cursor{ /* DOC(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.) */ -struct Buffer_Edit{ +STRUCT Buffer_Edit{ /* DOC(The str_start field specifies the first character in the accompanying string that corresponds with this edit.) */ int32_t str_start; /* DOC(The len field specifies the length of the string being written into the buffer.) */ @@ -635,7 +590,7 @@ struct Buffer_Edit{ /* DOC(Buffer_Summary acts as a handle to a buffer and describes the state of the buffer.) DOC_SEE(Access_Flag) DOC_SEE(Dirty_State) */ -struct Buffer_Summary{ +STRUCT Buffer_Summary{ /* DOC(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".) */ bool32 exists; @@ -681,7 +636,7 @@ struct Buffer_Summary{ /* DOC(View_Summary acts as a handle to a view and describes the state of the view.) DOC_SEE(Access_Flag) DOC_SEE(Full_Cursor) */ -struct View_Summary{ +STRUCT View_Summary{ /* DOC( 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". @@ -727,14 +682,14 @@ DOC(User_Input describes a user input event which can be either a key press or m DOC_SEE(User_Input_Type_ID) DOC_SEE(Generic_Command) */ -struct User_Input{ + STRUCT User_Input{ /* DOC(This field specifies whether the event was a key press or mouse event.) */ User_Input_Type_ID type; /* DOC(This field indicates that an abort event has occurred and the command needs to shut down.) */ bool32 abort; - union{ + UNION{ /* DOC(This field describes a key press event.) */ Key_Event_Data key; /* DOC(This field describes a mouse input event.) */ @@ -748,7 +703,7 @@ struct User_Input{ /* DOC(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.) */ -struct Query_Bar{ + STRUCT Query_Bar{ /* DOC(This specifies the prompt portion of the drop down bar.) */ String prompt; /* DOC(This specifies the main string portion of the drop down bar.) */ @@ -756,7 +711,7 @@ struct Query_Bar{ }; /* DOC(This feature is not implemented.) */ -struct Event_Message{ +STRUCT Event_Message{ /* DOC(This feature is not implemented.) */ int32_t type; }; @@ -766,7 +721,7 @@ DOC(Theme_Color stores a style tag/color pair, for the purpose of setting and ge DOC_SEE(Style_Tag) DOC_SEE(int_color) */ -struct Theme_Color{ +STRUCT Theme_Color{ /* DOC(The style slot in the style palette.) */ Style_Tag tag; /* DOC(The color in the slot.) */ @@ -787,7 +742,7 @@ DOC(This struct is used to bundle the parameters of the buffer_batch_edit functi for a few functions that return a batch edit to the user.) DOC_SEE(buffer_batch_edit) */ -struct Buffer_Batch_Edit{ +STRUCT Buffer_Batch_Edit{ /* DOC(The pointer to the edit string buffer.) */ char *str; /* DOC(The length of the edit string buffer.) */ diff --git a/4cpp_lexer.h b/4cpp_lexer.h index cfa20e95..e61a3817 100644 --- a/4cpp_lexer.h +++ b/4cpp_lexer.h @@ -12,7 +12,9 @@ # define FCPP_LINK static #endif -#define FCPP_INTERNAL FCPP_LINK +#ifndef API_EXPORT +#define API_EXPORT +#endif #include #if !defined(FSTRING_GUARD) @@ -150,7 +152,7 @@ static String_And_Flag keywords[] = { }; -FCPP_LINK Cpp_Get_Token_Result +API_EXPORT FCPP_LINK Cpp_Get_Token_Result cpp_get_token(Cpp_Token_Array array, int32_t pos)/* DOC_PARAM(array, The array of tokens from which to get a token.) DOC_PARAM(pos, The position, measured in bytes, to get the token for.) @@ -226,7 +228,7 @@ DOC_SEE(Cpp_Get_Token_Result) return(result); } -FCPP_INTERNAL Cpp_Lex_PP_State +FCPP_LINK Cpp_Lex_PP_State cpp_pp_directive_to_state(Cpp_Token_Type type){ Cpp_Lex_PP_State result = LSPP_default; switch (type){ @@ -280,7 +282,7 @@ cpp_pp_directive_to_state(Cpp_Token_Type type){ #define DrReturn(n) { token_array_out->count = token_i; *S_ptr = S; S_ptr->__pc__ = -1; return(n); } -FCPP_INTERNAL Cpp_Lex_Result +FCPP_LINK Cpp_Lex_Result cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, int32_t size, Cpp_Token_Array *token_array_out){ Cpp_Lex_Data S = *S_ptr; @@ -888,7 +890,7 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, int32_t siz #undef DrReturn #undef DrCase -FCPP_INTERNAL Cpp_Lex_Result +FCPP_LINK Cpp_Lex_Result cpp_lex_nonalloc_null_end_out_limit(Cpp_Lex_Data *S_ptr, char *chunk, int32_t size, Cpp_Token_Array *token_array_out, int32_t max_tokens_out){ Cpp_Token_Array temp_array = *token_array_out; @@ -908,7 +910,7 @@ cpp_lex_nonalloc_null_end_out_limit(Cpp_Lex_Data *S_ptr, char *chunk, int32_t si return(result); } -FCPP_INTERNAL Cpp_Lex_Result +FCPP_LINK Cpp_Lex_Result cpp_lex_nonalloc_no_null_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, int32_t size, int32_t full_size, Cpp_Token_Array *token_array_out){ Cpp_Lex_Result result = 0; @@ -928,7 +930,7 @@ cpp_lex_nonalloc_no_null_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, int32_t size return(result); } -FCPP_INTERNAL Cpp_Lex_Result +FCPP_LINK Cpp_Lex_Result cpp_lex_nonalloc_no_null_out_limit(Cpp_Lex_Data *S_ptr, char *chunk, int32_t size, int32_t full_size, Cpp_Token_Array *token_array_out, int32_t max_tokens_out){ Cpp_Token_Array temp_stack = *token_array_out; @@ -953,7 +955,7 @@ cpp_lex_nonalloc_no_null_out_limit(Cpp_Lex_Data *S_ptr, char *chunk, int32_t siz #define HAS_NULL_TERM ((int32_t)(-1)) #define NO_OUT_LIMIT ((int32_t)(-1)) -FCPP_LINK Cpp_Lex_Result +API_EXPORT FCPP_LINK Cpp_Lex_Result cpp_lex_step(Cpp_Lex_Data *S_ptr, char *chunk, int32_t size, int32_t full_size, Cpp_Token_Array *token_array_out, int32_t max_tokens_out)/* DOC_PARAM(S_ptr, The lexer state. Go to the Cpp_Lex_Data section to see how to initialize the state.) DOC_PARAM(chunk, The first or next chunk of the file being lexed.) @@ -1038,7 +1040,7 @@ DOC_SEE(Cpp_Lex_Result) return(result); } -FCPP_LINK Cpp_Lex_Data +API_EXPORT FCPP_LINK Cpp_Lex_Data cpp_lex_data_init()/* DOC_RETURN(A brand new lex state ready to begin lexing a file from the beginning.) @@ -1051,7 +1053,7 @@ as the file being lexed.) return(data); } -FCPP_LINK int32_t +API_EXPORT FCPP_LINK int32_t cpp_lex_data_temp_size(Cpp_Lex_Data *lex_data)/* DOC_PARAM(lex_data, The lex state from which to get the temporary buffer size.) DOC(This call gets the current size of the temporary buffer in the lexer state so @@ -1064,7 +1066,7 @@ DOC_SEE(cpp_lex_data_new_temp) return(result); } -FCPP_LINK void +API_EXPORT FCPP_LINK void cpp_lex_data_temp_read(Cpp_Lex_Data *lex_data, char *out_buffer)/* DOC_PARAM(lex_data, The lex state from which to read the temporary buffer.) DOC_PARAM(out_buffer, The buffer into which the contents of the temporary buffer will be written. @@ -1081,16 +1083,16 @@ DOC_SEE(cpp_lex_data_new_temp) } } -FCPP_LINK void +API_EXPORT FCPP_LINK void cpp_lex_data_new_temp_DEP(Cpp_Lex_Data *lex_data, char *new_buffer) /*DOC(Deprecated in 4cpp Lexer 1.0.1*/{} -FCPP_INTERNAL char +FCPP_LINK char cpp_token_get_pp_state(uint16_t bitfield){ return (char)(bitfield); } -FCPP_INTERNAL void +FCPP_LINK void cpp_shift_token_starts(Cpp_Token_Array *array, int32_t from_token_i, int32_t shift_amount){ Cpp_Token *token = array->tokens + from_token_i; int32_t count = array->count, i = 0; @@ -1099,7 +1101,7 @@ cpp_shift_token_starts(Cpp_Token_Array *array, int32_t from_token_i, int32_t shi } } -FCPP_INTERNAL Cpp_Token +FCPP_LINK Cpp_Token cpp_index_array(Cpp_Token_Array *array, int32_t file_size, int32_t index){ Cpp_Token result; if (index < array->count){ @@ -1115,7 +1117,7 @@ cpp_index_array(Cpp_Token_Array *array, int32_t file_size, int32_t index){ return(result); } -FCPP_LINK Cpp_Relex_Range +API_EXPORT FCPP_LINK Cpp_Relex_Range cpp_get_relex_range(Cpp_Token_Array *array, int32_t start_pos, int32_t end_pos) /* DOC_PARAM(array, A pointer to the token array that will be modified by the relex, @@ -1148,7 +1150,7 @@ The start and end points are based on the edited region of the file before the e return(range); } -FCPP_LINK Cpp_Relex_Data +API_EXPORT FCPP_LINK Cpp_Relex_Data cpp_relex_init(Cpp_Token_Array *array, int32_t start_pos, int32_t end_pos, int32_t character_shift_amount) /* DOC_PARAM(array, A pointer to the token array that will be modified by the relex, @@ -1192,7 +1194,7 @@ DOC_SEE(cpp_relex_is_start_chunk) return(state); } -FCPP_LINK int32_t +API_EXPORT FCPP_LINK int32_t cpp_relex_start_position(Cpp_Relex_Data *S_ptr) /* DOC_PARAM(S_ptr, A pointer to a state that is done with the first stage of initialization (cpp_relex_init)) @@ -1211,7 +1213,7 @@ DOC_SEE(cpp_relex_declare_first_chunk_position) return(result); } -FCPP_LINK void +API_EXPORT FCPP_LINK void cpp_relex_declare_first_chunk_position(Cpp_Relex_Data *S_ptr, int32_t position) /* DOC_PARAM(S_ptr, A pointer to a state that is done with the first stage of initialization (cpp_relex_init)) @@ -1230,7 +1232,7 @@ DOC_SEE(cpp_relex_start_position) S_ptr->lex.chunk_pos = position; } -FCPP_LINK int32_t +API_EXPORT FCPP_LINK int32_t cpp_relex_is_start_chunk(Cpp_Relex_Data *S_ptr, char *chunk, int32_t chunk_size) /* DOC_PARAM(S_ptr, A pointer to a state that is done with the first stage of initialization (cpp_relex_init)) @@ -1280,7 +1282,7 @@ DOC_SEE(cpp_relex_init) S_ptr->result_state = n; \ *S_ptr = S; S_ptr->__pc__ = -1; return(n); } -FCPP_LINK Cpp_Lex_Result +API_EXPORT FCPP_LINK Cpp_Lex_Result cpp_relex_step(Cpp_Relex_Data *S_ptr, char *chunk, int32_t chunk_size, int32_t full_size, Cpp_Token_Array *array, Cpp_Token_Array *relex_array) /* @@ -1385,7 +1387,7 @@ DOC_SEE(cpp_relex_abort) #undef DrReturn #undef DrCase -FCPP_LINK int32_t +API_EXPORT FCPP_LINK int32_t cpp_relex_get_new_count(Cpp_Relex_Data *S_ptr, int32_t current_count, Cpp_Token_Array *relex_array) /* DOC_PARAM(S_ptr, A pointer to a state that has gone through cpp_relex_step with a LexResult_Finished return.) @@ -1411,7 +1413,7 @@ the new array, it's capacity should be increased before passing to cpp_relex_com #include #endif -FCPP_INTERNAL void +FCPP_LINK void cpp__block_move(void *dst, void *src, int32_t size){ #if !defined(FCPP_FORBID_MEMCPY) memmove(dst, src, size); @@ -1433,7 +1435,7 @@ cpp__block_move(void *dst, void *src, int32_t size){ #endif } -FCPP_LINK void +API_EXPORT FCPP_LINK void cpp_relex_complete(Cpp_Relex_Data *S_ptr, Cpp_Token_Array *array, Cpp_Token_Array *relex_array) /* DOC_PARAM(S_ptr, A pointer to a state that has gone through cpp_relex_step with a LexResult_Finished return.) @@ -1460,7 +1462,7 @@ does the necessary replacement of tokens in the array to make it match the new f sizeof(Cpp_Token)*relex_array->count); } -FCPP_LINK void +API_EXPORT FCPP_LINK void cpp_relex_abort(Cpp_Relex_Data *S_ptr, Cpp_Token_Array *array) /* DOC_PARAM(S_ptr, A pointer to a state that has gone through at least one cpp_relex_step.) @@ -1480,7 +1482,7 @@ is dead.) #include #include -FCPP_LINK Cpp_Token_Array +API_EXPORT FCPP_LINK Cpp_Token_Array cpp_make_token_array(int32_t starting_max)/* DOC_PARAM(starting_max, The number of tokens to initialize the array with.) DOC_RETURN(An empty Cpp_Token_Array with memory malloc'd for storing tokens.) @@ -1495,7 +1497,7 @@ used in the convenience functions.) return(token_array); } -FCPP_LINK void +API_EXPORT FCPP_LINK void cpp_free_token_array(Cpp_Token_Array token_array)/* DOC_PARAM(token_array, An array previously allocated by cpp_make_token_array) DOC(This call frees a Cpp_Token_Array.) @@ -1504,7 +1506,7 @@ DOC_SEE(cpp_make_token_array) free(token_array.tokens); } -FCPP_LINK void +API_EXPORT FCPP_LINK void cpp_resize_token_array(Cpp_Token_Array *token_array, int32_t new_max)/* DOC_PARAM(token_array, An array previously allocated by cpp_make_token_array.) DOC_PARAM(new_max, The new maximum size the array should support. If this is not greater @@ -1525,7 +1527,7 @@ DOC_SEE(cpp_make_token_array) } } -FCPP_LINK void +API_EXPORT FCPP_LINK void cpp_lex_file(char *data, int32_t size, Cpp_Token_Array *token_array_out)/* DOC_PARAM(data, The file data to be lexed in a single contiguous block.) DOC_PARAM(size, The number of bytes in data.) diff --git a/4cpp_lexer_types.h b/4cpp_lexer_types.h index 2abf182e..8a7ca67b 100644 --- a/4cpp_lexer_types.h +++ b/4cpp_lexer_types.h @@ -12,8 +12,8 @@ #define ENUM_INTERNAL(type,name) typedef type name; enum name##_ #endif -#ifndef struct_internal -#define struct_internal struct +#ifndef STRUCT +#define STRUCT struct #endif /* DOC(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.) */ @@ -233,7 +233,7 @@ ENUM(uint32_t, Cpp_Token_Type){ /* DOC(Cpp_Token represents a single lexed token. It is the primary output of the lexing system.) DOC_SEE(Cpp_Token_Flag) */ -struct Cpp_Token{ + STRUCT Cpp_Token{ /* DOC(The type field indicates the type of the token. All tokens have a type no matter the circumstances.) */ Cpp_Token_Type type; @@ -275,7 +275,7 @@ ENUM(uint16_t, Cpp_Token_Flag){ 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.) */ -struct Cpp_Token_Array{ + STRUCT Cpp_Token_Array{ /* DOC(The tokens field points to the memory used to store the array of tokens.) */ Cpp_Token *tokens; @@ -291,7 +291,7 @@ static Cpp_Token_Array null_cpp_token_array = {0}; /* DOC(Cpp_Get_Token_Result is the return result of the cpp_get_token call.) DOC_SEE(cpp_get_token) */ -struct Cpp_Get_Token_Result{ + STRUCT Cpp_Get_Token_Result{ /* DOC(The token_index field indicates which token answers the query. To get the token from the source array CODE_EXAMPLE(array.tokens[result.token_index])) */ int32_t token_index; @@ -311,7 +311,7 @@ struct Cpp_Get_Token_Result{ /* DOC(Cpp_Relex_Range is the return result of the cpp_get_relex_range call.) DOC_SEE(cpp_get_relex_range) */ -struct Cpp_Relex_Range{ + STRUCT Cpp_Relex_Range{ /* DOC(The index of the first token in the unedited array that needs to be relexed.) */ int32_t start_token_index; /* DOC(The index of the first token in the unedited array after the edited range @@ -320,7 +320,7 @@ struct Cpp_Relex_Range{ int32_t end_token_index; }; -struct_internal Cpp_Lex_FSM{ +struct Cpp_Lex_FSM{ uint8_t state; uint8_t int_state; uint8_t emit_token; @@ -335,7 +335,7 @@ 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.) DOC_SEE(cpp_lex_data_init) HIDE_MEMBERS() */ -struct Cpp_Lex_Data{ + STRUCT Cpp_Lex_Data{ char tb[32]; int32_t tb_pos; int32_t token_start; @@ -375,7 +375,7 @@ ENUM(int32_t, Cpp_Lex_Result){ To create a new relex state call cpp_relex_init.) DOC_SEE(cpp_relex_init) HIDE_MEMBERS()*/ -struct Cpp_Relex_Data{ + STRUCT Cpp_Relex_Data{ Cpp_Lex_Data lex; Cpp_Token end_token; diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index 49d943cc..8eeaf17f 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -398,12 +398,9 @@ DOC_PARAM(item_index, This parameter specifies which item to read, 0 is the most DOC_PARAM(out, This parameter provides a buffer where the clipboard contents are written. This parameter may be NULL.) DOC_PARAM(len, This parameter specifies the length of the out buffer.) DOC_RETURN(This call returns the size of the item associated with item_index.) -DOC -( -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. -) + +DOC(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. ) + DOC_SEE(The_4coder_Clipboard) */{ Command_Data *cmd = (Command_Data*)app->cmd_context; @@ -423,7 +420,10 @@ DOC_SEE(The_4coder_Clipboard) } API_EXPORT int32_t -Get_Buffer_Count(Application_Links *app){ +Get_Buffer_Count(Application_Links *app) +/* +DOC(Gives the total number of buffers in the application.) +*/{ Command_Data *cmd = (Command_Data*)app->cmd_context; Working_Set *working_set = &cmd->models->working_set; int32_t result = working_set->file_count; @@ -709,21 +709,27 @@ DOC_SEE(Buffer_Batch_Edit_Type) } API_EXPORT int32_t -Buffer_Get_Setting(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting){ +Buffer_Get_Setting(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t *value_out) +/* +DOC_PARAM(buffer, the buffer from which to read a setting) +DOC_PARAM(setting, the setting to read from the buffer) +DOC_PARAM(value_out, address to write the setting value on success) +DOC_RETURN(returns non-zero on success) +*/{ Command_Data *cmd = (Command_Data*)app->cmd_context; Editing_File *file = imp_get_file(cmd, buffer); - int32_t result = -1; + int32_t result = 0; if (file){ switch (setting){ - case BufferSetting_Lex: result = file->settings.tokens_exist; break; - case BufferSetting_WrapLine: result = !file->settings.unwrapped_lines; break; - case BufferSetting_WrapPosition: result = file->settings.display_width; break; - case BufferSetting_MapID: result = file->settings.base_map_id; break; - case BufferSetting_Eol: result = file->settings.dos_write_mode; break; - case BufferSetting_Unimportant: result = file->settings.unimportant; break; - case BufferSetting_ReadOnly: result = file->settings.read_only; break; - case BufferSetting_VirtualWhitespace: result = file->settings.virtual_white; break; + case BufferSetting_Lex: result = file->settings.tokens_exist; break; + case BufferSetting_WrapLine: result = !file->settings.unwrapped_lines; break; + case BufferSetting_WrapPosition: result = file->settings.display_width; break; + case BufferSetting_MapID: result = file->settings.base_map_id; break; + case BufferSetting_Eol: result = file->settings.dos_write_mode; break; + case BufferSetting_Unimportant: result = file->settings.unimportant; break; + case BufferSetting_ReadOnly: result = file->settings.read_only; break; + case BufferSetting_VirtualWhitespace: result = file->settings.virtual_white; break; } } @@ -972,20 +978,61 @@ DOC_SEE(cpp_get_token) return(result); } -API_EXPORT void -Begin_Buffer_Creation(Application_Links *app, Buffer_Creation_Data *data, Buffer_Create_Flag flags){ +// TODO(allen): Buffer_Creation_Flag +API_EXPORT bool32 +Begin_Buffer_Creation(Application_Links *app, Buffer_Creation_Data *data, Buffer_Create_Flag flags) +/* +DOC_PARAM(data, a local user handle for the buffer creation process) +DOC_PARAM(flags, flags defining the buffer creation behavior) + +DOC(Begins a buffer creation by initializing a Buffer_Creation_Data struct. The buffer is not actually created until end_buffer_creation is called.) + +DOC_SEE(buffer_creation_name) +DOC_SEE(end_buffer_creation) + +DOC_SEE(Buffer_Creation_Data) +DOC_SEE(Buffer_Create_Flag) +*/{ + bool32 result = 0; + if (data){ data->flags = flags; + result = 1; + } + return(result); } -API_EXPORT void -Buffer_Creation_Name(Application_Links *app, Buffer_Creation_Data *data, char *filename, int32_t filename_len, uint32_t flags){ +API_EXPORT bool32 +Buffer_Creation_Name(Application_Links *app, Buffer_Creation_Data *data, char *filename, int32_t filename_len, uint32_t flags) +/* +DOC_PARAM(data, a local user handle for buffer creation that has already been initialized by begin_buffer_creation) +DOC_PARAM(filename, the name to associate to the buffer; This string need not be null terminated.) +DOC_PARAM(filename_len, the length of the filename string) +DOC_PARAM(flags, not currently used this should be 0) + +DOC(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.) + +DOC_SEE(begin_buffer_creation) +DOC_SEE(end_buffer_creation) +*/{ + bool32 result = 0; + if (data){ String fname = make_fixed_width_string(data->fname_space); copy_ss(&fname, make_string(filename, filename_len)); data->fname_len = filename_len; + result = 1; + } + return(result); } - + API_EXPORT Buffer_Summary -End_Buffer_Creation(Application_Links *app, Buffer_Creation_Data *data){ +End_Buffer_Creation(Application_Links *app, Buffer_Creation_Data *data) +/* +DOC_PARAM(data, a local user handle for buffer creation that has already been initialized by begin_buffer_creation and used in subsequent buffer creation flags) + +DOC_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.) + +DOC_SEE(begin_buffer_creation) +*/{ Command_Data *cmd = (Command_Data*)app->cmd_context; System_Functions *system = cmd->system; Models *models = cmd->models; @@ -995,7 +1042,7 @@ End_Buffer_Creation(Application_Links *app, Buffer_Creation_Data *data){ Buffer_Summary result = {0}; - if (data->fname_len > 0){ + if (data && data->fname_len > 0){ String fname = make_string(data->fname_space, data->fname_len); Editing_File *file = 0; @@ -1073,114 +1120,7 @@ End_Buffer_Creation(Application_Links *app, Buffer_Creation_Data *data){ } end_temp_memory(temp); - } - - return(result); } - -API_EXPORT Buffer_Summary -Create_Buffer_(Application_Links *app, char *filename, int32_t filename_len, Buffer_Create_Flag flags) -/* -DOC_PARAM(filename, The filename parameter specifies the name of the file to be opened or created; -it need not be null terminated.) -DOC_PARAM(filename_len, The filename_len parameter spcifies the length of the filename string.) -DOC_PARAM(flags, The flags parameter specifies behaviors for buffer creation.) -DOC_RETURN(This call returns the summary of the created buffer.) - -DOC(Tries to create a new buffer and associate it to the given filename. If such a buffer -already exists the existing buffer is returned in the Buffer_Summary and no new buffer is -created. If the buffer does not exist a new buffer is created and named after the given -filename. If the filename corresponds to a file on the disk that file is loaded and put into -buffer, if the filename does not correspond to a file on disk the buffer is created empty.) - -DOC_SEE(Buffer_Summary) -DOC_SEE(Buffer_Create_Flag) -*/{ - Command_Data *cmd = (Command_Data*)app->cmd_context; - System_Functions *system = cmd->system; - Models *models = cmd->models; - Working_Set *working_set = &models->working_set; - General_Memory *general = &models->mem.general; - Partition *part = &models->mem.part; - - Buffer_Summary result = {0}; - - String fname = make_string(filename, filename_len); - - Temp_Memory temp = begin_temp_memory(part); - - if (filename != 0){ - Editing_File *file = 0; - b32 do_new_file = 0; - Plat_Handle handle = {0}; - - Editing_File_Canon_Name canon = {0}; - if (get_canon_name(system, &canon, fname)){ - file = working_set_canon_contains(working_set, canon.name); - } - else{ - do_new_file = 1; - } - - if (!file){ - file = working_set_name_contains(working_set, fname); - } - - if (!file){ - if (!do_new_file){ - if (flags & BufferCreate_AlwaysNew){ - do_new_file = 1; - } - else{ - if (!system->load_handle(canon.name.str, &handle)){ - do_new_file = 1; - } - } - } - - if (!do_new_file){ - Assert(!handle_equal(handle, handle_zero())); - - i32 size = system->load_size(handle); - b32 in_general_mem = 0; - char *buffer = push_array(part, char, size); - - if (buffer == 0){ - buffer = (char*)general_memory_allocate(system, general, size); - Assert(buffer != 0); - in_general_mem = 1; - } - - if (system->load_file(handle, buffer, size)){ - file = working_set_alloc_always(system, working_set, general); - if (file){ - buffer_bind_file(system, general, working_set, file, canon.name); - buffer_bind_name(system, general, working_set, file, fname); - init_normal_file(system, models, file, buffer, size); - fill_buffer_summary(&result, file, cmd); - } - } - - if (in_general_mem){ - general_memory_free(system, general, buffer); - } - - system->load_close(handle); - } - else if (!(flags & BufferCreate_NeverNew)){ - file = working_set_alloc_always(system, working_set, general); - if (file){ - buffer_bind_name(system, general, working_set, file, fname); - init_normal_file(system, models, file, 0, 0); - fill_buffer_summary(&result, file, cmd); - } - } - } - else{ - fill_buffer_summary(&result, file, cmd); - } - } - end_temp_memory(temp); return(result); } @@ -1588,8 +1528,14 @@ DOC_SEE(get_active_view) return(result); } -API_EXPORT int32_t -View_Get_Setting(Application_Links *app, View_Summary *view, View_Setting_ID setting){ +API_EXPORT bool32 +View_Get_Setting(Application_Links *app, View_Summary *view, View_Setting_ID setting, int32_t *value_out) +/* +DOC_PARAM(view, the view from which to read a setting) +DOC_PARAM(setting, the view setting to read) +DOC_PARAM(value_out, address to write the setting value on success) +DOC_RETURN(returns non-zero on success) +*/{ Command_Data *cmd = (Command_Data*)app->cmd_context; View *vptr = imp_get_view(cmd, view); int32_t result = -1; @@ -2104,14 +2050,20 @@ DOC(This call sets the display font of a particular buffer.) } } -API_EXPORT int32_t +API_EXPORT bool32 Buffer_Get_Font(Application_Links *app, Buffer_Summary *buffer, char *name_out, int32_t name_max) +/* +DOC_PARAM(buffer, the buffer from which to get the font name) +DOC_PARAM(name_out, a character array in which to write the name of the font) +DOC_PARAM(name_max, the capacity of name_out) +DOC_RETURN(returns non-zero on success) +*/ { Command_Data *cmd = (Command_Data*)app->cmd_context; Models *models = cmd->models; Editing_File *file = imp_get_file(cmd, buffer); - int32_t result = 0; + bool32 result = 0; if (file){ Font_Set *set = models->font_set; String name = make_string_cap(name_out, 0, name_max); @@ -2249,6 +2201,11 @@ DOC(After this call the file list passed in should not be read or written to.) API_EXPORT void Set_GUI_Up_Down_Keys(Application_Links *app, int16_t up_key, int16_t down_key) +/* +DOC_PARAM(up_key, the code of the key that should be interpreted as an up key) +DOC_PARAM(down_key, the code of the key that should be interpreted as a down key) + +DOC(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.) */ { Command_Data *cmd = (Command_Data*)app->cmd_context; Models *models = cmd->models; diff --git a/4ed_metagen.cpp b/4ed_metagen.cpp index 2bad4c2c..a40c7be8 100644 --- a/4ed_metagen.cpp +++ b/4ed_metagen.cpp @@ -11,7 +11,9 @@ #include "4coder_version.h" +#if !defined(FSTRING_GUARD) #include "internal_4coder_string.cpp" +#endif #include "4cpp_lexer.h" @@ -21,33 +23,42 @@ #include #include "4coder_mem.h" +#include "meta_parser.cpp" #define InvalidPath Assert(!"Invalid path of execution") typedef struct Out_Context{ + char out_directory_space[256]; + String out_directory; FILE *file; String *str; } Out_Context; -static String -str_start_end(char *data, int32_t start, int32_t end){ - return(make_string(data + start, end - start)); -} - -static String -str_alloc(Partition *part, int32_t cap){ - return(make_string_cap(push_array(part, char, cap), 0, cap)); +static void +set_context_directory(Out_Context *context, char *dst_directory){ + context->out_directory = make_fixed_width_string(context->out_directory_space); + copy_sc(&context->out_directory, dst_directory); } static int32_t begin_file_out(Out_Context *out_context, char *filename, String *out){ + char str_space[512]; + String name = make_fixed_width_string(str_space); + if (out_context->out_directory.size > 0){ + append_ss(&name, out_context->out_directory); + append_sc(&name, "\\"); + } + append_sc(&name, filename); + terminate_with_null(&name); + int32_t r = 0; - out_context->file = fopen(filename, "wb"); + out_context->file = fopen(name.str, "wb"); out_context->str = out; out->size = 0; if (out_context->file){ r = 1; } + return(r); } @@ -173,18 +184,18 @@ static void struct_begin(String *str, char *name){ append_sc(str, "struct "); append_sc(str, name); - append_sc(str, "{\n"); + append_sc(str, "{\n"); //} } static void enum_begin(String *str, char *name){ append_sc(str, "enum "); append_sc(str, name); - append_sc(str, "{\n"); + append_sc(str, "{\n"); //} } static void -struct_end(String *str){ +struct_end(String *str){ //{ append_sc(str, "};\n\n"); } @@ -343,1753 +354,11 @@ generate_style(){ ////////////////////////////////////////////////////////////////////////////////////////////////// -typedef struct Parse_Context{ - Cpp_Token *token_s; - Cpp_Token *token_e; - Cpp_Token *token; - char *data; -} Parse_Context; - -typedef struct Argument{ - String param_string; - String param_name; -} Argument; - -typedef struct Argument_Breakdown{ - int32_t count; - Argument *args; -} Argument_Breakdown; - -typedef struct Documentation{ - int32_t param_count; - String *param_name; - String *param_docs; - String return_doc; - String main_doc; - int32_t see_also_count; - String *see_also; -} Documentation; - -typedef enum Item_Type{ - Item_Null, - Item_Function, - Item_CppName, - Item_Macro, - Item_Typedef, - Item_Struct, - Item_Union, - Item_Enum, - Item_Type_Count, -#define Item_Type_User0 Item_Type_Count -} Item_Type; - -typedef struct Item_Node{ - int32_t t; - - String cpp_name; - String name; - String ret; - String args; - String body; - String marker; - - String value; - String type; - String type_postfix; - String doc_string; - - Argument_Breakdown breakdown; - Documentation doc; - - Item_Node *first_child; - Item_Node *next_sibling; -} Item_Node; - -typedef struct Item_Set{ - Item_Node *items; - int32_t count; -} Item_Set; - -typedef struct Parse{ - String code; - Cpp_Token_Array tokens; - int32_t item_count; -} Parse; - -typedef struct Meta_Unit{ - Item_Set set; - - Parse *parse; - int32_t count; -} Meta_Unit; - -typedef struct Meta_Keywords{ - String key; - Item_Type type; -} Meta_Keywords; - -typedef struct Used_Links{ - String *strs; - int32_t count, max; -} Used_Links; - -static Item_Node null_item_node = {0}; - -static String -get_lexeme(Cpp_Token token, char *code){ - String str = make_string(code + token.start, token.size); - return(str); -} - -static Parse_Context -setup_parse_context(char *data, Cpp_Token_Array array){ - Parse_Context context; - context.token_s = array.tokens; - context.token_e = array.tokens + array.count; - context.token = context.token_s; - context.data = data; - return(context); -} - -static Parse_Context -setup_parse_context(Parse parse){ - Parse_Context context; - context.token_s = parse.tokens.tokens; - context.token_e = parse.tokens.tokens + parse.tokens.count; - context.token = context.token_s; - context.data = parse.code.str; - return(context); -} - -static Cpp_Token* -get_token(Parse_Context *context){ - Cpp_Token *result = context->token; - if (result >= context->token_e){ - result = 0; - } - return(result); -} - -static Cpp_Token* -get_next_token(Parse_Context *context){ - Cpp_Token *result = context->token+1; - context->token = result; - if (result >= context->token_e){ - result = 0; - context->token = context->token_e; - } - return(result); -} - -static Cpp_Token* -get_prev_token(Parse_Context *context){ - Cpp_Token *result = context->token-1; - if (result < context->token_s){ - result = 0; - } - else{ - context->token = result; - } - return(result); -} - -static Cpp_Token* -can_back_step(Parse_Context *context){ - Cpp_Token *result = context->token-1; - if (result < context->token_s){ - result = 0; - } - return(result); -} - -static Cpp_Token* -set_token(Parse_Context *context, Cpp_Token *token){ - Cpp_Token *result = 0; - if (token >= context->token_s && token < context->token_e){ - context->token = token; - result = token; - } - return(result); -} - -static String -file_dump(char *filename){ - String result = {0}; - FILE *file = fopen(filename, "rb"); - - if (file){ - fseek(file, 0, SEEK_END); - result.size = ftell(file); - fseek(file, 0, SEEK_SET); - - result.memory_size = result.size + 1; - result.str = (char*)malloc(result.memory_size); - - fread(result.str, 1, result.size, file); - result.str[result.size] = 0; - - fclose(file); - } - - return(result); -} - -static Parse -meta_lex(char *filename){ - Parse result = {0}; - result.code = file_dump(filename); - result.tokens = cpp_make_token_array(1024); - cpp_lex_file(result.code.str, result.code.size, &result.tokens); - return(result); -} - -static String -get_first_line(String source){ - String line = {0}; - int32_t pos = find_s_char(source, 0, '\n'); - line = substr(source, 0, pos); - return(line); -} - -static String -get_next_line(String source, String line){ - String next = {0}; - int32_t pos = (int32_t)(line.str - source.str) + line.size; - int32_t start = 0; - - if (pos < source.size){ - assert(source.str[pos] == '\n'); - start = pos + 1; - - if (start < source.size){ - pos = find_s_char(source, start, '\n'); - next = substr(source, start, pos - start); - } - } - - return(next); -} - -static int32_t -is_comment(String str){ - int32_t result = 0; - if (str.size >= 2){ - if (str.str[0] == '/' && - str.str[1] == '/'){ - result = 1; - } - } - return(result); -} - -typedef enum Doc_Note_Type{ - DOC_PARAM, - DOC_RETURN, - DOC, - DOC_SEE, - DOC_HIDE, - HIDE_MEMBERS, -} Doc_Note_Type; - -static String -doc_note_string[] = { - make_lit_string("DOC_PARAM"), - make_lit_string("DOC_RETURN"), - make_lit_string("DOC"), - make_lit_string("DOC_SEE"), - make_lit_string("DOC_HIDE"), - make_lit_string("HIDE_MEMBERS"), -}; - -static int32_t -check_and_fix_docs(String *doc_string){ - int32_t result = false; - - if (doc_string->size > 4){ - if (doc_string->str[0] == '/'){ - if (doc_string->str[1] == '*'){ - if (doc_string->str[doc_string->size - 2] == '*'){ - if (doc_string->str[doc_string->size - 1] == '/'){ - result = true; - doc_string->str += 2; - doc_string->size -= 4; - } - } - } - } - } - - return(result); -} - -static int32_t -get_doc_string_from_prev(Parse_Context *context, String *doc_string){ - int32_t result = false; - - if (can_back_step(context)){ - Cpp_Token *prev_token = get_token(context) - 1; - if (prev_token->type == CPP_TOKEN_COMMENT){ - *doc_string = get_lexeme(*prev_token, context->data); - if (check_and_fix_docs(doc_string)){ - result = true; - } - else{ - *doc_string = null_string; - } - } - } - - return(result); -} - -static String -doc_parse_note(String source, int32_t *pos){ - String result = {0}; - - int32_t p = *pos; - int32_t start = p; - for (; p < source.size; ++p){ - if (source.str[p] == '('){ - break; - } - } - if (p != source.size){ - result = make_string(source.str + start, p - start); - result = skip_chop_whitespace(result); - } - *pos = p; - - return(result); -} - -static String -doc_parse_note_string(String source, int32_t *pos){ - String result = {0}; - - assert(source.str[*pos] == '('); - - int32_t p = *pos + 1; - int32_t start = p; - - int32_t nest_level = 0; - - for (; p < source.size; ++p){ - if (source.str[p] == ')'){ - if (nest_level == 0){ - break; - } - else{ - --nest_level; - } - } - else if (source.str[p] == '('){ - ++nest_level; - } - } - if (p != source.size){ - result = make_string(source.str + start, p - start); - result = skip_chop_whitespace(result); - ++p; - } - *pos = p; - - return(result); -} - -static String -doc_parse_parameter(String source, int32_t *pos){ - String result = {0}; - - int32_t p = *pos; - int32_t start = p; - - for (; p < source.size; ++p){ - if (source.str[p] == ','){ - break; - } - } - if (p != source.size){ - result = make_string(source.str + start, p - start); - result = skip_chop_whitespace(result); - ++p; - } - *pos = p; - - return(result); -} - -static String -doc_parse_last_parameter(String source, int32_t *pos){ - String result = {0}; - - int32_t p = *pos; - int32_t start = p; - - for (; p < source.size; ++p){ - if (source.str[p] == ')'){ - break; - } - } - if (p == source.size){ - result = make_string(source.str + start, p - start); - result = skip_chop_whitespace(result); - } - *pos = p; - - return(result); -} - -static void -perform_doc_parse(Partition *part, String doc_string, Documentation *doc){ - int32_t keep_parsing = true; - int32_t pos = 0; - - int32_t param_count = 0; - int32_t see_count = 0; - - do{ - String doc_note = doc_parse_note(doc_string, &pos); - if (doc_note.size == 0){ - keep_parsing = false; - } - else{ - int32_t doc_note_type; - if (string_set_match(doc_note_string, ArrayCount(doc_note_string), doc_note, &doc_note_type)){ - - doc_parse_note_string(doc_string, &pos); - - switch (doc_note_type){ - case DOC_PARAM: ++param_count; break; - case DOC_SEE: ++see_count; break; - } - } - } - }while(keep_parsing); - - if (param_count + see_count > 0){ - int32_t memory_size = sizeof(String)*(2*param_count + see_count); - doc->param_name = push_array(part, String, memory_size); - doc->param_docs = doc->param_name + param_count; - doc->see_also = doc->param_docs + param_count; - - doc->param_count = param_count; - doc->see_also_count = see_count; - } - - int32_t param_index = 0; - int32_t see_index = 0; - - keep_parsing = true; - pos = 0; - do{ - String doc_note = doc_parse_note(doc_string, &pos); - if (doc_note.size == 0){ - keep_parsing = false; - } - else{ - int32_t doc_note_type; - if (string_set_match(doc_note_string, ArrayCount(doc_note_string), doc_note, &doc_note_type)){ - - String doc_note_string = doc_parse_note_string(doc_string, &pos); - - switch (doc_note_type){ - case DOC_PARAM: - { - assert(param_index < param_count); - int32_t param_pos = 0; - String param_name = doc_parse_parameter(doc_note_string, ¶m_pos); - String param_docs = doc_parse_last_parameter(doc_note_string, ¶m_pos); - doc->param_name[param_index] = param_name; - doc->param_docs[param_index] = param_docs; - ++param_index; - }break; - - case DOC_RETURN: - { - doc->return_doc = doc_note_string; - }break; - - case DOC: - { - doc->main_doc = doc_note_string; - }break; - - case DOC_SEE: - { - assert(see_index < see_count); - doc->see_also[see_index++] = doc_note_string; - }break; - } - } - else{ - fprintf(stderr, "warning: invalid doc note %.*s\n", doc_note.size, doc_note.str); - } - } - }while(keep_parsing); -} - -static Item_Set -allocate_item_set(Partition *part, int32_t count){ - Item_Set item_set = {0}; - if (count > 0){ - item_set.items = push_array(part, Item_Node, count); - item_set.count = count; - memset(item_set.items, 0, sizeof(Item_Node)*count); - } - return(item_set); -} - // // Meta Parse Rules // -static int32_t -struct_parse(Partition *part, int32_t is_struct, - Parse_Context *context, Item_Node *top_member); - -static int32_t -struct_parse_member(Partition *part, Parse_Context *context, Item_Node *member){ - - int32_t result = false; - - Cpp_Token *token = get_token(context); - - String doc_string = {0}; - get_doc_string_from_prev(context, &doc_string); - - Cpp_Token *start_token = token; - - for (; (token = get_token(context)) != 0; get_next_token(context)){ - if (token->type == CPP_TOKEN_SEMICOLON){ - break; - } - } - - if (token){ - String name = {0}; - Cpp_Token *token_j = 0; - int32_t nest_level = 0; - - for (; (token_j = get_token(context)) > start_token; get_prev_token(context)){ - if (token_j->type == CPP_TOKEN_BRACKET_CLOSE){ - ++nest_level; - } - else if (token_j->type == CPP_TOKEN_BRACKET_OPEN){ - --nest_level; - if (nest_level < 0){ - break; - } - } - - if (nest_level == 0){ - if (token_j->type == CPP_TOKEN_IDENTIFIER){ - break; - } - } - } - - name = skip_chop_whitespace(get_lexeme(*token_j, context->data)); - - String type = skip_chop_whitespace(str_start_end(context->data, start_token->start, token_j->start)); - - String type_postfix = - skip_chop_whitespace(str_start_end(context->data, token_j->start + token_j->size, token->start)); - - set_token(context, token+1); - result = true; - - member->name = name; - member->type = type; - member->type_postfix = type_postfix; - member->doc_string = doc_string; - member->first_child = 0; - member->next_sibling = 0; - } - - return(result); -} - -static Item_Node* -struct_parse_next_member(Partition *part, Parse_Context *context){ - Item_Node *result = 0; - - Cpp_Token *token = 0; - - for (; (token = get_token(context)) != 0; get_next_token(context)){ - if (token->type == CPP_TOKEN_IDENTIFIER || - (token->flags & CPP_TFLAG_IS_KEYWORD)){ - String lexeme = get_lexeme(*token, context->data); - - if (match_ss(lexeme, make_lit_string("struct"))){ - Item_Node *member = push_struct(part, Item_Node); - if (struct_parse(part, true, context, member)){ - result = member; - break; - } - else{ - assert(!"unhandled error"); - } - } - else if (match_ss(lexeme, make_lit_string("union"))){ - Item_Node *member = push_struct(part, Item_Node); - if (struct_parse(part, false, context, member)){ - result = member; - break; - } - else{ - assert(!"unhandled error"); - } - } - else{ - Item_Node *member = push_struct(part, Item_Node); - if (struct_parse_member(part, context, member)){ - result = member; - break; - } - else{ - assert(!"unhandled error"); - } - } - - } - else if (token->type == CPP_TOKEN_BRACE_CLOSE){ - break; - } - } - - return(result); -} - -static int32_t -struct_parse(Partition *part, int32_t is_struct, Parse_Context *context, Item_Node *top_member){ - - int32_t result = false; - - Cpp_Token *start_token = get_token(context); - Cpp_Token *token = 0; - - String doc_string = {0}; - get_doc_string_from_prev(context, &doc_string); - - for (; (token = get_token(context)) != 0; get_next_token(context)){ - if (token->type == CPP_TOKEN_BRACE_OPEN){ - break; - } - } - - if (token){ - Cpp_Token *token_j = token; - - for (; (token_j = get_token(context)) > start_token; get_prev_token(context)){ - if (token_j->type == CPP_TOKEN_IDENTIFIER){ - break; - } - } - - String name = {0}; - if (token_j != start_token){ - name = skip_chop_whitespace(get_lexeme(*token_j, context->data)); - } - - String type = {0}; - if (is_struct){ - type = make_lit_string("struct"); - } - else{ - type = make_lit_string("union"); - } - - set_token(context, token+1); - Item_Node *new_member = struct_parse_next_member(part, context); - - if (new_member){ - top_member->first_child = new_member; - - Item_Node *head_member = new_member; - for(;;){ - new_member = struct_parse_next_member(part, context); - if (new_member){ - head_member->next_sibling = new_member; - head_member = new_member; - } - else{ - break; - } - } - } - - for (; (token = get_token(context)) != 0; get_next_token(context)){ - if (token->type == CPP_TOKEN_SEMICOLON){ - break; - } - } - ++token; - - if (is_struct){ - top_member->t = Item_Struct; - } - else{ - top_member->t = Item_Union; - } - top_member->name = name; - top_member->type = type; - top_member->doc_string = doc_string; - top_member->next_sibling = 0; - - result = true; - } - - return(result); -} - -static int32_t -typedef_parse(Parse_Context *context, Item_Node *item){ - int32_t result = false; - - Cpp_Token *token = get_token(context); - String doc_string = {0}; - get_doc_string_from_prev(context, &doc_string); - - Cpp_Token *start_token = token; - - for (; (token = get_token(context)) != 0; get_next_token(context)){ - if (token->type == CPP_TOKEN_SEMICOLON){ - break; - } - } - - if (token){ - Cpp_Token *token_j = token; - - for (; (token_j = get_token(context)) > start_token; get_prev_token(context)){ - if (token_j->type == CPP_TOKEN_IDENTIFIER){ - break; - } - } - - String name = get_lexeme(*token_j, context->data); - - String type = skip_chop_whitespace( - str_start_end(context->data, start_token->start + start_token->size, token_j->start) - ); - - item->t = Item_Typedef; - item->type = type; - item->name = name; - item->doc_string = doc_string; - result = true; - } - - set_token(context, token); - - return(result); -} - -static int32_t -enum_parse(Partition *part, Parse_Context *context, Item_Node *item){ - - int32_t result = false; - - String doc_string = {0}; - get_doc_string_from_prev(context, &doc_string); - - Cpp_Token *start_token = get_token(context); - Cpp_Token *token = 0; - - for (; (token = get_token(context)) != 0; get_next_token(context)){ - if (token->type == CPP_TOKEN_BRACE_OPEN){ - break; - } - } - - if (token){ - String name = {0}; - Cpp_Token *token_j = 0; - - for (; (token_j = get_token(context)) != 0; get_prev_token(context)){ - if (token_j->type == CPP_TOKEN_IDENTIFIER){ - break; - } - } - - name = get_lexeme(*token_j, context->data); - - set_token(context, token); - for (; (token = get_token(context)) > start_token; get_next_token(context)){ - if (token->type == CPP_TOKEN_BRACE_OPEN){ - break; - } - } - - if (token){ - Item_Node *first_member = 0; - Item_Node *head_member = 0; - - for (; (token = get_token(context)) != 0; get_next_token(context)){ - if (token->type == CPP_TOKEN_BRACE_CLOSE){ - break; - } - else if (token->type == CPP_TOKEN_IDENTIFIER){ - String doc_string = {0}; - String name = {0}; - String value = {0}; - get_doc_string_from_prev(context, &doc_string); - - name = get_lexeme(*token, context->data); - - token = get_next_token(context); - - if (token){ - if (token->type == CPP_TOKEN_EQ){ - Cpp_Token *start_token = token; - - for (; (token = get_token(context)) != 0; get_next_token(context)){ - if (token->type == CPP_TOKEN_COMMA || - token->type == CPP_TOKEN_BRACE_CLOSE){ - break; - } - } - - value = skip_chop_whitespace( - str_start_end(context->data, start_token->start + start_token->size, token->start) - ); - - get_prev_token(context); - } - else{ - get_prev_token(context); - } - } - - Item_Node *new_member = push_struct(part, Item_Node); - if (first_member == 0){ - first_member = new_member; - } - - if (head_member){ - head_member->next_sibling = new_member; - } - head_member = new_member; - - new_member->name = name; - new_member->value = value; - new_member->doc_string = doc_string; - new_member->next_sibling = 0; - } - } - - if ((token = get_token(context)) != 0){ - for (; (token = get_token(context)) != 0; get_next_token(context)){ - if (token->type == CPP_TOKEN_BRACE_CLOSE){ - break; - } - } - get_next_token(context); - - item->t = Item_Enum; - item->name = name; - item->doc_string = doc_string; - item->first_child = first_member; - result = true; - } - } - } - - return(result); -} - -static Argument_Breakdown -allocate_argument_breakdown(Partition *part, int32_t count){ - Argument_Breakdown breakdown = {0}; - if (count > 0){ - breakdown.count = count; - breakdown.args = push_array(part, Argument, count); - memset(breakdown.args, 0, sizeof(Argument)*count); - } - return(breakdown); -} - -/* -Parse arguments by giving pointers to the tokens: -foo(a, ... , z) - ^ ^ -*/ -static Argument_Breakdown -parameter_parse(Partition *part, char *data, Cpp_Token *args_start_token, Cpp_Token *args_end_token){ - int32_t arg_index = 0; - Cpp_Token *arg_token = args_start_token + 1; - int32_t param_string_start = arg_token->start; - - int32_t arg_count = 1; - arg_token = args_start_token; - for (; arg_token < args_end_token; ++arg_token){ - if (arg_token->type == CPP_TOKEN_COMMA){ - ++arg_count; - } - } - - Argument_Breakdown breakdown = allocate_argument_breakdown(part, arg_count); - - arg_token = args_start_token + 1; - for (; arg_token <= args_end_token; ++arg_token){ - if (arg_token->type == CPP_TOKEN_COMMA || - arg_token->type == CPP_TOKEN_PARENTHESE_CLOSE){ - - int32_t size = arg_token->start - param_string_start; - String param_string = make_string(data + param_string_start, size); - param_string = chop_whitespace(param_string); - breakdown.args[arg_index].param_string = param_string; - - for (Cpp_Token *param_name_token = arg_token - 1; - param_name_token->start > param_string_start; - --param_name_token){ - if (param_name_token->type == CPP_TOKEN_IDENTIFIER){ - int32_t start = param_name_token->start; - int32_t size = param_name_token->size; - breakdown.args[arg_index].param_name = make_string(data + start, size); - break; - } - } - - ++arg_index; - - if (arg_token+1 <= args_end_token){ - param_string_start = arg_token[1].start; - } - } - } - - return(breakdown); -} - -/* -Moves the context in the following way: -~~~~~~~ name( ~~~~~~~ - ^ -> ^ -*/ -static int32_t -function_parse_goto_name(Parse_Context *context){ - int32_t result = false; - - Cpp_Token *token = 0; - - { - for (; (token = get_token(context)) != 0; get_next_token(context)){ - if (token->type == CPP_TOKEN_PARENTHESE_OPEN){ - break; - } - } - - if (get_token(context)){ - do{ - token = get_prev_token(context); - }while(token->type == CPP_TOKEN_COMMENT); - - if (token->type == CPP_TOKEN_IDENTIFIER){ - result = true; - } - } - } - - return(result); -} - -/* -Moves the context in the following way: -~~~~~~~ name( ~~~~~~~ /* XXX // - ^ ---------------> ^ -*/ -static int32_t -function_get_doc(Parse_Context *context, char *data, String *doc_string){ - int32_t result = false; - - Cpp_Token *token = get_token(context); - String lexeme = {0}; - - if (function_parse_goto_name(context)){ - if (token->type == CPP_TOKEN_IDENTIFIER){ - for (; (token = get_token(context)) != 0; get_next_token(context)){ - if (token->type == CPP_TOKEN_COMMENT){ - lexeme = get_lexeme(*token, data); - if (check_and_fix_docs(&lexeme)){ - *doc_string = lexeme; - result = true; - break; - } - } - else if (token->type == CPP_TOKEN_BRACE_OPEN){ - break; - } - } - } - } - - return(result); -} - -static int32_t -cpp_name_parse(Parse_Context *context, String *name){ - int32_t result = false; - - Cpp_Token *token = 0; - Cpp_Token *token_start = get_token(context); - - token = get_next_token(context); - if (token && token->type == CPP_TOKEN_PARENTHESE_OPEN){ - token = get_next_token(context); - if (token && token->type == CPP_TOKEN_IDENTIFIER){ - token = get_next_token(context); - if (token && token->type == CPP_TOKEN_PARENTHESE_CLOSE){ - *name = get_lexeme(*(token-1), context->data); - result = true; - } - } - } - - if (!result){ - set_token(context, token_start); - } - - return(result); -} - -/* -Moves the context in the following way: - RETTY~ name( ~~~~~~~ ) - ^ ---------------> ^ -*/ -static int32_t -function_sig_parse(Partition *part, Parse_Context *context, Item_Node *item, String cpp_name){ - int32_t result = false; - - Cpp_Token *token = 0; - Cpp_Token *args_start_token = 0; - Cpp_Token *ret_token = get_token(context); - - if (function_parse_goto_name(context)){ - token = get_token(context); - args_start_token = token+1; - item->name = get_lexeme(*token, context->data); - - item->ret = chop_whitespace( - str_start_end(context->data, ret_token->start, token->start) - ); - - for (; (token = get_token(context)) != 0; get_next_token(context)){ - if (token->type == CPP_TOKEN_PARENTHESE_CLOSE){ - break; - } - } - - if (token){ - item->args = - str_start_end(context->data, args_start_token->start, token->start + token->size); - item->t = Item_Function; - item->cpp_name = cpp_name; - item->breakdown = parameter_parse(part, context->data, args_start_token, token); - - Assert(get_token(context)->type == CPP_TOKEN_PARENTHESE_CLOSE); - result = true; - } - } - - return(result); -} - -/* -Moves the context in the following way: - MARKER ~~~ name( ~~~~~~~ ) - ^ -------------------> ^ -*/ -static int32_t -function_parse(Partition *part, Parse_Context *context, Item_Node *item, String cpp_name){ - int32_t result = false; - - String doc_string = {0}; - Cpp_Token *token = get_token(context); - - item->marker = get_lexeme(*token, context->data); - - if (function_get_doc(context, context->data, &doc_string)){ - item->doc_string = doc_string; - } - - set_token(context, token); - if (get_next_token(context)){ - if (function_sig_parse(part, context, item, cpp_name)){ - Assert(get_token(context)->type == CPP_TOKEN_PARENTHESE_CLOSE); - result = true; - } - } - - return(result); -} - -/* -Moves the context in the following way: - /* ~~~ // #define - ^ ----> ^ -*/ -static int32_t -macro_parse_check(Parse_Context *context){ - int32_t result = false; - - Cpp_Token *token = 0; - - if ((token = get_next_token(context)) != 0){ - if (token->type == CPP_TOKEN_COMMENT){ - if ((token = get_next_token(context)) != 0){ - if (token->type == CPP_PP_DEFINE){ - result = true; - } - } - } - } - - return(result); -} - -/* -Moves the context in the following way: - /* ~~~ // #define ~~~~~~~~~~~~~~~~~ NOT_IN_MACRO_BODY - ^ ----------------------------> ^ -*/ -static int32_t -macro_parse(Partition *part, Parse_Context *context, Item_Node *item){ - int32_t result = false; - - Cpp_Token *token = 0; - Cpp_Token *doc_token = 0; - Cpp_Token *args_start_token = 0; - - String doc_string = {0}; - - if (macro_parse_check(context)){ - token = get_token(context); - if (can_back_step(context)){ - doc_token = token-1; - - doc_string = get_lexeme(*doc_token, context->data); - - if (check_and_fix_docs(&doc_string)){ - item->doc_string = doc_string; - - for (; (token = get_token(context)) != 0; get_next_token(context)){ - if (token->type == CPP_TOKEN_IDENTIFIER){ - break; - } - } - - if (get_token(context) && (token->flags & CPP_TFLAG_PP_BODY)){ - item->name = get_lexeme(*token, context->data); - - if ((token = get_next_token(context)) != 0){ - args_start_token = token; - for (; (token = get_token(context)) != 0; get_next_token(context)){ - if (token->type == CPP_TOKEN_PARENTHESE_CLOSE){ - break; - } - } - - if (token){ - item->args = str_start_end(context->data, args_start_token->start, - token->start + token->size); - - item->breakdown = parameter_parse(part, context->data, args_start_token, token); - - if ((token = get_next_token(context)) != 0){ - Cpp_Token *body_start = token; - - if (body_start->flags & CPP_TFLAG_PP_BODY){ - for (; (token = get_token(context)) != 0; get_next_token(context)){ - if (!(token->flags & CPP_TFLAG_PP_BODY)){ - break; - } - } - - token = get_prev_token(context); - - item->body = - str_start_end(context->data, body_start->start, - token->start + token->size); - } - } - - item->t = Item_Macro; - result = true; - } - } - } - } - } - } - - return(result); -} - -static Meta_Unit -compile_meta_unit(Partition *part, char **files, int32_t file_count, - Meta_Keywords *keywords, int32_t key_count){ - Meta_Unit unit = {0}; - int32_t i = 0; - - unit.count = file_count; - unit.parse = push_array(part, Parse, file_count); - - for (i = 0; i < file_count; ++i){ - unit.parse[i] = meta_lex(files[i]); - } - - // TODO(allen): This stage counts nested structs - // and unions which is not correct. Luckily it only - // means we over allocate by a few items, but fixing it - // to be exactly correct would be nice. - for (int32_t J = 0; J < unit.count; ++J){ - Cpp_Token *token = 0; - Parse_Context context_ = setup_parse_context(unit.parse[J]); - Parse_Context *context = &context_; - - for (; (token = get_token(context)) != 0; get_next_token(context)){ - if (!(token->flags & CPP_TFLAG_PP_BODY)){ - - String lexeme = get_lexeme(*token, context->data); - int32_t match_index = 0; - if (string_set_match_table(keywords, sizeof(*keywords), key_count, lexeme, &match_index)){ - Item_Type type = keywords[match_index].type; - - if (type > Item_Null && type < Item_Type_Count){ - ++unit.set.count; - } - else{ - // TODO(allen): Warning - } - } - } - } - } - - if (unit.set.count > 0){ - unit.set = allocate_item_set(part, unit.set.count); - } - - int32_t index = 0; - - for (int32_t J = 0; J < unit.count; ++J){ - Cpp_Token *token = 0; - Parse_Context context_ = setup_parse_context(unit.parse[J]); - Parse_Context *context = &context_; - - String cpp_name = {0}; - int32_t has_cpp_name = 0; - - for (; (token = get_token(context)) != 0; get_next_token(context)){ - if (!(token->flags & CPP_TFLAG_PP_BODY)){ - - String lexeme = get_lexeme(*token, context->data); - int32_t match_index = 0; - if (string_set_match_table(keywords, sizeof(*keywords), key_count, lexeme, &match_index)){ - Item_Type type = keywords[match_index].type; - - switch (type){ - case Item_Function: - { - if (function_parse(part, context, unit.set.items + index, cpp_name)){ - Assert(unit.set.items[index].t == Item_Function); - ++index; - } - else{ - fprintf(stderr, "warning: invalid function signature\n"); - } - }break; - - case Item_CppName: - { - if (cpp_name_parse(context, &cpp_name)){ - has_cpp_name = 1; - } - else{ - // TODO(allen): warning message - } - }break; - - case Item_Macro: - { - if (macro_parse(part, context, unit.set.items + index)){ - Assert(unit.set.items[index].t == Item_Macro); - ++index; - } - else{ - // TODO(allen): warning message - } - }break; - - case Item_Typedef: //typedef - { - if (typedef_parse(context, unit.set.items + index)){ - Assert(unit.set.items[index].t == Item_Typedef); - ++index; - } - else{ - // TODO(allen): warning message - } - }break; - - case Item_Struct: case Item_Union: //struct/union - { - if (struct_parse(part, (type == Item_Struct), context, unit.set.items + index)){ - Assert(unit.set.items[index].t == Item_Struct || - unit.set.items[index].t == Item_Union); - ++index; - } - else{ - // TODO(allen): warning message - } - }break; - - case Item_Enum: //ENUM - { - if (enum_parse(part, context, unit.set.items + index)){ - Assert(unit.set.items[index].t == Item_Enum); - ++index; - } - else{ - // TODO(allen): warning message - } - }break; - - } - } - } - - if (has_cpp_name){ - has_cpp_name = 0; - } - else{ - cpp_name = null_string; - } - - unit.parse[J].item_count = index; - } - - // NOTE(allen): This is necessary for now because - // the original count is slightly overestimated thanks - // to nested structs and unions. - unit.set.count = index; - } - - return(unit); -} - -static void -init_used_links(Partition *part, Used_Links *used, int32_t count){ - used->strs = push_array(part, String, count); - used->count = 0; - used->max = count; -} - -static int32_t -try_to_use(Used_Links *used, String str){ - int32_t result = 1; - int32_t index = 0; - - if (string_set_match(used->strs, used->count, str, &index)){ - result = 0; - } - else{ - used->strs[used->count++] = str; - } - - return(result); -} - -static void -print_struct_html(String *out, Item_Node *member, int32_t hide_children){ - String name = member->name; - String type = member->type; - String type_postfix = member->type_postfix; - - append_ss (out, type); - append_s_char (out, ' '); - append_ss (out, name); - append_ss (out, type_postfix); - - if (match_ss(type, make_lit_string("struct")) || - match_ss(type, make_lit_string("union"))){ - - if (hide_children){ - append_sc(out, " { /* non-public internals */ } ;"); - } - else{ - append_sc(out, " {
"); - - for (Item_Node *member_iter = member->first_child; - member_iter != 0; - member_iter = member_iter->next_sibling){ - print_struct_html(out, member_iter, hide_children); - } - - append_sc(out, "
};
"); - } - } - else{ - append_sc(out, ";
"); - } -} - -static void -print_function_html(String *out, Used_Links *used, String cpp_name, - String ret, char *function_call_head, String name, Argument_Breakdown breakdown){ - - append_ss (out, ret); - append_s_char (out, ' '); - append_sc (out, function_call_head); - append_ss (out, name); - append_sc (out, "(
"); - - for (int32_t j = 0; j < breakdown.count; ++j){ - append_ss(out, breakdown.args[j].param_string); - if (j < breakdown.count - 1){ - append_s_char(out, ','); - } - append_sc(out, "
"); - } - - append_sc(out, "
)"); -} - -static void -print_macro_html(String *out, String name, Argument_Breakdown breakdown){ - - if (breakdown.count == 0){ - append_sc(out, "#define "); - append_ss(out, name); - append_sc(out, "()"); - } - else if (breakdown.count == 1){ - append_sc (out, "#define "); - append_ss (out, name); - append_s_char (out, '('); - append_ss (out, breakdown.args[0].param_string); - append_s_char (out, ')'); - } - else{ - append_sc (out, "#define "); - append_ss (out, name); - append_sc (out, "(
"); - - for (int32_t j = 0; j < breakdown.count; ++j){ - append_ss(out, breakdown.args[j].param_string); - if (j < breakdown.count - 1){ - append_s_char(out, ','); - } - append_sc(out, "
"); - } - - append_sc(out, ")
)"); - } -} - -#define BACK_COLOR "#FAFAFA" -#define TEXT_COLOR "#0D0D0D" -#define CODE_BACK "#DFDFDF" -#define EXAMPLE_BACK "#EFEFDF" - -#define POP_COLOR_1 "#309030" -#define POP_BACK_1 "#E0FFD0" -#define VISITED_LINK "#A0C050" - -#define POP_COLOR_2 "#005000" - -#define CODE_STYLE "font-family: \"Courier New\", Courier, monospace; text-align: left;" - -#define CODE_BLOCK_STYLE(back) \ -"margin-top: 3mm; margin-bottom: 3mm; font-size: .95em; " \ -"background: "back"; padding: 0.25em;" - -#define DESCRIPT_SECTION_STYLE CODE_BLOCK_STYLE(CODE_BACK) -#define EXAMPLE_CODE_STYLE CODE_BLOCK_STYLE(EXAMPLE_BACK) - -#define DOC_HEAD_OPEN "
" -#define DOC_HEAD_CLOSE "
" - -#define DOC_ITEM_HEAD_STYLE "font-weight: 600;" - -#define DOC_ITEM_HEAD_INL_OPEN "" -#define DOC_ITEM_HEAD_INL_CLOSE "" - -#define DOC_ITEM_HEAD_OPEN "
" -#define DOC_ITEM_HEAD_CLOSE "
" - -#define DOC_ITEM_OPEN "
" -#define DOC_ITEM_CLOSE "
" - -#define EXAMPLE_CODE_OPEN "
" -#define EXAMPLE_CODE_CLOSE "
" - -static String -get_first_double_line(String source){ - String line = {0}; - int32_t pos0 = find_substr_s(source, 0, make_lit_string("\n\n")); - int32_t pos1 = find_substr_s(source, 0, make_lit_string("\r\n\r\n")); - if (pos1 < pos0){ - pos0 = pos1; - } - line = substr(source, 0, pos0); - return(line); -} - -static String -get_next_double_line(String source, String line){ - String next = {0}; - int32_t pos = (int32_t)(line.str - source.str) + line.size; - int32_t start = 0, pos0 = 0, pos1 = 0; - - if (pos < source.size){ - assert(source.str[pos] == '\n' || source.str[pos] == '\r'); - start = pos + 1; - - if (start < source.size){ - pos0 = find_substr_s(source, start, make_lit_string("\n\n")); - pos1 = find_substr_s(source, start, make_lit_string("\r\n\r\n")); - if (pos1 < pos0){ - pos0 = pos1; - } - next = substr(source, start, pos0 - start); - } - } - - return(next); -} - -static String -get_next_word(String source, String prev_word){ - String word = {0}; - int32_t pos0 = (int32_t)(prev_word.str - source.str) + prev_word.size; - int32_t pos1 = 0; - char c = 0; - - for (; pos0 < source.size; ++pos0){ - c = source.str[pos0]; - if (!(char_is_whitespace(c) || c == '(' || c == ')')){ - break; - } - } - - if (pos0 < source.size){ - for (pos1 = pos0; pos1 < source.size; ++pos1){ - c = source.str[pos1]; - if (char_is_whitespace(c) || c == '(' || c == ')'){ - break; - } - } - - word = substr(source, pos0, pos1 - pos0); - } - - return(word); -} - -static String -get_first_word(String source){ - String start_str = make_string(source.str, 0); - String word = get_next_word(source, start_str); - return(word); -} - -enum Doc_Chunk_Type{ - DocChunk_PlainText, - DocChunk_CodeExample, - - DocChunk_Count -}; - -static String doc_chunk_headers[] = { - make_lit_string(""), - make_lit_string("CODE_EXAMPLE"), -}; - -static String -get_next_doc_chunk(String source, String prev_chunk, Doc_Chunk_Type *type){ - String chunk = {0}; - String word = {0}; - int32_t pos = source.size; - int32_t word_index = 0; - Doc_Chunk_Type t = DocChunk_PlainText; - - int32_t start_pos = (int32_t)(prev_chunk.str - source.str) + prev_chunk.size; - String source_tail = substr_tail(source, start_pos); - - Assert(DocChunk_Count == ArrayCount(doc_chunk_headers)); - - for (word = get_first_word(source_tail); - word.str; - word = get_next_word(source_tail, word), ++word_index){ - - for (int32_t i = 1; i < DocChunk_Count; ++i){ - if (match_ss(word, doc_chunk_headers[i])){ - pos = (int32_t)(word.str - source.str); - t = (Doc_Chunk_Type)i; - goto doublebreak; - } - } - } - doublebreak:; - - *type = DocChunk_PlainText; - if (word_index == 0){ - *type = t; - - int32_t nest_level = 1; - int32_t i = find_s_char(source, pos, '('); - for (++i; i < source.size; ++i){ - if (source.str[i] == '('){ - ++nest_level; - } - else if (source.str[i] == ')'){ - --nest_level; - if (nest_level == 0){ - break; - } - } - } - - pos = i+1; - } - - chunk = substr(source, start_pos, pos - start_pos); - - int32_t is_all_white = 1; - for (int32_t i = 0; i < chunk.size; ++i){ - if (!char_is_whitespace(chunk.str[i])){ - is_all_white = 0; - break; - } - } - - if (is_all_white){ - chunk = null_string; - } - - return(chunk); -} - -static String -get_first_doc_chunk(String source, Doc_Chunk_Type *type){ - String start_str = make_string(source.str, 0); - String chunk = get_next_doc_chunk(source, start_str, type); - return(chunk); -} - -static void -print_doc_description(String *out, Partition *part, String src){ - Doc_Chunk_Type type; - - for (String chunk = get_first_doc_chunk(src, &type); - chunk.str; - chunk = get_next_doc_chunk(src, chunk, &type)){ - - switch (type){ - case DocChunk_PlainText: - { - for (String line = get_first_double_line(chunk); - line.str; - line = get_next_double_line(chunk, line)){ - append_ss(out, line); - append_sc(out, "

"); - } - }break; - - case DocChunk_CodeExample: - { - int32_t start = 0; - int32_t end = chunk.size-1; - while (start < end && chunk.str[start] != '(') ++start; - start += 1; - while (end > start && chunk.str[end] != ')') --end; - - - append_sc(out, EXAMPLE_CODE_OPEN); - - if (start < end){ - String code_example = substr(chunk, start, end - start); - int32_t first_line = 1; - - for (String line = get_first_line(code_example); - line.str; - line = get_next_line(code_example, line)){ - - if (!(first_line && line.size == 0)){ - int32_t space_i = 0; - for (; space_i < line.size; ++space_i){ - if (line.str[space_i] == ' '){ - append_sc(out, " "); - } - else{ - break; - } - } - - String line_tail = substr_tail(line, space_i); - append_ss(out, line_tail); - append_sc(out, "
"); - } - first_line = 0; - } - } - - append_sc(out, EXAMPLE_CODE_CLOSE); - }break; - } - } -} - -static void -print_struct_docs(String *out, Partition *part, Item_Node *member){ - for (Item_Node *member_iter = member->first_child; - member_iter != 0; - member_iter = member_iter->next_sibling){ - String type = member_iter->type; - if (match_ss(type, make_lit_string("struct")) || - match_ss(type, make_lit_string("union"))){ - print_struct_docs(out, part, member_iter); - } - else{ - Documentation doc = {0}; - perform_doc_parse(part, member_iter->doc_string, &doc); - - append_sc(out, "
"); - - append_sc(out, "
"DOC_ITEM_HEAD_INL_OPEN); - append_ss(out, member_iter->name); - append_sc(out, DOC_ITEM_HEAD_INL_CLOSE"
"); - - append_sc(out, "
"DOC_ITEM_OPEN); - print_doc_description(out, part, doc.main_doc); - append_sc(out, DOC_ITEM_CLOSE"
"); - - append_sc(out, "
"); - } - } -} - -static void -print_see_also(String *out, Documentation *doc){ - int32_t doc_see_count = doc->see_also_count; - if (doc_see_count > 0){ - append_sc(out, DOC_HEAD_OPEN"See Also"DOC_HEAD_CLOSE); - - for (int32_t j = 0; j < doc_see_count; ++j){ - String see_also = doc->see_also[j]; - append_sc(out, DOC_ITEM_OPEN""); - append_ss(out, see_also); - append_sc(out, ""DOC_ITEM_CLOSE); - } - } -} - static void print_function_body_code(String *out, Parse_Context *context, int32_t start){ String pstr = {0}, lexeme = {0}; @@ -2099,6 +368,8 @@ print_function_body_code(String *out, Parse_Context *context, int32_t start){ int32_t nest_level = 0; int32_t finish = false; int32_t do_whitespace_print = false; + int32_t is_first = true; + for (; (token = get_token(context)) != 0; get_next_token(context)){ if (do_whitespace_print){ pstr = str_start_end(context->data, start, token->start); @@ -2124,6 +395,10 @@ print_function_body_code(String *out, Parse_Context *context, int32_t start){ finish = true; } } + if (is_first){ + do_print = false; + is_first = false; + } if (do_print){ pstr = get_lexeme(*token, context->data); @@ -2138,294 +413,6 @@ print_function_body_code(String *out, Parse_Context *context, int32_t start){ } } -static void -print_function_docs(String *out, Partition *part, String name, String doc_string){ - if (doc_string.size == 0){ - append_sc(out, "No documentation generated for this function."); - fprintf(stderr, "warning: no documentation string for %.*s\n", name.size, name.str); - } - - Temp_Memory temp = begin_temp_memory(part); - - Documentation doc = {0}; - - perform_doc_parse(part, doc_string, &doc); - - int32_t doc_param_count = doc.param_count; - if (doc_param_count > 0){ - append_sc(out, DOC_HEAD_OPEN"Parameters"DOC_HEAD_CLOSE); - - for (int32_t j = 0; j < doc_param_count; ++j){ - String param_name = doc.param_name[j]; - String param_docs = doc.param_docs[j]; - - // TODO(allen): check that param_name is actually - // a parameter to this function! - - append_sc(out, "
"DOC_ITEM_HEAD_OPEN); - append_ss(out, param_name); - append_sc(out, DOC_ITEM_HEAD_CLOSE"
"DOC_ITEM_OPEN); - append_ss(out, param_docs); - append_sc(out, DOC_ITEM_CLOSE"
"); - } - } - - String ret_doc = doc.return_doc; - if (ret_doc.size != 0){ - append_sc(out, DOC_HEAD_OPEN"Return"DOC_HEAD_CLOSE DOC_ITEM_OPEN); - append_ss(out, ret_doc); - append_sc(out, DOC_ITEM_CLOSE); - } - - String main_doc = doc.main_doc; - if (main_doc.size != 0){ - append_sc(out, DOC_HEAD_OPEN"Description"DOC_HEAD_CLOSE DOC_ITEM_OPEN); - print_doc_description(out, part, main_doc); - append_sc(out, DOC_ITEM_CLOSE); - } - - print_see_also(out, &doc); - - end_temp_memory(temp); -} - -static void -print_item_in_list(String *out, String name, char *id_postfix){ - append_sc(out, "
  • "); - append_ss(out, name); - append_sc(out, "
  • "); -} - -static void -print_item(String *out, Partition *part, Used_Links *used, - Item_Node *item, char *id_postfix, char *function_prefix, - char *section, int32_t I){ - Temp_Memory temp = begin_temp_memory(part); - - String name = item->name; - /* NOTE(allen): - Open a div for the whole item. - Put a heading in it with the name and section. - Open a "descriptive" box for the display of the code interface. - */ - append_sc(out, "
    "); - - int32_t has_cpp_name = 0; - if (item->cpp_name.str != 0){ - if (try_to_use(used, item->cpp_name)){ - append_sc(out, "
    "); - has_cpp_name = 1; - } - } - - append_sc (out, "

    §"); - append_sc (out, section); - append_s_char (out, '.'); - append_int_to_str (out, I); - append_sc (out, ": "); - append_ss (out, name); - append_sc (out, "

    "); - - append_sc(out, "
    "); - - switch (item->t){ - case Item_Function: - { - // NOTE(allen): Code box - Assert(function_prefix != 0); - print_function_html(out, used, item->cpp_name, - item->ret, function_prefix, item->name, item->breakdown); - - // NOTE(allen): Close the code box - append_sc(out, "
    "); - - // NOTE(allen): Descriptive section - print_function_docs(out, part, item->name, item->doc_string); - }break; - - case Item_Macro: - { - // NOTE(allen): Code box - print_macro_html(out, item->name, item->breakdown); - - // NOTE(allen): Close the code box - append_sc(out, "
    "); - - // NOTE(allen): Descriptive section - print_function_docs(out, part, item->name, item->doc_string); - }break; - - case Item_Typedef: - { - String type = item->type; - - // NOTE(allen): Code box - append_sc (out, "typedef "); - append_ss (out, type); - append_s_char (out, ' '); - append_ss (out, name); - append_s_char (out, ';'); - - // NOTE(allen): Close the code box - append_sc(out, "
    "); - - // NOTE(allen): Descriptive section - String doc_string = item->doc_string; - Documentation doc = {0}; - perform_doc_parse(part, doc_string, &doc); - - String main_doc = doc.main_doc; - if (main_doc.size != 0){ - append_sc(out, DOC_HEAD_OPEN"Description"DOC_HEAD_CLOSE); - - append_sc(out, DOC_ITEM_OPEN); - print_doc_description(out, part, main_doc); - append_sc(out, DOC_ITEM_CLOSE); - } - else{ - fprintf(stderr, "warning: no documentation string for %.*s\n", name.size, name.str); - } - - print_see_also(out, &doc); - - }break; - - case Item_Enum: - { - // NOTE(allen): Code box - append_sc (out, "enum "); - append_ss (out, name); - append_s_char (out, ';'); - - // NOTE(allen): Close the code box - append_sc(out, "
    "); - - // NOTE(allen): Descriptive section - String doc_string = item->doc_string; - Documentation doc = {0}; - perform_doc_parse(part, doc_string, &doc); - - String main_doc = doc.main_doc; - if (main_doc.size != 0){ - append_sc(out, DOC_HEAD_OPEN"Description"DOC_HEAD_CLOSE); - - append_sc(out, DOC_ITEM_OPEN); - print_doc_description(out, part, main_doc); - append_sc(out, DOC_ITEM_CLOSE); - } - else{ - fprintf(stderr, "warning: no documentation string for %.*s\n", name.size, name.str); - } - - if (item->first_child){ - append_sc(out, DOC_HEAD_OPEN"Values"DOC_HEAD_CLOSE); - - for (Item_Node *member = item->first_child; - member; - member = member->next_sibling){ - Documentation doc = {0}; - perform_doc_parse(part, member->doc_string, &doc); - - append_sc(out, "
    "); - - // NOTE(allen): Dafuq is this all? - append_sc(out, "
    "DOC_ITEM_HEAD_INL_OPEN); - append_ss(out, member->name); - append_sc(out, DOC_ITEM_HEAD_INL_CLOSE); - - if (member->value.str){ - append_sc(out, " = "); - append_ss(out, member->value); - } - - append_sc(out, "
    "); - - append_sc(out, "
    "DOC_ITEM_OPEN); - print_doc_description(out, part, doc.main_doc); - append_sc(out, DOC_ITEM_CLOSE"
    "); - - append_sc(out, "
    "); - } - } - - print_see_also(out, &doc); - - }break; - - case Item_Struct: case Item_Union: - { - String doc_string = item->doc_string; - - int32_t hide_members = 0; - - if (doc_string.size == 0){ - hide_members = 1; - } - else{ - for (String word = get_first_word(doc_string); - word.str; - word = get_next_word(doc_string, word)){ - if (match_ss(word, make_lit_string("HIDE_MEMBERS"))){ - hide_members = 1; - break; - } - } - } - - // NOTE(allen): Code box - print_struct_html(out, item, hide_members); - - // NOTE(allen): Close the code box - append_sc(out, "
    "); - - // NOTE(allen): Descriptive section - { - Documentation doc = {0}; - perform_doc_parse(part, doc_string, &doc); - - String main_doc = doc.main_doc; - if (main_doc.size != 0){ - append_sc(out, DOC_HEAD_OPEN"Description"DOC_HEAD_CLOSE); - - append_sc(out, DOC_ITEM_OPEN); - print_doc_description(out, part, main_doc); - append_sc(out, DOC_ITEM_CLOSE); - } - else{ - fprintf(stderr, "warning: no documentation string for %.*s\n", name.size, name.str); - } - - if (!hide_members){ - if (item->first_child){ - append_sc(out, DOC_HEAD_OPEN"Fields"DOC_HEAD_CLOSE); - print_struct_docs(out, part, item); - } - } - - print_see_also(out, &doc); - } - }break; - } - - if (has_cpp_name){ - append_sc(out, "
    "); - } - - // NOTE(allen): Close the item box - append_sc(out, "

    "); - - end_temp_memory(temp); -} - typedef struct App_API_Name{ String macro; String public_name; @@ -2447,7 +434,6 @@ static void generate_custom_headers(){ #define API_H "4coder_custom_api.h" #define OS_API_H "4ed_os_custom_api.h" -#define API_DOC "4coder_API.html" #define STRING_H "4coder_string.h" int32_t size = (512 << 20); @@ -2457,65 +443,36 @@ generate_custom_headers(){ Partition part_ = make_part(mem, size); Partition *part = &part_; - - // NOTE(allen): Parse the internal string file. - static char *string_files[] = { - "internal_4coder_string.cpp" - }; - - static Meta_Keywords string_keys[] = { - {make_lit_string("FSTRING_INLINE") , Item_Function } , - {make_lit_string("FSTRING_LINK") , Item_Function } , - {make_lit_string("DOC_EXPORT") , Item_Macro } , - {make_lit_string("CPP_NAME") , Item_CppName } , - }; - - Meta_Unit string_unit = compile_meta_unit(part, string_files, ArrayCount(string_files), - string_keys, ArrayCount(string_keys)); - - - // NOTE(allen): Parse the lexer library - static char *lexer_types_files[] = { - "4cpp_lexer_types.h", - }; - - static Meta_Keywords lexer_types_keys[] = { - {make_lit_string("typedef") , Item_Typedef } , - {make_lit_string("struct") , Item_Struct } , - {make_lit_string("union") , Item_Union } , + static Meta_Keywords meta_keywords[] = { + {make_lit_string("API_EXPORT") , Item_Function } , + {make_lit_string("API_EXPORT_INLINE") , Item_Function } , + {make_lit_string("API_EXPORT_MACRO") , Item_Macro } , + {make_lit_string("CPP_NAME") , Item_CppName } , + {make_lit_string("TYPEDEF") , Item_Typedef } , + {make_lit_string("STRUCT") , Item_Struct } , + {make_lit_string("UNION") , Item_Union } , {make_lit_string("ENUM") , Item_Enum } , }; - Meta_Unit lexer_types_unit = - compile_meta_unit(part, lexer_types_files, ArrayCount(lexer_types_files), - lexer_types_keys, ArrayCount(lexer_types_keys)); +#define ExpandArray(a) (a), (ArrayCount(a)) - static char *lexer_funcs_files[] = { - "4cpp_lexer.h", + // NOTE(allen): Parse the internal string file. + static char *string_files[] = { + "internal_4coder_string.cpp", + 0 }; - static Meta_Keywords lexer_funcs_keys[] = { - {make_lit_string("FCPP_LINK") , Item_Function } , - }; - - Meta_Unit lexer_funcs_unit = - compile_meta_unit(part, lexer_funcs_files, ArrayCount(lexer_funcs_files), - lexer_funcs_keys, ArrayCount(lexer_funcs_keys)); - + Meta_Unit string_unit = compile_meta_unit(part, ".", string_files, ExpandArray(meta_keywords)); // NOTE(allen): Parse the customization API files static char *functions_files[] = { "4ed_api_implementation.cpp", "win32_api_impl.cpp", + 0 }; - static Meta_Keywords functions_keys[] = { - {make_lit_string("API_EXPORT"), Item_Function}, - }; - - Meta_Unit unit_custom = compile_meta_unit(part, functions_files, ArrayCount(functions_files), - functions_keys, ArrayCount(functions_keys)); + Meta_Unit unit_custom = compile_meta_unit(part, ".", functions_files, ExpandArray(meta_keywords)); // NOTE(allen): Compute and store variations of the function names @@ -2536,21 +493,6 @@ generate_custom_headers(){ partition_align(part, 4); } - // NOTE(allen): Parse the customization API types - static char *type_files[] = { - "4coder_types.h", - }; - - static Meta_Keywords type_keys[] = { - {make_lit_string("typedef") , Item_Typedef } , - {make_lit_string("struct") , Item_Struct } , - {make_lit_string("union") , Item_Union } , - {make_lit_string("ENUM") , Item_Enum } , - }; - - Meta_Unit unit = compile_meta_unit(part, type_files, ArrayCount(type_files), - type_keys, ArrayCount(type_keys)); - // NOTE(allen): Output String out = str_alloc(part, 10 << 20); Out_Context context = {0}; @@ -2737,8 +679,7 @@ generate_custom_headers(){ append_sc(&out, "#if !defined(FCODER_STRING_H)\n#define FCODER_STRING_H\n\n"); do_print = false; - static int32_t RETURN_PADDING = 16; - static int32_t SIG_PADDING = 27; + static int32_t SIG_PADDING = 35; for (int32_t j = 0; j < string_unit.set.count; ++j){ char line_[2048]; @@ -2746,8 +687,8 @@ generate_custom_headers(){ Item_Node *item = string_unit.set.items + j; if (item->t == Item_Function){ - append_ss (&line, item->marker); - append_padding (&line, ' ', RETURN_PADDING); + //append_ss (&line, item->marker); + //append_padding (&line, ' ', RETURN_PADDING); append_ss (&line, item->ret); append_padding (&line, ' ', SIG_PADDING); append_ss (&line, item->name); @@ -2794,17 +735,15 @@ generate_custom_headers(){ if (cpp_name.str != 0){ Argument_Breakdown breakdown = item->breakdown; - append_ss (&line, make_lit_string("FSTRING_INLINE")); - append_padding(&line, ' ', RETURN_PADDING); append_ss (&line, item->ret); append_padding(&line, ' ', SIG_PADDING); append_ss (&line, cpp_name); append_ss (&line, item->args); if (match_ss(item->ret, make_lit_string("void"))){ - append_ss(&line, make_lit_string("{("));//} + append_ss(&line, make_lit_string("{(")); } else{ - append_ss(&line, make_lit_string("{return("));//} + append_ss(&line, make_lit_string("{return(")); } append_ss (&line, item->name); append_s_char(&line, '('); @@ -2821,7 +760,6 @@ generate_custom_headers(){ append_ss(&line, make_lit_string("void")); } - //{ append_ss(&line, make_lit_string("));}\n")); append_ss(&out, line); @@ -2832,7 +770,7 @@ generate_custom_headers(){ append_sc(&out, "\n#endif\n"); } - else if (match_ss(lexeme, make_lit_string("DOC_EXPORT"))){ + else if (match_ss(lexeme, make_lit_string("API_EXPORT_MACRO"))){ token = get_next_token(&pcontext); if (token && token->type == CPP_TOKEN_COMMENT){ token = get_next_token(&pcontext); @@ -2851,10 +789,10 @@ generate_custom_headers(){ } } - else if (match_ss(lexeme, make_lit_string("FSTRING_INLINE")) || - match_ss(lexeme, make_lit_string("FSTRING_LINK"))){ + else if (match_ss(lexeme, make_lit_string("API_EXPORT")) || + match_ss(lexeme, make_lit_string("API_EXPORT_INLINE"))){ if (!(token->flags & CPP_TFLAG_PP_BODY)){ - if (match_ss(lexeme, make_lit_string("FSTRING_INLINE"))){ + if (match_ss(lexeme, make_lit_string("API_EXPORT_INLINE"))){ append_sc(&out, "#if !defined(FSTRING_GUARD)\n"); } else{ @@ -2909,333 +847,6 @@ generate_custom_headers(){ else{ // TODO(allen): warning } - - - // Output Docs - - if (begin_file_out(&context, API_DOC, &out)){ - - Used_Links used_links = {0}; - init_used_links(part, &used_links, 4000); - - append_sc(&out, - "" - "" - "4coder API Docs" - "" - "\n" - "" - "
    " -// "

    4cpp Lexing Library

    "); - - "

    4coder API

    "); - - struct Section{ - char *id_string; - char *display_string; - }; - - static int32_t msection = -1; - - static Section sections[] = { - {"introduction", "Introduction"}, - {"4coder_systems", "4coder Systems"}, - {"types_and_functions", "Types and Functions"}, - {"string_library", "String Library"}, - {"lexer_library", "Lexer Library"} - }; - - append_sc(&out, "

    Table of Contents

    """); - -#define MAJOR_SECTION "1" - msection = 0; - - append_sc(&out, "\n

    §"MAJOR_SECTION" "); - append_sc(&out, sections[msection].display_string); - append_sc(&out, "

    "); - -#if 1 - // NOTE(allen): doc intro for lexer standalone - append_sc(&out, - "
    " - "

    This is the documentation for the 4cpp lexer version 1.1. " - "The documentation is the newest piece of this lexer project " - "so it may still have problems. What is here should be correct " - "and mostly complete.

    " - "

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

    " - "
    "); -#endif - - append_sc(&out, - "
    " - "

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

    " - "

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

    " - "
    "); - -#undef MAJOR_SECTION -#define MAJOR_SECTION "2" - msection = 1; - - // TODO(allen): Write the 4coder system descriptions. - append_sc(&out, "\n

    §"MAJOR_SECTION" "); - append_sc(&out, sections[msection].display_string); - append_sc(&out, "

    "); - - append_sc(&out, "
    Coming Soon
    "); - -#undef MAJOR_SECTION -#define MAJOR_SECTION "3" - msection = 2; - - append_sc(&out, "\n

    §"MAJOR_SECTION" "); - append_sc(&out, sections[msection].display_string); - append_sc(&out, "

    "); - -#undef SECTION -#define SECTION MAJOR_SECTION".1" - - append_sc(&out, "

    §"SECTION" Function List

      "); - for (int32_t i = 0; i < unit_custom.set.count; ++i){ - print_item_in_list(&out, func_4ed_names.names[i].public_name, "_doc"); - } - append_sc(&out, "
    "); - -#undef SECTION -#define SECTION MAJOR_SECTION".2" - - append_sc(&out, "

    §"SECTION" Type List

      "); - for (int32_t i = 0; i < unit.set.count; ++i){ - print_item_in_list(&out, unit.set.items[i].name, "_doc"); - } - append_sc(&out, "
    "); - -#undef SECTION -#define SECTION MAJOR_SECTION".3" - - append_sc(&out, "

    §"SECTION" Function Descriptions

    "); - for (int32_t i = 0; i < unit_custom.set.count; ++i){ - Item_Node *item = &unit_custom.set.items[i]; - String name = func_4ed_names.names[i].public_name; - - append_sc (&out, "

    §"SECTION"."); - append_int_to_str(&out, i+1); - append_sc (&out, ": "); - append_ss (&out, name); - append_sc (&out, "

    "); - - print_function_html(&out, &used_links, item->cpp_name, item->ret, "", name, item->breakdown); - append_sc(&out, "
    "); - - print_function_docs(&out, part, name, item->doc_string); - - append_sc(&out, "

    "); - } - -#undef SECTION -#define SECTION MAJOR_SECTION".4" - - append_sc(&out, "

    §"SECTION" Type Descriptions

    "); - - int32_t I = 1; - for (int32_t i = 0; i < unit.set.count; ++i, ++I){ - print_item(&out, part, &used_links, unit.set.items + i, "_doc", 0, SECTION, I); - } - -#undef MAJOR_SECTION -#define MAJOR_SECTION "4" - msection = 3; - - append_sc(&out, "\n

    §"MAJOR_SECTION" "); - append_sc(&out, sections[msection].display_string); - append_sc(&out, "

    "); - -#undef SECTION -#define SECTION MAJOR_SECTION".1" - - append_sc(&out, "

    §"SECTION" String Intro

    "); - - append_sc(&out, "
    Coming Soon
    "); - -#undef SECTION -#define SECTION MAJOR_SECTION".2" - - append_sc(&out, "

    §"SECTION" String Function List

    "); - - append_sc(&out, "
      "); - for (int32_t i = 0; i < string_unit.set.count; ++i){ - print_item_in_list(&out, string_unit.set.items[i].name, "_doc"); - } - append_sc(&out, "
    "); - -#undef SECTION -#define SECTION MAJOR_SECTION".3" - - append_sc(&out, "

    §"SECTION" String Function Descriptions

    "); - - for (int32_t i = 0; i < string_unit.set.count; ++i){ - print_item(&out, part, &used_links, string_unit.set.items+i, "_doc", "", SECTION, i+1); - } - -#undef MAJOR_SECTION -#define MAJOR_SECTION "5" - msection = 4; - - append_sc(&out, "\n

    §"MAJOR_SECTION" "); - append_sc(&out, sections[msection].display_string); - append_sc(&out, "

    "); - -#undef SECTION -#define SECTION MAJOR_SECTION".1" - - append_sc(&out, "

    §"SECTION" Lexer Intro

    "); - - append_sc(&out, - "
    " - "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." - "
    "); - -#undef SECTION -#define SECTION MAJOR_SECTION".2" - - append_sc(&out, "

    §"SECTION" Lexer Function List

    "); - - append_sc(&out, "
      "); - for (int32_t i = 0; i < lexer_funcs_unit.set.count; ++i){ - print_item_in_list(&out, lexer_funcs_unit.set.items[i].name, "_doc"); - } - append_sc(&out, "
    "); - -#undef SECTION -#define SECTION MAJOR_SECTION".3" - - append_sc(&out, "

    §"SECTION" Lexer Types List

    "); - - append_sc(&out, "
      "); - for (int32_t i = 0; i < lexer_types_unit.set.count; ++i){ - print_item_in_list(&out, lexer_types_unit.set.items[i].name, "_doc"); - } - append_sc(&out, "
    "); - -#undef SECTION -#define SECTION MAJOR_SECTION".4" - - append_sc(&out, "

    §"SECTION" Lexer Function Descriptions

    "); - for (int32_t i = 0; i < lexer_funcs_unit.set.count; ++i){ - print_item(&out, part, &used_links, lexer_funcs_unit.set.items+i, "_doc", "", SECTION, i+1); - } - -#undef SECTION -#define SECTION MAJOR_SECTION".5" - - append_sc(&out, "

    §"SECTION" Lexer Type Descriptions

    "); - for (int32_t i = 0; i < lexer_types_unit.set.count; ++i){ - print_item(&out, part, &used_links, lexer_types_unit.set.items+i, "_doc", "", SECTION, i+1); - } - - - append_sc(&out, "
    "); - end_file_out(context); - } - else{ - // TODO(allen): warning - } } int main(int argc, char **argv){ diff --git a/build.bat b/build.bat index fe951325..fc882613 100644 --- a/build.bat +++ b/build.bat @@ -3,7 +3,7 @@ call "ctime" -begin 4ed_data.ctm SET OPTS=/W4 /wd4310 /wd4100 /wd4201 /wd4505 /wd4996 /wd4127 /wd4510 /wd4512 /wd4610 /wd4390 /WX -SET OPTS=/GR- /EHa- /nologo /FC +SET OPTS=%OPTS% /GR- /EHa- /nologo /FC SET FirstError=0 diff --git a/internal_4coder_string.cpp b/internal_4coder_string.cpp index 24508240..3c35554e 100644 --- a/internal_4coder_string.cpp +++ b/internal_4coder_string.cpp @@ -1,7 +1,15 @@ #define FSTRING_DECLS #define FSTRING_BEGIN -#define DOC_EXPORT +#define API_EXPORT_MACRO + +#ifndef API_EXPORT +# define API_EXPORT +#endif + +#ifndef API_EXPORT_INLINE +# define API_EXPORT_INLINE +#endif #define CPP_NAME(n) @@ -61,73 +69,73 @@ static String null_string = {0}; // Character Helpers // -FSTRING_INLINE fstr_bool +API_EXPORT_INLINE FSTRING_INLINE fstr_bool char_is_slash(char c) /* DOC(This call returns non-zero if c is \ or /.) */{ return (c == '\\' || c == '/'); } -FSTRING_INLINE fstr_bool +API_EXPORT_INLINE FSTRING_INLINE fstr_bool char_is_upper(char c) /* DOC(If c is an uppercase letter this call returns true.) */{ return (c >= 'A' && c <= 'Z'); } -FSTRING_INLINE fstr_bool +API_EXPORT_INLINE FSTRING_INLINE fstr_bool char_is_lower(char c) /* DOC(If c is a lower letter this call returns true.) */{ return (c >= 'a' && c <= 'z'); } -FSTRING_INLINE char +API_EXPORT_INLINE FSTRING_INLINE char char_to_upper(char c) /* DOC(If c is a lowercase letter this call returns the uppercase equivalent, otherwise it returns c.) */{ return (c >= 'a' && c <= 'z') ? c + (char)('A' - 'a') : c; } -FSTRING_INLINE char +API_EXPORT_INLINE FSTRING_INLINE char char_to_lower(char c) /* DOC(If c is an uppercase letter this call returns the lowercase equivalent, otherwise it returns c.) */{ return (c >= 'A' && c <= 'Z') ? c - (char)('A' - 'a') : c; } -FSTRING_INLINE fstr_bool +API_EXPORT_INLINE FSTRING_INLINE fstr_bool char_is_whitespace(char c) /* DOC(This call returns non-zero if c is whitespace.) */{ return (c == ' ' || c == '\n' || c == '\r' || c == '\t'); } -FSTRING_INLINE fstr_bool +API_EXPORT_INLINE FSTRING_INLINE fstr_bool char_is_alpha_numeric(char c) /* DOC(This call returns non-zero if c is any alphanumeric character including underscore.) */{ return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '_'); } -FSTRING_INLINE fstr_bool +API_EXPORT_INLINE FSTRING_INLINE fstr_bool char_is_alpha_numeric_true(char c) /* DOC(This call returns non-zero if c is any alphanumeric character no including underscore.) */{ return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9'); } -FSTRING_INLINE fstr_bool +API_EXPORT_INLINE FSTRING_INLINE fstr_bool char_is_alpha(char c) /* DOC(This call returns non-zero if c is any alphabetic character including underscore.) */{ return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c == '_'); } -FSTRING_INLINE fstr_bool +API_EXPORT_INLINE FSTRING_INLINE fstr_bool char_is_alpha_true(char c) /* DOC(This call returns non-zero if c is any alphabetic character.) */{ return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'); } -FSTRING_INLINE fstr_bool +API_EXPORT_INLINE FSTRING_INLINE fstr_bool char_is_hex(char c) /* DOC(This call returns non-zero if c is any valid hexadecimal digit.) */{ return (c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f'); } -FSTRING_INLINE fstr_bool +API_EXPORT_INLINE FSTRING_INLINE fstr_bool char_is_numeric(char c) /* DOC(This call returns non-zero if c is any valid decimal digit.) */{ return (c >= '0' && c <= '9'); @@ -139,7 +147,7 @@ char_is_numeric(char c) // CPP_NAME(make_string) -FSTRING_INLINE String +API_EXPORT_INLINE FSTRING_INLINE String make_string_cap(void *str, int32_t size, int32_t mem_size)/* DOC_PARAM(str, The str parameter provides the of memory with which the string shall operate.) DOC_PARAM(size, The size parameter expresses the initial size of the string. @@ -154,7 +162,7 @@ DOC(This call returns the String created from the parameters.) return(result); } -FSTRING_INLINE String +API_EXPORT_INLINE FSTRING_INLINE String make_string(void *str, int32_t size)/* DOC_PARAM(str, The str parameter provides the of memory with which the string shall operate.) DOC_PARAM(size, The size parameter expresses the initial size of the string. @@ -170,19 +178,19 @@ DOC(This call returns the String created from the parameters.) return(result); } -DOC_EXPORT /* DOC(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.) */ +API_EXPORT_MACRO +/* DOC(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.) */ #define make_lit_string(s) (make_string_cap((char*)(s), sizeof(s)-1, sizeof(s))) -DOC_EXPORT /* DOC(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.) */ +API_EXPORT_MACRO +/* DOC(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.) */ #define make_fixed_width_string(s) (make_string_cap((char*)(s), 0, sizeof(s))) -DOC_EXPORT /* DOC(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.) */ +API_EXPORT_MACRO +/* DOC(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.) */ #define expand_str(s) ((s).str), ((s).size) -FSTRING_LINK int32_t +API_EXPORT FSTRING_LINK int32_t str_size(char *str) /* DOC(This call returns the number of bytes before a null terminator starting at str.) */{ int32_t i = 0; @@ -190,10 +198,9 @@ str_size(char *str) return(i); } -FSTRING_INLINE String +API_EXPORT_INLINE FSTRING_INLINE String make_string_slowly(void *str) -/* DOC(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.) */{ +/* DOC(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.) */{ String result; result.str = (char*)str; result.size = str_size((char*)str); @@ -202,7 +209,7 @@ treating that as the size and memory size of the string.) */{ } CPP_NAME(substr) -FSTRING_INLINE String +API_EXPORT_INLINE FSTRING_INLINE String substr_tail(String str, int32_t start) /* DOC(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. @@ -214,7 +221,7 @@ Usually strings created this way should only go through immutable calls.) */{ return(result); } -FSTRING_INLINE String +API_EXPORT_INLINE FSTRING_INLINE String substr(String str, int32_t start, int32_t size) /* DOC(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 @@ -229,7 +236,7 @@ will see changes. Usually strings created this way should only go through immuta return(result); } -FSTRING_LINK String +API_EXPORT FSTRING_LINK String skip_whitespace(String str) /* DOC(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 @@ -241,7 +248,7 @@ considered immutable.) DOC_SEE(substr) */{ return(result); } -FSTRING_LINK String +API_EXPORT FSTRING_LINK String chop_whitespace(String str) /* DOC(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 @@ -253,7 +260,7 @@ considered immutable.) DOC_SEE(substr) */{ return(result); } -FSTRING_LINK String +API_EXPORT FSTRING_LINK String skip_chop_whitespace(String str) /* DOC(This call is equivalent to calling skip_whitespace and chop_whitespace together.) DOC_SEE(skip_whitespace) DOC_SEE(chop_whitespace)*/{ @@ -262,7 +269,7 @@ DOC_SEE(skip_whitespace) DOC_SEE(chop_whitespace)*/{ return(str); } -FSTRING_INLINE String +API_EXPORT_INLINE FSTRING_INLINE String tailstr(String str) /* DOC(This call returns an empty String with underlying memory taken from the portion of str's memory that is not used.) */{ @@ -279,7 +286,7 @@ the portion of str's memory that is not used.) */{ // CPP_NAME(match) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool match_cc(char *a, char *b)/* DOC(This call returns non-zero if a and b are equivalent.) */{ for (int32_t i = 0;; ++i){ if (a[i] != b[i]){ @@ -292,7 +299,7 @@ match_cc(char *a, char *b)/* DOC(This call returns non-zero if a and b are equiv } CPP_NAME(match) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool match_sc(String a, char *b)/* DOC(This call returns non-zero if a and b are equivalent.) */{ int32_t i = 0; for (; i < a.size; ++i){ @@ -307,13 +314,13 @@ match_sc(String a, char *b)/* DOC(This call returns non-zero if a and b are equi } CPP_NAME(match) -FSTRING_INLINE fstr_bool +API_EXPORT_INLINE FSTRING_INLINE fstr_bool match_cs(char *a, String b)/* DOC(This call returns non-zero if a and b are equivalent.) */{ return(match_sc(b,a)); } CPP_NAME(match) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool match_ss(String a, String b)/* DOC(This call returns non-zero if a and b are equivalent.) */{ if (a.size != b.size){ return 0; @@ -327,7 +334,7 @@ match_ss(String a, String b)/* DOC(This call returns non-zero if a and b are equ } CPP_NAME(match_part) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool match_part_ccl(char *a, char *b, int32_t *len)/* DOC_PARAM(len, If this call returns non-zero this parameter is used to output the length of b.) DOC(This call is similar to a match call, except that it is permitted for a to be longer than b. @@ -343,7 +350,7 @@ In other words this call returns non-zero if b is a prefix of a.) */{ } CPP_NAME(match_part) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool match_part_scl(String a, char *b, int32_t *len)/* DOC_PARAM(len, If this call returns non-zero this parameter is used to output the length of b.) DOC(This call is similar to a match call, except that it is permitted for a to be longer than b. @@ -359,7 +366,7 @@ In other words this call returns non-zero if b is a prefix of a.) */{ } CPP_NAME(match_part) -FSTRING_INLINE fstr_bool +API_EXPORT_INLINE FSTRING_INLINE fstr_bool match_part_cc(char *a, char *b)/* DOC_PARAM(len, If this call returns non-zero this parameter is used to output the length of b.) DOC(This call is similar to a match call, except that it is permitted for a to be longer than b. @@ -369,7 +376,7 @@ In other words this call returns non-zero if b is a prefix of a.) */{ } CPP_NAME(match_part) -FSTRING_INLINE fstr_bool +API_EXPORT_INLINE FSTRING_INLINE fstr_bool match_part_sc(String a, char *b)/* DOC(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.) */{ @@ -378,7 +385,7 @@ In other words this call returns non-zero if b is a prefix of a.) */{ } CPP_NAME(match_part) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool match_part_cs(char *a, String b)/* DOC(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.) */{ @@ -391,7 +398,7 @@ In other words this call returns non-zero if b is a prefix of a.) */{ } CPP_NAME(match_part) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool match_part_ss(String a, String b)/* DOC(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.) */{ @@ -407,7 +414,7 @@ In other words this call returns non-zero if b is a prefix of a.) */{ } CPP_NAME(match_insensitive) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool match_insensitive_cc(char *a, char *b)/* DOC(This call returns non-zero if a and b are equivalent under case insensitive comparison.) */{ for (int32_t i = 0;; ++i){ @@ -422,7 +429,7 @@ DOC(This call returns non-zero if a and b are equivalent under case insensitive } CPP_NAME(match_insensitive) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool match_insensitive_sc(String a, char *b)/* DOC(This call returns non-zero if a and b are equivalent under case insensitive comparison.) */{ int32_t i = 0; @@ -439,14 +446,14 @@ DOC(This call returns non-zero if a and b are equivalent under case insensitive } CPP_NAME(match_insensitive) -FSTRING_INLINE fstr_bool +API_EXPORT_INLINE FSTRING_INLINE fstr_bool match_insensitive_cs(char *a, String b)/* DOC(This call returns non-zero if a and b are equivalent under case insensitive comparison.) */{ return match_insensitive_sc(b,a); } CPP_NAME(match_insensitive) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool match_insensitive_ss(String a, String b)/* DOC(This call returns non-zero if a and b are equivalent under case insensitive comparison.) */{ if (a.size != b.size){ @@ -462,7 +469,7 @@ DOC(This call returns non-zero if a and b are equivalent under case insensitive } CPP_NAME(match_part_insensitive) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool match_part_insensitive_ccl(char *a, char *b, int32_t *len)/* DOC_PARAM(len, If this call returns non-zero this parameter is used to output the length of b.) DOC(This call performs the same partial matching rule as match_part under case insensitive comparison.) @@ -478,7 +485,7 @@ DOC_SEE(match_part) */{ } CPP_NAME(match_part_insensitive) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool match_part_insensitive_scl(String a, char *b, int32_t *len)/* DOC_PARAM(len, If this call returns non-zero this parameter is used to output the length of b.) DOC(This call performs the same partial matching rule as match_part under case insensitive comparison.) @@ -495,7 +502,7 @@ DOC_SEE(match_part) */{ } CPP_NAME(match_part_insensitive) -FSTRING_INLINE fstr_bool +API_EXPORT_INLINE FSTRING_INLINE fstr_bool match_part_insensitive_cc(char *a, char *b)/* DOC(This call performs the same partial matching rule as match_part under case insensitive comparison.) DOC_SEE(match_part) */{ @@ -504,7 +511,7 @@ DOC_SEE(match_part) */{ } CPP_NAME(match_part_insensitive) -FSTRING_INLINE fstr_bool +API_EXPORT_INLINE FSTRING_INLINE fstr_bool match_part_insensitive_sc(String a, char *b)/* DOC(This call performs the same partial matching rule as match_part under case insensitive comparison.) DOC_SEE(match_part) */{ @@ -513,7 +520,7 @@ DOC_SEE(match_part) */{ } CPP_NAME(match_part_insensitive) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool match_part_insensitive_cs(char *a, String b)/* DOC(This call performs the same partial matching rule as match_part under case insensitive comparison.) DOC_SEE(match_part) */{ @@ -526,7 +533,7 @@ DOC_SEE(match_part) */{ } CPP_NAME(match_part_insensitive) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool match_part_insensitive_ss(String a, String b)/* DOC(This call performs the same partial matching rule as match_part under case insensitive comparison.) DOC_SEE(match_part) */{ @@ -542,7 +549,7 @@ DOC_SEE(match_part) */{ } CPP_NAME(compare) -FSTRING_LINK int32_t +API_EXPORT FSTRING_LINK int32_t compare_cc(char *a, char *b)/* DOC(This call returns zero if a and b are equivalent, it returns negative if a sorts before b alphabetically, @@ -556,7 +563,7 @@ and positive if a sorts after b alphabetically.) */{ } CPP_NAME(compare) -FSTRING_LINK int32_t +API_EXPORT FSTRING_LINK int32_t compare_sc(String a, char *b)/* DOC(This call returns zero if a and b are equivalent, it returns negative if a sorts before b alphabetically, @@ -580,7 +587,7 @@ and positive if a sorts after b alphabetically.) */{ } CPP_NAME(compare) -FSTRING_INLINE int32_t +API_EXPORT_INLINE FSTRING_INLINE int32_t compare_cs(char *a, String b)/* DOC(This call returns zero if a and b are equivalent, it returns negative if a sorts before b alphabetically, @@ -590,7 +597,7 @@ and positive if a sorts after b alphabetically.) */{ } CPP_NAME(compare) -FSTRING_LINK int32_t +API_EXPORT FSTRING_LINK int32_t compare_ss(String a, String b)/* DOC(This call returns zero if a and b are equivalent, it returns negative if a sorts before b alphabetically, @@ -619,7 +626,7 @@ and positive if a sorts after b alphabetically.) */{ // CPP_NAME(find) -FSTRING_LINK int32_t +API_EXPORT FSTRING_LINK int32_t find_c_char(char *str, int32_t start, char character)/* DOC_PARAM(str, The str parameter provides a null terminated string to search.) DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) @@ -632,7 +639,7 @@ if the character is not found.) */{ } CPP_NAME(find) -FSTRING_LINK int32_t +API_EXPORT FSTRING_LINK int32_t find_s_char(String str, int32_t start, char character)/* DOC_PARAM(str, The str parameter provides a string to search.) DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) @@ -645,7 +652,7 @@ if the character is not found.) */{ } CPP_NAME(rfind) -FSTRING_LINK int32_t +API_EXPORT FSTRING_LINK int32_t rfind_s_char(String str, int32_t start, char character)/* DOC_PARAM(str, The str parameter provides a string to search.) DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) @@ -658,7 +665,7 @@ the given character occurs. If the index is found it is returned otherwise -1 i } CPP_NAME(find) -FSTRING_LINK int32_t +API_EXPORT FSTRING_LINK int32_t find_c_chars(char *str, int32_t start, char *characters)/* DOC_PARAM(str, The str parameter provides a null terminated string to search.) DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) @@ -678,7 +685,7 @@ or the size of the string if no such character is not found.) */{ } CPP_NAME(find) -FSTRING_LINK int32_t +API_EXPORT FSTRING_LINK int32_t find_s_chars(String str, int32_t start, char *characters)/* DOC_PARAM(str, The str parameter provides a string to search.) DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) @@ -698,7 +705,7 @@ or the size of the string if no such character is not found.) */{ } CPP_NAME(find_substr) -FSTRING_LINK int32_t +API_EXPORT FSTRING_LINK int32_t find_substr_c(char *str, int32_t start, String seek)/* DOC_PARAM(str, The str parameter provides a null terminated string to search.) DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) @@ -730,7 +737,7 @@ size of str if no such substring in str is found.) */{ } CPP_NAME(find_substr) -FSTRING_LINK int32_t +API_EXPORT FSTRING_LINK int32_t find_substr_s(String str, int32_t start, String seek)/* DOC_PARAM(str, The str parameter provides a string to search.) DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) @@ -762,7 +769,7 @@ size of str if no such substring in str is found.) */{ } CPP_NAME(rfind_substr) -FSTRING_LINK int32_t +API_EXPORT FSTRING_LINK int32_t rfind_substr_s(String str, int32_t start, String seek)/* DOC_PARAM(str, The str parameter provides a string to search.) DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) @@ -796,7 +803,7 @@ or -1 if no such substring in str is found.) */{ } CPP_NAME(find_substr_insensitive) -FSTRING_LINK int32_t +API_EXPORT FSTRING_LINK int32_t find_substr_insensitive_c(char *str, int32_t start, String seek)/* DOC_PARAM(str, The str parameter provides a null terminated string to search.) DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) @@ -830,7 +837,7 @@ DOC_SEE(find_substr)*/{ } CPP_NAME(find_substr_insensitive) -FSTRING_LINK int32_t +API_EXPORT FSTRING_LINK int32_t find_substr_insensitive_s(String str, int32_t start, String seek)/* DOC_PARAM(str, The str parameter provides a string to search.) DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) @@ -866,21 +873,21 @@ DOC_SEE(find_substr)*/{ } CPP_NAME(has_substr) -FSTRING_INLINE fstr_bool +API_EXPORT_INLINE FSTRING_INLINE fstr_bool has_substr_c(char *s, String seek)/* DOC(This call returns non-zero if the string s contains a substring equivalent to seek.) */{ return (s[find_substr_c(s, 0, seek)] != 0); } CPP_NAME(has_substr) -FSTRING_INLINE fstr_bool +API_EXPORT_INLINE FSTRING_INLINE fstr_bool has_substr_s(String s, String seek)/* DOC(This call returns non-zero if the string s contains a substring equivalent to seek.) */{ return (find_substr_s(s, 0, seek) < s.size); } CPP_NAME(has_substr_insensitive) -FSTRING_INLINE fstr_bool +API_EXPORT_INLINE FSTRING_INLINE fstr_bool has_substr_insensitive_c(char *s, String seek)/* DOC(This call returns non-zero if the string s contains a substring equivalent to seek under case insensitive comparison.) */{ @@ -888,7 +895,7 @@ under case insensitive comparison.) */{ } CPP_NAME(has_substr_insensitive) -FSTRING_INLINE fstr_bool +API_EXPORT_INLINE FSTRING_INLINE fstr_bool has_substr_insensitive_s(String s, String seek)/* DOC(This call returns non-zero if the string s contains a substring equivalent to seek under case insensitive comparison.) */{ @@ -900,7 +907,7 @@ under case insensitive comparison.) */{ // CPP_NAME(copy_fast_unsafe) -FSTRING_LINK int32_t +API_EXPORT FSTRING_LINK int32_t copy_fast_unsafe_cc(char *dest, char *src)/* DOC(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 @@ -917,7 +924,7 @@ of bytes coppied to dest.) */{ } CPP_NAME(copy_fast_unsafe) -FSTRING_LINK int32_t +API_EXPORT FSTRING_LINK int32_t copy_fast_unsafe_cs(char *dest, String src)/* DOC(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 @@ -933,7 +940,7 @@ of bytes coppied to dest.) */{ } CPP_NAME(copy_checked) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool copy_checked_ss(String *dest, String src)/* DOC(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. @@ -952,7 +959,7 @@ This call returns non-zero on a successful copy.) */{ } CPP_NAME(copy_partial) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool copy_partial_sc(String *dest, char *src)/* DOC(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, @@ -973,7 +980,7 @@ if the entire string is coppied to dest.) */{ } CPP_NAME(copy_partial) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool copy_partial_ss(String *dest, String src)/* DOC(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, @@ -994,7 +1001,7 @@ if the entire string is coppied to dest.) */{ } CPP_NAME(copy) -FSTRING_INLINE int32_t +API_EXPORT_INLINE FSTRING_INLINE int32_t copy_cc(char *dest, char *src)/* DOC(This call performs a copy from src to dest equivalent to copy_fast_unsafe.) DOC_SEE(copy_fast_unsafe) */{ @@ -1002,7 +1009,7 @@ DOC_SEE(copy_fast_unsafe) */{ } CPP_NAME(copy) -FSTRING_INLINE void +API_EXPORT_INLINE FSTRING_INLINE void copy_ss(String *dest, String src)/* DOC(This call performs a copy from src to dest equivalent to copy_checked.) DOC_SEE(copy_checked) */{ @@ -1010,7 +1017,7 @@ DOC_SEE(copy_checked) */{ } CPP_NAME(copy) -FSTRING_INLINE void +API_EXPORT_INLINE FSTRING_INLINE void copy_sc(String *dest, char *src)/* DOC(This call performs a copy from src to dest equivalent to copy_partial.) DOC_SEE(copy_partial) */{ @@ -1018,7 +1025,7 @@ DOC_SEE(copy_partial) */{ } CPP_NAME(append_checked) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool append_checked_ss(String *dest, String src)/* DOC(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.) */{ @@ -1032,7 +1039,7 @@ to append src onto dest. If there is src is appended and the call returns non-ze } CPP_NAME(append_partial) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool append_partial_sc(String *dest, char *src)/* DOC(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.) */{ @@ -1043,7 +1050,7 @@ as possible. If the entire string is appended the call returns non-zero.) */{ } CPP_NAME(append_partial) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool append_partial_ss(String *dest, String src)/* DOC(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.) */{ @@ -1054,7 +1061,7 @@ as possible. If the entire string is appended the call returns non-zero.) */{ } CPP_NAME(append) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool append_s_char(String *dest, char c)/* DOC(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.) */{ @@ -1067,20 +1074,20 @@ memory the character is appended and the call returns non-zero.) */{ } CPP_NAME(append) -FSTRING_INLINE fstr_bool +API_EXPORT_INLINE FSTRING_INLINE fstr_bool append_ss(String *dest, String src)/* DOC(This call is equivalent to append_partial.) DOC_SEE(append_partial) */{ return append_partial_ss(dest, src); } CPP_NAME(append) -FSTRING_INLINE fstr_bool +API_EXPORT_INLINE FSTRING_INLINE fstr_bool append_sc(String *dest, char *src)/* DOC(This call is equivalent to append_partial.) DOC_SEE(append_partial) */{ return append_partial_sc(dest, src); } -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool terminate_with_null(String *str)/* DOC(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 @@ -1094,7 +1101,7 @@ byte in the strings underlying memory.) */{ return(result); } -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool append_padding(String *dest, char c, int32_t target_size)/* DOC(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 @@ -1118,7 +1125,7 @@ non-zero if dest does not run out of space in the underlying memory.) */{ // Other Edits // -FSTRING_LINK void +API_EXPORT FSTRING_LINK void replace_char(String *str, char replace, char with)/* DOC_PARAM(str, The str parameter provides the string in which replacement shall be performed.) DOC_PARAM(replace, The replace character specifies which character should be replaced.) @@ -1132,7 +1139,7 @@ DOC(This call replaces all occurances of character in str with another character } CPP_NAME(to_lower) -FSTRING_LINK void +API_EXPORT FSTRING_LINK void to_lower_cc(char *src, char *dst)/* DOC_PARAM(src, The source string to conver to lowercase. This string must be null terminated.) DOC_PARAM(dst, The destination buffer to receive the converted string. This must be large @@ -1148,7 +1155,7 @@ string in place.) } CPP_NAME(to_lower) -FSTRING_LINK void +API_EXPORT FSTRING_LINK void to_lower_ss(String *dst, String src)/* DOC_PARAM(dst, The destination buffer to receive the converted string. This must have a capacity of at least the size of src.) @@ -1170,7 +1177,7 @@ that src and dst may be exactly equal in order to convert the string in place.) } CPP_NAME(to_lower) -FSTRING_LINK void +API_EXPORT FSTRING_LINK void to_lower_s(String *str)/* DOC_PARAM(str, The string to be converted to all lowercase.) DOC(This version of to_lower converts str to lowercase in place.) @@ -1184,7 +1191,7 @@ DOC(This version of to_lower converts str to lowercase in place.) } CPP_NAME(to_upper) -FSTRING_LINK void +API_EXPORT FSTRING_LINK void to_upper_cc(char *src, char *dst)/* DOC_PARAM(src, The source string to convert to uppercase. This string must be null terminated.) DOC_PARAM(dst, The destination buffer to receive the converted string. @@ -1199,7 +1206,7 @@ that src and dst may be exactly equal in order to convert the string in place.) } CPP_NAME(to_upper) -FSTRING_LINK void +API_EXPORT FSTRING_LINK void to_upper_ss(String *dst, String src)/* DOC_PARAM(dst, The destination buffer to receive the converted string. This must have a capacity of at least the size of src.) @@ -1221,7 +1228,7 @@ that src and dst may be exactly equal in order to convert the string in place.) } CPP_NAME(to_upper) -FSTRING_LINK void +API_EXPORT FSTRING_LINK void to_upper_s(String *str)/* DOC_PARAM(str, The string to be converted to all uppercase.) DOC(This version of to_upper converts str to uppercase in place.) @@ -1235,7 +1242,7 @@ DOC(This version of to_upper converts str to uppercase in place.) } CPP_NAME(to_camel) -FSTRING_LINK void +API_EXPORT FSTRING_LINK void to_camel_cc(char *src, char *dst)/* DOC_PARAM(src, The source string to convert to camel case.) DOC_PARAM(dst, The destination buffer to receive the converted string. @@ -1270,7 +1277,7 @@ convert the string in place.) // String <-> Number Conversions // -FSTRING_LINK int32_t +API_EXPORT FSTRING_LINK int32_t int_to_str_size(int32_t x)/* DOC(This call returns the number of bytes required to represent x as a string.) */{ int32_t size = 1; @@ -1285,7 +1292,7 @@ DOC(This call returns the number of bytes required to represent x as a string.) return(size); } -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool int_to_str(String *dest, int32_t x)/* DOC(This call writes a string representation of x into dest. If there is enough space in dest this call returns non-zero.) */{ @@ -1333,7 +1340,7 @@ space in dest this call returns non-zero.) */{ return(result); } -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool append_int_to_str(String *dest, int32_t x)/* DOC(This call appends a string representation of x onto dest. If there is enough space in dest this call returns non-zero.) */{ @@ -1345,7 +1352,7 @@ space in dest this call returns non-zero.) */{ return(result); } -FSTRING_LINK int32_t +API_EXPORT FSTRING_LINK int32_t u64_to_str_size(uint64_t x)/* DOC(This call returns the number of bytes required to represent x as a string.) */{ int32_t size; @@ -1363,7 +1370,7 @@ DOC(This call returns the number of bytes required to represent x as a string.) return(size); } -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool u64_to_str(String *dest, uint64_t x)/* DOC(This call writes a string representation of x into dest. If there is enough space in dest this call returns non-zero.) */{ @@ -1402,7 +1409,7 @@ space in dest this call returns non-zero.) */{ return(result); } -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool append_u64_to_str(String *dest, uint64_t x)/* DOC(This call appends a string representation of x onto dest. If there is enough space in dest this call returns non-zero.) */{ @@ -1437,7 +1444,7 @@ get_float_vars(float x){ } #endif -FSTRING_LINK int32_t +API_EXPORT FSTRING_LINK int32_t float_to_str_size(float x)/* DOC(This call returns the number of bytes required to represent x as a string.) */{ Float_To_Str_Variables vars = get_float_vars(x); @@ -1446,7 +1453,7 @@ DOC(This call returns the number of bytes required to represent x as a string.) return(size); } -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool append_float_to_str(String *dest, float x)/* DOC(This call writes a string representation of x into dest. If there is enough space in dest this call returns non-zero.) */{ @@ -1464,7 +1471,7 @@ space in dest this call returns non-zero.) */{ return(result); } -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool float_to_str(String *dest, float x)/* DOC(This call appends a string representation of x onto dest. If there is enough space in dest this call returns non-zero.) */{ @@ -1475,7 +1482,7 @@ space in dest this call returns non-zero.) */{ } CPP_NAME(str_is_int) -FSTRING_LINK int32_t +API_EXPORT FSTRING_LINK int32_t str_is_int_c(char *str)/* DOC(If str is a valid string representation of an integer, this call returns non-zero) */{ fstr_bool result = 1; @@ -1489,7 +1496,7 @@ DOC(If str is a valid string representation of an integer, this call returns non } CPP_NAME(str_is_int) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool str_is_int_s(String str)/* DOC(If str is a valid string representation of an integer, this call returns non-zero.) */{ fstr_bool result = 1; @@ -1503,7 +1510,7 @@ DOC(If str is a valid string representation of an integer, this call returns non } CPP_NAME(str_to_int) -FSTRING_LINK int32_t +API_EXPORT FSTRING_LINK int32_t str_to_int_c(char *str)/* DOC(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.) */{ @@ -1522,7 +1529,7 @@ the integer represented by the string. Otherwise this call returns zero.) */{ } CPP_NAME(str_to_int) -FSTRING_LINK int32_t +API_EXPORT FSTRING_LINK int32_t str_to_int_s(String str)/* DOC(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.) */{ @@ -1540,7 +1547,7 @@ the integer represented by the string. Otherwise this call returns zero.) */{ return(x); } -FSTRING_LINK int32_t +API_EXPORT FSTRING_LINK int32_t hexchar_to_int(char c)/* DOC(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.) */{ @@ -1557,14 +1564,14 @@ the integer value of the digit. Otherwise the return is some nonsense value.) */ return(x); } -FSTRING_LINK char +API_EXPORT FSTRING_LINK char int_to_hexchar(int32_t x)/* DOC(If x is in the range [0,15] this call returns the equivalent lowercase hexadecimal digit. Otherwise the return is some nonsense value.) */{ return (x<10)?((char)x+'0'):((char)x+'a'-10); } -FSTRING_LINK uint32_t +API_EXPORT FSTRING_LINK uint32_t hexstr_to_int(String str)/* DOC(This call interprets str has a hexadecimal representation of an integer and returns the represented integer value.) */{ @@ -1583,7 +1590,7 @@ the represented integer value.) */{ return(x); } -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool color_to_hexstr(String *s, uint32_t color)/* DOC(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.) */{ @@ -1612,7 +1619,7 @@ If there is enough memory in s to represent the color this call returns non-zero return(result); } -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool hexstr_to_color(String s, uint32_t *out)/* DOC(This call interprets s as a color and writes the 32-bit integer representation into out.) */{ fstr_bool result = 0; @@ -1636,7 +1643,7 @@ DOC(This call interprets s as a color and writes the 32-bit integer representati // CPP_NAME(reverse_seek_slash) -FSTRING_LINK int32_t +API_EXPORT FSTRING_LINK int32_t reverse_seek_slash_pos(String str, int32_t pos)/* DOC(This call searches for a slash in str by starting pos bytes from the end and going backwards.) */{ int32_t i = str.size - 1 - pos; @@ -1646,20 +1653,20 @@ DOC(This call searches for a slash in str by starting pos bytes from the end and return i; } -FSTRING_INLINE int32_t +API_EXPORT_INLINE FSTRING_INLINE int32_t reverse_seek_slash(String str)/* DOC(This call searches for a slash in str by starting at the end and going backwards.) */{ return(reverse_seek_slash_pos(str, 0)); } -FSTRING_INLINE String +API_EXPORT_INLINE FSTRING_INLINE String front_of_directory(String dir)/* DOC(This call returns a substring of dir containing only the file name or folder name furthest to the right in the directory.) DOC_SEE(substr) */{ return substr_tail(dir, reverse_seek_slash(dir) + 1); } -FSTRING_INLINE String +API_EXPORT_INLINE FSTRING_INLINE String path_of_directory(String dir)/* DOC(This call returns a substring of dir containing the whole path except for the final file or folder name.) DOC_SEE(substr) */{ @@ -1667,7 +1674,7 @@ for the final file or folder name.) DOC_SEE(substr) */{ } CPP_NAME(set_last_folder) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool set_last_folder_sc(String *dir, char *folder_name, char slash)/* DOC_PARAM(dir, The dir parameter is the directory string in which to set the last folder in the directory.) DOC_PARAM(folder_name, The folder_name parameter is a null terminated string specifying the name to set @@ -1690,7 +1697,7 @@ If there is enough memory in dir this call returns non-zero.) */{ } CPP_NAME(set_last_folder) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool set_last_folder_ss(String *dir, String folder_name, char slash)/* DOC_PARAM(dir, The dir parameter is the directory string in which to set the last folder in the directory.) DOC_PARAM(folder_name, The folder_name parameter is a string specifying the name to set at the end of the directory.) @@ -1711,7 +1718,7 @@ If there is enough memory in dir this call returns non-zero.) */{ return(result); } -FSTRING_LINK String +API_EXPORT FSTRING_LINK String file_extension(String str)/* DOC(This call returns a substring containing only the file extension of the provided filename.) DOC_SEE(substr) */{ @@ -1723,7 +1730,7 @@ DOC_SEE(substr) */{ return(make_string(str.str+i, str.size-i)); } -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool remove_extension(String *str)/* DOC(This call attemps to delete a file extension off the end of a filename. This call returns non-zero on success.) */{ @@ -1739,7 +1746,7 @@ This call returns non-zero on success.) */{ return(result); } -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool remove_last_folder(String *str)/* DOC(This call attemps to delete a folder or filename off the end of a path string. This call returns non-zero on success.) */{ @@ -1754,7 +1761,7 @@ This call returns non-zero on success.) */{ // TODO(allen): Add hash-table extension to string sets. CPP_NAME(string_set_match) -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool string_set_match_table(void *str_set, int32_t item_size, int32_t count, String str, int32_t *match_index)/* DOC_PARAM(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.) @@ -1779,7 +1786,7 @@ DOC_SEE(match) */{ return(result); } -FSTRING_LINK fstr_bool +API_EXPORT FSTRING_LINK fstr_bool string_set_match(String *str_set, int32_t count, String str, int32_t *match_index)/* DOC_PARAM(str_set, The str_set parameter is an array of String structs specifying matchable strings.) DOC_PARAM(count, The count parameter specifies the number of String structs in the str_set array.) diff --git a/meta_parser.cpp b/meta_parser.cpp new file mode 100644 index 00000000..8a1934bf --- /dev/null +++ b/meta_parser.cpp @@ -0,0 +1,1368 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 01.11.2016 + * + * meta-compilation core system + * + */ + +// TOP + +#if !defined(META_PARSER_CPP_4CODER) +#define META_PARSER_CPP_4CODER + +#if !defined(FSTRING_GUARD) +#include "internal_4coder_string.cpp" +#endif + +#include "4cpp_lexer.h" + +#include +#include +#include +#include + +#include "4coder_mem.h" + +typedef struct Parse_Context{ + Cpp_Token *token_s; + Cpp_Token *token_e; + Cpp_Token *token; + char *data; +} Parse_Context; + +typedef struct Argument{ + String param_string; + String param_name; +} Argument; + +typedef struct Argument_Breakdown{ + int32_t count; + Argument *args; +} Argument_Breakdown; + +typedef struct Documentation{ + int32_t param_count; + String *param_name; + String *param_docs; + String return_doc; + String main_doc; + int32_t see_also_count; + String *see_also; +} Documentation; + +typedef enum Item_Type{ + Item_Null, + Item_Function, + Item_CppName, + Item_Macro, + Item_Typedef, + Item_Struct, + Item_Union, + Item_Enum, + Item_Type_Count, +#define Item_Type_User0 Item_Type_Count +} Item_Type; + +typedef struct Item_Node{ + int32_t t; + + String cpp_name; + String name; + String ret; + String args; + String body; + String marker; + + String value; + String type; + String type_postfix; + String doc_string; + + Argument_Breakdown breakdown; + Documentation doc; + + Item_Node *first_child; + Item_Node *next_sibling; +} Item_Node; + +typedef struct Item_Set{ + Item_Node *items; + int32_t count; +} Item_Set; + +typedef struct Parse{ + String code; + Cpp_Token_Array tokens; + int32_t item_count; +} Parse; + +typedef struct Meta_Unit{ + Item_Set set; + + Parse *parse; + int32_t count; +} Meta_Unit; + +typedef struct Meta_Keywords{ + String key; + Item_Type type; +} Meta_Keywords; + +typedef struct Used_Links{ + String *strs; + int32_t count, max; +} Used_Links; + +static Item_Node null_item_node = {0}; + +static String +str_start_end(char *data, int32_t start, int32_t end){ + return(make_string(data + start, end - start)); +} + +static String +get_lexeme(Cpp_Token token, char *code){ + String str = make_string(code + token.start, token.size); + return(str); +} + +static Parse_Context +setup_parse_context(char *data, Cpp_Token_Array array){ + Parse_Context context; + context.token_s = array.tokens; + context.token_e = array.tokens + array.count; + context.token = context.token_s; + context.data = data; + return(context); +} + +static Parse_Context +setup_parse_context(Parse parse){ + Parse_Context context; + context.token_s = parse.tokens.tokens; + context.token_e = parse.tokens.tokens + parse.tokens.count; + context.token = context.token_s; + context.data = parse.code.str; + return(context); +} + +static Cpp_Token* +get_token(Parse_Context *context){ + Cpp_Token *result = context->token; + if (result >= context->token_e){ + result = 0; + } + return(result); +} + +static Cpp_Token* +get_next_token(Parse_Context *context){ + Cpp_Token *result = context->token+1; + context->token = result; + if (result >= context->token_e){ + result = 0; + context->token = context->token_e; + } + return(result); +} + +static Cpp_Token* +get_prev_token(Parse_Context *context){ + Cpp_Token *result = context->token-1; + if (result < context->token_s){ + result = 0; + } + else{ + context->token = result; + } + return(result); +} + +static Cpp_Token* +can_back_step(Parse_Context *context){ + Cpp_Token *result = context->token-1; + if (result < context->token_s){ + result = 0; + } + return(result); +} + +static Cpp_Token* +set_token(Parse_Context *context, Cpp_Token *token){ + Cpp_Token *result = 0; + if (token >= context->token_s && token < context->token_e){ + context->token = token; + result = token; + } + return(result); +} + +static String +str_alloc(Partition *part, int32_t cap){ + return(make_string_cap(push_array(part, char, cap), 0, cap)); +} + +static Item_Set +allocate_item_set(Partition *part, int32_t count){ + Item_Set item_set = {0}; + if (count > 0){ + item_set.items = push_array(part, Item_Node, count); + item_set.count = count; + memset(item_set.items, 0, sizeof(Item_Node)*count); + } + return(item_set); +} + +static String +file_dump(char *filename){ + String result = {0}; + FILE *file = fopen(filename, "rb"); + + if (file){ + fseek(file, 0, SEEK_END); + result.size = ftell(file); + fseek(file, 0, SEEK_SET); + + result.memory_size = result.size + 1; + result.str = (char*)malloc(result.memory_size); + + fread(result.str, 1, result.size, file); + result.str[result.size] = 0; + + fclose(file); + } + + return(result); +} + +static Parse +meta_lex(char *filename){ + Parse result = {0}; + result.code = file_dump(filename); + result.tokens = cpp_make_token_array(1024); + cpp_lex_file(result.code.str, result.code.size, &result.tokens); + return(result); +} + +static String +get_first_line(String source){ + String line = {0}; + int32_t pos = find_s_char(source, 0, '\n'); + line = substr(source, 0, pos); + return(line); +} + +static String +get_next_line(String source, String line){ + String next = {0}; + int32_t pos = (int32_t)(line.str - source.str) + line.size; + int32_t start = 0; + + if (pos < source.size){ + assert(source.str[pos] == '\n'); + start = pos + 1; + + if (start < source.size){ + pos = find_s_char(source, start, '\n'); + next = substr(source, start, pos - start); + } + } + + return(next); +} + +static int32_t +is_comment(String str){ + int32_t result = 0; + if (str.size >= 2){ + if (str.str[0] == '/' && + str.str[1] == '/'){ + result = 1; + } + } + return(result); +} + +typedef enum Doc_Note_Type{ + DOC_PARAM, + DOC_RETURN, + DOC, + DOC_SEE, + DOC_HIDE, + HIDE_MEMBERS, +} Doc_Note_Type; + +static String +doc_note_string[] = { + make_lit_string("DOC_PARAM"), + make_lit_string("DOC_RETURN"), + make_lit_string("DOC"), + make_lit_string("DOC_SEE"), + make_lit_string("DOC_HIDE"), + make_lit_string("HIDE_MEMBERS"), +}; + +static int32_t +check_and_fix_docs(String *doc_string){ + int32_t result = false; + + if (doc_string->size > 4){ + if (doc_string->str[0] == '/'){ + if (doc_string->str[1] == '*'){ + if (doc_string->str[doc_string->size - 2] == '*'){ + if (doc_string->str[doc_string->size - 1] == '/'){ + result = true; + doc_string->str += 2; + doc_string->size -= 4; + } + } + } + } + } + + return(result); +} + +static int32_t +get_doc_string_from_prev(Parse_Context *context, String *doc_string){ + int32_t result = false; + + if (can_back_step(context)){ + Cpp_Token *prev_token = get_token(context) - 1; + if (prev_token->type == CPP_TOKEN_COMMENT){ + *doc_string = get_lexeme(*prev_token, context->data); + if (check_and_fix_docs(doc_string)){ + result = true; + } + else{ + *doc_string = null_string; + } + } + } + + return(result); +} + +static String +doc_parse_note(String source, int32_t *pos){ + String result = {0}; + + int32_t p = *pos; + int32_t start = p; + for (; p < source.size; ++p){ + if (source.str[p] == '('){ + break; + } + } + if (p != source.size){ + result = make_string(source.str + start, p - start); + result = skip_chop_whitespace(result); + } + *pos = p; + + return(result); +} + +static String +doc_parse_note_string(String source, int32_t *pos){ + String result = {0}; + + assert(source.str[*pos] == '('); + + int32_t p = *pos + 1; + int32_t start = p; + + int32_t nest_level = 0; + + for (; p < source.size; ++p){ + if (source.str[p] == ')'){ + if (nest_level == 0){ + break; + } + else{ + --nest_level; + } + } + else if (source.str[p] == '('){ + ++nest_level; + } + } + if (p != source.size){ + result = make_string(source.str + start, p - start); + result = skip_chop_whitespace(result); + ++p; + } + *pos = p; + + return(result); +} + +static String +doc_parse_parameter(String source, int32_t *pos){ + String result = {0}; + + int32_t p = *pos; + int32_t start = p; + + for (; p < source.size; ++p){ + if (source.str[p] == ','){ + break; + } + } + if (p != source.size){ + result = make_string(source.str + start, p - start); + result = skip_chop_whitespace(result); + ++p; + } + *pos = p; + + return(result); +} + +static String +doc_parse_last_parameter(String source, int32_t *pos){ + String result = {0}; + + int32_t p = *pos; + int32_t start = p; + + for (; p < source.size; ++p){ + if (source.str[p] == ')'){ + break; + } + } + if (p == source.size){ + result = make_string(source.str + start, p - start); + result = skip_chop_whitespace(result); + } + *pos = p; + + return(result); +} + +static void +perform_doc_parse(Partition *part, String doc_string, Documentation *doc){ + int32_t keep_parsing = true; + int32_t pos = 0; + + int32_t param_count = 0; + int32_t see_count = 0; + + do{ + String doc_note = doc_parse_note(doc_string, &pos); + if (doc_note.size == 0){ + keep_parsing = false; + } + else{ + int32_t doc_note_type; + if (string_set_match(doc_note_string, ArrayCount(doc_note_string), doc_note, &doc_note_type)){ + + doc_parse_note_string(doc_string, &pos); + + switch (doc_note_type){ + case DOC_PARAM: ++param_count; break; + case DOC_SEE: ++see_count; break; + } + } + } + }while(keep_parsing); + + if (param_count + see_count > 0){ + int32_t memory_size = sizeof(String)*(2*param_count + see_count); + doc->param_name = push_array(part, String, memory_size); + doc->param_docs = doc->param_name + param_count; + doc->see_also = doc->param_docs + param_count; + + doc->param_count = param_count; + doc->see_also_count = see_count; + } + + int32_t param_index = 0; + int32_t see_index = 0; + + keep_parsing = true; + pos = 0; + do{ + String doc_note = doc_parse_note(doc_string, &pos); + if (doc_note.size == 0){ + keep_parsing = false; + } + else{ + int32_t doc_note_type; + if (string_set_match(doc_note_string, ArrayCount(doc_note_string), doc_note, &doc_note_type)){ + + String doc_note_string = doc_parse_note_string(doc_string, &pos); + + switch (doc_note_type){ + case DOC_PARAM: + { + assert(param_index < param_count); + int32_t param_pos = 0; + String param_name = doc_parse_parameter(doc_note_string, ¶m_pos); + String param_docs = doc_parse_last_parameter(doc_note_string, ¶m_pos); + doc->param_name[param_index] = param_name; + doc->param_docs[param_index] = param_docs; + ++param_index; + }break; + + case DOC_RETURN: + { + doc->return_doc = doc_note_string; + }break; + + case DOC: + { + doc->main_doc = doc_note_string; + }break; + + case DOC_SEE: + { + assert(see_index < see_count); + doc->see_also[see_index++] = doc_note_string; + }break; + } + } + else{ + fprintf(stderr, "warning: invalid doc note %.*s\n", doc_note.size, doc_note.str); + } + } + }while(keep_parsing); +} + +static int32_t +struct_parse(Partition *part, int32_t is_struct, + Parse_Context *context, Item_Node *top_member); + +static int32_t +struct_parse_member(Partition *part, Parse_Context *context, Item_Node *member){ + int32_t result = false; + + Cpp_Token *token = get_token(context); + + String doc_string = {0}; + get_doc_string_from_prev(context, &doc_string); + + Cpp_Token *start_token = token; + + for (; (token = get_token(context)) != 0; get_next_token(context)){ + if (token->type == CPP_TOKEN_SEMICOLON){ + break; + } + } + + if (token){ + String name = {0}; + Cpp_Token *token_j = 0; + int32_t nest_level = 0; + + for (; (token_j = get_token(context)) > start_token; get_prev_token(context)){ + if (token_j->type == CPP_TOKEN_BRACKET_CLOSE){ + ++nest_level; + } + else if (token_j->type == CPP_TOKEN_BRACKET_OPEN){ + --nest_level; + if (nest_level < 0){ + break; + } + } + + if (nest_level == 0){ + if (token_j->type == CPP_TOKEN_IDENTIFIER){ + break; + } + } + } + + name = skip_chop_whitespace(get_lexeme(*token_j, context->data)); + + String type = skip_chop_whitespace(str_start_end(context->data, start_token->start, token_j->start)); + + String type_postfix = skip_chop_whitespace(str_start_end(context->data, token_j->start + token_j->size, token->start)); + + set_token(context, token+1); + result = true; + + member->name = name; + member->type = type; + member->type_postfix = type_postfix; + member->doc_string = doc_string; + member->first_child = 0; + member->next_sibling = 0; + } + + return(result); +} + +static Item_Node* +struct_parse_next_member(Partition *part, Parse_Context *context){ + Item_Node *result = 0; + + Cpp_Token *token = 0; + + for (; (token = get_token(context)) != 0; get_next_token(context)){ + if (token->type == CPP_TOKEN_IDENTIFIER || + (token->flags & CPP_TFLAG_IS_KEYWORD)){ + String lexeme = get_lexeme(*token, context->data); + + if (match_ss(lexeme, make_lit_string("STRUCT"))){ + Item_Node *member = push_struct(part, Item_Node); + if (struct_parse(part, true, context, member)){ + result = member; + break; + } + else{ + assert(!"unhandled error"); + } + } + else if (match_ss(lexeme, make_lit_string("UNION"))){ + Item_Node *member = push_struct(part, Item_Node); + if (struct_parse(part, false, context, member)){ + result = member; + break; + } + else{ + assert(!"unhandled error"); + } + } + else{ + Item_Node *member = push_struct(part, Item_Node); + if (struct_parse_member(part, context, member)){ + result = member; + break; + } + else{ + assert(!"unhandled error"); + } + } + } + else if (token->type == CPP_TOKEN_BRACE_CLOSE){ + break; + } + } + + return(result); +} + +static int32_t +struct_parse(Partition *part, int32_t is_struct, Parse_Context *context, Item_Node *top_member){ + int32_t result = false; + + Cpp_Token *start_token = get_token(context); + Cpp_Token *token = 0; + + String doc_string = {0}; + get_doc_string_from_prev(context, &doc_string); + + for (; (token = get_token(context)) != 0; get_next_token(context)){ + if (token->type == CPP_TOKEN_BRACE_OPEN){ + break; + } + } + + if (token){ + Cpp_Token *token_j = token; + + for (; (token_j = get_token(context)) > start_token; get_prev_token(context)){ + if (token_j->type == CPP_TOKEN_IDENTIFIER){ + break; + } + } + + String name = {0}; + if (token_j != start_token){ + name = skip_chop_whitespace(get_lexeme(*token_j, context->data)); + } + + String type = {0}; + if (is_struct){ + type = make_lit_string("struct"); + } + else{ + type = make_lit_string("union"); + } + + set_token(context, token+1); + Item_Node *new_member = struct_parse_next_member(part, context); + + if (new_member){ + top_member->first_child = new_member; + + Item_Node *head_member = new_member; + for(;;){ + new_member = struct_parse_next_member(part, context); + if (new_member){ + head_member->next_sibling = new_member; + head_member = new_member; + } + else{ + break; + } + } + } + + for (; (token = get_token(context)) != 0; get_next_token(context)){ + if (token->type == CPP_TOKEN_SEMICOLON){ + break; + } + } + ++token; + + if (is_struct){ + top_member->t = Item_Struct; + } + else{ + top_member->t = Item_Union; + } + top_member->name = name; + top_member->type = type; + top_member->doc_string = doc_string; + top_member->next_sibling = 0; + + result = true; + } + + return(result); +} + +static int32_t +typedef_parse(Parse_Context *context, Item_Node *item){ + int32_t result = false; + + Cpp_Token *token = get_token(context); + String doc_string = {0}; + get_doc_string_from_prev(context, &doc_string); + + Cpp_Token *start_token = token; + + for (; (token = get_token(context)) != 0; get_next_token(context)){ + if (token->type == CPP_TOKEN_SEMICOLON){ + break; + } + } + + if (token){ + Cpp_Token *token_j = token; + + for (; (token_j = get_token(context)) > start_token; get_prev_token(context)){ + if (token_j->type == CPP_TOKEN_IDENTIFIER){ + break; + } + } + + String name = get_lexeme(*token_j, context->data); + + String type = skip_chop_whitespace(str_start_end(context->data, start_token->start + start_token->size, token_j->start)); + + item->t = Item_Typedef; + item->type = type; + item->name = name; + item->doc_string = doc_string; + result = true; + } + + set_token(context, token); + + return(result); +} + +static int32_t +enum_parse(Partition *part, Parse_Context *context, Item_Node *item){ + int32_t result = false; + + String doc_string = {0}; + get_doc_string_from_prev(context, &doc_string); + + Cpp_Token *start_token = get_token(context); + Cpp_Token *token = 0; + + for (; (token = get_token(context)) != 0; get_next_token(context)){ + if (token->type == CPP_TOKEN_BRACE_OPEN){ + break; + } + } + + if (token){ + String name = {0}; + Cpp_Token *token_j = 0; + + for (; (token_j = get_token(context)) != 0; get_prev_token(context)){ + if (token_j->type == CPP_TOKEN_IDENTIFIER){ + break; + } + } + + name = get_lexeme(*token_j, context->data); + + set_token(context, token); + for (; (token = get_token(context)) > start_token; get_next_token(context)){ + if (token->type == CPP_TOKEN_BRACE_OPEN){ + break; + } + } + + if (token){ + Item_Node *first_member = 0; + Item_Node *head_member = 0; + + for (; (token = get_token(context)) != 0; get_next_token(context)){ + if (token->type == CPP_TOKEN_BRACE_CLOSE){ + break; + } + else if (token->type == CPP_TOKEN_IDENTIFIER){ + String doc_string = {0}; + String name = {0}; + String value = {0}; + get_doc_string_from_prev(context, &doc_string); + + name = get_lexeme(*token, context->data); + + token = get_next_token(context); + + if (token){ + if (token->type == CPP_TOKEN_EQ){ + Cpp_Token *start_token = token; + + for (; (token = get_token(context)) != 0; get_next_token(context)){ + if (token->type == CPP_TOKEN_COMMA || + token->type == CPP_TOKEN_BRACE_CLOSE){ + break; + } + } + + value = skip_chop_whitespace(str_start_end(context->data, start_token->start + start_token->size, token->start)); + + get_prev_token(context); + } + else{ + get_prev_token(context); + } + } + + Item_Node *new_member = push_struct(part, Item_Node); + if (first_member == 0){ + first_member = new_member; + } + + if (head_member){ + head_member->next_sibling = new_member; + } + head_member = new_member; + + new_member->name = name; + new_member->value = value; + new_member->doc_string = doc_string; + new_member->next_sibling = 0; + } + } + + if ((token = get_token(context)) != 0){ + for (; (token = get_token(context)) != 0; get_next_token(context)){ + if (token->type == CPP_TOKEN_BRACE_CLOSE){ + break; + } + } + get_next_token(context); + + item->t = Item_Enum; + item->name = name; + item->doc_string = doc_string; + item->first_child = first_member; + result = true; + } + } + } + + return(result); +} + +static Argument_Breakdown +allocate_argument_breakdown(Partition *part, int32_t count){ + Argument_Breakdown breakdown = {0}; + if (count > 0){ + breakdown.count = count; + breakdown.args = push_array(part, Argument, count); + memset(breakdown.args, 0, sizeof(Argument)*count); + } + return(breakdown); +} + +/* +Parse arguments by giving pointers to the tokens: +foo(a, ... , z) + ^ ^ +*/ +static Argument_Breakdown +parameter_parse(Partition *part, char *data, Cpp_Token *args_start_token, Cpp_Token *args_end_token){ + int32_t arg_index = 0; + Cpp_Token *arg_token = args_start_token + 1; + int32_t param_string_start = arg_token->start; + + int32_t arg_count = 1; + arg_token = args_start_token; + for (; arg_token < args_end_token; ++arg_token){ + if (arg_token->type == CPP_TOKEN_COMMA){ + ++arg_count; + } + } + + Argument_Breakdown breakdown = allocate_argument_breakdown(part, arg_count); + + arg_token = args_start_token + 1; + for (; arg_token <= args_end_token; ++arg_token){ + if (arg_token->type == CPP_TOKEN_COMMA || + arg_token->type == CPP_TOKEN_PARENTHESE_CLOSE){ + + int32_t size = arg_token->start - param_string_start; + String param_string = make_string(data + param_string_start, size); + param_string = chop_whitespace(param_string); + breakdown.args[arg_index].param_string = param_string; + + for (Cpp_Token *param_name_token = arg_token - 1; + param_name_token->start > param_string_start; + --param_name_token){ + if (param_name_token->type == CPP_TOKEN_IDENTIFIER){ + int32_t start = param_name_token->start; + int32_t size = param_name_token->size; + breakdown.args[arg_index].param_name = make_string(data + start, size); + break; + } + } + + ++arg_index; + + if (arg_token+1 <= args_end_token){ + param_string_start = arg_token[1].start; + } + } + } + + return(breakdown); +} + +/* +Moves the context in the following way: +~~~~~~~ name( ~~~~~~~ + ^ -> ^ +*/ +static int32_t +function_parse_goto_name(Parse_Context *context){ + int32_t result = false; + + Cpp_Token *token = 0; + + { + for (; (token = get_token(context)) != 0; get_next_token(context)){ + if (token->type == CPP_TOKEN_PARENTHESE_OPEN){ + break; + } + } + + if (get_token(context)){ + do{ + token = get_prev_token(context); + }while(token->type == CPP_TOKEN_COMMENT); + + if (token->type == CPP_TOKEN_IDENTIFIER){ + result = true; + } + } + } + + return(result); +} + +/* +Moves the context in the following way: +~~~~~~~ name( ~~~~~~~ /* XXX // + ^ ---------------> ^ +*/ +static int32_t +function_get_doc(Parse_Context *context, char *data, String *doc_string){ + int32_t result = false; + + Cpp_Token *token = get_token(context); + String lexeme = {0}; + + if (function_parse_goto_name(context)){ + if (token->type == CPP_TOKEN_IDENTIFIER){ + for (; (token = get_token(context)) != 0; get_next_token(context)){ + if (token->type == CPP_TOKEN_COMMENT){ + lexeme = get_lexeme(*token, data); + if (check_and_fix_docs(&lexeme)){ + *doc_string = lexeme; + result = true; + break; + } + } + else if (token->type == CPP_TOKEN_BRACE_OPEN){ + break; + } + } + } + } + + return(result); +} + +static int32_t +cpp_name_parse(Parse_Context *context, String *name){ + int32_t result = false; + + Cpp_Token *token = 0; + Cpp_Token *token_start = get_token(context); + + token = get_next_token(context); + if (token && token->type == CPP_TOKEN_PARENTHESE_OPEN){ + token = get_next_token(context); + if (token && token->type == CPP_TOKEN_IDENTIFIER){ + token = get_next_token(context); + if (token && token->type == CPP_TOKEN_PARENTHESE_CLOSE){ + *name = get_lexeme(*(token-1), context->data); + result = true; + } + } + } + + if (!result){ + set_token(context, token_start); + } + + return(result); +} + +/* +Moves the context in the following way: + RETTY~ name( ~~~~~~~ ) + ^ ---------------> ^ +*/ +static int32_t +function_sig_parse(Partition *part, Parse_Context *context, Item_Node *item, String cpp_name){ + int32_t result = false; + + Cpp_Token *token = 0; + Cpp_Token *args_start_token = 0; + Cpp_Token *ret_token = get_token(context); + + if (function_parse_goto_name(context)){ + token = get_token(context); + args_start_token = token+1; + item->name = get_lexeme(*token, context->data); + + item->ret = chop_whitespace(str_start_end(context->data, ret_token->start, token->start)); + + for (; (token = get_token(context)) != 0; get_next_token(context)){ + if (token->type == CPP_TOKEN_PARENTHESE_CLOSE){ + break; + } + } + + if (token){ + item->args = str_start_end(context->data, args_start_token->start, token->start + token->size); + item->t = Item_Function; + item->cpp_name = cpp_name; + item->breakdown = parameter_parse(part, context->data, args_start_token, token); + + Assert(get_token(context)->type == CPP_TOKEN_PARENTHESE_CLOSE); + result = true; + } + } + + return(result); +} + +/* +Moves the context in the following way: + MARKER ~~~ name( ~~~~~~~ ) + ^ -------------------> ^ +*/ +static int32_t +function_parse(Partition *part, Parse_Context *context, Item_Node *item, String cpp_name){ + int32_t result = false; + + String doc_string = {0}; + Cpp_Token *token = get_token(context); + + item->marker = get_lexeme(*token, context->data); + + if (function_get_doc(context, context->data, &doc_string)){ + item->doc_string = doc_string; + } + + set_token(context, token); + if (get_next_token(context)){ + if (function_sig_parse(part, context, item, cpp_name)){ + Assert(get_token(context)->type == CPP_TOKEN_PARENTHESE_CLOSE); + result = true; + } + } + + return(result); +} + +/* +Moves the context in the following way: + /* ~~~ // #define + ^ ----> ^ +*/ +static int32_t +macro_parse_check(Parse_Context *context){ + int32_t result = false; + + Cpp_Token *token = 0; + + if ((token = get_next_token(context)) != 0){ + if (token->type == CPP_TOKEN_COMMENT){ + if ((token = get_next_token(context)) != 0){ + if (token->type == CPP_PP_DEFINE){ + result = true; + } + } + } + } + + return(result); +} + +/* +Moves the context in the following way: + /* ~~~ // #define ~~~~~~~~~~~~~~~~~ NOT_IN_MACRO_BODY + ^ ----------------------------> ^ +*/ +static int32_t +macro_parse(Partition *part, Parse_Context *context, Item_Node *item){ + int32_t result = false; + + Cpp_Token *token = 0; + Cpp_Token *doc_token = 0; + Cpp_Token *args_start_token = 0; + + String doc_string = {0}; + + if (macro_parse_check(context)){ + token = get_token(context); + if (can_back_step(context)){ + doc_token = token-1; + + doc_string = get_lexeme(*doc_token, context->data); + + if (check_and_fix_docs(&doc_string)){ + item->doc_string = doc_string; + + for (; (token = get_token(context)) != 0; get_next_token(context)){ + if (token->type == CPP_TOKEN_IDENTIFIER){ + break; + } + } + + if (get_token(context) && (token->flags & CPP_TFLAG_PP_BODY)){ + item->name = get_lexeme(*token, context->data); + + if ((token = get_next_token(context)) != 0){ + args_start_token = token; + for (; (token = get_token(context)) != 0; get_next_token(context)){ + if (token->type == CPP_TOKEN_PARENTHESE_CLOSE){ + break; + } + } + + if (token){ + item->args = str_start_end(context->data, args_start_token->start, token->start + token->size); + + item->breakdown = parameter_parse(part, context->data, args_start_token, token); + + if ((token = get_next_token(context)) != 0){ + Cpp_Token *body_start = token; + + if (body_start->flags & CPP_TFLAG_PP_BODY){ + for (; (token = get_token(context)) != 0; get_next_token(context)){ + if (!(token->flags & CPP_TFLAG_PP_BODY)){ + break; + } + } + + token = get_prev_token(context); + + item->body = str_start_end(context->data, body_start->start,token->start + token->size); + } + } + + item->t = Item_Macro; + result = true; + } + } + } + } + } + } + + return(result); +} + +static Meta_Unit +compile_meta_unit(Partition *part, char *code_directory, char **files, Meta_Keywords *keywords, int32_t key_count){ + Meta_Unit unit = {0}; + + int32_t file_count = 0; + for (char **file_ptr = files; *file_ptr; ++file_ptr, ++file_count); + + unit.count = file_count; + unit.parse = push_array(part, Parse, file_count); + + int32_t i = 0; + for (char **file_ptr = files; *file_ptr; ++file_ptr, ++i){ + char str_space[512]; + String name = make_fixed_width_string(str_space); + append_sc(&name, code_directory); + append_sc(&name, "\\"); + append_sc(&name, *file_ptr); + terminate_with_null(&name); + + unit.parse[i] = meta_lex(name.str); + } + + // TODO(allen): This stage counts nested structs + // and unions which is not correct. Luckily it only + // means we over allocate by a few items, but fixing it + // to be exactly correct would be nice. + for (int32_t J = 0; J < unit.count; ++J){ + Cpp_Token *token = 0; + Parse_Context context_ = setup_parse_context(unit.parse[J]); + Parse_Context *context = &context_; + + for (; (token = get_token(context)) != 0; get_next_token(context)){ + if (!(token->flags & CPP_TFLAG_PP_BODY)){ + + String lexeme = get_lexeme(*token, context->data); + int32_t match_index = 0; + if (string_set_match_table(keywords, sizeof(*keywords), key_count, lexeme, &match_index)){ + Item_Type type = keywords[match_index].type; + + if (type > Item_Null && type < Item_Type_Count){ + ++unit.set.count; + } + else{ + // TODO(allen): Warning + } + } + } + } + } + + if (unit.set.count > 0){ + unit.set = allocate_item_set(part, unit.set.count); + } + + int32_t index = 0; + + for (int32_t J = 0; J < unit.count; ++J){ + Cpp_Token *token = 0; + Parse_Context context_ = setup_parse_context(unit.parse[J]); + Parse_Context *context = &context_; + + String cpp_name = {0}; + int32_t has_cpp_name = 0; + + for (; (token = get_token(context)) != 0; get_next_token(context)){ + if (!(token->flags & CPP_TFLAG_PP_BODY)){ + + String lexeme = get_lexeme(*token, context->data); + int32_t match_index = 0; + if (string_set_match_table(keywords, sizeof(*keywords), key_count, lexeme, &match_index)){ + Item_Type type = keywords[match_index].type; + + switch (type){ + case Item_Function: + { + if (function_parse(part, context, unit.set.items + index, cpp_name)){ + Assert(unit.set.items[index].t == Item_Function); + ++index; + } + else{ + fprintf(stderr, "warning: invalid function signature\n"); + } + }break; + + case Item_CppName: + { + if (cpp_name_parse(context, &cpp_name)){ + has_cpp_name = 1; + } + else{ + // TODO(allen): warning message + } + }break; + + case Item_Macro: + { + if (macro_parse(part, context, unit.set.items + index)){ + Assert(unit.set.items[index].t == Item_Macro); + ++index; + } + else{ + // TODO(allen): warning message + } + }break; + + case Item_Typedef: //typedef + { + if (typedef_parse(context, unit.set.items + index)){ + Assert(unit.set.items[index].t == Item_Typedef); + ++index; + } + else{ + // TODO(allen): warning message + } + }break; + + case Item_Struct: case Item_Union: //struct/union + { + if (struct_parse(part, (type == Item_Struct), context, unit.set.items + index)){ + Assert(unit.set.items[index].t == Item_Struct || + unit.set.items[index].t == Item_Union); + ++index; + } + else{ + // TODO(allen): warning message + } + }break; + + case Item_Enum: //ENUM + { + if (enum_parse(part, context, unit.set.items + index)){ + Assert(unit.set.items[index].t == Item_Enum); + ++index; + } + else{ + // TODO(allen): warning message + } + }break; + + } + } + } + + if (has_cpp_name){ + has_cpp_name = 0; + } + else{ + cpp_name = null_string; + } + + unit.parse[J].item_count = index; + } + + // NOTE(allen): This is necessary for now because + // the original count is slightly overestimated thanks + // to nested structs and unions. + unit.set.count = index; + } + + return(unit); +} + +#endif + +// BOTTOM + diff --git a/site/4ed_site.ctm b/site/4ed_site.ctm new file mode 100644 index 0000000000000000000000000000000000000000..56574130238c0f18a0279f5ecd9ea15e9b30ee13 GIT binary patch literal 1284 zcmYk*Yer<`$3z}f_f?afZN{Sz_J2`x<^*1ad&usg- z1atjScb!9uSkHM`Wu^<;iN2d0C8_4|WCC&x-OKfmsgOUUyz}$+B)E~h>1#$R>Mv1! zyZ;w8^1GBfA3LRitH~#qD_US3JFX=Bj5v>$)(@x?rBrdAPRa*ti>_(H!(_`9RRwG% z%k$okri+~2|4yyX6#aUdCFyU#haooqKHjglAm0k}`41T`yJv~|i&Wz_8z*OT{ddZP zl+UAKUSFhl%04UdX|gtOF%K>#@7)rkfwko3+W41+qQ8=cHYxKOhgWEiCUx*UoA)zP zednUdvrTv>-JD)-O=t7GtLVCr7n%=elWpI2EWkXkw-FgjFwY~!FJlEhPk!<`YZd1D z!DkWc+eLr&eNCK#&F7h+^Z0Aq_Q50Mf{DO!y~ueU;psY~QTQp@!_A!2CHg&}9+A5G zLb#rMD_Ws}>&O${H%np8Hx4*g+IwxRs>^(v$t=@Jpk`cCU1B3`_C8)CUxoR3xEg#y>K6Y$yY$X4N0{fY zoXuSabKYo*+yHZbSADGv=K6qWA1|2msl!9wa1pt%{M=SHKQH_~C2jUn!2CSyF119# PX0mmUr(dtA=lA +#include +#include +#include + +#include "4coder_mem.h" +#include "meta_parser.cpp" + +#define InvalidPath Assert(!"Invalid path of execution") + +typedef struct Out_Context{ + char out_directory_space[256]; + String out_directory; + FILE *file; + String *str; +} Out_Context; + +static void +set_context_directory(Out_Context *context, char *dst_directory){ + context->out_directory = make_fixed_width_string(context->out_directory_space); + copy_sc(&context->out_directory, dst_directory); +} + +static int32_t +begin_file_out(Out_Context *out_context, char *filename, String *out){ + char str_space[512]; + String name = make_fixed_width_string(str_space); + if (out_context->out_directory.size > 0){ + append_ss(&name, out_context->out_directory); + append_sc(&name, "\\"); + } + append_sc(&name, filename); + terminate_with_null(&name); + + int32_t r = 0; + out_context->file = fopen(name.str, "wb"); + out_context->str = out; + out->size = 0; + if (out_context->file){ + r = 1; + } + + return(r); +} + +static void +dump_file_out(Out_Context out_context){ + fwrite(out_context.str->str, 1, out_context.str->size, out_context.file); + out_context.str->size = 0; +} + +static void +end_file_out(Out_Context out_context){ + dump_file_out(out_context); + fclose(out_context.file); +} + +static String +make_out_string(int32_t x){ + String str; + str.size = 0; + str.memory_size = x; + str.str = (char*)malloc(x); + return(str); +} + +////////////////////////////////////////////////////////////////////////////////////////////////// + +// +// Meta Parse Rules +// + +static void +init_used_links(Partition *part, Used_Links *used, int32_t count){ + used->strs = push_array(part, String, count); + used->count = 0; + used->max = count; +} + +static int32_t +try_to_use(Used_Links *used, String str){ + int32_t result = 1; + int32_t index = 0; + + if (string_set_match(used->strs, used->count, str, &index)){ + result = 0; + } + else{ + used->strs[used->count++] = str; + } + + return(result); +} + +static void +print_struct_html(String *out, Item_Node *member, int32_t hide_children){ + String name = member->name; + String type = member->type; + String type_postfix = member->type_postfix; + + append_ss (out, type); + append_s_char (out, ' '); + append_ss (out, name); + append_ss (out, type_postfix); + + if (match_ss(type, make_lit_string("struct")) || + match_ss(type, make_lit_string("union"))){ + + if (hide_children){ + append_sc(out, " { /* non-public internals */ } ;"); + } + else{ + append_sc(out, " {
    "); + + for (Item_Node *member_iter = member->first_child; + member_iter != 0; + member_iter = member_iter->next_sibling){ + print_struct_html(out, member_iter, hide_children); + } + + append_sc(out, "
    };
    "); + } + } + else{ + append_sc(out, ";
    "); + } +} + +static void +print_function_html(String *out, Used_Links *used, String cpp_name, String ret, char *function_call_head, String name, Argument_Breakdown breakdown){ + + append_ss (out, ret); + append_s_char (out, ' '); + append_sc (out, function_call_head); + append_ss (out, name); + + if (breakdown.count == 0){ + append_sc(out, "()"); +} +else if (breakdown.count == 1){ + append_sc(out, "("); + append_ss(out, breakdown.args[0].param_string); + append_sc(out, ")"); +} +else{ + append_sc(out, "(
    "); + + for (int32_t j = 0; j < breakdown.count; ++j){ + append_ss(out, breakdown.args[j].param_string); + if (j < breakdown.count - 1){ + append_s_char(out, ','); + } + append_sc(out, "
    "); + } + + append_sc(out, "
    )"); +} +} + +static void +print_macro_html(String *out, String name, Argument_Breakdown breakdown){ + + append_sc (out, "#define "); + append_ss (out, name); + + if (breakdown.count == 0){ + append_sc(out, "()"); + } + else if (breakdown.count == 1){ + append_s_char (out, '('); + append_ss (out, breakdown.args[0].param_string); + append_s_char (out, ')'); + } + else{ + append_sc (out, "(
    "); + + for (int32_t j = 0; j < breakdown.count; ++j){ + append_ss(out, breakdown.args[j].param_string); + if (j < breakdown.count - 1){ + append_s_char(out, ','); + } + append_sc(out, "
    "); + } + + append_sc(out, ")
    )"); + } +} + +#define BACK_COLOR "#FAFAFA" +#define TEXT_COLOR "#0D0D0D" +#define CODE_BACK "#DFDFDF" +#define EXAMPLE_BACK "#EFEFDF" + +#define POP_COLOR_1 "#309030" +#define POP_BACK_1 "#E0FFD0" +#define VISITED_LINK "#A0C050" + +#define POP_COLOR_2 "#005000" + +#define CODE_STYLE "font-family: \"Courier New\", Courier, monospace; text-align: left;" + +#define CODE_BLOCK_STYLE(back) \ +"margin-top: 3mm; margin-bottom: 3mm; font-size: .95em; " \ +"background: "back"; padding: 0.25em;" + +#define DESCRIPT_SECTION_STYLE CODE_BLOCK_STYLE(CODE_BACK) +#define EXAMPLE_CODE_STYLE CODE_BLOCK_STYLE(EXAMPLE_BACK) + +#define DOC_HEAD_OPEN "
    " +#define DOC_HEAD_CLOSE "
    " + +#define DOC_ITEM_HEAD_STYLE "font-weight: 600;" + +#define DOC_ITEM_HEAD_INL_OPEN "" +#define DOC_ITEM_HEAD_INL_CLOSE "" + +#define DOC_ITEM_HEAD_OPEN "
    " +#define DOC_ITEM_HEAD_CLOSE "
    " + +#define DOC_ITEM_OPEN "
    " +#define DOC_ITEM_CLOSE "
    " + +#define EXAMPLE_CODE_OPEN "
    " +#define EXAMPLE_CODE_CLOSE "
    " + +static String +get_first_double_line(String source){ + String line = {0}; + int32_t pos0 = find_substr_s(source, 0, make_lit_string("\n\n")); + int32_t pos1 = find_substr_s(source, 0, make_lit_string("\r\n\r\n")); + if (pos1 < pos0){ + pos0 = pos1; + } + line = substr(source, 0, pos0); + return(line); +} + +static String +get_next_double_line(String source, String line){ + String next = {0}; + int32_t pos = (int32_t)(line.str - source.str) + line.size; + int32_t start = 0, pos0 = 0, pos1 = 0; + + if (pos < source.size){ + assert(source.str[pos] == '\n' || source.str[pos] == '\r'); + start = pos + 1; + + if (start < source.size){ + pos0 = find_substr_s(source, start, make_lit_string("\n\n")); + pos1 = find_substr_s(source, start, make_lit_string("\r\n\r\n")); + if (pos1 < pos0){ + pos0 = pos1; + } + next = substr(source, start, pos0 - start); + } + } + + return(next); +} + +static String +get_next_word(String source, String prev_word){ + String word = {0}; + int32_t pos0 = (int32_t)(prev_word.str - source.str) + prev_word.size; + int32_t pos1 = 0; + char c = 0; + + for (; pos0 < source.size; ++pos0){ + c = source.str[pos0]; + if (!(char_is_whitespace(c) || c == '(' || c == ')')){ + break; + } + } + + if (pos0 < source.size){ + for (pos1 = pos0; pos1 < source.size; ++pos1){ + c = source.str[pos1]; + if (char_is_whitespace(c) || c == '(' || c == ')'){ + break; + } + } + + word = substr(source, pos0, pos1 - pos0); + } + + return(word); +} + +static String +get_first_word(String source){ + String start_str = make_string(source.str, 0); + String word = get_next_word(source, start_str); + return(word); +} + +enum Doc_Chunk_Type{ + DocChunk_PlainText, + DocChunk_CodeExample, + + DocChunk_Count +}; + +static String doc_chunk_headers[] = { + make_lit_string(""), + make_lit_string("CODE_EXAMPLE"), +}; + +static String +get_next_doc_chunk(String source, String prev_chunk, Doc_Chunk_Type *type){ + String chunk = {0}; + String word = {0}; + int32_t pos = source.size; + int32_t word_index = 0; + Doc_Chunk_Type t = DocChunk_PlainText; + + int32_t start_pos = (int32_t)(prev_chunk.str - source.str) + prev_chunk.size; + String source_tail = substr_tail(source, start_pos); + + Assert(DocChunk_Count == ArrayCount(doc_chunk_headers)); + + for (word = get_first_word(source_tail); + word.str; + word = get_next_word(source_tail, word), ++word_index){ + + for (int32_t i = 1; i < DocChunk_Count; ++i){ + if (match_ss(word, doc_chunk_headers[i])){ + pos = (int32_t)(word.str - source.str); + t = (Doc_Chunk_Type)i; + goto doublebreak; + } + } + } + doublebreak:; + + *type = DocChunk_PlainText; + if (word_index == 0){ + *type = t; + + int32_t nest_level = 1; + int32_t i = find_s_char(source, pos, '('); + for (++i; i < source.size; ++i){ + if (source.str[i] == '('){ + ++nest_level; + } + else if (source.str[i] == ')'){ + --nest_level; + if (nest_level == 0){ + break; + } + } + } + + pos = i+1; + } + + chunk = substr(source, start_pos, pos - start_pos); + + int32_t is_all_white = 1; + for (int32_t i = 0; i < chunk.size; ++i){ + if (!char_is_whitespace(chunk.str[i])){ + is_all_white = 0; + break; + } + } + + if (is_all_white){ + chunk = null_string; + } + + return(chunk); +} + +static String +get_first_doc_chunk(String source, Doc_Chunk_Type *type){ + String start_str = make_string(source.str, 0); + String chunk = get_next_doc_chunk(source, start_str, type); + return(chunk); +} + +static void +print_doc_description(String *out, Partition *part, String src){ + Doc_Chunk_Type type; + + for (String chunk = get_first_doc_chunk(src, &type); + chunk.str; + chunk = get_next_doc_chunk(src, chunk, &type)){ + + switch (type){ + case DocChunk_PlainText: + { + for (String line = get_first_double_line(chunk); + line.str; + line = get_next_double_line(chunk, line)){ + append_ss(out, line); + append_sc(out, "

    "); + } + }break; + + case DocChunk_CodeExample: + { + int32_t start = 0; + int32_t end = chunk.size-1; + while (start < end && chunk.str[start] != '(') ++start; + start += 1; + while (end > start && chunk.str[end] != ')') --end; + + + append_sc(out, EXAMPLE_CODE_OPEN); + + if (start < end){ + String code_example = substr(chunk, start, end - start); + int32_t first_line = 1; + + for (String line = get_first_line(code_example); + line.str; + line = get_next_line(code_example, line)){ + + if (!(first_line && line.size == 0)){ + int32_t space_i = 0; + for (; space_i < line.size; ++space_i){ + if (line.str[space_i] == ' '){ + append_sc(out, " "); + } + else{ + break; + } + } + + String line_tail = substr_tail(line, space_i); + append_ss(out, line_tail); + append_sc(out, "
    "); + } + first_line = 0; + } + } + + append_sc(out, EXAMPLE_CODE_CLOSE); + }break; + } + } +} + +static void +print_struct_docs(String *out, Partition *part, Item_Node *member){ + for (Item_Node *member_iter = member->first_child; + member_iter != 0; + member_iter = member_iter->next_sibling){ + String type = member_iter->type; + if (match_ss(type, make_lit_string("struct")) || + match_ss(type, make_lit_string("union"))){ + print_struct_docs(out, part, member_iter); + } + else{ + Documentation doc = {0}; + perform_doc_parse(part, member_iter->doc_string, &doc); + + append_sc(out, "
    "); + + append_sc(out, "
    "DOC_ITEM_HEAD_INL_OPEN); + append_ss(out, member_iter->name); + append_sc(out, DOC_ITEM_HEAD_INL_CLOSE"
    "); + + append_sc(out, "
    "DOC_ITEM_OPEN); + print_doc_description(out, part, doc.main_doc); + append_sc(out, DOC_ITEM_CLOSE"
    "); + + append_sc(out, "
    "); + } + } +} + +static void +print_see_also(String *out, Documentation *doc){ + int32_t doc_see_count = doc->see_also_count; + if (doc_see_count > 0){ + append_sc(out, DOC_HEAD_OPEN"See Also"DOC_HEAD_CLOSE); + + for (int32_t j = 0; j < doc_see_count; ++j){ + String see_also = doc->see_also[j]; + append_sc(out, DOC_ITEM_OPEN""); + append_ss(out, see_also); + append_sc(out, ""DOC_ITEM_CLOSE); + } + } +} + +static void +print_function_body_code(String *out, Parse_Context *context, int32_t start){ + String pstr = {0}, lexeme = {0}; + Cpp_Token *token = 0; + + int32_t do_print = 0; + int32_t nest_level = 0; + int32_t finish = false; + int32_t do_whitespace_print = false; + for (; (token = get_token(context)) != 0; get_next_token(context)){ + if (do_whitespace_print){ + pstr = str_start_end(context->data, start, token->start); + append_ss(out, pstr); + } + else{ + do_whitespace_print = true; + } + + do_print = true; + if (token->type == CPP_TOKEN_COMMENT){ + lexeme = get_lexeme(*token, context->data); + if (check_and_fix_docs(&lexeme)){ + do_print = false; + } + } + else if (token->type == CPP_TOKEN_BRACE_OPEN){ + ++nest_level; + } + else if (token->type == CPP_TOKEN_BRACE_CLOSE){ + --nest_level; + if (nest_level == 0){ + finish = true; + } + } + + if (do_print){ + pstr = get_lexeme(*token, context->data); + append_ss(out, pstr); + } + + start = token->start + token->size; + + if (finish){ + break; + } + } +} + +static void +print_function_docs(String *out, Partition *part, String name, String doc_string){ + if (doc_string.size == 0){ + append_sc(out, "No documentation generated for this function."); + fprintf(stderr, "warning: no documentation string for %.*s\n", name.size, name.str); + } + + Temp_Memory temp = begin_temp_memory(part); + + Documentation doc = {0}; + + perform_doc_parse(part, doc_string, &doc); + + int32_t doc_param_count = doc.param_count; + if (doc_param_count > 0){ + append_sc(out, DOC_HEAD_OPEN"Parameters"DOC_HEAD_CLOSE); + + for (int32_t j = 0; j < doc_param_count; ++j){ + String param_name = doc.param_name[j]; + String param_docs = doc.param_docs[j]; + + // TODO(allen): check that param_name is actually + // a parameter to this function! + + append_sc(out, "
    "DOC_ITEM_HEAD_OPEN); + append_ss(out, param_name); + append_sc(out, DOC_ITEM_HEAD_CLOSE"
    "DOC_ITEM_OPEN); + append_ss(out, param_docs); + append_sc(out, DOC_ITEM_CLOSE"
    "); + } + } + + String ret_doc = doc.return_doc; + if (ret_doc.size != 0){ + append_sc(out, DOC_HEAD_OPEN"Return"DOC_HEAD_CLOSE DOC_ITEM_OPEN); + append_ss(out, ret_doc); + append_sc(out, DOC_ITEM_CLOSE); + } + + String main_doc = doc.main_doc; + if (main_doc.size != 0){ + append_sc(out, DOC_HEAD_OPEN"Description"DOC_HEAD_CLOSE DOC_ITEM_OPEN); + print_doc_description(out, part, main_doc); + append_sc(out, DOC_ITEM_CLOSE); + } + + print_see_also(out, &doc); + + end_temp_memory(temp); +} + +static void +print_item_in_list(String *out, String name, char *id_postfix){ + append_sc(out, "
  • "); + append_ss(out, name); + append_sc(out, "
  • "); +} + +static void +print_item(String *out, Partition *part, Used_Links *used, + Item_Node *item, char *id_postfix, char *function_prefix, + char *section, int32_t I){ + Temp_Memory temp = begin_temp_memory(part); + + String name = item->name; + /* NOTE(allen): + Open a div for the whole item. + Put a heading in it with the name and section. + Open a "descriptive" box for the display of the code interface. + */ + append_sc(out, "
    "); + + int32_t has_cpp_name = 0; + if (item->cpp_name.str != 0){ + if (try_to_use(used, item->cpp_name)){ + append_sc(out, "
    "); + has_cpp_name = 1; + } + } + + append_sc (out, "

    §"); + append_sc (out, section); + append_s_char (out, '.'); + append_int_to_str (out, I); + append_sc (out, ": "); + append_ss (out, name); + append_sc (out, "

    "); + + append_sc(out, "
    "); + + switch (item->t){ + case Item_Function: + { + // NOTE(allen): Code box + Assert(function_prefix != 0); + print_function_html(out, used, item->cpp_name, item->ret, function_prefix, item->name, item->breakdown); + + // NOTE(allen): Close the code box + append_sc(out, "
    "); + + // NOTE(allen): Descriptive section + print_function_docs(out, part, item->name, item->doc_string); + }break; + + case Item_Macro: + { + // NOTE(allen): Code box + print_macro_html(out, item->name, item->breakdown); + + // NOTE(allen): Close the code box + append_sc(out, "
    "); + + // NOTE(allen): Descriptive section + print_function_docs(out, part, item->name, item->doc_string); + }break; + + case Item_Typedef: + { + String type = item->type; + + // NOTE(allen): Code box + append_sc (out, "typedef "); + append_ss (out, type); + append_s_char (out, ' '); + append_ss (out, name); + append_s_char (out, ';'); + + // NOTE(allen): Close the code box + append_sc(out, "
    "); + + // NOTE(allen): Descriptive section + String doc_string = item->doc_string; + Documentation doc = {0}; + perform_doc_parse(part, doc_string, &doc); + + String main_doc = doc.main_doc; + if (main_doc.size != 0){ + append_sc(out, DOC_HEAD_OPEN"Description"DOC_HEAD_CLOSE); + + append_sc(out, DOC_ITEM_OPEN); + print_doc_description(out, part, main_doc); + append_sc(out, DOC_ITEM_CLOSE); + } + else{ + fprintf(stderr, "warning: no documentation string for %.*s\n", name.size, name.str); + } + + print_see_also(out, &doc); + + }break; + + case Item_Enum: + { + // NOTE(allen): Code box + append_sc (out, "enum "); + append_ss (out, name); + append_s_char (out, ';'); + + // NOTE(allen): Close the code box + append_sc(out, "
    "); + + // NOTE(allen): Descriptive section + String doc_string = item->doc_string; + Documentation doc = {0}; + perform_doc_parse(part, doc_string, &doc); + + String main_doc = doc.main_doc; + if (main_doc.size != 0){ + append_sc(out, DOC_HEAD_OPEN"Description"DOC_HEAD_CLOSE); + + append_sc(out, DOC_ITEM_OPEN); + print_doc_description(out, part, main_doc); + append_sc(out, DOC_ITEM_CLOSE); + } + else{ + fprintf(stderr, "warning: no documentation string for %.*s\n", name.size, name.str); + } + + if (item->first_child){ + append_sc(out, DOC_HEAD_OPEN"Values"DOC_HEAD_CLOSE); + + for (Item_Node *member = item->first_child; + member; + member = member->next_sibling){ + Documentation doc = {0}; + perform_doc_parse(part, member->doc_string, &doc); + + append_sc(out, "
    "); + + // NOTE(allen): Dafuq is this all? + append_sc(out, "
    "DOC_ITEM_HEAD_INL_OPEN); + append_ss(out, member->name); + append_sc(out, DOC_ITEM_HEAD_INL_CLOSE); + + if (member->value.str){ + append_sc(out, " = "); + append_ss(out, member->value); + } + + append_sc(out, "
    "); + + append_sc(out, "
    "DOC_ITEM_OPEN); + print_doc_description(out, part, doc.main_doc); + append_sc(out, DOC_ITEM_CLOSE"
    "); + + append_sc(out, "
    "); + } + } + + print_see_also(out, &doc); + + }break; + + case Item_Struct: case Item_Union: + { + String doc_string = item->doc_string; + + int32_t hide_members = 0; + + if (doc_string.size == 0){ + hide_members = 1; + } + else{ + for (String word = get_first_word(doc_string); + word.str; + word = get_next_word(doc_string, word)){ + if (match_ss(word, make_lit_string("HIDE_MEMBERS"))){ + hide_members = 1; + break; + } + } + } + + // NOTE(allen): Code box + print_struct_html(out, item, hide_members); + + // NOTE(allen): Close the code box + append_sc(out, "
    "); + + // NOTE(allen): Descriptive section + { + Documentation doc = {0}; + perform_doc_parse(part, doc_string, &doc); + + String main_doc = doc.main_doc; + if (main_doc.size != 0){ + append_sc(out, DOC_HEAD_OPEN"Description"DOC_HEAD_CLOSE); + + append_sc(out, DOC_ITEM_OPEN); + print_doc_description(out, part, main_doc); + append_sc(out, DOC_ITEM_CLOSE); + } + else{ + fprintf(stderr, "warning: no documentation string for %.*s\n", name.size, name.str); + } + + if (!hide_members){ + if (item->first_child){ + append_sc(out, DOC_HEAD_OPEN"Fields"DOC_HEAD_CLOSE); + print_struct_docs(out, part, item); + } + } + + print_see_also(out, &doc); + } + }break; + } + + if (has_cpp_name){ + append_sc(out, "
    "); + } + + // NOTE(allen): Close the item box + append_sc(out, "

    "); + + end_temp_memory(temp); +} + +typedef struct App_API_Name{ + String macro; + String public_name; +} App_API_Name; + +typedef struct App_API{ + App_API_Name *names; +} App_API; + +static App_API +allocate_app_api(Partition *part, int32_t count){ + App_API app_api = {0}; + app_api.names = push_array(part, App_API_Name, count); + memset(app_api.names, 0, sizeof(App_API_Name)*count); + return(app_api); +} + +static void +generate_custom_headers(char *code_directory, char *src_directory, char *dst_directory){ +#define API_DOC "4coder_API.html" + + int32_t size = (512 << 20); + void *mem = malloc(size); + memset(mem, 0, size); + + Partition part_ = make_part(mem, size); + Partition *part = &part_; + + static Meta_Keywords meta_keywords[] = { + {make_lit_string("API_EXPORT") , Item_Function } , + {make_lit_string("API_EXPORT_INLINE") , Item_Function } , + {make_lit_string("API_EXPORT_MACRO") , Item_Macro } , + {make_lit_string("CPP_NAME") , Item_CppName } , + {make_lit_string("TYPEDEF") , Item_Typedef } , + {make_lit_string("STRUCT") , Item_Struct } , + {make_lit_string("UNION") , Item_Union } , + {make_lit_string("ENUM") , Item_Enum } , + }; + +#define ExpandArray(a) (a), (ArrayCount(a)) + + // NOTE(allen): Parse the internal string file. + static char *string_files[] = { + "internal_4coder_string.cpp", + 0 + }; + + Meta_Unit string_unit = compile_meta_unit(part, code_directory, string_files, ExpandArray(meta_keywords)); + + // NOTE(allen): Parse the lexer library + static char *lexer_types_files[] = { + "4cpp_lexer_types.h", + 0 + }; + + Meta_Unit lexer_types_unit = compile_meta_unit(part, code_directory, lexer_types_files, ExpandArray(meta_keywords)); + + static char *lexer_funcs_files[] = { + "4cpp_lexer.h", + 0 + }; + + Meta_Unit lexer_funcs_unit = compile_meta_unit(part, code_directory, lexer_funcs_files, ExpandArray(meta_keywords)); + + + // NOTE(allen): Parse the customization API files + static char *functions_files[] = { + "4ed_api_implementation.cpp", + "win32_api_impl.cpp", + 0 + }; + + Meta_Unit unit_custom = compile_meta_unit(part, code_directory, functions_files, ExpandArray(meta_keywords)); + + + // NOTE(allen): Compute and store variations of the function names + App_API func_4ed_names = allocate_app_api(part, unit_custom.set.count); + + for (int32_t i = 0; i < unit_custom.set.count; ++i){ + String name_string = unit_custom.set.items[i].name; + String *macro = &func_4ed_names.names[i].macro; + String *public_name = &func_4ed_names.names[i].public_name; + + *macro = str_alloc(part, name_string.size+4); + to_upper_ss(macro, name_string); + append_ss(macro, make_lit_string("_SIG")); + + *public_name = str_alloc(part, name_string.size); + to_lower_ss(public_name, name_string); + + partition_align(part, 4); + } + + // NOTE(allen): Parse the customization API types + static char *type_files[] = { + "4coder_types.h", + 0 + }; + + Meta_Unit unit = compile_meta_unit(part, code_directory, type_files, ExpandArray(meta_keywords)); + + // NOTE(allen): Output + String out = str_alloc(part, 10 << 20); + Out_Context context = {0}; + + set_context_directory(&context, dst_directory); + + // Output Docs + if (begin_file_out(&context, API_DOC, &out)){ + + Used_Links used_links = {0}; + init_used_links(part, &used_links, 4000); + + append_sc(&out, + "" + "" + "4coder API Docs" + "" + "\n" + "" + "
    " + // "

    4cpp Lexing Library

    "); + + "

    4coder API

    "); + + struct Section{ + char *id_string; + char *display_string; + }; + + static int32_t msection = -1; + + static Section sections[] = { + {"introduction", "Introduction"}, + {"4coder_systems", "4coder Systems"}, + {"types_and_functions", "Types and Functions"}, + {"string_library", "String Library"}, + {"lexer_library", "Lexer Library"} + }; + + append_sc(&out, "

    Table of Contents

    """); + +#define MAJOR_SECTION "1" + msection = 0; + + append_sc(&out, "\n

    §"MAJOR_SECTION" "); + append_sc(&out, sections[msection].display_string); + append_sc(&out, "

    "); + +#if 0 + // NOTE(allen): doc intro for lexer standalone + append_sc(&out, + "
    " + "

    This is the documentation for the 4cpp lexer version 1.1. " + "The documentation is the newest piece of this lexer project " + "so it may still have problems. What is here should be correct " + "and mostly complete.

    " + "

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

    " + "
    "); +#endif + + append_sc(&out, + "
    " + "

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

    " + "

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

    " + "
    "); + +#undef MAJOR_SECTION +#define MAJOR_SECTION "2" + msection = 1; + + // TODO(allen): Write the 4coder system descriptions. + append_sc(&out, "\n

    §"MAJOR_SECTION" "); + append_sc(&out, sections[msection].display_string); + append_sc(&out, "

    "); + + append_sc(&out, "
    Coming Soon
    "); + +#undef MAJOR_SECTION +#define MAJOR_SECTION "3" + msection = 2; + + append_sc(&out, "\n

    §"MAJOR_SECTION" "); + append_sc(&out, sections[msection].display_string); + append_sc(&out, "

    "); + +#undef SECTION +#define SECTION MAJOR_SECTION".1" + + append_sc(&out, "

    §"SECTION" Function List

      "); + for (int32_t i = 0; i < unit_custom.set.count; ++i){ + print_item_in_list(&out, func_4ed_names.names[i].public_name, "_doc"); + } + append_sc(&out, "
    "); + +#undef SECTION +#define SECTION MAJOR_SECTION".2" + + append_sc(&out, "

    §"SECTION" Type List

      "); + for (int32_t i = 0; i < unit.set.count; ++i){ + print_item_in_list(&out, unit.set.items[i].name, "_doc"); + } + append_sc(&out, "
    "); + +#undef SECTION +#define SECTION MAJOR_SECTION".3" + + append_sc(&out, "

    §"SECTION" Function Descriptions

    "); + for (int32_t i = 0; i < unit_custom.set.count; ++i){ + Item_Node *item = &unit_custom.set.items[i]; + String name = func_4ed_names.names[i].public_name; + + append_sc (&out, "

    §"SECTION"."); + append_int_to_str(&out, i+1); + append_sc (&out, ": "); + append_ss (&out, name); + append_sc (&out, "

    "); + + print_function_html(&out, &used_links, item->cpp_name, item->ret, "", name, item->breakdown); + append_sc(&out, "
    "); + + print_function_docs(&out, part, name, item->doc_string); + + append_sc(&out, "

    "); + } + +#undef SECTION +#define SECTION MAJOR_SECTION".4" + + append_sc(&out, "

    §"SECTION" Type Descriptions

    "); + + int32_t I = 1; + for (int32_t i = 0; i < unit.set.count; ++i, ++I){ + print_item(&out, part, &used_links, unit.set.items + i, "_doc", 0, SECTION, I); + } + +#undef MAJOR_SECTION +#define MAJOR_SECTION "4" + msection = 3; + + append_sc(&out, "\n

    §"MAJOR_SECTION" "); + append_sc(&out, sections[msection].display_string); + append_sc(&out, "

    "); + +#undef SECTION +#define SECTION MAJOR_SECTION".1" + + append_sc(&out, "

    §"SECTION" String Intro

    "); + + append_sc(&out, "
    Coming Soon
    "); + +#undef SECTION +#define SECTION MAJOR_SECTION".2" + + append_sc(&out, "

    §"SECTION" String Function List

    "); + + append_sc(&out, "
      "); + for (int32_t i = 0; i < string_unit.set.count; ++i){ + print_item_in_list(&out, string_unit.set.items[i].name, "_doc"); + } + append_sc(&out, "
    "); + +#undef SECTION +#define SECTION MAJOR_SECTION".3" + + append_sc(&out, "

    §"SECTION" String Function Descriptions

    "); + + for (int32_t i = 0; i < string_unit.set.count; ++i){ + print_item(&out, part, &used_links, string_unit.set.items+i, "_doc", "", SECTION, i+1); + } + +#undef MAJOR_SECTION +#define MAJOR_SECTION "5" + msection = 4; + + append_sc(&out, "\n

    §"MAJOR_SECTION" "); + append_sc(&out, sections[msection].display_string); + append_sc(&out, "

    "); + +#undef SECTION +#define SECTION MAJOR_SECTION".1" + + append_sc(&out, "

    §"SECTION" Lexer Intro

    "); + + append_sc(&out, + "
    " + "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." + "
    "); + +#undef SECTION +#define SECTION MAJOR_SECTION".2" + + append_sc(&out, "

    §"SECTION" Lexer Function List

    "); + + append_sc(&out, "
      "); + for (int32_t i = 0; i < lexer_funcs_unit.set.count; ++i){ + print_item_in_list(&out, lexer_funcs_unit.set.items[i].name, "_doc"); + } + append_sc(&out, "
    "); + +#undef SECTION +#define SECTION MAJOR_SECTION".3" + + append_sc(&out, "

    §"SECTION" Lexer Types List

    "); + + append_sc(&out, "
      "); + for (int32_t i = 0; i < lexer_types_unit.set.count; ++i){ + print_item_in_list(&out, lexer_types_unit.set.items[i].name, "_doc"); + } + append_sc(&out, "
    "); + +#undef SECTION +#define SECTION MAJOR_SECTION".4" + + append_sc(&out, "

    §"SECTION" Lexer Function Descriptions

    "); + for (int32_t i = 0; i < lexer_funcs_unit.set.count; ++i){ + print_item(&out, part, &used_links, lexer_funcs_unit.set.items+i, "_doc", "", SECTION, i+1); + } + +#undef SECTION +#define SECTION MAJOR_SECTION".5" + + append_sc(&out, "

    §"SECTION" Lexer Type Descriptions

    "); + for (int32_t i = 0; i < lexer_types_unit.set.count; ++i){ + print_item(&out, part, &used_links, lexer_types_unit.set.items+i, "_doc", "", SECTION, i+1); + } + + + append_sc(&out, "
    "); + end_file_out(context); + } + else{ + // TODO(allen): warning + } +} + +int main(int argc, char **argv){ + if (argc == 4){ + generate_custom_headers(argv[1], argv[2], argv[3]); + } +} + +// BOTTOM + From 7f559c4016cba07f90cf5f9e649c1ddadd0be557 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Thu, 3 Nov 2016 00:57:26 -0400 Subject: [PATCH 3/7] setting up the site generator's general document system. --- 4ed_metagen.cpp | 4 +- site/4ed_site.ctm | Bin 1284 -> 1988 bytes site/abstract_document.h | 166 +++++++++++++++++++++++ meta_parser.cpp => site/meta_parser.cpp | 7 + site/sitegen.cpp | 170 +++++++++++++++++------- 5 files changed, 301 insertions(+), 46 deletions(-) create mode 100644 site/abstract_document.h rename meta_parser.cpp => site/meta_parser.cpp (99%) diff --git a/4ed_metagen.cpp b/4ed_metagen.cpp index a40c7be8..e585b9dd 100644 --- a/4ed_metagen.cpp +++ b/4ed_metagen.cpp @@ -23,7 +23,9 @@ #include #include "4coder_mem.h" -#include "meta_parser.cpp" + +// TODO(allen): In the end the metaprogramming base should be one sub-project, the site should be one sub-project, and this code generator should be one sub-project. +#include "site/meta_parser.cpp" #define InvalidPath Assert(!"Invalid path of execution") diff --git a/site/4ed_site.ctm b/site/4ed_site.ctm index 56574130238c0f18a0279f5ecd9ea15e9b30ee13..a204f9446f33df990f0a43d88467dca2c33eaa98 100644 GIT binary patch delta 717 zcmYk)O(?^07zgm*%$m@~&Cx}42{g`MhIxI~*7ip3 z<1A)lFN)zIEMNc*)W+9G$%9}`ve-(-zC9tfXL>2xGfl?xk+r>9GzP9fpwm;jN!|kQ z^oliVp0^13?5RYjYT^YKTq>(QjM=#HjZ^l$WTqwdkzeu{hV-P;WL&W8N-vn?_ub%# z#3dx-f;yQ=Og2J33&}-ARIq}T@@FM^0vtYQQj>8&^O0Xe#=u8WvW<-Wn^RFI`Mr>_ znu}=VG+zkMTkg75WE%z;^3xhB;DD(9tA&ggW=s!lWLz+^ukRq^eP?jMMRtM}dF}-= z_N9g@KRF;_Y}MNkM#Cqn`~T^F=3beDZ-@(Yc+3T49PoD8A0XpTX7Qc5-26QD{{RM9 Bw(lg%tn_mI509 diff --git a/site/abstract_document.h b/site/abstract_document.h new file mode 100644 index 00000000..896c2a0a --- /dev/null +++ b/site/abstract_document.h @@ -0,0 +1,166 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 25.02.2016 + * + * File editing view for 4coder + * + */ + +// TOP + +#if !defined(ABSTRACT_DOCUMENT_H) +#define ABSTRACT_DOCUMENT_H + +#define NotImplemented Assert(!"Not Implemented!") + +// Document Declaration + +struct Enriched_Text{ + int32_t t; +}; + +enum{ + Doc_Root, + Doc_Section, + Doc_Todo, + Doc_Element_List, + Doc_Full_Elements, +}; + +struct Document_Item{ + Document_Item *next; + int32_t type; + union{ + struct{ + Document_Item *first_child; + Document_Item *last_child; + String name; + } section; + + struct{ + Meta_Unit *unit; + } unit_elements; +}; +}; +static Document_Item null_document_item = {0}; + +struct Abstract_Document{ + // Document value members + Document_Item *root_item; + + // Document building members + Partition *part; + Document_Item *section_stack[16]; + int32_t section_top; +}; +static Abstract_Document null_abstract_document = {0}; + +static void +begin_document_description(Abstract_Document *doc, Partition *part){ + *doc = null_abstract_document; + doc->part = part; + + doc->root_item = push_struct(doc->part, Document_Item); + *doc->root_item = null_document_item; + doc->section_stack[doc->section_top] = doc->root_item; + doc->root_item->type = Doc_Root; +} + +static void +end_document_description(Abstract_Document *doc){ + Assert(doc->section_top == 0); +} + +static void +append_child(Document_Item *parent, Document_Item *item){ + Assert(parent->type == Doc_Root || parent->type == Doc_Section); + if (parent->section.last_child == 0){ + parent->section.first_child = item; + parent->section.last_child = item; + } + else{ + parent->section.last_child->next = item; + parent->section.last_child = item; + } +} + +static void +begin_section(Abstract_Document *doc, char *title){ + Assert(doc->section_top+1 < ArrayCount(doc->section_stack)); + + Document_Item *parent = doc->section_stack[doc->section_top]; + Document_Item *section = push_struct(doc->part, Document_Item); + *section = null_document_item; + doc->section_stack[++doc->section_top] = section; + + section->type = Doc_Section; + + int32_t title_len = str_size(title); + section->section.name = make_string_cap(push_array(doc->part, char, title_len+1), 0, title_len+1); + partition_align(doc->part, 8); + append_sc(§ion->section.name, title); + + append_child(parent, section); + } + +static void +end_section(Abstract_Document *doc){ + Assert(doc->section_top > 0); + --doc->section_top; +} + +static void +add_todo(Abstract_Document *doc){ + Assert(doc->section_top+1 < ArrayCount(doc->section_stack)); + + Document_Item *parent = doc->section_stack[doc->section_top]; + Document_Item *item = push_struct(doc->part, Document_Item); + *item = null_document_item; + item->type = Doc_Todo; + + append_child(parent, item); +} + +static void +add_element_list(Abstract_Document *doc, Meta_Unit *unit){ + Assert(doc->section_top+1 < ArrayCount(doc->section_stack)); + + Document_Item *parent = doc->section_stack[doc->section_top]; + Document_Item *item = push_struct(doc->part, Document_Item); + *item = null_document_item; + item->type = Doc_Element_List; + item->unit_elements.unit = unit; + + append_child(parent, item); +} + +static void +add_full_elements(Abstract_Document *doc, Meta_Unit *unit){ + Assert(doc->section_top+1 < ArrayCount(doc->section_stack)); + + Document_Item *parent = doc->section_stack[doc->section_top]; + Document_Item *item = push_struct(doc->part, Document_Item); + *item = null_document_item; + item->type = Doc_Full_Elements; + item->unit_elements.unit = unit; + + append_child(parent, item); +} + +static void +add_enriched_text(Abstract_Document *doc, Enriched_Text *text){ + NotImplemented; +} + +// Document Generation + +static void +generate_document_html(Out_Context *context, Abstract_Document *doc){ + +} + +#endif + +// BOTTOM + diff --git a/meta_parser.cpp b/site/meta_parser.cpp similarity index 99% rename from meta_parser.cpp rename to site/meta_parser.cpp index 8a1934bf..65badc77 100644 --- a/meta_parser.cpp +++ b/site/meta_parser.cpp @@ -1362,6 +1362,13 @@ compile_meta_unit(Partition *part, char *code_directory, char **files, Meta_Keyw return(unit); } +static Meta_Unit +compile_meta_unit(Partition *part, char *code_directory, char *file, Meta_Keywords *keywords, int32_t key_count){ + char *file_array[2] = {file, 0}; + Meta_Unit unit = compile_meta_unit(part, code_directory, file_array, keywords, key_count); + return(unit); +} + #endif // BOTTOM diff --git a/site/sitegen.cpp b/site/sitegen.cpp index 5a2c448a..69ff272c 100644 --- a/site/sitegen.cpp +++ b/site/sitegen.cpp @@ -22,9 +22,12 @@ #include "4coder_mem.h" #include "meta_parser.cpp" +#include "abstract_document.h" #define InvalidPath Assert(!"Invalid path of execution") +// TODO(allen): Move the Out_Context into it's own file. + typedef struct Out_Context{ char out_directory_space[256]; String out_directory; @@ -856,7 +859,34 @@ allocate_app_api(Partition *part, int32_t count){ } static void -generate_custom_headers(char *code_directory, char *src_directory, char *dst_directory){ +assert_files_are_equal(char *directory, char *filename1, char *filename2){ + char space[256]; + String name = make_fixed_width_string(space); + append_sc(&name, directory); + append_sc(&name, "\\"); + append_sc(&name, filename1); + terminate_with_null(&name); + + String file1 = file_dump(name.str); + + name.size = 0; + append_sc(&name, directory); + append_sc(&name, "\\"); + append_sc(&name, filename2); + terminate_with_null(&name); + + String file2 = file_dump(name.str); + + if (!match(file1, file2)){ + fprintf(stderr, "Failed transitional test: %s != %s\n", filename1, filename2); + } + else{ + fprintf(stderr, "Passed transitional test: %s == %s\n", filename1, filename2); + } + } + +static void +generate_site(char *code_directory, char *src_directory, char *dst_directory){ #define API_DOC "4coder_API.html" int32_t size = (512 << 20); @@ -879,45 +909,29 @@ generate_custom_headers(char *code_directory, char *src_directory, char *dst_dir #define ExpandArray(a) (a), (ArrayCount(a)) - // NOTE(allen): Parse the internal string file. - static char *string_files[] = { - "internal_4coder_string.cpp", - 0 - }; + // NOTE(allen): Parse the important code. + Meta_Unit custom_types_unit = compile_meta_unit(part, code_directory, "4coder_types.h", ExpandArray(meta_keywords)); - Meta_Unit string_unit = compile_meta_unit(part, code_directory, string_files, ExpandArray(meta_keywords)); + Meta_Unit lexer_funcs_unit = compile_meta_unit(part, code_directory, "4cpp_lexer.h", ExpandArray(meta_keywords)); - // NOTE(allen): Parse the lexer library - static char *lexer_types_files[] = { - "4cpp_lexer_types.h", - 0 - }; + Meta_Unit lexer_types_unit = compile_meta_unit(part, code_directory, "4cpp_lexer_types.h", ExpandArray(meta_keywords)); - Meta_Unit lexer_types_unit = compile_meta_unit(part, code_directory, lexer_types_files, ExpandArray(meta_keywords)); + Meta_Unit string_unit = compile_meta_unit(part, code_directory, "internal_4coder_string.cpp", ExpandArray(meta_keywords)); - static char *lexer_funcs_files[] = { - "4cpp_lexer.h", - 0 - }; - - Meta_Unit lexer_funcs_unit = compile_meta_unit(part, code_directory, lexer_funcs_files, ExpandArray(meta_keywords)); - - - // NOTE(allen): Parse the customization API files static char *functions_files[] = { "4ed_api_implementation.cpp", "win32_api_impl.cpp", 0 }; - Meta_Unit unit_custom = compile_meta_unit(part, code_directory, functions_files, ExpandArray(meta_keywords)); + Meta_Unit custom_funcs_unit = compile_meta_unit(part, code_directory, functions_files, ExpandArray(meta_keywords)); - // NOTE(allen): Compute and store variations of the function names - App_API func_4ed_names = allocate_app_api(part, unit_custom.set.count); + // NOTE(allen): Compute and store variations of the custom function names + App_API func_4ed_names = allocate_app_api(part, custom_funcs_unit.set.count); - for (int32_t i = 0; i < unit_custom.set.count; ++i){ - String name_string = unit_custom.set.items[i].name; + for (int32_t i = 0; i < custom_funcs_unit.set.count; ++i){ + String name_string = custom_funcs_unit.set.items[i].name; String *macro = &func_4ed_names.names[i].macro; String *public_name = &func_4ed_names.names[i].public_name; @@ -931,23 +945,88 @@ generate_custom_headers(char *code_directory, char *src_directory, char *dst_dir partition_align(part, 4); } - // NOTE(allen): Parse the customization API types - static char *type_files[] = { - "4coder_types.h", - 0 - }; - Meta_Unit unit = compile_meta_unit(part, code_directory, type_files, ExpandArray(meta_keywords)); + // NOTE(allen): Put together the abstract document + Abstract_Document doc = {0}; + begin_document_description(&doc, part); + + begin_section(&doc, "Intro"); + add_todo(&doc); + end_section(&doc); + + begin_section(&doc, "4coder Systems Overview"); + add_todo(&doc); + end_section(&doc); + + begin_section(&doc, "Types and Functions"); + { + begin_section(&doc, "Function List"); + add_element_list(&doc, &custom_funcs_unit); + end_section(&doc); + begin_section(&doc, "Type List"); + add_element_list(&doc, &custom_types_unit); + end_section(&doc); + begin_section(&doc, "Function Descriptions"); + add_full_elements(&doc, &custom_funcs_unit); + end_section(&doc); + begin_section(&doc, "Type Descriptions"); + add_full_elements(&doc, &custom_types_unit); + end_section(&doc); + } + end_section(&doc); + + begin_section(&doc, "String Library"); + { + begin_section(&doc, "String Library Intro"); + add_todo(&doc); + end_section(&doc); + begin_section(&doc, "String Function List"); + add_element_list(&doc, &string_unit); + end_section(&doc); + begin_section(&doc, "String Function Descriptions"); + add_full_elements(&doc, &string_unit); + end_section(&doc); + } + end_section(&doc); + + begin_section(&doc, "Lexer Library"); + { + begin_section(&doc, "Lexer Intro"); + add_todo(&doc); + end_section(&doc); + begin_section(&doc, "Lexer Function List"); + add_element_list(&doc, &lexer_funcs_unit); + end_section(&doc); + begin_section(&doc, "Lexer Type List"); + add_element_list(&doc, &lexer_types_unit); + end_section(&doc); + begin_section(&doc, "Lexer Function Descriptions"); + add_full_elements(&doc, &lexer_funcs_unit); + end_section(&doc); + begin_section(&doc, "Lexer Type Descriptions"); + add_full_elements(&doc, &lexer_types_unit); + end_section(&doc); + } + end_section(&doc); + + end_document_description(&doc); // NOTE(allen): Output String out = str_alloc(part, 10 << 20); Out_Context context = {0}; - set_context_directory(&context, dst_directory); - // Output Docs + // Output Docs - General Document Generator + if (begin_file_out(&context, "gen-test.html", &out)){ + generate_document_html(&context, &doc); + end_file_out(context); + } + else{ + // TODO(allen): warning + } + + // Output Docs - Direct Method if (begin_file_out(&context, API_DOC, &out)){ - Used_Links used_links = {0}; init_used_links(part, &used_links, 4000); @@ -1103,7 +1182,7 @@ generate_custom_headers(char *code_directory, char *src_directory, char *dst_dir #define SECTION MAJOR_SECTION".1" append_sc(&out, "

    §"SECTION" Function List

      "); - for (int32_t i = 0; i < unit_custom.set.count; ++i){ + for (int32_t i = 0; i < custom_funcs_unit.set.count; ++i){ print_item_in_list(&out, func_4ed_names.names[i].public_name, "_doc"); } append_sc(&out, "
    "); @@ -1112,8 +1191,8 @@ generate_custom_headers(char *code_directory, char *src_directory, char *dst_dir #define SECTION MAJOR_SECTION".2" append_sc(&out, "

    §"SECTION" Type List

      "); - for (int32_t i = 0; i < unit.set.count; ++i){ - print_item_in_list(&out, unit.set.items[i].name, "_doc"); + for (int32_t i = 0; i < custom_types_unit.set.count; ++i){ + print_item_in_list(&out, custom_types_unit.set.items[i].name, "_doc"); } append_sc(&out, "
    "); @@ -1121,8 +1200,8 @@ generate_custom_headers(char *code_directory, char *src_directory, char *dst_dir #define SECTION MAJOR_SECTION".3" append_sc(&out, "

    §"SECTION" Function Descriptions

    "); - for (int32_t i = 0; i < unit_custom.set.count; ++i){ - Item_Node *item = &unit_custom.set.items[i]; + for (int32_t i = 0; i < custom_funcs_unit.set.count; ++i){ + Item_Node *item = &custom_funcs_unit.set.items[i]; String name = func_4ed_names.names[i].public_name; append_sc (&out, "" + +#define HTML_DOC_ITEM_HEAD_STYLE "font-weight: 600;" + +#define HTML_DOC_ITEM_HEAD_INL_OPEN "" +#define HTML_DOC_ITEM_HEAD_INL_CLOSE "" + +#define HTML_DOC_ITEM_HEAD_OPEN "
    " +#define HTML_DOC_ITEM_HEAD_CLOSE "
    " + +#define HTML_DOC_ITEM_OPEN "
    " +#define HTML_DOC_ITEM_CLOSE "
    " + +#define HTML_EXAMPLE_CODE_OPEN "
    " +#define HTML_EXAMPLE_CODE_CLOSE "
    " + +struct Section_Counter{ + int32_t counter[16]; + int32_t nest_level; +}; + +static void +append_section_number(String *out, Section_Counter section_counter){ + for (int32_t i = 1; i <= section_counter.nest_level; ++i){ + append_int_to_str(out, section_counter.counter[i]); + if (i != section_counter.nest_level){ + append_sc(out, "."); + } + } +} + +static void +write_enriched_text_html(String *out, Enriched_Text *text){ + String source = text->source; + + append_sc(out, "
    "); + + // TODO(allen): get this working +#if 0 + for (String line = get_first_double_line(source); + line.str; + line = get_next_double_line(chunk, line)){ + append_sc(out, "

    "); + append_ss(out, line); + append_sc(out, "

    "); + } +#endif + append_ss(out, source); + + append_sc(out, "
    "); + } + +static void +doc_item_head_html(String *out, Document_Item *item, Section_Counter section_counter){ + switch (item->type){ + case Doc_Root: + { + append_sc(out, + "" + "" + ""); + append_ss(out, item->section.name); + append_sc(out, + "" + "" + "\n" + "" + "
    "); + + + append_sc(out, "

    "); + append_ss(out, item->section.name); + append_sc(out, "

    "); + }break; + + case Doc_Section: + { + if (section_counter.nest_level <= 1){ + if (item->section.id.size > 0){ + append_sc(out, "\n

    §"); + } + else{ + append_sc(out, "\n

    §"); + } + append_section_number(out, section_counter); + append_sc(out, " "); + append_ss(out, item->section.name); + append_sc(out, "

    "); + } + else{ + if (item->section.id.size > 0){ + append_sc(out, "

    §"); + } + else{ + append_sc(out, "

    §"); + } + append_section_number(out, section_counter); + append_sc(out, " "); + append_ss(out, item->section.name); + append_sc(out, "

    "); + } + }break; + + case Doc_Enriched_Text: + { + write_enriched_text_html(out, item->text.text); + }break; + + case Doc_Table_Of_Contents: + { + append_sc(out, "

    Table of Contents

    "); + }break; + } +} + +static void +doc_item_foot_html(String *out, Document_Item *item, Section_Counter section_counter){ + switch (item->type){ + case Doc_Root: + { + append_sc(out, "
    "); + }break; + + case Doc_Section: break; + + case Doc_Table_Of_Contents: break; + } +} + +static void +generate_item_html(String *out, Document_Item *item, Section_Counter *section_counter){ + Section_Counter sc = *section_counter; + doc_item_head_html(out, item, sc); + + if (item->type == Doc_Root || item->type == Doc_Section){ + int32_t level = ++section_counter->nest_level; + section_counter->counter[level] = 1; + for (Document_Item *m = item->section.first_child; + m != 0; + m = m->next){ + generate_item_html(out, m, section_counter); + } + --section_counter->nest_level; + ++section_counter->counter[section_counter->nest_level]; + } + + doc_item_foot_html(out, item, sc); +} + +static void +generate_document_html(String *out, Abstract_Document *doc){ + Section_Counter section_counter = {0}; + section_counter.counter[section_counter.nest_level] = 1; + generate_item_html(out, doc->root_item, §ion_counter); +} + +#endif + +// BOTTOM + diff --git a/site/abstract_document.h b/site/abstract_document.h deleted file mode 100644 index 896c2a0a..00000000 --- a/site/abstract_document.h +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Mr. 4th Dimention - Allen Webster - * - * 25.02.2016 - * - * File editing view for 4coder - * - */ - -// TOP - -#if !defined(ABSTRACT_DOCUMENT_H) -#define ABSTRACT_DOCUMENT_H - -#define NotImplemented Assert(!"Not Implemented!") - -// Document Declaration - -struct Enriched_Text{ - int32_t t; -}; - -enum{ - Doc_Root, - Doc_Section, - Doc_Todo, - Doc_Element_List, - Doc_Full_Elements, -}; - -struct Document_Item{ - Document_Item *next; - int32_t type; - union{ - struct{ - Document_Item *first_child; - Document_Item *last_child; - String name; - } section; - - struct{ - Meta_Unit *unit; - } unit_elements; -}; -}; -static Document_Item null_document_item = {0}; - -struct Abstract_Document{ - // Document value members - Document_Item *root_item; - - // Document building members - Partition *part; - Document_Item *section_stack[16]; - int32_t section_top; -}; -static Abstract_Document null_abstract_document = {0}; - -static void -begin_document_description(Abstract_Document *doc, Partition *part){ - *doc = null_abstract_document; - doc->part = part; - - doc->root_item = push_struct(doc->part, Document_Item); - *doc->root_item = null_document_item; - doc->section_stack[doc->section_top] = doc->root_item; - doc->root_item->type = Doc_Root; -} - -static void -end_document_description(Abstract_Document *doc){ - Assert(doc->section_top == 0); -} - -static void -append_child(Document_Item *parent, Document_Item *item){ - Assert(parent->type == Doc_Root || parent->type == Doc_Section); - if (parent->section.last_child == 0){ - parent->section.first_child = item; - parent->section.last_child = item; - } - else{ - parent->section.last_child->next = item; - parent->section.last_child = item; - } -} - -static void -begin_section(Abstract_Document *doc, char *title){ - Assert(doc->section_top+1 < ArrayCount(doc->section_stack)); - - Document_Item *parent = doc->section_stack[doc->section_top]; - Document_Item *section = push_struct(doc->part, Document_Item); - *section = null_document_item; - doc->section_stack[++doc->section_top] = section; - - section->type = Doc_Section; - - int32_t title_len = str_size(title); - section->section.name = make_string_cap(push_array(doc->part, char, title_len+1), 0, title_len+1); - partition_align(doc->part, 8); - append_sc(§ion->section.name, title); - - append_child(parent, section); - } - -static void -end_section(Abstract_Document *doc){ - Assert(doc->section_top > 0); - --doc->section_top; -} - -static void -add_todo(Abstract_Document *doc){ - Assert(doc->section_top+1 < ArrayCount(doc->section_stack)); - - Document_Item *parent = doc->section_stack[doc->section_top]; - Document_Item *item = push_struct(doc->part, Document_Item); - *item = null_document_item; - item->type = Doc_Todo; - - append_child(parent, item); -} - -static void -add_element_list(Abstract_Document *doc, Meta_Unit *unit){ - Assert(doc->section_top+1 < ArrayCount(doc->section_stack)); - - Document_Item *parent = doc->section_stack[doc->section_top]; - Document_Item *item = push_struct(doc->part, Document_Item); - *item = null_document_item; - item->type = Doc_Element_List; - item->unit_elements.unit = unit; - - append_child(parent, item); -} - -static void -add_full_elements(Abstract_Document *doc, Meta_Unit *unit){ - Assert(doc->section_top+1 < ArrayCount(doc->section_stack)); - - Document_Item *parent = doc->section_stack[doc->section_top]; - Document_Item *item = push_struct(doc->part, Document_Item); - *item = null_document_item; - item->type = Doc_Full_Elements; - item->unit_elements.unit = unit; - - append_child(parent, item); -} - -static void -add_enriched_text(Abstract_Document *doc, Enriched_Text *text){ - NotImplemented; -} - -// Document Generation - -static void -generate_document_html(Out_Context *context, Abstract_Document *doc){ - -} - -#endif - -// BOTTOM - diff --git a/site/out_context.cpp b/site/out_context.cpp new file mode 100644 index 00000000..f3dc8d45 --- /dev/null +++ b/site/out_context.cpp @@ -0,0 +1,75 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 25.02.2016 + * + * File editing view for 4coder + * + */ + +// TOP + +#if !defined(OUT_CONTEXT_4CODER) +#define OUT_CONTEXT_4CODER + +typedef struct Out_Context{ + char out_directory_space[256]; + String out_directory; + FILE *file; + String *str; +} Out_Context; + +static void +set_context_directory(Out_Context *context, char *dst_directory){ + context->out_directory = make_fixed_width_string(context->out_directory_space); + copy_sc(&context->out_directory, dst_directory); +} + +static int32_t +begin_file_out(Out_Context *out_context, char *filename, String *out){ + char str_space[512]; + String name = make_fixed_width_string(str_space); + if (out_context->out_directory.size > 0){ + append_ss(&name, out_context->out_directory); + append_sc(&name, "\\"); + } + append_sc(&name, filename); + terminate_with_null(&name); + + int32_t r = 0; + out_context->file = fopen(name.str, "wb"); + out_context->str = out; + out->size = 0; + if (out_context->file){ + r = 1; + } + + return(r); +} + +static void +dump_file_out(Out_Context out_context){ + fwrite(out_context.str->str, 1, out_context.str->size, out_context.file); + out_context.str->size = 0; +} + +static void +end_file_out(Out_Context out_context){ + dump_file_out(out_context); + fclose(out_context.file); +} + +static String +make_out_string(int32_t x){ + String str; + str.size = 0; + str.memory_size = x; + str.str = (char*)malloc(x); + return(str); +} + +#endif + +// BOTTOM + + diff --git a/site/sitegen.cpp b/site/sitegen.cpp index 69ff272c..98524102 100644 --- a/site/sitegen.cpp +++ b/site/sitegen.cpp @@ -22,68 +22,11 @@ #include "4coder_mem.h" #include "meta_parser.cpp" -#include "abstract_document.h" +#include "out_context.cpp" +#include "abstract_document.cpp" #define InvalidPath Assert(!"Invalid path of execution") -// TODO(allen): Move the Out_Context into it's own file. - -typedef struct Out_Context{ - char out_directory_space[256]; - String out_directory; - FILE *file; - String *str; -} Out_Context; - -static void -set_context_directory(Out_Context *context, char *dst_directory){ - context->out_directory = make_fixed_width_string(context->out_directory_space); - copy_sc(&context->out_directory, dst_directory); -} - -static int32_t -begin_file_out(Out_Context *out_context, char *filename, String *out){ - char str_space[512]; - String name = make_fixed_width_string(str_space); - if (out_context->out_directory.size > 0){ - append_ss(&name, out_context->out_directory); - append_sc(&name, "\\"); - } - append_sc(&name, filename); - terminate_with_null(&name); - - int32_t r = 0; - out_context->file = fopen(name.str, "wb"); - out_context->str = out; - out->size = 0; - if (out_context->file){ - r = 1; - } - - return(r); -} - -static void -dump_file_out(Out_Context out_context){ - fwrite(out_context.str->str, 1, out_context.str->size, out_context.file); - out_context.str->size = 0; -} - -static void -end_file_out(Out_Context out_context){ - dump_file_out(out_context); - fclose(out_context.file); -} - -static String -make_out_string(int32_t x){ - String str; - str.size = 0; - str.memory_size = x; - str.str = (char*)malloc(x); - return(str); -} - ////////////////////////////////////////////////////////////////////////////////////////////////// // @@ -243,6 +186,7 @@ print_macro_html(String *out, String name, Argument_Breakdown breakdown){ #define EXAMPLE_CODE_OPEN "
    " #define EXAMPLE_CODE_CLOSE "
    " +// TODO(allen): move string iteration utils somewhere cooler (4coder_string.h?) static String get_first_double_line(String source){ String line = {0}; @@ -877,7 +821,7 @@ assert_files_are_equal(char *directory, char *filename1, char *filename2){ String file2 = file_dump(name.str); - if (!match(file1, file2)){ + if (!match_ss(file1, file2)){ fprintf(stderr, "Failed transitional test: %s != %s\n", filename1, filename2); } else{ @@ -945,65 +889,69 @@ generate_site(char *code_directory, char *src_directory, char *dst_directory){ partition_align(part, 4); } + // NOTE(allen): Load enriched text materials + Enriched_Text introduction = load_enriched_text(part, src_directory, "introduction.txt"); // NOTE(allen): Put together the abstract document Abstract_Document doc = {0}; - begin_document_description(&doc, part); + begin_document_description(&doc, part, "4coder API Docs"); - begin_section(&doc, "Intro"); + add_table_of_contents(&doc); + + begin_section(&doc, "Introduction", "introduction"); + add_enriched_text(&doc, &introduction); + end_section(&doc); + + begin_section(&doc, "4coder Systems", "4coder_systems"); add_todo(&doc); end_section(&doc); - begin_section(&doc, "4coder Systems Overview"); - add_todo(&doc); - end_section(&doc); - - begin_section(&doc, "Types and Functions"); + begin_section(&doc, "Types and Functions", "types_and_functions"); { - begin_section(&doc, "Function List"); + begin_section(&doc, "Function List", 0); add_element_list(&doc, &custom_funcs_unit); end_section(&doc); - begin_section(&doc, "Type List"); + begin_section(&doc, "Type List", 0); add_element_list(&doc, &custom_types_unit); end_section(&doc); - begin_section(&doc, "Function Descriptions"); + begin_section(&doc, "Function Descriptions", 0); add_full_elements(&doc, &custom_funcs_unit); end_section(&doc); - begin_section(&doc, "Type Descriptions"); + begin_section(&doc, "Type Descriptions", 0); add_full_elements(&doc, &custom_types_unit); end_section(&doc); } end_section(&doc); - begin_section(&doc, "String Library"); + begin_section(&doc, "String Library", "string_library"); { - begin_section(&doc, "String Library Intro"); + begin_section(&doc, "String Library Intro", 0); add_todo(&doc); end_section(&doc); - begin_section(&doc, "String Function List"); + begin_section(&doc, "String Function List", 0); add_element_list(&doc, &string_unit); end_section(&doc); - begin_section(&doc, "String Function Descriptions"); + begin_section(&doc, "String Function Descriptions", 0); add_full_elements(&doc, &string_unit); end_section(&doc); } end_section(&doc); - begin_section(&doc, "Lexer Library"); + begin_section(&doc, "Lexer Library", "lexer_library"); { - begin_section(&doc, "Lexer Intro"); + begin_section(&doc, "Lexer Intro", 0); add_todo(&doc); end_section(&doc); - begin_section(&doc, "Lexer Function List"); + begin_section(&doc, "Lexer Function List", 0); add_element_list(&doc, &lexer_funcs_unit); end_section(&doc); - begin_section(&doc, "Lexer Type List"); + begin_section(&doc, "Lexer Type List", 0); add_element_list(&doc, &lexer_types_unit); end_section(&doc); - begin_section(&doc, "Lexer Function Descriptions"); + begin_section(&doc, "Lexer Function Descriptions", 0); add_full_elements(&doc, &lexer_funcs_unit); end_section(&doc); - begin_section(&doc, "Lexer Type Descriptions"); + begin_section(&doc, "Lexer Type Descriptions", 0); add_full_elements(&doc, &lexer_types_unit); end_section(&doc); } @@ -1018,7 +966,7 @@ generate_site(char *code_directory, char *src_directory, char *dst_directory){ // Output Docs - General Document Generator if (begin_file_out(&context, "gen-test.html", &out)){ - generate_document_html(&context, &doc); + generate_document_html(&out, &doc); end_file_out(context); } else{ @@ -1083,9 +1031,9 @@ generate_site(char *code_directory, char *src_directory, char *dst_directory){ "" "
    " - // "

    4cpp Lexing Library

    "); + //"

    4cpp Lexing Library

    "); - "

    4coder API

    "); + "

    4coder API Docs

    "); struct Section{ char *id_string; @@ -1102,7 +1050,7 @@ generate_site(char *code_directory, char *src_directory, char *dst_directory){ {"lexer_library", "Lexer Library"} }; - append_sc(&out, "

    Table of Contents

    ""
      "); + append_sc(&out, "

      Table of Contents

        "); int32_t section_count = ArrayCount(sections); for (int32_t i = 0; i < section_count; ++i){ @@ -1348,6 +1296,18 @@ generate_site(char *code_directory, char *src_directory, char *dst_directory){ // TODO(allen): warning } + // Here to test the file equality tester + // Output Docs - General Document Generator + if (begin_file_out(&context, "gen-test2.html", &out)){ + generate_document_html(&out, &doc); + end_file_out(context); + } + else{ + // TODO(allen): warning + } + + assert_files_are_equal(dst_directory, API_DOC, API_DOC); + assert_files_are_equal(dst_directory, "gen-test.html", "gen-test2.html"); assert_files_are_equal(dst_directory, API_DOC, "gen-test.html"); } diff --git a/site/source_material/introduction.txt b/site/source_material/introduction.txt new file mode 100644 index 00000000..fe5e083a --- /dev/null +++ b/site/source_material/introduction.txt @@ -0,0 +1,4 @@ + +This is the documentation for the 4cpp lexer version 1.1. The documentation is the newest piece of this lexer project so it may still have problems. What is here should be correct and mostly complete. + +If you have questions or discover errors please contact \CODE_STYLE{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 \CODE_STYLE{4coder.handmade.network} \ No newline at end of file From e8405a5c044405eded427344533d16fe576fd4c5 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Fri, 4 Nov 2016 22:59:35 -0400 Subject: [PATCH 5/7] fixed file loading bug --- 4coder_string.h | 82 ++++++++++++++++++++ 4ed.cpp | 10 ++- 4ed_api_implementation.cpp | 6 +- 4ed_file_view.cpp | 4 +- build.cpp | 12 +-- internal_4coder_string.cpp | 70 +++++++++++++++++ site/4ed_site.ctm | Bin 2948 -> 3412 bytes site/abstract_document.cpp | 61 +++++++++++++-- site/sitegen.cpp | 77 +----------------- site/source_material/introduction.txt | 4 +- site/source_material/lexer_introduction.txt | 4 + 11 files changed, 237 insertions(+), 93 deletions(-) create mode 100644 site/source_material/lexer_introduction.txt diff --git a/4coder_string.h b/4coder_string.h index 5fc78e27..11f55dad 100644 --- a/4coder_string.h +++ b/4coder_string.h @@ -169,6 +169,10 @@ FSTRING_LINK fstr_bool remove_extension(String *str); FSTRING_LINK fstr_bool remove_last_folder(String *str); FSTRING_LINK fstr_bool string_set_match_table(void *str_set, int32_t item_size, int32_t count, String str, int32_t *match_index); FSTRING_LINK fstr_bool string_set_match(String *str_set, int32_t count, String str, int32_t *match_index); +FSTRING_LINK String get_first_double_line(String source); +FSTRING_LINK String get_next_double_line(String source, String line); +FSTRING_LINK String get_next_word(String source, String prev_word); +FSTRING_LINK String get_first_word(String source); #endif @@ -1919,6 +1923,84 @@ string_set_match(String *str_set, int32_t count, String str, int32_t *match_inde } #endif +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK String +get_first_double_line(String source){ + String line = {0}; + int32_t pos0 = find_substr_s(source, 0, make_lit_string("\n\n")); + int32_t pos1 = find_substr_s(source, 0, make_lit_string("\r\n\r\n")); + if (pos1 < pos0){ + pos0 = pos1; + } + line = substr(source, 0, pos0); + return(line); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK String +get_next_double_line(String source, String line){ + String next = {0}; + int32_t pos = (int32_t)(line.str - source.str) + line.size; + int32_t start = 0, pos0 = 0, pos1 = 0; + + if (pos < source.size){ + //Assert(source.str[pos] == '\n' || source.str[pos] == '\r'); + start = pos + 1; + + if (start < source.size){ + pos0 = find_substr_s(source, start, make_lit_string("\n\n")); + pos1 = find_substr_s(source, start, make_lit_string("\r\n\r\n")); + if (pos1 < pos0){ + pos0 = pos1; + } + next = substr(source, start, pos0 - start); + } + } + + return(next); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK String +get_next_word(String source, String prev_word){ + + String word = {0}; + int32_t pos0 = (int32_t)(prev_word.str - source.str) + prev_word.size; + int32_t pos1 = 0; + char c = 0; + + for (; pos0 < source.size; ++pos0){ + c = source.str[pos0]; + if (!(char_is_whitespace(c) || c == '(' || c == ')')){ + break; + } + } + + if (pos0 < source.size){ + for (pos1 = pos0; pos1 < source.size; ++pos1){ + c = source.str[pos1]; + if (char_is_whitespace(c) || c == '(' || c == ')'){ + break; + } + } + + word = substr(source, pos0, pos1 - pos0); + } + + return(word); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK String +get_first_word(String source){ + String start_str = make_string(source.str, 0); + String word = get_next_word(source, start_str); + return(word); +} +#endif #ifndef FSTRING_EXPERIMENTAL #define FSTRING_EXPERIMENTAL diff --git a/4ed.cpp b/4ed.cpp index 421d208a..5b2f3b89 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -361,6 +361,8 @@ COMMAND_DECL(reopen){ if (buffer){ if (system->load_file(handle, buffer, size)){ + system->load_close(handle); + General_Memory *general = &models->mem.general; File_Edit_Positions edit_poss[16]; @@ -395,11 +397,15 @@ COMMAND_DECL(reopen){ file->settings.unwrapped_lines); } } + else{ + system->load_close(handle); + } + } + else{ + system->load_close(handle); } end_temp_memory(temp); - - system->load_close(handle); } } } diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index 8eeaf17f..20bae7c8 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -1091,6 +1091,7 @@ DOC_SEE(begin_buffer_creation) } if (system->load_file(handle, buffer, size)){ + system->load_close(handle); file = working_set_alloc_always(system, working_set, general); if (file){ buffer_bind_file(system, general, working_set, file, canon.name); @@ -1099,12 +1100,13 @@ DOC_SEE(begin_buffer_creation) fill_buffer_summary(&result, file, cmd); } } + else{ + system->load_close(handle); + } if (in_general_mem){ general_memory_free(system, general, buffer); } - - system->load_close(handle); } else if (!(flags & BufferCreate_NeverNew)){ file = working_set_alloc_always(system, working_set, general); diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index 290ed873..806cd25c 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -3792,10 +3792,12 @@ view_open_file(System_Functions *system, Models *models, View *view, String file } if (system->load_file(handle, buffer, size)){ + system->load_close(handle); init_normal_file(system, models, file, buffer, size); } - + else{ system->load_close(handle); + } if (gen_buffer){ general_memory_free(system, general, buffer); diff --git a/build.cpp b/build.cpp index 8f2c1d72..c9bfa18c 100644 --- a/build.cpp +++ b/build.cpp @@ -822,17 +822,17 @@ do_buildsuper(char *cdir){ //terminate_with_null(&str); //buildsuper(cdir, BUILD_DIR, str.str); #if defined(IS_WINDOWS) - copy_sc(&str, "../code/internal_4coder_tests.cpp"); - terminate_with_null(&str); - buildsuper(cdir, BUILD_DIR, str.str); + //copy_sc(&str, "../code/internal_4coder_tests.cpp"); + //terminate_with_null(&str); + //buildsuper(cdir, BUILD_DIR, str.str); #else copy_sc(&str, "../code/power/4coder_experiments.cpp"); terminate_with_null(&str); buildsuper(cdir, BUILD_DIR, str.str); #endif - //copy_sc(&str, "../code/power/4coder_casey.cpp"); - //terminate_with_null(&str); - //buildsuper(cdir, BUILD_DIR, str.str); + copy_sc(&str, "../code/power/4coder_casey.cpp"); + terminate_with_null(&str); + buildsuper(cdir, BUILD_DIR, str.str); //copy_sc(&str, "../4vim/4coder_chronal.cpp"); //terminate_with_null(&str); //buildsuper(cdir, BUILD_DIR, str.str); diff --git a/internal_4coder_string.cpp b/internal_4coder_string.cpp index 3c35554e..d7672859 100644 --- a/internal_4coder_string.cpp +++ b/internal_4coder_string.cpp @@ -1799,6 +1799,76 @@ DOC_SEE(match) */{ return(result); } +API_EXPORT FSTRING_LINK String +get_first_double_line(String source){ + String line = {0}; + int32_t pos0 = find_substr_s(source, 0, make_lit_string("\n\n")); + int32_t pos1 = find_substr_s(source, 0, make_lit_string("\r\n\r\n")); + if (pos1 < pos0){ + pos0 = pos1; + } + line = substr(source, 0, pos0); + return(line); +} + +API_EXPORT FSTRING_LINK String +get_next_double_line(String source, String line){ + String next = {0}; + int32_t pos = (int32_t)(line.str - source.str) + line.size; + int32_t start = 0, pos0 = 0, pos1 = 0; + + if (pos < source.size){ + //Assert(source.str[pos] == '\n' || source.str[pos] == '\r'); + start = pos + 1; + + if (start < source.size){ + pos0 = find_substr_s(source, start, make_lit_string("\n\n")); + pos1 = find_substr_s(source, start, make_lit_string("\r\n\r\n")); + if (pos1 < pos0){ + pos0 = pos1; + } + next = substr(source, start, pos0 - start); + } + } + + return(next); +} + +API_EXPORT FSTRING_LINK String +get_next_word(String source, String prev_word){ + + String word = {0}; + int32_t pos0 = (int32_t)(prev_word.str - source.str) + prev_word.size; + int32_t pos1 = 0; + char c = 0; + + for (; pos0 < source.size; ++pos0){ + c = source.str[pos0]; + if (!(char_is_whitespace(c) || c == '(' || c == ')')){ + break; + } + } + + if (pos0 < source.size){ + for (pos1 = pos0; pos1 < source.size; ++pos1){ + c = source.str[pos1]; + if (char_is_whitespace(c) || c == '(' || c == ')'){ + break; + } + } + + word = substr(source, pos0, pos1 - pos0); + } + + return(word); +} + +API_EXPORT FSTRING_LINK String +get_first_word(String source){ + String start_str = make_string(source.str, 0); + String word = get_next_word(source, start_str); + return(word); +} #ifndef FSTRING_EXPERIMENTAL #define FSTRING_EXPERIMENTAL diff --git a/site/4ed_site.ctm b/site/4ed_site.ctm index ff554d873870113f192d00a08b1b0dce00f5e0ac..f0a30ff6ec92f00e0f460aee2d6cce2fa9e4b7a5 100644 GIT binary patch delta 475 zcmZn>zaq7vg}Yv>Wx|`CW|tV585kJOG69KIu`720`HVnj4-lsnZMNSH<<|oFA7&W2 z!T5PVe)pcpC>S3kzel7t5yr0r@+($OOat*j=Dz`&fAe0;9TJ;P4N|2kHO1z}@mNl7p}DXlKLtAO{=! zv*f|}wLtqBPE~rBBLo;2Bp)|b!T8lc4V{73O)!2hkna+Ir3=Id`Dj1TLN^udNihBf zAb)m!%5)gNAIRU+X}$u+pAY13yVblI#y=Yj6j"); - // TODO(allen): get this working -#if 0 for (String line = get_first_double_line(source); line.str; - line = get_next_double_line(chunk, line)){ + line = get_next_double_line(source, line)){ + String l = skip_chop_whitespace(line); append_sc(out, "

        "); - append_ss(out, line); + + //append_ss(out, l); + int32_t start = 0, i = 0; + for (; i < l.size; ++i){ + if (l.str[i] == '\\'){ + append_ss(out, substr(l, start, i-start)); + + int32_t command_start = i+1; + int32_t command_end = command_start; + for (; command_end < l.size; ++command_end){ + if (!char_is_alpha_numeric(l.str[command_end])){ + break; + } + } + + if (command_end == command_start){ + if (command_end < l.size && l.str[command_end] == '\\'){ + ++command_end; + } + } + + String command_string = substr(l, command_start, command_end - command_start); + + static String enriched_commands[] = { + make_lit_string("\\"), + make_lit_string("VERSION"), + make_lit_string("CODE_STYLE"), + }; + + int32_t match_index = 0; + if (string_set_match(enriched_commands, ArrayCount(enriched_commands), command_string, &match_index)){ + switch (match_index){ + case 0: append_sc(out, "\\"); break; + case 1: append_sc(out, VERSION); break; + case 2: append_sc(out, " TEST "); break; + } + } + else{ + append_sc(out,"! Doc generator error: unrecognized command !"); + fprintf(stderr, "error: Unrecognized command %.*s\n", command_string.size, command_string.str); + } + + i = command_end; + start = i; + } + } + + if (start != i){ + append_ss(out, substr(l, start, i-start)); + } + append_sc(out, "

        "); } -#endif - append_ss(out, source); append_sc(out, "
    "); } @@ -292,7 +339,9 @@ doc_item_head_html(String *out, Document_Item *item, Section_Counter section_cou "" "" ""); + append_ss(out, item->section.name); + append_sc(out, "" "