Hypothetically speaking:

On every system I have worked with, I can take a binary
executable, make a copy of it, append arbitrary garbage onto
the end, and the modified executable still works.  When I examine
the details of their file formats, this makes complete sense
(since binary files are built around the idea of not knowing or
caring what else is in the file, beyond the immediately relevant,
at each stage of execution).

Thus, if the executable could figure out what its own file name
was, it could, in principle inspect its file for something at the
end which details some file offset and length, which would be
a script it would should execute at startup.

If J were built this way, with the shipped image having a small
script at the end to boot into the normal 3-space indent interactive
session, it would be relatively trivial to provide a replacement script
at the end.  (If the default script were short enough, it would make
sense to simply append a new script+offset/length and ignore the
previous one.)

(Or perhaps something more structured -- an array of named
file offsets and lengths representing psuedo files?)

You wind up needing an OS specific mechanism to locate
the executable, based on 0{::ARGV, so here's a model for that:

fexist=: 1:@(1!:7) ::0:"0
unix=:3 :0
 me=.0{::ARGV
 if.'/'={.me do.me return.end.
 cwd=.'/',~1!:43''
 if.'/'e.me do.cwd,me return.end.
 fixpath=.(cwd,])^:('/'~:{.)
 0{::(fexist#])(('/',me),~fixpath)L:0 <;._1':',2!:5'PATH'
)

NB.    "       ;   other
splitwin=:(0;(0 10#:10*".;._2(0 :0));'";'i.a.)&;:
    0.0     2.0     1.1  NB. 0: a start
    0.5     2.5     1.0  NB. 1: a directory name
    2.0     0.0     3.1  NB. 2: b start
    2.5     0.5     3.0  NB. 3: b directory name
)

windows=:3 :0
 me=.0{::ARGV
 if.':'={.}.me do.me return.end.
 cwd=.'\',~1!:43''
 drv=.2{.cwd
 fixpath=.[: (cwd,])^:(':'~:[EMAIL PROTECTED]) (drv,])^:('\'={.)
 if.fexist<fixpath me do.fixpath me return.end.
 0{::(fexist#])(('\',me),~fixpath)L:0 splitwin 2!:5'PATH'
)

--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to