fully removed out context

master
Allen Webster 2017-07-10 13:42:09 -04:00
parent b3c40ba79b
commit e5abd6a135
6 changed files with 100 additions and 43 deletions

View File

@ -60,6 +60,9 @@ internal void fm_copy_file(char *file, char *newname);
internal void fm_copy_all(char *source, char *tag, char *folder);
internal void fm_copy_folder(char *src_dir, char *dst_dir, char *src_folder);
// File Reading and Writing
internal void fm_write_file(char *file_name, char *data, u32 size);
// Zip
internal void fm_zip(char *parent, char *folder, char *dest);
@ -219,6 +222,10 @@ fm_align(){
fm_arena_pos = (fm_arena_pos+7)&(~7);
}
//
// Windows implementation
//
#if defined(IS_WINDOWS)
typedef uint32_t DWORD;
@ -239,6 +246,28 @@ typedef union _LARGE_INTEGER {
} u;
LONGLONG QuadPart;
} LARGE_INTEGER, *PLARGE_INTEGER;
typedef void* HANDLE;
typedef void* PVOID;
typedef void* LPVOID;
typedef void* LPCVOID;
typedef DWORD* LPDWORD;
#if defined(_WIN64)
typedef unsigned __int64 ULONG_PTR;
#else
typedef unsigned long ULONG_PTR;
#endif
typedef struct _OVERLAPPED {
ULONG_PTR Internal;
ULONG_PTR InternalHigh;
union {
struct {
DWORD Offset;
DWORD OffsetHigh;
};
PVOID Pointer;
};
HANDLE hEvent;
} OVERLAPPED, *LPOVERLAPPED;
#define WINAPI
@ -249,8 +278,30 @@ extern "C"{
BOOL WINAPI QueryPerformanceFrequency(_Out_ LARGE_INTEGER *lpFrequency);
BOOL WINAPI CreateDirectoryA(_In_ LPCTSTR lpPathName, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes);
BOOL WINAPI CopyFileA(_In_ LPCTSTR lpExistingFileName, _In_ LPCTSTR lpNewFileName, _In_ BOOL bFailIfExists);
HANDLE WINAPI CreateFileA(_In_ LPCTSTR lpFileName, _In_ DWORD dwDesiredAccess, _In_ DWORD dwShareMode,_In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _In_ DWORD dwCreationDisposition, _In_ DWORD dwFlagsAndAttributes, _In_opt_ HANDLE hTemplateFile);
BOOL WINAPI WriteFile(_In_ HANDLE hFile, _In_ LPCVOID lpBuffer, _In_ DWORD nNumberOfBytesToWrite, _Out_opt_ LPDWORD lpNumberOfBytesWritten, _Inout_opt_ LPOVERLAPPED lpOverlapped);
BOOL WINAPI ReadFile(_In_ HANDLE hFile, _Out_ LPVOID lpBuffer, _In_ DWORD nNumberOfBytesToRead, _Out_opt_ LPDWORD lpNumberOfBytesRead, _Inout_opt_ LPOVERLAPPED lpOverlapped);
BOOL WINAPI CloseHandle(_In_ HANDLE hObject);
}
#define INVALID_HANDLE_VALUE ((HANDLE) -1)
#define GENERIC_READ 0x80000000
#define GENERIC_WRITE 0x40000000
#define GENERIC_EXECUTE 0x20000000
#define GENERIC_ALL 0x10000000
#define CREATE_NEW 1
#define CREATE_ALWAYS 2
#define OPEN_EXISTING 3
#define OPEN_ALWAYS 4
#define TRUNCATE_EXISTING 5
#define FILE_ATTRIBUTE_READONLY 0x00000001
#define FILE_ATTRIBUTE_NORMAL 0x00000080
#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
static uint64_t perf_frequency;
static void
@ -362,6 +413,23 @@ fm_copy_all(char *source, char *tag, char *folder){
}
}
internal void
fm_write_file(char *file_name, char *data, u32 size){
HANDLE file = CreateFileA(file_name, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if (file != INVALID_HANDLE_VALUE){
DWORD written = 0;
for (;written < size;){
DWORD newly_written = 0;
if (!WriteFile(file, data + written, size - written, &newly_written, 0)){
break;
}
written += newly_written;
}
Assert(written == size);
CloseHandle(file);
}
}
static void
fm_zip(char *parent, char *folder, char *dest){
char cdir[512];
@ -374,6 +442,10 @@ fm_zip(char *parent, char *folder, char *dest){
systemf("copy %s\\4ed_gobble.zip %s & del %s\\4ed_gobble.zip", cdir, dest, cdir);
}
//
// Unix implementation
//
#elif defined(IS_LINUX) || defined(IS_MAC)
#include <time.h>
@ -478,6 +550,16 @@ fm_copy_all(char *source, char *tag, char *folder){
}
}
internal void
fm_write_file(char *file_name, char *data, u32 size){
// TODO(allen): Real unix version?
FILE *file = fopen(file_name, "wb");
if (file != 0){
fwrite(data, 1, size, file);
fclose(file);
}
}
static void
fm_zip(char *parent, char *folder, char *file){
Temp_Dir temp = fm_pushdir(parent);

View File

@ -115,7 +115,8 @@ generate_keycode_enum(){
"return(result);\n"
"}\n");
end_file_out(filename_keycodes, &out);
fm_write_file(filename_keycodes, out.str, out.size);
out.size = 0;
fm_end_temp(temp);
}
@ -240,7 +241,8 @@ generate_style(){
}
append(&out, "};\n");
end_file_out(filename_4coder, &out);
fm_write_file(filename_4coder, out.str, out.size);
out.size = 0;
struct_begin(&out, "Interactive_Style");
{
@ -298,7 +300,8 @@ generate_style(){
"}\n\n");
}
end_file_out(filename_4ed, &out);
fm_write_file(filename_4ed, out.str, out.size);
out.size = 0;
fm_end_temp(temp);
}
@ -400,11 +403,11 @@ generate_custom_headers(){
String *public_name = &func_4ed_names.names[i].public_name;
*macro = str_alloc(name_string.size+4);
to_upper_ss(macro, name_string);
to_upper(macro, name_string);
append(macro, make_lit_string("_SIG"));
*public_name = str_alloc(name_string.size);
to_lower_ss(public_name, name_string);
to_lower(public_name, name_string);
fm_align();
}
@ -435,7 +438,8 @@ generate_custom_headers(){
append(&out, "_Function);\n");
}
end_file_out(OS_API_H, &out);
fm_write_file(OS_API_H, out.str, out.size);
out.size = 0;
append(&out, "struct Application_Links;\n");
@ -518,7 +522,7 @@ generate_custom_headers(){
}
append(&out, "){");
if (match_ss(ret, make_lit_string("void"))){
if (match(ret, make_lit_string("void"))){
append(&out, "(");
}
else{
@ -548,7 +552,8 @@ generate_custom_headers(){
}
append(&out, "#endif\n");
end_file_out(API_H, &out);
fm_write_file(API_H, out.str, out.size);
out.size = 0;
fm_end_temp(temp);
}

View File

@ -1,32 +0,0 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 25.02.2016
*
* File editing view for 4coder
*
*/
// TOP
#if !defined(OUT_CONTEXT_4CODER)
#define OUT_CONTEXT_4CODER
internal void
end_file_out(char *out_file, String *out_data){
FILE *file = fopen(out_file, "wb");
if (file != 0){
fwrite(out_data->str, 1, out_data->size, file);
fclose(file);
}
else{
fprintf(stdout, "Could not open output file %s\n", out_file);
}
out_data->size = 0;
}
#endif
// BOTTOM

View File

@ -98,7 +98,8 @@ do_html_output(Document_System *doc_system, char *dst_directory, Abstract_Item *
if (doc_get_link_string(doc, doc_link, sizeof(doc_link))){
generate_document_html(&out, doc_system, doc);
char *name = fm_str(dst_directory, "/", doc_link);
end_file_out(name, &out);
fm_write_file(name, out.str, out.size);
out.size = 0;
}
}

View File

@ -1,5 +1,5 @@
1
0
100
101

View File

@ -433,7 +433,8 @@ int main(){
pstr = str_start_end(pcontext.data, start, parse.code.size);
append(&out, pstr);
end_file_out(GENERATED_FILE, &out);
fm_write_file(GENERATED_FILE, out.str, out.size);
out.size = 0;
// NOTE(allen): Publish the new file. (Would like to be able to automatically test the result before publishing).
{