/*-
 * chgdate() calls getdate(), which converts an input start date 
 * plus a series of modification instructions to a new date.
 *
 * USAGE:
 *
 * chgdate 	[ -n ]
 *		[ date ]
 *		[ date   date_modifier_list ]
 *		[ modified_date  -  modified_date ]
 *
 * where a date is specified by:
 * 	   { now | today | weekday | month day[, year] 
 *		| mm/dd[/yy] | {month|mm} number weekday | julian_day }
 *
 * and a date modifier by:
 *	   { +-number      { {d | w | m | y }  |  weekday } } 
 *
 * options for the returned date format are:
 *	-0	Mon dd[, yyyy]
 * 	-1	Mon dd, year (Wday) julian_day
 *	-2	mm:dd:yyyy:wdaynum:julian_day
 *	-3	Mon:dd:yyyy:Wday:julian_day
 *	-4	julian_day
 *
 * chgdate returns date in format '1' as the default;
 *
 * chgdate with no argument or the argument 'now' or 'today', 
 * returns the current date;
 *
 * chgdate with the argument 'weekday', returns date for the
 * 'weekday' of the _current_ week (sunday = start);
 *
 * chgdate with the arguments 'month day, year' or 'mm/dd/yy[yy]', 
 * returns the date for the input string; the ', year' or '/yy[yy]' 
 * can be omitted, with the default being the current year.
 *
 * chgdate with any of the above date arguments, and one or more _pairs_
 * of number--unit modifiers, returns the modified date resulting from all
 * the modifications; e.g., now 1 m -1 y == this day of the next month for
 * the previous year.
 *
 * chgdate with arguments giving a 'date' or 'month' followed by a 'number'
 * and a 'weekday', returns the date for the number-th weekday in the month;
 * e.g., 1 3 mon == third monday in january of the current year.
 *
 * chgdate with a binary 'minus' (-) among the arguments returns
 * the number of days difference between two dates.
 *
 * chgdate accepts a julian date; it thus serves to interconvert gregorian
 * and julian dates.
 *
 * J.A. Rupley, Tucson, AZ  85716
 *
 */

#include <stdio.h>
#include <stdlib.h>


int
main(argc, argv)
	int             argc;
	char          **argv;
{
	char           *sp;
	int             formatflag;
	int             argcnt;

	void            exit();
	extern char    *getdate();

	if (argc > 1 && *argv[1] == '-') {
		formatflag = atoi(&argv[1][1]);
		argcnt = 2;
	} else {
		formatflag = 1;
		argcnt = 1;
	}

	if (!(sp = getdate(formatflag, argcnt, argc, argv))) {
		fprintf(stderr, "chgdate: error return from getdate\n");
		exit(1);
	} else {
		/* output month day, year, or whatever is returned */
		fprintf(stdout, "%s\n", sp);
	}

	return (0);
}
