Conditional includes and generic routine names (was: Re: Euphoria feature request)

new topic     » topic index » view thread      » older message » newer message

> From: Pete Lomax <petelomax at blueyonder.co.uk>
> Subject: Re: Euphoria feature request
> 
> 
> On Tue, 09 Dec 2003 19:31:14 -0500, "Philip D."
> <philip1987 at hotmail.com> wrote:
> 
> 
>>If it is supported ( the user downloaded my support file 
>>for the editor )
> 
> OK, that simplifies the problem loads.
> 
> 
>>I don't know how to include all the support files when I do not know ahead 
>>of time which files are there, and I don't know how to call the common 
>>routines ( such as openFile ) that would be present in every support file ( 
>>because there will be namespace problems ).
> 
> 
> My solution would be to create a start-up file, eg:
> 
> editor.exw:
> include editexw.e
> include editpdf.e
> include mainedit.e
> <end of editor.exw>
> 
> That's it, three (or so) lines, so it is easy to delete/recreate such
> a file as & when additional components are downloaded.
> 
> You cannot use namespaces, each common routine (eg openFile) has to be
> uniquely named (eg openExwFile), but you can build the required string
> and use routine_id (if it does not return -1) to call it, or (if it
> does return -1) prompt to download the required component.
> 

	You don't need namespaces and still use generic names, but it's a bit 
complicated:

--in editexw.e:
function openFile(sequence fname,sequence mode)
--function body
end function
dynAPI[openFile_]=routine_id(openFile)
--and so on for all file-specific API calls

--in editor.exw:

sequence extensionsFoundWhileInCurrentSession={}
--add any new extension here, dot included
sequence dynAPI_repository={}
--add the value of dynAPI after a new extension was found
global constant openFile_=1, closeFile_=2,
--other name=index API interface pairings
global sequence dynAPI={<def wrapper routine_id for opeenFile>,
			<def wrapper routine_id for closeFile>,
--...any other stuff as needed
			}
constant defdynAPI=dynAPI

-- ...

include editexw.e
dynAPI=defdynAPI
include editpdf.e
dynAPI=defdynAPI

--...

function openFile(sequence fname,sequence mode)
integer p,l,nfn
sequence newAPI
l=length(fname)
p=find('.',reverse(fname))
p=find(fname[l+1-p,l],extensionsFoundWhileInCurrentsession)
if p>0 then dynAPI=dynAPI_repository[p]
else
--ask user if he wants to download support file, if any is available
--if Cancel then return -1
--else
--	if support file not found, ask user if default handling might be
--appropriate, at his own risks
--		if Yes then dynAPI=defdynAPI
--		else return -1
--		end if
--	else
--		start dl manager (dlmngr.exw)
--		dlmngr.exw downloads support file and copies it to $newext.e$
--		dlmngr.exw includes $newext.e$ (this is a static statement)
--and sprint's the new value for dynAPI to $new_API.e$
--		dlmngr.exw terminates so that editor.exw resumes execution
--		nfn=open("$new_API.e$","r")
--		newAPI=get(nfn)
--		close(nfn)
--		dynAPI=newAPI[2]
--		dynAPI_repository=append(dynAPI_repository,dynAPI)
--extensionsFoundWhileInCurrentSession=append(extensionsFoundWhileInCurrentSession,fname[l+3..l])
--	end if
--skipped error catching
end if
return call_func(dynAPI[openFile_],{fname,mode})
end function

function closeFile(integer fn)
call_proc(dynAPI[closeFile_,{fn})
end function

	Ok, you have to spin another process (dlmngr.exw) off, so the scheme won't 
work under DOS32.
	I also assumed that you don't process a file with a new extension before 
opeming it, so that all info gathering can be in the openFile routine's code.
	You may also use Bach2 so that openFile and dlmngr are coroutines; this 
eliminates the need for $new_API.e$. IPC (from the archive) might work as well.

Untested, but looks correct. HTH.

CChris

> Hope that helps,
>

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu