mirror of
https://github.com/suchmememanyskill/TegraExplorer.git
synced 2024-11-09 21:51:48 +00:00
60 lines
1.4 KiB
C
60 lines
1.4 KiB
C
|
#include "StringClass.h"
|
||
|
#include "compat.h"
|
||
|
#include "intClass.h"
|
||
|
#include <string.h>
|
||
|
|
||
|
char* getStringValue(Variable_t* var) {
|
||
|
if (var->variableType != StringClass)
|
||
|
return NULL;
|
||
|
|
||
|
return var->string.value;
|
||
|
}
|
||
|
|
||
|
// Will NOT copy the string, the pointer is taken as-is
|
||
|
StringClass_t createStringClass(char* in, u8 free) {
|
||
|
StringClass_t a = { 0 };
|
||
|
a.free = free;
|
||
|
a.value = in;
|
||
|
return a;
|
||
|
}
|
||
|
|
||
|
Variable_t newStringVariable(char *x, u8 readOnly, u8 freeOnExit) {
|
||
|
Variable_t var = { .variableType = StringClass, .readOnly = readOnly, .string = createStringClass(x, freeOnExit) };
|
||
|
return var;
|
||
|
}
|
||
|
|
||
|
ClassFunction(printStringVariable) {
|
||
|
if (caller->variableType == StringClass) {
|
||
|
StringClass_t* a = &caller->string;
|
||
|
gfx_printf("%s", a->value);
|
||
|
}
|
||
|
return &emptyClass;
|
||
|
}
|
||
|
|
||
|
ClassFunction(addStringVariables) {
|
||
|
char* s1 = getStringValue(caller);
|
||
|
char* s2 = getStringValue(*args);
|
||
|
|
||
|
char* n = malloc(strlen(s1) + strlen(s2) + 1);
|
||
|
strcpy(n, s1);
|
||
|
strcat(n, s2);
|
||
|
|
||
|
return newStringVariablePtr(n, 0, 1);
|
||
|
}
|
||
|
|
||
|
ClassFunction(getStringLength) {
|
||
|
char* s1 = getStringValue(caller);
|
||
|
return newIntVariablePtr(strlen(s1));
|
||
|
}
|
||
|
|
||
|
u8 oneStringArg[] = { StringClass };
|
||
|
|
||
|
ClassFunctionTableEntry_t stringFunctions[] = {
|
||
|
{"print", printStringVariable, 0, 0},
|
||
|
{"+", addStringVariables, 1, oneStringArg },
|
||
|
{"len", getStringLength, 0, 0},
|
||
|
};
|
||
|
|
||
|
Variable_t getStringMember(Variable_t* var, char* memberName) {
|
||
|
return getGenericFunctionMember(var, memberName, stringFunctions, ARRAY_SIZE(stringFunctions));
|
||
|
}
|