[mw-devel] [Git][milliways/mw][master] defer outputting a colour sequence

Alice Mitchell alice at sucs.org
Fri Mar 29 14:51:41 GMT 2019


Alice Mitchell pushed to branch master at milliways / mw


Commits:
fa8bd1ff by Alice Mitchell at 2019-03-29T14:50:15Z
defer outputting a colour sequence
If we dont alter the output string until we have a valid escape sequence
then we dont accidentally forget the current acting colour when bad
sequences are found

- - - - -


1 changed file:

- src/client/colour.c


Changes:

=====================================
src/client/colour.c
=====================================
@@ -51,9 +51,11 @@ static int hex_decode(const char *input, int len)
 }
 
 /* return colour code sequence */
-int colour(const char *input, char *output, int outlen)
+int colour(const char *input, char *result, int reslen)
 {
 	int consume = 0;
+	char output[1024];
+	int outlen = sizeof(output);
 
 	if (outlen) output[0] = '\0';
 	/* original colour mode */
@@ -81,10 +83,10 @@ int colour(const char *input, char *output, int outlen)
 
 			if (i>=0 && i < COLOUR_LIMIT) {
 				if (colour_chart[i] != NULL)
-					copy_in(output, outlen, colour_chart[i]);
+					copy_in(result, reslen, colour_chart[i]);
 				else
 				if (colour_chart[0] != NULL)
-					copy_in(output, outlen, colour_chart[0]);
+					copy_in(result, reslen, colour_chart[0]);
 			}
 			return consume;
 		}
@@ -100,6 +102,7 @@ int colour(const char *input, char *output, int outlen)
 			output[i++] = '0';
 			output[i++] = 'm';
 			output[i] = '\0';
+			copy_in(result, reslen, output);
 			return(consume);
 		}
 
@@ -146,6 +149,7 @@ int colour(const char *input, char *output, int outlen)
 
 		output[i++] = 'm';
 		output[i] = '\0';
+		copy_in(result, reslen, output);
 	}
 	if (*input == '&') {
 		bool fg_done = false;
@@ -178,18 +182,17 @@ int colour(const char *input, char *output, int outlen)
 				snprintf(&output[outused], outlen-outused, "\033[%d;5;%dm", fg_done?48:38, col);
 				fg_done = true;
 			} else {
-				output[0] = '\0';
 				return 0;
 			}
 			outused = strlen(output);
 		} while(input[consume] == ':');
 
 		if (input[consume] != '&') {
-			output[0] = '\0';
 			return 0;
 		}
 		consume++;
 	}
+	copy_in(result, reslen, output);
 	return(consume);
 }
 



View it on GitLab: https://projects.sucs.org/milliways/mw/commit/fa8bd1ffb7712b557e529563848938065de65528

-- 
View it on GitLab: https://projects.sucs.org/milliways/mw/commit/fa8bd1ffb7712b557e529563848938065de65528
You're receiving this email because of your account on projects.sucs.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/mw-devel/attachments/20190329/1c248879/attachment-0001.html>


More information about the mw-devel mailing list