diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 52b667e67c..b2ba8e6f37 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,19 @@ 2008-12-31 13:59 UTC+0100 Foo Bar */ +2008-05-12 14:24 UTC+0100 Viktor Szakats (harbour.01 syenar hu) + * bin/bld.bat + + Added hbpcre to lib list. + + * source/rtl/hbini.prg + ; Some formatting. + + * tests/Makefile + + tests/parseini.prg + + tests/parseini.ini + + tests/parseins.ini + + Added .ini handling tests. Adapted from xhb. + 2008-05-12 13:56 UTC+0100 Viktor Szakats (harbour.01 syenar hu) * bin/bld.bat + Added %HB_USER_LIB% for w32/msvc. diff --git a/harbour/bin/bld.bat b/harbour/bin/bld.bat index e4eeabbf5d..4c6addb998 100644 --- a/harbour/bin/bld.bat +++ b/harbour/bin/bld.bat @@ -174,7 +174,7 @@ if "%HB_INC_INSTALL%" == "" set HB_INC_INSTALL=..\include\ if not "%HB_COMPILER%" == "rsx32" GOTO A_DOS_RSX32_NOT - gcc %1.c -Zrsx32 %CFLAGS% -I%HB_INC_INSTALL% -L%HB_LIB_INSTALL% -lhbcpage -lhbdebug -lhbvm -lhbrtl -l%_HB_GT_LIB% -lhblang -lhbrdd -lhbrtl -lhbvm -lhbmacro -lhbpp -lrddfpt -lrddntx -lrddcdx -lhbsix -lhbcommon + gcc %1.c -Zrsx32 %CFLAGS% -I%HB_INC_INSTALL% -L%HB_LIB_INSTALL% -lhbcpage -lhbdebug -lhbvm -lhbrtl -l%_HB_GT_LIB% -lhblang -lhbrdd -lhbrtl -lhbvm -lhbmacro -lhbpp -lrddfpt -lrddntx -lrddcdx -lhbsix -lhbcommon -lhbpcre goto END :A_DOS_RSX32_NOT @@ -198,6 +198,7 @@ if "%HB_INC_INSTALL%" == "" set HB_INC_INSTALL=..\include\ echo LIB rddfpt.lib >> build.tmp echo LIB hbsix.lib >> build.tmp echo LIB hbcommon.lib >> build.tmp + echo LIB hbpcre.lib >> build.tmp wlink @build.tmp del build.tmp goto END @@ -208,13 +209,13 @@ if not "%HB_ARCHITECTURE%" == "w32" goto A_OS2 if "%HB_GT_LIB%" == "" set _HB_GT_LIB=gtwin - if "%HB_COMPILER%" == "bcc32" bcc32 -O2 -d %CFLAGS% -I%HB_INC_INSTALL% -L%HB_LIB_INSTALL% %1.c %HB_USER_LIBS% hbcpage.lib hbdebug.lib hbvm.lib hbrtl.lib %_HB_GT_LIB%.lib hblang.lib hbrdd.lib hbmacro.lib hbpp.lib rddfpt.lib rddntx.lib rddcdx.lib hbsix.lib hbcommon.lib + if "%HB_COMPILER%" == "bcc32" bcc32 -O2 -d %CFLAGS% -I%HB_INC_INSTALL% -L%HB_LIB_INSTALL% %1.c %HB_USER_LIBS% hbcpage.lib hbdebug.lib hbvm.lib hbrtl.lib %_HB_GT_LIB%.lib hblang.lib hbrdd.lib hbmacro.lib hbpp.lib rddfpt.lib rddntx.lib rddcdx.lib hbsix.lib hbcommon.lib hbpcre.lib - if "%HB_COMPILER%" == "gcc" gcc %1.c -o%1.exe %CFLAGS% -I%HB_INC_INSTALL% -L%HB_LIB_INSTALL% -lhbcpage -lhbdebug -lhbvm -lhbrtl -l%_HB_GT_LIB% -lhblang -lhbrdd -lhbrtl -lhbvm -lhbmacro -lhbpp -lrddfpt -lrddntx -lrddcdx -lhbsix -lhbcommon - if "%HB_COMPILER%" == "mingw32" gcc %1.c -o%1.exe %CFLAGS% -mno-cygwin -I%HB_INC_INSTALL% %HB_INC_TEMP% -L%HB_LIB_INSTALL% -lhbcpage -lhbdebug -lhbvm -lhbrtl -l%_HB_GT_LIB% -lhblang -lhbrdd -lhbrtl -lhbvm -lhbmacro -lhbpp -lrddfpt -lrddntx -lrddcdx -lhbsix -lhbcommon - if "%HB_COMPILER%" == "rsxnt" gcc %1.c -Zwin32 %CFLAGS% -I%HB_INC_INSTALL% -L%HB_LIB_INSTALL% -lhbcpage -lhbdebug -lhbvm -lhbrtl -l%_HB_GT_LIB% -lhblang -lhbrdd -lhbrtl -lhbvm -lhbmacro -lhbpp -lrddfpt -lrddntx -lrddcdx -lhbsix -lhbcommon + if "%HB_COMPILER%" == "gcc" gcc %1.c -o%1.exe %CFLAGS% -I%HB_INC_INSTALL% -L%HB_LIB_INSTALL% -lhbcpage -lhbdebug -lhbvm -lhbrtl -l%_HB_GT_LIB% -lhblang -lhbrdd -lhbrtl -lhbvm -lhbmacro -lhbpp -lrddfpt -lrddntx -lrddcdx -lhbsix -lhbcommon -lhbpcre + if "%HB_COMPILER%" == "mingw32" gcc %1.c -o%1.exe %CFLAGS% -mno-cygwin -I%HB_INC_INSTALL% %HB_INC_TEMP% -L%HB_LIB_INSTALL% -lhbcpage -lhbdebug -lhbvm -lhbrtl -l%_HB_GT_LIB% -lhblang -lhbrdd -lhbrtl -lhbvm -lhbmacro -lhbpp -lrddfpt -lrddntx -lrddcdx -lhbsix -lhbcommon -lhbpcre + if "%HB_COMPILER%" == "rsxnt" gcc %1.c -Zwin32 %CFLAGS% -I%HB_INC_INSTALL% -L%HB_LIB_INSTALL% -lhbcpage -lhbdebug -lhbvm -lhbrtl -l%_HB_GT_LIB% -lhblang -lhbrdd -lhbrtl -lhbvm -lhbmacro -lhbpp -lrddfpt -lrddntx -lrddcdx -lhbsix -lhbcommon -lhbpcre - if "%HB_COMPILER%" == "msvc" cl -TP -W3 %CFLAGS% -I%HB_INC_INSTALL% %1.c /link /subsystem:CONSOLE %HB_USER_LIBS% %HB_LIB_INSTALL%\hbcpage.lib %HB_LIB_INSTALL%\hbdebug.lib %HB_LIB_INSTALL%\hbvm.lib %HB_LIB_INSTALL%\hbrtl.lib %HB_LIB_INSTALL%\%_HB_GT_LIB%.lib %HB_LIB_INSTALL%\hblang.lib %HB_LIB_INSTALL%\hbrdd.lib %HB_LIB_INSTALL%\hbmacro.lib %HB_LIB_INSTALL%\hbpp.lib %HB_LIB_INSTALL%\rddntx.lib %HB_LIB_INSTALL%\rddcdx.lib %HB_LIB_INSTALL%\rddfpt.lib %HB_LIB_INSTALL%\hbsix.lib %HB_LIB_INSTALL%\hbcommon.lib user32.lib winspool.lib + if "%HB_COMPILER%" == "msvc" cl -TP -W3 %CFLAGS% -I%HB_INC_INSTALL% %1.c /link /subsystem:CONSOLE %HB_USER_LIBS% %HB_LIB_INSTALL%\hbcpage.lib %HB_LIB_INSTALL%\hbdebug.lib %HB_LIB_INSTALL%\hbvm.lib %HB_LIB_INSTALL%\hbrtl.lib %HB_LIB_INSTALL%\%_HB_GT_LIB%.lib %HB_LIB_INSTALL%\hblang.lib %HB_LIB_INSTALL%\hbrdd.lib %HB_LIB_INSTALL%\hbmacro.lib %HB_LIB_INSTALL%\hbpp.lib %HB_LIB_INSTALL%\rddntx.lib %HB_LIB_INSTALL%\rddcdx.lib %HB_LIB_INSTALL%\rddfpt.lib %HB_LIB_INSTALL%\hbsix.lib %HB_LIB_INSTALL%\hbcommon.lib %HB_LIB_INSTALL%\hbpcre.lib user32.lib winspool.lib if "%HB_COMPILER%" == "msvc" echo Ignore LNK4033 warning :C_WATCOM @@ -238,6 +239,7 @@ if not "%HB_ARCHITECTURE%" == "w32" goto A_OS2 echo LIB hbsix.lib >> build.tmp echo LIB hbrdd.lib >> build.tmp echo LIB hbcommon.lib >> build.tmp + echo LIB hbpcre.lib >> build.tmp echo LIB kernel32.lib >> build.tmp echo LIB user32.lib >> build.tmp echo LIB winspool.lib >> build.tmp @@ -253,8 +255,8 @@ if not "%HB_ARCHITECTURE%" == "w32" goto A_OS2 if "%HB_GT_LIB%" == "" set _HB_GT_LIB=gtos2 - if "%HB_COMPILER%" == "gcc" gcc %1.c %CFLAGS% -I%HB_INC_INSTALL% -L%HB_LIB_INSTALL% -lhbcpage -lhbdebug -lhbvm -lhbrtl -l%_HB_GT_LIB% -lhblang -lhbrdd -lhbrtl -lhbvm -lhbmacro -lhbpp -lrddfpt -lrddntx -lrddcdx -lhbsix -lhbcommon - if "%HB_COMPILER%" == "icc" icc /Gs+ /W2 /Se /Sd+ /Ti+ /C- /Tp %CFLAGS% -I%HB_INC_INSTALL% %1.c %HB_LIB_INSTALL%\hbcpage.lib %HB_LIB_INSTALL%\hbdebug.lib %HB_LIB_INSTALL%\hbvm.lib %HB_LIB_INSTALL%\hbrtl.lib %HB_LIB_INSTALL%\%_HB_GT_LIB%.lib %HB_LIB_INSTALL%\hblang.lib %HB_LIB_INSTALL%\hbrdd.lib %HB_LIB_INSTALL%\hbrtl.lib %HB_LIB_INSTALL%\hbvm.lib %HB_LIB_INSTALL%\hbmacro.lib %HB_LIB_INSTALL%\hbpp.lib %HB_LIB_INSTALL%\rddfpt.lib %HB_LIB_INSTALL%\rddntx.lib %HB_LIB_INSTALL%\rddcdx.lib %HB_LIB_INSTALL%\hbsix.lib %HB_LIB_INSTALL%\hbcommon.lib + if "%HB_COMPILER%" == "gcc" gcc %1.c %CFLAGS% -I%HB_INC_INSTALL% -L%HB_LIB_INSTALL% -lhbcpage -lhbdebug -lhbvm -lhbrtl -l%_HB_GT_LIB% -lhblang -lhbrdd -lhbrtl -lhbvm -lhbmacro -lhbpp -lrddfpt -lrddntx -lrddcdx -lhbsix -lhbcommon -lhbpcre + if "%HB_COMPILER%" == "icc" icc /Gs+ /W2 /Se /Sd+ /Ti+ /C- /Tp %CFLAGS% -I%HB_INC_INSTALL% %1.c %HB_LIB_INSTALL%\hbcpage.lib %HB_LIB_INSTALL%\hbdebug.lib %HB_LIB_INSTALL%\hbvm.lib %HB_LIB_INSTALL%\hbrtl.lib %HB_LIB_INSTALL%\%_HB_GT_LIB%.lib %HB_LIB_INSTALL%\hblang.lib %HB_LIB_INSTALL%\hbrdd.lib %HB_LIB_INSTALL%\hbrtl.lib %HB_LIB_INSTALL%\hbvm.lib %HB_LIB_INSTALL%\hbmacro.lib %HB_LIB_INSTALL%\hbpp.lib %HB_LIB_INSTALL%\rddfpt.lib %HB_LIB_INSTALL%\rddntx.lib %HB_LIB_INSTALL%\rddcdx.lib %HB_LIB_INSTALL%\hbsix.lib %HB_LIB_INSTALL%\hbcommon.lib %HB_LIB_INSTALL%\hbpcre.lib goto END :A_LINUX @@ -263,7 +265,7 @@ if not "%HB_ARCHITECTURE%" == "w32" goto A_OS2 if "%HB_GT_LIB%" == "" set _HB_GT_LIB=gtstd - if "%HB_COMPILER%" == "gcc" gcc %1.c %CFLAGS% -I%HB_INC_INSTALL% -L../lib -lhbcpage -lhbdebug -lhbvm -lhbrtl -l%_HB_GT_LIB% -lhblang -lhbrdd -lhbrtl -lhbvm -lhbmacro -lhbpp -lrddfpt -lrddntx -lrddcdx -lhbsix -lhbcommon + if "%HB_COMPILER%" == "gcc" gcc %1.c %CFLAGS% -I%HB_INC_INSTALL% -L../lib -lhbcpage -lhbdebug -lhbvm -lhbrtl -l%_HB_GT_LIB% -lhblang -lhbrdd -lhbrtl -lhbvm -lhbmacro -lhbpp -lrddfpt -lrddntx -lrddcdx -lhbsix -lhbcommon -lhbpcre goto END :CLEANUP diff --git a/harbour/source/rtl/hbini.prg b/harbour/source/rtl/hbini.prg index 7b575abc92..35e3307d34 100644 --- a/harbour/source/rtl/hbini.prg +++ b/harbour/source/rtl/hbini.prg @@ -6,7 +6,7 @@ * xHarbour Project source code: * Handling .ini files * - * Copyright 2002 Giancarlo Niccolai [gian@niccolai.ws] + * Copyright 2002 Giancarlo Niccolai * www - http://www.xharbour.org * * this program is free software; you can redistribute it and/or modify @@ -83,36 +83,39 @@ STATIC s_cHalfLineComment := "#" PROCEDURE hb_IniSetComment( cLc, cHlc ) + s_cLineComment := cLc s_cHalfLineComment := cHlc -RETURN -FUNCTION HB_IniNew( bAutoMain ) + RETURN + +FUNCTION HB_IniNew( lAutoMain ) LOCAL hIni := hb_Hash() - IF bAutoMain + IF lAutoMain hIni[ "MAIN" ] := hb_Hash() ENDIF -RETURN hIni + RETURN hIni -FUNCTION hb_IniRead( cFileSpec, bKeyCaseSens, cSplitters, bAutoMain ) + +FUNCTION hb_IniRead( cFileSpec, lKeyCaseSens, cSplitters, lAutoMain ) LOCAL hIni := hb_Hash() /* Default case sensitiveness for keys */ - DEFAULT bKeyCaseSens TO .T. + DEFAULT lKeyCaseSens TO .T. DEFAULT cSplitters TO "=|:" - DEFAULT bAutoMain TO .T. + DEFAULT lAutoMain TO .T. - hb_HCaseMatch( hIni, bKeyCaseSens ) + hb_HCaseMatch( hIni, lKeyCaseSens ) - IF bAutoMain + IF lAutoMain hIni[ "MAIN" ] := hb_Hash() ENDIF -RETURN hb_IniRdLow( hIni, cFileSpec, bKeyCaseSens, cSplitters, bAutoMain ) + RETURN hb_IniRdLow( hIni, cFileSpec, lKeyCaseSens, cSplitters, lAutoMain ) -STATIC FUNCTION hb_IniRdLow( hIni, cFileSpec, bKeyCaseSens, cSplitters, bAutoMain ) +STATIC FUNCTION hb_IniRdLow( hIni, cFileSpec, lKeyCaseSens, cSplitters, lAutoMain ) LOCAL aFiles LOCAL cFile, nLen LOCAL aKeyVal, hCurrentSection @@ -151,7 +154,7 @@ STATIC FUNCTION hb_IniRdLow( hIni, cFileSpec, bKeyCaseSens, cSplitters, bAutoMai FClose( hFile ) /* Always begin with the MAIN section */ - IF bAutoMain + IF lAutoMain hCurrentSection := hIni[ "MAIN" ] ELSE hCurrentSection := hIni @@ -215,7 +218,7 @@ STATIC FUNCTION hb_IniRdLow( hIni, cFileSpec, bKeyCaseSens, cSplitters, bAutoMai IF Len( aKeyVal[ 2 ] ) == 0 LOOP ENDIF - hb_IniRdLow( hIni, aKeyVal[ 2 ], bKeyCaseSens, cSplitters, bAutoMain ) + hb_IniRdLow( hIni, aKeyVal[ 2 ], lKeyCaseSens, cSplitters, lAutoMain ) cLine := "" LOOP ENDIF @@ -226,7 +229,7 @@ STATIC FUNCTION hb_IniRdLow( hIni, cFileSpec, bKeyCaseSens, cSplitters, bAutoMai cLine := AllTrim( aKeyVal[ 2 ] ) IF Len( cLine ) != 0 hCurrentSection := hb_Hash() - IF ! bKeyCaseSens + IF ! lKeyCaseSens cLine := Upper( cLine ) ENDIF hIni[ cLine ] := hCurrentSection @@ -244,7 +247,7 @@ STATIC FUNCTION hb_IniRdLow( hIni, cFileSpec, bKeyCaseSens, cSplitters, bAutoMai ENDIF /* If not case sensitive, use upper keys */ - IF ! bKeyCaseSens + IF ! lKeyCaseSens aKeyVal[ 1 ] := Upper( aKeyVal[ 1 ] ) ENDIF @@ -252,10 +255,10 @@ STATIC FUNCTION hb_IniRdLow( hIni, cFileSpec, bKeyCaseSens, cSplitters, bAutoMai cLine := "" ENDDO -RETURN hIni + RETURN hIni -FUNCTION hb_IniWrite( xFileName, hIni, cCommentBegin, cCommentEnd, bAutoMain ) +FUNCTION hb_IniWrite( xFileName, hIni, cCommentBegin, cCommentEnd, lAutoMain ) LOCAL hFile LOCAL lClose LOCAL cNewLine := hb_OSNewLine() @@ -286,10 +289,10 @@ FUNCTION hb_IniWrite( xFileName, hIni, cCommentBegin, cCommentEnd, bAutoMain ) ENDIF ENDIF - DEFAULT bAutoMain TO .T. + DEFAULT lAutoMain TO .T. /* Write toplevel section */ - IF bAutoMain + IF lAutoMain /* When automain is on, write the main section */ hb_HEval( hIni[ "MAIN" ], ; { |cKey, xVal| FWrite( hFile, hb_CStr( cKey ) + " = " + ; @@ -305,7 +308,7 @@ FUNCTION hb_IniWrite( xFileName, hIni, cCommentBegin, cCommentEnd, bAutoMain ) FOR EACH cSection IN hIni /* Avoid re-processing main section */ - IF bAutoMain + IF lAutoMain /* When automain is on, skip section named MAIN */ IF cSection:__enumKey == "MAIN" LOOP @@ -344,4 +347,4 @@ FUNCTION hb_IniWrite( xFileName, hIni, cCommentBegin, cCommentEnd, bAutoMain ) FClose( hFile ) ENDIF -RETURN .T. + RETURN .T. diff --git a/harbour/tests/Makefile b/harbour/tests/Makefile index aa6a6d66d9..d5ca2e41e4 100644 --- a/harbour/tests/Makefile +++ b/harbour/tests/Makefile @@ -97,6 +97,7 @@ PRG_SOURCES=\ output.prg \ overload.prg \ parexpr.prg \ + parseini.prg \ passref.prg \ procline.prg \ procname.prg \ diff --git a/harbour/tests/parseini.ini b/harbour/tests/parseini.ini new file mode 100644 index 0000000000..337211f519 --- /dev/null +++ b/harbour/tests/parseini.ini @@ -0,0 +1,38 @@ +# +# $Id$ +# + +; Demo INI file +; +; Copyright 2003 Giancarlo Niccolai (gian@niccolai.ws) +; (showing another style of comment here ) + +# This is the MAIN section + +Procedure = Demo ini file +Name = Parseini.ini + +#including a subfile +include parseins.ini + +[Files] #Declaring files section +Path=/home/pub +Filename: foobar.pdf # variable declared with ':' + +Long= A Data || + Spreading || + On varius lines || + here. + +[Printers] +LPT1 = \\HEAD\Lexmark + +#including a subfile +include parseins.ini + +#invalid line +An invalid line + +# +# End! +# diff --git a/harbour/tests/parseini.prg b/harbour/tests/parseini.prg new file mode 100644 index 0000000000..bbfa40e10d --- /dev/null +++ b/harbour/tests/parseini.prg @@ -0,0 +1,110 @@ +/* + * $Id$ + */ + +****************************************************************** +* Test for Ini file reading/writing +* +* Giancarlo Niccolai +* + +PROCEDURE Main( cName ) + LOCAL aIni, aSect + LOCAL cSection + LOCAL cKey + LOCAL nRow := 1 + + set color to w+/b + CLEAR SCREEN + @nRow++,20 SAY "H A R B O U R - .ini file parser test" + @nRow++,5 SAY "Call from command line using a .ini filename as the only parameter" + nRow++ + + IF Empty( cName ) + cName := "parseini.ini" + @nRow++, 5 SAY "Using default parseini.ini file" + ENDIF + + aIni := hb_IniRead( cName ) + + @nRow, 0 + + ? "Content of " + cName + + IF Empty( aIni ) + ? "Not a valid .ini file!" + ELSE + FOR EACH cSection IN aIni:Keys + ? + ? "Section [" + cSection + "]" + aSect := aIni[ cSection ] + + FOR EACH cKey IN aSect:Keys + ? cKey + " = " + aSect[ cKey ] + NEXT + NEXT + ENDIF + + ? + ? "Adding section 'Added', with key NEW = new" + aIni[ "Added" ] := hb_Hash() + aIni[ "Added" ][ "NEW" ] := "new" + + ? "Writing output to parseini_out.ini" + IF hb_IniWrite( "parseini_out.ini", aIni, "#Generated file; don't touch", "#End of file") + ? "File written" + ELSE + ? "Can't write file" + ENDIF + ? + ? "Press any key to next text." + Inkey(0) + ? + ? "REPEATING TESTS WITHOUT AUTOMATIC MAIN SECTION" + + aIni := hb_IniRead( cName, /*default case*/ , /*Default key indicators */ , .F. ) + + @nRow, 0 + + ? "Content of " + cName + + IF Empty( aIni ) + ? "Not a valid .ini file!" + ELSE + FOR EACH cSection IN aIni:Keys + /* Now (without automatic main), toplevel options may be in the root hash */ + aSect := aIni[ cSection ] + + IF HB_IsHash( aSect ) + /* It's a section */ + ? + ? "Section [" + cSection + "]" + + FOR EACH cKey IN aSect:Keys + ? cKey + " = " + aSect[ cKey ] + NEXT + ELSE + /* It's a toplevel option */ + ? "TOPLEVEL option:", cSection + " = " + aSect + ENDIF + NEXT + ENDIF + + ? + ? "Adding section 'Added', with key NEW = new" + aIni[ "Added" ] := hb_Hash() + aIni[ "Added" ][ "NEW" ] := "new" + + ? "Writing output to parseini_out1.ini" + IF hb_IniWrite( "parseini_out1.ini", aIni,; + "#Generated file without main auto section; don't touch", "#End of file",; + .F. ) + ? "File written" + ELSE + ? "Can't write file" + ENDIF + ? + ? "Press any key to next text." + Inkey(0) + +RETURN diff --git a/harbour/tests/parseins.ini b/harbour/tests/parseins.ini new file mode 100644 index 0000000000..38dd3a081e --- /dev/null +++ b/harbour/tests/parseins.ini @@ -0,0 +1,38 @@ +# +# $Id$ +# + +; Demo INI file +; +; Copyright 2003 Giancarlo Niccolai (gian@niccolai.ws) +; (showing another style of comment here ) + +# This is the MAIN section + +Procedure = Demo ini file +Name = Parseini.ini + +#including a subfile +include parseini2.ini + +[Files] #Declaring files section +Path=/home/pub +Filename: foobar.pdf # variable declared with ':' + +Long= A Data || + Spreading || + On varius lines || + here. + +[Printers] +LPT1 = \\HEAD\Lexmark + +#including a subfile +include parseini2.ini + +#invalid line +An invalid line + +# +# End! +#