fischer-michael@YALE.ARPA.UUCP (04/30/87)
Here is the little program I promised that sets *_SHELL_P and gets
around the problem of MSH not being able to find its profile when
using GEMBOOT.
=====*=====*=====*=====*=====*=====*=====*=====*=====*=====*=====*=====
/* SET_ENV.C
Purpose: Rewrites the system path string.
Usage: set_env [username]
Description:
Writes the string "USER=<username>\0PATH=\0\0" into the string
buffer pointed to by _shell_p, where <username> is the optional
command line argument to set_env. If <username> is omitted,
then the string "PATH=\0\0" is written instead.
The Mark Williams shell msh.prg (V2.0) uses this string as its
initial environment, so environment variables USER and PATH will
be defined when msh starts up (or just PATH if run with no
argument). The profile can then modify its action based on the
contents of USER. For example, if USER=MIKE, the profile line
C:\${USER}.MSH
will cause msh to run the shell script in C:\MIKE.MSH.
Set_env is particularly useful in conjunction with gemboot.prg,
Konrad Hahn's program that solves the 40 folder problem. By
eliminating the semicolons that gemboot leaves in the system
path string, it fixes the problem with msh not being able to
find its profile file. It should be placed in the .BAT startup
file invoked by gemboot. For example, putting
SET_ENV MIKE
in the gemboot startup file MIKE.BAT allows msh to subsequently
customize itself according to MIKE's preferences.
Caution: set_env does not modify the pointer _shell_p but instead
writes into memory pointed to by _shell_p. If insufficient memory
has been allocated to contain the new string, set_env will simply
overwrite whatever lies beyond, possibly crashing the system
or causing other problems. Gemboot seems to allocate a buffer
of 80 or more bytes, and I have not noticed any problems using
set_env with gemboot, but other programs that set _shell_p might
not be so generous.
Author: Michael J. Fischer
Address: Arpanet: fischer@yale.arpa
Bitnet: fischer@yale-cs
Distribution:
THIS PROGRAM IS PLACED IN THE PUBLIC DOMAIN WITHOUT WARRANTY
OF ANY KIND. IT MAY BE FREELY COPIED, MODIFIED, OR REDISTRIBUTED
AT WILL.
*/
#include <stdio.h>
#define _shell_p 0x4f6L /* system path variable */
long peekl();
main(argc, argv)
int argc;
char *argv[];
{
char *s = (char *) peekl(_shell_p);
if (argc >= 2) {
strcpy(s, "USER=");
strcat(s, argv[1]);
s += strlen(argv[1]) + 6;
}
strcpy(s, "PATH=");
s += 6;
*s = '\0';
}
=====*=====*=====*=====*=====*=====*=====*=====*=====*=====*=====*=====
--Mike Fischer
Arpanet: fischer@yale.arpa
Bitnet: fischer@yale-cs
-------