home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / amiga / programm / 17760 < prev    next >
Encoding:
Text File  |  1992-12-23  |  2.4 KB  |  92 lines

  1. Path: sparky!uunet!rayssd!galaxia!mrsoft!mrr
  2. From: mrr@mrsoft.network23.com (Mark Rinfret)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: SAS C6.1 datecmp bug
  5. Message-ID: <LY3bs*+T0@mrsoft.network23.com>
  6. Date: Wed, 23 Dec 1992 09:56:47 GMT
  7. References: <BzD93n.JCo@usenet.ucs.indiana.edu> <BzEqDF.A5H@unx.sas.com> <1992Dec21.030843.16107@bohra.cpg.oz.au>
  8. Organization: MRsoftware
  9. X-Newsreader: Arn V1.00
  10. Lines: 80
  11.  
  12. Well, you don't have this to complain about any more. I wrote this a long,
  13. long time ago (original name was CompareDS). It's a drop-in replacement
  14. for the broken datecmp(). Merry Christmas! 
  15.  
  16. ( If you turn on the file's "S"bit with the PROTECT command, this file is 
  17. self-compiling/linking.)
  18.  
  19. ;/* datecmp.c
  20. sc DEFINE=TEST LINK datecmp
  21. quit;
  22. */
  23.  
  24. #include <exec/types.h>
  25. #include <dos/dos.h>
  26.  
  27. /*  FUNCTION
  28.         datecmp - compare two DateStamp values.
  29.  
  30.     SYNOPSIS
  31.         int datecmp(const struct DateStamp *date1, 
  32.                     const struct DateStamp *date2);
  33.  
  34.     DESCRIPTION
  35.         datecmp performs an ordered comparison between two DateStamp
  36.         values, returning the following result codes:
  37.  
  38.             -1 => date1 < date2
  39.              0 => date1 == date2
  40.              1 => date1 > date2
  41.  
  42.     NOTE:
  43.         This routine makes an assumption about the DateStamp structure,
  44.         specifically that it can be viewed as an array of 3 long integers
  45.         in days, minutes and ticks order.
  46.  */
  47.  
  48. int
  49. datecmp(const struct DateStamp *date1, const struct DateStamp *date2)
  50. {
  51.     USHORT  i;
  52.     LONG    compare;
  53.     LONG    *d1 = (LONG *) date1;
  54.     LONG    *d2 = (LONG *) date2;
  55.  
  56.     for (i = 0; i < 3; ++i) {
  57.         if (compare = (d1[i] - d2[i])) {
  58.             return ( (compare < 0) ? -1 : 1);
  59.         }
  60.     }
  61.     return 0;                       /* dates match */
  62. }
  63.  
  64. #ifdef TEST
  65. #include <stdio.h>
  66. #include <proto/dos.h>
  67.  
  68. int main(int argc, char **argv)
  69. {
  70.     static struct DateStamp __aligned date1;
  71.     static struct DateStamp __aligned date2;
  72.  
  73.     DateStamp(&date1);
  74.     Delay(50L);
  75.     DateStamp(&date2);
  76.  
  77.     if (datecmp(&date1, &date2) >= 0)
  78.         printf("Mark screwed up.\n");
  79.     else if (datecmp(&date2, &date1) <= 0)
  80.         printf("Rinfret blew it.\n");
  81.     else
  82.         printf("This datecmp() looks OK. Send Mark lots of money.\n");
  83. }
  84.  
  85. #endif
  86.  
  87. # Mark R. Rinfret                   MRsoftware
  88. # Certified Amiga Developer         348 Indian Avenue
  89. # mrr@mrsoft.network23.com          Portsmouth, RI  02871
  90. # galaxia!mrsoft!mrr                (401) 846-7639
  91. #
  92.