Re: Multi-purpose include/standalone files - neat trick

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

True, I hadn't though of the full-path instance.  Your idea is a good
one.  But perhaps using match() instead of compare() by including
wildcard.e would have the same effect.  Although, if the file is
included and the pathname of the main file contains the name of the
included file, match() could give a false positive.

Feature request:
  Since the interpreter already knows whether a file is stand-alone or
included, I don't think it would be hard to provide a built-in boolean
to tell the program its scope.  For example,

if is_include_file()=TRUE then
  do_something()
else
  do_something_else()
end if

Michael J. Sabal

>>> MichaelANelson at WORLDNET.ATT.NET 10/23/02 11:27AM >>>

Mike,

This code doesn't work for me, as command_line returns the full path,
not
just the file name. I have added code to strip the path info below.

-- Mike Nelson

include misc.e

function get_filename(sequence f)
    integer slash,index
    if platform()=LINUX then slash='/' else slash='\\' end if
    index=find(slash,f)
    in index=0 then return f end if
    return get_filename(f[index+1..length(f)])
end function


> -- The following lines allow the option of this program being
> -- run as either a stand-alone program or an included file.
>
> sequence cmd_line
>
> cmd_line = command_line()
    cmd_line[2]=get_filename(cmd_line[2])
> if compare(lower(cmd_line[2]),"spidreng.exw")=0 or
>    compare(lower(cmd_line[2]),"spidreng")=0 then
>   if length(cmd_line)>3 then
>     spider_set_proxy(cmd_line[4])
>   end if
>   if length(cmd_line)<3 then
>     puts(1,"Syntax:\n")
>     puts(1,"exw spidreng.exw scriptname proxy_address\n\n")
>   else
>     spider_run_main(cmd_line[3])
>   end if
> end if

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

Search



Quick Links

User menu

Not signed in.

Misc Menu