ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/fixargv0.c
(Generate patch)

Comparing ray/src/common/fixargv0.c (file contents):
Revision 2.8 by greg, Fri Aug 5 00:12:46 2016 UTC vs.
Revision 2.11 by greg, Sat Jun 7 05:09:45 2025 UTC

# Line 2 | Line 2
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 "rtio.h"
11 + #include "paths.h"
12   #include <ctype.h>
11 #include <string.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, *end;
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';
24                        end = cp;
31                          continue;
26                case '\\':                      /* remove directory */
27                        /* make sure the original pointer remains the same */
28                        memmove(av0, cp+1, end-cp);
29                        return(av0);
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   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines