of_delete


pfcapsrv.pbl   >   pfc_n_cst_inifile   >   of_delete   

Full name pfc_n_cst_inifile.of_delete
Access public
Extend of integer
Return value integer
Prototype public function integer of_delete(string,string)

Name Datatype
No Data

Name Datatype
lb_sectionfound boolean
lb_skipline boolean
lblb_newfile blob
li_file integer
li_filewriterc integer
li_rc integer
ll_first long
ll_last long
ll_length long
ll_pos long
lnv_filesrv n_cst_filesrv
lnv_string n_cst_string
ls_line string
ls_section string
ls_temp string

public function integer of_delete (string as_file, string as_section);//////////////////////////////////////////////////////////////////////////////
//
//	Function:  		of_Delete
//
//	Access:  		public
//
//	Arguments:		
//	as_file			The .ini file.
//	as_section		The section name to remove from the INI file.
//						(Do not include the brackets with this argument.)
//
//	Returns:  		Integer
//						 1	success
//						 0	section does not exist in the INI file.
//						-1	error
//						-2 if .INI file does not exist or has not been specified.
//
//	Description:  	Removes the specified section and all entries for 
//						that section from the INI file.
//
//////////////////////////////////////////////////////////////////////////////
//
//	Revision History
//
//	Version
//	5.0   Initial version
//	5.0.03	Function is now case-insensitive
//
//////////////////////////////////////////////////////////////////////////////
//
//	Copyright © 1996-1997 Sybase, Inc. and its subsidiaries.  All rights reserved.
//	Any distribution of the PowerBuilder Foundation Classes (PFC)
//	source code by other than Sybase, Inc. and its subsidiaries is prohibited.
//
//////////////////////////////////////////////////////////////////////////////

blob			lblb_newfile
boolean		lb_skipline
boolean		lb_sectionfound
integer		li_file
integer		li_rc = 1
integer		li_filewriterc
long			ll_length
long			ll_first
long			ll_last
long			ll_pos
string		ls_line
string		ls_section
string		ls_temp
n_cst_string 	lnv_string
n_cst_filesrv 	lnv_filesrv

SetPointer (Hourglass!)

// Determine if file exists.
if not FileExists (as_file) then
	return -2
end if

// Open file for reading (check rc).
ll_length = FileLength (as_file)
li_file = FileOpen (as_file)
if li_file = -1 then	return li_file

//////////////////////////////////////////////////////////////////////////////
// Read the file and locate the desired section that should be removed.
//////////////////////////////////////////////////////////////////////////////
do while li_rc >= 0
	
	// Read one line from the file (validate the rc).
	li_rc = FileRead (li_file, ls_line)
	if li_rc = -1 then
		return -1
	end if

	// Check that at least one character was read.
	if li_rc >= 1 then
		// Look for a section header components (the OpenBracket and CloseBracket (if any)).
		ll_first = Pos (ls_line, "[")
		ll_last = Pos (ls_line, "]")
		
		// Was section header found?
		if ll_first >0 and ll_last >0 then
			// Yes, a section has been found.
			// Get the name of the section.
			ls_temp = lnv_string.of_LeftTrim (ls_line, true, true)
			if Left (ls_temp, 1) = "[" then
				ll_pos = Pos (ls_temp, "]")
				ls_section = Mid (ls_temp, 2, ll_pos - 2)
				// Determine if this is the section being searched for.				
				if Lower (ls_section) = Lower (as_section) then
					// The search for section has been found.
					lb_sectionfound = true
					// Skip ALL lines until a new section is found.
					lb_skipline = true
				else
					// Do not skip this section or just simply Stop skipping.
					lb_skipline = false
				end if
			end if
		end if
	end if

	// Add the carriage control.
	ls_line = ls_line + of_GetLineEnding()

	// Create the output file by including all lines not
	// marked to be skipped.
	if li_rc >= 0 and not lb_skipline then
		lblb_newfile = lblb_newfile + Blob (ls_line)
	end if
loop 

// Close the input file
FileClose (li_file)

//If the section was not found, return
if not lb_sectionfound then
	return 0
end if

//Replace the file with the section removed.
li_rc = f_SetFilesrv(lnv_filesrv, True)
If li_rc <> 1 Then Return -1
li_filewriterc = lnv_filesrv.of_FileWrite (as_file, lblb_newfile, False)
li_rc = f_SetFilesrv(lnv_filesrv, False)

return li_filewriterc

end function

     
Name Owner
pfc_n_cst_apppreference.of_save pfc_n_cst_apppreference
pfc_n_cst_winsrv_preference.of_save pfc_n_cst_winsrv_preference

     
Name Owner
systemfunctions.blob systemfunctions
systemfunctions.fileclose systemfunctions
systemfunctions.fileexists systemfunctions
systemfunctions.filelength systemfunctions
systemfunctions.fileopen systemfunctions
systemfunctions.fileread systemfunctions
systemfunctions.left systemfunctions
systemfunctions.lower systemfunctions
systemfunctions.mid systemfunctions
systemfunctions.pos systemfunctions
systemfunctions.setpointer systemfunctions
pfc_n_cst_string.of_lefttrim pfc_n_cst_string
pfc_n_cst_inifile.of_getlineending pfc_n_cst_inifile
pfc_n_cst_filesrv.of_FileWrite pfc_n_cst_filesrv
f_setfilesrv.f_setfilesrv f_setfilesrv

     
Full name
No Data

     
Name Scope
No Data