shithub: tinygl

Download patch

ref: 5627ff136277c6bd7e331d6b141a45e56f9b052b
parent: dca221c7ace3880930814b1847d14d4efa5ab1a9
author: gek169 <gek169>
date: Wed May 12 10:39:07 EDT 2021

Automatic commit.

--- a/include-demo/stringutil.h
+++ b/include-demo/stringutil.h
@@ -79,14 +79,14 @@
 
 static unsigned int strprefix(const char *pre, const char *str)
 {
-    unsigned long lenpre = strlen(pre),
-           lenstr = strlen(str);
-    return lenstr < lenpre ? 0 : memcmp(pre, str, lenpre) == 0;
+		unsigned long lenpre = strlen(pre),
+					 lenstr = strlen(str);
+		return lenstr < lenpre ? 0 : memcmp(pre, str, lenpre) == 0;
 }
 
 static unsigned int streq(const char *pre, const char *str)
 {
-    return strcmp(pre, str) == 0;
+		return strcmp(pre, str) == 0;
 }
 
 static long strfind(const char* text, const char* subtext){
@@ -95,7 +95,7 @@
 	long st = strlen(subtext);
 	for(;text[ti] != '\0';ti++){
 		if(text[ti] == subtext[si]) {
-			si++; 
+			si++;
 			if(subtext[si] == '\0') return (ti - st)+1;
 		}else{
 			if(subtext[si] == '\0') return (ti - st)+1;
@@ -116,17 +116,20 @@
 		if(c == terminator)break;
 		buf[i] = c;
 	}
-	buf[buflen-1] = '\0'; 
+	buf[buflen-1] = '\0';
 	return i;
 }
 
 
+
+
+
 static char* read_until_terminator_alloced(FILE* f, unsigned long* lenout, char terminator, unsigned long initsize){
 	char c;
 	char* buf;
 	unsigned long bcap = initsize;
 	char* bufold;
-	unsigned long blen = 0; 
+	unsigned long blen = 0;
 	buf = STRUTIL_ALLOC(initsize);
 	if(!buf) return NULL;
 	while(1){
@@ -142,7 +145,7 @@
 			}
 		buf[blen++] = c;
 	}
-	buf[blen] = '\0'; 
+	buf[blen] = '\0';
 	*lenout = blen;
 	return buf;
 }
@@ -172,7 +175,7 @@
 static char* strencodealloc(const char* inbuf, const char** tokens, unsigned long ntokens, char esc, char tokmark){
 	unsigned long lenin;
 	char c; unsigned long i = 0; unsigned long j;
-	char c_str[512]; 
+	char c_str[512];
 	char* out = NULL;
 
 	lenin = strlen(inbuf);
@@ -182,21 +185,21 @@
 	c_str[0] = 0;
 	c_str[1] = 0;
 	c_str[511] = 0;
-	
+
 	for(j = 0; j < ntokens; j++){
 		out = strcataf1(out, tokens[2*j]);
-		
+
 		sprintf(c_str, "%lu", (unsigned long)strlen(tokens[2*j+1]));
 		out = strcataf1(out, c_str);
 		c_str[0] = tokmark;
 		c_str[1] = 0;
 		out = strcataf1(out, c_str);
-		out = strcataf1(out, tokens[2*j+1]);	
+		out = strcataf1(out, tokens[2*j+1]);
 	}
 	c_str[0] = esc;
 	c_str[1] = 0;
 	out = strcataf1(out, c_str);
-	
+
 	for(i=0; i<lenin; i++){ unsigned long t;
 		for(t = 0; t < ntokens; t++) /*t- the token we are processing.*/
 			if(strprefix(tokens[t*2+1], inbuf+i)){ /*Matched at least one*/
@@ -209,7 +212,7 @@
 						break; /*The number of these things is limited.*/
 				}
 				/*We know what token and how many, write it to out*/
-				
+
 				c_str[0] = tokmark;
 				c_str[1] = 0;
 				out = strcataf1(out, c_str);
@@ -239,43 +242,43 @@
 static char* strdecodealloc(char* inbuf){
 	unsigned long lenin, ntokens;
 	char* out;char** tokens = NULL; char esc; char tokmark; long doescape;
-	char c; unsigned long vv,l,i = 2; 
+	char c; unsigned long vv,l,i = 2;
 	char c_str[2] = {0,0};
-	esc = inbuf[0]; 
-	tokmark = inbuf[1]; 
-	
+	esc = inbuf[0];
+	tokmark = inbuf[1];
+
 	lenin = strlen(inbuf);
-	
-	
+
+
 	out = strcatalloc("","");
-	
-	
-	
-	
+
+
+
+
 	ntokens = 0;
 		if(lenin < 3) {
-	
+
 		return NULL;
 	}
 
-	
+
 	{if(i <= lenin) c = inbuf[i++]; else {goto end;}}; /*has to occur before the loop.*/
 	while(c != esc){	ntokens++;
-		tokens = STRUTIL_REALLOC(tokens, ntokens * 2 * sizeof(char*)); 
-		
-		
+		tokens = STRUTIL_REALLOC(tokens, ntokens * 2 * sizeof(char*));
+
+
 		tokens[(ntokens-1)*2] = strcatalloc("","");
 		tokens[(ntokens-1)*2+1] = strcatalloc("","");
-		
-		
-		if(!isalpha(c)) goto end;	
+
+
+		if(!isalpha(c)) goto end;
 		while(isalpha(c)){
 			c_str[0] = c;
 			tokens[(ntokens-1)*2] = strcatallocf1(tokens[(ntokens-1)*2], c_str);
 			{if(i <= lenin) c = inbuf[i++]; else {goto end;}};
 		}
-	
-	
+
+
 		l = 0;
 		if(!isdigit(c)) goto end;
 		while(isdigit(c) && c!=tokmark){
@@ -284,19 +287,19 @@
 			l += atoi(c_str);
 			{if(i <= lenin) c = inbuf[i++]; else {goto end;}};
 		}
-	
-	
-	
+
+
+
 		for(vv = 0; vv < l; vv++){
 			{if(i <= lenin) c = inbuf[i++]; else {goto end;}};
 			c_str[0] = c;
-			tokens[(ntokens-1)*2+1] = strcatallocf1(tokens[(ntokens-1)*2+1], c_str);	
+			tokens[(ntokens-1)*2+1] = strcatallocf1(tokens[(ntokens-1)*2+1], c_str);
 		}
 		{if(i <= lenin) c = inbuf[i++]; else {goto end;}};
-	
+
 	}
-	
-	
+
+
 	{if(i <= lenin) c = inbuf[i++]; else {goto end;}};
 	doescape = 0;
 	while(i<=lenin){
@@ -316,7 +319,7 @@
 				}
 			else {l=1;}
 			i--;
-			
+
 			for(t = 0; t < ntokens; t++)
 				if(strprefix(tokens[t*2], inbuf+i)){ unsigned long q;
 					for(q = 0; q < l; q++)
@@ -324,7 +327,7 @@
 					i+=strlen(tokens[t*2]);
 					break; /*break out of the for.*/
 				}
-			
+
 			if(i<=lenin) {if(i <= lenin) c = inbuf[i++]; else {goto end;}};
 			continue;
 		}else{
@@ -342,6 +345,52 @@
 	}
 
 	return out;
+}
+
+
+
+static char* str_repl_alloc(char* text, char* subtext, char* replacement){
+	long bruh; char* result = NULL;
+	bruh = strfind(text, subtext);
+	if(bruh == -1) return (strcatalloc("", text)); /*This is already proper.*/
+	result = str_null_terminated_alloc(text, bruh);
+	result = strcatallocf1(result, replacement);
+	result = strcatallocf1(result, text+bruh+strlen(subtext));
+	return result;
+}
+
+static char* str_repl_allocf(char* text, char* subtext, char* replacement){
+	char * result = str_repl_alloc(text, subtext, replacement);
+	free(text);
+	return result;
+}
+
+typedef struct strll{
+	char* text;
+	unsigned long identification;
+	struct strll* right;
+	struct strll* child;
+	struct strll* left;
+}strll;
+
+static strll tokenize(char* alloced_text, const char* token){
+	strll result = {0}; strll* current;
+	long current_token_location;
+	long len_token;
+	current = &result;
+	len_token = strlen(token);
+	current_token_location = strfind(alloced_text, token);
+	while(current_token_location > -1){
+		char* temp = strcatalloc(alloced_text+ current_token_location + len_token, "");
+		current->text = str_null_terminated_alloc(alloced_text,current_token_location);
+		printf("TOKEN FOUND: '%s'", current->text);
+		free(alloced_text);
+		alloced_text = temp;
+		current_token_location = strfind(alloced_text, token);
+		current->right = malloc(sizeof(strll));
+		current = current->right;
+	}
+	return result;
 }
 
 #endif