From a3a0acb982a87c5e8d92d5206dd75f4939bf2761 Mon Sep 17 00:00:00 2001 From: "John M. Boyer" Date: Sun, 15 May 2016 13:22:09 -0700 Subject: [PATCH] Enable -test command-line param to work under Mac/Linux --- c/planarity.c | 15 ++++++++-- c/planarity.h | 2 +- c/planarityCommandLine.c | 4 +-- c/planarityUtils.c | 64 +++++++++++++++++++++++++++++++++++++++- configure.ac | 2 +- 5 files changed, 80 insertions(+), 7 deletions(-) diff --git a/c/planarity.c b/c/planarity.c index e99f225..699059a 100644 --- a/c/planarity.c +++ b/c/planarity.c @@ -8,9 +8,20 @@ See the LICENSE.TXT file for licensing information. void ProjectTitle() { + // This message is the main location of the version number. + // The format is major.minor.maintenance.tweak + // Major is for an overhaul (e.g. many features, data structure change) + // Minor is for feature addition, e.g. a new algorithm implementation added + // Maintenance is for functional revision, e.g. bug fix to algorithm implementation + // Tweak is for a non-functional revision, e.g. change of build scripts or testing code + + // If the version here is increased, also increase it in configure.ac + // Furthermore, a change of Major, Minor or Maintenance here should cause a change + // of Current, Revision and/or Age as documented in configure.ac + Message("\n==================================================" - "\nThe Edge Addition Planarity Suite version 3.0.0.4" - "\nCopyright (c) 1997-2015 by John M. Boyer" + "\nThe Edge Addition Planarity Suite version 3.0.0.5" + "\nCopyright (c) 1997-2016 by John M. Boyer" "\nContact info: jboyer at acm.org" "\n==================================================" "\n"); diff --git a/c/planarity.h b/c/planarity.h index f44e1ee..b0cfa62 100644 --- a/c/planarity.h +++ b/c/planarity.h @@ -58,7 +58,7 @@ void Prompt(char *message); void SaveAsciiGraph(graphP theGraph, char *filename); -int FilesEqual(char *file1Name, char *file2Name); +int TextFilesEqual(char *file1Name, char *file2Name); int GetEmbedFlags(char command); char *GetAlgorithmName(char command); diff --git a/c/planarityCommandLine.c b/c/planarityCommandLine.c index 42ff2aa..e714993 100644 --- a/c/planarityCommandLine.c +++ b/c/planarityCommandLine.c @@ -283,7 +283,7 @@ int runSpecificGraphTest(char *command, char *infileName) if (Result == 0) { - if (FilesEqual(testfileName, outfileName) == TRUE) + if (TextFilesEqual(testfileName, outfileName) == TRUE) { Message("Test succeeded (result equal to exemplar).\n"); unlink(outfileName); @@ -309,7 +309,7 @@ int runSpecificGraphTest(char *command, char *infileName) if (Result == 0) { - if (FilesEqual(testfileName, outfileName) == TRUE) + if (TextFilesEqual(testfileName, outfileName) == TRUE) { Message("Test succeeded (secondary result equal to exemplar).\n"); unlink(outfileName); diff --git a/c/planarityUtils.c b/c/planarityUtils.c index e77102e..079b067 100644 --- a/c/planarityUtils.c +++ b/c/planarityUtils.c @@ -127,7 +127,69 @@ void SaveAsciiGraph(graphP theGraph, char *filename) /**************************************************************************** ****************************************************************************/ -int FilesEqual(char *file1Name, char *file2Name) +int TextFilesEqual(char *file1Name, char *file2Name) +{ + FILE *infile1 = NULL, *infile2 = NULL; + int Result = TRUE; + + infile1 = fopen(file1Name, "r"); + infile2 = fopen(file2Name, "r"); + + if (infile1 == NULL || infile2 == NULL) + Result = FALSE; + else + { + int c1=0, c2=0; + + // Read the first file to the end + while ((c1 = fgetc(infile1)) != EOF) + { + // Want to suppress distinction between lines ending with CRLF versus LF + if (c1 == '\r') + continue; + + // Get a char from the second file, except suppress CR again + while ((c2 = fgetc(infile2)) == '\r') + ; + + // If we got a char from the first file, but not from the second + // then the second file is shorter, so files are not equal + if (c2 == EOF) + { + Result = FALSE; + break; + } + + // If we got a char from second file, but not equal to char from + // first file, then files are not equal + if (c1 != c2) + { + Result = FALSE; + break; + } + } + + // If we got to the end of the first file without breaking the loop... + if (c1 == EOF) + { + // Then, once again, suppress CRs first, and then... + while ((c2 = fgetc(infile2)) == '\r') + ; + // Test whether or not the second file also ends, same as the first. + if (fgetc(infile2) != EOF) + Result = FALSE; + } + } + + if (infile1 != NULL) fclose(infile1); + if (infile2 != NULL) fclose(infile2); + return Result; +} + +/**************************************************************************** + ****************************************************************************/ + +int BinaryFilesEqual(char *file1Name, char *file2Name) { FILE *infile1 = NULL, *infile2 = NULL; int Result = TRUE; diff --git a/configure.ac b/configure.ac index 9cd71d8..e87fc51 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT(planarity, 3.0.0.4, jboyer@acm.org) +AC_INIT(planarity, 3.0.0.5, jboyer@acm.org) AM_INIT_AUTOMAKE([subdir-objects] [foreign]) AC_CONFIG_SRCDIR([c/])