Doxygen Source Code Documentation
thd_initprefix.c File Reference
#include "mrilib.h"#include "thd.h"Go to the source code of this file.
Functions | |
| THD_datablock_array * | THD_init_prefix_datablocks (char *prefixname, THD_string_array *regfile_list) |
Function Documentation
|
||||||||||||
|
Definition at line 17 of file thd_initprefix.c. References ADDTO_DBARR, THD_string_array::ar, DATASET_HEADER_SUFFIX, FILENAME_TO_PREFIX, INIT_DBARR, THD_string_array::num, REMOVEFROM_SARR, SARR_lookfor_substring(), THD_init_one_datablock(), and THD_MAX_NAME. Referenced by THD_init_alldir_datablocks().
00019 {
00020 THD_datablock_array * dblk_arr ;
00021 THD_datablock * dblk ;
00022 int nlast , nnext , plen , ii ;
00023 char prefixcode[THD_MAX_NAME] , dirname[THD_MAX_NAME] , ptemp[THD_MAX_NAME] ;
00024 char * fname ;
00025
00026 /* initialize answer */
00027
00028 INIT_DBARR( dblk_arr ) ;
00029
00030 if( prefixname == NULL || strlen(prefixname) == 0 ||
00031 regfile_list == NULL || regfile_list->num <= 0 ) return dblk_arr ;
00032
00033 strcpy(prefixcode,prefixname) ; strcat(prefixcode,"+") ;
00034
00035 /* for each file that could be a dataset header, try to make a datablock */
00036
00037 nlast = 0 ; /* start first search at beginning of list */
00038
00039 do{
00040
00041 /* look for the correct type of filename */
00042
00043 nnext = SARR_lookfor_substring( regfile_list ,
00044 DATASET_HEADER_SUFFIX , nlast ) ;
00045
00046 if( nnext < 0 ) break ; /* no more header files */
00047 nlast = nnext + 1 ; /* start next search here */
00048
00049 fname = regfile_list->ar[nnext] ;
00050 if( strstr(fname,prefixcode) == NULL ) continue ; /* wrong prefix */
00051 FILENAME_TO_PREFIX(fname,ptemp) ;
00052 if( strcmp(prefixname,ptemp) != 0 ) continue ; /* wrong prefix */
00053
00054 /* try to make datablock from this file */
00055
00056 /*-- find directory in fname --*/
00057
00058 plen = strlen(fname) ;
00059 for( ii=plen-1 ; ii >= 0 ; ii-- ) if( fname[ii] == '/' ) break ;
00060
00061 if( ii < 0 ){
00062 strcpy( dirname , "./" ) ; /* fake directory name */
00063 } else {
00064 strcpy( dirname , fname ) ;
00065 dirname[ii+1] = '\0' ;
00066 }
00067
00068 /* try to make datablock from this file */
00069
00070 dblk = THD_init_one_datablock( dirname , fname ) ;
00071 if( dblk != NULL ) ADDTO_DBARR(dblk_arr,dblk) ;
00072 REMOVEFROM_SARR( regfile_list , nnext ) ;
00073
00074 } while(1) ;
00075
00076 return dblk_arr ;
00077 }
|