import java.io.*;
import java.util.*;

/**
 * Remember.java - a program that compares todays date to tab
 * delimeted files of important dates.
 * @author Andrew Herrington
 * @date 1/22/06
 * @lab Lab4
 * @section 1
 */


public class IO_herrinaj_Remember
{
    private static Scanner        dateScanner;
    private static PrintWriter    screen;
    
	/** ========================================================
	* 
	*  main method - Creates the variables needed, prints todays
	*  dates and loops through all of the arguements from the
	*  command line and calls process dates on the files
	*              
	*  @param args   command line arguments used to take 
	*  in file names
	*/

    public static void main(String[] args)
    {
       GregorianCalendar        today;
       String                   name;       
       File						dates;

       
       today    = new GregorianCalendar();
       screen   = new PrintWriter(System.out);


       
       screen.printf(Locale.US, "\nToday's Date: %1$te %1$tB %1$tY\n", today);
       screen.flush();       
       
       System.out.println(args.length);

       //loops while there are still more inputs from the
       //command line
       for(int i = 0; i<args.length; i++)
       {
    	   dates = new File(args[i]);
    	   try 
    	   {
    		   dateScanner = new Scanner(dates);
    	   } catch (FileNotFoundException fnfe) 
    	   {
    		   screen.println("File not found.");
    		   fnfe.printStackTrace();
    	   } //end catch

    	   processDates(today);
       }//end for
       
       } //end main
    
	/** ========================================================
	* 
	* processDates - scans through a tab delimeted file of
	* important dates and looks for dates that correspond to the
	* date passed to it.  
	*              
	*  @param GregorianCalendar today - today's dates
	*/

    private static void processDates(GregorianCalendar today)
    {
       int           day, month;              
       String        name;
       

       // Use the '\t' (tab) and '/' characters as delimiters
       dateScanner.useDelimiter("[\t/]");
          
          
       while (dateScanner.hasNext())
       {
          month = dateScanner.nextInt();
          day   = dateScanner.nextInt();
          name  = dateScanner.nextLine();

          if ((month == (today.get(Calendar.MONTH)+1)) && 
              (day   == today.get(Calendar.DAY_OF_MONTH)))
          {
             screen.printf("%s\n", name);
             screen.flush();
          }//end if
       }//end while
    } //end processDates
    

} //end remember
