rename bdiff.c to isequal.c, make it handle different line-endings as equal
This commit is contained in:
parent
85e8a6cb9f
commit
1a92368aed
6 changed files with 62 additions and 36 deletions
|
@ -24,7 +24,7 @@ CL65 := $(if $(wildcard ../../bin/cl65*),../../bin/cl65,cl65)
|
|||
|
||||
WORKDIR = ../../testwrk/asm
|
||||
|
||||
DIFF = $(WORKDIR)/bdiff$(EXE)
|
||||
DIFF = $(WORKDIR)/isequal$(EXE)
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -O2
|
||||
|
@ -44,7 +44,7 @@ all: $(OPCODE_BINS) $(CPUDETECT_BINS)
|
|||
$(WORKDIR):
|
||||
$(call MKDIR,$(WORKDIR))
|
||||
|
||||
$(DIFF): ../bdiff.c | $(WORKDIR)
|
||||
$(DIFF): ../isequal.c | $(WORKDIR)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
define OPCODE_template
|
||||
|
|
28
test/bdiff.c
28
test/bdiff.c
|
@ -1,28 +0,0 @@
|
|||
|
||||
// minimal tool to compare two binaries
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *f1, *f2;
|
||||
if (argc < 3) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
f1 = fopen(argv[1], "rb");
|
||||
f2 = fopen(argv[2], "rb");
|
||||
if ((f1 == NULL) || (f2 == NULL)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
for(;;) {
|
||||
if (feof(f1) && feof(f2)) {
|
||||
return EXIT_SUCCESS;
|
||||
} else if (feof(f1) || feof(f2)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (fgetc(f1) != fgetc(f2)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,7 +25,7 @@ DA65 := $(if $(wildcard ../../bin/da65*),../../bin/da65,da65)
|
|||
|
||||
WORKDIR = ../../testwrk/dasm
|
||||
|
||||
DIFF = $(WORKDIR)/bdiff$(EXE)
|
||||
DIFF = $(WORKDIR)/isequal$(EXE)
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -O2
|
||||
|
@ -44,7 +44,7 @@ all: $(BINS)
|
|||
$(WORKDIR):
|
||||
$(call MKDIR,$(WORKDIR))
|
||||
|
||||
$(DIFF): ../bdiff.c | $(WORKDIR)
|
||||
$(DIFF): ../isequal.c | $(WORKDIR)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
define DISASS_template
|
||||
|
|
54
test/isequal.c
Normal file
54
test/isequal.c
Normal file
|
@ -0,0 +1,54 @@
|
|||
|
||||
// minimal tool to compare two text files
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* get the next character from FILE and convert commonly used line-endings all
|
||||
into the same value (0x0a, as used on *nix systems)
|
||||
|
||||
recognized values/pairs:
|
||||
|
||||
0x0a (LF) Linux, macOS
|
||||
0x0d, 0x0a (CR, LF) Windows, MSDOS, OS/2
|
||||
0x0d (CR) classic MacOS
|
||||
*/
|
||||
|
||||
int getnext(FILE *f)
|
||||
{
|
||||
int c = fgetc(f);
|
||||
if (c == 0x0d) {
|
||||
if (!feof(f)) {
|
||||
int n = fgetc(f);
|
||||
if (n != 0x0a) {
|
||||
ungetc(n, f);
|
||||
}
|
||||
clearerr(f); /* clears EOF when we did not push back */
|
||||
}
|
||||
return 0x0a;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *f1, *f2;
|
||||
if (argc < 3) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
f1 = fopen(argv[1], "rb");
|
||||
f2 = fopen(argv[2], "rb");
|
||||
if ((f1 == NULL) || (f2 == NULL)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
for(;;) {
|
||||
if (feof(f1) && feof(f2)) {
|
||||
return EXIT_SUCCESS;
|
||||
} else if (feof(f1) || feof(f2)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (getnext(f1) != getnext(f2)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -37,7 +37,7 @@ WORKDIR = ..$S..$Stestwrk$Smisc
|
|||
|
||||
OPTIONS = g O Os Osi Osir Osr Oi Oir Or
|
||||
|
||||
DIFF = $(WORKDIR)$Sbdiff$(EXE)
|
||||
DIFF = $(WORKDIR)$Sisequal$(EXE)
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -O2
|
||||
|
@ -58,7 +58,7 @@ all: $(TESTS)
|
|||
$(WORKDIR):
|
||||
$(call MKDIR,$(WORKDIR))
|
||||
|
||||
$(DIFF): ../bdiff.c | $(WORKDIR)
|
||||
$(DIFF): ../isequal.c | $(WORKDIR)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
define PRG_template
|
||||
|
|
|
@ -35,7 +35,7 @@ WORKDIR = ..$S..$Stestwrk$Sref
|
|||
|
||||
OPTIONS = g O Os Osi Osir Osr Oi Oir Or
|
||||
|
||||
DIFF = $(WORKDIR)$Sbdiff$(EXE)
|
||||
DIFF = $(WORKDIR)$Sisequal$(EXE)
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -O2 -Wall -W -Wextra -funsigned-char -fwrapv -fno-strict-overflow
|
||||
|
@ -57,7 +57,7 @@ $(WORKDIR)/%.ref: %.c | $(WORKDIR)
|
|||
$(CC) $(CFLAGS) -o $(WORKDIR)/$*.host $< $(NULLERR)
|
||||
$(WORKDIR)$S$*.host > $@
|
||||
|
||||
$(DIFF): ../bdiff.c | $(WORKDIR)
|
||||
$(DIFF): ../isequal.c | $(WORKDIR)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
# "yaccdbg.c" includes "yacc.c".
|
||||
|
|
Loading…
Add table
Reference in a new issue