Re: [AD] get_executable_name in unix |
[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]
Peter Wang wrote on Sat Apr 08, 2000 um 12:31:10PM: > I'm not a code-Nazi, and the file in question isn't even mine, but > could you please keep your patches consistent with the rest of the > file? Some things I noted: So, I corrected the things that Peter pointed out, copied the code to the linux driver also and added my comment to the docs. New patch is attached. > BTW, I'm pretty sure Michael would know that it's not "X-Windows", > but just doesn't care. What's in a name? Valid names are listed in X(1), registed is "X Window System". Greetings, Eduard. -- ===================================================================== Eduard Bloch <eb@xxxxxxxxxx>; HP: http://eduard.bloch.com/edecosi 0xEDF008C5(gpg): E6EB 98E2 B885 8FF0 6C04 5C1D E106 481E EDF0 08C5
diff -u --recursive --new-file allegro-3.9.32.orig/docs/allegro._tx allegro-3.9.32/docs/allegro._tx --- allegro-3.9.32.orig/docs/allegro._tx Mon Mar 13 01:24:00 2000 +++ allegro-3.9.32/docs/allegro._tx Sat Apr 8 21:17:17 2000 @@ -4704,6 +4704,11 @@ Fills buf with the full path to the current executable, returning at most size bytes. + On Linux and Unix platforms, the executed binary will be searched + in the $PATH environment if argv[0] doesn't contain the full pathname + (eg. if the executed binary is somewhere in the path and was called + directly from the command line). + @@char *@fix_filename_case(char *path); @xref fix_filename_slashes, fix_filename_path Converts a filename to a standardised case. On DOS platforms, they will diff -u --recursive --new-file allegro-3.9.32.orig/src/linux/lsystem.c allegro-3.9.32/src/linux/lsystem.c --- allegro-3.9.32.orig/src/linux/lsystem.c Mon Mar 13 01:23:49 2000 +++ allegro-3.9.32/src/linux/lsystem.c Sat Apr 8 21:06:52 2000 @@ -27,6 +27,8 @@ #include "allegro/aintvga.h" #include "linalleg.h" +#include <sys/stat.h> + #ifdef HAVE_SYS_IO_H /* This exists in Red Hat systems, at least, and defines the iopl function * which, contrary to the documentation, is left out of unistd.h. @@ -219,7 +221,40 @@ */ static void sys_linux_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]; + 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 it*/ + entries++; + i=0; + } + else { + path_parts[entries][i]=path[c]; + i++; + } + path_parts[entries][i]='\0'; /* terminate the last string */ + } + } + 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 "/" + argv[0] */ + strcat(path_parts[c], __crt0_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); + } } 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 21:06:39 2000 @@ -11,8 +11,11 @@ * Main system driver for the X-Windows library. * * By Michael Bukin. + * + * Searching in $PATH by Eduard Bloch * * See readme.txt for copyright information. + * */ @@ -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; @@ -45,13 +50,13 @@ static _DRIVER_INFO *_xwin_sysdrv_timer_drivers(void); -/* the main system driver for running under X-Windows */ +/* the main system driver for running under X11 */ 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, @@ -219,10 +224,48 @@ /* _xwin_sysdrv_get_executable_name: * Return full path to the current executable. + * + * <Comment for the manpage:> On Unix systems, if the program was + * called without the complete path-name (eg. because it is placed + * somewhere in $PATH) the PATH environment will be searched for the + * correct binary file. */ 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]; + 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 it*/ + entries++; + i=0; + } + else { + path_parts[entries][i]=path[c]; + i++; + } + path_parts[entries][i]='\0'; /* terminate the last string */ + } + } + 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 "/" + argv[0] */ + strcat(path_parts[c], __crt0_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); + } }
Attachment:
pgp6xYnBocr7u.pgp
Description: PGP signature
Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |