How to translate this union ?

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

How to translate this union ?

ik-6
Hello list,

I'm trying to translate the following union to Pascal, but I do not understand it, and so does h2pas.
How to translate it ?

Thanks,

Ido


LINESIP - Opening the source for communication
http://www.linesip.com
http://www.linesip.co.il



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

RE : [fpc-pascal] How to translate this union ?

Ludo Brands
Message
Can you post the original c code? You point to a file that seems to be a reworked output from h2pas. As it is now, it indeed doesn't make any sense. I would think the su_len,su_family,su_port should make up a record but they aren't.
 
I suggest you move the #defines inside the union declaration to somewhere before the union declaration. It'll double up the ifdef's but make the code so much more readable.
 
 
-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de ik
Envoyé : vendredi 29 avril 2011 22:15
À : FPC-Pascal users discussions
Objet : [fpc-pascal] How to translate this union ?

Hello list,

I'm trying to translate the following union to Pascal, but I do not understand it, and so does h2pas.
How to translate it ?

Thanks,

Ido


LINESIP - Opening the source for communication
http://www.linesip.com
http://www.linesip.co.il



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: RE : [fpc-pascal] How to translate this union ?

ik-6



On Sat, Apr 30, 2011 at 10:18, Ludo Brands <[hidden email]> wrote:
Can you post the original c code? You point to a file that seems to be a reworked output from h2pas. As it is now, it indeed doesn't make any sense. I would think the su_len,su_family,su_port should make up a record but they aren't.

Actually it's my own code :) But here is the original header, line 157. The question is how can I create this lines ?

 
 
I suggest you move the #defines inside the union declaration to somewhere before the union declaration. It'll double up the ifdef's but make the code so much more readable.

Thanks,

Ido
 
 
 
-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de ik
Envoyé : vendredi 29 avril 2011 22:15
À : FPC-Pascal users discussions
Objet : [fpc-pascal] How to translate this union ?

Hello list,

I'm trying to translate the following union to Pascal, but I do not understand it, and so does h2pas.
How to translate it ?

Thanks,

Ido


LINESIP - Opening the source for communication
http://www.linesip.com
http://www.linesip.co.il



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

RE : RE : [fpc-pascal] How to translate this union ?

Ludo Brands
In reply to this post by Ludo Brands
Message
Forget my previous reply. I found the original header file on sourceforge.
 
I have alse a better understanding now of what the code is supposed to do: in case DOCUMENTATION_ONLY is not defined,  a reference to, for example, su_sockaddr_u.su_family will be subsstituted by su_sockaddr_u.susa.sa_family.
You could use macros and do a {$define su_family:=susa.sa_family} with the following limitations:
- if you have variables or other record members named su_family, not part of the su_sockaddr_u record, they will be renamed also.
- it works only for the units that include your .inc file.
 
-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de Ludo Brands
Envoyé : samedi 30 avril 2011 09:18
À : 'FPC-Pascal users discussions'
Objet : RE : [fpc-pascal] How to translate this union ?

Can you post the original c code? You point to a file that seems to be a reworked output from h2pas. As it is now, it indeed doesn't make any sense. I would think the su_len,su_family,su_port should make up a record but they aren't.
 
I suggest you move the #defines inside the union declaration to somewhere before the union declaration. It'll double up the ifdef's but make the code so much more readable.
 
 
-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de ik
Envoyé : vendredi 29 avril 2011 22:15
À : FPC-Pascal users discussions
Objet : [fpc-pascal] How to translate this union ?

Hello list,

I'm trying to translate the following union to Pascal, but I do not understand it, and so does h2pas.
How to translate it ?

Thanks,

Ido


LINESIP - Opening the source for communication
http://www.linesip.com
http://www.linesip.co.il



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

RE : RE : RE : [fpc-pascal] How to translate this union ?

Ludo Brands
Message
Using macros, the translation looks like
 
{$MACRO ON}
{$ifndef DOCUMENTATION_ONLY}
{$if SU_HAVE_SOCKADDR_SA_LEN <>0}
  {$define su_len:=su_sa.sa_len}
{$else}
  {$define su_len:=su_array[0]}
{$endif}
{$define su_family:=su_sa.sa_family}
{$define su_port:=su_sin.sin_port}
{$define su_scope_id:=su_array32[6]}
{$endif}
type
    su_sockaddr_u = record
        case longint of
          {$ifdef DOCUMENTATION_ONLY}
          0 : ( su_len : byte );
          1 : ( su_family : byte );
          2 : ( su_port : word );
          {$else}
          3 : ( su_dummy : smallint );
          {$endif}
          4 : ( su_array : array[0..31] of char );
          5 : ( su_array16 : array[0..15] of word );
          6 : ( su_array32 : array[0..7] of longword );
          7 : ( su_sa : sockaddr );
          8 : ( su_sin : sockaddr_in );
          {$if SU_HAVE_IN6 <>0}
          9 : ( su_sin6 : sockaddr_in6 );
          {$endif}
          {$ifdef DOCUMENTATION_ONLY}
          10 : ( su_scope_id : longword );
          {$endif}
        end;
-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de Ludo Brands
Envoyé : samedi 30 avril 2011 10:29
À : 'FPC-Pascal users discussions'
Objet : RE : RE : [fpc-pascal] How to translate this union ?

Forget my previous reply. I found the original header file on sourceforge.
 
I have alse a better understanding now of what the code is supposed to do: in case DOCUMENTATION_ONLY is not defined,  a reference to, for example, su_sockaddr_u.su_family will be subsstituted by su_sockaddr_u.susa.sa_family.
You could use macros and do a {$define su_family:=susa.sa_family} with the following limitations:
- if you have variables or other record members named su_family, not part of the su_sockaddr_u record, they will be renamed also.
- it works only for the units that include your .inc file.
 
-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de Ludo Brands
Envoyé : samedi 30 avril 2011 09:18
À : 'FPC-Pascal users discussions'
Objet : RE : [fpc-pascal] How to translate this union ?

Can you post the original c code? You point to a file that seems to be a reworked output from h2pas. As it is now, it indeed doesn't make any sense. I would think the su_len,su_family,su_port should make up a record but they aren't.
 
I suggest you move the #defines inside the union declaration to somewhere before the union declaration. It'll double up the ifdef's but make the code so much more readable.
 
 
-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de ik
Envoyé : vendredi 29 avril 2011 22:15
À : FPC-Pascal users discussions
Objet : [fpc-pascal] How to translate this union ?

Hello list,

I'm trying to translate the following union to Pascal, but I do not understand it, and so does h2pas.
How to translate it ?

Thanks,

Ido


LINESIP - Opening the source for communication
http://www.linesip.com
http://www.linesip.co.il



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: RE : RE : RE : [fpc-pascal] How to translate this union ?

Sven Barth-2
Question:

In case of DOCUMENTATION_ONLY not defined, does

su_sockaddr_u = record
(...)
   1 : ( su_sa.sa_family : byte )
(...)
end;

really compile?
(From what I know about Pascal I would say: no)

Regards,
Sven

On 30.04.2011 10:53, Ludo Brands wrote:

> Using macros, the translation looks like
> {$MACRO ON}
> {$ifndef DOCUMENTATION_ONLY}
> {$if SU_HAVE_SOCKADDR_SA_LEN <>0}
> {$define su_len:=su_sa.sa_len}
> {$else}
> {$define su_len:=su_array[0]}
> {$endif}
> {$define su_family:=su_sa.sa_family}
> {$define su_port:=su_sin.sin_port}
> {$define su_scope_id:=su_array32[6]}
> {$endif}
> type
> su_sockaddr_u = record
> case longint of
> {$ifdef DOCUMENTATION_ONLY}
> 0 : ( su_len : byte );
> 1 : ( su_family : byte );
> 2 : ( su_port : word );
> {$else}
> 3 : ( su_dummy : smallint );
> {$endif}
> 4 : ( su_array : array[0..31] of char );
> 5 : ( su_array16 : array[0..15] of word );
> 6 : ( su_array32 : array[0..7] of longword );
> 7 : ( su_sa : sockaddr );
> 8 : ( su_sin : sockaddr_in );
> {$if SU_HAVE_IN6 <>0}
> 9 : ( su_sin6 : sockaddr_in6 );
> {$endif}
> {$ifdef DOCUMENTATION_ONLY}
> 10 : ( su_scope_id : longword );
> {$endif}
> end;
>
>     -----Message d'origine-----
>     *De :* [hidden email]
>     [mailto:[hidden email]] *De la part de*
>     Ludo Brands
>     *Envoyé :* samedi 30 avril 2011 10:29
>     *À :* 'FPC-Pascal users discussions'
>     *Objet :* RE : RE : [fpc-pascal] How to translate this union ?
>
>     Forget my previous reply. I found the original header file on
>     sourceforge.
>     I have alse a better understanding now of what the code is supposed
>     to do: in case DOCUMENTATION_ONLY is not defined, a reference to,
>     for example, su_sockaddr_u.su_family will be subsstituted by
>     su_sockaddr_u.susa.sa_family.
>     You could use macros and do a {$define su_family:=susa.sa_family}
>     with the following limitations:
>     - if you have variables or other record members named su_family, not
>     part of the su_sockaddr_u record, they will be renamed also.
>     - it works only for the units that include your .inc file.
>
>         -----Message d'origine-----
>         *De :* [hidden email]
>         [mailto:[hidden email]] *De la part de*
>         Ludo Brands
>         *Envoyé :* samedi 30 avril 2011 09:18
>         *À :* 'FPC-Pascal users discussions'
>         *Objet :* RE : [fpc-pascal] How to translate this union ?
>
>         Can you post the original c code? You point to a file that seems
>         to be a reworked output from h2pas. As it is now, it indeed
>         doesn't make any sense. I would think the
>         su_len,su_family,su_port should make up a record but they aren't.
>         I suggest you move the #defines inside the union declaration to
>         somewhere before the union declaration. It'll double up the
>         ifdef's but make the code so much more readable.
>         -----Message d'origine-----
>         *De :* [hidden email]
>         [mailto:[hidden email]] *De la part de* ik
>         *Envoyé :* vendredi 29 avril 2011 22:15
>         *À :* FPC-Pascal users discussions
>         *Objet :* [fpc-pascal] How to translate this union ?
>
>             Hello list,
>
>             I'm trying to translate the following union
>             <https://github.com/ik5/sofia-sip/blob/master/src/lib/sui.inc#L199>
>             to Pascal, but I do not understand it, and so does h2pas.
>             How to translate it ?
>
>             Thanks,
>
>             Ido
>
>
>             LINESIP - Opening the source for communication
>             http://www.linesip.com
>             http://www.linesip.co.il
>
>
>
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

RE : RE : RE : RE : [fpc-pascal] How to translate this union ?

Ludo Brands
That is why it is conditional :
su_sockaddr_u = record
(...)
{$ifdef DOCUMENTATION_ONLY}
 0 : ( su_len : byte );
 1 : ( su_family : byte );
 2 : ( su_port : word );
{$else}
 3 : ( su_dummy : smallint );
{$endif}
(...)
end;

Cheers, Ludo
-----Message d'origine-----
De : [hidden email]
[mailto:[hidden email]] De la part de Sven Barth
Envoyé : dimanche 1 mai 2011 00:19
À : [hidden email]
Objet : Re: RE : RE : RE : [fpc-pascal] How to translate this union ?


Question:

In case of DOCUMENTATION_ONLY not defined, does

su_sockaddr_u = record
(...)
   1 : ( su_sa.sa_family : byte )
(...)
end;

really compile?
(From what I know about Pascal I would say: no)

Regards,
Sven

On 30.04.2011 10:53, Ludo Brands wrote:

> Using macros, the translation looks like
> {$MACRO ON}
> {$ifndef DOCUMENTATION_ONLY}
> {$if SU_HAVE_SOCKADDR_SA_LEN <>0}
> {$define su_len:=su_sa.sa_len}
> {$else}
> {$define su_len:=su_array[0]}
> {$endif}
> {$define su_family:=su_sa.sa_family}
> {$define su_port:=su_sin.sin_port}
> {$define su_scope_id:=su_array32[6]}
> {$endif}
> type
> su_sockaddr_u = record
> case longint of
> {$ifdef DOCUMENTATION_ONLY}
> 0 : ( su_len : byte );
> 1 : ( su_family : byte );
> 2 : ( su_port : word );
> {$else}
> 3 : ( su_dummy : smallint );
> {$endif}
> 4 : ( su_array : array[0..31] of char );
> 5 : ( su_array16 : array[0..15] of word );
> 6 : ( su_array32 : array[0..7] of longword );
> 7 : ( su_sa : sockaddr );
> 8 : ( su_sin : sockaddr_in );
> {$if SU_HAVE_IN6 <>0}
> 9 : ( su_sin6 : sockaddr_in6 );
> {$endif}
> {$ifdef DOCUMENTATION_ONLY}
> 10 : ( su_scope_id : longword );
> {$endif}
> end;
>
>     -----Message d'origine-----
>     *De :* [hidden email]
>     [mailto:[hidden email]] *De la part de*
>     Ludo Brands
>     *Envoyé :* samedi 30 avril 2011 10:29
>     *À :* 'FPC-Pascal users discussions'
>     *Objet :* RE : RE : [fpc-pascal] How to translate this union ?
>
>     Forget my previous reply. I found the original header file on
>     sourceforge.
>     I have alse a better understanding now of what the code is supposed
>     to do: in case DOCUMENTATION_ONLY is not defined, a reference to,
>     for example, su_sockaddr_u.su_family will be subsstituted by
>     su_sockaddr_u.susa.sa_family.
>     You could use macros and do a {$define su_family:=susa.sa_family}
>     with the following limitations:
>     - if you have variables or other record members named su_family, not
>     part of the su_sockaddr_u record, they will be renamed also.
>     - it works only for the units that include your .inc file.
>
>         -----Message d'origine-----
>         *De :* [hidden email]
>         [mailto:[hidden email]] *De la part de*
>         Ludo Brands
>         *Envoyé :* samedi 30 avril 2011 09:18
>         *À :* 'FPC-Pascal users discussions'
>         *Objet :* RE : [fpc-pascal] How to translate this union ?
>
>         Can you post the original c code? You point to a file that seems
>         to be a reworked output from h2pas. As it is now, it indeed
>         doesn't make any sense. I would think the
>         su_len,su_family,su_port should make up a record but they aren't.
>         I suggest you move the #defines inside the union declaration to
>         somewhere before the union declaration. It'll double up the
>         ifdef's but make the code so much more readable.
>         -----Message d'origine-----
>         *De :* [hidden email]
>         [mailto:[hidden email]] *De la part de*
ik
>         *Envoyé :* vendredi 29 avril 2011 22:15
>         *À :* FPC-Pascal users discussions
>         *Objet :* [fpc-pascal] How to translate this union ?
>
>             Hello list,
>
>             I'm trying to translate the following union
>
<https://github.com/ik5/sofia-sip/blob/master/src/lib/sui.inc#L199>

>             to Pascal, but I do not understand it, and so does h2pas.
>             How to translate it ?
>
>             Thanks,
>
>             Ido
>
>
>             LINESIP - Opening the source for communication
>             http://www.linesip.com
>             http://www.linesip.co.il
>
>
>
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: RE : RE : RE : RE : [fpc-pascal] How to translate this union ?

Sven Barth-2
Ahhh right... *bangs his head against the wall*

Regards,
Sven

On 01.05.2011 09:36, Ludo Brands wrote:

> That is why it is conditional :
> su_sockaddr_u = record
> (...)
> {$ifdef DOCUMENTATION_ONLY}
>   0 : ( su_len : byte );
>   1 : ( su_family : byte );
>   2 : ( su_port : word );
> {$else}
>   3 : ( su_dummy : smallint );
> {$endif}
> (...)
> end;
>
> Cheers, Ludo
> -----Message d'origine-----
> De : [hidden email]
> [mailto:[hidden email]] De la part de Sven Barth
> Envoyé : dimanche 1 mai 2011 00:19
> À : [hidden email]
> Objet : Re: RE : RE : RE : [fpc-pascal] How to translate this union ?
>
>
> Question:
>
> In case of DOCUMENTATION_ONLY not defined, does
>
> su_sockaddr_u = record
> (...)
>     1 : ( su_sa.sa_family : byte )
> (...)
> end;
>
> really compile?
> (From what I know about Pascal I would say: no)
>
> Regards,
> Sven
>
> On 30.04.2011 10:53, Ludo Brands wrote:
>> Using macros, the translation looks like
>> {$MACRO ON}
>> {$ifndef DOCUMENTATION_ONLY}
>> {$if SU_HAVE_SOCKADDR_SA_LEN<>0}
>> {$define su_len:=su_sa.sa_len}
>> {$else}
>> {$define su_len:=su_array[0]}
>> {$endif}
>> {$define su_family:=su_sa.sa_family}
>> {$define su_port:=su_sin.sin_port}
>> {$define su_scope_id:=su_array32[6]}
>> {$endif}
>> type
>> su_sockaddr_u = record
>> case longint of
>> {$ifdef DOCUMENTATION_ONLY}
>> 0 : ( su_len : byte );
>> 1 : ( su_family : byte );
>> 2 : ( su_port : word );
>> {$else}
>> 3 : ( su_dummy : smallint );
>> {$endif}
>> 4 : ( su_array : array[0..31] of char );
>> 5 : ( su_array16 : array[0..15] of word );
>> 6 : ( su_array32 : array[0..7] of longword );
>> 7 : ( su_sa : sockaddr );
>> 8 : ( su_sin : sockaddr_in );
>> {$if SU_HAVE_IN6<>0}
>> 9 : ( su_sin6 : sockaddr_in6 );
>> {$endif}
>> {$ifdef DOCUMENTATION_ONLY}
>> 10 : ( su_scope_id : longword );
>> {$endif}
>> end;
>>
>>      -----Message d'origine-----
>>      *De :* [hidden email]
>>      [mailto:[hidden email]] *De la part de*
>>      Ludo Brands
>>      *Envoyé :* samedi 30 avril 2011 10:29
>>      *À :* 'FPC-Pascal users discussions'
>>      *Objet :* RE : RE : [fpc-pascal] How to translate this union ?
>>
>>      Forget my previous reply. I found the original header file on
>>      sourceforge.
>>      I have alse a better understanding now of what the code is supposed
>>      to do: in case DOCUMENTATION_ONLY is not defined, a reference to,
>>      for example, su_sockaddr_u.su_family will be subsstituted by
>>      su_sockaddr_u.susa.sa_family.
>>      You could use macros and do a {$define su_family:=susa.sa_family}
>>      with the following limitations:
>>      - if you have variables or other record members named su_family, not
>>      part of the su_sockaddr_u record, they will be renamed also.
>>      - it works only for the units that include your .inc file.
>>
>>          -----Message d'origine-----
>>          *De :* [hidden email]
>>          [mailto:[hidden email]] *De la part de*
>>          Ludo Brands
>>          *Envoyé :* samedi 30 avril 2011 09:18
>>          *À :* 'FPC-Pascal users discussions'
>>          *Objet :* RE : [fpc-pascal] How to translate this union ?
>>
>>          Can you post the original c code? You point to a file that seems
>>          to be a reworked output from h2pas. As it is now, it indeed
>>          doesn't make any sense. I would think the
>>          su_len,su_family,su_port should make up a record but they aren't.
>>          I suggest you move the #defines inside the union declaration to
>>          somewhere before the union declaration. It'll double up the
>>          ifdef's but make the code so much more readable.
>>          -----Message d'origine-----
>>          *De :* [hidden email]
>>          [mailto:[hidden email]] *De la part de*
> ik
>>          *Envoyé :* vendredi 29 avril 2011 22:15
>>          *À :* FPC-Pascal users discussions
>>          *Objet :* [fpc-pascal] How to translate this union ?
>>
>>              Hello list,
>>
>>              I'm trying to translate the following union
>>
> <https://github.com/ik5/sofia-sip/blob/master/src/lib/sui.inc#L199>
>>              to Pascal, but I do not understand it, and so does h2pas.
>>              How to translate it ?
>>
>>              Thanks,
>>
>>              Ido
>>
>>
>>              LINESIP - Opening the source for communication
>>              http://www.linesip.com
>>              http://www.linesip.co.il
>>
>>
>>
>>
>> _______________________________________________
>> fpc-pascal maillist  -  [hidden email]
>> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: RE : RE : RE : [fpc-pascal] How to translate this union ?

ik-6
In reply to this post by Ludo Brands

I've done the following at the moment:

{$IFDEF SU_HAVE_SOCKADDR_SA_LEN}
// #define               su_len          su_sa.sa_len <- unsupported for now
{$ELSE}
// #define               su_len          su_array[0] <- unsupported for now
{$ENDIF}
// #define               su_family       su_sa.sa_family <- unsupported for now
// #define               su_port         su_sin.sin_port <- unsupported for now
// #define               su_scope_id     su_array32[6] <- unsupported for now 

su_sockaddr_u  = record
                     case Byte of
                       0 : (su_dummy   : cshort);                  //< Dummy member to initialize
                       1 : (su_array   : array[0..31] of char);    // Presented as chars
                       2 : (su_array16 : array[0..15] of cuint16); // Presented as 16-bit ints
                       3 : (su_array32 : array[0..8]  of cuint32); // Presented as 32-bit ints
                       4 : (su_sa      : sockaddr);                // Address in struct sockaddr format
                       5 : (su_sin     : sockaddr_in);             // Address in IPv4 format
{$IFDEF SU_HAVE_IN6}
                       6 : (su_sin6    : sockaddr_in6);            // Address in IPv6 format
{$ENDIF}
                   end;


As I understood by you and C developers that I talked to, the macro create a shortcut to be used.

Thanks,

Ido

On Sat, Apr 30, 2011 at 11:53, Ludo Brands <[hidden email]> wrote:
Using macros, the translation looks like
 
{$MACRO ON}
{$ifndef DOCUMENTATION_ONLY}
{$if SU_HAVE_SOCKADDR_SA_LEN <>0}
  {$define su_len:=su_sa.sa_len}
{$else}
  {$define su_len:=su_array[0]}
{$endif}
{$define su_family:=su_sa.sa_family}
{$define su_port:=su_sin.sin_port}
{$define su_scope_id:=su_array32[6]}
{$endif}
type
    su_sockaddr_u = record
        case longint of
          {$ifdef DOCUMENTATION_ONLY}
          0 : ( su_len : byte );
          1 : ( su_family : byte );
          2 : ( su_port : word );
          {$else}
          3 : ( su_dummy : smallint );
          {$endif}
          4 : ( su_array : array[0..31] of char );
          5 : ( su_array16 : array[0..15] of word );
          6 : ( su_array32 : array[0..7] of longword );
          7 : ( su_sa : sockaddr );
          8 : ( su_sin : sockaddr_in );
          {$if SU_HAVE_IN6 <>0}
          9 : ( su_sin6 : sockaddr_in6 );
          {$endif}
          {$ifdef DOCUMENTATION_ONLY}
          10 : ( su_scope_id : longword );
          {$endif}
        end;
-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de Ludo Brands
Envoyé : samedi 30 avril 2011 10:29

À : 'FPC-Pascal users discussions'
Objet : RE : RE : [fpc-pascal] How to translate this union ?

Forget my previous reply. I found the original header file on sourceforge.
 
I have alse a better understanding now of what the code is supposed to do: in case DOCUMENTATION_ONLY is not defined,  a reference to, for example, su_sockaddr_u.su_family will be subsstituted by su_sockaddr_u.susa.sa_family.
You could use macros and do a {$define su_family:=susa.sa_family} with the following limitations:
- if you have variables or other record members named su_family, not part of the su_sockaddr_u record, they will be renamed also.
- it works only for the units that include your .inc file.
 
-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de Ludo Brands
Envoyé : samedi 30 avril 2011 09:18
À : 'FPC-Pascal users discussions'
Objet : RE : [fpc-pascal] How to translate this union ?

Can you post the original c code? You point to a file that seems to be a reworked output from h2pas. As it is now, it indeed doesn't make any sense. I would think the su_len,su_family,su_port should make up a record but they aren't.
 
I suggest you move the #defines inside the union declaration to somewhere before the union declaration. It'll double up the ifdef's but make the code so much more readable.
 
 
-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de ik
Envoyé : vendredi 29 avril 2011 22:15
À : FPC-Pascal users discussions
Objet : [fpc-pascal] How to translate this union ?

Hello list,

I'm trying to translate the following union to Pascal, but I do not understand it, and so does h2pas.
How to translate it ?

Thanks,

Ido


LINESIP - Opening the source for communication
http://www.linesip.com
http://www.linesip.co.il



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

RE : RE : RE : RE : [fpc-pascal] How to translate this union ?

Ludo Brands
Message
O. You have avoided using macros but are loosing the access to "pseudo" members su_len,su_family,su_port and su_scope_id. The DOCUMENTATION_ONLY suggests that these members are documented parts of the interface. Also it will be up to the user to figure out where to get su_len according to SU_HAVE_SOCKADDR_SA_LEN.
 
 
 -----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de ik
Envoyé : jeudi 5 mai 2011 15:19
À : FPC-Pascal users discussions
Objet : Re: RE : RE : RE : [fpc-pascal] How to translate this union ?


I've done the following at the moment:

{$IFDEF SU_HAVE_SOCKADDR_SA_LEN}
// #define               su_len          su_sa.sa_len <- unsupported for now
{$ELSE}
// #define               su_len          su_array[0] <- unsupported for now
{$ENDIF}
// #define               su_family       su_sa.sa_family <- unsupported for now
// #define               su_port         su_sin.sin_port <- unsupported for now
// #define               su_scope_id     su_array32[6] <- unsupported for now 

su_sockaddr_u  = record
                     case Byte of
                       0 : (su_dummy   : cshort);                  //< Dummy member to initialize
                       1 : (su_array   : array[0..31] of char);    // Presented as chars
                       2 : (su_array16 : array[0..15] of cuint16); // Presented as 16-bit ints
                       3 : (su_array32 : array[0..8]  of cuint32); // Presented as 32-bit ints
                       4 : (su_sa      : sockaddr);                // Address in struct sockaddr format
                       5 : (su_sin     : sockaddr_in);             // Address in IPv4 format
{$IFDEF SU_HAVE_IN6}
                       6 : (su_sin6    : sockaddr_in6);            // Address in IPv6 format
{$ENDIF}
                   end;


As I understood by you and C developers that I talked to, the macro create a shortcut to be used.

Thanks,

Ido

On Sat, Apr 30, 2011 at 11:53, Ludo Brands <[hidden email]> wrote:
Using macros, the translation looks like
 
{$MACRO ON}
{$ifndef DOCUMENTATION_ONLY}
{$if SU_HAVE_SOCKADDR_SA_LEN <>0}
  {$define su_len:=su_sa.sa_len}
{$else}
  {$define su_len:=su_array[0]}
{$endif}
{$define su_family:=su_sa.sa_family}
{$define su_port:=su_sin.sin_port}
{$define su_scope_id:=su_array32[6]}
{$endif}
type
    su_sockaddr_u = record
        case longint of
          {$ifdef DOCUMENTATION_ONLY}
          0 : ( su_len : byte );
          1 : ( su_family : byte );
          2 : ( su_port : word );
          {$else}
          3 : ( su_dummy : smallint );
          {$endif}
          4 : ( su_array : array[0..31] of char );
          5 : ( su_array16 : array[0..15] of word );
          6 : ( su_array32 : array[0..7] of longword );
          7 : ( su_sa : sockaddr );
          8 : ( su_sin : sockaddr_in );
          {$if SU_HAVE_IN6 <>0}
          9 : ( su_sin6 : sockaddr_in6 );
          {$endif}
          {$ifdef DOCUMENTATION_ONLY}
          10 : ( su_scope_id : longword );
          {$endif}
        end;
-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de Ludo Brands
Envoyé : samedi 30 avril 2011 10:29

À : 'FPC-Pascal users discussions'
Objet : RE : RE : [fpc-pascal] How to translate this union ?

Forget my previous reply. I found the original header file on sourceforge.
 
I have alse a better understanding now of what the code is supposed to do: in case DOCUMENTATION_ONLY is not defined,  a reference to, for example, su_sockaddr_u.su_family will be subsstituted by su_sockaddr_u.susa.sa_family.
You could use macros and do a {$define su_family:=susa.sa_family} with the following limitations:
- if you have variables or other record members named su_family, not part of the su_sockaddr_u record, they will be renamed also.
- it works only for the units that include your .inc file.
 
-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de Ludo Brands
Envoyé : samedi 30 avril 2011 09:18
À : 'FPC-Pascal users discussions'
Objet : RE : [fpc-pascal] How to translate this union ?

Can you post the original c code? You point to a file that seems to be a reworked output from h2pas. As it is now, it indeed doesn't make any sense. I would think the su_len,su_family,su_port should make up a record but they aren't.
 
I suggest you move the #defines inside the union declaration to somewhere before the union declaration. It'll double up the ifdef's but make the code so much more readable.
 
 
-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de ik
Envoyé : vendredi 29 avril 2011 22:15
À : FPC-Pascal users discussions
Objet : [fpc-pascal] How to translate this union ?

Hello list,

I'm trying to translate the following union to Pascal, but I do not understand it, and so does h2pas.
How to translate it ?

Thanks,

Ido


LINESIP - Opening the source for communication
http://www.linesip.com
http://www.linesip.co.il



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: RE : RE : RE : RE : [fpc-pascal] How to translate this union ?

ik-6


On Thu, May 5, 2011 at 17:05, Ludo Brands <[hidden email]> wrote:
O. You have avoided using macros but are loosing the access to "pseudo" members su_len,su_family,su_port and su_scope_id. The DOCUMENTATION_ONLY suggests that these members are documented parts of the interface. Also it will be up to the user to figure out where to get su_len according to SU_HAVE_SOCKADDR_SA_LEN.

I can not find them in the preprocessor code (the define and the "document only" members), that's why I avoided them at this point. but if I'll find them required, I'll invest more time to add them.
 
 
 
 -----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de ik
Envoyé : jeudi 5 mai 2011 15:19

À : FPC-Pascal users discussions
Objet : Re: RE : RE : RE : [fpc-pascal] How to translate this union ?


I've done the following at the moment:

{$IFDEF SU_HAVE_SOCKADDR_SA_LEN}
// #define               su_len          su_sa.sa_len <- unsupported for now
{$ELSE}
// #define               su_len          su_array[0] <- unsupported for now
{$ENDIF}
// #define               su_family       su_sa.sa_family <- unsupported for now
// #define               su_port         su_sin.sin_port <- unsupported for now
// #define               su_scope_id     su_array32[6] <- unsupported for now 

su_sockaddr_u  = record
                     case Byte of
                       0 : (su_dummy   : cshort);                  //< Dummy member to initialize
                       1 : (su_array   : array[0..31] of char);    // Presented as chars
                       2 : (su_array16 : array[0..15] of cuint16); // Presented as 16-bit ints
                       3 : (su_array32 : array[0..8]  of cuint32); // Presented as 32-bit ints
                       4 : (su_sa      : sockaddr);                // Address in struct sockaddr format
                       5 : (su_sin     : sockaddr_in);             // Address in IPv4 format
{$IFDEF SU_HAVE_IN6}
                       6 : (su_sin6    : sockaddr_in6);            // Address in IPv6 format
{$ENDIF}
                   end;


As I understood by you and C developers that I talked to, the macro create a shortcut to be used.

Thanks,

Ido

On Sat, Apr 30, 2011 at 11:53, Ludo Brands <[hidden email]> wrote:
Using macros, the translation looks like
 
{$MACRO ON}
{$ifndef DOCUMENTATION_ONLY}
{$if SU_HAVE_SOCKADDR_SA_LEN <>0}
  {$define su_len:=su_sa.sa_len}
{$else}
  {$define su_len:=su_array[0]}
{$endif}
{$define su_family:=su_sa.sa_family}
{$define su_port:=su_sin.sin_port}
{$define su_scope_id:=su_array32[6]}
{$endif}
type
    su_sockaddr_u = record
        case longint of
          {$ifdef DOCUMENTATION_ONLY}
          0 : ( su_len : byte );
          1 : ( su_family : byte );
          2 : ( su_port : word );
          {$else}
          3 : ( su_dummy : smallint );
          {$endif}
          4 : ( su_array : array[0..31] of char );
          5 : ( su_array16 : array[0..15] of word );
          6 : ( su_array32 : array[0..7] of longword );
          7 : ( su_sa : sockaddr );
          8 : ( su_sin : sockaddr_in );
          {$if SU_HAVE_IN6 <>0}
          9 : ( su_sin6 : sockaddr_in6 );
          {$endif}
          {$ifdef DOCUMENTATION_ONLY}
          10 : ( su_scope_id : longword );
          {$endif}
        end;
-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de Ludo Brands
Envoyé : samedi 30 avril 2011 10:29

À : 'FPC-Pascal users discussions'
Objet : RE : RE : [fpc-pascal] How to translate this union ?

Forget my previous reply. I found the original header file on sourceforge.
 
I have alse a better understanding now of what the code is supposed to do: in case DOCUMENTATION_ONLY is not defined,  a reference to, for example, su_sockaddr_u.su_family will be subsstituted by su_sockaddr_u.susa.sa_family.
You could use macros and do a {$define su_family:=susa.sa_family} with the following limitations:
- if you have variables or other record members named su_family, not part of the su_sockaddr_u record, they will be renamed also.
- it works only for the units that include your .inc file.
 
-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de Ludo Brands
Envoyé : samedi 30 avril 2011 09:18
À : 'FPC-Pascal users discussions'
Objet : RE : [fpc-pascal] How to translate this union ?

Can you post the original c code? You point to a file that seems to be a reworked output from h2pas. As it is now, it indeed doesn't make any sense. I would think the su_len,su_family,su_port should make up a record but they aren't.
 
I suggest you move the #defines inside the union declaration to somewhere before the union declaration. It'll double up the ifdef's but make the code so much more readable.
 
 
-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de ik
Envoyé : vendredi 29 avril 2011 22:15
À : FPC-Pascal users discussions
Objet : [fpc-pascal] How to translate this union ?

Hello list,

I'm trying to translate the following union to Pascal, but I do not understand it, and so does h2pas.
How to translate it ?

Thanks,

Ido


LINESIP - Opening the source for communication
http://www.linesip.com
http://www.linesip.co.il



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

RE : RE : RE : RE : RE : [fpc-pascal] How to translate this union ?

Ludo Brands
Message
I guess DOCUMENTATION_ONLY is defined in an external tool such as doxygen. Applications wouldn't define this. My point is that if the "pseudo" members are documented, someone will soon or later use them. If this header translation is for your personal
use only, then all is fine...
 
-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de ik
Envoyé : jeudi 5 mai 2011 16:15
À : FPC-Pascal users discussions
Objet : Re: RE : RE : RE : RE : [fpc-pascal] How to translate this union ?



On Thu, May 5, 2011 at 17:05, Ludo Brands <[hidden email]> wrote:
O. You have avoided using macros but are loosing the access to "pseudo" members su_len,su_family,su_port and su_scope_id. The DOCUMENTATION_ONLY suggests that these members are documented parts of the interface. Also it will be up to the user to figure out where to get su_len according to SU_HAVE_SOCKADDR_SA_LEN.

I can not find them in the preprocessor code (the define and the "document only" members), that's why I avoided them at this point. but if I'll find them required, I'll invest more time to add them.
 
 
 
 -----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de ik
Envoyé : jeudi 5 mai 2011 15:19

À : FPC-Pascal users discussions
Objet : Re: RE : RE : RE : [fpc-pascal] How to translate this union ?


I've done the following at the moment:

{$IFDEF SU_HAVE_SOCKADDR_SA_LEN}
// #define               su_len          su_sa.sa_len <- unsupported for now
{$ELSE}
// #define               su_len          su_array[0] <- unsupported for now
{$ENDIF}
// #define               su_family       su_sa.sa_family <- unsupported for now
// #define               su_port         su_sin.sin_port <- unsupported for now
// #define               su_scope_id     su_array32[6] <- unsupported for now 

su_sockaddr_u  = record
                     case Byte of
                       0 : (su_dummy   : cshort);                  //< Dummy member to initialize
                       1 : (su_array   : array[0..31] of char);    // Presented as chars
                       2 : (su_array16 : array[0..15] of cuint16); // Presented as 16-bit ints
                       3 : (su_array32 : array[0..8]  of cuint32); // Presented as 32-bit ints
                       4 : (su_sa      : sockaddr);                // Address in struct sockaddr format
                       5 : (su_sin     : sockaddr_in);             // Address in IPv4 format
{$IFDEF SU_HAVE_IN6}
                       6 : (su_sin6    : sockaddr_in6);            // Address in IPv6 format
{$ENDIF}
                   end;


As I understood by you and C developers that I talked to, the macro create a shortcut to be used.

Thanks,

Ido

On Sat, Apr 30, 2011 at 11:53, Ludo Brands <[hidden email]> wrote:
Using macros, the translation looks like
 
{$MACRO ON}
{$ifndef DOCUMENTATION_ONLY}
{$if SU_HAVE_SOCKADDR_SA_LEN <>0}
  {$define su_len:=su_sa.sa_len}
{$else}
  {$define su_len:=su_array[0]}
{$endif}
{$define su_family:=su_sa.sa_family}
{$define su_port:=su_sin.sin_port}
{$define su_scope_id:=su_array32[6]}
{$endif}
type
    su_sockaddr_u = record
        case longint of
          {$ifdef DOCUMENTATION_ONLY}
          0 : ( su_len : byte );
          1 : ( su_family : byte );
          2 : ( su_port : word );
          {$else}
          3 : ( su_dummy : smallint );
          {$endif}
          4 : ( su_array : array[0..31] of char );
          5 : ( su_array16 : array[0..15] of word );
          6 : ( su_array32 : array[0..7] of longword );
          7 : ( su_sa : sockaddr );
          8 : ( su_sin : sockaddr_in );
          {$if SU_HAVE_IN6 <>0}
          9 : ( su_sin6 : sockaddr_in6 );
          {$endif}
          {$ifdef DOCUMENTATION_ONLY}
          10 : ( su_scope_id : longword );
          {$endif}
        end;
-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de Ludo Brands
Envoyé : samedi 30 avril 2011 10:29

À : 'FPC-Pascal users discussions'
Objet : RE : RE : [fpc-pascal] How to translate this union ?

Forget my previous reply. I found the original header file on sourceforge.
 
I have alse a better understanding now of what the code is supposed to do: in case DOCUMENTATION_ONLY is not defined,  a reference to, for example, su_sockaddr_u.su_family will be subsstituted by su_sockaddr_u.susa.sa_family.
You could use macros and do a {$define su_family:=susa.sa_family} with the following limitations:
- if you have variables or other record members named su_family, not part of the su_sockaddr_u record, they will be renamed also.
- it works only for the units that include your .inc file.
 
-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de Ludo Brands
Envoyé : samedi 30 avril 2011 09:18
À : 'FPC-Pascal users discussions'
Objet : RE : [fpc-pascal] How to translate this union ?

Can you post the original c code? You point to a file that seems to be a reworked output from h2pas. As it is now, it indeed doesn't make any sense. I would think the su_len,su_family,su_port should make up a record but they aren't.
 
I suggest you move the #defines inside the union declaration to somewhere before the union declaration. It'll double up the ifdef's but make the code so much more readable.
 
 
-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de ik
Envoyé : vendredi 29 avril 2011 22:15
À : FPC-Pascal users discussions
Objet : [fpc-pascal] How to translate this union ?

Hello list,

I'm trying to translate the following union to Pascal, but I do not understand it, and so does h2pas.
How to translate it ?

Thanks,

Ido


LINESIP - Opening the source for communication
http://www.linesip.com
http://www.linesip.co.il



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal