1 |
greg |
2.1 |
#ifndef lint |
2 |
schorsch |
2.7 |
static const char RCSid[] = "$Id: fixargv0.c,v 2.6 2016/03/19 00:44:46 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 |
greg |
2.3 |
#include "copyright.h" |
11 |
greg |
2.1 |
|
12 |
schorsch |
2.4 |
#include <ctype.h> |
13 |
schorsch |
2.6 |
#include <string.h> |
14 |
greg |
2.1 |
|
15 |
schorsch |
2.5 |
extern char * |
16 |
greg |
2.1 |
fixargv0(av0) /* extract command name from full path */ |
17 |
|
|
char *av0; |
18 |
|
|
{ |
19 |
schorsch |
2.7 |
register char *cp = av0, *end = av0; |
20 |
greg |
2.1 |
|
21 |
|
|
while (*cp) cp++; /* start from end */ |
22 |
schorsch |
2.7 |
end = cp; |
23 |
greg |
2.1 |
while (cp-- > av0) |
24 |
|
|
switch (*cp) { /* fix up command name */ |
25 |
|
|
case '.': /* remove extension */ |
26 |
|
|
*cp = '\0'; |
27 |
schorsch |
2.7 |
end = cp; |
28 |
greg |
2.1 |
continue; |
29 |
|
|
case '\\': /* remove directory */ |
30 |
schorsch |
2.7 |
/* make sure the original pointer remains the same */ |
31 |
|
|
memmove(av0, cp+1, end-cp); |
32 |
schorsch |
2.6 |
break; |
33 |
greg |
2.1 |
default: /* convert to lower case */ |
34 |
|
|
*cp = tolower(*cp); |
35 |
|
|
continue; |
36 |
|
|
} |
37 |
|
|
return(av0); |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
|