changeset 467:25199ff67309

build: added a simple cat-like program tha pads each file to a multiple of 80 bytes Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Mon, 11 Apr 2011 23:00:13 -0400
parents 678579f3a83b
children 55668d7e8374
files build/.gitignore build/Makefile build/padcat.c
diffstat 3 files changed, 43 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/build/.gitignore	Mon Apr 11 22:34:24 2011 -0400
+++ b/build/.gitignore	Mon Apr 11 23:00:13 2011 -0400
@@ -1,1 +1,2 @@
 ccw_gen
+padcat
--- a/build/Makefile	Mon Apr 11 22:34:24 2011 -0400
+++ b/build/Makefile	Mon Apr 11 23:00:13 2011 -0400
@@ -1,10 +1,13 @@
 HOSTCC=gcc
 CFLAGS=-Wall -O2 -g
 
-all: ccw_gen
+all: ccw_gen padcat
 
 clean:
-	rm -f ccw_gen
+	rm -f ccw_gen padcat
 
 ccw_gen: ccw_gen.c
 	$(HOSTCC) $(CFLAGS) -o $@ $<
+
+padcat: padcat.c
+	$(HOSTCC) $(CFLAGS) -o $@ $<
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/build/padcat.c	Mon Apr 11 23:00:13 2011 -0400
@@ -0,0 +1,37 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+void cat(char *fn)
+{
+	FILE *f;
+	char buf[80];
+	size_t n;
+
+	f = fopen(fn, "rb");
+	if (!f) {
+		fprintf(stderr, "Could not open file \"%s\". Skipping.\n",
+			fn);
+		return;
+	}
+
+	do {
+		memset(buf, 0, 80);
+		n = fread(buf, 1, 80, f);
+		if (n)
+			assert(fwrite(buf, 1, 80, stdout) == 80);
+	} while(n == 80);
+
+	fclose(f);
+}
+
+int main(int argc, char **argv)
+{
+	int i;
+
+	for(i=1; i<argc; i++)
+		cat(argv[i]);
+
+	return 0;
+}