new custom keywords booster pack; logging system in windows

master
Allen Webster 2017-06-12 13:40:54 -04:00
parent 624e35f8d7
commit 6a9f00a780
7 changed files with 216 additions and 7 deletions

View File

@ -13,6 +13,7 @@ TYPE: 'internal-for-default-system'
#include "4coder_helper/4coder_bind_helper.h"
#include "4coder_project_commands.cpp"
#include "languages/4coder_language_cpp.h"
#include "languages/4coder_language_rust.h"
#include "languages/4coder_language_cs.h"
#include "languages/4coder_language_java.h"
@ -119,6 +120,13 @@ OPEN_FILE_HOOK_SIG(default_file_settings){
parse_context_id = parse_context_language_rust;
}
if (match(ext, "cpp") || match(ext, "h") || match(ext, "c") || match(ext, "hpp") || match(ext, "cc")){
if (parse_context_language_cpp == 0){
init_language_cpp(app);
}
parse_context_id = parse_context_language_cpp;
}
break;
}
}

20
4ed.cpp
View File

@ -945,6 +945,7 @@ enum Command_Line_Action{
CLAct_WindowStreamMode,
CLAct_FontSize,
CLAct_FontUseHinting,
CLAct_Log,
CLAct_Count
};
@ -958,11 +959,10 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings,
char *arg = 0;
Command_Line_Mode mode = CLMode_App;
Command_Line_Action action = CLAct_Nothing;
i32 i = 0, index = 0;
b32 strict = 0;
b32 strict = false;
settings->init_files_max = ArrayCount(settings->init_files);
for (i = 1; i <= clparams.argc; ++i){
for (i32 i = 1; i <= clparams.argc; ++i){
if (i == clparams.argc){
arg = "";
}
@ -989,8 +989,8 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings,
if (arg[0] == '-'){
action = CLAct_Ignore;
switch (arg[1]){
case 'd': action = CLAct_CustomDLL; strict = 0; break;
case 'D': action = CLAct_CustomDLL; strict = 1; break;
case 'd': action = CLAct_CustomDLL; strict = false; break;
case 'D': action = CLAct_CustomDLL; strict = true; break;
case 'i': action = CLAct_InitialFilePosition; break;
@ -1002,11 +1002,13 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings,
case 'f': action = CLAct_FontSize; break;
case 'h': action = CLAct_FontUseHinting; --i; break;
case 'L': action = CLAct_Log; --i; break;
}
}
else if (arg[0] != 0){
if (settings->init_files_count < settings->init_files_max){
index = settings->init_files_count++;
i32 index = settings->init_files_count++;
settings->init_files[index] = arg;
}
}
@ -1088,6 +1090,12 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings,
plat_settings->use_hinting = true;
action = CLAct_Nothing;
}break;
case CLAct_Log:
{
plat_settings->use_log = true;
action = CLAct_Nothing;
}break;
}
}break;

2
4ed.h
View File

@ -57,6 +57,8 @@ struct Plat_Settings{
b8 fullscreen_window;
b8 stream_mode;
b8 use_log;
i32 window_w, window_h;
i32 window_x, window_y;
b8 set_window_pos;

Binary file not shown.

View File

@ -231,6 +231,9 @@ typedef Sys_Is_Fullscreen_Sig(System_Is_Fullscreen);
typedef Sys_Send_Exit_Signal_Sig(System_Send_Exit_Signal);
// debug
#define Sys_Log_Sig(name) void name(char *message, u32 length)
typedef Sys_Log_Sig(System_Log);
#define INTERNAL_Sys_Get_Thread_States_Sig(name) void name(Thread_Group_ID id, b8 *running, i32 *pending)
typedef INTERNAL_Sys_Get_Thread_States_Sig(INTERNAL_System_Get_Thread_States);
@ -288,6 +291,7 @@ struct System_Functions{
System_Send_Exit_Signal *send_exit_signal;
// debug: 1
System_Log *log;
INTERNAL_System_Get_Thread_States *internal_get_thread_states;
};

View File

@ -0,0 +1,161 @@
/*
4coder_language_cpp.h - Sets up the C++ language context.
TYPE: 'langauge-description'
*/
// TOP
#if !defined(FCODER_LANGUAGE_CPP_H)
#define FCODER_LANGUAGE_CPP_H
static Parse_Context_ID parse_context_language_cpp;
#define PSAT(s, t) {s, sizeof(s)-1, t}
static void
init_language_cpp(Application_Links *app){
if (parse_context_language_cpp != 0) return;
Parser_String_And_Type kw[] = {
PSAT("true" , CPP_TOKEN_BOOLEAN_CONSTANT),
PSAT("false" , CPP_TOKEN_BOOLEAN_CONSTANT),
PSAT("and" , CPP_TOKEN_AND),
PSAT("and_eq" , CPP_TOKEN_ANDEQ),
PSAT("bitand" , CPP_TOKEN_BIT_AND),
PSAT("bitor" , CPP_TOKEN_BIT_OR),
PSAT("or" , CPP_TOKEN_OR),
PSAT("or_eq" , CPP_TOKEN_OREQ),
PSAT("sizeof" , CPP_TOKEN_SIZEOF),
PSAT("alignof" , CPP_TOKEN_ALIGNOF),
PSAT("decltype" , CPP_TOKEN_DECLTYPE),
PSAT("throw" , CPP_TOKEN_THROW),
PSAT("new" , CPP_TOKEN_NEW),
PSAT("delete" , CPP_TOKEN_DELETE),
PSAT("xor" , CPP_TOKEN_BIT_XOR),
PSAT("xor_eq" , CPP_TOKEN_XOREQ),
PSAT("not" , CPP_TOKEN_NOT),
PSAT("not_eq" , CPP_TOKEN_NOTEQ),
PSAT("typeid" , CPP_TOKEN_TYPEID),
PSAT("compl" , CPP_TOKEN_BIT_NOT),
PSAT("void" , CPP_TOKEN_KEY_TYPE),
PSAT("bool" , CPP_TOKEN_KEY_TYPE),
PSAT("char" , CPP_TOKEN_KEY_TYPE),
PSAT("int" , CPP_TOKEN_KEY_TYPE),
PSAT("float" , CPP_TOKEN_KEY_TYPE),
PSAT("double" , CPP_TOKEN_KEY_TYPE),
PSAT("long" , CPP_TOKEN_KEY_MODIFIER),
PSAT("short" , CPP_TOKEN_KEY_MODIFIER),
PSAT("unsigned" , CPP_TOKEN_KEY_MODIFIER),
PSAT("const" , CPP_TOKEN_KEY_QUALIFIER),
PSAT("volatile" , CPP_TOKEN_KEY_QUALIFIER),
PSAT("asm" , CPP_TOKEN_KEY_CONTROL_FLOW),
PSAT("break" , CPP_TOKEN_KEY_CONTROL_FLOW),
PSAT("case" , CPP_TOKEN_KEY_CONTROL_FLOW),
PSAT("catch" , CPP_TOKEN_KEY_CONTROL_FLOW),
PSAT("continue" , CPP_TOKEN_KEY_CONTROL_FLOW),
PSAT("default" , CPP_TOKEN_KEY_CONTROL_FLOW),
PSAT("do" , CPP_TOKEN_KEY_CONTROL_FLOW),
PSAT("else" , CPP_TOKEN_KEY_CONTROL_FLOW),
PSAT("for" , CPP_TOKEN_KEY_CONTROL_FLOW),
PSAT("goto" , CPP_TOKEN_KEY_CONTROL_FLOW),
PSAT("if" , CPP_TOKEN_KEY_CONTROL_FLOW),
PSAT("return" , CPP_TOKEN_KEY_CONTROL_FLOW),
PSAT("switch" , CPP_TOKEN_KEY_CONTROL_FLOW),
PSAT("try" , CPP_TOKEN_KEY_CONTROL_FLOW),
PSAT("while" , CPP_TOKEN_KEY_CONTROL_FLOW),
PSAT("static_assert" , CPP_TOKEN_KEY_CONTROL_FLOW),
PSAT("const_cast" , CPP_TOKEN_KEY_CAST),
PSAT("dynamic_cast" , CPP_TOKEN_KEY_CAST),
PSAT("reinterpret_cast" , CPP_TOKEN_KEY_CAST),
PSAT("static_cast" , CPP_TOKEN_KEY_CAST),
PSAT("class" , CPP_TOKEN_KEY_TYPE_DECLARATION),
PSAT("enum" , CPP_TOKEN_KEY_TYPE_DECLARATION),
PSAT("struct" , CPP_TOKEN_KEY_TYPE_DECLARATION),
PSAT("typedef" , CPP_TOKEN_KEY_TYPE_DECLARATION),
PSAT("union" , CPP_TOKEN_KEY_TYPE_DECLARATION),
PSAT("template" , CPP_TOKEN_KEY_TYPE_DECLARATION),
PSAT("typename" , CPP_TOKEN_KEY_TYPE_DECLARATION),
PSAT("friend" , CPP_TOKEN_KEY_ACCESS),
PSAT("namespace" , CPP_TOKEN_KEY_ACCESS),
PSAT("private" , CPP_TOKEN_KEY_ACCESS),
PSAT("protected" , CPP_TOKEN_KEY_ACCESS),
PSAT("public" , CPP_TOKEN_KEY_ACCESS),
PSAT("using" , CPP_TOKEN_KEY_ACCESS),
PSAT("extern" , CPP_TOKEN_KEY_LINKAGE),
PSAT("export" , CPP_TOKEN_KEY_LINKAGE),
PSAT("inline" , CPP_TOKEN_KEY_LINKAGE),
PSAT("static" , CPP_TOKEN_KEY_LINKAGE),
PSAT("virtual" , CPP_TOKEN_KEY_LINKAGE),
PSAT("alignas" , CPP_TOKEN_KEY_OTHER),
PSAT("explicit" , CPP_TOKEN_KEY_OTHER),
PSAT("noexcept" , CPP_TOKEN_KEY_OTHER),
PSAT("nullptr" , CPP_TOKEN_KEY_OTHER),
PSAT("operator" , CPP_TOKEN_KEY_OTHER),
PSAT("register" , CPP_TOKEN_KEY_OTHER),
PSAT("this" , CPP_TOKEN_KEY_OTHER),
PSAT("thread_local" , CPP_TOKEN_KEY_OTHER),
#if defined(EXTRA_KEYWORDS)
#include EXTRA_KEYWORDS
#undef EXTRA_KEYWORDS
#endif
};
Parser_String_And_Type pp[] = {
PSAT("include" , CPP_PP_INCLUDE ),
PSAT("INCLUDE" , CPP_PP_INCLUDE ),
PSAT("version" , CPP_PP_VERSION ),
PSAT("VERSION" , CPP_PP_VERSION ),
PSAT("ifndef" , CPP_PP_IFNDEF ),
PSAT("IFNDEF" , CPP_PP_IFNDEF ),
PSAT("define" , CPP_PP_DEFINE ),
PSAT("DEFINE" , CPP_PP_DEFINE ),
PSAT("import" , CPP_PP_IMPORT ),
PSAT("IMPORT" , CPP_PP_IMPORT ),
PSAT("pragma" , CPP_PP_PRAGMA ),
PSAT("PRAGMA" , CPP_PP_PRAGMA ),
PSAT("undef" , CPP_PP_UNDEF ),
PSAT("UNDEF" , CPP_PP_UNDEF ),
PSAT("endif" , CPP_PP_ENDIF ),
PSAT("ENDIF" , CPP_PP_ENDIF ),
PSAT("error" , CPP_PP_ERROR ),
PSAT("ERROR" , CPP_PP_ERROR ),
PSAT("ifdef" , CPP_PP_IFDEF ),
PSAT("IFDEF" , CPP_PP_IFDEF ),
PSAT("using" , CPP_PP_USING ),
PSAT("USING" , CPP_PP_USING ),
PSAT("else" , CPP_PP_ELSE ),
PSAT("ELSE" , CPP_PP_ELSE ),
PSAT("elif" , CPP_PP_ELIF ),
PSAT("ELIF" , CPP_PP_ELIF ),
PSAT("line" , CPP_PP_LINE ),
PSAT("LINE" , CPP_PP_LINE ),
PSAT("if" , CPP_PP_IF ),
PSAT("IF" , CPP_PP_IF ),
#if defined(EXTRA_PREPROPS)
#include EXTRA_PREPROPS
#undef EXTRA_PREPROPS
#endif
};
parse_context_language_cpp = create_parse_context(app, kw, ArrayCount(kw), pp, ArrayCount(pp));
}
#undef PSAT
#endif
// BOTTOM

View File

@ -202,6 +202,8 @@ typedef struct Win32_Vars{
b32 first;
i32 running_cli;
u32 log_position;
} Win32_Vars;
global Win32_Vars win32vars;
@ -1089,6 +1091,28 @@ Sys_Get_4ed_Path_Sig(system_get_4ed_path){
return(size);
}
internal
Sys_Log_Sig(system_log){
if (win32vars.settings.use_log){
u8 space[4096];
String str = make_fixed_width_string(space);
system_get_binary_path(&str);
append_sc(&str, "4coder_log.txt");
terminate_with_null(&str);
HANDLE file = CreateFile_utf8(space, GENERIC_WRITE, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if (file != INVALID_HANDLE_VALUE){
SetFilePointer(file, win32vars.log_position, 0, FILE_BEGIN);
win32vars.log_position += length;
DWORD written = 0;
DWORD total_written = 0;
do{
WriteFile(file, message + total_written, length - total_written, &written, 0);
total_written += written;
}while(total_written < length);
CloseHandle(file);
}
}
}
/*
NOTE(casey): This follows Raymond Chen's prescription
@ -1452,6 +1476,7 @@ Win32LoadSystemCode(){
win32vars.system.is_fullscreen = system_is_fullscreen;win32vars.system.show_mouse_cursor = system_show_mouse_cursor;
win32vars.system.send_exit_signal = system_send_exit_signal;
win32vars.system.log = system_log;
#if FRED_INTERNAL
win32vars.system.internal_get_thread_states = INTERNAL_get_thread_states;
#endif
@ -2236,6 +2261,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
// NOTE(allen): Just guess.
win32vars.count_per_usecond = 1;
}
Assert(win32vars.count_per_usecond != 0);
//
// Main Loop