[AD] get_executable_name in unix |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Hi,
I changed the _xwin_sysdrv_get_executable_name to lookup in the PATH
environment instead of using argv[0] only. That's needed since a program
could be called from command line without the full path, so the exe file
would be in an different directory and not in the current as assumed by
using argv[0] for opening the binary file.
I also changed "X-Windows" info-string to "X Window System" which is the
official name of that.
Greetings,
Eduard.
--
=====================================================================
Eduard Bloch <eb@xxxxxxxxxx>; HP: http://eduard.bloch.com/edecosi
0xEDF008C5(gpg): E6EB 98E2 B885 8FF0 6C04 5C1D E106 481E EDF0 08C5
**
The feature you'd like to have is probably already installed on your
Linux system.
diff -u --recursive --new-file allegro-3.9.32.orig/src/x/xsystem.c allegro-3.9.32/src/x/xsystem.c
--- allegro-3.9.32.orig/src/x/xsystem.c Mon Mar 13 01:23:53 2000
+++ allegro-3.9.32/src/x/xsystem.c Sat Apr 8 00:00:23 2000
@@ -13,6 +13,9 @@
* By Michael Bukin.
*
* See readme.txt for copyright information.
+ *
+ * Modified by Eduard Bloch Fri, 7 Apr 2000 23:37:45 +0200
+ * (Lookup in path for our executable)
*/
@@ -25,6 +28,8 @@
#include <sys/time.h>
#include <unistd.h>
+#include <sys/stat.h>
+#include <string.h>
void (*_xwin_keyboard_interrupt)(int pressed, int code) = 0;
@@ -46,12 +51,13 @@
/* the main system driver for running under X-Windows */
+/* EB: IT is called X11 or X-Window [System], NOT X-WindowS */
SYSTEM_DRIVER system_xwin =
{
SYSTEM_XWINDOWS,
empty_string,
empty_string,
- "X-Windows",
+ "X Window System",
_xwin_sysdrv_init,
_xwin_sysdrv_exit,
_xwin_sysdrv_get_executable_name,
@@ -222,7 +228,41 @@
*/
static void _xwin_sysdrv_get_executable_name(char *output, int size)
{
- do_uconvert(__crt0_argv[0], U_ASCII, output, U_CURRENT, size);
+ int c,entries=0, i=0;
+ char *path,path_parts[30][250]; // reserve an array for max. 30 path entries
+ struct stat finfo;
+
+ path=(char *)getenv("PATH");
+ if(path){
+ for(c=0; c<strlen(path); c++){
+ if(path[c]==':'){
+ path_parts[entries][i]='\0'; // terminate the previos string
+ entries++; // next entry
+ i=0; // reset char position in the entry
+ }
+ else {
+ path_parts[entries][i]=path[c]; // fill entries with path-strings
+ i++;
+ }
+ path_parts[entries][i]='\0'; // terminate the last string
+ }
+ }
+ // so, let's test
+ if(entries!=0 && (!strchr(__crt0_argv[0], '/'))){
+ // if path is decoded and program called without /'s
+ for(c=0; c<=entries; c++){
+ strcat(path_parts[c], "/"); // append / and...
+ strcat(path_parts[c], __crt0_argv[0]); // ...argv[0]
+ if((stat(path_parts[c], &finfo)==0) && (!S_ISDIR (finfo.st_mode))){
+ // check if it is a valid file and not a directory
+ do_uconvert (path_parts[c], U_ASCII, output, U_CURRENT, size);
+ return;
+ }
+ }
+ }
+ else {
+ do_uconvert (__crt0_argv[0], U_ASCII, output, U_CURRENT, size);
+ }
}