ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/fixargv0.c
Revision: 2.11
Committed: Sat Jun 7 05:09:45 2025 UTC (18 hours, 15 minutes ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 2.10: +26 -1 lines
Log Message:
refactor: Put some declarations into "paths.h" and included in "platform.h"

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: fixargv0.c,v 2.10 2025/06/03 21:31:51 greg Exp $";
3 #endif
4 /*
5 * Fix argv[0] and assign global progname variable
6 *
7 * External symbols declared in paths.h
8 */
9
10 #include "rtio.h"
11 #include "paths.h"
12 #include <ctype.h>
13
14 char *progname = NULL; /* global argv[0] */
15
16 char *
17 fixargv0(char *av0) /* extract command name from full path */
18 {
19 char *cp = av0;
20
21 while (*cp) cp++; /* start from end */
22
23 while (cp-- > av0)
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';
31 continue;
32 default: /* convert to lower case */
33 *cp = tolower(*cp);
34 continue;
35 #endif
36 }
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 }