Category : Batch File Utilities - mostly for DOS
Archive   : RBSETENV.ZIP
Filename : ADDPATH.C
* addpath.c
*
* Returned status:
* 0 OK (including case where nothing needs to be done)
* 1 bad arguments
*
*/
#include
#include
#include
void exit(int status) { _exit(status); }
#define writes(s,i) write(i,s,strlen(s));
main(int argc, char *argv[])
{
int len;
char *path, *newdir, *p;
if( argc != 2) {
writes("Usage: addpath pathname\n",2);
exit(1);
} else {
newdir = strupr(argv[1]);
len = strlen(newdir);
/* strip off a trailing ";" and upper-case */
if( *(newdir+len-1) == ';') *(newdir+len-1) = '\0';
path = getenv("PATH");
writes(path,1);
if ((p = strstr(path,newdir)) == NULL) {
/* not in path already - add it */
writes(";",1);
writes(newdir,1);
} else {
/* we found it, but it may be a partial match */
if ( ((p == path) || (p != path && *(p-1) == ';'))
&& (*(p+len) == ';' || *(p+len) == '\0') ) {
/* already in path */
} else {
/* it was a bogus match - add the new one */
writes(";",1);
writes(newdir,1);
}
}
}
return(0);
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/