source: branches/fscctrl_safety_limits/dim/src/swap.c@ 20115

Last change on this file since 20115 was 11071, checked in by tbretz, 14 years ago
Replaced v19r21 by a version extracted with 'unzip -a' to get proper unix text format.
File size: 2.4 KB
Line 
1/*
2 * (Delphi Network Access) implements the network layer for the DIM
3 * (Delphi Information Managment) System.
4 *
5 * Started date : 10-11-91
6 * Written by : C. Gaspar
7 * UNIX adjustment: G.C. Ballintijn
8 *
9 */
10
11double _swapd( double d )
12{
13 double r[2];
14 register char *p, *q;
15 register int n;
16
17 p = (char *) &r[1];
18 q = (char *) &d;
19 for( n = sizeof(double)+1; --n; *--p = *q++) ;
20 return r[0];
21}
22
23int _swapl( int l )
24{
25 int r[2];
26 register char *p, *q;
27
28 p = (char *) &r[1];
29 q = (char *) &l;
30 *--p = *q++;
31 *--p = *q++;
32 *--p = *q++;
33 *--p = *q++;
34
35 return r[0];
36}
37
38short _swaps( short s )
39{
40 short r[2];
41 register char *p, *q;
42
43 p = (char *) &r[1];
44 q = (char *) &s;
45 *--p = *q++;
46 *--p = *q++;
47
48 return r[0];
49}
50
51double _swapd_by_addr( double *d )
52{
53 double r[2];
54 register char *p, *q;
55 register int n;
56
57 p = (char *) &r[1];
58 q = (char *) d;
59 for( n = sizeof(double)+1; --n; *--p = *q++) ;
60
61 return r[0];
62}
63
64int _swapl_by_addr( int *l )
65{
66 int r[2];
67 register char *p, *q;
68
69 p = (char *) &r[1];
70 q = (char *) l;
71 *--p = *q++;
72 *--p = *q++;
73 *--p = *q++;
74 *--p = *q++;
75
76 return r[0];
77}
78
79short _swaps_by_addr( short *s )
80{
81 short r[2];
82 register char *p, *q;
83
84 p = (char *) &r[1];
85 q = (char *) s;
86 *--p = *q++;
87 *--p = *q++;
88
89 return r[0];
90}
91
92void _swaps_buffer( short *s2, short *s1, int n)
93{
94 register char *p, *q;
95 short r[2];
96 register short *s;
97
98 p = (char *) s2;
99 q = (char *) s1;
100 if( p != q ) {
101 p += sizeof(short);
102 for( n++; --n; p += 2*sizeof(short)) {
103 *--p = *q++;
104 *--p = *q++;
105 }
106 } else {
107 for( s = s2, n++; --n; *s++ = r[0]) {
108 p = (char *) &r[1] ;
109 *--p = *q++;
110 *--p = *q++;
111 }
112 }
113}
114
115void _swapl_buffer( int *s2, int *s1, int n)
116{
117 register char *p, *q;
118 int r[2];
119 register int *l;
120
121 p = (char *) s2;
122 q = (char *) s1;
123 if( p != q ) {
124 p += sizeof(int);
125 for( n++; --n; p += 2*sizeof(int)) {
126 *--p = *q++;
127 *--p = *q++;
128 *--p = *q++;
129 *--p = *q++;
130 }
131 } else {
132 for( l = s2, n++; --n; *l++ = r[0]) {
133 p = (char *) &r[1] ;
134 *--p = *q++;
135 *--p = *q++;
136 *--p = *q++;
137 *--p = *q++;
138 }
139 }
140}
141
142
143void _swapd_buffer( double *s2, double *s1, int n)
144{
145 register char *p, *q;
146 double r[2];
147 register double *d;
148 register int m;
149
150 p = (char *) s2;
151 q = (char *) s1;
152 if( p != q ) {
153 p += sizeof(double);
154 for( n++; --n; p += 2*sizeof(double)) {
155 for( m = sizeof(double)+1; --m; *--p = *q++) ;
156 }
157 } else {
158 for( d = s2, n++; --n; *d++ = r[0]) {
159 p = (char *) &r[1] ;
160 for( m = sizeof(double)+1; --m; *--p = *q++) ;
161 }
162 }
163}
164
165
Note: See TracBrowser for help on using the repository browser.