Recent

Author Topic: Help me translate this header  (Read 5595 times)

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Help me translate this header
« Reply #15 on: March 27, 2020, 07:51:10 pm »
So it practically just we have to do the job of the C preprocessor ourselves as we expand all of the macro manually.

Well, yes, that's the idea; after all, Pascal has no "C preprocessor" ;)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

bytebites

  • Hero Member
  • *****
  • Posts: 632
Re: Help me translate this header
« Reply #16 on: March 27, 2020, 07:52:16 pm »
 K_quotedbl      =  '\"'; //  34

is wrong. Escape char is not needed.

Mys suggestion for iup_isShiftXkey was wrong indeed.

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: Help me translate this header
« Reply #17 on: March 27, 2020, 07:55:27 pm »
K_quotedbl      =  '\"'; //  34
You're right.  I missed that one.  Thank you for pointing it out.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

guest65405

  • Guest
Re: Help me translate this header
« Reply #18 on: March 27, 2020, 10:14:34 pm »
Code: C  [Select][+][-]
  1.  
  2. #define iup_isShiftXkey(_c) ((_c) & 0x10000000)
  3.  
converts to
Code: Pascal  [Select][+][-]
  1. function iup_isShiftXkey(_c : longint) :boolean;
  2.   begin
  3.     result:=_c and $10000000;
  4.   end;
Ah, I found your mistake. You have been a Pascal coder too long to forgot C's single & and | are logical operator And and Or of Pascal. So they should be type longint, not boolean.

p/s: I don't know why Pascal use the same name And and Or for both the boolean operators and logical operators. It's really confusing at first.

guest65405

  • Guest
Re: Help me translate this header
« Reply #19 on: March 27, 2020, 10:20:28 pm »
Finally I ended up with this monster: https://pastebin.com/xtNDQPT4

p/s: I adapted from the h2pas output, so the dreadful functions still there.

guest65405

  • Guest
Re: Help me translate this header
« Reply #20 on: March 27, 2020, 10:22:49 pm »
use this  (in 3 pieces because the forum software complained about too many characters)
Code: Pascal  [Select][+][-]
  1. program TestConversion;
  2.  
  3.  
  4. // from 32 to 126, all character sets are equal,
  5. // the key code is the same as the ASCii character code.
  6.  
  7. const
  8.   K_SP            =  ' ' ; //  32 (0x20)
  9.   K_exclam        =  '!' ; //  33
  10.   K_quotedbl      =  '"'; //  34  { !! removed backslash }
  11.   K_numbersign    =  '#' ; //  35
  12.   K_dollar        =  '$' ; //  36
  13.   K_percent       =  '%' ; //  37
  14.   K_ampersand     =  '&' ; //  38
  15.   K_apostrophe    =  ''''; //  39
  16.   K_parentleft    =  '(' ; //  40
  17.   K_parentright   =  ')' ; //  41
  18.   K_asterisk      =  '*' ; //  42
  19.   K_plus          =  '+' ; //  43
  20.   K_comma         =  ',' ; //  44
  21.   K_minus         =  '-' ; //  45
  22.   K_period        =  '.' ; //  46
  23.   K_slash         =  '/' ; //  47
  24.   K_0             =  '0' ; //  48 (0x30)
  25.   K_1             =  '1' ; //  49
  26.   K_2             =  '2' ; //  50
  27.   K_3             =  '3' ; //  51
  28.   K_4             =  '4' ; //  52
  29.   K_5             =  '5' ; //  53
  30.   K_6             =  '6' ; //  54
  31.   K_7             =  '7' ; //  55
  32.   K_8             =  '8' ; //  56
  33.   K_9             =  '9' ; //  57
  34.   K_colon         =  ':' ; //  58
  35.   K_semicolon     =  ';' ; //  59
  36.   K_less          =  '<' ; //  60
  37.   K_equal         =  '=' ; //  61
  38.   K_greater       =  '>' ; //  62
  39.   K_question      =  '?' ; //  63
  40.   K_at            =  '@' ; //  64
  41.   K_ucA           =  'A' ; //  65 (0x41)    !! added "uc" to elimiate duplicate
  42.   K_ucB           =  'B' ; //  66           !! added "uc" to elimiate duplicate
  43.   K_ucC           =  'C' ; //  67           !! added "uc" to elimiate duplicate
  44.   K_ucD           =  'D' ; //  68           !! added "uc" to elimiate duplicate
  45.   K_ucE           =  'E' ; //  69           !! added "uc" to elimiate duplicate
  46.   K_ucF           =  'F' ; //  70           !! added "uc" to elimiate duplicate
  47.   K_ucG           =  'G' ; //  71           !! added "uc" to elimiate duplicate
  48.   K_ucH           =  'H' ; //  72           !! added "uc" to elimiate duplicate
  49.   K_ucI           =  'I' ; //  73           !! added "uc" to elimiate duplicate
  50.   K_ucJ           =  'J' ; //  74           !! added "uc" to elimiate duplicate
  51.   K_ucK           =  'K' ; //  75           !! added "uc" to elimiate duplicate
  52.   K_ucL           =  'L' ; //  76           !! added "uc" to elimiate duplicate
  53.   K_ucM           =  'M' ; //  77           !! added "uc" to elimiate duplicate
  54.   K_ucN           =  'N' ; //  78           !! added "uc" to elimiate duplicate
  55.   K_ucO           =  'O' ; //  79           !! added "uc" to elimiate duplicate
  56.   K_ucP           =  'P' ; //  80           !! added "uc" to elimiate duplicate
  57.   K_ucQ           =  'Q' ; //  81           !! added "uc" to elimiate duplicate
  58.   K_ucR           =  'R' ; //  82           !! added "uc" to elimiate duplicate
  59.   K_ucS           =  'S' ; //  83           !! added "uc" to elimiate duplicate
  60.   K_ucT           =  'T' ; //  84           !! added "uc" to elimiate duplicate
  61.   K_ucU           =  'U' ; //  85           !! added "uc" to elimiate duplicate
  62.   K_ucV           =  'V' ; //  86           !! added "uc" to elimiate duplicate
  63.   K_ucW           =  'W' ; //  87           !! added "uc" to elimiate duplicate
  64.   K_ucX           =  'X' ; //  88           !! added "uc" to elimiate duplicate
  65.   K_ucY           =  'Y' ; //  89           !! added "uc" to elimiate duplicate
  66.   K_ucZ           =  'Z' ; //  90           !! added "uc" to elimiate duplicate
  67.   K_bracketleft   =  '[' ; //  91
  68.   K_backslash     =  '\' ; //  92
  69.   K_bracketright  =   ']'; //  93
  70.   K_circum        =  '^' ; //  94
  71.   K_underscore    =  '_' ; //  95
  72.   K_grave         =  '`' ; //  96
  73.   K_lca           =  'a' ; //  97 (0x61)    !! added "lc" to elimiate duplicate
  74.   K_lcb           =  'b' ; //  98           !! added "lc" to elimiate duplicate
  75.   K_lcc           =  'c' ; //  99           !! added "lc" to elimiate duplicate
  76.   K_lcd           =  'd' ; // 100           !! added "lc" to elimiate duplicate
  77.   K_lce           =  'e' ; // 101           !! added "lc" to elimiate duplicate
  78.   K_lcf           =  'f' ; // 102           !! added "lc" to elimiate duplicate
  79.   K_lcg           =  'g' ; // 103           !! added "lc" to elimiate duplicate
  80.   K_lch           =  'h' ; // 104           !! added "lc" to elimiate duplicate
  81.   K_lci           =  'i' ; // 105           !! added "lc" to elimiate duplicate
  82.   K_lcj           =  'j' ; // 106           !! added "lc" to elimiate duplicate
  83.   K_lck           =  'k' ; // 107           !! added "lc" to elimiate duplicate
  84.   K_lcl           =  'l' ; // 108           !! added "lc" to elimiate duplicate
  85.   K_lcm           =  'm' ; // 109           !! added "lc" to elimiate duplicate
  86.   K_lcn           =  'n' ; // 110           !! added "lc" to elimiate duplicate
  87.   K_lco           =  'o' ; // 111           !! added "lc" to elimiate duplicate
  88.   K_lcp           =  'p' ; // 112           !! added "lc" to elimiate duplicate
  89.   K_lcq           =  'q' ; // 113           !! added "lc" to elimiate duplicate
  90.   K_lcr           =  'r' ; // 114           !! added "lc" to elimiate duplicate
  91.   K_lcs           =  's' ; // 115           !! added "lc" to elimiate duplicate
  92.   K_lct           =  't' ; // 116           !! added "lc" to elimiate duplicate
  93.   K_lcu           =  'u' ; // 117           !! added "lc" to elimiate duplicate
  94.   K_lcv           =  'v' ; // 118           !! added "lc" to elimiate duplicate
  95.   K_lcw           =  'w' ; // 119           !! added "lc" to elimiate duplicate
  96.   K_lcx           =  'x' ; // 120           !! added "lc" to elimiate duplicate
  97.   K_lcy           =  'y' ; // 121           !! added "lc" to elimiate duplicate
  98.   K_lcz           =  'z' ; // 122           !! added "lc" to elimiate duplicate
  99.   K_braceleft     =  '{' ; // 123
  100.   K_bar           =  '|' ; // 124
  101.   K_braceright    =  '}' ; // 125
  102.   K_tilde         =  '~' ; // 126 (0x7E)
  103.  
  104. // Printable ASCii keys
  105.  
  106. // #define iup_isprint(_c) ((_c) > 31 && (_c) < 127)
  107.  
  108. function iup_isprint(_c : DWORD)
  109.        : boolean32; inline;
  110. begin
  111.   result := (_c > 31) and (_c < 127);
  112. end;
  113.  
  114.  
  115. // also define the escape sequences that have keys associated
  116.  
  117. const
  118.   K_eBS           = 8 ;    // '\b' 8
  119.   K_eTAB          = 9 ;    // '\t' 9
  120.  
  121.   K_eLF           = 10;    // '\n' 10 (0Ah) not a real key, is a combination of
  122.                            //               CR with a modifier, just to document
  123.  
  124.   K_eCR           = 13;    // '\r' 13 (0Dh)
  125.  
  126.  
  127.  
  128. // backward compatible definitions
  129.  
  130. const
  131.   K_quoteleft     = K_grave     ;
  132.   K_quoteright    = K_apostrophe;
  133.  
  134.   { this synonym can be implemented as an FPC macro or as a repeat of the     }
  135.   { iup_isXkey function                                                       }
  136.   {                                                                           }
  137.   { isxkey          = iup_isXkey;                                             }
  138.  
  139.  
  140.  
  141. // IUP Extended Key Codes, range start at 128      */
  142.  
  143. // #define iup_isXkey(_c)      ((_c) >= 128)
  144. // same as isxkey
  145.  
  146. function iup_isXkey(_c : DWORD)
  147.        : boolean32; inline;
  148. begin
  149.   result := (_c > 128);
  150. end;
  151.  
  152. function isxkey(_c : DWORD) : boolean32; inline;
  153. begin
  154.   result := iup_isXkey(_c);
  155. end;
  156.  
  157.  
  158. // These use the same definition as X11 and GDK.
  159. // This also means that any X11 or GDK definition can also be used.
  160.  
  161. const
  162.   K_PAUSE         = DWORD($FF13);
  163.   K_ESC           = DWORD($FF1B);
  164.   K_HOME          = DWORD($FF50);
  165.   K_LEFT          = DWORD($FF51);
  166.   K_UP            = DWORD($FF52);
  167.   K_RIGHT         = DWORD($FF53);
  168.   K_DOWN          = DWORD($FF54);
  169.   K_PGUP          = DWORD($FF55);
  170.   K_PGDN          = DWORD($FF56);
  171.   K_END           = DWORD($FF57);
  172.   K_MIDDLE        = DWORD($FF0B);
  173.   K_Print         = DWORD($FF61);
  174.   K_INS           = DWORD($FF63);
  175.   K_Menu          = DWORD($FF67);
  176.   K_DEL           = DWORD($FFFF);
  177.   K_F1            = DWORD($FFBE);
  178.   K_F2            = DWORD($FFBF);
  179.   K_F3            = DWORD($FFC0);
  180.   K_F4            = DWORD($FFC1);
  181.   K_F5            = DWORD($FFC2);
  182.   K_F6            = DWORD($FFC3);
  183.   K_F7            = DWORD($FFC4);
  184.   K_F8            = DWORD($FFC5);
  185.   K_F9            = DWORD($FFC6);
  186.   K_F10           = DWORD($FFC7);
  187.   K_F11           = DWORD($FFC8);
  188.   K_F12           = DWORD($FFC9);
  189.  
  190. // no Shift/Ctrl/Alt
  191.  
  192. const
  193.   K_LSHIFT        = DWORD($FFE1);
  194.   K_RSHIFT        = DWORD($FFE2);
  195.   K_LCTRL         = DWORD($FFE3);
  196.   K_RCTRL         = DWORD($FFE4);
  197.   K_LALT          = DWORD($FFE9);
  198.   K_RALT          = DWORD($FFEA);
  199.  
  200.   K_NUM           = DWORD($FF7F);
  201.   K_SCROLL        = DWORD($FF14);
  202.   K_CAPS          = DWORD($FFE5);
  203.  
  204.  
  205. // Also, these are the same as the Latin-1 definition
  206.  
  207. const
  208.   K_lccedilla     = DWORD($00E7);  // duplicate identifier - changed to lc..
  209.   K_uCcedilla     = DWORD($00C7);  //    "          "                to uC..
  210.  
  211.   K_acute         = DWORD($00B4);  // no Shift/Ctrl/Alt
  212.   K_diaeresis     = DWORD($00A8);
  213.  
  214.  
remainder on next 2 posts

ETA: removed the backslash in "double quote" definition.

@bytebites: thank you for catching that.

Thank you very much.

p/s: Fsck! I forgot Pascal is case insensitive! My version still use the same name as C.

guest65405

  • Guest
Re: Help me translate this header
« Reply #21 on: March 27, 2020, 10:30:30 pm »
Code: Pascal  [Select][+][-]
  1.   K_yA            = DWORD(K_ucA         ) or $80000000;   // Sys
  2.   K_yB            = DWORD(K_ucB         ) or $80000000;   // Sys
  3.   K_yC            = DWORD(K_ucC         ) or $80000000;   // Sys
  4.   K_yD            = DWORD(K_ucD         ) or $80000000;   // Sys
  5.   K_yE            = DWORD(K_ucE         ) or $80000000;   // Sys
  6.   K_yF            = DWORD(K_ucF         ) or $80000000;   // Sys
  7.   K_yG            = DWORD(K_ucG         ) or $80000000;   // Sys
  8.   K_yH            = DWORD(K_ucH         ) or $80000000;   // Sys
  9.   K_yI            = DWORD(K_ucI         ) or $80000000;   // Sys
  10.   K_yJ            = DWORD(K_ucJ         ) or $80000000;   // Sys
  11.   K_yK            = DWORD(K_ucK         ) or $80000000;   // Sys
  12.   K_yL            = DWORD(K_ucL         ) or $80000000;   // Sys
  13.   K_yM            = DWORD(K_ucM         ) or $80000000;   // Sys
  14.   K_yN            = DWORD(K_ucN         ) or $80000000;   // Sys
  15.   K_yO            = DWORD(K_ucO         ) or $80000000;   // Sys
  16.   K_yP            = DWORD(K_ucP         ) or $80000000;   // Sys
  17.   K_yQ            = DWORD(K_ucQ         ) or $80000000;   // Sys
  18.   K_yR            = DWORD(K_ucR         ) or $80000000;   // Sys
  19.   K_yS            = DWORD(K_ucS         ) or $80000000;   // Sys
  20.   K_yT            = DWORD(K_ucT         ) or $80000000;   // Sys
  21.   K_yU            = DWORD(K_ucU         ) or $80000000;   // Sys
  22.   K_yV            = DWORD(K_ucV         ) or $80000000;   // Sys
  23.   K_yW            = DWORD(K_ucW         ) or $80000000;   // Sys
  24.   K_yX            = DWORD(K_ucX         ) or $80000000;   // Sys
  25.   K_yY            = DWORD(K_ucY         ) or $80000000;   // Sys
  26.   K_yZ            = DWORD(K_ucZ         ) or $80000000;   // Sys
  27.   K_y1            = DWORD(K_1           ) or $80000000;   // Sys
  28.   K_y2            = DWORD(K_2           ) or $80000000;   // Sys
  29.   K_y3            = DWORD(K_3           ) or $80000000;   // Sys
  30.   K_y4            = DWORD(K_4           ) or $80000000;   // Sys
  31.   K_y5            = DWORD(K_5           ) or $80000000;   // Sys
  32.   K_y6            = DWORD(K_6           ) or $80000000;   // Sys
  33.   K_y7            = DWORD(K_7           ) or $80000000;   // Sys
  34.   K_y8            = DWORD(K_8           ) or $80000000;   // Sys
  35.   K_y9            = DWORD(K_9           ) or $80000000;   // Sys
  36.   K_y0            = DWORD(K_0           ) or $80000000;   // Sys
  37.   K_yPlus         = DWORD(K_plus        ) or $80000000;   // Sys
  38.   K_yComma        = DWORD(K_comma       ) or $80000000;   // Sys
  39.   K_yMinus        = DWORD(K_minus       ) or $80000000;   // Sys
  40.   K_yPeriod       = DWORD(K_period      ) or $80000000;   // Sys
  41.   K_ySlash        = DWORD(K_slash       ) or $80000000;   // Sys
  42.   K_ySemicolon    = DWORD(K_semicolon   ) or $80000000;   // Sys
  43.   K_yEqual        = DWORD(K_equal       ) or $80000000;   // Sys
  44.   K_yBracketleft  = DWORD(K_bracketleft ) or $80000000;   // Sys
  45.   K_yBracketright = DWORD(K_bracketright) or $80000000;   // Sys
  46.   K_yBackslash    = DWORD(K_backslash   ) or $80000000;   // Sys
  47.   K_yAsterisk     = DWORD(K_asterisk    ) or $80000000;   // Sys
  48.  
  49. begin
  50. end.
Finally!

Just copy/paste the three pieces in one file and you're good to go.

ETA:
change the comparisons in the functions from "> 0" to "<> 0".  It's better that way.

Wait a minute, please. I didn't see anywhere on this header  "> 0" or "<> 0". Could you point me to this line?

p/s: Or it could be because I'm too tired. Please let me know how long it took you to do that. I have spent two hours to have the monster I posted above.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Help me translate this header
« Reply #22 on: March 27, 2020, 10:59:42 pm »

So it practically just we have to do the job of the C preprocessor ourselves as we expand all of the macro manually. I will be easily done wilth a few find and replace with regex.

The reason why preprocessor is hard to translate is that there are cases where the definition is incomplete and only given complete meaning by the context where it is included.

This makes fool proof processing of macro containing headers difficult.

That said, one could (always) try to do some more heuristics to translate more.

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: Help me translate this header
« Reply #23 on: March 27, 2020, 11:15:07 pm »
Wait a minute, please. I didn't see anywhere on this header  "> 0" or "<> 0". Could you point me to this line?

p/s: Or it could be because I'm too tired. Please let me know how long it took you to do that. I have spent two hours to have the monster I posted above.
Remember, there are three (3) pieces.  The second (2nd) piece has the functions that do a comparison "> 0", it would be better if the comparison was "<> 0". (it should work "as is" but comparing against not zero is safer.)

It took somewhere between 10 and 15 minutes.  It would have taken a couple minutes less if it hadn't been for the duplicate identifiers.

Make sure you get all three pieces and "glue" them together.


(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

guest65405

  • Guest
Re: Help me translate this header
« Reply #24 on: March 28, 2020, 05:07:09 am »
Wait a minute, please. I didn't see anywhere on this header  "> 0" or "<> 0". Could you point me to this line?

p/s: Or it could be because I'm too tired. Please let me know how long it took you to do that. I have spent two hours to have the monster I posted above.
Remember, there are three (3) pieces.  The second (2nd) piece has the functions that do a comparison "> 0", it would be better if the comparison was "<> 0". (it should work "as is" but comparing against not zero is safer.)

It took somewhere between 10 and 15 minutes.  It would have taken a couple minutes less if it hadn't been for the duplicate identifiers.

Make sure you get all three pieces and "glue" them together.

Oh, I see. I would rather keep it as is to keep compatibility with the original header.

Here is the complete file after merged all three pieces: https://pastebin.com/drDTgS2A

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: Help me translate this header
« Reply #25 on: March 28, 2020, 05:13:10 am »
Here is the complete file after merged all three pieces: https://pastebin.com/drDTgS2A
It looks good.

Oh, I see. I would rather keep it as is to keep compatibility with the original header.
It wouldn't affect compatibility.  In case you're interested, the lines affected would be 226, 235, 244 and 253.


(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

guest65405

  • Guest
Re: Help me translate this header
« Reply #26 on: March 28, 2020, 05:29:20 am »
It wouldn't affect compatibility.  In case you're interested, the lines affected would be 226, 235, 244 and 253.

In case you're interested, I have created a github repo: https://github.com/ruanjiaxing/iup_pascal

p/s: this is the first time I use a version control system.

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: Help me translate this header
« Reply #27 on: March 28, 2020, 02:18:30 pm »
In case you're interested, I have created a github repo: https://github.com/ruanjiaxing/iup_pascal
I'm pleased to see the results available to all those who might need it. :)
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Help me translate this header
« Reply #28 on: March 28, 2020, 03:04:09 pm »
isn't there a  h2pas utility in the mix with fpc ?
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Help me translate this header
« Reply #29 on: March 28, 2020, 03:45:24 pm »
isn't there a  h2pas utility in the mix with fpc ?

Read the first (and following) posts: the starting problem was that h2pas couldn't manage the header file. :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018