shithub: nvi

Download patch

ref: 0a8b65bdc3e24922fb611cbc5ac0f590a11189a3
parent: 67f145ccd1617605c4984f5566fbeadfce390101
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Wed Jul 7 05:52:21 EDT 2021

fix youtu.be links

--- a/nvi.c
+++ b/nvi.c
@@ -78,7 +78,7 @@
 		usage();
 	vid = argv[0];
 	if(strncmp(argv[0], "http", 4) == 0){
-		if(strstr(argv[0], "youtu") != nil && (vid = strrchr(argv[0], '=')) != nil)
+		if(strstr(argv[0], "youtu") != nil && (vid = strrpbrk(argv[0], "/=")) != nil)
 			vid++;
 		else
 			fun = peertube;
--- a/nvi.h
+++ b/nvi.h
@@ -43,6 +43,7 @@
 JSON *jfield(JSON *j, int type, ...);
 char *jstrdup(JSON *j, char *name);
 vlong jint(JSON *j, char *name);
+char *strrpbrk(char *s, char *c);
 
 #pragma varargck type "Z" vlong
 int Zfmt(Fmt *f);
--- a/util.c
+++ b/util.c
@@ -203,3 +203,19 @@
 	}
 	return 0;
 }
+
+char*
+strrpbrk(char *s, char *c)
+{
+	char *r, *s0;
+
+	if(*c == 0)
+		return strchr(s, 0);
+	for(r = nil, s0 = s; *c != 0; c++, s = s0){
+		while(s = strchr(s, *c)){
+			r = s++;
+			s0 = s;
+		}
+	}
+	return r;
+}