]> git.sur5r.net Git - c128-kasse/blob - src/cat.c
make cat.c compile again
[c128-kasse] / src / cat.c
1 #include <stdio.h>
2 #include <conio.h>
3 #include <string.h>
4 #include <dirent.h>
5 #include <stdlib.h>
6
7 #include "general.h"
8
9 #define x2(x) (buffer[x] < 10 ? "0" : ""), buffer[x]
10
11 int main() {
12         char *filename = NULL;
13         FILE *file;
14         unsigned int c;
15         unsigned char i;
16         char buffer[8];
17         char readable[9];
18
19         memset(readable, '\0', 9);
20
21         while (1) {
22                 clrscr();
23                 while (filename == NULL || *filename == '\0') {
24                         printf("Please enter filename (q to exit):\r\n");
25                         filename = get_input();
26                 }
27                 if (*filename == 'q')
28                         return 0;
29                 c = 0;
30                 if ((file = fopen(filename, "r")) == NULL) {
31                         printf("Could not open file\r\n");
32                         continue;
33                 }
34                 clrscr();
35                 while (!feof(file)) {
36                         if (fgets(buffer, 8, file) != buffer) {
37                                 printf("Could not read from file, bailing out\r\n");
38                                 return 1;
39                         }
40                         for (i = 0; i < 8; i++)
41                                 if (    (buffer[i] >= 0x41 && buffer[i] <= 0x5A) ||
42                                         (buffer[i] >= 0xC1 && buffer[i] <= 0xDA) ||
43                                         (buffer[i] >= 0x30 && buffer[i] <= 0x39))
44                                         readable[i] = buffer[i];
45                                 else readable[i] = 0x2E;
46                         printf("%s%x |%s%x %s%x %s%x %s%x %s%x %s%x %s%x %s%x| %s \n",
47                                 (c <= 0xF ? "0" : ""), c,
48                                 x2(0), x2(1), x2(2), x2(3),
49                                 x2(4), x2(5), x2(6), x2(7),
50                                 readable);
51                         c++;
52                         if ((c % 20) == 0) {
53                                 get_input();
54                                 clrscr();
55                         }
56                 }
57                 fclose(file);
58                 filename = NULL;
59                 printf("File finished, press RETURN...\n");
60                 get_input();
61         }
62 }