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,string)

Name Datatype
No Data

Name Datatype
lb_entryremoved boolean
lb_sectionfound boolean
lb_skipline boolean
lblb_newfile blob
li_file integer
li_filewriterc integer
li_keylength 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, string as_key);//////////////////////////////////////////////////////////////////////////////
//
//	Function:  		of_Delete
//
//	Access:  		public
//
//	Arguments:		
//	as_file			The .ini file.
//	as_section		The section name that the entry to be deleted is in.
//							(Do not include the brackets with this argument.)
//	as_key			The key name of the entry that should be deleted from
//							the specified section.
//							(Key name is the name to the left of the "=" sign).
//
//	Returns:			Integer
//						 1	success
//						 0	section does not exist, or key name does not exist
//							within specified section.
//						-1	file error
//						-2 if .INI file does not exist or has not been specified.
//
//	Description:  	Removes the specified entry from the specified section 
//						in 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
boolean		lb_entryremoved
integer		li_file
integer		li_rc = 1
integer		li_filewriterc
integer		li_keylength
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
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 entry that should be removed.
//////////////////////////////////////////////////////////////////////////////
li_keylength = Len (as_key)
do while li_rc >= 0
	
	// Read one line from the input file (check the rc).
	li_rc = FileRead (li_file, ls_line)
	if li_rc = -1 then
		return -1
	end if
	
	if not lb_entryremoved then
		if li_rc > 0 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 header 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 section being searched for has been found.
						lb_sectionfound = true
					else
						// This is not the section being searched for.
						lb_sectionfound = false
					end if
				end if
			else
				// Is current line part of the section being searched?
				if lb_sectionfound then
					// Yes, Locate the key within the section.
					ls_temp = lnv_string.of_LeftTrim (ls_line, true, true)
					// Determine if this is the key being searched for.							
					if Lower (Left (ls_temp, li_keylength)) = Lower (as_key) then
						// Yes, the key has been found.						
						ls_temp = lnv_string.of_LeftTrim (Mid (ls_temp, li_keylength + 1), true, true)
						if Char (ls_temp) = "=" then
							// Start skipping.
							lb_skipline = true
							// The desired entry will be removed.
							lb_entryremoved = true
						end if
					end if
				end if
			end if
		end if
	else
		// Stop skipping lines.
		lb_skipline = false
	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 or key were not found, return.
if (not lb_sectionfound) or (not lb_entryremoved) then
	return 0
end if

//Replace the file with the entry 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
No Data

     
Name Owner
systemfunctions.blob systemfunctions
systemfunctions.char systemfunctions
systemfunctions.fileclose systemfunctions
systemfunctions.fileexists systemfunctions
systemfunctions.filelength systemfunctions
systemfunctions.fileopen systemfunctions
systemfunctions.fileread systemfunctions
systemfunctions.left systemfunctions
systemfunctions.len systemfunctions
systemfunctions.lower systemfunctions
systemfunctions.mid 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