From 8dd0b278fef8840a5a8ca84a59b4ed3b5081095e Mon Sep 17 00:00:00 2001 From: "David G. Holm" Date: Tue, 13 Jul 1999 00:45:18 +0000 Subject: [PATCH] See ChangeLog entry 19990712-19:30 EDT David G. Holm --- harbour/ChangeLog | 5 ++ harbour/tests/working/inifiles.prg | 81 ++++++++++++++---------------- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 9002b536c4..93dcc04e62 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,8 @@ +19990712-19:30 EDT David G. Holm + * tests/working/inifiles.prg + ! new() no longer returns nil and now checks to see if the file was + successfully opened or created before attempting to access it + 19990712-19:15 EDT David G. Holm * source/rtl/files.c ! hb_fsCreate now creates files that are read-write instead of write-only diff --git a/harbour/tests/working/inifiles.prg b/harbour/tests/working/inifiles.prg index 3e67f48816..5bf49d7c7d 100644 --- a/harbour/tests/working/inifiles.prg +++ b/harbour/tests/working/inifiles.prg @@ -61,8 +61,6 @@ static function New(cFileName) if empty(cFileName) // raise an error? outerr('No filename passed to TIniFile():New()') - return nil - else ::FileName := cFilename ::Contents := {} @@ -71,57 +69,54 @@ static function New(cFileName) if File(cFileName) hFile := fopen(cFilename, 0) - else hFile := fcreate(cFilename) endif - cFile := space(IF_BUFFER) - do while (nPos := fread(hFile, @cFile, IF_BUFFER)) > 0 - - do while !Empty(cFile) - if (nPos := At(Chr(13), cFile)) > 1 - cLine := alltrim(Left(cFile, nPos - 1)) - cFile := substr(cFile, nPos + 1) - - else - cLine := cFile - cFile := '' - endif - - if !Empty(cLine) - if Left(cLine, 1) == '[' // new section - if (nPos := At(']', cLine)) > 1 - cLine := substr(cLine, 2, nPos - 2); - - else - cLine := substr(cLine, 2) - endif - - AAdd(::Contents, { cLine, { /* this will be CurrArray */ } } ) - CurrArray := ::Contents[Len(::Contents)][2] - - elseif Left(cLine, 1) == ';' // preserve comments - AAdd( CurrArray, { NIL, cLine } ) + if hFile <> -1 + cFile := space(IF_BUFFER) + do while (nPos := fread(hFile, @cFile, IF_BUFFER)) > 0 + do while !Empty(cFile) + if (nPos := At(Chr(13), cFile)) > 1 + cLine := alltrim(Left(cFile, nPos - 1)) + cFile := substr(cFile, nPos + 1) else - if (nPos := At('=', cLine)) > 0 - cIdent := Left(cLine, nPos - 1) - cLine := SubStr(cLine, nPos + 1) - - AAdd( CurrArray, { cIdent, cLine } ) - + cLine := cFile + cFile := '' + endif + + if !Empty(cLine) + if Left(cLine, 1) == '[' // new section + if (nPos := At(']', cLine)) > 1 + cLine := substr(cLine, 2, nPos - 2); + else + cLine := substr(cLine, 2) + endif + + AAdd(::Contents, { cLine, { /* this will be CurrArray */ } } ) + CurrArray := ::Contents[Len(::Contents)][2] + + elseif Left(cLine, 1) == ';' // preserve comments + AAdd( CurrArray, { NIL, cLine } ) + else - AAdd( CurrArray, { cLine, '' } ) + if (nPos := At('=', cLine)) > 0 + cIdent := Left(cLine, nPos - 1) + cLine := SubStr(cLine, nPos + 1) + AAdd( CurrArray, { cIdent, cLine } ) + else + AAdd( CurrArray, { cLine, '' } ) + endif endif endif - endif - end + end - cFile := space(IF_BUFFER) - fread(hFile, cFile, IF_BUFFER) - end - fclose(hFile) + cFile := space(IF_BUFFER) + fread(hFile, cFile, IF_BUFFER) + end + fclose(hFile) + endif endif return Self