Simple malloc has been added, splitting the path now works
This commit is contained in:
1 parent
e12768398d
commit
d5bc5e8958
7 files changed
+2277
-398
No files matched your search
+2
-2
@@ -1,4 +1,5 @@
|
||||
void print(string);
|
||||
void* dump_ax_return(input);
|
||||
|
||||
void print(string)
|
||||
char* string;
|
||||
@@ -31,7 +32,7 @@ void print_stack(argument)
|
||||
#endasm
|
||||
}
|
||||
|
||||
dump_ax_return(input)
|
||||
void* dump_ax_return(input)
|
||||
void* input;
|
||||
{
|
||||
return input;
|
||||
@@ -40,7 +41,6 @@ void* input;
|
||||
void dump_ax(input)
|
||||
void* input;
|
||||
{
|
||||
// Force the variable in ax
|
||||
dump_ax_return(input)
|
||||
#asm
|
||||
push bp
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
unsigned int global_heap_start = 0;
|
||||
unsigned int global_heap_end = 0;
|
||||
unsigned int global_heap_next = 0;
|
||||
|
||||
void* malloc(num_bytes);
|
||||
int set_heap_settings(param_start, param_end);
|
||||
unsigned int get_heap_next();
|
||||
|
||||
void* malloc(num_bytes)
|
||||
int num_bytes;
|
||||
{
|
||||
unsigned int allocated_pointer = global_heap_next;
|
||||
global_heap_next = global_heap_next + num_bytes;
|
||||
if (global_heap_next > global_heap_end)
|
||||
{
|
||||
return 0; /* No more memory */
|
||||
}
|
||||
|
||||
return allocated_pointer;
|
||||
}
|
||||
|
||||
int set_heap_settings(param_start, param_end)
|
||||
unsigned int param_start;
|
||||
unsigned int param_end;
|
||||
{
|
||||
global_heap_start = param_start;
|
||||
global_heap_next = param_start;
|
||||
global_heap_end = param_end;
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int get_heap_next()
|
||||
{
|
||||
return global_heap_next;
|
||||
}
|
||||
@@ -1,7 +1,30 @@
|
||||
|
||||
|
||||
typedef struct Length_String {
|
||||
short dynamic;
|
||||
unsigned int length;
|
||||
char *chars;
|
||||
} Length_String;
|
||||
|
||||
typedef struct String_Array {
|
||||
unsigned int length;
|
||||
Length_String **strings;
|
||||
} String_Array;
|
||||
|
||||
void strcpy (destination, destination_segment, source, source_segment );
|
||||
int strlen (source, source_segment);
|
||||
void memcpy (destination, destination_segment, source, source_segment, num_bytes );
|
||||
|
||||
// Additionals to standard c lib.
|
||||
String_Array *string_split_c(string, delim, keep_delim);
|
||||
Length_String *make_length_string(length, chars);
|
||||
Length_String *make_length_string_c(cstring);
|
||||
String_Array *length_string_split(string, delim, keep_delim);
|
||||
String_Array *create_length_string_array(array_size);
|
||||
Length_String *create_length_string(length, chars);
|
||||
|
||||
|
||||
|
||||
int strlen (source, source_segment)
|
||||
{
|
||||
#asm
|
||||
@@ -141,4 +164,121 @@ int num_bytes;
|
||||
pop bp
|
||||
|
||||
#endasm
|
||||
}
|
||||
|
||||
String_Array *string_split_c(string, delim, keep_delim)
|
||||
char *string;
|
||||
char delim;
|
||||
short keep_delim;
|
||||
{
|
||||
return length_string_split(make_length_string_c(string), delim, keep_delim);
|
||||
}
|
||||
|
||||
Length_String *make_length_string_c(cstring)
|
||||
char *cstring;
|
||||
{
|
||||
return make_length_string(strlen(cstring, 0x7e0), cstring);
|
||||
}
|
||||
|
||||
Length_String *make_length_string(length, chars)
|
||||
unsigned int length;
|
||||
char *chars;
|
||||
{
|
||||
|
||||
Length_String *legth_string = malloc(sizeof(Length_String));
|
||||
|
||||
char *copy = malloc(length + 1); // Space for null terminator
|
||||
memcpy(copy, 0x7e0, chars, 0x7e0, length);
|
||||
copy[length] = '\0';
|
||||
|
||||
legth_string->dynamic = 0;
|
||||
legth_string->length = length;
|
||||
legth_string->chars = (char *)chars;
|
||||
|
||||
return legth_string;
|
||||
}
|
||||
|
||||
String_Array *length_string_split(string, delim, keep_delim)
|
||||
Length_String *string;
|
||||
char delim;
|
||||
short keep_delim;
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned int last;
|
||||
|
||||
unsigned int count = 0;
|
||||
unsigned int insert_index = 0;
|
||||
String_Array *result;
|
||||
int k;
|
||||
|
||||
i = 0;
|
||||
last = 0;
|
||||
while(i < string->length) {
|
||||
if (string->chars[i] == delim) {
|
||||
if (i > last+1) {
|
||||
++count;
|
||||
}
|
||||
last = i;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
if (i > last+1) {
|
||||
++count;
|
||||
}
|
||||
|
||||
result = create_length_string_array(count);
|
||||
|
||||
if (keep_delim)
|
||||
{
|
||||
k = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
k = 1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
last = 0;
|
||||
while(i < string->length) {
|
||||
if (string->chars[i] == delim) {
|
||||
if (i > last+1) {
|
||||
result->strings[insert_index++] = create_length_string(i-(last+k), string->chars+(last+k));
|
||||
}
|
||||
last = i;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
if (i > last+1) {
|
||||
result->strings[insert_index++] = create_length_string(i-(last+k), ((string->chars)+(last+k)));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
String_Array *create_length_string_array(array_size)
|
||||
int array_size;
|
||||
{
|
||||
String_Array *result = malloc(sizeof(String_Array));
|
||||
result->length = array_size;
|
||||
result->strings = malloc(array_size * sizeof(Length_String));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Length_String *create_length_string(length, chars)
|
||||
unsigned int length;
|
||||
char *chars;
|
||||
{
|
||||
|
||||
Length_String *legth_string = malloc(sizeof(Length_String));
|
||||
char *copy = malloc(length + 1); // Space for null terminator
|
||||
memcpy(copy, 0x7e0, chars, 0x7e0, length);
|
||||
copy[length] = '\0';
|
||||
|
||||
legth_string->dynamic = 1;
|
||||
legth_string->length = length;
|
||||
legth_string->chars = copy;
|
||||
|
||||
return legth_string;
|
||||
}
|
||||
Reference in new issue
Block a user