#ifndef __INC_LOCTEST_C
#define __INC_LOCTEST_C
/*******************************************************************
 $CRT 21 Nov 1996 : hp

 $AUT Holger Burkarth
 $DAT >>loctest.c<<   29 Jan 1997    13:52:07 - (C) ProDAD
*******************************************************************/

//##ex mcpp:cppc -gs -o pos:pos/ex/loctest p:pLib/StartCode.o p:/pOS_RKRM/pLocale/loctest.c p:pLib/StdIO.o -l pOSStub -l pOS -l CPPList -i p:

/***********************************************************
  pOS programing example - Copyright (C) 1995-97 proDAD

  This code was written as an easy to understand example,
  how to program pOS features. It is provided 'as-is',
  without any express or implied warranty.

  Permission is hereby granted to use, copy and modify
  this source code for any purpose, without fee, subject
  to the following conditions:

    (1) This notice may not be removed or altered from any
        source distribution.

    (2) Altered source versions must be plainly marked as
        such, and must not be misrepresented as being
        the original source code.

    (3) If only executable code is distributed, then the
        accompanying documentation have to state that
        "this software is based in part on examples of
        the pOS developer packet".

    (4) Permission for use of this code is granted only
        if the user accepts full responsibility for any
        undesirable consequences. proDAD accept NO LIABILITY
        for damages of any kind.

  ©proDAD
***********************************************************/

#include <p:pExec/Types.h>
#include <p:pExec/CallBack.h>
#include <p:pDOS/ArgTags.h>
#include <p:pDOS/DosArgs.h>
#include <p:pDOS/Date.h>
#include <p:pLocale/Catalog.h>
#include <p:pLocale/Locale.h>
#include <p:pLocale/LocTags.h>
#include <p:pProto/pExec2.h>
#include <p:pProto/pDOS2.h>
#include <p:pProto/pLocale2.h>

#ifdef _____ME_____
  #include "grund/inc_string.h"
  #include "grund/inc_stdio.h"
#else
 #ifdef __cplusplus
 extern "C"  {
 #endif
  #include <string.h>
  #include <stdio.h>
 #ifdef __cplusplus
 }
 #endif
#endif


struct pOS_Library *gb_LocaleBase;


const CHAR *HelpText=
""
;

const CHAR *PrgHeader=
"Little Demo For pLocale.library";

const CHAR *PrgVerText=
"$VER: 1.0 ("__DATE2__") (Copyright 1996-97 by proDAD) (Created by Holger Papajewski)";



const CHAR *CmpTestArray[] =
{
  "test", "Test",
  "Bar",  "Bär",
  "Bär",  "Beere",
  "heiß", "heist",
  NULL, NULL
};


const pOS_CatalogItem gb_defStrs[] =
{
  { 0x01000000, "*** defString0 ***" },
  { 0x01000001, "*** defString1 ***" },
  { 0x01000002, "*** defString2 ***" },
  { 0x01000003, "*** defString3 ***" },
  { 0x01000009, "*** defString9 ***" },
  { 0x0100000a, "*** defString10 ***" },
  { 0x0100000b, "*** defString11 ***" },
  { 0, NULL },
};

/*----------------------------------
moegliche Callbackfunktion fuer pOS_FormatDate()
-----------------------------------*/
VOID FormatDateCB(_R_A0 const pOS_Callback *cb,
  _R_A1 pOS_FormatDateCBData *data )
{
  if(cb->cb_UserData[1] > 1) {
    cb->cb_UserData[1]--;
    *((CHAR*)cb->cb_UserData[0]) = data->fdd_FmtData.rdft_Data;
    (CHAR*)cb->cb_UserData[0]++;
    *((CHAR*)cb->cb_UserData[0]) = '\0';
  }
}


/*----------------------------------
-----------------------------------*/
extern "C"
int main( void )
{
  pOS_Locale     *Loc;
  pOS_Catalog    *Cat;

  pOS_DosArgs  *Args;
  ULONG Ops[1] = {0};
  ULONG cnt;
  CHAR *str = "abcdef ABCDEF äüöÄÜÖ ß?_.,";
  CHAR *tmp;

  Args = pOS_ReadDosArgs( "",Ops,sizeof(Ops)/sizeof(ULONG),
    ARGTAG_PrgHeaderText, (ULONG)PrgHeader,    /* kurze Programm-Beschreibung */
    ARGTAG_HelpText,      (ULONG)HelpText,     /* Help-Texte */
    ARGTAG_PrgVerText,    (ULONG)PrgVerText,   /* VER-String */
    TAG_DONE);

  if(Args) {
    if(gb_LocaleBase = pOS_OpenLibrary("plocale.library",0)) {

      /* SystemDefaultLocale oeffnen */
      Loc = pOS_OpenLocale("Env:sys/locale.prefs");

      if( Loc ) {
        printf("Locale Structure\n");
        printf("|%s|\n",Loc->loc_LocaleName);
        printf("|%s|\n",Loc->loc_LanguageName);
        printf("|%s|\n",Loc->loc_CountryCode);
        printf("|%ld|\n",Loc->loc_TelephoneCode);
        printf("|%ld|\n",Loc->loc_GMTOffset);
        printf("|%ld|\n",Loc->loc_MeasuringSystem);
        printf("|%ld|\n",Loc->loc_CalendarType);
        printf("|%s|\n",Loc->loc_DateTimeFormat);
        printf("|%s|\n",Loc->loc_DateFormat);
        printf("|%s|\n",Loc->loc_TimeFormat);
        printf("|%s|\n",Loc->loc_ShortDateTimeFormat);
        printf("|%s|\n",Loc->loc_ShortDateFormat);
        printf("|%s|\n",Loc->loc_ShortTimeFormat);
        printf("|%s|\n",Loc->loc_DecimalPoint);
        printf("|%s|\n",Loc->loc_GroupSeparator);
        printf("|%s|\n",Loc->loc_FracGroupSeparator);
        printf("|%s|\n",Loc->loc_MonDecimalPoint);
        printf("|%s|\n",Loc->loc_MonGroupSeparator);
        printf("|%s|\n",Loc->loc_MonFracGroupSeparator);
        printf("|%s|\n",Loc->loc_CurrencySymbol);
        printf("|%s|\n",Loc->loc_SmallCurrencySymbol);
        printf("|%s|\n\n",Loc->loc_IntCurrencySymbol);

        printf("Locale Strings\n");
        for( cnt=1; cnt<LOCALE_MAXSTR; cnt++ )
          printf("%03ld: |%s|\n",cnt,pOS_GetLocaleStr(Loc,cnt));

        /* LocaleToUpper bzw. LocaleToLower Test */
        printf("\nOrginal: %s",str);
        printf("\nToUpper: ");
        tmp = str;
        while( *tmp )
          putc(pOS_LocaleToUpper(Loc,*tmp++),stdout);

        printf("\nToLower: ");
        tmp = str;
        while( *tmp )
          putc(pOS_LocaleToLower(Loc,*tmp++),stdout);

        puts("");

        if(Cat = pOS_OpenCatalog(NULL,"sys/sys.catalog",
              LOCTAG_DefStrings, (ULONG)gb_defStrs,
              LOCTAG_Version, 1,
              TAG_DONE)){

          ULONG x;

          printf("\nCatalog Contents:\n");
          for(x=0x01000000;x<0x01000012;x++)
            printf("%03lx: |%s|\n",x,pOS_GetCatalogStr(Cat,x,"*** no entry ***"));

          pOS_CloseCatalog(Cat);
        }
        else printf("Error open Catalog |%s|.\n","sys/sys.catalog");


        /* StrnCmp test */

        const CHAR **strs = CmpTestArray;

        printf("\nStrnCmp-Test\n");
        while( *strs ) {
          SLONG ret;

          ret = pOS_StrnCmp(Loc,*strs,*(strs+1),-1);

          if( ret < 0 )
            printf("|%s| ist kleiner als |%s|\n",*strs,*(strs+1));
          else if( ret > 0 )
            printf("|%s| ist größer als |%s|\n",*strs,*(strs+1));
          else
            printf("|%s| ist gleich |%s|\n",*strs,*(strs+1));

          strs += 2;
        }


        strs = CmpTestArray;

        printf("\nStrniCmp-Test\n");
        while( *strs ) {
          SLONG ret;

          ret = pOS_StrniCmp(Loc,*strs,*(strs+1),-1);

          if( ret < 0 )
            printf("|%s| ist kleiner als |%s|\n",*strs,*(strs+1));
          else if( ret > 0 )
            printf("|%s| ist größer als |%s|\n",*strs,*(strs+1));
          else
            printf("|%s| ist gleich |%s|\n",*strs,*(strs+1));

          strs += 2;
        }

        printf("\nDatum formatiert mit Locale->loc_DateTimeFormat\n");
        CHAR DateBuffer[128]="";
        pOS_DateStamp DS;
        pOS_Callback  FmtCB={{0},0,0,0};

        FmtCB.cb_Node.ln_Type=NTYP_CALLBACK;
        FmtCB.cb_Code=(ULONG(*)(_R_A0 const pOS_Callback*,_R_A1 APTR))FormatDateCB;
        FmtCB.cb_UserData[0]=(ULONG)DateBuffer;
        FmtCB.cb_UserData[1]=128;
        pOS_GetDateStamp( &DS );

        pOS_FormatDate(Loc,"%C",&DS,&FmtCB);
        printf("|%s|\n",DateBuffer);


        printf("\nDatum formatiert mit Locale->loc_ShortDateTimeFormat\n");
        cnt=pOS_FormatDateStr(Loc,"%c",&DS,DateBuffer,128);
        printf("|%s|   length: %ld\n",DateBuffer,cnt);

        cnt=pOS_FormatDateStr(Loc,"%a, den %e.%b.%Y",&DS,DateBuffer,128);
        printf("\n|%s|   length: %ld\n",DateBuffer,cnt);

        pOS_CloseLocale(Loc);
      }
      else printf("Error open Locale.\n");

      pOS_CloseLibrary(gb_LocaleBase);
    }
    else printf("Error open Locale.library.\n");

    pOS_DeleteDosArgs(Args);
  }
  return(0);
}


#endif
