[comp.sys.acorn] 'Shelling out' under RiscOS - the Ansilib system

rogersh%t2e@uk.ac.man.cs (Huw J. Rogers) (06/05/91)

	Under Release 3 or greater of the C compiler, Ansilib allows programs
to call other programs via the system() function. In order to retain the
'parent' program in memory and return gracefully to it it does several things:

	1) deinstall all handlers referencing 'parent' program
	2) install an exit handler
	3) copy up the 'parent' program to the top of memory
	4) set HIMEM to just below this copy so it won't get overwritten
	5) call OSCLI to run the 'child' program
	6) OSCLI either returns or the 'child' program calls the exit handler,
		which takes us to 7)
	7) reset HIMEM to previous value
	8) deinstall exit handler
	9) copy down 'parent' program to reinstall it
	10) reinstall all handlers deinstalled in 1)
	11) return from system() with appropriate exit code...

	What I want is some example code that does all that - in particular
copes with problems with the stack that arise when messing about like this.
This is a fairly common problem with any application that allows arbitrary
OSCLI commands which can invoke subprograms, but there are several *nasty*
complications - despite Acorn trying to make it sound simple to do this
in the PRM section dealing with exit handlers.

	Thanks in advance,

	-Huw

[ H.J.Rogers (INTERNET: rogersh%p4%cs.man.ac.uk@cunyvm.cuny.edu)       ]
[    ,_,     (BITNET/EARN: rogersh%p4%cs.man.ac.uk@UKACRL.BITNET)      ]
[  :-(_)-o   (UUCP: ...!uunet!cunyvm.cuny.edu!cs.man.ac.uk!p4!rogersh) ]
[   _} {_    (JANET: rogersh%p4@uk.ac.man.cs)                          ]

gtoal@tardis.computer-science.edinburgh.ac.uk (06/07/91)

In article <2623@m1.cs.man.ac.uk> rogersh%t2e@uk.ac.man.cs (Huw J. Rogers) writes:
:
:	Under Release 3 or greater of the C compiler, Ansilib allows programs
:to call other programs via the system() function. In order to retain the
:'parent' program in memory and return gracefully to it it does several things:
:
:	1) deinstall all handlers referencing 'parent' program
:	2) install an exit handler
:	3) copy up the 'parent' program to the top of memory
:	4) set HIMEM to just below this copy so it won't get overwritten
:	5) call OSCLI to run the 'child' program
:	6) OSCLI either returns or the 'child' program calls the exit handler,
:		which takes us to 7)
:	7) reset HIMEM to previous value
:	8) deinstall exit handler
:	9) copy down 'parent' program to reinstall it
:	10) reinstall all handlers deinstalled in 1)
:	11) return from system() with appropriate exit code...
:
:	What I want is some example code that does all that - in particular
:copes with problems with the stack that arise when messing about like this.
:This is a fairly common problem with any application that allows arbitrary
:OSCLI commands which can invoke subprograms, but there are several *nasty*
:complications - despite Acorn trying to make it sound simple to do this
:in the PRM section dealing with exit handlers.
:
:	Thanks in advance,
:
:	-Huw

Personally I'd try another approach -- if running under the wimp, why
not write a system() which starts up the command as another process, in
a VM of its own?  (which IMHO is what Acorn should have done -- causes
havoc with your interrupt routines if one gets hit whe calling system)

Of course, if you do this, you have to fall back on the acorn style
if you detect that you're not in the wimp...

Graham