Category : Recently Uploaded Files
Archive   : SNPD9503.ZIP
Filename : ADDTIME.C

 
Output of file : ADDTIME.C contained in archive : SNPD9503.ZIP
/*
** ADDTIME.C - Add a time period to a base time, normalizing the result
**
** arguments: 1 - Base hours (0 -> 24)
** 2 - Base minutes (0 -> 59)
** 3 - Base seconds (0 -> 59)
** 4 - Span hours
** 5 - Span minutes
** 6 - Span seconds
** 7 - Address of returned hours (0 -> 23)
** 9 - Address of returned minutes (0 -> 59)
** 10 - Address of returned seconds (0 -> 59)
** 11 - Address of number of days to add to result
**
** returns: 0 if no error, non-zero if base time range error
**
** Notes: 1) Span values may be negative.
** 2) Overflowing midnight will cause a positive number of days to be
** returned.
** 3) Underflowing midnight will cause a negative number of days to be
** returned.
**
** Original Copyright 1994 by Bob Stout as part of
** the MicroFirm Function Library (MFL)
**
** This subset version is donated to the public domain.
*/

#include

int add_time(unsigned basehrs, unsigned basemins, unsigned basesecs,
int spanhrs, int spanmins, int spansecs,
unsigned *hrs, unsigned *mins, unsigned *secs, int *days)
{
int h, m, s;
div_t r;

if (basehrs > 24 || basemins > 59 || basesecs > 59)
return -1;

if (24 == basehrs)
basehrs = 0;
h = (int)basehrs + spanhrs;
m = (int)basemins + spanmins;
s = (int)basesecs + spansecs;

r = div(s, 60);
if (s < 0)
{
r.rem += 60;
--r.quot;
}
*secs = r.rem;
m += r.quot;

r = div(m, 60);
if (m < 0)
{
r.rem += 60;
--r.quot;
}
*mins = r.rem;
h += r.quot;

r = div(h, 24);
if (h < 0)
{
r.rem += 24;
--r.quot;
}
*hrs = r.rem;
*days = r.quot;

return 0;
}

#ifdef TEST

#include

main(int argc, char *argv[])
{
unsigned bh, bm, bs, h, m, s;
int sh, sm, ss, days;

if (7 > argc)
{
puts("Usage: ADDTIME base_hrs base_mins base_secs "
"span_hrs span_mins span_secs");
return EXIT_FAILURE;
}

bh = (unsigned)atoi(argv[1]);
bm = (unsigned)atoi(argv[2]);
bs = (unsigned)atoi(argv[3]);
sh = atoi(argv[4]);
sm = atoi(argv[5]);
ss = atoi(argv[6]);

printf("add_time() returned %d\n",
add_time(bh, bm, bs, sh, sm, ss, &h, &m, &s, &days));

printf("%2d:%02d:%02d + %2d:%02d:%02d = %2d:%02d:%02d + %d days\n",
bh, bm, bs, sh, sm, ss, h, m, s, days);
}

#endif


  3 Responses to “Category : Recently Uploaded Files
Archive   : SNPD9503.ZIP
Filename : ADDTIME.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/