00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <stdio.h>
00039 #include <stdlib.h>
00040 #include "utility.h"
00041
00042 #ifdef NEEDMENDIAN
00043 #include <machine/endian.h>
00044 #endif
00045 #ifdef NEEDENDIAN
00046 #include <endian.h>
00047 #endif
00048 #ifdef NEEDSENDIAN
00049 #include <sys/endian.h>
00050 #endif
00051
00052 void
00053 printbits(int x)
00054 {
00055 int i;
00056
00057 for(i=31;i>=0;i--) {
00058 printf("%d", (x>>i)&0x1);
00059 if(i%4==0) printf(" ");
00060 }
00061 }
00062
00063
00064
00065
00066
00067
00068
00069 int
00070 ffs(x)
00071 int x;
00072 {
00073 int n = 1, m = 1;
00074
00075 if (!x)
00076 return 0;
00077 while (!(x & m)) {
00078 m += m;
00079 n++;
00080 }
00081 return n;
00082 }
00083
00084
00085
00086 static int
00087 ibol(o, p, n)
00088 int o;
00089 char *p;
00090 int n;
00091 {
00092 int i, j;
00093
00094 if (p[0] == 0) {
00095 i = 0;
00096 } else if (p[0] == n - 1) {
00097 i = 3;
00098 } else if (p[0] == n / 2) {
00099 i = 2;
00100 } else if (p[0] == n / 2 - 1) {
00101 i = 1;
00102 } else {
00103 fprintf(stderr, "can't generate signature for my integer byte order\n");
00104 abort();
00105 }
00106
00107 j = ffs(n) - 1;
00108
00109
00110
00111
00112 return ((i << 3) | j) << o;
00113 }
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 unsigned char fs1[] = { 0x3f, 0x80, 0x00, 0x00 };
00135 unsigned char fs2[] = { 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
00136 unsigned char fs4[] = { 0x40, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00 };
00137 unsigned char fs5[] = { 0x40, 0x80, 0x00, 0x00 };
00138 unsigned char fs6[] = { 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
00139
00140 struct floatsig thesigs[] = {
00141 { 0, 0, "UNKNOWN" },
00142 { 4, fs1, "IEEE_single" },
00143 { 8, fs2, "IEEE_double" },
00144 { 0, 0, "UNDEFINED" },
00145 { 8, fs4, "Cray" },
00146 { 4, fs5, "Convex_single" },
00147 { 8, fs6, "Convex_double" },
00148 { 0, 0, "UNDEFINED" },
00149 { 0, 0, "UNDEFINED" },
00150 { 0, 0, "UNDEFINED" },
00151 { 0, 0, "UNDEFINED" },
00152 { 0, 0, "UNDEFINED" },
00153 { 0, 0, "UNDEFINED" },
00154 { 0, 0, "UNDEFINED" },
00155 { 0, 0, "UNDEFINED" },
00156 { 0, 0, "UNDEFINED" },
00157 };
00158
00159
00160 static int
00161 fbol(o, p, n)
00162 int o;
00163 unsigned char *p;
00164 int n;
00165 {
00166 int i, j;
00167
00168 for (i = 0; i < 16; i++) {
00169 if (thesigs[i].length == n) {
00170 for (j = 0; j < n; j++)
00171 if (p[j] != thesigs[i].bytes[j])
00172 break;
00173 if (j == n)
00174 return ((3 << 4) | i) << o;
00175
00176 for (j = 0; j < n; j++)
00177 if (p[n - 1 - j] != thesigs[i].bytes[j])
00178 break;
00179 if (j == n)
00180 return i << o;
00181 }
00182 }
00183 fprintf(stderr, "can't generate signature for my integer byte order\n");
00184 abort();
00185 return 0;
00186 }
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215 int
00216 pvmgetdsig()
00217 {
00218 static int myfmt = -1;
00219
00220 short i0;
00221 int i1;
00222 long i2;
00223 float f0;
00224 double f1;
00225 int i;
00226 int fmt;
00227
00228 if (myfmt != -1)
00229 return myfmt;
00230
00231 fmt = 0;
00232
00233 i0 = 0;
00234 for (i = 0; i < sizeof(i0); i++)
00235 i0 += (short)i << (i * 8);
00236 fmt |= ibol(0, (char *) &i0, (int) sizeof(i0));
00237
00238 i1 = 0;
00239 for (i = 0; i < sizeof(i1); i++)
00240 i1 += (int)i << (i * 8);
00241 fmt |= ibol(5, (char *) &i1, (int) sizeof(i1));
00242
00243 i2 = 0;
00244 for (i = 0; i < sizeof(i2); i++)
00245 i2 += (long)i << (i * 8);
00246 fmt |= ibol(10, (char *) &i2, (int) sizeof(i2));
00247
00248 f0 = 1.0;
00249 fmt |= fbol(15, (unsigned char *) &f0, (int) sizeof(f0));
00250
00251 f1 = 1.0;
00252 fmt |= fbol(21, (unsigned char *) &f1, (int) sizeof(f1));
00253
00254 myfmt = fmt;
00255 return fmt;
00256 }
00257
00258