Environment variables: please use (V7 & later)
Ian F. Darwin
ian at utcsstat.UUCP
Wed Nov 9 05:12:27 AEST 1983
A number of programs has appeared in net.sources recently which
call other programs such as editors, mailers, etc., and having the names of
these things burned into the code. You have to change the source
to make it work with your favorite editor, mailer, or whatever.
It's real easy to use environment variables to get the name of the
editor, mailer or paginator which joe foo user wants to use. It adds
all of four lines to the code. To wit (basically grepped from working code):
#define DEFEDITOR "/bin/ed"
#define ENVEDITOR "EDITOR"
char *p, editor[BUFSIZ], *getenv();
...
...
strcpy(editor, (p=getenv(ENVEDITOR))==NULL?DEFEDITOR:p);
That's all there is to it. You can then say
sprintf(cmdline,"%s %s",editor,filename);
if (system(cmdline) != 0){
fprintf(stderr,"?edit failed?");
other error action (exit, return...)
}
That's the tutorial. The plea? Please use environment variables
*whenever* you want the name of an EDITOR, PAGER, MAILER or similar
class of program. It makes life much easier for those of us who just
explained to joe t. user that setting EDITOR works in readnews, now
we don't have to explain why it *doesn't* work in your code.
Thanks.
More information about the Comp.unix.wizards
mailing list