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

  1. #ifndef NO_IDENT
  2. static char *Id = "$Id: sybintim.c,v 1.7 1995/10/19 15:42:44 tom Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Title:    sysbintim.c
  7.  * Author:    Thomas E. Dickey
  8.  * Created:    13 Jul 1984
  9.  * Last update:
  10.  *        19 Oct 1995, DEC-C clean-compile on AXP
  11.  *        03 Jun 1995, prototypes
  12.  *        26 Jun 1985, make this recognize the DCL-style VMS date format
  13.  *                 (keywords, fill-in-gaps).
  14.  *        13 Jul 1984
  15.  *
  16.  * Function:    Use the VMS procedure SYS$BINTIM to convert a null-ended
  17.  *        string into a 64-bit date value.
  18.  *
  19.  * Parameters:    ci_    => string to convert
  20.  *        bfr_    => 2-word buffer to load with date.
  21.  *
  22.  * Returns:    0 if no error is detected in the parse, otherwise the $BINTIM
  23.  *        code.
  24.  *
  25.  * Patch:    Should consider adding things like "YESTERDAY:6:30"
  26.  * Bugs:    If user gives a string like "6::.4", then the current minute
  27.  *        and second are filled in, rather than using zero.
  28.  */
  29.  
  30. #include    <starlet.h>
  31. #include    <lib$routines.h>
  32. #include    <ctype.h>
  33. #include    <ssdef.h>
  34. #include    <descrip.h>
  35. #include    <string.h>
  36.  
  37. #include    "strutils.h"
  38. #include    "sysutils.h"
  39.  
  40. #define    MAXDAY    24
  41. #define    MAXBFR    80
  42.  
  43. /* FIXME: AXP */
  44. static    int    day[2] = {0x2a69c000, 0xc9};
  45. static    char    zeros[] = " 00:00:00.00";
  46.             /* 0123456789ab */
  47.  
  48. int
  49. sysbintim (char *ci_, DATENT *obfr)
  50. {
  51.     static    char    bigbfr[MAXBFR];    /* FIXME */
  52.     static    char    midbfr[MAXBFR];
  53.     $DESCRIPTOR(DSCx,bigbfr);
  54.     $DESCRIPTOR(midnite,midbfr);
  55.     DATENT    base;
  56.     int    j;
  57.     int    num    = strlen(ci_);
  58.     char    *c_, *d_, *e_;
  59.  
  60.     if (num >= (MAXBFR-1))
  61.         num = (MAXBFR-1);
  62.     for (j = 0; j < num; j++)
  63.         bigbfr[j] = _toupper(ci_[j]);
  64.     bigbfr[num] = '\0';
  65.  
  66.     /*
  67.      * Compute the base of the current day, to use in keyword-dates:
  68.      */
  69.     sys$gettim (obfr);
  70.     sysasctim (midbfr, obfr, MAXDAY);
  71.     strcpy (&midbfr[11], zeros);
  72.     midnite.dsc$a_pointer = midbfr;
  73.     midnite.dsc$w_length  = strlen(midbfr);
  74.     sys$bintim (&midnite, obfr);
  75.     base = *obfr;
  76.  
  77.     if (strabbr (bigbfr, "TODAY", num, 3))
  78.         num = 0;
  79.     else if (strabbr (bigbfr, "YESTERDAY", num, 1))
  80.     {
  81.         lib$subx (base, day, obfr, 0);
  82.         num = 0;
  83.     }
  84.     else if (strabbr (bigbfr, "TOMORROW", num, 3))
  85.     {
  86.         lib$addx (base, day, obfr, 0);
  87.         num = 0;
  88.     }
  89.     /*
  90.      * $BINTIM cannot parse the ':' used in DCL to separate date, time.
  91.      * Convert this to a trailing space and supply trailing zeros.  Also,
  92.      * if the year and/or month is not given, supply these:
  93.      */
  94.     else
  95.     {
  96.         register int dash = 0;
  97.         d_ = zeros;
  98.         for (c_ = bigbfr; *c_; c_++)
  99.         {
  100.             if (*c_ == '-')
  101.                 dash++;
  102.             else
  103.             {
  104.                 if (*c_ == ':' && dash)        *c_ = ' ';
  105.                 if (*c_ == ' ')
  106.                 {
  107.                     if (*d_)        d_ += 3;
  108.                     break;
  109.                 }
  110.                 if (ispunct(*c_) && *d_)    d_ += 3;
  111.             }
  112.         }
  113.  
  114.         if (*d_ && !dash)    d_ += 3;
  115.         e_ = dash ? c_ : bigbfr;
  116.         if (*c_ || !dash)
  117.         {
  118.             if (*c_ == ' ')        c_++;
  119.             while (*c_ && *d_)
  120.             {
  121.                 if (ispunct(*c_))    d_ += 3;
  122.                 c_++;
  123.             }
  124.             if (*d_) strcpy (c_, d_);
  125.         }
  126.         else        /* Default to midnight for time    */
  127.             strcpy (c_, zeros);
  128.  
  129.         /*
  130.          * Insert month (mmm) and year (yyyy) if omitted, since
  131.          * $BINTIM does not permit *gaps*, but only loss of significance.
  132.          */
  133.         if (dash < 2)
  134.         {
  135.             char    time[sizeof(zeros)+2];
  136.             strcpy (time, e_);
  137.             *e_ = '\0';
  138.             if (dash == 1)    /* dd-mmm given    */
  139.             {
  140.                 strncpy (e_, midbfr+6, 5);
  141.                 strcpy (e_+5, time);
  142.             }
  143.             else        /* dash==0, assume 'hh' of 'hh:mm' */
  144.             {
  145.                 strcpy (bigbfr, midbfr);
  146.                 strcpy (bigbfr+12, time);
  147.             }
  148.         }
  149.  
  150.         DSCx.dsc$w_length  = strlen(bigbfr);
  151.  
  152.         if ((num = sys$bintim (&DSCx, obfr)) == SS$_NORMAL)    num = 0;
  153.     }
  154.     return (num);
  155. }
  156.