| 2 |
|
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 4 |
|
/* |
| 5 |
< |
* Fix argv[0] for DOS environments |
| 5 |
> |
* Fix argv[0] and assign global progname variable |
| 6 |
|
* |
| 7 |
|
* External symbols declared in paths.h |
| 8 |
|
*/ |
| 9 |
|
|
| 10 |
< |
#include "copyright.h" |
| 11 |
< |
|
| 10 |
> |
#include "rtio.h" |
| 11 |
> |
#include "paths.h" |
| 12 |
|
#include <ctype.h> |
| 13 |
– |
#include <string.h> |
| 13 |
|
|
| 14 |
< |
extern char * |
| 15 |
< |
fixargv0(av0) /* extract command name from full path */ |
| 16 |
< |
char *av0; |
| 14 |
> |
char *progname = NULL; /* global argv[0] */ |
| 15 |
> |
|
| 16 |
> |
char * |
| 17 |
> |
fixargv0(char *av0) /* extract command name from full path */ |
| 18 |
|
{ |
| 19 |
< |
register char *cp = av0, *end = av0; |
| 19 |
> |
char *cp = av0; |
| 20 |
|
|
| 21 |
|
while (*cp) cp++; /* start from end */ |
| 22 |
< |
end = cp; |
| 22 |
> |
|
| 23 |
|
while (cp-- > av0) |
| 24 |
< |
switch (*cp) { /* fix up command name */ |
| 24 |
> |
switch (*cp) { |
| 25 |
> |
CASEDIRSEP: /* remove directory */ |
| 26 |
> |
av0 = cp+1; |
| 27 |
> |
break; |
| 28 |
> |
#if defined(_WIN32) || defined(_WIN64) /* only do for Windows: */ |
| 29 |
|
case '.': /* remove extension */ |
| 30 |
|
*cp = '\0'; |
| 27 |
– |
end = cp; |
| 31 |
|
continue; |
| 29 |
– |
case '\\': /* remove directory */ |
| 30 |
– |
/* make sure the original pointer remains the same */ |
| 31 |
– |
memmove(av0, cp+1, end-cp); |
| 32 |
– |
break; |
| 32 |
|
default: /* convert to lower case */ |
| 33 |
|
*cp = tolower(*cp); |
| 34 |
|
continue; |
| 35 |
+ |
#endif |
| 36 |
|
} |
| 37 |
< |
return(av0); |
| 37 |
> |
return(progname = av0); |
| 38 |
|
} |
| 39 |
|
|
| 40 |
|
|
| 41 |
+ |
void |
| 42 |
+ |
printargs( /* print command arguments to a file */ |
| 43 |
+ |
int ac, |
| 44 |
+ |
char **av, |
| 45 |
+ |
FILE *fp |
| 46 |
+ |
) |
| 47 |
+ |
{ |
| 48 |
+ |
if (ac <= 0) return; |
| 49 |
+ |
|
| 50 |
+ |
if (progname == NULL) |
| 51 |
+ |
fixargv0(av[0]); |
| 52 |
+ |
|
| 53 |
+ |
if (progname >= av[0] && progname - av[0] < strlen(av[0])) |
| 54 |
+ |
fputword(progname, fp); |
| 55 |
+ |
else |
| 56 |
+ |
fputword(av[0], fp); |
| 57 |
+ |
while (--ac > 0) { |
| 58 |
+ |
fputc(' ', fp); |
| 59 |
+ |
fputword(*++av, fp); |
| 60 |
+ |
} |
| 61 |
+ |
fputc('\n', fp); |
| 62 |
+ |
} |