Author Topic: FreeBASIC file operations with CWstr  (Read 565 times)

0 Members and 1 Guest are viewing this topic.

Offline Juergen Kuehlwein

  • Full Member
  • ***
  • Posts: 118
FreeBASIC file operations with CWstr
« on: January 26, 2019, 03:35:10 PM »
I thought i would open a new thread for file operations, because the other one is getting quite lengthy...

JosÚ,

i remember you posting somewhere, you had classes for unicode file operations, but i cannot find them (other than "CFileSys.inc, CFileTime.inc and CFindFile.inc) in WinFBX. Running own tests in FreeBASIC, it seems i cannot have unicode file names, but i can read and write WSTRINGs to and from files. So the real shortcoming is at the "OPEN" statement, all others work with WSTRING - is this correct ?


JK

Offline JosÚ Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2517
    • JosÚ Roca Software
Re: FreeBASIC file operations with CWstr
« Reply #1 on: January 26, 2019, 06:53:45 PM »
> So the real shortcoming is at the "OPEN" statement, all others work with WSTRING - is this correct ?

None of the FB instrinsic procedures that deal with files accept unicode file names.

Offline JosÚ Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2517
    • JosÚ Roca Software
Re: FreeBASIC file operations with CWstr
« Reply #2 on: January 26, 2019, 06:54:51 PM »
> i remember you posting somewhere, you had classes for unicode file operations, but i cannot find them (other than "CFileSys.inc, CFileTime.inc and CFindFile.inc) in WinFBX.

There are many classes and procedures to work with files in unicode.
See: https://github.com/JoseRoca/WinFBX/tree/master/docs/File%20Management

Offline Juergen Kuehlwein

  • Full Member
  • ***
  • Posts: 118
Re: FreeBASIC file operations with CWstr
« Reply #3 on: January 26, 2019, 10:44:34 PM »
Ok, i cannot have unicode file names, but i can have unicode file data - can you confirm that? In other words: once i have opened a file, i can read and write WSTRINGs from and to it, at least this is what a quick test seems to show.

Code: [Select]
dim s as string
dim w as wstring * 16

  s = "d:\asdf.txt"
  w = "asdf"


  open s for binary as #1
    put #1,, w
  close #1 

  w = ""

  open s for binary as #1
    get #1,, w
  close #1 

  s = ""
  s = w
 
  print s
  print len(s)
  sleep

JK

Offline JosÚ Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2517
    • JosÚ Roca Software
Re: FreeBASIC file operations with CWstr
« Reply #4 on: January 26, 2019, 10:46:43 PM »
I haven't tried with binary files, but it works with files opened with OPEN using "utf16" encoding.
« Last Edit: January 26, 2019, 10:52:37 PM by JosÚ Roca »

Offline Juergen Kuehlwein

  • Full Member
  • ***
  • Posts: 118
Re: FreeBASIC file operations with CWstr
« Reply #5 on: January 26, 2019, 11:30:29 PM »
It┤s not about file encoding alone, i can read and write WSTRINGs from and to an ASCII encoded file, so basically unicode strings work with files, but real unicode file names fail. If you change "s" in my previous code example from string to wstring, it will work with the same file name, but with Russian characters, it fails. So there must be some conversion from wstring to string under the hood for the "open" statement.

This means - and this is my point: it would only require to enable unicode file names in order to get FreeBASIC working with unicode and files in total . The rest of it can already do that, of course the usual adaptions for avoiding "**" with USTRINGs would be necessary for the various input and output methods.

Having a look at the runtime library this seems to be the case!

Jeff, i know you are busy with other things, but can you confirm that?


JK   

Offline Juergen Kuehlwein

  • Full Member
  • ***
  • Posts: 118
Re: FreeBASIC file operations with CWstr
« Reply #6 on: April 07, 2019, 11:47:27 AM »
In the meantime i have a very first version, which can open files with real unicode names (russian characters) using the "OPEN" statement. Making all file functions work with USTRING will be a whole lot of work, but at least i know now, that it is possible the way i thought.


JK

Offline Juergen Kuehlwein

  • Full Member
  • ***
  • Posts: 118
Re: FreeBASIC file operations with CWstr
« Reply #7 on: April 28, 2019, 11:20:37 PM »
I┤m making substantial progress here, i have converted almost all FB statements using filenames or paths to work with real unicode names. Currently i support: open, filecopy, fileattr, filelen, filedatetime, filexists, kill, name, command, exec, chain, run, dir, curdir, mkdir, chdir, rmdir and exepath.

There are still problems with: shell, environ, setenviron. Dylibload is yet to come.

Did i miss statements?


JK