]> git.sur5r.net Git - c128-kasse/commitdiff
Add hex viewer "cat"
authorsECuRE <sECuRE@af93e077-1a23-4f1e-9cbe-9382a9d578f5>
Fri, 2 Nov 2007 21:51:13 +0000 (21:51 +0000)
committersECuRE <sECuRE@af93e077-1a23-4f1e-9cbe-9382a9d578f5>
Fri, 2 Nov 2007 21:51:13 +0000 (21:51 +0000)
git-svn-id: https://shell.noname-ev.de/svn/kasse/c128@78 af93e077-1a23-4f1e-9cbe-9382a9d578f5

Makefile
include/cat.h [new file with mode: 0644]
src/cat.c [new file with mode: 0644]

index f8b9ab717bda65eff153e7cc23246470f0389691..ba5932a5a64c5686b5a718fb75659f3214b71388 100644 (file)
--- 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 (file)
index 0000000..e69de29
diff --git a/src/cat.c b/src/cat.c
new file mode 100644 (file)
index 0000000..fedf007
--- /dev/null
+++ b/src/cat.c
@@ -0,0 +1,81 @@
+#include <stdio.h>
+#include <conio.h>
+#include <string.h>
+#include <dirent.h>
+#include <cbm.h>
+
+#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();
+       }
+}