/* 1 1 1 1 1 1 11 1 1 11 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 11 1 111 111 111111 1 1 1 1 1 1 11 1 1 1 1 1 1 1 111111 1 111111 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1111 11 1 11 11111 | | 1111 1 1 111 | | 111 1 11 1111 ( ! ) Release 1.6 - esfand 22 1374 111111 11111111111111111 \ / March 12 1996 111111 111111 111111 --- 1 | |--0 Copyright (c) 1996 1 1 1 |___| NetNative 1 11111 ! ! native@netnative.com 1 1 1 ! ! P.O.Box 391403 1 / \ Mountain View, Ca. 94039-1403 1 ~~~~~ 1 * Copyright (c) 1993-96 NetNative * * Permission to use this software is hereby granted without fee, provided * that there is no fee charged by the user. Also, no part of this software * may be modified or used in a commercial software or service without the * specific, prior written permission of NetNative. * * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. * * IN NO EVENT SHALL NETNATIVE BE LIABLE FOR ANY SPECIAL, INCIDENTAL, * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE * POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #define EOL '\n' #define EOL_char '\n' #define NOTEOL '\\' #define BLANK ' ' #define JalaliBase 79 #define JYearOffset 621 #define JWkDayOff 3 #define GWkDayOff 0 #define FALSE 0 #define TRUE 1 #define Solar 365.25 #define GYearOff 226894 static int GDayTab[2][13] = { {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, }; static int JDayTab[2][13] = { {0, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29}, {0, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 30}, }; static char *GCalMonthsJ[] ={ " March-April", " April-May", " May-June", " June-July", " July-August", " August-September", " September-October", " October-November", " November-December", " December-January", " January-February", " February-March"}; static char *JCalMonthsG[2][12] ={ { " dy-bhmn", " bhmn-asfnd", " asfnd-frvrdyn", " frvrdyn-ardybhSt", " ardybhSt-Krdad", " Krdad-tyr", " tyr-mrdad", " mrdad-Shryvr", " Shryvr-mhr", " mhr-Aban", " Aban-AZr", " AZr-dy"}, { " day-bahman", " bahman-esfand", " esfand-farvardin", " farvardin-ordibehesht", " ordibehesht-khordad", " khordad-tir", " tir-mordad", " mordad-shahrivar", " shahrivar-mehr", " mehr-Aban", " Aban-Azar", " Azar-day"} }; static char *JCalMonths[2][12] ={ {" frvrdyn", " ardybhSt", " Krdad", " tyr", " mrdad", " Shryvr", " mhr", " Aban", " AZr", " dy", " bhmn", " asfnd"}, { " farvardin", " ordibehesht", " khordad", " tir", " mordad", " shahrivar", " mehr", " Aban", " Azar", " day", " bahman", " esfand"} }; static char *GCalMonths[] ={ " January", " February", " March", " April", " May", " June", " July", " August", " September", " October", " November", " December"}; static char *JCalMonthsGerd[] ={ " . ", " . _ > q _9 ", " (_): / / / ", " .. c |", " __,_w_8_,_ > |", " .: / ", " | .", " > |> _7", " / ", " : ", " _,_ ", " / : ", " | ", " > |> _o ", " / ", " c ", " q_ _8_w ", " / /: / ", " ", " _8_o ", " / ", " | ~", " . |_ |", " (_) . ", " . ~", " > |", " / ", " ", " > ", " (_S ", " ", " . _o_8_ ", " (_) . ", " . . |", " ]_,_9_w |", " "}; static char *JCalWkDaysGerd[] ={ " c ", " w > w _7 __ _7 ", " (_/ (_S (_/ (_c c (_. "}; static char *JCalWkDays1[2][1] ={ {" Snbh ykSn dvSn shSn GharSn pnjSn jmeh "}, {" shanb yeksh dosh sehsh chehar panj jomeh"}}; static char *JCalWkDays2[] ={ " SAT SUN MON TUE WED THU FRI"}; static char *GCalWkDays[] ={ " SUN MON TUE WED THU FRI SAT"}; static char *EMonthTab[] = {"Err","JAN","FEB","MAR","APR","MAY","JUN", "JUL","AUG","SEP","OCT","NOV","DEC"}; static char *PMonthTab[2][13] = { {"Err","FRV","ARD","KRD","TYR","MRD","SHR", "MHR","ABA","AZR","DY ","BHM","ASF"}, {"Err","FAR","ORD","KHO","TIR","MOR","SHA", "MEH","ABA","AZA","DAY","BAH","ESF"} }; static char *EMonthTab2[] = {"Err","Jan","Feb","Mar","Apr","May","Jun", "Jul","Aug","Sep","Oct","Nov","Dec"}; static char *PMonthTab2[2][13] = { {"Err","frvrdyn","ardybhSt","Krdad","tyr","mrdad","Shryvr","mhr", "Aban","AZr","dy","bhmn","asfnd"}, {"Err","farvardin","ordibehesht","khordad","tir","mordad","shahrivar","mehr", "Aban","Azar","day","bahman","esfand"} }; static char *EDayOfWeek[7] = {"MON","TUE","WED","THU","FRI","SAT","SUN"}; static char *PDayOfWeek[7] = {"dvSnbh","sh~Snbh","GharSnbh","pnjSnbh","jmeh","Snbh","ykSnbh"}; static char *PDayOfWeek2[7] = {"dvSnbh ", "sh~Snbh ", "GharSnbh", "pnjSnbh ", "jmeh ", "Snbh ", "ykSnbh "}; static char *blank[] = {" "," "}; FILE *out_file; char file_name[20]; char EOF_char; int DEBUG; int Gerdsooz; char EOF_char; int code; int Jalali, Greg; int ConvertJalali, ConvertGreg; int calyear; int PersForm; int NumMonth; int G; long debug; long Jleap(long year); long JLeapYears(long JYear); long Gleap(long year); long GLeapYears(long JYear); main(argc, argv) int argc; char *argv[]; { long hour, min, wday; long year, month, day; long jdayofyr, gdayofyr; EOF_char = EOF; debug = 0; if (open_files(argv, &month, &day, &year) == 1) return 1; if (Jalali) JCalendar(calyear); else if (Greg) GCalendar(calyear); else { /* fprintf(out_file, "\n%ld %ld %ld\n",month, day, year);*/ if (ConvertGreg) JalaliDate(year, month, day); else if (ConvertJalali) GregorianDate(year, month, day); else /* display current date */ { out_file = stdout; GetTime (&hour, &min, &wday, &month, &day, &year); year = year + 1900; month = month + 1; JalaliDate(year, month, day); /* help(); */ } } wrapup(); } /* Compute Jalali Day Of Year from Year, Month, and Day */ long JDayOfYear(year, month, day) long year, month, day; { long i, leap; leap = Jleap(year); for (i=1; i< month; i++) day += JDayTab[leap][i]; return day; } /* Compute Gregorian Day Of Year from Year, Month, and Day */ long GDayOfYear(year, month, day) long year, month, day; { long i, leap; leap = Gleap(year); for (i=1; i< month; i++) day += GDayTab[leap][i]; return day; } long JalaliDays(JYear, JMonth, JDay) long JYear, JMonth, JDay; { long TotalDays; long Leap, tmp; Leap = JLeapYears(JYear-1); /* find all leap years that have passed */ tmp = JDayOfYear(JYear, JMonth, JDay); TotalDays = (JYear -1) * 365 + Leap + tmp; if (debug) fprintf (out_file,"Leap= %ld, JDayOfYear = %ld \n",Leap, JDayOfYear(JYear,JMonth,JDay)); return TotalDays; } long GregDays(GYear, GMonth, GDay) long GYear, GMonth, GDay; { long Div4, Div100, Div400; long TotalDays, tmp; Div4 = (GYear-1)/4; Div100 = (GYear-1)/100; Div400 = (GYear-1)/400; tmp = GDayOfYear(GYear, GMonth, GDay); TotalDays = (GYear -1) * 365 + tmp + Div4 - Div100 + Div400; return TotalDays; } /* Distance in days of origin of Jalali calendar from Origin of Gregorian calendar */ #define GYearOff 226894 /* Compute Jalali date from Gregorian Year, Month & Day */ JalaliDate(GYear, GMonth, GDay) long GYear, GMonth, GDay; { long TotalDays; long JYear, JMonth, JDay; TotalDays = GregDays(GYear, GMonth, GDay); if (debug) fprintf(out_file,"Total Jalali Days = %ld\n",TotalDays); JalaliYMD(TotalDays, &JYear, &JMonth, &JDay); if (PersForm) if (NumMonth) fprintf(out_file, "%ld %ld %ld\n",JDay, JMonth, JYear); else fprintf(out_file, "%ld %s %ld\n",JDay, PMonthTab2[G][JMonth], JYear); else fprintf(out_file, "%s %ld %ld\n",PMonthTab2[G][JMonth], JDay, JYear); } /* Compute Jalali date from Gregorian Total Days */ JalaliYMD(TotalDays, JYear, JMonth, JDay) long TotalDays, *JYear, *JMonth, *JDay; { long GYear, GMonth, GDay; long JDays; long Leap; TotalDays -= GYearOff; /* estimate full Jalai years passed */ *JYear = TotalDays / (Solar - 0.25/33); /* find all leap years that have passed */ Leap=JLeapYears(*JYear); JDays = TotalDays - (365 * *JYear + Leap); *JYear +=1; if (!JDays) { *JYear -=1; if(Jleap(*JYear)) JDays = 366; else JDays = 365; } else if (JDays == 366 && !Jleap(*JYear)) { JDays = 1; *JYear +=1; } JMonthDay(*JYear, JDays, &*JMonth, &*JDay); } /* Compute Gregorian date from Jalali Year, Month & Day */ GregorianDate(JYear, JMonth, JDay) long JYear, JMonth, JDay; { long TotalDays; long GYear, GMonth, GDay; TotalDays = JalaliDays(JYear, JMonth, JDay); if (debug) fprintf(out_file,"Total Jalali Days = %ld\n",TotalDays); GregorianYMD(TotalDays, &GYear, &GMonth, &GDay); if (PersForm) if(NumMonth) fprintf(out_file, "%ld %ld %ld\n",GDay, GMonth, GYear); else fprintf(out_file, "%ld %s %ld\n",GDay, EMonthTab2[GMonth], GYear); else fprintf(out_file, "%s %ld %ld\n",EMonthTab2[GMonth], GDay, GYear); } /* Compute Gregorian date from Jalali Total Days */ GregorianYMD(TotalDays, GYear, GMonth, GDay) long TotalDays, *GYear, *GMonth, *GDay; { long Div33, Div4, Div100, Div400; long GDays; TotalDays += GYearOff; /* Total Gregorian days passed */ *GYear = TotalDays / (Solar - 0.25/33); Div4 = *GYear/4; Div100 = *GYear/100; Div400 = *GYear/400; /* find Gregorian day of year */ GDays = TotalDays - (365 * *GYear) - (Div4 - Div100 + Div400); *GYear +=1; if (debug) fprintf(out_file,"Gregorian DayOfYear = %ld\n",GDays); if (!GDays) { *GYear -=1; if(Gleap(*GYear)) GDays = 366; else GDays = 365; } else if ( GDays == 366 && !Gleap(*GYear)) { GDays = 1; *GYear +=1; } if (debug) fprintf(out_file,"Gregorian DayOfYear = %ld GYear = %ld\n",GDays, *GYear); GMonthDay(*GYear, GDays, &*GMonth, &*GDay); } /* Set Jalali Month & Day from Jalali Year & Day Of Year */ JMonthDay(JYear, JDayOfYear, Month, Day) long JYear, JDayOfYear, *Month, *Day; { long i, leap; leap = Jleap(JYear); for (i=1; JDayOfYear > JDayTab[leap][i]; i++) JDayOfYear -= JDayTab[leap][i]; *Month = i; *Day = JDayOfYear; } /* Set Gregorian Month & Day from Gergorian Year & Day Of Year */ GMonthDay(GYear, GDayOfYear, Month, Day) long GYear, GDayOfYear, *Month, *Day; { long i, leap; leap = Gleap(GYear); for (i=1; GDayOfYear> GDayTab[leap][i]; i++) GDayOfYear -= GDayTab[leap][i]; *Month = i; *Day = GDayOfYear; } /* Decides if Jalali year a leap one: those years that have a remainder of 1, 5, 9, 13, 17, 22, 26, and 30 when divided by 33 */ long Jleap(year) long year; { long tmp; tmp = year % 33; if (tmp == 1 || tmp == 5||tmp==9||tmp==13||tmp==17||tmp==22||tmp==26||tmp==30) return 1; else return 0; } /* find all Jalali leap years until JYear */ long JLeapYears(JYear) long JYear; { long Leap, CurrentCycle, Div33, i; Div33 = JYear/33; /* number of 33-year-periods */ CurrentCycle = JYear - (Div33 * 33); Leap = Div33 * 8; if (CurrentCycle > 0) for (i=1; (i<=CurrentCycle&&i<=18); i+=4) Leap++; if (CurrentCycle > 21) for (i=22; i<= CurrentCycle&&i<=30; i+=4) /* for (i=22; i<=30; i+=4) */ Leap++; return Leap; } /* Decides if Gregorian year a leap one: those years that are divisible by (4 but not 100) & those that are dvisible by 400. */ long Gleap(year) long year; { if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) return 1; else return 0; } int open_files(argv, cmonth, cday, cyear) char *argv[]; long *cmonth, *cday, *cyear; { long out_flag; long get_date; long INTRO, HELP; char *tmp1[12]; char *tmp2[12]; G=TRUE; out_flag=FALSE; Jalali=FALSE; ConvertGreg=FALSE; ConvertJalali=FALSE; Greg=FALSE; Gerdsooz = FALSE; get_date = FALSE; INTRO = FALSE; HELP = FALSE; while (*++argv != NULL) { if ((strcmp(*argv, "-o")) == 0) { out_file = fopen(*++argv, "w"); out_flag=TRUE; } else if (((strcmp(*argv, "-j")) == 0)|((strcmp(*argv, "-J")) == 0)) { ConvertJalali=TRUE; get_date = TRUE; } else if (((strcmp(*argv, "-g")) == 0)|((strcmp(*argv, "-G")) == 0)) { ConvertGreg=TRUE; get_date = TRUE; } else if (((strcmp(*argv, "-ge")) == 0)|((strcmp(*argv, "-GE")) == 0)) G=FALSE; else if (((strcmp(*argv, "-h")) == 0)|((strcmp(*argv, "-H")) == 0)) HELP = TRUE; else if (((strcmp(*argv, "-i")) == 0)|((strcmp(*argv, "-I")) == 0)) INTRO = TRUE; else if (((strcmp(*argv, "-p")) == 0)|((strcmp(*argv, "-P")) == 0)) Gerdsooz=TRUE; else if (((strcmp(*argv, "-jy")) == 0)|((strcmp(*argv, "-JY")) == 0)) { Jalali=TRUE; if (*++argv == NULL) { } calyear = atoi(*argv); } else if (((strcmp(*argv, "-gy")) == 0)|((strcmp(*argv, "-GY")) == 0)) { Greg=TRUE; if(*++argv ==NULL) { } calyear = atoi(*argv); } else { printf("illegal option ==> %s\n", *argv); return(1); } if (get_date) { get_date = FALSE; if (*++argv == NULL) { } *tmp1 = *argv; if (*++argv == NULL) { } *tmp2 = *argv; if (*++argv == NULL) { } *cyear = atoi(*argv); if (*tmp1[0] >= '0' && *tmp1[0] <= '9') { PersForm = TRUE; *cday = atoi(*tmp1); if (*tmp2[0] >= '1' && *tmp2[0] <= '9') { *cmonth = atoi(*tmp2); NumMonth = TRUE; } else { NumMonth = FALSE; convert_month(*tmp2, &*cmonth); } } else { NumMonth = FALSE; PersForm = FALSE; *cday = atoi(*tmp2); convert_month(*tmp1, &*cmonth); } if (*cyear < 0) printf(" ==> %s, is not a valid year <==\n", *argv); if (*cmonth <1 | *cmonth >12) { if (PersForm) printf(" ==> %s, is not a valid month <==\n", *tmp2); else printf(" ==> %s, is not a valid month <==\n", *tmp1); return 1; } if(*cday <= 0 | (ConvertJalali && *cday > JDayTab[Jleap(*cyear)][*cmonth])| (ConvertGreg && *cday > GDayTab[Gleap(*cyear)][*cmonth])) { if(PersForm) printf(" ==> %s, is not a valid day <==\n", *tmp1); else printf(" ==> %s, is not a valid day <==\n", *tmp2); return 1; } } } if (!out_flag) out_file = stdout; if (INTRO) { intro(); return(1); } if (HELP) { help(); return(1); } return(0); } convert_month(tmp, cmonth) char tmp[12]; long *cmonth; { char test[3]; long l, i; *cmonth = 0; l = strlen(tmp); if ( l < 3) { if (l == 2 && ConvertJalali) { test[0] = toupper(tmp[0]); test[1] = toupper(tmp[1]); test[2] = ' '; if ((strncmp(test, "DY ", 3) == 0)) *cmonth = 10; } return 0; } else { test[0] = toupper(tmp[0]); test[1] = toupper(tmp[1]); test[2] = toupper(tmp[2]); } if (ConvertJalali) { for (i=1; i<13; i++) { if (((strncmp(test, PMonthTab[0][i], 3)) == 0)|((strncmp(test, PMonthTab[1][i], 3)) == 0)) { *cmonth = i; return 0; } } } else { for (i=1; i<13; i++) { if (((strncmp(test, EMonthTab[i], 3)) == 0)) { *cmonth = i; return 0; } } } } wrapup() { char in_char; fclose(out_file); } GetTime (hour, min, wday, mon, mday, year) long *hour, *min, *wday, *mon, *mday, *year; { long clock, time(); struct tm *theTime, *localtime(); clock = time ((long *) 0); theTime = localtime (&clock); *hour = theTime->tm_hour; *min = theTime->tm_min; *wday = theTime->tm_wday; *mon = theTime->tm_mon; *mday = theTime->tm_mday; *year = theTime->tm_year; } JCalendar(year) long year; { long leap, i, g, first; long jdays; long dindex[13], jdaysindex[13]; long GYear, GMonth, GDay; leap = Jleap(year); jdays = JalaliDays(year, 1l, 1l); GregorianYMD(jdays, &GYear, &GMonth, &GDay); for (i=1; i<13; i++) { jdaysindex[i] = jdays; dindex[i] = (jdays - JWkDayOff) %7; jdays += JDayTab[leap][i]; } fprintf (out_file, " *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n\n"); fprintf (out_file, " Jalali Year %ld\n", year); fprintf (out_file, " Gregorian Years %ld-%ld\n\n", GYear, GYear+1); fprintf (out_file, " *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n\n"); for (g=1; g<13; g+=1) { if (Gerdsooz) { fprintf (out_file, "%s%c", JCalMonthsGerd[(g-1)*3], EOL_char); fprintf (out_file, "%s%c", JCalMonthsGerd[(g-1)*3+1], EOL_char); fprintf (out_file, "%s%c%c", JCalMonthsGerd[(g-1)*3+2], EOL_char, EOL_char); fprintf (out_file, "%s%c%c", GCalMonthsJ[g-1], EOL_char, EOL_char); for (i=0; i<3; i++) fprintf (out_file, "%s%c", JCalWkDaysGerd[i], EOL_char); fprintf (out_file, "%c", EOL_char); } else { fprintf (out_file, "%s%c%c", JCalMonths[G][g-1], EOL_char, EOL_char); fprintf (out_file, "%s%c%c", GCalMonthsJ[g-1], EOL_char, EOL_char); fprintf (out_file, "%s%c%c", JCalWkDays1[G][0], EOL_char, EOL_char); fprintf (out_file, "%s%c%c", JCalWkDays2[0], EOL_char, EOL_char); } first=TRUE; i=1; while(i <= JDayTab[leap][g]) { fprintf (out_file, "%s", blank[1]); JPrintCal(first, &i, g, &dindex[g], leap, jdaysindex[g]); fprintf (out_file, "%c", EOL_char); fprintf (out_file, "%c", EOL_char); first = FALSE; } } } JPrintCal(first, i, g, dindex, leap, jdaysindex) long first, *i, g, *dindex, leap, jdaysindex; { long m; long GYear, GMonth, GDay; if (first) for (m=0; m < *dindex; m++) fprintf (out_file, "%s", blank[0]); while(*dindex < 7) { if (*i <= JDayTab[leap][g]) { fprintf (out_file, "%4ld", *i); GregorianYMD(jdaysindex + *i - 1, &GYear, &GMonth, &GDay); fprintf (out_file, "/%ld", GDay); if (GDay < 10) putc (BLANK, out_file); } else fprintf (out_file, "%s", blank[0]); *i +=1; *dindex +=1; } *dindex = 0; } GCalendar(year) long year; { long leap, i, g, first; long gdays; long dindex[13], gdaysindex[13]; long JYear, JMonth, JDay; leap = Gleap(year); gdays = GregDays(year, 1l, 1l); JalaliYMD(gdays, &JYear, &JMonth, &JDay); for (i=1; i<13; i++) { gdaysindex[i] = gdays; dindex[i] = (gdays - GWkDayOff) %7; gdays += GDayTab[leap][i]; } fprintf (out_file, " *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n\n"); fprintf (out_file, " Gregorian Year %ld\n", year); fprintf (out_file, " Jalali Years %ld-%ld\n\n", JYear, JYear+1); fprintf (out_file, " *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n\n"); for (g=1; g<13; g+=1) { fprintf (out_file, "%s%c%c", GCalMonths[g-1], EOL_char, EOL_char); fprintf (out_file, "%s%c%c", JCalMonthsG[G][g-1], EOL_char, EOL_char); fprintf (out_file, "%s%c%c", GCalWkDays[0], EOL_char, EOL_char); first=TRUE; i=1; while(i <= GDayTab[leap][g]) { fprintf (out_file, "%s", blank[1]); GPrintCal(first, &i, g, &dindex[g], leap, gdaysindex[g]); fprintf (out_file, "%c", EOL_char); fprintf (out_file, "%c", EOL_char); first = FALSE; } } } GPrintCal(first, i, g, dindex, leap, gdaysindex) long first, *i, g, *dindex, leap, gdaysindex; { long m; long JYear, JMonth, JDay; if (first) for (m=0; m < *dindex; m++) fprintf (out_file, "%s", blank[0]); while(*dindex < 7) { if (*i <= GDayTab[leap][g]) { fprintf (out_file, "%4ld", *i); JalaliYMD(gdaysindex + *i - 1, &JYear, &JMonth, &JDay); fprintf (out_file, "/%ld", JDay); if (JDay < 10) putc (BLANK, out_file); } else fprintf (out_file, "%s", blank[0]); *i +=1; *dindex +=1; } *dindex = 0; } help() { fprintf(out_file," 1 1 \n"); fprintf(out_file," 1 1 1 1 11 1 1 11 1 1 1 1 \n"); fprintf(out_file," 1 1 1 1 1 1 1 1 1 1 11 11 1 111 \n"); fprintf(out_file," 111 111111 1 1 1 1 1 1 11 1 1 1 \n"); fprintf(out_file," 1 1 1 1 111111 1 111111 1 1 1 \n"); fprintf(out_file," 1 1 1 1 1 1 1 1 1 1 1 1 1 \n"); fprintf(out_file," 1 1 1 1 1 1 1 1 1 1 1 1 1111 \n"); fprintf(out_file," 11 1 11 11111 \n"); fprintf(out_file," | | 1111 1 1 111 \n"); fprintf(out_file," | | 111 1 11 1111 \n"); fprintf(out_file," ( ! ) Release 1.6 - esfand 22 1374 111111 11111111111111111 \n"); fprintf(out_file," \\ / March 12 1996 111111 111111 111111 \n"); fprintf(out_file," --- 1\n"); fprintf(out_file," | |--0 Copyright (c) 1993-96 1 1 1\n"); fprintf(out_file," |___| NetNative 1 11111\n"); fprintf(out_file," ! ! native@netnative.com 1 1 1\n"); fprintf(out_file," ! ! P.O.Box 391403 1\n"); fprintf(out_file," / \\ Mountain View, Ca. 94039-1403 1\n"); fprintf(out_file," ~~~~~ 1\n"); fprintf(out_file,"\n"); fprintf(out_file,"khayam [[-h] / [-i] / [[-j/g DATE] / [-jy [-p]/-gy ] -ge ] [-o out_file]\n"); fprintf(out_file,"\n"); fprintf(out_file,"khayam -h - Outputs help message.\n"); fprintf(out_file,"\n"); fprintf(out_file,"khayam -i - Outputs introduction to khayam.\n"); fprintf(out_file,"\n"); fprintf(out_file,"khayam -ge - Uses Gerdsooz encoding for Jalali month names.\n"); fprintf(out_file,"\n"); fprintf(out_file,"khayam -jy YEAR - Outputs Jalali calendar for year YEAR.\n"); fprintf(out_file," with -p option, Gerdsooz's Persian font headers are used.\n"); fprintf(out_file," Ex: khayam -jy 1372\n"); fprintf(out_file," khayam -p -jy 1372\n"); fprintf(out_file," khayam -ge -jy 1372\n"); fprintf(out_file,"\n"); fprintf(out_file,"khayam -gy YEAR - Outputs Gregorian calendar for year YEAR.\n"); fprintf(out_file," Ex: khayam -gy 1993\n"); fprintf(out_file,"\n"); fprintf(out_file,"khayam -j DATE - Reads Jalali Date & Outputs the corresponding Gregorian Date.\n"); fprintf(out_file," Ex: khayam -j 29 12 1371 outputs -> 20 3 1993 (Day Month Year)\n"); fprintf(out_file," khayam -j asfnd 29 1371 outputs -> Mar 20 1993 (Month Day Year)\n"); fprintf(out_file," khayam -j 29 asfnd 1371 outputs -> 20 Mar 1993 (Day Month Year)\n"); fprintf(out_file,"\n"); fprintf(out_file,"khayam -g DATE - Reads Gregorian Date & Outputs the corresponding Jalali Date.\n"); fprintf(out_file," Ex: khayam -g 21 3 1993 outputs -> 1 1 1372 (Day Month Year)\n"); fprintf(out_file," khayam -g Mar 21 1993 outputs -> frvrdyn 1 1372 (Month Day Year)\n"); fprintf(out_file," khayam -ge -g 21 Mar 1993 outputs -> 1 farvardin 1372 (Day Month Year)\n"); fprintf(out_file,"\n"); fprintf(out_file,"Months: 1 through 12, or from the following list. First 3 letters are ok.\n"); fprintf(out_file,"\n"); fprintf(out_file,"Jalali: frvrdyn, ardybhSt, Krdad, tyr, mrdad, Shryvr, \n"); fprintf(out_file," mhr, Aban, AZr, dy, bhmn, asfnd\n"); fprintf(out_file," OR\n"); fprintf(out_file,"Jalali: farvardin, ordibehesht, khordad, tir, mordad, shahrivar, \n"); fprintf(out_file," mehr, Aban, Azr, day, bahman, esfand\n"); fprintf(out_file,"\n"); fprintf(out_file,"Gregorian: January, February, March, April, May, June, \n"); fprintf(out_file," July, August, September, October, November, December\n"); fprintf(out_file,"\n"); fprintf(out_file,"\n"); fprintf(out_file ," . = | . | : | \n"); fprintf(out_file ," > ]_)__,_o _____,_7_c __o_c 4__|__9 |__o . __ | \n"); fprintf(out_file ," / : . . / (_) : \n"); fprintf(out_file ,"\n"); fprintf(out_file ," . = | | / | \n"); fprintf(out_file ," > ]_)_,_o _____ _D |_ 4_) _o > _____ |_ > \n"); fprintf(out_file ," / : . / . (_S . : / \n"); fprintf(out_file ,"\n"); fprintf(out_file ," . | . | . . : | \n"); fprintf(out_file ," q_7 4_7 . |_9_ _7 |> _9 o_c _o |_w \n"); fprintf(out_file ," (_S / / c (_) : / (_S / ( (_S \n"); fprintf(out_file ,"\n"); fprintf(out_file ," . = c / | || ~ c \n"); fprintf(out_file ," > ]_)_,_o __,_w 4_) | 4_||_,_ | w_,_ \n"); fprintf(out_file ," / : . / :c / (_/ :c \n"); fprintf(out_file ,"\n"); fprintf(out_file ," | . \n"); fprintf(out_file ," - o |_,_7 _o_c - \n"); fprintf(out_file ," ( : / \n"); fprintf(out_file ,"\n"); } intro() { fprintf (out_file ,"\n"); fprintf (out_file ," ** Introduction by Dr. Hossein Bagher Zadeh **\n"); fprintf (out_file ,"\n"); fprintf (out_file ," The 'khayam' Program\n"); fprintf (out_file ,"\n"); fprintf (out_file ,"The 'khayam' program allows you to convert the Jalaali and Gregorian\n"); fprintf (out_file ,"calendars into each other. The first is official in Iran (and\n"); fprintf (out_file ,"surrounding areas like Afghanistan, Central Asian Republics and\n"); fprintf (out_file ,"Kurdish Mesopotamia) and the second in the west. The Jalaali calendar\n"); fprintf (out_file ,"is named after Jalaal-ol-Din Malek-shaah-e Saljuqi by the great\n"); fprintf (out_file ,"Iranian poet/mathematician Omar Khayyam who re-worked it in late fifth\n"); fprintf (out_file ,"century hejri. The Gregorian calendar is named after Pope Gregory\n"); fprintf (out_file ,"XIII who introduced the latest changes in the calendar in 1582 AD.\n"); fprintf (out_file ,"The two have more or less the same year-length, but are based on\n"); fprintf (out_file ,"completely different systems. They differ in both structures and in\n"); fprintf (out_file ,"the way they deal with leap years.\n"); fprintf (out_file ,"\n"); fprintf (out_file ,"The Jalaali calendar has a natural/universal character. It spans\n"); fprintf (out_file ,"across a cycle of four full seasons of the year starting with the first\n"); fprintf (out_file ,"day of spring (for the northern hemisphere). It also has a regular\n"); fprintf (out_file ,"(but not uniform) distribution of days per month. The first six months\n"); fprintf (out_file ,"all have 31 days and the second six months all have 30 days in leap \n"); fprintf (out_file ,"years, with the last month having 29 days in non-leap years. The \n"); fprintf (out_file ,"calendar is roughly mapped onto the familiar Zodiac system in the west.\n"); fprintf (out_file ,"\n"); fprintf (out_file ,"The Gregorian calendar differs from Jalaali in both respects. Here,\n"); fprintf (out_file ,"there is no direct correspondence between the year and the natural\n"); fprintf (out_file ,"seasons. Also, the months have arbitrary length of seven 31 days,\n"); fprintf (out_file ,"four 30 days and one 28/29 days interleaved irregularly.\n"); fprintf (out_file ,"\n"); fprintf (out_file ,"Moreover, the Jalaali year follows closely the movement of the earth\n"); fprintf (out_file ,"(round the sun). A natural solar year is approximately 365 days, 5\n"); fprintf (out_file ,"hours and 49 minutes. For the Jalaali calendar, it begins (tahvil-e\n"); fprintf (out_file ,"saal) at the point when the sun appears to cross the equator from the\n"); fprintf (out_file ,"southern hemisphere to the northern hemisphere as viewed from the\n"); fprintf (out_file ,"center of the earth. Then for the purposes of the calendar, if the\n"); fprintf (out_file ,"exact moment of tahvil-e saal is before midday (Tehran time), the same\n"); fprintf (out_file ,"day is regarded as the New Year's Day (1st Farvardin). Otherwise, the\n"); fprintf (out_file ,"New Year begins in the following day. The convention results in 8\n"); fprintf (out_file ,"leap years in every cycle of (roughly) 33 years. The leap years are,\n"); fprintf (out_file ,"currently, those with a remainder (after dividing by 33) of 1, 5, 9,\n"); fprintf (out_file ,"13, 17, 22, 26, and 30. For instance, 1370 divided by 33 leaves 17 as\n"); fprintf (out_file ,"the remainder, and so it was a leap year. The next leap year will be\n"); fprintf (out_file ,"1375 - with a four year gap, rather than the usual three, between the\n"); fprintf (out_file ,"two leap years.\n"); fprintf (out_file ,"\n"); fprintf (out_file ,"The Gregorian calendar uses a simplified convention which has the\n"); fprintf (out_file ,"effect of greater variance with the natural year. Here, the leap\n"); fprintf (out_file ,"years are fixed for every fourth year except for the years which are\n"); fprintf (out_file ,"divisible by 100 but not by 400. So, the year 2000 will be a leap\n"); fprintf (out_file ,"year (as it is divisible by 400) but not, say, 2100.\n"); fprintf (out_file ,"\n"); fprintf (out_file ,"The program takes all these factors into account. However, it should\n"); fprintf (out_file ,"be noted that the Gregorian calendar was last modified in 1582 AD. Also,\n"); fprintf (out_file ,"due to the fact that the Jalaali year follows closely the movement of\n"); fprintf (out_file ,"the earth (and based on the time declared by Dr. Iraj Malekpoor of\n"); fprintf (out_file ,"Tehran Geophysics Institute for the 1372 tahvil-e saal), the table of\n"); fprintf (out_file ,"leap years in a the 33-year cycle may change early in the 17th century\n"); fprintf (out_file ,"hejri by the four-year gap being pushed one step back. Similarly, if\n"); fprintf (out_file ,"we use the Jalaali calendar retrospectively, a similar distortion may\n"); fprintf (out_file ,"be seen around 1110 by the gap being pushed ahead one step. (The\n"); fprintf (out_file ,"present Jalaali calendar was last re-introduced early this century.\n"); fprintf (out_file ,"Before then its use was restricted mainly to astronomy/astrology.)\n"); fprintf (out_file ,"\n"); fprintf (out_file ,"Taking these possibilities into account, the conversion should be\n"); fprintf (out_file ,"correct for the years between 1734-2254 of Gregorian calendar and\n"); fprintf (out_file ,"1112-1633 of Jalaali calendar. But for the dates outside these ranges\n"); fprintf (out_file ,"some modifications may need to be made.\n"); fprintf (out_file ,"\n"); fprintf (out_file ,"For more details about the two calendars see ``The Great Leap Years\n"); fprintf (out_file ,"Gap'' obtainable by ftp from tehran.stanford.edu.\n"); fprintf (out_file ,"\n"); fprintf (out_file ,"Please forward your questions to ghbr@fmg.bt.co.uk.\n"); fprintf (out_file ,"\n"); fprintf (out_file ,"\n"); fprintf (out_file ,"\n"); }