PA_ByteSwapTokens

4D - Documentation   Français   English   German   4D Plugin API, Command Theme List   4D Plugin API, Command Alphabetical List   Back   Previous   Next

version 2003


PA_ByteSwapTokens (tokens; len)

ParameterTypeDescription
tokenschar *Tokens to byteswap
lenlongLength of the tokens' buffer

Description

The routine PA_ByteSwapTokens allows the 4D plug-in to byte swap a line of 4th Dimension code that has been tokenized (using PA_Tokenize) on a platform whose byte ordering is different than the platform where the 4D plug-in is running.

Before the call, pass the text of the tokens in Tokens and its length in len.

After the call, Tokens holds the byte swapped tokens.

A 4D plug-in should call this routine before detokenizing or executing tokens that have been built on another platform.

Example

For example, a plug-in could save the tokens in a structure that holds private data, such as a platform flag (say, 'ABCD' under MacOS). Before detokenizing or executing the tokens, the plug-in checks the signature, and byteswaps the tokens if necessary.

   #define      TOKENS_FLAG            'ABCD'
   #define      BYTESWAPPED_TOKENS_FLAG   'DCBA'
      
   void SaveTokens ( Stream* stream, char* tokens, long len )
   {
      myWriteLongToStream( stream, TOKENS_FLAG );
      myWriteLongToStream( stream, len );
      myWriteBufferToStream( stream, tokens, len );
   }
   
   char* LoadTokens( Stream* stream,  )
   {
      long byteswap, len;
      char*tokens = 0;
      
      byteswap = myReadLongInStream( stream );
      len = myReadLongInStream( stream );
      if ( byteswap == BYTESWAPPED_TOKENS_FLAG )
         ByteSwapLong( &len );
      tokens = malloc( len );
      if  ( tokens )
      {
         myReadBufferInStream( stream, tokens, len );
         if ( byteswap == BYTESWAPPED_TOKENS_FLAG )   // byteswap the tokens if needed
            PA_ByteSwapTokens( loadedTokens.fTokens, loadedTokens.fLen );
      }
      return tokens;
   }

See Also

PA_ExecuteTokens, PA_ExecuteTokensAsFunction, PA_Tokenize.

Error Handling

Use PA_GetLastError to see if an error occurred


4D - Documentation   Français   English   German   4D Plugin API, Command Theme List   4D Plugin API, Command Alphabetical List   Back   Previous   Next