INI files handling exists BUG

Moderator: Rathinagiri

Post Reply
huiyi_ch
Posts: 172
Joined: Sat May 21, 2016 5:27 am

INI files handling exists BUG

Post by huiyi_ch »

<r>经过测试,我发现,在读取INI 文件时,在HMG3.4.4版中仍存在BUG,我以前曾经反映过,经过Pablo César的修改后并下发了补丁http://www.hmgforum.com/viewtopic.php?f=43&t=4 ... ini#p47988 ,好像在HMG3.4.4中并未得到修正。我一直使用Pablo César提供的补丁。近日我又发现,当ENTRY为汉字时,无法读取到SECTION下的键值。 <br/>
<br/>
After testing, I found that bugs still exist in the hmg3.4.4 version when I read the ini file, which I have reflected before, modified by Pablo César and patched. I have been using the patch provided by Pablo César. Recently, I found that when entry is Chinese character, I can not read the key value under section. <br/>

<CODE><s>

Code: Select all

</s><i>
</i>#include <hmg.ch>
FUNCTION main()
LOCAL cIniFile := GetStartupFolder() + '\demo.ini'
LOCAL aRet

If !File(cIniFile)
   SetIniValue(cIniFile)
Endif
*msgdebug( HMG_GetPrivateProfileSection ( cIniFile, "HMG" ) )
aRet := GetValue(cIniFile)

AEVAL( aRet, { |x| MsgDebug( x, ValType(x) ) } )
RETURN NIL


PROCEDURE SetIniValue( cIni )

BEGIN INI FILE cIni
  SET SECTION 'HMG'  ENTRY '版本' TO 3.43            
  SET SECTION 'HMG'  ENTRY 'DESCRIBE_1' TO "我非常喜欢HMG!"      
  SET SECTION 'HMG'  ENTRY 'DESCRIBE_2' TO "I LIKE HMG VERY MUCH!"
  SET SECTION 'HMG1' ENTRY 'DESCRIBE_3' TO {"1",2,.T.}
  SET SECTION 'HMG1' ENTRY 'DESCRIBE_4' TO Date()
  SET SECTION 'HMG1' ENTRY 'DESCRIBE_5' TO Nil
  SET SECTION 'HMG1' ENTRY 'DESCRIBE_6' TO .F.
END INI

RETURN


FUNCTION GetValue( cIni )
LOCAL cDescrib_1:="", cDescrib_2:="", cDescrib_3:={}
LOCAL cDescrib_4:=Date(), cDescrib_5:=Nil, cDescrib_6:=.F., nVers:=0

BEGIN INI FILE (cIni)
// _GetIni( cSection, cEntry, cDefault, uVar )
// cDescrib_1 := _GetIni( "HMG", "DESCRIBE_1",, cDescrib_1 )
   GET cDescrib_1 SECTION 'HMG'  ENTRY 'DESCRIBE_1' DEFAULT '' //display "我非常" in 3.4.4 version ,the read value is incomplete and there is a bug  ,However, using the patch provided by Pablo César, the display is normal  
   GET cDescrib_2 SECTION 'HMG'  ENTRY 'DESCRIBE_2' DEFAULT ''
   GET nVers      SECTION 'HMG'  ENTRY '版本' DEFAULT 3.43  //ok in hmg3.4.4 version ,But the patch provided by the Pablo César is unreadable and displays a blank
   GET cDescrib_3 SECTION 'HMG1' ENTRY 'DESCRIBE_3' DEFAULT {}
   GET cDescrib_4 SECTION 'HMG1' ENTRY 'DESCRIBE_4' DEFAULT Date()
   GET cDescrib_5 SECTION 'HMG1' ENTRY 'DESCRIBE_5' DEFAULT Nil
   GET cDescrib_6 SECTION 'HMG1' ENTRY 'DESCRIBE_6' DEFAULT .F.
END INI
RETURN {cDescrib_1, cDescrib_2, nVers, cDescrib_3, cDescrib_4, cDescrib_5, cDescrib_6}
<e>
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: INI files handling exists BUG

Post by edk »

Hello Hui Yi.
I'm not an expert in C, but try to replace the file c_ini.c from the attachment to the folder c:\hmg.3.4.4\SOURCE\Ini\
c_ini.7z
(1.96 KiB) Downloaded 482 times
Then rebuild the INI library with c:\hmg.3.4.4\SOURCE\Ini\buildlib.bat

Of course, before replacing the file, make sure to back it up. ;)

I tested on the original version of h_ini.prg from HMG 3.4.4 (without Pablo's patches)
Bez tytułu.png
Bez tytułu.png (3.08 KiB) Viewed 58935 times
Edward.
huiyi_ch
Posts: 172
Joined: Sat May 21, 2016 5:27 am

Re: INI files handling exists BUG

Post by huiyi_ch »

Hello EDK.
First of all, thank you for your reply in time!
I have preliminarily tested your patch, which is normal when hmg-Unicode does not set CODE PAGE. But if CODE PAGE is set up, Some unknown characters will appear in the result of the program running. See an example:

Code: Select all

#include <hmg.ch>
request hb_codepage_gbk
FUNCTION main()
LOCAL cIniFile := GetStartupFolder() + '\demo.ini'
LOCAL aRet
hb_CdPSelect("GBK")
If !File(cIniFile)
   SetIniValue(cIniFile)
Endif
*msgdebug( HMG_GetPrivateProfileSection ( cIniFile, "HMG" ) )
aRet := GetValue(cIniFile)

AEVAL( aRet, { |x| MsgDebug( x, ValType(x) ) } )
RETURN NIL


PROCEDURE SetIniValue( cIni )

BEGIN INI FILE cIni
  SET SECTION 'HMG'  ENTRY '我的HMG版本是' TO 3.43            
  SET SECTION 'HMG'  ENTRY 'DESCRIBE_1' TO "我非常喜欢HMG!它太强大了"      
  SET SECTION 'HMG'  ENTRY 'DESCRIBE_2' TO "I LIKE HMG VERY MUCH!"
  SET SECTION 'HMG1' ENTRY 'DESCRIBE_3' TO {"1",2,.T.}
  SET SECTION 'HMG1' ENTRY 'DESCRIBE_4' TO Date()
  SET SECTION 'HMG1' ENTRY 'DESCRIBE_5' TO Nil
  SET SECTION 'HMG1' ENTRY 'DESCRIBE_6' TO .F.
END INI

RETURN


FUNCTION GetValue( cIni )
LOCAL cDescrib_1:="", cDescrib_2:="", cDescrib_3:={}
LOCAL cDescrib_4:=Date(), cDescrib_5:=Nil, cDescrib_6:=.F., nVers:=0

BEGIN INI FILE (cIni)
// _GetIni( cSection, cEntry, cDefault, uVar )
// cDescrib_1 := _GetIni( "HMG", "DESCRIBE_1",, cDescrib_1 )
   GET cDescrib_1 SECTION 'HMG'  ENTRY 'DESCRIBE_1' DEFAULT ''
   GET cDescrib_2 SECTION 'HMG'  ENTRY 'DESCRIBE_2' DEFAULT ''
   GET nVers      SECTION 'HMG'  ENTRY '我的HMG版本是' DEFAULT 3.43 
   GET cDescrib_3 SECTION 'HMG1' ENTRY 'DESCRIBE_3' DEFAULT {}
   GET cDescrib_4 SECTION 'HMG1' ENTRY 'DESCRIBE_4' DEFAULT Date()
   GET cDescrib_5 SECTION 'HMG1' ENTRY 'DESCRIBE_5' DEFAULT Nil
   GET cDescrib_6 SECTION 'HMG1' ENTRY 'DESCRIBE_6' DEFAULT .F.
END INI
RETURN {cDescrib_1, cDescrib_2, nVers, cDescrib_3, cDescrib_4, cDescrib_5, cDescrib_6}

display value of DESCRIBE_1
display value of DESCRIBE_1
p.png (17.1 KiB) Viewed 58882 times
demo.ini
demo.ini
config.png (60.88 KiB) Viewed 58882 times
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: INI files handling exists BUG

Post by edk »

Hey.
It seems to me that this is not the fault of my patch, because it only improves the collection of values from the INI file.
There is a problem here at the stage of creating the INI file.
Please note that the source file of prg is probably encoded in UNICODE (UTF-8). In your code, however, you have defined the GBK Simplified Chinese code page:

Code: Select all

hb_CdPSelect("GBK")
You are trying to save the characters string hardcoded in UTF-8 into the INI file that will be encoded in GBK.
config.png
config.png (69.17 KiB) Viewed 58834 times
See what happens if you convert a string from UTF-8 to GBK before saving it to the INI file?

Code: Select all

 SET SECTION 'HMG'  ENTRY 'DESCRIBE_1' TO hb_Utf8ToStr( "我非常喜欢HMG!它太强大了" )
You can also try to save the prg file in the GBK code page, then you do not do character conversion.

I tested on the Polish ISO code page and it seems to me that it works correctly.
huiyi_ch
Posts: 172
Joined: Sat May 21, 2016 5:27 am

Re: INI files handling exists BUG

Post by huiyi_ch »

Hello Edward.
After further testing, that your patch is correct. I made a low - level error, which was caused by the incorrect encoded of my PRG file. I'm so sorry for you. I think this patch can be added to the next HMG version.
Thank you again for your hard work. You are so great!
HUIYI
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: INI files handling exists BUG

Post by edk »

没关系. ;)
huiyi_ch
Posts: 172
Joined: Sat May 21, 2016 5:27 am

Re: INI files handling exists BUG

Post by huiyi_ch »

edk wrote: Mon Mar 26, 2018 1:25 pm Hello Hui Yi.
I'm not an expert in C, but try to replace the file c_ini.c from the attachment to the folder c:\hmg.3.4.4\SOURCE\Ini\
c_ini.7z

Then rebuild the INI library with c:\hmg.3.4.4\SOURCE\Ini\buildlib.bat

Of course, before replacing the file, make sure to back it up. ;)

I tested on the original version of h_ini.prg from HMG 3.4.4 (without Pablo's patches)

Bez tytułu.png

Edward.
hello,
After testing, when HMG was working with INI files, I found bugs in both the new version of hmg.3.6 and earlier, and although Edward released patches, subsequent versions did not correct them.
Post Reply