| 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 "paths.h" | 
| 11 |  | #include <ctype.h> | 
| 11 | – | #include <string.h> | 
| 12 |  |  | 
| 13 | + | char    *progname = NULL;       /* global argv[0] */ | 
| 14 | + |  | 
| 15 |  | char * | 
| 16 |  | fixargv0(char *av0)             /* extract command name from full path */ | 
| 17 |  | { | 
| 18 | < | char  *cp = av0, *end; | 
| 18 | > | char  *cp = av0; | 
| 19 |  |  | 
| 20 |  | while (*cp) cp++;               /* start from end */ | 
| 21 | < | end = cp; | 
| 21 | > |  | 
| 22 |  | while (cp-- > av0) | 
| 23 | < | switch (*cp) {          /* fix up command name */ | 
| 23 | > | switch (*cp) { | 
| 24 | > | CASEDIRSEP:                     /* remove directory */ | 
| 25 | > | av0 = cp+1; | 
| 26 | > | break; | 
| 27 | > | #if defined(_WIN32) || defined(_WIN64)  /* only do for Windows: */ | 
| 28 |  | case '.':                       /* remove extension */ | 
| 29 |  | *cp = '\0'; | 
| 24 | – | end = cp; | 
| 30 |  | continue; | 
| 26 | – | case '\\':                      /* remove directory */ | 
| 27 | – | case '/': | 
| 28 | – | /* make sure the original pointer remains the same */ | 
| 29 | – | memmove(av0, cp+1, end-cp); | 
| 30 | – | return(av0); | 
| 31 |  | default:                        /* convert to lower case */ | 
| 32 |  | *cp = tolower(*cp); | 
| 33 |  | continue; | 
| 34 | + | #endif | 
| 35 |  | } | 
| 36 | < | return(av0); | 
| 36 | > | return(progname = av0); | 
| 37 |  | } |