Doxygen Source Code Documentation
niml.h File Reference
#include <stddef.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <ctype.h>#include <errno.h>#include <sys/types.h>#include <sys/stat.h>#include <string.h>#include <sys/socket.h>#include <netinet/in.h>#include <netinet/tcp.h>#include <netdb.h>#include <arpa/inet.h>#include <sys/time.h>#include <fcntl.h>#include <sys/times.h>#include <limits.h>#include <sys/ipc.h>#include <sys/shm.h>Go to the source code of this file.
Data Structures | |
| struct | complex |
| struct | DIME_message |
| struct | DIME_part |
| struct | Dtable |
| struct | Htable |
| struct | NI_affine_3dmap |
| struct | NI_byte_vector |
| struct | NI_complex_vector |
| struct | NI_dataset |
| struct | NI_double_vector |
| struct | NI_element |
| struct | NI_float_one |
| struct | NI_float_vector |
| struct | NI_group |
| struct | NI_int_vector |
| struct | NI_objcontainer |
| struct | NI_points_domain |
| struct | NI_procins |
| struct | NI_rect_domain |
| struct | NI_rgb_vector |
| struct | NI_rgba_vector |
| struct | NI_rowtype |
| struct | NI_short_vector |
| struct | NI_statistic |
| struct | NI_str_array |
| struct | NI_stream_type |
| struct | NI_string_vector |
| struct | NI_struct |
| struct | NI_vector |
| struct | rgb |
| struct | rgba |
| struct | SHMioc |
Defines | |
| #define | offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) |
| #define | NI_BYTE 0 |
| #define | NI_SHORT 1 |
| #define | NI_INT 2 |
| #define | NI_FLOAT32 3 |
| #define | NI_FLOAT NI_FLOAT32 |
| #define | NI_FLOAT64 4 |
| #define | NI_DOUBLE NI_FLOAT64 |
| #define | NI_COMPLEX64 5 |
| #define | NI_COMPLEX NI_COMPLEX64 |
| #define | NI_RGB 6 |
| #define | NI_RGBA 7 |
| #define | NI_IS_NUMERIC_TYPE(t) ( (t) >= 0 && (t) <= NI_RGBA ) |
| #define | NI_STRING 8 |
| #define | NI_NUM_TYPES 9 |
| #define | NI_NUM_BASIC_TYPES 8 |
| #define | IS_DATUM_CHAR(c) |
| #define | NI_is_builtin_type(t) ( (t) >= 0 && (t) < NI_NUM_TYPES ) |
| #define | NI_is_basic_type(t) ( (t) >= 0 && (t) < NI_NUM_BASIC_TYPES ) |
| #define | ROWTYPE_VARSIZE_MASK (1<<0) |
| #define | ROWTYPE_is_varsize(rr) (((rr)->flag & ROWTYPE_VARSIZE_MASK) != 0) |
| #define | ROWTYPE_part_dimen(rt, pt, qq) ( *((int *)( (pt) + (rt)->part_off[ (rt)->part_dim[qq] ] )) ) |
| #define | delete_rowtype(rr) |
| #define | ROWTYPE_is_basic_code NI_is_basic_type |
| #define | NI_ELEMENT_TYPE 17 |
| #define | NI_GROUP_TYPE 18 |
| #define | NI_PROCINS_TYPE 19 |
| #define | SHM_WAIT_CREATE 9 |
| #define | SHM_WAIT_ACCEPT 10 |
| #define | SHM_IS_DEAD 99 |
| #define | SHM_CREATOR 33 |
| #define | SHM_ACCEPTOR 44 |
| #define | SHM_DEFAULT_SIZE 196689 |
| #define | SHM_HSIZE 128 |
| #define | SHM_SIZE1 0 |
| #define | SHM_BSTART1 1 |
| #define | SHM_BEND1 2 |
| #define | SHM_SIZE2 3 |
| #define | SHM_BSTART2 4 |
| #define | SHM_BEND2 5 |
| #define | NI_BUFSIZE (31*1024) |
| #define | NI_TCP_TYPE 1 |
| #define | NI_FILE_TYPE 2 |
| #define | NI_STRING_TYPE 3 |
| #define | NI_REMOTE_TYPE 4 |
| #define | NI_FD_TYPE 5 |
| #define | NI_SHM_TYPE 6 |
| #define | TCP_WAIT_ACCEPT 7 |
| #define | TCP_WAIT_CONNECT 8 |
| #define | MARKED_FOR_DEATH 6666 |
| #define | NI_INPUT_MODE 0 |
| #define | NI_OUTPUT_MODE 1 |
| #define | NI_TEXT_MODE 0 |
| #define | NI_BINARY_MODE 1 |
| #define | NI_BASE64_MODE 2 |
| #define | NI_HEADERONLY_FLAG (1<<8) |
| #define | NI_HEADERSHARP_FLAG (1<<9) |
| #define | NI_LSB_FIRST 1 |
| #define | NI_MSB_FIRST 2 |
| #define | NI_ATTMODE_NORMAL 0 |
| #define | NI_ATTMODE_SPACED 1 |
| #define | NI_ATTMODE_LAST 1 |
| #define | NI_NAMEMODE_NORMAL 0 |
| #define | NI_NAMEMODE_ALIAS 1 |
| #define | NI_NAMEMODE_LAST 1 |
| #define | sizeof_Htable(ht) ((ht)->ntot) |
| #define | DIME_MB_MASK (1<<0) |
| #define | DIME_ME_MASK (1<<1) |
| #define | DIME_CF_MASK (1<<2) |
| #define | DIME_VERSION_MASK (0xf8) |
| #define | NI_malloc(typ, a) (typ*) hidden_NI_malloc((a),__FILE__,__LINE__) |
| #define | NI_calloc(a, b) hidden_NI_malloc((a)*(b),__FILE__,__LINE__) |
| #define | NI_realloc(a, typ, b) (typ*) hidden_NI_realloc((a),(b),__FILE__,__LINE__) |
| #define | NI_free(a) hidden_NI_free((a),__FILE__,__LINE__) |
| #define | NI_FREE(p) ( NI_free(p), (p)=NULL ) |
| #define | NI_new(typ) ( NI_malloc(typ, sizeof(typ)) ) |
| #define | NI_is_file(pn) (NI_filesize(pn) >= 0) |
| #define | NI_SWAP_MASK (1<<0) |
| #define | NI_LTEND_MASK (1<<1) |
| #define | NI_STREAM_CLOSE(nn) do{ NI_stream_close(nn); (nn)=NULL; } while(0) |
| #define | NI_BASIC_PARTS |
| #define | NI_float_val(nd) ((nd)->val) |
| #define | NI_stat_code(nd) ((nd)->statcode) |
| #define | NI_stat_param_num(nd) ((nd)->param_num) |
| #define | NI_stat_param(nd, i, j) |
| #define | NI_STAT_CORREL 2 |
| #define | NI_STAT_TTEST 3 |
| #define | NI_STAT_FTEST 4 |
| #define | NI_STAT_ZSCORE 5 |
| #define | NI_STAT_CHISQ 6 |
| #define | NI_STAT_BETA 7 |
| #define | NI_STAT_BINOM 8 |
| #define | NI_STAT_GAMMA 9 |
| #define | NI_STAT_POISSON 10 |
| #define | NI_STAT_NORMAL 11 |
| #define | NI_STAT_FTEST_NONC 12 |
| #define | NI_STAT_CHISQ_NONC 13 |
| #define | NI_STAT_LOGISTIC 14 |
| #define | NI_STAT_LAPLACE 15 |
| #define | NI_STAT_UNIFORM 16 |
| #define | NI_STAT_TTEST_NONC 17 |
| #define | NI_STAT_WEIBULL 18 |
| #define | NI_STAT_CHI 19 |
| #define | NI_STAT_INVGAUSS 20 |
| #define | NI_STAT_EXTVAL 21 |
| #define | NI_STAT_PVAL 22 |
| #define | NI_STAT_LOGPVAL 23 |
| #define | NI_STAT_LOG10PVAL 24 |
| #define | NI_STAT_FIRSTCODE 2 |
| #define | NI_STAT_LASTCODE 24 |
| #define | NI_NODE_DIRECTION 55 |
| #define | NI_INDEX_DIRECTION 56 |
| #define | NI_dataset_vecnum(nd) ( ((nd)->order == NI_NODE_DIRECTION) ? (nd)->num_val : (nd)->num_node ) |
| #define | NI_dataset_veclen(nd) ( ((nd)->order == NI_NODE_DIRECTION) ? (nd)->num_node: (nd)->num_val ) |
| #define | NI_opposite_order(oo) ( ((oo) == NI_NODE_DIRECTION) ? NI_INDEX_DIRECTION : NI_NODE_DIRECTION ) |
| #define | NI_STRUCT_TYPE 6660000 |
| #define | NI_FLOAT_ONE_TYPE 6660002 |
| #define | NI_STATISTIC_TYPE 6660003 |
| #define | NI_DATASET_TYPE 6660004 |
| #define | NI_VECTOR_TYPE 6660100 |
| #define | NI_BYTE_VECTOR_TYPE 6660101 |
| #define | NI_SHORT_VECTOR_TYPE 6660102 |
| #define | NI_INT_VECTOR_TYPE 6660103 |
| #define | NI_FLOAT_VECTOR_TYPE 6660104 |
| #define | NI_DOUBLE_VECTOR_TYPE 6660105 |
| #define | NI_COMPLEX_VECTOR_TYPE 6660106 |
| #define | NI_RGB_VECTOR_TYPE 6660107 |
| #define | NI_RGBA_VECTOR_TYPE 6660108 |
| #define | NI_STRING_VECTOR_TYPE 6660109 |
| #define | NI_is_vector_type(tt) ( (tt) >= NI_VECTOR_TYPE && (tt) <= NI_STRING_VECTOR_TYPE ) |
| #define | NI_patch_vector_type(nn) |
| #define | NI_RECT_DOMAIN_TYPE 6660201 |
| #define | NI_POINTS_DOMAIN_TYPE 6660202 |
| #define | NI_is_domain_type(tt) ( (tt) >= NI_RECT_DOMAIN_TYPE && (tt) <= NI_POINTS_DOMAIN_TYPE ) |
| #define | NI_AFFINE_3DMAP_TYPE 6660301 |
| #define | NI_is_3dmap_type(tt) ( (tt) >= NI_AFFINE_3DMAP_TYPE && (tt) <= NI_AFFINE_3DMAP_TYPE ) |
| #define | NI_datatype_size(n) NI_rowtype_code_to_size(n) |
| #define | NI_delete_str_array(sar) |
| #define | NI_decode_str_array NI_decode_string_list |
| #define | IDCODE_LEN 32 |
| #define | LEN_IDCODE IDCODE_LEN |
Typedefs | |
| typedef unsigned char | byte |
| typedef NI_rowtype | NI_rowtype |
| typedef NI_stream_type * | NI_stream |
| typedef int | NI_index_t |
| typedef void | NI_voidfunc () |
| typedef int(* | NI_objconverter_func )(NI_objcontainer *) |
Functions | |
| int | NI_rowtype_define (char *, char *) |
| NI_rowtype * | NI_rowtype_find_name (char *) |
| NI_rowtype * | NI_rowtype_find_code (int) |
| int | NI_rowtype_name_to_code (char *) |
| char * | NI_rowtype_code_to_name (int) |
| char * | NI_rowtype_code_to_alias (int) |
| int | NI_rowtype_name_to_size (char *) |
| int | NI_rowtype_code_to_size (int) |
| int | NI_rowtype_vsize (NI_rowtype *, void *) |
| void | NI_val_to_text (NI_rowtype *, char *, char *) |
| int | NI_val_to_binary (NI_rowtype *, char *, char *) |
| void | NI_multival_to_text (NI_rowtype *, int, char *, char *) |
| int | NI_multival_to_binary (NI_rowtype *, int, char *, char *) |
| int | NI_has_String (NI_rowtype *) |
| void | NI_swap_column (NI_rowtype *, int, char *) |
| void | NI_rowtype_debug (int) |
| char * | NI_type_name (int) |
| NI_procins * | NI_rowtype_procins (NI_rowtype *) |
| void | NI_set_attribute_mode (int) |
| void | NI_set_typename_mode (int) |
| Htable * | new_Htable (int) |
| void | destroy_Htable (Htable *) |
| void | addto_Htable (char *, void *, Htable *) |
| void * | findin_Htable (char *, Htable *) |
| void | removefrom_Htable (char *, Htable *) |
| void | profile_Htable (char *, Htable *) |
| void | subsume_Htable (Htable *, Htable *) |
| void | Htable_set_vtkill (int) |
| void | resize_Htable (int, Htable *) |
| Dtable * | new_Dtable (int) |
| void | destroy_Dtable (Dtable *) |
| void | addto_Dtable (char *, char *, Dtable *) |
| char * | findin_Dtable_a (char *, Dtable *) |
| char * | findin_Dtable_b (char *, Dtable *) |
| void | removefrom_Dtable_a (char *, Dtable *) |
| void | removefrom_Dtable_b (char *, Dtable *) |
| int | listize_Dtable (Dtable *, char ***, char ***) |
| char * | Dtable_to_nimlstring (Dtable *, char *) |
| Dtable * | Dtable_from_nimlstring (char *) |
| DIME_message * | DIME_read_message (NI_stream_type *, int) |
| DIME_part * | DIME_read_part (NI_stream_type *, int) |
| void | DIME_destroy_message (DIME_message *) |
| void * | hidden_NI_malloc (size_t, char *, int) |
| void * | hidden_NI_realloc (void *, size_t, char *, int) |
| void | hidden_NI_free (void *, char *, int) |
| char * | NI_malloc_status (void) |
| void | NI_malloc_dump (void) |
| void | NI_malloc_enable_tracking (void) |
| int | NI_malloc_tracking_enabled (void) |
| int | NI_malloc_replace (void *(*um)(size_t), void *(*ur)(void *, size_t), void(*uf)(void *)) |
| char * | NI_strncpy (char *, const char *, size_t) |
| char * | NI_strdup (char *) |
| int | NI_strlen (char *) |
| long | NI_filesize (char *) |
| int | NI_clock_time (void) |
| int | NI_byteorder (void) |
| void | NI_swap2 (int, void *) |
| void | NI_swap4 (int, void *) |
| void | NI_swap8 (int, void *) |
| char * | NI_mktemp (char *) |
| int | NI_type_size (int) |
| int | NI_element_rowsize (NI_element *) |
| int | NI_element_allsize (NI_element *) |
| void | NI_free_element (void *) |
| int | NI_element_type (void *) |
| char * | NI_element_name (void *) |
| NI_element * | NI_new_data_element (char *, int) |
| void | NI_add_column (NI_element *, int, void *) |
| void | NI_set_attribute (void *, char *, char *) |
| char * | NI_get_attribute (void *, char *) |
| void | NI_insert_value (NI_element *, int, int, void *) |
| void | NI_add_column_stride (NI_element *, int, void *, int) |
| void | NI_fill_column_stride (NI_element *, int, void *, int, int) |
| void | NI_insert_string (NI_element *, int, int, char *) |
| void | NI_alter_veclen (NI_element *, int) |
| NI_group * | NI_new_group_element (void) |
| void | NI_add_to_group (NI_group *, void *) |
| void | NI_rename_group (NI_group *, char *) |
| void | NI_remove_from_group (NI_group *, void *) |
| int | NI_search_group_shallow (NI_group *, char *, void ***) |
| int | NI_search_group_deep (NI_group *, char *, void ***) |
| NI_procins * | NI_new_processing_instruction (char *) |
| void | NI_swap_vector (int, int, void *) |
| NI_stream | NI_stream_open (char *, char *) |
| int | NI_stream_goodcheck (NI_stream_type *, int) |
| void | NI_stream_close (NI_stream_type *) |
| void | NI_stream_kill (NI_stream_type *) |
| void | NI_stream_closenow (NI_stream_type *) |
| int | NI_stream_readcheck (NI_stream_type *, int) |
| int | NI_stream_writecheck (NI_stream_type *, int) |
| int | NI_stream_write (NI_stream_type *, char *, int) |
| int | NI_stream_read (NI_stream_type *, char *, int) |
| void | NI_binary_threshold (NI_stream_type *, int) |
| void | NI_sleep (int) |
| char * | NI_stream_getbuf (NI_stream_type *) |
| void | NI_stream_clearbuf (NI_stream_type *) |
| void | NI_stream_setbuf (NI_stream_type *, char *) |
| char * | NI_stream_name (NI_stream_type *) |
| int | NI_stream_readable (NI_stream_type *) |
| int | NI_stream_writeable (NI_stream_type *) |
| int | NI_stream_hasinput (NI_stream_type *, int) |
| void | NI_stream_seek (NI_stream_type *, int, int) |
| int | NI_stream_writestring (NI_stream_type *, char *) |
| int | NI_stream_setbufsize (NI_stream_type *, int) |
| int | NI_stream_getbufsize (NI_stream_type *) |
| int | NI_stream_readbuf (NI_stream_type *, char *, int) |
| int | NI_stream_readbuf64 (NI_stream_type *, char *, int) |
| int | NI_text_to_val (NI_stream_type *, NI_rowtype *, void *, int) |
| int | NI_binary_to_val (NI_stream_type *, NI_rowtype *, void *, int) |
| int | NI_base64_to_val (NI_stream_type *, NI_rowtype *, void *, int) |
| int | NI_stream_setb64 (NI_stream_type *, int) |
| int | NI_stream_reopen (NI_stream_type *, char *) |
| void * | NI_read_element (NI_stream_type *, int) |
| int | NI_write_element (NI_stream_type *, void *, int) |
| int | NI_write_procins (NI_stream_type *, char *) |
| int | NI_write_columns (NI_stream_type *, int, int *, int, void **, int) |
| int | NI_write_rowtype (NI_stream_type *, NI_rowtype *, int, void *, int) |
| int | NI_read_columns (NI_stream_type *, int, int *, int, void **, int, int) |
| void | NI_free_column (NI_rowtype *, int, void *) |
| void * | NI_copy_column (NI_rowtype *, int, void *) |
| int | NI_size_column (NI_rowtype *, int, void *) |
| void | NI_read_header_only (int) |
| void * | NI_read_element_header (NI_stream_type *, int) |
| void | NI_skip_procins (int) |
| int | NI_read_URL_tmpdir (char *url, char **tname) |
| int | NI_read_URL (char *url, char **data) |
| void | NI_set_URL_ftp_ident (char *name, char *pwd) |
| void | B64_set_crlf (int nn) |
| void | B64_set_linelen (int ll) |
| void | B64_to_binary (int nb64, byte *b64, int *nbin, byte **bin) |
| void | B64_to_base64 (int nbin, byte *bin, int *nb64, byte **b64) |
| char * | MD5_static_array (int n, char *bytes) |
| char * | MD5_malloc_array (int n, char *bytes) |
| char * | MD5_static_string (char *string) |
| char * | MD5_malloc_string (char *string) |
| char * | MD5_static_file (char *filename) |
| char * | MD5_malloc_file (char *filename) |
| char * | MD5_B64_array (int n, char *bytes) |
| char * | MD5_B64_string (char *string) |
| char * | MD5_B64_file (char *filename) |
| char * | UNIQ_idcode (void) |
| void | UNIQ_idcode_fill (char *) |
| char * | UNIQ_hashcode (char *) |
| char * | UUID_hashcode (char *) |
| char * | UUID_idcode (void) |
| char * | NI_hostname_to_inet (char *host) |
| void | NI_add_trusted_host (char *hostname) |
| int | NI_trust_host (char *hostid) |
| void | NI_free_struct (void *) |
| void * | NI_copy_struct (void *) |
| void * | NI_pointto_struct (void *) |
| void | NI_register_struct (void *) |
| void * | NI_find_struct (char *) |
| void | NI_unregister_struct (void *) |
| int | NI_stat_numparam (int) |
| char * | NI_stat_distname (int) |
| void | NI_stat_decode (char *, int *, float *, float *, float *) |
| char * | NI_stat_encode (int, float, float, float) |
| void * | NI_new_vector (int, NI_index_t) |
| void | NI_set_vector_range (void *) |
| void * | NI_dataset_transpose (void *) |
| int | NI_do (NI_stream_type *, NI_element *) |
| void | NI_register_doer (char *, NI_voidfunc *) |
| NI_str_array * | NI_decode_string_list (char *ss, char *sep) |
| void * | NI_registry_malloc (char *, char *, size_t) |
| void * | NI_registry_realloc (void *, size_t) |
| void | NI_registry_free (void *) |
| void * | NI_registry_idcode_to_ptr (char *) |
| char * | NI_registry_idcode_to_name (char *) |
| char * | NI_registry_ptr_to_idcode (void *) |
| char * | NI_registry_ptr_to_name (void *) |
| void | NI_registry_idcode_altername (char *, char *) |
| void | NI_registry_ptr_altername (void *, char *) |
| size_t | NI_registry_idcode_to_len (char *) |
| size_t | NI_registry_ptr_to_len (void *) |
| void * | NI_registry_add (char *, char *, void *) |
| void * | NI_registry_replace (void *, void *) |
| char * | NI_self_idcode (void *) |
| void | NI_suck_stream (char *, int, int *, NI_objcontainer ***) |
| void | NI_convert_elm_to_obj (NI_objcontainer *) |
| void | NI_convert_obj_to_elm (NI_objcontainer *) |
| void | NI_register_objconverters (char *, NI_objconverter_func, NI_objconverter_func) |
Define Documentation
|
|
Value: do{ NI_free((rr)->name) ; \ NI_free((rr)->userdef) ; \ NI_free((rr)->comp_typ) ; \ NI_free((rr)->part_typ) ; \ NI_free((rr)->part_off) ; \ NI_free(rr) ; } while(0) Definition at line 153 of file niml.h. Referenced by NI_rowtype_define(). |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Definition at line 1184 of file niml.h. Referenced by NI_convert_elm_to_obj(), NI_register_objconverters(), and NI_suck_stream(). |
|
|
Value: ( (c) == 'b' || (c) == 's' || (c) == 'i' || \ (c) == 'f' || (c) == 'd' || (c) == 'c' || \ (c) == 'r' || (c) == 'S' || (c) == 'L' || \ (c) == 'R' ) |
|
|
|
|
|
|
Definition at line 1137 of file niml.h. Referenced by NI_copy_struct(), and NI_free_struct(). |
|
|
Definition at line 406 of file niml.h. Referenced by NI_set_typename_mode(). |
|
|
|
|
|
|
|
|
Definition at line 394 of file niml.h. Referenced by main(), NI_read_columns(), NI_read_element(), NI_write_columns(), and NI_write_element(). |
|
|
Value: int type ; \ int nref ; \ char *idcode ; \ char *name
|
|
|
|
Size of NI_stream buffer. Definition at line 327 of file niml.h. Referenced by AFNI_niml_workproc(), NI_stream_open(), and THD_read_niml_atr(). |
|
|
|
Definition at line 1112 of file niml.h. Referenced by NI_copy_struct(), and NI_free_struct(). |
|
|
|
|
|
Definition at line 74 of file niml.h. Referenced by decode_type_field(), NI_set_vector_range(), NI_swap_column(), NI_text_to_val(), NI_val_to_text(), and setup_basic_types(). |
|
|
|
|
|
Definition at line 1117 of file niml.h. Referenced by NI_copy_struct(), and NI_free_struct(). |
|
|
Definition at line 1109 of file niml.h. Referenced by NI_copy_struct(), NI_dataset_transpose(), and NI_free_struct(). |
|
|
Definition at line 1095 of file niml.h. Referenced by NI_dataset_transpose(). |
|
|
Definition at line 1092 of file niml.h. Referenced by NI_copy_struct(), NI_dataset_transpose(), and NI_free_struct(). |
|
|
Definition at line 1142 of file niml.h. Referenced by NI_copy_struct(), NI_dataset_transpose(), NI_new_vector(), and NI_set_vector_range(). |
|
|
|
|
|
Value: do{ int pp ; \ for( pp=0 ; pp < (sar)->num ; pp++ ) \ NI_free( (sar)->str[pp] ); \ NI_free((sar)->str) ; NI_free(sar) ; \ } while(0) Definition at line 1155 of file niml.h. Referenced by basis_parser(), make_empty_data_element(), mri_1D_fromstring(), NI_rowtype_define(), SYM_expand_ranges(), THD_datablock_from_atr(), THD_load_tcat(), THD_open_3D(), and THD_open_tcat(). |
|
|
Definition at line 72 of file niml.h. Referenced by decode_type_field(), matrix_to_niml(), NI_set_vector_range(), NI_swap_column(), NI_text_to_val(), NI_val_to_text(), niml_to_matrix(), setup_basic_types(), SUMA_AddDsetNelCol(), SUMA_AddNelCol(), SUMA_Copy_Part_Column(), SUMA_FillDsetNelCol(), SUMA_FillNelCol(), and SUMA_oDsetNel2nDsetNgr(). |
|
|
Definition at line 1116 of file niml.h. Referenced by NI_copy_struct(), and NI_free_struct(). |
|
|
|
Definition at line 377 of file niml.h. Referenced by NI_stream_close_keep(), NI_stream_goodcheck(), NI_stream_open(), NI_stream_read(), NI_stream_readcheck(), NI_stream_setbufsize(), NI_stream_write(), and NI_stream_writecheck(). |
|
|
Definition at line 374 of file niml.h. Referenced by NI_stream_close_keep(), NI_stream_goodcheck(), NI_stream_open(), NI_stream_read(), NI_stream_readcheck(), NI_stream_seek(), NI_stream_setbufsize(), NI_stream_write(), and NI_stream_writecheck(). |
|
|
|
|
|
|
|
|
|
Definition at line 1107 of file niml.h. Referenced by NI_copy_struct(), and NI_free_struct(). |
|
|
|
|
|
Definition at line 1115 of file niml.h. Referenced by NI_copy_struct(), and NI_free_struct(). |
|
|
Free and set pointer to NULL. |
|
|
|
|
Definition at line 396 of file niml.h. Referenced by NI_write_element(), and NIML_to_stderr(). |
|
|
Definition at line 397 of file niml.h. Referenced by main(), NI_write_element(), NIML_to_stderr(), SUMA_FakeIt(), SUMA_SaveVisualState(), SUMA_SendToSuma(), and SUMA_Write_DrawnROI_NIML(). |
|
|
|
|
|
Definition at line 387 of file niml.h. Referenced by NI_stream_goodcheck(), NI_stream_open(), NI_stream_readable(), NI_stream_setbuf(), and NI_stream_setbufsize(). |
|
|
|
Definition at line 1114 of file niml.h. Referenced by NI_copy_struct(), and NI_free_struct(). |
|
|
|
|
|
|
|
|
Definition at line 99 of file niml.h. Referenced by NI_new_vector(), and NI_set_vector_range(). |
|
|
|
|
|
Definition at line 543 of file niml.h. Referenced by NI_malloc_dump(). |
|
|
Definition at line 78 of file niml.h. Referenced by THD_open_3D(). |
|
|
Definition at line 1122 of file niml.h. Referenced by NI_set_vector_range(). |
|
|
Definition at line 399 of file niml.h. Referenced by NI_byteorder(), NI_read_element(), NI_write_element(), and THD_write_1D(). |
|
|
Definition at line 633 of file niml.h. Referenced by NI_read_columns(), and NI_read_element(). |
|
|
|
Definition at line 400 of file niml.h. Referenced by NI_byteorder(), and NI_read_element(). |
|
|
Definition at line 413 of file niml.h. Referenced by NI_type_name(). |
|
|
|
|
|
Definition at line 412 of file niml.h. Referenced by NI_set_typename_mode(). |
|
|
Make a new block of a given type. Definition at line 531 of file niml.h. Referenced by NI_dataset_transpose(), NI_new_vector(), NI_rowtype_define(), and setup_basic_types(). |
|
|
|
|
|
Number of types of fixed size ("basic" types). Note that if this changes, the NI_rowtype stuff must be altered accordingly. Definition at line 90 of file niml.h. Referenced by NI_rowtype_code_to_alias(), NI_rowtype_find_name(), and setup_basic_types(). |
|
|
One more than the last NI_ data type code defined above. |
|
|
Definition at line 1098 of file niml.h. Referenced by NI_dataset_transpose(). |
|
|
Definition at line 388 of file niml.h. Referenced by NI_stream_clearbuf(), NI_stream_close_keep(), NI_stream_getbuf(), NI_stream_open(), NI_stream_read(), NI_stream_readcheck(), NI_stream_writeable(), and NI_stream_writecheck(). |
|
|
Value: do{ if( NI_is_vector_type((nn)->type) && \ NI_is_builtin_type((nn)->vec_typ) ) \ (nn)->type = NI_VECTOR_TYPE + (nn)->vec_typ + 1 ; \ } while(0) |
|
|
Definition at line 1132 of file niml.h. Referenced by NI_copy_struct(), and NI_free_struct(). |
|
|
Definition at line 192 of file niml.h. Referenced by AFNI_niml_workproc(), AFNI_process_NIML_data(), main(), NI_element_name(), NI_element_type(), NI_free_element(), NI_get_attribute(), NI_new_processing_instruction(), NI_read_element(), NI_set_attribute(), and NI_write_element(). |
|
|
|
Definition at line 1131 of file niml.h. Referenced by NI_copy_struct(), and NI_free_struct(). |
|
|
Definition at line 376 of file niml.h. Referenced by NI_stream_close_keep(), NI_stream_fillbuf(), NI_stream_goodcheck(), NI_stream_open(), NI_stream_read(), NI_stream_readbuf(), NI_stream_readcheck(), NI_stream_write(), and NI_stream_writecheck(). |
|
|
Definition at line 75 of file niml.h. Referenced by decode_type_field(), NI_set_vector_range(), NI_swap_column(), NI_text_to_val(), NI_val_to_text(), and setup_basic_types(). |
|
|
Definition at line 1118 of file niml.h. Referenced by NI_copy_struct(), and NI_free_struct(). |
|
|
Definition at line 76 of file niml.h. Referenced by decode_type_field(), NI_set_vector_range(), NI_swap_column(), NI_text_to_val(), NI_val_to_text(), and setup_basic_types(). |
|
|
Definition at line 1119 of file niml.h. Referenced by NI_copy_struct(), and NI_free_struct(). |
|
|
Definition at line 378 of file niml.h. Referenced by NI_stream_close_keep(), NI_stream_goodcheck(), NI_stream_open(), NI_stream_read(), NI_stream_readable(), NI_stream_readcheck(), NI_stream_setbufsize(), NI_stream_write(), NI_stream_writeable(), and NI_stream_writecheck(). |
|
|
Definition at line 67 of file niml.h. Referenced by decode_type_field(), NI_set_vector_range(), NI_swap_column(), NI_text_to_val(), NI_val_to_text(), setup_basic_types(), and SUMA_Copy_Part_Column(). |
|
|
Definition at line 1113 of file niml.h. Referenced by NI_copy_struct(), and NI_free_struct(). |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Parameters * |
|
|
|
|
|
Definition at line 788 of file niml.h. Referenced by NI_stat_decode(), and THD_open_3D(). |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Definition at line 789 of file niml.h. Referenced by NI_stat_decode(), NI_stat_distname(), NI_stat_encode(), NI_stat_numparam(), and THD_open_3D(). |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Value: ( ((nd)->param[i]->type == NI_FLOAT_ONE_TYPE) \ ? ( ((NI_float_one *)(nd)->param[i])->val ) \ : ( ((NI_float_vector *)(nd)->param[i])->vec[j] ) ) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Definition at line 1108 of file niml.h. Referenced by NI_copy_struct(), and NI_free_struct(). |
|
|
Close a NI_stream, and set the pointer to NULL. |
|
|
|
Definition at line 375 of file niml.h. Referenced by NI_stream_clearbuf(), NI_stream_close_keep(), NI_stream_fillbuf(), NI_stream_getbuf(), NI_stream_goodcheck(), NI_stream_open(), NI_stream_read(), NI_stream_readbuf(), NI_stream_readcheck(), NI_stream_setbuf(), NI_stream_setbufsize(), NI_stream_write(), NI_stream_writecheck(), NI_write_columns(), and NI_write_element(). |
|
|
Definition at line 1120 of file niml.h. Referenced by NI_copy_struct(), and NI_free_struct(). |
|
|
Definition at line 1106 of file niml.h. Referenced by NI_copy_struct(), and NI_free_struct(). |
|
|
Definition at line 632 of file niml.h. Referenced by NI_read_columns(), and NI_read_element(). |
|
|
Definition at line 373 of file niml.h. Referenced by NI_stream_close_keep(), NI_stream_goodcheck(), NI_stream_open(), NI_stream_read(), NI_stream_readable(), NI_stream_readcheck(), NI_stream_reopen(), NI_stream_setbufsize(), NI_stream_write(), NI_stream_writeable(), NI_stream_writecheck(), and tcp_sigurg_handler(). |
|
|
|
Definition at line 1111 of file niml.h. Referenced by NI_copy_struct(), NI_free_struct(), and NI_new_vector(). |
|
|
Definition at line 32 of file niml.h. Referenced by AGNI_nod_to_NIML_row(), AGNI_nod_to_NIML_rows(), NIML_to_AGNI_nod(), ply_describe_other_elements(), ply_get_other_element(), and setup_basic_types(). |
|
|
Used to test if a rowtype code is a basic type. |
|
|
Check if a NI_rowtype struct is marked as having variable size data Definition at line 141 of file niml.h. Referenced by NI_base64_to_val(), NI_binary_to_val(), NI_copy_column(), NI_free_column(), NI_insert_value(), NI_read_columns(), NI_rowtype_define(), NI_rowtype_vsize(), NI_size_column(), NI_text_to_val(), NI_val_to_binary(), NI_write_columns(), and SUMA_MaskedCopyofDset(). |
|
|
Get the dimension of the qq-th part of the struct stored at pointer pt, of type rt. This macro should only be used if rt->part_dim[qq] >= 0. Definition at line 147 of file niml.h. Referenced by NI_base64_to_val(), NI_binary_to_val(), NI_copy_column(), NI_insert_value(), NI_rowtype_vsize(), NI_swap_column(), NI_text_to_val(), and NI_write_columns(). |
|
|
NI_rowtype bit flag for variable size data. Definition at line 137 of file niml.h. Referenced by NI_rowtype_define(), and setup_basic_types(). |
|
|
Definition at line 271 of file niml.h. Referenced by SHM_init(), SHM_readcheck(), SHM_recv(), SHM_send(), and SHM_writecheck(). |
|
|
Definition at line 278 of file niml.h. Referenced by SHM_fill_accept(), and SHM_init(). |
|
|
Definition at line 281 of file niml.h. Referenced by SHM_fill_accept(), and SHM_init(). |
|
|
Definition at line 277 of file niml.h. Referenced by SHM_fill_accept(), and SHM_init(). |
|
|
Definition at line 280 of file niml.h. Referenced by SHM_fill_accept(), and SHM_init(). |
|
|
Definition at line 270 of file niml.h. Referenced by SHM_init(), SHM_readcheck(), SHM_recv(), SHM_send(), and SHM_writecheck(). |
|
|
Definition at line 273 of file niml.h. Referenced by SHM_init(). |
|
|
Definition at line 275 of file niml.h. Referenced by SHM_fill_accept(), and SHM_init(). |
|
|
Definition at line 268 of file niml.h. Referenced by SHM_close(), SHM_fill_accept(), and SHM_goodcheck(). |
|
|
Definition at line 276 of file niml.h. Referenced by SHM_fill_accept(), and SHM_init(). |
|
|
Definition at line 279 of file niml.h. Referenced by SHM_fill_accept(), and SHM_init(). |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Typedef Documentation
|
|
|
|
|
Definition at line 683 of file niml.h. Referenced by NI_copy_struct(), NI_dataset_transpose(), NI_free_struct(), NI_new_vector(), and NI_set_vector_range(). |
|
|
Definition at line 1197 of file niml.h. Referenced by NI_register_objconverters(). |
|
|
|
|
|
Opaque type for the C API. |
|
|
Definition at line 1146 of file niml.h. Referenced by NI_register_doer(). |
Function Documentation
|
||||||||||||||||
|
Insert string pair str_a,str_b into the Dtable. Copies of the strings are made. ------------------------------------------------------------------- Definition at line 40 of file niml_dtable.c. References addto_Htable(), dt, Dtable::hta, Dtable::htb, and sb. Referenced by DRAW_label_CB(), and Dtable_from_nimlstring().
00041 {
00042 char *sa , *sb ;
00043 if( dt == NULL || str_a == NULL || str_b == NULL ) return ;
00044 sa = strdup(str_a) ; sb = strdup(str_b) ;
00045 addto_Htable( sa , (void *)sb , dt->hta ) ;
00046 addto_Htable( sb , (void *)sa , dt->htb ) ;
00047 return ;
00048 }
|
|
||||||||||||||||
|
Add a string/pointer pair to a hash table.
Definition at line 129 of file niml_htable.c. References calloc, Htable::ctab, free, hashkey(), key, Htable::len, Htable::ntab, Htable::ntot, realloc, removefrom_Htable(), UINT, Htable::vtab, and vtkill. Referenced by addto_Dtable(), NI_register_struct(), NI_registry_add(), NI_registry_malloc(), NI_registry_realloc(), NI_registry_replace(), subsume_Htable(), and THD_init_session().
00130 {
00131 UINT jj ;
00132 int kk , ll=-1 ;
00133 char *key ;
00134
00135 /* check for bad inputs */
00136
00137 if( str == NULL || ht == NULL ) return ;
00138
00139 if( vpt == NULL ){ removefrom_Htable( str , ht ) ; return ; }
00140
00141 jj = hashkey(str) % ht->len ; /* hash table row */
00142
00143 key = strdup(str) ; /* internal key string */
00144
00145 if( ht->vtab[jj] == NULL ){ /* create this row in table */
00146
00147 ht->vtab[jj] = (void **) calloc(3,sizeof(void *)) ;
00148 ht->ctab[jj] = (char **) calloc(3,sizeof(char *)) ;
00149 ht->ntab[jj] = 3 ; /* made 2 extra entries */
00150
00151 ht->vtab[jj][0] = vpt ; /* save pointer */
00152 ht->ctab[jj][0] = key ; /* save key string */
00153 ht->ntot ++ ; /* 1 more in table */
00154
00155 } else { /* search this row */
00156
00157 for( kk=0 ; kk < ht->ntab[jj] ; kk++ ){
00158 if( ht->ctab[jj][kk] == NULL ){ if(ll < 0) ll=kk; } /* add here? */
00159 else if( strcmp(key,ht->ctab[jj][kk]) == 0 ) break ; /* found it? */
00160 }
00161
00162 if( kk == ht->ntab[jj] ){ /* didn't find str in row already */
00163
00164 if( ll >= 0 ){ /* have a NULL slot from scan above */
00165
00166 ht->vtab[jj][ll] = vpt ; /* save ptr */
00167 ht->ctab[jj][ll] = key ; /* save key string */
00168 ht->ntot ++ ; /* 1 more in table */
00169
00170 } else { /* must make row longer */
00171
00172 ht->vtab[jj] = (void **) realloc( ht->vtab[jj] , (kk+3)*sizeof(void *)) ;
00173 ht->ctab[jj] = (char **) realloc( ht->ctab[jj] , (kk+3)*sizeof(char *)) ;
00174 ht->ntab[jj] = kk+3 ;
00175
00176 ht->vtab[jj][kk] = vpt ; /* save ptr */
00177 ht->ctab[jj][kk] = key ; /* save key string */
00178 ht->ntot ++ ; /* 1 more in table */
00179
00180 ht->vtab[jj][kk+1] = ht->vtab[jj][kk+2] = NULL ; /* created 2 extra */
00181 ht->ctab[jj][kk+1] = ht->ctab[jj][kk+2] = NULL ; /* elements above */
00182
00183 }
00184
00185 } else { /* found str in row at index kk */
00186
00187 if( vtkill && ht->vtab[jj][kk] != NULL ) free(ht->vtab[jj][kk]) ;
00188
00189 ht->vtab[jj][kk] = vpt ; /* replace old ptr with new */
00190 free(key) ; /* don't need this */
00191 }
00192 }
00193 }
|
|
|
Set the number of characters to use for end of line: 1 = Unix standard (LF only); 2 = DOS standard (CR LF). ------------------------------------------------------------------------ Definition at line 19 of file niml_b64.c. References ncrlf. Referenced by main().
|
|
|
Set the length of a line of output in base64; ll should be between 16 and 76 (inclusive). Will round down to a multiple of 4. ------------------------------------------------------------------------ Definition at line 31 of file niml_b64.c. References linelen. Referenced by main().
|
|
||||||||||||||||||||
|
Convert binary array to base64 encoding. Inputs: nbin = number of bytes in bin bin = array of binary bytes to encode Outputs: *nb64 = number of base64 bytes [*nb64==0 flags an error] b64 = pointer to newly malloc()-ed space with bytes The output array (*b64) line length can be set by B64_set_linelen(n) where n is from 16 to 76. The default is 72. Note, however, that encoded bytes will always be written out in groups of 4. The output array line separator can be the LF character only (Unix) or the CR-LF combination (DOS, etc.). This is controlled by B64_set_crlf(n) where n=1 for LF, n=2 for CR LF. The default is LF. The output array will be terminated with a line separator. If you call B64_set_crlf(0) then this will toggle the use of line separators. There will be no ASCII NUL character at the end of *b64 -- that is, the output is not a C string. Example:
Definition at line 177 of file niml_b64.c.
00178 {
00179 int ii,jj , nn,n3 ;
00180 byte a,b,c , w,x,y,z ;
00181
00182 /*- sanity checks -*/
00183
00184 if( nb64 == NULL || b64 == NULL ) return ;
00185 if( nbin <= 0 || bin == NULL ){ *nb64 = 0 ; *b64 = NULL ; return ; }
00186
00187 /* calculate size of output (3 bytes in -> 4 bytes out, plus EOL */
00188
00189 nn = (int)((4.0*(linelen+ncrlf+1.0)/(3.0*linelen))*nbin + 256.0) ;
00190 *b64 = (byte *) malloc(sizeof(byte)*nn) ;
00191 if( *b64 == NULL ){ *nb64 = 0 ; return ; } /* this is bad */
00192
00193 /*- do blocks of 3 bytes in -*/
00194
00195 load_encode_table() ;
00196 n3 = (nbin/3)*3 ;
00197 for( nn=jj=ii=0 ; ii < n3 ; ){
00198
00199 /* encode next 3 bytes to 4 outputs */
00200
00201 a = bin[ii++] ; b = bin[ii++] ; c = bin[ii++] ;
00202 B64_encode3(a,b,c,w,x,y,z) ;
00203 (*b64)[jj++] = w ;
00204 (*b64)[jj++] = x ;
00205 (*b64)[jj++] = y ;
00206 (*b64)[jj++] = z ;
00207
00208 /* if we past the line length, add the EOL stuff */
00209
00210 if( !nocrlf ){
00211 nn += 4 ; if( nn >= linelen ){
00212 if( ncrlf == 2 ) (*b64)[jj++] = B64_EOL1 ;
00213 (*b64)[jj++] = B64_EOL2 ;
00214 nn = 0 ;
00215 }
00216 }
00217 }
00218
00219 /*- do the leftover data, if any (1 or 2 bytes) -*/
00220
00221 if( ii < nbin ){
00222 if( ii == nbin-2 )
00223 B64_encode2(bin[ii],bin[ii+1],w,x,y,z) ;
00224 else
00225 B64_encode1(bin[ii],w,x,y,z) ;
00226
00227 (*b64)[jj++] = w ;
00228 (*b64)[jj++] = x ;
00229 (*b64)[jj++] = y ;
00230 (*b64)[jj++] = z ; nn += 4 ;
00231 }
00232
00233 /* if any output bytes are left, add EOL */
00234
00235 if( nn > 0 && !nocrlf ){
00236 if( ncrlf == 2 ) (*b64)[jj++] = B64_EOL1 ;
00237 (*b64)[jj++] = B64_EOL2 ;
00238 }
00239
00240 /* resize output array to be exact fit */
00241
00242 *b64 = (byte *) realloc( *b64 , sizeof(byte)*jj ) ;
00243 *nb64 = jj ;
00244 return ;
00245 }
|
|
||||||||||||||||||||
|
Convert base64-encoded array to a binary array (decoding). Inputs:
Definition at line 92 of file niml_b64.c. References a, B64_decode4, B64_decode_count, B64_goodchar, byte, c, load_decode_table(), malloc, and realloc. Referenced by main().
00093 {
00094 int ii,jj , nn ;
00095 byte a,b,c , w,x,y,z ;
00096
00097 /*- sanity checks -*/
00098
00099 if( nbin == NULL || bin == NULL ) return ;
00100
00101 if( nb64 < 4 || b64 == NULL ){ *nbin = 0 ; *bin = NULL ; return ; }
00102
00103 *bin = (byte *) malloc(sizeof(byte)*(2+3*nb64/4)) ;
00104 if( *bin == NULL ){ *nbin = 0 ; return ; }
00105
00106 /*- some work -*/
00107
00108 load_decode_table() ;
00109 for( ii=jj=0 ; ii < nb64 ; ){ /* scan inputs, skipping bad characters */
00110
00111 /* get next 4 characters (use '=' if we hit the end early) */
00112
00113 w = b64[ii++] ;
00114 while( !B64_goodchar(w) && ii < nb64 ) w = b64[ii++] ;
00115 x = (ii < nb64) ? b64[ii++] : '=' ;
00116 while( !B64_goodchar(x) && ii < nb64 ) x = b64[ii++] ;
00117 y = (ii < nb64) ? b64[ii++] : '=' ;
00118 while( !B64_goodchar(y) && ii < nb64 ) y = b64[ii++] ;
00119 z = (ii < nb64) ? b64[ii++] : '=' ;
00120 while( !B64_goodchar(z) && ii < nb64 ) z = b64[ii++] ;
00121
00122 B64_decode4(w,x,y,z,a,b,c) ; /* decode 4 bytes into 3 */
00123
00124 if( z == '=' ){ /* got to the end? */
00125 nn = B64_decode_count(w,x,y,z) ; /* see how many to save */
00126 if( nn > 0 ) (*bin)[jj++] = a ;
00127 if( nn > 1 ) (*bin)[jj++] = b ;
00128 break ; /* end of decoding loop */
00129 }
00130
00131 /* not at the end => save all 3 outputs, loop back */
00132
00133 (*bin)[jj++] = a ; (*bin)[jj++] = b ; (*bin)[jj++] = c ;
00134 }
00135
00136 /* resize output array to be exact fit */
00137
00138 *bin = (byte *) realloc( *bin , sizeof(byte)*jj ) ;
00139 *nbin = jj ;
00140 return ;
00141 }
|
|
|
Death and destruction of a Dtable. ------------------------------------------------------------------- Definition at line 25 of file niml_dtable.c. References destroy_Htable(), dt, Dtable::hta, Htable_set_vtkill(), and Dtable::htb. Referenced by DRAW_finalize_dset_CB(), DRAW_label_getfile(), and DRAW_main().
00026 {
00027 if( dt == NULL ) return ;
00028 Htable_set_vtkill(1) ;
00029 destroy_Htable( dt->hta ) ;
00030 destroy_Htable( dt->htb ) ;
00031 Htable_set_vtkill(0) ; ;
00032 return ;
00033 }
|
|
|
Delete a Htable forever. ----------------------------------------------------------- Definition at line 65 of file niml_htable.c. References Htable::ctab, free, Htable::len, Htable::ntab, and Htable::vtab. Referenced by AFNI_finalize_read_sess_CB(), AFNI_read_inputs(), AFNI_rescan_session_NEW(), AFNI_rescan_session_OLD(), and destroy_Dtable().
00066 {
00067 int jj , kk ;
00068
00069 if( ht == NULL ) return ;
00070
00071 for( jj=0 ; jj < ht->len ; jj++ ){
00072 if( ht->vtab[jj] != NULL ){
00073 if( vtkill ){
00074 for( kk=0 ; kk < ht->ntab[jj] ; kk++ )
00075 if( ht->vtab[jj][kk] != NULL ) free(ht->vtab[jj][kk]) ;
00076 }
00077 free(ht->vtab[jj]) ;
00078 }
00079 if( ht->ctab[jj] != NULL ){
00080 for( kk=0 ; kk < ht->ntab[jj] ; kk++ )
00081 if( ht->ctab[jj][kk] != NULL ) free(ht->ctab[jj][kk]) ;
00082 free(ht->ctab[jj]) ;
00083 }
00084 }
00085 free(ht->vtab) ; free(ht->ctab) ; free(ht->ntab) ; free(ht) ;
00086 return ;
00087 }
|
|
|
|
|
||||||||||||
|
|
|
||||||||||||
|
|
|
|
Definition at line 164 of file niml_dtable.c. References addto_Dtable(), dt, l, new_Dtable(), NI_element_type(), NI_ELEMENT_TYPE, NI_free_element(), NI_read_element(), NI_stream_close(), NI_stream_open(), NI_stream_setbuf(), NI_STRING, NI_element::vec, NI_element::vec_filled, NI_element::vec_len, NI_element::vec_num, and NI_element::vec_typ. Referenced by DRAW_finalize_dset_CB(), and DRAW_label_getfile().
00165 {
00166 NI_stream ns ;
00167 NI_element *nel ;
00168 int nn , ii ;
00169 Dtable *dt ;
00170 char **la , **lb ;
00171
00172 if( nstr == NULL || *nstr == '\0' ) return NULL ;
00173
00174 /* convert string to a NIML element */
00175
00176 ns = NI_stream_open( "str:" , "r" ) ;
00177 NI_stream_setbuf( ns , nstr ) ;
00178 nel = (NI_element *)NI_read_element( ns , 1 ) ;
00179 NI_stream_close( ns ) ;
00180 if( nel == NULL ) return NULL ;
00181
00182 /* see if element is OK for this purpose */
00183
00184 if( NI_element_type(nel) != NI_ELEMENT_TYPE ){
00185 NI_free_element(nel) ; return NULL ;
00186 }
00187
00188 if( nel->vec_len < 1 || /* empty element? */
00189 nel->vec_filled < 1 || /* no data was filled in? */
00190 nel->vec_num < 2 || /* less than 4 columns? */
00191 nel->vec_typ[0] != NI_STRING || /* must be String, String */
00192 nel->vec_typ[1] != NI_STRING ){
00193
00194 NI_free_element(nel) ; return NULL ;
00195 }
00196
00197 la = (char **) nel->vec[0] ; /* first column of String */
00198 lb = (char **) nel->vec[1] ; /* second column of String */
00199
00200 nn = nel->vec_filled ;
00201 ii = rint(sqrt(2*nn+1.0l)) ;
00202 if( ii < 7 ) ii = 7 ; else if( ii%2 == 0 ) ii++ ;
00203
00204 /* make table, insert strings */
00205
00206 dt = new_Dtable( ii ) ;
00207 for( ii=0 ; ii < nn ; ii++ )
00208 addto_Dtable( la[ii] , lb[ii] , dt ) ;
00209
00210 NI_free_element(nel) ; return dt ;
00211 }
|
|
||||||||||||
|
Definition at line 134 of file niml_dtable.c. References dt, free, listize_Dtable(), name, NI_add_column(), NI_free_element(), NI_new_data_element(), NI_stream_close(), NI_stream_getbuf(), NI_stream_open(), NI_STRING, NI_TEXT_MODE, and NI_write_element(). Referenced by DRAW_attach_dtable(), and dump_vallab().
00135 {
00136 int nn , ii ;
00137 char **la , **lb , *stout ;
00138 NI_element *nel ;
00139 NI_stream ns ;
00140
00141 nn = listize_Dtable( dt , &la , &lb ) ;
00142 if( nn == 0 || la == NULL || lb == NULL ) return (char *)NULL ;
00143
00144 if( name == NULL || *name == '\0' ) name = "Dtable" ;
00145
00146 nel = NI_new_data_element( name , nn ) ;
00147 NI_add_column( nel , NI_STRING , la ) ;
00148 NI_add_column( nel , NI_STRING , lb ) ;
00149 free(la) ; free(lb) ;
00150
00151 ns = NI_stream_open( "str:" , "w" ) ;
00152 (void) NI_write_element( ns , nel , NI_TEXT_MODE ) ;
00153 NI_free_element( nel ) ;
00154 stout = strdup( NI_stream_getbuf(ns) ) ;
00155 NI_stream_close( ns ) ;
00156 nn = strlen(stout) ;
00157 for( ii=nn-1 ; ii > 0 && isspace(stout[ii]) ; ii-- ) ; /* trailing blanks */
00158 stout[ii+1] = '\0' ;
00159 return stout ;
00160 }
|
|
||||||||||||
|
Definition at line 52 of file niml_dtable.c. References dt, findin_Htable(), and Dtable::hta. Referenced by DRAW_label_CB(), and DRAW_set_value_label().
00053 {
00054 if( dt == NULL || str_a == NULL ) return NULL ;
00055 return (char *)findin_Htable( str_a , dt->hta ) ;
00056 }
|
|
||||||||||||
|
Definition at line 60 of file niml_dtable.c. References dt, findin_Htable(), and Dtable::htb. Referenced by DRAW_label_CB().
00061 {
00062 if( dt == NULL || str_b == NULL ) return NULL ;
00063 return (char *)findin_Htable( str_b , dt->htb ) ;
00064 }
|
|
||||||||||||
|
Definition at line 95 of file niml_htable.c. References Htable::ctab, hashkey(), key, Htable::len, Htable::ntab, Htable::ntot, UINT, and Htable::vtab. Referenced by AFNI_find_warp(), findin_Dtable_a(), findin_Dtable_b(), NI_find_struct(), NI_register_struct(), NI_registry_add(), NI_registry_free(), NI_registry_idcode_altername(), NI_registry_idcode_to_len(), NI_registry_idcode_to_name(), NI_registry_idcode_to_ptr(), NI_registry_malloc(), NI_registry_ptr_altername(), NI_registry_ptr_to_idcode(), NI_registry_ptr_to_len(), NI_registry_ptr_to_name(), NI_registry_realloc(), NI_registry_replace(), NI_rowtype_find_name(), removefrom_Dtable_a(), and removefrom_Dtable_b().
00096 {
00097 UINT jj ;
00098 int kk , ntab ;
00099 char *key , **ctab ;
00100 void ***vtab ;
00101
00102 if( str == NULL || ht == NULL || ht->ntot == 0 ) return NULL ;
00103
00104 jj = hashkey(str) % ht->len ; /* hash table row */
00105
00106 vtab = ht->vtab ;
00107
00108 if( vtab[jj] == NULL ) return NULL ; /* nothing there */
00109
00110 key = str ;
00111
00112 ctab = ht->ctab[jj] ; ntab = ht->ntab[jj] ;
00113
00114 for( kk=0 ; kk < ntab ; kk++ ) /* scan for match of key to ctab */
00115 if( ctab[kk] != NULL && strcmp(key,ctab[kk]) == 0 )
00116 return vtab[jj][kk];
00117
00118 return NULL ; /* no match found */
00119 }
|
|
||||||||||||||||
|
Definition at line 623 of file niml_malloc.c. References free, free_track(), NI_dpr(), shift_tracker, use_tracking, and user_free. Referenced by NI_free().
00624 {
00625 NI_mallitem *ip ;
00626
00627 if( fred == NULL ) return ;
00628
00629 if( use_userfunc ) user_free(fred) ;
00630 else if( use_tracking && (ip=shift_tracker(fred)) != NULL ) free_track( ip ) ;
00631 else free( fred ) ;
00632
00633 #ifdef NIML_DEBUG
00634 NI_dpr("hidden_NI_free: called from %s#%d\n",fnam,lnum) ;
00635 #endif
00636
00637 }
|
|
||||||||||||||||
|
Allocate memory (actually uses calloc); calls exit() if it fails. ---------------------------------------------------------------------------- Definition at line 568 of file niml_malloc.c. References calloc, calloc_track(), NI_dpr(), NI_sleep(), p, and user_malloc. Referenced by hidden_NI_realloc().
00569 {
00570 void *p ;
00571
00572 if( use_userfunc ){ p = user_malloc(n); if(p)memset(p,0,n); }
00573 else if( use_tracking ) p = calloc_track(1,n,fnam,lnum) ;
00574 else p = calloc(1,n) ;
00575
00576 if( p == NULL ){
00577 fprintf(stderr,"** ERROR: NI_malloc() fails. Aauugghh!\n") ;
00578 NI_sleep(333); exit(1);
00579 }
00580
00581 #ifdef NIML_DEBUG
00582 NI_dpr("hidden_NI_malloc: called from %s#%d\n",fnam,lnum) ;
00583 #endif
00584
00585 return p ;
00586 }
|
|
||||||||||||||||||||
|
Reallocate memory; calls exit() if it fails. ---------------------------------------------------------------------------- Definition at line 592 of file niml_malloc.c. References hidden_NI_malloc(), NI_dpr(), NI_sleep(), q, realloc, realloc_track(), shift_tracker, use_tracking, and user_realloc.
00593 {
00594 NI_mallitem *ip ;
00595 void *q ;
00596
00597 if( fred == NULL )
00598 return hidden_NI_malloc( n , fnam , lnum ) ;
00599
00600 if( use_userfunc )
00601 q = user_realloc( fred , n ) ;
00602 else if( use_tracking && (ip=shift_tracker(fred)) != NULL )
00603 q = realloc_track( ip , n , fnam,lnum ) ;
00604 else
00605 q = realloc( fred , n ) ;
00606
00607 if( q == NULL && n > 0 ){
00608 fprintf(stderr,"** ERROR: NI_realloc() fails. Ooooogg!\n");
00609 NI_sleep(333); exit(1);
00610 }
00611
00612 #ifdef NIML_DEBUG
00613 NI_dpr("hidden_NI_realloc: called from %s#%d\n",fnam,lnum) ;
00614 #endif
00615
00616 return q ;
00617 }
|
|
|
Definition at line 18 of file niml_htable.c. References vtkill. Referenced by destroy_Dtable().
00018 { vtkill = vt ; }
|
|
||||||||||||||||
|
Definition at line 107 of file niml_dtable.c. References Htable::ctab, dt, Dtable::hta, Htable::len, Htable::ntab, realloc, sb, and Htable::vtab. Referenced by DRAW_label_EV(), and Dtable_to_nimlstring().
00108 {
00109 char **la=NULL , **lb=NULL , *sa,*sb ;
00110 int jj,kk,nn ;
00111 Htable *ht ;
00112
00113 if( dt == NULL || list_a == NULL || list_b == NULL ) return 0 ;
00114
00115 ht = dt->hta ;
00116
00117 for( nn=jj=0 ; jj < ht->len ; jj++ ){
00118 if( ht->vtab[jj] == NULL ) continue ;
00119 for( kk=0 ; kk < ht->ntab[jj] ; kk++ ){
00120 sa = (char *) ht->ctab[jj][kk] ; if( sa == NULL ) continue ;
00121 sb = (char *) ht->vtab[jj][kk] ; if( sb == NULL ) continue ;
00122 la = (char **) realloc( (void *)la , sizeof(char *)*(nn+1) ) ;
00123 lb = (char **) realloc( (void *)lb , sizeof(char *)*(nn+1) ) ;
00124 la[nn] = sa ; lb[nn] = sb ; nn++ ;
00125 }
00126 }
00127 *list_a = la ; *list_b = lb ; return nn ;
00128 }
|
|
||||||||||||
|
Return the MD5 hash of an array as a Base64 string, instead of a hex string. strlen(result) is 22 instead of 32 result is malloc()-ed and should be free()-d when appropriate ------------------------------------------------------------------------------ Definition at line 466 of file niml_md5.c. References MD5_to_B64(), MD5Final(), MD5Init(), and MD5Update(). Referenced by MD5_B64_string().
00467 {
00468 MD5_CTX context;
00469 unsigned char digest[16];
00470
00471 if( n < 0 || bytes == NULL ) return NULL ;
00472
00473 MD5Init( &context ) ;
00474 MD5Update( &context, (unsigned char *)bytes, n ) ;
00475 MD5Final( digest, &context ) ;
00476
00477 return MD5_to_B64( digest ) ;
00478 }
|
|
|
Return the MD5 hash of a file as a Base64 string, instead of a hex string.
Definition at line 500 of file niml_md5.c. References file, MD5_to_B64(), MD5Final(), MD5Init(), and MD5Update().
00501 {
00502 FILE *file;
00503 MD5_CTX context;
00504 int len;
00505 unsigned char buffer[1024] ;
00506 unsigned char digest[16] ;
00507
00508 if( (file=fopen (filename, "rb")) == NULL ) return NULL ;
00509
00510 MD5Init( &context ) ;
00511
00512 while( len = fread(buffer, 1, 1024, file) )
00513 MD5Update( &context, buffer, len ) ;
00514
00515 MD5Final( digest, &context );
00516 fclose (file);
00517
00518 return MD5_to_B64( digest ) ;
00519 }
|
|
|
Return the MD5 hash of a C string as a Base64 string, instead of a hex string. strlen(result) is 22 instead of 32 result is malloc()-ed and should be free()-d when appropriate ------------------------------------------------------------------------------ Definition at line 487 of file niml_md5.c. References MD5_B64_array(). Referenced by UNIQ_hashcode(), and UNIQ_idcode().
00488 {
00489 if( string == NULL ) string = "ElvisTheKing" ;
00490 return MD5_B64_array( strlen(string) , string ) ;
00491 }
|
|
||||||||||||
|
Digest an array and returns the printable string of the result, stored in a malloc()-ed array (length=32+1 bytes). ------------------------------------------------------------------------ Definition at line 372 of file niml_md5.c. References malloc, and MD5_static_array(). Referenced by MD5_malloc_string().
00373 {
00374 char *st , *dy ;
00375 st = MD5_static_array( n , bytes ) ;
00376 if( st == NULL ) return NULL ;
00377 dy = (char *) malloc(33) ; strcpy(dy,st) ; return dy ;
00378 }
|
|
|
Digests a file and prints the result, stored in a malloc()-ed array (length=32+1 bytes). ------------------------------------------------------------------------ Definition at line 433 of file niml_md5.c. References malloc, and MD5_static_file().
00434 {
00435 char *st , *dy ;
00436
00437 st = MD5_static_file( filename ) ;
00438 if( st == NULL ) return NULL ;
00439 dy = (char *) malloc(33) ; strcpy(dy,st) ; return dy ;
00440 }
|
|
|
Digest a C string and returns the printable string of the result, stored in a malloc()-ed array (length=32+1 bytes). ------------------------------------------------------------------------ Definition at line 396 of file niml_md5.c. References MD5_malloc_array().
00397 {
00398 if( string == NULL ) string = "ElvisTheKing" ;
00399 return MD5_malloc_array( strlen(string)+1 , string ) ;
00400 }
|
|
||||||||||||
|
Digest an array and returns the printable string of the result, stored in a static array (length=32+1 bytes). ------------------------------------------------------------------------ Definition at line 353 of file niml_md5.c. References MD5_static_printf(), MD5Final(), MD5Init(), and MD5Update(). Referenced by MD5_malloc_array(), and MD5_static_string().
00354 {
00355 MD5_CTX context;
00356 unsigned char digest[16];
00357
00358 if( n < 0 || bytes == NULL ) return NULL ;
00359
00360 MD5Init( &context ) ;
00361 MD5Update( &context, (unsigned char *)bytes, n ) ;
00362 MD5Final( digest, &context ) ;
00363
00364 return MD5_static_printf(digest) ;
00365 }
|
|
|
Digests a file and prints the result, stored in a static array (length=32+1 bytes). ------------------------------------------------------------------------ Definition at line 407 of file niml_md5.c. References file, MD5_static_printf(), MD5Final(), MD5Init(), and MD5Update(). Referenced by MD5_malloc_file().
00408 {
00409 FILE *file;
00410 MD5_CTX context;
00411 int len;
00412 unsigned char buffer[1024] ;
00413 unsigned char digest[16] ;
00414
00415 if( (file = fopen(filename, "rb")) == NULL ) return NULL ;
00416
00417 MD5Init( &context ) ;
00418
00419 while( len = fread(buffer, 1, 1024, file) )
00420 MD5Update( &context, buffer, len ) ;
00421
00422 MD5Final( digest, &context );
00423 fclose (file);
00424
00425 return MD5_static_printf( digest ) ;
00426 }
|
|
|
Digest a C string and returns the printable string of the result, stored in a static array (length=32+1 bytes). ------------------------------------------------------------------------ Definition at line 385 of file niml_md5.c. References MD5_static_array().
00386 {
00387 if( string == NULL ) string = "ElvisTheKing" ;
00388 return MD5_static_array( strlen(string) , string ) ;
00389 }
|
|
|
Create a Dtable with len slots. ------------------------------------------------------------------- Definition at line 12 of file niml_dtable.c. References calloc, dt, Dtable::hta, Dtable::htb, and new_Htable(). Referenced by DRAW_label_CB(), and Dtable_from_nimlstring().
00013 {
00014 Dtable *dt ;
00015 dt = (Dtable *) calloc( 1 , sizeof(Dtable) ) ;
00016 dt->hta = new_Htable( len ) ;
00017 dt->htb = new_Htable( len ) ;
00018 return dt ;
00019 }
|
|
|
Create a new Htable, with len slots. --------------------------------------------------------- Definition at line 44 of file niml_htable.c. References calloc, Htable::ctab, Htable::len, Htable::ntab, and Htable::vtab. Referenced by AFNI_finalize_read_sess_CB(), AFNI_read_inputs(), AFNI_rescan_session_NEW(), AFNI_rescan_session_OLD(), init_registry(), new_Dtable(), NI_register_struct(), resize_Htable(), setup_basic_types(), and THD_init_session().
00045 {
00046 Htable *ht ;
00047
00048 if( len <= 7 ) len = 7 ; /* smallest allowed */
00049 else if( len%2 == 0 ) len++ ; /* mustn't be even */
00050
00051 ht = (Htable *) calloc( 1 , sizeof(Htable) ) ;
00052
00053 ht->len = len ;
00054 ht->vtab = (void ***) calloc( len , sizeof(void **) ) ;
00055 ht->ctab = (char ***) calloc( len , sizeof(char **) ) ;
00056 ht->ntab = (int *) calloc( len , sizeof(int) ) ;
00057
00058 return ht ;
00059 }
|
|
||||||||||||||||
|
Add a vector (column) of data to a data element.
Definition at line 442 of file niml_element.c. References NI_copy_column(), NI_ELEMENT_TYPE, NI_malloc, NI_realloc, NI_rowtype_find_code(), NI_rowtype::size, typ, NI_element::type, NI_element::vec, NI_element::vec_len, NI_element::vec_num, and NI_element::vec_typ. Referenced by AFNI_niml_redisplay_CB(), AFNI_niml_viewpoint_CB(), AGNI_nod_to_NIML_col(), Dtable_to_nimlstring(), intvec_to_niml(), main(), matrix_to_niml(), mri_to_niml(), NI_add_column_stride(), stringvec_to_niml(), SUMA_FakeIt(), SUMA_ixyz_to_NIML(), SUMA_makeNI_CrossHair(), SUMA_makeNI_SurfIJK(), SUMA_makeNI_SurfINORM(), SUMA_makeNI_SurfIXYZ(), SUMA_Write_DrawnROI_NIML(), symvec_to_niml(), THD_nimlize_dsetatr(), THD_subbrick_to_niml(), and v2s_write_outfile_niml().
00443 {
00444 int nn ;
00445 NI_rowtype *rt ;
00446
00447 /* check for reasonable inputs */
00448
00449 if( nel == NULL || nel->vec_len <= 0 ) return ;
00450 if( nel->type != NI_ELEMENT_TYPE ) return ;
00451 rt = NI_rowtype_find_code(typ) ; if( rt == NULL ) return ;
00452
00453 /* get number of vectors currently in element */
00454
00455 nn = nel->vec_num ;
00456
00457 /* add 1 to the vec_typ array */
00458
00459 nel->vec_typ = NI_realloc( nel->vec_typ, int, sizeof(int)*(nn+1) ) ;
00460 nel->vec_typ[nn] = typ ;
00461
00462 /* add 1 element to the vec array, and copy data into it */
00463
00464 nel->vec = NI_realloc( nel->vec , void*, sizeof(void *)*(nn+1) ) ;
00465 if( arr != NULL )
00466 nel->vec[nn] = NI_copy_column( rt , nel->vec_len , arr ) ;
00467 else
00468 nel->vec[nn] = NI_malloc(void, rt->size * nel->vec_len ) ;
00469
00470 /* add 1 to the count of vectors */
00471
00472 nel->vec_num = nn+1 ;
00473 return ;
00474 }
|
|
||||||||||||||||||||
|
As in NI_add_column(), but adding every stride-th element from arr. Thus, arr should be at least nel->vec_len * stride elements long. -------------------------------------------------------------------------- Definition at line 517 of file niml_element.c. References NI_add_column(), NI_ELEMENT_TYPE, NI_insert_value(), NI_rowtype_find_code(), NI_rowtype::size, stride, typ, NI_element::type, NI_element::vec_len, and NI_element::vec_num. Referenced by SUMA_AddDsetColAttr(), SUMA_AddDsetNelCol(), SUMA_AddGenDsetColAttr(), SUMA_AddNelCol(), SUMA_AddNgrHist(), SUMA_Mesh_IJK2Mesh_IJK_nel(), SUMA_NodeXYZ2NodeXYZ_nel(), and SUMA_oDsetNel2nDsetNgr().
00518 {
00519 int nn , ii ;
00520 NI_rowtype *rt ;
00521 char *idat ;
00522
00523 /* check for reasonable inputs */
00524
00525 if( nel == NULL || nel->vec_len <= 0 ) return ;
00526 if( nel->type != NI_ELEMENT_TYPE ) return ;
00527 rt = NI_rowtype_find_code(typ) ; if( rt == NULL ) return ;
00528
00529 /* add an empty column */
00530
00531 NI_add_column( nel , typ , NULL ) ;
00532 if( arr == NULL ) return ; /* no input data ==> we're done */
00533
00534 /* loop over inputs and put them in one at a time */
00535
00536 nn = nel->vec_num-1 ;
00537 idat = (char *) arr ;
00538
00539 for( ii=0 ; ii < nel->vec_len ; ii++ )
00540 NI_insert_value( nel , ii , nn , idat + (ii*stride*rt->size) ) ;
00541
00542 return ;
00543 }
|
|
||||||||||||
|
Add an element to a group element. ------------------------------------------------------------------------- Definition at line 955 of file niml_element.c. References NI_element_type(), NI_GROUP_TYPE, NI_realloc, NI_group::part, NI_group::part_num, NI_group::part_typ, tt, and NI_group::type. Referenced by main(), NI_read_element(), SUMA_AddDsetColAttr(), SUMA_AddGenDsetColAttr(), SUMA_AddNgrHist(), SUMA_NewDsetGrp(), SUMA_oDsetNel2nDsetNgr(), SUMA_SO2nimlSO(), THD_dataset_to_niml(), and THD_nimlize_dsetatr().
00956 {
00957 int nn , tt=NI_element_type(nini) ;
00958
00959 if( ngr == NULL || ngr->type != NI_GROUP_TYPE || tt < 0 ) return ;
00960
00961 nn = ngr->part_num ;
00962
00963 ngr->part_typ = NI_realloc( ngr->part_typ , int, sizeof(int)*(nn+1) ) ;
00964 ngr->part_typ[nn] = tt ;
00965 ngr->part = NI_realloc( ngr->part , void*, sizeof(void *)*(nn+1) );
00966 ngr->part[nn] = nini ;
00967 ngr->part_num = nn+1 ;
00968 return ;
00969 }
|
|
|
Externally callable routine to add a host to the trusted list. If call with NULL, will just initialize the default trusted host list. ---------------------------------------------------------------------------- Definition at line 675 of file niml_stream.c. References add_trusted_host(), host_num, and init_trusted_list(). Referenced by main(), NI_suck_stream(), and TRUST_addhost().
00676 {
00677 if( host_num == 0 ) init_trusted_list() ;
00678 if( hostname == NULL || hostname[0] == '\0' ) return ;
00679 add_trusted_host(hostname) ;
00680 }
|
|
||||||||||||
|
Change the length of all the columns in a data element.
Definition at line 485 of file niml_element.c. References NI_ELEMENT_TYPE, NI_realloc, NI_rowtype_find_code(), NI_rowtype::size, NI_element::type, NI_element::vec, NI_element::vec_filled, NI_element::vec_len, NI_element::vec_num, and NI_element::vec_typ.
00486 {
00487 int oldlen , ii ;
00488 NI_rowtype *rt ;
00489 char *pt ;
00490
00491 if( nel == NULL || nel->type != NI_ELEMENT_TYPE ) return ;
00492 if( nel->vec_len <= 0 || newlen <= 0 ) return ;
00493
00494 if( nel->vec_num == 0 ){ /* if have no data yet */
00495 nel->vec_len = nel->vec_filled = newlen; return;
00496 }
00497
00498 oldlen = nel->vec_len ; if( oldlen == newlen ) return ;
00499
00500 for( ii=0 ; ii < nel->vec_num ; ii++ ){
00501 rt = NI_rowtype_find_code( nel->vec_typ[ii] ) ;
00502 nel->vec[ii] = NI_realloc( nel->vec[ii] , void , rt->size * newlen ) ;
00503 if( oldlen < newlen ){
00504 pt = ((char *)nel->vec[ii]) + (rt->size * oldlen) ; /* zero fill */
00505 memset( pt , 0 , (newlen-oldlen)*rt->size ) ; /* new data! */
00506 }
00507 }
00508
00509 nel->vec_len = nel->vec_filled = newlen ; return ;
00510 }
|
|
||||||||||||||||||||
|
Decode Base64 data from the NI_stream ns into a rowtype struct *dpt.
Definition at line 1680 of file niml_rowtype.c. References NI_rowtype::code, NI_free, NI_malloc, NI_stream_readbuf64(), NI_STRING, NI_swap4(), NI_rowtype::part_dim, NI_rowtype::part_num, NI_rowtype::part_off, NI_rowtype::part_rtp, NI_rowtype::psiz, ROWTYPE_is_varsize, ROWTYPE_part_dimen, NI_rowtype::size, and swap. Referenced by NI_read_columns().
01681 {
01682 int nn , jj ;
01683
01684 if( rt->code == NI_STRING ) return 0 ; /* shouldn't happen */
01685
01686 if( rt->size == rt->psiz ){ /* fixed-size type with no padding */
01687 /* ==> can read directly into data struct */
01688
01689 jj = NI_stream_readbuf64( ns , (char *)dpt , rt->size ) ;
01690 return (jj == rt->size) ;
01691
01692 } else { /* derived type */
01693
01694 char *dat = (char *)dpt , **aaa = NULL ;
01695 int ii , naaa = 0 , iaaa = 0 ;
01696
01697 if( ROWTYPE_is_varsize(rt) ){ /* variable dim arrays inside */
01698 for( naaa=ii=0 ; ii < rt->part_num ; ii++ )
01699 if( rt->part_dim[ii] >= 0 ) naaa++ ; /* count var dim arrays */
01700 if( naaa > 0 )
01701 aaa = NI_malloc(char*, sizeof(char *)*naaa) ; /* save their addresses */
01702 } /* for possible deletion later */
01703
01704 /* loop over parts and load them;
01705 set nn=0 if read fails at any part (and break out of read loop) */
01706
01707 for( nn=1,ii=0 ; ii < rt->part_num ; ii++ ){
01708
01709 if( rt->part_dim[ii] < 0 ){ /* read one fixed dim part */
01710
01711 nn = NI_base64_to_val( ns, rt->part_rtp[ii], dat+rt->part_off[ii], 0 );
01712
01713 } else { /* read var dim array */
01714
01715 char **apt = (char **)(dat+rt->part_off[ii]); /* data in struct */
01716 /* will be ptr to array */
01717 int dim = ROWTYPE_part_dimen(rt,dat,ii) ; /* dimension of part */
01718 int siz = rt->part_rtp[ii]->size ; /* size of one part */
01719
01720 if( swap ) NI_swap4( 1 , &dim ) ; /* byte-swap dim, which was */
01721 /* just read in a moment ago */
01722
01723 if( dim > 0 ){ /* need to get some data */
01724 *apt = NI_malloc(char, siz * dim ); /* make array */
01725
01726 if( siz != rt->part_rtp[ii]->psiz ){ /* padded values ==> */
01727 for( jj=0 ; jj < dim ; jj++ ){ /* read 1 val at a time */
01728 nn = NI_base64_to_val( ns, rt->part_rtp[ii],
01729 *apt + siz * jj , 0 ) ;
01730 if( !nn ) break ; /* bad read */
01731 }
01732
01733 } else { /* unpadded values ==> read all at once */
01734 jj = NI_stream_readbuf64( ns , *apt , siz*dim ) ;
01735 nn = ( jj == siz*dim ) ;
01736 }
01737
01738 } else {
01739 *apt = NULL ; /* dim=0 ==> no array needed */
01740 }
01741 aaa[iaaa++] = *apt ; /* save for possible deletion */
01742 /* if read fails later in loop */
01743 }
01744
01745 if( !nn ) break ; /* some read was bad */
01746 } /* end of loop over parts */
01747
01748 /* bad news ==> delete any allocated var dim arrays */
01749
01750 if( !nn ){
01751 for( ii=0 ; ii < iaaa ; ii++ ) NI_free( aaa[ii] ) ;
01752 }
01753 NI_free( aaa ) ; /* don't need list of var dim arrays no more */
01754 }
01755
01756 return nn ;
01757 }
|
|
||||||||||||
|
|
|
||||||||||||||||||||
|
Decode binary data from the NI_stream ns into a rowtype struct *dpt.
Definition at line 1591 of file niml_rowtype.c. References NI_rowtype::code, NI_free, NI_malloc, NI_stream_readbuf(), NI_STRING, NI_swap4(), NI_rowtype::part_dim, NI_rowtype::part_num, NI_rowtype::part_off, NI_rowtype::part_rtp, NI_rowtype::psiz, ROWTYPE_is_varsize, ROWTYPE_part_dimen, NI_rowtype::size, and swap. Referenced by NI_read_columns().
01592 {
01593 int nn , jj ;
01594
01595 if( rt->code == NI_STRING ) return 0 ; /* shouldn't happen */
01596
01597 if( rt->size == rt->psiz ){ /* fixed-size type with no padding */
01598 /* ==> can read directly into data struct */
01599
01600 jj = NI_stream_readbuf( ns , (char *)dpt , rt->size ) ;
01601 return (jj == rt->size) ;
01602
01603 } else { /* derived type */
01604
01605 char *dat = (char *)dpt , **aaa = NULL ;
01606 int ii , naaa = 0 , iaaa = 0 ;
01607
01608 if( ROWTYPE_is_varsize(rt) ){ /* variable dim arrays inside */
01609 for( naaa=ii=0 ; ii < rt->part_num ; ii++ )
01610 if( rt->part_dim[ii] >= 0 ) naaa++ ; /* count var dim arrays */
01611 if( naaa > 0 )
01612 aaa = NI_malloc(char*, sizeof(char *)*naaa) ; /* save their addresses */
01613 } /* for possible deletion later */
01614
01615 /* loop over parts and load them;
01616 set nn=0 if read fails at any part (and break out of read loop) */
01617
01618 for( nn=1,ii=0 ; ii < rt->part_num ; ii++ ){
01619
01620 if( rt->part_dim[ii] < 0 ){ /* read one fixed dim part */
01621
01622 nn = NI_binary_to_val( ns, rt->part_rtp[ii], dat+rt->part_off[ii], 0 );
01623
01624 } else { /* read var dim array */
01625
01626 char **apt = (char **)(dat+rt->part_off[ii]); /* data in struct */
01627 /* will be ptr to array */
01628 int dim = ROWTYPE_part_dimen(rt,dat,ii) ; /* dimension of part */
01629 int siz = rt->part_rtp[ii]->size ; /* size of one part */
01630
01631 if( swap ) NI_swap4( 1 , &dim ) ; /* byte-swap dim, which was */
01632 /* just read in a moment ago */
01633
01634 if( dim > 0 ){ /* need to get some data */
01635 *apt = NI_malloc(char, siz * dim ); /* make array */
01636
01637 if( siz != rt->part_rtp[ii]->psiz ){ /* padded values ==> */
01638 for( jj=0 ; jj < dim ; jj++ ){ /* read 1 val at a time */
01639 nn = NI_binary_to_val( ns, rt->part_rtp[ii],
01640 *apt + siz * jj , 0 ) ;
01641 if( !nn ) break ; /* bad read */
01642 }
01643
01644 } else { /* unpadded values ==> read all at once */
01645 jj = NI_stream_readbuf( ns , *apt , siz*dim ) ;
01646 nn = ( jj == siz*dim ) ;
01647 }
01648
01649 } else {
01650 *apt = NULL ; /* dim=0 ==> no array needed */
01651 }
01652 aaa[iaaa++] = *apt ; /* save for possible deletion */
01653 /* if read fails later in loop */
01654 }
01655
01656 if( !nn ) break ; /* some read was bad */
01657 } /* end of loop over parts */
01658
01659 /* bad news ==> delete any allocated var dim arrays */
01660
01661 if( !nn ){
01662 for( ii=0 ; ii < iaaa ; ii++ ) NI_free( aaa[ii] ) ;
01663 }
01664 NI_free( aaa ) ; /* don't need list of var dim arrays no more */
01665 }
01666
01667 return nn ;
01668 }
|
|
|
Find the byte order on this system. Return is either NI_LSB_FIRST or NI_MSB_FIRST. We are assuming that there are only 2 possible order, which is of course false. ----------------------------------------------------------------- Definition at line 14 of file niml_byteorder.c. References NI_LSB_FIRST, and NI_MSB_FIRST. Referenced by NI_read_element(), NI_write_element(), and THD_write_1D().
00015 {
00016 union { unsigned char bb[2] ;
00017 short ss ; } fred ;
00018
00019 fred.bb[0] = 1 ; fred.bb[1] = 0 ;
00020
00021 return (fred.ss == 1) ? NI_LSB_FIRST : NI_MSB_FIRST ;
00022 }
|
|
|
Return time elapsed since first call to this routine (msec). Note this will overflow an int after 24+ days. You probably don't want to use this if the program will be running continuously for such a long time. ----------------------------------------------------------------- Definition at line 62 of file niml_util.c. Referenced by AFNI_faceup(), AFNI_niml_redisplay_CB(), AFNI_niml_workproc(), ISQ_drawing_EV(), main(), mri_warp3d_align_one(), mri_warp3D_align_setup(), NI_read_element(), NI_stream_fillbuf(), NI_suck_stream(), NI_write_columns(), process_NIML_AFNI_dataset(), process_NIML_AFNI_volumedata(), process_NIML_Node_ROI(), process_NIML_SUMA_ijk(), process_NIML_SUMA_ixyz(), process_NIML_SUMA_node_normals(), scan_for_angles(), SHM_goodcheck(), SHM_readcheck(), and SUMA_niml_workproc().
00063 {
00064 struct timeval new_tval ;
00065 struct timezone tzone ;
00066 static struct timeval old_tval ;
00067 static int first = 1 ;
00068
00069 gettimeofday( &new_tval , &tzone ) ;
00070
00071 if( first ){
00072 old_tval = new_tval ;
00073 first = 0 ;
00074 return 0 ;
00075 }
00076
00077 if( old_tval.tv_usec > new_tval.tv_usec ){
00078 new_tval.tv_usec += 1000000 ;
00079 new_tval.tv_sec -- ;
00080 }
00081
00082 return (int)( (new_tval.tv_sec - old_tval.tv_sec )*1000.0
00083 +(new_tval.tv_usec - old_tval.tv_usec)*0.001 + 0.5 ) ;
00084 }
|
|
|
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 }
|
|
|
|
|
||||||||||||||||
|
Copy a column of rowtype structs, including var dim arrays. Return is the pointer to the copy. ------------------------------------------------------------------------------ Definition at line 2042 of file niml_rowtype.c. References NI_malloc, NI_strdup(), NI_STRING, NI_rowtype::part_dim, NI_rowtype::part_num, NI_rowtype::part_off, NI_rowtype::part_rtp, NI_rowtype::part_typ, ROWTYPE_is_varsize, ROWTYPE_part_dimen, and NI_rowtype::size. Referenced by NI_add_column().
02043 {
02044 char *dat=(char *)cpt , *ndat , *nptr , *qpt ;
02045 int ii , jj , kk ;
02046
02047 if( rt == NULL || dat == NULL || col_len < 1 ) return NULL ;
02048
02049 /* make a quick (surface) copy */
02050
02051 ndat = NI_malloc(char, rt->size * col_len ) ; /* new data column */
02052 memcpy( ndat , dat , rt->size * col_len ) ; /* the quick copying */
02053
02054 /* copy any var dim arrays inside, since the pointers
02055 in ndat right now still point to data in dat,
02056 but we want ndat to be entirely self-contained! */
02057
02058 if( ROWTYPE_is_varsize(rt) ){
02059 for( ii=0 ; ii < col_len ; ii++ ){ /* loop over structs */
02060 nptr = ndat + rt->size * ii ; /* ptr to this struct */
02061 for( jj=0 ; jj < rt->part_num ; jj++ ){ /* loop over parts */
02062
02063 if( rt->part_typ[jj] == NI_STRING ){ /* a string part */
02064 char **apt = (char **)(nptr+rt->part_off[jj]) ; /* *apt => data */
02065 qpt = NI_strdup(*apt) ; *apt = qpt ;
02066 } else if( rt->part_dim[jj] >= 0 ){
02067 char **apt = (char **)(nptr+rt->part_off[jj]) ; /* *apt => data */
02068 if( *apt != NULL ){
02069 kk = ROWTYPE_part_dimen(rt,nptr,jj) * rt->part_rtp[jj]->size ;
02070 qpt = NI_malloc(char, kk) ; memcpy(qpt,*apt,kk) ; *apt = qpt ;
02071 }
02072 }
02073 }
02074 }
02075 }
02076
02077 return ndat ;
02078 }
|
|
|
Make a copy of a struct, as opposed to a new reference (which is what NI_pointto_struct() does). ------------------------------------------------------------- Definition at line 218 of file niml_struct.c. References DUPLICATE_STRUCT, NI_AFFINE_3DMAP_TYPE, NI_BYTE_VECTOR_TYPE, NI_COMPLEX_VECTOR_TYPE, NI_DATASET_TYPE, NI_dataset_vecnum, NI_datatype_size, NI_DOUBLE_VECTOR_TYPE, NI_FLOAT_ONE_TYPE, NI_FLOAT_VECTOR_TYPE, NI_index_t, NI_INT_VECTOR_TYPE, NI_malloc, NI_POINTS_DOMAIN_TYPE, NI_RECT_DOMAIN_TYPE, NI_RGB_VECTOR_TYPE, NI_RGBA_VECTOR_TYPE, NI_SHORT_VECTOR_TYPE, NI_STATISTIC_TYPE, NI_strdup(), NI_STRING_VECTOR_TYPE, NI_STRUCT_TYPE, and NI_VECTOR_TYPE.
00219 {
00220 NI_struct *nd = (NI_struct *)ndd ;
00221 NI_struct *ndnew=NULL ;
00222
00223 if( nd == NULL ) return NULL ; /* bad input :-( */
00224
00225 switch( nd->type ){ /* N.B.: there is no default */
00226
00227 case NI_STRUCT_TYPE:{
00228 DUPLICATE_STRUCT(NI_struct) ;
00229 }
00230 break ;
00231
00232 case NI_FLOAT_ONE_TYPE:{
00233 DUPLICATE_STRUCT(NI_float_one) ;
00234 nn->val = qq->val ;
00235 }
00236 break ;
00237
00238 case NI_AFFINE_3DMAP_TYPE:{
00239 DUPLICATE_STRUCT(NI_affine_3dmap) ;
00240 nn->mat[0][0] = qq->mat[0][0]; nn->mat[0][1] = qq->mat[0][1];
00241 nn->mat[0][2] = qq->mat[0][2]; nn->mat[0][3] = qq->mat[0][3];
00242 nn->mat[1][0] = qq->mat[1][0]; nn->mat[1][1] = qq->mat[1][1];
00243 nn->mat[1][2] = qq->mat[1][2]; nn->mat[1][3] = qq->mat[1][3];
00244 nn->mat[2][0] = qq->mat[2][0]; nn->mat[2][1] = qq->mat[2][1];
00245 nn->mat[2][2] = qq->mat[2][2]; nn->mat[2][3] = qq->mat[2][3];
00246 nn->mat[3][0] = qq->mat[3][0]; nn->mat[3][1] = qq->mat[3][1];
00247 nn->mat[3][2] = qq->mat[3][2]; nn->mat[3][3] = qq->mat[3][3];
00248 }
00249 break ;
00250
00251 case NI_RECT_DOMAIN_TYPE:{
00252 DUPLICATE_STRUCT(NI_rect_domain) ;
00253 nn->nx = qq->nx; nn->ny = qq->ny; nn->nz = qq->nz; nn->nt = qq->nt;
00254 nn->dx = qq->dx; nn->dy = qq->dy; nn->dz = qq->dz; nn->dt = qq->dt;
00255 nn->xo = qq->xo; nn->yo = qq->yo; nn->zo = qq->zo; nn->to = qq->to;
00256 }
00257 break ;
00258
00259 case NI_STATISTIC_TYPE:{
00260 NI_index_t ii ;
00261 DUPLICATE_STRUCT(NI_statistic) ;
00262 nn->statcode = qq->statcode ;
00263 nn->param_num = qq->param_num ;
00264 if( qq->param != NULL ){
00265 nn->param = NI_malloc(NI_struct*, sizeof(NI_struct *)*nn->param_num) ;
00266 for( ii=0 ; ii < nn->param_num ; ii++ )
00267 nn->param[ii] = (NI_struct *)NI_copy_struct( qq->param[ii] ) ; /* recursion */
00268 } else {
00269 nn->param = NULL ;
00270 }
00271 }
00272 break ;
00273
00274 case NI_VECTOR_TYPE:
00275 case NI_BYTE_VECTOR_TYPE:
00276 case NI_SHORT_VECTOR_TYPE:
00277 case NI_INT_VECTOR_TYPE:
00278 case NI_FLOAT_VECTOR_TYPE:
00279 case NI_DOUBLE_VECTOR_TYPE:
00280 case NI_COMPLEX_VECTOR_TYPE:
00281 case NI_RGB_VECTOR_TYPE:
00282 case NI_RGBA_VECTOR_TYPE:{
00283 NI_index_t ii ;
00284 DUPLICATE_STRUCT(NI_vector) ;
00285 nn->vec_len = qq->vec_len ;
00286 nn->vec_typ = qq->vec_typ ;
00287 if( qq->vec != NULL ){ /* copy array */
00288 ii = nn->vec_len * NI_datatype_size(nn->vec_typ) ;
00289 nn->vec = NI_malloc(void, ii) ;
00290 memcpy( nn->vec , qq->vec , ii ) ;
00291 } else {
00292 nn->vec = NULL ;
00293 }
00294 if( qq->vec_range != NULL ){ /* copy array */
00295 ii = 2 * NI_datatype_size(nn->vec_typ) ;
00296 nn->vec_range = NI_malloc(void, ii) ;
00297 memcpy( nn->vec_range , qq->vec_range , ii ) ;
00298 } else {
00299 nn->vec_range = NULL ;
00300 }
00301 nn->statistic = (NI_statistic *)NI_copy_struct( qq->statistic ) ; /* recursion */
00302 }
00303 break ;
00304
00305 case NI_STRING_VECTOR_TYPE:{
00306 NI_index_t ii ;
00307 DUPLICATE_STRUCT(NI_string_vector) ;
00308 nn->vec_len = qq->vec_len ;
00309 nn->vec_typ = qq->vec_typ ;
00310 if( qq->vec != NULL ){ /* copy array */
00311 nn->vec = NI_malloc(char*, sizeof(char *)*nn->vec_len) ;
00312 for( ii=0 ; ii < nn->vec_len ; ii++ )
00313 nn->vec[ii] = NI_strdup(qq->vec[ii]) ;
00314 } else {
00315 nn->vec = NULL ;
00316 }
00317 nn->vec_range = NULL ; /* string vectors don't use vec_range */
00318 nn->statistic = NULL ;
00319 }
00320 break ;
00321
00322 case NI_POINTS_DOMAIN_TYPE:{
00323 NI_index_t ii ;
00324 DUPLICATE_STRUCT(NI_points_domain) ;
00325 nn->num_node = ii = qq->num_node ;
00326 if( qq->id != NULL ){ /* copy array */
00327 nn->id = NI_malloc(NI_index_t, ii*sizeof(NI_index_t)) ;
00328 memcpy( nn->id , qq->id , ii*sizeof(NI_index_t) ) ;
00329 }
00330 if( qq->x != NULL ){ /* copy array */
00331 nn->x = NI_malloc(float, ii*sizeof(float)) ;
00332 memcpy( nn->x , qq->x , ii*sizeof(float) ) ;
00333 }
00334 if( qq->y != NULL ){ /* copy array */
00335 nn->y = NI_malloc(float, ii*sizeof(float)) ;
00336 memcpy( nn->y , qq->y , ii*sizeof(float) ) ;
00337 }
00338 if( qq->z != NULL ){ /* copy array */
00339 nn->z = NI_malloc(float, ii*sizeof(float)) ;
00340 memcpy( nn->z , qq->z , ii*sizeof(float) ) ;
00341 }
00342 nn->seq = qq->seq; nn->seqbase = qq->seqbase; nn->sorted = qq->sorted;
00343 }
00344 break ;
00345
00346 case NI_DATASET_TYPE:{
00347 DUPLICATE_STRUCT(NI_dataset) ;
00348 nn->num_node = qq->num_node ;
00349 nn->num_val = qq->num_val ;
00350 nn->order = qq->order ;
00351 if( qq->vec != NULL ){
00352 NI_index_t nv , ii ;
00353 nv = NI_dataset_vecnum(nn) ;
00354 nn->vec = NI_malloc(NI_vector*, sizeof(NI_vector *)*nv) ;
00355 for( ii=0 ; ii < nv ; ii++ )
00356 nn->vec[ii] = (NI_vector *)NI_copy_struct( qq->vec[ii] ) ; /* recursion */
00357 } else {
00358 nn->vec = NULL ;
00359 }
00360 nn->domain = (NI_struct *)NI_copy_struct( qq->domain ) ; /* recursion */
00361 }
00362 break ;
00363
00364 }
00365
00366 return (void *)ndnew ;
00367 }
|
|
|
Transpose a dataset, so that rows are columns and vice- versa.
Definition at line 28 of file niml_dataset.c. References COPY_BASIC_STRUCT, NI_dataset::domain, NI_DATASET_TYPE, NI_dataset_veclen, NI_dataset_vecnum, NI_datatype_size, NI_index_t, NI_malloc, NI_new, NI_new_vector(), NI_opposite_order, NI_pointto_struct(), NI_set_vector_range(), NI_strdup(), NI_STRING, NI_dataset::num_node, NI_dataset::num_val, NI_dataset::order, NI_vector::statistic, tt, NI_dataset::vec, NI_vector::vec, and NI_vector::vec_typ.
00029 {
00030 NI_dataset *ndnew , *nd = (NI_dataset *)ndd ;
00031 NI_index_t ii,jj , nvec_old,nvec_new , len_old,len_new ;
00032 int tt , lt ;
00033
00034 if( nd == NULL ||
00035 nd->type != NI_DATASET_TYPE ||
00036 nd->vec == NULL ) return NULL ; /* bad input */
00037
00038 /* check if all columns have same type, etc. */
00039
00040 nvec_old = NI_dataset_vecnum(nd) ;
00041 len_old = NI_dataset_veclen(nd) ;
00042
00043 if( nvec_old <= 0 || len_old <= 0 ) return NULL ;
00044 if( nd->vec[0] == NULL ) return NULL ;
00045 if( nd->vec[0]->statistic != NULL ) return NULL ;
00046
00047 tt = nd->vec[0]->vec_typ ;
00048 lt = NI_datatype_size(tt) ;
00049 for( ii=1 ; ii < nvec_old ; ii++ ){
00050 if( nd->vec[ii] == NULL ) return NULL ;
00051 if( nd->vec[ii]->vec_typ != tt ) return NULL ;
00052 if( nd->vec[ii]->statistic != NULL ) return NULL ;
00053 }
00054
00055 /* create output struct */
00056
00057 ndnew = NI_new(NI_dataset) ;
00058 COPY_BASIC_STRUCT(ndnew,nd) ;
00059 ndnew->num_node = nd->num_node ;
00060 ndnew->num_val = nd->num_val ;
00061 ndnew->order = NI_opposite_order(nd->order) ; /* flipped */
00062 ndnew->domain = (NI_struct *)NI_pointto_struct(nd->domain) ; /* same domain */
00063
00064 /* create new vectors */
00065
00066 nvec_new = NI_dataset_vecnum(ndnew) ;
00067 len_new = NI_dataset_veclen(ndnew) ;
00068
00069 ndnew->vec = NI_malloc(NI_vector*, sizeof(NI_vector *) * nvec_new ) ;
00070 for( ii=0 ; ii < nvec_new ; ii++ )
00071 ndnew->vec[ii] = (NI_vector *)NI_new_vector( tt , len_new ) ;
00072
00073 /* copy data from old vectors to new vectors */
00074
00075 if( tt != NI_STRING ){ /* copy fixed length content */
00076
00077 char *vnew , *vold ;
00078 for( ii=0 ; ii < nvec_new ; ii++ ){
00079 vnew = (char *)ndnew->vec[ii]->vec ;
00080 for( jj=0 ; jj < nvec_old ; jj++ ){
00081 vold = (char *)nd->vec[jj]->vec ;
00082 memcpy( vnew+lt*jj , vold+lt*ii , lt ) ;
00083 }
00084 }
00085
00086 for( ii=0 ; ii < nvec_new ; ii++ )
00087 NI_set_vector_range( ndnew->vec[ii] ) ;
00088
00089 } else { /* duplicate strings */
00090
00091 char **vnew , **vold ;
00092 for( ii=0 ; ii < nvec_new ; ii++ ){
00093 vnew = (char **)ndnew->vec[ii]->vec ;
00094 for( jj=0 ; jj < nvec_old ; jj++ ){
00095 vold = (char **)nd->vec[jj]->vec ;
00096 vnew[jj] = NI_strdup( vold[ii] ) ;
00097 }
00098 }
00099
00100 }
00101
00102 /** done **/
00103
00104 return (void *)ndnew ;
00105 }
|
|
||||||||||||
|
Decode a single string into a bunch of strings, separated by characters from the list in sep.
Definition at line 338 of file niml_header.c. References NI_malloc, NI_realloc, NI_strlen(), NI_str_array::num, and NI_str_array::str. Referenced by basis_parser(), make_empty_data_element(), mri_1D_fromstring(), NI_rowtype_define(), SYM_expand_ranges(), THD_datablock_from_atr(), THD_load_tcat(), THD_open_3D(), and THD_open_tcat().
00339 {
00340 NI_str_array *sar ;
00341 int num , nn,id,jd , lss ;
00342
00343 if( ss == NULL || ss[0] == '\0' ) return NULL ; /* bad input */
00344
00345 if( sep == NULL || sep[0] == '\0' ) sep = "," ; /* default sep */
00346
00347 sar = NI_malloc(NI_str_array, sizeof(NI_str_array)) ; /* create output */
00348 sar->num = 0 ; sar->str = NULL ;
00349
00350 /* scan for sub-strings */
00351
00352 lss = NI_strlen(ss) ;
00353 num = id = 0 ;
00354 while( id < lss ){
00355
00356 /* skip current position ahead over whitespace */
00357
00358 while( id < lss && isspace(ss[id]) ) id++ ;
00359 if( id == lss ) break ; /* ran out of string */
00360
00361 jd = id ; /* save current position (start of new string) */
00362
00363 /* skip ahead until ss[id] is a separator [or a space - 10 Dec 2002] */
00364
00365 while( id < lss && strchr(sep,ss[id]) == NULL && !isspace(ss[id]) ) id++;
00366 if( id == jd ){ id++; continue; } /* is only a separator? */
00367
00368 /* new sub-string runs from ss[jd] to ss[id-1] */
00369
00370 sar->str = NI_realloc( sar->str , char*, sizeof(char *)*(num+1) ) ;
00371
00372 nn = id-jd ; /* length of sub-string */
00373 #if 0
00374 while( nn > 0 && isspace(ss[jd+nn-1]) ) nn-- ; /* clip trailing blanks */
00375 #endif
00376 sar->str[num] = NI_malloc(char, nn+1) ; /* make output string */
00377 if( nn > 0 ) memcpy(sar->str[num],ss+jd,nn) ; /* copy sub-string */
00378 sar->str[num++][nn] = '\0' ; /* terminate output */
00379
00380 id++ ; /* skip separator */
00381 }
00382
00383 sar->num = num ; return sar ;
00384 }
|
|
||||||||||||
|
Carry out an action ordered by a "ni_do" element received on the input stream. Actions we know about:
Definition at line 75 of file niml_do.c. References builtin(), doer_func, doer_num, doer_verb, NI_element::name, NI_ELEMENT_TYPE, NI_free, NI_get_attribute(), NI_rowtype_define(), NI_stream_close_keep(), NI_stream_open(), object, tt, and NI_element::type. Referenced by NI_read_element().
00076 {
00077 char *verb , *object ;
00078 int ii , builtin=0 ;
00079
00080 /*- check inputs for OK-ositiness -*/
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 /* 25 Apr 2005: check for diverse forms of the verb and object attributes */
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 ; /* need a verb; */
00098 /* but not always */
00099 /* need an object */
00100 /*******************************************/
00101 /*---- check for various builtin verbs ----*/
00102 /*******************************************/
00103
00104 if( strcmp(verb,"reopen_this") == 0 ){ /****----- reopen stream ------****/
00105
00106 NI_stream_type *nsnew ;
00107
00108 if( object == NULL || object[0] == '\0' ) return -1 ; /* bad */
00109
00110 nsnew = NI_stream_open( object , "r" ) ; /* open new stream */
00111 if( nsnew == NULL ) return -1 ; /* bad */
00112
00113 NI_stream_close_keep(ns,0) ; /* trash old stream */
00114 *ns = *nsnew; NI_free(nsnew); /* replace old guts */
00115 builtin = 1 ;
00116
00117 } /****------------------------- end reopen --------------------------*****/
00118
00119 else if( strcmp(verb,"close_this") == 0 ){ /****-- close this stream -****/
00120
00121 NI_stream_close_keep(ns,0); /* close and mark as dead */
00122 builtin = 1 ;
00123
00124 } /****------------------------ end close_this ------------------------****/
00125
00126 else if( strcmp(verb,"typedef") == 0 ){ /****-- define a NIML type -****/
00127 /**** [12 Feb 2003] ****/
00128 char tnam[256] , tdef[8200] ;
00129 int tt ;
00130
00131 if( object == NULL || object[0] == '\0' ) return -1 ; /* bad */
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 ; /* bad definition */
00137 builtin = 1 ;
00138
00139 } /****------------------------ end typedef ---------------------------****/
00140
00141 /**************************************************************/
00142 /**** Here, check for user-defined callbacks [12 Feb 2003] ****/
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 /*--- if we get here, we got a verb we don't recognize ---*/
00155
00156 return ((builtin) ? 0 : -1) ;
00157 }
|
|
|
|
|
|
Return the name of a NI element. If the input is bad, returns a NULL pointer. Do not free this pointer! It points to the name string inside the element struct. ------------------------------------------------------------------------- Definition at line 275 of file niml_element.c. References NI_element::name, NI_group::name, NI_procins::name, NI_ELEMENT_TYPE, NI_GROUP_TYPE, NI_PROCINS_TYPE, NI_element::type, NI_group::type, and NI_procins::type. Referenced by NI_search_group_deep(), and NI_search_group_shallow().
00276 {
00277 NI_element *nel = (NI_element *) nini ;
00278 NI_group *ngr = (NI_group *) nini ;
00279 NI_procins *npi = (NI_procins *) nini ;
00280
00281 if( nini == NULL ) return NULL ;
00282
00283 if( nel->type == NI_ELEMENT_TYPE ) return nel->name ;
00284 if( ngr->type == NI_GROUP_TYPE ) return ngr->name ;
00285 if( npi->type == NI_PROCINS_TYPE ) return npi->name ;
00286
00287 return NULL ;
00288 }
|
|
|
|
|
|
Return the type of something that points to a NI element.
Definition at line 254 of file niml_element.c. References NI_ELEMENT_TYPE, NI_GROUP_TYPE, NI_PROCINS_TYPE, NI_element::type, NI_group::type, and NI_procins::type. Referenced by AFNI_niml_workproc(), AFNI_process_NIML_data(), AIVVV_workproc(), Dtable_from_nimlstring(), main(), NI_add_to_group(), NI_free_element(), NI_get_attribute(), NI_search_group_deep(), NI_set_attribute(), NI_suck_stream(), NI_write_element(), niml_to_mri(), NIML_to_stderr(), SUMA_LoadNimlDset(), SUMA_process_NIML_data(), THD_add_bricks(), THD_dblkatr_from_niml(), THD_niml_to_dataset(), THD_open_3D(), THD_open_nifti(), and THD_read_niml_atr().
00255 {
00256 NI_element *nel = (NI_element *) nini ;
00257 NI_group *ngr = (NI_group *) nini ;
00258 NI_procins *npi = (NI_procins *) nini ; /* 16 Mar 2005 */
00259
00260 if( nini == NULL ) return -1 ;
00261
00262 if( nel->type == NI_ELEMENT_TYPE ) return NI_ELEMENT_TYPE ;
00263 if( ngr->type == NI_GROUP_TYPE ) return NI_GROUP_TYPE ;
00264 if( npi->type == NI_PROCINS_TYPE ) return NI_PROCINS_TYPE ;
00265
00266 return -1 ;
00267 }
|
|
|
Return the file length (-1 if file not found). ---------------------------------------------------------------------------- Definition at line 31 of file niml_util.c. Referenced by NI_stream_open(), read_URL_ftp(), read_URL_http(), and THD_read_niml_atr().
00032 {
00033 static struct stat buf ; int ii ;
00034
00035 if( pathname == NULL ) return -1 ;
00036 ii = stat( pathname , &buf ) ; if( ii != 0 ) return -1 ;
00037 return buf.st_size ;
00038 }
|
|
||||||||||||||||||||||||
|
ZSS; Fills an already created column with values up to vec_filled the values in arr are inserted into nel->vec[nn] -------------------------------------------------------------------------- Definition at line 550 of file niml_element.c. References NI_ELEMENT_TYPE, NI_insert_value(), NI_rowtype_find_code(), NI_rowtype::size, stride, typ, NI_element::type, NI_element::vec, NI_element::vec_filled, NI_element::vec_len, NI_element::vec_num, and NI_element::vec_typ. Referenced by SUMA_FillDsetNelCol(), and SUMA_FillNelCol().
00552 {
00553 int ii , nf;
00554 NI_rowtype *rt ;
00555 char *idat ;
00556
00557 /* check for reasonable inputs */
00558
00559 if( nel == NULL || nel->vec_len <= 0 ) return ;
00560 if( nel->type != NI_ELEMENT_TYPE ) return ;
00561 rt = NI_rowtype_find_code(typ) ; if( rt == NULL ) return ;
00562
00563 /* check for NULL column or other similar errors*/
00564
00565 if( arr == NULL ) return ;
00566 if( nel->vec[nn] == NULL ) return ;
00567 if( nn < 0 || nn >= nel->vec_num ) return ;
00568 if( typ != nel->vec_typ[nn] ) return ;
00569
00570 /* loop over inputs and put them in */
00571
00572 if( nel->vec_filled > 0 && nel->vec_filled <= nel->vec_len )
00573 nf = nel->vec_filled ;
00574 else
00575 nf = nel->vec_len ;
00576
00577 idat = (char *) arr ;
00578
00579 for( ii=0 ; ii < nf ; ii++ )
00580 NI_insert_value( nel , ii , nn , idat + (ii*stride*rt->size) ) ;
00581
00582 return ;
00583 }
|
|
|
Find a struct by its idcode. Definition at line 39 of file niml_struct.c. References findin_Htable().
00040 {
00041 void *vp ;
00042 if( idcode == NULL ) return NULL ; /* nothing to do */
00043 vp = findin_Htable( idcode , ni_struct_table ) ;
00044 return vp ;
00045 }
|
|
||||||||||||||||
|
Delete a column of rowtype structs, including any var dim arrays. Assumes everything was allocated with NI_malloc(). After this is called, the cpt argument should be set to NULL. ---------------------------------------------------------------------------- Definition at line 2010 of file niml_rowtype.c. References NI_free, NI_STRING, NI_rowtype::part_dim, NI_rowtype::part_num, NI_rowtype::part_off, NI_rowtype::part_typ, ROWTYPE_is_varsize, and NI_rowtype::size. Referenced by NI_free_element().
02011 {
02012 char *dat=(char *)cpt , *ptr ;
02013 int ii , jj ;
02014
02015 if( rt == NULL || dat == NULL || col_len < 1 ) return ; /* nothing to do */
02016
02017 /* if has variable dim arrays inside, free them */
02018
02019 if( ROWTYPE_is_varsize(rt) ){
02020 for( ii=0 ; ii < col_len ; ii++ ){ /* loop over structs */
02021 ptr = dat + rt->size * ii ; /* pointer to this struct */
02022 for( jj=0 ; jj < rt->part_num ; jj++ ){ /* loop over parts */
02023 if( rt->part_typ[jj] == NI_STRING ||
02024 rt->part_dim[jj] >= 0 ){
02025 char **apt = (char **)(ptr+rt->part_off[jj]) ;
02026 NI_free(*apt) ; *apt = NULL ;
02027 }
02028 }
02029 }
02030 }
02031
02032 /* free the column array itself */
02033
02034 NI_free(cpt) ; return ;
02035 }
|
|
|
|
Decrement the reference counter, and destroy the struct (recursively in some cases) if the counter goes to zero. ------------------------------------------------------------- Definition at line 90 of file niml_struct.c. References DELETE_STRUCT, NI_dataset::domain, NI_points_domain::id, NI_AFFINE_3DMAP_TYPE, NI_BYTE_VECTOR_TYPE, NI_COMPLEX_VECTOR_TYPE, NI_DATASET_TYPE, NI_dataset_vecnum, NI_DOUBLE_VECTOR_TYPE, NI_FLOAT_ONE_TYPE, NI_FLOAT_VECTOR_TYPE, NI_free, NI_index_t, NI_INT_VECTOR_TYPE, NI_POINTS_DOMAIN_TYPE, NI_RECT_DOMAIN_TYPE, NI_RGB_VECTOR_TYPE, NI_RGBA_VECTOR_TYPE, NI_SHORT_VECTOR_TYPE, NI_STATISTIC_TYPE, NI_STRING_VECTOR_TYPE, NI_STRUCT_TYPE, NI_VECTOR_TYPE, NI_statistic::param, NI_statistic::param_num, NI_vector::statistic, NI_vector::vec, NI_string_vector::vec, NI_dataset::vec, NI_string_vector::vec_len, NI_vector::vec_range, NI_points_domain::x, NI_points_domain::y, and NI_points_domain::z.
00091 {
00092 NI_struct *nd = (NI_struct *)ndd ;
00093 if( nd == NULL ) return ;
00094
00095 /* decrementation */
00096
00097 nd->nref -- ;
00098 if( nd->nref > 0 ) return ; /* keep it */
00099
00100 /* OK, blot it from the universe */
00101
00102 switch( nd->type ){ /* N.B.: there is no default */
00103
00104 case NI_STRUCT_TYPE: /* These types have no sub-structs */
00105 case NI_FLOAT_ONE_TYPE: /* or sub-arrays that need deleting */
00106 case NI_AFFINE_3DMAP_TYPE:
00107 case NI_RECT_DOMAIN_TYPE:
00108 DELETE_STRUCT(nd) ;
00109 break ;
00110
00111 case NI_STATISTIC_TYPE:{
00112 NI_statistic *ns = (NI_statistic *)nd ;
00113 NI_index_t ii ;
00114 if( ns->param != NULL ){
00115 for( ii=0 ; ii < ns->param_num ; ii++ )
00116 NI_free_struct( ns->param[ii] ) ; /* recursion */
00117 NI_free(ns->param) ;
00118 }
00119 }
00120 DELETE_STRUCT(nd) ;
00121 break ;
00122
00123 case NI_VECTOR_TYPE:
00124 case NI_BYTE_VECTOR_TYPE:
00125 case NI_SHORT_VECTOR_TYPE:
00126 case NI_INT_VECTOR_TYPE:
00127 case NI_FLOAT_VECTOR_TYPE:
00128 case NI_DOUBLE_VECTOR_TYPE:
00129 case NI_COMPLEX_VECTOR_TYPE:
00130 case NI_RGB_VECTOR_TYPE:
00131 case NI_RGBA_VECTOR_TYPE:{
00132 NI_vector *nv = (NI_vector *)nd ;
00133 NI_free( nv->vec ) ;
00134 NI_free( nv->vec_range ) ;
00135 NI_free( nv->statistic ) ;
00136 }
00137 DELETE_STRUCT(nd) ;
00138 break ;
00139
00140 case NI_STRING_VECTOR_TYPE:{
00141 NI_string_vector *nv = (NI_string_vector *)nd ;
00142 NI_index_t ii ;
00143 if( nv->vec != NULL ){
00144 for( ii=0 ; ii < nv->vec_len ; ii++ )
00145 NI_free( nv->vec[ii] ) ;
00146 NI_free( nv->vec ) ;
00147 }
00148 /* vec_range not used for string vectors */
00149 /* statistic not used for string vectors */
00150 }
00151 DELETE_STRUCT(nd) ;
00152 break ;
00153
00154 case NI_POINTS_DOMAIN_TYPE:{
00155 NI_points_domain *np = (NI_points_domain *)nd ;
00156 NI_free( np->id ) ;
00157 NI_free( np->x ) ;
00158 NI_free( np->y ) ;
00159 NI_free( np->z ) ;
00160 }
00161 DELETE_STRUCT(nd) ;
00162 break ;
00163
00164 case NI_DATASET_TYPE:{
00165 NI_dataset *nn = (NI_dataset *)nd ;
00166 if( nn->vec != NULL ){
00167 NI_index_t nv , ii ;
00168 nv = NI_dataset_vecnum(nn) ;
00169 for( ii=0 ; ii < nv ; ii++ )
00170 NI_free_struct( nn->vec[ii] ) ; /* recursion */
00171 NI_free( nn->vec ) ;
00172 }
00173 NI_free_struct( nn->domain ) ; /* recursion */
00174 }
00175 DELETE_STRUCT(nd) ;
00176 break ;
00177
00178 }
00179
00180 return ;
00181 }
|
|
||||||||||||
|
Get an attribute with the given LHS name. Returns a pointer to the RHS field in the element if the attribute name is found; otherwise returns NULL. If the LHS is found, but the RHS is NULL, returns a pointer to an empty C string ("\0"). Do not free() the result from this function, since it points to the internal field of the element! ------------------------------------------------------------------------- Definition at line 755 of file niml_element.c. References NI_element::attr_lhs, NI_group::attr_lhs, NI_procins::attr_lhs, NI_element::attr_num, NI_group::attr_num, NI_procins::attr_num, NI_element::attr_rhs, NI_group::attr_rhs, NI_procins::attr_rhs, NI_element_type(), NI_ELEMENT_TYPE, NI_GROUP_TYPE, NI_PROCINS_TYPE, and tt. Referenced by AFNI_niml_workproc(), AFNI_start_version_check(), NI_do(), NI_self_idcode(), nifti_set_afni_extension(), niml_to_mri(), process_NIML_AFNI_volumedata(), process_NIML_Node_ROI(), process_NIML_SUMA_ijk(), process_NIML_SUMA_ixyz(), process_NIML_SUMA_node_normals(), SUMA_AddNelHist(), SUMA_ColLabelCopy(), SUMA_DsetColLabelCopy(), SUMA_FakeIt(), SUMA_FindDset(), SUMA_GetColRange(), SUMA_MaskedCopyofDset(), SUMA_Mesh_IJK_nel2Mesh_IJK(), SUMA_niml_workproc(), SUMA_nimlSO2SO(), SUMA_NodeXYZ_nel2NodeXYZ(), SUMA_oDsetNel2nDsetNgr(), SUMA_OpenDrawnROI_NIML(), SUMA_process_NIML_data(), SUMA_sdset_id(), SUMA_sdset_idmdom(), SUMA_TypeOfColNumb(), SUMA_TypeOfDsetColNumb(), SUMA_VolPar_nel2SOVolPar(), THD_add_bricks(), THD_dblkatr_from_niml(), THD_niml_to_dataset(), THD_open_3D(), THD_open_nifti(), and XSAVE_input().
00756 {
00757 int nn , tt=NI_element_type(nini) ;
00758 static char *zorkon = "\0" ;
00759
00760 if( tt < 0 || attname == NULL || attname[0] == '\0' ) return NULL ;
00761
00762 /* input is a data element */
00763
00764 if( tt == NI_ELEMENT_TYPE ){
00765 NI_element *nel = (NI_element *) nini ;
00766
00767 for( nn=0 ; nn < nel->attr_num ; nn++ )
00768 if( strcmp(nel->attr_lhs[nn],attname) == 0 ) break ;
00769
00770 if( nn == nel->attr_num ) return NULL ;
00771
00772 if( nel->attr_rhs[nn] == NULL ) return zorkon ;
00773
00774 return nel->attr_rhs[nn] ;
00775
00776 /* input is a group element */
00777
00778 } else if( tt == NI_GROUP_TYPE ){
00779 NI_group *ngr = (NI_group *) nini ;
00780
00781 for( nn=0 ; nn < ngr->attr_num ; nn++ )
00782 if( strcmp(ngr->attr_lhs[nn],attname) == 0 ) break ;
00783
00784 if( nn == ngr->attr_num ) return NULL ;
00785
00786 if( ngr->attr_rhs[nn] == NULL ) return zorkon ;
00787
00788 return ngr->attr_rhs[nn] ;
00789
00790 /* input is a processing instruction */
00791
00792 } else if( tt == NI_PROCINS_TYPE ){
00793 NI_procins *npi = (NI_procins *) nini ;
00794
00795 for( nn=0 ; nn < npi->attr_num ; nn++ )
00796 if( strcmp(npi->attr_lhs[nn],attname) == 0 ) break ;
00797
00798 if( nn == npi->attr_num ) return NULL ;
00799
00800 if( npi->attr_rhs[nn] == NULL ) return zorkon ;
00801
00802 return npi->attr_rhs[nn] ;
00803 }
00804
00805 return NULL ; /* should never be reached */
00806 }
|
|
|
Return 1 if the type contains a String part, 0 if not. -------------------------------------------------------------------------- Definition at line 1033 of file niml_rowtype.c. References NI_rowtype::code, NI_STRING, NI_rowtype::part_num, NI_rowtype::part_rtp, and ROWTYPE_is_builtin_code. Referenced by NI_read_columns(), NI_write_columns(), and NI_write_element().
01034 {
01035 int ii , jj ;
01036
01037 if( rt == NULL ) return 0 ;
01038
01039 /* test #1: if a NIML builtin type, test if it is String */
01040
01041 if( ROWTYPE_is_builtin_code(rt->code) ) return (rt->code == NI_STRING) ;
01042
01043 /* test the parts */
01044
01045 for( ii=0 ; ii < rt->part_num ; ii++ ){
01046 if( ROWTYPE_is_builtin_code(rt->part_rtp[ii]->code) ){ /* builtin part */
01047 if( rt->part_rtp[ii]->code == NI_STRING ) return 1;
01048 } else { /* derived part */
01049 if( NI_has_String( rt->part_rtp[ii] ) ) return 1; /* recursion */
01050 }
01051 }
01052 return 0 ;
01053 }
|
|
|
Return the Internet address (in 'dot' format, as a string) given the name of the host. If NULL is returned, some error occurrrrred. The string is NI_malloc()-ed, and should be NI_free()-ed when no longer needed. ------------------------------------------------------------------ Definition at line 569 of file niml_stream.c. References NI_strdup(). Referenced by add_trusted_host(), and NI_trust_host().
00570 {
00571 struct hostent *hostp ;
00572 char * iname = NULL , *str ;
00573 int ll ;
00574
00575 if( host == NULL || host[0] == '\0' ) return NULL ;
00576
00577 hostp = gethostbyname(host) ; if( hostp == NULL ) return NULL ;
00578
00579 str = inet_ntoa(*((struct in_addr *)(hostp->h_addr))) ;
00580 if( str == NULL || str[0] == '\0' ) return NULL ;
00581
00582 iname = NI_strdup(str) ; return iname ;
00583 }
|
|
||||||||||||||||||||
|
Definition at line 655 of file niml_element.c. References NI_ELEMENT_TYPE, NI_insert_value(), NI_STRING, NI_element::type, NI_element::vec_len, NI_element::vec_num, and NI_element::vec_typ.
00656 {
00657 if( nel == NULL || str == NULL ) return ;
00658 if( nel->type != NI_ELEMENT_TYPE ) return ;
00659 if( row < 0 || row >= nel->vec_len ) return ;
00660 if( col < 0 || col >= nel->vec_num ) return ;
00661 if( nel->vec_typ[col] != NI_STRING ) return ;
00662
00663 NI_insert_value( nel , row,col , &str ); return ;
00664 }
|
|
||||||||||||||||||||
|
Replace the row-th value in the col-th column of the data element.
Definition at line 607 of file niml_element.c. References NI_ELEMENT_TYPE, NI_malloc, NI_rowtype_find_code(), NI_strdup(), NI_STRING, NI_rowtype::part_dim, NI_rowtype::part_num, NI_rowtype::part_off, NI_rowtype::part_rtp, NI_rowtype::part_typ, ROWTYPE_is_varsize, ROWTYPE_part_dimen, NI_rowtype::size, NI_element::type, NI_element::vec, NI_element::vec_len, NI_element::vec_num, and NI_element::vec_typ. Referenced by NI_add_column_stride(), NI_fill_column_stride(), and NI_insert_string().
00608 {
00609 NI_rowtype *rt ;
00610 char *cdat , *idat=(char *)dat , *qpt ;
00611 int jj , kk ;
00612
00613 /* check for reasonable inputs */
00614
00615 if( nel == NULL || idat == NULL ) return ;
00616 if( nel->type != NI_ELEMENT_TYPE ) return ;
00617 if( nel->vec_len <= 0 ) return ;
00618 if( row < 0 || row >= nel->vec_len ) return ;
00619 if( col < 0 || col >= nel->vec_num ) return ;
00620
00621 rt = NI_rowtype_find_code( nel->vec_typ[col] ) ;
00622 if( rt == NULL ) return ;
00623
00624 cdat = (char *) nel->vec[col] ; /* points to column data */
00625 cdat = cdat + rt->size * row ; /* points to data to alter */
00626
00627 /* shallow copy of input data over data now present */
00628
00629 memcpy( cdat , idat , rt->size ) ;
00630
00631 /* copy any var dim arrays inside */
00632
00633 if( ROWTYPE_is_varsize(rt) ){
00634 for( jj=0 ; jj < rt->part_num ; jj++ ){ /* loop over parts */
00635
00636 if( rt->part_typ[jj] == NI_STRING ){ /* a string part */
00637 char **apt = (char **)(cdat+rt->part_off[jj]) ; /* *apt => data */
00638 qpt = NI_strdup(*apt) ; *apt = qpt ;
00639
00640 } else if( rt->part_dim[jj] >= 0 ){ /* var dim array */
00641 char **apt = (char **)(cdat+rt->part_off[jj]) ; /* *apt => data */
00642 if( *apt != NULL ){
00643 kk = ROWTYPE_part_dimen(rt,cdat,jj) * rt->part_rtp[jj]->size ;
00644 qpt = NI_malloc(char, kk) ; memcpy(qpt,*apt,kk) ; *apt = qpt ;
00645 }
00646 }
00647 }
00648 }
00649
00650 return ;
00651 }
|
|
|
Write a file with lots of info about the current status. ------------------------------------------------------------------- Definition at line 425 of file niml_malloc.c. References free, malloc, nhtab, NI_is_file, NI_malloc_status(), NI_mallitem::pmt, NI_mallitem::pss, qsort_intint(), SLOTS, and use_tracking.
00426 {
00427 int ii,jj,kk ;
00428 char fname[32] , *str ;
00429 FILE *fp = NULL ;
00430 int nptr=0 ;
00431 int *ss , *jk ;
00432
00433 if( ! use_tracking ) return ;
00434
00435 /* find and open an output file */
00436
00437 for( ii=1 ; ii < 1000 ; ii++ ){
00438 sprintf(fname,"NI_malldump.%03d",ii) ;
00439 if( NI_is_file(fname) ) continue ;
00440 fp = fopen( fname , "w" ) ;
00441 if( fp == NULL ){
00442 fprintf(stderr,"** Unable to open file %s for malloc table dump!\n",
00443 fname ) ;
00444 return ;
00445 }
00446 break ;
00447 }
00448
00449 if( fp == NULL ){
00450 fprintf(stderr,"** Attempt to exceed 999 malloc table dump files!\n") ;
00451 return ;
00452 }
00453
00454 /* count number of entries in the hash table */
00455
00456 for( jj=0 ; jj < SLOTS ; jj++ ){
00457 for( kk=0 ; kk < nhtab[jj] ; kk++ ){
00458 if( htab[jj][kk].pmt != NULL ) nptr++ ;
00459 }
00460 }
00461
00462 if( nptr < 1 ){
00463 fprintf(fp ,"--- Nothing is malloc()-ed !? ---\n") ;
00464 fprintf(stderr,"--- Nothing is malloc()-ed !? ---\n") ;
00465 fclose(fp) ;
00466 }
00467
00468 /* setup to sort by serial number */
00469
00470 ss = (int *) malloc(sizeof(int)*nptr) ; /* serial number */
00471 jk = (int *) malloc(sizeof(int)*nptr) ; /* holds combination of jj and kk */
00472
00473 #define JBASE 32768 /* JBASE * SLOTS must be less than max int */
00474
00475 /* scan table for non-NULL entries */
00476
00477 for( ii=jj=0 ; jj < SLOTS ; jj++ ){
00478 for( kk=0 ; kk < nhtab[jj] ; kk++ ){
00479 if( htab[jj][kk].pmt != NULL ){
00480 ss[ii] = htab[jj][kk].pss ; /* save serial number */
00481 jk[ii] = JBASE*jj + kk ; /* save jj and kk */
00482 ii++ ;
00483 }
00484 }
00485 }
00486
00487 qsort_intint( nptr , ss , jk ) ; /* sort by ss, carrying jk along */
00488
00489 /* now print table in serial number order */
00490
00491 fprintf(fp, "MCW Malloc Table Dump:\n"
00492 "serial# size source file line# address hash(j,k)\n"
00493 "------- ---------- -------------------- ----- ---------- ---------\n") ;
00494
00495 for( ii=0 ; ii < nptr ; ii++ ){
00496 jj = jk[ii] / JBASE ; /* retrieve jj and kk */
00497 kk = jk[ii] % JBASE ;
00498 if( htab[jj][kk].pmt != NULL ){
00499 fprintf(fp,"%7u %10u %-20.30s %5d %10p %5d %3d",
00500 htab[jj][kk].pss , (unsigned int)htab[jj][kk].psz ,
00501 htab[jj][kk].pfn , htab[jj][kk].pln , htab[jj][kk].pmt ,
00502 jj,kk ) ;
00503 fprintf(fp,"\n") ;
00504 }
00505 else
00506 fprintf(fp,"*** Error at ii=%d jj=%d kk=%d\n",ii,jj,kk) ;
00507 }
00508
00509 free(ss) ; free(jk) ;
00510
00511 /* and print out the summary line (to the file and screen) */
00512
00513 str = NI_malloc_status() ;
00514 fprintf(fp,"----- Summary: %s\n",str) ;
00515 fclose(fp) ;
00516
00517 fprintf(stderr,"** Malloc table dumped to file %s\n",fname) ;
00518 fprintf(stderr,"** Summary: %s\n",str) ;
00519
00520 return ;
00521 }
|
|
|
Turn on use of the tracking routines. ------------------------------------------------------------------ Definition at line 527 of file niml_malloc.c. References getenv(), malloc, nhtab, ni_mall_used, SLOTS, and use_tracking. Referenced by NI_stream_open().
00528 {
00529 char *str ;
00530
00531 if( use_userfunc ) return ; /* 25 Mar 2003 */
00532 ni_mall_used = 1 ;
00533
00534 if( use_tracking ) return ; /* 05 Nov 2001 */
00535
00536 str = getenv("AFNI_NO_MCW_MALLOC") ;
00537 if( str == NULL )
00538 str = getenv("NIML_MALLOC_DISABLE") ;
00539
00540 use_tracking = 1 ;
00541 if( str!=NULL && ( *str=='y' || *str=='Y') ) use_tracking = 0 ;
00542
00543 if( use_tracking && htab == NULL ){ /* initialize hash table */
00544 int jj ;
00545 htab = (NI_mallitem **) malloc( SLOTS * sizeof(NI_mallitem *) ) ;
00546 nhtab = (int *) malloc( SLOTS * sizeof(int) ) ;
00547 for( jj=0 ; jj < SLOTS ; jj++ ){
00548 htab[jj] = NULL ; nhtab[jj] = 0 ;
00549 }
00550 }
00551
00552 return ;
00553 }
|
|
||||||||||||||||
|
Allow user to replace malloc(), realloc(), and free() functions used in NI_malloc(), NI_realloc(), and NI_free().
Definition at line 31 of file niml_malloc.c. References ni_mall_used, use_userfunc, user_free, user_malloc, and user_realloc.
00033 {
00034
00035 if( ni_mall_used ||
00036 use_userfunc ||
00037 um == NULL ||
00038 ur == NULL ||
00039 uf == NULL ) return 0 ;
00040
00041 user_malloc = um ;
00042 user_realloc = ur ;
00043 user_free = uf ;
00044 use_userfunc = 1 ;
00045 return 1 ;
00046 }
|
|
|
Definition at line 401 of file niml_malloc.c. References nhtab, NI_mallitem::pmt, probe_track(), NI_mallitem::psz, SLOTS, UINT, and use_tracking. Referenced by NI_dpr(), and NI_malloc_dump().
00402 {
00403 static char buf[128] = "\0" ;
00404 int jj,kk , nptr=0 ; size_t nbyt=0 ;
00405
00406 if( ! use_tracking ) return "not enabled" ;
00407
00408 for( jj=0 ; jj < SLOTS ; jj++ ){
00409 for( kk=0 ; kk < nhtab[jj] ; kk++ ){
00410 if( htab[jj][kk].pmt != NULL ){
00411 probe_track( htab[jj]+kk , NULL,0 ) ; /* check for integrity */
00412 nptr++ ; nbyt += htab[jj][kk].psz ;
00413 }
00414 }
00415 }
00416
00417 sprintf(buf,"chunks=%d bytes=%u",nptr,(UINT)nbyt) ;
00418 return buf ;
00419 }
|
|
|
Lets the user check if the tracking routines are in use. ----------------------------------------------------------------- Definition at line 559 of file niml_malloc.c. References use_tracking.
00560 {
00561 return (use_tracking != 0) ;
00562 }
|
|
|
Replacement for mktemp(). Definition at line 89 of file niml_util.c. References UUID_idcode(). Referenced by read_URL_ftp(), and read_URL_http().
00090 {
00091 int nt ; char *xx,*uu ; struct stat buf ;
00092
00093 if( templ == NULL || templ[0] == '\0' ) return NULL ;
00094
00095 nt = strlen(templ) ;
00096 if( nt < 6 ){ templ[0] = '\0'; return NULL; }
00097 xx = templ+(nt-6) ;
00098 if( strcmp(xx,"XXXXXX") != 0 ){ templ[0] = '\0'; return NULL; }
00099
00100 while(1){
00101 uu = UUID_idcode() ;
00102 memcpy( xx , uu , 6 ) ;
00103 nt = stat( templ , &buf ) ;
00104 if( nt != 0 ) return templ ;
00105 }
00106 }
|
|
||||||||||||||||||||
|
Copy nv fixed dim type values in binary format to the wbuf.
Definition at line 1010 of file niml_rowtype.c. References NI_val_to_binary(), NI_rowtype::psiz, and NI_rowtype::size. Referenced by NI_write_columns().
01011 {
01012 int jj=0 ;
01013
01014 if( rt->size == rt->psiz ){ /* fixed dim, unpadded structs */
01015 /* ==> Write all data at once */
01016 jj = nv * rt->size ;
01017 memcpy(wbuf,dpt,jj);
01018
01019 } else if( rt->psiz > 0 ){ /* Derived type is harder: */
01020 /* Write each struct separately */
01021 int ii ;
01022 for( ii=0 ; ii < nv ; ii++ )
01023 jj += NI_val_to_binary( rt , dpt+(ii*rt->size) , wbuf+jj ) ;
01024
01025 }
01026 return jj ;
01027 }
|
|
||||||||||||||||||||
|
Encode nv type values at the end of the text string wbuf. typ must be a fixed dim type code, or NI_STRING. --------------------------------------------------------------------------- Definition at line 967 of file niml_rowtype.c. References NI_val_to_text(), and NI_rowtype::size. Referenced by NI_write_columns().
00968 {
00969 int ii , jj=rt->size ;
00970
00971 for( ii=0 ; ii < nv ; ii++ )
00972 NI_val_to_text( rt , dpt+ii*jj , wbuf ) ;
00973 }
|
|
||||||||||||
|
Create a new data element.
Definition at line 384 of file niml_element.c. References NI_element::attr_lhs, NI_element::attr_num, NI_element::attr_rhs, name, NI_element::name, NI_ELEMENT_TYPE, NI_malloc, NI_strdup(), NI_element::outmode, NI_element::type, NI_element::vec, NI_element::vec_axis_delta, NI_element::vec_axis_label, NI_element::vec_axis_len, NI_element::vec_axis_origin, NI_element::vec_axis_unit, NI_element::vec_filled, NI_element::vec_len, NI_element::vec_num, NI_element::vec_rank, and NI_element::vec_typ. Referenced by AFNI_niml_redisplay_CB(), AFNI_niml_viewpoint_CB(), AFNI_version_check(), AGNI_nod_to_NIML_col(), AGNI_nod_to_NIML_row(), AGNI_nod_to_NIML_rows(), Dtable_to_nimlstring(), DWI_NIML_create_graph(), intvec_to_niml(), main(), matrix_to_niml(), mri_to_niml(), stringvec_to_niml(), SUMA_AddDsetColAttr(), SUMA_AddGenDsetColAttr(), SUMA_AddNgrHist(), SUMA_Engine(), SUMA_FakeIt(), SUMA_ixyz_to_NIML(), SUMA_makeNI_CrossHair(), SUMA_makeNI_SurfIJK(), SUMA_makeNI_SurfINORM(), SUMA_makeNI_SurfIXYZ(), SUMA_NewDsetGrp(), SUMA_NewNel(), SUMA_oDsetNel2nDsetNgr(), SUMA_SendToSuma(), SUMA_Write_DrawnROI_NIML(), symvec_to_niml(), THD_nimlize_dsetatr(), THD_subbrick_to_niml(), v2s_write_outfile_niml(), and XSAVE_output().
00385 {
00386 NI_element *nel ;
00387
00388 if( name == NULL || name[0] == '\0' || veclen < 0 ) return NULL ;
00389
00390 nel = NI_malloc(NI_element, sizeof(NI_element) ) ;
00391
00392 nel->type = NI_ELEMENT_TYPE ; /* mark as being a data element */
00393
00394 nel->outmode = -1 ; /* 29 Mar 2005 */
00395
00396 nel->name = NI_strdup(name) ;
00397 nel->attr_num = 0 ;
00398 nel->attr_lhs = nel->attr_rhs = NULL ; /* no attributes yes */
00399
00400 nel->vec_num = 0 ; /* no vectors yet */
00401 nel->vec_typ = NULL ;
00402 nel->vec = NULL ;
00403
00404 if( veclen == 0 ){ /* empty element */
00405 nel->vec_len = 0 ;
00406 nel->vec_filled = 0 ;
00407 nel->vec_rank = 0 ;
00408 nel->vec_axis_len = NULL ;
00409 } else { /* element with data to */
00410 nel->vec_len = veclen ; /* come via NI_add_column */
00411 nel->vec_filled = veclen ;
00412 nel->vec_rank = 1 ;
00413 nel->vec_axis_len = NI_malloc(int, sizeof(int)) ;
00414 nel->vec_axis_len[0] = veclen ;
00415 }
00416
00417 nel->vec_axis_delta = NULL ;
00418 nel->vec_axis_origin = NULL ;
00419 nel->vec_axis_unit = NULL ;
00420 nel->vec_axis_label = NULL ;
00421
00422 return nel ;
00423 }
|
|
|
Create a new group element. ------------------------------------------------------------------------- Definition at line 930 of file niml_element.c. References NI_group::attr_lhs, NI_group::attr_num, NI_group::attr_rhs, NI_group::name, NI_GROUP_TYPE, NI_malloc, NI_group::outmode, NI_group::part, NI_group::part_num, NI_group::part_typ, and NI_group::type. Referenced by main(), SUMA_NewDsetGrp(), SUMA_oDsetNel2nDsetNgr(), SUMA_SO2nimlSO(), and THD_nimlize_dsetatr().
00931 {
00932 NI_group *ngr ;
00933
00934 ngr = NI_malloc(NI_group, sizeof(NI_group) ) ;
00935
00936 ngr->type = NI_GROUP_TYPE ;
00937
00938 ngr->outmode = -1 ; /* 29 Mar 2005 */
00939
00940 ngr->attr_num = 0 ;
00941 ngr->attr_lhs = ngr->attr_rhs = NULL ;
00942
00943 ngr->part_num = 0 ;
00944 ngr->part_typ = NULL ;
00945 ngr->part = NULL ;
00946 ngr->name = NULL ; /* 03 Jun 2002 */
00947
00948 return ngr ;
00949 }
|
|
|
Create a new processing instruction with a given 'target' name. ------------------------------------------------------------------------- Definition at line 909 of file niml_element.c. References NI_procins::attr_lhs, NI_procins::attr_num, NI_procins::attr_rhs, name, NI_procins::name, NI_malloc, NI_PROCINS_TYPE, NI_strdup(), and NI_procins::type. Referenced by NI_rowtype_procins().
00910 {
00911 NI_procins *npi ;
00912
00913 if( name == NULL || name[0] == '\0' ) return NULL ;
00914
00915 npi = NI_malloc(NI_procins,sizeof(NI_procins)) ;
00916
00917 npi->type = NI_PROCINS_TYPE ;
00918 npi->name = NI_strdup(name) ;
00919
00920 npi->attr_num = 0 ;
00921 npi->attr_lhs = npi->attr_rhs = NULL ;
00922
00923 return npi ;
00924 }
|
|
||||||||||||
|
Create a new vector, of the given type and length. Returns NULL if an error occurs. Otherwise, the vec and vec_range arrays are calloc()-ed, and the statistic struct is set to NULL. ------------------------------------------------------------- Definition at line 10 of file niml_vector.c. References NI_datatype_size, NI_index_t, NI_is_builtin_type, NI_malloc, NI_new, NI_STRING, NI_VECTOR_TYPE, NI_vector::statistic, NI_vector::vec, NI_vector::vec_range, and NI_vector::vec_typ. Referenced by NI_dataset_transpose().
00011 {
00012 NI_vector *nv ;
00013 NI_index_t ii ;
00014 int siz ;
00015
00016 if( len <= 0 ) return NULL ;
00017
00018 siz = NI_datatype_size( dtyp ) ;
00019 if( dtyp != NI_STRING && siz <= 0 ) return NULL ;
00020
00021 nv = NI_new(NI_vector) ;
00022 if( NI_is_builtin_type(dtyp) )
00023 nv->type = NI_VECTOR_TYPE + dtyp + 1 ; /* type patched */
00024 else
00025 nv->type = NI_VECTOR_TYPE ; /* generic type */
00026 nv->vec_typ = dtyp ;
00027
00028 if( dtyp != NI_STRING ){
00029 nv->vec = NI_malloc(void, NI_datatype_size(dtyp) * len ) ;
00030 nv->vec_range = NI_malloc(void, NI_datatype_size(dtyp) * 2 ) ;
00031 } else {
00032 nv->vec = NI_malloc(void, sizeof(char *) * len ) ;
00033 nv->vec_range = NULL ; /* string vectors don't use vec_range */
00034 }
00035 nv->statistic = NULL ;
00036 return (void *)nv ;
00037 }
|
|
|
Return a copy of the pointer to the struct, also incrementing its reference counter. Definition at line 62 of file niml_struct.c. Referenced by NI_dataset_transpose().
|
|
||||||||||||||||||||||||||||||||
|
Read "columns" of data from a NI_stream. Each column is an array of structs of some NI_rowtype (including the builtin types):
Definition at line 1411 of file niml_rowtype.c. References NI_stream_type::bad, flags, NI_BASE64_MODE, NI_base64_to_val(), NI_BINARY_MODE, NI_binary_to_val(), NI_dpr(), NI_free, NI_has_String(), NI_LTEND_MASK, NI_malloc, NI_realloc, NI_rowtype_find_code(), NI_stream_goodcheck(), NI_stream_hasinput(), NI_stream_readable(), NI_stream_readbuf(), NI_stream_readbuf64(), NI_swap_column(), NI_SWAP_MASK, NI_TEXT_MODE, NI_text_to_val(), NI_rowtype::psiz, ROWTYPE_is_varsize, NI_rowtype::size, and swap. Referenced by NI_read_element().
01414 {
01415 int ii,jj , row , dim , nin , col , nn ;
01416 char *ptr , **col_dat=(char **)col_dpt ;
01417
01418 NI_rowtype **rt=NULL ; /* array of NI_rowtype, 1 per column */
01419 int *vsiz=NULL , vsiz_tot=0 ;
01420 int *fsiz=NULL , fsiz_tot=0 ;
01421
01422 int (*ReadFun)( NI_stream_type *, NI_rowtype *, void *, int ) ;
01423 int ltend = (flags & NI_LTEND_MASK) != 0 ;
01424 int swap = (flags & NI_SWAP_MASK) != 0 ;
01425 int ReadFlag ;
01426 int open_ended = (col_len==0) , row_top ; /* 27 Mar 2003 */
01427
01428 # undef FREEUP
01429 # define FREEUP do{ NI_free(rt); NI_free(vsiz); NI_free(fsiz); } while(0)
01430
01431 /*-- check inputs --*/
01432
01433 if( col_num <= 0 || col_len < 0 ) return 0 ;
01434 if( col_typ == NULL || col_dat == NULL ) return -1 ;
01435 if( !NI_stream_readable(ns) ) return -1 ;
01436
01437 #ifdef NIML_DEBUG
01438 NI_dpr("ENTER NI_read_columns\n") ;
01439 #endif
01440
01441 /*-- check stream --*/
01442
01443 if( ns->bad ){ /* not connected yet? */
01444 jj = NI_stream_goodcheck(ns,666) ; /* try to connect it */
01445 if( jj < 1 ) return jj ; /* 0 is nothing yet, -1 is death */
01446 }
01447 jj = NI_stream_hasinput(ns,666) ; /* any data to be had? */
01448 if( jj < 0 ) return jj ; /* only exit if stream is actually bad */
01449
01450 /* create array of NI_rowtype for columns, etc. */
01451
01452 rt = NI_malloc(NI_rowtype*, sizeof(NI_rowtype *) * col_num ) ;
01453 vsiz = NI_malloc(int, sizeof(int) * col_num ) ;
01454 fsiz = NI_malloc(int, sizeof(int) * col_num ) ;
01455 if( open_ended ) col_len = 1 ;
01456 for( col=0 ; col < col_num ; col++ ){
01457
01458 rt[col] = NI_rowtype_find_code( col_typ[col] ) ;
01459 if( rt[col] == NULL ){ FREEUP; return -1; }
01460 if( tmode != NI_TEXT_MODE && NI_has_String(rt[col]) ){ FREEUP; return -1; }
01461
01462 vsiz[col] = ROWTYPE_is_varsize(rt[col]) ; /* variable dim type? */
01463 fsiz[col] = rt[col]->size ; /* fixed size of struct (w/padding) */
01464 vsiz_tot += vsiz[col] ;
01465 fsiz_tot += fsiz[col] ;
01466
01467 /* setup data array for this column */
01468
01469 if( col_dat[col] == NULL ){
01470 col_dat[col] = NI_malloc(char, fsiz[col]*col_len ) ; /* make space */
01471 } else {
01472 if( open_ended ){ FREEUP; return -1; }
01473 memset( col_dat[col], 0 , fsiz[col]*col_len ) ; /* set space to 0 */
01474 }
01475 }
01476
01477 /*-- Special (and fast) case:
01478 one compact (no padding) fixed-size rowtype,
01479 and binary input ==> can read all data direct from stream at once --*/
01480
01481 if( col_num == 1 &&
01482 fsiz[0] == rt[0]->psiz && /* struct size == data size */
01483 tmode == NI_BINARY_MODE &&
01484 !open_ended ){
01485
01486 nin = NI_stream_readbuf( ns , col_dat[0] , fsiz[0]*col_len ) ;
01487 if( nin < fsiz[0] ){ FREEUP; return (nin >= 0) ? 0 : -1 ; } /* bad */
01488 nin = nin / fsiz[0] ; /* number of rows finished */
01489 goto ReadFinality ; /* post-process input down below */
01490 }
01491
01492 /*-- 21 Apr 2005: repeat above for Base64 input --*/
01493
01494 if( col_num == 1 &&
01495 fsiz[0] == rt[0]->psiz && /* struct size == data size */
01496 tmode == NI_BASE64_MODE &&
01497 !open_ended ){
01498
01499 nin = NI_stream_readbuf64( ns , col_dat[0] , fsiz[0]*col_len ) ;
01500 if( nin < fsiz[0] ){ FREEUP; return (nin >= 0) ? 0 : -1 ; } /* bad */
01501 nin = nin / fsiz[0] ; /* number of rows finished */
01502 goto ReadFinality ; /* post-process input down below */
01503 }
01504
01505 /*-- Choose function to read from stream and fill one struct --*/
01506
01507 switch( tmode ){
01508 case NI_TEXT_MODE: ReadFun = NI_text_to_val ; ReadFlag = ltend; break;
01509 case NI_BINARY_MODE: ReadFun = NI_binary_to_val; ReadFlag = swap ; break;
01510 case NI_BASE64_MODE: ReadFun = NI_base64_to_val; ReadFlag = swap ; break;
01511 default:
01512 fprintf(stderr,"\n** NI_read_columns: unknown input tmode=%d\n",tmode);
01513 FREEUP ; return -1 ;
01514 }
01515
01516 /*-- OK, have to read the hard ways --*/
01517
01518 row_top = (open_ended) ? 1999999999 : col_len ; /* 28 Mar 2003 */
01519
01520 for( row=0 ; row < row_top ; row++ ){ /* loop over rows */
01521 /* until all done */
01522
01523 #ifdef NIML_DEBUG
01524 NI_dpr(" Starting row #%d\n",row) ;
01525 #endif
01526
01527 /* 27 Mar 2003: maybe need to extend length of columns */
01528
01529 if( open_ended && row >= col_len ){
01530 #ifdef NIML_DEBUG
01531 NI_dpr(" Extending column lengths!\n") ;
01532 #endif
01533 jj = (int)(1.2*col_len+32) ;
01534 for( col=0 ; col < col_num ; col++ ){
01535 col_dat[col] = NI_realloc( col_dat[col] , char, fsiz[col]*jj ) ;
01536 memset( col_dat[col]+fsiz[col]*col_len, 0 , fsiz[col]*(jj-col_len) ) ;
01537 }
01538 col_len = jj ;
01539 }
01540
01541 /* loop over columns, read into struct */
01542
01543 for( col=0 ; col < col_num ; col++ ){
01544 ptr = col_dat[col] + fsiz[col]*row ; /* ptr to row-th struct */
01545 nn = ReadFun( ns, rt[col], ptr, ReadFlag ) ; /* read data to struct */
01546 if( !nn ) break ;
01547 }
01548 if( !nn ) break ; /* some ReadFun() failed */
01549 }
01550
01551 if( row == 0 ){ /* didn't finish any rows */
01552 if( open_ended ){
01553 for( col=0 ; col < col_num ; col++ ) NI_free(col_dat[col]) ;
01554 }
01555 FREEUP; return -1;
01556 }
01557
01558 nin = row ; /* number of rows finished */
01559
01560 if( open_ended && nin < col_len ){ /* truncate columns */
01561 for( col=0 ; col < col_num ; col++ )
01562 col_dat[col] = NI_realloc( col_dat[col] , char, fsiz[col]*nin ) ;
01563 }
01564
01565 /*-- Have read all data; byte swap if needed, then get outta here --*/
01566
01567 ReadFinality:
01568
01569 if( tmode != NI_TEXT_MODE && swap ){
01570 for( col=0 ; col < col_num ; col++ )
01571 NI_swap_column( rt[col] , nin , col_dat[col] ) ;
01572 }
01573
01574 #ifdef NIML_DEBUG
01575 NI_dpr("Leaving NI_read_columns\n") ;
01576 #endif
01577
01578 FREEUP ; return nin ;
01579 }
|
|
||||||||||||
|
Read an element (maybe a group) from the stream, waiting up to msec milliseconds for the header to appear. (After that, this function may wait a long time for the rest of the element to appear, unless the data stream comes to a premature end.) Return is NULL if nothing can be read at this time. Otherwise, use NI_element_type(return value) to determine if the element read is a data element or a group element. Note that a header that is longer than ns->bufsize will never be read properly, since we must have the entire header in the buffer before processing it. This should only be a problem for deranged users. If such a vast header is encountered, it will be flushed. If header start '<' and stop '>' are encountered, then this function will read data until it can create an element, or until the data stream is bad (i.e., the file ends, or the socket closes). If NULL is returned, that can be because there is no data to read even in the buffer, or because the input data stream has gone bad (i.e., will return no more data ever). To check for the latter case, use NI_stream_readcheck(). If a "<ni_do ... />" or "<?ni_do ... ?>" element is encountered, it will not be returned to the caller. Instead, the actions it orders will be carried out in function NI_do(), and the function will loop back to find some other input. ---------------------------------------------------------------------- Definition at line 126 of file niml_elemio.c. References NI_procins::attr_lhs, NI_element::attr_lhs, NI_procins::attr_num, NI_element::attr_num, NI_procins::attr_rhs, NI_element::attr_rhs, NI_stream_type::b64_numleft, NI_stream_type::bad, NI_stream_type::buf, destroy_header_stuff(), header_stuff::empty, header_stuff_is_group(), header_stuff_is_procins(), header_stuff::lhs, make_empty_data_element(), make_empty_group_element(), MARKED_FOR_DEATH, header_stuff::name, NI_procins::name, NI_element::name, header_stuff::nattr, NI_add_to_group(), NI_BASE64_MODE, NI_BINARY_MODE, NI_byteorder(), NI_clock_time(), NI_do(), NI_dpr(), NI_free, NI_free_element(), NI_LSB_FIRST, NI_LTEND_MASK, NI_malloc, NI_MSB_FIRST, NI_PROCINS_TYPE, NI_read_columns(), NI_reset_buffer(), NI_sleep(), NI_strdup(), NI_stream_goodcheck(), NI_stream_readcheck(), NI_SWAP_MASK, NI_TEXT_MODE, NI_stream_type::npos, parse_header_stuff(), read_header_only, header_stuff::rhs, scan_for_angles(), string_index(), swap, NI_procins::type, NI_element::vec, NI_element::vec_axis_len, NI_element::vec_filled, NI_element::vec_len, NI_element::vec_num, NI_element::vec_rank, and NI_element::vec_typ. Referenced by AFNI_niml_workproc(), AFNI_start_version_check(), AIVVV_workproc(), Dtable_from_nimlstring(), main(), NI_read_element_header(), NI_read_file_nohead(), NI_suck_stream(), SUMA_FakeIt(), SUMA_LoadNimlDset(), SUMA_LoadVisualState(), SUMA_niml_workproc(), SUMA_OpenDrawnROI_NIML(), THD_load_3D(), THD_open_3D(), THD_open_nifti(), THD_read_niml_atr(), and XSAVE_input().
00127 {
00128 int ii,nn,nhs , num_restart ;
00129 char *cstart , *cstop ;
00130 header_stuff *hs ;
00131 int start_time=NI_clock_time() , mleft ;
00132
00133 if( ns == NULL || ns->bad == MARKED_FOR_DEATH || ns->buf == NULL )
00134 return NULL ; /* bad input stream */
00135
00136 #ifdef NIML_DEBUG
00137 NI_dpr("ENTER NI_read_element\n") ;
00138 #endif
00139
00140 if( msec < 0 ) msec = 999999999 ; /* a long time (11+ days) */
00141
00142 /* if we have a socket that hasn't connected,
00143 then see if it can connect now */
00144
00145 if( ns->bad ){
00146 nn = NI_stream_goodcheck( ns , msec ) ;
00147 if( nn < 1 ) return NULL ; /* didn't connect */
00148 }
00149
00150 /*-- Try to find the element header --*/
00151
00152 num_restart = 0 ;
00153 HeadRestart: /* loop back here to retry */
00154 num_restart++ ;
00155 mleft = msec - (NI_clock_time()-start_time) ; /* time left */
00156 if( num_restart > 1 && mleft <= 0 ) return NULL ; /* don't allow too many loops */
00157
00158 #ifdef NIML_DEBUG
00159 NI_dpr("NI_read_element: HeadRestart scan_for_angles; num_restart=%d\n" ,
00160 num_restart ) ;
00161 #endif
00162
00163 nn = scan_for_angles( ns , 0 ) ; /* look for '<stuff>' */
00164
00165 /* didn't find it */
00166
00167 if( nn < 0 ){
00168 if( NI_stream_readcheck(ns,0) < 0 ) return NULL ; /* connection lost */
00169 NI_sleep(2); goto HeadRestart; /* try again */
00170 }
00171
00172 #ifdef NIML_DEBUG
00173 NI_dpr("NI_read_element: found '<'\n") ;
00174 #endif
00175
00176 /* ns->buf[ns->npos] = opening '<' ; ns->buf[nn-1] = closing '>' */
00177
00178 /* see if we found '<>', which is meaningless,
00179 or a trailer '</stuff>', which is illegal here */
00180
00181 if( nn - ns->npos <= 2 || ns->buf[ns->npos+1] == '/' ){
00182 ns->npos = nn; NI_reset_buffer(ns); /* toss the '<..>', try again */
00183 #ifdef NIML_DEBUG
00184 NI_dpr("NI_read_element: illegal header found? skipping\n") ;
00185 #endif
00186 goto HeadRestart ;
00187 }
00188
00189 /*----- Parse the header data and prepare to make an element! -----*/
00190
00191 #ifdef NIML_DEBUG
00192 NI_dpr("NI_read_element: parsing putative header\n") ;
00193 #endif
00194
00195 hs = parse_header_stuff( nn - ns->npos , ns->buf + ns->npos , &nhs ) ;
00196
00197 if( hs == NULL ){ /* something bad happened there */
00198 fprintf(stderr,"NI_read_element: bad element header found!\n") ;
00199 ns->npos = nn; NI_reset_buffer(ns); /* toss the '<..>', try again */
00200 goto HeadRestart ;
00201 }
00202
00203 /*----- If here, have parsed a header (and will not HeadRestart).
00204 First, expunge the data bytes that were consumed to make
00205 the header; that is, we can then start reading data from
00206 ns->buf[ns->npos] .. ns->buf[ns->nbuf-1] --*/
00207
00208 ns->npos = nn ;
00209
00210 #ifdef NIML_DEBUG
00211 NI_dpr("NI_read_element: header parsed successfully\n") ;
00212 #endif
00213
00214 /*--------------- Now make an element of some kind ---------------*/
00215
00216 if( header_stuff_is_procins(hs) ){ /*--- a processing instruction ---*/
00217
00218 NI_procins *npi ;
00219
00220 if( strcmp(hs->name,"?ni_do") == 0 ){ /* 19 Apr 2005: special case! */
00221 NI_element *nel ;
00222 nel = make_empty_data_element( hs ) ; /* temporary element */
00223 destroy_header_stuff( hs ) ;
00224 NI_do( ns , nel ) ; /* do the stuff it says */
00225 NI_free_element( nel ) ; /* then destroy it */
00226 if( ns->bad == MARKED_FOR_DEATH || ns->buf == NULL ) return NULL ;
00227 num_restart = 0 ; goto HeadRestart ;
00228 }
00229
00230 /* 03 Jun 2005: if ordered to skip these things, do so */
00231
00232 if( skip_procins ){
00233 destroy_header_stuff( hs ) ; num_restart = 0 ; goto HeadRestart ;
00234 }
00235
00236 /* normal case: make a procins element and give it to the caller */
00237
00238 npi = NI_malloc(NI_procins,sizeof(NI_procins)) ;
00239 npi->type = NI_PROCINS_TYPE ;
00240 npi->name = NI_strdup( hs->name + 1 ) ; /* skip the '?' */
00241
00242 npi->attr_num = hs->nattr ;
00243 if( npi->attr_num > 0 ){
00244 npi->attr_lhs = hs->lhs ; hs->lhs = NULL ;
00245 npi->attr_rhs = hs->rhs ; hs->rhs = NULL ;
00246 } else {
00247 npi->attr_lhs = npi->attr_rhs = NULL ;
00248 }
00249
00250 destroy_header_stuff( hs ) ;
00251
00252 return npi ;
00253
00254 } /*--- end of reading a processing instruction ---*/
00255
00256 else if( header_stuff_is_group(hs) ){ /*---- a group element ----*/
00257
00258 NI_group *ngr ;
00259 void *nini ;
00260 int empty=hs->empty ;
00261
00262 read_header_only = 0 ; /* 23 Mar 2003 */
00263
00264 start_time = NI_clock_time() ; /* allow up to 10 sec for next */
00265 msec = 9999 ; /* element to appear, before giving up */
00266
00267 ngr = make_empty_group_element( hs ) ; /* copies name and attributes */
00268 destroy_header_stuff( hs ) ;
00269 if( empty ) return ngr ; /* 03 Jun 2002: empty group is legal */
00270
00271 /* we now have to read the elements within the group */
00272
00273 num_restart = 0 ;
00274 while(1){ /* loop to find an element */
00275
00276 #ifdef NIML_DEBUG
00277 NI_dpr("NI_read_element: ni_group scan_for_angles; num_restart=%d\n",
00278 num_restart ) ;
00279 #endif
00280
00281 nn = scan_for_angles( ns , 10 ) ; /* find header/trailer '<...>' */
00282
00283 mleft = msec - (NI_clock_time()-start_time) ;
00284 if( mleft < 0 ) mleft = 0 ;
00285
00286 if( nn <= 0 ){ /* didn't find it */
00287 if( NI_stream_readcheck(ns,0) < 0 ) break ; /* real bad */
00288 if( num_restart > 1 && mleft == 0 ) break ; /* time's up */
00289 num_restart++ ;
00290 continue ; /* try again (but not forever) */
00291 }
00292
00293 /* check if we found a trailer element '</stuff>' */
00294
00295 if( ns->buf[ns->npos+1] == '/' ){ /* trailer */
00296 ns->npos = nn ; /* so end the group */
00297 break ;
00298 }
00299
00300 /* not a trailer, so try to make an element out of it */
00301
00302 nini = NI_read_element( ns , mleft ) ; /* recursion! */
00303 if( nini != NULL ){
00304 NI_add_to_group( ngr , nini ) ; /* this is good */
00305 num_restart = 0 ;
00306 start_time = NI_clock_time() ; /* restart the wait clock */
00307 } else { /* this is bad */
00308 if( NI_stream_readcheck(ns,0) < 0 ) break ; /* real bad */
00309 mleft = msec - (NI_clock_time()-start_time) ;
00310 if( num_restart > 1 && mleft <= 0 ) break ; /* time's up */
00311 num_restart++ ;
00312 }
00313 }
00314
00315 /* and we are done */
00316
00317 return ngr ;
00318
00319 } /* end of reading group element */
00320
00321 else { /*------------------------ a data element ---------------------*/
00322
00323 NI_element *nel ;
00324 int form, swap, nbrow , row,col ;
00325
00326 nel = make_empty_data_element( hs ) ;
00327 destroy_header_stuff( hs ) ;
00328
00329 /*-- check if this is an empty element --*/
00330
00331 if( nel == NULL || /* nel == NULL should never happen. */
00332 nel->vec_rank == 0 || /* These other cases are indication */
00333 nel->vec_num == 0 || /* that this is an 'empty' element. */
00334 nel->vec_typ == NULL || /* ==> The header is all there is. */
00335 nel->vec == NULL ||
00336 nel->name[0] == '!' || /* Stupid XML declaration */
00337 read_header_only ){
00338
00339 #ifdef NIML_DEBUG
00340 NI_dpr("NI_read_element: returning empty element\n") ;
00341 #endif
00342
00343 /*-- 23 Aug 2002: do something, instead of returning data? --*/
00344
00345 if( nel != NULL && strcmp(nel->name,"ni_do") == 0 ){
00346 NI_do( ns , nel ) ;
00347 NI_free_element( nel ) ;
00348 if( ns->bad == MARKED_FOR_DEATH || ns->buf == NULL ) return NULL ;
00349 num_restart = 0 ; goto HeadRestart ;
00350 }
00351
00352 if( read_header_only && nel->vec != NULL ){
00353 for( ii=0 ; ii < nel->vec_num ; ii++ ) NI_free(nel->vec[ii]) ;
00354 NI_free(nel->vec) ; nel->vec = NULL ;
00355 }
00356
00357 return nel ; /* default: return element */
00358 }
00359
00360 /*-- If here, must read data from the buffer into nel->vec --*/
00361
00362 /* Find the form of the input */
00363
00364 form = NI_TEXT_MODE ; /* default is text mode */
00365 swap = 0 ; /* and (obviously) don't byte swap */
00366
00367 ii = string_index( "ni_form" , nel->attr_num , nel->attr_lhs ) ;
00368
00369 if( ii >= 0 && nel->attr_rhs[ii] != NULL ){ /* parse ni_form=rhs */
00370
00371 /* binary or base64 mode? */
00372
00373 if( strstr(nel->attr_rhs[ii],"binary") != NULL )
00374 form = NI_BINARY_MODE ;
00375 else if( strstr(nel->attr_rhs[ii],"base64") != NULL ){
00376 form = NI_BASE64_MODE ;
00377 ns->b64_numleft = 0 ; /* 21 Apr 2005: reset Base64 leftovers */
00378 }
00379
00380 /* check byteorder in header vs. this CPU */
00381
00382 if( form != NI_TEXT_MODE ){
00383 int order=NI_MSB_FIRST ; /* default input byteorder */
00384 if( strstr(nel->attr_rhs[ii],"lsb") != NULL ) order = NI_LSB_FIRST;
00385 swap = ( order != NI_byteorder() ) ; /* swap bytes? */
00386 }
00387 }
00388
00389 /*-- 13 Feb 2003: Use new NI_read_columns() function to get data. --*/
00390
00391 if( form == NI_TEXT_MODE ) ii = NI_LTEND_MASK ; /* end on '<' char */
00392 else if( swap ) ii = NI_SWAP_MASK ; /* swap binary data */
00393 else ii = 0 ; /* no special flag */
00394
00395 row = NI_read_columns( ns ,
00396 nel->vec_num, nel->vec_typ,
00397 nel->vec_len, nel->vec , form, ii );
00398
00399 nel->vec_filled = (row >= 0) ? row : 0 ;
00400
00401 /* 27 Mar 2003: allow for case where vec_len is
00402 inferred from how much data we read */
00403
00404 if( nel->vec_len == 0 ){
00405 if( nel->vec_axis_len == NULL )
00406 nel->vec_axis_len = NI_malloc(int, sizeof(int)) ;
00407
00408 nel->vec_axis_len[0] = nel->vec_len = nel->vec_filled ;
00409 nel->vec_rank = 1 ;
00410 }
00411
00412 /*-- Now scan for the end-of-element marker '</something>' and
00413 skip all input bytes up to (and including) the final '>'. --*/
00414
00415 num_restart = 0 ;
00416 TailRestart:
00417 num_restart++ ;
00418
00419 if( num_restart < 99 ){ /* don't loop forever, dude */
00420 int is_tail ;
00421
00422 #ifdef NIML_DEBUG
00423 NI_dpr("NI_read_element: TailRestart scan_for_angles; num_restart=%d\n" ,
00424 num_restart ) ;
00425 #endif
00426
00427 nn = scan_for_angles( ns , 99 ) ; /* find '<...>' */
00428
00429 /* if we didn't find '<...>' at all,
00430 then if the I/O stream is bad, just exit;
00431 otherwise, try scanning for '<...>' again */
00432
00433 if( nn < 0 ){
00434 if( NI_stream_readcheck(ns,0) < 0 ) return nel ;
00435 goto TailRestart ;
00436 }
00437
00438 /* we have '<...>', but make sure it starts with '</' */
00439
00440 is_tail = ( ns->buf[ns->npos+1] == '/' ) ;
00441
00442 if( !is_tail ){ /* no '/'? */
00443 ns->npos = nn ; NI_reset_buffer(ns) ; /* skip '<...>' */
00444 goto TailRestart ; /* and try again */
00445 }
00446
00447 ns->npos = nn ; /* skip '</...>' and we are done here! */
00448 }
00449
00450 /*-- And are done with the input stream and the data element! --*/
00451
00452 #ifdef NIML_DEBUG
00453 NI_dpr("NI_read_element: returning filled data element\n") ;
00454 #endif
00455
00456 /*-- 23 Aug 2002: do something, instead of returning data? --*/
00457
00458 if( strcmp(nel->name,"ni_do") == 0 ){
00459 NI_do( ns , nel ) ;
00460 NI_free_element( nel ) ;
00461 num_restart = 0 ; goto HeadRestart ;
00462 }
00463
00464 return nel ;
00465
00466 } /* end of reading data element */
00467
00468 return NULL ; /* should never be reached */
00469 }
|
|
||||||||||||
|
Read only the header part of the next element. ---------------------------------------------------------------------- Definition at line 86 of file niml_elemio.c. References NI_read_element(), and read_header_only.
00087 {
00088 void *nini ;
00089 read_header_only = 1 ;
00090 nini = NI_read_element( ns , msec ) ;
00091 read_header_only = 0 ;
00092 return nini ;
00093 }
|
|
|
Definition at line 77 of file niml_elemio.c. References r, and read_header_only. Referenced by THD_open_3D().
00077 { read_header_only=r ; } /* 23 Mar 2003 */
|
|
||||||||||||
|
Read a URL (ftp:// or http://) into memory. The return value is the number of bytes read, and *data points to the data. If the return value is negative, then something bad happened. Example:
Definition at line 400 of file niml_url.c. References FTP, getenv(), HTTP, read_URL_ftp(), read_URL_http(), and www_debug. Referenced by can_get_testfile(), NI_read_URL_tmpdir(), NI_stream_open(), THD_fetch_dataset(), THD_fetch_many_datasets(), and TTget_ppm().
00401 {
00402 int nn ;
00403 if( url == NULL || data == NULL ) return( -1 );
00404
00405 if( getenv("NIML_WWW_DEBUG") != NULL ) www_debug = 1 ;
00406
00407 if( strstr(url,HTTP) == url ){
00408 nn = read_URL_http( url , 4444 , data ) ; return(nn) ;
00409 }
00410
00411 else if( strstr(url,FTP) == url ){
00412 nn = read_URL_ftp( url , data ) ; return(nn) ;
00413 }
00414
00415 return( -1 );
00416 }
|
|
||||||||||||
|
Read a URL and save it to disk in tmpdir. The filename it is saved in is returned in the malloc-ed space *tname. The byte count is the return value of the function; if <= 0, then an error transpired (and *tname is not set). Example:
Definition at line 432 of file niml_url.c. References free, malloc, NI_read_URL(), setup_tmpdir(), tmpdir, trailname(), tt, and unlink. Referenced by THD_fetch_1D(), and THD_fetch_dataset().
00433 {
00434 int nn , ll ;
00435 char *data , *fname , *tt ;
00436 FILE *fp ;
00437
00438 if( url == NULL || tname == NULL ) return( -1 );
00439
00440 nn = NI_read_URL( url , &data ) ; /* get the data into memory */
00441 if( nn <= 0 ) return( -1 ); /* bad */
00442
00443 /* make the output filename */
00444
00445 setup_tmpdir() ;
00446 fname = (char *)malloc(strlen(url)+strlen(tmpdir)+1) ;
00447 tt = trailname(url,0) ;
00448 strcpy(fname,tmpdir) ; strcat(fname,tt) ; ll = strlen(fname) ;
00449 if( ll > 3 && strcmp(fname+(ll-3),".gz") == 0 ) fname[ll-3] = '\0' ;
00450
00451 /* open and write output */
00452
00453 fp = fopen( fname , "wb" ) ;
00454 if( fp == NULL ){
00455 fprintf(stderr,"** Can't open temporary file %s\n",fname);
00456 free(data) ; return( -1 );
00457 }
00458 ll = fwrite(data,1,nn,fp) ; fclose(fp) ; free(data) ;
00459 if( ll != nn ){ unlink(fname); return( -1 ); } /* write failed */
00460
00461 *tname = fname ; return( nn );
00462 }
|
|
||||||||||||
|
Register a callback for a "ni_do" verb. [12 Feb 2003] The function will be called like so
However, you CAN register a callback for a builtin verb. The normal processing will take place, then the user callback will be invoked if that processing was good. [This feature was added on 30 Dec 2003.] ----------------------------------------------------------------------------- Definition at line 30 of file niml_do.c. References doer_func, doer_num, doer_verb, NI_realloc, NI_strdup(), and NI_voidfunc. Referenced by AFNI_init_niml(), and timeout_CB().
00031 {
00032 int ii ;
00033
00034 if( verb == NULL || *verb == '\0' ) return ;
00035
00036 /* see if verb already in table */
00037
00038 for( ii=0 ; ii < doer_num ; ii++ )
00039 if( strcmp(verb,doer_verb[ii]) == 0 ) break ;
00040
00041 /* if was in table, replace func (may be NULL) */
00042
00043 if( ii < doer_num ){
00044 doer_func[ii] = func ; return ;
00045 }
00046
00047 /* defining a new verb */
00048
00049 if( func == NULL ) return ; /* quit if no func */
00050
00051 /* expand tables of verbs and funcs */
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 }
|
|
||||||||||||||||
|
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 }
|
|
|
Register a struct by its idcode (if it has one). Definition at line 11 of file niml_struct.c. References addto_Htable(), findin_Htable(), and new_Htable().
00012 {
00013 NI_struct *nd = (NI_struct *)ndd ;
00014 void *vp ;
00015
00016 /* can't register without idcode */
00017
00018 if( nd == NULL || nd->idcode == NULL ) return ;
00019
00020 /* 1st time in ==> create hash table */
00021
00022 if( ni_struct_table == NULL )
00023 ni_struct_table = new_Htable( 1031 ) ;
00024
00025 /* see if it already is registered */
00026
00027 vp = findin_Htable( nd->idcode , ni_struct_table ) ;
00028 if( vp != NULL ) return ; /* duplicate entry */
00029
00030 /* OK, add it to the table */
00031
00032 addto_Htable( nd->idcode , nd , ni_struct_table ) ;
00033 return ;
00034 }
|
|
||||||||||||||||
|
Associate a given pointer (non-NULL) with idcode and name string.
Definition at line 138 of file niml_registry.c. References addto_Htable(), calloc, findin_Htable(), registry_entry::flags, registry_entry::idc, init_registry(), registry_entry::ipt, name, registry_entry::name, NI_strncpy(), NIREG_PRIVATE_MALLOC, registry_entry::vlen, registry_entry::vpt, and vpt_to_char().
00139 {
00140 void *xpt ;
00141 registry_entry *rent ; /* pay this or be evicted */
00142
00143 init_registry() ; /* setup empty hash tables, if needed */
00144
00145 if( idcode == NULL || *idcode == '\0' || vpt == NULL ) return NULL ;
00146
00147 /* check to see if already have this idcode */
00148
00149 xpt = findin_Htable( idcode , registry_htable_idc ) ;
00150 if( xpt != NULL ) return NULL ; /* bad */
00151
00152 /* make the registry entry for this doohicky */
00153
00154 rent = calloc(1,sizeof(registry_entry)) ;
00155 NI_strncpy( rent->idc , idcode , 32 ) ; /* copy idcode */
00156 rent->vpt = vpt ; /* copy data pointer */
00157 rent->vlen = 0 ; /* set length */
00158 vpt_to_char( vpt , rent->ipt ) ; /* string version of data pointer */
00159 if( name == NULL ) name = "\0" ;
00160 rent->name = strdup(name) ; /* copy name */
00161 rent->flags = NIREG_PRIVATE_MALLOC ; /* init flags */
00162
00163 /* and index this new registry entry under the idcode and the pointer */
00164
00165 addto_Htable( rent->idc , (void *)rent , registry_htable_idc ) ;
00166 addto_Htable( rent->ipt , (void *)rent , registry_htable_ipt ) ;
00167
00168 return vpt ; /* give the user the pointer he asked for */
00169 }
|
|
|
Definition at line 256 of file niml_registry.c. References findin_Htable(), registry_entry::idc, registry_entry::ipt, NIREG_free, removefrom_Htable(), and vpt_to_char().
00257 {
00258 char ipt[32] ;
00259 registry_entry *rent ;
00260
00261 if( vpt == NULL || registry_htable_ipt == NULL ) return ;
00262
00263 /* look for the pointer in the index */
00264
00265 vpt_to_char( vpt , ipt ) ;
00266 rent = (registry_entry *) findin_Htable( ipt , registry_htable_ipt ) ;
00267 if( rent == NULL ) return ; /* stupid users must be punished somehow */
00268
00269 removefrom_Htable( rent->ipt , registry_htable_ipt ) ;
00270 removefrom_Htable( rent->idc , registry_htable_idc ) ;
00271 NIREG_free( rent ) ;
00272 return ;
00273 }
|
|
||||||||||||
|
Given an idcode, modify the name string that goes with it. Definition at line 373 of file niml_registry.c. References findin_Htable(), free, and registry_entry::name.
00374 {
00375 registry_entry *rent ;
00376
00377 rent = (registry_entry *) findin_Htable( idcode , registry_htable_idc ) ;
00378 if( rent == NULL ) return ;
00379 free((void *)rent->name) ;
00380 if( newname == NULL ) newname = "\0" ;
00381 rent->name = strdup(newname) ;
00382 return ;
00383 }
|
|
|
Given an idcode, get the data length that goes with it. Note that 0 is returned if the data ptr was setup with len=0 OR* if the idcode can't be found in the registry. --------------------------------------------------------------------- Definition at line 293 of file niml_registry.c. References findin_Htable(), and registry_entry::vlen.
00294 {
00295 registry_entry *rent ;
00296
00297 rent = (registry_entry *) findin_Htable( idcode , registry_htable_idc ) ;
00298 if( rent == NULL ) return 0 ;
00299 return rent->vlen ;
00300 }
|
|
|
Given an idcode, get the name string that went with it. This is the pointer into the internal registry_entry struct, so don't modify it! --------------------------------------------------------------------- Definition at line 327 of file niml_registry.c. References findin_Htable(), and registry_entry::name.
00328 {
00329 registry_entry *rent ;
00330
00331 rent = (registry_entry *) findin_Htable( idcode , registry_htable_idc ) ;
00332 if( rent == NULL ) return NULL ;
00333 return rent->name ;
00334 }
|
|
|
Given an idcode, get the data pointer that goes with it. Definition at line 278 of file niml_registry.c. References findin_Htable(), and registry_entry::vpt.
00279 {
00280 registry_entry *rent ;
00281
00282 rent = (registry_entry *) findin_Htable( idcode , registry_htable_idc ) ;
00283 if( rent == NULL ) return NULL ;
00284 return rent->vpt ;
00285 }
|
|
||||||||||||||||
|
Allocate memory with calloc(), and associate it with a given idcode and name string.
Definition at line 87 of file niml_registry.c. References addto_Htable(), calloc, findin_Htable(), registry_entry::flags, registry_entry::idc, init_registry(), registry_entry::ipt, name, registry_entry::name, NI_strncpy(), registry_entry::vlen, registry_entry::vpt, and vpt_to_char().
00088 {
00089 void *vpt ;
00090 int lll ;
00091 registry_entry *rent ; /* pay this or be evicted */
00092
00093 init_registry() ; /* setup empty hash tables, if needed */
00094
00095 if( idcode == NULL || *idcode == '\0' ) return NULL ;
00096
00097 /* check to see if already have this idcode */
00098
00099 vpt = findin_Htable( idcode , registry_htable_idc ) ;
00100 if( vpt != NULL ) return NULL ; /* bad */
00101
00102 /* allocate space for result of this function */
00103
00104 lll = (len == 0) ? 4 : len ;
00105 vpt = calloc(1,lll) ;
00106 if( vpt == NULL ) return NULL ; /* bad */
00107
00108 if( len == 0 ){ char *cpt=(char *)vpt; *cpt = '\0'; }
00109
00110 /* make the registry entry for this doohicky */
00111
00112 rent = calloc(1,sizeof(registry_entry)) ;
00113 NI_strncpy( rent->idc , idcode , 32 ) ; /* copy idcode */
00114 rent->vpt = vpt ; /* copy data pointer */
00115 rent->vlen = len ; /* save length */
00116 vpt_to_char( vpt , rent->ipt ) ; /* string version of data pointer */
00117 if( name == NULL ) name = "\0" ;
00118 rent->name = strdup(name) ; /* copy name */
00119 rent->flags = 0 ; /* init flags */
00120
00121 /* and index this new registry entry under the idcode and the pointer */
00122
00123 addto_Htable( rent->idc , (void *)rent , registry_htable_idc ) ;
00124 addto_Htable( rent->ipt , (void *)rent , registry_htable_ipt ) ;
00125
00126 return vpt ; /* give the user the pointer he asked for */
00127 }
|
|
||||||||||||
|
Given a data pointer, alter the name string that goes with it. Definition at line 388 of file niml_registry.c. References findin_Htable(), free, registry_entry::name, and vpt_to_char().
00389 {
00390 char ipt[32] ;
00391 registry_entry *rent ;
00392
00393 if( vpt == NULL || registry_htable_ipt == NULL ) return ;
00394
00395 vpt_to_char( vpt , ipt ) ;
00396 rent = (registry_entry *) findin_Htable( ipt , registry_htable_ipt ) ;
00397 if( rent == NULL ) return ;
00398 free((void *)rent->name) ;
00399 if( newname == NULL ) newname = "\0" ;
00400 rent->name = strdup(newname) ;
00401 return ;
00402 }
|
|
|
Given a data pointer, return a pointer to the idcode that corresponds. Don't modify this! --------------------------------------------------------------------- Definition at line 341 of file niml_registry.c. References findin_Htable(), registry_entry::idc, and vpt_to_char().
00342 {
00343 char ipt[32] ;
00344 registry_entry *rent ;
00345
00346 if( vpt == NULL || registry_htable_ipt == NULL ) return ;
00347
00348 vpt_to_char( vpt , ipt ) ;
00349 rent = (registry_entry *) findin_Htable( ipt , registry_htable_ipt ) ;
00350 if( rent == NULL ) return ;
00351 return rent->idc ;
00352 }
|
|
|
Given a data pointer, get the data length that goes with it. Note that 0 is returned if the data ptr was setup with len=0 OR* if the data ptr can't be found in the registry. --------------------------------------------------------------------- Definition at line 308 of file niml_registry.c. References findin_Htable(), registry_entry::vlen, and vpt_to_char().
00309 {
00310 char ipt[32] ;
00311 registry_entry *rent ;
00312
00313 if( vpt == NULL || registry_htable_ipt == NULL ) return ;
00314
00315 vpt_to_char( vpt , ipt ) ;
00316 rent = (registry_entry *) findin_Htable( ipt , registry_htable_ipt ) ;
00317 if( rent == NULL ) return 0 ;
00318 return rent->vlen ;
00319 }
|
|
|
Given a data pointer, get the name string that corresponds. Definition at line 357 of file niml_registry.c. References findin_Htable(), registry_entry::name, and vpt_to_char().
00358 {
00359 char ipt[32] ;
00360 registry_entry *rent ;
00361
00362 if( vpt == NULL || registry_htable_ipt == NULL ) return ;
00363
00364 vpt_to_char( vpt , ipt ) ;
00365 rent = (registry_entry *) findin_Htable( ipt , registry_htable_ipt ) ;
00366 if( rent == NULL ) return ;
00367 return rent->name ;
00368 }
|
|
||||||||||||
|
Like realloc(), but also updates the indexes.
Definition at line 182 of file niml_registry.c. References addto_Htable(), findin_Htable(), registry_entry::ipt, NIREG_isprivate, realloc, removefrom_Htable(), registry_entry::vlen, registry_entry::vpt, and vpt_to_char().
00183 {
00184 char ipt[32] ;
00185 void *vpt_new ;
00186 int lll ;
00187 registry_entry *rent ;
00188
00189 if( vpt == NULL || registry_htable_ipt == NULL ) return NULL ;
00190
00191 /* look up the pointer in the index */
00192
00193 vpt_to_char( vpt , ipt ) ;
00194 rent = (registry_entry *) findin_Htable( ipt , registry_htable_ipt ) ;
00195 if( rent == NULL ) return NULL ; /* not found!? */
00196 if( NIREG_isprivate(rent) ) return NULL ; /* bad user */
00197
00198 lll = (newlen == 0) ? 4 : newlen ;
00199 vpt_new = realloc( vpt , lll ) ; /* get new allocation */
00200 if( vpt_new == NULL ) return NULL ; /* bad */
00201 if( vpt_new == vpt ) return vpt ; /* no change! */
00202
00203 /* remove the pointer-based entry from the index,
00204 then make a new pointer index */
00205
00206 removefrom_Htable( ipt , registry_htable_ipt ) ;
00207
00208 rent->vpt = vpt_new ;
00209 rent->vlen = newlen ;
00210 vpt_to_char( vpt , rent->ipt ) ;
00211 addto_Htable( rent->ipt , (void *)rent , registry_htable_ipt ) ;
00212
00213 return vpt_new ; /* give back the new pointer */
00214 }
|
|
||||||||||||
|
For something added with NI_registry_add(), lets you replace the pointer with some other pointer. --------------------------------------------------------------------- Definition at line 221 of file niml_registry.c. References addto_Htable(), findin_Htable(), registry_entry::flags, free, registry_entry::ipt, NIREG_isprivate, NIREG_PRIVATE_MALLOC, removefrom_Htable(), registry_entry::vlen, registry_entry::vpt, and vpt_to_char().
00222 {
00223 char ipt[32] ;
00224 registry_entry *rent ;
00225
00226 if( vpt == NULL || vpt_new == NULL ||
00227 registry_htable_ipt == NULL ) return NULL ;
00228
00229 if( vpt == vpt_new ) return vpt ;
00230
00231 /* look up the pointer in the index */
00232
00233 vpt_to_char( vpt , ipt ) ;
00234 rent = (registry_entry *) findin_Htable( ipt , registry_htable_ipt ) ;
00235 if( rent == NULL ) return NULL ; /* not found!? */
00236
00237 if( !NIREG_isprivate(rent) ) free((void *)vpt) ;
00238
00239 /* remove the pointer-based entry from the index,
00240 then make a new pointer index */
00241
00242 removefrom_Htable( ipt , registry_htable_ipt ) ;
00243
00244 rent->vpt = vpt_new ;
00245 rent->vlen = 0 ; /* len is unknown here */
00246 vpt_to_char( vpt , rent->ipt ) ;
00247 addto_Htable( rent->ipt , (void *)rent , registry_htable_ipt ) ;
00248 rent->flags = NIREG_PRIVATE_MALLOC ;
00249
00250 return vpt_new ; /* give back the new pointer */
00251 }
|
|
||||||||||||
|
Remove an element from a group. Does NOT delete the element; that is the caller's responsibility, if desired. ------------------------------------------------------------------------- Definition at line 976 of file niml_element.c. References NI_GROUP_TYPE, NI_group::part, NI_group::part_num, NI_group::part_typ, and NI_group::type. Referenced by nifti_set_afni_extension().
00977 {
00978 int ii , nn , jj ;
00979
00980 if( ngr == NULL || ngr->type != NI_GROUP_TYPE || nini == NULL ) return ;
00981
00982 nn = ngr->part_num ;
00983 for( ii=0 ; ii < nn ; ii++ ) /* search for part */
00984 if( nini == ngr->part[ii] ) break ;
00985 if( ii == nn ) return ; /* not found */
00986
00987 for( jj=ii+1 ; jj < nn ; jj++ ){ /* move parts above down */
00988 ngr->part_typ[jj-1] = ngr->part_typ[jj] ;
00989 ngr->part [jj-1] = ngr->part [jj] ;
00990 }
00991 ngr->part[nn-1] = NULL ; /* NULL-ify last part to be safe */
00992 ngr->part_num -- ; /* reduce part count */
00993 return ;
00994 }
|
|
||||||||||||
|
Rename a group element from the default - 03 Jun 2002. ------------------------------------------------------------------------- Definition at line 1000 of file niml_element.c. References NI_group::name, NI_free, NI_GROUP_TYPE, NI_strdup(), and NI_group::type. Referenced by main(), nifti_set_afni_extension(), SUMA_NewDsetGrp(), SUMA_oDsetNel2nDsetNgr(), SUMA_SO2nimlSO(), THD_dataset_to_niml(), and THD_nimlize_dsetatr().
|
|
|
Given a rowtype code, find its alias name. This is only valid for builtin types; for user-defined types, the return value is the user-supplied type name string. Don't free this string! ---------------------------------------------------------------------- Definition at line 776 of file niml_rowtype.c. References NI_NUM_BASIC_TYPES, NI_rowtype_code_to_name(), setup_basic_types(), and type_alias. Referenced by NI_type_name().
00777 {
00778 if( rowtype_table == NULL ) setup_basic_types() ;
00779 if( nn <= NI_NUM_BASIC_TYPES ) return type_alias[nn] ;
00780 return NI_rowtype_code_to_name( nn ) ;
00781 }
|
|
|
Given a rowtype code, find its string name. Returns NULL if the code isn't found in the rowtype table, otherwise returns the pointer to the name inside the table (i.e., don't free this string!). ---------------------------------------------------------------------- Definition at line 763 of file niml_rowtype.c. References NI_rowtype::name, and NI_rowtype_find_code(). Referenced by NI_rowtype_code_to_alias(), and NI_type_name().
00764 {
00765 NI_rowtype *rt = NI_rowtype_find_code( nn ) ;
00766 if( rt != NULL ) return rt->name ;
00767 return NULL ;
00768 }
|
|
|
Given a rowtype code, find its struct size in bytes. See also NI_rowtype_name_to_size(). ------------------------------------------------------------- Definition at line 806 of file niml_rowtype.c. References NI_rowtype_find_code(), ROWTYPE_OFFSET, setup_basic_types(), NI_rowtype::size, and type_size. Referenced by NI_type_size().
00807 {
00808 static int last_dtyp=-1 , last_size=-1 ; /* 12 Dec 2002 */
00809 NI_rowtype *rt ;
00810
00811 if( rowtype_table == NULL ) setup_basic_types() ;
00812 if( dtyp < 0 ) return -1 ;
00813 if( dtyp < ROWTYPE_OFFSET ) return type_size[dtyp] ;
00814 if( dtyp == last_dtyp ) return last_size ;
00815
00816 rt = NI_rowtype_find_code(dtyp) ;
00817 if( rt != NULL ){
00818 last_dtyp = dtyp; last_size = rt->size; return last_size;
00819 }
00820 return -1 ; /* bad */
00821 }
|
|
|
Set debug flag for rowtype stuff. Definition at line 89 of file niml_rowtype.c. References ROWTYPE_debug.
00089 { ROWTYPE_debug = n ; }
|
|
||||||||||||
|
Definition at line 266 of file niml_rowtype.c. References NI_rowtype::algn, NI_rowtype::code, NI_rowtype::comp_dim, NI_rowtype::comp_num, NI_rowtype::comp_typ, delete_rowtype, ERREX, NI_rowtype::flag, NI_rowtype::name, NI_decode_string_list(), NI_delete_str_array, NI_free, NI_INT, NI_is_name(), NI_malloc, NI_new, NI_realloc, NI_rowtype_find_code(), NI_rowtype_find_name(), NI_strdup(), NI_strncpy(), NI_str_array::num, NI_rowtype::part_dim, NI_rowtype::part_num, NI_rowtype::part_off, NI_rowtype::part_rtp, NI_rowtype::part_siz, NI_rowtype::part_typ, pointer_alignment, pointer_size, NI_rowtype::psiz, ROWTYPE_BASE_CODE, ROWTYPE_is_varsize, rowtype_num, ROWTYPE_register, ROWTYPE_VARSIZE_MASK, setup_basic_types(), NI_rowtype::size, NI_str_array::str, and NI_rowtype::userdef. Referenced by NI_do(), NI_rowtype_find_name(), SUMA_Create_CommonFields(), and SUMA_FakeIt().
00267 {
00268 NI_rowtype *rt , *qt ;
00269 int ii,jj , id,jd,kd,isdim,nn , almax,cbase,np,pb , last_size ;
00270 NI_str_array *sar ;
00271 char *tp,*sp,*bp , str[256] ;
00272
00273 /*-- check inputs --*/
00274
00275 if( !NI_is_name(tname) ) ERREX("bad typename") ;
00276 if( strlen(tname) > 255 ) ERREX("toolong typename") ;
00277 if( tdef == NULL || *tdef == '\0' ) ERREX("empty type definition") ;
00278
00279 /*-- create Htable of basic types, if not already defined --*/
00280
00281 if( rowtype_table == NULL ) setup_basic_types() ;
00282
00283 /*-- see if type name already defined --*/
00284 /*-- 25 Mar 2003: if it is, return the old code --*/
00285
00286 rt = NI_rowtype_find_name( tname ) ;
00287 if( rt != NULL ){
00288 if( strcmp(rt->userdef,tdef) != 0 ){
00289 fprintf(stderr,
00290 "++ NI_rowtype_define: illegal attempt to redefine type '%s'\n"
00291 "++ old definition: %s\n"
00292 "++ (failed) new definition: %s\n" ,
00293 tname , rt->userdef , tdef ) ;
00294 }
00295 return rt->code ;
00296 }
00297
00298 /*-- break defining string into components --*/
00299
00300 sar = NI_decode_string_list( tdef , ",;" ) ;
00301
00302 if( sar == NULL || sar->num < 1 ){
00303 NI_free(sar) ; ERREX("illegal definition") ;
00304 }
00305
00306 /*-- initialize the new rowtype --*/
00307
00308 rt = NI_new( NI_rowtype ) ;
00309 rt->name = NI_strdup( tname ) ;
00310 rt->userdef = NI_strdup( tdef ) ;
00311 rt->flag = 0 ;
00312
00313 /*-- loop over components in tdef, loading the new rt with their info --*/
00314
00315 rt->part_num = rt->comp_num = 0 ;
00316
00317 for( ii=0 ; ii < sar->num ; ii++ ){
00318
00319 tp = sar->str[ii] ;
00320 id = 0 ; kd = strlen(tp) ; /* type name of part will be in tp[id..kd-1] */
00321 if( kd == 0 ){
00322 delete_rowtype(rt); NI_delete_str_array(sar); ERREX("empty component name?");
00323 }
00324
00325 /* get count, if present, into jd */
00326
00327 sp = strchr(tp,'*') ; /* format of component string: count*type */
00328 bp = strchr(tp,'[') ; /* format of component string: type[count] */
00329
00330 if( sp != NULL || bp != NULL ){ /*** a count is present ***/
00331
00332 if( sp != NULL && bp != NULL ){ /* can't have both forms! */
00333 delete_rowtype(rt); NI_delete_str_array(sar); ERREX("two repeat counts?");
00334 }
00335
00336 if( sp != NULL ){ /* format: count*type */
00337 nn = 0 ; /* - count starts at nn */
00338 id = (sp-tp)+1 ; /* - type name starts at id */
00339 } else { /* format: type[count] */
00340 kd = (bp-tp) ; /* - type name ends at kd-1 */
00341 nn = kd+1 ; /* - count starts at nn */
00342 }
00343
00344 jd = -1 ;
00345 if( tp[nn] != '#' ){ /* count is a plain number */
00346 isdim = 0 ;
00347 sscanf( tp+nn , "%d" , &jd ) ;
00348 if( jd <= 0 ){
00349 delete_rowtype(rt); NI_delete_str_array(sar); ERREX("bad repeat number");
00350 }
00351 } else { /* count is a #reference */
00352 isdim = 1 ;
00353 sscanf( tp+nn+1 , "%d" , &jd ) ; /* ref must be to index */
00354 if( jd <= 0 || jd > ii ){ /* before this component */
00355 delete_rowtype(rt); NI_delete_str_array(sar); ERREX("bad #index");
00356 }
00357 if( rt->comp_typ[jd-1] != NI_INT || /* ref must be to an int */
00358 rt->comp_dim[jd-1] >= 0 ){ /* of fixed dim (1 int) */
00359 delete_rowtype(rt); NI_delete_str_array(sar); ERREX("non-int #index");
00360 }
00361 }
00362 } else {
00363 isdim = 0 ; jd = 1 ; /* default count of 1 */
00364 }
00365
00366 /* get the type of this component from its name */
00367
00368 if( kd-id < 1 || kd-id > 255 ){
00369 delete_rowtype(rt); NI_delete_str_array(sar); ERREX("toolong component name");
00370 }
00371
00372 NI_strncpy( str , tp+id , kd-id+1 ) ; /* copy component name into str */
00373 qt = NI_rowtype_find_name( str ) ; /* look it up in the table */
00374 if( qt == NULL ){
00375 delete_rowtype(rt); NI_delete_str_array(sar); ERREX("bad component type");
00376 }
00377
00378 if( !isdim ){ /*** fixed count: add jd copies of this component type ***/
00379
00380 rt->comp_typ = NI_realloc( rt->comp_typ, int, sizeof(int)*(rt->comp_num+jd) );
00381 rt->comp_dim = NI_realloc( rt->comp_dim, int, sizeof(int)*(rt->comp_num+jd) );
00382
00383 for( jj=0 ; jj < jd ; jj++ ){
00384 rt->comp_typ[rt->comp_num + jj] = qt->code ;
00385 rt->comp_dim[rt->comp_num + jj] = -1 ; /* fixed dim part */
00386 }
00387
00388 rt->comp_num += jd ; /* have more components now */
00389 rt->part_num += jd * qt->part_num ; /* have more parts now */
00390
00391 if( ROWTYPE_is_varsize(qt) ) /* if component is variable dim, */
00392 rt->flag |= ROWTYPE_VARSIZE_MASK ; /* mark rowtype as variable dim */
00393
00394 } else { /*** variable count: add 1 component that is a pointer */
00395 /*** to an array of fixed dim elements, */
00396 /*** dimension given in component #jd */
00397
00398 /* but can't have a var dim array of var dim arrays! */
00399
00400 if( ROWTYPE_is_varsize(qt) ){
00401 delete_rowtype(rt); NI_delete_str_array(sar);
00402 ERREX("variable dim array must have fixed dim type");
00403 }
00404
00405 rt->comp_typ = NI_realloc( rt->comp_typ, int, sizeof(int)*(rt->comp_num+1) );
00406 rt->comp_dim = NI_realloc( rt->comp_dim, int, sizeof(int)*(rt->comp_num+1) );
00407
00408 rt->comp_typ[rt->comp_num] = qt->code ; /* type this points to */
00409 rt->comp_dim[rt->comp_num] = jd-1 ; /* which component has */
00410 /* array dimension count */
00411 rt->comp_num ++ ; /* 1 more component */
00412 rt->part_num ++ ; /* and 1 more part */
00413
00414 rt->flag |= ROWTYPE_VARSIZE_MASK ; /* mark rowtype as variable dim */
00415
00416 }
00417
00418 } /* end of loop over components */
00419
00420 NI_delete_str_array(sar) ; /* done with this string array */
00421
00422 if( rt->part_num == 0 ){ delete_rowtype(rt); ERREX("no components?"); }
00423
00424 /*** now loop over components, breaking them down into their parts,
00425 storing the part types and their offsets into the C struct ***/
00426
00427 rt->part_off = NI_malloc(int, sizeof(int) * rt->part_num ) ;
00428 rt->part_typ = NI_malloc(int, sizeof(int) * rt->part_num ) ;
00429 rt->part_dim = NI_malloc(int, sizeof(int) * rt->part_num ) ;
00430 rt->part_siz = NI_malloc(int, sizeof(int) * rt->part_num ) ;
00431 rt->part_rtp = NI_malloc(NI_rowtype*, sizeof(NI_rowtype *) * rt->part_num ) ;
00432
00433 almax = 1 ; /* will be largest type_alignment of any part */
00434 cbase = 0 ; /* base offset into struct for next component */
00435 id = 0 ; /* part number we are about to work on */
00436
00437 for( ii=0 ; ii < rt->comp_num ; ii++ ){
00438
00439 /*** component is a ***/
00440 if( rt->comp_dim[ii] >= 0 ){ /*** variable dim array ***/
00441 /*** ==> store 1 pointer ***/
00442
00443 if( pointer_alignment > 1 ){ /* make sure cbase */
00444 jd = cbase % pointer_alignment ; /* is aligned OK */
00445 if( jd > 0 ) cbase += (pointer_alignment-jd) ;
00446 }
00447
00448 /* Note that this is the only case where a part_typ
00449 might end up as a derived type - normally, part_typ
00450 will be a builtin type code (NI_BYTE .. NI_STRING).
00451 Note the limitation that the type of variable dim
00452 arrays be a fixed dim type. */
00453
00454 rt->part_typ[id] = rt->comp_typ[ii] ;
00455 rt->part_off[id] = cbase ;
00456 rt->part_siz[id] = pointer_size ;
00457 rt->part_rtp[id] = NI_rowtype_find_code( rt->part_typ[id] ) ;
00458
00459 /* count number of parts before the dimension component into kd */
00460 /* so we can store the part index of this dimension component */
00461
00462 for( jd=kd=0 ; jd < rt->comp_dim[ii] ; jd++ ){
00463 if( rt->comp_dim[jd] >= 0 ){ /* this component is a pointer itself */
00464 kd++ ;
00465 } else { /* this component has fixed dim parts */
00466 qt = NI_rowtype_find_code( rt->comp_typ[jd] ) ;
00467 kd += qt->part_num ;
00468 }
00469 }
00470 rt->part_dim[id] = kd ; /* which part is the dimension of this part */
00471
00472 kd = pointer_alignment ;
00473 if( kd > almax ) almax = kd ;
00474
00475 id++ ; cbase += pointer_size ;
00476
00477 } else { /*** fixed dim type, possibly with multiple parts ***/
00478
00479 qt = NI_rowtype_find_code( rt->comp_typ[ii] ) ; /* component type */
00480
00481 /* adjust cbase upward if this component isn't properly aligned */
00482
00483 if( qt->algn > 1 ){
00484 jd = cbase % qt->algn ;
00485 if( jd > 0 ) cbase += (qt->algn-jd) ;
00486 }
00487
00488 pb = id ; /* part base index for this component */
00489 np = qt->part_num ; /* number of parts to add here */
00490
00491 rt->part_typ[id] = qt->part_typ[0] ; /* first part from component */
00492 rt->part_off[id] = cbase ; /* goes at the current base */
00493 rt->part_dim[id] = -1 ; /* 1st part cannot be variable dim array */
00494 rt->part_rtp[id] = NI_rowtype_find_code( rt->part_typ[id] ) ;
00495
00496 kd = rt->part_rtp[id]->algn ; /* alignment of part */
00497 if( kd > almax ) almax = kd ; /* keep track of largest alignment */
00498
00499 last_size = rt->part_rtp[id]->size ; /* size of 1st part */
00500 rt->part_siz[id] = last_size ;
00501
00502 id++ ; /* prepare to add next part */
00503
00504 /* loop over rest of parts from this component */
00505
00506 for( jj=1 ; jj < np ; jj++,id++ ){
00507
00508 rt->part_typ[id] = qt->part_typ[jj] ; /* type of new part */
00509 rt->part_rtp[id] = NI_rowtype_find_code( rt->part_typ[id] ) ;
00510
00511 if( qt->part_dim[jj] < 0 ){ /******* fixed dim part **/
00512
00513 nn = last_size ; /* # bytes in last part */
00514 jd = rt->part_off[id-1] ; /* offset of last part */
00515 kd = rt->part_rtp[id]->algn ; /* how to align new part */
00516 if( kd > almax ) almax = kd ; /* keep track of largest alignment */
00517
00518 nn += jd ; /* next available byte = sum of last offset and size */
00519 if( kd > 1 ){ /* must move nn up if */
00520 jd = nn % kd ; /* not on exact multiple */
00521 if( jd > 0 ) nn += (kd-jd) ; /* of jj bytes alignment */
00522 }
00523 rt->part_off[id] = nn ;
00524 rt->part_dim[id] = -1 ; /* mark as fixed dim part */
00525
00526 last_size = rt->part_rtp[id]->size ; /* size of this part */
00527 rt->part_siz[id] = last_size ;
00528
00529 } else { /***** variable dim array part **/
00530
00531 nn = last_size ;
00532 jd = rt->part_off[id-1] ;
00533 kd = pointer_alignment ; /* we are storing a pointer here */
00534 if( kd > almax ) almax = kd ;
00535 nn += jd ;
00536 if( kd > 1 ){
00537 jd = nn % kd ;
00538 if( jd > 0 ) nn += (kd-jd) ;
00539 }
00540 rt->part_off[id] = nn ;
00541 last_size = pointer_size ;
00542 rt->part_siz[id] = last_size ;
00543
00544 /* qt->part_dim[jj] is the part index in qt
00545 of the dimension for this variable dim array part;
00546 we must convert that to a part index in the new rowtype */
00547
00548 rt->part_dim[id] = pb + qt->part_dim[jj] ;
00549
00550 }
00551
00552 } /* end of loop over parts within this component */
00553
00554 /* now move the base offset up by the size of the current
00555 component (which may be bigger than the sum of its parts) */
00556
00557 cbase += qt->size ;
00558
00559 } /* end of fixed dim component part-izing */
00560
00561 } /* end of loop over components */
00562
00563 /* now compute the overall size of this new rowtype:
00564 at this point,
00565 cbase = next byte offset available after last part;
00566 this would be the size, but may have to be pushed
00567 up to allow for byte alignment of this rowtype */
00568
00569 rt->algn = almax ;
00570 if( rt->algn > 1 ){
00571 jd = cbase % rt->algn ;
00572 if( jd > 0 ) cbase += (rt->algn-jd) ;
00573 }
00574 rt->size = cbase ; /* this size is the sizeof(struct),
00575 and doesn't include var dim arrays or
00576 Strings, just the pointers to those things */
00577
00578 /* 26 Dec 2002: Compute the sum of the part sizes
00579 (zero if this has variable dim arrays).
00580 If rt->psiz == rt->size, then
00581 struct is stored without padding bytes. */
00582
00583 rt->psiz = 0 ;
00584 if( !ROWTYPE_is_varsize(rt) ){
00585 for( ii=0 ; ii < rt->part_num ; ii++ )
00586 rt->psiz += rt->part_siz[ii] ;
00587 }
00588
00589 /* 28 Oct 2004: Move assignment of the new rowtype code to the end,
00590 since a recursive call via NI_rowtype_find_name()
00591 might have created a new rowtype before this one.
00592 An example definition: "int,VECTOR_float_32,int". */
00593
00594 rt->code = ROWTYPE_BASE_CODE + rowtype_num ;
00595
00596 /** debugging printouts **/
00597
00598 if( ROWTYPE_debug ){
00599 fprintf(stderr,"\n") ;
00600 fprintf(stderr,"NI_rowtype_define: '%s' = '%s'\n",tname,tdef) ;
00601 fprintf(stderr," code = %d\n",rt->code) ;
00602 fprintf(stderr," size = %d\n",rt->size) ;
00603 fprintf(stderr," psiz = %d\n",rt->psiz) ;
00604 fprintf(stderr," algn = %d\n",rt->algn) ;
00605 fprintf(stderr," flag = %d\n",rt->flag) ;
00606
00607 fprintf(stderr," comp_num = %d\n",rt->part_num) ;
00608
00609 fprintf(stderr," comp_typ = " ) ;
00610 for( ii=0 ; ii < rt->comp_num ; ii++ ) fprintf(stderr,"%4d ",rt->comp_typ[ii]) ;
00611 fprintf(stderr,"\n") ;
00612
00613 fprintf(stderr," comp_dim = " ) ;
00614 for( ii=0 ; ii < rt->comp_num ; ii++ ) fprintf(stderr,"%4d ",rt->comp_dim[ii]) ;
00615 fprintf(stderr,"\n") ;
00616
00617 fprintf(stderr," part_num = %d\n",rt->part_num) ;
00618
00619 fprintf(stderr," part_typ = " ) ;
00620 for( ii=0 ; ii < rt->part_num ; ii++ ) fprintf(stderr,"%4d ",rt->part_typ[ii]) ;
00621 fprintf(stderr,"\n") ;
00622
00623 fprintf(stderr," part_off = " ) ;
00624 for( ii=0 ; ii < rt->part_num ; ii++ ) fprintf(stderr,"%4d ",rt->part_off[ii]) ;
00625 fprintf(stderr,"\n") ;
00626
00627 fprintf(stderr," part_siz = " ) ;
00628 for( ii=0 ; ii < rt->part_num ; ii++ ) fprintf(stderr,"%4d ",rt->part_siz[ii]) ;
00629 fprintf(stderr,"\n") ;
00630
00631 fprintf(stderr," part_dim = " ) ;
00632 for( ii=0 ; ii < rt->part_num ; ii++ ) fprintf(stderr,"%4d ",rt->part_dim[ii]) ;
00633 fprintf(stderr,"\n") ;
00634 }
00635
00636 /* save this in the table of rowtypes,
00637 and return the numerical code for this new type */
00638
00639 ROWTYPE_register(rt) ;
00640 return rt->code ;
00641 }
|
|
|
Find a rowtype by its integer code. Definition at line 735 of file niml_rowtype.c. References ROWTYPE_BASE_CODE, rowtype_num, ROWTYPE_OFFSET, and setup_basic_types(). Referenced by NI_add_column(), NI_add_column_stride(), NI_alter_veclen(), NI_fill_column_stride(), NI_free_element(), NI_insert_value(), NI_read_columns(), NI_rowtype_code_to_name(), NI_rowtype_code_to_size(), NI_rowtype_define(), NI_write_columns(), NI_write_element(), and SUMA_MaskedCopyofDset().
00736 {
00737 if( nn < 0 ) return NULL ;
00738 if( rowtype_table == NULL ) setup_basic_types() ;
00739 if( nn >= ROWTYPE_OFFSET ) nn = nn - ROWTYPE_BASE_CODE ;
00740 if( nn < 0 || nn >= rowtype_num ) return NULL ;
00741 return rowtype_array[nn] ;
00742 }
|
|
|
Find a rowtype by its name. 19 Feb 2003: or its alias. 28 Oct 2004: If name is of form VECTOR_basictype_length, then a new rowtype is created on the spot; e.g., "VECTOR_float_32" is like "float[32]". Definition at line 670 of file niml_rowtype.c. References findin_Htable(), NI_NUM_BASIC_TYPES, NI_rowtype_define(), ROWTYPE_BASE_CODE, ROWTYPE_OFFSET, setup_basic_types(), tt, type_alias, and type_name. Referenced by NI_rowtype_define(), NI_rowtype_name_to_code(), and NI_rowtype_name_to_size().
00671 {
00672 NI_rowtype *rt ; int ii ;
00673 static int busy=0 ; /* 28 Oct 2004: prevent recursion */
00674
00675 if( nn == NULL || *nn == '\0' ) return NULL ;
00676 if( rowtype_table == NULL ) setup_basic_types() ;
00677 rt = (NI_rowtype *) findin_Htable(nn,rowtype_table) ;
00678 if( rt != NULL ) return rt ;
00679
00680 /* 19 Feb 2003: linear search for basic type alias */
00681
00682 for( ii=0 ; ii <= NI_NUM_BASIC_TYPES ; ii++ )
00683 if( strcmp(type_alias[ii],nn) == 0 ) return rowtype_array[ii] ;
00684
00685 /*-- 28 Oct 2004: Define fixed size vector types here and now:
00686 format of nn must be VECTOR_basictype_length --*/
00687
00688 if( busy ) return NULL ; /* cannot allow re-entry below here! */
00689
00690 ii = strlen(nn) ;
00691 if( ii < 12 || strncmp(nn,"VECTOR_",7) != 0 || strchr(nn+7,'_') == NULL )
00692 return NULL ;
00693
00694 { char bt[32] , rt[64] ; int tt , dd ;
00695
00696 /* extract basic type name (after "VECTOR_") into bt array */
00697
00698 for( ii=7 ; ii < 32 && nn[ii] != '\0' && nn[ii] != '_' ; ii++ )
00699 bt[ii-7] = nn[ii] ;
00700 if( nn[ii] != '_' ) return NULL ; /* bad end of basic type name */
00701 bt[ii-7] = '\0' ; /* terminate with NUL byte */
00702
00703 /* find bt name in basic type name list (or alias list) */
00704
00705 for( tt=0 ; tt <= NI_NUM_BASIC_TYPES ; tt++ )
00706 if( strcmp(type_name[tt],bt) == 0 ) break ;
00707
00708 if( tt > NI_NUM_BASIC_TYPES ){
00709 for( tt=0 ; tt <= NI_NUM_BASIC_TYPES ; tt++ )
00710 if( strcmp(type_alias[tt],bt) == 0 ) break ;
00711 if( tt > NI_NUM_BASIC_TYPES ) return NULL ;
00712 }
00713
00714 /* find dimension after the nn[ii] character, which is '_' */
00715
00716 dd = 0 ; sscanf( nn+ii+1 , "%d" , &dd ) ;
00717 if( dd <= 0 ) return NULL ;
00718
00719 /* ready to create a new rowtype now */
00720
00721 sprintf(rt,"%s[%d]",type_name[tt],dd) ;
00722
00723 busy = 1 ; /* prevent recursion!!! */
00724 tt = NI_rowtype_define( nn , rt ) ;
00725 busy = 0 ;
00726 if( tt >= ROWTYPE_OFFSET ) return rowtype_array[tt-ROWTYPE_BASE_CODE] ;
00727 }
00728
00729 return NULL ;
00730 }
|
|
|
Given a rowtype name, find its integer code. Returns -1 if the name isn't found in the rowtype table. ---------------------------------------------------------------------- Definition at line 749 of file niml_rowtype.c. References NI_rowtype::code, and NI_rowtype_find_name(). Referenced by decode_type_field().
00750 {
00751 NI_rowtype *rt = NI_rowtype_find_name( nn ) ;
00752 if( rt != NULL ) return rt->code ;
00753 return -1 ;
00754 }
|
|
|
Given a rowtype name, find its struct size in bytes.
Definition at line 794 of file niml_rowtype.c. References NI_rowtype_find_name(), and NI_rowtype::size.
00795 {
00796 NI_rowtype *rt = NI_rowtype_find_name( nn ) ;
00797 if( rt != NULL ) return rt->size ;
00798 return -1 ;
00799 }
|
|
|
Make an 'ni_do' element that defines a given rowtype. Definition at line 646 of file niml_rowtype.c. References NI_rowtype::name, NI_free, NI_malloc, NI_new_processing_instruction(), NI_set_attribute(), and NI_rowtype::userdef.
00647 {
00648 NI_procins *npi ;
00649 char *rhs ;
00650
00651 if( rt == NULL ) return NULL ;
00652
00653 npi = NI_new_processing_instruction( "ni_do" ) ;
00654 NI_set_attribute( npi , "ni_verb" , "typedef" ) ;
00655
00656 rhs = NI_malloc(char,strlen(rt->name)+strlen(rt->userdef)+4) ;
00657 sprintf( rhs , "%s %s" , rt->name , rt->userdef ) ;
00658 NI_set_attribute( npi , "ni_object" , rhs ) ;
00659 NI_free( rhs ) ;
00660 return npi ;
00661 }
|
|
||||||||||||
|
Compute the size of all the data in a struct defined in a NI_rowtype (not including padding), for this instance of the struct, allowing for variable array parts. Zero is returned if something bad happens. ------------------------------------------------------------------------- Definition at line 830 of file niml_rowtype.c. References NI_STRING, NI_strlen(), NI_rowtype::part_dim, NI_rowtype::part_num, NI_rowtype::part_rtp, NI_rowtype::part_siz, NI_rowtype::part_typ, NI_rowtype::psiz, ROWTYPE_is_varsize, and ROWTYPE_part_dimen. Referenced by NI_size_column(), and NI_write_columns().
00831 {
00832 int ii,jj , ss ;
00833 char *dat = (char *)dpt ;
00834
00835 if( rt == NULL ) return 0; /* nonsense input */
00836 if( !ROWTYPE_is_varsize(rt) ) return rt->psiz; /* fixed dim struct */
00837 if( dat == NULL ) return 0; /* var size with no data? */
00838
00839 /* loop over parts, adding up part sizes,
00840 including var dim arrays and String parts */
00841
00842 for( ii=ss=0 ; ii < rt->part_num ; ii++ ){
00843 if( rt->part_typ[ii] == NI_STRING ){ /* String is special */
00844 char *str = *((char **)((dat) + (rt)->part_off[ii])) ;
00845 ss += NI_strlen(str) ;
00846 } else if( rt->part_dim[ii] < 0 ){ /* 1 fixed dim type */
00847 ss += rt->part_siz[ii] ;
00848 } else { /* var dim array */
00849 jj = ROWTYPE_part_dimen(rt,dat,ii) ; /* array size */
00850 ss += jj * rt->part_rtp[ii]->psiz ; /* size of all parts */
00851 } /* in var dim array */
00852 }
00853
00854 return ss ;
00855 }
|
|
||||||||||||||||
|
Return a list of all elements in a group that have a given name.
Definition at line 1064 of file niml_element.c. References NI_element_name(), NI_element_type(), NI_free, NI_GROUP_TYPE, NI_realloc, NI_group::part, NI_group::part_num, and NI_group::type. Referenced by THD_open_nifti().
01065 {
01066 void **nelar=NULL , *nini ;
01067 int ii , nn=0 ;
01068 char *nm ;
01069
01070 if( ngr == NULL || ngr->type != NI_GROUP_TYPE ) return 0 ;
01071 if( enam == NULL || *enam == '\0' || nipt == NULL ) return 0 ;
01072 if( ngr->part_num == 0 ) return 0 ;
01073
01074 for( ii=0 ; ii < ngr->part_num ; ii++ ){
01075 nini = ngr->part[ii] ;
01076 nm = NI_element_name( nini ) ;
01077 if( nm != NULL && strcmp(nm,enam) == 0 ){
01078 nelar = (void **) NI_realloc(nelar,void*,nn+1) ;
01079 nelar[nn++] = nini ;
01080 }
01081 if( NI_element_type(nini) == NI_GROUP_TYPE ){ /* recursion */
01082 int nsub , jj ; void **esub ;
01083 nsub = NI_search_group_deep( nini , enam , &esub ) ;
01084 if( nsub > 0 ){
01085 nelar = (void **) NI_realloc(nelar,void*,nn+nsub) ;
01086 for( jj=0 ; jj < nsub ; jj++ ) nelar[nn++] = esub[jj] ;
01087 NI_free(esub) ;
01088 }
01089 }
01090 }
01091
01092 if( nn > 0 ) *nipt = nelar ;
01093 return nn ;
01094 }
|
|
||||||||||||||||
|
Return a list of all elements in a group that have a given name.
Definition at line 1023 of file niml_element.c. References NI_element_name(), NI_GROUP_TYPE, NI_realloc, NI_group::part, NI_group::part_num, and NI_group::type.
01024 {
01025 void **nelar=NULL , *nini ;
01026 int ii , nn=0 ;
01027 char *nm ;
01028
01029 if( ngr == NULL || ngr->type != NI_GROUP_TYPE ) return 0 ;
01030 if( enam == NULL || *enam == '\0' || nipt == NULL ) return 0 ;
01031 if( ngr->part_num == 0 ) return 0 ;
01032
01033 for( ii=0 ; ii < ngr->part_num ; ii++ ){
01034 nini = ngr->part[ii] ;
01035 nm = NI_element_name( nini ) ;
01036 if( nm != NULL && strcmp(nm,enam) == 0 ){
01037 nelar = (void **) NI_realloc(nelar,void*,nn+1) ;
01038 nelar[nn++] = nini ;
01039 }
01040 }
01041
01042 if( nn > 0 ) *nipt = nelar ;
01043 return nn ;
01044 }
|
|
|
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 }
|
|
||||||||||||||||
|
Add an attribute to a data or group element. If an attribute with the same attname already exists, then it will be replaced with this one. -------------------------------------------------------------------------- Definition at line 672 of file niml_element.c. References NI_element::attr_lhs, NI_group::attr_lhs, NI_procins::attr_lhs, NI_element::attr_num, NI_group::attr_num, NI_procins::attr_num, NI_element::attr_rhs, NI_group::attr_rhs, NI_procins::attr_rhs, NI_element_type(), NI_ELEMENT_TYPE, NI_free, NI_GROUP_TYPE, NI_PROCINS_TYPE, NI_realloc, NI_strdup(), and tt. Referenced by AFNI_niml_redisplay_CB(), AFNI_niml_viewpoint_CB(), AFNI_version_check(), DWI_NIML_create_graph(), main(), mri_to_niml(), NI_rowtype_procins(), NI_write_element(), nifti_set_afni_extension(), SUMA_AddColAttr(), SUMA_AddGenColAttr(), SUMA_AddNelHist(), SUMA_CreateDsetPointer(), SUMA_Engine(), SUMA_FakeIt(), SUMA_LoadDsetFile(), SUMA_makeNI_SurfIJK(), SUMA_makeNI_SurfINORM(), SUMA_makeNI_SurfIXYZ(), SUMA_Mesh_IJK2Mesh_IJK_nel(), SUMA_NewDsetGrp(), SUMA_NewDsetID(), SUMA_NewNel(), SUMA_nimlSO2SO(), SUMA_NodeVal2irgba_nel(), SUMA_NodeXYZ2NodeXYZ_nel(), SUMA_oDsetNel2nDsetNgr(), SUMA_Paint_SO_ROIplanes(), SUMA_SaveVisualState(), SUMA_SendDset_Afni(), SUMA_SendToSuma(), SUMA_SO2nimlSO(), SUMA_SOVolPar2VolPar_nel(), SUMA_Write_DrawnROI_NIML(), SUMA_WriteDset(), THD_nimlize_dsetatr(), THD_subbrick_to_niml(), THD_write_nimlatr(), and XSAVE_output().
00673 {
00674 int nn , tt=NI_element_type(nini) ;
00675
00676 if( tt < 0 || attname == NULL || attname[0] == '\0' ) return ;
00677
00678 /* input is a data element */
00679
00680 if( tt == NI_ELEMENT_TYPE ){
00681 NI_element *nel = (NI_element *) nini ;
00682
00683 /* see if name is already in element header */
00684
00685 for( nn=0 ; nn < nel->attr_num ; nn++ )
00686 if( strcmp(nel->attr_lhs[nn],attname) == 0 ) break ;
00687
00688 /* if not, then add a header attribute */
00689
00690 if( nn == nel->attr_num ){
00691 nel->attr_lhs = NI_realloc( nel->attr_lhs, char*, sizeof(char *)*(nn+1) );
00692 nel->attr_rhs = NI_realloc( nel->attr_rhs, char*, sizeof(char *)*(nn+1) );
00693 nel->attr_num = nn+1 ;
00694 } else {
00695 NI_free(nel->attr_lhs[nn]) ; /* free old attribute */
00696 NI_free(nel->attr_rhs[nn]) ;
00697 }
00698
00699 nel->attr_lhs[nn] = NI_strdup(attname) ;
00700 nel->attr_rhs[nn] = NI_strdup(attvalue);
00701
00702 /* input is a group element */
00703
00704 } else if( tt == NI_GROUP_TYPE ){
00705 NI_group *ngr = (NI_group *) nini ;
00706
00707 for( nn=0 ; nn < ngr->attr_num ; nn++ )
00708 if( strcmp(ngr->attr_lhs[nn],attname) == 0 ) break ;
00709
00710 if( nn == ngr->attr_num ){
00711 ngr->attr_lhs = NI_realloc( ngr->attr_lhs, char*, sizeof(char *)*(nn+1) );
00712 ngr->attr_rhs = NI_realloc( ngr->attr_rhs, char*, sizeof(char *)*(nn+1) );
00713 ngr->attr_num = nn+1 ;
00714 } else {
00715 NI_free(ngr->attr_lhs[nn]) ;
00716 NI_free(ngr->attr_rhs[nn]) ;
00717 }
00718
00719 ngr->attr_lhs[nn] = NI_strdup(attname) ;
00720 ngr->attr_rhs[nn] = NI_strdup(attvalue);
00721
00722 /* input is a processing instruction */
00723
00724 } else if( tt == NI_PROCINS_TYPE ){
00725 NI_procins *npi = (NI_procins *) nini ;
00726
00727 for( nn=0 ; nn < npi->attr_num ; nn++ )
00728 if( strcmp(npi->attr_lhs[nn],attname) == 0 ) break ;
00729
00730 if( nn == npi->attr_num ){
00731 npi->attr_lhs = NI_realloc( npi->attr_lhs, char*, sizeof(char *)*(nn+1) );
00732 npi->attr_rhs = NI_realloc( npi->attr_rhs, char*, sizeof(char *)*(nn+1) );
00733 npi->attr_num = nn+1 ;
00734 } else {
00735 NI_free(npi->attr_lhs[nn]) ;
00736 NI_free(npi->attr_rhs[nn]) ;
00737 }
00738
00739 npi->attr_lhs[nn] = NI_strdup(attname) ;
00740 npi->attr_rhs[nn] = NI_strdup(attvalue);
00741 }
00742
00743 return ;
00744 }
|
|
|
|
|
|
Set the mode for writing type names:
Definition at line 877 of file niml_elemio.c. References name_mode, NI_ATTMODE_LAST, and NI_NAMEMODE_NORMAL.
00878 {
00879 if( nmode > 0 && nmode <= NI_ATTMODE_LAST ) name_mode = nmode ;
00880 else name_mode = NI_NAMEMODE_NORMAL;
00881 }
|
|
||||||||||||
|
|
|
|
Set the range in a vector struct. Definition at line 42 of file niml_vector.c. References rgba::a, rgb::b, rgba::b, rgb::g, rgba::g, complex::i, NI_BYTE, NI_COMPLEX, NI_datatype_size, NI_DOUBLE, NI_FLOAT, NI_index_t, NI_INT, NI_is_builtin_type, NI_is_vector_type, NI_malloc, NI_RGB, NI_RGBA, NI_SHORT, NI_STRING, complex::r, rgb::r, rgba::r, NI_vector::vec, NI_vector::vec_len, NI_vector::vec_range, and NI_vector::vec_typ. Referenced by NI_dataset_transpose().
00043 {
00044 NI_vector *nv = (NI_vector *)nvv ;
00045 NI_index_t len, ii ;
00046
00047 if( nv == NULL ||
00048 !NI_is_vector_type(nv->type) ||
00049 !NI_is_builtin_type(nv->vec_typ) ||
00050 nv->vec_typ == NI_STRING ) return ;
00051
00052 len = nv->vec_len ; if( len <= 0 ) return ;
00053
00054 if( nv->vec_range == NULL )
00055 nv->vec_range = NI_malloc(void, 2*NI_datatype_size(nv->vec_typ) ) ;
00056
00057 switch( nv->vec_typ ){ /* no default */
00058
00059 case NI_BYTE:{
00060 byte *vv = (byte *)nv->vec ;
00061 byte *vr = (byte *)nv->vec_range ;
00062 byte vbot=vv[0], vtop=vv[0] ;
00063 for( ii=1 ; ii < len ; ii++ )
00064 if( vv[ii] < vbot ) vbot = vv[ii] ;
00065 else if( vv[ii] > vtop ) vtop = vv[ii] ;
00066 vr[0] = vbot ; vr[1] = vtop ;
00067 }
00068 break ;
00069
00070 case NI_SHORT:{
00071 short *vv = (short *)nv->vec ;
00072 short *vr = (short *)nv->vec_range ;
00073 short vbot=vv[0], vtop=vv[0] ;
00074 for( ii=1 ; ii < len ; ii++ )
00075 if( vv[ii] < vbot ) vbot = vv[ii] ;
00076 else if( vv[ii] > vtop ) vtop = vv[ii] ;
00077 vr[0] = vbot ; vr[1] = vtop ;
00078 }
00079 break ;
00080
00081 case NI_INT:{
00082 int *vv = (int *)nv->vec ;
00083 int *vr = (int *)nv->vec_range ;
00084 int vbot=vv[0], vtop=vv[0] ;
00085 for( ii=1 ; ii < len ; ii++ )
00086 if( vv[ii] < vbot ) vbot = vv[ii] ;
00087 else if( vv[ii] > vtop ) vtop = vv[ii] ;
00088 vr[0] = vbot ; vr[1] = vtop ;
00089 }
00090 break ;
00091
00092 case NI_FLOAT:{
00093 float *vv = (float *)nv->vec ;
00094 float *vr = (float *)nv->vec_range ;
00095 float vbot=vv[0], vtop=vv[0] ;
00096 for( ii=1 ; ii < len ; ii++ )
00097 if( vv[ii] < vbot ) vbot = vv[ii] ;
00098 else if( vv[ii] > vtop ) vtop = vv[ii] ;
00099 vr[0] = vbot ; vr[1] = vtop ;
00100 }
00101 break ;
00102
00103 case NI_DOUBLE:{
00104 double *vv = (double *)nv->vec ;
00105 double *vr = (double *)nv->vec_range ;
00106 double vbot=vv[0], vtop=vv[0] ;
00107 for( ii=1 ; ii < len ; ii++ )
00108 if( vv[ii] < vbot ) vbot = vv[ii] ;
00109 else if( vv[ii] > vtop ) vtop = vv[ii] ;
00110 vr[0] = vbot ; vr[1] = vtop ;
00111 }
00112 break ;
00113
00114 case NI_COMPLEX:{
00115 complex *vv = (complex *)nv->vec ;
00116 complex *vr = (complex *)nv->vec_range ;
00117 complex vbot=vv[0], vtop=vv[0] ;
00118 for( ii=1 ; ii < len ; ii++ ){
00119 if( vv[ii].r < vbot.r ) vbot.r = vv[ii].r ;
00120 else if( vv[ii].r > vtop.r ) vtop.r = vv[ii].r ;
00121 if( vv[ii].i < vbot.i ) vbot.i = vv[ii].i ;
00122 else if( vv[ii].i > vtop.i ) vtop.i = vv[ii].i ;
00123 }
00124 vr[0] = vbot ; vr[1] = vtop ;
00125 }
00126 break ;
00127
00128 case NI_RGB:{
00129 rgb *vv = (rgb *)nv->vec ;
00130 rgb *vr = (rgb *)nv->vec_range ;
00131 rgb vbot=vv[0], vtop=vv[0] ;
00132 for( ii=1 ; ii < len ; ii++ ){
00133 if( vv[ii].r < vbot.r ) vbot.r = vv[ii].r ;
00134 else if( vv[ii].r > vtop.r ) vtop.r = vv[ii].r ;
00135 if( vv[ii].g < vbot.g ) vbot.g = vv[ii].g ;
00136 else if( vv[ii].g > vtop.g ) vtop.g = vv[ii].g ;
00137 if( vv[ii].b < vbot.b ) vbot.b = vv[ii].b ;
00138 else if( vv[ii].b > vtop.b ) vtop.b = vv[ii].b ;
00139 }
00140 vr[0] = vbot ; vr[1] = vtop ;
00141 }
00142 break ;
00143
00144 case NI_RGBA:{
00145 rgba *vv = (rgba *)nv->vec ;
00146 rgba *vr = (rgba *)nv->vec_range ;
00147 rgba vbot=vv[0], vtop=vv[0] ;
00148 for( ii=1 ; ii < len ; ii++ ){
00149 if( vv[ii].r < vbot.r ) vbot.r = vv[ii].r ;
00150 else if( vv[ii].r > vtop.r ) vtop.r = vv[ii].r ;
00151 if( vv[ii].g < vbot.g ) vbot.g = vv[ii].g ;
00152 else if( vv[ii].g > vtop.g ) vtop.g = vv[ii].g ;
00153 if( vv[ii].b < vbot.b ) vbot.b = vv[ii].b ;
00154 else if( vv[ii].b > vtop.b ) vtop.b = vv[ii].b ;
00155 if( vv[ii].a < vbot.a ) vbot.a = vv[ii].a ;
00156 else if( vv[ii].a > vtop.a ) vtop.a = vv[ii].a ;
00157 }
00158 vr[0] = vbot ; vr[1] = vtop ;
00159 }
00160 break ;
00161
00162 }
00163
00164 return ;
00165 }
|
|
||||||||||||||||
|
Return the length in bytes of a column of data (not counting padding). The pointer to the data is needed since it might contain variable size data (String or vardim arrays). ---------------------------------------------------------------------------- Definition at line 2086 of file niml_rowtype.c. References NI_rowtype_vsize(), NI_rowtype::psiz, ROWTYPE_is_varsize, and NI_rowtype::size. Referenced by NI_write_element().
02087 {
02088 char *dat = (char *)cpt ;
02089 int ii , ndat ;
02090
02091 if( rt == NULL || col_len <= 0 )
02092 return 0; /* nonsense input */
02093 if( !ROWTYPE_is_varsize(rt) || dat == NULL )
02094 return (col_len*rt->psiz); /* fixed dim struct */
02095
02096 /* must loop through elements and add up their variable sizes */
02097
02098 ndat = 0 ;
02099 for( ii=0 ; ii < col_len ; ii++ )
02100 ndat += NI_rowtype_vsize( rt , dat + ii*rt->size ) ;
02101
02102 return ndat ;
02103 }
|
|
|
Definition at line 80 of file niml_elemio.c. References r, and skip_procins. Referenced by THD_load_3D(), and THD_open_3D().
00080 { skip_procins = r ; } /* 03 Jun 2005 */
|
|
|
Sleep a given # of milliseconds (uses the Unix select routine). --------------------------------------------------------------------- Definition at line 44 of file niml_util.c. Referenced by AFNI_faceup(), AFNI_serverlog(), AIVVV_niml_quitter(), AIVVV_workproc(), atexit_open_streams(), hidden_NI_malloc(), hidden_NI_realloc(), main(), NI_read_element(), NI_stream_close_keep(), NI_stream_goodcheck(), SHM_fill_accept(), SHM_goodcheck(), SHM_init(), SHM_nattach(), SHM_readcheck(), SHM_sendall(), SHM_writecheck(), SUMA_process_NIML_data(), and SUMA_SendToSuma().
00045 {
00046 struct timeval tv ;
00047 if( msec <= 0 ) return ; /* can't wait into the past */
00048 tv.tv_sec = msec/1000 ;
00049 tv.tv_usec = (msec%1000)*1000 ;
00050 select( 1 , NULL,NULL,NULL , &tv ) ;
00051 return ;
00052 }
|
|
||||||||||||||||||||||||
|
Definition at line 141 of file niml_stat.c. References NI_stat_distname(), NI_STAT_FIRSTCODE, NI_STAT_LASTCODE, and NI_stat_numparam(). Referenced by THD_datablock_from_atr().
00142 {
00143 int jj , ll ;
00144 char *dnam , qnam[64] ;
00145
00146 if( scode == NULL ) return ; /* bad input */
00147 *scode = 0 ;
00148 if( str == NULL || *str == '\0' ) return ; /* bad input */
00149
00150 /* scan for distribution name */
00151
00152 for( jj=NI_STAT_FIRSTCODE ; jj <= NI_STAT_LASTCODE ; jj++ ){
00153 dnam = NI_stat_distname(jj) ;
00154 strcpy(qnam,dnam); strcat(qnam,"("); ll = strlen(qnam);
00155 if( strncasecmp(str,qnam,ll) == 0 ) break ;
00156 }
00157 if( jj <= NI_STAT_LASTCODE ){
00158 float parm[3]={1.0f,1.0f,1.0f} ; int np,kk,mm , sp ;
00159 np = NI_stat_numparam(jj) ; sp = ll ;
00160 for( kk=0 ; kk < np ; kk++ ){
00161 mm = 0 ; sscanf(str+sp,"%f%n",parm+kk,&mm) ; sp += mm+1 ;
00162 }
00163 *scode = jj ; /* Save results */
00164 if( p1 != NULL ) *p1 = parm[0] ; /* into output */
00165 if( p2 != NULL ) *p2 = parm[1] ; /* variables. */
00166 if( p3 != NULL ) *p3 = parm[2] ;
00167 }
00168 return ;
00169 }
|
|
|
Definition at line 30 of file niml_stat.c. References distname, and NI_STAT_LASTCODE. Referenced by NI_stat_decode(), THD_open_3D(), and THD_write_1D().
00031 {
00032 return distname[(scode >=0 && scode <= NI_STAT_LASTCODE) ? scode : 0] ;
00033 }
|
|
||||||||||||||||||||
|
Definition at line 101 of file niml_stat.c. References distname, malloc, NI_fval_to_char(), NI_STAT_LASTCODE, and NI_stat_numparam(). Referenced by THD_set_dataset_attributes().
00102 {
00103 char *buf , *nam , b1[16] , b2[16] , b3[16] ;
00104 int np ;
00105
00106 if( scode < NI_STAT_FIRSTCODE || scode > NI_STAT_LASTCODE ){
00107 buf = strdup("none") ; return buf ;
00108 }
00109
00110 np = NI_stat_numparam( scode ) ; /* # of parameters */
00111 nam = distname[scode] ; /* distribution name */
00112 buf = malloc( 20*(np+1) ) ; /* output buffer */
00113 switch( np ){
00114 case 0:
00115 sprintf(buf,"%s()",nam) ; break ;
00116
00117 case 1:
00118 NI_fval_to_char( p1 , b1 ) ;
00119 sprintf(buf,"%s(%s)",nam,b1) ; break ;
00120
00121 case 2:
00122 NI_fval_to_char( p1 , b1 ) ;
00123 NI_fval_to_char( p2 , b2 ) ;
00124 sprintf(buf,"%s(%s,%s)",nam,b1,b2) ; break ;
00125
00126 default:
00127 case 3:
00128 NI_fval_to_char( p1 , b1 ) ;
00129 NI_fval_to_char( p2 , b2 ) ;
00130 NI_fval_to_char( p3 , b3 ) ;
00131 sprintf(buf,"%s(%s,%s,%s)",nam,b1,b2,b3) ; break ;
00132 }
00133
00134 return buf ;
00135 }
|
|
|
Definition at line 23 of file niml_stat.c. References NI_STAT_LASTCODE, and numparam. Referenced by NI_stat_decode(), NI_stat_encode(), THD_datablock_from_atr(), THD_open_3D(), and THD_write_1D().
00024 {
00025 return numparam[(scode >=0 && scode <= NI_STAT_LASTCODE) ? scode : 0] ;
00026 }
|
|
|
Like strdup, but better (input=NULL ==> output=NULL). -------------------------------------------------------------------------- Definition at line 141 of file niml_util.c. References NI_malloc, and NI_strlen(). Referenced by make_empty_data_element(), NI_copy_column(), NI_copy_struct(), NI_dataset_transpose(), NI_hostname_to_inet(), NI_insert_value(), NI_new_data_element(), NI_new_processing_instruction(), NI_read_element(), NI_register_doer(), NI_rename_group(), NI_rowtype_define(), NI_set_attribute(), NI_set_axes(), NI_set_units(), quotize_float_vector(), setup_basic_types(), and tcp_accept().
|
|
|
Clear the buffer of a str: writing NI_stream. This is intended to let you write anew without having to close and open again. ------------------------------------------------------------------------- Definition at line 2219 of file niml_stream.c. References NI_stream_type::buf, NI_stream_type::bufsize, NI_stream_type::io_mode, NI_stream_type::nbuf, NI_free, NI_malloc, NI_OUTPUT_MODE, NI_STRING_TYPE, and NI_stream_type::type.
02220 {
02221 if( ns == NULL ||
02222 ns->type != NI_STRING_TYPE ||
02223 ns->io_mode != NI_OUTPUT_MODE ) return ; /* bad inputs */
02224
02225 NI_free(ns->buf) ;
02226 ns->nbuf = 0 ;
02227 ns->bufsize = 1 ;
02228 ns->buf = NI_malloc(char, 1) ; /* 1 byte set to zero */
02229 }
|
|
|
|
Close a NI_stream without sending a "close_this" message to the other end of the stream. Definition at line 2469 of file niml_stream.c. References NI_free, and NI_stream_close_keep(). Referenced by AFNI_niml_atexit(), AFNI_niml_workproc(), AFNI_serverlog(), AIVVV_niml_quitter(), AIVVV_workproc(), main(), NI_stream_reopen(), NI_suck_stream(), and NIML_to_stderr().
02470 {
02471 NI_stream_close_keep(ns,0) ; NI_free(ns) ; return ;
02472 }
|
|
|
Return the output string buffer for a NI_stream of str: type. If the input is not a "w" str: stream, then NULL is returned. Otherwise a pointer to the internal buffer is returned. This will be a NUL terminated string. ------------------------------------------------------------------------- Definition at line 2204 of file niml_stream.c. References NI_stream_type::bad, NI_stream_type::buf, NI_stream_type::io_mode, MARKED_FOR_DEATH, NI_OUTPUT_MODE, NI_STRING_TYPE, and NI_stream_type::type. Referenced by Dtable_to_nimlstring(), main(), nifti_set_afni_extension(), and SUMA_DsetInfo().
02205 {
02206 if( ns == NULL ||
02207 ns->type != NI_STRING_TYPE ||
02208 ns->io_mode != NI_OUTPUT_MODE ||
02209 ns->bad == MARKED_FOR_DEATH ) return NULL ; /* bad inputs */
02210
02211 return ns->buf ;
02212 }
|
|
|
Get the input buffer size for a NI_stream. Returns -1 if the stream is bad, or has been sentenced to death. ------------------------------------------------------------------------- Definition at line 2191 of file niml_stream.c. References NI_stream_type::bad, NI_stream_type::bufsize, and MARKED_FOR_DEATH.
02192 {
02193 if( ns == NULL || ns->bad == MARKED_FOR_DEATH ) return -1 ;
02194 return ns->bufsize ;
02195 }
|
|
||||||||||||
|
Check if the given NI_stream is properly opened for I/O. If not, wait up to msec milliseconds to establish the connection to the other end; if msec < 0, will wait nearly forever. Returns 1 if ready; 0 if not (but may become good later); -1 if an error occurs. Possible -1 errors are:
Definition at line 2276 of file niml_stream.c. References NI_stream_type::bad, CLOSEDOWN, NI_stream_type::fp, NI_stream_type::io_mode, MARKED_FOR_DEATH, MIN, NI_stream_type::name, NEXTDMS, NI_dpr(), NI_FD_TYPE, NI_FILE_TYPE, NI_free, NI_INPUT_MODE, NI_REMOTE_TYPE, NI_SHM_TYPE, NI_sleep(), NI_stream_readcheck(), NI_STRING_TYPE, NI_strncpy(), NI_TCP_TYPE, NI_stream_type::port, NI_stream_type::sd, SHM_goodcheck(), NI_stream_type::shmioc, tcp_accept(), tcp_alivecheck(), tcp_connect(), tcp_readcheck(), and NI_stream_type::type. Referenced by AFNI_niml_redisplay_CB(), AFNI_niml_viewpoint_CB(), AFNI_niml_workproc(), AIVVV_workproc(), main(), NI_read_columns(), NI_read_element(), NI_stream_fillbuf(), NI_stream_read(), NI_stream_readcheck(), NI_stream_reopen(), NI_stream_writecheck(), NI_suck_stream(), NI_write_columns(), NI_write_element(), NI_write_procins(), SUMA_Engine(), SUMA_niml_workproc(), SUMA_SendToAfni(), and SUMA_SendToSuma().
02277 {
02278 int ii , jj ;
02279 char *bbb ;
02280
02281 /** check inputs for OK-osity **/
02282
02283 if( ns == NULL || ns->bad == MARKED_FOR_DEATH ) return -1 ;
02284
02285 switch( ns->type ){
02286
02287 #ifndef DONT_USE_SHM
02288 /** Shared memory **/
02289
02290 case NI_SHM_TYPE:
02291 return SHM_goodcheck( ns->shmioc , msec ) ;
02292 #endif
02293
02294 /** File I/O [there is never any waiting here] **/
02295
02296 case NI_FILE_TYPE:
02297 if( ns->fp == NULL ) return -1 ; /* should never happen */
02298 if( ns->io_mode == NI_INPUT_MODE )
02299 return NI_stream_readcheck(ns,0) ; /* input mode */
02300 else
02301 return 1 ; /* output mode */
02302
02303 case NI_FD_TYPE:
02304 return 1 ; /* no way to check */
02305
02306 /** String I/O **/
02307
02308 case NI_STRING_TYPE:
02309 if( ns->io_mode == NI_INPUT_MODE )
02310 return NI_stream_readcheck(ns,0) ; /* input mode */
02311 else
02312 return 1 ; /* output mode */
02313
02314 /** remote Web input */
02315
02316 case NI_REMOTE_TYPE:
02317 if( ns->io_mode == NI_INPUT_MODE )
02318 return NI_stream_readcheck(ns,0) ; /* input mode */
02319 else
02320 return -1 ; /* output mode */
02321
02322 /** Socket I/O **/
02323
02324 case NI_TCP_TYPE:
02325 if( ns->bad == 0 ){ /** if good before, then check if is still good **/
02326 int ich ;
02327 ich = tcp_alivecheck(ns->sd) ;
02328
02329 #ifdef NIML_DEBUG
02330 if( ich == 0 ) /* 17 Jun 2003 */
02331 NI_dpr("++ Socket %s (port %d) has gone bad!\n",ns->name,ns->port);
02332 #endif
02333
02334 if( ich == 0 ) return -1 ;
02335 return 1 ;
02336 }
02337
02338 /** wasn't good before, so check if that condition has changed **/
02339
02340 /** TCP/IP waiting to accept call from another host **/
02341
02342 if( ns->bad == TCP_WAIT_ACCEPT ){
02343 ii = tcp_readcheck(ns->sd,msec) ; /* see if ready */
02344 if( ii > 0 ){ /* if socket ready: */
02345 jj = tcp_accept( ns->sd , NULL,&bbb ) ; /* accept connection */
02346 if( jj >= 0 ){ /* if accept worked */
02347 CLOSEDOWN( ns->sd ) ; /* close old socket */
02348 NI_strncpy(ns->name,bbb,256) ; /* put IP into name */
02349 NI_free(bbb); ns->bad = 0; ns->sd = jj; /* and ready to go! */
02350 fcntl( ns->sd, F_SETOWN, (int)getpid() ); /* 02 Jan 2004 */
02351 }
02352 }
02353 }
02354
02355 /** TCP/IP waiting to connect call to another host **/
02356
02357 else if( ns->bad == TCP_WAIT_CONNECT ){
02358 int dms=0 , ms ;
02359
02360 if( msec < 0 ) msec = 999999999 ; /* a long time (11+ days) */
02361 for( ms=0 ; ms < msec ; ms += dms ){
02362 ns->sd = tcp_connect( ns->name , ns->port ); /* try to connect */
02363 if( ns->sd >= 0 ) break ; /* worked? get out */
02364 dms = NEXTDMS(dms); dms = MIN(dms,msec-ms); NI_sleep(dms);
02365 }
02366 if( ns->sd < 0 ) /* one last try? */
02367 ns->sd = tcp_connect( ns->name , ns->port ) ;
02368
02369 if( ns->sd >= 0 ) ns->bad = 0 ; /* succeeded? */
02370 if( ns->sd >= 0 )
02371 fcntl( ns->sd, F_SETOWN, (int)getpid() ); /* 02 Jan 2004 */
02372 }
02373
02374 /** see if it turned from bad to good **/
02375
02376 return (ns->bad == 0) ;
02377 }
02378
02379 return -1 ; /* unreachable, I hope */
02380 }
|
|
||||||||||||
|
Check if the NI_stream has data read to be read, or has data stored in its internal buffer.
Definition at line 2490 of file niml_stream.c. References NI_stream_type::bad, MARKED_FOR_DEATH, NI_stream_type::nbuf, NI_stream_readcheck(), and NI_stream_type::npos. Referenced by AFNI_niml_workproc(), AIVVV_workproc(), NI_read_columns(), and SUMA_niml_workproc().
02491 {
02492 if( ns == NULL || ns->bad == MARKED_FOR_DEATH ) return -1 ;
02493
02494 if( ns->npos < ns->nbuf ) return 1 ; /* check if has data in buffer */
02495 return NI_stream_readcheck( ns , msec ) ; /* see if any data can be read */
02496 }
|
|
|
Definition at line 2478 of file niml_stream.c. References NI_free, and NI_stream_close_keep(). Referenced by SUMA_niml_hangup().
02479 {
02480 NI_stream_close_keep(ns,3) ; NI_free(ns) ; return ;
02481 }
|
|
|
Return the name set in the NI_stream header. (This is the pointer to the internal string, so don't free it!) ------------------------------------------------------------------------- Definition at line 2151 of file niml_stream.c. References NI_stream_type::name. Referenced by AFNI_niml_workproc(), and SUMA_niml_workproc().
02152 {
02153 if( ns == NULL ) return NULL ;
02154 return ns->name ;
02155 }
|
|
||||||||||||
|
Open a NIML input or output stream, and return a pointer to it.
name = "tcp:host:port" to connect a socket to system "host" on the given port number. One process should open in "w" mode and one in "r" mode. name = "shm:keyname:size1+size2" to connect to a shared memory segment created with "keyname" for the ID and with I/O buffer sizes of size1 ("w" process to "r" process) and size2 ("r" process to "w" process).
name = "http://hostname/filename" to read data from a Web server name = "ftp://hostname/filename" to read data from an FTP server
mode = "w" to open a stream for writing
The inputs "host" (for tcp:) and "filename" (for file:) are limited to a maximum of 127 bytes. For str:, there is no limit for the "r" stream (but clearly you can't have any NUL bytes in there). For shm:, "keyname" is limited to 127 bytes also. Since opening a socket or shared memory segment requires sychronizing two processes, you can't read or write to a tcp: or shm: stream immediately. Instead you have to check if it is "good" first. This can be done using the function NI_stream_goodcheck(). After a tcp: "r" stream is good, then the string ns->name contains the IP address of the connecting host, in "dot" form (e.g., "201.202.203.204"); here, "ns" is the NI_stream returned by this routine.
Definition at line 1609 of file niml_stream.c. References add_open_stream(), atexit(), atexit_is_setup, atexit_open_streams(), NI_stream_type::b64_numleft, NI_stream_type::bad, NI_stream_type::bin_thresh, NI_stream_type::buf, NI_stream_type::bufsize, CLOSEDOWN, fd, fdopen(), NI_stream_type::fp, NI_stream_type::fsize, getenv(), NI_stream_type::goodcheck_time, NI_stream_type::io_mode, name, NI_stream_type::name, NI_stream_type::nbuf, NI_BUFSIZE, NI_FD_TYPE, NI_FILE_TYPE, NI_filesize(), NI_free, NI_INPUT_MODE, NI_malloc, NI_malloc_enable_tracking(), NI_OUTPUT_MODE, NI_read_URL(), NI_REMOTE_TYPE, NI_SHM_TYPE, NI_STRING_TYPE, NI_strlen(), NI_strncpy(), NI_TCP_TYPE, NI_stream_type::npos, NI_stream_type::orig_name, NI_stream_type::port, NI_stream_type::sd, SHM_init(), NI_stream_type::shmioc, sigurg, tcp_accept(), tcp_connect(), tcp_listen(), tcp_readcheck(), tcp_sigurg_handler(), and NI_stream_type::type. Referenced by AFNI_niml_workproc(), AFNI_serverlog(), AFNI_start_version_check(), AFNI_version_check(), AIVVV_workproc(), Dtable_from_nimlstring(), Dtable_to_nimlstring(), DWI_Open_NIML_stream(), main(), NI_do(), NI_read_file_nohead(), NI_stream_reopen(), NI_suck_stream(), nifti_set_afni_extension(), NIML_to_stderr(), open_URL_hpf(), SUMA_DsetInfo(), SUMA_Engine(), SUMA_FakeIt(), SUMA_LoadNimlDset(), SUMA_LoadVisualState(), SUMA_nel_stdout(), SUMA_niml_call(), SUMA_niml_workproc(), SUMA_OpenDrawnROI_NIML(), SUMA_SaveVisualState(), SUMA_SendToSuma(), SUMA_ShowNel(), SUMA_Write_DrawnROI_NIML(), THD_load_3D(), THD_open_3D(), THD_open_nifti(), THD_read_niml_atr(), THD_write_nimlatr(), v2s_write_outfile_niml(), XSAVE_input(), and XSAVE_output().
01610 {
01611 NI_stream_type *ns ;
01612 int do_create , do_accept ;
01613
01614 /** perhaps initialize debug output **/
01615
01616 #ifdef NIML_DEBUG
01617 if( dfp == NULL ){
01618 char *eee = getenv("NIML_DEBUG") ;
01619 if( eee != NULL ){
01620 dfp = (strcmp(eee,"stderr")==0) ? stderr : fopen(eee,"w") ;
01621 if( dfp == NULL ){ dfp = stderr; eee = "stderr [defaulted]"; }
01622 fprintf(stderr,"NIML: debug output to %s\n",eee) ;
01623 }
01624 }
01625 #endif
01626
01627 #ifdef NIML_DEBUG
01628 NI_malloc_enable_tracking() ;
01629 #endif
01630
01631 /** check if inputs are reasonable **/
01632
01633 if( NI_strlen(name) < 4 ) return NULL ;
01634
01635 if( mode == NULL ) return NULL ;
01636
01637 do_create = (*mode == 'w' || *mode == 'a') ;
01638 do_accept = (*mode == 'r') ;
01639
01640 if( !do_create && !do_accept ) return NULL ;
01641
01642 if( ! atexit_is_setup ){ /* 22 Apr 2005 */
01643 atexit(atexit_open_streams) ; atexit_is_setup = 1 ;
01644 }
01645
01646 /************************************/
01647 /***** deal with TCP/IP sockets *****/
01648
01649 if( strncmp(name,"tcp:",4) == 0 ){
01650 char host[256] , *hend ;
01651 int port=-1 , ii , jj ;
01652
01653 if( NI_strlen(name) > 127 ) return NULL ;
01654
01655 /** find "host" substring **/
01656
01657 hend = strstr( name+4 , ":" ) ;
01658 if( hend == NULL || hend-name > 255 ) return NULL ;
01659
01660 for( ii=4 ; name[ii] != ':' ; ii++ ) host[ii-4] = name[ii] ;
01661 host[ii-4] = '\0' ;
01662
01663 /** get "port" number **/
01664
01665 port = strtol( name+ii+1 , NULL , 10 ) ;
01666 if( port <= 0 ) return NULL ;
01667
01668 /** initialize NI_stream_type output struct **/
01669
01670 ns = NI_malloc(NI_stream_type, sizeof(NI_stream_type) ) ;
01671
01672 ns->type = NI_TCP_TYPE; /* what kind is this? */
01673 ns->port = port ; /* save the port # */
01674 ns->nbuf = 0 ; /* buffer is empty */
01675 ns->npos = 0 ; /* scan starts at 0 */
01676 ns->b64_numleft = 0 ;
01677
01678 ns->buf = NI_malloc(char, NI_BUFSIZE) ;
01679 ns->bufsize = NI_BUFSIZE ;
01680 ns->name[0] = '\0' ;
01681 NI_strncpy(ns->orig_name,name,256) ; /* 23 Aug 2002 */
01682
01683 ns->bin_thresh = -1 ; /* write in text mode */
01684
01685 /* 02 Jan 2004: setup SIGURG handler for OOB data reception. */
01686
01687 if( !sigurg ){ signal(SIGURG,tcp_sigurg_handler); sigurg = 1; }
01688
01689 /** attach to incoming call "r" **/
01690
01691 if( do_accept ){
01692 ns->io_mode = NI_INPUT_MODE ;
01693 ns->sd = tcp_listen( port ) ; /* set up to listen */
01694 if( ns->sd < 0 ){ /* error? must die! */
01695 NI_free(ns->buf); NI_free(ns); return NULL;
01696 }
01697 ns->bad = TCP_WAIT_ACCEPT ; /* not connected yet */
01698 ii = tcp_readcheck(ns->sd,1) ; /* see if ready */
01699 if( ii > 0 ){ /* if socket ready: */
01700 jj = tcp_accept( ns->sd , NULL,&hend ) ; /* accept connection */
01701 if( jj >= 0 ){ /* if accept worked */
01702 CLOSEDOWN( ns->sd ) ; /* close old socket */
01703 NI_strncpy(ns->name,hend,256) ; /* put IP into name */
01704 NI_free(hend); ns->bad = 0; ns->sd = jj ; /* and ready to go! */
01705 fcntl( ns->sd, F_SETOWN, (int)getpid() ) ; /* 02 Jan 2004 */
01706 }
01707 }
01708
01709 add_open_stream(ns) ; /* 02 Jan 2004 */
01710 ns->goodcheck_time = -99 ; /* 23 Nov 2004 */
01711 return ns ;
01712 }
01713
01714 /** place an outgoing call "w" **/
01715
01716 if( do_create ){
01717 struct hostent *hostp ;
01718 ns->io_mode = NI_OUTPUT_MODE ;
01719 hostp = gethostbyname(host) ; /* lookup host on net */
01720 if( hostp == NULL ){ /* fails? must die! */
01721 NI_free(ns->buf); NI_free(ns); return NULL;
01722 }
01723 ns->sd = tcp_connect( host , port ) ; /* connect to host */
01724 ns->bad = (ns->sd < 0) ? TCP_WAIT_CONNECT : 0 ; /* fails? must wait */
01725 NI_strncpy(ns->name,host,256) ; /* save the host name */
01726 if( ns->sd >= 0 )
01727 fcntl( ns->sd, F_SETOWN, (int)getpid() ) ; /* 02 Jan 2004 */
01728
01729 add_open_stream(ns) ; /* 02 Jan 2004 */
01730 ns->goodcheck_time = -99 ; /* 23 Nov 2004 */
01731 return ns ;
01732 }
01733 return NULL ; /* should never be reached */
01734 }
01735
01736 #ifndef DONT_USE_SHM
01737 /*********************************************/
01738 /***** deal with shared memory transport *****/
01739
01740 if( strncmp(name,"shm:",4) == 0 ){
01741 SHMioc *ioc ;
01742
01743 if( *mode == 'a' ) mode = "w" ;
01744 ioc = SHM_init( name , mode ) ; /* open segment */
01745 if( ioc == NULL ) return NULL ; /* this is bad bad bad */
01746
01747 /** initialize NI_stream_type output **/
01748
01749 ns = NI_malloc(NI_stream_type, sizeof(NI_stream_type) ) ;
01750
01751 ns->type = NI_SHM_TYPE; /* what kind is this? */
01752 ns->nbuf = 0 ; /* buffer is empty */
01753 ns->npos = 0 ; /* scan starts at 0 */
01754 ns->io_mode = do_create ? NI_OUTPUT_MODE
01755 : NI_INPUT_MODE ;
01756 ns->bad = 0 ;
01757 ns->shmioc = ioc ;
01758 ns->b64_numleft = 0 ;
01759
01760 ns->buf = NI_malloc(char, NI_BUFSIZE) ;
01761 ns->bufsize = NI_BUFSIZE ;
01762
01763 NI_strncpy( ns->name , name , 256 ) ;
01764
01765 NI_strncpy(ns->orig_name,name,256) ; /* 23 Aug 2002 */
01766
01767 add_open_stream(ns) ; /* 02 Jan 2004 */
01768 ns->goodcheck_time = -99 ; /* 23 Nov 2004 */
01769 return ns ;
01770 }
01771 #endif /* DONT_USE_SHM */
01772
01773 /**********************************/
01774 /***** deal with simple files *****/
01775
01776 if( strncmp(name,"file:",5) == 0 ){
01777
01778 char *fname = name+5 , *fmode ;
01779 FILE *fp ;
01780
01781 if( NI_strlen(name) > 255 || NI_strlen(fname) < 1 ) return NULL ;
01782
01783 if( *mode == 'a' ) fmode = "ab" ;
01784 else fmode = do_create ? (char *)"wb" : (char *)"rb" ;
01785 fp = fopen( fname , fmode ) ;
01786
01787 if( fp == NULL ) return NULL ;
01788
01789 /** initialize NI_stream_type output **/
01790
01791 ns = NI_malloc(NI_stream_type, sizeof(NI_stream_type) ) ;
01792
01793 ns->type = NI_FILE_TYPE; /* what kind is this? */
01794 ns->nbuf = 0 ; /* buffer is empty */
01795 ns->npos = 0 ; /* scan starts at 0 */
01796 ns->fp = fp ;
01797 ns->io_mode = do_create ? NI_OUTPUT_MODE
01798 : NI_INPUT_MODE ;
01799 ns->bad = 0 ;
01800 ns->b64_numleft = 0 ;
01801
01802 ns->bufsize = do_create ? 16 : NI_BUFSIZE ;
01803 ns->buf = NI_malloc(char, ns->bufsize) ;
01804
01805 NI_strncpy( ns->name , fname , 256 ) ;
01806
01807 NI_strncpy(ns->orig_name,name,256) ; /* 23 Aug 2002 */
01808
01809 if( ns->io_mode == NI_INPUT_MODE ) /* save the file size */
01810 ns->fsize = NI_filesize( fname ) ; /* if we are reading */
01811 else
01812 ns->fsize = -1 ;
01813
01814 add_open_stream(ns) ; /* 02 Jan 2004 */
01815 ns->goodcheck_time = -99 ; /* 23 Nov 2004 */
01816 return ns ;
01817 }
01818
01819 /********************************************************************/
01820 /***** fd: very similar to a file, but we don't have to open it *****/
01821
01822 if( strncmp(name,"stdin:" ,6) == 0 ) name = "fd:0" ; /* 25 Mar 2003 */
01823 else if( strncmp(name,"stdout:",7) == 0 ) name = "fd:1" ;
01824 else if( strncmp(name,"stderr:",7) == 0 ) name = "fd:2" ;
01825
01826 if( strncmp(name,"fd:",3) == 0 ){
01827 int fd=-1 ; FILE *fp ;
01828
01829 sscanf(name+3,"%d",&fd) ;
01830 if( fd < 0 ) return NULL ; /* bad integer */
01831
01832 switch( fd ){
01833 default:
01834 fp = fdopen( fd , do_create ? "wb" : "rb" ) ;
01835 if( fp == NULL ) return NULL ;
01836 break ;
01837
01838 case 0:
01839 fp = stdin ;
01840 if( do_create ) return NULL ;
01841 break ;
01842
01843 case 1:
01844 fp = stdout ;
01845 if( !do_create ) return NULL ;
01846 break ;
01847
01848 case 2:
01849 fp = stderr ;
01850 if( !do_create ) return NULL ;
01851 break ;
01852 }
01853
01854 /** initialize NI_stream_type output **/
01855
01856 ns = NI_malloc(NI_stream_type, sizeof(NI_stream_type) ) ;
01857
01858 ns->type = NI_FD_TYPE; /* what kind is this? */
01859 ns->nbuf = 0 ; /* buffer is empty */
01860 ns->npos = 0 ; /* scan starts at 0 */
01861 ns->fp = fp ;
01862 ns->io_mode = do_create ? NI_OUTPUT_MODE
01863 : NI_INPUT_MODE ;
01864 ns->bad = 0 ;
01865 ns->b64_numleft = 0 ;
01866
01867 ns->bufsize = do_create ? 16 : NI_BUFSIZE ;
01868 ns->buf = NI_malloc(char, ns->bufsize) ;
01869
01870 NI_strncpy( ns->name , name , 256 ) ;
01871
01872 NI_strncpy(ns->orig_name,name,256) ; /* 23 Aug 2002 */
01873
01874 ns->fsize = -1 ;
01875
01876 add_open_stream(ns) ; /* 02 Jan 2004 */
01877 ns->goodcheck_time = -99 ; /* 23 Nov 2004 */
01878 return ns ;
01879 }
01880
01881 /*********************************/
01882 /***** str: string array I/O *****/
01883
01884 if( strncmp(name,"str:",4) == 0 ){
01885
01886 int nn = NI_strlen(name+4) ; /* may be 0 */
01887
01888 ns = NI_malloc(NI_stream_type, sizeof(NI_stream_type) ) ;
01889
01890 ns->type = NI_STRING_TYPE; /* what kind is this? */
01891 ns->io_mode = do_create ? NI_OUTPUT_MODE
01892 : NI_INPUT_MODE ;
01893 ns->bad = 0 ;
01894 ns->npos = 0 ; /* scan starts at 0 */
01895 ns->b64_numleft = 0 ;
01896
01897 /* Note that bufsize == nbuf+1 for str:
01898 This is because we don't count the terminal NUL
01899 in nbuf (number of readable bytes),
01900 but do count it in bufsize (size of the buf array) */
01901
01902 if( do_accept ){ /* read from stuff after str: */
01903 ns->nbuf = nn ;
01904 ns->bufsize = nn+1 ;
01905 ns->buf = NI_malloc(char, nn+1) ;
01906 strcpy(ns->buf,name+4) ;
01907 } else { /* write to a string */
01908 ns->nbuf = 0 ;
01909 ns->bufsize = 1 ;
01910 ns->buf = NI_malloc(char, 1) ; /* 1 byte set to zero */
01911 }
01912
01913 strcpy( ns->name , "ElvisHasLeftTheBuilding" ) ;
01914
01915 NI_strncpy(ns->orig_name,name,256) ; /* 23 Aug 2002 */
01916
01917 add_open_stream(ns) ; /* 02 Jan 2004 */
01918 ns->goodcheck_time = -99 ; /* 23 Nov 2004 */
01919 return ns ;
01920 }
01921
01922 /*********************************/
01923 /***** http:// or ftp:// I/O *****/
01924
01925 if( strncmp(name,"http://",7) == 0 || strncmp(name,"ftp://",6) == 0 ){
01926 int nn ;
01927 char *data=NULL ;
01928
01929 if( do_create ) return NULL ; /* bad */
01930
01931 nn = NI_read_URL( name , &data ) ;
01932
01933 if( data == NULL || nn <= 4 ){ /* bad */
01934 NI_free(data); return NULL;
01935 }
01936
01937 ns = NI_malloc(NI_stream_type, sizeof(NI_stream_type) ) ;
01938
01939 ns->type = NI_REMOTE_TYPE; /* what kind is this? */
01940 ns->io_mode = NI_INPUT_MODE ;
01941 ns->bad = 0 ;
01942 ns->npos = 0 ; /* scan starts at 0 */
01943 ns->nbuf = nn ;
01944 ns->bufsize = nn ;
01945 ns->buf = data ;
01946 ns->b64_numleft = 0 ;
01947
01948 NI_strncpy( ns->name , name , 256 ) ;
01949
01950 NI_strncpy(ns->orig_name,name,256) ; /* 23 Aug 2002 */
01951
01952 add_open_stream(ns) ; /* 02 Jan 2004 */
01953 ns->goodcheck_time = -99 ; /* 23 Nov 2004 */
01954 return ns ;
01955 }
01956
01957 return NULL ; /* should never be reached */
01958 }
|
|
||||||||||||||||
|
Read up to nbytes of data from the NI_stream, into buffer. Returns the number of bytes actually read. For both the case of sockets and files, this may be less than nbytes (may even be 0). If an error occurs and no data is read, -1 is returned. For tcp: streams, if no data is available, this function will wait until something can be read. If this behavior is undesirable, then you should use NI_stream_readcheck() before calling this function in order to see if any data is available. For shm: streams, will return immediately if no data is available. For file: streams, this function simply tries to read from the file. Whether or not it succeeds, it will return immediately. It should never return -1; if it returns 0, this means end-of-file. --------------------------------------------------------------------------- Definition at line 2783 of file niml_stream.c. References NI_stream_type::bad, NI_stream_type::buf, NI_stream_type::fp, NI_stream_type::io_mode, NI_stream_type::nbuf, NI_dpr(), NI_FD_TYPE, NI_FILE_TYPE, NI_OUTPUT_MODE, NI_REMOTE_TYPE, NI_SHM_TYPE, NI_stream_goodcheck(), NI_STRING_TYPE, NI_TCP_TYPE, NI_stream_type::npos, PERROR, NI_stream_type::sd, SHM_recv(), NI_stream_type::shmioc, tcp_readcheck(), tcp_recv, and NI_stream_type::type. Referenced by main(), NI_stream_fillbuf(), and read_URL_http().
02784 {
02785 int ii ;
02786
02787 /** check for reasonable inputs **/
02788
02789 if( ns == NULL || ns->bad || buffer == NULL || nbytes < 0 ) return -1 ;
02790
02791 if( nbytes == 0 ) return 0 ;
02792
02793 #ifdef NIML_DEBUG
02794 NI_dpr("ENTER NI_stream_read\n") ;
02795 #endif
02796
02797 switch( ns->type ){
02798
02799 #ifndef DONT_USE_SHM
02800 case NI_SHM_TYPE:
02801 return SHM_recv( ns->shmioc , buffer , nbytes ) ;
02802 #endif
02803
02804 /** tcp: just use recv **/
02805
02806 case NI_TCP_TYPE:
02807 ii = NI_stream_goodcheck(ns,1) ; if( ii != 1 ) return ii ;
02808 #if 0
02809 /* wait 'till we can read fer shur */
02810 do{ ii=tcp_readcheck(ns->sd,1); } while( ii==0 ) ;
02811 if( ii < 0 ) return -1 ;
02812 #endif
02813 errno = 0 ;
02814 ii = tcp_recv( ns->sd , buffer , nbytes , 0 ) ;
02815 if( ii == -1 || errno != 0 ) PERROR("NI_stream_read(recv)") ;
02816 #ifdef NIML_DEBUG
02817 NI_dpr(" tcp: got %d/%d bytes ***\n",ii,nbytes) ;
02818 #endif
02819 return ii ;
02820
02821 /** file: just use fread **/
02822
02823 case NI_FD_TYPE:
02824 case NI_FILE_TYPE:
02825 if( ns->fp == NULL || ns->io_mode == NI_OUTPUT_MODE ) return -1 ;
02826 ii = fread( buffer , 1 , nbytes , ns->fp ) ;
02827 return ii ;
02828
02829 /** str: copy bytes out of the buffer string **/
02830
02831 case NI_REMOTE_TYPE:
02832 case NI_STRING_TYPE:
02833 if( ns->io_mode == NI_OUTPUT_MODE ) return -1 ; /* bad stream */
02834 ii = ns->nbuf - ns->npos ; /* how much is left */
02835 if( ii <= 0 ) return -1 ; /* no data left */
02836 if( ii > nbytes ) ii = nbytes ; /* amount to copy */
02837 memcpy( buffer , ns->buf+ns->npos , ii ) ; /* copy it */
02838 ns->npos += ii ; /* advance position */
02839 return ii ;
02840 }
02841
02842 return -1 ; /* should not be reached */
02843 }
|
|
|
Return 1 if it is legal to read from this stream, 0 if it isn't. This doesn't say anything about if it is practical to read at this moment; for that, use NI_stream_readcheck(). ------------------------------------------------------------------------- Definition at line 2126 of file niml_stream.c. References NI_stream_type::bad, NI_stream_type::io_mode, MARKED_FOR_DEATH, NI_INPUT_MODE, NI_SHM_TYPE, NI_TCP_TYPE, and NI_stream_type::type. Referenced by NI_read_columns(), NI_stream_readbuf(), and NI_stream_readbuf64().
02127 {
02128 if( ns == NULL || ns->bad == MARKED_FOR_DEATH ) return 0 ;
02129 if( ns->type == NI_TCP_TYPE || ns->type == NI_SHM_TYPE ) return 1 ;
02130 return (ns->io_mode == NI_INPUT_MODE) ;
02131 }
|
|
||||||||||||||||
|
Buffered read from a NI_stream. Unlike NI_stream_read(), will try to read all nbytes of data, waiting if necessary. Also works through the internal buffer, rather than directly to the stream. Return value is number of bytes read. May be less than nbytes if the stream closed (or was used up) before nbytes of data was read. Will return -1 if something is rotten. ------------------------------------------------------------------------- Definition at line 2937 of file niml_stream.c. References NI_stream_type::buf, NI_stream_type::bufsize, MIN, NI_stream_type::nbuf, NI_REMOTE_TYPE, NI_reset_buffer(), NI_stream_fillbuf(), NI_stream_readable(), NI_STRING_TYPE, NI_stream_type::npos, and NI_stream_type::type. Referenced by NI_binary_to_val(), and NI_read_columns().
02938 {
02939 int ii , jj , bs , nout=0 ;
02940
02941 /** check for reasonable inputs **/
02942
02943 if( nbytes == 0 ) return 0; /* that was real easy */
02944 if( buffer == NULL || nbytes < 0 ) return -1; /* stupid caller */
02945 if( ns->buf == NULL || ns->bufsize == 0 ) return -1; /* shouldn't happen */
02946 if( !NI_stream_readable(ns) ) return -1; /* stupid stream */
02947
02948 /* see how many unused bytes are already in the input buffer */
02949
02950 ii = ns->nbuf - ns->npos ;
02951
02952 if( ii >= nbytes ){ /* have all the data we need already */
02953 memcpy( buffer , ns->buf + ns->npos , nbytes ) ;
02954 ns->npos += nbytes ;
02955 if( ns->npos == ns->nbuf ) ns->nbuf = ns->npos = 0 ; /* buffer used up */
02956 return nbytes ;
02957 }
02958
02959 /* copy what data we already have, if any */
02960
02961 if( ii > 0 ){
02962 memcpy( buffer , ns->buf + ns->npos , ii ) ; nout = ii ;
02963 }
02964 ns->nbuf = ns->npos = 0 ; /* buffer used up */
02965
02966 /* input streams with fixed length buffers ==> can't do no more */
02967
02968 if( ns->type == NI_REMOTE_TYPE || ns->type == NI_STRING_TYPE )
02969 return (nout > 0) ? nout : -1 ;
02970
02971 /* otherwise, fill the buffer and try again */
02972
02973 bs = ns->bufsize ;
02974
02975 while( nout < nbytes ){
02976
02977 jj = MIN( bs , nbytes-nout ) ; /* how much to try to read */
02978 ii = NI_stream_fillbuf( ns,jj,1666 ) ; /* read into stream buffer */
02979
02980 if( ii > 0 ){ /* got something */
02981 ii = ns->nbuf ; /* how much now in buffer */
02982 if( ii > nbytes-nout ) ii = nbytes-nout ;
02983 memcpy( buffer+nout , ns->buf , ii ) ; nout += ii ;
02984 ns->npos += ii ; NI_reset_buffer( ns ) ;
02985 } else { /* got nothing */
02986 break ; /* so quit */
02987 }
02988 }
02989
02990 if( nout == 0 && ii < 0 ) nout = -1 ; /* no data and an I/O error */
02991 return nout ;
02992 }
|
|
||||||||||||||||
|
Buffered read from a NI_stream, like NI_stream_readbuf, but also:
Definition at line 3004 of file niml_stream.c. References a, B64_decode4, B64_decode_count, B64_goodchar, NI_stream_type::b64_left, NI_stream_type::b64_numleft, NI_stream_type::buf, NI_stream_type::bufsize, c, load_decode_table(), NI_stream_type::nbuf, NI_reset_buffer(), NI_stream_fillbuf(), NI_stream_readable(), and NI_stream_type::npos. Referenced by NI_base64_to_val(), and NI_read_columns().
03005 {
03006 int ii , jj , bs , nout=0 ;
03007 byte a ,b ,c , w,x,y,z ;
03008 byte ag,bg,cg ;
03009 int num_reread , bpos ;
03010
03011 /** check for reasonable inputs **/
03012
03013 if( nbytes == 0 ) return 0; /* that was real easy */
03014 if( buffer == NULL || nbytes < 0 ) return -1; /* stupid caller */
03015 if( ns->buf == NULL || ns->bufsize == 0 ) return -1; /* shouldn't happen */
03016 if( !NI_stream_readable(ns) ) return -1; /* stupid stream */
03017
03018 /* are there decoded leftover bytes from a previous call?
03019 if so, use them up first */
03020
03021 if( ns->b64_numleft > 0 ){
03022
03023 if( ns->b64_numleft >= nbytes ){ /* have enough leftovers for all! */
03024 memcpy( buffer , ns->b64_left , nbytes ) ;
03025 ns->b64_numleft -= nbytes ;
03026 if( ns->b64_numleft > 0 ) /* must shift remaining leftovers down */
03027 memmove( ns->b64_left , ns->b64_left + nbytes , ns->b64_numleft ) ;
03028 return nbytes ; /* done done done! */
03029 }
03030
03031 /* if here, have a few bytes leftover, but not enough */
03032
03033 memcpy( buffer , ns->b64_left , ns->b64_numleft ) ;
03034 nout = ns->b64_numleft ; /* how many so far */
03035 ns->b64_numleft = 0 ; /* have none left now */
03036 }
03037
03038 /* now need to decode some bytes from the input stream;
03039 this is done 4 input bytes at a time,
03040 which are decoded to 3 output bytes */
03041
03042 load_decode_table() ; /* prepare for Base64 decoding */
03043
03044 /** loopback point for reading more data from stream into internal buffer **/
03045
03046 num_reread = 0 ;
03047 Base64Reread:
03048 ag = bg = cg = 0 ;
03049 num_reread++ ; if( num_reread > 5 ) goto Base64Done ; /* done waiting! */
03050
03051 /* read more data into buffer, if needed */
03052
03053 if( num_reread > 1 || ns->nbuf - ns->npos < 4 ){
03054 NI_reset_buffer(ns) ; /* discard used up data => ns->npos==0 */
03055 ii = 5 - ns->nbuf ; if( ii <= 1 ) ii = 2 ;
03056 ii = NI_stream_fillbuf( ns , ii , 1666 ) ;
03057 if( ns->nbuf < 4 ) goto Base64Done ; /* can't get no satisfaction! */
03058 }
03059
03060 /*** Copy valid Base64 bytes out of buffer (skipping others),
03061 converting them to binary as we get full quads,
03062 putting the results into buffer.
03063
03064 Exit loop if we hit a '<' character (end of NIML element),
03065 or hit an '=' character (end of Base64 data stream).
03066
03067 Jump back to Base64Reread (above) if we run out of data in the
03068 buffer before we fulfill the caller's demand for nbytes of output. ***/
03069
03070 while( 1 ){
03071 ag = bg = cg = 0 ;
03072 bpos = ns->npos ; /* scan forward in buffer using bpos */
03073
03074 /* get next valid Base64 character into w;
03075 skip whitespaces and other non-Base64 stuff;
03076 if we hit the end token '<' first, quit;
03077 if we hit the end of the buffer first, need more data */
03078
03079 w = ns->buf[bpos++] ;
03080 while( !B64_goodchar(w) && w != '<' && bpos < ns->nbuf )
03081 w = ns->buf[bpos++] ;
03082 ns->npos = bpos-1 ; /** if we have to reread, will start here, at w **/
03083 if( w == '<' ) goto Base64Done;
03084 if( bpos == ns->nbuf ) goto Base64Reread; /* not enuf data yet */
03085
03086 /* repeat to fill x */
03087
03088 x = ns->buf[bpos++] ;
03089 while( !B64_goodchar(x) && x != '<' && bpos < ns->nbuf )
03090 x = ns->buf[bpos++] ;
03091 if( x == '<' ){ ns->npos = bpos-1; goto Base64Done; }
03092 if( bpos == ns->nbuf ) goto Base64Reread;
03093
03094 /* repeat to fill y */
03095
03096 y = ns->buf[bpos++] ;
03097 while( !B64_goodchar(y) && y != '<' && bpos < ns->nbuf )
03098 y = ns->buf[bpos++] ;
03099 if( y == '<' ){ ns->npos = bpos-1; goto Base64Done; }
03100 if( bpos == ns->nbuf ) goto Base64Reread;
03101
03102 /* repeat to fill z */
03103
03104 z = ns->buf[bpos++] ;
03105 while( !B64_goodchar(z) && z != '<' && bpos < ns->nbuf )
03106 z = ns->buf[bpos++] ;
03107 if( z == '<' ){ ns->npos = bpos-1; goto Base64Done; }
03108
03109 /* at this point, have w,x,y,z to decode */
03110
03111 ns->npos = bpos ; /* scan continues at next place in buffer */
03112
03113 B64_decode4(w,x,y,z,a,b,c) ; /* decode 4 bytes into 3 */
03114
03115 if( z == '=' ){ /* got to the end of Base64? */
03116 int nn = B64_decode_count(w,x,y,z) ; /* see how many bytes to save */
03117 ag = (nn > 0) ; /* a byte is good? */
03118 bg = (nn > 1) ; /* b byte is good? */
03119 cg = 0 ; /* c byte is bad!! */
03120
03121 /* save good bytes into output buffer;
03122 if we reach end of the required number of bytes, we're done */
03123
03124 if( ag ){ buffer[nout++]=a; ag=0; if(nout >= nbytes) goto Base64Done; }
03125 if( bg ){ buffer[nout++]=b; bg=0; if(nout >= nbytes) goto Base64Done; }
03126 goto Base64Done ;
03127 }
03128
03129 /* not at the end of Base64 =>
03130 save bytes, and skip out if we fill up the output array */
03131
03132 ag = bg = cg = 1 ; /* all 3 bytes are good */
03133 buffer[nout++]=a; ag=0; if(nout >= nbytes) goto Base64Done;
03134 buffer[nout++]=b; bg=0; if(nout >= nbytes) goto Base64Done;
03135 buffer[nout++]=c; cg=0; if(nout >= nbytes) goto Base64Done;
03136
03137 /* now, loop back to decode the next 4 bytes;
03138 BUT, if we don't have at least 4 bytes in the input buffer,
03139 must do a re-read first! */
03140
03141 num_reread = 1 ; /* finished at least 1 quad ==> reset penalty clock */
03142 if( ns->nbuf - ns->npos < 4 ) goto Base64Reread ;
03143
03144 } /* end of while(1) loop */
03145
03146 /* At this point:
03147 have finished reading and decoding,
03148 have nout bytes in output buffer,
03149 and might have some good bytes left that need to be saved */
03150
03151 Base64Done:
03152 ns->b64_numleft = 0 ;
03153 if( ag ) ns->b64_left[ ns->b64_numleft++ ] = a ;
03154 if( bg ) ns->b64_left[ ns->b64_numleft++ ] = b ;
03155 if( cg ) ns->b64_left[ ns->b64_numleft++ ] = c ;
03156
03157 return nout ;
03158 }
|
|
||||||||||||
|
Check if the NI_stream is ready to have data read out of it. If not, the routine will wait up to msec milliseconds for data to be available. If msec < 0, this routine will wait nearly forever. The return value is 1 if data is ready, 0 if not; -1 will be returned if some unrecoverable error is detected:
Definition at line 2512 of file niml_stream.c. References NI_stream_type::bad, NI_stream_type::fp, NI_stream_type::fsize, NI_stream_type::io_mode, MARKED_FOR_DEATH, NI_stream_type::nbuf, NI_FD_TYPE, NI_FILE_TYPE, NI_OUTPUT_MODE, NI_REMOTE_TYPE, NI_SHM_TYPE, NI_stream_goodcheck(), NI_STRING_TYPE, NI_TCP_TYPE, NI_stream_type::npos, NI_stream_type::sd, SHM_readcheck(), NI_stream_type::shmioc, tcp_alivecheck(), tcp_readcheck(), and NI_stream_type::type. Referenced by main(), NI_read_element(), NI_stream_fillbuf(), NI_stream_goodcheck(), NI_stream_hasinput(), open_URL_hpf(), read_URL_http(), and SUMA_niml_workproc().
02513 {
02514 int ii ;
02515
02516 if( ns == NULL || ns->bad == MARKED_FOR_DEATH ) return -1 ;
02517
02518 switch( ns->type ){
02519
02520 #ifndef DONT_USE_SHM
02521 case NI_SHM_TYPE:
02522 ii = SHM_readcheck( ns->shmioc , msec ) ;
02523 if( ii > 0 ) ii = 1 ;
02524 return ii ;
02525 #endif
02526
02527 /** tcp: ==> uses the Unix "select" mechanism **/
02528
02529 case NI_TCP_TYPE:
02530 ii = NI_stream_goodcheck(ns,0) ; /* check if it is connected */
02531 if( ii == -1 ) return -1 ; /* some error */
02532 if( ii == 0 ){ /* not good yet */
02533 ii = NI_stream_goodcheck(ns,msec) ; /* so wait for it to get good */
02534 if( ii != 1 ) return ii ; /* if still not good, exit */
02535 }
02536 ii = tcp_alivecheck( ns->sd ) ; /* see if it is still open */
02537 if( !ii ) return -1 ; /* if not open, error exit */
02538 ii = tcp_readcheck( ns->sd , msec ) ; /* see if any data is there */
02539 return ii ;
02540
02541 /** fd: ==> use select, as in tcp: **/
02542
02543 case NI_FD_TYPE:
02544 ii = tcp_readcheck( fileno(ns->fp) , msec ) ;
02545 return ii ;
02546
02547 /** file: ==> check current file position and length of file **/
02548
02549 case NI_FILE_TYPE:{
02550 long f_len , f_pos ;
02551
02552 if( ns->fp == NULL ||
02553 ns->io_mode == NI_OUTPUT_MODE ) return -1 ; /* never? */
02554
02555 f_len = ns->fsize ; /* length of file */
02556 if( f_len < 0 ) return -1 ; /* file not found (?) */
02557
02558 f_pos = ftell( ns->fp ) ; /* where are we now? */
02559 if( f_pos < 0 ) return -1 ; /* should never happen */
02560
02561 return (f_pos < f_len) ? 1 : -1 ; /* is good or bad, but */
02562 /* never just neutral */
02563 }
02564
02565 /** str: ==> check current buffer position **/
02566
02567 case NI_REMOTE_TYPE:
02568 case NI_STRING_TYPE:{
02569 if( ns->io_mode == NI_OUTPUT_MODE ) return -1 ; /* never? */
02570
02571 return (ns->npos < ns->nbuf) ? 1 : -1 ; /* is data left? */
02572 }
02573 }
02574
02575 return -1 ; /* should never happen */
02576 }
|
|
||||||||||||
|
Re-open a NI_stream on a different channel. This is only possible if the input original stream (ns) is tcp: type.
Return value is 1 if things are OK, 0 if not. Failure can occur because:
Definition at line 1986 of file niml_stream.c. References add_open_stream(), NI_stream_type::bad, getenv(), MARKED_FOR_DEATH, NI_stream_type::name, NI_dpr(), NI_free, NI_stream_close_keep(), NI_stream_closenow(), NI_stream_goodcheck(), NI_stream_open(), NI_stream_write(), NI_strncpy(), NI_TCP_TYPE, NI_stream_type::orig_name, NI_stream_type::port, remove_open_stream(), and NI_stream_type::type. Referenced by DWI_Open_NIML_stream(), main(), and SUMA_niml_call().
01987 {
01988 NI_stream_type *nsnew ;
01989 int typ_new=0 , port_new=0 , jj,kk ;
01990 char msg[1024] ;
01991
01992 /* check inputs for sanity */
01993
01994 if( ns == NULL || ns->type != NI_TCP_TYPE ) return 0 ; /* bad input stream */
01995 if( ns->bad == MARKED_FOR_DEATH ) return 0 ; /* really bad */
01996 if( nname == NULL || nname[0] == '\0' ) return 0 ; /* bad new name */
01997
01998 if( strncmp(nname,"tcp::",5) == 0 ){ /* new is tcp:? */
01999 typ_new = NI_TCP_TYPE ;
02000 port_new = strtol(nname+5,NULL,10) ;
02001 if( port_new <= 0 ) return 0 ; /* bad new port */
02002 if( port_new == ns->port ) return 1 ; /* same as before? */
02003 #ifndef DONT_USE_SHM
02004 } else if( strncmp(nname,"shm:" ,4) == 0 ){ /* new is shm:? */
02005 char *eee = getenv("AFNI_NOSHM") ; /* 06 Jun 2003 */
02006 if( eee != NULL && toupper(*eee) == 'Y' ){ /* shm: is disabled */
02007 fprintf(stderr,"** NI_stream_reopen: shm is disabled\n");
02008 return 0 ;
02009 }
02010 if( strstr(ns->orig_name,":localhost:") == NULL ){ /* can't do shm: */
02011 fprintf(stderr,"** NI_stream_reopen: shm not localhost!\n"); /* but on localhost */
02012 return 0 ;
02013 }
02014 #endif
02015 } else {
02016 fprintf(stderr,"** NI_stream_reopen: illegal input '%s'\n",nname);
02017 return 0 ; /* bad new name */
02018 }
02019
02020 #ifdef NIML_DEBUG
02021 NI_dpr("NI_stream_reopen: waiting for original connection to be good\n") ;
02022 #endif
02023
02024 /* wait for existing stream to be connected */
02025
02026 for( kk=0 ; kk < 10 ; kk++ ){
02027 jj = NI_stream_goodcheck( ns , 1000 ) ; /* wait 1 sec */
02028 if( jj > 0 ) break; /* good :-) */
02029 if( kk == 0 )
02030 fprintf(stderr,"++ NI_stream_reopen: Waiting for socket connection") ;
02031 else
02032 fprintf(stderr,".") ;
02033 }
02034 if( kk == 10 ){ fprintf(stderr," *Failed*\n"); return 0; }
02035 if( kk > 0 ) fprintf(stderr," *Good*\n") ;
02036
02037 /* open new stream as the writer */
02038
02039 if( strncmp(nname,"tcp::",5) == 0 ){
02040 sprintf(msg,"tcp:%s:%d",ns->name,port_new) ; /* old hostname */
02041 }
02042 #ifndef DONT_USE_SHM
02043 else if( strncmp(nname,"shm:" ,4) == 0 ){
02044 NI_strncpy(msg,nname,1024) ;
02045 }
02046 #endif
02047
02048 #ifdef NIML_DEBUG
02049 NI_dpr("NI_stream_reopen: opening new stream %s\n",msg) ;
02050 #endif
02051
02052 nsnew = NI_stream_open( msg, "w" ) ;
02053 if( nsnew == NULL ) return 0 ; /* bad :-( */
02054
02055 /* send message on old stream to other
02056 program, telling it to open the new stream */
02057
02058 sprintf(msg,"<?ni_do ni_verb='reopen_this' ni_object='%s' ?>\n",nname) ;
02059 kk = strlen(msg) ;
02060
02061 #ifdef NIML_DEBUG
02062 NI_dpr("NI_stream_reopen: sending message %s",msg) ;
02063 #endif
02064
02065 jj = NI_stream_write( ns , msg , kk ) ;
02066 if( jj < kk ){
02067 NI_stream_closenow(nsnew) ; return 0 ; /* bad write! */
02068 }
02069
02070 /* now wait for other program to open the new stream */
02071
02072 #ifdef NIML_DEBUG
02073 NI_dpr("NI_stream_reopen: waiting for new stream to be good\n") ;
02074 #endif
02075
02076 jj = NI_stream_goodcheck( nsnew , 5000 ) ; /* wait up to 5 sec */
02077 if( jj <= 0 ){
02078 NI_stream_closenow(nsnew) ; return 0 ; /* never got good */
02079 }
02080
02081 /* if here, new stream is ready:
02082 close the old stream and replace its
02083 contents with the contents of the new stream */
02084
02085 #ifdef NIML_DEBUG
02086 NI_dpr("NI_stream_reopen: closing old stream\n") ;
02087 #endif
02088
02089 NI_stream_close_keep(ns,0) ; /* will be removed from open streams list */
02090
02091 *ns = *nsnew ;
02092
02093 /* 10 Jun 2005: at this point, nsnew is in the open streams list,
02094 but the pointer nsnew is about to die, and so we
02095 must munge the open streams list around now to
02096 make sure that nsnew is removed and ns is re-added! */
02097
02098 remove_open_stream(nsnew) ; NI_free(nsnew) ; add_open_stream(ns) ;
02099
02100 return 1 ; /* :-) */
02101 }
|
|
||||||||||||||||
|
Seek file: stream to a specific offset location.
Definition at line 2109 of file niml_stream.c. References NI_stream_type::bad, NI_stream_type::fp, MARKED_FOR_DEATH, NI_stream_type::nbuf, NI_FILE_TYPE, NI_stream_type::npos, offset, and NI_stream_type::type.
02110 {
02111 if( ns == NULL ||
02112 ns->bad == MARKED_FOR_DEATH ||
02113 ns->type != NI_FILE_TYPE ||
02114 ns->fp == NULL ) return ;
02115
02116 fseek( ns->fp , offset , whence ) ; /* seek file */
02117 ns->nbuf = ns->npos = 0 ; /* clear buffer */
02118 }
|
|
||||||||||||
|
|
|
||||||||||||
|
Reset the input string buffer for a NI_stream of str: type. If the input is not a "r" str: stream, then nothing happens. Otherwise, the current contents of the buffer are discarded, and the buffer is replaced with a copy of the input string. ------------------------------------------------------------------------- Definition at line 2238 of file niml_stream.c. References NI_stream_type::bad, NI_stream_type::buf, NI_stream_type::bufsize, NI_stream_type::io_mode, MARKED_FOR_DEATH, NI_stream_type::nbuf, NI_free, NI_INPUT_MODE, NI_malloc, NI_STRING_TYPE, NI_strlen(), NI_stream_type::npos, and NI_stream_type::type. Referenced by Dtable_from_nimlstring(), and THD_open_nifti().
02239 {
02240 int nn ;
02241
02242 if( ns == NULL ||
02243 ns->type != NI_STRING_TYPE ||
02244 ns->io_mode != NI_INPUT_MODE ||
02245 str == NULL ||
02246 ns->bad == MARKED_FOR_DEATH ) return ; /* bad inputs */
02247
02248 NI_free(ns->buf) ; /* take out the trash */
02249 nn = NI_strlen(str) ; /* size of new buffer string */
02250 ns->nbuf = nn ; /* set num char in new buffer */
02251 ns->npos = 0 ; /* reset scan position */
02252 ns->bufsize = nn+1 ; /* allow space for NUL byte */
02253 ns->buf = NI_malloc(char, nn+1) ; /* and make the buffer */
02254 strcpy(ns->buf,str) ; /* and set its contents */
02255 return ;
02256 }
|
|
||||||||||||
|
Alter the input buffer size for a NI_stream.
Definition at line 2165 of file niml_stream.c. References NI_stream_type::bad, NI_stream_type::buf, NI_stream_type::bufsize, NI_stream_type::io_mode, MARKED_FOR_DEATH, NI_stream_type::nbuf, NI_FD_TYPE, NI_FILE_TYPE, NI_INPUT_MODE, NI_realloc, NI_SHM_TYPE, NI_STRING_TYPE, NI_TCP_TYPE, and NI_stream_type::type. Referenced by AFNI_niml_workproc(), and THD_read_niml_atr().
02166 {
02167 char *qbuf ;
02168 if( ns == NULL ||
02169 ns->type == NI_STRING_TYPE ||
02170 ns->bad == MARKED_FOR_DEATH ||
02171 bs < 666 ||
02172 bs < ns->nbuf ) return -1 ; /* bad inputs */
02173
02174 if( !( ns->type == NI_TCP_TYPE || ns->type == NI_SHM_TYPE ||
02175 (ns->type == NI_FILE_TYPE && ns->io_mode == NI_INPUT_MODE) ||
02176 (ns->type == NI_FD_TYPE && ns->io_mode == NI_INPUT_MODE) ) )
02177 return -1 ;
02178
02179 qbuf = NI_realloc( ns->buf , char , bs ) ;
02180 if( qbuf == NULL ) return -1 ; /* this is bad */
02181 ns->buf = qbuf ;
02182 ns->bufsize = bs ;
02183 return 1 ;
02184 }
|
|
||||||||||||||||
|
Send nbytes of data from buffer down the NI_stream. Return value is the number of bytes actually sent, or is -1 if some error occurs (which means that the NI_stream is bad). If 0 is returned, this means you tried to write to something that is temporarily unavailable.
Definition at line 2674 of file niml_stream.c. References NI_stream_type::bad, NI_stream_type::buf, NI_stream_type::bufsize, NI_stream_type::fp, MARKED_FOR_DEATH, NI_stream_type::nbuf, NI_dpr(), NI_FD_TYPE, NI_FILE_TYPE, NI_realloc, NI_REMOTE_TYPE, NI_SHM_TYPE, NI_stream_writecheck(), NI_STRING_TYPE, NI_TCP_TYPE, nosigpipe, PERROR, NI_stream_type::sd, SHM_sendall(), NI_stream_type::shmioc, tcp_send, tcp_writecheck(), and NI_stream_type::type. Referenced by AFNI_serverlog(), main(), NI_stream_reopen(), NI_stream_writestring(), NI_write_columns(), NI_write_element(), and open_URL_hpf().
02675 {
02676 int ii , nsent ;
02677
02678 /** check for reasonable inputs **/
02679
02680 if( ns == NULL || ns->bad ||
02681 buffer == NULL || nbytes < 0 || ns->bad == MARKED_FOR_DEATH ) return -1;
02682
02683 if( nbytes == 0 ) return 0 ; /* that was easy */
02684
02685 #ifdef NIML_DEBUG
02686 NI_dpr("ENTER NI_stream_write\n") ;
02687 #endif
02688
02689 if( ns->type != NI_TCP_TYPE ){
02690 ii = NI_stream_writecheck(ns,66) ; /* check if stream is still OK */
02691 if( ii < 0 ) return ii ; /* if not, vamoose the ranch */
02692 }
02693
02694 switch( ns->type ){
02695
02696 #ifndef DONT_USE_SHM
02697 case NI_SHM_TYPE:
02698 return SHM_sendall( ns->shmioc , buffer , nbytes ) ;
02699 #endif
02700
02701 /** tcp: ==> just use send **/
02702
02703 case NI_TCP_TYPE:
02704
02705 if( ns->bad ) return 0 ; /* socket not ready yet */
02706
02707 /* turn off SIGPIPE signals, which will otherwise be
02708 raised if we send to a socket when the other end has crashed */
02709
02710 if( !nosigpipe ){ signal(SIGPIPE,SIG_IGN); nosigpipe = 1; }
02711
02712 #if 0
02713 /* 03 Mar 2002: wait until we can write fer shur */
02714 do{ ii=tcp_writecheck(ns->sd,1) ; } while(ii==0) ;
02715 if( ii < 0 ) return -1 ;
02716 #endif
02717
02718 errno = 0 ;
02719 nsent = tcp_send( ns->sd , buffer , nbytes , 0 ) ;
02720 if( nsent < nbytes || errno != 0 ) PERROR("NI_stream_write(send)") ;
02721 if( nsent == 0 ){ fprintf(stderr,"tcp send: 0/%d\n",nbytes); nsent=-1; }
02722 return nsent ;
02723
02724 /** file: ==> just fwrite **/
02725
02726 case NI_FD_TYPE:
02727 case NI_FILE_TYPE:
02728 #ifdef NIML_DEBUG
02729 NI_dpr(" file: about to write %d bytes\n",nbytes) ;
02730 #endif
02731 nsent = fwrite( buffer , 1 , nbytes , ns->fp ) ;
02732 if( nsent < nbytes ) PERROR("NI_stream_write(fwrite)") ;
02733 #ifdef NIML_DEBUG
02734 NI_dpr(" file: actually wrote %d bytes\n",nsent) ;
02735 #endif
02736 if( nsent == 0 ) nsent = -1 ;
02737 fflush(ns->fp) ;
02738 return nsent ;
02739
02740 /** str: ==> append to buffer in stream struct **/
02741
02742 case NI_STRING_TYPE:
02743 #ifdef NIML_DEBUG
02744 NI_dpr("NI_stream_write str: input=%s\n",ns->buf) ;
02745 #endif
02746 ns->buf = NI_realloc( ns->buf , char , ns->bufsize+nbytes ) ;
02747 memcpy( ns->buf+ns->nbuf , buffer , nbytes ) ;
02748 ns->nbuf += nbytes ; ns->buf[ns->nbuf] = '\0' ;
02749 ns->bufsize += nbytes ;
02750 #ifdef NIML_DEBUG
02751 NI_dpr("NI_stream_write str: output=%s\n",ns->buf) ;
02752 #endif
02753 return nbytes ;
02754
02755 /** ftp: or http: ==> can't write! */
02756
02757 case NI_REMOTE_TYPE:
02758 return -1 ;
02759 }
02760
02761 return -1 ; /* should not be reached */
02762 }
|
|
|
Return 1 if it is legal to write to this stream, 0 if it isn't. This doesn't say anything about if it is practical to write at this moment; for that, use NI_stream_writecheck(). ------------------------------------------------------------------------- Definition at line 2139 of file niml_stream.c. References NI_stream_type::bad, NI_stream_type::io_mode, MARKED_FOR_DEATH, NI_OUTPUT_MODE, NI_SHM_TYPE, NI_TCP_TYPE, and NI_stream_type::type. Referenced by NI_stream_writecheck(), NI_write_columns(), NI_write_element(), and NI_write_procins().
02140 {
02141 if( ns == NULL || ns->bad == MARKED_FOR_DEATH ) return 0 ;
02142 if( ns->type == NI_TCP_TYPE || ns->type == NI_SHM_TYPE ) return 1 ;
02143 return (ns->io_mode == NI_OUTPUT_MODE) ;
02144 }
|
|
||||||||||||
|
Check if the NI_stream is ready to have data written into it. If not, the routine will wait up to msec milliseconds for writing to be allowable. If msec < 0, this routine will wait nearly forever. The return value is 1 if data can be sent, 0 if not; -1 will be returned if some unrecoverable error is detected:
Definition at line 2590 of file niml_stream.c. References NI_stream_type::bad, NI_stream_type::fp, NI_stream_type::io_mode, NI_FD_TYPE, NI_FILE_TYPE, NI_OUTPUT_MODE, NI_REMOTE_TYPE, NI_SHM_TYPE, NI_stream_goodcheck(), NI_stream_writeable(), NI_STRING_TYPE, NI_TCP_TYPE, NI_stream_type::sd, SHM_writecheck(), NI_stream_type::shmioc, tcp_writecheck(), and NI_stream_type::type. Referenced by AFNI_serverlog(), DWI_Open_NIML_stream(), main(), NI_stream_close_keep(), NI_stream_write(), NI_write_columns(), NI_write_element(), NI_write_procins(), open_URL_hpf(), and SUMA_niml_call().
02591 {
02592 int ii ;
02593
02594 if( !NI_stream_writeable(ns) ) return -1 ;
02595
02596 switch( ns->type ){
02597
02598 #ifndef DONT_USE_SHM
02599 case NI_SHM_TYPE:
02600 ii = SHM_writecheck( ns->shmioc , msec ) ;
02601 if( ii > 0 ) ii = 1 ;
02602 return ii ;
02603 #endif
02604
02605 /** tcp: ==> uses the Unix "select" mechanism **/
02606
02607 case NI_TCP_TYPE:
02608 if( ns->bad ){ /* not marked as good */
02609 ii = NI_stream_goodcheck(ns,0) ; /* check if has become good */
02610 if( ii == -1 ) return -1 ; /* some error when checking */
02611 if( ii == 0 ){ /* not good yet, */
02612 ii = NI_stream_goodcheck(ns,msec); /* so wait for it to get good */
02613 if( ii != 1 ) return ii ; /* if still not good, exit */
02614 }
02615 }
02616 /* socket is good, so */
02617 return tcp_writecheck(ns->sd,msec) ; /* check if we can write bytes */
02618
02619 /** fd: ==> use select, as in tcp: **/
02620
02621 case NI_FD_TYPE:
02622 return tcp_writecheck( fileno(ns->fp) , msec ) ;
02623
02624 /** file: ==> if the file was opened in write mode **/
02625
02626 case NI_FILE_TYPE:
02627 return ( (ns->fp != NULL && ns->io_mode == NI_OUTPUT_MODE) ? 1
02628 : -1 ) ;
02629
02630 /** str: ==> if the string was opened in write mode **/
02631
02632 case NI_STRING_TYPE:
02633 return ( (ns->io_mode == NI_OUTPUT_MODE) ? 1
02634 : -1 ) ;
02635 /** http: or ftp: **/
02636
02637 case NI_REMOTE_TYPE: /* can't write to remote files */
02638 return -1 ;
02639 }
02640
02641 return -1 ; /* should never be reached */
02642 }
|
|
||||||||||||
|
Send a string (without the NUL byte) down the NI_stream. [15 Oct 2002] ------------------------------------------------------------------------------ Definition at line 2648 of file niml_stream.c.
02649 {
02650 if( str == NULL ) return -1 ;
02651 return NI_stream_write( ns , str , strlen(str) ) ;
02652 }
|
|
|
Like strlen, but better (input=NULL ==> output=0). -------------------------------------------------------------------------- Definition at line 131 of file niml_util.c. Referenced by decode_dimen_string(), decode_type_string(), NI_decode_string_list(), NI_rowtype_vsize(), NI_strdup(), NI_stream_open(), NI_stream_setbuf(), NI_write_element(), quotize_string(), quotize_string_vector(), SUMA_NI_decode_string_list(), SUMA_NI_get_ith_string(), and unescape_inplace().
00132 {
00133 if( str == NULL ) return 0 ;
00134 return strlen(str) ;
00135 }
|
|
||||||||||||||||
|
Like strncpy, but better (result always ends in NUL char). If dest is NULL, does nothing. If src is NULL, put a NUL char in dest[0]. ---------------------------------------------------------------------------- Definition at line 119 of file niml_util.c. Referenced by NI_convert_elm_to_obj(), NI_register_objconverters(), NI_registry_add(), NI_registry_malloc(), NI_rowtype_define(), NI_stream_goodcheck(), NI_stream_open(), NI_stream_reopen(), NI_suck_stream(), niml_to_symvec(), parse_header_stuff(), setup_tmpdir(), SUMA_FakeIt(), THD_niml_to_dataset(), and THD_open_3D().
00120 {
00121 if( dest == NULL || n == 0 ) return NULL ;
00122 if( src == NULL || n == 1 ){ dest[0] = '\0' ; return dest ; }
00123 strncpy( dest , src , n-1 ) ;
00124 dest[n-1] = '\0' ; return dest ;
00125 }
|
|
||||||||||||||||||||
|
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_element::name, NI_group::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 }
|
|
||||||||||||
|
Swap arrays of 2 bytes (shorts). ----------------------------------------------------------------- Definition at line 33 of file niml_byteorder.c. References twobytes::a, twobytes::b, and tt. Referenced by NI_swap_column().
|
|
||||||||||||
|
Swap arrays of 4 bytes (ints or floats). ----------------------------------------------------------------- Definition at line 54 of file niml_byteorder.c. References fourbytes::a, fourbytes::b, fourbytes::c, fourbytes::d, and tt. Referenced by NI_base64_to_val(), NI_binary_to_val(), and NI_swap_column().
00055 {
00056 register int ii ;
00057 register fourbytes *tb = (fourbytes *) ar ;
00058 register unsigned char tt , uu ;
00059
00060 for( ii=0 ; ii < n ; ii++ ){
00061 tt = tb[ii].a ; tb[ii].a = tb[ii].d ; tb[ii].d = tt ;
00062 uu = tb[ii].b ; tb[ii].b = tb[ii].c ; tb[ii].c = uu ;
00063 }
00064 return ;
00065 }
|
|
||||||||||||
|
Swap arrays of 8 bytes (doubles or 64 bit ints). ----------------------------------------------------------------- Definition at line 76 of file niml_byteorder.c. References eightbytes::a, eightbytes::b, eightbytes::c, eightbytes::d, eightbytes::e, eightbytes::f, eightbytes::g, eightbytes::h, and tt. Referenced by NI_swap_column().
00077 {
00078 register int ii ;
00079 register eightbytes *tb = (eightbytes *) ar ;
00080 register unsigned char tt , uu , vv , ww ;
00081
00082 for( ii=0 ; ii < n ; ii++ ){
00083 tt = tb[ii].a ; tb[ii].a = tb[ii].h ; tb[ii].h = tt ;
00084 uu = tb[ii].b ; tb[ii].b = tb[ii].g ; tb[ii].g = uu ;
00085 vv = tb[ii].c ; tb[ii].c = tb[ii].f ; tb[ii].f = vv ;
00086 ww = tb[ii].d ; tb[ii].d = tb[ii].e ; tb[ii].e = ww ;
00087 }
00088 return ;
00089 }
|
|
||||||||||||||||
|
Swap bytes in a bunch of rowtype structs. --------------------------------------------------------------------------- Definition at line 1942 of file niml_rowtype.c. References NI_rowtype::code, NI_BYTE, NI_COMPLEX, NI_DOUBLE, NI_FLOAT, NI_INT, NI_RGB, NI_RGBA, NI_SHORT, NI_STRING, NI_swap2(), NI_swap4(), NI_swap8(), NI_rowtype::part_dim, NI_rowtype::part_num, NI_rowtype::part_off, NI_rowtype::part_rtp, ROWTYPE_part_dimen, and NI_rowtype::size. Referenced by NI_read_columns().
01943 {
01944 if( rt == NULL || nrow <= 0 || dat == NULL ) return ; /* stupid inputs */
01945
01946 switch( rt->code ){
01947
01948 case NI_RGB:
01949 case NI_RGBA:
01950 case NI_STRING:
01951 case NI_BYTE: return ; /* nothing to do */
01952
01953 /*-- basic types --*/
01954
01955 case NI_SHORT:
01956 NI_swap2( nrow , dat ) ;
01957 return ;
01958
01959 case NI_INT:
01960 case NI_FLOAT:
01961 NI_swap4( nrow , dat ) ;
01962 return ;
01963
01964 case NI_DOUBLE:
01965 NI_swap8( nrow , dat ) ;
01966 return ;
01967
01968 case NI_COMPLEX:
01969 NI_swap4( 2*nrow , dat ) ;
01970 return ;
01971
01972 /* a derived type (use recursion) */
01973
01974 default:{
01975 int ii , row , fsiz = rt->size ;
01976 char *ptr ;
01977
01978 for( row=0 ; row < nrow ; row++ ){
01979 ptr = dat + fsiz*row ; /* ptr to row-th element */
01980
01981 /* loop over parts and swap them, 1 at a time */
01982
01983 for( ii=0 ; ii < rt->part_num ; ii++ ){
01984
01985 if( rt->part_dim[ii] < 0 ){ /* fixed dim part */
01986
01987 NI_swap_column( rt->part_rtp[ii] , 1 , ptr+rt->part_off[ii] ) ;
01988
01989 } else { /* var dim array */
01990
01991 char **apt = (char **)(ptr+rt->part_off[ii]); /* data in struct */
01992 /* is ptr to array */
01993 int dim = ROWTYPE_part_dimen(rt,dat,ii) ; /* dimension of part */
01994 NI_swap_column( rt->part_rtp[ii] , dim , *apt ) ;
01995
01996 }
01997 } /* end of loop over parts */
01998 } /* end of loop over rows */
01999 }
02000 return ;
02001 }
02002 }
|
|
||||||||||||||||
|
|
|
||||||||||||||||||||
|
Decode text from the NI_stream into a rowtype struct.
Definition at line 1767 of file niml_rowtype.c. References rgba::a, rgb::b, rgba::b, NI_rowtype::code, rgb::g, rgba::g, complex::i, NI_BYTE, NI_COMPLEX, NI_decode_one_double(), NI_decode_one_string(), NI_DOUBLE, NI_FLOAT, NI_free, NI_INT, NI_malloc, NI_RGB, NI_RGBA, NI_SHORT, NI_STRING, NI_rowtype::part_dim, NI_rowtype::part_num, NI_rowtype::part_off, NI_rowtype::part_rtp, complex::r, rgb::r, rgba::r, ROWTYPE_is_varsize, ROWTYPE_part_dimen, NI_rowtype::size, unescape_inplace(), and v1. Referenced by NI_read_columns().
01768 {
01769 int nn ;
01770
01771 switch( rt->code ){
01772
01773 /*-- a derived type: fill the parts by recursion --*/
01774
01775 default:{
01776 char *dat = (char *)dpt , **aaa = NULL ;
01777 int ii , jj , naaa = 0 , iaaa = 0 ;
01778
01779 if( ROWTYPE_is_varsize(rt) ){ /* variable dim arrays inside */
01780 for( naaa=ii=0 ; ii < rt->part_num ; ii++ )
01781 if( rt->part_dim[ii] >= 0 ) naaa++ ; /* count var dim arrays */
01782 if( naaa > 0 )
01783 aaa = NI_malloc(char*, sizeof(char *)*naaa) ; /* save their addresses */
01784 } /* for possible deletion later */
01785
01786 /* loop over parts and load them */
01787
01788 for( nn=1,ii=0 ; ii < rt->part_num ; ii++ ){
01789
01790 if( rt->part_dim[ii] < 0 ){ /* one fixed dim part */
01791
01792 nn = NI_text_to_val( ns, rt->part_rtp[ii],
01793 dat+rt->part_off[ii], ltend );
01794
01795 } else { /* var dim array */
01796
01797 char **apt = (char **)(dat+rt->part_off[ii]); /* data in struct */
01798 /* will be ptr to array */
01799 int dim = ROWTYPE_part_dimen(rt,dat,ii) ; /* dimension of part */
01800 int siz = rt->part_rtp[ii]->size ; /* size of one part struct */
01801 if( dim > 0 ){
01802 *apt = NI_malloc(char, siz * dim ); /* make array */
01803 for( jj=0 ; jj < dim ; jj++ ){ /* get values for array */
01804 nn = NI_text_to_val( ns, rt->part_rtp[ii],
01805 *apt + siz * jj , ltend ) ;
01806 if( !nn ) break ;
01807 }
01808 } else {
01809 *apt = NULL ; /* dim=0 ==> no array needed */
01810 }
01811 aaa[iaaa++] = *apt ; /* save for possible deletion */
01812
01813 }
01814
01815 if( !nn ) break ; /* some read was bad */
01816 } /* end of loop over parts */
01817
01818 /* bad news ==> delete any allocated var dim arrays */
01819
01820 if( !nn ){
01821 for( ii=0 ; ii < iaaa ; ii++ ) NI_free( aaa[ii] ) ;
01822 NI_free( aaa ) ;
01823 return 0 ;
01824 }
01825 NI_free( aaa ) ; /* in any case, dump this */
01826 }
01827 break ;
01828
01829 /*-- the 9 builtin types below here; first up: String! --*/
01830
01831 case NI_STRING:{
01832 char *val=NULL ;
01833 char **vpt = (char **) dpt ;
01834 nn = NI_decode_one_string( ns , &val , ltend ) ;
01835 if( !nn || val == NULL ) return 0 ;
01836 unescape_inplace(val) ;
01837 *vpt = val ;
01838 }
01839 break ;
01840
01841 /*-- numeric types below here --*/
01842
01843 case NI_BYTE:{
01844 double val ;
01845 byte *vpt = (byte *) dpt ;
01846 nn = NI_decode_one_double( ns , &val , ltend ) ;
01847 if( !nn ) return 0 ;
01848 *vpt = (byte) val ;
01849 }
01850 break ;
01851
01852 case NI_SHORT:{
01853 double val ;
01854 short *vpt = (short *) dpt ;
01855 nn = NI_decode_one_double( ns , &val , ltend ) ;
01856 if( !nn ) return 0 ;
01857 *vpt = (short) val ;
01858 }
01859 break ;
01860
01861 case NI_INT:{
01862 double val ;
01863 int *vpt = (int *) dpt ;
01864 nn = NI_decode_one_double( ns , &val , ltend ) ;
01865 if( !nn ) return 0 ;
01866 *vpt = (int) val ;
01867 }
01868 break ;
01869
01870 case NI_FLOAT:{
01871 double val ;
01872 float *vpt = (float *) dpt ;
01873 nn = NI_decode_one_double( ns , &val , ltend ) ;
01874 if( !nn ) return 0 ;
01875 *vpt = (float) val ;
01876 }
01877 break ;
01878
01879 case NI_DOUBLE:{
01880 double val ;
01881 double *vpt = (double *) dpt ;
01882 nn = NI_decode_one_double( ns , &val , ltend ) ;
01883 if( !nn ) return 0 ;
01884 *vpt = (double) val ;
01885 }
01886 break ;
01887
01888 case NI_COMPLEX:{
01889 double v1,v2 ;
01890 complex *vpt = (complex *) dpt ;
01891 nn = NI_decode_one_double( ns , &v1 , ltend ) ;
01892 if( !nn ) return 0 ;
01893 nn = NI_decode_one_double( ns , &v2 , ltend ) ;
01894 if( !nn ) return 0 ;
01895 vpt->r = (float) v1 ;
01896 vpt->i = (float) v2 ;
01897 }
01898 break ;
01899
01900 case NI_RGB:{
01901 double v1,v2,v3 ;
01902 rgb *vpt = (rgb *) dpt ;
01903 nn = NI_decode_one_double( ns , &v1 , ltend ) ;
01904 if( !nn ) return 0 ;
01905 nn = NI_decode_one_double( ns , &v2 , ltend ) ;
01906 if( !nn ) return 0 ;
01907 nn = NI_decode_one_double( ns , &v3 , ltend ) ;
01908 if( !nn ) return 0 ;
01909 vpt->r = (byte) v1 ;
01910 vpt->g = (byte) v2 ;
01911 vpt->b = (byte) v3 ;
01912 }
01913 break ;
01914
01915 case NI_RGBA:{
01916 double v1,v2,v3,v4 ;
01917 rgba *vpt = (rgba *) dpt ;
01918 nn = NI_decode_one_double( ns , &v1 , ltend ) ;
01919 if( !nn ) return 0 ;
01920 nn = NI_decode_one_double( ns , &v2 , ltend ) ;
01921 if( !nn ) return 0 ;
01922 nn = NI_decode_one_double( ns , &v3 , ltend ) ;
01923 if( !nn ) return 0 ;
01924 nn = NI_decode_one_double( ns , &v4 , ltend ) ;
01925 if( !nn ) return 0 ;
01926 vpt->r = (byte) v1 ;
01927 vpt->g = (byte) v2 ;
01928 vpt->b = (byte) v3 ;
01929 vpt->a = (byte) v4 ;
01930 }
01931 break ;
01932
01933 } /* end of switch on type */
01934
01935 return 1 ; /* good */
01936 }
|
|
|
Return 1 if we like hostid, 0 if we don't. ----------------------------------------------------------------------------- Definition at line 686 of file niml_stream.c. References getenv(), host_list, host_num, hostname_dotted(), init_trusted_list(), NI_free, and NI_hostname_to_inet(). Referenced by tcp_accept().
00687 {
00688 int ii ;
00689 char *hh = hostid ;
00690
00691 /* if the trusted list is empty,
00692 see if we want to be completely trusting;
00693 if not, then initialize the trusted list and then check */
00694
00695 if( host_num == 0 ){
00696 char *eee = getenv("NIML_COMPLETE_TRUST") ;
00697 if( eee != NULL && toupper(*eee) == 'Y' ) return 1 ; /* complete trust */
00698 init_trusted_list() ;
00699 }
00700
00701 if( hostid == NULL || hostid[0] == '\0' ) return 0 ;
00702
00703 if( !hostname_dotted(hostid) ){
00704 hh = NI_hostname_to_inet(hostid) ; /* will be NI_malloc()-ed */
00705 if( hh == NULL ) return 0 ;
00706 }
00707
00708 /* to be trusted, hostid must start with same
00709 string as something in the trusted host_list array */
00710
00711 for( ii=0 ; ii < host_num ; ii++ ){
00712 if( strstr(hh,host_list[ii]) == hh ){
00713 if( hh != hostid ) NI_free(hh) ;
00714 return 1 ;
00715 }
00716 }
00717
00718 if( hh != hostid ) NI_free(hh) ;
00719 return 0 ;
00720 }
|
|
|
Return the type name given the integer code. Definition at line 886 of file niml_elemio.c. References name_mode, NI_NAMEMODE_ALIAS, NI_rowtype_code_to_alias(), and NI_rowtype_code_to_name(). Referenced by NI_write_element().
00887 {
00888 return (name_mode == NI_NAMEMODE_ALIAS) ? NI_rowtype_code_to_alias(code)
00889 : NI_rowtype_code_to_name (code) ;
00890 }
|
|
|
Byte size of a given integer type code. Modified 13 Feb 2003 to use the new rowtype stuff. --------------------------------------------------------------------------- Definition at line 237 of file niml_element.c. References NI_rowtype_code_to_size(). Referenced by make_empty_data_element().
00238 {
00239 int ii = NI_rowtype_code_to_size( tval ) ;
00240 return (ii > 0) ? ii : 0 ;
00241 }
|
|
|
Remove a struct from the table. Definition at line 50 of file niml_struct.c. References removefrom_Htable().
00051 {
00052 NI_struct *nd = (NI_struct *)ndd ;
00053 if( nd == NULL || nd->idcode == NULL ) return ;
00054 removefrom_Htable( nd->idcode , ni_struct_table ) ;
00055 return ;
00056 }
|
|
||||||||||||||||
|
Copy 1 fixed dim type (no String or var dim array parts here) value in binary format to the wbuf.
Definition at line 982 of file niml_rowtype.c. References NI_rowtype::part_num, NI_rowtype::part_off, NI_rowtype::part_siz, NI_rowtype::psiz, ROWTYPE_is_varsize, and NI_rowtype::size. Referenced by NI_multival_to_binary(), and NI_write_columns().
00983 {
00984 int jj=0 ; /* will be return value */
00985
00986 if( rt->size == rt->psiz ){ /* fixed dim, unpadded struct */
00987
00988 jj = rt->size ;
00989 memcpy(wbuf,dpt,jj) ;
00990
00991 } else if( !ROWTYPE_is_varsize(rt) ){ /* derived fixed dim type */
00992 /* ==> write each part separately */
00993 int ii ;
00994 for( ii=0 ; ii < rt->part_num ; ii++ ){
00995 memcpy(wbuf+jj,dpt+rt->part_off[ii],rt->part_siz[ii]) ;
00996 jj += rt->part_siz[ii] ;
00997 }
00998
00999 }
01000
01001 return jj ;
01002 }
|
|
||||||||||||||||
|
Encode 1 type value at the end of the text string wbuf (which is assumed to be plenty long). typ must be a fixed dim type code, or NI_STRING. Structs with var dim arrays must be handled separately. --------------------------------------------------------------------------- Definition at line 863 of file niml_rowtype.c. References a, NI_rowtype::code, gbuf, i, NI_BYTE, NI_COMPLEX, NI_DOUBLE, NI_FLOAT, NI_free, NI_INT, NI_RGB, NI_RGBA, NI_SHORT, NI_STRING, NI_rowtype::part_num, NI_rowtype::part_off, NI_rowtype::part_rtp, quotize_string(), and r. Referenced by NI_multival_to_text(), and NI_write_columns().
00864 {
00865 int jj = strlen(wbuf) ;
00866
00867 switch( rt->code ){
00868
00869 /*-- a derived type (will not contain var dim arrays) --*/
00870
00871 default:{
00872 if( rt != NULL ){
00873 int ii ;
00874 for( ii=0 ; ii < rt->part_num ; ii++ ) /* recursion */
00875 NI_val_to_text( rt->part_rtp[ii] , dpt + rt->part_off[ii] , wbuf ) ;
00876 }
00877 }
00878 break ;
00879
00880 /*-- integer types --*/
00881
00882 case NI_BYTE:{
00883 byte *vpt = (byte *)dpt ;
00884 sprintf(wbuf+jj," %u",(unsigned int)vpt[0]) ;
00885 }
00886 break ;
00887
00888 case NI_SHORT:{
00889 short *vpt = (short *)dpt ;
00890 sprintf(wbuf+jj," %d",(int)vpt[0]) ;
00891 }
00892 break ;
00893
00894 case NI_INT:{
00895 int *vpt = (int *)dpt ;
00896 sprintf(wbuf+jj," %d",vpt[0]) ;
00897 }
00898 break ;
00899
00900 /* multiple byte structs */
00901
00902 case NI_RGB:{
00903 rgb *vpt = (rgb *)dpt ;
00904 sprintf(wbuf+jj," %u %u %u",vpt[0].r,vpt[0].g,vpt[0].b) ;
00905 }
00906 break ;
00907
00908 case NI_RGBA:{
00909 rgba *vpt = (rgba *)dpt ;
00910 sprintf(wbuf+jj," %u %u %u %u",
00911 vpt[0].r,vpt[0].g,vpt[0].b,vpt[0].a) ;
00912 }
00913 break ;
00914
00915 /* for floating point outputs,
00916 first print to a temp string, then clip trailing and leading blanks */
00917
00918 case NI_FLOAT:{
00919 float *vpt = (float *)dpt ;
00920 char fbuf[32] ; int ff ;
00921 sprintf(fbuf,"%12.6g",vpt[0]) ;
00922 for( ff=strlen(fbuf) ; fbuf[ff]==' ' ; ff-- ) fbuf[ff] = '\0' ;
00923 for( ff=0 ; fbuf[ff] == ' ' ; ff++ ) ;
00924 sprintf(wbuf+jj," %s",fbuf+ff) ;
00925 }
00926 break ;
00927
00928 case NI_DOUBLE:{
00929 double *vpt = (double *)dpt ;
00930 char fbuf[32] ; int ff ;
00931 sprintf(fbuf,"%18.12g",vpt[0]) ;
00932 for( ff=strlen(fbuf) ; fbuf[ff]==' ' ; ff-- ) fbuf[ff] = '\0' ;
00933 for( ff=0 ; fbuf[ff] == ' ' ; ff++ ) ;
00934 sprintf(wbuf+jj," %s",fbuf+ff) ;
00935 }
00936 break ;
00937
00938 case NI_COMPLEX:{
00939 complex *vpt = (complex *)dpt ;
00940 char fbuf[32],gbuf[32] ; int ff,gg ;
00941 sprintf(fbuf,"%12.6g",vpt[0].r) ;
00942 for( ff=strlen(fbuf) ; fbuf[ff]==' ' ; ff-- ) fbuf[ff] = '\0' ;
00943 for( ff=0 ; fbuf[ff] == ' ' ; ff++ ) ;
00944 sprintf(gbuf,"%12.6g",vpt[0].i) ;
00945 for( gg=strlen(gbuf) ; gbuf[gg]==' ' ; gg-- ) gbuf[gg] = '\0' ;
00946 for( gg=0 ; gbuf[gg] == ' ' ; gg++ ) ;
00947 sprintf(wbuf+jj," %s %s",fbuf+ff,gbuf+gg) ;
00948 }
00949 break ;
00950
00951 case NI_STRING:{ /* 30 Dec 2002 */
00952 char **vpt = (char **)dpt , *str ;
00953 str = quotize_string( *vpt ) ;
00954 sprintf(wbuf+jj," %s",str) ;
00955 NI_free(str) ;
00956 }
00957 break ;
00958
00959 } /* end of switch on part type */
00960 }
|
|
||||||||||||||||||||||||||||
|
Write "columns" of data to a NI_stream. Each column is an array of structs of some NI_rowtype (including the builtin types):
Definition at line 1089 of file niml_rowtype.c. References a, B64_encode1, B64_encode2, B64_encode3, NI_stream_type::bad, c, cbuf, load_encode_table(), NI_BASE64_MODE, NI_BINARY_MODE, NI_clock_time(), NI_dpr(), NI_has_String(), NI_malloc, NI_multival_to_binary(), NI_multival_to_text(), NI_realloc, NI_rowtype_find_code(), NI_rowtype_vsize(), NI_stream_goodcheck(), NI_stream_write(), NI_stream_writeable(), NI_stream_writecheck(), NI_stream_writestring(), NI_STRING_TYPE, NI_TEXT_MODE, NI_val_to_binary(), NI_val_to_text(), NI_rowtype::part_dim, NI_rowtype::part_num, NI_rowtype::part_off, NI_rowtype::psiz, ROWTYPE_is_varsize, ROWTYPE_part_dimen, NI_rowtype::size, and NI_stream_type::type. Referenced by NI_write_element(), and NI_write_rowtype().
01092 {
01093 int ii,jj , row , dim , ntot,nout , col ;
01094 char *ptr , **col_dat=(char **)col_dpt ;
01095 int nwbuf,bb=0,cc=0;
01096 char *wbuf=NULL ; /* write buffer */
01097 char *bbuf=NULL ; /* copy of write buffer */
01098 char *cbuf=NULL ; /* Base64 buffer */
01099
01100 NI_rowtype **rt=NULL ; /* array of NI_rowtype, 1 per column */
01101 int *vsiz=NULL , vsiz_tot=0 ;
01102 int *fsiz=NULL , fsiz_tot=0 ;
01103
01104 # undef FREEUP
01105 # define FREEUP do{ NI_free(wbuf); NI_free(bbuf); NI_free(cbuf); \
01106 NI_free(rt) ; NI_free(vsiz); NI_free(fsiz); \
01107 } while(0)
01108
01109 /*-- check inputs --*/
01110
01111 if( col_num <= 0 || col_len <= 0 ) return 0 ;
01112 if( col_typ == NULL || col_dat == NULL ) return -1 ;
01113 if( !NI_stream_writeable(ns) ) return -1 ;
01114
01115 #if 0
01116 fprintf(stderr,"NI_write_columns: col_num=%d col_len=%d tmode=%d\n",col_num,col_len,tmode) ;
01117 #endif
01118
01119 /*-- check stream --*/
01120
01121 if( ns->bad ){ /* not connected yet? */
01122 jj = NI_stream_goodcheck(ns,666) ; /* try to connect it */
01123 if( jj < 1 ) return jj ; /* 0 is nothing yet, -1 is death */
01124 }
01125 #if 1
01126 jj = NI_stream_writecheck(ns,666) ;
01127 if( jj < 0 ) return jj ; /* only exit if stream is actually bad */
01128 #endif
01129
01130 if( ns->type == NI_STRING_TYPE ) /* output to string buffer ==> text mode */
01131 tmode = NI_TEXT_MODE ;
01132
01133 /* create array of NI_rowtype for columns, etc. */
01134
01135 rt = NI_malloc(NI_rowtype*, sizeof(NI_rowtype *) * col_num ) ;
01136 vsiz = NI_malloc(int, sizeof(int) * col_num ) ;
01137 fsiz = NI_malloc(int, sizeof(int) * col_num ) ;
01138 for( col=0 ; col < col_num ; col++ ){
01139
01140 /* convert column type code to rowtype pointer */
01141
01142 rt[col] = NI_rowtype_find_code( col_typ[col] ) ;
01143
01144 /* can't find type, or no data in column? take this job and shove it */
01145
01146 if( rt[col] == NULL || col_dat[col] == NULL ){ FREEUP; return -1; }
01147
01148 vsiz[col] = ROWTYPE_is_varsize(rt[col]) ; /* variable dim type? */
01149 fsiz[col] = rt[col]->size ; /* fixed size of struct (w/padding) */
01150 vsiz_tot += vsiz[col] ;
01151 fsiz_tot += fsiz[col] ;
01152
01153 /* can only write String parts in text mode */
01154
01155 if( tmode != NI_TEXT_MODE && NI_has_String(rt[col]) ) tmode = NI_TEXT_MODE;
01156 }
01157
01158 /*-- Special (and fast) case:
01159 one compact (no padding) fixed-size rowtype,
01160 and binary output ==> can write all data direct to stream at once --*/
01161
01162 if( col_num == 1 && tmode == NI_BINARY_MODE && fsiz[0] == rt[0]->psiz ){
01163 #if 0
01164 int ct = NI_clock_time() ;
01165 #endif
01166 nout = NI_stream_write( ns , col_dat[0] , fsiz[0]*col_len ) ;
01167 #if 0
01168 ct = NI_clock_time()-ct ;
01169 fprintf(stderr,"NI_write_columns FAST case: %d bytes in %d ms\n",fsiz[0]*col_len,ct) ;
01170 #endif
01171 FREEUP ; return nout ;
01172 }
01173
01174 /*-- allocate space for the write buffer (1 row at a time) --*/
01175
01176 switch( tmode ){
01177 default: tmode = NI_TEXT_MODE ; /* fall through */
01178 case NI_TEXT_MODE: nwbuf = 6*fsiz_tot ; break ;
01179
01180 case NI_BASE64_MODE:
01181 case NI_BINARY_MODE: nwbuf = fsiz_tot ; break ;
01182 }
01183 wbuf = NI_malloc(char, nwbuf+128) ; /* 128 for the hell of it */
01184
01185 /* create buffers for Base64 output, if needed */
01186
01187 if( tmode == NI_BASE64_MODE ){
01188 bbuf = NI_malloc(char, nwbuf+128) ; bb = 0 ; /* binary buffer */
01189 cbuf = NI_malloc(char, 2*nwbuf+128) ; cc = 0 ; /* base64 buffer */
01190 load_encode_table() ;
01191 }
01192
01193 /* this macro take the 'nout' number of output bytes
01194 and adds into the running total ntot if all was well;
01195 if all was not well with the write, then it aborts the output */
01196
01197 # undef ADDOUT
01198 # define ADDOUT \
01199 if( nout < 0 ){ \
01200 fprintf(stderr,"NIML:: write abort!\n"); \
01201 FREEUP ; return -1 ; \
01202 } else ntot+=nout
01203
01204 /*-- loop over output rows,
01205 format for output into wbuf, and then send to output stream --*/
01206
01207 ntot = 0 ; /* total number of bytes output to stream */
01208
01209 for( row=0 ; row < col_len ; row++ ){
01210
01211 /* expand write buffer if any type contains variable dim array(s) */
01212
01213 if( vsiz_tot ){
01214 for( jj=col=0 ; col < col_num ; col++ ){
01215 ptr = col_dat[col] + fsiz[col]*row ; /* ptr to row-th element */
01216 jj += NI_rowtype_vsize( rt[col] , ptr ); /* size of data, w/var arrays */
01217 }
01218 if( tmode == NI_TEXT_MODE ) jj *= 6 ;
01219 if( jj > nwbuf ){ /* did it get bigger? */
01220 nwbuf = jj ;
01221 wbuf = NI_realloc(wbuf, char,nwbuf+128) ;
01222 if( tmode == NI_BASE64_MODE ){ /* expand Base64 stuff, too */
01223 bbuf = NI_realloc(bbuf, char, nwbuf+128) ;
01224 cbuf = NI_realloc(cbuf, char,2*nwbuf+128) ;
01225 }
01226 }
01227 }
01228
01229 /* initialize write buffer for this row */
01230
01231 switch( tmode ){
01232 case NI_TEXT_MODE: wbuf[0] = '\0'; break; /* clear buffer */
01233 case NI_BASE64_MODE:
01234 case NI_BINARY_MODE: jj = 0 ; break; /* clear byte count */
01235 }
01236
01237 /* loop over columns, write each into the buffer */
01238
01239 for( col=0 ; col < col_num ; col++ ){
01240 ptr = col_dat[col] + fsiz[col]*row ; /* ptr to row-th struct */
01241 /* in this columns */
01242
01243 /* write each part of this struct into the buffer */
01244
01245 /* in text mode, strlen(wbuf) keeps track of number of bytes;
01246 in binary mode, jj keeps track of number of bytes written */
01247
01248 for( ii=0 ; ii < rt[col]->part_num ; ii++ ){ /*-- loop over parts --*/
01249
01250 if( rt[col]->part_dim[ii] < 0 ){ /*-- a single value --*/
01251 switch( tmode ){ /*-- output method (text or binary) --*/
01252
01253 case NI_TEXT_MODE: /*-- sprintf value to output --*/
01254 NI_val_to_text( rt[col]->part_rtp[ii],
01255 ptr+rt[col]->part_off[ii], wbuf ) ;
01256 break ;
01257
01258 case NI_BASE64_MODE: /*-- memcpy values to output --*/
01259 case NI_BINARY_MODE:
01260 jj += NI_val_to_binary( rt[col]->part_rtp[ii],
01261 ptr+rt[col]->part_off[ii], wbuf+jj ) ;
01262 break ;
01263 }
01264
01265 } else { /*-- variable dimension array --*/
01266
01267 char **apt = (char **)(ptr+rt[col]->part_off[ii]); /* data in struct */
01268 /* is ptr to array */
01269
01270 dim = ROWTYPE_part_dimen(rt[col],ptr,ii) ; /* dimension of part */
01271 if( dim > 0 && *apt != NULL ){
01272 switch( tmode ){
01273 case NI_TEXT_MODE:
01274 NI_multival_to_text( rt[col]->part_rtp[ii] , dim ,
01275 *apt , wbuf ) ;
01276 break ;
01277 case NI_BASE64_MODE:
01278 case NI_BINARY_MODE:
01279 jj += NI_multival_to_binary( rt[col]->part_rtp[ii] , dim ,
01280 *apt , wbuf+jj ) ;
01281 break ;
01282 }
01283 }
01284 }
01285
01286 } /* end of loop over parts in this column struct */
01287 } /* end of loop over columns */
01288
01289 /*- actually write the row data in wbuf out -*/
01290
01291 switch( tmode ){
01292
01293 case NI_TEXT_MODE: /* each row is on a separate line */
01294 strcat(wbuf,"\n") ;
01295 nout = NI_stream_writestring( ns , wbuf ) ;
01296 ADDOUT ;
01297 break ;
01298
01299 case NI_BINARY_MODE: /* jj bytes of binary in wbuf */
01300 nout = NI_stream_write( ns , wbuf , jj ) ;
01301 #ifdef NIML_DEBUG
01302 if( nout != jj ) NI_dpr("NI_write_columns: col#%d sends %d bytes; nout=%d\n",col,jj,nout) ;
01303 #endif
01304 ADDOUT ;
01305 break ;
01306
01307 case NI_BASE64_MODE:{ /* convert binary triples into base64 quads */
01308 int nb , nb3 , nb64 , pp,qq ;
01309 byte a,b,c,w,x,y,z ;
01310
01311 /* bbuf = bb bytes of unprocessed data from last struct
01312 plus jj bytes of data from new struct
01313 (bb will be 0 or 1 or 2) */
01314
01315 memcpy(bbuf+bb,wbuf,jj) ; /* add wbuf to tail of bbuf */
01316 nb = jj+bb ; /* number of bytes in bb */
01317 if( nb < 3 ){ bb = nb; break; } /* need at least 3 bytes */
01318 nb3 = 3*(nb/3) ; /* will encode nb3 bytes */
01319
01320 /* cbuf = base64 output buffer */
01321 /* cc = # bytes written since last EOL */
01322
01323 for( qq=pp=0 ; pp < nb3 ; ){
01324 a = bbuf[pp++] ; b = bbuf[pp++] ; c = bbuf[pp++] ;
01325 B64_encode3(a,b,c,w,x,y,z) ;
01326 cbuf[qq++] = w ; cbuf[qq++] = x ;
01327 cbuf[qq++] = y ; cbuf[qq++] = z ;
01328 cc += 4; if( cc > 64 ){ cbuf[qq++]=B64_EOL2; cc=0; }
01329 }
01330
01331 /* write base64 bytes to output */
01332
01333 nout = NI_stream_write( ns , cbuf , qq ) ;
01334 ADDOUT ;
01335
01336 /* deal with leftover bytes in bbuf */
01337
01338 bb = nb - nb3 ; /* num leftover bytes = 0, 1, or 2 */
01339 if( bb > 0 ){
01340 bbuf[0] = bbuf[nb3] ; /* copy leftovers */
01341 if( bb > 1 ) bbuf[1] = bbuf[nb3+1] ; /* to front of bbuf */
01342 }
01343 }
01344 break ;
01345 }
01346
01347 } /* end of loop over output structs (row) */
01348
01349 /* in Base64 mode, we might have to clean
01350 up if there are any leftover bytes in bbuf,
01351 or at least write an end of line */
01352
01353 if( tmode == NI_BASE64_MODE ){
01354 if( bb > 0 ){ /* num leftover bytes of data */
01355 byte w,x,y,z , a=bbuf[0],b=bbuf[1] ;
01356 if( bb == 2 ) B64_encode2(a,b,w,x,y,z) ;
01357 else B64_encode1(a,w,x,y,z) ;
01358 cbuf[0] = w ; cbuf[1] = x ;
01359 cbuf[2] = y ; cbuf[3] = z ; cbuf[4] = B64_EOL2 ;
01360 nout = NI_stream_write( ns , cbuf , 5 ) ;
01361 ADDOUT ;
01362 } else if( cc > 0 ){ /* just write an end of line */
01363 cbuf[0] = B64_EOL2 ;
01364 nout = NI_stream_write( ns , cbuf , 1 ) ;
01365 ADDOUT ;
01366 }
01367 }
01368
01369 /*-- cleanup and return --*/
01370
01371 FREEUP ;
01372 return ntot ;
01373 }
|
|
||||||||||||||||
|
Write an element (data or group) to a stream. Return value is number of bytes written to the stream. If return is -1, something bad happened. You should then check the stream with NI_stream_goodcheck(), for example. If the stream is temporarily unable to write (e.g., the socket buffer is full), then this function will wait until it is ready. If you don't want that behavior, you should use NI_stream_writecheck() before calling this function. -------------------------------------------------------------------------- Definition at line 904 of file niml_elemio.c. References att_len, NI_procins::attr_lhs, NI_group::attr_lhs, NI_element::attr_lhs, NI_procins::attr_num, NI_group::attr_num, NI_element::attr_num, NI_procins::attr_rhs, NI_group::attr_rhs, NI_element::attr_rhs, NI_stream_type::bad, cbuf, NI_procins::name, NI_group::name, NI_element::name, NI_BASE64_MODE, NI_BINARY_MODE, NI_byteorder(), NI_dpr(), NI_element_type(), NI_ELEMENT_TYPE, NI_free, NI_GROUP_TYPE, NI_has_String(), NI_HEADERONLY_FLAG, NI_HEADERSHARP_FLAG, NI_is_name(), NI_LSB_FIRST, NI_malloc, NI_PROCINS_TYPE, NI_realloc, NI_rowtype_find_code(), NI_set_attribute(), NI_size_column(), NI_stream_goodcheck(), NI_stream_write(), NI_stream_writeable(), NI_stream_writecheck(), NI_stream_writestring(), NI_STRING_TYPE, NI_strlen(), NI_TEXT_MODE, NI_type_name(), NI_write_columns(), NI_group::outmode, NI_element::outmode, NI_group::part, NI_group::part_num, quotize_float_vector(), quotize_int_vector(), quotize_string(), quotize_string_vector(), tt, NI_stream_type::type, NI_element::vec, NI_element::vec_axis_delta, NI_element::vec_axis_label, NI_element::vec_axis_len, NI_element::vec_axis_origin, NI_element::vec_axis_unit, NI_element::vec_len, NI_element::vec_num, NI_element::vec_rank, and NI_element::vec_typ. Referenced by AFNI_niml_redisplay_CB(), AFNI_niml_viewpoint_CB(), AFNI_version_check(), Dtable_to_nimlstring(), DWI_NIML_create_graph(), main(), nifti_set_afni_extension(), NIML_to_stderr(), SUMA_DsetInfo(), SUMA_Engine(), SUMA_FakeIt(), SUMA_nel_stdout(), SUMA_Paint_SO_ROIplanes_w(), SUMA_SaveVisualState(), SUMA_SendDset_Afni(), SUMA_SendToSuma(), SUMA_ShowNel(), SUMA_Write_DrawnROI_NIML(), THD_write_nimlatr(), v2s_write_outfile_niml(), and XSAVE_output().
00905 {
00906 char *wbuf , *att=NULL , *qtt , *btt ;
00907 int nwbuf , ii,jj,row,col , tt=NI_element_type(nini) , ntot=0,nout ;
00908 int att_len , kk ;
00909
00910 char *bbuf , *cbuf ; /* base64 stuff */
00911 int bb=0 , cc=0 ;
00912
00913 char *att_prefix , *att_equals , *att_trail ;
00914 int header_only , header_sharp , outmode ;
00915
00916 /*--- 09 Mar 2005: outmode overrided tmode, if present ---*/
00917
00918 switch( tt ){
00919 default: return -1 ; /* bad input! */
00920
00921 case NI_GROUP_TYPE:{
00922 NI_group *ngr = (NI_group *) nini ;
00923 outmode = ngr->outmode ;
00924 }
00925 break ;
00926
00927 case NI_ELEMENT_TYPE:{
00928 NI_element *nel = (NI_element *) nini ;
00929 outmode = nel->outmode ;
00930 }
00931 break ;
00932
00933 case NI_PROCINS_TYPE:{ /* 16 Mar 2005 */
00934 outmode = NI_TEXT_MODE ;
00935 }
00936 break ;
00937 }
00938 if( outmode >= 0 ) tmode = outmode ;
00939
00940 /*--- determine special cases from the flags above bit #7 ---*/
00941
00942 header_only = ((tmode & NI_HEADERONLY_FLAG ) != 0) ; /* 20 Feb 2003 */
00943 header_sharp = ((tmode & NI_HEADERSHARP_FLAG) != 0) ; /* 20 Mar 2003 */
00944
00945 /* ADDOUT = after writing, add byte count if OK, else quit */
00946 /* AF = thing to do if ADDOUT is quitting */
00947
00948 #ifdef NIML_DEBUG
00949 NI_dpr("ENTER NI_write_element\n") ;
00950 #endif
00951
00952 #undef AF
00953 #define AF 0
00954 #define ADDOUT if(nout<0){AF;fprintf(stderr,"NIML: write abort!\n");return -1;} else ntot+=nout
00955
00956 if( !NI_stream_writeable(ns) ) return -1 ; /* stupid user */
00957
00958 if( ns->bad ){ /* socket that hasn't connected yet */
00959 #ifdef NIML_DEBUG
00960 NI_dpr("NI_write_element: write socket not connected\n") ;
00961 #endif
00962 jj = NI_stream_goodcheck(ns,666) ; /* try to connect it */
00963 if( jj < 1 ) return jj ; /* 0 is nothing yet, -1 is death */
00964 #ifdef NIML_DEBUG
00965 NI_dpr("NI_write_element: write socket now connected\n") ;
00966 #endif
00967 } else { /* check if good ns has gone bad */
00968 jj = NI_stream_writecheck(ns,666) ;
00969 if( jj < 0 ) return jj ;
00970 }
00971
00972 tmode &= 255 ;
00973 if( ns->type == NI_STRING_TYPE ) /* string output only in text mode */
00974 tmode = NI_TEXT_MODE ;
00975
00976 if( tmode != NI_TEXT_MODE ) header_sharp = 0 ; /* 20 Mar 2003 */
00977
00978 /*-- 15 Oct 2002: write attributes with lots of space, or little --*/
00979 /*-- 20 Mar 2003: modified for "# lhs = rhs" type of header --*/
00980
00981 att_prefix = (header_sharp) ? (char *)"\n# " /* write this before each attribute */
00982 : (char *)"\n " ;
00983
00984 att_equals = (header_sharp) ? (char *)" = " /* write this between lhs and rhs */
00985 : (char *)"=" ;
00986
00987 att_trail = (header_sharp) ? (char *)"\n# " /* write this before closing ">" */
00988 : (char *)" " ;
00989
00990 /*------------------ write a processing instruction ------------------*/
00991
00992 if( tt == NI_PROCINS_TYPE ){
00993
00994 NI_procins *npi = (NI_procins *)nini ;
00995
00996 if( header_sharp ){ nout = NI_stream_writestring(ns,"# "); ADDOUT; }
00997
00998 nout = NI_stream_writestring( ns , "<?" ) ; ADDOUT ;
00999 nout = NI_stream_writestring( ns , npi->name ) ; ADDOUT ;
01000
01001 /*- attributes -*/
01002
01003 for( ii=0 ; ii < npi->attr_num ; ii++ ){
01004
01005 jj = NI_strlen( npi->attr_lhs[ii] ) ; if( jj == 0 ) continue ;
01006 nout = NI_stream_writestring( ns , " " ) ; ADDOUT ;
01007 if( NI_is_name(npi->attr_lhs[ii]) ){
01008 nout = NI_stream_write( ns , npi->attr_lhs[ii] , jj ) ;
01009 } else {
01010 att = quotize_string( npi->attr_lhs[ii] ) ;
01011 nout = NI_stream_writestring( ns , att ) ; NI_free(att) ;
01012 }
01013 ADDOUT ;
01014
01015 jj = NI_strlen( npi->attr_rhs[ii] ) ; if( jj == 0 ) continue ;
01016 nout = NI_stream_writestring( ns , "=" ) ; ADDOUT ;
01017 att = quotize_string( npi->attr_rhs[ii] ) ;
01018 nout = NI_stream_writestring( ns , att ) ; NI_free(att) ; ADDOUT ;
01019 }
01020
01021 nout = NI_stream_writestring( ns , " ?>\n" ) ; ADDOUT ;
01022
01023 return ntot ; /*** done with processing instruction ***/
01024
01025 /*------------------ write a group element ------------------*/
01026
01027 } else if( tt == NI_GROUP_TYPE ){
01028
01029 NI_group *ngr = (NI_group *) nini ;
01030 char *gname ;
01031
01032 /* 24 Feb 2005: all group elements used to be named "ni_group",
01033 but no more; now they have attribute ni_form="ni_group" */
01034
01035 gname = ngr->name ;
01036 if( gname == NULL || *gname == '\0' ) gname = "ni_group" ;
01037
01038 /*- group header -*/
01039
01040 if( header_sharp ){ nout = NI_stream_writestring(ns,"# "); ADDOUT; }
01041 #if 1
01042 nout = NI_stream_writestring( ns , "<" ) ; ADDOUT ;
01043 nout = NI_stream_writestring( ns , gname ) ; ADDOUT ;
01044 #else
01045 nout = NI_stream_writestring( ns , "<ni_group" ) ; ADDOUT ;
01046 #endif
01047
01048 /*- attributes -*/
01049
01050 NI_set_attribute( ngr , "ni_form" , "ni_group" ) ; /* 24 Feb 2005 */
01051
01052 for( ii=0 ; ii < ngr->attr_num ; ii++ ){
01053
01054 jj = NI_strlen( ngr->attr_lhs[ii] ) ; if( jj == 0 ) continue ;
01055 nout = NI_stream_writestring( ns , att_prefix ) ; ADDOUT ;
01056 if( NI_is_name(ngr->attr_lhs[ii]) ){
01057 nout = NI_stream_write( ns , ngr->attr_lhs[ii] , jj ) ;
01058 } else {
01059 att = quotize_string( ngr->attr_lhs[ii] ) ;
01060 nout = NI_stream_writestring( ns , att ) ; NI_free(att) ;
01061 }
01062 ADDOUT ;
01063
01064 jj = NI_strlen( ngr->attr_rhs[ii] ) ; if( jj == 0 ) continue ;
01065 nout = NI_stream_writestring( ns , att_equals ) ; ADDOUT ;
01066 att = quotize_string( ngr->attr_rhs[ii] ) ;
01067 nout = NI_stream_writestring( ns , att ) ; NI_free(att) ; ADDOUT ;
01068 }
01069
01070 /*- close group header -*/
01071
01072 nout = NI_stream_writestring( ns , att_trail ) ; ADDOUT ;
01073 nout = NI_stream_writestring( ns , ">\n" ) ; ADDOUT ;
01074
01075 /*- write the group parts (recursively) -*/
01076
01077 for( ii=0 ; ii < ngr->part_num ; ii++ ){
01078 nout = NI_write_element( ns , ngr->part[ii] , tmode ) ; ADDOUT ;
01079 }
01080
01081 /*- group trailer -*/
01082
01083 if( header_sharp ){ nout = NI_stream_writestring(ns,"# "); ADDOUT; }
01084 #if 1
01085 nout = NI_stream_writestring( ns , "</" ) ; ADDOUT ;
01086 nout = NI_stream_writestring( ns , gname ) ; ADDOUT ;
01087 nout = NI_stream_writestring( ns , ">\n" ) ; ADDOUT ;
01088 #else
01089 nout = NI_stream_writestring( ns , "</ni_group>\n" ) ; ADDOUT ;
01090 #endif
01091
01092 return ntot ; /*** done with group element ***/
01093
01094 /*------------------ write a data element ------------------*/
01095
01096 } else if( tt == NI_ELEMENT_TYPE ){
01097
01098 NI_element *nel = (NI_element *) nini ;
01099
01100 /*- sanity check (should never fail) -*/
01101
01102 jj = NI_strlen(nel->name) ; if( jj == 0 ) return -1 ;
01103
01104 /*- select the data output mode -*/
01105
01106 /* Strings can only be written in text mode */
01107
01108 if( tmode != NI_TEXT_MODE ){
01109 for( jj=0 ; jj < nel->vec_num ; jj++ ){
01110 if( NI_has_String(NI_rowtype_find_code(nel->vec_typ[jj])) ){
01111 tmode = NI_TEXT_MODE ; break ;
01112 }
01113 }
01114 }
01115
01116 switch( tmode ){
01117 default: tmode = NI_TEXT_MODE ; break ;
01118
01119 case NI_BINARY_MODE: break ;
01120 case NI_BASE64_MODE: break ;
01121 }
01122
01123 /* space to hold attribute strings */
01124
01125 att_len = 8192 + 64*nel->vec_num + 128*nel->vec_rank ;
01126 att = NI_malloc(char, att_len ) ;
01127
01128 #undef AF
01129 #define AF NI_free(att) /* free att if we have to quit early now */
01130
01131 /* write start of header "<name" */
01132
01133 if( header_sharp ){ nout = NI_stream_writestring(ns,"# "); ADDOUT; }
01134 strcpy(att,"<") ; strcat(att,nel->name) ;
01135 nout = NI_stream_writestring( ns , att ) ; ADDOUT ;
01136
01137 /*- write "special" attributes, if not an empty element -*/
01138
01139 if( nel->vec_len > 0 && nel->vec_num > 0 ){
01140 int ll , tt ;
01141
01142 /* ni_form (depends on tmode) */
01143
01144 switch( tmode ){
01145 default:
01146 case NI_TEXT_MODE:
01147 *att = '\0' ; /* text form is default */
01148 break ;
01149
01150 case NI_BINARY_MODE:
01151 case NI_BASE64_MODE:
01152 sprintf(att,"%sni_form%s\"%s.%s\"" ,
01153 att_prefix , att_equals ,
01154 (tmode == NI_BINARY_MODE) ? "binary" : "base64" ,
01155 (NI_byteorder()==NI_LSB_FIRST) ? "lsbfirst" : "msbfirst" );
01156 break ;
01157 }
01158 if( *att != '\0' ){
01159 nout = NI_stream_writestring( ns , att ) ; ADDOUT ;
01160 }
01161
01162 /** do ni_type **/
01163
01164 sprintf(att,"%sni_type%s\"" , att_prefix , att_equals ) ;
01165 for( ll=-1,ii=0 ; ii < nel->vec_num ; ii++ ){
01166 if( nel->vec_typ[ii] != ll ){ /* not the previous type */
01167 if( ll >= 0 ){ /* write the previous type out now */
01168 btt = att + strlen(att) ;
01169 if( jj > 1 ) sprintf(btt,"%d*%s,",jj,NI_type_name(ll)) ;
01170 else sprintf(btt,"%s," , NI_type_name(ll)) ;
01171 }
01172 ll = nel->vec_typ[ii] ; /* save new type code */
01173 jj = 1 ; /* it now has count 1 */
01174
01175 } else { /* same as previous type */
01176 jj++ ; /* so add 1 to its count */
01177 }
01178 }
01179 /* write the last type we found */
01180 btt = att + strlen(att) ;
01181 if( jj > 1 ) sprintf(btt,"%d*%s\"",jj,NI_type_name(ll)) ;
01182 else sprintf(btt,"%s\"" , NI_type_name(ll)) ;
01183
01184 nout = NI_stream_writestring( ns , att ) ; ADDOUT ;
01185
01186 /** do ni_dimen **/
01187
01188 if( nel->vec_rank > 1 ){
01189 sprintf(att,"%sni_dimen%s" , att_prefix , att_equals ) ;
01190 qtt = quotize_int_vector( nel->vec_rank ,
01191 nel->vec_axis_len , ',' ) ;
01192 strcat(att,qtt) ; NI_free(qtt) ;
01193 } else {
01194 sprintf(att,"%sni_dimen%s\"%d\"",att_prefix,att_equals,nel->vec_len);
01195 }
01196 nout = NI_stream_writestring( ns , att ) ; ADDOUT ;
01197
01198 #if 0
01199 /** 26 Mar 2003: write number of bytes of data contained herein **/
01200
01201 for( jj=ii=0 ; ii < nel->vec_num ; ii++ )
01202 jj += NI_size_column( NI_rowtype_find_code(nel->vec_typ[ii]) ,
01203 nel->vec_len , nel->vec[ii] ) ;
01204 sprintf(att,"%sni_datasize%s\"%d\"" , att_prefix , att_equals , jj ) ;
01205 nout = NI_stream_writestring( ns , att ) ; ADDOUT ;
01206 #endif
01207
01208 #if 0
01209 /* extras: ni_veclen and ni_vecnum attributes */
01210
01211 sprintf(att,"%sni_veclen%s\"%d\"", att_prefix,att_equals,nel->vec_len) ;
01212 nout = NI_stream_writestring( ns , att ) ; ADDOUT ;
01213
01214 sprintf(att,"%sni_vecnum%s\"%d\"", att_prefix,att_equals,nel->vec_num) ;
01215 nout = NI_stream_writestring( ns , att ) ; ADDOUT ;
01216 #endif
01217 /* ni_delta */
01218
01219 if( nel->vec_axis_delta != NULL ){
01220 sprintf(att,"%sni_delta%s",att_prefix,att_equals) ;
01221 qtt = quotize_float_vector( nel->vec_rank ,
01222 nel->vec_axis_delta , ',' ) ;
01223 strcat(att,qtt) ; NI_free(qtt) ;
01224 nout = NI_stream_writestring( ns , att ) ; ADDOUT ;
01225 }
01226
01227 /* ni_origin */
01228
01229 if( nel->vec_axis_origin != NULL ){
01230 sprintf(att,"%sni_origin%s",att_prefix,att_equals) ;
01231 qtt = quotize_float_vector( nel->vec_rank ,
01232 nel->vec_axis_origin , ',' ) ;
01233 strcat(att,qtt) ; NI_free(qtt) ;
01234 nout = NI_stream_writestring( ns , att ) ; ADDOUT ;
01235 }
01236
01237 /* ni_units */
01238
01239 if( nel->vec_axis_unit != NULL ){
01240 sprintf(att,"%sni_units%s",att_prefix,att_equals) ;
01241 qtt = quotize_string_vector( nel->vec_rank ,
01242 nel->vec_axis_unit , ',' ) ;
01243 strcat(att,qtt) ; NI_free(qtt) ;
01244 nout = NI_stream_writestring( ns , att ) ; ADDOUT ;
01245 }
01246
01247 /* ni_axes */
01248
01249 if( nel->vec_axis_label != NULL ){
01250 sprintf(att,"%sni_axes%s",att_prefix,att_equals) ;
01251 qtt = quotize_string_vector( nel->vec_rank ,
01252 nel->vec_axis_label , ',' ) ;
01253 strcat(att,qtt) ; NI_free(qtt) ;
01254 nout = NI_stream_writestring( ns , att ) ; ADDOUT ;
01255 }
01256
01257 }
01258
01259 /*- other attributes -*/
01260
01261 for( ii=0 ; ii < nel->attr_num ; ii++ ){
01262
01263 jj = NI_strlen( nel->attr_lhs[ii] ) ; if( jj == 0 ) continue ;
01264
01265 /* skip "special" attributes */
01266
01267 if( strcmp(nel->attr_lhs[ii],"ni_form") == 0 ) continue ;
01268 if( strcmp(nel->attr_lhs[ii],"ni_type") == 0 ) continue ;
01269 if( strcmp(nel->attr_lhs[ii],"ni_dimen") == 0 ) continue ;
01270 if( strcmp(nel->attr_lhs[ii],"ni_veclen") == 0 ) continue ;
01271 if( strcmp(nel->attr_lhs[ii],"ni_vecnum") == 0 ) continue ;
01272 if( strcmp(nel->attr_lhs[ii],"ni_delta") == 0 ) continue ;
01273 if( strcmp(nel->attr_lhs[ii],"ni_origin") == 0 ) continue ;
01274 if( strcmp(nel->attr_lhs[ii],"ni_units") == 0 ) continue ;
01275 if( strcmp(nel->attr_lhs[ii],"ni_axes") == 0 ) continue ;
01276 if( strcmp(nel->attr_lhs[ii],"ni_datasize") == 0 ) continue ; /* 13 Apr 2004 */
01277
01278 kk = NI_strlen( nel->attr_rhs[ii] ) ;
01279
01280 /* do the work */
01281
01282 if( jj+kk+128 > att_len ){ /* 13 Jun 2003 */
01283 att_len = jj+kk+128 ;
01284 att = NI_realloc( att , char, att_len ) ;
01285 }
01286
01287 strcpy(att,att_prefix) ;
01288
01289 if( NI_is_name(nel->attr_lhs[ii]) ){ /* the 'normal' case */
01290 strcat(att,nel->attr_lhs[ii]) ;
01291 } else { /* not legal in XML */
01292 qtt = quotize_string( nel->attr_lhs[ii] ) ;
01293 strcat(att,qtt) ; NI_free(qtt) ;
01294 }
01295
01296 if( kk > 0 ){
01297 strcat(att,att_equals) ;
01298 qtt = quotize_string( nel->attr_rhs[ii] ) ; /* RHS always quoted */
01299 strcat(att,qtt) ; NI_free(qtt) ;
01300 }
01301 nout = NI_stream_writestring( ns , att ) ; ADDOUT ;
01302 }
01303
01304 NI_free(att) ; att = NULL ; /* done with attributes */
01305
01306 #undef AF
01307 #define AF 0 /* nothing to do if we have to quit early */
01308
01309 /*- close header -*/
01310
01311 if( nel->vec_len == 0 || /* An 'empty' element (no data) */
01312 nel->vec_num == 0 ||
01313 nel->vec_typ == NULL ||
01314 nel->vec == NULL ){
01315
01316 nout = NI_stream_writestring( ns , att_trail ) ; ADDOUT ;
01317 nout = NI_stream_writestring( ns , "/>\n" ) ; ADDOUT ;
01318
01319 #ifdef NIML_DEBUG
01320 NI_dpr("NI_write_element: empty element '%s' had %d total bytes\n",nel->name,ntot) ;
01321 #endif
01322 return ntot ; /*** done with empty data element ***/
01323 }
01324
01325 /*- if here, must write some data out -*/
01326
01327 /* first, terminate the header,
01328 and allocate space for the write buffer (1 row at a time) */
01329
01330 switch( tmode ){
01331 default:
01332 case NI_TEXT_MODE:
01333 btt = ">\n" ; /* add a newline */
01334 break ;
01335
01336 case NI_BINARY_MODE:
01337 btt = ">" ; /* no newline */
01338 break ;
01339
01340 case NI_BASE64_MODE:
01341 btt = ">\n" ; /* add a newline */
01342 break ;
01343 }
01344
01345 nout = NI_stream_writestring( ns , att_trail ) ; ADDOUT ;
01346 nout = NI_stream_writestring( ns , btt ) ; ADDOUT ;
01347
01348 /*-- 13 Feb 2003: data output is now done elsewhere --*/
01349
01350 if( !header_only ){
01351 nout = NI_write_columns( ns, nel->vec_num, nel->vec_typ,
01352 nel->vec_len, nel->vec , tmode ) ;
01353 ADDOUT ;
01354 }
01355 #ifdef NIML_DEBUG
01356 else NI_dpr("NI_write_element: header_only case\n") ;
01357 #endif
01358
01359 /*- write element trailer -*/
01360
01361 if( header_sharp ){ nout = NI_stream_writestring(ns,"# "); ADDOUT; }
01362 nout = NI_stream_writestring( ns , "</" ) ; ADDOUT ;
01363 nout = NI_stream_writestring( ns , nel->name ) ; ADDOUT ;
01364 nout = NI_stream_writestring( ns , ">\n\n" ) ; ADDOUT ;
01365
01366 #ifdef NIML_DEBUG
01367 NI_dpr("NI_write_element: data element '%s' had %d total bytes\n",nel->name,ntot) ;
01368 #endif
01369 return ntot ; /*** done with full data element ***/
01370
01371 } /* end of write data element */
01372
01373 return -1 ; /* should never be reachable */
01374 }
|
|
||||||||||||
|
Write a simple processing instruction to the stream:
Definition at line 45 of file niml_elemio.c. References NI_stream_type::bad, free, IS_STRING_CHAR, malloc, NI_stream_goodcheck(), NI_stream_writeable(), NI_stream_writecheck(), and NI_stream_writestring(). Referenced by main(), and SUMA_SendDset_Afni().
00046 {
00047 char *buf ; int jj ;
00048
00049 /* check inputs for good-ositifulness */
00050
00051 if( !NI_stream_writeable(ns) ) return -1 ; /* stupid user */
00052 if( str == NULL || !IS_STRING_CHAR(*str) ) return -1 ;
00053
00054 /* check if stream is ready to take data */
00055
00056 if( ns->bad ){ /* socket that hasn't connected yet */
00057 jj = NI_stream_goodcheck(ns,666) ; /* try to connect it */
00058 if( jj < 1 ) return jj ; /* 0 is nothing yet, -1 is death */
00059 } else { /* check if good ns has gone bad */
00060 jj = NI_stream_writecheck(ns,666) ;
00061 if( jj < 0 ) return jj ;
00062 }
00063
00064 /* write the processing instruction: "<?str ?>\n" */
00065
00066 buf = (char *)malloc(strlen(str)+16) ;
00067 sprintf( buf , "<?%s ?>\n" , str ) ;
00068 jj = NI_stream_writestring( ns , buf ) ;
00069
00070 free((void *)buf) ; return jj ;
00071 }
|
|
||||||||||||||||||||||||
|
Write one column of structs to the output stream. Now superseded by NI_write_columns(). -------------------------------------------------------------------------- Definition at line 1060 of file niml_rowtype.c. References NI_rowtype::code, and NI_write_columns().
01062 {
01063 void *dpt = dat ;
01064 if( rt == NULL ) return -1 ;
01065 return NI_write_columns( ns , 1 , &(rt->code) , ndat , &dpt , tmode ) ;
01066 }
|
|
||||||||||||
|
Profile a Htable to stdout. ------------------------------------------------------------------- Definition at line 234 of file niml_htable.c. References Htable::ctab, Htable::len, Htable::ntab, Htable::ntot, and Htable::vtab. Referenced by setup_basic_types().
00235 {
00236 int jj, kk , nn ;
00237
00238 printf("\n----- Htable profile: %s\n",(str != NULL) ? str : "" ) ;
00239 if( ht == NULL ){
00240 printf("++ EMPTY ++\n") ; return ;
00241 }
00242
00243 printf("Rows=%d Ntot=%d\n",ht->len,ht->ntot) ;
00244
00245 for( jj=0 ; jj < ht->len ; jj++ ){
00246 printf(" #%05d: ",jj) ;
00247 if( ht->vtab[jj] == NULL ){
00248 printf("++ EMPTY ++\n") ;
00249 } else {
00250 for( nn=kk=0 ; kk < ht->ntab[jj] ; kk++ ){
00251 if( ht->ctab[jj][kk] != NULL ){ printf("*") ; nn++ ; }
00252 else { printf(".") ; }
00253 }
00254 printf(" [ntab=%d nn=%d]\n",ht->ntab[jj],nn) ;
00255 }
00256 }
00257 fflush(stdout) ;
00258 }
|
|
||||||||||||
|
Definition at line 68 of file niml_dtable.c. References dt, findin_Htable(), free, Dtable::hta, Dtable::htb, and removefrom_Htable(). Referenced by DRAW_label_CB().
00069 {
00070 char *str_bb , *str_aa ;
00071 if( dt == NULL ) return ;
00072 str_bb = (char *)findin_Htable( str_a , dt->hta ) ;
00073 if( str_bb == NULL ) return ;
00074 str_aa = (char *)findin_Htable( str_bb, dt->htb ) ;
00075 removefrom_Htable( str_a , dt->hta ) ;
00076 removefrom_Htable( str_bb, dt->htb ) ;
00077
00078 /* must also remove dangling targets from each Htable */
00079
00080 free((void *)str_bb) ; if( str_aa != NULL ) free((void *)str_aa) ;
00081 return ;
00082 }
|
|
||||||||||||
|
Definition at line 86 of file niml_dtable.c. References dt, findin_Htable(), free, Dtable::hta, Dtable::htb, and removefrom_Htable().
00087 {
00088 char *str_aa , *str_bb ;
00089 if( dt == NULL ) return ;
00090 str_aa = (char *)findin_Htable( str_b , dt->htb ) ;
00091 if( str_aa == NULL ) return ;
00092 str_bb = (char *)findin_Htable( str_aa, dt->hta ) ;
00093 removefrom_Htable( str_b , dt->htb ) ;
00094 removefrom_Htable( str_aa, dt->hta ) ;
00095
00096 free((void *)str_aa) ; if( str_bb != NULL ) free((void *)str_bb) ;
00097 return ;
00098 }
|
|
||||||||||||
|
Remove an entry from a Htable. ---------------------------------------------------------- Definition at line 199 of file niml_htable.c. References Htable::ctab, free, hashkey(), key, Htable::len, Htable::ntab, Htable::ntot, UINT, Htable::vtab, and vtkill. Referenced by addto_Htable(), NI_registry_free(), NI_registry_realloc(), NI_registry_replace(), NI_unregister_struct(), removefrom_Dtable_a(), and removefrom_Dtable_b().
00200 {
00201 UINT jj ;
00202 int kk ;
00203 char *key ;
00204 void ***vtab ;
00205 char **ctab ;
00206 int ntab ;
00207
00208 if( str == NULL || ht == NULL || ht->ntot == 0 ) return ;
00209
00210 jj = hashkey(str) % ht->len ; /* hash table row */
00211
00212 vtab = ht->vtab ;
00213
00214 if( vtab[jj] == NULL ) return ; /* nothing there */
00215
00216 key = str ;
00217
00218 ctab = ht->ctab[jj] ; ntab = ht->ntab[jj] ;
00219
00220 for( kk=0 ; kk < ntab ; kk++ ) /* scan for match of key to ctab */
00221 if( ctab[kk] != NULL && strcmp(key,ctab[kk]) == 0 ){
00222 free(ctab[kk]); ctab[kk] = NULL;
00223 if( vtkill && vtab[jj][kk] != NULL ) free(vtab[jj][kk]) ;
00224 vtab[jj][kk] = NULL; ht->ntot--; break;
00225 }
00226
00227 return ;
00228 }
|
|
||||||||||||
|
Resize the guts of a Htable [28 Feb 2005] ------------------------------------------------------------------- Definition at line 285 of file niml_htable.c. References Htable::ctab, free, Htable::len, new_Htable(), Htable::ntab, Htable::ntot, subsume_Htable(), and Htable::vtab.
00286 {
00287 Htable *htnew ;
00288 int jj , kk ;
00289
00290 if( ht == NULL ) return ;
00291
00292 /* auto-resize? */
00293
00294 if( newlen == 0 ){
00295 if( ht->ntot <= 131 * ht->len ) return ;
00296 newlen = ht->ntot / 37 ;
00297 }
00298
00299 /* create new Htable, copy contents of this one into it */
00300
00301 htnew = new_Htable( newlen ) ;
00302 if( htnew == NULL ) return ;
00303
00304 subsume_Htable( ht , htnew ) ;
00305
00306 /* erase contents of this one now */
00307
00308 for( jj=0 ; jj < ht->len ; jj++ ){
00309 if( ht->vtab[jj] != NULL ) free(ht->vtab[jj]) ;
00310
00311 if( ht->ctab[jj] != NULL ){
00312 for( kk=0 ; kk < ht->ntab[jj] ; kk++ )
00313 if( ht->ctab[jj][kk] != NULL ) free(ht->ctab[jj][kk]) ;
00314 free(ht->ctab[jj]) ;
00315 }
00316 }
00317 free(ht->vtab) ; free(ht->ctab) ; free(ht->ntab) ;
00318
00319 /* copy guts of new Htable over the guts of this one */
00320
00321 *ht = *htnew ;
00322
00323 /* free the shell of the new Htable and exit */
00324
00325 free((void *)htnew) ; return ;
00326 }
|
|
||||||||||||
|
Put contents of htold into htnew. ------------------------------------------------------------------- Definition at line 264 of file niml_htable.c. References addto_Htable(), Htable::ctab, Htable::len, Htable::ntab, Htable::ntot, and Htable::vtab. Referenced by AFNI_finalize_read_sess_CB(), AFNI_read_inputs(), AFNI_rescan_session_NEW(), AFNI_rescan_session_OLD(), and resize_Htable().
00265 {
00266 int kk,jj ;
00267
00268 /* check inputs for sanity */
00269
00270 if( htold == NULL || htold->ntot == 0 || htnew == NULL ) return ;
00271
00272 for( jj=0 ; jj < htold->len ; jj++ ){
00273 if( htold->vtab[jj] != NULL ){
00274 for( kk=0 ; kk < htold->ntab[jj] ; kk++ )
00275 if( htold->ctab[jj][kk] != NULL )
00276 addto_Htable( htold->ctab[jj][kk] , htold->vtab[jj][kk] , htnew ) ;
00277 }
00278 }
00279 }
|
|
|
Make an idcode-formatted malloc-ed string from an input string. Unlike UNIQ_idcode(), this will always return the same value, given the same input. ------------------------------------------------------------------------ Definition at line 144 of file niml_uuid.c. References calloc, free, getenv(), and MD5_B64_string(). Referenced by main(), MCW_hash_idcode(), SUMA_NewDsetGrp(), SUMA_NewNel(), and UNIQ_idcode().
00145 {
00146 char *idc , *eee ;
00147 int ii , nn ;
00148
00149 idc = (char *)calloc(1,32) ;
00150
00151 eee = getenv("IDCODE_PREFIX") ;
00152 if( eee != NULL && isalpha(eee[0]) ){
00153 for( ii=0 ; ii < 3 && isalnum(eee[ii]) ; ii++ )
00154 idc[ii] = eee[ii] ;
00155 } else {
00156 strcpy(idc,"XYZ") ; /* innocent default prefix */
00157 }
00158 strcat(idc,"_") ; /* recall idc was calloc()-ed */
00159
00160 if( str == NULL || str[0] == '\0' ) str = "Onen i Estel Edain" ;
00161 eee = MD5_B64_string(str) ;
00162 nn = strlen(eee) ;
00163 for( ii=0 ; ii < nn ; ii++ ){
00164 if( eee[ii] == '/' ) eee[ii] = '-' ; /* / -> - */
00165 else if( eee[ii] == '+' ) eee[ii] = '_' ; /* + -> _ */
00166 }
00167 strcat(idc,eee) ; free(eee) ; return idc ;
00168 }
|
|
|
Return a globally unique identifier (I hope). This is a malloc()-ed string of length <= 31 (plus the NUL byte; the whole thing will fit into a char[32] array). The output does not contain any '/'s, so it could be used as a temporary filename. Repeated calls to this function should never return the same string. Method: Generate a string from the system identfier information and the current time of day. MD5 hash this to a 128 byte code. Base64 encode this to a 22 byte string. Replace '/' with '-' and '+' with '_'. Add 4 character prefix (1st 3 characters of environment variable IDCODE_PREFIX plus '_'). Sample output: "XYZ_VdfGpfzy_NlY-2d7tA8Q1w" ------------------------------------------------------------------------- Definition at line 121 of file niml_uuid.c. References AFMALL, free, getenv(), and MD5_B64_string().
00122 {
00123 char *buf , *idc ;
00124
00125 /* get uniq string from system */
00126
00127 buf = get_UNIQ_string() ;
00128
00129 /* make the output by hashing the string in buf */
00130
00131 idc = UNIQ_hashcode( buf ) ;
00132
00133 /* free workspace and get outta here */
00134
00135 free(buf) ; return idc ;
00136 }
|
|
|
Fill a user-supplied buffer (length at least 32) with an idcode. That is, idc should point to a char array of length 32 (or more). ------------------------------------------------------------------------ Definition at line 175 of file niml_uuid.c. References free, and UNIQ_idcode(). Referenced by proc_finalize_shm_volumes(), process_NIML_SUMA_ixyz(), suma2afni_surf(), SUMA_Alloc_Axis(), SUMA_Alloc_SegmentDO(), SUMA_AllocateDrawnROI(), SUMA_AllocateROI(), SUMA_Cmap_To_SO(), SUMA_Cmap_To_SO_old(), SUMA_CreateChildSO(), SUMA_CreateIcosahedron(), SUMA_MaskedCopyofDset(), SUMA_morphToStd(), SUMA_NewDsetGrp(), SUMA_NewDsetID(), SUMA_NewNel(), SUMA_NewSO(), SUMA_NodeVal2irgba_nel(), and THD_alloc_datablock().
00176 {
00177 char *bbb ;
00178 if( idc == NULL ) return ;
00179 bbb = UNIQ_idcode() ;
00180 strcpy(idc,bbb) ; free(bbb) ; return ;
00181 }
|
|
|
Hash a string and return a malloc()-ed string (36+1 bytes) in the "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" format. ------------------------------------------------------------------------ Definition at line 188 of file niml_uuid.c. References calloc, MD5Final(), MD5Init(), and MD5Update(). Referenced by UUID_idcode().
00189 {
00190 MD5_CTX context;
00191 unsigned char digest[16];
00192 char *idc ;
00193 int ii , nn ;
00194
00195 if( str == NULL || str[0] == '\0' ) str = "Onen i Estel Edain" ;
00196
00197 MD5Init( &context ) ;
00198 MD5Update( &context, (unsigned char *)str, strlen(str) ) ;
00199 MD5Final( digest, &context ) ;
00200
00201 idc = (char *)calloc(1,48) ;
00202 sprintf(idc,
00203 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" ,
00204 digest[0] , digest[1] , digest[2] , digest[3] , digest[4] ,
00205 digest[5] , digest[6] , digest[7] , digest[8] , digest[9] ,
00206 digest[10], digest[11], digest[12], digest[13], digest[14],
00207 digest[15]
00208 ) ;
00209
00210 return idc ;
00211 }
|
|
|
Hash a unique string and return a malloc()-ed string (36+1 bytes) in the "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" format. The result should be unique worldwide, for all time. ------------------------------------------------------------------------ Definition at line 219 of file niml_uuid.c. References free, get_UNIQ_string(), and UUID_hashcode(). Referenced by main(), and NI_mktemp().
00220 {
00221 char *buf , *idc ;
00222
00223 /* get uniq string from system */
00224
00225 buf = get_UNIQ_string() ;
00226
00227 /* make the output by hashing the string in buf */
00228
00229 idc = UUID_hashcode( buf ) ;
00230
00231 /* free workspace and get outta here */
00232
00233 free(buf) ; return idc ;
00234 }
|