Doxygen Source Code Documentation
thd_getpathprogs.c File Reference
#include "mrilib.h"
#include "thd.h"
Go to the source code of this file.
Functions | |
char * | THD_find_executable (char *ename) |
THD_string_array * | THD_getpathprogs (THD_string_array *dlist) |
THD_string_array * | THD_get_all_executables (char *dname) |
Variables | |
int | einit = 0 |
THD_string_array * | elist = NULL |
Function Documentation
|
Find an executable in the PATH by its name, if it exists. If not, NULL is returned. If it exists, a pointer to static storage is returned (i.e., don't free() this pointer!). ------------------------------------------------------------------------------ Definition at line 13 of file thd_getpathprogs.c. References THD_string_array::ar, einit, ENTRY, THD_string_array::num, RETURN, THD_getpathprogs(), and THD_trailname(). Referenced by ISQ_setup_ppmto_filters(), JPEG_matrix_gray(), mpeg_setup(), mri_read_stuff(), mri_write_jpg(), setup_mri_write_angif(), and THD_write_minc().
00014 { 00015 char *etr , *str ; 00016 int ii ; 00017 00018 ENTRY("THD_find_executable") ; 00019 00020 if( !einit ){ einit = 1 ; elist = THD_getpathprogs(NULL) ; } 00021 if( elist == NULL ) RETURN(NULL) ; 00022 00023 etr = THD_trailname( ename , 0 ) ; 00024 00025 for( ii=0 ; ii < elist->num ; ii++ ){ 00026 str = THD_trailname( elist->ar[ii] , 0 ) ; 00027 if( strcmp(str,etr) == 0 ) RETURN(elist->ar[ii]) ; 00028 } 00029 00030 RETURN(NULL) ; 00031 } |
|
Read all executable filenames from a directory. Definition at line 128 of file thd_getpathprogs.c. References ADDTO_SARR, THD_string_array::ar, DESTROY_SARR, ENTRY, far, INIT_SARR, THD_string_array::num, RETURN, SARR_NUM, STATUS, THD_extract_regular_files(), THD_get_all_filenames(), and THD_is_executable(). Referenced by THD_getpathprogs().
00129 { 00130 int ir , ll , ii ; 00131 char *fname , *tname ; 00132 float *far ; 00133 THD_string_array *outar, *alist, *rlist ; 00134 00135 ENTRY("THD_get_all_executables") ; 00136 00137 /*----- sanity check and initialize -----*/ 00138 00139 if( dname == NULL || strlen(dname) == 0 ) RETURN(NULL) ; 00140 INIT_SARR( outar ) ; 00141 00142 /*----- find all regular files -----*/ 00143 00144 if(PRINT_TRACING){ 00145 char str[256];sprintf(str,"call THD_get_all_filenames(%s)",dname); STATUS(str); 00146 } 00147 alist = THD_get_all_filenames( dname ) ; 00148 00149 if( alist == NULL ) RETURN(NULL) ; 00150 STATUS("call THD_extract_regular_files") ; 00151 rlist = THD_extract_regular_files( alist ) ; 00152 DESTROY_SARR( alist ) ; 00153 if( rlist == NULL ) RETURN(NULL) ; 00154 00155 /* 04 Feb 2002: don't include .so libraries, etc. */ 00156 00157 for( ir=0 ; ir < rlist->num ; ir++ ){ 00158 fname = rlist->ar[ir] ; 00159 if( THD_is_executable(fname) && 00160 !strstr(fname,".so") && 00161 !strstr(fname,".la") ) ADDTO_SARR(outar,fname) ; 00162 } 00163 00164 DESTROY_SARR(rlist) ; 00165 00166 if( SARR_NUM(outar) == 0 ) DESTROY_SARR(outar) ; 00167 00168 RETURN( outar ); 00169 } |
|
Return a list of all executable files in the PATH and the dlist. Definition at line 36 of file thd_getpathprogs.c. References ADDTO_SARR, THD_string_array::ar, DESTROY_SARR, ENTRY, free, INIT_SARR, malloc, my_getenv(), THD_string_array::num, RETURN, SARR_NUM, THD_equiv_files(), THD_get_all_executables(), THD_is_directory(), and THD_MAX_NAME. Referenced by THD_find_executable().
00037 { 00038 int id , ii , ndir ; 00039 char *epath , *eee ; 00040 THD_string_array *elist , *tlist , *qlist ; 00041 00042 ENTRY("THD_getpathprogs") ; 00043 00044 /*----- sanity check and initialize -----*/ 00045 00046 epath = my_getenv( "PATH" ) ; 00047 ndir = (dlist != NULL) ? dlist->num : 0 ; 00048 00049 if( ndir == 0 && epath == NULL ) RETURN(NULL) ; 00050 00051 INIT_SARR(elist) ; 00052 INIT_SARR(qlist) ; /* 04 Feb 2002: list of searched directories */ 00053 00054 /*----- for each input directory, find all executable files -----*/ 00055 00056 for( id=0 ; id < ndir ; id++ ){ 00057 00058 tlist = THD_get_all_executables( dlist->ar[id] ) ; 00059 if( tlist == NULL ) continue ; 00060 00061 for( ii=0 ; ii < tlist->num ; ii++ ) /* copy names to output array */ 00062 ADDTO_SARR( elist , tlist->ar[ii] ) ; 00063 00064 ADDTO_SARR(qlist,dlist->ar[id]) ; /* 04 Feb 2002 */ 00065 00066 DESTROY_SARR(tlist) ; 00067 } 00068 00069 /*----- also do directories in environment path, if any -----*/ 00070 00071 if( epath != NULL ){ 00072 int epos =0 , ll = strlen(epath) ; 00073 char *elocal ; 00074 char ename[THD_MAX_NAME] ; 00075 00076 /* copy path list into local memory */ 00077 00078 elocal = (char *) malloc( sizeof(char) * (ll+2) ) ; 00079 strcpy( elocal , epath ) ; elocal[ll] = ' ' ; elocal[ll+1] = '\0' ; 00080 00081 /* replace colons with blanks */ 00082 00083 for( ii=0 ; ii < ll ; ii++ ) 00084 if( elocal[ii] == ':' ) elocal[ii] = ' ' ; 00085 00086 /* extract blank delimited strings, 00087 use as directory names to get timeseries files */ 00088 00089 do{ 00090 ii = sscanf( elocal+epos , "%s%n" , ename , &id ) ; 00091 if( ii < 1 ) break ; /* no read ==> end of work */ 00092 epos += id ; /* epos = char after last one scanned */ 00093 00094 ii = strlen(ename) ; /* make sure name has */ 00095 if( ename[ii-1] != '/' ){ /* a trailing '/' on it */ 00096 ename[ii] = '/' ; ename[ii+1] = '\0' ; 00097 } 00098 if( !THD_is_directory(ename) ) continue ; /* 25 Feb 2002 */ 00099 00100 /* 04 Feb 2002: check if we already searched this directory */ 00101 00102 for( ii=0 ; ii < qlist->num ; ii++ ) 00103 if( THD_equiv_files(qlist->ar[ii],ename) ) break ; 00104 if( ii < qlist->num ) continue ; /* skip this directory */ 00105 ADDTO_SARR(qlist,ename) ; 00106 00107 tlist = THD_get_all_executables( ename ) ; /* read this directory */ 00108 if( tlist != NULL ){ 00109 for( ii=0 ; ii < tlist->num ; ii++ ) /* move names to output */ 00110 ADDTO_SARR( elist , tlist->ar[ii] ) ; 00111 DESTROY_SARR(tlist) ; 00112 } 00113 00114 } while( epos < ll ) ; /* scan until 'epos' is after end of epath */ 00115 00116 free(elocal) ; 00117 } 00118 00119 if( SARR_NUM(elist) == 0 ) DESTROY_SARR(elist) ; 00120 00121 DESTROY_SARR(qlist) ; /* 04 Feb 2002 */ 00122 RETURN(elist) ; 00123 } |
Variable Documentation
|
Definition at line 4 of file thd_getpathprogs.c. Referenced by THD_find_executable(). |
|
Definition at line 5 of file thd_getpathprogs.c. |