clparams almost done

This commit is contained in:
Allen Webster 2016-02-04 12:00:58 -05:00
parent 8195020bfd
commit 164a18c4a9
7 changed files with 5301 additions and 5205 deletions

148
4ed.cpp
View File

@ -770,32 +770,28 @@ app_push_file_binding(App_Vars *vars, int sys_id, int app_id){
vars->sys_app_bindings[vars->sys_app_count++] = binding;
}
internal File_View*
app_open_file(System_Functions *system, App_Vars *vars, Exchange *exchange,
Live_Views *live_set, Working_Set *working_set, Panel *panel,
Command_Data *command_data, char *filename, int len){
String filename_str;
struct App_Open_File_Result{
Editing_File *file;
b32 is_new;
};
internal App_Open_File_Result
app_open_file_background(App_Vars *vars, Exchange *exchange, Working_Set *working_set, String filename){
Get_File_Result file;
i32 file_id;
File_View *result;
Mem_Options *mem;
Editing_File *target_file = 0;
b32 created_file = 0;
App_Open_File_Result result = {};
filename_str = make_string(filename, len);
mem = &vars->mem;
result = 0;
target_file = working_set_contains(working_set, filename_str);
if (!target_file){
Get_File_Result file = working_set_get_available_file(working_set);
result.file = working_set_contains(working_set, filename);
if (result.file == 0){
file = working_set_get_available_file(working_set);
if (file.file){
file_id = exchange_request_file(exchange, filename, len);
file_id = exchange_request_file(exchange, filename.str, filename.size);
if (file_id){
created_file = 1;
target_file = file.file;
file_set_name(target_file, filename);
file_set_to_loading(target_file);
table_add(&working_set->table, target_file->name.source_path, file.index);
result.is_new = 1;
result.file = file.file;
file_set_name(result.file, filename.str);
file_set_to_loading(result.file);
table_add(&working_set->table, result.file->name.source_path, file.index);
app_push_file_binding(vars, file_id, file.index);
}
@ -805,7 +801,20 @@ app_open_file(System_Functions *system, App_Vars *vars, Exchange *exchange,
}
}
if (target_file){
return(result);
}
internal File_View*
app_open_file(System_Functions *system, App_Vars *vars, Exchange *exchange,
Live_Views *live_set, Working_Set *working_set, Panel *panel,
Command_Data *command_data, String filename){
App_Open_File_Result file;
Mem_Options *mem = &vars->mem;
File_View *result = 0;
file = app_open_file_background(vars, exchange, working_set, filename);
if (file.file){
Style *style = command_data->style;
View *new_view = live_set_alloc_view(live_set, mem);
@ -821,7 +830,7 @@ app_open_file(System_Functions *system, App_Vars *vars, Exchange *exchange,
Temp_Memory temp = begin_temp_memory(&mem->part);
command_data->part = partition_sub_part(&mem->part, Kbytes(16));
view_set_file(system, file_view, target_file, vars->font_set,
view_set_file(system, file_view, file.file, vars->font_set,
style, vars->hooks[hook_open_file], command_data,
&app_links);
@ -829,7 +838,7 @@ app_open_file(System_Functions *system, App_Vars *vars, Exchange *exchange,
end_temp_memory(temp);
command_data->view = old_view;
new_view->map = app_get_map(vars, target_file->settings.base_map_id);
new_view->map = app_get_map(vars, file.file->settings.base_map_id);
}
return(result);
@ -867,7 +876,7 @@ COMMAND_DECL(interactive_open){
String string = make_string(filename, filename_len);
app_open_file(system, vars, exchange,
live_set, working_set, panel,
command, string.str, string.size);
command, string);
}
else{
View *new_view = live_set_alloc_view(live_set, mem);
@ -909,49 +918,6 @@ COMMAND_DECL(reopen){
else{
// TODO(allen): feedback message
}
#if 0
ProfileMomentFunction();
REQ_FILE_VIEW(view);
REQ_FILE(file, view);
USE_STYLE(style);
USE_LAYOUT(layout);
USE_MEM(mem);
USE_VARS(vars);
Editing_File temp_file;
if (file_create(system, mem, &temp_file, make_c_str(file->source_path), style->font)){
file_close(system, &mem->general, file);
*file = temp_file;
file->source_path.str = file->source_path_;
file->live_name.str = file->live_name_;
#if BUFFER_EXPERIMENT_SCALPEL <= 0
if (file->tokens_exist)
file_first_lex_parallel(system, &mem->general, file);
#endif
Partition old_part = command->part;
Temp_Memory temp = begin_temp_memory(&vars->mem.part);
command->part = partition_sub_part(&vars->mem.part, 16 << 10);
view_set_file(system, view, file, style,
vars->hooks[hook_open_file], command, app_links);
command->part = old_part;
end_temp_memory(temp);
i32 panel_count = layout->panel_count;
Panel *panels = layout->panels;
for (i32 i = 0; i < panel_count; ++i){
Panel *current_panel = panels + i;
View *current_view_ = current_panel->view;
File_View *current_view = view_to_file_view(current_view_);
if (current_view && current_view != view && current_view->file == file){
view_set_file(system, current_view, current_view->file, style, 0, command, app_links);
}
}
}
#endif
}
COMMAND_DECL(save){
@ -2540,7 +2506,7 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings,
case 'd': action = CLAct_CustomDLL; strict = 0; break;
case 'D': action = CLAct_CustomDLL; strict = 1; break;
case 'l': action = CLAct_InitialFilePosition; break;
case 'i': action = CLAct_InitialFilePosition; break;
case 'w': action = CLAct_WindowSize; break;
case 'W': action = CLAct_WindowMaximize; break;
@ -2634,6 +2600,9 @@ App_Read_Command_Line_Sig(app_read_command_line){
App_Vars *vars = app_setup_memory(memory);
init_command_line_settings(&vars->settings, plat_settings, clparams);
*files = vars->settings.init_files;
*file_count = &vars->settings.init_files_count;
return(output_size);
}
@ -3318,12 +3287,23 @@ App_Step_Sig(app_step){
command_data.part.pos = 0;
}
char *file_name;
i32 i;
for (i = 0; i < vars->settings.init_file_count; ++i){
file_name = vars->settings.init_files[i];
// TODO(allen): open files, do not attach to view
//app_open_file(system, vars, exchange,live_set, working_set, panel,command, string.str, string.size);
String file_name;
Panel *panel = vars->layout.panels;
for (i = 0; i < vars->settings.init_files_count; ++i, ++panel){
file_name = make_string_slowly(vars->settings.init_files[i]);
if (i < vars->layout.panel_count){
app_open_file(system, vars, exchange, &vars->live_set, &vars->working_set, panel,
&command_data, file_name);
if (i == 0){
}
}
else{
app_open_file_background(vars, exchange, &vars->working_set, file_name);
}
}
}
@ -3445,7 +3425,7 @@ App_Step_Sig(app_step){
command_data.view = (View*)
app_open_file(system, vars, exchange,
live_set, working_set, panel,
&command_data, string->str, string->size);
&command_data, *string);
}break;
case DACT_SAVE_AS:
@ -3635,6 +3615,7 @@ App_Step_Sig(app_step){
for (i32 i = 0; i < vars->sys_app_count; ++i){
Sys_App_Binding *binding;
b32 remove = 0;
b32 failed = 0;
binding = vars->sys_app_bindings + i;
byte *data;
@ -3660,13 +3641,22 @@ App_Step_Sig(app_step){
else{
file_create_empty(system, &vars->mem, ed_file, filename,
vars->font_set, vars->style.font_id);
//
i32 panel_count = vars->layout.panel_count;
Panel *current_panel = vars->layout.panels;
for (i32 i = 0; i < panel_count; ++i, ++current_panel){
File_View *current_view = view_to_file_view(current_panel->view);
if (current_view && current_view->file == ed_file){
view_measure_wraps(system, &vars->mem.general, current_view);
}
}
}
exchange_free_file(exchange, binding->sys_id);
remove = 1;
}
if (exchange_file_save_complete(exchange, binding->sys_id, &data, &size, &max)){
if (exchange_file_save_complete(exchange, binding->sys_id, &data, &size, &max, &failed)){
Assert(remove == 0);
if (data){
@ -3681,6 +3671,8 @@ App_Step_Sig(app_step){
exchange_free_file(exchange, binding->sys_id);
remove = 1;
// if (failed) { TODO(allen): saving error, now what? }
}
if (remove){

4
4ed.h
View File

@ -106,7 +106,8 @@ enum File_Exchange_Flag{
FEx_Ready = 0x2,
FEx_Not_Exist = 0x4,
FEx_Save = 0x8,
FEx_Save_Complete = 0x10
FEx_Save_Complete = 0x10,
FEx_Save_Failed = 0x20
};
struct File_Exchange{
@ -140,6 +141,7 @@ struct Plat_Settings{
Application_Memory *memory, \
String current_directory, \
Plat_Settings *plat_settings, \
char ***files, i32 **file_count, \
Command_Line_Parameters clparams \
)

View File

@ -1,217 +1,235 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 9.12.2015
*
* Exchange stuff
*
*/
// TOP
internal void
ex__file_insert(File_Slot *pos, File_Slot *file){
pos->next->prev = file;
file->next = pos->next;
pos->next = file;
file->prev = pos;
}
internal void
ex__file_remove(File_Slot *file){
file->next->prev = file->prev;
file->prev->next = file->next;
}
internal void
ex__check_file(File_Slot *pos){
File_Slot *file = pos;
Assert(pos == pos->next->prev);
for (pos = pos->next;
file != pos;
pos = pos->next){
Assert(pos == pos->next->prev);
}
}
internal void
ex__check(File_Exchange *file_exchange){
ex__check_file(&file_exchange->available);
ex__check_file(&file_exchange->active);
ex__check_file(&file_exchange->free_list);
}
internal void
ex__clear(File_Slot *file){
file->data = 0;
file->size = 0;
file->max = 0;
file->flags = 0;
}
internal File_Slot*
ex__get_file(Exchange *exchange){
File_Exchange *files = &exchange->file;
File_Slot *file;
++files->num_active;
file = files->available.next;
ex__file_remove(file);
ex__clear(file);
ex__file_insert(&files->active, file);
ex__check(files);
return file;
}
internal void
ex__set_filename(File_Slot *file, char *filename, int len){
memcpy(file->filename, filename, len);
file->filename[len] = 0;
file->filename_len = len;
}
internal i32
exchange_request_file(Exchange *exchange, char *filename, int len){
File_Exchange *files = &exchange->file;
i32 result = 0;
if (len+1 < FileNameMax){
if (files->num_active < files->max){
File_Slot *file = ex__get_file(exchange);
ex__set_filename(file, filename, len);
file->flags |= FEx_Request;
result = (int)(file - files->files) + 1;
}
}
return result;
}
internal b32
exchange_file_ready(Exchange *exchange, i32 file_id, byte **data, int *size, int *max){
File_Exchange *files = &exchange->file;
b32 result = 0;
if (file_id > 0 && file_id <= files->max){
File_Slot *file = files->files + file_id - 1;
if (file->flags & FEx_Ready){
*data = file->data;
*size = file->size;
*max = file->max;
result = 1;
}
if (file->flags & FEx_Not_Exist){
*data = 0;
*size = 0;
*max = 0;
result = 1;
}
}
return result;
}
internal i32
exchange_save_file(Exchange *exchange, char *filename, int len,
byte *data, int size, int max){
File_Exchange *files = &exchange->file;
i32 result = 0;
if (len+1 < FileNameMax){
if (files->num_active < files->max){
File_Slot *file = ex__get_file(exchange);
ex__set_filename(file, filename, len);
file->flags |= FEx_Save;
file->data = data;
file->size = size;
file->max = max;
result = (int)(file - files->files) + 1;
}
}
return result;
}
internal b32
exchange_file_save_complete(Exchange *exchange, i32 file_id, byte **data, int *size, int *max){
File_Exchange *files = &exchange->file;
b32 result = 0;
if (file_id > 0 && file_id <= files->max){
File_Slot *file = files->files + file_id - 1;
if (file->flags & FEx_Save_Complete){
*data = file->data;
*size = file->size;
*max = file->max;
result = 1;
}
}
return result;
}
internal char*
exchange_file_filename(Exchange *exchange, i32 file_id, i32 *size = 0){
File_Exchange *files = &exchange->file;
char *result = 0;
if (file_id > 0 && file_id <= files->max){
File_Slot *file = files->files + file_id - 1;
result = file->filename;
if (size) *size = file->filename_len;
}
return result;
}
internal void
exchange_free_file(Exchange *exchange, i32 file_id){
File_Exchange *files = &exchange->file;
if (file_id > 0 && file_id <= files->max){
File_Slot *file = files->files + file_id - 1;
ex__file_remove(file);
ex__file_insert(&files->free_list, file);
ex__check(files);
--files->num_active;
}
}
internal void
exchange_clear_file(Exchange *exchange, i32 file_id){
File_Exchange *files = &exchange->file;
if (file_id > 0 && file_id <= files->max){
File_Slot *file = files->files + file_id - 1;
ex__clear(file);
}
}
internal b32
queue_job_is_pending(Work_Queue *queue, u32 job_id){
b32 result;
u32 job_index;
Full_Job_Data *full_job;
job_index = job_id % QUEUE_WRAP;
full_job = queue->jobs + job_index;
Assert(full_job->id == job_id);
result = 0;
if (full_job->running_thread != 0){
result = 1;
}
return(result);
}
// BOTTOM
/*
* Mr. 4th Dimention - Allen Webster
*
* 9.12.2015
*
* Exchange stuff
*
*/
// TOP
internal void
ex__file_insert(File_Slot *pos, File_Slot *file){
pos->next->prev = file;
file->next = pos->next;
pos->next = file;
file->prev = pos;
}
internal void
ex__file_remove(File_Slot *file){
file->next->prev = file->prev;
file->prev->next = file->next;
}
internal void
ex__check_file(File_Slot *pos){
File_Slot *file = pos;
Assert(pos == pos->next->prev);
for (pos = pos->next;
file != pos;
pos = pos->next){
Assert(pos == pos->next->prev);
}
}
internal void
ex__check(File_Exchange *file_exchange){
ex__check_file(&file_exchange->available);
ex__check_file(&file_exchange->active);
ex__check_file(&file_exchange->free_list);
}
internal void
ex__clear(File_Slot *file){
file->data = 0;
file->size = 0;
file->max = 0;
file->flags = 0;
}
internal File_Slot*
ex__get_file(Exchange *exchange){
File_Exchange *files = &exchange->file;
File_Slot *file;
++files->num_active;
file = files->available.next;
ex__file_remove(file);
ex__clear(file);
ex__file_insert(&files->active, file);
ex__check(files);
return file;
}
internal void
ex__set_filename(File_Slot *file, char *filename, int len){
memcpy(file->filename, filename, len);
file->filename[len] = 0;
file->filename_len = len;
}
internal i32
exchange_request_file(Exchange *exchange, char *filename, int len){
File_Exchange *files = &exchange->file;
i32 result = 0;
if (len+1 < FileNameMax){
if (files->num_active < files->max){
File_Slot *file = ex__get_file(exchange);
ex__set_filename(file, filename, len);
file->flags |= FEx_Request;
result = (int)(file - files->files) + 1;
}
}
return result;
}
internal b32
exchange_file_ready(Exchange *exchange, i32 file_id, byte **data, int *size, int *max){
File_Exchange *files = &exchange->file;
b32 result = 0;
if (file_id > 0 && file_id <= files->max){
File_Slot *file = files->files + file_id - 1;
if (file->flags & FEx_Ready){
*data = file->data;
*size = file->size;
*max = file->max;
result = 1;
}
if (file->flags & FEx_Not_Exist){
*data = 0;
*size = 0;
*max = 0;
result = 1;
}
}
return result;
}
internal b32
exchange_file_does_not_exist(Exchange *exchange, i32 file_id){
File_Exchange *files = &exchange->file;
b32 result = 1;
File_Slot *slot;
if (file_id > 0 && file_id <= files->max){
slot = files->files + file_id - 1;
if (!(slot->flags & FEx_Not_Exist)){
result = 0;
}
}
return result;
}
internal i32
exchange_save_file(Exchange *exchange, char *filename, int len,
byte *data, int size, int max){
File_Exchange *files = &exchange->file;
i32 result = 0;
if (len+1 < FileNameMax){
if (files->num_active < files->max){
File_Slot *file = ex__get_file(exchange);
ex__set_filename(file, filename, len);
file->flags |= FEx_Save;
file->data = data;
file->size = size;
file->max = max;
result = (int)(file - files->files) + 1;
}
}
return result;
}
internal b32
exchange_file_save_complete(Exchange *exchange, i32 file_id, byte **data, int *size, int *max, int *failed){
File_Exchange *files = &exchange->file;
b32 result = 0;
if (file_id > 0 && file_id <= files->max){
File_Slot *file = files->files + file_id - 1;
if (file->flags & FEx_Save_Complete || file->flags & FEx_Save_Failed){
*data = file->data;
*size = file->size;
*max = file->max;
result = 1;
*failed = (file->flags & FEx_Save_Complete)?(1):(0);
}
}
return result;
}
internal char*
exchange_file_filename(Exchange *exchange, i32 file_id, i32 *size = 0){
File_Exchange *files = &exchange->file;
char *result = 0;
if (file_id > 0 && file_id <= files->max){
File_Slot *file = files->files + file_id - 1;
result = file->filename;
if (size) *size = file->filename_len;
}
return result;
}
internal void
exchange_free_file(Exchange *exchange, i32 file_id){
File_Exchange *files = &exchange->file;
if (file_id > 0 && file_id <= files->max){
File_Slot *file = files->files + file_id - 1;
ex__file_remove(file);
ex__file_insert(&files->free_list, file);
ex__check(files);
--files->num_active;
}
}
internal void
exchange_clear_file(Exchange *exchange, i32 file_id){
File_Exchange *files = &exchange->file;
if (file_id > 0 && file_id <= files->max){
File_Slot *file = files->files + file_id - 1;
ex__clear(file);
}
}
internal b32
queue_job_is_pending(Work_Queue *queue, u32 job_id){
b32 result;
u32 job_index;
Full_Job_Data *full_job;
job_index = job_id % QUEUE_WRAP;
full_job = queue->jobs + job_index;
Assert(full_job->id == job_id);
result = 0;
if (full_job->running_thread != 0){
result = 1;
}
return(result);
}
// BOTTOM

File diff suppressed because it is too large Load Diff

View File

@ -1,200 +1,205 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 12.12.2014
*
* Meta setup for project codename "4ed"
*
*/
#ifndef FRED_META_H
#define FRED_META_H
#include <string.h>
#include <stdint.h>
typedef uint8_t u8;
typedef uint64_t u64;
typedef uint32_t u32;
typedef uint16_t u16;
typedef int8_t i8;
typedef int64_t i64;
typedef int32_t i32;
typedef int16_t i16;
typedef i32 bool32;
typedef i8 bool8;
typedef i32 b32;
typedef i8 b8;
typedef uint8_t byte;
typedef float real32;
typedef double real64;
typedef float f32;
typedef double f64;
struct Data{
byte *data;
i32 size;
};
#define external extern "C"
#define internal static
#define globalvar static
#define persist static
#define globalconst static const
inline i32
raw_ptr_dif(void *a, void *b) { return (i32)((u8*)a - (u8*)b); }
#define COMP_ID_(a,b,c,d) (d << 24) | (c << 16) | (b << 8) | a
#define COMPOSE_ID(a,b,c,d) (COMP_ID_((a),(b),(c),(d)))
#define S(X) #X
#define S_(X) S(X)
#define S__LINE__ S_(__LINE__)
#if FRED_PRINT_DEBUG == 1
internal void
_OutDbgStr(u8*);
# include <stdio.h>
# if FRED_PRINT_DEBUG_FILE_LINE
# define FredDbg(con, size, ...) {_OutDbgStr((u8*)("FILE:"__FILE__"LINE:"S__LINE__"\n")); char msg[size]; sprintf(msg, __VA_ARGS__); _OutDbgStr((u8*)msg);}
# else
# define FredDbg(con, size, ...) {char msg[size]; sprintf(msg, __VA_ARGS__); _OutDbgStr((u8*)msg);}
# endif
#elif FRED_PRINT_DEBUG == 2
# include <stdio.h>
# if FRED_PRINT_DEBUG_FILE_LINE
# define FredDbg(con, size, ...) {fprintf((con)->log, ("FILE:"__FILE__"LINE:"S__LINE__"\n")); fprintf(__VA_ARGS__);}
# else
# define FredDbg(con, size, ...) {fprintf((con)->log, __VA_ARGS__);}
# endif
#else
# define FredDbg(con, size, ...)
#endif
#if FRED_INTERNAL && FRED_FULL_ERRORS
# include <stdio.h>
# define FatalErrorFormat(alt, size, ...) {char msg[size]; sprintf(msg, __VA_ARGS__); FatalError(msg);}
#else
# define FatalErrorFormat(alt, size, ...) {FatalError(alt);}
#endif
#if FRED_SLOW
# define Assert(c) assert(c)
#else
# define Assert(c)
#endif
#define TentativeAssert(c) Assert(c)
#define FatalError(message) system_fatal_error((u8*)message)
#define AllowLocal(name) (void)name
#define ArrayCount(array) (sizeof(array)/sizeof(array[0]))
#define OffsetOfStruct(S,c) ((i64)(& ((S*)0)->c ))
#define OffsetOfPtr(s,c) ((i64)((char*)(&(s)->c) - (char*)(s)))
#define Swap(a,b) {auto t = a; a = b; b = t;}
#ifndef literal
#define literal(s) s, (sizeof(s)-1)
#endif
#define Min(a,b) (((a)<(b))?(a):(b))
#define Max(a,b) (((a)>(b))?(a):(b))
#define TMax(t,v) globalconst t max_##t = v
TMax(u8, 255);
TMax(u16, 65535);
TMax(u32, 4294967295);
TMax(u64, 18446744073709551615U);
TMax(i8, 127);
TMax(i16, 32767);
TMax(i32, 2147483647);
TMax(i64, 9223372036854775807);
#undef TMax
#define TMin(t) globalconst t min_##t = 0
TMin(u8);
TMin(u16);
TMin(u32);
TMin(u64);
#undef TMin
#define TMin(t,v) globalconst t min_##t = ((t)v)
TMin(i8, -0xF0);
TMin(i16, -0xF000);
TMin(i32, -0xF00000);
TMin(i64, -0xF0000000LL);
#undef TMin
internal i32
LargeRoundUp(i32 x, i32 granularity){
i32 original_x = x;
x /= granularity;
x *= granularity;
if (x < original_x){
x += granularity;
}
return x;
}
#define Bit_0 (1 << 0)
#define Bit_1 (1 << 1)
#define Bit_2 (1 << 2)
#define Bit_3 (1 << 3)
#define Bit_4 (1 << 4)
#define Bit_5 (1 << 5)
#define Bit_6 (1 << 6)
#define Bit_7 (1 << 7)
#define Bit_8 (1 << 8)
#define Bit_9 (1 << 9)
#define Bit_10 (1 << 10)
#define Bit_11 (1 << 11)
#define Bit_12 (1 << 12)
#define Bit_13 (1 << 13)
#define Bit_14 (1 << 14)
#define Bit_15 (1 << 15)
#define Bit_16 (1 << 16)
#define Bit_17 (1 << 17)
#define Bit_18 (1 << 18)
#define Bit_19 (1 << 19)
#define Bit_20 (1 << 20)
#define Bit_21 (1 << 21)
#define Bit_22 (1 << 22)
#define Bit_23 (1 << 23)
#define Bit_24 (1 << 24)
#define Bit_25 (1 << 25)
#define Bit_26 (1 << 26)
#define Bit_27 (1 << 27)
#define Bit_28 (1 << 28)
#define Bit_29 (1 << 29)
#define Bit_30 (1 << 30)
#define Bit_31 (1 << 31)
#define Byte_0 (0xFFU)
#define Byte_1 (0xFFU << 8)
#define Byte_2 (0xFFU << 16)
#define Byte_3 (0xFFU << 24)
#define Byte_4 (0xFFU << 32)
#define Byte_5 (0xFFU << 40)
#define Byte_6 (0xFFU << 48)
#define Byte_7 (0xFFU << 56)
#define bytes(n) (n)
#define Kbytes(n) ((n) << 10)
#define Mbytes(n) ((n) << 20)
#define Gbytes(n) (((u64)n) << 30)
#define Tbytes(n) (((u64)n) << 40)
#endif
/*
* Mr. 4th Dimention - Allen Webster
*
* 12.12.2014
*
* Meta setup for project codename "4ed"
*
*/
#ifndef FRED_META_H
#define FRED_META_H
#include <string.h>
#include <stdint.h>
typedef uint8_t u8;
typedef uint64_t u64;
typedef uint32_t u32;
typedef uint16_t u16;
typedef int8_t i8;
typedef int64_t i64;
typedef int32_t i32;
typedef int16_t i16;
typedef i32 bool32;
typedef i8 bool8;
typedef i32 b32;
typedef i8 b8;
typedef uint8_t byte;
typedef float real32;
typedef double real64;
typedef float f32;
typedef double f64;
struct Data{
byte *data;
i32 size;
};
#define external extern "C"
#define internal static
#define globalvar static
#define persist static
#define globalconst static const
#define DrBegin() switch (s.__pc__){ case 0:;
#define DrEnd() default: Assert(!"Invalid __pc__"); }
#define DrYield(pc, n) { s.__pc__ = pc; *state = s; return(n); case pc:; }
#define DrReturn(n) { s.__pc__ = -1; return(n); }
inline i32
raw_ptr_dif(void *a, void *b) { return (i32)((u8*)a - (u8*)b); }
#define COMP_ID_(a,b,c,d) (d << 24) | (c << 16) | (b << 8) | a
#define COMPOSE_ID(a,b,c,d) (COMP_ID_((a),(b),(c),(d)))
#define S(X) #X
#define S_(X) S(X)
#define S__LINE__ S_(__LINE__)
#if FRED_PRINT_DEBUG == 1
internal void
_OutDbgStr(u8*);
# include <stdio.h>
# if FRED_PRINT_DEBUG_FILE_LINE
# define FredDbg(con, size, ...) {_OutDbgStr((u8*)("FILE:"__FILE__"LINE:"S__LINE__"\n")); char msg[size]; sprintf(msg, __VA_ARGS__); _OutDbgStr((u8*)msg);}
# else
# define FredDbg(con, size, ...) {char msg[size]; sprintf(msg, __VA_ARGS__); _OutDbgStr((u8*)msg);}
# endif
#elif FRED_PRINT_DEBUG == 2
# include <stdio.h>
# if FRED_PRINT_DEBUG_FILE_LINE
# define FredDbg(con, size, ...) {fprintf((con)->log, ("FILE:"__FILE__"LINE:"S__LINE__"\n")); fprintf(__VA_ARGS__);}
# else
# define FredDbg(con, size, ...) {fprintf((con)->log, __VA_ARGS__);}
# endif
#else
# define FredDbg(con, size, ...)
#endif
#if FRED_INTERNAL && FRED_FULL_ERRORS
# include <stdio.h>
# define FatalErrorFormat(alt, size, ...) {char msg[size]; sprintf(msg, __VA_ARGS__); FatalError(msg);}
#else
# define FatalErrorFormat(alt, size, ...) {FatalError(alt);}
#endif
#if FRED_SLOW
# define Assert(c) assert(c)
#else
# define Assert(c)
#endif
#define TentativeAssert(c) Assert(c)
#define FatalError(message) system_fatal_error((u8*)message)
#define AllowLocal(name) (void)name
#define ArrayCount(array) (sizeof(array)/sizeof(array[0]))
#define OffsetOfStruct(S,c) ((i64)(& ((S*)0)->c ))
#define OffsetOfPtr(s,c) ((i64)((char*)(&(s)->c) - (char*)(s)))
#define Swap(a,b) {auto t = a; a = b; b = t;}
#ifndef literal
#define literal(s) s, (sizeof(s)-1)
#endif
#define Min(a,b) (((a)<(b))?(a):(b))
#define Max(a,b) (((a)>(b))?(a):(b))
#define TMax(t,v) globalconst t max_##t = v
TMax(u8, 255);
TMax(u16, 65535);
TMax(u32, 4294967295);
TMax(u64, 18446744073709551615U);
TMax(i8, 127);
TMax(i16, 32767);
TMax(i32, 2147483647);
TMax(i64, 9223372036854775807);
#undef TMax
#define TMin(t) globalconst t min_##t = 0
TMin(u8);
TMin(u16);
TMin(u32);
TMin(u64);
#undef TMin
#define TMin(t,v) globalconst t min_##t = ((t)v)
TMin(i8, -0xF0);
TMin(i16, -0xF000);
TMin(i32, -0xF00000);
TMin(i64, -0xF0000000LL);
#undef TMin
internal i32
LargeRoundUp(i32 x, i32 granularity){
i32 original_x = x;
x /= granularity;
x *= granularity;
if (x < original_x){
x += granularity;
}
return x;
}
#define Bit_0 (1 << 0)
#define Bit_1 (1 << 1)
#define Bit_2 (1 << 2)
#define Bit_3 (1 << 3)
#define Bit_4 (1 << 4)
#define Bit_5 (1 << 5)
#define Bit_6 (1 << 6)
#define Bit_7 (1 << 7)
#define Bit_8 (1 << 8)
#define Bit_9 (1 << 9)
#define Bit_10 (1 << 10)
#define Bit_11 (1 << 11)
#define Bit_12 (1 << 12)
#define Bit_13 (1 << 13)
#define Bit_14 (1 << 14)
#define Bit_15 (1 << 15)
#define Bit_16 (1 << 16)
#define Bit_17 (1 << 17)
#define Bit_18 (1 << 18)
#define Bit_19 (1 << 19)
#define Bit_20 (1 << 20)
#define Bit_21 (1 << 21)
#define Bit_22 (1 << 22)
#define Bit_23 (1 << 23)
#define Bit_24 (1 << 24)
#define Bit_25 (1 << 25)
#define Bit_26 (1 << 26)
#define Bit_27 (1 << 27)
#define Bit_28 (1 << 28)
#define Bit_29 (1 << 29)
#define Bit_30 (1 << 30)
#define Bit_31 (1 << 31)
#define Byte_0 (0xFFU)
#define Byte_1 (0xFFU << 8)
#define Byte_2 (0xFFU << 16)
#define Byte_3 (0xFFU << 24)
#define Byte_4 (0xFFU << 32)
#define Byte_5 (0xFFU << 40)
#define Byte_6 (0xFFU << 48)
#define Byte_7 (0xFFU << 56)
#define bytes(n) (n)
#define Kbytes(n) ((n) << 10)
#define Mbytes(n) ((n) << 20)
#define Gbytes(n) (((u64)n) << 30)
#define Tbytes(n) (((u64)n) << 40)
#endif

BIN
vc120.pdb

Binary file not shown.

View File

@ -314,6 +314,21 @@ system_save_file(char *filename, void *data, i32 size){
return 1;
}
internal b32
system_file_can_be_made(char *filename){
HANDLE file;
file = CreateFile((char*)filename, GENERIC_WRITE, 0, 0,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if (!file || file == INVALID_HANDLE_VALUE){
return 0;
}
CloseHandle(file);
return 1;
}
internal
Sys_File_Time_Stamp_Sig(system_file_time_stamp){
u64 result;
@ -1423,8 +1438,12 @@ UpdateLoop(LPVOID param){
if (file->flags & FEx_Save){
Assert((file->flags & FEx_Request) == 0);
file->flags &= (~FEx_Save);
system_save_file(file->filename, file->data, file->size);
file->flags |= FEx_Save_Complete;
if (system_save_file(file->filename, file->data, file->size)){
file->flags |= FEx_Save_Complete;
}
else{
file->flags |= FEx_Save_Failed;
}
}
if (file->flags & FEx_Request){
@ -1543,12 +1562,16 @@ WinMain(HINSTANCE hInstance,
Command_Line_Parameters clparams;
clparams.argv = __argv;
clparams.argc = __argc;
char **files;
i32 *file_count;
i32 output_size =
win32vars.app.read_command_line(system,
&memory_vars,
current_directory,
&win32vars.settings,
&files, &file_count,
clparams);
//
@ -1556,6 +1579,18 @@ WinMain(HINSTANCE hInstance,
// TODO
}
if (output_size != 0) return 0;
{
i32 i, j;
i32 end = *file_count;
for (i = 0, j = 0; i < end; ++i){
if (system_file_can_be_made(files[i])){
files[j] = files[i];
++j;
}
}
*file_count = j;
}
LARGE_INTEGER lpf;
QueryPerformanceFrequency(&lpf);