Atari Logo
Atari Computer

Hauptseite -
Welches System? -
Hardware -
Software -
Emulatoren -
Internet
MausNet
Programmieren
Verweise
Über

C

Home string.h Stringfunktionen in cookie.c math.h

13.3.2 Stringfunktionen in cjar.c

Auch für die Suche nach einem bestimmten Cookie werden die Stringfunktionen benötigt. Da sich ein Vergleich eines long schneller durchführen läßt, als ein strncmp, wurde in cookie.c nur eine Vergleichsfunktion für den Namen als long implementiert. Deshalb müssen die 4 Bytes des Cookie-Ids von der Zeichenkette in einen long kopiert werden. Dazu wird eine long Variable deklariert und mittels memcpy werden die 4 Bytes des Cookienamens an den Speicherplatz kopiert, den der long belegt. Da sich solche Tricks auf eine bestimmte Größe der Datentypen verlassen, sind sie nicht unbedingt portabel. Außerdem erschweren sie das Verständnis des Programms. In diesem Fall ist der Trick aber gerechtfertigt, weil der Name des Cookies zwar in der Regel ein Kürzel ist, aber kein nullterminierter C-String.

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

#include <stddef.h>
#include <string.h>
#include "cookie.h"
#include "cjar.h"

#define _p_cookies (void *)0x5a0l

CookieEntry *CookieJar = NULL;

int CjarInit(void)
{  long OldStack;

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

CookieEntry *CjarSearchL(long Name)
{  CookieEntry *AktCookie;

   if (CookieJar != NULL)
      CjarInit();
   if (CookieJar != NULL)
   {
      AktCookie = CookieJar;
      while (!CookieIsNullCookie(AktCookie) &&
             !CookieIsCookie(AktCookie,Name))
      {
         AktCookie++;
      }
      if (CookieIsNullCookie(AktCookie))
         return NULL;
      else
         return AktCookie;
   }
   else
      return NULL;
}

CookieEntry *CjarSearchS(char *Name)
{  long CookieNameAsLong;

   memcpy(&CookieNameAsLong, Name, 4);
   return CjarSearchL(CookieNameAsLong);
}

void CjarTraverse(CookieAction ActionFkt)
{  CookieEntry *AktCookie;

   if (CookieJar != NULL)
      CjarInit();
   if (CookieJar != NULL)
   {
      AktCookie = CookieJar;
      while (!CookieIsNullCookie(AktCookie))
      {
         (*ActionFkt)(AktCookie);
         AktCookie++;
      }
   }
}

Home string.h Stringfunktionen in cookie.c math.h


Best viewed with any browser English version not yet available.

Änderungen und Irrtümer vorbehalten. Letzte Änderung:
14 September 2001.
Home - Mail an den Webmaster - Impressum