Upload files to "src"
This commit is contained in:
34
src/fileHandle.c
Normal file
34
src/fileHandle.c
Normal file
@@ -0,0 +1,34 @@
|
||||
// this code is licenced under Wrathmark licence
|
||||
// © 2026 wullie wulliestudio.com
|
||||
// please see attached licence for full usage and rights
|
||||
|
||||
#include "stdWullie.h"
|
||||
#include "localheader.h"
|
||||
|
||||
// it should be set to W for wumbo
|
||||
// opens files
|
||||
long Wopen(const char *pathname, int flags, int mode){
|
||||
if(pathname == NULL || flags == NULL || mode == NULL){
|
||||
safeError(NULL);
|
||||
}
|
||||
syscall3(SYS_open, (long)pathname, flags, mode);
|
||||
}
|
||||
|
||||
// named like this to not cause compat issues with glibc
|
||||
long closeFile(long fd){
|
||||
if(fd == NULL){
|
||||
safeError(NULL);
|
||||
}
|
||||
syscall2(SYS_close, fd, 0);
|
||||
}
|
||||
|
||||
// read whats in the file descripter and move it into a buffer
|
||||
long reader(long fd, char *string){
|
||||
syscall3(SYS_read, fd, (long)string, sizeof(string)-1);
|
||||
|
||||
}
|
||||
|
||||
// does that it say on the tin
|
||||
long mkdir(const char *filePath, int mode){
|
||||
syscall2(SYS_mkdir, (long)filePath, mode);
|
||||
}
|
||||
56
src/funcs.c
56
src/funcs.c
@@ -9,46 +9,34 @@
|
||||
// our own exit LINUX ONLY
|
||||
void exit(int code){
|
||||
syscall1(SYS_exit, code);
|
||||
for(;;){}
|
||||
for(;;) {}
|
||||
}
|
||||
|
||||
|
||||
// handles the length of a string for print
|
||||
long unsigned strlen(char *string){
|
||||
char *cursor = string;
|
||||
while(*cursor){
|
||||
cursor++;
|
||||
// safty last
|
||||
void safeError(char *error){
|
||||
if(error != NULL){
|
||||
print(error);
|
||||
ColorPrint("exiting with code -1\n", RED);
|
||||
exit(-1);
|
||||
}
|
||||
long unsigned result = cursor - string;
|
||||
return result;
|
||||
|
||||
print("something went wrong ");
|
||||
ColorPrint("exiting with code -1\n", RED);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// only use this when something will work but not as intended
|
||||
void riskyError(){
|
||||
print("not critical error was found\n");
|
||||
}
|
||||
|
||||
|
||||
// print
|
||||
void print(char *string){
|
||||
syscall3(SYS_write, 1, (long)string, strlen(string));
|
||||
}
|
||||
// #Schlaf mein Kindlein, schlaf doch ein, der Rabe hat nach dir gerufen.#
|
||||
void sleeper(long seconds){
|
||||
timespec duration = {0};
|
||||
duration.tv_sec = seconds;
|
||||
|
||||
// it can do everythig print can but better
|
||||
void ColorPrint(char *string, char *color){
|
||||
syscall3(SYS_write, 1, (long)color, strlen(color));
|
||||
syscall3(SYS_write, 1, (long)string, strlen(string));
|
||||
syscall3(SYS_write, 1, (long)NORMAL, sizeof(NORMAL)-1);
|
||||
}
|
||||
syscall2(SYS_sleep, (long)(&duration), 0);
|
||||
|
||||
|
||||
// instead of changing the foreground it changes the background
|
||||
void BackgroundPrint(char *string, char *Bcolor){
|
||||
syscall3(SYS_write, 1, (long)Bcolor, strlen(Bcolor));
|
||||
syscall3(SYS_write, 1, (long)string, strlen(string));
|
||||
syscall3(SYS_write, 1, (long)NORMAL, sizeof(NORMAL)-1);
|
||||
}
|
||||
|
||||
// it should be set to W for wumbo
|
||||
long Wopen(const char *pathname, int flags, int mode){
|
||||
syscall3(SYS_open, (long)pathname, flags, mode);
|
||||
}
|
||||
|
||||
// named like this to not cause compat issues with glibc
|
||||
long closeFile(long fd){
|
||||
syscall2(SYS_close, fd);
|
||||
}
|
||||
|
||||
50
src/main.c
50
src/main.c
@@ -5,11 +5,51 @@
|
||||
#include "stdWullie.h"
|
||||
#include "localheader.h"
|
||||
|
||||
int main(){
|
||||
print("look Ma no stdlib\n");
|
||||
ColorPrint("NOW WITH COLORS\n", RED);
|
||||
BackgroundPrint("and backgrounds\n", BBLUE);
|
||||
ColorPrint("NOW WITH COLORS", RED);
|
||||
int main(int argc, char *argv[]){
|
||||
|
||||
if(argc != 2){
|
||||
print("test functions for stdWullie use agruments 1 - 3 to test features\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *rawArg = argv[1];
|
||||
long argNum = intParser(rawArg);
|
||||
|
||||
switch(argNum){
|
||||
case 1:
|
||||
print("look Ma no stdlib\n");
|
||||
ColorPrint("NOW WITH COLORS\n", RED);
|
||||
BackgroundPrint("and backgrounds\n", BBLUE);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
print("test for safe exit\n");
|
||||
safeError(NULL);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
print("sleep for 2 seconds before exit\n");
|
||||
sleeper(2);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
char string[] = "contvers to upper then to lower\n";
|
||||
upper(string);
|
||||
print(string);
|
||||
lower(string);
|
||||
print(string);
|
||||
break;
|
||||
|
||||
case 5:
|
||||
print("making a test dir with the name test\n");
|
||||
mkdir("test", 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
print("no args given or arg is out of range\n");
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
27
src/math.c
Normal file
27
src/math.c
Normal file
@@ -0,0 +1,27 @@
|
||||
// this code is licenced under Wrathmark licence
|
||||
// © 2026 wullie wulliestudio.com
|
||||
// please see attached licence for full usage and rights
|
||||
|
||||
#include "stdWullie.h"
|
||||
|
||||
// int parser basicly atol
|
||||
int intParser(char *rawInt){
|
||||
int result = 0;
|
||||
char *cursor = rawInt;
|
||||
|
||||
while(*cursor >= '0' && *cursor <= '9'){
|
||||
result = result * 10 + (*cursor - '0');
|
||||
cursor++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// fast inverse square root why: bc this is my lib
|
||||
float invSqrt(float x){
|
||||
float xhalf = 0.5f * x;
|
||||
int i = *(int*)&x;
|
||||
i = 0x5f3759df - (i >> 1);
|
||||
x = *(float*)&i;
|
||||
x = x*(1.5f - xhalf*x*x);
|
||||
return x;
|
||||
}
|
||||
70
src/printing.c
Normal file
70
src/printing.c
Normal file
@@ -0,0 +1,70 @@
|
||||
// this code is licenced under Wrathmark licence
|
||||
// © 2026 wullie wulliestudio.com
|
||||
// please see attached licence for full usage and rights
|
||||
|
||||
#include "stdWullie.h"
|
||||
#include "localheader.h"
|
||||
|
||||
// handles the length of a string for print
|
||||
long unsigned lengthStr(char *string){
|
||||
char *cursor = string;
|
||||
while(*cursor){
|
||||
cursor++;
|
||||
}
|
||||
long unsigned result = cursor - string;
|
||||
return result;
|
||||
}
|
||||
|
||||
// its print what do you expect? for it to read?
|
||||
void print(char *string){
|
||||
syscall3(SYS_write, 1, (long)string, lengthStr(string));
|
||||
}
|
||||
|
||||
// it can do everythig print can but better
|
||||
void ColorPrint(char *string, char *color){
|
||||
syscall3(SYS_write, 1, (long)color, lengthStr(color));
|
||||
syscall3(SYS_write, 1, (long)string, lengthStr(string));
|
||||
syscall3(SYS_write, 1, (long)NORMAL, sizeof(NORMAL)-1);
|
||||
}
|
||||
|
||||
// instead of changing the foreground it changes the background
|
||||
void BackgroundPrint(char *string, char *Bcolor){
|
||||
syscall3(SYS_write, 1, (long)Bcolor, lengthStr(Bcolor));
|
||||
syscall3(SYS_write, 1, (long)string, lengthStr(string));
|
||||
syscall3(SYS_write, 1, (long)NORMAL, sizeof(NORMAL)-1);
|
||||
}
|
||||
|
||||
// converts a sting to uppercase
|
||||
void upper(char string[]){
|
||||
int i = 0;
|
||||
while(string[i] != '\0'){
|
||||
if(string[i] >= 'a' && string[i] <= 'z') {
|
||||
string[i] = string[i] - 32;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
// does the same but to lower case instead
|
||||
void lower(char string[]){
|
||||
int cursor = 0;
|
||||
while(string[cursor] != '\0'){
|
||||
if(string[cursor] >= 'A' && string[cursor] <= 'Z'){
|
||||
string[cursor] = string[cursor] + 32;
|
||||
}
|
||||
cursor++;
|
||||
}
|
||||
}
|
||||
|
||||
// converts an int to a char
|
||||
//char str(int number){
|
||||
// char numbChar[];
|
||||
// int *cursor = number;
|
||||
|
||||
// while(*cursor >=0 && *cursor <=9){
|
||||
// numbChar = *numbChar / 10 +(*cursor - 0);
|
||||
// cursor++
|
||||
// }
|
||||
// return numbChar;
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user