Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
niml_do.c
Go to the documentation of this file.00001 #include "niml_private.h"
00002
00003
00004
00005 static int doer_num = 0 ;
00006 static char **doer_verb = NULL ;
00007 static NI_voidfunc **doer_func = NULL ;
00008
00009 typedef void (*ddfun)(char *,NI_stream_type *,NI_element *) ;
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 void NI_register_doer( char *verb , NI_voidfunc *func )
00031 {
00032 int ii ;
00033
00034 if( verb == NULL || *verb == '\0' ) return ;
00035
00036
00037
00038 for( ii=0 ; ii < doer_num ; ii++ )
00039 if( strcmp(verb,doer_verb[ii]) == 0 ) break ;
00040
00041
00042
00043 if( ii < doer_num ){
00044 doer_func[ii] = func ; return ;
00045 }
00046
00047
00048
00049 if( func == NULL ) return ;
00050
00051
00052
00053 ii = doer_num++ ;
00054
00055 doer_verb = NI_realloc( doer_verb, char*, sizeof(char *)*doer_num ) ;
00056 doer_verb[ii] = NI_strdup(verb) ;
00057
00058 doer_func = NI_realloc( doer_func , NI_voidfunc*, sizeof(NI_voidfunc *)*doer_num ) ;
00059 doer_func[ii] = func ;
00060 return ;
00061 }
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 int NI_do( NI_stream_type *ns , NI_element *nel )
00076 {
00077 char *verb , *object ;
00078 int ii , builtin=0 ;
00079
00080
00081
00082 if( ns == NULL || nel == NULL || nel->type != NI_ELEMENT_TYPE ) return -1 ;
00083
00084 if( strcmp(nel->name ,"ni_do") != 0 &&
00085 strcmp(nel->name+1,"ni_do") != 0 ) return -1 ;
00086
00087
00088
00089 verb = NI_get_attribute( nel , "ni_verb" ) ;
00090 if( verb == NULL ) verb = NI_get_attribute( nel , "verb" ) ;
00091
00092 object = NI_get_attribute( nel , "ni_object" ) ;
00093 if( object == NULL ) object = NI_get_attribute( nel , "object" ) ;
00094 if( object == NULL ) object = NI_get_attribute( nel , "ni_obj" ) ;
00095 if( object == NULL ) object = NI_get_attribute( nel , "obj" ) ;
00096
00097 if( verb == NULL || verb[0] == '\0' ) return -1 ;
00098
00099
00100
00101
00102
00103
00104 if( strcmp(verb,"reopen_this") == 0 ){
00105
00106 NI_stream_type *nsnew ;
00107
00108 if( object == NULL || object[0] == '\0' ) return -1 ;
00109
00110 nsnew = NI_stream_open( object , "r" ) ;
00111 if( nsnew == NULL ) return -1 ;
00112
00113 NI_stream_close_keep(ns,0) ;
00114 *ns = *nsnew; NI_free(nsnew);
00115 builtin = 1 ;
00116
00117 }
00118
00119 else if( strcmp(verb,"close_this") == 0 ){
00120
00121 NI_stream_close_keep(ns,0);
00122 builtin = 1 ;
00123
00124 }
00125
00126 else if( strcmp(verb,"typedef") == 0 ){
00127
00128 char tnam[256] , tdef[8200] ;
00129 int tt ;
00130
00131 if( object == NULL || object[0] == '\0' ) return -1 ;
00132
00133 tnam[0] = tdef[0] = '\0' ;
00134 sscanf(object,"%255s %8199s",tnam,tdef) ;
00135 tt = NI_rowtype_define( tnam , tdef ) ;
00136 if( tt < 0 ) return -1 ;
00137 builtin = 1 ;
00138
00139 }
00140
00141
00142
00143
00144 for( ii=0 ; ii < doer_num ; ii++ ){
00145 if( strcmp(verb,doer_verb[ii]) == 0 ){
00146 if( doer_func[ii] != NULL ){
00147 void (*df)(char *,NI_stream_type *,NI_element *) = (ddfun)doer_func[ii] ;
00148 df( object , ns , nel ) ;
00149 }
00150 return 0 ;
00151 }
00152 }
00153
00154
00155
00156 return ((builtin) ? 0 : -1) ;
00157 }