shithub: riscv

Download patch

ref: 87fa1a78e323cd68189519e3413403f4423491a4
parent: 1be74e0b703a569fee0129b0560f4e5b92da7f5b
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Nov 29 11:53:01 EST 2022

iconv: copy extra data verbatim to allow font conversion/compression

--- a/sys/man/1/crop
+++ b/sys/man/1/crop
@@ -114,8 +114,11 @@
 .I Iconv
 changes the format of pixels in the image
 .I file
-(default standard input) and writes the resulting image to standard output.
-Pixels in the image are converted according to the channel descriptor
+(default standard input) and writes the resulting image to standard
+output.  Any extra data following the source image is copied verbatim,
+which allows converting fonts without losing subfont header and
+character information.  Pixels in the image are converted according to
+the channel descriptor
 .IR chandesc ,
 (see
 .IR image (6)).
--- a/sys/src/cmd/iconv.c
+++ b/sys/src/cmd/iconv.c
@@ -40,9 +40,10 @@
 main(int argc, char *argv[])
 {
 	char *tostr, *file;
-	int fd, uncompressed;
+	int fd, uncompressed, r;
 	ulong tochan;
 	Memimage *m, *n;
+	uchar extra[8192];
 
 	tostr = nil;
 	uncompressed = 0;
@@ -60,24 +61,20 @@
 	memimageinit();
 
 	file = "<stdin>";
-	m = nil;
-
+	fd = 0;
 	switch(argc){
 	case 0:
-		m = readmemimage(0);
 		break;
 	case 1:
-		file = argv[0];
-		fd = open(file, OREAD);
+		fd = open(file = argv[0], OREAD);
 		if(fd < 0)
 			sysfatal("can't open %s: %r", file);
-		m = readmemimage(fd);
-		close(fd);
 		break;
 	default:
 		usage();
 	}
 
+	m = readmemimage(fd);
 	if(m == nil)
 		sysfatal("can't read %s: %r", file);
 
@@ -98,5 +95,15 @@
 		writeuncompressed(1, n);
 	else
 		writememimage(1, n);
+
+	for(;;){
+		if((r = read(fd, extra, sizeof(extra))) < 0)
+			sysfatal("read failed: %r");
+		if(r == 0)
+			break;
+		if(write(1, extra, r) != r)
+			sysfatal("write failed: %r");
+	}
+
 	exits(nil);
 }