home *** CD-ROM | disk | FTP | other *** search
- /* DATE_() -- returns current date as a string in the form
- mm-dd-yyyy
-
- Copyright (c) 1984 by JMI Software Consultants, Inc.
- */
-
- #include "acom.h"
- #include "host.h"
-
- BTEXT *DATE_(ss)
- BTEXT **ss;
- {
- IMPORT BTEXT *s_new();
- IMPORT TEXT *itob();
- IMPORT INT strlpfx;
- INTERN REGVAL inregs = {0x2a00, 0x0000, 0x0000, 0x0000, 0x0000};
- REGVAL r;
- TEXT *s;
-
- *ss = s_new(*ss, 10);
- intdos(&inregs, &r);
- s = *ss + strlpfx;
- s = itob(s, 2, r.dx >> 8);
- *s++ = '-';
- s = itob(s, 2, r.dx & 0x00ff);
- *s++ = '-';
- s = itob(s, 4, r.cx);
- *s = NULLCH;
- return(*ss);
- }
-
- /* SDATE_(s) - sets the system date from the string s.
- s may be in any of the following forms:
- mm-dd-yy
- mm/dd/yy
- mm-dd-yyyy
- mm/dd/yyyy
- */
-
- VOID SDATE_(s)
- BTEXT *s;
- {
- IMPORT INT strlpfx;
- INTERN REGVAL date = {0x2b00, 0x0000, 0x0000, 0x0000, 0x0000};
- REGVAL r;
- INT month, day, year, err;
-
- month = day = year = err = 0;
- s += strlpfx;
- while (*s != '-' && *s != '/')
- month = month * 10 + *s++ - '0';
- *s++;
- while (*s != '-' && *s != '/')
- day = day * 10 + *s++ - '0';
- *s++;
- while (*s)
- year = year * 10 + *s++ - '0';
- if (year < 100)
- year += 1900;
- date.cx = year;
- date.dx = (month << 8) + day;
- intdos(&date, &r);
- err = r.ax & 0x00ff;
- if (err)
- xerror(4, "SDATE_");
- }
-
- /* TIME_() -- returns the current time as a string in the form
- hh:mm:ss
- */
-
- BTEXT *TIME_(ss)
- BTEXT **ss;
- {
- IMPORT BTEXT *s_new();
- IMPORT INT strlpfx;
- IMPORT TEXT *itob();
- INTERN REGVAL inregs = {0x2c00, 0x0000, 0x0000, 0x0000, 0x0000};
- REGVAL r;
- TEXT *s;
-
- *ss = s_new(*ss, 8);
- intdos(&inregs, &r);
- s = *ss + strlpfx;
- s = itob(s, 2, r.cx >> 8);
- *s++ = ':';
- s = itob(s, 2, r.cx & 0x00ff);
- *s++ = ':';
- s = itob(s, 2, r.dx >> 8);
- *s = NULLCH;
- return(*ss);
- }
-
- /* STIME_(s) - sets the system time from the string s.
- s may be in any of the following forms:
- hh
- hh:mm
- hh:mm:ss
- */
-
- VOID STIME_(s)
- BTEXT *s;
- {
- IMPORT INT strlpfx;
- INTERN REGVAL time = {0x2d00, 0x0000, 0x0000, 0x0000, 0x0000};
- REGVAL r;
- INT hour, mins, secs, err;
-
- hour = mins = secs = err = 0;
- s += strlpfx;
- while (*s != ':' && *s != NULLCH)
- hour = hour * 10 + *s++ - '0';
- if (*s++ == ':')
- while (*s != ':' && *s != NULLCH)
- mins = mins * 10 + *s++ - '0';
- if (*s++ == ':')
- while (*s)
- secs = secs * 10 + *s++ - '0';
- time.cx = (hour << 8) + mins;
- time.dx = secs << 8;
- intdos(&time, &r);
- err = r.ax & 0x00ff;
- if (err)
- xerror(4, "STIME_");
- }
-
-
- TEXT *itob(buf, size, n)
- TEXT *buf;
- COUNT size, n;
- {
- COUNT divisor;
-
- divisor = 1;
- while (--size > 0)
- divisor *= 10;
- while (divisor > 0)
- {
- *buf++ = (n / divisor) % 10 + '0';
- divisor /= 10;
- }
- return(buf);
- }