home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / slackwar / a / util / util-lin.10 / util-lin / util-linux-1.10 / ddate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-05  |  3.9 KB  |  172 lines

  1. /* ddate.c .. converts boring normal dates to fun Discordian Date -><-
  2.    written  the 65th day of The Aftermath in the Year of Our Lady of 
  3.    Discord 3157 by Druel the Chaotic aka Jeremy Johnson aka
  4.    mpython@gnu.ai.mit.edu  
  5.  
  6.    and I'm not responsible if this program messes anything up (except your 
  7.    mind, I'm responsible for that)
  8.  
  9.    Modifications for Unix by Lee Harvey Oswald Smith, K.S.C.
  10.    Five tons of flax.
  11. */
  12.  
  13. #include <time.h>
  14. #include <string.h>
  15. #include <stdio.h>
  16.  
  17. struct disc_time
  18. {int season; /* 0-4 */
  19.  int day; /* 0-72 */
  20.  int yday; /* 0-365 */
  21.  int year; /* 3066- */
  22. };
  23.  
  24. char *ending(int);
  25. void print(struct disc_time,char **);
  26. struct disc_time convert(int,int);
  27. struct disc_time makeday(int,int,int);
  28.  
  29. main (int argc,char **argv) 
  30. {long t;
  31.  struct tm *eris;
  32.  int bob,raw;
  33.  struct disc_time hastur;
  34.  if (argc==4)
  35.     { int moe,larry,curly;
  36.       moe=atoi(argv[1]);
  37.       larry=atoi(argv[2]);
  38.       curly=atoi(argv[3]);
  39.       hastur=makeday(moe,larry,curly);
  40.     }
  41.   else if (argc!=1)
  42.     { fprintf(stderr,"Syntax: DiscDate [month day year]");
  43.       exit(1);
  44.     }
  45.   else
  46.     {
  47.       t= time(NULL);
  48.       eris=localtime(&t);
  49.       bob=eris->tm_yday; /* days since Jan 1. */
  50.       raw=eris->tm_year; /* years since 1980 */
  51.       hastur=convert(bob,raw);
  52.     }
  53.       print(hastur,argv);
  54. }
  55.  
  56. struct disc_time makeday(int imonth,int iday,int iyear) /*i for input */
  57. { struct disc_time funkychickens;
  58.   
  59.   int cal[12] = 
  60.     {
  61.        31,28,31,30,31,30,31,31,30,31,30,31
  62.     };
  63.   int dayspast=0;
  64.  
  65.   imonth--;
  66.   funkychickens.year= iyear+1166;
  67.   while(imonth>0)
  68.      {
  69.        dayspast+=cal[--imonth];
  70.      }
  71.   funkychickens.day=dayspast+iday-1;
  72.   funkychickens.season=0;
  73.    if((funkychickens.year%4)==2)
  74.      {
  75.        if (funkychickens.day==59)
  76.          funkychickens.day=-1;
  77.      }
  78.   funkychickens.yday=funkychickens.day;
  79. /*               note: EQUAL SIGN...hopefully that fixes it */
  80.   while(funkychickens.day>=73)
  81.       {
  82.     funkychickens.season++;
  83.     funkychickens.day-=73;
  84.       }
  85.   return funkychickens;
  86. }
  87.  
  88. char *ending(int num)
  89. {  
  90.  int temp;
  91.  char *funkychickens;
  92.  
  93.  funkychickens=(char *)malloc(sizeof(char)*3);
  94.  
  95.   temp=num%10; /* get 0-9 */  
  96.   switch (temp)
  97.   { case 1:
  98.       strcpy(funkychickens,"st");
  99.       break;
  100.     case 2:
  101.       strcpy(funkychickens,"nd");
  102.       break;
  103.     case 3:
  104.       strcpy(funkychickens,"rd");
  105.       break;
  106.     default:
  107.       strcpy(funkychickens,"th");
  108.     }
  109.  return funkychickens;
  110. }
  111.  
  112. struct disc_time convert(int nday, int nyear)
  113. {  struct disc_time funkychickens;
  114.    
  115.    funkychickens.year = nyear+3066;
  116.    funkychickens.day=nday;
  117.    funkychickens.season=0;
  118.    if ((funkychickens.year%4)==2)
  119.      {if (funkychickens.day==59)
  120.     funkychickens.day=-1;
  121.      else if (funkychickens.day >59)
  122.        funkychickens.day-=1;
  123.     }
  124.    funkychickens.yday=funkychickens.day;
  125.    while (funkychickens.day>=73)
  126.      { funkychickens.season++;
  127.        funkychickens.day-=73;
  128.      }
  129.    return funkychickens;
  130.   
  131.  }
  132.  
  133. void print(struct disc_time tick, char **args)
  134. { char *days[5] = { "Sweetmorn",
  135.             "Boomtime",
  136.             "Pungenday",
  137.             "Prickle-Prickle",
  138.             "Setting Orange"
  139.           };
  140.   char *seasons[5] = { "Chaos",
  141.                "Discord",
  142.                "Confusion",
  143.                "Bureaucracy",
  144.                "The Aftermath"
  145.                      };
  146.   char *holidays[5][2] = { "Mungday", "Chaoflux",
  147.                "Mojoday", "Discoflux",
  148.                "Syaday",  "Confuflux",
  149.                "Zaraday", "Bureflux",
  150.                "Maladay", "Afflux"
  151.              };
  152.   if (args[1]==NULL)
  153.     printf("Today is ");
  154.   else
  155.     printf("%s-%s-%s is ",args[1],args[2],args[3]);
  156.   if (tick.day==-1) printf("St. Tib's Day!");
  157.   else
  158.     { tick.day++;
  159.       printf("%s",days[tick.yday%5]);
  160.       printf(", the %d", tick.day);
  161.       printf("%s day of %s",ending(tick.day),seasons[tick.season]) ;
  162.     }
  163.   printf(" in the YOLD %d\n",tick.year);
  164.   if ((tick.day==5)||(tick.day==50))
  165.     { printf("Celebrate ");
  166.       if (tick.day==5)
  167.     printf("%s\n",holidays[tick.season][0]);
  168.       else
  169.     printf("%s\n",holidays[tick.season][1]);
  170.     }
  171. }
  172.