Skip to content

Commit

Permalink
fix: properly handling of cr/lf in dftxt2tap utility
Browse files Browse the repository at this point in the history
  • Loading branch information
iss committed Jan 23, 2021
1 parent 6f28a7c commit e109033
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Binary file modified Oric-DFLAT/emulator/dftxt2tap
Binary file not shown.
20 changes: 14 additions & 6 deletions Oric-DFLAT/emulator/util/dftxt2tap/dftxt2tap/dftxt2tap.cpp
Expand Up @@ -8,6 +8,7 @@
#if defined(__linux__) || defined(__APPLE__)
#include <assert.h>
#include <errno.h>
#define pathchr '/'
#define strcpy_s strcpy
#define strcat_s strcat
#define errno_t int
Expand Down Expand Up @@ -47,6 +48,8 @@ char* _itoa_s(int value, char* str, int radix) {
c = *p, *p = *q, *q = c;
return str;
}
#else
#define pathchr '\\'
#endif

FILE *in, *out;
Expand Down Expand Up @@ -74,8 +77,8 @@ int init(int argc, char *argv[])
}

/* Get filename portion of destination, must be <16 chars */
for (i = strlen(argv[argc-1]); (i > 1) && (argv[argc-1][i] != '\\'); i--);
if (argv[argc-1][i] == '\\') i++;
for (i = strlen(argv[argc-1]); (i > 1) && (argv[argc-1][i] != pathchr); i--);
if (argv[argc-1][i] == pathchr) i++;
strcpy_s(fname, &argv[argc-1][i]);
if (strlen(fname) > 15) {
printf("Destination filename too long.\n");
Expand All @@ -99,11 +102,16 @@ void gettxtline()
char lineStr[10];
char temp[250];

do {
while (i<sizeof(line)-2) {
valin = fgetc(in);
if (valin == 0xff) valin = 0x0d;
if (valin != 0x0a) line[i++] = valin;
} while (valin != 0x0d);
if (feof(in)) break;
if (valin == 0x0a || valin == 0x0d) {
if (i == 0) continue;
else break;
}
line[i++] = valin;
}
if (i > 0) line[i++] = 0x0d;
line[i] = 0;
if ((i > 1) && (lineNo!=0)) {
if (atoi(line) == 0) {
Expand Down

0 comments on commit e109033

Please sign in to comment.