Re: Multi-purpose include/standalone files - neat trick
Both options are good and concise, but rely on variables set outside the
file. Personally, I like my include files to be self-contained whenever
possible. The use of command_line() accomplishes that goal. This
snippet of code from one of my projects handles stand-alone vs. include
checking, syntax checking, and parameter initialization from the command
line. If the file was included, the parameters would be passed through
the procedure call.
HTH,
Michael J. Sabal
-- 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()
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
>>> jbrown105 at speedymail.org 10/22/02 08:19PM >>>
Before routine_id() (BTW I never did figure out this trick on my own),
I
used
this method:
file eubasic.e:
global integer included
included = 0
include/standalone file:
include eubasic.e
if included = 0 then
....
else
...
end if
....
in main file:
include eubasic.e
included = 1
include the includable/standalone file
|
Not Categorized, Please Help
|
|