--- /dev/null
+.\" All Rites Reversed. This file is in the PUBLIC DOMAIN.
+.\" Kallisti.
+.TH DDATE 1 "59 Bureaucracy 3161" "" "Emperor Norton Utilities"
+.SH NAME
+ddate \- converts Gregorian dates to Discordian dates
+.SH SYNOPSIS
+.B ddate [+format] [date]
+.SH DESCRIPTION
+.B ddate
+prints the date in Discordian date format.
+.PP
+If called with no arguments,
+.B ddate
+will get the current system date, convert this to the Discordian
+date format and print this on the standard output. Alternatively, a
+Gregorian date may be specified on the command line, in the form of a numerical
+day, month and year.
+.PP
+If a format string is specified, the Discordian date will be printed in
+a format specified by the string. This mechanism works similarly to the
+format string mechanism of
+.B date(1),
+only almost completely differently. The fields are:
+.IP %A
+Full name of the day of the week (i.e., Sweetmorn)
+.IP %a
+Abbreviated name of the day of the week (i.e., SM)
+.IP %B
+Full name of the season (i.e., Chaos)
+.IP %b
+Abbreviated name of the season (i.e., Chs)
+.IP %d
+Ordinal number of day in season (i.e., 23)
+.IP %e
+Cardinal number of day in season (i.e., 23rd)
+.IP %H
+Name of current Holyday, if any
+.IP %N
+Magic code to prevent rest of format from being printed unless today is
+a Holyday.
+.IP %n
+Newline
+.IP %t
+Tab
+.IP %X
+Number of days remaining until X-Day. (Not valid if the SubGenius options
+are not compiled in.)
+.IP %{
+.IP %}
+Used to enclose the part of the string which is to be replaced with the
+words "St. Tib's Day" if the current day is St. Tib's Day.
+.IP %\.
+Try it and see.
+.bp
+.SH EXAMPLES
+.nf
+% ddate
+.br
+Sweetmorn, Bureaucracy 42, 3161 YOLD
+.PP
+% ddate +'Today is %{%A, the %e of %B%}, %Y. %N%nCelebrate %H'
+.br
+Today is Sweetmorn, the 42nd of Bureaucracy, 3161.
+.PP
+% ddate +"It's %{%A, the %e of %B%}, %Y. %N%nCelebrate %H" 26 9 1995
+.br
+It's Prickle-Prickle, the 50th of Bureaucracy, 3161.
+.br
+Celebrate Bureflux
+.PP
+% ddate +'Today's %{%A, the %e of %B%}, %Y. %N%nCelebrate %H' 29 2 1996
+.br
+Today's St. Tib's Day, 3162.
+.br
+
+.SH BUGS
+
+.B ddate(1)
+will produce undefined behaviour if asked to produce the date for St. Tib's
+day and its format string does not contain the St. Tib's Day delimiters
+%{ and %}.
+
+.SH NOTE
+
+After `X-Day' passed without incident, the Church of the SubGenius
+declared that it had got the year upside down - X-Day is actually in 8661 AD
+rather than 1998 AD. Thus, the True X-Day is Cfn 40, 9827.
+
+.SH AUTHOR
+.nh
+Original program by Druel the Chaotic aka Jeremy Johnson (mpython@gnu.ai.mit.edu)
+.br
+Major rewrite by Lee H:. O:. Smith, KYTP, aka Andrew Bulhak (acb@dev.null.org)
+.br
+Five tons of flax.
+
+.SH DISTRIBUTION POLICY
+
+Public domain. All rites reversed.
+
+.SH SEE ALSO
+
+date(1),
+.br
+http://www.subgenius.com/
+.br
+Malaclypse the Younger,
+.I "Principia Discordia, Or How I Found Goddess And What I Did To Her When I Found Her"
+
--- /dev/null
+/* $ 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.
+ (*) Charles Wilson changes under GPL
+
+ 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 Mi¶kiewicz <misiek@pld.ORG.PL>
+ - added Native Language Support
+
+ 2000-03-17 Burt Holzman <bnh@iname.com>
+ - added range checks for dates
+
+ 2002-01-26 Charles Wilson
+ - minor changes so that it compiles on cygwin
+ - removed nls.h dependency (but retain NLS capabiltiy)
+ - changes (c) 2002 Charles Wilson. Licensed under the GPL.
+
+*/
+
+/* configuration options VVVVV READ THIS!!! */
+
+/* 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 */
+
+/* If you are ideologically, theologically or otherwise opposed to the
+ * Church of the SubGenius and do not wish your copy of ddate(1) to contain
+ * code for counting down to X-Day, undefine KILL_BOB */
+
+#define KILL_BOB 13013
+
+/* If you wish ddate(1) to contain SubGenius slogans, define PRAISE_BOB */
+
+/*#define PRAISE_BOB 13013*/
+
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <stdio.h>
+#include "config.h"
+
+#ifndef PACKAGE
+#define PACKAGE "cygutils"
+#endif
+
+#ifndef LOCALEDIR
+#define LOCALEDIR "/usr/share/locale"
+#endif
+
+#ifdef HAVE_LOCALE_H
+# include <locale.h>
+#endif
+
+#ifdef ENABLE_NLS
+# include <libintl.h>
+# define _(Text) gettext (Text)
+# ifdef gettext_noop
+# define N_(String) gettext_noop (String)
+# else
+# define N_(String) (String)
+# endif
+#else
+# undef bindtextdomain
+# define bindtextdomain(Domain, Directory) /* empty */
+# undef textdomain
+# define textdomain(Domain) /* empty */
+# define _(Text) (Text)
+# define N_(Text) (Text)
+#endif
+
+#ifndef __GNUC__
+#define inline /* foo */
+#endif
+
+#ifdef KILL_BOB
+int xday_countdown(int yday, int year);
+#endif
+
+
+/* string constants */
+
+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 *excl[] = {
+ "Hail Eris!", "All Hail Discordia!", "Kallisti!", "Fnord.", "Or not.",
+ "Wibble.", "Pzat!", "P'tang!", "Frink!",
+#ifdef PRAISE_BOB
+ "Slack!", "Praise \"Bob\"!", "Or kill me.",
+#endif /* PRAISE_BOB */
+ /* randomness, from the Net and other places. Feel free to add (after
+ checking with the relevant authorities, of course). */
+ "Grudnuk demand sustenance!", "Keep the Lasagna flying!",
+ "Umlaut Zebra über alles!", "You are what you see.",
+ "Or is it?", "This statement is false.",
+#if defined(linux) || defined (__linux__) || defined (__linux)
+ "Hail Eris, Hack Linux!",
+#endif
+ ""
+};
+
+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 inline char *ending(int i) {
+ return (i%10==1)?"st":(i%10==2?"nd":(i%10==3?"rd":"th"));
+}
+
+static inline int leapp(int i) {
+ return (!(DY(i)%4))&&((DY(i)%100)||(!(DY(i)%400)));
+}
+
+/* select a random string */
+static inline char *sel(char **strings, int num) {
+ return(strings[random()%num]);
+}
+
+void print(struct disc_time,char **); /* old */
+void format(char *buf, const char* fmt, struct disc_time dt);
+/* read a fortune file */
+int load_fortunes(char *fn, char *delim, char** result);
+
+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;
+
+ setlocale(LC_ALL, "");
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
+
+ srandom(time(NULL));
+ /* do args here */
+ for(pi=1; pi<argc; pi++) {
+ switch(argv[pi][0]) {
+ case '+': fnord=argv[pi]+1; break;
+ case '-':
+ switch(argv[pi][1]) {
+ case 'V':
+ printf(_("%s from %s version %s\n"), progname, PACKAGE, VERSION);
+ default: goto usage;
+ }
+ default: goto thud;
+ }
+ }
+
+ thud:
+ if (argc-pi==3){
+ int moe=atoi(argv[pi]), larry=atoi(argv[pi+1]), curly=atoi(argv[pi+2]);
+ hastur=makeday(
+#ifdef US_FORMAT
+ moe,larry,
+#else
+ larry,moe,
+#endif
+ curly);
+ if (hastur.season == -1) {
+ printf("Invalid date -- out of range\n");
+ return -1;
+ }
+ fnord=fnord?fnord:default_fmt;
+ } else if (argc!=pi) {
+ usage:
+ fprintf(stderr,_("usage: %s [+format] [day month year]\n"), argv[0]);
+ exit(1);
+ } else {
+ t= time(NULL);
+ eris=localtime(&t);
+ bob=eris->tm_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; i<fmtlen; i++) {
+ if(fmt[i]=='%') {
+ switch(fmt[i+1]) {
+ case 'A':
+ case 'a':
+ case 'd':
+ case 'e':
+ if(tib_start>0) 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<fmtlen; i++) {
+ if((i==tib_start) && (dt.day==-1)) {
+ /* handle St. Tib's Day */
+ strcpy(bufptr, _("St. Tib's Day")); bufptr += 13;
+ i=tib_end;
+ } else {
+ if(fmt[i]=='%') {
+ char *wibble=0, snarf[23];
+ switch(fmt[++i]) {
+ case 'A': wibble=day_long[dt.yday%5]; break;
+ case 'a': wibble=day_short[dt.yday%5]; break;
+ case 'B': wibble=season_long[dt.season]; break;
+ case 'b': wibble=season_short[dt.season]; break;
+ case 'd': sprintf(snarf, "%d", dt.day+1); wibble=snarf; break;
+ case 'e': sprintf(snarf, "%d%s", dt.day+1, ending(dt.day+1));
+ wibble=snarf; break;
+ case 'H': if(dt.day==4||dt.day==49)
+ wibble=holyday[dt.season][dt.day==49]; break;
+ case 'N': if(dt.day!=4&&dt.day!=49) goto eschaton; break;
+ case 'n': *(bufptr++)='\n'; break;
+ case 't': *(bufptr++)='\t'; break;
+
+ case 'Y': sprintf(snarf, "%d", dt.year); wibble=snarf; break;
+ case '.': wibble=sel(excl, sizeof(excl)/sizeof(excl[0]));
+ break;
+#ifdef KILL_BOB
+ case 'X': sprintf(snarf, "%d",
+ xday_countdown(dt.yday, dt.year));
+ wibble = snarf; break;
+#endif /* KILL_BOB */
+ }
+ if(wibble) {
+/* fprintf(stderr, "wibble = (%s)\n", wibble);*/
+ strcpy(bufptr, wibble); bufptr+=strlen(wibble);
+ }
+ } else {
+ *(bufptr++) = fmt[i];
+ }
+ }
+ }
+ eschaton:
+ *(bufptr)=0;
+}
+
+struct disc_time makeday(int imonth,int iday,int iyear) /*i for input */
+{
+ struct disc_time funkychickens;
+
+ int cal[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
+ int dayspast=0;
+
+ /* basic range checks */
+ if (imonth < 1 || imonth > 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;
+
+ }
+
+#ifdef KILL_BOB
+
+/* Code for counting down to X-Day, X-Day being Cfn 40, 3164
+ *
+ * After `X-Day' passed without incident, the CoSG declared that it had
+ * got the year upside down --- X-Day is actually in 8661 AD rather than
+ * 1998 AD.
+ *
+ * Thus, the True X-Day is Cfn 40, 9827.
+ *
+ */
+
+int xday_countdown(int yday, int year) {
+ int r=(185-yday)+(((yday<59)&&(leapp(year)))?1:0);
+ while(year<9827) r+=(leapp(++year)?366:365);
+ while(year>9827) r-=(leapp(year--)?366:365);
+ return r;
+}
+
+#endif
--- /dev/null
+
+PERPETUAL DATE CONVERTER FROM GREGORIAN TO POEE CALENDAR
+
+SEASONS
+ 1. Chaos -- Patron Apostle Hung Mung
+ 2. Discord -- Patron Apostle Dr. Van Van Mojo
+ 3. Confusion -- Patron Apostle Sri Syadasti
+ 4. Bureaucracy -- Patron Apostle Zarathud
+ 5. The Aftermath -- Patron Apostle the Elder Malaclypse
+
+DAYS OF THE WEEK*
+ 1. Sweetmorn *The DAYS OF THE WEEK
+ 2. Boomtime are named from the five
+ 3. Pungenday basic elements: SWEET,
+ 4. Prickle-Prickle BOOM, PUNGENT, PRICKLE,
+ 5. Setting Orange and ORANGE.
+
+HOLYDAYS
+A. Apostle Holydays B. Seasons Holydays
+ 1. Mungday 1. Chaoflux
+ 2. Mojoday 2. Discoflux
+ 3. Syaday 3. Confuflux
+ 4. Zaraday 4. Bureflux
+ 5. Maladay 5. Afflux
+Each occurs on the 5th Each occurs on the 50th
+day of the Season day of the Season
+
+C. Saint Tib's Day -- occurs once every four years (1 + 4 = 5) and is
+ inserted between the 59th and 60th days of the Season of Chaos
+
+ ST BT PD PP SO SM BT PD PP SO
+Jan 1 2 3 4 5 1 2 3 4 5 Chs Jul 5 6 7 8 9 40 41 42 43 44 Cfn
+ 6 7 8 9 10 6 7 8 9 10 10 11 12 13 14 45 46 47 48 49
+ 11 12 13 14 15 11 12 13 14 15 15 16 17 18 19 50 51 52 53 54
+ 16 17 18 19 20 16 17 18 19 20 20 21 22 23 24 55 56 57 58 59
+ 21 22 23 24 25 21 22 23 24 25 25 26 27 28 29 60 61 62 63 64
+ 26 27 28 29 30 26 27 28 29 30 30 31 1 2 3 65 66 67 68 69
+ 31 1 2 3 4 31 32 33 34 35 Aug 4 5 6 7 8 70 71 72 73 1 Bcy
+Feb 5 6 7 8 9 36 37 38 39 40 9 10 11 12 13 2 3 4 5 6
+ 10 11 12 13 14 41 42 43 44 45 14 15 16 17 18 7 8 9 10 11
+ 15 16 17 18 19 46 47 48 49 50 19 20 21 22 23 12 13 14 15 16
+ 20 21 22 23 24 51 52 53 54 55 24 25 26 27 28 17 18 19 20 21
+ 25 26 27 28* 1 56 57 58 59 60 29 30 31 1 2 22 23 24 25 26
+Mar 2 3 4 5 6 61 62 63 64 65 Sep 3 4 5 6 7 27 28 29 30 31
+ 7 8 9 10 11 66 67 68 69 70 8 9 10 11 12 32 33 34 35 36
+ 12 13 14 15 16 71 72 73 1 2 Dsc 13 14 15 16 17 37 38 39 40 41
+ 17 18 19 20 21 3 4 5 6 7 18 19 20 21 22 42 43 44 45 46
+ 22 23 24 25 26 8 9 10 11 12 23 24 25 26 27 47 48 49 50 51
+ 27 28 29 30 31 13 14 15 16 17 28 29 30 1 2 52 53 54 55 56
+Apr 1 2 3 4 5 18 19 20 21 22 Oct 3 4 5 6 7 57 58 59 60 61
+ 6 7 8 9 10 23 24 25 26 27 8 9 10 11 12 62 63 64 65 66
+ 11 12 13 14 15 28 29 30 31 32 13 14 15 16 17 67 68 69 70 71
+ 16 17 18 19 20 33 34 35 36 37 18 19 20 21 22 72 73 1 2 3 Afm
+ 21 22 23 24 25 38 39 40 41 42 23 24 25 26 27 4 5 6 7 8
+ 26 27 28 29 30 43 44 45 46 47 28 29 30 31 1 9 10 11 12 13
+May 1 2 3 4 5 48 49 50 51 52 Nov 2 3 4 5 6 14 15 16 17 18
+ 6 7 8 9 10 53 54 55 56 57 7 8 9 10 11 19 20 21 22 23
+ 11 12 13 14 15 58 59 60 61 62 12 13 14 15 16 24 25 26 27 28
+ 16 17 18 19 20 63 64 65 66 67 17 18 19 20 21 29 30 31 32 33
+ 21 22 23 24 25 68 69 70 71 72 22 23 24 25 26 34 35 36 37 38
+ 26 27 28 29 30 73 1 2 3 4 Cfn 27 28 29 30 1 39 40 41 42 43
+ 31 1 2 3 4 5 6 7 8 9 Dec 2 3 4 5 6 44 45 46 47 48
+Jun 5 6 7 8 9 10 11 12 13 14 7 8 9 10 11 49 50 51 52 53
+ 10 11 12 13 14 15 16 17 18 19 12 13 14 15 16 54 55 56 57 58
+ 15 16 17 18 19 20 21 22 23 24 17 18 19 20 21 59 60 61 62 63
+ 20 21 22 23 24 25 26 27 28 29 22 23 24 25 26 64 65 66 67 68
+ 25 26 27 28 29 30 31 32 33 34 27 28 29 30 31 69 70 71 72 73
+ 30 1 2 3 4 35 36 37 38 39 [1970 = 3136] [Next St. Tib's Day in 3138]
+
+ SACRED DOCUMENT OF THE FROGS (old Erisian poem):
+ 73 Days hath
+ Chaos, Discord, Confusion, Bureaucracy, and Aftermath
+