setting up Mac OS build code, fixes to the string library

master
Allen Webster 2017-06-26 21:11:23 -04:00
parent 964efa909d
commit f9153fa2a5
8 changed files with 316 additions and 203 deletions

File diff suppressed because it is too large Load Diff

View File

@ -34,7 +34,9 @@
# if defined(__gnu_linux__)
# define IS_LINUX
# else
# elif defined(__APPLE__) && defined(__MACH__)
# define IS_MAC
#else
# error This compiler/platform combo is not supported yet
# endif

View File

@ -5,7 +5,7 @@ if [ -z "$BUILD_MODE" ]; then
BUILD_MODE="-DDEV_BUILD"
fi
WARNINGS="-Wno-write-strings"
WARNINGS="-Wno-write-strings -Wno-comment -Wno-logical-op-parentheses -Wno-null-dereference -Wno-switch"
FLAGS="-D_GNU_SOURCE -fPIC -fpermissive $BUILD_MODE"
g++ $WARNINGS $FLAGS meta/build.cpp -g -o ../build/build

View File

@ -28,6 +28,13 @@ static char platform_correct_slash = '\\';
#define SLASH "/"
static char platform_correct_slash = '/';
#elif defined(IS_MAC)
# define ONLY_WINDOWS(x) (void)0
# define ONLY_LINUX(x) (void)0
#define SLASH "/"
static char platform_correct_slash = '/';
#else
# define ONLY_WINDOWS(x) (void)0
# define ONLY_LINUX(x) (void)0
@ -281,8 +288,145 @@ pushdir(char *dir){
int32_t chresult = chdir(dir);
if (result == 0 || chresult != 0){
printf("trying pushdir %s\n", dir);
assert(result != 0);
assert(chresult == 0);
Assert(result != 0);
Assert(chresult == 0);
}
return(temp);
}
static void
popdir(Temp_Dir temp){
chdir(temp.dir);
}
static void
init_time_system(){
// NOTE(allen): do nothing
}
static uint64_t
get_time(){
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
get_current_directory(char *buffer, int32_t max){
int32_t result = 0;
char *d = getcwd(buffer, max);
if (d == buffer){
result = strlen(buffer);
}
return(result);
}
static void
execute_in_dir(char *dir, char *str, char *args){
if (dir){
if (args){
Temp_Dir temp = pushdir(dir);
systemf("%s %s", str, args);
popdir(temp);
}
else{
Temp_Dir temp = pushdir(dir);
systemf("%s", str);
popdir(temp);
}
}
else{
if (args){
systemf("%s %s", str, args);
}
else{
systemf("%s", str);
}
}
}
static void
slash_fix(char *path){}
static void
make_folder_if_missing(char *dir, char *folder){
if (folder){
systemf("mkdir -p %s/%s", dir, folder);
}
else{
systemf("mkdir -p %s", dir);
}
}
static void
clear_folder(char *folder){
systemf("rm -rf %s*", folder);
}
static void
delete_file(char *file){
systemf("rm %s", file);
}
static void
copy_file(char *path, char *file, char *folder1, char *folder2, char *newname){
if (!newname){
newname = file;
}
if (path){
if (folder2){
systemf("cp %s/%s %s/%s/%s", path, file, folder1, folder2, newname);
}
else{
systemf("cp %s/%s %s/%s", path, file, folder1, newname);
}
}
else{
if (folder2){
systemf("cp %s %s/%s/%s", file, folder1, folder2, newname);
}
else{
systemf("cp %s %s/%s", file, folder1, newname);
}
}
}
static void
copy_all(char *source, char *tag, char *folder){
if (source){
systemf("cp -f %s/%s %s", source, tag, folder);
}
else{
systemf("cp -f %s %s", tag, folder);
}
}
static void
zip(char *parent, char *folder, char *file){
Temp_Dir temp = pushdir(parent);
printf("PARENT DIR: %s\n", parent);
systemf("zip -r %s %s", file, folder);
popdir(temp);
}
#elif defined(IS_MAC)
#include <time.h>
#include <unistd.h>
static Temp_Dir
pushdir(char *dir){
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);
Assert(result != 0);
Assert(chresult == 0);
}
return(temp);
}

View File

@ -1,5 +1,5 @@
1
0
74
76

10
string/build.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash
WARNINGS="-Wno-write-strings -Wno-comment -Wno-logical-op-parentheses -Wno-null-dereference -Wno-switch"
FLAGS="-D_GNU_SOURCE -fPIC -fpermissive"
g++ $WARNINGS $FLAGS ../code/string/string_builder.cpp -g -o ../build/string_builder
pushd string
../../build/string_builder
popd

View File

@ -66,7 +66,7 @@ char_is_upper(char c)
API_EXPORT_INLINE FSTRING_INLINE b32_4tech
char_is_upper_utf8(char c)
/* DOC(If c is an uppercase letter this call returns true.) */{
return (c >= 'A' && c <= 'Z' || c >= 128);
return (c >= 'A' && c <= 'Z' || (unsigned char)c >= 128);
}
API_EXPORT_INLINE FSTRING_INLINE b32_4tech
@ -78,7 +78,7 @@ char_is_lower(char c)
API_EXPORT_INLINE FSTRING_INLINE b32_4tech
char_is_lower_utf8(u8_4tech c)
/* DOC(If c is a lower letter this call returns true.) */{
return (c >= 'a' && c <= 'z' || c >= 128);
return (c >= 'a' && c <= 'z' || (unsigned char)c >= 128);
}
API_EXPORT_INLINE FSTRING_INLINE char
@ -108,7 +108,7 @@ char_is_alpha_numeric(char c)
API_EXPORT_INLINE FSTRING_INLINE b32_4tech
char_is_alpha_numeric_utf8(u8_4tech c)
/* DOC(This call returns non-zero if c is any alphanumeric character including underscore, or is a part of a UTF8 sequence outside of ASCII.) */{
return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '_' || c >= 128);
return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '_' || (unsigned char)c >= 128);
}
API_EXPORT_INLINE FSTRING_INLINE b32_4tech
@ -120,7 +120,7 @@ char_is_alpha_numeric_true(char c)
API_EXPORT_INLINE FSTRING_INLINE b32_4tech
char_is_alpha_numeric_true_utf8(u8_4tech c)
/* DOC(This call returns non-zero if c is any alphanumeric character no including underscore.) */{
return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c >= 128);
return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || (unsigned char)c >= 128);
}
API_EXPORT_INLINE FSTRING_INLINE b32_4tech
@ -132,7 +132,7 @@ char_is_alpha(char c)
API_EXPORT_INLINE FSTRING_INLINE b32_4tech
char_is_alpha_utf8(u8_4tech c)
/* DOC(This call returns non-zero if c is any alphabetic character including underscore, or is a part of a UTF8 sequence outside of ASCII.) */{
return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c == '_' || c >= 128);
return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c == '_' || (unsigned char)c >= 128);
}
API_EXPORT_INLINE FSTRING_INLINE b32_4tech
@ -144,7 +144,7 @@ char_is_alpha_true(char c)
API_EXPORT_INLINE FSTRING_INLINE b32_4tech
char_is_alpha_true_utf8(u8_4tech c)
/* DOC(This call returns non-zero if c is any alphabetic character, or is a part of a UTF8 sequence outside of ASCII.) */{
return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= 128);
return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || (unsigned char)c >= 128);
}
API_EXPORT_INLINE FSTRING_INLINE b32_4tech
@ -156,7 +156,7 @@ char_is_hex(char c)
API_EXPORT_INLINE FSTRING_INLINE b32_4tech
char_is_hex_utf8(u8_4tech c)
/* DOC(This call returns non-zero if c is any valid hexadecimal digit, or is a part of a UTF8 sequence outside of ASCII.) */{
return (c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f' || c >= 128);
return (c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f' || (unsigned char)c >= 128);
}
API_EXPORT_INLINE FSTRING_INLINE b32_4tech
@ -168,7 +168,7 @@ char_is_numeric(char c)
API_EXPORT_INLINE FSTRING_INLINE b32_4tech
char_is_numeric_utf8(u8_4tech c)
/* DOC(This call returns non-zero if c is any valid decimal digit, or is a part of a UTF8 sequence outside of ASCII.) */{
return (c >= '0' && c <= '9' || c >= 128);
return (c >= '0' && c <= '9' || (unsigned char)c >= 128);
}
@ -1452,17 +1452,11 @@ space in dest this call returns non-zero.) */{
API_EXPORT FSTRING_LINK i32_4tech
u64_to_str_size(uint64_t x)/*
DOC(This call returns the number of bytes required to represent x as a string.) */{
i32_4tech size;
if (x < 0){
size = 0;
}
else{
size = 1;
i32_4tech size = 1;
x /= 10;
while (x != 0){
x /= 10;
while (x != 0){
x /= 10;
++size;
}
++size;
}
return(size);
}

View File

@ -481,7 +481,7 @@ int main(){
}
#define FTECH_FILE_MOVING_IMPLEMENTATION
#include "..\meta\4tech_file_moving.h"
#include "../meta/4tech_file_moving.h"
// BOTTOM