/* $ DVCS ID: $jer|,523/lhos,KYTP!41023161\b"?" <<= DO NOT DELETE! */ /* ddate.c .. converts boring normal dates to fun Discordian Date -><- written the 65th day of The Aftermath in the Year of Our Lady of Discord 3157 by Druel the Chaotic aka Jeremy Johnson aka mpython@gnu.ai.mit.edu 28 Sever St Apt #3 Worcester MA 01609 and I'm not responsible if this program messes anything up (except your mind, I'm responsible for that) (k) YOLD 3161 and all time before and after. Reprint, reuse, and recycle what you wish. This program is in the public domain. Distribute freely. Or not. Majorly hacked, extended and bogotified/debogotified on Sweetmorn, Bureaucracy 42, 3161 YOLD, by Lee H:. O:. Smith, KYTP, aka Andrew Bulhak, aka acb@dev.null.org and I'm not responsible if this program messes anything up (except your mind, I'm responsible for that) (and that goes for me as well --lhos) Version history: Bureflux 3161: First release of enhanced ddate with format strings 59 Bcy, 3161: PRAISE_BOB and KILL_BOB options split, other minor changes. 1999-02-22 Arkadiusz Miskiewicz - added Native Language Support 2000-03-17 Burt Holzman - added range checks for dates */ /* If you wish ddate(1) to print the date in the same format as Druel's * original ddate when called in immediate mode, define OLD_IMMEDIATE_FMT */ #define OLD_IMMEDIATE_FMT /* If you wish to use the US format for aneristic dates (m-d-y), as opposed to * the Commonwealth format, define US_FORMAT. */ /* #define US_FORMAT */ #include #include #include #include char *day_long[5] = { "Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle", "Setting Orange" }; char *day_short[5] = { "SM", "BT", "PD", "PP", "SO"}; char *season_long[5] = { "Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath" }; char *season_short[5] = { "Chs", "Dsc", "Cfn", "Bcy", "Afm"}; char *holyday[5][2] = { { "Mungday", "Chaoflux" }, { "Mojoday", "Discoflux" }, { "Syaday", "Confuflux" }, { "Zaraday", "Bureflux" }, { "Maladay", "Afflux" } }; struct disc_time { int season; /* 0-4 */ int day; /* 0-72 */ int yday; /* 0-365 */ int year; /* 3066- */ }; char default_fmt[] = "%{%A, %B %d%}, %Y YOLD"; char *default_immediate_fmt= #ifdef OLD_IMMEDIATE_FMT "Today is %{%A, the %e day of %B%} in the YOLD %Y%N%nCelebrate %H" #else default_fmt #endif ; #define DY(y) (y+1166) static char *ending(int i) { return i/10==1?"th":(i%10==1?"st":(i%10==2?"nd":(i%10==3?"rd":"th"))); } static int leapp(int i) { return (!(DY(i)%4))&&((DY(i)%100)||(!(DY(i)%400))); } void format(char *buf, const char* fmt, struct disc_time dt); struct disc_time convert(int,int); struct disc_time makeday(int,int,int); int main (int argc, char *argv[]) { long t; struct tm *eris; int bob,raw; struct disc_time hastur; char schwa[23*17], *fnord=0; int pi; char *progname, *p; progname = argv[0]; if ((p = strrchr(progname, '/')) != NULL) progname = p+1; srand(time(NULL)); /* do args here */ for(pi=1; pitm_yday; /* days since Jan 1. */ raw=eris->tm_year; /* years since 1980 */ hastur=convert(bob,raw); fnord=fnord?fnord:default_immediate_fmt; } format(schwa, fnord, hastur); printf("%s\n", schwa); return 0; } void format(char *buf, const char* fmt, struct disc_time dt) { int tib_start=-1, tib_end=0; int i, fmtlen=strlen(fmt); char *bufptr=buf; /* fprintf(stderr, "format(%p, \"%s\", dt)\n", buf, fmt);*/ /* first, find extents of St. Tib's Day area, if defined */ for(i=0; i0) tib_end=i+1; else tib_start=i; break; case '{': tib_start=i; break; case '}': tib_end=i+1; break; } } } /* now do the formatting */ buf[0]=0; for(i=0; i 12) { funkychickens.season = -1; return funkychickens; } if (iday < 1 || iday > cal[imonth-1]) { if (!(imonth == 2 && iday == 29 && iyear%4 == 0 && (iyear%100 != 0 || iyear%400 == 0))) { funkychickens.season = -1; return funkychickens; } } imonth--; funkychickens.year= iyear+1166; while(imonth>0) { dayspast+=cal[--imonth]; } funkychickens.day=dayspast+iday-1; funkychickens.season=0; if((funkychickens.year%4)==2) { if (funkychickens.day==59 && iday==29) funkychickens.day=-1; } funkychickens.yday=funkychickens.day; /* note: EQUAL SIGN...hopefully that fixes it */ while(funkychickens.day>=73) { funkychickens.season++; funkychickens.day-=73; } return funkychickens; } struct disc_time convert(int nday, int nyear) { struct disc_time funkychickens; funkychickens.year = nyear+3066; funkychickens.day=nday; funkychickens.season=0; if ((funkychickens.year%4)==2) {if (funkychickens.day==59) funkychickens.day=-1; else if (funkychickens.day >59) funkychickens.day-=1; } funkychickens.yday=funkychickens.day; while (funkychickens.day>=73) { funkychickens.season++; funkychickens.day-=73; } return funkychickens; }