2016-02-25 23:52:11 +00:00
|
|
|
/*
|
2016-08-30 19:30:41 +00:00
|
|
|
* Mr. 4th Dimention - Allen Webster
|
|
|
|
*
|
|
|
|
* 25.02.2016
|
|
|
|
*
|
|
|
|
* File editing view for 4coder
|
|
|
|
*
|
|
|
|
*/
|
2016-02-25 23:52:11 +00:00
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
#define KEYCODES_FILE "4coder_API/keycodes.h"
|
|
|
|
#define STYLE_FILE "4coder_API/style.h"
|
2016-02-25 23:52:11 +00:00
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
#define API_H "4coder_API/app_functions.h"
|
|
|
|
#define OS_API_H "4ed_os_custom_api.h"
|
|
|
|
|
2017-07-07 23:54:50 +00:00
|
|
|
#include "4ed_meta_defines.h"
|
2017-01-23 06:19:43 +00:00
|
|
|
#include "../4coder_API/version.h"
|
|
|
|
|
|
|
|
#define FSTRING_IMPLEMENTATION
|
|
|
|
#include "../4coder_lib/4coder_string.h"
|
2017-07-10 16:35:25 +00:00
|
|
|
//#include "../4coder_lib/4coder_mem.h"
|
2016-06-24 19:33:37 +00:00
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
#include "../4cpp/4cpp_lexer.h"
|
2016-06-24 19:33:37 +00:00
|
|
|
|
2016-08-30 19:30:41 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2016-11-03 04:57:26 +00:00
|
|
|
|
2017-07-10 16:35:25 +00:00
|
|
|
#define FTECH_FILE_MOVING_IMPLEMENTATION
|
|
|
|
#include "4ed_file_moving.h"
|
2017-07-09 04:28:33 +00:00
|
|
|
#include "4ed_meta_parser.cpp"
|
2017-07-10 16:35:25 +00:00
|
|
|
#include "4ed_meta_keywords.h"
|
2017-07-09 04:28:33 +00:00
|
|
|
#include "4ed_out_context.cpp"
|
2016-03-04 23:10:00 +00:00
|
|
|
|
2016-09-02 19:39:38 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
2016-02-25 23:52:11 +00:00
|
|
|
char *keys_that_need_codes[] = {
|
2016-06-07 18:52:40 +00:00
|
|
|
"back",
|
|
|
|
"up",
|
|
|
|
"down",
|
|
|
|
"left",
|
|
|
|
"right",
|
|
|
|
"del",
|
|
|
|
"insert",
|
|
|
|
"home",
|
|
|
|
"end",
|
|
|
|
"page_up",
|
|
|
|
"page_down",
|
|
|
|
"esc",
|
|
|
|
|
|
|
|
"mouse_left",
|
|
|
|
"mouse_right",
|
2016-09-09 17:14:38 +00:00
|
|
|
"mouse_left_release",
|
|
|
|
"mouse_right_release",
|
2016-02-25 23:52:11 +00:00
|
|
|
|
|
|
|
"f1",
|
|
|
|
"f2",
|
|
|
|
"f3",
|
|
|
|
"f4",
|
|
|
|
"f5",
|
|
|
|
"f6",
|
|
|
|
"f7",
|
|
|
|
"f8",
|
|
|
|
|
|
|
|
"f9",
|
|
|
|
"f10",
|
|
|
|
"f11",
|
|
|
|
"f12",
|
|
|
|
"f13",
|
|
|
|
"f14",
|
|
|
|
"f15",
|
|
|
|
"f16",
|
|
|
|
};
|
|
|
|
|
2017-02-12 06:01:01 +00:00
|
|
|
internal void
|
2016-08-30 19:30:41 +00:00
|
|
|
generate_keycode_enum(){
|
2017-01-23 06:19:43 +00:00
|
|
|
char *filename_keycodes = KEYCODES_FILE;
|
2017-02-12 06:01:01 +00:00
|
|
|
|
2017-02-18 01:04:41 +00:00
|
|
|
uint16_t code = 0xD800;
|
2016-02-25 23:52:11 +00:00
|
|
|
|
2016-09-02 19:39:38 +00:00
|
|
|
String out = make_out_string(10 << 20);
|
2016-06-07 16:26:11 +00:00
|
|
|
|
2017-02-12 06:01:01 +00:00
|
|
|
Out_Context context = {0};
|
2016-09-02 19:39:38 +00:00
|
|
|
if (begin_file_out(&context, filename_keycodes, &out)){
|
2017-02-12 06:01:01 +00:00
|
|
|
int32_t count = ArrayCount(keys_that_need_codes);
|
2016-09-02 19:39:38 +00:00
|
|
|
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "enum{\n");
|
2017-02-12 06:01:01 +00:00
|
|
|
for (int32_t i = 0; i < count;){
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "key_");
|
|
|
|
append(&out, keys_that_need_codes[i++]);
|
|
|
|
append(&out, " = ");
|
2017-02-12 06:01:01 +00:00
|
|
|
append_int_to_str(&out, code++);
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, ",\n");
|
2016-09-02 19:39:38 +00:00
|
|
|
}
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "};\n");
|
2016-09-02 19:39:38 +00:00
|
|
|
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out,
|
|
|
|
"static char*\n"
|
|
|
|
"global_key_name(uint32_t key_code, int32_t *size){\n"
|
|
|
|
"char *result = 0;\n"
|
|
|
|
"switch(key_code){\n");
|
2016-09-02 19:39:38 +00:00
|
|
|
|
2017-02-12 06:01:01 +00:00
|
|
|
for (int32_t i = 0; i < count; ++i){
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "case key_");
|
|
|
|
append(&out, keys_that_need_codes[i]);
|
|
|
|
append(&out, ": result = \"");
|
|
|
|
append(&out, keys_that_need_codes[i]);
|
|
|
|
append(&out, "\"; *size = sizeof(\"");
|
|
|
|
append(&out, keys_that_need_codes[i]);
|
|
|
|
append(&out, "\")-1; break;\n");
|
2016-09-02 19:39:38 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out,
|
|
|
|
"}\n"
|
|
|
|
"return(result);\n"
|
|
|
|
"}\n");
|
2016-09-02 19:39:38 +00:00
|
|
|
|
|
|
|
end_file_out(context);
|
2016-06-07 16:26:11 +00:00
|
|
|
}
|
2016-02-27 17:34:13 +00:00
|
|
|
}
|
|
|
|
|
2016-03-04 23:10:00 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
2016-09-02 19:39:38 +00:00
|
|
|
static void
|
|
|
|
struct_begin(String *str, char *name){
|
2017-07-10 16:35:25 +00:00
|
|
|
append(str, "struct ");
|
|
|
|
append(str, name);
|
|
|
|
append(str, "{\n"); //}
|
2016-09-02 19:39:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
enum_begin(String *str, char *name){
|
2017-07-10 16:35:25 +00:00
|
|
|
append(str, "enum ");
|
|
|
|
append(str, name);
|
|
|
|
append(str, "{\n"); //}
|
2016-09-02 19:39:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-11-02 03:27:51 +00:00
|
|
|
struct_end(String *str){ //{
|
2017-07-10 16:35:25 +00:00
|
|
|
append(str, "};\n\n");
|
2016-09-02 19:39:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char* bar_style_fields[] = {
|
2016-03-04 23:10:00 +00:00
|
|
|
"bar",
|
|
|
|
"bar_active",
|
|
|
|
"base",
|
|
|
|
"pop1",
|
|
|
|
"pop2",
|
|
|
|
};
|
|
|
|
|
2016-09-02 19:39:38 +00:00
|
|
|
static char* main_style_fields[] = {
|
2016-03-04 23:10:00 +00:00
|
|
|
"back",
|
2016-06-07 18:52:40 +00:00
|
|
|
"margin",
|
|
|
|
"margin_hover",
|
|
|
|
"margin_active",
|
2017-04-23 02:11:03 +00:00
|
|
|
"list_item",
|
|
|
|
"list_item_hover",
|
|
|
|
"list_item_active",
|
2016-06-07 18:52:40 +00:00
|
|
|
"cursor",
|
|
|
|
"at_cursor",
|
|
|
|
"highlight",
|
|
|
|
"at_highlight",
|
|
|
|
"mark",
|
|
|
|
"default",
|
|
|
|
"comment",
|
|
|
|
"keyword",
|
|
|
|
"str_constant",
|
|
|
|
"char_constant",
|
|
|
|
"int_constant",
|
|
|
|
"float_constant",
|
|
|
|
"bool_constant",
|
2016-03-04 23:10:00 +00:00
|
|
|
"preproc",
|
2016-06-07 18:52:40 +00:00
|
|
|
"include",
|
|
|
|
"special_character",
|
2016-10-14 21:21:17 +00:00
|
|
|
"ghost_character",
|
2016-06-07 18:52:40 +00:00
|
|
|
"highlight_junk",
|
|
|
|
"highlight_white",
|
2016-03-04 23:10:00 +00:00
|
|
|
"paste",
|
|
|
|
"undo",
|
|
|
|
"next_undo",
|
|
|
|
};
|
|
|
|
|
2016-03-05 04:10:55 +00:00
|
|
|
static char*
|
|
|
|
make_style_tag(char *tag){
|
|
|
|
char *str;
|
2016-08-29 01:03:26 +00:00
|
|
|
int32_t len;
|
2016-03-04 23:10:00 +00:00
|
|
|
|
2016-08-29 01:03:26 +00:00
|
|
|
len = (int32_t)strlen(tag);
|
2016-03-05 04:10:55 +00:00
|
|
|
str = (char*)malloc(len + 1);
|
2016-09-02 19:39:38 +00:00
|
|
|
to_camel_cc(tag, str);
|
2016-03-05 04:10:55 +00:00
|
|
|
str[len] = 0;
|
2016-06-07 18:52:40 +00:00
|
|
|
|
2016-03-05 04:10:55 +00:00
|
|
|
return(str);
|
2016-03-04 23:10:00 +00:00
|
|
|
}
|
|
|
|
|
2016-09-02 19:39:38 +00:00
|
|
|
static void
|
2016-08-30 19:30:41 +00:00
|
|
|
generate_style(){
|
2017-01-23 06:19:43 +00:00
|
|
|
char filename_4coder[] = STYLE_FILE;
|
2016-03-04 23:10:00 +00:00
|
|
|
char filename_4ed[] = "4ed_style.h";
|
2016-06-07 18:52:40 +00:00
|
|
|
|
2016-09-02 19:39:38 +00:00
|
|
|
String out = make_out_string(10 << 20);
|
|
|
|
Out_Context context = {0};
|
2016-03-04 23:10:00 +00:00
|
|
|
|
2016-09-02 19:39:38 +00:00
|
|
|
if (begin_file_out(&context, filename_4coder, &out)){
|
|
|
|
|
|
|
|
enum_begin(&out, "Style_Tag");
|
|
|
|
{
|
2017-06-05 21:48:49 +00:00
|
|
|
int32_t count = ArrayCount(bar_style_fields);
|
|
|
|
for (int32_t i = 0; i < count; ++i){
|
|
|
|
char *tag = make_style_tag(bar_style_fields[i]);
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "Stag_");
|
|
|
|
append(&out, tag);
|
|
|
|
append(&out, ",\n");
|
2016-09-02 19:39:38 +00:00
|
|
|
free(tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
count = ArrayCount(main_style_fields);
|
2017-06-05 21:48:49 +00:00
|
|
|
for (int32_t i = 0; i < count; ++i){
|
|
|
|
char *tag = make_style_tag(main_style_fields[i]);
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "Stag_");
|
|
|
|
append(&out, tag);
|
|
|
|
append(&out, ",\n");
|
2016-09-02 19:39:38 +00:00
|
|
|
free(tag);
|
|
|
|
}
|
2017-06-05 21:48:49 +00:00
|
|
|
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "Stag_COUNT\n");
|
2016-03-04 23:10:00 +00:00
|
|
|
}
|
2016-09-02 19:39:38 +00:00
|
|
|
struct_end(&out);
|
|
|
|
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "static char *style_tag_names[] = {\n");
|
2017-06-05 21:48:49 +00:00
|
|
|
{
|
|
|
|
int32_t count = ArrayCount(bar_style_fields);
|
|
|
|
for (int32_t i = 0; i < count; ++i){
|
|
|
|
char *tag = make_style_tag(bar_style_fields[i]);
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "\"");
|
|
|
|
append(&out, tag);
|
|
|
|
append(&out, "\",\n");
|
2017-06-05 21:48:49 +00:00
|
|
|
free(tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
count = ArrayCount(main_style_fields);
|
|
|
|
for (int32_t i = 0; i < count; ++i){
|
|
|
|
char *tag = make_style_tag(main_style_fields[i]);
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "\"");
|
|
|
|
append(&out, tag);
|
|
|
|
append(&out, "\",\n");
|
2017-06-05 21:48:49 +00:00
|
|
|
free(tag);
|
|
|
|
}
|
|
|
|
}
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "};\n");
|
2017-06-05 21:48:49 +00:00
|
|
|
|
2016-09-02 19:39:38 +00:00
|
|
|
end_file_out(context);
|
2016-03-04 23:10:00 +00:00
|
|
|
}
|
|
|
|
|
2016-09-02 19:39:38 +00:00
|
|
|
if (begin_file_out(&context, filename_4ed, &out)){
|
|
|
|
|
|
|
|
struct_begin(&out, "Interactive_Style");
|
|
|
|
{
|
2017-06-05 21:48:49 +00:00
|
|
|
int32_t count = ArrayCount(bar_style_fields);
|
|
|
|
for (int32_t i = 0; i < count; ++i){
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "u32 ");
|
|
|
|
append(&out, bar_style_fields[i]);
|
|
|
|
append(&out, "_color;\n");
|
2016-09-02 19:39:38 +00:00
|
|
|
}
|
2016-03-04 23:10:00 +00:00
|
|
|
}
|
2016-09-02 19:39:38 +00:00
|
|
|
struct_end(&out);
|
|
|
|
|
|
|
|
struct_begin(&out, "Style_Main_Data");
|
|
|
|
{
|
2017-06-05 21:48:49 +00:00
|
|
|
int32_t count = ArrayCount(main_style_fields);
|
|
|
|
for (int32_t i = 0; i < count; ++i){
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "u32 ");
|
|
|
|
append(&out, main_style_fields[i]);
|
|
|
|
append(&out, "_color;\n");
|
2016-09-02 19:39:38 +00:00
|
|
|
}
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "Interactive_Style file_info_style;\n");
|
2016-03-05 04:10:55 +00:00
|
|
|
}
|
2016-09-02 19:39:38 +00:00
|
|
|
struct_end(&out);
|
2016-03-05 04:10:55 +00:00
|
|
|
|
2016-11-02 03:27:51 +00:00
|
|
|
{
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out,
|
|
|
|
"inline u32*\n"
|
|
|
|
"style_index_by_tag(Style_Main_Data *s, u32 tag){\n"
|
|
|
|
"u32 *result = 0;\n"
|
|
|
|
"switch (tag){\n");
|
2016-09-04 16:39:21 +00:00
|
|
|
|
2017-06-05 21:48:49 +00:00
|
|
|
int32_t count = ArrayCount(bar_style_fields);
|
|
|
|
for (int32_t i = 0; i < count; ++i){
|
|
|
|
char *tag = make_style_tag(bar_style_fields[i]);
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "case Stag_");
|
|
|
|
append(&out, tag);
|
|
|
|
append(&out, ": result = &s->file_info_style.");
|
|
|
|
append(&out, bar_style_fields[i]);
|
|
|
|
append(&out, "_color; break;\n");
|
2016-11-02 03:27:51 +00:00
|
|
|
free(tag);
|
|
|
|
}
|
2016-09-04 16:39:21 +00:00
|
|
|
|
2016-11-02 03:27:51 +00:00
|
|
|
count = ArrayCount(main_style_fields);
|
2017-06-05 21:48:49 +00:00
|
|
|
for (int32_t i = 0; i < count; ++i){
|
|
|
|
char *tag = make_style_tag(main_style_fields[i]);
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "case Stag_");
|
|
|
|
append(&out, tag);
|
|
|
|
append(&out, ": result = &s->");
|
|
|
|
append(&out, main_style_fields[i]);
|
|
|
|
append(&out, "_color; break;\n");
|
2016-11-02 03:27:51 +00:00
|
|
|
free(tag);
|
|
|
|
}
|
2016-09-04 16:39:21 +00:00
|
|
|
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out,
|
|
|
|
"}\n"
|
|
|
|
"return(result);\n"
|
|
|
|
"}\n\n");
|
2016-09-04 16:39:21 +00:00
|
|
|
}
|
|
|
|
|
2016-11-02 03:27:51 +00:00
|
|
|
end_file_out(context);
|
2016-09-03 02:27:09 +00:00
|
|
|
}
|
2016-11-02 03:27:51 +00:00
|
|
|
|
|
|
|
free(out.str);
|
2016-09-03 02:27:09 +00:00
|
|
|
}
|
|
|
|
|
2016-11-02 03:27:51 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
//
|
|
|
|
// Meta Parse Rules
|
|
|
|
//
|
|
|
|
|
2016-07-06 19:18:10 +00:00
|
|
|
static void
|
2016-09-04 05:08:36 +00:00
|
|
|
print_function_body_code(String *out, Parse_Context *context, int32_t start){
|
|
|
|
String pstr = {0}, lexeme = {0};
|
|
|
|
Cpp_Token *token = 0;
|
2016-07-06 19:18:10 +00:00
|
|
|
|
2016-09-04 05:08:36 +00:00
|
|
|
int32_t do_print = 0;
|
2016-08-29 01:03:26 +00:00
|
|
|
int32_t nest_level = 0;
|
|
|
|
int32_t finish = false;
|
|
|
|
int32_t do_whitespace_print = false;
|
2016-11-02 03:27:51 +00:00
|
|
|
int32_t is_first = true;
|
|
|
|
|
2016-09-04 05:08:36 +00:00
|
|
|
for (; (token = get_token(context)) != 0; get_next_token(context)){
|
2016-07-06 19:18:10 +00:00
|
|
|
if (do_whitespace_print){
|
2016-09-04 05:08:36 +00:00
|
|
|
pstr = str_start_end(context->data, start, token->start);
|
2017-07-10 16:35:25 +00:00
|
|
|
append(out, pstr);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
do_whitespace_print = true;
|
|
|
|
}
|
|
|
|
|
2016-09-04 05:08:36 +00:00
|
|
|
do_print = true;
|
2016-07-06 19:18:10 +00:00
|
|
|
if (token->type == CPP_TOKEN_COMMENT){
|
2016-09-04 05:08:36 +00:00
|
|
|
lexeme = get_lexeme(*token, context->data);
|
2016-07-06 19:18:10 +00:00
|
|
|
if (check_and_fix_docs(&lexeme)){
|
|
|
|
do_print = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (token->type == CPP_TOKEN_BRACE_OPEN){
|
|
|
|
++nest_level;
|
|
|
|
}
|
|
|
|
else if (token->type == CPP_TOKEN_BRACE_CLOSE){
|
|
|
|
--nest_level;
|
|
|
|
if (nest_level == 0){
|
|
|
|
finish = true;
|
|
|
|
}
|
|
|
|
}
|
2016-11-02 03:27:51 +00:00
|
|
|
if (is_first){
|
|
|
|
do_print = false;
|
|
|
|
is_first = false;
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
|
2016-09-04 05:08:36 +00:00
|
|
|
if (do_print){
|
|
|
|
pstr = get_lexeme(*token, context->data);
|
2017-07-10 16:35:25 +00:00
|
|
|
append(out, pstr);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
|
2016-09-04 05:08:36 +00:00
|
|
|
start = token->start + token->size;
|
|
|
|
|
2016-07-06 19:18:10 +00:00
|
|
|
if (finish){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-02 19:39:38 +00:00
|
|
|
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
|
2017-07-10 16:35:25 +00:00
|
|
|
allocate_app_api(int32_t count){
|
2016-09-02 19:39:38 +00:00
|
|
|
App_API app_api = {0};
|
2017-07-10 16:35:25 +00:00
|
|
|
app_api.names = fm_push_array(App_API_Name, count);
|
2016-09-03 05:03:03 +00:00
|
|
|
memset(app_api.names, 0, sizeof(App_API_Name)*count);
|
2016-09-02 19:39:38 +00:00
|
|
|
return(app_api);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-07-06 19:18:10 +00:00
|
|
|
generate_custom_headers(){
|
2017-01-23 06:19:43 +00:00
|
|
|
META_BEGIN();
|
2016-07-06 19:18:10 +00:00
|
|
|
|
2016-08-30 19:30:41 +00:00
|
|
|
int32_t size = (512 << 20);
|
2016-07-06 19:18:10 +00:00
|
|
|
void *mem = malloc(size);
|
|
|
|
memset(mem, 0, size);
|
|
|
|
|
2016-09-04 01:44:12 +00:00
|
|
|
// NOTE(allen): Parse the customization API files
|
2017-01-23 06:19:43 +00:00
|
|
|
static char *functions_files[] = { "4ed_api_implementation.cpp", 0 };
|
2017-07-10 16:35:25 +00:00
|
|
|
Meta_Unit unit_custom = compile_meta_unit(".", functions_files, ExpandArray(meta_keywords));
|
2017-01-23 06:19:43 +00:00
|
|
|
if (unit_custom.parse == 0){
|
|
|
|
Assert(!"Missing one or more input files!");
|
|
|
|
}
|
2016-09-04 01:44:12 +00:00
|
|
|
|
|
|
|
// NOTE(allen): Compute and store variations of the function names
|
2017-07-10 16:35:25 +00:00
|
|
|
App_API func_4ed_names = allocate_app_api(unit_custom.set.count);
|
2016-07-06 19:18:10 +00:00
|
|
|
|
2016-09-03 22:43:37 +00:00
|
|
|
for (int32_t i = 0; i < unit_custom.set.count; ++i){
|
|
|
|
String name_string = unit_custom.set.items[i].name;
|
2016-09-02 19:39:38 +00:00
|
|
|
String *macro = &func_4ed_names.names[i].macro;
|
|
|
|
String *public_name = &func_4ed_names.names[i].public_name;
|
2016-05-25 22:43:58 +00:00
|
|
|
|
2017-07-10 16:35:25 +00:00
|
|
|
*macro = str_alloc(name_string.size+4);
|
2016-09-04 01:44:12 +00:00
|
|
|
to_upper_ss(macro, name_string);
|
2017-07-10 16:35:25 +00:00
|
|
|
append(macro, make_lit_string("_SIG"));
|
2016-06-24 19:33:37 +00:00
|
|
|
|
2017-07-10 16:35:25 +00:00
|
|
|
*public_name = str_alloc(name_string.size);
|
2016-09-04 01:44:12 +00:00
|
|
|
to_lower_ss(public_name, name_string);
|
2016-06-24 19:33:37 +00:00
|
|
|
|
2017-07-10 16:35:25 +00:00
|
|
|
fm_align();
|
2016-06-24 19:33:37 +00:00
|
|
|
}
|
|
|
|
|
2016-09-04 01:44:12 +00:00
|
|
|
// NOTE(allen): Output
|
2017-07-10 16:35:25 +00:00
|
|
|
String out = str_alloc(10 << 20);
|
2016-09-04 01:44:12 +00:00
|
|
|
Out_Context context = {0};
|
2016-05-25 22:43:58 +00:00
|
|
|
|
2016-09-04 01:44:12 +00:00
|
|
|
// NOTE(allen): Custom API headers
|
|
|
|
if (begin_file_out(&context, OS_API_H, &out)){
|
|
|
|
int32_t main_api_count = unit_custom.parse[0].item_count;
|
|
|
|
int32_t os_api_count = unit_custom.parse[1].item_count;
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "struct Application_Links;\n");
|
2017-01-23 06:19:43 +00:00
|
|
|
|
2016-09-04 01:44:12 +00:00
|
|
|
for (int32_t i = main_api_count; i < os_api_count; ++i){
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "#define ");
|
|
|
|
append(&out, func_4ed_names.names[i].macro);
|
|
|
|
append(&out, "(n) ");
|
|
|
|
append(&out, unit_custom.set.items[i].ret);
|
|
|
|
append(&out, " n");
|
|
|
|
append(&out, unit_custom.set.items[i].args);
|
2016-09-04 01:44:12 +00:00
|
|
|
append_s_char(&out, '\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int32_t i = main_api_count; i < os_api_count; ++i){
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "typedef ");
|
|
|
|
append(&out, func_4ed_names.names[i].macro);
|
2016-09-04 01:44:12 +00:00
|
|
|
append_s_char(&out, '(');
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, unit_custom.set.items[i].name);
|
|
|
|
append(&out, "_Function);\n");
|
2016-09-04 01:44:12 +00:00
|
|
|
}
|
2016-05-25 22:43:58 +00:00
|
|
|
|
2016-09-04 01:44:12 +00:00
|
|
|
end_file_out(context);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
// TODO(allen): warning
|
2016-05-25 22:43:58 +00:00
|
|
|
}
|
|
|
|
|
2016-09-04 01:44:12 +00:00
|
|
|
if (begin_file_out(&context, API_H, &out)){
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "struct Application_Links;\n");
|
2017-01-23 06:19:43 +00:00
|
|
|
|
2016-09-04 01:44:12 +00:00
|
|
|
for (int32_t i = 0; i < unit_custom.set.count; ++i){
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "#define ");
|
|
|
|
append(&out, func_4ed_names.names[i].macro);
|
|
|
|
append(&out, "(n) ");
|
|
|
|
append(&out, unit_custom.set.items[i].ret);
|
|
|
|
append(&out, " n");
|
|
|
|
append(&out, unit_custom.set.items[i].args);
|
2016-09-04 01:44:12 +00:00
|
|
|
append_s_char(&out, '\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int32_t i = 0; i < unit_custom.set.count; ++i){
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "typedef ");
|
|
|
|
append(&out, func_4ed_names.names[i].macro);
|
2016-09-04 01:44:12 +00:00
|
|
|
append_s_char(&out, '(');
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, unit_custom.set.items[i].name);
|
|
|
|
append(&out, "_Function);\n");
|
2016-09-04 01:44:12 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "struct Application_Links{\n");
|
2016-09-17 00:03:09 +00:00
|
|
|
|
2016-09-04 01:44:12 +00:00
|
|
|
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "#if defined(ALLOW_DEP_4CODER)\n");
|
2016-09-04 01:44:12 +00:00
|
|
|
for (int32_t i = 0; i < unit_custom.set.count; ++i){
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, unit_custom.set.items[i].name);
|
|
|
|
append(&out, "_Function *");
|
|
|
|
append(&out, func_4ed_names.names[i].public_name);
|
|
|
|
append(&out, ";\n");
|
2016-09-04 01:44:12 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "#else\n");
|
2016-09-17 00:03:09 +00:00
|
|
|
|
|
|
|
for (int32_t i = 0; i < unit_custom.set.count; ++i){
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, unit_custom.set.items[i].name);
|
|
|
|
append(&out, "_Function *");
|
|
|
|
append(&out, func_4ed_names.names[i].public_name);
|
|
|
|
append(&out, "_;\n");
|
2016-09-17 00:03:09 +00:00
|
|
|
}
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "#endif\n");
|
|
|
|
|
|
|
|
append(&out,
|
|
|
|
"void *memory;\n"
|
|
|
|
"int32_t memory_size;\n"
|
|
|
|
"void *cmd_context;\n"
|
|
|
|
"void *system_links;\n"
|
|
|
|
"void *current_coroutine;\n"
|
|
|
|
"int32_t type_coroutine;\n"
|
|
|
|
"};\n");
|
|
|
|
|
|
|
|
append(&out, "#define FillAppLinksAPI(app_links) do{");
|
2016-09-04 01:44:12 +00:00
|
|
|
for (int32_t i = 0; i < unit_custom.set.count; ++i){
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "\\\napp_links->");
|
|
|
|
append(&out, func_4ed_names.names[i].public_name);
|
|
|
|
append(&out, "_ = ");
|
|
|
|
append(&out, unit_custom.set.items[i].name);
|
2016-09-04 01:44:12 +00:00
|
|
|
append_s_char(&out, ';');
|
|
|
|
}
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "} while(false)\n");
|
2016-09-04 01:44:12 +00:00
|
|
|
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "#if defined(ALLOW_DEP_4CODER)\n");
|
2016-09-17 00:03:09 +00:00
|
|
|
for (int32_t use_dep = 1; use_dep >= 0; --use_dep){
|
|
|
|
for (int32_t i = 0; i < unit_custom.set.count; ++i){
|
|
|
|
Argument_Breakdown breakdown = unit_custom.set.items[i].breakdown;
|
|
|
|
String ret = unit_custom.set.items[i].ret;
|
|
|
|
String public_name = func_4ed_names.names[i].public_name;
|
|
|
|
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "static inline ");
|
|
|
|
append(&out, ret);
|
|
|
|
append(&out, " ");
|
|
|
|
append(&out, public_name);
|
2016-09-17 00:03:09 +00:00
|
|
|
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "(");
|
2016-09-17 00:03:09 +00:00
|
|
|
for (int32_t j = 0; j < breakdown.count; ++j){
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, breakdown.args[j].param_string);
|
2016-09-17 00:03:09 +00:00
|
|
|
if (j+1 != breakdown.count){
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, ", ");
|
2016-09-17 00:03:09 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "){");
|
2016-09-17 00:03:09 +00:00
|
|
|
|
|
|
|
if (match_ss(ret, make_lit_string("void"))){
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "(");
|
2016-09-17 00:03:09 +00:00
|
|
|
}
|
|
|
|
else{
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "return(");
|
2016-09-17 00:03:09 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "app->");
|
|
|
|
append(&out, public_name);
|
2016-09-17 00:03:09 +00:00
|
|
|
if (!use_dep){
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "_");
|
2016-09-17 00:03:09 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "(");
|
2016-09-17 00:03:09 +00:00
|
|
|
for (int32_t j = 0; j < breakdown.count; ++j){
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, breakdown.args[j].param_name);
|
2016-09-17 00:03:09 +00:00
|
|
|
if (j+1 != breakdown.count){
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, ", ");
|
2016-09-17 00:03:09 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, ")");
|
2016-09-17 00:03:09 +00:00
|
|
|
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, ");}\n");
|
2016-09-17 00:03:09 +00:00
|
|
|
}
|
|
|
|
if (use_dep == 1){
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "#else\n");
|
2016-09-17 00:03:09 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-10 16:35:25 +00:00
|
|
|
append(&out, "#endif\n");
|
2016-09-17 00:03:09 +00:00
|
|
|
|
2016-09-04 01:44:12 +00:00
|
|
|
end_file_out(context);
|
2016-05-31 01:22:55 +00:00
|
|
|
}
|
2016-09-04 05:08:36 +00:00
|
|
|
else{
|
|
|
|
// TODO(allen): warning
|
|
|
|
}
|
2016-05-25 22:43:58 +00:00
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
META_FINISH();
|
2016-05-25 22:43:58 +00:00
|
|
|
}
|
|
|
|
|
2016-07-02 14:15:15 +00:00
|
|
|
int main(int argc, char **argv){
|
2017-07-10 16:35:25 +00:00
|
|
|
fm_init_system();
|
2016-08-30 19:30:41 +00:00
|
|
|
generate_keycode_enum();
|
|
|
|
generate_style();
|
|
|
|
generate_custom_headers();
|
2016-02-25 23:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|