/*
   <p><i>national</i> - Test harness for <i>country()</i>.</p>

   <p>Also used to syntax check <i>/etc/country</i>.</p>

   <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      "2.0"
#define COPYRIGHT    "(c) M.C.Gregorie, 1996"

#include "environ.h"

#ifdef MSDOS
#include <dos.h>
#endif

#ifdef LINUX
#include <stdlib.h>
#endif

main(int argc, char **argv)
{
    time_t         timer;
    struct tm      *tbp;
    CHARDATE       datestr;
    CHARTIME       timestr;
    struct COUNTRY info;
    int            code;
    int            i;
    int            year;

    setprog(argv[0]);
    
    for (i=1; i<argc; i++)
        if (strcmp(argv[i],"-?") == 0 || strcmp(argv[i],"/?") == 0)
        {
            printf("\nnational v%s %s\n\n",VERSION,COPYRIGHT);
            printf("Syntax:   national <country code> <year>\n");
            printf("          The country code must be present if the\n");
            printf("          year is supplied. Years less than 80 are\n");
            printf("          assumed to be in the next century\n");
            printf("Function: Check country data\n");
            printf("Options:  none\n");
            return(0);
        }

    if (argc<2)
        code = 0;
    else
        code = atoi(argv[1]);
    if (code<0)
    {
        country(-code,(struct COUNTRY *)-1);
        country(0,&info);
    }
    else
        country(code, &info);

    if (argc>=3)
    {
        year = atoi(argv[2]);
        if (year<0 || year>99)
        {
            printf("Year must be 00-99\n");
            exit(1);
        }
    }

    printf("National information for country code %d\n\n",code);
    printf("Date format: %d\n",info.co_date);
    printf("Currency:    %s\n",info.co_curr);
    printf("Thousands:   %s\n",info.co_thsep);
    printf("Decimal sep: %s\n",info.co_desep);
    printf("Date sep:    %s\n",info.co_dtsep);
    printf("Time sep:    %s\n",info.co_tmsep);
    printf("Curr.style:  %d\n",info.co_currstyle);
    printf("Curr.places: %d\n",info.co_digits);
    printf("Time format: %d\n",info.co_time);
    printf("Case map:    %ld\n",info.co_case);
    printf("Data sep:    %s\n",info.co_dasep);
    /*
        Now check out autodate() and autotime() using the 
        system time & date.
    */
    timer = time(NULL);            /* read the clock */
    tbp = localtime(&timer);    /* split out elements */
    if (argc>=3)
        tbp->tm_year = year;

    printf("\nShow formats for date and time\n\n");
    datestr = autodate(tbp,AUTOFMT, 0);
    timestr = autotime(tbp);
    printf("Default formats:         %s  %s\n",datestr,timestr);
    if (code<0)
        code = -code;
    datestr = autodate(tbp,MANUAL,code);
    timestr = autotime(tbp);
    printf("Formats for code %03d:    %s  %s\n",code,datestr,timestr);
    datestr = autodate(tbp,DDMMMYY, 0);
    printf("Character month:         %s\n",datestr);

    return (0);
}
