ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/fixargv0.c
Revision: 2.10
Committed: Tue Jun 3 21:31:51 2025 UTC (3 days, 19 hours ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.9: +14 -13 lines
Log Message:
refactor: More consistent use of global char * progname and fixargv0()

File Contents

# User Rev Content
1 greg 2.1 #ifndef lint
2 greg 2.10 static const char RCSid[] = "$Id: fixargv0.c,v 2.9 2020/07/24 16:58:16 greg Exp $";
3 greg 2.1 #endif
4     /*
5 greg 2.10 * Fix argv[0] and assign global progname variable
6 greg 2.2 *
7 schorsch 2.4 * External symbols declared in paths.h
8 greg 2.2 */
9    
10 greg 2.10 #include "paths.h"
11 schorsch 2.4 #include <ctype.h>
12 greg 2.10
13     char *progname = NULL; /* global argv[0] */
14 greg 2.1
15 greg 2.8 char *
16     fixargv0(char *av0) /* extract command name from full path */
17 greg 2.1 {
18 greg 2.10 char *cp = av0;
19 greg 2.1
20     while (*cp) cp++; /* start from end */
21 greg 2.10
22 greg 2.1 while (cp-- > av0)
23 greg 2.10 switch (*cp) {
24     CASEDIRSEP: /* remove directory */
25     av0 = cp+1;
26     break;
27     #if defined(_WIN32) || defined(_WIN64) /* only do for Windows: */
28 greg 2.1 case '.': /* remove extension */
29     *cp = '\0';
30     continue;
31     default: /* convert to lower case */
32     *cp = tolower(*cp);
33     continue;
34 greg 2.10 #endif
35 greg 2.1 }
36 greg 2.10 return(progname = av0);
37 greg 2.1 }