1207753Smm/////////////////////////////////////////////////////////////////////////////// 2207753Smm// 3207753Smm/// \file tuklib_progname.c 4207753Smm/// \brief Program name to be displayed in messages 5207753Smm// 6207753Smm// Author: Lasse Collin 7207753Smm// 8207753Smm// This file has been put into the public domain. 9207753Smm// You can do whatever you want with this file. 10207753Smm// 11207753Smm/////////////////////////////////////////////////////////////////////////////// 12207753Smm 13207753Smm#include "tuklib_progname.h" 14207753Smm#include <string.h> 15207753Smm 16207753Smm 17207753Smm#if !HAVE_DECL_PROGRAM_INVOCATION_NAME 18207753Smmchar *progname = NULL; 19207753Smm#endif 20207753Smm 21207753Smm 22207753Smmextern void 23207753Smmtuklib_progname_init(char **argv) 24207753Smm{ 25207753Smm#ifdef TUKLIB_DOSLIKE 26207753Smm // On these systems, argv[0] always has the full path and .exe 27207753Smm // suffix even if the user just types the plain program name. 28207753Smm // We modify argv[0] to make it nicer to read. 29207753Smm 30207753Smm // Strip the leading path. 31207753Smm char *p = argv[0] + strlen(argv[0]); 32207753Smm while (argv[0] < p && p[-1] != '/' && p[-1] != '\\') 33207753Smm --p; 34207753Smm 35207753Smm argv[0] = p; 36207753Smm 37207753Smm // Strip the .exe suffix. 38207753Smm p = strrchr(p, '.'); 39207753Smm if (p != NULL) 40207753Smm *p = '\0'; 41207753Smm 42207753Smm // Make it lowercase. 43207753Smm for (p = argv[0]; *p != '\0'; ++p) 44207753Smm if (*p >= 'A' && *p <= 'Z') 45207753Smm *p = *p - 'A' + 'a'; 46207753Smm#endif 47207753Smm 48207753Smm progname = argv[0]; 49207753Smm return; 50207753Smm} 51