Module Name:    othersrc
Committed By:   agc
Date:           Thu May 12 05:42:18 UTC 2011

Modified Files:
        othersrc/external/bsd/circa: tst
        othersrc/external/bsd/circa/dist: circa.c main.c

Log Message:
catch up in dynamic buffer size changes in driver program.

add some tests for larger files, one with large sector sizes


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.1 -r1.2 othersrc/external/bsd/circa/tst
cvs rdiff -u -r1.2 -r1.3 othersrc/external/bsd/circa/dist/circa.c
cvs rdiff -u -r1.3 -r1.4 othersrc/external/bsd/circa/dist/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: othersrc/external/bsd/circa/tst
diff -u othersrc/external/bsd/circa/tst:1.1.1.1 othersrc/external/bsd/circa/tst:1.2
--- othersrc/external/bsd/circa/tst:1.1.1.1	Sat May  7 02:31:24 2011
+++ othersrc/external/bsd/circa/tst	Thu May 12 05:42:18 2011
@@ -47,6 +47,16 @@
 ${r} -d -o h3 h2
 diff dist/circa.h h3
 rm -f h2 h3
+echo "5. big file"
+ls -l /usr/share/dict/words
+${r} -o big2 /usr/share/dict/words
+${r} -d -o big3 big2
+diff /usr/share/dict/words big3
+rm -f big2 big3
+echo "6. big file, large sector size"
+${r} -o big2 -s 25600 /usr/share/dict/words
+${r} -d -o big3 big2
+rm -f big2 big3
 echo "All tests completed"
 
 exit 0

Index: othersrc/external/bsd/circa/dist/circa.c
diff -u othersrc/external/bsd/circa/dist/circa.c:1.2 othersrc/external/bsd/circa/dist/circa.c:1.3
--- othersrc/external/bsd/circa/dist/circa.c:1.2	Thu May 12 04:11:15 2011
+++ othersrc/external/bsd/circa/dist/circa.c	Thu May 12 05:42:18 2011
@@ -120,10 +120,6 @@
 	int		f;
 	int		b;
 
-	if (insize > CIRCA_DATA_SIZE) {
-		(void) fprintf(stderr, "encode: no init\n");
-		return 0;
-	}
 	if (!circa->init) {
 		circa_init(circa, outsize);
 	}
@@ -131,7 +127,7 @@
 	(void) memcpy(circa->c3data, &isize, sizeof(isize));
 	(void) memcpy(&circa->c3data[sizeof(isize)], inp, insize);
 	(void) memset(circa->c1data, 0x0, sizeof(circa->c1data));
-	/* C3 even nybbles delayed 2 frames */
+	/* C3 even 4 bytes delayed 2 frames */
 	for (f = 0 ; f < (int)circa->maxframes ; f++) {
 		for (b = 0 ; b < C3_FRAME_SIZE ; b++) {
 			if (((b / 4) & 1) == 0) {
@@ -236,7 +232,7 @@
 		PERMUTE5(circa->c3data, f, C3OFF, 4, 12, 14, 20, 16);
 		PERMUTE5(circa->c3data, f, C3OFF, 5, 13, 15, 21, 17);
 	}
-	/* C3 even nybbles delayed 2 frames */
+	/* C3 even 4 bytes delayed 2 frames */
 	for (f = 0 ; f < (int)circa->maxframes ; f++) {
 		for (b = 0 ; b < C3_FRAME_SIZE ; b++) {
 			circa->c1data[C3OFF(f, b)] = (((b / 4) & 1) == 0) ?

Index: othersrc/external/bsd/circa/dist/main.c
diff -u othersrc/external/bsd/circa/dist/main.c:1.3 othersrc/external/bsd/circa/dist/main.c:1.4
--- othersrc/external/bsd/circa/dist/main.c:1.3	Thu May 12 04:12:54 2011
+++ othersrc/external/bsd/circa/dist/main.c	Thu May 12 05:42:18 2011
@@ -41,8 +41,8 @@
 static int
 do_circa(circa_t *circa, size_t sectorsize, int encoding, char *in, char *fout)
 {
-	uint8_t	 buf[CIRCA_SECTOR_SIZE];
-	uint8_t	 out[CIRCA_SECTOR_SIZE];
+	uint8_t	*buf;
+	uint8_t	*out;
 	size_t	 readsize;
 	FILE	*fpout;
 	FILE	*fpin;
@@ -72,7 +72,11 @@
 			return 0;
 		}
 		readsize = circa->datasize;
-		outcc = circa_put_header(circa, out, sizeof(out));
+		if ((buf = calloc(1, sectorsize)) == NULL || (out = calloc(1, sectorsize)) == NULL) {
+			(void) fprintf(stderr, "can't allocate sectorsize buffers\n");
+			return 0;
+		}
+		outcc = circa_put_header(circa, out, sectorsize);
 		if (write(fileno(fpout), out, outcc) != outcc) {
 			(void) fprintf(stderr, "short write\n");
 			return 0;
@@ -83,17 +87,22 @@
 			(void) fprintf(stderr, "short read\n");
 			return 0;
 		}
-		circa_get_header(circa, &circa->header, sizeof(circa->header));
-		if (!circa_init(circa, readsize = circa->header.sectorsize)) {
+		if (circa_get_header(circa, &circa->header, sizeof(circa->header)) != sizeof(circa->header) ||
+		    !circa_init(circa, readsize = sectorsize = circa->header.sectorsize)) {
 			(void) fprintf(stderr, "bad sectorsize %zu\n", sectorsize);
 			return 0;
 		}
+		if ((buf = calloc(1, sectorsize)) == NULL ||
+		    (out = calloc(1, sectorsize)) == NULL) {
+			(void) fprintf(stderr, "can't allocate sectorsize buffers\n");
+			return 0;
+		}
 	}
 	for (ok = 1 ; ok && (cc = read(fileno(fpin), buf, readsize)) > 0 ; ) {
 		if (encoding) {
-			outcc = circa_encode(circa, buf, cc, out, sizeof(out));
+			outcc = circa_encode(circa, buf, cc, out, sectorsize);
 		} else {
-			outcc = circa_decode(circa, buf, cc, out, sizeof(out));
+			outcc = circa_decode(circa, buf, cc, out, sectorsize);
 		}
 		if (write(fileno(fpout), out, outcc) != outcc) {
 			(void) fprintf(stderr, "short write (%d)\n", outcc);
@@ -106,6 +115,8 @@
 	if (fpout != stdout) {
 		fclose(fpout);
 	}
+	free(out);
+	free(buf);
 	return ok;
 }
 

Reply via email to