flashbench: improve pretty-printing and indentation

All pretty-printed output is now 8 characters wide.
Indent the program by four spaces, not tabs, so it
fits better here.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
diff --git a/flashbench.c b/flashbench.c
index cf28826..7b7f402 100644
--- a/flashbench.c
+++ b/flashbench.c
@@ -462,65 +462,57 @@
 	};
 #endif	
 
+#if 1
+	/* show effect of type of access within AU */
 	struct operation program[] = {
-		{O_LEN_POW2, 11, -512},
-		{O_SEQUENCE, 3},
-			{O_DROP},
-				{O_PRINTF},
-				{O_FORMAT},
-				{O_LENGTH},
-			{O_PRINT, .string = " linear write0/write1/writerand/read\n"},
-			{O_OFF_FIXED, .val = 1024 * 4096 * 4}, {O_DROP},
-			{O_SEQUENCE, 10},
-				{O_DROP}, {O_LEN_FIXED, .val = 1024 * 4096},
-					{O_WRITE_RAND},
-				{O_PRINTF}, {O_FORMAT},
-					{O_REDUCE, .aggregate = A_AVERAGE},
-					{O_BPS},
-					{O_OFF_LIN, 8192, -1},
-					{O_WRITE_ZERO},
-				{O_PRINTF}, {O_FORMAT},
-					{O_REDUCE, .aggregate = A_AVERAGE},
-					{O_BPS},
-					{O_OFF_LIN, 8192, -1},
-					{O_WRITE_ONE},
-				{O_PRINTF}, {O_FORMAT},
-					{O_REDUCE, .aggregate = A_AVERAGE},
-					{O_BPS},
-					{O_OFF_LIN, 8192, -1},
-					{O_WRITE_RAND},
-				{O_PRINTF}, {O_FORMAT},
-					{O_REDUCE, .aggregate = A_AVERAGE},
-					{O_BPS},
-					{O_OFF_LIN, 8192, -1},
-					{O_READ},
-				{O_PRINTF}, {O_FORMAT},
-					{O_REDUCE, .aggregate = A_AVERAGE},
-					{O_BPS},
-					{O_OFF_RAND, 8192, -1},
-					{O_WRITE_ZERO},
-				{O_PRINTF}, {O_FORMAT},
-					{O_REDUCE, .aggregate = A_AVERAGE},
-					{O_BPS},
-					{O_OFF_RAND, 8192, -1},
-					{O_WRITE_ONE},
-				{O_PRINTF}, {O_FORMAT},
-					{O_REDUCE, .aggregate = A_AVERAGE},
-					{O_BPS},
-					{O_OFF_RAND, 8192, -1},
-					{O_WRITE_RAND},
-				{O_PRINTF}, {O_FORMAT},
-					{O_REDUCE, .aggregate = A_AVERAGE},
-					{O_BPS},
-					{O_OFF_RAND, 8192, -1},
-					{O_READ},
-				{O_NEWLINE},
-				{O_END},
-			{O_END},
-		{O_END},
+            /* loop through power of two multiple of one sector */
+            {O_LEN_POW2, 11, -512},
+            {O_SEQUENCE, 3},
+                /* print block size */
+                {O_DROP},
+                    {O_PRINTF},
+                    {O_FORMAT},
+                    {O_LENGTH},
+                /* start four units into the device, to skip FAT */
+                {O_OFF_FIXED, .val = 1024 * 4096 * 4}, {O_DROP},
+                    /* print one line of aggregated
+                        per second results */
+                    {O_PRINTF}, {O_FORMAT}, {O_SEQUENCE, 9},
+                        /* write one block to clear state of block,
+                           ignore result */
+                        {O_DROP}, {O_LEN_FIXED, .val = 1024 * 4096},
+                                {O_WRITE_RAND},
+                        /* linear write zeroes */
+                        {O_REDUCE, .aggregate = A_AVERAGE}, {O_BPS},
+                                {O_OFF_LIN, 8192, -1}, {O_WRITE_ZERO},
+                        /* linear write ones */
+                        {O_REDUCE, .aggregate = A_AVERAGE}, {O_BPS},
+                                {O_OFF_LIN, 8192, -1}, {O_WRITE_ONE},
+                        /* linear write 0x5a */
+                        {O_REDUCE, .aggregate = A_AVERAGE}, {O_BPS},
+                                {O_OFF_LIN, 8192, -1}, {O_WRITE_RAND},
+                        /* linear read */
+                        {O_REDUCE, .aggregate = A_AVERAGE}, {O_BPS},
+                                {O_OFF_LIN, 8192, -1}, {O_READ},
+                        /* random write zeroes */
+                        {O_REDUCE, .aggregate = A_AVERAGE}, {O_BPS},
+                                {O_OFF_RAND, 8192, -1}, {O_WRITE_ZERO},
+                        /* random write ones */
+                        {O_REDUCE, .aggregate = A_AVERAGE}, {O_BPS},
+                                {O_OFF_RAND, 8192, -1}, {O_WRITE_ONE},
+                        /* random write 0x5a */
+                        {O_REDUCE, .aggregate = A_AVERAGE}, {O_BPS},
+                                {O_OFF_RAND, 8192, -1}, {O_WRITE_RAND},
+                        /* random read */
+                        {O_REDUCE, .aggregate = A_AVERAGE}, {O_BPS},
+                                {O_OFF_RAND, 8192, -1}, {O_READ},
+                        {O_END},
+                {O_NEWLINE},
+                {O_END},
+            {O_END},
 	};
-
-	call(program, dev, 0, 4096 * 1024, 1);
+	call(program, dev, 0, 4096 * 1024, 0);
+#endif
 
 	return 0;
 }
diff --git a/vm.c b/vm.c
index 02c16ed..348aa91 100644
--- a/vm.c
+++ b/vm.c
@@ -5,6 +5,7 @@
 #include <unistd.h>
 #include <sys/types.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "dev.h"
 #include "vm.h"
@@ -221,28 +222,29 @@
 			out = val;
 		else
 			out = to_res(res_ptr(val), R_STRING);
-		break;
+
+		return out;
 
 	case R_BYTE:
 		if (l < 1024)
-			snprintf(out.s, 8, "%lldB", l);
+			snprintf(out.s, 8, "%0lldB", l);
 		else if (l < 1024 * 1024)
-			snprintf(out.s, 8, "%.3gKiB", l / 1024.0);
+			snprintf(out.s, 8, "%0.3gKiB", l / 1024.0);
 		else if (l < 1024 * 1024 * 1024)
-			snprintf(out.s, 8, "%.3gMiB", l / (1024.0 * 1024.0));
+			snprintf(out.s, 8, "%0.3gMiB", l / (1024.0 * 1024.0));
 		else
-			snprintf(out.s, 8, "%.4gGiB", l / (1024.0 * 1024.0 * 1024.0));
+			snprintf(out.s, 8, "%0.4gGiB", l / (1024.0 * 1024.0 * 1024.0));
 		break;
 
 	case R_BPS:
 		if (l < 1024)
-			snprintf(out.s, 8, "%lldB/s", l);
+			snprintf(out.s, 8, "%0lldB/s", l);
 		else if (l < 1024 * 1024)
-			snprintf(out.s, 8, "%.3gK/s", l / 1024.0);
+			snprintf(out.s, 8, "%.03gK/s", l / 1024.0);
 		else if (l < 1024 * 1024 * 1024)
-			snprintf(out.s, 8, "%.3gM/s", l / (1024.0 * 1024.0));
+			snprintf(out.s, 8, "%.03gM/s", l / (1024.0 * 1024.0));
 		else
-			snprintf(out.s, 8, "%.4gG/s", l / (1024.0 * 1024.0 * 1024.0));
+			snprintf(out.s, 8, "%.04gG/s", l / (1024.0 * 1024.0 * 1024.0));
 		break;
 		
 
@@ -257,9 +259,13 @@
 			snprintf(out.s, 8, "%.4gs", l / 1000000000.0);
 		break;
 	default:
-		out = res_null;
+		return res_null;
 	}
 
+	for (x = strlen(out.s); x<7; x++)
+		out.s[x] = ' ';
+	out.s[7] = '\0';
+
 	return out;
 }