Category : Files from Magazines
Archive   : V12N09.ZIP
Filename : DOWGJ.C

 
Output of file : DOWGJ.C contained in archive : V12N09.ZIP
/*********************************************************************
DOWGJ - Day_Of_the_Week Gregorian or Julian calendar
**********************************************************************

Author: Roberto R. Viscogliosi
Date Written : 10/92
Release: 1.1

This program computes the Day_Of_the_Week for a given date using
the Gregorian calendar as default, or the Julian calendar when an
extra argument is given at the command line.

Input Arguments:
mm dd yyyy [c]
where:
mm = month, dd = day, yyyy = year
[c] = any value forces the use of the Julian calendar;
no value uses the Gregorian calendar.

Example: DOWGJ 10 12 1492 j
Last change: 14 Jan 93 2:30 pm
***********************************************************************/

#include
#include

#define OK 0
#define GRG 1

long dow (int, int, int, int);
void help (char *);

//====================================================================
// MAIN process
//====================================================================
int main (ac, av)
int ac;
char *av[];
{
int day, month, year, calendar = GRG, ret = OK;

static char *dowstr[7] = {
"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"
};

for (;;) {
// check arguments passed
if (ac < 4) { // not enough args.
ret = !OK;
break;
}
// get/verify the input values
if (((month = atoi (av[1])) < 1) ||
((day = atoi (av[2])) < 1) ||
((year = atoi (av[3])) < 1)
) { // invalid values
ret = !OK;
break;
}
// check if Julian calendar requested
if (ac > 4) { // reset the calendar indicator
calendar = !GRG;
}
// prevent overflow by check year size
if (year > 9999) { // year too large
ret = !OK;
break;
}
// compute and show the day_of_the_week
printf ("%02d/%02d/%04d is on %s %s\n",
month, day, year,
dowstr [dow (month, day, year, calendar)],
(calendar == GRG) ? "" : "(Julian calendar)"
);
break;
}
// check for errors
if (ret) {
help (av[0]);
}
exit (ret);
}
//====================================================================
// DOW - Return the day of the week value 0-6 (0 = Sunday)
// based on the date (month, day, year) and calendar
//====================================================================
long dow (month, day, year, calendar)
int month, day, year, calendar;
{
static char month_val[12] = {
// J F M A M J J A S O N D
6,2,2,5,0,3,5,1,4,6,2,4
};

return (( day \
+ (month_val [month - 1]) \

- ((month < 3) \
? ((calendar == GRG) \
? ((!(year % 4)) && \
((year % 100) || (!(year % 400)))) \
: (1*(!(year % 4)))) \
: 0 \
) \
+ year \
+ (year / 4) \
+ ((calendar == GRG) \
? ((year / 400) - (year / 100)) \
: 5 \
) \
) % 7 \
);
}

//====================================================================
// HELP - Print the help info
//====================================================================
static void help (fn)
char *fn;
{
printf ("\nWelcome to DOWGJ (DOW Gregorian or Julian) Version 1.1\n");
printf (" by R. Viscogliosi\n");
printf ("\nTo use it, please enter:\n");
printf ("\n %s mm dd yyyy [c]\n", fn);
printf ("\n (If [c] is specified then the date is in Julian,\n");
printf (" else the date defaults to the Gregorian calendar)\n");
printf ("\n (e.g. 'DOWGJ 10 12 1492 j' was on Friday (Julian))\n");
}


  3 Responses to “Category : Files from Magazines
Archive   : V12N09.ZIP
Filename : DOWGJ.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/