diff options
author | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-04-23 12:37:28 +0330 |
---|---|---|
committer | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-04-23 12:37:28 +0330 |
commit | ab832419702bd28e9b59a9fce169114384a43d88 (patch) | |
tree | 272af4685d2f8448b7f289e5f99b3965566a8f66 | |
parent | 1644f22d76b24ead55fdf7ad48ec7b32323b427b (diff) |
prepairing stuff for import in codes
-rw-r--r-- | code/basic.felan | 40 | ||||
-rw-r--r-- | src/utils/file.c | 15 | ||||
-rw-r--r-- | src/utils/file.h | 1 |
3 files changed, 56 insertions, 0 deletions
diff --git a/code/basic.felan b/code/basic.felan new file mode 100644 index 0000000..9d93ef8 --- /dev/null +++ b/code/basic.felan @@ -0,0 +1,40 @@ +string :: []u8; + +print :: (value:[]u8)->void{ + i :u64= 0; + while i < value.length { + putc value[i]; + i += 1; + } +}; + +print :: (value:u64)->void{ + value := value; + result :[20]u8 = undefined; + i := 0; + while { + result[i] = '0' + @cast(value % 10,u8); + i += 1; + value /= 10; + value != 0; + } {} + + j := 0; + while j < i { + putc result[j]; + j += 1; + } +}; + +to_u64 :: (value:string) -> u64 { + i := value.length; + result :u64= 0; + + while i > 0 { + c := value[i-1]; + result *= 10; + result += @cast(c - '0',u64); + i -= 1; + } + return result; +}; diff --git a/src/utils/file.c b/src/utils/file.c index 6d737f7..714dc2c 100644 --- a/src/utils/file.c +++ b/src/utils/file.c @@ -44,6 +44,10 @@ void filePush(const char *filePath, char *code) { } char *readWholeFile(const char *filePath) { + const size_t index = getFileIndex(filePath); + if (index != fileCodes_length) { + return fileCodes[index]; + } FILE *file = fopen(filePath, "r"); if (!file) { @@ -65,3 +69,14 @@ char *readWholeFile(const char *filePath) { return str; } + +size_t getFileIndex(const char *filePath) { + for (size_t i = 0; i < fileCodes_length; ++i) { + const char *str = fileCodes_names[i]; + if (strcmp(filePath, str) == 0) { + return i; + } + } + + return fileCodes_length; +} diff --git a/src/utils/file.h b/src/utils/file.h index 31e6503..f0b0d8c 100644 --- a/src/utils/file.h +++ b/src/utils/file.h @@ -13,3 +13,4 @@ void fileDelete(); void filePush(const char *filePath,char *code); char *readWholeFile(const char *filePath); +size_t getFileIndex(const char *filePath); |