shithub: mcfs

Download patch

ref: c25cfff58848750588f1883d4ed74c3fdbb7fa85
parent: 735f5336e5f49b41cd512530d6d8b266de9277c3
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Tue Sep 22 05:35:01 EDT 2020

srt: fix junk written on non-english text

--- a/srt.c
+++ b/srt.c
@@ -36,19 +36,27 @@
 	uchar *s, *o;
 
 	for(i = 0; i < np; i++, p++){
-		for(s = o = p->data, n = 0; n < p->sz; n++){
+		for(s = o = p->data, n = 0; n < p->sz;){
 			if(*s == '\r'){
-				if(n+1 >= p->sz || s[1] != '\n')
-					*s = '\n';
-				else{
+				*o++ = '\n';
+				s++;
+				n++;
+				if(n >= p->sz)
+					break;
+				if(*s == '\n'){
 					s++;
 					n++;
+					continue;
 				}
 			}
 			*o++ = *s++;
+			n++;
 		}
+		if(*o == '\n' && o != p->data)
+			o--;
 		Bprint(out, "%zd\n%P --> %P\n", ++ctx->frid, ts, ts+ctx->blockdur);
-		Bprint(out, "%.*s\n\n", p->sz, (char*)p->data);
+		Bwrite(out, p->data, o - p->data);
+		Bwrite(out, "\n\n", 2);
 	}
 
 	return 0;