#include <stdio.h>
#include <time.h>

main(argc,argv)
int argc;
char *argv[];
{
   FILE *stream,*fopen();
   char FileName[50],
        Month[4],
        Day[3],
        Year[3];
   char WriteLine[40][80],*TheTime;
   time_t curtime;
   unsigned int numlines,i;
   if(argc < 2) {
      printf("Usage: [33mDiary <directory>\n[0m\nWhere directory is where to put the output of the diary program.\nIT MUST END IN : OR /!! EXAMPLE: DH0:DIARY/\nYou can put this in a batch file or alias to make it easier (Example):\nDIARY DH0:DIARY/\n"
             "\n[32mThere will be a different file for each day, but you can add on to it\nas much as you want during the day.[0m\n");
      exit(5);
   }
   time(&curtime);
   TheTime=ctime(&curtime);
   for(i=0;i<3;i++)
      Month[i]=toupper(TheTime[i+4]);
   Month[3]='\0';
   for(i=0;i<2;i++)
      Day[i]=TheTime[i+8];
   Day[2]='\0';
   for(i=0;i<2;i++)
      Year[i]=TheTime[i+22];
   Year[2]='\0';
   sprintf(FileName,"%s%s-%s-%s\0",argv[1],Day,Month,Year);
   printf("[H[JDiary v1.0: Written by Captain Spock of Starship BBS (702) 361-2725\n\nFile = %s:\nType 'X' on a blank line to end input.\n======================================\n\n",FileName);
   printf("%s---------------------------------------------------------------------------\n",TheTime);
   for(;;) {
      gets(WriteLine[numlines]);
      if(toupper(WriteLine[numlines][0]) == 'X') break;
      ++numlines;
   }
   if(numlines==0) {
      printf("Aborted..\n");
      exit(10);
   }
   if(!(stream=fopen(FileName,"a"))) {
      printf("Couldn't open diary file: %s\n",FileName);
      exit(5);
   }
   fprintf(stream,"%s---------------------------------------------------------------------------\n",TheTime);
   for(i=0;i<numlines;i++)
      fprintf(stream,"%s\n\0",WriteLine[i]);
   fputc('\n',stream);
   fclose(stream);
   printf("Saved..\n");
}
