mirror of
https://github.com/koenkooi/foo2zjs.git
synced 2026-01-22 11:44:49 +08:00
Update xqxdecode.c
Xqxdecode has a fundamental flaw that means it never actually ran properly. It uses `fgets()` to read the header lines, under the assumption that they are newline-terminated. However, the most important of them all, the one preceding the ',XQX' magic number is actually null-terminated, so the program never ever correctly identifies the magic number and gets completely lost in the file. By adding our own `fgetsn()` that looks for both newline and null makes it work.
This commit is contained in:
parent
e04290de6b
commit
36442ffa71
23
xqxdecode.c
23
xqxdecode.c
@ -142,6 +142,27 @@ proff(int curOff)
|
|||||||
printf("%6x: ", curOff);
|
printf("%6x: ", curOff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char*
|
||||||
|
fgetsn(char* str, int n, FILE* stream)
|
||||||
|
{
|
||||||
|
register int c;
|
||||||
|
register char ch;
|
||||||
|
register char* cs;
|
||||||
|
cs = str;
|
||||||
|
|
||||||
|
while (--n > 0 && (c = getc(stream)) != EOF) {
|
||||||
|
ch = (*cs++ = c);
|
||||||
|
if (ch == '\n') {
|
||||||
|
*cs = '\0';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (ch == '\0')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (c == EOF && cs == str) ? NULL : str;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
decode(FILE *fp)
|
decode(FILE *fp)
|
||||||
{
|
{
|
||||||
@ -178,7 +199,7 @@ decode(FILE *fp)
|
|||||||
{
|
{
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
while (fgets(buf, sizeof(buf), fp))
|
while (fgetsn(buf, sizeof(buf), fp))
|
||||||
{
|
{
|
||||||
proff(curOff);
|
proff(curOff);
|
||||||
if (buf[0] == '\033')
|
if (buf[0] == '\033')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user