fix: isprint => canprint

add a canprint() func that return true iif
char is ascii (< 0x80) and not a control char
(> 0x1F), as isprint() seems to be different
under Linux and Windows
This commit is contained in:
Stéphane Lesimple
2020-08-25 13:03:05 +02:00
parent 5ab5f9b0cb
commit 5553ed332f
9 changed files with 65 additions and 18 deletions

View File

@@ -747,8 +747,8 @@ void HexDump(unsigned char *buf, int len, int step)
for(j=0; j<step; j++)
{ if(i+j >= len) break;
if((j&0x07) == 0x07)
PrintLog("%c ", isprint(buf[i+j]) ? buf[i+j] : '.');
else PrintLog("%c", isprint(buf[i+j]) ? buf[i+j] : '.');
PrintLog("%c ", canprint(buf[i+j]) ? buf[i+j] : '.');
else PrintLog("%c", canprint(buf[i+j]) ? buf[i+j] : '.');
}
PrintLog("\n");

View File

@@ -1089,6 +1089,7 @@ void CallMethodDestructors(void);
*** misc.c
***/
int canprint(char);
char* sgettext(char*);
char* sgettext_utf8(char*);

View File

@@ -36,6 +36,34 @@
* Also, individual behaviour may deviate from standard functions.
*/
#ifdef SYS_MINGW
#include <windows.h>
#define stat _stati64
#define lseek _lseeki64
/* The original windows ftruncate has off_size (32bit) */
int large_ftruncate(int fd, gint64 size)
{ gint32 handle;
if((handle=_get_osfhandle(fd)) == -1)
return -1;
if(_lseeki64(fd, size, SEEK_SET) == -1)
return -1;
if(SetEndOfFile((HANDLE)handle) == 0)
return -1;
return 0;
}
#else
#define large_ftruncate ftruncate
#endif /* SYS_MINGW */
/*
* convert special chars in file names to correct OS encoding
*/
@@ -279,7 +307,7 @@ int LargeClose(LargeFile *lf)
int LargeTruncate(LargeFile *lf, off_t length)
{ int result;
result = (ftruncate(lf->fileHandle, length) == 0);
result = (large_ftruncate(lf->fileHandle, length) == 0);
if(result)
lf->size = length;
@@ -319,6 +347,19 @@ FILE *portable_fopen(char *path, char *modes)
return file;
}
#ifdef SYS_MINGW
int portable_mkdir(char *path)
{ int status;
char *cp_path;
cp_path = os_path(path);
status = mkdir(cp_path);
g_free(cp_path);
return status;
}
#endif
/***
*** Convenience functions
***/

5
misc.c
View File

@@ -22,6 +22,11 @@
#include "dvdisaster.h"
int canprint(char c)
{
return ((isascii(c) && !iscntrl(c)) ? 1 : 0);
}
/***
*** gettext() convenience
***/

View File

@@ -623,7 +623,7 @@ static void render_sector(raw_editor_context *rec)
gdk_gc_set_rgb_fg_color(Closure->drawGC,Closure->foreground);
sprintf(byte, "%c", isprint(buf[idx]) ? buf[idx] : '.');
sprintf(byte, "%c", canprint(buf[idx]) ? buf[idx] : '.');
idx++;
SetText(rec->layout, byte, &w, &h);
gdk_draw_layout(d, Closure->drawGC, x, y, rec->layout);

View File

@@ -726,8 +726,8 @@ void RS01Fix(Image *image)
PrintCLI(_("-> Error located in sector %lld at byte %4d (value %02x '%c', expected %02x '%c')\n"),
block_idx[location], bi,
old, isprint(old) ? old : '.',
new, isprint(new) ? new : '.');
old, canprint(old) ? old : '.',
new, canprint(new) ? new : '.');
}
if(!erasure_map[location])

View File

@@ -734,8 +734,8 @@ void RS02Fix(Image *image)
PrintCLI(msg,
sector, bi,
old, isprint(old) ? old : '.',
new, isprint(new) ? new : '.');
old, canprint(old) ? old : '.',
new, canprint(new) ? new : '.');
}
fc->imgBlock[location][offset] ^= gf_alpha_to[mod_fieldmax(gf_index_of[num1] + gf_index_of[num2] + GF_FIELDMAX - gf_index_of[den])];

View File

@@ -800,8 +800,8 @@ void RS03Fix(Image *image)
PrintCLI(msg,
sector, type, bi,
old, isprint(old) ? old : '.',
new, isprint(new) ? new : '.');
old, canprint(old) ? old : '.',
new, canprint(new) ? new : '.');
}
fc->imgBlock[location][offset] ^= gf_alpha_to[mod_fieldmax(gf_index_of[num1] + gf_index_of[num2] + GF_FIELDMAX - gf_index_of[den])];

View File

@@ -124,7 +124,7 @@ int InquireDevice(DeviceHandle *dh, int probe_only)
if(i>0 && !isspace((int)ibuf[i-1])) /* separate the version string */
ibuf[i++] = ' ';
}
if( isprint(ab->buf[j]) /* eliminate multiple spaces and unprintables */
if( canprint(ab->buf[j]) /* eliminate multiple spaces and unprintables */
&& (!isspace(ab->buf[j]) || (i>0 && !isspace((int)ibuf[i-1]))))
{ vbuf[i] = ab->buf[j];
ibuf[i++] = ab->buf[j];
@@ -724,11 +724,11 @@ static int query_dvd(DeviceHandle *dh, int probe_only)
Verbose("#DVD: physical info contains lead-in data\n");
for(j=0; j<6; j++)
dh->manuID[j] = isprint(buf[0x225+j]) ? buf[0x225+j] : ' ';
dh->manuID[j] = canprint(buf[0x225+j]) ? buf[0x225+j] : ' ';
dh->manuID[6] = ' ';
for(j=0; j<6; j++)
dh->manuID[j+7] = isprint(buf[0x22d+j]) ? buf[0x22d+j] : ' ';
dh->manuID[j+7] = canprint(buf[0x22d+j]) ? buf[0x22d+j] : ' ';
dh->manuID[13] = 0;
for(j=11; j>=0; j--)
@@ -784,7 +784,7 @@ static int query_dvd(DeviceHandle *dh, int probe_only)
Verbose("#DVD: assuming DVD plus; phy_info4/6 now 0x%x 0x%x\n", phy_info4, phy_info6);
for(i=0; i<11; i++)
dh->manuID[i] = isprint(buf[23+i]) ? buf[23+i] : ' ';
dh->manuID[i] = canprint(buf[23+i]) ? buf[23+i] : ' ';
dh->manuID[11] = 0;
for(i=10; i>=0; i--)
@@ -828,11 +828,11 @@ static int query_dvd(DeviceHandle *dh, int probe_only)
Verbose("#DVD: assuming DVD dash\n");
for(i=0; i<6; i++)
dh->manuID[i] = isprint(buf[21+i]) ? buf[21+i] : ' ';
dh->manuID[i] = canprint(buf[21+i]) ? buf[21+i] : ' ';
dh->manuID[6] = ' ';
for(i=0; i<6; i++)
dh->manuID[i+7] = isprint(buf[29+i]) ? buf[29+i] : ' ';
dh->manuID[i+7] = canprint(buf[29+i]) ? buf[29+i] : ' ';
dh->manuID[13] = 0;
for(i=11; i>=0; i--)
@@ -1010,7 +1010,7 @@ static int query_bd(DeviceHandle *dh, int probe_only)
for(i=0,j=-1; i<6; i++) /* Disc Manufacturer ID */
{ char c = buf[4+100+i];
if(isprint(c))
if(canprint(c))
{ dh->manuID[i] = c; j=i;
}
else dh->manuID[i] = ' ';
@@ -1019,7 +1019,7 @@ static int query_bd(DeviceHandle *dh, int probe_only)
for(i=0; i<3; i++) /* Media type ID */
{ char c = buf[4+106+i];
dh->manuID[++j] = isprint(c) ? c : ' ';
dh->manuID[++j] = canprint(c) ? c : ' ';
}
if(dh->manuID[j] == ',')
dh->manuID[j]=0;