Author Topic: Testers (cross-platform) wanted for a bit of code  (Read 5045 times)

0 Members and 1 Guest are viewing this topic.

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Testers (cross-platform) wanted for a bit of code
« on: September 29, 2021, 05:33:56 am »
I'm currently fixing stuff, also taking the opportunity to improve things.

Need to know if the following code works on all QB64 supported platforms, but I've only Windows systems to test on, so this is a call on all Mac/Linux users.

The following code does expand a relative path into a fully qualified absolut path, it works on Windows 32- and 64-bit, but what about Mac/Linux?

Code: QB64: [Select]
  1.     FUNCTION ExpandPath%& ALIAS _fullpath (buffer$, filespec$, BYVAL bufSize&)
  2.  
  3. PRINT "First test should work and print full path to qb64.exe"
  4. buff$ = STRING$(1056, CHR$(0))
  5. file$ = "qb64.exe"
  6. succ%& = ExpandPath%&(buff$, file$ + CHR$(0), 1056)
  7. IF succ%& > 0 THEN
  8.     PRINT "Result: success"
  9.     PRINT "Buffer: "; LEFT$(buff$, INSTR(buff$, CHR$(0)) - 1)
  10.     PRINT "Length:"; INSTR(buff$, CHR$(0)) - 1
  11.     PRINT "Result: error"
  12.     PRINT "Buffer: "; LEFT$(buff$, INSTR(buff$, CHR$(0)) - 1)
  13.     PRINT "Length:"; INSTR(buff$, CHR$(0)) - 1
  14.  
  15. PRINT "Second test should fail and print empty buffer and zero length"
  16. buff$ = STRING$(3, CHR$(0))
  17. file$ = "qb64.exe"
  18. succ%& = ExpandPath%&(buff$, file$ + CHR$(0), 3)
  19. IF succ%& > 0 THEN
  20.     PRINT "Result: success"
  21.     PRINT "Buffer: "; LEFT$(buff$, INSTR(buff$, CHR$(0)) - 1)
  22.     PRINT "Length:"; INSTR(buff$, CHR$(0)) - 1
  23.     PRINT "Result: error"
  24.     PRINT "Buffer: "; LEFT$(buff$, INSTR(buff$, CHR$(0)) - 1)
  25.     PRINT "Length:"; INSTR(buff$, CHR$(0)) - 1
  26.  
  27.  
  28.  
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
Re: Testers (cross-platform) wanted for a bit of code
« Reply #1 on: September 29, 2021, 09:46:06 am »
There's no _fullpath function in Unix, but there's the very similar realpath:
Code: [Select]
Declare Library
    Function realpath%& (path$, buf$)
End Declare

Print expandpath$("untitled.bas")


Function expandpath$ (relpath$)
    buf$ = String$(4096, Chr$(0)) 'PATH_MAX
    r%& = realpath%&(relpath$ + Chr$(0), buf$)
    If r%& = 0 Then
        expandpath$ = ""
    Else
        expandpath$ = Left$(buf$, InStr(buf$, Chr$(0)) - 1)
    End If
End Function

I've hardcoded the output buffer size as 4096 which is PATH_MAX on my current Linux, but that's pretty dodgy. A better way to do things would be to pass NULL for the second argument, then realpath returns a pointer to a malloc'd buffer that you can call free on.

I didn't do that because copying the data from the buffer into a QB64 string turns out to be rather annoying, so you get the hacky version for now.

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • View Profile
    • Resume
Re: Testers (cross-platform) wanted for a bit of code
« Reply #2 on: September 29, 2021, 02:27:53 pm »
In Ubuntu 20.04, and either compiling in v1.5 or the development build 2.0, I get an internal compiler error:

Quote
In file included from qbx.cpp:2173:
../temp/main.txt: In function ‘void QBMAIN(void*)’:
../temp/main.txt:29:30: error: ‘_fullpath’ was not declared in this scope
   29 | *__OFFSET_SUCC=(  ptrszint  )_fullpath((char*)(__STRING_BUFF)->chr,(char*)(qbs_add(__STRING_FILE,func_chr( 0 )))->chr, 1056 );
      |                                                      ^~~~~~~~~
../temp/main.txt:153:30: error: ‘_fullpath’ was not declared in this scope
  153 | *__OFFSET_SUCC=(  ptrszint  )_fullpath((char*)(__STRING_BUFF)->chr,(char*)(qbs_add(__STRING_FILE,func_chr( 0 )))->chr, 3 );
      |                                                        ^~~~~~~~~
____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: Testers (cross-platform) wanted for a bit of code
« Reply #3 on: September 29, 2021, 02:36:37 pm »
Thank you @luke and @GeorgeMcGinn for your replies.

George, could you please check, if Luke's code is working for you?
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Testers (cross-platform) wanted for a bit of code
« Reply #4 on: September 29, 2021, 04:02:41 pm »
Just a confirmation on my 32-bit windows for you.  I get the results you got and expected.

- Dav

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • View Profile
    • Resume
Re: Testers (cross-platform) wanted for a bit of code
« Reply #5 on: October 04, 2021, 11:42:51 pm »
@RhoSigma  - I just tried to compile it with the development build that is out there now, and I get the same internal compiler errors.

I'm running Linux Ubuntu 20.04 and 64-bit processing, it that means anything,

Thank you @luke and @GeorgeMcGinn for your replies.

George, could you please check, if Luke's code is working for you?
____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: Testers (cross-platform) wanted for a bit of code
« Reply #6 on: October 05, 2021, 04:02:17 am »
Thanks for testing @Dav and @George McGinn, the problem is already resolved now to my satisfaction.
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • View Profile
    • Resume
Re: Testers (cross-platform) wanted for a bit of code
« Reply #7 on: October 05, 2021, 12:49:15 pm »
Sorry, I missed Luke's code. It works fine now.



Thanks for testing @Dav and @George McGinn, the problem is already resolved now to my satisfaction.
____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)