home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!rayssd!galaxia!mrsoft!mrr
- From: mrr@mrsoft.network23.com (Mark Rinfret)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: SAS C6.1 datecmp bug
- Message-ID: <LY3bs*+T0@mrsoft.network23.com>
- Date: Wed, 23 Dec 1992 09:56:47 GMT
- References: <BzD93n.JCo@usenet.ucs.indiana.edu> <BzEqDF.A5H@unx.sas.com> <1992Dec21.030843.16107@bohra.cpg.oz.au>
- Organization: MRsoftware
- X-Newsreader: Arn V1.00
- Lines: 80
-
- Well, you don't have this to complain about any more. I wrote this a long,
- long time ago (original name was CompareDS). It's a drop-in replacement
- for the broken datecmp(). Merry Christmas!
-
- ( If you turn on the file's "S"bit with the PROTECT command, this file is
- self-compiling/linking.)
-
- ;/* datecmp.c
- sc DEFINE=TEST LINK datecmp
- quit;
- */
-
- #include <exec/types.h>
- #include <dos/dos.h>
-
- /* FUNCTION
- datecmp - compare two DateStamp values.
-
- SYNOPSIS
- int datecmp(const struct DateStamp *date1,
- const struct DateStamp *date2);
-
- DESCRIPTION
- datecmp performs an ordered comparison between two DateStamp
- values, returning the following result codes:
-
- -1 => date1 < date2
- 0 => date1 == date2
- 1 => date1 > date2
-
- NOTE:
- This routine makes an assumption about the DateStamp structure,
- specifically that it can be viewed as an array of 3 long integers
- in days, minutes and ticks order.
- */
-
- int
- datecmp(const struct DateStamp *date1, const struct DateStamp *date2)
- {
- USHORT i;
- LONG compare;
- LONG *d1 = (LONG *) date1;
- LONG *d2 = (LONG *) date2;
-
- for (i = 0; i < 3; ++i) {
- if (compare = (d1[i] - d2[i])) {
- return ( (compare < 0) ? -1 : 1);
- }
- }
- return 0; /* dates match */
- }
-
- #ifdef TEST
- #include <stdio.h>
- #include <proto/dos.h>
-
- int main(int argc, char **argv)
- {
- static struct DateStamp __aligned date1;
- static struct DateStamp __aligned date2;
-
- DateStamp(&date1);
- Delay(50L);
- DateStamp(&date2);
-
- if (datecmp(&date1, &date2) >= 0)
- printf("Mark screwed up.\n");
- else if (datecmp(&date2, &date1) <= 0)
- printf("Rinfret blew it.\n");
- else
- printf("This datecmp() looks OK. Send Mark lots of money.\n");
- }
-
- #endif
-
- # Mark R. Rinfret MRsoftware
- # Certified Amiga Developer 348 Indian Avenue
- # mrr@mrsoft.network23.com Portsmouth, RI 02871
- # galaxia!mrsoft!mrr (401) 846-7639
- #
-