Steve Leach tried posting to pop-forum in reply to Terry Dartnall's
question, but for some reason the mail->news gateway did not work, so I
am reposting his reply to Terry.
Apologies to anyone who has already seen it.
I believe Terry's original question is actually answered by putting
the pop11 library to be compiled in a directory in $popcomppath,
and simply typing this to run and compile the file.
pop11 <filename>
But that assumes that all the environment variables have been set
up already, e.g. in the user's .login file, which is how most people
have been using Poplog until now.
Steve's answer deals with the case where that is not so.
See also Andrew Sayer's message posted on 15th March.
Aaron
===================================================================
Date: Wed, 15 Mar 2000 12:54:03 +0000
To: Terry Dartnall <terryd@cit.gu.edu.au>
From: "Stephen F. K. Leach" <steve@watchfield.com>
Subject: Re: loading lib files from Unix
Cc: popforum <pop-forum@cs.bham.ac.uk>
Hi Terry,
>Is there a way to load a pop file straight from Unix? I want to write a
>little Unix procedure that loads a lib file that has an exposed procedure call
>at the end, so that typing the file name straight to the Unix prompt runs
>the file. At the moment I don't know how to run a pop file without being in
>poplog already.
This does slightly depend on which UNIX you are using. However, what I
do is write a little C program for dispatching the Poplog binary - the
problem is that Poplog expects a whole bunch of environment variables
to be set up. The other problem is that UNIX just hands over the file
and it will have an initial line starting with "#!" stuck in it. (What a
pity UNIX Poplog does not have #! as an end-of-line comment!)
I compile the attached code with -DUSEPOP=${usepop} in order to get
the right location. As you will see, I build it to run corepop11,
the rawest pop11 binary but you can adapt it to run the binary of your
choice.
cc -O -o runpop runpop.c -DUSEPOP='"'${usepop}'"' -DBINARY="corepop11" /
-DIMAGE='"/usr/local/psv/runpop.psv"'
[Note that these macros are defining C-strings so you need to get the
double quotes passed through. That is why you get the strange quoting
sequences above. If you do not like this just define the macros
explicitly in the C code.]
You will need to build the saved image. The only job this has to do
is skip the initial line and execute the rest of the file. I attach
a suitable bit of Pop11 code for the job as file runpop.p. I build the
image using the command line
corepop11 %nort mkimage -entry runpop /usr/local/psv/runpop.psv ./runpop.p
I then stick the runpop in a suitable location e.g. /usr/local/bin/runpop.
Now all you have to do is put
#!/usr/local/bin/runpop
as the first line of your file and mark the file as executable using
chmod a+rx hello
Presumably your file contains some erudite code. Mine contains
npr( 'Hello, world!' );
and when I type
./hello
I get back
Hello, world!
which is what I wanted.
Of course, you do not have to use a C executable for /usr/local/bin/runpop.
Aaron Sloman recently posted a version written in one of the UNIX shells
as I recall.
[Yes: see
http://www.cs.bham.ac.uk/research/poplog/man/bin/poplog
but I think this deals with a different problem from the one I
took Terry to be raising.]
However, you will get a very big speed bonus for the C
executable. On my Linux system, this executable is 13K unstripped,
4K stripped, incidentally.
Hope this helps.
Steve
P.S. This is such a rigmarole, in my view, that I would dearly like us to
include such as thing as a default part of Poplog installation.
-- runpop.c -----------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define LOCAL USEPOP
#define POPCONTRIB USEPOP
int main( int argc, char **argv ) {
putenv( "usepop=" USEPOP );
putenv( "popcom=" USEPOP "/pop/com" );
putenv( "popsrc=" USEPOP "/pop/src" );
putenv( "popsys=" USEPOP "/pop/pop" );
putenv( "popexternlib=" USEPOP "/pop/extern/lib" );
putenv( "popobjlib=" USEPOP "/pop/obj" );
putenv( "popautolib=" USEPOP "/pop/lib/auto" );
putenv( "popdatalib=" USEPOP "/pop/lib/data" );
putenv( "popliblib=" USEPOP "/pop/lib/lib" );
putenv( "poppwmlib=" USEPOP "/pop/lib/pwm" );
putenv( "popsunlib=" USEPOP "/pop/lib/sun" );
putenv( "popvedlib=" USEPOP "/pop/lib/ved" );
putenv( "poplocal=" LOCAL );
putenv( "poplocalauto=" LOCAL "/local/auto" );
putenv( "poplocalbin=" LOCAL "/local/bin" );
putenv( "popcontrib=" POPCONTRIB );
putenv( "popsavelib=" USEPOP "/pop/lib/psv" );
putenv( "popcomppath=$poplocalauto:$popautolib:$popliblib" );
putenv( "popsavepath=:$poplib:$poplocalbin:$popsavelib" );
putenv( "popexlinkbase=" USEPOP "/pop/pop/basepop11.stb" );
if ( argc == 2 ) {
execl( USEPOP "/pop/pop/" BINARY, BINARY, "+" IMAGE, argv[1], 0 );
}
return EXIT_FAILURE;
}
-- runpop.p ---------------------------------------------------------
define runpop();
lvars f;
for f in poparglist do
/* Optionally, you may want runpop to execute in the directory
of the file being executed. Simply assign
sys_fname_path( f ) -> current_directory
if that is what you want.
*/
lvars procedure d = discin( f );
until d() == `\n` do enduntil;
pop11_compile( d )
endfor;
enddefine;
==============End of posting by Steve Leach==================
--
Aaron Sloman, ( http://www.cs.bham.ac.uk/~axs/ )
School of Computer Science, The University of Birmingham, B15 2TT, UK
EMAIL A.Sloman AT cs.bham.ac.uk (NB: Anti Spam address)
TOOLS: http://www.cs.bham.ac.uk/research/poplog/freepoplog.html
|