home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l200 / 6.ddi / LIB / DATETIME.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-09-08  |  2.7 KB  |  144 lines

  1. /*      DATE_() -- returns current date as a string in the form
  2.                   mm-dd-yyyy
  3.  
  4.         Copyright (c) 1984 by JMI Software Consultants,    Inc.
  5. */
  6.  
  7. #include "acom.h"
  8. #include "host.h"
  9.  
  10. BTEXT *DATE_(ss)
  11.     BTEXT **ss;
  12.     {
  13.     IMPORT BTEXT *s_new();
  14.     IMPORT TEXT    *itob();
  15.     IMPORT INT strlpfx;
  16.     INTERN REGVAL inregs = {0x2a00,    0x0000,    0x0000,    0x0000, 0x0000};
  17.     REGVAL r;
  18.     TEXT *s;
  19.  
  20.     *ss    = s_new(*ss, 10);
  21.     intdos(&inregs,    &r);
  22.     s =    *ss    + strlpfx;
  23.     s =    itob(s,    2, r.dx    >> 8);
  24.     *s++ = '-';
  25.     s =    itob(s,    2, r.dx    & 0x00ff);
  26.     *s++ = '-';
  27.     s =    itob(s,    4, r.cx);
  28.     *s = NULLCH;
  29.     return(*ss);
  30.     }
  31.  
  32. /*    SDATE_(s) -    sets the system    date from the string s.
  33.     s may be in    any    of the following forms:
  34.     mm-dd-yy
  35.     mm/dd/yy
  36.     mm-dd-yyyy
  37.     mm/dd/yyyy
  38.  */
  39.  
  40. VOID SDATE_(s)
  41.     BTEXT *s;
  42.     {
  43.     IMPORT INT strlpfx;
  44.     INTERN REGVAL date = {0x2b00, 0x0000, 0x0000, 0x0000, 0x0000};
  45.     REGVAL r;
  46.     INT    month, day,    year, err;
  47.  
  48.     month =    day    = year = err = 0;
  49.     s += strlpfx;
  50.     while (*s != '-' &&     *s != '/')
  51.         month =    month *    10 + *s++ -    '0';
  52.     *s++;
  53.     while (*s != '-' && *s != '/')
  54.         day    = day *    10 + *s++ -    '0';
  55.     *s++;
  56.     while (*s)
  57.         year = year    * 10 + *s++    - '0';
  58.     if (year < 100)
  59.         year +=    1900;
  60.     date.cx    = year;
  61.     date.dx    = (month <<    8) + day;
  62.     intdos(&date, &r);
  63.     err    = r.ax & 0x00ff;
  64.     if (err)
  65.         xerror(4, "SDATE_");
  66.     }
  67.  
  68. /*      TIME_() -- returns the current time as a string in the form
  69.                  hh:mm:ss
  70. */
  71.  
  72. BTEXT *TIME_(ss)
  73.     BTEXT **ss;
  74.     {
  75.     IMPORT BTEXT *s_new();
  76.     IMPORT INT strlpfx;
  77.     IMPORT TEXT    *itob();
  78.     INTERN REGVAL inregs = {0x2c00,    0x0000,    0x0000,    0x0000, 0x0000};
  79.     REGVAL r;
  80.     TEXT *s;
  81.  
  82.     *ss    = s_new(*ss, 8);
  83.     intdos(&inregs,    &r);
  84.     s =    *ss    + strlpfx;
  85.     s =    itob(s,    2, r.cx    >> 8);
  86.     *s++ = ':';
  87.     s =    itob(s,    2, r.cx    & 0x00ff);
  88.     *s++ = ':';
  89.     s =    itob(s,    2, r.dx    >> 8);
  90.     *s = NULLCH;
  91.     return(*ss);
  92.     }
  93.  
  94. /*    STIME_(s) -    sets the system    time from the string s.
  95.     s may be in    any    of the following forms:
  96.     hh
  97.     hh:mm
  98.     hh:mm:ss
  99.  */
  100.  
  101. VOID STIME_(s)
  102.     BTEXT *s;
  103.     {
  104.     IMPORT INT strlpfx;
  105.     INTERN REGVAL time = {0x2d00, 0x0000, 0x0000, 0x0000, 0x0000};
  106.     REGVAL r;
  107.     INT    hour, mins,    secs, err;
  108.  
  109.     hour = mins    = secs = err = 0;
  110.     s += strlpfx;
  111.     while (*s != ':' &&    *s != NULLCH)
  112.         hour = hour    * 10 + *s++    - '0';
  113.     if (*s++ ==    ':')
  114.         while (*s != ':' &&    *s != NULLCH)
  115.             mins = mins    * 10 + *s++    - '0';
  116.     if (*s++ ==    ':')
  117.         while (*s)
  118.             secs = secs    * 10 + *s++    - '0';
  119.     time.cx    = (hour    << 8) +    mins;
  120.     time.dx    = secs << 8;
  121.     intdos(&time, &r);
  122.     err    = r.ax & 0x00ff;
  123.     if (err)
  124.         xerror(4, "STIME_");
  125.     }
  126.  
  127.  
  128. TEXT *itob(buf,    size, n)
  129.     TEXT *buf;
  130.     COUNT size,    n;
  131.     {
  132.     COUNT divisor;
  133.  
  134.     divisor    = 1;
  135.     while (--size >    0)
  136.         divisor    *= 10;
  137.     while (divisor > 0)
  138.         {
  139.         *buf++ = (n    / divisor) % 10    + '0';
  140.         divisor    /= 10;
  141.         }
  142.     return(buf);
  143.     }
  144.