Skip to content

Commit

Permalink
vlstrtok
Browse files Browse the repository at this point in the history
  • Loading branch information
realzvqle committed Aug 18, 2024
1 parent acbc3e0 commit 739e3f2
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 16 deletions.
28 changes: 14 additions & 14 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@


void VlEntry() {
VlPuts(L"VulaOS Build INDEV (0.0.2)\n\n");
VlPuts(L"Input Test\n\n");

VlPuts(L"VulaOS Build INDEV (0.0.3)\n\n");
VlPuts(L"String Parsing Test\n\n");


while (1) {
VlSleep(9);
WCHAR* name = VlGets(L"Whats Your Name?", 1024);
if (name == NULL) {
VlPuts(L"Memory allocation failed\n");
continue;
}

// gotta implement vlprintf soon lol
VlPuts(L"Hi ");
VlPuts(name);
WCHAR* first;
WCHAR* second;
WCHAR* input = VlGets(L"Type Strings So It Can Be Parsed", 1024);
VlStrTok(&first, 512,& second, 512, L' ', input);
VlPuts(first);
VlPuts(L" --- ");
VlPuts(second);
VlPuts(L"\n");

VlFreeString(name, 1024);
VlFreeString(input, 1024);
VlFreeString(first, 512);
VlFreeString(second, 512);
}
}

Expand Down
43 changes: 43 additions & 0 deletions src/vlcrt.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "vlcrt.h"
#include "vula.h"
#include <minwindef.h>
#include <vcruntime.h>
#include <winnt.h>

Expand Down Expand Up @@ -396,6 +397,48 @@ WCHAR* VlGets(WCHAR* prompt, size_t size) {
}




void VlStrTok(WCHAR** firststring, size_t firststringsize, WCHAR** secondstring, size_t secondstringsize, WCHAR delimiter, WCHAR* sourcestring) {
*firststring = (WCHAR*)VlAlloc(firststringsize * sizeof(WCHAR));
*secondstring = (WCHAR*)VlAlloc(secondstringsize * sizeof(WCHAR));

for (int j = 0; j < firststringsize; j++) {
(*firststring)[j] = L'\0';
}
for (int j = 0; j < secondstringsize; j++) {
(*secondstring)[j] = L'\0';
}

int i = 0;
int firstIndex = 0;
int secondIndex = 0;
BOOL switcher = FALSE;

while (sourcestring[i] != L'\0') {
if(switcher == FALSE){
if (sourcestring[i] == delimiter) {
switcher = TRUE;
i++;
continue;
}
else if (firstIndex < firststringsize - 1) {
(*firststring)[firstIndex++] = sourcestring[i];
}
}
else {
if (secondIndex < secondstringsize - 1) {
(*secondstring)[secondIndex++] = sourcestring[i];
}
}

i++;
}
(*firststring)[firststringsize - 1] = L'\0';
(*secondstring)[secondstringsize - 1] = L'\0';
}


BOOL VlFreeString(WCHAR* string, size_t size){
BOOL result = VlFree(string, size * sizeof(WCHAR));
return result;
Expand Down
3 changes: 1 addition & 2 deletions src/vlcrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ WCHAR* VlCharToString(WCHAR character);
WCHAR VlGetKey();
WCHAR* VlGets(WCHAR* prompt, size_t size);
BOOL VlFreeString(WCHAR* string, size_t size);


void VlStrTok(WCHAR** firststring, size_t firststringsize, WCHAR** secondstring, size_t secondstringsize, WCHAR delimiter, WCHAR* sourcestring);


#endif

0 comments on commit 739e3f2

Please sign in to comment.