2017-01-23 06:19:43 +00:00
|
|
|
/*
|
2017-04-01 06:15:47 +00:00
|
|
|
4tech_file_moving.h - Code for moving files around on the file system.
|
|
|
|
By Allen Webster
|
|
|
|
21.01.2017 (dd.mm.yyyy)
|
|
|
|
*/
|
2017-01-23 06:19:43 +00:00
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
|
|
|
#if !defined(FTECH_FILE_MOVING_H)
|
|
|
|
#define FTECH_FILE_MOVING_H
|
|
|
|
|
2017-04-01 06:18:45 +00:00
|
|
|
#include "../4ed_os_comp_cracking.h"
|
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
#include <stdio.h> // include system for windows
|
|
|
|
#include <stdlib.h> // include system for linux (YAY!)
|
2017-07-07 23:54:50 +00:00
|
|
|
#include <stdarg.h>
|
2017-07-08 19:25:23 +00:00
|
|
|
#include <string.h>
|
2017-01-23 06:19:43 +00:00
|
|
|
|
2017-07-07 23:54:50 +00:00
|
|
|
//
|
|
|
|
// API
|
|
|
|
//
|
2017-04-01 06:15:47 +00:00
|
|
|
|
2017-07-07 23:54:50 +00:00
|
|
|
// System commands
|
2017-02-24 02:30:29 +00:00
|
|
|
static char SF_CMD[4096];
|
2017-01-23 06:19:43 +00:00
|
|
|
static i32 error_state = 0;
|
|
|
|
static i32 prev_error = 0;
|
|
|
|
|
2017-07-07 23:54:50 +00:00
|
|
|
#if defined(FM_PRINT_COMMANDS)
|
|
|
|
#define SYSTEMF_PRINTF(...) printf(__VA_ARGS__);
|
|
|
|
#else
|
|
|
|
#define SYSTEMF_PRINTF(...)
|
|
|
|
#endif
|
|
|
|
|
2017-02-24 02:30:29 +00:00
|
|
|
#define systemf(...) do{ \
|
|
|
|
int32_t n = snprintf(SF_CMD, sizeof(SF_CMD), __VA_ARGS__); \
|
|
|
|
AllowLocal(n); \
|
|
|
|
Assert(n < sizeof(SF_CMD)); \
|
2017-07-07 23:54:50 +00:00
|
|
|
SYSTEMF_PRINTF("%s\n", SF_CMD); \
|
2017-02-24 02:30:29 +00:00
|
|
|
prev_error = system(SF_CMD); \
|
|
|
|
if (prev_error != 0) error_state = 1; \
|
2017-01-23 06:19:43 +00:00
|
|
|
}while(0)
|
|
|
|
|
2017-07-07 23:54:50 +00:00
|
|
|
internal void fm_execute_in_dir(char *dir, char *str, char *args);
|
|
|
|
|
|
|
|
// Init
|
|
|
|
internal void fm_init_system();
|
|
|
|
|
|
|
|
// Timing
|
|
|
|
internal u64 fm_get_time();
|
|
|
|
|
|
|
|
#define LLU_CAST(n) (long long unsigned int)(n)
|
|
|
|
#define BEGIN_TIME_SECTION() uint64_t start = fm_get_time()
|
|
|
|
#define END_TIME_SECTION(n) uint64_t total = fm_get_time() - start; printf("%-20s: %.2llu.%.6llu\n", (n), LLU_CAST(total/1000000), LLU_CAST(total%1000000));
|
|
|
|
|
|
|
|
// Files and Folders Manipulation
|
2017-07-08 05:40:27 +00:00
|
|
|
internal void fm_make_folder_if_missing(char *dir);
|
2017-07-07 23:54:50 +00:00
|
|
|
internal void fm_clear_folder(char *folder);
|
|
|
|
internal void fm_delete_file(char *file);
|
2017-07-08 05:40:27 +00:00
|
|
|
internal void fm_copy_file(char *file, char *newname);
|
2017-07-07 23:54:50 +00:00
|
|
|
internal void fm_copy_all(char *source, char *tag, char *folder);
|
2017-07-08 19:25:23 +00:00
|
|
|
internal void fm_copy_folder(char *src_dir, char *dst_dir, char *src_folder);
|
2017-01-23 06:19:43 +00:00
|
|
|
|
2017-07-07 23:54:50 +00:00
|
|
|
// Zip
|
|
|
|
internal void fm_zip(char *parent, char *folder, char *dest);
|
2017-01-23 06:19:43 +00:00
|
|
|
|
2017-07-09 00:48:53 +00:00
|
|
|
// Slash Correction
|
2017-07-07 23:54:50 +00:00
|
|
|
internal void fm_slash_fix(char *path);
|
|
|
|
|
2017-07-09 00:48:53 +00:00
|
|
|
// Memory concat helpers
|
2017-07-07 23:54:50 +00:00
|
|
|
internal char *fm_prepare_string_internal(char *s1, ...);
|
2017-07-08 05:40:27 +00:00
|
|
|
#define fm_str(...) fm_prepare_string_internal(__VA_ARGS__, 0)
|
2017-07-07 23:54:50 +00:00
|
|
|
|
2017-07-09 00:48:53 +00:00
|
|
|
internal char **fm_prepare_list_internal(char **l1, ...);
|
|
|
|
#define fm_list(...) fm_prepare_list_internal(__VA_ARGS__, 0)
|
|
|
|
|
|
|
|
internal char **fm_list_one_item(char *item);
|
|
|
|
|
|
|
|
// File System Navigation
|
2017-07-09 04:28:33 +00:00
|
|
|
typedef umem String_Temp;
|
|
|
|
internal String_Temp fm_begin_temp();
|
|
|
|
internal void fm_end_temp(String_Temp temp);
|
2017-07-07 23:54:50 +00:00
|
|
|
|
|
|
|
internal i32 fm_get_current_directory(char *buffer, i32 max);
|
2017-01-23 06:19:43 +00:00
|
|
|
|
|
|
|
typedef struct Temp_Dir{
|
|
|
|
char dir[512];
|
|
|
|
} Temp_Dir;
|
|
|
|
|
2017-07-07 23:54:50 +00:00
|
|
|
internal Temp_Dir fm_pushdir(char *dir);
|
|
|
|
internal void fm_popdir(Temp_Dir temp);
|
2017-01-23 06:19:43 +00:00
|
|
|
|
2017-07-08 05:40:27 +00:00
|
|
|
// Build Line
|
|
|
|
#define BUILD_LINE_MAX 4096
|
|
|
|
typedef struct Build_Line{
|
|
|
|
char build_optionsA[BUILD_LINE_MAX];
|
|
|
|
char build_optionsB[BUILD_LINE_MAX];
|
|
|
|
char *build_options;
|
|
|
|
char *build_options_prev;
|
|
|
|
i32 build_max;
|
|
|
|
} Build_Line;
|
|
|
|
|
|
|
|
internal void fm_init_build_line(Build_Line *line);
|
|
|
|
internal void fm_finish_build_line(Build_Line *line);
|
|
|
|
|
|
|
|
internal void fm__swap_ptr(char **A, char **B);
|
|
|
|
|
|
|
|
#if defined(IS_CL)
|
|
|
|
|
|
|
|
#define fm_add_to_line(line, str, ...) do{ \
|
|
|
|
snprintf(line.build_options, \
|
|
|
|
line.build_max, "%s "str, \
|
|
|
|
line.build_options_prev, __VA_ARGS__); \
|
|
|
|
fm__swap_ptr(&line.build_options, &line.build_options_prev); \
|
|
|
|
}while(0)
|
|
|
|
|
|
|
|
#elif defined(IS_GCC)
|
|
|
|
|
|
|
|
#define fm_add_to_line(line, str, ...) do{ \
|
|
|
|
snprintf(line.build_options, line.build_max, "%s "str, \
|
|
|
|
line.build_options_prev, ##__VA_ARGS__); \
|
|
|
|
fm__swap_ptr(&line.build_options, &line.build_options_prev); \
|
|
|
|
}while(0)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-07-07 23:54:50 +00:00
|
|
|
// Slashes
|
|
|
|
#if defined(IS_WINDOWS)
|
|
|
|
#define SLASH "\\"
|
|
|
|
static char platform_correct_slash = '\\';
|
|
|
|
#elif defined(IS_LINUX) || defined(IS_MAC)
|
|
|
|
#define SLASH "/"
|
|
|
|
static char platform_correct_slash = '/';
|
|
|
|
#else
|
|
|
|
#error Slash not set for this platform.
|
2017-01-23 06:19:43 +00:00
|
|
|
#endif
|
|
|
|
|
2017-07-08 03:38:29 +00:00
|
|
|
// File Extensions
|
|
|
|
#if defined(IS_WINDOWS)
|
2017-07-08 05:40:27 +00:00
|
|
|
# define EXE ".exe"
|
2017-07-08 03:38:29 +00:00
|
|
|
#elif defined(IS_LINUX) || defined(IS_MAC)
|
2017-07-08 05:40:27 +00:00
|
|
|
# define EXE ""
|
2017-07-08 03:38:29 +00:00
|
|
|
#else
|
2017-07-08 05:40:27 +00:00
|
|
|
# error No EXE format specified for this OS
|
2017-07-08 03:38:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(IS_WINDOWS)
|
2017-07-08 05:40:27 +00:00
|
|
|
# define PDB ".pdb"
|
2017-07-08 03:38:29 +00:00
|
|
|
#elif defined(IS_LINUX) || defined(IS_MAC)
|
2017-07-08 05:40:27 +00:00
|
|
|
# define PDB ""
|
2017-07-08 03:38:29 +00:00
|
|
|
#else
|
2017-07-08 05:40:27 +00:00
|
|
|
# error No PDB format specified for this OS
|
2017-07-08 03:38:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(IS_WINDOWS)
|
2017-07-08 05:40:27 +00:00
|
|
|
# define DLL ".dll"
|
2017-07-08 03:38:29 +00:00
|
|
|
#elif defined(IS_LINUX) || defined(IS_MAC)
|
2017-07-08 05:40:27 +00:00
|
|
|
# define DLL ".so"
|
2017-07-08 03:38:29 +00:00
|
|
|
#else
|
2017-07-08 05:40:27 +00:00
|
|
|
# error No DLL format specified for this OS
|
2017-07-08 03:38:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(IS_WINDOWS)
|
2017-07-08 05:40:27 +00:00
|
|
|
# define BAT ".bat"
|
2017-07-08 03:38:29 +00:00
|
|
|
#elif defined(IS_LINUX) || defined(IS_MAC)
|
2017-07-08 05:40:27 +00:00
|
|
|
# define BAT ".sh"
|
2017-07-08 03:38:29 +00:00
|
|
|
#else
|
2017-07-08 05:40:27 +00:00
|
|
|
# error No BAT format specified for this OS
|
2017-07-08 03:38:29 +00:00
|
|
|
#endif
|
|
|
|
|
2017-07-07 23:54:50 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//
|
|
|
|
// Implementation
|
|
|
|
//
|
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
#if defined(FTECH_FILE_MOVING_IMPLEMENTATION) && !defined(FTECH_FILE_MOVING_IMPL_GUARD)
|
|
|
|
#define FTECH_FILE_MOVING_IMPL_GUARD
|
|
|
|
|
2017-07-07 23:54:50 +00:00
|
|
|
char *fm_arena_memory = 0;
|
|
|
|
umem fm_arena_pos = 0;
|
|
|
|
umem fm_arena_max = 0;
|
|
|
|
|
|
|
|
internal void
|
|
|
|
fm__init_memory(){
|
|
|
|
fm_arena_max = MB(16);
|
|
|
|
fm_arena_memory = (char*)malloc(fm_arena_max);
|
|
|
|
}
|
|
|
|
|
2017-07-09 04:28:33 +00:00
|
|
|
internal String_Temp
|
2017-07-07 23:54:50 +00:00
|
|
|
fm_begin_temp(){
|
|
|
|
return(fm_arena_pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
2017-07-09 04:28:33 +00:00
|
|
|
fm_end_temp(String_Temp temp){
|
2017-07-07 23:54:50 +00:00
|
|
|
fm_arena_pos = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void*
|
|
|
|
fm__push(umem size){
|
|
|
|
void *result = fm_arena_memory + fm_arena_pos;
|
|
|
|
if (size + fm_arena_pos > fm_arena_max){
|
|
|
|
result = 0;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
fm_arena_pos += size;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
#if defined(IS_WINDOWS)
|
|
|
|
|
|
|
|
typedef uint32_t DWORD;
|
|
|
|
typedef int32_t LONG;
|
|
|
|
typedef int64_t LONGLONG;
|
|
|
|
typedef char* LPTSTR;
|
|
|
|
typedef char* LPCTSTR;
|
|
|
|
typedef int32_t BOOL;
|
|
|
|
typedef void* LPSECURITY_ATTRIBUTES;
|
|
|
|
typedef union _LARGE_INTEGER {
|
|
|
|
struct {
|
|
|
|
DWORD LowPart;
|
|
|
|
LONG HighPart;
|
|
|
|
};
|
|
|
|
struct {
|
|
|
|
DWORD LowPart;
|
|
|
|
LONG HighPart;
|
|
|
|
} u;
|
|
|
|
LONGLONG QuadPart;
|
|
|
|
} LARGE_INTEGER, *PLARGE_INTEGER;
|
|
|
|
|
|
|
|
#define WINAPI
|
|
|
|
|
|
|
|
extern "C"{
|
|
|
|
DWORD WINAPI GetCurrentDirectoryA(_In_ DWORD nBufferLength, _Out_ LPTSTR lpBuffer);
|
|
|
|
BOOL WINAPI SetCurrentDirectoryA(_In_ LPCTSTR lpPathName);
|
|
|
|
BOOL WINAPI QueryPerformanceCounter(_Out_ LARGE_INTEGER *lpPerformanceCount);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t perf_frequency;
|
|
|
|
|
2017-07-07 23:54:50 +00:00
|
|
|
static void
|
|
|
|
fm_init_system(){
|
|
|
|
LARGE_INTEGER lint;
|
|
|
|
if (QueryPerformanceFrequency(&lint)){
|
|
|
|
perf_frequency = lint.QuadPart;
|
|
|
|
}
|
|
|
|
fm__init_memory();
|
|
|
|
}
|
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
static Temp_Dir
|
2017-07-07 23:54:50 +00:00
|
|
|
fm_pushdir(char *dir){
|
2017-01-23 06:19:43 +00:00
|
|
|
Temp_Dir temp = {0};
|
|
|
|
GetCurrentDirectoryA(sizeof(temp.dir), temp.dir);
|
|
|
|
SetCurrentDirectoryA(dir);
|
|
|
|
return(temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-07 23:54:50 +00:00
|
|
|
fm_popdir(Temp_Dir temp){
|
2017-01-23 06:19:43 +00:00
|
|
|
SetCurrentDirectoryA(temp.dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t
|
2017-07-07 23:54:50 +00:00
|
|
|
fm_get_time(){
|
2017-01-23 06:19:43 +00:00
|
|
|
uint64_t time = 0;
|
|
|
|
LARGE_INTEGER lint;
|
|
|
|
if (QueryPerformanceCounter(&lint)){
|
|
|
|
time = lint.QuadPart;
|
|
|
|
time = (time * 1000000) / perf_frequency;
|
|
|
|
}
|
|
|
|
return(time);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int32_t
|
2017-07-07 23:54:50 +00:00
|
|
|
fm_get_current_directory(char *buffer, int32_t max){
|
2017-01-23 06:19:43 +00:00
|
|
|
int32_t result = GetCurrentDirectoryA(max, buffer);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-07 23:54:50 +00:00
|
|
|
fm_execute_in_dir(char *dir, char *str, char *args){
|
2017-01-23 06:19:43 +00:00
|
|
|
if (dir){
|
2017-07-07 23:54:50 +00:00
|
|
|
Temp_Dir temp = fm_pushdir(dir);
|
2017-01-23 06:19:43 +00:00
|
|
|
if (args){
|
|
|
|
systemf("call \"%s\" %s", str, args);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
systemf("call \"%s\"", str);
|
|
|
|
}
|
2017-07-07 23:54:50 +00:00
|
|
|
fm_popdir(temp);
|
2017-01-23 06:19:43 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
if (args){
|
|
|
|
systemf("call \"%s\" %s", str, args);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
systemf("call \"%s\"", str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-07 23:54:50 +00:00
|
|
|
fm_slash_fix(char *path){
|
2017-07-08 19:25:23 +00:00
|
|
|
if (path != 0){
|
2017-01-23 06:19:43 +00:00
|
|
|
for (int32_t i = 0; path[i]; ++i){
|
|
|
|
if (path[i] == '/') path[i] = '\\';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-08 05:40:27 +00:00
|
|
|
fm_make_folder_if_missing(char *dir){
|
2017-07-08 19:25:23 +00:00
|
|
|
char *path = fm_str(dir);
|
|
|
|
char *p = path;
|
2017-01-23 06:19:43 +00:00
|
|
|
for (; *p; ++p){
|
|
|
|
if (*p == '\\'){
|
|
|
|
*p = 0;
|
2017-07-08 19:25:23 +00:00
|
|
|
CreateDirectoryA(path, 0);
|
2017-01-23 06:19:43 +00:00
|
|
|
*p = '\\';
|
|
|
|
}
|
|
|
|
}
|
2017-07-08 19:25:23 +00:00
|
|
|
CreateDirectoryA(path, 0);
|
2017-01-23 06:19:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-07 23:54:50 +00:00
|
|
|
fm_clear_folder(char *folder){
|
2017-06-27 02:47:00 +00:00
|
|
|
systemf("del /S /Q /F %s\\* & rmdir /S /Q %s & mkdir %s", folder, folder, folder);
|
2017-01-23 06:19:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-07 23:54:50 +00:00
|
|
|
fm_delete_file(char *file){
|
2017-01-23 06:19:43 +00:00
|
|
|
systemf("del %s", file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-08 05:40:27 +00:00
|
|
|
fm_copy_file(char *file, char *newname){
|
|
|
|
CopyFileA(file, newname, 0);
|
2017-01-23 06:19:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-07 23:54:50 +00:00
|
|
|
fm_copy_all(char *source, char *tag, char *folder){
|
2017-01-23 06:19:43 +00:00
|
|
|
if (source){
|
|
|
|
systemf("copy %s\\%s %s\\*", source, tag, folder);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
systemf("copy %s %s\\*", tag, folder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-07 23:54:50 +00:00
|
|
|
fm_zip(char *parent, char *folder, char *dest){
|
2017-01-23 06:19:43 +00:00
|
|
|
char cdir[512];
|
2017-07-07 23:54:50 +00:00
|
|
|
fm_get_current_directory(cdir, sizeof(cdir));
|
2017-01-23 06:19:43 +00:00
|
|
|
|
2017-07-07 23:54:50 +00:00
|
|
|
Temp_Dir temp = fm_pushdir(parent);
|
|
|
|
systemf("%s\\zip %s\\4ed_gobble.zip", cdir, cdir);
|
|
|
|
fm_popdir(temp);
|
2017-01-23 06:19:43 +00:00
|
|
|
|
2017-07-07 23:54:50 +00:00
|
|
|
systemf("copy %s\\4ed_gobble.zip %s & del %s\\4ed_gobble.zip", cdir, dest, cdir);
|
2017-01-23 06:19:43 +00:00
|
|
|
}
|
|
|
|
|
2017-06-27 02:47:00 +00:00
|
|
|
#elif defined(IS_LINUX) || defined(IS_MAC)
|
2017-01-23 06:19:43 +00:00
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
static Temp_Dir
|
2017-07-07 23:54:50 +00:00
|
|
|
fm_pushdir(char *dir){
|
2017-01-23 06:19:43 +00:00
|
|
|
Temp_Dir temp;
|
|
|
|
char *result = getcwd(temp.dir, sizeof(temp.dir));
|
|
|
|
int32_t chresult = chdir(dir);
|
|
|
|
if (result == 0 || chresult != 0){
|
|
|
|
printf("trying pushdir %s\n", dir);
|
2017-06-27 01:11:23 +00:00
|
|
|
Assert(result != 0);
|
|
|
|
Assert(chresult == 0);
|
|
|
|
}
|
|
|
|
return(temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-07 23:54:50 +00:00
|
|
|
fm_popdir(Temp_Dir temp){
|
2017-06-27 01:11:23 +00:00
|
|
|
chdir(temp.dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-08 03:38:29 +00:00
|
|
|
fm_init_system(){
|
2017-07-08 05:40:27 +00:00
|
|
|
fm__init_memory();
|
2017-06-27 01:11:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t
|
2017-07-07 23:54:50 +00:00
|
|
|
fm_get_time(){
|
2017-06-27 01:11:23 +00:00
|
|
|
struct timespec spec;
|
|
|
|
uint64_t result;
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &spec);
|
|
|
|
result = (spec.tv_sec * (uint64_t)(1000000)) + (spec.tv_nsec / (uint64_t)(1000));
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int32_t
|
2017-07-07 23:54:50 +00:00
|
|
|
fm_get_current_directory(char *buffer, int32_t max){
|
2017-06-27 01:11:23 +00:00
|
|
|
int32_t result = 0;
|
|
|
|
char *d = getcwd(buffer, max);
|
|
|
|
if (d == buffer){
|
|
|
|
result = strlen(buffer);
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-07 23:54:50 +00:00
|
|
|
fm_execute_in_dir(char *dir, char *str, char *args){
|
2017-06-27 01:11:23 +00:00
|
|
|
if (dir){
|
|
|
|
if (args){
|
2017-07-07 23:54:50 +00:00
|
|
|
Temp_Dir temp = fm_pushdir(dir);
|
2017-06-27 01:11:23 +00:00
|
|
|
systemf("%s %s", str, args);
|
2017-07-08 03:38:29 +00:00
|
|
|
fm_popdir(temp);
|
2017-06-27 01:11:23 +00:00
|
|
|
}
|
|
|
|
else{
|
2017-07-07 23:54:50 +00:00
|
|
|
Temp_Dir temp = fm_pushdir(dir);
|
2017-06-27 01:11:23 +00:00
|
|
|
systemf("%s", str);
|
2017-07-08 03:38:29 +00:00
|
|
|
fm_popdir(temp);
|
2017-06-27 01:11:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if (args){
|
|
|
|
systemf("%s %s", str, args);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
systemf("%s", str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-07 23:54:50 +00:00
|
|
|
fm_slash_fix(char *path){}
|
2017-06-27 01:11:23 +00:00
|
|
|
|
|
|
|
static void
|
2017-07-08 05:40:27 +00:00
|
|
|
fm_make_folder_if_missing(char *dir){
|
|
|
|
systemf("mkdir -p %s", dir);
|
2017-06-27 01:11:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-07 23:54:50 +00:00
|
|
|
fm_clear_folder(char *folder){
|
2017-06-27 01:11:23 +00:00
|
|
|
systemf("rm -rf %s*", folder);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-07 23:54:50 +00:00
|
|
|
fm_delete_file(char *file){
|
2017-06-27 01:11:23 +00:00
|
|
|
systemf("rm %s", file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-08 05:40:27 +00:00
|
|
|
fm_copy_file(char *file, char *newname){
|
|
|
|
systemf("cp %s %s", file, newname);
|
2017-06-27 01:11:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-07 23:54:50 +00:00
|
|
|
fm_copy_all(char *source, char *tag, char *folder){
|
2017-06-27 01:11:23 +00:00
|
|
|
if (source){
|
|
|
|
systemf("cp -f %s/%s %s", source, tag, folder);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
systemf("cp -f %s %s", tag, folder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-07 23:54:50 +00:00
|
|
|
fm_zip(char *parent, char *folder, char *file){
|
|
|
|
Temp_Dir temp = fm_pushdir(parent);
|
2017-06-27 01:11:23 +00:00
|
|
|
printf("PARENT DIR: %s\n", parent);
|
|
|
|
systemf("zip -r %s %s", file, folder);
|
2017-07-08 03:38:29 +00:00
|
|
|
fm_popdir(temp);
|
2017-06-27 01:11:23 +00:00
|
|
|
}
|
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
#else
|
|
|
|
#error This OS is not supported yet
|
|
|
|
#endif
|
|
|
|
|
2017-07-07 23:54:50 +00:00
|
|
|
internal void
|
2017-07-08 19:25:23 +00:00
|
|
|
fm_copy_folder(char *src_dir, char *dst_dir, char *src_folder){
|
|
|
|
Temp_Dir temp = fm_pushdir(src_dir);
|
2017-07-08 05:40:27 +00:00
|
|
|
fm_make_folder_if_missing(fm_str(dst_dir, "/", src_folder));
|
2017-07-08 19:25:23 +00:00
|
|
|
char *copy_name = fm_str(dst_dir, "/", src_folder);
|
|
|
|
fm_copy_all(src_folder, "*", copy_name);
|
|
|
|
fm_popdir(temp);
|
2017-07-07 23:54:50 +00:00
|
|
|
}
|
|
|
|
|
2017-07-09 00:48:53 +00:00
|
|
|
// List Helpers
|
|
|
|
internal umem
|
|
|
|
listsize(void *p, umem item_size){
|
|
|
|
u64 zero = 0;
|
|
|
|
u8 *ptr = (u8*)p;
|
|
|
|
for (;memcmp(ptr, &zero, item_size) != 0; ptr += item_size);
|
|
|
|
umem size = (ptr - (u8*)p);
|
|
|
|
return(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void*
|
|
|
|
fm__prepare(umem item_size, void *i1, va_list list){
|
|
|
|
umem size = listsize(i1, item_size);
|
|
|
|
void *result = (void*)fm__push(size);
|
|
|
|
memcpy(result, i1, size);
|
|
|
|
|
|
|
|
void *ln = va_arg(list, void*);
|
|
|
|
for (;ln != 0;){
|
|
|
|
size = listsize(ln, item_size);
|
|
|
|
void *new_str = (void*)fm__push(size);
|
|
|
|
memcpy(new_str, ln, size);
|
|
|
|
ln = va_arg(list, void*);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *terminator = (void*)fm__push(item_size);
|
|
|
|
memset(terminator, 0, item_size);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2017-07-07 23:54:50 +00:00
|
|
|
internal char*
|
|
|
|
fm_prepare_string_internal(char *s1, ...){
|
2017-07-09 00:48:53 +00:00
|
|
|
umem item_size = sizeof(*s1);
|
2017-07-07 23:54:50 +00:00
|
|
|
va_list list;
|
|
|
|
va_start(list, s1);
|
2017-07-09 00:48:53 +00:00
|
|
|
char *result = (char*)fm__prepare(item_size, s1, list);
|
2017-07-07 23:54:50 +00:00
|
|
|
va_end(list);
|
|
|
|
fm_slash_fix(result);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2017-07-09 00:48:53 +00:00
|
|
|
internal char**
|
|
|
|
fm_prepare_list_internal(char **p1, ...){
|
|
|
|
umem item_size = sizeof(*p1);
|
|
|
|
va_list list;
|
|
|
|
va_start(list, p1);
|
|
|
|
char **result = (char**)fm__prepare(item_size, p1, list);
|
|
|
|
va_end(list);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal char**
|
|
|
|
fm_list_one_item(char *item){
|
|
|
|
char **result = (char**)fm__push(sizeof(char*)*2);
|
|
|
|
result[0] = item;
|
|
|
|
result[1] = 0;
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build Line
|
2017-07-08 05:40:27 +00:00
|
|
|
internal void
|
|
|
|
fm_init_build_line(Build_Line *line){
|
|
|
|
line->build_options = line->build_optionsA;
|
|
|
|
line->build_options_prev = line->build_optionsB;
|
|
|
|
line->build_optionsA[0] = 0;
|
|
|
|
line->build_optionsB[0] = 0;
|
|
|
|
line->build_max = BUILD_LINE_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
|
|
|
fm_finish_build_line(Build_Line *line){
|
|
|
|
fm__swap_ptr(&line->build_options, &line->build_options_prev);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
|
|
|
fm__swap_ptr(char **A, char **B){
|
|
|
|
char *a = *A;
|
|
|
|
char *b = *B;
|
|
|
|
*A = b;
|
|
|
|
*B = a;
|
|
|
|
}
|
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|