• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

unicode File I/O

Started by James C. Fuller, April 01, 2016, 12:05:47 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

James C. Fuller

Patrice,
  You, as others, advocate UNICODE apps.
How do you save/read data to files? Primarily text but could be struct and or binary data.
Files need to be shared with other apps that may or may not be unicode aware.
This would be for PowerBASIC,c++, or WinDev
My guess would be ansi file saves?

James

Patrice Terrier

In that case ANSI is the only common denominator.

And i always store setup and binary data in ANSI mode to save disk space.

For example, i am using this with the WinLIFT sks files, to turn them back into UNICODE

long skReadStr(IN WCHAR* szConfigFile, OUT long &nDone) {
    wstring sBf;
    long nItem = 0, s1 = 0, s2 = 0, s3 = 0;
    while (nDone == 0) {
       sBf = LTRIM$(CharToWstring((char*) skBufin(szConfigFile, nDone).c_str()), $SPACE);
       if (nDone == 0) {
           if (sBf.length() > 0) {
               if (sBf[0] != (WCHAR) 39) {
                   s1 = INSTR(0, sBf, L"'");
                   s2 = INSTR(-1, sBf, $DQUOTE);
                   if (s1 == 0) {
                       s3 = INSTR(-1, sBf, $SQUOTE);
                       if (s3 > s2) { s1 = s3; }
                   }
                   if (s1) { sBf = RTRIM$(LEFT$(sBf, s1 - 1), $SPACE); }
                   s1 = INSTR(0, sBf, $DQUOTE);
                   if ((s1 > 0) && (s1 < s2)) {
                      sBf = MID$(sBf, s1 + 1, s2 - s1 - 1);
                      nItem = (long) UBOUND(g_sCfg);
                      g_sCfg.resize(nItem + 1);
                      g_sCfg[nItem] = sBf;
                   }
               }
           }
       }
    }
    return nItem;
}

Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

James C. Fuller

Patrice,
  Thank you for your insight.
Now if I understand correctly; for internal use I should use _AddressTypeW and for
file and load/save convert to _AddressTypeA and save that to disk? For loading it would be the reverse.
I'm investigating Fred's TCLib and decided UNICODE only for my bc9Basic source.
I have a utility that converts ansi c++ source to UNICODE using tchar.h.
I have to jump through hoops in places to keep it from changing ansi that I need as ansi,
hence the //<---UNICODE AWARE //>---UNICODE AWARE  tags.
Any quick tips on the converstion other than pounding each item through the WideCharToMultiByte and MultiByteToWideChar routines?
Thank You,
James


typedef struct _AddressTypeW
{
    _TCHAR     Company[64];
    _TCHAR     LastName[32];
    _TCHAR     FirstName[32];
    _TCHAR     Address1[64];
    _TCHAR     Address2[64];
    _TCHAR     Address3[64];
    _TCHAR     CityName[24];
    _TCHAR     StateName[4];
    _TCHAR     ZipCode[12];
    long     Country;
    _TCHAR     Phone[24];
    _TCHAR     Fax[24];
    _TCHAR     Email[64];
    _TCHAR     Url[64];
    _TCHAR     Comments[1024];
} AddressTypeW, *LPADDRESSTYPEW;


typedef struct _AddressTypeA
{
//<---UNICODE AWARE
    char     Company[64];
    char     LastName[32];
    char     FirstName[32];
    char     Address1[64];
    char     Address2[64];
    char     Address3[64];
    char     CityName[24];
    char     StateName[4];
    char     ZipCode[12];
    long     Country;
    char     Phone[24];
    char     Fax[24];
    char     Email[64];
    char     Url[64];
    char     Comments[1024];
//>---UNICODE AWARE
} AddressTypeA, *LPADDRESSTYPEA;


Patrice Terrier

#3
The main reason why i use UNICODE, is because most of the modern API requires it, and because of Windows itself.

I have developped a full set of routines to keep using the same syntax in C++ than in PB.
The only difference i am using UCASE for all UNICODE, and lowercase for ANSI.

UNICODE = LEFT$, RIGHT$, MID$, RTRIM$, etc.
ANSI = left$, right$, mid$, rtrim$, etc.

The main reason is that i can easily use cut and paste from one language to another, and wile using C++ i can immediatly see if i am refering to ANSI or UNICODE just looking at the case, while in PB lowercase or uppercase makes no diffrence.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

James C. Fuller

Patrice,
  I had forgotten about this thread but I wanted to get Mike's usage (if any) anyway.
Are you actually creating true Unicode text files with a BOM or just pumping out Unicode for your apps to read back in?

James

Patrice Terrier

When reading writing to file i always use ASCII files to keep them small and readable by everyone.
The only exception would be for international database, and only for the specific text fields that must be readable in native languages (mandarin, cyrillic, kanji, etc.)

However, when dealing with the API i always use UNICODE because this is the native one to communicate with the current Windows API. And the same reason why i switched to 64-bit.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

James C. Fuller

Patrice,
  Is this primarily standard fare with software across the board?
I have NO international experience on this subject.
How does a Russian version of Visual Studio handle default text file io?
Is the source code edited and saved in Cyrillic or ANSI?

What about WinDev?

James

Patrice Terrier

#7
Source code is saved in ASCII, because the core compiler is the same whatever the language, and produces always same machine code .

Only the programming envrironment is using unicode, to display the GUI interface with the same language than the host computer used for development.

For WinDev, the Chinese version is speaking Mandarin and using ideograms.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com