From d8c196b5d4959165d1fcc5f31ff8fb9f95b1900e Mon Sep 17 00:00:00 2001 From: sECuRE Date: Fri, 2 Nov 2007 21:51:13 +0000 Subject: [PATCH] Add hex viewer "cat" git-svn-id: https://shell.noname-ev.de/svn/kasse/c128@78 af93e077-1a23-4f1e-9cbe-9382a9d578f5 --- Makefile | 3 ++ include/cat.h | 0 src/cat.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 include/cat.h create mode 100644 src/cat.c diff --git a/Makefile b/Makefile index f8b9ab7..ba5932a 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,9 @@ itemz: src/config.o src/itemz.o src/general.o src/credit_manager.o # cp /tmp/cc65/lib/c128* . PATH=${PATH}:~/customSoftware/cc65-2.11.0/src/ld65:/tmp/cc65/lib ${CL} -t c128 src/config.o src/itemz.o src/general.o src/credit_manager.o -o itemz +cat: src/general.o src/cat.o + ${CL} -t c128 src/general.o src/cat.o -o cat + all: kasse itemz package: all diff --git a/include/cat.h b/include/cat.h new file mode 100644 index 0000000..e69de29 diff --git a/src/cat.c b/src/cat.c new file mode 100644 index 0000000..fedf007 --- /dev/null +++ b/src/cat.c @@ -0,0 +1,81 @@ +#include +#include +#include +#include +#include + +#include "general.h" + +#define x2(x) (buffer[x] < 10 ? "0" : ""), buffer[x] + +int main() { + char *filename = NULL; + FILE *file; + unsigned int c; + unsigned char i; + char buffer[8]; + char readable[9]; + struct cbm_dirent *dirent; + + memset(readable, '\0', 9); + + while (1) { + clrscr(); + while (filename == NULL || *filename == '\0') { + printf("Please enter filename (q to exit, d for dirlist):\r\n"); + filename = get_input(); + } + if (*filename == 'q') + return 0; + else if (*filename == 'd') { + c = 0; + if (cbm_opendir((BYTE)8, (BYTE)8) != 0) { + cprintf("could not open directory\r\n"); + return 1; + } + while (cbm_readdir((BYTE)8, dirent) == 0) { + printf("file %d: %s\n", c, dirent->name); + get_input(); + } + cbm_closedir((BYTE)8); + + printf("Finished listing directory, press RETURN...\n"); + get_input(); + + filename = NULL; + continue; + } + c = 0; + if ((file = fopen(filename, "r")) == NULL) { + printf("Could not open file\r\n"); + continue; + } + clrscr(); + while (!feof(file)) { + if (fgets(buffer, 8, file) != buffer) { + printf("Could not read from file, bailing out\r\n"); + return 1; + } + for (i = 0; i < 8; i++) + if ( (buffer[i] >= 0x41 && buffer[i] <= 0x5A) || + (buffer[i] >= 0xC1 && buffer[i] <= 0xDA) || + (buffer[i] >= 0x30 && buffer[i] <= 0x39)) + readable[i] = buffer[i]; + else readable[i] = 0x2E; + printf("%s%x |%s%x %s%x %s%x %s%x %s%x %s%x %s%x %s%x| %s \n", + (c <= 0xF ? "0" : ""), c, + x2(0), x2(1), x2(2), x2(3), + x2(4), x2(5), x2(6), x2(7), + readable); + c++; + if ((c % 20) == 0) { + get_input(); + clrscr(); + } + } + fclose(file); + filename = NULL; + printf("File finished, press RETURN...\n"); + get_input(); + } +} -- 2.39.5