source: trunk/FACT++/dim/src/copy_swap.c@ 18522

Last change on this file since 18522 was 15282, checked in by tbretz, 12 years ago
Updated to v20r7.
File size: 8.1 KB
Line 
1#define DIMLIB
2#include <dim.h>
3#include <dic.h>
4#include <dis.h>
5
6#ifdef VMS
7# include <cvtdef.h>
8#endif
9
10#if defined(WIN32) || defined(__unix__)
11#define PADD64
12#endif
13
14#if defined(aix) || defined (LYNXOS)
15#undef PADD64
16#endif
17
18#if defined(__linux__) && !defined (__LP64__)
19#undef PADD64
20#endif
21
22static int Dic_padding = 1;
23static int Dis_padding = 1;
24
25void dic_disable_padding()
26{
27 Dic_padding = 0;
28}
29
30void dis_disable_padding()
31{
32 Dis_padding = 0;
33}
34
35static int get_curr_bytes(int items, int bytes_left, int item_size)
36{
37 int num;
38
39 if(!(num = items))
40 {
41 num = bytes_left;
42 }
43 else
44 {
45 num *= item_size;
46 }
47 return num;
48}
49
50#ifdef vms
51
52static int check_vms_out(flags, format, curr_par_num, buff_out)
53short flags;
54int format, curr_par_num;
55void *buff_out;
56{
57 unsigned int input_code;
58 int i;
59 int num;
60
61 if( (flags & IT_IS_FLOAT) && ((format & 0xF0) == IEEE_FLOAT) )
62 {
63 switch(flags & 0x3)
64 {
65 case SWAPL :
66 num = curr_par_num;
67 (int *)buff_out -= num;
68 for( i = 0; i < num; i++)
69 {
70 cvt$convert_float((void *)buff_out, CVT$K_VAX_F,
71 (void *)buff_out, CVT$K_IEEE_S,
72 0 );
73 ((int *)buff_out)++;
74 }
75 break;
76 case SWAPD :
77#ifdef __alpha
78 input_code = CVT$K_VAX_G;
79#else
80 input_code = CVT$K_VAX_D;
81#endif
82 num = curr_par_num;
83 (double *)buff_out -= num;
84 for( i = 0; i < num; i++ )
85 {
86 cvt$convert_float((void *)buff_out, input_code,
87 (void *)buff_out, CVT$K_IEEE_T,
88 0 );
89 ((double *)buff_out)++;
90 }
91 break;
92 }
93 }
94}
95
96
97
98static int check_vms_in(flags, curr_par_num, curr_par_bytes, buff_out)
99short flags;
100int curr_par_num, curr_par_bytes;
101void *buff_out;
102{
103 unsigned int input_code, output_code;
104 int i;
105 int num;
106
107 if(flags & 0xF0)
108 {
109 switch(curr_par_bytes)
110 {
111 case SIZEOF_FLOAT :
112 if((flags & 0xF0) == IEEE_FLOAT)
113 {
114 num = curr_par_num;
115 (int *)buff_out -= num;
116 for( i = 0; i<num; i++)
117 {
118 cvt$convert_float((void *)buff_out, CVT$K_IEEE_S,
119 (void *)buff_out, CVT$K_VAX_F,
120 0 );
121 ((int *)buff_out)++;
122 }
123 }
124 break;
125 case SIZEOF_DOUBLE :
126#ifdef __alpha
127 output_code = CVT$K_VAX_G;
128#else
129 output_code = CVT$K_VAX_D;
130#endif
131 switch(flags & 0xF0)
132 {
133 case VAX_FLOAT:
134 input_code = CVT$K_VAX_D;
135 break;
136 case AXP_FLOAT:
137 input_code = CVT$K_VAX_G;
138 break;
139 case IEEE_FLOAT:
140 input_code = CVT$K_IEEE_T;
141 break;
142 }
143 num = curr_par_num;
144 (double *)buff_out -= num;
145 for( i = 0; i<num; i++)
146 {
147 cvt$convert_float((void *)buff_out, input_code,
148 (void *)buff_out, output_code,
149 0 );
150 ((double *)buff_out)++;
151 }
152 break;
153 }
154 }
155}
156
157#endif
158
159static int check_padding(int curr_bytes, int item_size)
160{
161 int num;
162
163 if( (num = curr_bytes % item_size))
164 {
165 num = item_size - num;
166 }
167 return num;
168}
169
170int copy_swap_buffer_out(int format, FORMAT_STR *format_data, void *buff_out, void *buff_in, int size)
171{
172 int num = 0, pad_num = 0, curr_size = 0, curr_out = 0;
173 int next_par_bytes, curr_par_num;
174
175 if(format){}
176 if(!format_data->par_bytes) {
177 if(buff_in != buff_out)
178 memcpy( buff_out, buff_in, (size_t)size );
179 return(size);
180 }
181 next_par_bytes = format_data->par_bytes;
182 while(next_par_bytes)
183 {
184 curr_par_num = format_data->par_num;
185 if((curr_size+(curr_par_num * format_data->par_bytes))
186 > size)
187 {
188 curr_par_num = (size - curr_size)/format_data->par_bytes;
189 next_par_bytes = 0;
190 }
191 switch(format_data->flags & 0x3)
192 {
193 case NOSWAP :
194
195 num = get_curr_bytes(curr_par_num,
196 size - curr_size, SIZEOF_CHAR);
197
198 memcpy( buff_out, buff_in, (size_t)num);
199 inc_pter( buff_in, num);
200 inc_pter( buff_out, num);
201 curr_out += num;
202 break;
203 case SWAPS :
204 num = get_curr_bytes(curr_par_num,
205 size - curr_size, SIZEOF_SHORT);
206
207 if(Dis_padding)
208 {
209 if( (pad_num = check_padding(curr_size, SIZEOF_SHORT)) )
210 {
211 inc_pter( buff_in, pad_num);
212 curr_size += pad_num;
213 }
214 }
215 memcpy( buff_out, buff_in, (size_t)num);
216 inc_pter( buff_in, num);
217 inc_pter( buff_out, num);
218 curr_out += num;
219 break;
220 case SWAPL :
221 num = get_curr_bytes(curr_par_num,
222 size - curr_size, SIZEOF_LONG);
223
224 if(Dis_padding)
225 {
226 if( (pad_num = check_padding(curr_size, SIZEOF_LONG)) )
227 {
228 inc_pter( buff_in, pad_num);
229 curr_size += pad_num;
230 }
231 }
232 memcpy( buff_out, buff_in, (size_t)num);
233 inc_pter( buff_in, num);
234 inc_pter( buff_out, num);
235 curr_out += num;
236 break;
237 case SWAPD :
238 num = get_curr_bytes(curr_par_num,
239 size - curr_size, SIZEOF_DOUBLE);
240
241 if(Dis_padding)
242 {
243#ifdef PADD64
244 if( (pad_num = check_padding(curr_size, SIZEOF_DOUBLE)) )
245#else
246 if( (pad_num = check_padding(curr_size, SIZEOF_LONG)) )
247#endif
248 {
249 inc_pter( buff_in, pad_num);
250 curr_size += pad_num;
251 }
252 }
253 memcpy( buff_out, buff_in, (size_t)num);
254 inc_pter( buff_in, num);
255 inc_pter( buff_out, num);
256 curr_out += num;
257 break;
258 }
259#ifdef vms
260 check_vms_out(format_data->flags, format, curr_par_num, buff_out);
261#endif
262 curr_size += num;
263 format_data++;
264 if(next_par_bytes)
265 next_par_bytes = format_data->par_bytes;
266 }
267 return(curr_out);
268}
269
270int copy_swap_buffer_in(FORMAT_STR *format_data, void *buff_out, void *buff_in, int size)
271{
272 int num, pad_num, curr_size = 0, curr_out = 0;
273 int next_par_bytes, curr_par_num, curr_par_bytes;
274
275 num = 0;
276 if(!format_data->par_bytes) {
277 if(buff_in != buff_out)
278 memcpy( buff_out, buff_in, (size_t)size );
279 return(size);
280 }
281 next_par_bytes = format_data->par_bytes;
282 while(next_par_bytes)
283 {
284 curr_par_num = format_data->par_num;
285 curr_par_bytes = format_data->par_bytes;
286 if((curr_size+(curr_par_num * curr_par_bytes))
287 > size)
288 {
289 curr_par_num = (size - curr_size)/curr_par_bytes;
290 next_par_bytes = 0;
291 }
292 switch(format_data->flags & 0x3)
293 {
294 case NOSWAP :
295
296 num = get_curr_bytes(curr_par_num,
297 size - curr_size, curr_par_bytes);
298
299 if(Dic_padding)
300 {
301 if(curr_par_bytes == SIZEOF_DOUBLE)
302 {
303#ifdef PADD64
304 if( (pad_num = check_padding(curr_out, SIZEOF_DOUBLE)) )
305#else
306 if( (pad_num = check_padding(curr_out, SIZEOF_LONG)) )
307#endif
308 {
309 inc_pter( buff_out, pad_num);
310 curr_out += pad_num;
311 }
312 }
313 else
314 {
315 if( (pad_num = check_padding(curr_out, curr_par_bytes)) )
316 {
317 inc_pter( buff_out, pad_num);
318 curr_out += pad_num;
319 }
320 }
321 }
322
323 if(buff_in != buff_out)
324 memcpy( buff_out, buff_in, (size_t)num);
325 inc_pter( buff_in, num);
326 inc_pter( buff_out, num);
327 curr_out += num;
328 break;
329 case SWAPS :
330
331 num = get_curr_bytes(curr_par_num,
332 size - curr_size, SIZEOF_SHORT);
333
334 if(Dic_padding)
335 {
336 if( (pad_num = check_padding(curr_out, SIZEOF_SHORT)) )
337 {
338 inc_pter( buff_out, pad_num);
339 curr_out += pad_num;
340 }
341 }
342 _swaps_buffer( (short *)buff_out, (short *)buff_in, num/SIZEOF_SHORT) ;
343 inc_pter( buff_in, num);
344 inc_pter( buff_out, num);
345 curr_out += num;
346 break;
347 case SWAPL :
348
349 num = get_curr_bytes(curr_par_num,
350 size - curr_size, SIZEOF_LONG);
351
352 if(Dic_padding)
353 {
354 if( (pad_num = check_padding(curr_out, SIZEOF_LONG)) )
355 {
356 inc_pter( buff_out, pad_num);
357 curr_out += pad_num;
358 }
359 }
360 _swapl_buffer( (short *)buff_out, (short *)buff_in, num/SIZEOF_LONG) ;
361 inc_pter( buff_in, num);
362 inc_pter( buff_out, num);
363 curr_out += num;
364 break;
365 case SWAPD :
366
367 num = get_curr_bytes(curr_par_num,
368 size - curr_size, SIZEOF_DOUBLE);
369
370 if(Dic_padding)
371 {
372#ifdef PADD64
373 if( (pad_num = check_padding(curr_out, SIZEOF_DOUBLE)) )
374#else
375 if( (pad_num = check_padding(curr_out, SIZEOF_LONG)) )
376#endif
377 {
378 inc_pter( buff_out, pad_num);
379 curr_out += pad_num;
380 }
381 }
382 _swapd_buffer( (short *)buff_out, (short *)buff_in, num/SIZEOF_DOUBLE) ;
383 inc_pter( buff_in, num);
384 inc_pter( buff_out, num);
385 curr_out += num;
386 break;
387 }
388#ifdef vms
389 check_vms_in(format_data->flags, curr_par_num, curr_par_bytes, buff_out);
390#endif
391 curr_size += num;
392 format_data++;
393 if(next_par_bytes)
394 next_par_bytes = format_data->par_bytes;
395 }
396 return(curr_out);
397}
398
399
400
401
402
403
404
405
406
407
408
409
410
Note: See TracBrowser for help on using the repository browser.