[DUG] C code help

Brian Wrigley bswrigley at xtra.co.nz
Fri Jul 14 14:33:05 NZST 2006


No, that function won't change the value in the flag. It just tests it and returns True if that field of a global variable (m_nFieldFlags) contains the value "Text_UTF8" and returns False if that field contains any of the other 3 values.

What is it that your own program needs to do with this field? Just determine the value? Or do you need to set or change it and pass the resulting entire flags word (which possibly includes other fields which should not be changed) back to an external process or device?

Regards,
Brian
  ----- Original Message ----- 
  From: Ross Levis 
  To: NZ Borland Developers Group - Delphi List 
  Sent: Friday, July 14, 2006 10:41 AM
  Subject: Re: [DUG] C code help


  Hi Brian

  Thanks for your detailed reply.

  I wondered if I should have included the code used to test the value.  Here is one such function

      BOOL GetIsUTF8Text() { return ((m_nFieldFlags & TAG_FIELD_FLAG_DATA_TYPE_MASK) == TAG_FIELD_FLAG_DATA_TYPE_TEXT_UTF8) ? TRUE : FALSE; }

  I see that it is ANDing the Mask.  There are no other flags using the same byte of this 4 byte flag.

  Does this affect the value that will be found/stored in this flag for a Binary type?

  Thanks,
  Ross.
    It's a two-bit field by the look of it, using bits 1 and 2 of the word (numbering from bit 0 = least significant to 31 = most significant).
    6 (bit pattern 110) is the mask, ie it's used with a bitwise AND to select just those two bits from the word.
    the four values of the two-bit field are apparently:
    0 = Text UTF8
    1 = binary
    2 = External Info
    3  - reserved

    So not just a simple 1-bit flag like I thought from what you posted in the first message.

    With the various values of that field the whole word might look like:
    0000 0000 = Text UTF8
    0000 0002 = binary
    0000 0004 = External Info
    0000 0006  - reserved

    Except, we don't know what might be in the rest of the word. Probably not zeroes, so the values you are interested in will be combined with other fields. Possibly even, that 3-bit field is repeated several times in the word, with additional masking and shifting being used to pick fields out. In your first message, you also showed:

    #define APE_TAG_FLAG_CONTAINS_FOOTER            (1 << 30)

    which suggests bit 30 is also used as a one-bit flag. But whether this is in the same word or not can't necessarily be determined from the #defines. You'll probably need to find the code that masks, sets and tests these fields to be sure how they're used, for example look for something like:

        value = (word & TAG_FIELD_FLAG_DATA_TYPE_MASK) >> 1;

    to extract the value of the field from the word;

    or, to set the value to, say "External Info":

        word &= ~TAG_FIELD_FLAG_DATA_TYPE_MASK;
        word |= TAG_FIELD_FLAG_DATA_TYPE_EXTERNAL_INFO;

    To achieve the same operations in Delphi, use the bitwise logical operators not, and, or, xor, shl and shr. Snipped from the help screen:


----------------------------------------------------------------------------

    The following logical operators perform bitwise manipulation on integer operands. For example, if the value stored in X (in binary) is 001101 and the value stored in Y is 100001, the statement

    Z := X or Y;

    assigns the value 101101 to Z.

          Operator  Operation  Operand types  Result type  Examples  
          not  bitwise negation  integer  integer  not X  
          and  bitwise and  integer  integer  X and Y  
          or  bitwise or  integer  integer  X or Y  
          xor  bitwise xor  integer  integer  X xor Y  
          shl  bitwise shift left  integer  integer  X shl 2  
          shr  bitwise shift right  integer  integer  Y shl I 

    The following rules apply to bitwise operators.

    The result of a not operation is of the same type as the operand.
     If the operands of an and, or, or xor operation are both integers, the result is of the predefined integer type with the smallest range that includes all possible values of both types.
     The operations x shl y and x shr y shift the value of x to the left or right by y bits, which is equivalent to multiplying or dividing x by 2^y; the result is of the same type as x
    . For example, if N stores the value 01101 (decimal 13), then N shl 1 returns 11010 (decimal 26).

----------------------------------------------------------------------------



    Hope some of this helps clarify things a bit and doesn't just muddy it further,

    Brian



----------------------------------------------------------------------------


    _______________________________________________
    Delphi mailing list
    Delphi at ns3.123.co.nz
    http://ns3.123.co.nz/mailman/listinfo/delphi



------------------------------------------------------------------------------


  _______________________________________________
  Delphi mailing list
  Delphi at ns3.123.co.nz
  http://ns3.123.co.nz/mailman/listinfo/delphi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ns3.123.co.nz/pipermail/delphi/attachments/20060714/99373f1b/attachment-0001.html


More information about the Delphi mailing list