Skip to content

Commit

Permalink
Merge pull request #11 from EimaMei/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
EimaMei authored May 25, 2024
2 parents e5745f1 + 14b3e7f commit 04a5dec
Show file tree
Hide file tree
Showing 5 changed files with 857 additions and 616 deletions.
14 changes: 7 additions & 7 deletions examples/bit.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#define SI_IMPLEMENTATION
#include <sili.h>

inline cstring operatingSystem(void) {
cstring operatingSystem(void) {
static char res[] =
#if defined(SI_SYSTEM_WINDOWS)
"Windows"
Expand All @@ -22,7 +22,7 @@ inline cstring operatingSystem(void) {
}


inline cstring cpuArch(void) {
cstring cpuArch(void) {
static char res[] =
#if defined(SI_CPU_X86)
"x86"
Expand All @@ -48,19 +48,19 @@ inline cstring cpuArch(void) {
return res;
}

inline usize cpu_arch_bit(void) {
usize cpu_arch_bit(void) {
#if defined(SI_ARCH_64_BIT)
return 64;
#elif defined(SI_ARCH_32_BIT)
return 32;
#endif
}

inline cstring cpuEndian(void) {
cstring cpuEndian(void) {
return (SI_HOST_IS_LITTLE_ENDIAN == true) ? "little-endian" : "big-endian";
}

inline cstring compiler(void) {
cstring compiler(void) {
static char res[] =
#if defined(SI_COMPILER_GCC)
"GCC"
Expand All @@ -76,7 +76,7 @@ inline cstring compiler(void) {
return res;
}

inline cstring language(void) {
cstring language(void) {
static char res[] =
#if defined(SI_LANGUAGE_C)
"C"
Expand All @@ -93,7 +93,7 @@ inline cstring language(void) {
return res;
}

inline cstring standard(void) {
cstring standard(void) {
static char res[] =
#if !defined(SI_LANGUAGE_CPP)
#if SI_STANDARD_VERSION == SI_STANDARD_C89
Expand Down
22 changes: 14 additions & 8 deletions examples/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

void example1(siAllocator* heap) {
siAllocator* stack = si_allocatorMakeStack(SI_KILO(4));

si_printf("==============\n\n==============\nExample 1:\n");

siFile file = si_fileOpen("examples/file.c"); /* If the file doesn't exist or fails to open any other way, then we will get an assertion error. */
Expand All @@ -17,7 +17,7 @@ void example1(siAllocator* heap) {

siFile newFile = si_fileCreate("random.txt");
si_fileWrite(&newFile, "A silly file\nwith a sili newline.");
siString content = si_fileReadContents(heap, newFile);
siString content = si_fileReadContents(newFile, heap);

si_printf(
"About 'random.txt':\n\t"
Expand All @@ -28,7 +28,7 @@ void example1(siAllocator* heap) {
content
);

siArray(siString) fileLine = si_fileReadlines(heap, file);
siArray(siString) fileLine = si_fileReadlines(file, heap);
si_printf(
"QContents of '%s' ('%zd' lines in total):\n",
si_pathBaseName(file.filename), si_arrayLen(fileLine)
Expand All @@ -42,7 +42,7 @@ void example1(siAllocator* heap) {
si_allocatorReset(heap);

si_fileWriteAtLine(&newFile, "but now we have a changed line", 1);
siArray(siString) newFileLines = si_fileReadlines(heap, newFile);
siArray(siString) newFileLines = si_fileReadlines(newFile, heap);
si_printf(
"Contents of '%s' ('%zd' lines in total):\n",
si_pathBaseName("randomDir/random.txt"), si_arrayLen(newFileLines)
Expand All @@ -60,14 +60,14 @@ void example2(void) {
si_printf("==============\n\n==============\nExample 2:\n");

b32 exist = si_pathExists("example.c");
si_printf("File 'example.c' %s\n", (exist ? "DOES exist" : "DOESN'T exist"));

exist = si_pathExists("random.txt");
if (!exist) {
SI_PANIC();
si_printf("Since 'random.txt' doesn't exist, we'll just create one\n");

siFile file = si_fileCreate("random.txt");
si_fileWrite(&file, "KANT RUINED US ALL");
si_fileWrite(&file, "KANT RUINED EVERYTHING");
si_fileClose(file);
}

Expand Down Expand Up @@ -113,7 +113,9 @@ void example3(void) {
{
si_pathRemove("SI_FILE_THAT_DOESNT_EXIST");

si_pathCreateFolder("testFolder");
b32 res = si_pathCreateFolder("testFolder");
SI_ASSERT(res);

siFilePermissions perms = si_pathPermissions("testFolder");
si_printf("Permissions of 'testFolder' (in octal): %o\n", perms);

Expand Down Expand Up @@ -142,6 +144,8 @@ void example3(void) {
si_fileClose(file);

si_pathRemove(file.filename);
si_pathRemove("hardLink");
si_pathRemove("softLink");

si_printf("Temporary path of the system: %s\n", si_pathGetTmp());
}
Expand All @@ -168,6 +172,8 @@ void example4(siAllocator* alloc) {
si_printf("%zu: %s - %i\n", count, entry.path, entry.type);
count += 1;
}

si_pathRemove(ROOT_PATH);
}

void example5(siAllocator* alloc) {
Expand All @@ -184,7 +190,7 @@ void example5(siAllocator* alloc) {
si_printf("%B - %B (%#b, %#b)\n", true, false, true, false);
si_printf("Pointer to the heap: %p\n", alloc);
si_printf("This will print nothing: '%n', 100%%.\n", (signed int*)nil);
si_printf("%CRThis text will be displayed in red%C, while this: %CBblue%C!\n");
si_printf("%CRThis text will be displayed in red%C, while this: %CBin blue%C!\n");
si_fprintf(SI_STDOUT, "Unicode works both on Unix and Windows* (ąčęėįšųū„“)\n\t%CY* - Works as long as the font supports the codepoint, which for some reason isn't common.%C\n");
}

Expand Down
2 changes: 1 addition & 1 deletion examples/pair.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ int main(void) {
siAllocator* stack = si_allocatorMakeStack(0xFF);

/* Example 3.0: siPair (based on https://cplusplus.com/reference/utility/pair/pair/) */
printf("==============\n\n==============\nExample 3.0:\n");
si_printf("==============\n\n==============\nExample 3.0:\n");

siPair(siString, f64) product1;
siPair(siString, f64) product2 = si_pairMake(si_stringMake(stack, "tomatoes"), 2.30);
Expand Down
2 changes: 1 addition & 1 deletion examples/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ i16 threadTest(b32* arg) {
i16 count = INT16_MIN;

if (loop) {
printf("The function will increment 'count' from %d to %d:\n", INT16_MIN, INT16_MAX);
si_printf("The function will increment 'count' from %d to %d:\n", INT16_MIN, INT16_MAX);
si_sleep(2000);
while (count < INT16_MAX) {
count += 1;
Expand Down
Loading

0 comments on commit 04a5dec

Please sign in to comment.