From a7bd3ad0dbe29b798a781ab514c4a9ee85235e58 Mon Sep 17 00:00:00 2001 From: uz Date: Mon, 24 Jan 2011 16:15:35 +0000 Subject: [PATCH] Added a compar function for file positions. git-svn-id: svn://svn.cc65.org/cc65/trunk@4912 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/common/filepos.c | 33 +++++++++++++++++++++++++++++---- src/common/filepos.h | 8 +++++++- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/common/filepos.c b/src/common/filepos.c index ba5309514..6613f8b3d 100644 --- a/src/common/filepos.c +++ b/src/common/filepos.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998-2000 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@musoftware.de */ +/* (C) 1998-2011, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -54,3 +54,28 @@ void InitFilePos (FilePos* P) +int CompareFilePos (const FilePos* P1, const FilePos* P2) +/* Compare two file positions. Return zero if both are equal, return a value + * > 0 if P1 is greater and P2, and a value < 0 if P1 is less than P2. The + * compare rates file index over line over column. + */ +{ + if (P1->Name > P2->Name) { + return 1; + } else if (P1->Name < P2->Name) { + return -1; + } else if (P1->Line > P2->Line) { + return 1; + } else if (P1->Line < P2->Line) { + return -1; + } else if (P1->Col > P2->Col) { + return 1; + } else if (P1->Col < P2->Col) { + return -1; + } else { + return 0; + } +} + + + diff --git a/src/common/filepos.h b/src/common/filepos.h index e84ebbba0..b9b2e4024 100644 --- a/src/common/filepos.h +++ b/src/common/filepos.h @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1998-2010, Ullrich von Bassewitz */ +/* (C) 1998-2011, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -66,6 +66,12 @@ struct FilePos { void InitFilePos (FilePos* P); /* Initialize the file position (set all fields to zero) */ +int CompareFilePos (const FilePos* P1, const FilePos* P2); +/* Compare two file positions. Return zero if both are equal, return a value + * > 0 if P1 is greater and P2, and a value < 0 if P1 is less than P2. The + * compare rates file index over line over column. + */ + /* End of filepos.h */