shithub: scc

Download patch

ref: bfbefb4496a9c40b86a329e8ed8071f6ee50ae4e
parent: 1f44228008dcc08e27ab84b1da11867d2c9bf3ae
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Aug 6 17:29:29 EDT 2018

[lib/scc] Add support for ' in pack functions

--- a/lib/scc/bpack.c
+++ b/lib/scc/bpack.c
@@ -5,10 +5,12 @@
 int
 bpack(unsigned char *dst, char *fmt, ...)
 {
-	unsigned char *bp;
+	unsigned char *bp, *cp;
 	unsigned s;
 	unsigned long l;
 	unsigned long long q;
+	size_t n;
+	int d;
 	va_list va;
 
 	bp = dst;
@@ -15,6 +17,15 @@
 	va_start(va, fmt);
 	while (*fmt) {
 		switch (*fmt++) {
+		case '\'':
+			for (n = 0; isdigit(*fmt); n += d) {
+				n *= 10;
+				d = *fmt++ - '0';
+			}
+			cp = va_arg(va, char *);
+			while (n--)
+				*bp++ = *cp++;
+			break;
 		case 'c':
 			*bp++ = va_arg(va, unsigned);
 			break;
--- a/lib/scc/lpack.c
+++ b/lib/scc/lpack.c
@@ -5,10 +5,12 @@
 int
 lpack(unsigned char *dst, char *fmt, ...)
 {
-	unsigned char *bp;
+	unsigned char *bp, *cp;
 	unsigned s;
 	unsigned long l;
 	unsigned long long q;
+	size_t n;
+	int d;
 	va_list va;
 
 	bp = dst;
@@ -15,6 +17,15 @@
 	va_start(va, fmt);
 	while (*fmt) {
 		switch (*fmt++) {
+		case '\'':
+			for (n = 0; isdigit(*fmt); n += d) {
+				n *= 10;
+				d = *fmt++ - '0';
+			}
+			cp = va_arg(va, char *);
+			while (n--)
+				*bp++ = *cp++;
+			break;
 		case 'c':
 			*bp++ = va_arg(va, unsigned);
 			break;