From 9a5d57f96151a40e73e8b6998deeea5d21882f04 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Fri, 2 Sep 2016 15:39:38 -0400 Subject: [PATCH] changed function_set in metagen so that it is not structure of arrays any more; introduced item type --- 4coder_API.html | 80 +++-- 4coder_keycodes.h | 2 +- 4coder_string.h | 31 ++ 4cpp_lexer_tables.c | 14 +- 4ed_metagen.cpp | 642 +++++++++++++++++++------------------ 4ed_style.h | 68 ++-- build.c | 4 +- internal_4coder_string.cpp | 38 ++- 8 files changed, 491 insertions(+), 388 deletions(-) diff --git a/4coder_API.html b/4coder_API.html index 9ac39eda..1c42b978 100644 --- a/4coder_API.html +++ b/4coder_API.html @@ -1176,6 +1176,7 @@ Coming Soon
  • to_upper_cc
  • to_upper_ss
  • to_upper_s
  • +
  • to_camel_cc
  • int_to_str_size
  • int_to_str
  • append_int_to_str
  • @@ -1967,8 +1968,8 @@ void to_upper_cc(
    dst
    -
    The destination buffer to receive the converted string. This must be large -enough to contain all of src and a null terminator.
    +
    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.

    @@ -1979,7 +1980,7 @@ void to_upper_ss(
    Parameters
    src
    -
    The source string to conver to uppercase.
    +
    The source string to convert to uppercase.
    dst
    @@ -1998,153 +1999,170 @@ void to_upper_s(
    The string to be converted to all uppercase.
    Description
    This version of to_upper converts str to uppercase in place.

    -

    §4.3.86: int_to_str_size

    +

    §4.3.86: 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.87: 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.87: int_to_str

    +

    §4.3.88: 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.88: append_int_to_str

    +

    §4.3.89: 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.89: u64_to_str_size

    +

    §4.3.90: 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.90: u64_to_str

    +

    §4.3.91: 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.91: append_u64_to_str

    +

    §4.3.92: 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.92: float_to_str_size

    +

    §4.3.93: 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.93: append_float_to_str

    +

    §4.3.94: 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.94: float_to_str

    +

    §4.3.95: 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.95: str_is_int_c

    +

    §4.3.96: 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.96: str_is_int_s

    +

    §4.3.97: 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.97: str_to_int_c

    +

    §4.3.98: 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.98: str_to_int_s

    +

    §4.3.99: 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.99: hexchar_to_int

    +

    §4.3.100: 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.100: int_to_hexchar

    +

    §4.3.101: 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.101: hexstr_to_int

    +

    §4.3.102: 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.102: color_to_hexstr

    +

    §4.3.103: 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.103: hexstr_to_color

    +

    §4.3.104: 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.104: reverse_seek_slash_pos

    +

    §4.3.105: 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.105: reverse_seek_slash

    +

    §4.3.106: 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.106: front_of_directory

    +

    §4.3.107: 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.107: path_of_directory

    +

    §4.3.108: 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.108: set_last_folder_sc

    +

    §4.3.109: set_last_folder_sc

    fstr_bool set_last_folder_sc(
    String *dir,
    char *folder_name,
    char slash
    ) @@ -2164,7 +2182,7 @@ at the end of 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.109: set_last_folder_ss

    +

    §4.3.110: set_last_folder_ss

    fstr_bool set_last_folder_ss(
    String *dir,
    String folder_name,
    char slash
    ) @@ -2183,27 +2201,27 @@ fstr_bool set_last_folder_ss(
    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.110: file_extension

    +

    §4.3.111: 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.111: remove_extension

    +

    §4.3.112: 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.112: remove_last_folder

    +

    §4.3.113: 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.113: string_set_match

    +

    §4.3.114: string_set_match

    fstr_bool string_set_match(
    String *str_set,
    int32_t count,
    String str,
    int32_t *match_index
    ) diff --git a/4coder_keycodes.h b/4coder_keycodes.h index 484b40d7..ef638bec 100644 --- a/4coder_keycodes.h +++ b/4coder_keycodes.h @@ -1,4 +1,4 @@ -enum Key_Code_Names{ +enum{ key_back = 1, key_up = 2, key_down = 3, diff --git a/4coder_string.h b/4coder_string.h index daf69684..bf954f63 100644 --- a/4coder_string.h +++ b/4coder_string.h @@ -138,6 +138,7 @@ 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 *src, String *dst); 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); @@ -232,6 +233,7 @@ FSTRING_INLINE void to_lower(String *str); FSTRING_INLINE void to_upper(char *src, char *dst); FSTRING_INLINE void to_upper(String *src, String *dst); FSTRING_INLINE void to_upper(String *str); +FSTRING_INLINE void to_camel(char *src, char *dst); FSTRING_INLINE int32_t str_is_int(char *str); FSTRING_INLINE fstr_bool str_is_int(String str); FSTRING_INLINE int32_t str_to_int(char *str); @@ -366,6 +368,8 @@ FSTRING_INLINE void to_upper(String *src, String *dst){(to_upper_ss(src,dst));} 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 @@ -1503,6 +1507,33 @@ to_upper_s(String *str){ } #endif + +#if defined(FSTRING_IMPLEMENTATION) +FSTRING_LINK void +to_camel_cc(char *src, char *dst){ + char *c, ch; + int32_t is_first = 1; + for (c = src; *c != 0; ++c){ + ch = *c; + if (char_is_alpha_numeric_true(ch)){ + if (is_first){ + is_first = 0; + ch = char_to_upper(ch); + } + else{ + ch = char_to_lower(ch); + } + } + else{ + is_first = 1; + } + *dst++ = ch; + } + *dst = 0; +} +#endif + + // // String <-> Number Conversions // diff --git a/4cpp_lexer_tables.c b/4cpp_lexer_tables.c index 9efef62d..f05d4125 100644 --- a/4cpp_lexer_tables.c +++ b/4cpp_lexer_tables.c @@ -57,7 +57,7 @@ uint8_t main_fsm_table[] = { 33,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 24,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,25,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 37,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, -26,41,42,43,44, 5, 6, 5,10,10, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,27,67,29,69,70,71,72,73,74,75,76,77,78,39, +26,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,27,67,29,69,70,71,72,73,74,75,76,77,78,39, 1, 1,42, 4, 4, 5, 6, 5, 8, 9, 8,51,52,53,54,55,16,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 1, 1,42, 4, 4, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 40,41,42,43,44, 7, 7, 5,10,10, 8,51,52,53,54,55,56,57,19,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, @@ -137,7 +137,7 @@ uint8_t pp_macro_fsm_table[] = { 33,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 24,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,25,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 37,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, -26,41,42,43,44, 5, 6, 5,10,10, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,27,67,29,69,70,71,72,73,74,75,76,77,78,39, +26,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,27,67,29,69,70,71,72,73,74,75,76,77,78,39, 1, 1,42, 4, 4, 5, 6, 5, 8, 9, 8,51,52,53,54,55,16,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 1, 1,42, 4, 4, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 40,41,42,43,44, 7, 7, 5,10,10, 8,51,52,53,54,55,56,57,19,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, @@ -177,7 +177,7 @@ uint8_t pp_identifier_fsm_table[] = { 33,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 24,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,25,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 37,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, -26,41,42,43,44, 5, 6, 5,10,10, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,27,67,29,69,70,71,72,73,74,75,76,77,78,39, +26,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,27,67,29,69,70,71,72,73,74,75,76,77,78,39, 1, 1,42, 4, 4, 5, 6, 5, 8, 9, 8,51,52,53,54,55,16,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 1, 1,42, 4, 4, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 40,41,42,43,44, 7, 7, 5,10,10, 8,51,52,53,54,55,56,57,19,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, @@ -217,7 +217,7 @@ uint8_t pp_body_if_fsm_table[] = { 33,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 24,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,25,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 37,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, -26,41,42,43,44, 5, 6, 5,10,10, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,27,67,29,69,70,71,72,73,74,75,76,77,78,39, +26,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,27,67,29,69,70,71,72,73,74,75,76,77,78,39, 1, 1,42, 4, 4, 5, 6, 5, 8, 9, 8,51,52,53,54,55,16,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 1, 1,42, 4, 4, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 40,41,42,43,44, 7, 7, 5,10,10, 8,51,52,53,54,55,56,57,19,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, @@ -257,7 +257,7 @@ uint8_t pp_body_fsm_table[] = { 33,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 24,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,25,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 37,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, -26,41,42,43,44, 5, 6, 5,10,10, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,27,67,29,69,70,71,72,73,74,75,76,77,78,39, +26,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,27,67,29,69,70,71,72,73,74,75,76,77,78,39, 1, 1,42, 4, 4, 5, 6, 5, 8, 9, 8,51,52,53,54,55,16,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 1, 1,42, 4, 4, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 40,41,42,43,44, 7, 7, 5,10,10, 8,51,52,53,54,55,56,57,19,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, @@ -297,7 +297,7 @@ uint8_t pp_number_fsm_table[] = { 33,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 24,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,25,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 37,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, -26,41,42,43,44, 5, 6, 5,10,10, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,27,67,29,69,70,71,72,73,74,75,76,77,78,39, +26,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,27,67,29,69,70,71,72,73,74,75,76,77,78,39, 1, 1,42, 4, 4, 5, 6, 5, 8, 9, 8,51,52,53,54,55,16,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 1, 1,42, 4, 4, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 40,41,42,43,44, 7, 7, 5,10,10, 8,51,52,53,54,55,56,57,19,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, @@ -349,7 +349,7 @@ uint8_t pp_junk_fsm_table[] = { 33,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 24,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,25,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 37,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, -26,41,42,43,44, 5, 6, 5,10,10, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,27,67,29,69,70,71,72,73,74,75,76,77,78,39, +26,41,42,43,44, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,27,67,29,69,70,71,72,73,74,75,76,77,78,39, 1, 1,42, 4, 4, 5, 6, 5, 8, 9, 8,51,52,53,54,55,16,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 1, 1,42, 4, 4, 5, 6, 5, 8, 9, 8,51,52,53,54,55,56,57,18,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, 40,41,42,43,44, 7, 7, 5,10,10, 8,51,52,53,54,55,56,57,19,18,20,20,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,39, diff --git a/4ed_metagen.cpp b/4ed_metagen.cpp index 7223b286..0516bae5 100644 --- a/4ed_metagen.cpp +++ b/4ed_metagen.cpp @@ -23,54 +23,39 @@ #include "4coder_mem.h" -struct Struct_Field{ - char *type; - char *name; -}; +typedef struct Out_Context{ + FILE *file; + String *str; +} Out_Context; -void to_camel(char *src, char *dst){ - char *c, ch; - int32_t is_first = 1; - for (c = src; *c != 0; ++c){ - ch = *c; - if (char_is_alpha_numeric_true(ch)){ - if (is_first){ - is_first = 0; - ch = char_to_upper(ch); - } - else{ - ch = char_to_lower(ch); - } - } - else{ - is_first = 1; - } - *dst++ = ch; +static int32_t +begin_file_out(Out_Context *out_context, char *filename, String *out){ + int32_t r = 0; + out_context->file = fopen(filename, "wb"); + out_context->str = out; + out->size = 0; + if (out_context->file){ + r = 1; } - *dst = 0; + return(r); } -void struct_begin(FILE *file, char *name){ - fprintf(file, "struct %s{\n", name); +static void +end_file_out(Out_Context out_context){ + fwrite(out_context.str->str, 1, out_context.str->size, out_context.file); + fclose(out_context.file); } -void struct_fields(FILE *file, Struct_Field *fields, int32_t count){ - int32_t i; - for (i = 0; i < count; ++i){ - fprintf(file, " %s %s;\n", fields[i].type, fields[i].name); - } +static String +make_out_string(int32_t x){ + String str; + str.size = 0; + str.memory_size = x; + str.str = (char*)malloc(x); + return(str); } -void struct_end(FILE *file){ - fprintf(file, "};\n\n"); -} - - -void enum_begin(FILE *file, char *name){ - fprintf(file, "enum %s{\n", name); -} - - +////////////////////////////////////////////////////////////////////////////////////////////////// char *keys_that_need_codes[] = { "back", "up", @@ -109,54 +94,82 @@ char *keys_that_need_codes[] = { void generate_keycode_enum(){ - FILE *file; char *filename_keycodes = "4coder_keycodes.h"; - int32_t i, count; + Out_Context context = {0}; + int32_t i = 0, count = 0; unsigned char code = 1; - file = fopen(filename_keycodes, "wb"); - fprintf(file, "enum Key_Code_Names{\n"); - count = ArrayCount(keys_that_need_codes); - for (i = 0; i < count; i){ - if (strcmp(keys_that_need_codes[i], "f1") == 0 && code < 0x7F){ - code = 0x7F; - } - switch (code){ - case '\n': code++; break; - case '\t': code++; break; - case 0x20: code = 0x7F; break; - default: - fprintf(file, "key_%s = %d,\n", keys_that_need_codes[i++], code++); - break; - } - } - fprintf(file, "};\n"); + String out = make_out_string(10 << 20); - fprintf(file, - "static char*\n" - "global_key_name(int32_t key_code, int32_t *size){\n" - "char *result = 0;\n" - "switch(key_code){\n" - ); - for (i = 0; i < count; ++i){ - fprintf(file, - "case key_%s: result = \"%s\"; *size = sizeof(\"%s\")-1; break;\n", - keys_that_need_codes[i], - keys_that_need_codes[i], - keys_that_need_codes[i] - ); + if (begin_file_out(&context, filename_keycodes, &out)){ + count = ArrayCount(keys_that_need_codes); + + append_sc(&out, "enum{\n"); + for (i = 0; i < count; i){ + if (strcmp(keys_that_need_codes[i], "f1") == 0 && code < 0x7F){ + code = 0x7F; + } + switch (code){ + case '\n': code++; break; + case '\t': code++; break; + case 0x20: code = 0x7F; break; + default: + append_sc(&out, "key_"); + append_sc(&out, keys_that_need_codes[i++]); + append_sc(&out, " = "); + append_int_to_str(&out, code++); + append_sc(&out, ",\n"); + break; + } + } + append_sc(&out, "};\n"); + + append_sc(&out, + "static char*\n" + "global_key_name(int32_t key_code, int32_t *size){\n" + "char *result = 0;\n" + "switch(key_code){\n"); + + for (i = 0; i < count; ++i){ + append_sc(&out, "case key_"); + append_sc(&out, keys_that_need_codes[i]); + append_sc(&out, ": result = \""); + append_sc(&out, keys_that_need_codes[i]); + append_sc(&out, "\"; *size = sizeof(\""); + append_sc(&out, keys_that_need_codes[i]); + append_sc(&out, "\")-1; break;\n"); + } + + append_sc(&out, + "}\n" + "return(result);\n" + "}\n"); + + end_file_out(context); } - fprintf(file, - "}\n" - "return(result);\n" - "}\n" - ); - - fclose(file); } ////////////////////////////////////////////////////////////////////////////////////////////////// -char* bar_style_fields[] = { +static void +struct_begin(String *str, char *name){ + append_sc(str, "struct "); + append_sc(str, name); + append_sc(str, "{\n"); +} + +static void +enum_begin(String *str, char *name){ + append_sc(str, "enum "); + append_sc(str, name); + append_sc(str, "{\n"); +} + +static void +struct_end(String *str){ + append_sc(str, "};\n\n"); +} + +static char* bar_style_fields[] = { "bar", "bar_active", "base", @@ -164,7 +177,7 @@ char* bar_style_fields[] = { "pop2", }; -char* main_style_fields[] = { +static char* main_style_fields[] = { "back", "margin", "margin_hover", @@ -199,101 +212,124 @@ make_style_tag(char *tag){ len = (int32_t)strlen(tag); str = (char*)malloc(len + 1); - to_camel(tag, str); + to_camel_cc(tag, str); str[len] = 0; return(str); } -char style_index_function_start[] = -"inline u32*\n" -"style_index_by_tag(Style_Main_Data *s, u32 tag){\n" -" u32 *result = 0;\n" -" switch (tag){\n"; - -char style_index_function_end[] = -" }\n" -" return(result);\n" -"}\n\n"; - -char style_case[] = " case Stag_%s: result = &s->%s_color; break;\n"; -char style_info_case[] = " case Stag_%s: result = &s->file_info_style.%s_color; break;\n"; - -void +static void generate_style(){ char filename_4coder[] = "4coder_style.h"; char filename_4ed[] = "4ed_style.h"; - FILE *file; - char *tag; - int32_t count, i; + char *tag = 0; + int32_t count = 0, i = 0; - file = fopen(filename_4coder, "wb"); - enum_begin(file, "Style_Tag"); - { - count = ArrayCount(bar_style_fields); - for (i = 0; i < count; ++i){ - tag = make_style_tag(bar_style_fields[i]); - fprintf(file, "Stag_%s,\n", tag); - free(tag); + String out = make_out_string(10 << 20); + Out_Context context = {0}; + + if (begin_file_out(&context, filename_4coder, &out)){ + + enum_begin(&out, "Style_Tag"); + { + count = ArrayCount(bar_style_fields); + for (i = 0; i < count; ++i){ + tag = make_style_tag(bar_style_fields[i]); + append_sc(&out, "Stag_"); + append_sc(&out, tag); + append_sc(&out, ",\n"); + free(tag); + } + + count = ArrayCount(main_style_fields); + for (i = 0; i < count; ++i){ + tag = make_style_tag(main_style_fields[i]); + append_sc(&out, "Stag_"); + append_sc(&out, tag); + append_sc(&out, ",\n"); + free(tag); + } + } + struct_end(&out); + + end_file_out(context); + } + + if (begin_file_out(&context, filename_4ed, &out)){ + + struct_begin(&out, "Interactive_Style"); + { + count = ArrayCount(bar_style_fields); + for (i = 0; i < count; ++i){ + append_sc(&out, "u32 "); + append_sc(&out, bar_style_fields[i]); + append_sc(&out, "_color;\n"); + } + } + struct_end(&out); + + struct_begin(&out, "Style_Main_Data"); + { + count = ArrayCount(main_style_fields); + for (i = 0; i < count; ++i){ + append_sc(&out, "u32 "); + append_sc(&out, main_style_fields[i]); + append_sc(&out, "_color;\n"); + } + append_sc(&out, "Interactive_Style file_info_style;\n"); + } + struct_end(&out); + + { + append_sc(&out, + "inline u32*\n" + "style_index_by_tag(Style_Main_Data *s, u32 tag){\n" + "u32 *result = 0;\n" + "switch (tag){\n"); + + count = ArrayCount(bar_style_fields); + for (i = 0; i < count; ++i){ + tag = make_style_tag(bar_style_fields[i]); + append_sc(&out, "case Stag_"); + append_sc(&out, tag); + append_sc(&out, ": result = &s->file_info_style."); + append_sc(&out, bar_style_fields[i]); + append_sc(&out, "_color; break;\n"); + free(tag); + } + + count = ArrayCount(main_style_fields); + for (i = 0; i < count; ++i){ + tag = make_style_tag(main_style_fields[i]); + append_sc(&out, "case Stag_"); + append_sc(&out, tag); + append_sc(&out, ": result = &s->"); + append_sc(&out, main_style_fields[i]); + append_sc(&out, "_color; break;\n"); + free(tag); + } + + append_sc(&out, + "}\n" + "return(result);\n" + "}\n\n"); } - count = ArrayCount(main_style_fields); - for (i = 0; i < count; ++i){ - tag = make_style_tag(main_style_fields[i]); - fprintf(file, "Stag_%s,\n", tag); - free(tag); - } - } - struct_end(file); - fclose(file); - - file = fopen(filename_4ed, "wb"); - struct_begin(file, "Interactive_Style"); - { - count = ArrayCount(bar_style_fields); - for (i = 0; i < count; ++i){ - fprintf(file, "u32 %s_color;\n", bar_style_fields[i]); - } - } - struct_end(file); - - struct_begin(file, "Style_Main_Data"); - { - count = ArrayCount(main_style_fields); - for (i = 0; i < count; ++i){ - fprintf(file, "u32 %s_color;\n", main_style_fields[i]); - } - fprintf(file, "Interactive_Style file_info_style;\n"); - } - struct_end(file); - - { - fprintf(file, "%s", style_index_function_start); - count = ArrayCount(bar_style_fields); - for (i = 0; i < count; ++i){ - tag = make_style_tag(bar_style_fields[i]); - fprintf(file, style_info_case, tag, bar_style_fields[i]); - free(tag); - } - - count = ArrayCount(main_style_fields); - for (i = 0; i < count; ++i){ - tag = make_style_tag(main_style_fields[i]); - fprintf(file, style_case, tag, main_style_fields[i]); - free(tag); - } - fprintf(file, "%s", style_index_function_end); + end_file_out(context); } - fclose(file); + free(out.str); } -#if 1 ////////////////////////////////////////////////////////////////////////////////////////////////// +typedef struct Argument{ + String param_string; + String param_name; +} Argument; + typedef struct Argument_Breakdown{ int32_t count; - String *param_string; - String *param_name; + Argument *args; } Argument_Breakdown; typedef struct Documentation{ @@ -306,26 +342,32 @@ typedef struct Documentation{ String *see_also; } Documentation; -typedef struct App_API{ - String *macros; - String *public_name; -} App_API; +enum{ + Item_Null, + Item_Function, + Item_Macro, + Item_Typedef, +}; + +typedef struct Item_Node{ + int32_t t; + + String name; + String ret; + String args; + String body; + String marker; + String cpp_name; + + String type; + String doc_string; + + Argument_Breakdown breakdown; + Documentation doc; +} Item_Node; typedef struct Function_Set{ - String *name; - String *ret; - String *args; - String *body; - String *marker; - String *cpp_name; - - String *doc_string; - - int32_t *is_macro; - int32_t *valid; - - Argument_Breakdown *breakdown; - Documentation *doc; + Item_Node *funcs; } Function_Set; typedef struct Typedef_Set{ @@ -361,15 +403,9 @@ typedef struct Enum_Set{ String *doc_string; } Enum_Set; -void -zero_index(Function_Set fnc_set, int32_t sig_count){ - fnc_set.name [sig_count] = string_zero(); - fnc_set.ret [sig_count] = string_zero(); - fnc_set.args [sig_count] = string_zero(); - fnc_set.valid[sig_count] = 0; -} +static Item_Node null_item_node = {0}; -String +static String file_dump(char *filename){ String result = {0}; FILE *file = fopen(filename, "rb"); @@ -391,7 +427,7 @@ file_dump(char *filename){ return(result); } -String +static String get_first_line(String source){ String line = {0}; int32_t pos = find_s_char(source, 0, '\n'); @@ -399,7 +435,7 @@ get_first_line(String source){ return(line); } -String +static String get_next_line(String source, String line){ String next = {0}; int32_t pos = (int32_t)(line.str - source.str) + line.size; @@ -455,12 +491,12 @@ check_and_fix_docs(String *lexeme){ return(result); } -enum Doc_Note_Type{ +typedef enum Doc_Note_Type{ DOC_PARAM, DOC_RETURN, DOC, DOC_SEE -}; +} Doc_Note_Type; static String doc_note_string[] = { @@ -470,7 +506,7 @@ doc_note_string[] = { make_lit_string("DOC_SEE"), }; -String +static String doc_parse_note(String source, int32_t *pos){ String result = {0}; @@ -490,7 +526,7 @@ doc_parse_note(String source, int32_t *pos){ return(result); } -String +static String doc_parse_note_string(String source, int32_t *pos){ String result = {0}; @@ -524,7 +560,7 @@ doc_parse_note_string(String source, int32_t *pos){ return(result); } -String +static String doc_parse_parameter(String source, int32_t *pos){ String result = {0}; @@ -942,7 +978,7 @@ print_struct_html(FILE *file, Struct_Member *member){ static void print_function_html(FILE *file, Function_Set function_set, int32_t i, String name, char *function_call_head){ - String ret = function_set.ret[i]; + String ret = function_set.funcs[i].ret; fprintf(file, "%.*s %s%.*s(\n" "
    ", @@ -950,10 +986,10 @@ print_function_html(FILE *file, Function_Set function_set, int32_t i, String nam function_call_head, name.size, name.str); - Argument_Breakdown *breakdown = &function_set.breakdown[i]; + Argument_Breakdown *breakdown = &function_set.funcs[i].breakdown; int32_t arg_count = breakdown->count; for (int32_t j = 0; j < arg_count; ++j){ - String param_string = breakdown->param_string[j]; + String param_string = breakdown->args[j].param_string; if (j < arg_count - 1){ fprintf(file, "%.*s,
    ", param_string.size, param_string.str); } @@ -967,7 +1003,7 @@ print_function_html(FILE *file, Function_Set function_set, int32_t i, String nam static void print_macro_html(FILE *file, Function_Set function_set, int32_t i, String name){ - Argument_Breakdown *breakdown = &function_set.breakdown[i]; + Argument_Breakdown *breakdown = &function_set.funcs[i].breakdown; int32_t arg_count = breakdown->count; if (arg_count == 0){ fprintf(file, @@ -975,7 +1011,7 @@ print_macro_html(FILE *file, Function_Set function_set, int32_t i, String name){ name.size, name.str); } else if (arg_count == 1){ - String param_string = breakdown->param_string[0]; + String param_string = breakdown->args[0].param_string; fprintf(file, "#define %.*s(%.*s)", name.size, name.str, @@ -988,7 +1024,7 @@ print_macro_html(FILE *file, Function_Set function_set, int32_t i, String name){ name.size, name.str); for (int32_t j = 0; j < arg_count; ++j){ - String param_string = breakdown->param_string[j]; + String param_string = breakdown->args[j].param_string; if (j < arg_count - 1){ fprintf(file, "%.*s,
    ", param_string.size, param_string.str); } @@ -1186,52 +1222,22 @@ parse_enum(Partition *part, char *data, return(result); } -static App_API -allocate_app_api(int32_t count){ - App_API app_api = {0}; - int32_t memory_size = (sizeof(String)*2)*count; - app_api.macros = (String*)malloc(memory_size); - app_api.public_name = app_api.macros + count; - memset(app_api.macros, 0, memory_size); - return(app_api); -} - static Function_Set allocate_function_set(int32_t count){ Function_Set function_set = {0}; - int32_t memory_size = (sizeof(String)*7 + - sizeof(int32_t)*2 + - sizeof(Argument_Breakdown) + - sizeof(Documentation))*count; - - String *str_ptr = (String*)malloc(memory_size); - function_set.name = str_ptr; str_ptr += count; - function_set.ret = str_ptr; str_ptr += count; - function_set.args = str_ptr; str_ptr += count; - function_set.body = str_ptr; str_ptr += count; - function_set.marker = str_ptr; str_ptr += count; - function_set.cpp_name = str_ptr; str_ptr += count; - function_set.doc_string = str_ptr; str_ptr += count; - - function_set.is_macro = (int32_t*)(function_set.doc_string + count); - function_set.valid = function_set.is_macro + count; - - function_set.breakdown = (Argument_Breakdown*)(function_set.valid + count); - - function_set.doc = (Documentation*)(function_set.breakdown + count); - - memset(function_set.name, 0, memory_size); + int32_t memory_size = sizeof(Item_Node)*count; + function_set.funcs = (Item_Node*)malloc(memory_size); + memset(function_set.funcs, 0, memory_size); return(function_set); } static Argument_Breakdown allocate_argument_breakdown(int32_t count){ Argument_Breakdown breakdown = {0}; - int32_t memory_size = (sizeof(String)*2)*count; + int32_t memory_size = sizeof(Argument)*count; breakdown.count = count; - breakdown.param_string = (String*)malloc(memory_size); - breakdown.param_name = breakdown.param_string + count; - memset(breakdown.param_string, 0, memory_size); + breakdown.args = (Argument*)malloc(memory_size); + memset(breakdown.args, 0, memory_size); return(breakdown); } @@ -1259,7 +1265,7 @@ do_parameter_parse(char *data, Cpp_Token *args_start_token, Cpp_Token *token){ 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.param_string[arg_index] = 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; @@ -1267,7 +1273,7 @@ do_parameter_parse(char *data, Cpp_Token *args_start_token, Cpp_Token *token){ if (param_name_token->type == CPP_TOKEN_IDENTIFIER){ int32_t start = param_name_token->start; int32_t size = param_name_token->size; - breakdown.param_name[arg_index] = make_string(data + start, size); + breakdown.args[arg_index].param_name = make_string(data + start, size); break; } } @@ -1392,12 +1398,12 @@ do_function_parse(int32_t *index, Cpp_Token **token_ptr, int32_t count, Cpp_Toke Cpp_Token *args_start_token = token+1; - function_set.name[sig_count] = make_string(data + token->start, token->size); + function_set.funcs[sig_count].name = make_string(data + token->start, token->size); int32_t size = token->start - ret_start_token->start; String ret = make_string(data + ret_start_token->start, size); ret = chop_whitespace(ret); - function_set.ret[sig_count] = ret; + function_set.funcs[sig_count].ret = ret; for (; i < count; ++i, ++token){ if (token->type == CPP_TOKEN_PARENTHESE_CLOSE){ @@ -1407,15 +1413,15 @@ do_function_parse(int32_t *index, Cpp_Token **token_ptr, int32_t count, Cpp_Toke if (i < count){ int32_t size = token->start + token->size - args_start_token->start;; - function_set.args[sig_count] = + function_set.funcs[sig_count].args = make_string(data + args_start_token->start, size); - function_set.valid[sig_count] = true; + function_set.funcs[sig_count].t = Item_Function; result = true; - Argument_Breakdown *breakdown = &function_set.breakdown[sig_count]; + Argument_Breakdown *breakdown = &function_set.funcs[sig_count].breakdown; *breakdown = do_parameter_parse(data, args_start_token, token); - function_set.cpp_name[sig_count] = cpp_name; + function_set.funcs[sig_count].cpp_name = cpp_name; } *index = i; @@ -1433,7 +1439,7 @@ do_full_function_parse(int32_t *index, Cpp_Token **token_ptr, int32_t count, cha Cpp_Token *token = *token_ptr; { - function_set.marker[sig_count] = make_string(data + token->start, token->size); + function_set.funcs[sig_count].marker = make_string(data + token->start, token->size); int32_t j = i; Cpp_Token *jtoken = token; @@ -1442,7 +1448,7 @@ do_full_function_parse(int32_t *index, Cpp_Token **token_ptr, int32_t count, cha if (token->type == CPP_TOKEN_IDENTIFIER){ String doc_string = {0}; if (do_function_get_doc(&j, &jtoken, count, data, &doc_string)){ - function_set.doc_string[sig_count] = doc_string; + function_set.funcs[sig_count].doc_string = doc_string; } } } @@ -1506,7 +1512,7 @@ do_macro_parse(int32_t *index, Cpp_Token **token_ptr, int32_t count, String doc_string = make_string(data + doc_token->start, doc_token->size); if (check_and_fix_docs(&doc_string)){ - macro_set.doc_string[sig_count] = doc_string; + macro_set.funcs[sig_count].doc_string = doc_string; for (; i < count; ++i, ++token){ if (token->type == CPP_TOKEN_IDENTIFIER){ @@ -1515,7 +1521,7 @@ do_macro_parse(int32_t *index, Cpp_Token **token_ptr, int32_t count, } if (i < count && (token->flags & CPP_TFLAG_PP_BODY)){ - macro_set.name[sig_count] = make_string(data + token->start, token->size); + macro_set.funcs[sig_count].name = make_string(data + token->start, token->size); ++i, ++token; if (i < count){ @@ -1529,9 +1535,9 @@ do_macro_parse(int32_t *index, Cpp_Token **token_ptr, int32_t count, if (i < count){ int32_t start = args_start_token->start; int32_t end = token->start + token->size; - macro_set.args[sig_count] = make_string(data + start, end - start); + macro_set.funcs[sig_count].args = make_string(data + start, end - start); - Argument_Breakdown *breakdown = ¯o_set.breakdown[sig_count]; + Argument_Breakdown *breakdown = ¯o_set.funcs[sig_count].breakdown; *breakdown = do_parameter_parse(data, args_start_token, token); ++i, ++token; @@ -1551,12 +1557,11 @@ do_macro_parse(int32_t *index, Cpp_Token **token_ptr, int32_t count, start = body_start->start; end = body_end->start + body_end->size; - macro_set.body[sig_count] = make_string(data + start, end - start); + macro_set.funcs[sig_count].body = make_string(data + start, end - start); } } - macro_set.is_macro[sig_count] = true; - macro_set.valid[sig_count] = true; + macro_set.funcs[sig_count].t = Item_Macro; result = true; } } @@ -1570,12 +1575,12 @@ do_macro_parse(int32_t *index, Cpp_Token **token_ptr, int32_t count, return(result); } -struct String_Function_Marker{ +typedef struct String_Function_Marker{ int32_t parse_function; int32_t is_inline; int32_t parse_doc; int32_t cpp_name; -}; +} String_Function_Marker; static String_Function_Marker do_string_function_marker_check(String lexeme){ @@ -1720,7 +1725,25 @@ print_function_docs(FILE *file, Partition *part, String name, String doc_string) print_see_also(file, doc); } -void +typedef struct App_API_Name{ + String macro; + String public_name; +} App_API_Name; + +typedef struct App_API{ + App_API_Name *names; +} App_API; + +static App_API +allocate_app_api(int32_t count){ + App_API app_api = {0}; + int32_t memory_size = sizeof(App_API_Name)*count; + app_api.names = (App_API_Name*)malloc(memory_size); + memset(app_api.names, 0, memory_size); + return(app_api); +} + +static void generate_custom_headers(){ #define API_H "4coder_custom_api.h" #define OS_API_H "4ed_os_custom_api.h" @@ -1869,7 +1892,7 @@ generate_custom_headers(){ } Function_Set function_set = allocate_function_set(line_count); - App_API app_function_set = allocate_app_api(line_count); + App_API func_4ed_names = allocate_app_api(line_count); int32_t sig_count = 0; int32_t sig_count_per_file[2]; @@ -1891,8 +1914,8 @@ generate_custom_headers(){ if (match_ss(lexeme, make_lit_string("API_EXPORT"))){ do_full_function_parse(&i, &token, count, data, function_set, sig_count, string_zero()); - if (!function_set.valid[sig_count]){ - zero_index(function_set, sig_count); + if (function_set.funcs[sig_count].t == Item_Null){ + function_set.funcs[sig_count] = null_item_node; // TODO(allen): get warning file name and line numbers fprintf(stderr, "generator warning : invalid function signature\n"); } @@ -1905,9 +1928,9 @@ generate_custom_headers(){ } for (int32_t i = 0; i < sig_count; ++i){ - String name_string = function_set.name[i]; - String *macro = app_function_set.macros + i; - String *public_name = app_function_set.public_name + i; + String name_string = function_set.funcs[i].name; + String *macro = &func_4ed_names.names[i].macro; + String *public_name = &func_4ed_names.names[i].public_name; macro->size = 0; macro->memory_size = name_string.size+4; @@ -1931,9 +1954,9 @@ generate_custom_headers(){ int32_t main_api_count = sig_count_per_file[0]; for (int32_t i = main_api_count; i < sig_count; ++i){ - String ret_string = function_set.ret[i]; - String args_string = function_set.args[i]; - String macro_string = app_function_set.macros[i]; + String ret_string = function_set.funcs[i].ret; + String args_string = function_set.funcs[i].args; + String macro_string = func_4ed_names.names[i].macro; fprintf(file, "#define %.*s(n) %.*s n%.*s\n", macro_string.size, macro_string.str, @@ -1942,8 +1965,8 @@ generate_custom_headers(){ } for (int32_t i = main_api_count; i < sig_count; ++i){ - String name_string = function_set.name[i]; - String macro_string = app_function_set.macros[i]; + String name_string = function_set.funcs[i].name; + String macro_string = func_4ed_names.names[i].macro; fprintf(file, "typedef %.*s(%.*s_Function);\n", macro_string.size, macro_string.str, @@ -1955,9 +1978,9 @@ generate_custom_headers(){ file = fopen(API_H, "wb"); for (int32_t i = 0; i < sig_count; ++i){ - String ret_string = function_set.ret[i]; - String args_string = function_set.args[i]; - String macro_string = app_function_set.macros[i]; + String ret_string = function_set.funcs[i].ret; + String args_string = function_set.funcs[i].args; + String macro_string = func_4ed_names.names[i].macro; fprintf(file, "#define %.*s(n) %.*s n%.*s\n", macro_string.size, macro_string.str, @@ -1966,8 +1989,8 @@ generate_custom_headers(){ } for (int32_t i = 0; i < sig_count; ++i){ - String name_string = function_set.name[i]; - String macro_string = app_function_set.macros[i]; + String name_string = function_set.funcs[i].name; + String macro_string = func_4ed_names.names[i].macro; fprintf(file, "typedef %.*s(%.*s_Function);\n", macro_string.size, macro_string.str, @@ -1980,8 +2003,8 @@ generate_custom_headers(){ " int32_t memory_size;\n" ); for (int32_t i = 0; i < sig_count; ++i){ - String name_string = function_set.name[i]; - String public_string = app_function_set.public_name[i]; + String name_string = function_set.funcs[i].name; + String public_string = func_4ed_names.names[i].public_name; fprintf(file, " %.*s_Function *%.*s;\n", name_string.size, name_string.str, @@ -1997,8 +2020,8 @@ generate_custom_headers(){ fprintf(file, "#define FillAppLinksAPI(app_links) do{"); for (int32_t i = 0; i < sig_count; ++i){ - String name = function_set.name[i]; - String public_string = app_function_set.public_name[i]; + String name = function_set.funcs[i].name; + String public_string = func_4ed_names.names[i].public_name; fprintf(file, "\\\n" @@ -2282,26 +2305,26 @@ generate_custom_headers(){ char line_space[2048]; String line = make_fixed_width_string(line_space); - if (!string_function_set.is_macro[j]){ - String marker = string_function_set.marker[j]; - String ret = string_function_set.ret[j]; - String name = string_function_set.name[j]; - String args = string_function_set.args[j]; - - append_ss(&line, marker); + if (string_function_set.funcs[j].t != Item_Macro){ + String marker = string_function_set.funcs[j].marker; + String ret = string_function_set.funcs[j].ret; + String name = string_function_set.funcs[j].name; + String args = string_function_set.funcs[j].args; + + append_ss(&line, marker); append_padding(&line, ' ', RETURN_PADDING); - append_ss(&line, ret); + append_ss(&line, ret); append_padding(&line, ' ', SIG_PADDING); - append_ss(&line, name); - append_ss(&line, args); - terminate_with_null(&line); - - fprintf(file, "%s;\n", line.str); - } - else{ - String name = string_function_set.name[j]; - String args = string_function_set.args[j]; - String body = string_function_set.body[j]; + append_ss(&line, name); + append_ss(&line, args); + terminate_with_null(&line); + + fprintf(file, "%s;\n", line.str); + } + else{ + String name = string_function_set.funcs[j].name; + String args = string_function_set.funcs[j].args; + String body = string_function_set.funcs[j].body; append_ss(&line, make_lit_string("#ifndef ")); append_padding(&line, ' ', 10); @@ -2336,11 +2359,11 @@ generate_custom_headers(){ char line_space[2048]; String line = make_fixed_width_string(line_space); - if (!string_function_set.is_macro[j]){ - String cpp_name = string_function_set.cpp_name[j]; + if (string_function_set.funcs[j].t != Item_Macro){ + String cpp_name = string_function_set.funcs[j].cpp_name; if (cpp_name.str != 0){ - String ret = string_function_set.ret[j]; - String args = string_function_set.args[j]; + String ret = string_function_set.funcs[j].ret; + String args = string_function_set.funcs[j].args; append_ss(&line, make_lit_string("FSTRING_INLINE")); append_padding(&line, ' ', RETURN_PADDING); @@ -2367,13 +2390,13 @@ generate_custom_headers(){ char line_space[2048]; String line = make_fixed_width_string(line_space); - if (!string_function_set.is_macro[j]){ - String cpp_name = string_function_set.cpp_name[j]; + if (string_function_set.funcs[j].t != Item_Macro){ + String cpp_name = string_function_set.funcs[j].cpp_name; if (cpp_name.str != 0){ - String name = string_function_set.name[j]; - String ret = string_function_set.ret[j]; - String args = string_function_set.args[j]; - Argument_Breakdown breakdown = string_function_set.breakdown[j]; + String name = string_function_set.funcs[j].name; + String ret = string_function_set.funcs[j].ret; + String args = string_function_set.funcs[j].args; + Argument_Breakdown breakdown = string_function_set.funcs[j].breakdown; append_ss(&line, make_lit_string("FSTRING_INLINE")); append_s_char(&line, ' '); @@ -2395,7 +2418,7 @@ generate_custom_headers(){ if (i != 0){ append_s_char(&line, ','); } - append_ss(&line, breakdown.param_name[i]); + append_ss(&line, breakdown.args[i].param_name); } } else{ @@ -2644,7 +2667,7 @@ generate_custom_headers(){ "
      \n"); for (int32_t i = 0; i < sig_count; ++i){ - String name = app_function_set.public_name[i]; + String name = func_4ed_names.names[i].public_name; fprintf(file, "
    • " "%.*s" @@ -2714,7 +2737,7 @@ generate_custom_headers(){ fprintf(file, "

      §"SECTION" Function Descriptions

      \n"); for (int32_t i = 0; i < sig_count; ++i){ - String name = app_function_set.public_name[i]; + String name = func_4ed_names.names[i].public_name; fprintf(file, "
      \n" @@ -2726,7 +2749,7 @@ generate_custom_headers(){ print_function_html(file, function_set, i, name, "app->"); fprintf(file, "
      \n"); - String doc_string = function_set.doc_string[i]; + String doc_string = function_set.funcs[i].doc_string; print_function_docs(file, part, name, doc_string); fprintf(file, "

    \n"); @@ -2990,7 +3013,7 @@ generate_custom_headers(){ } for (int32_t i = 0; i < string_sig_count; ++i){ - String name = string_function_set.name[i]; + String name = string_function_set.funcs[i].name; int32_t index = 0; if (!string_set_match(used_strings, used_string_count, name, &index)){ fprintf(file, @@ -3015,7 +3038,7 @@ generate_custom_headers(){ "
      \n"); for (int32_t i = 0; i < string_sig_count; ++i){ - String name = string_function_set.name[i]; + String name = string_function_set.funcs[i].name; int32_t index = 0; int32_t do_id = false; if (!string_set_match(used_strings, used_string_count, name, &index)){ @@ -3038,7 +3061,7 @@ generate_custom_headers(){ "
      \n", i+1, name.size, name.str); - if (string_function_set.is_macro[i]){ + if (string_function_set.funcs[i].t == Item_Macro){ print_macro_html(file, string_function_set, i, name); } else{ @@ -3048,7 +3071,7 @@ generate_custom_headers(){ fprintf(file, "
      \n"); - String doc_string = string_function_set.doc_string[i]; + String doc_string = string_function_set.funcs[i].doc_string; print_function_docs(file, part, name, doc_string); fprintf(file, "

    \n"); @@ -3064,7 +3087,6 @@ generate_custom_headers(){ fclose(file); } } -#endif int main(int argc, char **argv){ generate_keycode_enum(); diff --git a/4ed_style.h b/4ed_style.h index 0ae1e91e..f31eb94b 100644 --- a/4ed_style.h +++ b/4ed_style.h @@ -37,39 +37,39 @@ Interactive_Style file_info_style; inline u32* style_index_by_tag(Style_Main_Data *s, u32 tag){ - u32 *result = 0; - switch (tag){ - case Stag_Bar: result = &s->file_info_style.bar_color; break; - case Stag_Bar_Active: result = &s->file_info_style.bar_active_color; break; - case Stag_Base: result = &s->file_info_style.base_color; break; - case Stag_Pop1: result = &s->file_info_style.pop1_color; break; - case Stag_Pop2: result = &s->file_info_style.pop2_color; break; - case Stag_Back: result = &s->back_color; break; - case Stag_Margin: result = &s->margin_color; break; - case Stag_Margin_Hover: result = &s->margin_hover_color; break; - case Stag_Margin_Active: result = &s->margin_active_color; break; - case Stag_Cursor: result = &s->cursor_color; break; - case Stag_At_Cursor: result = &s->at_cursor_color; break; - case Stag_Highlight: result = &s->highlight_color; break; - case Stag_At_Highlight: result = &s->at_highlight_color; break; - case Stag_Mark: result = &s->mark_color; break; - case Stag_Default: result = &s->default_color; break; - case Stag_Comment: result = &s->comment_color; break; - case Stag_Keyword: result = &s->keyword_color; break; - case Stag_Str_Constant: result = &s->str_constant_color; break; - case Stag_Char_Constant: result = &s->char_constant_color; break; - case Stag_Int_Constant: result = &s->int_constant_color; break; - case Stag_Float_Constant: result = &s->float_constant_color; break; - case Stag_Bool_Constant: result = &s->bool_constant_color; break; - case Stag_Preproc: result = &s->preproc_color; break; - case Stag_Include: result = &s->include_color; break; - case Stag_Special_Character: result = &s->special_character_color; break; - case Stag_Highlight_Junk: result = &s->highlight_junk_color; break; - case Stag_Highlight_White: result = &s->highlight_white_color; break; - case Stag_Paste: result = &s->paste_color; break; - case Stag_Undo: result = &s->undo_color; break; - case Stag_Next_Undo: result = &s->next_undo_color; break; - } - return(result); +u32 *result = 0; +switch (tag){ +case Stag_Bar: result = &s->file_info_style.bar_color; break; +case Stag_Bar_Active: result = &s->file_info_style.bar_active_color; break; +case Stag_Base: result = &s->file_info_style.base_color; break; +case Stag_Pop1: result = &s->file_info_style.pop1_color; break; +case Stag_Pop2: result = &s->file_info_style.pop2_color; break; +case Stag_Back: result = &s->back_color; break; +case Stag_Margin: result = &s->margin_color; break; +case Stag_Margin_Hover: result = &s->margin_hover_color; break; +case Stag_Margin_Active: result = &s->margin_active_color; break; +case Stag_Cursor: result = &s->cursor_color; break; +case Stag_At_Cursor: result = &s->at_cursor_color; break; +case Stag_Highlight: result = &s->highlight_color; break; +case Stag_At_Highlight: result = &s->at_highlight_color; break; +case Stag_Mark: result = &s->mark_color; break; +case Stag_Default: result = &s->default_color; break; +case Stag_Comment: result = &s->comment_color; break; +case Stag_Keyword: result = &s->keyword_color; break; +case Stag_Str_Constant: result = &s->str_constant_color; break; +case Stag_Char_Constant: result = &s->char_constant_color; break; +case Stag_Int_Constant: result = &s->int_constant_color; break; +case Stag_Float_Constant: result = &s->float_constant_color; break; +case Stag_Bool_Constant: result = &s->bool_constant_color; break; +case Stag_Preproc: result = &s->preproc_color; break; +case Stag_Include: result = &s->include_color; break; +case Stag_Special_Character: result = &s->special_character_color; break; +case Stag_Highlight_Junk: result = &s->highlight_junk_color; break; +case Stag_Highlight_White: result = &s->highlight_white_color; break; +case Stag_Paste: result = &s->paste_color; break; +case Stag_Undo: result = &s->undo_color; break; +case Stag_Next_Undo: result = &s->next_undo_color; break; +} +return(result); } diff --git a/build.c b/build.c index 23f1aa7c..70d3e639 100644 --- a/build.c +++ b/build.c @@ -264,7 +264,7 @@ buildsuper(char *code_path, char *out_path, char *filename){ static void standard_build(char *cdir, uint32_t flags){ -#if 0 +#if 1 { BEGIN_TIME_SECTION(); build(OPTS, cdir, "fsm_table_generator.cpp", @@ -294,7 +294,7 @@ standard_build(char *cdir, uint32_t flags){ } #endif -#if 0 +#if 1 { BEGIN_TIME_SECTION(); //buildsuper(cdir, BUILD_DIR, "../code/4coder_default_bindings.cpp"); diff --git a/internal_4coder_string.cpp b/internal_4coder_string.cpp index aaf681e2..263e5764 100644 --- a/internal_4coder_string.cpp +++ b/internal_4coder_string.cpp @@ -1178,8 +1178,8 @@ CPP_NAME(to_upper) FSTRING_LINK void to_upper_cc(char *src, char *dst)/* DOC_PARAM(src, The source string to convert to uppercase. This string must be null terminated.) -DOC_PARAM(dst, The destination buffer to receive the converted string. This must be large -enough to contain all of src and a null terminator.) +DOC_PARAM(dst, The destination buffer to receive the converted string. +This must be large enough to contain all of src and a null terminator.) DOC(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.) */{ @@ -1192,7 +1192,7 @@ that src and dst may be exactly equal in order to convert the string in place.) CPP_NAME(to_upper) FSTRING_LINK void to_upper_ss(String *src, String *dst)/* -DOC_PARAM(src, The source string to conver to uppercase.) +DOC_PARAM(src, The source string to convert to uppercase.) DOC_PARAM(dst, The destination buffer to receive the converted string. This must have a capacity of at least the size of src.) DOC(Rewrites the string in src into dst. src and dst should not overlap with the exception @@ -1224,6 +1224,38 @@ DOC(This version of to_upper converts str to uppercase in place.) } } +CPP_NAME(to_camel) +FSTRING_LINK void +to_camel_cc(char *src, char *dst)/* +DOC_PARAM(src, The source string to convert to camel case.) +DOC_PARAM(dst, The destination buffer to receive the converted string. +This must be large enough to contain all of src and a null terminator.) +DOC(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.) +*/{ + char *c, ch; + int32_t is_first = 1; + for (c = src; *c != 0; ++c){ + ch = *c; + if (char_is_alpha_numeric_true(ch)){ + if (is_first){ + is_first = 0; + ch = char_to_upper(ch); + } + else{ + ch = char_to_lower(ch); + } + } + else{ + is_first = 1; + } + *dst++ = ch; + } + *dst = 0; +} + + // // String <-> Number Conversions //