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
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
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
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_PP_ERROR_MESSAGE = 21
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_TYPE_DECLARATION = 28
CPP_TOKEN_KEY_ACCESS = 29
CPP_TOKEN_KEY_LINKAGE = 30
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_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_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_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_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_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_MUL = 84
This type is for parser use, it is not output by the lexer.
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_BIT_AND = 97
This type is for parser use, it is not output by the lexer.
CPP_TOKEN_TERNARY_QMARK = 102
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 57de388b..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);
@@ -217,7 +239,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
@@ -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..11f55dad 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,183 @@ 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);
+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
#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 +260,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 +268,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 +276,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 +284,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 +292,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 +300,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 +308,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 +316,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 +324,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 +332,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 +340,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 +348,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 +362,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 +373,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 +384,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 +394,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 +407,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 +419,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 +434,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 +446,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 +458,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 +468,7 @@ skip_chop_whitespace(String str)
#endif
#if !defined(FSTRING_GUARD)
-FSTRING_INLINE String
+ FSTRING_INLINE String
tailstr(String str)
{
String result;
@@ -482,7 +486,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 +501,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 +518,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 +526,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 +542,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 +557,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 +572,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 +581,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 +590,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 +603,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 +619,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 +635,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 +653,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 +661,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 +678,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 +693,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 +709,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 +718,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 +727,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 +740,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 +756,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 +769,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 +792,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 +801,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 +829,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 +839,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 +849,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 +859,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 +876,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 +893,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 +922,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 +951,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 +982,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 +1013,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 +1046,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 +1054,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 +1062,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 +1070,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 +1082,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 +1096,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 +1109,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 +1127,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 +1146,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 +1165,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 +1173,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 +1181,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 +1189,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 +1203,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 +1214,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 +1225,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 +1238,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 +1246,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 +1265,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 +1288,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 +1300,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 +1311,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 +1329,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 +1342,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 +1353,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 +1371,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 +1384,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 +1414,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 +1430,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 +1478,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 +1490,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 +1509,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 +1548,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 +1583,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 +1593,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 +1611,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 +1622,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 +1637,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 +1652,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 +1671,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 +1689,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 +1706,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 +1732,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 +1761,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 +1786,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 +1797,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 +1819,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 +1838,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 +1856,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 +1868,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 +1884,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 +1899,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,13 +1916,91 @@ 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);
}
#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/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.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 49d943cc..1ad8db02 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;
@@ -1044,6 +1091,7 @@ End_Buffer_Creation(Application_Links *app, Buffer_Creation_Data *data){
}
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);
@@ -1052,12 +1100,13 @@ End_Buffer_Creation(Application_Links *app, Buffer_Creation_Data *data){
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);
@@ -1073,114 +1122,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);
}
@@ -1201,14 +1143,16 @@ DOC_RETURN(This call returns non-zero on success.)
Editing_File *file = imp_get_file(cmd, buffer);
if (file){
+ if (file_get_sync(file) != DirtyState_UpToDate){
result = true;
Partition *part = &models->mem.part;
Temp_Memory temp = begin_temp_memory(part);
String name = make_string_terminated(part, filename, filename_len);
- save_file_to_name(system, &models->mem, file, name.str);
- end_temp_memory(temp);
- }
+ save_file_to_name(system, &models->mem, file, name.str);
+ end_temp_memory(temp);
+ }
+ }
return(result);
}
@@ -1588,8 +1532,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 +2054,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 +2205,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_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/4ed_metagen.cpp b/4ed_metagen.cpp
index 2bad4c2c..e585b9dd 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"
@@ -22,32 +24,43 @@
#include "4coder_mem.h"
+// 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")
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 +186,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 +356,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 +370,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 +397,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 +415,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, "
");
- }
- }
-
- 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, "