/* Dieses Programm demonstriert die Benutzung der
 * Funktion FormatDate()
 * Verwendeter C-Compiler: SAS-C 6.5x
 */
#include <exec/types.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/locale.h>
#include <proto/utility.h>
#include <stdio.h>

struct Library *LocaleBase=NULL;
struct Locale *locale;

/* Diese Routine wird vom Betriebssystem angesprungen.
 * Wir leiten den Aufruf schnurstracks an unsere eigene
 * Routine weiter */
ULONG __saveds __asm hookEntry(
             register __a0 struct Hook *h, 
             register __a2 void *obj, 
             register __a1 void *msg)
{
  return((*h->h_SubEntry) (h,obj,msg));
}
/* Füllt die Hook-Struktur aus */
void InitHook(struct Hook *hook,
              ULONG (*func)(), 
              void *data)
{
  if( hook ) {
    hook->h_Entry = (ULONG (*)()) hookEntry;
    hook->h_SubEntry = func;
    hook->h_Data = data;
  }
}
/* Erhält zeichenweise Informationen von FormatDate()
 * der Locale-Library und gibt sie aus */
ULONG __saveds __asm My_FormatDate(
  register __a0 struct Hook *h, 
  register __a2 void *obj, 
  register __a1 void *msg) /* Hier steht das Zeichen */
{
  if( msg != 0 ) printf("%c",msg);
  else           printf("\n");
  return 1;
}
void main(ULONG argc, char **argv)
{
  struct Hook formdate;
  if( argc ) {
    /* Nur vom CLI zu starten */
    LocaleBase=OpenLibrary("locale.library",38);
    if( LocaleBase ) {
      locale=OpenLocale(NULL);
      if( locale ) {
        struct DateStamp ds;
        /* Die DateStamp-Struktur wird von FormatDate()
         * benötigt */
        DateStamp(&ds);
        /* Einrichten unseres Hooks */
        InitHook(&formdate, My_FormatDate, NULL);
        /* Aufruf der Routine. Die Ausgabe erfolgt
         * in Ma_FormatDate() */
        FormatDate(locale,locale->loc_DateFormat,
                   &ds,&formdate);
        CloseLocale( locale );
      }
      CloseLibrary(LocaleBase);
    } else printf("Locale-Library nicht vorhanden\n");
  }
}
