| 1 |
greg |
2.1 |
#ifndef lint
|
| 2 |
greg |
2.8 |
static const char RCSid[] = "$Id: fixargv0.c,v 2.7 2016/03/20 16:36:17 schorsch Exp $";
|
| 3 |
greg |
2.1 |
#endif
|
| 4 |
|
|
/*
|
| 5 |
|
|
* Fix argv[0] for DOS environments
|
| 6 |
greg |
2.2 |
*
|
| 7 |
schorsch |
2.4 |
* External symbols declared in paths.h
|
| 8 |
greg |
2.2 |
*/
|
| 9 |
|
|
|
| 10 |
schorsch |
2.4 |
#include <ctype.h>
|
| 11 |
schorsch |
2.6 |
#include <string.h>
|
| 12 |
greg |
2.1 |
|
| 13 |
greg |
2.8 |
char *
|
| 14 |
|
|
fixargv0(char *av0) /* extract command name from full path */
|
| 15 |
greg |
2.1 |
{
|
| 16 |
greg |
2.8 |
char *cp = av0, *end;
|
| 17 |
greg |
2.1 |
|
| 18 |
|
|
while (*cp) cp++; /* start from end */
|
| 19 |
schorsch |
2.7 |
end = cp;
|
| 20 |
greg |
2.1 |
while (cp-- > av0)
|
| 21 |
|
|
switch (*cp) { /* fix up command name */
|
| 22 |
|
|
case '.': /* remove extension */
|
| 23 |
|
|
*cp = '\0';
|
| 24 |
schorsch |
2.7 |
end = cp;
|
| 25 |
greg |
2.1 |
continue;
|
| 26 |
|
|
case '\\': /* remove directory */
|
| 27 |
schorsch |
2.7 |
/* make sure the original pointer remains the same */
|
| 28 |
|
|
memmove(av0, cp+1, end-cp);
|
| 29 |
greg |
2.8 |
return(av0);
|
| 30 |
greg |
2.1 |
default: /* convert to lower case */
|
| 31 |
|
|
*cp = tolower(*cp);
|
| 32 |
|
|
continue;
|
| 33 |
|
|
}
|
| 34 |
|
|
return(av0);
|
| 35 |
|
|
}
|