diff --git a/scat/GNUmakefile b/scat/GNUmakefile new file mode 100644 index 0000000..5010a19 --- /dev/null +++ b/scat/GNUmakefile @@ -0,0 +1,16 @@ +include GNUmakevars +include GNUmakerules + +all: scat + +scat: scat.o +scat.o: scat.c scat.h +scat.h: scat.en.msg + gencat -H scat.h scat.en.cat scat.en.msg + +%.cat: %.msg + gencat $@ $^ + +clean: + rm -f *.cat *.o scat core +install: $(BINDIR)/time_t diff --git a/scat/scat.c b/scat/scat.c new file mode 100644 index 0000000..93e2bab --- /dev/null +++ b/scat/scat.c @@ -0,0 +1,86 @@ +#include +#include +#include +#include + +#include +#include + +#include "scat.h" + +char *cmnd; +nl_catd catalog; + +void usage(void) { + fprintf(stderr, + catgets(catalog, MSG_Set, MSG_USAGE, + "Usage: %s [file ...]\n"), + cmnd); + exit(1); +} + + +void do_safecat(const char *filename) { + FILE *fp; + int c; + + + if (strcmp(filename, "-") == 0) { + fp = stdin; + } else { + if ((fp = fopen(filename, "r")) == NULL) { + fprintf(stderr, + catgets(catalog, MSG_Set, MSG_OPEN, + "%s: cannot open `%s' for reading: %s\n"), + cmnd, filename); + exit(1); + } + } + while ((c = getc(fp)) != EOF) { + if (isprint(c) || isspace(c)) { + if (putchar(c) == EOF) { + fprintf(stderr, + catgets(catalog, MSG_Set, MSG_WRITE, + "%s: cannot write stdout: %s\n"), + cmnd, filename); + exit(1); + } + } else { + if (printf("\\x%02X", c) == EOF) { + fprintf(stderr, + catgets(catalog, MSG_Set, MSG_WRITE, + "%s: cannot write stdout: %s\n"), + cmnd, filename); + exit(1); + } + } + } + if (ferror(fp)) { + fprintf(stderr, + catgets(catalog, MSG_Set, MSG_READ, + "%s: cannot read from `%s': %s\n"), + cmnd, filename); + exit(1); + } + if (strcmp(filename, "-") == 0) { + } else { + fclose(fp); + } + +} + + +int main(int argc, char **argv) { + setlocale(LC_ALL, ""); + + catalog = catopen("scat", 0); + if (argc == 1) { + do_safecat("-"); + } else { + int i; + for (i = 1; i < argc; i++) { + do_safecat(argv[i]); + } + } + return 0; +} diff --git a/scat/scat.en.msg b/scat/scat.en.msg new file mode 100644 index 0000000..d774299 --- /dev/null +++ b/scat/scat.en.msg @@ -0,0 +1,5 @@ +$set MSG_ +USAGE Usage: %s [files]\n +OPEN %s: cannot open `%s' for reading: %s\n +WRITE %s: cannot write to stdout: %s\n +READ %s: cannot read from `%s': %s\n