/*
   <p><i>disptime</i> - Display the current date and time</p>    

                Release history:
                    
                1.0 -           Initial release
                1.1 - Aug 1992  copyright notice added
                1.2 - Aug 1992  autotime(), autodate() used
                1.3 - Feb 2002  ported to Linux
                1.4 - Jan 2003  added -b option

   <kbd>
   <b>environ - C programming support functions</b><br>
   Copyright (C) 2005  Martin C Gregorie
   
   This program is free software; you can redistribute it and/or
   modify it under the terms of the Lesser GNU General Public License.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
  
   You should have received a copy of the Lesser GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   </kbd>
  
   <p>Contact Martin Gregorie at <i>martin@gregorie.org</i></p>
*/

#define VERSION       "1.4"
#define COPYRIGHT     "(c) M.C.Gregorie, 1992"

#include "environ.h"

main(int argc, char **argv)
{
    int opt;
    int binout;

    time_t      timer;
    struct tm   *tbp;
    CHARDATE    datestr;
    CHARTIME    timestr;

    setprog(argv[0]);

    /*
    	Prevent confusion between "-?" and any other invalid option
    */  
    optbad = '!';
    binout = 0;
    while ((opt = getopt(argc,argv,"?b")) != EOF)
    {
        if (opt == 'b')
        {
            binout = 1;
        }
        else
        if (opt == '?')
        {
            printf("\ndisptime v%s %s\n\n",VERSION,COPYRIGHT);
            printf("Syntax:   disptime\n");
            printf("Function: Display the current date and time\n");
            printf("Options:  none\n");
            return(0);
        }
        else
        {
            error(progname(), "Invalid option supplied", "");
        }
    }            

    /*
        Get the time & date from the system
    */
    timer = time(NULL);         /* read the clock */

    /* 
        Output the time
    */
    if (binout)
    {
       /*
          Output binary time (seconds since the epoc start in UMT).
       */
       printf("%ld\n", timer);
    }
    else
    {
       /*
          Split out elements into tbp struct, use autodate and autotime
          to format them and output the result;
       */
       tbp = localtime(&timer);
       datestr = autodate(tbp,DDMMMYY, 0);
       timestr = autotime(tbp);
       printf("\n%s  %s\n",datestr,timestr);
    }
    return(0);
}

