1 #ifndef _NIML_PRIVATE_HEADER_FILE_
2 #define _NIML_PRIVATE_HEADER_FILE_
3 
4 #include "niml.h"
5 
6 #define USE_NEW_IOFUN      /* 13 Feb 2003 */
7 
8 /****************************************************************************/
9 /********* NIML private definitions, not needed by user programs ************/
10 /****************************************************************************/
11 
12 /************************** Debugging stuff (duh) ***************************/
13 
14 /*** Debug printout will only be enable if NIML_DEBUG
15      is defined here, AND if environment variable NIML_DEBUG
16      is also set to a filename (special case: or to the string "stderr"). ***/
17 
18 #define NIML_DEBUG
19 
20 #include <stdarg.h>
21 
22 extern FILE *dfp ;                     /* debug file pointer */
23 extern void NI_dpr( char * , ... ) ;   /* print debug stuff */
24 
25 /******************** typedefs used only internally *************************/
26 
27 /*! Holds strings from the <header and=attributes> */
28 
29 typedef struct {
30    int nattr ;            /*!< Number of attributes. */
31    int empty ;            /*!< Did header end in '/>'? */
32    char *name ;           /*!< Header name string. */
33    char **lhs ;           /*!< Left-hand-sides of attributes. */
34    char **rhs ;           /*!< Right-hand-sides of attributes (may be NULL). */
35 } header_stuff ;
36 
37 /*! A pair of integers (what did you think it was?). */
38 
39 #ifndef TYPEDEF_intpair
40 #define TYPEDEF_intpair
41 typedef struct { int i,j ; } intpair ;
42 #endif
43 
44 /*! An array of integers. */
45 
46 typedef struct { int num; int *ar; } int_array ;
47 
48 /****************************************************************************/
49 
50 extern void NI_stream_close_keep( NI_stream_type * ,int ) ;
51 
52 extern int string_index( char *targ, int nstr, char *str[] ) ;
53 extern int unescape_inplace( char *str ) ;
54 extern char * quotize_string( char *str ) ;
55 extern char * quotize_string_vector( int num , char **str , char sep ) ;
56 extern char * quotize_int_vector( int num , int *vec , char sep ) ;
57 extern char * quotize_float_vector( int num , float *vec , char sep ) ;
58 extern int NI_is_name( char *str ) ;
59 extern char * trailname( char *fname , int lev ) ;
60 
61 /****************************************************************************/
62 
63 extern int  dtable_mode ;
64 extern byte dtable[256] ;
65 extern int  linelen ;
66 extern int  ncrlf   ;
67 extern int  nocrlf  ;
68 
69 #define B64_goodchar(c) (dtable[c] != 0x80)  /* for decode only */
70 
71 #define B64_EOL1 '\r'   /* CR */
72 #define B64_EOL2 '\n'   /* LF */
73 
74 /*! Encode 3 bytes (a,b,c) into 4 bytes (w,x,y,z) */
75 
76 #define B64_encode3(a,b,c,w,x,y,z)                 \
77      ( w = dtable[(a)>>2]                      ,   \
78        x = dtable[((a & 3) << 4) | (b >> 4)]   ,   \
79        y = dtable[((b & 0xF) << 2) | (c >> 6)] ,   \
80        z = dtable[c & 0x3F]                     )
81 
82 /*! Encode 2 bytes (a,b) into 4 bytes (w,x,y,z) */
83 
84 #define B64_encode2(a,b,w,x,y,z)                   \
85      ( B64_encode3(a,b,0,w,x,y,z) , z = '=' )
86 
87 /*! Encode 1 byte (a) into 4 bytes (w,x,y,z) */
88 
89 #define B64_encode1(a,w,x,y,z)                     \
90      ( B64_encode3(a,0,0,w,x,y,z) , y=z = '=' )
91 
92 /*! Decode 4 bytes (w,x,y,z) into 3 bytes (a,b,c) */
93 
94 #define B64_decode4(w,x,y,z,a,b,c)                 \
95      ( a = (dtable[w] << 2) | (dtable[x] >> 4) ,   \
96        b = (dtable[x] << 4) | (dtable[y] >> 2) ,   \
97        c = (dtable[y] << 6) | dtable[z]         )
98 
99 /*! Determine how many output bytes are encoded in a quad (w,x,y,z) */
100 
101 #define B64_decode_count(w,x,y,z)                  \
102      ( ((w)=='='||(x)=='=') ? 0                    \
103                             : ((y)=='=') ? 1       \
104                             : ((z)=='=') ? 2 : 3 )
105 
106 extern void load_encode_table(void) ;
107 extern void load_decode_table(void) ;
108 
109 /****************************************************************************/
110 
111 typedef unsigned char *POINTER;   /* POINTER defines a generic pointer type */
112 typedef unsigned short int UINT2; /* UINT2 defines a two byte word */
113 typedef unsigned long int UINT4;  /* UINT4 defines a four byte word */
114 
115 /* MD5 context data type */
116 
117 typedef struct {
118   UINT4 state[4];                                        /* state (ABCD) */
119   UINT4 count[2];             /* number of bits, modulo 2^64 (lsb first) */
120   unsigned char buffer[64];                              /* input buffer */
121 } MD5_CTX;
122 
123 /* prototypes for some internal functions */
124 
125 extern void MD5Init (MD5_CTX *);
126 extern void MD5Update (MD5_CTX *, unsigned char *, unsigned int);
127 extern void MD5Final (unsigned char [16], MD5_CTX *);
128 
129 /****************************************************************************/
130 
131 extern int     typedef_nib ;
132 extern int     typedef_num ;
133 extern char ** typedef_nam ;
134 extern char ** typedef_typ ;
135 extern char ** typedef_dim ;
136 
137 /*! Characters allowed inside unquoted strings. */
138 
139 #define IS_STRING_CHAR(c) ( isgraph(c) && !isspace(c) &&  \
140                             (c) != '>' && (c) != '/'  &&  \
141                             (c) != '=' && (c) != '<'    )
142 
143 /*! Defines what we consider a quoting character. */
144 
145 #define IS_QUOTE_CHAR(c)  ( (c) == '"' || (c) == '\'' )
146 
147 /*! Defines characters allowed inside a "name". */
148 
149 #define IS_NAME_CHAR(c) \
150   (isalnum(c) || (c)=='_' || (c)=='.' || (c)=='-' || (c)==':')
151 
152 extern void destroy_header_stuff( header_stuff *hs ) ;
153 extern intpair find_string( int nst, int nch, char *ch ) ;
154 extern header_stuff * parse_header_stuff( int ndat, char *dat, int *nused ) ;
155 extern intpair decode_type_field( char *tf ) ;
156 extern int_array * decode_dimen_string( char *ds ) ;
157 extern int_array * decode_type_string( char *ts ) ;
158 extern char NI_type_char( int typ ) ;
159 extern void enhance_header_stuff( header_stuff *hs ) ;
160 extern char * get_header_attribute( header_stuff *hs , char *attname ) ;
161 
162 /****************************************************************************/
163 
164 extern NI_element * make_empty_data_element ( header_stuff *hs ) ;
165 extern NI_group   * make_empty_group_element( header_stuff *hs ) ;
166 extern void NI_fill_vector_row( NI_element *nel , int row , char *buf ) ;
167 
168 extern int NI_stream_writestring( NI_stream_type *ns , char *str ) ;
169 extern int NI_stream_fillbuf( NI_stream_type *ns, int minread, int msec ) ;
170 
171 extern void NI_reset_buffer( NI_stream_type * ) ;
172 extern int  NI_decode_one_double( NI_stream_type *, double *, int ) ;
173 extern int  NI_decode_one_string( NI_stream_type *, char ** , int ) ;
174 
175 extern void NI_set_veclab_from_stringlist( NI_element *nel , char *vstr ) ;
176 extern void NI_set_attribute_from_veclab_array( NI_element *nel , char **vec_lab ) ;
177 
178 #endif
179