home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / flistfrontend / src / syhour.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-21  |  2.3 KB  |  97 lines

  1. #ifndef NO_IDENT
  2. static char *Id = "$Id: syhour.c,v 1.5 1995/10/21 17:20:40 tom Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Title:    syshour.c
  7.  * Author:    Thomas E. Dickey
  8.  * Created:    02 Aug 1984
  9.  * Last update:
  10.  *        21 Oct 1995, DEC-C clean-compile on AXP
  11.  *        19 Feb 1995, prototypes
  12.  *        25 Jun 1985, corrected comments.
  13.  *        21 Dec 1984, test for special cases 0, -1 which cause the system
  14.  *                 routines to supriously generate current-time-of-day.
  15.  *
  16.  * Function:    Given a 64-bit VMS date+time, return a corresponding
  17.  *        single-word value for hours and minutes within the day.
  18.  *
  19.  * Parameters:    q_    => 64-bit (quad-word) system date
  20.  *
  21.  * Returns:    A single (32-bit) unsigned integer.  This function is used
  22.  *        to sort filedates by time-of-day.  Since the actual number
  23.  *        of 10MHz clock ticks would not really fit within 32 bits,
  24.  *        the entire result must be right-shifted by at least 3 bits.
  25.  *        (A full day is 0xC9.2A69C000.)
  26.  */
  27.  
  28. #include <string.h>
  29.  
  30. #include "sysutils.h"
  31.  
  32. #define    SHR    8
  33. #define    WORD    32
  34.  
  35. /*
  36.  * On VAX we've got to shift the date down so we'll have the hour portion
  37.  * of the date in the low-order 32-bits that we use for sorting.  AXP doesn't
  38.  * have to do this.
  39.  */
  40. #ifdef __alpha
  41. #define    lo_temp temp
  42. #else    /* vax */
  43. #define    lo_temp temp.date64[0]
  44. #define    hi_temp temp.date64[1]
  45. #endif
  46.  
  47. static    char    origin[] = "17-NOV-1858";
  48.  
  49. unsigned
  50. syshour (DATENT *q_)
  51. {
  52.     DATENT temp;
  53.     char    bfr[80];
  54.  
  55.     if (!isOkDate(q_))
  56.         lo_temp = 0;
  57.     else if (isBigDate(q_))
  58.         lo_temp = -1;
  59.     else
  60.     {
  61.         sysasctim (bfr, q_, sizeof(bfr));
  62.         strncpy (bfr, origin, sizeof(origin)-1);
  63.         sysbintim (bfr, &temp);
  64.         lo_temp >>= SHR;
  65. #ifndef __alpha
  66.         lo_temp += (hi_temp << (WORD-SHR));
  67. #endif
  68.     }
  69.     return (lo_temp);
  70. }
  71.  
  72. /*
  73.  * Function:    Convert the integer returned by 'syshour' to a string (hours
  74.  *        and minutes only).
  75.  *
  76.  * Parameters:    co_    => output string
  77.  *        q    =  single-word integer to convert
  78.  *        len    =  maximum length of output string
  79.  */
  80. void
  81. syshours (char *co_, unsigned q, int len)
  82. {
  83.     DATENT  temp;
  84.     int    max;
  85.     char    bfr[80], *ci_;
  86.  
  87. #ifndef __alpha
  88.     hi_temp = q >> (WORD-SHR);        /* Reconstruct 64-bit time */
  89. #endif
  90.     lo_temp = q << SHR;
  91.     sysasctim (bfr, &temp, sizeof(bfr));     /* Get a string (from origin) */
  92.     ci_ = &bfr[sizeof(origin)];        /* => hh:mm:ss.cc    */
  93.     if (len < (max = strlen(ci_)))    max = len;
  94.     strncpy (co_, ci_, max);
  95.     co_[max] = '\0';
  96. }
  97.