converted portion of the HTML doc generator to string append instead of fprintf

master
Allen Webster 2016-09-04 01:08:36 -04:00
parent 8fdff026af
commit a80e99d575
3 changed files with 537 additions and 904 deletions

File diff suppressed because one or more lines are too long

View File

@ -169,225 +169,79 @@ 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_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 fstr_bool string_set_match(String *str_set, int32_t count, String str, int32_t *match_index);
#if !defined(FSTRING_C)
// NOTE(allen): This section is here to enable nicer names
// for C++ users who can have overloaded functions. None of
// these functions add new features.
FSTRING_INLINE String make_string(void *str, int32_t size, int32_t mem_size);
FSTRING_INLINE String substr(String str, int32_t start);
FSTRING_INLINE fstr_bool match(char *a, char *b);
FSTRING_INLINE fstr_bool match(String a, char *b);
FSTRING_INLINE fstr_bool match(char *a, String b);
FSTRING_INLINE fstr_bool match(String a, String b);
FSTRING_INLINE fstr_bool match_part(char *a, char *b, int32_t *len);
FSTRING_INLINE fstr_bool match_part(String a, char *b, int32_t *len);
FSTRING_INLINE fstr_bool match_part(char *a, char *b);
FSTRING_INLINE fstr_bool match_part(String a, char *b);
FSTRING_INLINE fstr_bool match_part(char *a, String b);
FSTRING_INLINE fstr_bool match_part(String a, String b);
FSTRING_INLINE fstr_bool match_insensitive(char *a, char *b);
FSTRING_INLINE fstr_bool match_insensitive(String a, char *b);
FSTRING_INLINE fstr_bool match_insensitive(char *a, String b);
FSTRING_INLINE fstr_bool match_insensitive(String a, String b);
FSTRING_INLINE fstr_bool match_part_insensitive(char *a, char *b, int32_t *len);
FSTRING_INLINE fstr_bool match_part_insensitive(String a, char *b, int32_t *len);
FSTRING_INLINE fstr_bool match_part_insensitive(char *a, char *b);
FSTRING_INLINE fstr_bool match_part_insensitive(String a, char *b);
FSTRING_INLINE fstr_bool match_part_insensitive(char *a, String b);
FSTRING_INLINE fstr_bool match_part_insensitive(String a, String b);
FSTRING_INLINE int32_t compare(char *a, char *b);
FSTRING_INLINE int32_t compare(String a, char *b);
FSTRING_INLINE int32_t compare(char *a, String b);
FSTRING_INLINE int32_t compare(String a, String b);
FSTRING_INLINE int32_t find(char *str, int32_t start, char character);
FSTRING_INLINE int32_t find(String str, int32_t start, char character);
FSTRING_INLINE int32_t rfind(String str, int32_t start, char character);
FSTRING_INLINE int32_t find(char *str, int32_t start, char *characters);
FSTRING_INLINE int32_t find(String str, int32_t start, char *characters);
FSTRING_INLINE int32_t find_substr(char *str, int32_t start, String seek);
FSTRING_INLINE int32_t find_substr(String str, int32_t start, String seek);
FSTRING_INLINE int32_t rfind_substr(String str, int32_t start, String seek);
FSTRING_INLINE int32_t find_substr_insensitive(char *str, int32_t start, String seek);
FSTRING_INLINE int32_t find_substr_insensitive(String str, int32_t start, String seek);
FSTRING_INLINE fstr_bool has_substr(char *s, String seek);
FSTRING_INLINE fstr_bool has_substr(String s, String seek);
FSTRING_INLINE fstr_bool has_substr_insensitive(char *s, String seek);
FSTRING_INLINE fstr_bool has_substr_insensitive(String s, String seek);
FSTRING_INLINE int32_t copy_fast_unsafe(char *dest, char *src);
FSTRING_INLINE int32_t copy_fast_unsafe(char *dest, String src);
FSTRING_INLINE fstr_bool copy_checked(String *dest, String src);
FSTRING_INLINE fstr_bool copy_partial(String *dest, char *src);
FSTRING_INLINE fstr_bool copy_partial(String *dest, String src);
FSTRING_INLINE int32_t copy(char *dest, char *src);
FSTRING_INLINE void copy(String *dest, String src);
FSTRING_INLINE void copy(String *dest, char *src);
FSTRING_INLINE fstr_bool append_checked(String *dest, String src);
FSTRING_INLINE fstr_bool append_partial(String *dest, char *src);
FSTRING_INLINE fstr_bool append_partial(String *dest, String src);
FSTRING_INLINE fstr_bool append(String *dest, char c);
FSTRING_INLINE fstr_bool append(String *dest, String src);
FSTRING_INLINE fstr_bool append(String *dest, char *src);
FSTRING_INLINE void to_lower(char *src, char *dst);
FSTRING_INLINE void to_lower(String *dst, String src);
FSTRING_INLINE void to_lower(String *str);
FSTRING_INLINE void to_upper(char *src, char *dst);
FSTRING_INLINE void to_upper(String *dst, String src);
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);
FSTRING_INLINE int32_t str_to_int(String str);
FSTRING_INLINE int32_t reverse_seek_slash(String str, int32_t pos);
FSTRING_INLINE fstr_bool set_last_folder(String *dir, char *folder_name, char slash);
FSTRING_INLINE fstr_bool set_last_folder(String *dir, String folder_name, char slash);
FSTRING_INLINE fstr_bool string_set_match(void *str_set, int32_t item_size, int32_t count, String str, int32_t *match_index);
#endif
#endif #endif
#if !defined(FSTRING_C) && !defined(FSTRING_GUARD) #if !defined(FSTRING_C) && !defined(FSTRING_GUARD)
FSTRING_INLINE String FSTRING_INLINE String make_string(void *str, int32_t size, int32_t mem_size){return(make_string_cap(str,size,mem_size));}
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 String FSTRING_INLINE fstr_bool match(char *a, char *b){return(match_cc(a,b));}
substr(String str, int32_t start){return(substr_tail(str,start));} FSTRING_INLINE fstr_bool match(String a, char *b){return(match_sc(a,b));}
FSTRING_INLINE fstr_bool FSTRING_INLINE fstr_bool match(char *a, String b){return(match_cs(a,b));}
match(char *a, char *b){return(match_cc(a,b));} FSTRING_INLINE fstr_bool match(String a, String b){return(match_ss(a,b));}
FSTRING_INLINE fstr_bool FSTRING_INLINE fstr_bool match_part(char *a, char *b, int32_t *len){return(match_part_ccl(a,b,len));}
match(String a, char *b){return(match_sc(a,b));} FSTRING_INLINE fstr_bool match_part(String a, char *b, int32_t *len){return(match_part_scl(a,b,len));}
FSTRING_INLINE fstr_bool FSTRING_INLINE fstr_bool match_part(char *a, char *b){return(match_part_cc(a,b));}
match(char *a, String b){return(match_cs(a,b));} FSTRING_INLINE fstr_bool match_part(String a, char *b){return(match_part_sc(a,b));}
FSTRING_INLINE fstr_bool FSTRING_INLINE fstr_bool match_part(char *a, String b){return(match_part_cs(a,b));}
match(String a, String b){return(match_ss(a,b));} FSTRING_INLINE fstr_bool match_part(String a, String b){return(match_part_ss(a,b));}
FSTRING_INLINE fstr_bool FSTRING_INLINE fstr_bool match_insensitive(char *a, char *b){return(match_insensitive_cc(a,b));}
match_part(char *a, char *b, int32_t *len){return(match_part_ccl(a,b,len));} FSTRING_INLINE fstr_bool match_insensitive(String a, char *b){return(match_insensitive_sc(a,b));}
FSTRING_INLINE fstr_bool FSTRING_INLINE fstr_bool match_insensitive(char *a, String b){return(match_insensitive_cs(a,b));}
match_part(String a, char *b, int32_t *len){return(match_part_scl(a,b,len));} FSTRING_INLINE fstr_bool match_insensitive(String a, String b){return(match_insensitive_ss(a,b));}
FSTRING_INLINE fstr_bool FSTRING_INLINE fstr_bool match_part_insensitive(char *a, char *b, int32_t *len){return(match_part_insensitive_ccl(a,b,len));}
match_part(char *a, char *b){return(match_part_cc(a,b));} 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 FSTRING_INLINE fstr_bool match_part_insensitive(char *a, char *b){return(match_part_insensitive_cc(a,b));}
match_part(String a, char *b){return(match_part_sc(a,b));} FSTRING_INLINE fstr_bool match_part_insensitive(String a, char *b){return(match_part_insensitive_sc(a,b));}
FSTRING_INLINE fstr_bool FSTRING_INLINE fstr_bool match_part_insensitive(char *a, String b){return(match_part_insensitive_cs(a,b));}
match_part(char *a, String b){return(match_part_cs(a,b));} FSTRING_INLINE fstr_bool match_part_insensitive(String a, String b){return(match_part_insensitive_ss(a,b));}
FSTRING_INLINE fstr_bool FSTRING_INLINE int32_t compare(char *a, char *b){return(compare_cc(a,b));}
match_part(String a, String b){return(match_part_ss(a,b));} FSTRING_INLINE int32_t compare(String a, char *b){return(compare_sc(a,b));}
FSTRING_INLINE fstr_bool FSTRING_INLINE int32_t compare(char *a, String b){return(compare_cs(a,b));}
match_insensitive(char *a, char *b){return(match_insensitive_cc(a,b));} FSTRING_INLINE int32_t compare(String a, String b){return(compare_ss(a,b));}
FSTRING_INLINE fstr_bool FSTRING_INLINE int32_t find(char *str, int32_t start, char character){return(find_c_char(str,start,character));}
match_insensitive(String a, char *b){return(match_insensitive_sc(a,b));} FSTRING_INLINE int32_t find(String str, int32_t start, char character){return(find_s_char(str,start,character));}
FSTRING_INLINE fstr_bool FSTRING_INLINE int32_t rfind(String str, int32_t start, char character){return(rfind_s_char(str,start,character));}
match_insensitive(char *a, String b){return(match_insensitive_cs(a,b));} FSTRING_INLINE int32_t find(char *str, int32_t start, char *characters){return(find_c_chars(str,start,characters));}
FSTRING_INLINE fstr_bool FSTRING_INLINE int32_t find(String str, int32_t start, char *characters){return(find_s_chars(str,start,characters));}
match_insensitive(String a, String b){return(match_insensitive_ss(a,b));} FSTRING_INLINE int32_t find_substr(char *str, int32_t start, String seek){return(find_substr_c(str,start,seek));}
FSTRING_INLINE fstr_bool FSTRING_INLINE int32_t find_substr(String str, int32_t start, String seek){return(find_substr_s(str,start,seek));}
match_part_insensitive(char *a, char *b, int32_t *len){return(match_part_insensitive_ccl(a,b,len));} FSTRING_INLINE int32_t rfind_substr(String str, int32_t start, String seek){return(rfind_substr_s(str,start,seek));}
FSTRING_INLINE fstr_bool FSTRING_INLINE int32_t find_substr_insensitive(char *str, int32_t start, String seek){return(find_substr_insensitive_c(str,start,seek));}
match_part_insensitive(String a, char *b, int32_t *len){return(match_part_insensitive_scl(a,b,len));} 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 FSTRING_INLINE fstr_bool has_substr(char *s, String seek){return(has_substr_c(s,seek));}
match_part_insensitive(char *a, char *b){return(match_part_insensitive_cc(a,b));} FSTRING_INLINE fstr_bool has_substr(String s, String seek){return(has_substr_s(s,seek));}
FSTRING_INLINE fstr_bool FSTRING_INLINE fstr_bool has_substr_insensitive(char *s, String seek){return(has_substr_insensitive_c(s,seek));}
match_part_insensitive(String a, char *b){return(match_part_insensitive_sc(a,b));} FSTRING_INLINE fstr_bool has_substr_insensitive(String s, String seek){return(has_substr_insensitive_s(s,seek));}
FSTRING_INLINE fstr_bool FSTRING_INLINE int32_t copy_fast_unsafe(char *dest, char *src){return(copy_fast_unsafe_cc(dest,src));}
match_part_insensitive(char *a, String b){return(match_part_insensitive_cs(a,b));} FSTRING_INLINE int32_t copy_fast_unsafe(char *dest, String src){return(copy_fast_unsafe_cs(dest,src));}
FSTRING_INLINE fstr_bool FSTRING_INLINE fstr_bool copy_checked(String *dest, String src){return(copy_checked_ss(dest,src));}
match_part_insensitive(String a, String b){return(match_part_insensitive_ss(a,b));} FSTRING_INLINE fstr_bool copy_partial(String *dest, char *src){return(copy_partial_sc(dest,src));}
FSTRING_INLINE int32_t FSTRING_INLINE fstr_bool copy_partial(String *dest, String src){return(copy_partial_ss(dest,src));}
compare(char *a, char *b){return(compare_cc(a,b));} FSTRING_INLINE int32_t copy(char *dest, char *src){return(copy_cc(dest,src));}
FSTRING_INLINE int32_t FSTRING_INLINE void copy(String *dest, String src){(copy_ss(dest,src));}
compare(String a, char *b){return(compare_sc(a,b));} FSTRING_INLINE void copy(String *dest, char *src){(copy_sc(dest,src));}
FSTRING_INLINE int32_t FSTRING_INLINE fstr_bool append_checked(String *dest, String src){return(append_checked_ss(dest,src));}
compare(char *a, String b){return(compare_cs(a,b));} FSTRING_INLINE fstr_bool append_partial(String *dest, char *src){return(append_partial_sc(dest,src));}
FSTRING_INLINE int32_t FSTRING_INLINE fstr_bool append_partial(String *dest, String src){return(append_partial_ss(dest,src));}
compare(String a, String b){return(compare_ss(a,b));} FSTRING_INLINE fstr_bool append(String *dest, char c){return(append_s_char(dest,c));}
FSTRING_INLINE int32_t FSTRING_INLINE fstr_bool append(String *dest, String src){return(append_ss(dest,src));}
find(char *str, int32_t start, char character){return(find_c_char(str,start,character));} FSTRING_INLINE fstr_bool append(String *dest, char *src){return(append_sc(dest,src));}
FSTRING_INLINE int32_t FSTRING_INLINE void to_lower(char *src, char *dst){(to_lower_cc(src,dst));}
find(String str, int32_t start, char character){return(find_s_char(str,start,character));} FSTRING_INLINE void to_lower(String *dst, String src){(to_lower_ss(dst,src));}
FSTRING_INLINE int32_t FSTRING_INLINE void to_lower(String *str){(to_lower_s(str));}
rfind(String str, int32_t start, char character){return(rfind_s_char(str,start,character));} FSTRING_INLINE void to_upper(char *src, char *dst){(to_upper_cc(src,dst));}
FSTRING_INLINE int32_t FSTRING_INLINE void to_upper(String *dst, String src){(to_upper_ss(dst,src));}
find(char *str, int32_t start, char *characters){return(find_c_chars(str,start,characters));} FSTRING_INLINE void to_upper(String *str){(to_upper_s(str));}
FSTRING_INLINE int32_t FSTRING_INLINE void to_camel(char *src, char *dst){(to_camel_cc(src,dst));}
find(String str, int32_t start, char *characters){return(find_s_chars(str,start,characters));} FSTRING_INLINE int32_t str_is_int(char *str){return(str_is_int_c(str));}
FSTRING_INLINE int32_t FSTRING_INLINE fstr_bool str_is_int(String str){return(str_is_int_s(str));}
find_substr(char *str, int32_t start, String seek){return(find_substr_c(str,start,seek));} FSTRING_INLINE int32_t str_to_int(char *str){return(str_to_int_c(str));}
FSTRING_INLINE int32_t FSTRING_INLINE int32_t str_to_int(String str){return(str_to_int_s(str));}
find_substr(String str, int32_t start, String seek){return(find_substr_s(str,start,seek));} FSTRING_INLINE int32_t reverse_seek_slash(String str, int32_t pos){return(reverse_seek_slash_pos(str,pos));}
FSTRING_INLINE int32_t FSTRING_INLINE fstr_bool set_last_folder(String *dir, char *folder_name, char slash){return(set_last_folder_sc(dir,folder_name,slash));}
rfind_substr(String str, int32_t start, String seek){return(rfind_substr_s(str,start,seek));} 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 int32_t 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));}
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));}
#endif #endif

View File

@ -1877,28 +1877,26 @@ print_str(FILE *file, String str){
} }
static void static void
print_function_body_code(FILE *file, int32_t *index, Cpp_Token **token_ptr, int32_t count, String *code, print_function_body_code(String *out, Parse_Context *context, int32_t start){
int32_t start){ String pstr = {0}, lexeme = {0};
int32_t i = *index; Cpp_Token *token = 0;
Cpp_Token *token = *token_ptr;
String pstr = {0};
int32_t do_print = 0;
int32_t nest_level = 0; int32_t nest_level = 0;
int32_t finish = false; int32_t finish = false;
int32_t do_whitespace_print = false; int32_t do_whitespace_print = false;
for (; i < count; ++i, ++token){ for (; (token = get_token(context)) != 0; get_next_token(context)){
if (do_whitespace_print){ if (do_whitespace_print){
pstr = str_start_end(code->str, start, token->start); pstr = str_start_end(context->data, start, token->start);
print_str(file, pstr); append_ss(out, pstr);
} }
else{ else{
do_whitespace_print = true; do_whitespace_print = true;
} }
int32_t do_print = true; do_print = true;
if (token->type == CPP_TOKEN_COMMENT){ if (token->type == CPP_TOKEN_COMMENT){
String lexeme = make_string(code->str + token->start, token->size); lexeme = get_lexeme(*token, context->data);
if (check_and_fix_docs(&lexeme)){ if (check_and_fix_docs(&lexeme)){
do_print = false; do_print = false;
} }
@ -1913,28 +1911,23 @@ print_function_body_code(FILE *file, int32_t *index, Cpp_Token **token_ptr, int3
} }
} }
if (i < count){
if (do_print){ if (do_print){
pstr = make_string(code->str + token->start, token->size); pstr = get_lexeme(*token, context->data);
print_str(file, pstr); append_ss(out, pstr);
} }
start = token->start + token->size; start = token->start + token->size;
}
if (finish){ if (finish){
break; break;
} }
} }
*index = i;
*token_ptr = token;
} }
static void static void
print_function_docs(FILE *file, Partition *part, String name, String doc_string){ print_function_docs(FILE *file, Partition *part, String name, String doc_string){
if (doc_string.size == 0){ if (doc_string.size == 0){
fprintf(file, "No documentation generated for this function, assume it is non-public.\n"); fprintf(file, "No documentation generated for this function.\n");
fprintf(stderr, "warning: no documentation string for %.*s\n", name.size, name.str); fprintf(stderr, "warning: no documentation string for %.*s\n", name.size, name.str);
} }
@ -2264,8 +2257,6 @@ generate_custom_headers(){
append_s_char(&out, '\n'); append_s_char(&out, '\n');
} }
dump_file_out(context);
for (int32_t i = main_api_count; i < os_api_count; ++i){ for (int32_t i = main_api_count; i < os_api_count; ++i){
append_sc(&out, "typedef "); append_sc(&out, "typedef ");
append_ss(&out, func_4ed_names.names[i].macro); append_ss(&out, func_4ed_names.names[i].macro);
@ -2281,8 +2272,6 @@ generate_custom_headers(){
} }
if (begin_file_out(&context, API_H, &out)){ if (begin_file_out(&context, API_H, &out)){
file = context.file;
for (int32_t i = 0; i < unit_custom.set.count; ++i){ for (int32_t i = 0; i < unit_custom.set.count; ++i){
append_sc(&out, "#define "); append_sc(&out, "#define ");
append_ss(&out, func_4ed_names.names[i].macro); append_ss(&out, func_4ed_names.names[i].macro);
@ -2333,31 +2322,24 @@ generate_custom_headers(){
end_file_out(context); end_file_out(context);
} }
else{
// TODO(allen): warning
}
// NOTE(allen): Documentation // NOTE(allen): String Library
{ if (begin_file_out(&context, STRING_H, &out)){
file = context.file;
//
// Output 4coder_string.h
//
file = fopen(STRING_H, "wb");
{
String *code = &string_unit.parse[0].code;
Cpp_Token_Stack *token_stack = &string_unit.parse[0].tokens;
Cpp_Token *token = 0;
int32_t start = 0; int32_t start = 0;
int32_t count = token_stack->count; Parse parse = string_unit.parse[0];
Cpp_Token *tokens = token_stack->tokens; Parse_Context pcontext = setup_parse_context(parse);
Cpp_Token *token = tokens;
int32_t i = 0;
for (i = 0; i < count; ++i, ++token){ for (; (token = get_token(&pcontext)) != 0; get_next_token(&pcontext)){
if (token->type == CPP_TOKEN_IDENTIFIER && if (!(token->flags & CPP_TFLAG_PP_BODY) &&
!(token->flags & CPP_TFLAG_PP_BODY)){ token->type == CPP_TOKEN_IDENTIFIER){
String lexeme = make_string(code->str + token->start, token->size); String lexeme = get_lexeme(*token, pcontext.data);
if (match_ss(lexeme, make_lit_string("FSTRING_BEGIN"))){ if (match_ss(lexeme, make_lit_string("FSTRING_BEGIN"))){
start = token->start + token->size; start = token->start + token->size;
break; break;
@ -2368,81 +2350,67 @@ generate_custom_headers(){
String pstr = {0}; String pstr = {0};
int32_t do_whitespace_print = true; int32_t do_whitespace_print = true;
for(++i, ++token; i < count; ++i, ++token){ for(;(token = get_next_token(&pcontext)) != 0;){
if (do_whitespace_print){ if (do_whitespace_print){
pstr = str_start_end(code->str, start, token->start); pstr = str_start_end(pcontext.data, start, token->start);
print_str(file, pstr); append_ss(&out, pstr);
} }
else{ else{
do_whitespace_print = true; do_whitespace_print = true;
} }
String lexeme = get_lexeme(*token, code->str); String lexeme = get_lexeme(*token, pcontext.data);
int32_t do_print = true; int32_t do_print = true;
if (match_ss(lexeme, make_lit_string("FSTRING_DECLS"))){ if (match_ss(lexeme, make_lit_string("FSTRING_DECLS"))){
fprintf(file, "#if !defined(FCODER_STRING_H)\n#define FCODER_STRING_H\n\n"); append_sc(&out, "#if !defined(FCODER_STRING_H)\n#define FCODER_STRING_H\n\n");
do_print = false; do_print = false;
#define RETURN_PADDING 16 static int32_t RETURN_PADDING = 16;
#define SIG_PADDING 30 static int32_t SIG_PADDING = 27;
for (int32_t j = 0; j < string_unit.set.count; ++j){ for (int32_t j = 0; j < string_unit.set.count; ++j){
char line_space[2048]; char line_[2048];
String line = make_fixed_width_string(line_space); String line = make_fixed_width_string(line_);
Item_Node *item = string_unit.set.items + j; Item_Node *item = string_unit.set.items + j;
if (item->t != Item_Macro){ if (item->t == Item_Function){
String marker = item->marker; append_ss (&line, item->marker);
String ret = item->ret;
String name = item->name;
String args = item->args;
append_ss(&line, marker);
append_padding (&line, ' ', RETURN_PADDING); append_padding (&line, ' ', RETURN_PADDING);
append_ss(&line, ret); append_ss (&line, item->ret);
append_padding (&line, ' ', SIG_PADDING); append_padding (&line, ' ', SIG_PADDING);
append_ss(&line, name); append_ss (&line, item->name);
append_ss(&line, args); append_ss (&line, item->args);
terminate_with_null(&line); append_sc (&line, ";\n");
fprintf(file, "%s;\n", line.str);
} }
else{ else if (item->t == Item_Macro){
String name = item->name;
String args = item->args;
String body = item->body;
append_ss (&line, make_lit_string("#ifndef ")); append_ss (&line, make_lit_string("#ifndef "));
append_padding (&line, ' ', 10); append_padding (&line, ' ', 10);
append_ss(&line, name); append_ss (&line, item->name);
terminate_with_null(&line); append_s_char (&line, '\n');
fprintf(file, "%s\n", line.str);
line.size = 0;
append_ss (&line, make_lit_string("# define ")); append_ss (&line, make_lit_string("# define "));
append_padding (&line, ' ', 10); append_padding (&line, ' ', 10);
append_ss(&line, name); append_ss (&line, item->name);
append_ss(&line, args); append_ss (&line, item->args);
append_s_char (&line, ' '); append_s_char (&line, ' ');
append_ss(&line, body); append_ss (&line, item->body);
terminate_with_null(&line); append_s_char (&line, '\n');
fprintf(file, "%s\n", line.str);
line.size = 0;
append_ss (&line, make_lit_string("#endif")); append_ss (&line, make_lit_string("#endif"));
terminate_with_null(&line); append_s_char (&line, '\n');
fprintf(file, "%s\n", line.str);
} }
else{
InvalidPath;
} }
{ append_ss(&out, line);
fprintf(file, "\n#if !defined(FSTRING_C)\n\n" }
"// NOTE(allen): This section is here to enable nicer names\n"
"// for C++ users who can have overloaded functions. None of\n" append_sc(&out, "\n#endif\n");
"// these functions add new features.\n");
// NOTE(allen): C++ overload definitions
append_sc(&out, "\n#if !defined(FSTRING_C) && !defined(FSTRING_GUARD)\n\n");
for (int32_t j = 0; j < string_unit.set.count; ++j){ for (int32_t j = 0; j < string_unit.set.count; ++j){
char line_space[2048]; char line_space[2048];
@ -2450,60 +2418,24 @@ generate_custom_headers(){
Item_Node *item = &string_unit.set.items[j]; Item_Node *item = &string_unit.set.items[j];
if (item->t != Item_Macro){ if (item->t == Item_Function){
String cpp_name = item->cpp_name; String cpp_name = item->cpp_name;
if (cpp_name.str != 0){ if (cpp_name.str != 0){
String ret = item->ret;
String args = item->args;
append_ss(&line, make_lit_string("FSTRING_INLINE"));
append_padding(&line, ' ', RETURN_PADDING);
append_ss(&line, ret);
append_padding(&line, ' ', SIG_PADDING);
append_ss(&line, cpp_name);
append_ss(&line, args);
terminate_with_null(&line);
fprintf(file, "%s;\n", line.str);
}
}
}
fprintf(file, "\n#endif\n");
}
fprintf(file, "\n#endif\n");
{
fprintf(file, "\n#if !defined(FSTRING_C) && !defined(FSTRING_GUARD)\n\n");
for (int32_t j = 0; j < string_unit.set.count; ++j){
char line_space[2048];
String line = make_fixed_width_string(line_space);
Item_Node *item = &string_unit.set.items[j];
if (item->t != Item_Macro){
String cpp_name = item->cpp_name;
if (cpp_name.str != 0){
String name = item->name;
String ret = item->ret;
String args = item->args;
Argument_Breakdown breakdown = item->breakdown; Argument_Breakdown breakdown = item->breakdown;
append_ss (&line, make_lit_string("FSTRING_INLINE")); append_ss (&line, make_lit_string("FSTRING_INLINE"));
append_s_char(&line, ' '); append_padding(&line, ' ', RETURN_PADDING);
append_ss(&line, ret); append_ss (&line, item->ret);
append_s_char(&line, '\n'); append_padding(&line, ' ', SIG_PADDING);
append_ss (&line, cpp_name); append_ss (&line, cpp_name);
append_ss(&line, args); append_ss (&line, item->args);
if (match_ss(ret, make_lit_string("void"))){ if (match_ss(item->ret, make_lit_string("void"))){
append_ss(&line, make_lit_string("{(")); append_ss(&line, make_lit_string("{("));//}
} }
else{ else{
append_ss(&line, make_lit_string("{return(")); append_ss(&line, make_lit_string("{return("));//}
} }
append_ss(&line, name); append_ss (&line, item->name);
append_s_char(&line, '('); append_s_char(&line, '(');
if (breakdown.count > 0){ if (breakdown.count > 0){
@ -2518,160 +2450,154 @@ generate_custom_headers(){
append_ss(&line, make_lit_string("void")); append_ss(&line, make_lit_string("void"));
} }
append_ss(&line, make_lit_string("));}")); //{
terminate_with_null(&line); append_ss(&line, make_lit_string("));}\n"));
fprintf(file, "%s\n", line.str); append_ss(&out, line);
} }
} }
} }
fprintf(file, "\n#endif\n"); append_sc(&out, "\n#endif\n");
}
} }
else if (match_ss(lexeme, make_lit_string("DOC_EXPORT"))){ else if (match_ss(lexeme, make_lit_string("DOC_EXPORT"))){
++i, ++token; token = get_next_token(&pcontext);
if (i < count && token->type == CPP_TOKEN_COMMENT){ if (token && token->type == CPP_TOKEN_COMMENT){
++i, ++token; token = get_next_token(&pcontext);
if (i < count && token->type == CPP_PP_DEFINE){ if (token && token->type == CPP_PP_DEFINE){
++i, ++token; for (;(token = get_next_token(&pcontext)) != 0;){
for (; i < count; ++i, ++token){
if (!(token->flags & CPP_TFLAG_PP_BODY)){ if (!(token->flags & CPP_TFLAG_PP_BODY)){
break; break;
} }
} }
--i, --token; if (token != 0){
get_prev_token(&pcontext);
}
do_print = false; do_print = false;
do_whitespace_print = false; do_whitespace_print = false;
} }
} }
} }
else if (match_ss(lexeme, make_lit_string("FSTRING_INLINE"))){
else if (match_ss(lexeme, make_lit_string("FSTRING_INLINE")) ||
match_ss(lexeme, make_lit_string("FSTRING_LINK"))){
if (!(token->flags & CPP_TFLAG_PP_BODY)){ if (!(token->flags & CPP_TFLAG_PP_BODY)){
fprintf(file, "#if !defined(FSTRING_GUARD)\n"); if (match_ss(lexeme, make_lit_string("FSTRING_INLINE"))){
append_sc(&out, "#if !defined(FSTRING_GUARD)\n");
print_function_body_code(file, &i, &token, count, code, start); }
else{
fprintf(file, "\n#endif"); append_sc(&out, "#if defined(FSTRING_IMPLEMENTATION)\n");
}
print_function_body_code(&out, &pcontext, start);
append_sc(&out, "\n#endif");
do_print = false; do_print = false;
} }
} }
else if (match_ss(lexeme, make_lit_string("FSTRING_LINK"))){
if (!(token->flags & CPP_TFLAG_PP_BODY)){
fprintf(file, "#if defined(FSTRING_IMPLEMENTATION)\n");
print_function_body_code(file, &i, &token, count, code, start);
fprintf(file, "\n#endif");
do_print = false;
}
}
else if (match_ss(lexeme, make_lit_string("CPP_NAME"))){ else if (match_ss(lexeme, make_lit_string("CPP_NAME"))){
Cpp_Token *token_start = token; Cpp_Token *token_start = token;
int32_t i_start = i;
int32_t has_cpp_name = false; int32_t has_cpp_name = false;
++i, ++token; token = get_next_token(&pcontext);
if (token->type == CPP_TOKEN_PARENTHESE_OPEN){ if (token && token->type == CPP_TOKEN_PARENTHESE_OPEN){
++i, ++token; token = get_next_token(&pcontext);
if (token->type == CPP_TOKEN_IDENTIFIER){ if (token && token->type == CPP_TOKEN_IDENTIFIER){
++i, ++token; token = get_next_token(&pcontext);
if (token->type == CPP_TOKEN_PARENTHESE_CLOSE){ if (token && token->type == CPP_TOKEN_PARENTHESE_CLOSE){
has_cpp_name = true; has_cpp_name = true;
do_print = false;
} }
} }
} }
if (!has_cpp_name){ if (!has_cpp_name){
i = i_start; token = set_token(&pcontext, token_start);
token = token_start; }
} }
do_print = false;
}
else if (token->type == CPP_TOKEN_COMMENT){ else if (token->type == CPP_TOKEN_COMMENT){
lexeme = make_string(code->str + token->start, token->size);
if (check_and_fix_docs(&lexeme)){ if (check_and_fix_docs(&lexeme)){
do_print = false; do_print = false;
} }
} }
if (i < count){ if ((token = get_token(&pcontext)) != 0){
if (do_print){ if (do_print){
pstr = make_string(code->str + token->start, token->size); pstr = get_lexeme(*token, pcontext.data);
print_str(file, pstr); append_ss(&out, pstr);
} }
start = token->start + token->size; start = token->start + token->size;
} }
} }
pstr = str_start_end(code->str, start, code->size); pstr = str_start_end(pcontext.data, start, parse.code.size);
print_str(file, pstr); append_ss(&out, pstr);
end_file_out(context);
}
else{
// TODO(allen): warning
} }
fclose(file);
//
// Output Docs // Output Docs
//
file = fopen(API_DOC, "wb"); if (begin_file_out(&context, API_DOC, &out)){
fprintf(file, append_sc(&out,
"<html lang=\"en-US\">\n" "<html lang=\"en-US\">"
"<head>\n" "<head>"
"<title>4coder API Docs</title>\n" "<title>4coder API Docs</title>"
"<style>\n" "<style>"
"body { " "body { "
"background: " BACK_COLOR "; " "background: " BACK_COLOR "; "
"color: " TEXT_COLOR "; " "color: " TEXT_COLOR "; "
"}\n" "}"
// H things // H things
"h1,h2,h3,h4 { " "h1,h2,h3,h4 { "
"color: " POP_COLOR_1 "; " "color: " POP_COLOR_1 "; "
"margin: 0; " "margin: 0; "
"}\n" "}"
"h2 { " "h2 { "
"margin-top: 6mm; " "margin-top: 6mm; "
"}\n" "}"
"h3 { " "h3 { "
"margin-top: 5mm; margin-bottom: 5mm; " "margin-top: 5mm; margin-bottom: 5mm; "
"}\n" "}"
"h4 { " "h4 { "
"font-size: 1.1em; " "font-size: 1.1em; "
"}\n" "}"
// ANCHORS // ANCHORS
"a { " "a { "
"color: " POP_COLOR_1 "; " "color: " POP_COLOR_1 "; "
"text-decoration: none; " "text-decoration: none; "
"}\n" "}"
"a:visited { " "a:visited { "
"color: " VISITED_LINK "; " "color: " VISITED_LINK "; "
"}\n" "}"
"a:hover { " "a:hover { "
"background: " POP_BACK_1 "; " "background: " POP_BACK_1 "; "
"}\n" "}"
// LIST // LIST
"ul { " "ul { "
"list-style: none; " "list-style: none; "
"padding: 0; " "padding: 0; "
"margin: 0; " "margin: 0; "
"}\n" "}"
"</style>\n" "</style>"
"</head>\n" "</head>\n"
"<body>\n" "<body>"
"<div style='font-family:Arial; margin: 0 auto; " "<div style='font-family:Arial; margin: 0 auto; "
"width: 800px; text-align: justify; line-height: 1.25;'>\n" "width: 800px; text-align: justify; line-height: 1.25;'>"
"<h1 style='margin-top: 5mm; margin-bottom: 5mm;'>4coder API</h1>\n" "<h1 style='margin-top: 5mm; margin-bottom: 5mm;'>4coder API</h1>"
); );
struct Section{ struct Section{
@ -2686,126 +2612,113 @@ generate_custom_headers(){
{"string_library", "String Library"} {"string_library", "String Library"}
}; };
fprintf(file, append_sc(&out,
"<h3 style='margin:0;'>Table of Contents</h3>\n" "<h3 style='margin:0;'>Table of Contents</h3>""<ul>");
"<ul>\n");
dump_file_out(context);
int32_t section_count = ArrayCount(sections); int32_t section_count = ArrayCount(sections);
for (int32_t i = 0; i < section_count; ++i){ for (int32_t i = 0; i < section_count; ++i){
fprintf(file, append_sc (&out, "<li><a href='#section_");
"<li><a href='#section_%s'>&sect;%d %s</a></li>", append_sc (&out, sections[i].id_string);
sections[i].id_string, append_sc (&out, "'>&sect;");
i+1, append_int_to_str (&out, i+1);
sections[i].display_string); append_s_char (&out, ' ');
append_sc (&out, sections[i].display_string);
append_sc (&out, "</a></li>");
} }
fprintf(file, append_sc(&out, "</ul>");
"</ul>\n"
);
#define MAJOR_SECTION "1" #define MAJOR_SECTION "1"
fprintf(file, append_sc(&out, "\n<h2 id='section_");
"<h2 id='section_%s'>&sect;"MAJOR_SECTION" %s</h2>\n" append_sc(&out, sections[0].id_string);
"<div>\n" append_sc(&out, "'>&sect;"MAJOR_SECTION" ");
append_sc(&out, sections[0].display_string);
"<p>\n" append_sc(&out,
"This is the documentation for " VERSION " The documentation is still under " "</h2>"
"construction so some of the links are linking to sections that have not " "<div>"
"been written yet. What is here should be correct and I suspect useful " "<p>This is the documentation for " VERSION " The documentation is still "
"even without some of the other sections. " "under construction so some of the links are linking to sections that "
"</p>\n" "have not been written yet. What is here should be correct and I suspect "
"useful even without some of the other sections.</p>"
"<p>\n" "<p>If you have questions or discover errors please contact "
"If you have questions or discover errors please contact "
"<span style='"CODE_STYLE"'>editor@4coder.net</span> or " "<span style='"CODE_STYLE"'>editor@4coder.net</span> or "
"to get help from community members you can post on the " "to get help from community members you can post on the "
"4coder forums hosted on handmade.network at " "4coder forums hosted on handmade.network at "
"<span style='"CODE_STYLE"'>4coder.handmade.network</span>" "<span style='"CODE_STYLE"'>4coder.handmade.network</span></p>"
"</p>\n" "</div>");
"</div>\n",
sections[0].id_string,
sections[0].display_string
);
#undef MAJOR_SECTION #undef MAJOR_SECTION
#define MAJOR_SECTION "2" #define MAJOR_SECTION "2"
// TODO(allen): Write the 4coder system descriptions. // TODO(allen): Write the 4coder system descriptions.
fprintf(file, append_sc(&out, "\n<h2 id='section_");
"<h2 id='section_%s'>&sect;"MAJOR_SECTION" %s</h2>\n", append_sc(&out, sections[1].id_string);
sections[1].id_string, append_sc(&out, "'>&sect;"MAJOR_SECTION" ");
sections[1].display_string); append_sc(&out, sections[1].display_string);
append_sc(&out, "</h2>");
{ append_sc(&out, "<div><i>Coming Soon</i><div>");
fprintf(file,
"<div><i>\n"
"Coming Soon"
"</i><div>\n");
}
#undef MAJOR_SECTION #undef MAJOR_SECTION
#define MAJOR_SECTION "3" #define MAJOR_SECTION "3"
fprintf(file, append_sc(&out, "\n<h2 id='section_");
"<h2 id='section_%s'>&sect;"MAJOR_SECTION" %s</h2>\n", append_sc(&out, sections[2].id_string);
sections[2].id_string, append_sc(&out, "'>&sect;"MAJOR_SECTION" ");
sections[2].display_string); append_sc(&out, sections[2].display_string);
{ append_sc(&out, "</h2>");
#undef SECTION #undef SECTION
#define SECTION MAJOR_SECTION".1" #define SECTION MAJOR_SECTION".1"
fprintf(file, append_sc(&out, "<h3>&sect;"SECTION" Function List</h3><ul>");
"<h3>&sect;"SECTION" Function List</h3>\n"
"<ul>\n");
for (int32_t i = 0; i < unit_custom.set.count; ++i){ for (int32_t i = 0; i < unit_custom.set.count; ++i){
String name = func_4ed_names.names[i].public_name; String name = func_4ed_names.names[i].public_name;
fprintf(file, append_sc(&out, "<li><a href='#");
"<li>" append_ss(&out, name);
"<a href='#%.*s_doc'>%.*s</a>" append_sc(&out, "_doc'>");
"</li>\n", append_ss(&out, name);
name.size, name.str, append_sc(&out, "</a></li>");
name.size, name.str
);
} }
fprintf(file, "</ul>\n"); append_sc(&out, "</ul>");
#undef SECTION #undef SECTION
#define SECTION MAJOR_SECTION".2" #define SECTION MAJOR_SECTION".2"
fprintf(file, append_sc(&out, "<h3>&sect;"SECTION" Type List</h3><ul>");
"<h3>&sect;"SECTION" Type List</h3>\n"
"<ul>\n"
);
for (int32_t i = 0; i < unit.set.count; ++i){ for (int32_t i = 0; i < unit.set.count; ++i){
String name = unit.set.items[i].name; String name = unit.set.items[i].name;
fprintf(file, append_sc(&out, "<li><a href='#");
"<li>" append_ss(&out, name);
"<a href='#%.*s_doc'>%.*s</a>" append_sc(&out, "_doc'>");
"</li>\n", append_ss(&out, name);
name.size, name.str, append_sc(&out, "</a></li>");
name.size, name.str
);
} }
append_sc(&out, "</ul>");
fprintf(file, "</ul>\n");
#undef SECTION #undef SECTION
#define SECTION MAJOR_SECTION".3" #define SECTION MAJOR_SECTION".3"
fprintf(file, "<h3>&sect;"SECTION" Function Descriptions</h3>\n"); append_sc(&out, "<h3>&sect;"SECTION" Function Descriptions</h3>\n");
for (int32_t i = 0; i < unit_custom.set.count; ++i){ for (int32_t i = 0; i < unit_custom.set.count; ++i){
String name = func_4ed_names.names[i].public_name; String name = func_4ed_names.names[i].public_name;
fprintf(file, append_sc (&out, "<div id='");
"<div id='%.*s_doc' style='margin-bottom: 1cm;'>\n" append_ss (&out, name);
"<h4>&sect;"SECTION".%d: %.*s</h4>\n" append_sc (&out, "_doc' style='margin-bottom: 1cm;'><h4>&sect;"SECTION".");
"<div style='"CODE_STYLE" "DESCRIPT_SECTION_STYLE"'>", append_int_to_str(&out, i+1);
name.size, name.str, i+1, append_sc (&out, ": ");
name.size, name.str append_ss (&out, name);
); append_sc (&out, "</h4><div style='"CODE_STYLE" "DESCRIPT_SECTION_STYLE"'>");
dump_file_out(context);
// TODO(allen): Continue converting this to the string system.
print_function_html(file, unit_custom.set.items[i], name, "app->"); print_function_html(file, unit_custom.set.items[i], name, "app->");
fprintf(file, "</div>\n"); fprintf(file, "</div>\n");
@ -2823,7 +2736,7 @@ generate_custom_headers(){
for (int32_t i = 0; i < unit.set.count; ++i, ++I){ for (int32_t i = 0; i < unit.set.count; ++i, ++I){
print_item(part, file, unit.set.items + i, SECTION, I); print_item(part, file, unit.set.items + i, SECTION, I);
} }
}
#undef MAJOR_SECTION #undef MAJOR_SECTION
#define MAJOR_SECTION "4" #define MAJOR_SECTION "4"
@ -2936,7 +2849,10 @@ generate_custom_headers(){
"</html>\n" "</html>\n"
); );
fclose(file); end_file_out(context);
}
else{
// TODO(allen): warning
} }
} }