Doxygen Source Code Documentation
niml_sucker.c File Reference
#include "niml_private.h"Go to the source code of this file.
| Data Structures | |
| struct | NI_converterstruct | 
| Functions | |
| char * | NI_self_idcode (void *nini) | 
| void | NI_suck_stream (char *sname, int msec, int *ndc, NI_objcontainer ***dc) | 
| void | NI_register_objconverters (char *self_name, NI_objconverter_func elm_to_obj, NI_objconverter_func obj_to_elm) | 
| void | NI_convert_elm_to_obj (NI_objcontainer *dc) | 
| Variables | |
| int | num_converters = 0 | 
| NI_converterstruct * | converters = NULL | 
Function Documentation
| 
 | 
| See if we can convert an element to an object. On input: 
 Definition at line 154 of file niml_sucker.c. References IDCODE_LEN, NI_strncpy(), num_converters, NI_objcontainer::self_name, and NI_converterstruct::to_obj. Referenced by NI_suck_stream(). 
 00155 {
00156    int cc , nn ;
00157 
00158    if( dc == NULL ) return ;
00159 
00160    if( strcmp(dc->typename,"NI_ELEMENT") != 0 &&
00161        strcmp(dc->typename,"NI_GROUP"  ) != 0   ) return ;
00162 
00163    for( cc=0 ; cc < num_converters ; cc++ )
00164      if( strcmp(converters[cc].self_name,dc->self_name) == 0 ) break ;
00165 
00166    if( cc == num_converters ) return ;
00167 
00168    nn = converters[cc].to_obj( dc ) ;
00169    if( nn > 0 )
00170      NI_strncpy( dc->typename , dc->self_name , IDCODE_LEN ) ;
00171 
00172    return ;
00173 }
 | 
| 
 | ||||||||||||||||
| 
 Definition at line 118 of file niml_sucker.c. References IDCODE_LEN, NI_objconverter_func, NI_strncpy(), num_converters, realloc, NI_converterstruct::to_elm, and NI_converterstruct::to_obj. 
 00121 {
00122    int cc ;
00123 
00124    if( self_name == NULL || *self_name == '\0' ) return ;
00125    if( elm_to_obj == (NI_objconverter_func)NULL  ) return ;
00126 
00127    for( cc=0 ; cc < num_converters ; cc++ )
00128      if( strcmp(converters[cc].self_name,self_name) == 0 ) break ;
00129 
00130    if( cc == num_converters ){
00131      num_converters++ ;
00132      converters = (NI_converterstruct *)
00133                     realloc( (void *)converters ,
00134                              sizeof(NI_converterstruct)*num_converters ) ;
00135    }
00136 
00137    NI_strncpy( converters[cc].self_name , self_name , IDCODE_LEN ) ;
00138    converters[cc].to_obj = elm_to_obj ;
00139    converters[cc].to_elm = obj_to_elm ;
00140    return ;
00141 }
 | 
| 
 | 
| Return a pointer to the idcode of a NIML element (group or data), if it has one. Otherwise, return NULL. Do not modify or free() this string, since it points into the NIML element struct. ----------------------------------------------------------------------------- Definition at line 9 of file niml_sucker.c. References NI_get_attribute(). Referenced by NI_suck_stream(). 
 00010 {
00011    char *rhs ;
00012    int ii ;
00013    static char *iname[] = { "self_idcode" ,
00014                             "AFNI_idcode" ,
00015                             "ni_idcode"   ,
00016                             "idcode"      ,
00017                             NULL           } ;
00018 
00019    for( ii=0 ; iname[ii] != NULL ; ii++ ){
00020      rhs = NI_get_attribute( nini , iname[ii] ) ;
00021      if( rhs != NULL ) return rhs ;
00022    }
00023 
00024    return NULL ;
00025 }
 | 
| 
 | ||||||||||||||||||||
| Open a stream, read all NIML stuff possible from it, close it. 
 Definition at line 34 of file niml_sucker.c. References calloc, free, IDCODE_LEN, NI_group::name, NI_element::name, NI_add_trusted_host(), NI_clock_time(), NI_convert_elm_to_obj(), NI_ELEMENT_TYPE, NI_element_type(), NI_GROUP_TYPE, NI_read_element(), NI_self_idcode(), NI_stream_closenow(), NI_stream_goodcheck(), NI_stream_open(), NI_strncpy(), realloc, NI_objcontainer::self_data, NI_objcontainer::self_idcode, and NI_objcontainer::self_name. 
 00035 {
00036    NI_stream ns ;
00037    int nn , start_msec=NI_clock_time() ;
00038    NI_objcontainer *mdc ;
00039    void *nini ;
00040    char *rhs ;
00041 
00042    /*-- startup and sanity checks --*/
00043 
00044    if( ndc == NULL ) return ;  /* clueless caller */
00045    *ndc = 0 ;                  /* number of objects found thus far */
00046    if( dc == NULL ) return ;   /* stupid caller */
00047    *dc = NULL ;                /* array of objects found thus far */
00048 
00049    ns = NI_stream_open( sname , "r" ) ;
00050    if( ns == NULL ) return ;                /* not so good */
00051 
00052    NI_add_trusted_host(NULL) ;
00053         if( msec == 0 ) msec = 1 ;                /* short waits */
00054    else if( msec <  0 ) msec = 999999999 ;        /* long waits */
00055 
00056    /*-- wait for connection to be good --*/
00057 
00058    nn = NI_stream_goodcheck( ns , msec ) ;
00059    if( nn <= 0 ){ NI_stream_closenow(ns); return; }
00060 
00061    /*-- loopback point to get a new NI element (group or data) --*/
00062 
00063  GetElement:
00064    nini = NI_read_element( ns , msec ) ;
00065    if( nini == NULL ){ NI_stream_closenow(ns); return; } /*** the way out ***/
00066 
00067    nn  = NI_element_type(nini) ;
00068    rhs = NI_self_idcode (nini) ;
00069    mdc = (NI_objcontainer *)calloc(1,sizeof(NI_objcontainer)) ;
00070 
00071    mdc->self_data = nini ;
00072    NI_strncpy( mdc->self_idcode , rhs , IDCODE_LEN ) ;
00073 
00074    if( nn == NI_ELEMENT_TYPE ){
00075      NI_element *nel = (NI_element *)nini ;
00076 
00077      NI_strncpy( mdc->typename  , "NI_ELEMENT" , IDCODE_LEN ) ;
00078      NI_strncpy( mdc->self_name , nel->name    , IDCODE_LEN ) ;
00079 
00080    } else if( nn == NI_GROUP_TYPE ){
00081      NI_group *ngr = (NI_group *)nini ;
00082 
00083      NI_strncpy( mdc->typename  , "NI_GROUP" , IDCODE_LEN ) ;
00084      NI_strncpy( mdc->self_name , ngr->name  , IDCODE_LEN ) ;
00085 
00086    } else {  /** should never happen */
00087 
00088      fprintf(stderr,"\n** ERROR: non-NIML data on stream '%s' !!\n",sname) ;
00089      free((void *)mdc) ;
00090      goto GetElement ;
00091 
00092    }
00093 
00094    /*-- add new element to output list --*/
00095 
00096    NI_convert_elm_to_obj( mdc ) ; /* convert to struct in-place, if possible */
00097 
00098    (*ndc)++ ;
00099    (*dc) = (NI_objcontainer **)realloc( (void *)(*dc) ,
00100                                          sizeof(NI_objcontainer *) * (*ndc) ) ;
00101    (*dc)[(*ndc)-1] = mdc ;
00102 
00103    goto GetElement ;
00104 }
 | 
Variable Documentation
| 
 | 
| 
 Definition at line 114 of file niml_sucker.c. | 
| 
 | 
| 
 Definition at line 113 of file niml_sucker.c. Referenced by NI_convert_elm_to_obj(), and NI_register_objconverters(). | 
 
                             
                             
                             
                             
                             
                             
                             
                             
                             
                             
                             
                             
 
 
 
 
       
	   
	   
	   
	  