~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/sys/dynamic/icopy.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)Array & Vector copying. (int verion)
  2  * Ie copy displaced vectors and arrays, casting as necessary.
  3  */
  4 
  5 #include <math.h>
  6 #include <stdio.h>
  7 #include <tina/sys.h>
  8 #include <tina/sysfuncs.h>
  9 
 10 void    error();
 11 
 12 /* make int copy of displaced vector of unsigned chars */
 13 
 14 int    *ivector_uccopy(unsigned char *v, int n1, int n2)
 15 {
 16     int    *ptr;
 17     int     i;
 18 
 19     if (n2 <= n1)
 20     {
 21         error("ivector_uccopy: bad array bounds", warning);
 22         return (NULL);
 23     }
 24     ptr = (int *) ralloc((unsigned) (n2 - n1) * sizeof(int)) - n1;
 25     for (i = n1; i < n2; ++i)
 26     {
 27         ptr[i] = v[i];
 28     }
 29     return (ptr);
 30 }
 31 
 32 /* make int copy of displaced array of unsigned chars */
 33 
 34 int   **iarray_uccopy(unsigned char **a, int m1, int n1, int m2, int n2)
 35 {
 36     int   **ptr;
 37     int     m = m2 - m1, n = n2 - n1;
 38     int     i, j;
 39 
 40     if (m < 0 || n < 0)
 41     {
 42         error("iarray_uccopy: bad array bounds", non_fatal);
 43         return (NULL);
 44     }
 45     if (m == 0 || n == 0)
 46     {
 47         error("iarray_uccopy: zero array size", warning);
 48         return (NULL);
 49     }
 50     ptr = (int **) ralloc((unsigned) m * sizeof(int *)) - m1;
 51     for (i = m1; i < m2; ++i)
 52         ptr[i] = (int *) ralloc((unsigned) n * sizeof(int)) - n1;
 53     for (i = m1; i < m2; ++i)
 54         for (j = n1; j < n2; ++j)
 55             ptr[i][j] = a[i][j];
 56     return (ptr);
 57 }
 58 
 59 /* make int copy of displaced lower triangle of unsigned chars */
 60 
 61 int   **ilower_uccopy(unsigned char **a, int m1, int n1, int m2, int n2)
 62 {
 63     int   **ptr;
 64     int     m = m2 - m1, n = n2 - n1;
 65     int     i, j;
 66 
 67     if (m < 0 || n < 0)
 68     {
 69         error("ilower_uccopy: bad array bounds", non_fatal);
 70         return (NULL);
 71     }
 72     if (m == 0 || n == 0)
 73     {
 74         error("ilower_uccopy: zero array size", warning);
 75         return (NULL);
 76     }
 77     ptr = (int **) ralloc((unsigned) m * sizeof(int *)) - m1;
 78     for (i = m1; i < m2; ++i)
 79         ptr[i] = (int *) ralloc((unsigned) n * sizeof(int)) - n1;
 80     for (i = m1; i < m2; ++i)
 81         for (j = n1; j <= i; ++j)
 82             ptr[i][j] = a[i][j];
 83     return (ptr);
 84 }
 85 
 86 /* make int copy of displaced upper triangle of unsigned chars */
 87 
 88 int   **iupper_uccopy(unsigned char **a, int n1, int n2)
 89 {
 90     int   **ptr;
 91     int     n = n2 - n1;
 92     int     i, j;
 93 
 94     if (n < 0)
 95     {
 96         error("iupper_uccopy: bad array bounds", non_fatal);
 97         return (NULL);
 98     }
 99     if (n == 0)
100     {
101         error("iupper_uccopy: zero array size", warning);
102         return (NULL);
103     }
104     ptr = (int **) ralloc((unsigned) n * sizeof(int *)) - n1;
105     for (i = n1; i < n2; ++i)
106         ptr[i] = (int *) ralloc((unsigned) (n2 - i) * sizeof(int)) - i;
107     for (i = n1; i < n2; ++i)
108         for (j = i; j < n2; ++j)
109             ptr[i][j] = a[i][j];
110     return (ptr);
111 }
112 
113 /* make int copy of displaced vector of chars */
114 
115 int    *ivector_ccopy(char *v, int n1, int n2)
116 {
117     int    *ptr;
118     int     i;
119 
120     if (n2 <= n1)
121     {
122         error("ivector_ccopy: bad array bounds", warning);
123         return (NULL);
124     }
125     ptr = (int *) ralloc((unsigned) (n2 - n1) * sizeof(int)) - n1;
126     for (i = n1; i < n2; ++i)
127     {
128         ptr[i] = v[i];
129     }
130     return (ptr);
131 }
132 
133 /* make int copy of displaced array of chars */
134 
135 int   **iarray_ccopy(char **a, int m1, int n1, int m2, int n2)
136 {
137     int   **ptr;
138     int     m = m2 - m1, n = n2 - n1;
139     int     i, j;
140 
141     if (m < 0 || n < 0)
142     {
143         error("iarray_ccopy: bad array bounds", non_fatal);
144         return (NULL);
145     }
146     if (m == 0 || n == 0)
147     {
148         error("iarray_ccopy: zero array size", warning);
149         return (NULL);
150     }
151     ptr = (int **) ralloc((unsigned) m * sizeof(int *)) - m1;
152     for (i = m1; i < m2; ++i)
153         ptr[i] = (int *) ralloc((unsigned) n * sizeof(int)) - n1;
154     for (i = m1; i < m2; ++i)
155         for (j = n1; j < n2; ++j)
156             ptr[i][j] = a[i][j];
157     return (ptr);
158 }
159 
160 /* make int copy of displaced lower triangle of chars */
161 
162 int   **ilower_ccopy(char **a, int m1, int n1, int m2, int n2)
163 {
164     int   **ptr;
165     int     m = m2 - m1, n = n2 - n1;
166     int     i, j;
167 
168     if (m < 0 || n < 0)
169     {
170         error("ilower_ccopy: bad array bounds", non_fatal);
171         return (NULL);
172     }
173     if (m == 0 || n == 0)
174     {
175         error("ilower_ccopy: zero array size", warning);
176         return (NULL);
177     }
178     ptr = (int **) ralloc((unsigned) m * sizeof(int *)) - m1;
179     for (i = m1; i < m2; ++i)
180         ptr[i] = (int *) ralloc((unsigned) n * sizeof(int)) - n1;
181     for (i = m1; i < m2; ++i)
182         for (j = n1; j <= i; ++j)
183             ptr[i][j] = a[i][j];
184     return (ptr);
185 }
186 
187 /* make int copy of displaced upper triangle of chars */
188 
189 int   **iupper_ccopy(char **a, int n1, int n2)
190 {
191     int   **ptr;
192     int     n = n2 - n1;
193     int     i, j;
194 
195     if (n < 0)
196     {
197         error("iupper_ccopy: bad array bounds", non_fatal);
198         return (NULL);
199     }
200     if (n == 0)
201     {
202         error("iupper_ccopy: zero array size", warning);
203         return (NULL);
204     }
205     ptr = (int **) ralloc((unsigned) n * sizeof(int *)) - n1;
206     for (i = n1; i < n2; ++i)
207         ptr[i] = (int *) ralloc((unsigned) (n2 - i) * sizeof(int)) - i;
208     for (i = n1; i < n2; ++i)
209         for (j = i; j < n2; ++j)
210             ptr[i][j] = a[i][j];
211     return (ptr);
212 }
213 
214 /* make int copy of displaced vector of shorts */
215 
216 int    *ivector_scopy(short int *v, int n1, int n2)
217 {
218     int    *ptr;
219     int     i;
220 
221     if (n2 <= n1)
222     {
223         error("ivector_scopy: bad array bounds", warning);
224         return (NULL);
225     }
226     ptr = (int *) ralloc((unsigned) (n2 - n1) * sizeof(int)) - n1;
227     for (i = n1; i < n2; ++i)
228     {
229         ptr[i] = v[i];
230     }
231     return (ptr);
232 }
233 
234 /* make int copy of displaced array of shorts */
235 
236 int   **iarray_scopy(short int **a, int m1, int n1, int m2, int n2)
237 {
238     int   **ptr;
239     int     m = m2 - m1, n = n2 - n1;
240     int     i, j;
241 
242     if (m < 0 || n < 0)
243     {
244         error("iarray_scopy: bad array bounds", non_fatal);
245         return (NULL);
246     }
247     if (m == 0 || n == 0)
248     {
249         error("iarray_scopy: zero array size", warning);
250         return (NULL);
251     }
252     ptr = (int **) ralloc((unsigned) m * sizeof(int *)) - m1;
253     for (i = m1; i < m2; ++i)
254         ptr[i] = (int *) ralloc((unsigned) n * sizeof(int)) - n1;
255     for (i = m1; i < m2; ++i)
256         for (j = n1; j < n2; ++j)
257             ptr[i][j] = a[i][j];
258     return (ptr);
259 }
260 
261 /* make int copy of displaced lower triangle of shorts */
262 
263 int   **ilower_scopy(short int **a, int m1, int n1, int m2, int n2)
264 {
265     int   **ptr;
266     int     m = m2 - m1, n = n2 - n1;
267     int     i, j;
268 
269     if (m < 0 || n < 0)
270     {
271         error("ilower_scopy: bad array bounds", non_fatal);
272         return (NULL);
273     }
274     if (m == 0 || n == 0)
275     {
276         error("ilower_scopy: zero array size", warning);
277         return (NULL);
278     }
279     ptr = (int **) ralloc((unsigned) m * sizeof(int *)) - m1;
280     for (i = m1; i < m2; ++i)
281         ptr[i] = (int *) ralloc((unsigned) n * sizeof(int)) - n1;
282     for (i = m1; i < m2; ++i)
283         for (j = n1; j <= i; ++j)
284             ptr[i][j] = a[i][j];
285     return (ptr);
286 }
287 
288 /* make int copy of displaced upper triangle of shorts */
289 
290 int   **iupper_scopy(short int **a, int n1, int n2)
291 {
292     int   **ptr;
293     int     n = n2 - n1;
294     int     i, j;
295 
296     if (n < 0)
297     {
298         error("iupper_scopy: bad array bounds", non_fatal);
299         return (NULL);
300     }
301     if (n == 0)
302     {
303         error("iupper_scopy: zero array size", warning);
304         return (NULL);
305     }
306     ptr = (int **) ralloc((unsigned) n * sizeof(int *)) - n1;
307     for (i = n1; i < n2; ++i)
308         ptr[i] = (int *) ralloc((unsigned) (n2 - i) * sizeof(int)) - i;
309     for (i = n1; i < n2; ++i)
310         for (j = i; j < n2; ++j)
311             ptr[i][j] = a[i][j];
312     return (ptr);
313 }
314 
315 /* make int copy of displaced vector of floats */
316 
317 int    *ivector_icopy(int *v, int n1, int n2)
318 {
319     int    *ptr;
320     int     i;
321 
322     if (n2 <= n1)
323     {
324         error("ivector_icopy: bad array bounds", warning);
325         return (NULL);
326     }
327     ptr = (int *) ralloc((unsigned) (n2 - n1) * sizeof(int)) - n1;
328     for (i = n1; i < n2; ++i)
329     {
330         ptr[i] = v[i];
331     }
332     return (ptr);
333 }
334 
335 /* make int copy of displaced array of floats */
336 
337 int   **iarray_icopy(int **a, int m1, int n1, int m2, int n2)
338 {
339     int   **ptr;
340     int     m = m2 - m1, n = n2 - n1;
341     int     i, j;
342 
343     if (m < 0 || n < 0)
344     {
345         error("iarray_icopy: bad array bounds", non_fatal);
346         return (NULL);
347     }
348     if (m == 0 || n == 0)
349     {
350         error("iarray_icopy: zero array size", warning);
351         return (NULL);
352     }
353     ptr = (int **) ralloc((unsigned) m * sizeof(int *)) - m1;
354     for (i = m1; i < m2; ++i)
355         ptr[i] = (int *) ralloc((unsigned) n * sizeof(int)) - n1;
356     for (i = m1; i < m2; ++i)
357         for (j = n1; j < n2; ++j)
358             ptr[i][j] = a[i][j];
359     return (ptr);
360 }
361 
362 /* make int copy of displaced lower triangle of floats */
363 
364 int   **ilower_icopy(int **a, int m1, int n1, int m2, int n2)
365 {
366     int   **ptr;
367     int     m = m2 - m1, n = n2 - n1;
368     int     i, j;
369 
370     if (m < 0 || n < 0)
371     {
372         error("ilower_icopy: bad array bounds", non_fatal);
373         return (NULL);
374     }
375     if (m == 0 || n == 0)
376     {
377         error("ilower_icopy: zero array size", warning);
378         return (NULL);
379     }
380     ptr = (int **) ralloc((unsigned) m * sizeof(int *)) - m1;
381     for (i = m1; i < m2; ++i)
382         ptr[i] = (int *) ralloc((unsigned) n * sizeof(int)) - n1;
383     for (i = m1; i < m2; ++i)
384         for (j = n1; j <= i; ++j)
385             ptr[i][j] = a[i][j];
386     return (ptr);
387 }
388 
389 /* make int copy of displaced upper triangle of floats */
390 
391 int   **iupper_icopy(int **a, int n1, int n2)
392 {
393     int   **ptr;
394     int     n = n2 - n1;
395     int     i, j;
396 
397     if (n < 0)
398     {
399         error("iupper_icopy: bad array bounds", non_fatal);
400         return (NULL);
401     }
402     if (n == 0)
403     {
404         error("iupper_icopy: zero array size", warning);
405         return (NULL);
406     }
407     ptr = (int **) ralloc((unsigned) n * sizeof(int *)) - n1;
408     for (i = n1; i < n2; ++i)
409         ptr[i] = (int *) ralloc((unsigned) (n2 - i) * sizeof(int)) - i;
410     for (i = n1; i < n2; ++i)
411         for (j = i; j < n2; ++j)
412             ptr[i][j] = a[i][j];
413     return (ptr);
414 }
415 
416 /* make int copy of displaced vector of floats */
417 
418 int    *ivector_fcopy(float *v, int n1, int n2)
419 {
420     int    *ptr;
421     int     i;
422 
423     if (n2 <= n1)
424     {
425         error("ivector_fcopy: bad array bounds", warning);
426         return (NULL);
427     }
428     ptr = (int *) ralloc((unsigned) (n2 - n1) * sizeof(int)) - n1;
429     for (i = n1; i < n2; ++i)
430     {
431         ptr[i] = (int) v[i];
432     }
433     return (ptr);
434 }
435 
436 /* make int copy of displaced array of floats */
437 
438 int   **iarray_fcopy(float **a, int m1, int n1, int m2, int n2)
439 {
440     int   **ptr;
441     int     m = m2 - m1, n = n2 - n1;
442     int     i, j;
443 
444     if (m < 0 || n < 0)
445     {
446         error("iarray_fcopy: bad array bounds", non_fatal);
447         return (NULL);
448     }
449     if (m == 0 || n == 0)
450     {
451         error("iarray_fcopy: zero array size", warning);
452         return (NULL);
453     }
454     ptr = (int **) ralloc((unsigned) m * sizeof(int *)) - m1;
455     for (i = m1; i < m2; ++i)
456         ptr[i] = (int *) ralloc((unsigned) n * sizeof(int)) - n1;
457     for (i = m1; i < m2; ++i)
458         for (j = n1; j < n2; ++j)
459             ptr[i][j] = (int) a[i][j];
460     return (ptr);
461 }
462 
463 /* make int copy of displaced lower triangle of floats */
464 
465 int   **ilower_fcopy(float **a, int m1, int n1, int m2, int n2)
466 {
467     int   **ptr;
468     int     m = m2 - m1, n = n2 - n1;
469     int     i, j;
470 
471     if (m < 0 || n < 0)
472     {
473         error("ilower_fcopy: bad array bounds", non_fatal);
474         return (NULL);
475     }
476     if (m == 0 || n == 0)
477     {
478         error("ilower_fcopy: zero array size", warning);
479         return (NULL);
480     }
481     ptr = (int **) ralloc((unsigned) m * sizeof(int *)) - m1;
482     for (i = m1; i < m2; ++i)
483         ptr[i] = (int *) ralloc((unsigned) n * sizeof(int)) - n1;
484     for (i = m1; i < m2; ++i)
485         for (j = n1; j <= i; ++j)
486             ptr[i][j] = (int) a[i][j];
487     return (ptr);
488 }
489 
490 /* make int copy of displaced upper triangle of floats */
491 
492 int   **iupper_fcopy(float **a, int n1, int n2)
493 {
494     int   **ptr;
495     int     n = n2 - n1;
496     int     i, j;
497 
498     if (n < 0)
499     {
500         error("iupper_fcopy: bad array bounds", non_fatal);
501         return (NULL);
502     }
503     if (n == 0)
504     {
505         error("iupper_fcopy: zero array size", warning);
506         return (NULL);
507     }
508     ptr = (int **) ralloc((unsigned) n * sizeof(int *)) - n1;
509     for (i = n1; i < n2; ++i)
510         ptr[i] = (int *) ralloc((unsigned) (n2 - i) * sizeof(int)) - i;
511     for (i = n1; i < n2; ++i)
512         for (j = i; j < n2; ++j)
513             ptr[i][j] = (int) a[i][j];
514     return (ptr);
515 }
516 
517 /* make int copy of displaced vector of doubles */
518 
519 int    *ivector_dcopy(double *v, int n1, int n2)
520 {
521     int    *ptr;
522     int     i;
523 
524     if (n2 <= n1)
525     {
526         error("ivector_dcopy: bad array bounds", warning);
527         return (NULL);
528     }
529     ptr = (int *) ralloc((unsigned) (n2 - n1) * sizeof(int)) - n1;
530     for (i = n1; i < n2; ++i)
531     {
532         ptr[i] = (int) v[i];
533     }
534     return (ptr);
535 }
536 
537 /* make int copy of displaced array of doubles */
538 
539 int   **iarray_dcopy(double **a, int m1, int n1, int m2, int n2)
540 {
541     int   **ptr;
542     int     m = m2 - m1, n = n2 - n1;
543     int     i, j;
544 
545     if (m < 0 || n < 0)
546     {
547         error("iarray_dcopy: bad array bounds", non_fatal);
548         return (NULL);
549     }
550     if (m == 0 || n == 0)
551     {
552         error("iarray_dcopy: zero array size", warning);
553         return (NULL);
554     }
555     ptr = (int **) ralloc((unsigned) m * sizeof(int *)) - m1;
556     for (i = m1; i < m2; ++i)
557         ptr[i] = (int *) ralloc((unsigned) n * sizeof(int)) - n1;
558     for (i = m1; i < m2; ++i)
559         for (j = n1; j < n2; ++j)
560             ptr[i][j] = (int) a[i][j];
561     return (ptr);
562 }
563 
564 /* make int copy of displaced lower triangle of doubles */
565 
566 int   **ilower_dcopy(double **a, int m1, int n1, int m2, int n2)
567 {
568     int   **ptr;
569     int     m = m2 - m1, n = n2 - n1;
570     int     i, j;
571 
572     if (m < 0 || n < 0)
573     {
574         error("ilower_dcopy: bad array bounds", non_fatal);
575         return (NULL);
576     }
577     if (m == 0 || n == 0)
578     {
579         error("ilower_dcopy: zero array size", warning);
580         return (NULL);
581     }
582     ptr = (int **) ralloc((unsigned) m * sizeof(int *)) - m1;
583     for (i = m1; i < m2; ++i)
584         ptr[i] = (int *) ralloc((unsigned) n * sizeof(int)) - n1;
585     for (i = m1; i < m2; ++i)
586         for (j = n1; j <= i; ++j)
587             ptr[i][j] = (int) a[i][j];
588     return (ptr);
589 }
590 
591 /* make int copy of displaced upper triangle of doubles */
592 
593 int   **iupper_dcopy(double **a, int n1, int n2)
594 {
595     int   **ptr;
596     int     n = n2 - n1;
597     int     i, j;
598 
599     if (n < 0)
600     {
601         error("iupper_dcopy: bad array bounds", non_fatal);
602         return (NULL);
603     }
604     if (n == 0)
605     {
606         error("iupper_dcopy: zero array size", warning);
607         return (NULL);
608     }
609     ptr = (int **) ralloc((unsigned) n * sizeof(int *)) - n1;
610     for (i = n1; i < n2; ++i)
611         ptr[i] = (int *) ralloc((unsigned) (n2 - i) * sizeof(int)) - i;
612     for (i = n1; i < n2; ++i)
613         for (j = i; j < n2; ++j)
614             ptr[i][j] = (int) a[i][j];
615     return (ptr);
616 }
617 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.