#ifdef __TURBOC__
#include <tos.h>
#else
#ifdef __GNUC__
#include <osbind.h>
#else
#include <tosbind.h>
#endif
#endif
#include <stdio.h>

#define _p_cookies (void *)0x5a0l
#define NULL_COOKIE 0l

typedef struct cookie_entry {
   union {
      unsigned long name_long;
      char name_array[4];
   } name;
   unsigned long value;
} CookieEntry;

CookieEntry *GetCookieJar(void)
{  long OldStack;
   CookieEntry *CookieJar;

   OldStack = Super(0L);
   CookieJar = *((CookieEntry**)_p_cookies);
   Super((void *)OldStack);
   return CookieJar;
}

void PrintCookie(CookieEntry *Cookie)
{
   printf("Name des Cookies: %d\n", Cookie->name.name_long);
   printf("Wert des Cookies: %d\n", Cookie->value);
}

int IsNullCookie(CookieEntry *Cookie)
{
   return (Cookie->name.name_long == NULL_COOKIE);
}

void TraverseCookieJar(CookieEntry *Cookie)
{
   while (!IsNullCookie(Cookie))
   {
      PrintCookie(Cookie);
      Cookie++;
   }
}

int main(void)
{  CookieEntry *CookieJar;

   CookieJar = GetCookieJar();
   if (CookieJar == (CookieEntry *)0)
      printf("Dieses System hat keinen Cookie Jar\n");
   else
      TraverseCookieJar(CookieJar);
   return 0;
}
