diff options
-rw-r--r-- | doc/HISTORY | 2 | ||||
-rw-r--r-- | lib/libpm.c | 39 |
2 files changed, 33 insertions, 8 deletions
diff --git a/doc/HISTORY b/doc/HISTORY index 3d41b1c3..7297c09e 100644 --- a/doc/HISTORY +++ b/doc/HISTORY @@ -12,6 +12,8 @@ not yet BJH Release 10.58.00 pgmtexture: fix array bounds violations in various calculations. Always broken. + Windows: compute program name correctly. + xpmtoppm: Make it work on XPM with zero characters per pixel. 11.12.30 BJH Release 10.57.00 diff --git a/lib/libpm.c b/lib/libpm.c index 69085099..54bd04cb 100644 --- a/lib/libpm.c +++ b/lib/libpm.c @@ -594,6 +594,32 @@ showNetpbmHelp(const char progname[]) { +static const char * +progNameFromArg0(const char * const arg0) { + +#ifdef _WIN32 + + char filename[256]; + + _splitpath(arg0, 0, 0, filename, 0); + +#else + + /* Just take the last component of the file name, e.g. "foo" in + "/local/bin/foo" + */ + const char * const slashPos = strrchr(arg0, '/'); + + const char * const filename = slashPos ? slashPos + 1 : arg0; + +#endif + + return pm_strdup(filename); +} + + + + void pm_proginit(int * const argcP, const char * argv[]) { /*---------------------------------------------------------------------------- @@ -604,8 +630,12 @@ pm_proginit(int * const argcP, const char * argv[]) { This includes calling pm_init() to initialize the Netpbm libraries. -----------------------------------------------------------------------------*/ + const char * const progname = progNameFromArg0(argv[0]); + /* Note: this is technically a memory leak; it is malloc'ed memory + that we have no way to give back because there is no pm_progterm(). + So it goes down with the ship when the OS terminates the program. + */ int argn, i; - const char * progname; bool showmessages; bool show_version; /* We're supposed to just show the version information, then exit the @@ -615,13 +645,6 @@ pm_proginit(int * const argcP, const char * argv[]) { /* We're supposed to just tell user where to get help, then exit the program. */ - - /* Extract program name. */ - progname = strrchr( argv[0], '/'); - if (progname == NULL) - progname = argv[0]; - else - ++progname; pm_init(progname, 0); |