/*****

                                 FileDate
                          written by Joseph Hodge

         The purpose of this utility is to allow a person to change the file
     dates of any files he/she chooses, I am sure there is probably utilities
     like this around somewhere, but I have not seen them. This version does
     not support wildcards, perhaps future versions will.

*****/

#include <exec/types.h>
#include <dos/dos.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>



void sr(char *s);

/******* this utility uses the Rom Dos.library functions SetFileDate() and
         StrToDate() , which are ideal because they do error checking for us
         if the commandline arguments are invalid
*******/

main(int argc,char *argv[])
{
  struct DateTime dt;
  char mydate[256];
  char mytime[256];
  char FileName[256];;
  if(argc<3)
  {
     printf("FileDate, version 1.0, written by Joseph Hodge\n");
     printf("usage: FileDate <PathName> <mm/dd/yy> [hh:mm:ss]\n");
     printf("   ie: FileDate ram:temp 03-02-92 23:00:01\n");
     printf("\n");
     exit(0);
  }
 
  strcpy(FileName,argv[1]);
  strcpy(mydate,argv[2]); 
  strcpy(mytime,"");

  if(argc==4) { strcpy(mytime,argv[3]); sr(mytime); } 
  
  sr(mydate);



  /**** Prepare DateTime structure so we can use the Dos library in Rom to
        do the conversion to a DateStamp structure
   ****/

  dt.dat_StrDate=(UBYTE *)mydate;
  dt.dat_StrDay=NULL;
  dt.dat_StrTime= (mytime[0]=='\0') ? (UBYTE *)"00:00:01":(UBYTE *)mytime;
  dt.dat_Flags=NULL;
  dt.dat_Format=FORMAT_USA;

  /**** StrToDate to create us a DateStamp for the SetFileDate rom function ****/
  if(StrToDate(&dt))
  {
    if(!SetFileDate(FileName,(struct DateStamp *)&(dt.dat_Stamp)))
    {
      printf("Error, cannot set the date\n");
    }else printf("Date changed to %s\n",mydate);
  }else
  {
    printf("Error, Invalid date\n");
  }
  exit(0);
}


/***** sr() Strips trailing ascii characters from a given string that are below
       the ASCII value of 31
*****/
