From 8fdb8b090e44e778cef76befb12554ff4a29b766 Mon Sep 17 00:00:00 2001 From: Mid Favila Date: Tue, 6 Sep 2022 18:23:51 -0400 Subject: [PATCH] Add Makefile. Remove empty unfold.c. --- src/Makefile | 21 +++++++++++++++++++++ src/support.h | 12 ++++++------ src/unfold.c | 1 - src/vis.c | 13 ++++++------- 4 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 src/Makefile delete mode 100644 src/unfold.c diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..1ebdd75 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,21 @@ +.POSIX: +.SUFFIX: + +PREFIX = /usr + +BINS = \ + overwrite \ + strcmp \ + vis + +all: $(BINS) + +install: all + install -Dm755 $(BINS) $(DESTDIR)/$(PREFIX)/bin/ + +clean: + rm *.o $(BINS) *~ a.out + +.SUFFIX: +.c.o: + cc -c -o $< $(CFLAGS) $(LDFLAGS) diff --git a/src/support.h b/src/support.h index b655b5e..a00f932 100644 --- a/src/support.h +++ b/src/support.h @@ -44,17 +44,17 @@ void throw(long unsigned int condition, void *info) { switch(condition) { - case UNKNOWN_FAIL: printf("unknown failure\n"); + case UNKNOWN_FAIL: fprintf(stderr, "unknown failure\n"); exit(UNKNOWN_FAIL); - case MALLOC_FAIL: printf("malloc failure\n"); + case MALLOC_FAIL: fprintf(stderr, "malloc failure\n"); exit(MALLOC_FAIL); - case NEEDARG_FAIL: printf("usage: %s\n", (char *) info); + case NEEDARG_FAIL: fprintf(stderr, "usage: %s\n", (char *) info); exit(NEEDARG_FAIL); - case FOPEN_FAIL: printf("failed to open: %s\n", (char *) info); + case FOPEN_FAIL: fprintf(stderr, "failed to open: %s\n", (char *) info); exit(FOPEN_FAIL); - case WRITE_FAIL: printf("failed to write: %s\n", (char *) info); + case WRITE_FAIL: fprintf(stderr, "failed to write: %s\n", (char *) info); exit(WRITE_FAIL); - default: printf("You shouldn't be seeing this.\nSomething is very wrong.\n"); + default: fprintf(stderr, "You shouldn't be seeing this.\nSomething is very wrong.\n"); exit(-256); } } diff --git a/src/unfold.c b/src/unfold.c deleted file mode 100644 index 792d600..0000000 --- a/src/unfold.c +++ /dev/null @@ -1 +0,0 @@ -# diff --git a/src/vis.c b/src/vis.c index bba16d3..d49b00a 100644 --- a/src/vis.c +++ b/src/vis.c @@ -8,19 +8,18 @@ int main(int argc, char **argv) { - int i, c; - FILE *fp; - i = c = 0; + int c; + c = 0; - for(;(c = getchar()) != EOF; i++) + for(;(c = getchar()) != EOF;) { - if(isascii(c) && (c != ' ' && c != '\n' && c != '\t')) + if(isascii(c) && !(c == ' ' || c == '\n' || c == '\t')) { - printf("%c", c); + putc(c, stdout); } else { - printf("%.3o", c); + fprintf(stdout, "%.3o", c); } }