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

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

View File

@ -1,5 +1,5 @@
/* /*
4coder_string.h - Version 1.0.72 4coder_string.h - Version 1.0.74
no warranty implied; use at your own risk no warranty implied; use at your own risk
This software is in the public domain. Where that dedication is not This software is in the public domain. Where that dedication is not
@ -12,37 +12,6 @@ To use in C mode: #define FSTRING_C
// TOP // TOP
// 4tech_standard_preamble.h
#if !defined(FTECH_INTEGERS)
#define FTECH_INTEGERS
#include <stdint.h>
typedef int8_t i8_4tech;
typedef int16_t i16_4tech;
typedef int32_t i32_4tech;
typedef int64_t i64_4tech;
typedef uint8_t u8_4tech;
typedef uint16_t u16_4tech;
typedef uint32_t u32_4tech;
typedef uint64_t u64_4tech;
#if defined(FTECH_32_BIT)
typedef u32_4tech umem_4tech;
#else
typedef u64_4tech umem_4tech;
#endif
typedef float f32_4tech;
typedef double f64_4tech;
typedef int8_t b8_4tech;
typedef int32_t b32_4tech;
#endif
#if !defined(Assert)
# define Assert(n) do{ if (!(n)) *(int*)0 = 0xA11E; }while(0)
#endif
// standard preamble end
#if !defined(FSTRING_LINK) #if !defined(FSTRING_LINK)
@ -316,7 +285,7 @@ char_is_upper(char c)
FSTRING_INLINE b32_4tech FSTRING_INLINE b32_4tech
char_is_upper_utf8(char c) char_is_upper_utf8(char c)
{ {
return (c >= 'A' && c <= 'Z' || c >= 128); return (c >= 'A' && c <= 'Z' || (unsigned char)c >= 128);
} }
#endif #endif
@ -332,7 +301,7 @@ char_is_lower(char c)
FSTRING_INLINE b32_4tech FSTRING_INLINE b32_4tech
char_is_lower_utf8(u8_4tech c) char_is_lower_utf8(u8_4tech c)
{ {
return (c >= 'a' && c <= 'z' || c >= 128); return (c >= 'a' && c <= 'z' || (unsigned char)c >= 128);
} }
#endif #endif
@ -372,7 +341,7 @@ char_is_alpha_numeric(char c)
FSTRING_INLINE b32_4tech FSTRING_INLINE b32_4tech
char_is_alpha_numeric_utf8(u8_4tech c) char_is_alpha_numeric_utf8(u8_4tech c)
{ {
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);
} }
#endif #endif
@ -388,7 +357,7 @@ char_is_alpha_numeric_true(char c)
FSTRING_INLINE b32_4tech FSTRING_INLINE b32_4tech
char_is_alpha_numeric_true_utf8(u8_4tech c) char_is_alpha_numeric_true_utf8(u8_4tech c)
{ {
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);
} }
#endif #endif
@ -404,7 +373,7 @@ char_is_alpha(char c)
FSTRING_INLINE b32_4tech FSTRING_INLINE b32_4tech
char_is_alpha_utf8(u8_4tech c) char_is_alpha_utf8(u8_4tech c)
{ {
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);
} }
#endif #endif
@ -420,7 +389,7 @@ char_is_alpha_true(char c)
FSTRING_INLINE b32_4tech FSTRING_INLINE b32_4tech
char_is_alpha_true_utf8(u8_4tech c) char_is_alpha_true_utf8(u8_4tech c)
{ {
return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= 128); return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || (unsigned char)c >= 128);
} }
#endif #endif
@ -436,7 +405,7 @@ char_is_hex(char c)
FSTRING_INLINE b32_4tech FSTRING_INLINE b32_4tech
char_is_hex_utf8(u8_4tech c) char_is_hex_utf8(u8_4tech c)
{ {
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);
} }
#endif #endif
@ -452,7 +421,7 @@ char_is_numeric(char c)
FSTRING_INLINE b32_4tech FSTRING_INLINE b32_4tech
char_is_numeric_utf8(u8_4tech c) char_is_numeric_utf8(u8_4tech c)
{ {
return (c >= '0' && c <= '9' || c >= 128); return (c >= '0' && c <= '9' || (unsigned char)c >= 128);
} }
#endif #endif
@ -1656,18 +1625,12 @@ append_int_to_str(String *dest, i32_4tech x){
#if defined(FSTRING_IMPLEMENTATION) #if defined(FSTRING_IMPLEMENTATION)
FSTRING_LINK i32_4tech FSTRING_LINK i32_4tech
u64_to_str_size(uint64_t x){ u64_to_str_size(uint64_t x){
i32_4tech size; i32_4tech size = 1;
if (x < 0){
size = 0;
}
else{
size = 1;
x /= 10; x /= 10;
while (x != 0){ while (x != 0){
x /= 10; x /= 10;
++size; ++size;
} }
}
return(size); return(size);
} }
#endif #endif

View File

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

View File

@ -5,7 +5,7 @@ if [ -z "$BUILD_MODE" ]; then
BUILD_MODE="-DDEV_BUILD" BUILD_MODE="-DDEV_BUILD"
fi 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" FLAGS="-D_GNU_SOURCE -fPIC -fpermissive $BUILD_MODE"
g++ $WARNINGS $FLAGS meta/build.cpp -g -o ../build/build g++ $WARNINGS $FLAGS meta/build.cpp -g -o ../build/build

View File

@ -28,6 +28,13 @@ static char platform_correct_slash = '\\';
#define SLASH "/" #define SLASH "/"
static char platform_correct_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 #else
# define ONLY_WINDOWS(x) (void)0 # define ONLY_WINDOWS(x) (void)0
# define ONLY_LINUX(x) (void)0 # define ONLY_LINUX(x) (void)0
@ -281,8 +288,145 @@ pushdir(char *dir){
int32_t chresult = chdir(dir); int32_t chresult = chdir(dir);
if (result == 0 || chresult != 0){ if (result == 0 || chresult != 0){
printf("trying pushdir %s\n", dir); printf("trying pushdir %s\n", dir);
assert(result != 0); Assert(result != 0);
assert(chresult == 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); return(temp);
} }

View File

@ -1,5 +1,5 @@
1 1
0 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 API_EXPORT_INLINE FSTRING_INLINE b32_4tech
char_is_upper_utf8(char c) char_is_upper_utf8(char c)
/* DOC(If c is an uppercase letter this call returns true.) */{ /* 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 API_EXPORT_INLINE FSTRING_INLINE b32_4tech
@ -78,7 +78,7 @@ char_is_lower(char c)
API_EXPORT_INLINE FSTRING_INLINE b32_4tech API_EXPORT_INLINE FSTRING_INLINE b32_4tech
char_is_lower_utf8(u8_4tech c) char_is_lower_utf8(u8_4tech c)
/* DOC(If c is a lower letter this call returns true.) */{ /* 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 API_EXPORT_INLINE FSTRING_INLINE char
@ -108,7 +108,7 @@ char_is_alpha_numeric(char c)
API_EXPORT_INLINE FSTRING_INLINE b32_4tech API_EXPORT_INLINE FSTRING_INLINE b32_4tech
char_is_alpha_numeric_utf8(u8_4tech c) 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.) */{ /* 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 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 API_EXPORT_INLINE FSTRING_INLINE b32_4tech
char_is_alpha_numeric_true_utf8(u8_4tech c) char_is_alpha_numeric_true_utf8(u8_4tech c)
/* DOC(This call returns non-zero if c is any alphanumeric character no including underscore.) */{ /* 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 API_EXPORT_INLINE FSTRING_INLINE b32_4tech
@ -132,7 +132,7 @@ char_is_alpha(char c)
API_EXPORT_INLINE FSTRING_INLINE b32_4tech API_EXPORT_INLINE FSTRING_INLINE b32_4tech
char_is_alpha_utf8(u8_4tech c) 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.) */{ /* 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 API_EXPORT_INLINE FSTRING_INLINE b32_4tech
@ -144,7 +144,7 @@ char_is_alpha_true(char c)
API_EXPORT_INLINE FSTRING_INLINE b32_4tech API_EXPORT_INLINE FSTRING_INLINE b32_4tech
char_is_alpha_true_utf8(u8_4tech c) 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.) */{ /* 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 API_EXPORT_INLINE FSTRING_INLINE b32_4tech
@ -156,7 +156,7 @@ char_is_hex(char c)
API_EXPORT_INLINE FSTRING_INLINE b32_4tech API_EXPORT_INLINE FSTRING_INLINE b32_4tech
char_is_hex_utf8(u8_4tech c) 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.) */{ /* 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 API_EXPORT_INLINE FSTRING_INLINE b32_4tech
@ -168,7 +168,7 @@ char_is_numeric(char c)
API_EXPORT_INLINE FSTRING_INLINE b32_4tech API_EXPORT_INLINE FSTRING_INLINE b32_4tech
char_is_numeric_utf8(u8_4tech c) 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.) */{ /* 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,18 +1452,12 @@ space in dest this call returns non-zero.) */{
API_EXPORT FSTRING_LINK i32_4tech API_EXPORT FSTRING_LINK i32_4tech
u64_to_str_size(uint64_t x)/* u64_to_str_size(uint64_t x)/*
DOC(This call returns the number of bytes required to represent x as a string.) */{ DOC(This call returns the number of bytes required to represent x as a string.) */{
i32_4tech size; i32_4tech size = 1;
if (x < 0){
size = 0;
}
else{
size = 1;
x /= 10; x /= 10;
while (x != 0){ while (x != 0){
x /= 10; x /= 10;
++size; ++size;
} }
}
return(size); return(size);
} }

View File

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