Results 1 to 4 of 4

Thread: problem with storing greek chars to a buffer (os linux)

  1. #1
    Join Date
    Jul 2006
    Posts
    79
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default problem with storing greek chars to a buffer (os linux)

    hello everyone and happy new year.
    i am not sure how to tackle this problem or where is originates from so i am writing here in hope that if you can not help you can at least point me in a direction.

    I am writing some little program using only standard c++ library and i am opening a file that contains strings. there are numbers , english and greek letters among the characters. the reading is done fine and the data are then stored onto a buffer (without undergoing any processing) as a few int values ( the lengths of the strings), followed by a long c string - the concatenation of all the strings of the file.
    the receive application can then use the lengths of the strings to separate the strings from the string again.

    so examining the buffer contents in the shared memory i found that the numbers have their correct corresponding values (0x30 for char '0' etcetc.) and the lengths of the strings in the c string are correct too. but the greek characters and system chars found among them (like spacebar) where wrong - did not have their expected (extended) ascii values. the funny thing is if i printf the strings of the file, they appear correctly on console!!

    i have set LC_ALL environment variable in my linux machine to en_US.UTF-8, just in case this is an important detail. and the file was written from vim (not internally from the program). is it possible that the file is written in utf-16 format? utf-8? could it be something wrong in the code?(see below)
    thank you in advance for your help


    CODE:
    once i have the independent strings with 'loadInfoConf()' i serialise them and send them to the shMem using:

    Qt Code:
    1. string detailsStr; details.writeStructToStream(GUILastMessage.oNL,GUILastMessage.oTL,GUILastMessage.sNL,GUILastMessage.sLL,
    2. GUILastMessage.iDL,GUILastMessage.mDL,detailsStr);
    3. strcpy(&GUILastMessage.oAndS_str,detailsStr.c_str());
    To copy to clipboard, switch view to plain text mode 


    ---------------------------------------------------------------
    Qt Code:
    1. void InfoClass::loadInfoConf()
    2. {
    3. string curLine="",sumLine="", lines[6];
    4. int i=0;
    5.  
    6. ifstream infoConfFile(INFOCONF_FILENAME);
    7. if (infoConfFile.is_open())
    8. {
    9. while (!infoConfFile.eof())
    10. {
    11. getline(infoConfFile,curLine);
    12. if ((curLine!="EOV"))
    13. {
    14. if (curLine!="")
    15. sumLine=sumLine+curLine+"\n";
    16. }
    17. else
    18. {
    19. lines[i]=sumLine;
    20. sumLine="";
    21. i++;
    22. }
    23. }
    24. infoConfFile.close();
    25.  
    26. //remove the last char which is always \n due to the way
    27. //the file open parser (just above) works
    28. lines[0].erase( (lines[0].length()-1) ,1);
    29. lines[1].erase( (lines[1].length()-1) ,1);
    30. lines[2].erase( (lines[2].length()-1) ,1);
    31. lines[3].erase( (lines[3].length()-1) ,1);
    32. lines[4].erase( (lines[4].length()-1) ,1);
    33. lines[5].erase( (lines[5].length()-1) ,1);
    34.  
    35. info.operatorTel = lines[0];
    36. info.operatorName = lines[1];
    37. info.stationNum = lines[2];
    38. info.stationLoc = lines[3];
    39. info.instDate = lines[4];
    40. info.maintDate = lines[5];
    41.  
    42. }
    43. else
    44. cout<<"could not open info file\n";
    45. }
    To copy to clipboard, switch view to plain text mode 
    ------------------------------------------------------------------------------------
    Qt Code:
    1. void InfoClass::writeStructToStream (int &on_len, int &ot_len, int &sn_len, int &sl_len,
    2. int &id_len, int &md_len, string &buffer)
    3. {
    4. on_len=info.operatorName.length();
    5. ot_len=info.operatorTel.length();
    6. sn_len=info.stationNum.length();
    7. sl_len=info.stationLoc.length();
    8. id_len=info.instDate.length();
    9. md_len=info.maintDate.length();
    10.  
    11. //int totLen=on_len+ot_len+sn_len+sl_len+id_len+md_len/*+1*/;
    12. string tmpbuf="";
    13. tmpbuf += info.operatorTel;
    14. tmpbuf += info.operatorName;
    15. tmpbuf += info.stationNum;
    16. tmpbuf += info.stationLoc;
    17. tmpbuf += info.instDate;
    18. tmpbuf += info.maintDate;
    19.  
    20. buffer=tmpbuf;
    21. }
    To copy to clipboard, switch view to plain text mode 
    -------------------------------------------------------------------------
    Last edited by jacek; 3rd January 2007 at 17:53. Reason: wrapped too long lines

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problem with storing greek chars to a buffer (os linux)

    Maybe the string contains some \0 characters because of using unicode? Strcpy would then only copy the part of the string until the first occurence of the null character. You shouldn't use strcpy for extended strings. Either use memcpy or encode the string somehow to contain only valid values.

  3. #3
    Join Date
    Jul 2006
    Posts
    79
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: problem with storing greek chars to a buffer (os linux)

    i did change that but nothing changed.
    english characters and numbers work fine.
    if i add greek the application can not handle it.
    i just tried the opposite too. from the other application ( a GUI) i type in english chars, and this application (the controller) reads them fine and saves them fine. if i type greek from the GUI, the RIGHT ascii characters codes appear on the sharedMem but the controller can not read them (a cout at runtime outputs little squares on the console) and in the file what is saved is 'ÈáÃ*Üóçò' (if it is readable - that does not look lie greek chars to my end).

    i tried in main.cpp to do a setlocale(LC_ALL,"el_GR.ISO-8859-7"); but no luck either.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problem with storing greek chars to a buffer (os linux)

    How do you save that buffer to a shared mem segment? How do you extract the data from the string? Do you use c_str()? What happens if you write that data to a file instead of storing it in the shared segment?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.