Author Topic: Question about IUP  (Read 23231 times)

0 Members and 3 Guests are viewing this topic.

JRS

  • Guest
Re: Question about IUP
« Reply #15 on: May 27, 2015, 09:23:41 AM »
Quote
PS: Yes, o2 will accept IUP headers undoctored.

One of the best features in O2. IMHO
« Last Edit: May 27, 2015, 12:50:56 PM by John »

JRS

  • Guest
Re: Question about IUP
« Reply #16 on: May 27, 2015, 11:30:59 PM »
Roland,

I wanted to mention another IUP effort I have going on the BASM Forum. It works on BASM Windows and Linux. (32 bit only)

John

Arnold

  • Guest
Re: Question about IUP
« Reply #17 on: May 28, 2015, 02:20:14 PM »
Hi John,

thank you for the link. Until recently I was not aware that there exist so many flavours of basic. But for the moment I will try to learn and use OxygenBasic. The Iup library is one activity to achieve this.

Roland

Arnold

  • Guest
Re: Question about IUP
« Reply #18 on: May 28, 2015, 02:24:46 PM »
Hi Charles,

thank you for the IupMessagef solution. It is important to know that the C modifiers must be respected in some way in OxygenBasic too.

Nevertheless IupScanf does not fire and I do not know what I am doing wrong. There should be an input dialog with the fields for editing. I assume that IupScanf expects a pointer to a C string ending with zero, followed by some pointers to the fields containing the (formatted) values. The count of the sequence \n in the format string is one more than the fields.

Instead of using
! IupScanf     (char *format, ...) as int
I tried
! IupScanf     (sys *list) as int

and tried to build an array of pointers (also tried using a type). But my efforts are in vain:

Code: OxygenBasic
  1. includepath "iup\"      
  2. extern lib "IUP/iup.dll" cdecl
  3.      
  4. ! IupOpen      (sys argc,argv) as int
  5. ! IupClose     ()
  6. ! IupMessage   (char *title, char *msg)
  7. ! IupMessagef  (char *title, char *format, ...)
  8. '! IupScanf     (char *format, ...) as int
  9. ! IupScanf     (sys *list) as int
  10. end extern
  11.  
  12.  
  13. extern cdecl      
  14.  
  15. 'indexbase 0
  16.  
  17. % lf   = chr(10)    '\n' ??
  18. % crlf = chr(13,10)
  19.  
  20.  
  21.   int result
  22.   bstring text = nuls 300
  23.   text ="This is a vector of characters" & chr(0)
  24.  
  25.   bstring fmt = nuls 100
  26.   bstring  fmt =
  27.     "IupScanf Example\n"  &
  28.     "Text: %300.5%s\n" & chr(0)  
  29.  
  30.  
  31. sys f at strptr fmt : print f lf cast char f
  32. sys t at strptr text: print t lf cast char t
  33.  
  34. dim p(2) => (f,t)
  35.  
  36.  
  37.   IupOpen(0,0)
  38.   result = IupScanf(@p)
  39.  
  40.   if result = -1 then
  41.     IupMessage("IupScanf","Operation canceled")
  42.   else
  43.     print "success"
  44. '    IupMessagef("IupScanf","Text: %s\nFields read successfully: %d",text, result)
  45.  end if
  46.  
  47.   IupClose()
  48.  

I only get a result of -1 or a crash of the program. I think there is a solution, but I do not find the missing point. Perhaps it is necessary to use assembly?

Roland

JRS

  • Guest
Re: Question about IUP
« Reply #19 on: May 28, 2015, 04:53:16 PM »
IupScanf

Quote
It is recommended that new applications use the IupGetParam dialog instead.

FYI: Be happy,  variadic functions are out of reach in the interpretive world. Some saving grace is that there are IUP variadic functions that are convenience wrappers to non-variadic functions. I emulate most of the variadic functionality with control creation with the IupCreate() and IupAppend() under the SB covers in the extension module. There as a few variadic functions I have no immediate solution for. Most are obscure functions and not core IUP.
« Last Edit: May 28, 2015, 07:16:23 PM by John »

Charles Pegge

  • Guest
Re: Question about IUP
« Reply #20 on: May 29, 2015, 01:45:31 AM »
Hi Roland, John,

Both IupScanf and IupGetParam appear to be dud. And I have checked that the parameters were passed correctly.

Code: OxygenBasic
  1.  
  2. includepath "$\inc\"
  3. % filename  "z.exe"
  4. 'include     "RTL32.inc"
  5. 'include     "console.inc"
  6. 'include      "minwin.inc"
  7.  
  8.  
  9. includepath "iup\"      
  10. extern lib "IUP/iup.dll" cdecl
  11. include "iup.h"
  12.      
  13. extern cdecl      
  14.  
  15.  
  16.   IupOpen(null,null)
  17.  
  18.  
  19.   'SCANF TEST
  20.  ===========
  21.  
  22.   int result
  23.   string sdat=nuls 300
  24.   int    idat
  25.   double fdat
  26.   result = IupScanf("IupScanf Example\n Text:%300.5%s",strptr sdat,null)
  27.   print sdat
  28.  
  29.  
  30.   'GETPARAM TEST
  31.  ==============
  32.  
  33.   int pboolean = 1;
  34.   int pinteger = 3456;
  35.   float preal = 3.543f;
  36.   int pinteger2 = 192;
  37.   float preal2 = 0.5f;
  38.   float pangle = 90;
  39.   char pstring[100] = "string text";
  40.   char pfont[100] = "Courier, 24";
  41.   char pcolor[100] = "255 0 128";
  42.   int plist = 2, poptions = 1;
  43.   char pstring2[200] = "second text\nsecond line";
  44.   char file_name[500] = "test.jpg";
  45.  
  46.   sys param_action=0
  47.   'itr !
  48.  
  49.   if not (IupGetParam("Title", param_action, 0,
  50.  
  51.                    "Bt %u[, MyCancel, Help!]\n"+
  52.                    "Boolean: %b[No,Yes]\n"+
  53.                    "Integer: %i\n"+
  54.                    "Real 1: %r\n"+
  55.                    "Sep1 %t\n"+
  56.                    "Integer: %i[0,255]\n"+
  57.                    "Real 2: %r[-1.5,1.5,0.05]\n"+
  58.                    "Sep2 %t\n"+
  59.                    "Angle: %a[0,360]\n"+
  60.                    "String: %s\n"+
  61.                    "Options: %o|item0|item1|item2|\n" +
  62.                    "List: %l|item0|item1|item2|item3|item4|item5|item6|\n" +
  63.                    "File: %f[OPEN|*.bmp;*.jpg|CURRENT|NO|NO]\n"+
  64.                    "Color: %c{Color Tip}\n"+
  65.                    "Font: %n\n"+
  66.                    "Sep3 %t\n"+
  67.                    "Multiline: %m\n",
  68.                    &pboolean, &pinteger, &preal, &pinteger2, &preal2, &pangle, pstring,
  69.                    &poptions, &plist, file_name, pcolor, pfont, pstring2, NULL))
  70.  
  71.   end if
  72.  
  73.   print pinteger
  74.   IupClose()
  75.  

JRS

  • Guest
Re: Question about IUP
« Reply #21 on: May 29, 2015, 02:40:35 AM »
Charles & Roland,

I have passed on your findings to the IUP SourceForge peer support mailing list asking Antonio (IUP author) to verify on his end.

JRS

  • Guest
Re: Question about IUP
« Reply #22 on: May 29, 2015, 10:52:00 AM »
Quote from: Antonio
But what is the bug? IupGetparam is widely used around here.

       

Code: C
  1. /* IupScanf: Example in C
  2.    Shows a dialog with three fields to be filled.
  3.    One receives a string, the other receives a real number and
  4.    the last receives an integer number.
  5. */
  6.  
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <iup.h>
  10.  
  11. int main(int argc, char **argv)
  12. {
  13.   int ret;
  14.   int integer = 12;
  15.   float real = 1e-3f;
  16.   char text[300]="This is a vector of characters";
  17.   char *fmt =
  18.   {
  19.    "IupScanf Example\n"
  20.    "Text: %300.5%s\n"
  21.    "Real: %20.10%g\n"
  22.    "Integer: %3.10%d\n"
  23.   };
  24.  
  25.   IupOpen(&argc, &argv);
  26.  
  27.   IupSetLanguage("ENGLISH");
  28.  
  29.   ret = IupScanf(fmt, text, &real, &integer);
  30.   if (ret == -1)
  31.     IupMessage("IupScanf","Operation canceled");
  32.   else
  33.     IupMessagef("IupScanf","Text: %s\nReal: %f\nInteger: %d\nFields read successfully: %d",text,real,integer,ret);
  34.  
  35.   IupClose();
  36.  
  37.   return EXIT_SUCCESS;
  38.  
  39. }
  40.  
« Last Edit: May 29, 2015, 04:41:08 PM by John »

Arnold

  • Guest
Re: Question about IUP
« Reply #23 on: May 30, 2015, 08:43:57 AM »
Hi Charles, hi John,

thank you for the help and investigation. For me it is an important finding, that there must be paid some attention when using formatted floats with the Iup library. As there are so many things which work without problem - and there is still a lot to examine - I am optimistic that IupScanf and IupGetParam will work finally too.

Roland

Charles Pegge

  • Guest
Re: Question about IUP
« Reply #24 on: May 30, 2015, 11:58:23 PM »
Got it!

Each format line must terminate with chr(10)

Function ReplaceBN() provided to replace all "\n" with chr(10)

Code: OxygenBasic
  1. 'THESE DIALOGS DO NOT SHOW
  2.  
  3. includepath "$\inc\"
  4. % filename  "z.exe"
  5. 'include     "RTL32.inc"
  6. 'include     "console.inc"
  7. 'include      "minwin.inc"
  8.  
  9.  
  10. includepath "iup\"      
  11. extern lib "IUP/iup.dll" cdecl
  12. include "iup.h"
  13.      
  14. extern cdecl      
  15.  
  16. function ReplaceBN(char*fmt) as string
  17. ========================================
  18.   string s=fmt
  19.   do
  20.     i=instr(s,"\n")
  21.     if i then
  22.       s=left(s,i-1)+chr(10)+mid(s,i+2)
  23.     else
  24.       exit do
  25.     end if
  26.   end do
  27.   return s
  28. end function
  29.  
  30.  
  31. function main(sys argc,argv) as sys
  32. ===================================
  33.  
  34.   IupOpen(null,null)
  35.  'IupSetLanguage("ENGLISH");
  36.  
  37.  
  38.   'SCANF TEST
  39.  ===========
  40.  
  41.   int ret;
  42.   int integer = 12;
  43.   float real  = 1e-3f;
  44.   string text = "This is a vector of characters";
  45.  
  46.   string fmt= _
  47.   "IupScanf Example\n"+
  48.   "Text: %300.5%s\n"+
  49.   "Real: %20.10%g\n"+
  50.   "Integer: %3.10%d\n"
  51.  
  52.  
  53.   fmt = replaceBN fmt
  54.  
  55.  
  56.   ret = IupScanf(fmt, text, &real, &integer);
  57.   if (ret == -1)
  58.     IupMessage("IupScanf","Operation canceled");
  59.   else
  60.     IupMessagef("IupScanf","Text: %s\nReal: %f\nInteger: %d\nFields read successfully: %d",text,real,integer,ret);
  61.   end if
  62.  
  63.  
  64.   'GETPARAM TEST
  65.  ==============
  66.  
  67.   int pboolean = 1;
  68.   int pinteger = 3456;
  69.   float preal = 3.543f;
  70.   int pinteger2 = 192;
  71.   float preal2 = 0.5f;
  72.   float pangle = 90;
  73.   char pstring[100] = "string text";
  74.   char pfont[100] = "Courier, 24";
  75.   char pcolor[100] = "255 0 128";
  76.   int plist = 2, poptions = 1;
  77.   char pstring2[200] = "second text\nsecond line";
  78.   char file_name[500] = "test.jpg";
  79.  
  80.   sys param_action=0
  81.   'itr !
  82.  
  83.   if not (IupGetParam("Title", param_action, 0,
  84.                    replaceBN (
  85.                    "Bt %u[, MyCancel, Help!]\n"+
  86.                    "Boolean: %b[No,Yes]\n"+
  87.                    "Integer: %i\n"+
  88.                    "Real 1: %r\n"+
  89.                    "Sep1 %t\n"+
  90.                    "Integer: %i[0,255]\n"+
  91.                    "Real 2: %r[-1.5,1.5,0.05]\n"+
  92.                    "Sep2 %t\n"+
  93.                    "Angle: %a[0,360]\n"+
  94.                    "String: %s\n"+
  95.                    "Options: %o|item0|item1|item2|\n" +
  96.                    "List: %l|item0|item1|item2|item3|item4|item5|item6|\n" +
  97.                    "File: %f[OPEN|*.bmp;*.jpg|CURRENT|NO|NO]\n"+
  98.                    "Color: %c{Color Tip}\n"+
  99.                    "Font: %n\n"+
  100.                    "Sep3 %t\n"+
  101.                    "Multiline: %m\n"),
  102.                    &pboolean, &pinteger, &preal, &pinteger2, &preal2, &pangle, pstring,
  103.                    &poptions, &plist, file_name, pcolor, pfont, pstring2, NULL))
  104.   end if
  105.  
  106.   IupClose()
  107. end function
  108.  
  109. main null,null
  110.  

JRS

  • Guest
Re: Question about IUP
« Reply #25 on: May 31, 2015, 01:21:14 AM »
Good catch Charles!


Arnold

  • Guest
Re: Question about IUP
« Reply #26 on: May 31, 2015, 01:36:18 AM »
Hi Charles,

this is really, really cool. I knew there was a small mistake in my logic, but sometimes it is not so easy to find the needle in the haystack. To retrieve the final results now is rather easy e.g. with IupScanf:

Code: OxygenBasic
  1.  
  2. .....
  3. % lf=chr(10)
  4. .....
  5.   ret = IupScanf(fmt, strptr text, &real, &integer);
  6.   if (ret == -1)
  7.     IupMessage("IupScanf","Operation canceled");
  8.   else
  9.     IupMessagef("IupScanf","Text: %s" lf "Real: %lf" lf "Integer: %d" lf "Fields read successfully: %d",text,double(real),integer,ret);
  10.   end if
  11.  
  12.  
  13.   IupClose()
  14. end function
  15.  
  16. main null,null
  17.  
  18.  

I am really happy and I am convinced that the remaining functions of the Iup Library will work ok too.

Roland
« Last Edit: May 31, 2015, 01:48:39 AM by Arnold »

Arnold

  • Guest
Re: Question about IUP
« Reply #27 on: May 31, 2015, 03:19:28 AM »
Best of all: your function ReplaceBN can be used for formatted output. The code for IupScanf would then be:

Code: OxygenBasic
  1. includepath "$\inc\"
  2. % filename  "z.exe"
  3. 'include     "RTL32.inc"
  4. 'include     "console.inc"
  5. 'include      "minwin.inc"
  6.  
  7.  
  8. includepath "iup\"      
  9. extern lib "IUP/iup.dll" cdecl
  10. include "iup.h"
  11.      
  12. extern cdecl
  13.      
  14.  
  15. function ReplaceBN(char*fmt) as string
  16. ========================================
  17.   string s=fmt
  18.   do
  19.     i=instr(s,"\n")
  20.     if i then
  21.       s=left(s,i-1)+chr(10)+mid(s,i+2)
  22.     else
  23.       exit do
  24.     end if
  25.   end do
  26.   return s
  27. end function
  28.  
  29.  
  30. function main(sys argc,argv) as sys
  31. ===================================
  32.  
  33.   IupOpen(null,null)
  34.  
  35.  
  36.   'SCANF TEST
  37.  ===========
  38.  
  39.   int ret;
  40.   int integr = 12;
  41.   double real  = 0.001;
  42.   char text[300] = "This is a vector of characters";
  43.          
  44.   string fmt= _
  45.   "IupScanf Example\n"+
  46.   "Text: %300.5%s\n"+
  47.   "Real: %20.10%lf\n"+
  48.   "Integer: %20.10%d\n"
  49.  
  50.  
  51.   fmt = replaceBN fmt
  52.  
  53.  
  54.   ret = IupScanf(fmt,  @text, &real, &integr);
  55.   if (ret == -1)
  56.     IupMessage("IupScanf","Operation canceled");
  57.   else
  58.     IupMessagef("IupScanf", replaceBN("Text: %s\nReal: %f\nInteger: %d\nFields read successfully: %d"),text,real,integr,ret);
  59.   end if
  60.  
  61.  
  62.   IupClose()
  63. end function
  64.  
  65. main null,null
  66.  
  67.  

The use of replaceBN will be useful for some more Iup functions.

Edit:

I used for the variable text char[300] again to prevent a crash of the program.
« Last Edit: May 31, 2015, 10:50:38 AM by Arnold »

JRS

  • Guest
Re: Question about IUP
« Reply #28 on: May 31, 2015, 09:16:11 PM »
I didn't know O2 would let you end a line with a ;


Arnold

  • Guest
Re: Question about IUP
« Reply #29 on: May 31, 2015, 10:27:50 PM »
Yes Oxygenbasic is very flexible in some cases. But you must be careful: ';' is treated as a comment. To use it as a separator one must use #separator semicolon before. (See Oxygen Help file).