[comp.sys.atari.st] Setting default environment from auto folder

dcw@doc.ic.ac.uk (Duncan C White) (12/07/88)

Hello there,

	For some time, I've been trying to get Unix-style environments
	to work on my ST, for programs which may be run from a command shell
	or from the desktop.

	If I run such programs from Gulam, everything is fine.
	I can set up the environment I want in the gulam.g file
	[well, actually binary patched to c:\gl.g], and then getenv
	to my hearts content...
	Incidentally, I use Lattice C 3.04, which [unlike MWC & Alycon, I
	believe??] provides a getenv() call... this works with Gulam perfectly.

	But, if I run a program from the desktop, there is no environment
	set up initially.
	What I'd like to do is write a program to be placed in the auto folder
	which will read a text file of Gulam/Csh-style setenv commands, and
	set up the global environment for the ST.

	I have 1st Publishing's "Anatomy of the Atari ST", which suggests
	[page 253] in the section on ST System Variables, that at $4BC there
	is "the_env: default environment string - 4 zero bytes"

	I had assumed that this was a pointer to the default environment..
	but I've had singular lack of success in setting it [in supervisor
	mode, of course] and doing a TSR call.  My attempts usually end in
	the machine going into a reboot loop until I deactivate the
	environment setter with setinit [first program in my auto folder]

	Is it safe to TSR from the auto folder?   To enter supervisor mode
	in auto folder?  Is the_env a pointer, or if not, is there another
	system variable which is more appropriate?
	If I succeed, will Gulam merge the two environments [ie. inherit
	the global environment] or will it simply ignore the global env?

	Can anybody help me?  Any details on environment format, relevent ST
	System Variables, would be hugely appreciated...

	Please mail suggestions to me and I'll summarise ...

		Duncan

[ Reply to: dcw@doc.ic.ac.uk or ...!ukc!icdoc!dcw ]
----------------------------------------------------------------------------
Duncan White,           |       "Middle East Policy was a fiasco and a
Dept. Of Computing,     |       disaster, but Central American policy was
Imperial College,       |       in better shape - it was merely a disaster!"
London SW7, England     |                  Spitting Image on Reagan...

Thomas_E_Zerucha@cup.portal.com (12/10/88)

I managed to do it - it was fairly simple, but what you have to do is find
the pointer in the environment of the parent of the process from the auto
folder (or the parent of the parent - the one that the desktop gets).

A short assembly program follows (the one I use)

---cut here---
	.text
*housekeeping
	move.l	a7,a5
	move.l	4(a5),a5	;compute size for TSR call
	move.l	$c(a5),d6	;text
	add.l	$14(a5),d6	;data
	add.l	$1c(a5),d6	;bss
	add.l	#$100,d6	;basepage
	add.l	#$40,d6		;saftey
* alter vector
	move.l	#doit,-(sp)	;point to the vector changer code
	move.w	#38,-(sp)	;we want to do it in supervisor mode!
	trap	#14		;execute it!
	addq.l	#6,sp
* tell everyone we are here
	pea	msg1
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp
* TSR
	clr	-(sp)		;exit but stay
	move.l	d6,-(sp)
	move	#$31,-(sp)
	trap	#1

bexit:	move	#0,-(sp)
	trap	#1
* set env upon startup
movenv:
	move.l	a7,a5
	move.l	4(a5),a5
	move.l	a5,a4
linkup:
	move.l	$24(a4),a4
	movea.l	$2c(a4),a3
	cmp.w	#0,(a3)
	beq.s	setwork
	move.l	a4,a5
	bra.s	linkup
setwork:

	move.l	#workar,$2c(a5)
	move.l	shlsav,a5
	jmp	(a5)
***
* install (in super) vector
doit:	move.l	$4fe,shlsav	;move
	move.l	#movenv,$4fe	;move
	rts                     ;and return
***
*************************
	.data
msg1:		dc.b	'GEM Resource Path Set\r\n',0
shlsav:		dc.l	0
workar:	dc.b	'PATH=;D:\\RESOURCE;D:\\;D:\\BIN'
	dc.b	';d:\\LANG;D:\\SCRIPTS;D:\\USRBIN;.',0
	dc.b	'TEMP=c:\\tmp\\',0
	dc.b	'INCLUDE=d:\\include\\',0
	dc.b	'SYMB=d:\\lang\\',0
	dc.b	'LIB=d:\\lib\\',0
	dc.b	'STARTUP=d:\\lib\\gemstart',0
	dc.b	'RUNTIME=d:\\lib\\gemlib',0
	dc.b	'SUFF=,.prg,.ttp,.tos',0
	dc.b	'LIBPATH=d:\\mwlib,d:\\lang,.',0
	dc.b	'INCDIR=d:\\mwinc\\',0
	dc.b	'TMPDIR=c:\\tmp\\',0
	dc.b	'TIMEZONE=EST:0:EDT',0
	dc.b	'M2SBM=d:\\modlibs',0
	dc.b	'M2OBM=d:\\modlibs',0
	dc.b	'EDITOR=stedt.ttp',0
        dc.b    'SEDT=d:\\include\\',0
	dc.b	'SHELL=csh.tos',0
	dc.b	0,0

	.end