// // Programmer: Craig Stuart Sapp // Creation Date: Tue Jul 13 12:32:41 PDT 1999 // Last Modified: Wed Jul 14 19:12:55 PDT 1999 // Filename: hcal.cpp // Syntax: C++ // $Smake: g++ -static -o %b Calendar.cpp Options.cpp % // Options_private.cpp %f && strip %b // // Description: Historic Calendar generation. // Give the calendar of the specified location // with the correct choice made between Gregorian and // Julian calendars for the specified location. // // Notes: 3 Jan 1 Julian = 1 Jan 1 Gregorian proleptic // // The beginning of the Julian year is 25 March, some regions adopted // 1 Jan as the beginning of the year before converting to Gregorian // calendar. // // The beginning of the Gregorian year is 1 Jan without exception. // // A "Nicene Day" has been defined for this program. It is defined as // the first day in each calendar (Julian and Gregorian proleptic) which the // day names correspond: // The first day on which the two calendars maintain the same day is: // 1 Mar 200 Julian = 1 Mar 200 Gregorian proleptic // The last day on which they coincide is: // 28 Feb 300 Julian = 28 Feb 300 Gregorian proleptic // 29 Feb 300 Julian = 1 Mar 300 Gregorian proleptic // #include #include #include #include "Options.h" #include "Calendar.h" #define DISPLAY_UNKNOWN -1 #define DISPLAY_MONTH 1 #define DISPLAY_YEAR 2 #define DISPLAY_NICENE 3 #define DISPLAY_DEBUG 4 // global variables: Calendar cal; // calendar object which will determine what // calendar to use for the assgned dates // global variables for command-line options: Options options; int year = YEAR_UNKNOWN; // command-line year int month = MONTH_UNKNOWN; // command-line year int day = DAY_UNKNOWN; // command-line year int displayType = DISPLAY_UNKNOWN; // for deciding what to display int yearDisplayType = 0; // for regular cal style year calendar // function declarations: char* centerline (char* buffer, const char* string, int linelen, char rfill = '\0'); void checkOptions (Options& opts); void locales (void); void example (void); void help (void); void usage (const char* command); /////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) { options.setOptions(argc, argv); checkOptions(options); char buffer[128] = {0}; int calendar = CALENDAR_UNKNOWN; switch (displayType) { case DISPLAY_MONTH: if (options.getBoolean("label")) { calendar = cal.getMonthCalendar(); cout << centerline(buffer, Calendar::getCalendarName(calendar), 20, ' '); cout << '\n'; } cal.printMonth(); break; case DISPLAY_YEAR: if (options.getBoolean("label")) { calendar = cal.getYearCalendar(); if (options.getBoolean("single")) { cout << centerline(buffer, Calendar::getCalendarName(calendar), 20, ' '); } else { cout << centerline(buffer, Calendar::getCalendarName(calendar), 66, ' '); } cout << '\n'; } cal.printYear(cout, yearDisplayType); break; case DISPLAY_NICENE: cout << "Day number is: " << cal.getNiceneDay() << " for " << Calendar::getCalendarName( Calendar::getCalendar(cal.getLocale(), cal.getNiceneDay())) << " calendar" << endl; break; case DISPLAY_DEBUG: cout << "Julian Nicene day is: " << Calendar::niceneDay(CALENDAR_JULIAN, year, month, day) << endl; cout << "Gregorian Nicene day is: " << Calendar::niceneDay(CALENDAR_GREGORIAN, year, month, day) << endl; cout << "Julian Year is: " << Calendar::getYear(CALENDAR_JULIAN, Calendar::niceneDay(CALENDAR_JULIAN, year, month, day)) << endl; cout << "Gregorian Year is: " << Calendar::getYear(CALENDAR_GREGORIAN, Calendar::niceneDay(CALENDAR_GREGORIAN, year, month, day)) << endl; cout << "Julian Month is: " << Calendar::getMonth(CALENDAR_JULIAN, Calendar::niceneDay(CALENDAR_JULIAN, year, month, day)) << endl; cout << "Gregorian Month is: " << Calendar::getMonth(CALENDAR_GREGORIAN, Calendar::niceneDay(CALENDAR_GREGORIAN, year, month, day)) << endl; cout << "Julian Day is: " << Calendar::getDay(CALENDAR_JULIAN, Calendar::niceneDay(CALENDAR_JULIAN, year, month, day)) << endl; cout << "Gregorian Day is: " << Calendar::getDay(CALENDAR_GREGORIAN, Calendar::niceneDay(CALENDAR_GREGORIAN, year, month, day)) << endl; } return 0; } /////////////////////////////////////////////////////////////////////////// ////////////////////////////// // // centerline -- center the given string in the buffer according to the // given line length default value: rfill = '\0' // char* centerline(char* buffer, const char* string, int linelen, char rfill) { int length = strlen(string); if (length > linelen) { strncpy(buffer, string, linelen); } int rightside = (linelen - length)/2; int leftside = linelen - length - rightside; int i; for (i=0; i