ian@utcsstat.UUCP (Ian F. Darwin) (11/08/83)
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.
notes@fortune.UUCP (11/10/83)
#R:utcsstat:-140400:fortune:11600027:000:928 fortune!olson Nov 9 16:11:00 1983 I have been guilty of this in the past also. It usually seems silly/inexcusable to use full path names, especially if you are doing an execlp(), popen(), system(), etc. However, in the case of 4.1 BSD, there are, for example, 2 versions of ls, mail, grep, ... Usually one is the bell labs version and one is BSD, and the features and options are different. If you happen to be relying on a feature of a particular program, you obviously don't want to use whatever the user has chosen. It is often desirable to be sure that you are not getting something a user has in their local bin, which happens to have the same name as one of the `standard' commands. In addition, a lot of users will not have the variable set, so one has to choose some sort of default anyway. Even more to the point, local conventions of what environmental variables are meaningful vary. Dave Olson, Fortune Systems {ihnp4|harpo|hpda}!fortune!olson