This commit is contained in:
Nishi 2025-12-28 18:17:59 +09:00
commit 1e25fa45f8
Signed by: nishi
GPG key ID: 27EF69B208EB9343
2 changed files with 48 additions and 0 deletions

View file

@ -1,5 +1,7 @@
#include <MDE/Core/String.h>
#include <stb_ds.h>
char* MDEStringDuplicate(const char* src) {
char* s = malloc(strlen(src) + 1);
@ -34,3 +36,47 @@ char* MDEStringConcatenate4(const char* str1, const char* str2, const char* str3
return r;
}
char** MDEStringToExec(const char* exec, const char* file) {
char** a = NULL;
int i;
char* buf = malloc(1);
buf[0] = 0;
for(i = 0;; i++) {
if(exec[i] == ' ' || exec[i] == 0) {
if(strlen(buf) > 0) arrput(a, buf);
buf = malloc(1);
buf[0] = 0;
if(exec[i] == 0) break;
} else if(exec[i] == '%') {
char c = exec[++i];
if(c == 'f' && file != NULL) {
char* old = buf;
buf = malloc(strlen(old) + strlen(file) + 1);
strcpy(buf, old);
strcpy(buf + strlen(old), file);
free(old);
}
} else {
char* old = buf;
buf = malloc(strlen(old) + 2);
strcpy(buf, old);
buf[strlen(old)] = exec[i];
buf[strlen(old) + 1] = 0;
free(old);
}
}
arrput(a, NULL);
return a;
}

View file

@ -15,6 +15,8 @@ char* MDEStringConcatenate3(const char* str1, const char* str2, const char* str3
char* MDEStringConcatenate4(const char* str1, const char* str2, const char* str3, const char* str4);
char** MDEStringToExec(const char* exec, const char* file);
#ifdef __cplusplus
}
#endif