19 #include <grass/gis.h>
20 #include <grass/Vect.h>
36 extern unsigned char dbl_cnvrt[
sizeof(double)];
37 extern unsigned char flt_cnvrt[
sizeof(float)];
38 extern unsigned char lng_cnvrt[
sizeof(long)];
39 extern unsigned char int_cnvrt[
sizeof(int)];
40 extern unsigned char shrt_cnvrt[
sizeof(short)];
44 static char *buffer =
NULL;
45 static int buf_alloced = 0;
47 static int buf_alloc(
int needed)
52 if (needed <= buf_alloced)
78 unsigned char *c1, *c2;
81 ret =
dig_fread(buf, PORT_DOUBLE, cnt, fp);
87 buf_alloc(cnt * PORT_DOUBLE);
88 ret =
dig_fread(buffer, PORT_DOUBLE, cnt, fp);
92 c1 = (
unsigned char *)buffer;
93 c2 = (
unsigned char *)buf;
94 for (i = 0; i < cnt; i++) {
95 for (j = 0; j < PORT_DOUBLE; j++) {
109 unsigned char *c1, *c2;
112 ret =
dig_fread(buf, PORT_FLOAT, cnt, fp);
118 buf_alloc(cnt * PORT_FLOAT);
119 ret =
dig_fread(buffer, PORT_FLOAT, cnt, fp);
123 c1 = (
unsigned char *)buffer;
124 c2 = (
unsigned char *)buf;
125 for (i = 0; i < cnt; i++) {
126 for (j = 0; j < PORT_FLOAT; j++) {
140 unsigned char *c1, *c2;
144 ret =
dig_fread(buf, PORT_LONG, cnt, fp);
150 buf_alloc(cnt * PORT_LONG);
151 ret =
dig_fread(buffer, PORT_LONG, cnt, fp);
155 memset(buf, 0, cnt *
sizeof(
long));
157 c1 = (
unsigned char *)buffer;
159 c2 = (
unsigned char *)buf;
161 c2 = (
unsigned char *)buf +
nat_lng - PORT_LONG;
162 for (i = 0; i < cnt; i++) {
165 if (c1[PORT_LONG - 1] & 0x80)
166 memset(c2, 0xff,
sizeof(
long));
170 memset(c2, 0xff,
sizeof(
long));
172 memcpy(c2, c1, PORT_LONG);
180 buf_alloc(cnt * PORT_LONG);
181 ret =
dig_fread(buffer, PORT_LONG, cnt, fp);
185 memset(buf, 0, cnt *
sizeof(
long));
187 c1 = (
unsigned char *)buffer;
188 c2 = (
unsigned char *)buf;
189 for (i = 0; i < cnt; i++) {
191 if (
Cur_Head->byte_order == ENDIAN_LITTLE) {
192 if (c1[PORT_LONG - 1] & 0x80)
193 memset(c2, 0xff,
sizeof(
long));
197 memset(c2, 0xff,
sizeof(
long));
199 for (j = 0; j < PORT_LONG; j++)
212 unsigned char *c1, *c2;
222 buf_alloc(cnt * PORT_INT);
223 ret =
dig_fread(buffer, PORT_INT, cnt, fp);
227 memset(buf, 0, cnt *
sizeof(
int));
229 c1 = (
unsigned char *)buffer;
231 c2 = (
unsigned char *)buf;
233 c2 = (
unsigned char *)buf +
nat_int - PORT_INT;
234 for (i = 0; i < cnt; i++) {
237 if (c1[PORT_INT - 1] & 0x80)
238 memset(c2, 0xff,
sizeof(
int));
242 memset(c2, 0xff,
sizeof(
int));
244 memcpy(c2, c1, PORT_INT);
252 buf_alloc(cnt * PORT_INT);
253 ret =
dig_fread(buffer, PORT_INT, cnt, fp);
257 memset(buf, 0, cnt *
sizeof(
int));
259 c1 = (
unsigned char *)buffer;
260 c2 = (
unsigned char *)buf;
261 for (i = 0; i < cnt; i++) {
263 if (
Cur_Head->byte_order == ENDIAN_LITTLE) {
264 if (c1[PORT_INT - 1] & 0x80)
265 memset(c2, 0xff,
sizeof(
int));
269 memset(c2, 0xff,
sizeof(
int));
271 for (j = 0; j < PORT_INT; j++)
284 unsigned char *c1, *c2;
288 ret =
dig_fread(buf, PORT_SHORT, cnt, fp);
294 buf_alloc(cnt * PORT_SHORT);
295 if (0 >= (ret =
dig_fread(buffer, PORT_SHORT, cnt, fp)))
299 memset(buf, 0, cnt *
sizeof(
short));
301 c1 = (
unsigned char *)buffer;
303 c2 = (
unsigned char *)buf;
305 c2 = (
unsigned char *)buf +
nat_shrt - PORT_SHORT;
306 for (i = 0; i < cnt; i++) {
309 if (c1[PORT_SHORT - 1] & 0x80)
310 memset(c2, 0xff,
sizeof(
short));
314 memset(c2, 0xff,
sizeof(
short));
316 memcpy(c2, c1, PORT_SHORT);
324 buf_alloc(cnt * PORT_SHORT);
325 ret =
dig_fread(buffer, PORT_SHORT, cnt, fp);
329 memset(buf, 0, cnt *
sizeof(
short));
331 c1 = (
unsigned char *)buffer;
332 c2 = (
unsigned char *)buf;
333 for (i = 0; i < cnt; i++) {
335 if (
Cur_Head->byte_order == ENDIAN_LITTLE) {
336 if (c1[PORT_SHORT - 1] & 0x80)
337 memset(c2, 0xff,
sizeof(
short));
341 memset(c2, 0xff,
sizeof(
short));
343 for (j = 0; j < PORT_SHORT; j++)
344 c2[
Cur_Head->shrt_cnvrt[j]] = c1[j];
357 ret =
dig_fread(buf, PORT_CHAR, cnt, fp);
377 int cnt, GVFILE * fp)
380 unsigned char *c1, *c2;
383 if (
dig_fwrite(buf, PORT_DOUBLE, cnt, fp) == cnt)
387 buf_alloc(cnt * PORT_DOUBLE);
388 c1 = (
unsigned char *)buf;
389 c2 = (
unsigned char *)buffer;
390 for (i = 0; i < cnt; i++) {
391 for (j = 0; j < PORT_DOUBLE; j++)
393 c1 +=
sizeof(
double);
396 if (
dig_fwrite(buffer, PORT_DOUBLE, cnt, fp) == cnt)
403 int cnt, GVFILE * fp)
406 unsigned char *c1, *c2;
409 if (
dig_fwrite(buf, PORT_FLOAT, cnt, fp) == cnt)
413 buf_alloc(cnt * PORT_FLOAT);
414 c1 = (
unsigned char *)buf;
415 c2 = (
unsigned char *)buffer;
416 for (i = 0; i < cnt; i++) {
417 for (j = 0; j < PORT_FLOAT; j++)
422 if (
dig_fwrite(buffer, PORT_FLOAT, cnt, fp) == cnt)
429 int cnt, GVFILE * fp)
432 unsigned char *c1, *c2;
436 if (
dig_fwrite(buf, PORT_LONG, cnt, fp) == cnt)
440 buf_alloc(cnt * PORT_LONG);
442 c1 = (
unsigned char *)buf;
444 c1 = (
unsigned char *)buf +
nat_lng - PORT_LONG;
445 c2 = (
unsigned char *)buffer;
446 for (i = 0; i < cnt; i++) {
447 memcpy(c2, c1, PORT_LONG);
451 if (
dig_fwrite(buffer, PORT_LONG, cnt, fp) == cnt)
456 buf_alloc(cnt * PORT_LONG);
457 c1 = (
unsigned char *)buf;
458 c2 = (
unsigned char *)buffer;
459 for (i = 0; i < cnt; i++) {
460 for (j = 0; j < PORT_LONG; j++)
465 if (
dig_fwrite(buffer, PORT_LONG, cnt, fp) == cnt)
472 int cnt, GVFILE * fp)
475 unsigned char *c1, *c2;
479 if (
dig_fwrite(buf, PORT_INT, cnt, fp) == cnt)
483 buf_alloc(cnt * PORT_INT);
485 c1 = (
unsigned char *)buf;
487 c1 = (
unsigned char *)buf +
nat_int - PORT_INT;
488 c2 = (
unsigned char *)buffer;
489 for (i = 0; i < cnt; i++) {
490 memcpy(c2, c1, PORT_INT);
494 if (
dig_fwrite(buffer, PORT_INT, cnt, fp) == cnt)
499 buf_alloc(cnt * PORT_INT);
500 c1 = (
unsigned char *)buf;
501 c2 = (
unsigned char *)buffer;
502 for (i = 0; i < cnt; i++) {
503 for (j = 0; j < PORT_INT; j++)
508 if (
dig_fwrite(buffer, PORT_INT, cnt, fp) == cnt)
515 int cnt, GVFILE * fp)
518 unsigned char *c1, *c2;
522 if (
dig_fwrite(buf, PORT_SHORT, cnt, fp) == cnt)
526 buf_alloc(cnt * PORT_SHORT);
528 c1 = (
unsigned char *)buf;
530 c1 = (
unsigned char *)buf +
nat_shrt - PORT_SHORT;
531 c2 = (
unsigned char *)buffer;
532 for (i = 0; i < cnt; i++) {
533 memcpy(c2, c1, PORT_SHORT);
537 if (
dig_fwrite(buffer, PORT_SHORT, cnt, fp) == cnt)
542 buf_alloc(cnt * PORT_SHORT);
543 c1 = (
unsigned char *)buf;
544 c2 = (
unsigned char *)buffer;
545 for (i = 0; i < cnt; i++) {
546 for (j = 0; j < PORT_SHORT; j++)
547 c2[j] = c1[
Cur_Head->shrt_cnvrt[j]];
551 if (
dig_fwrite(buffer, PORT_SHORT, cnt, fp) == cnt)
559 int cnt, GVFILE * fp)
565 int cnt, GVFILE * fp)
567 if (
dig_fwrite(buf, PORT_CHAR, cnt, fp) == cnt)
580 port->byte_order = byte_order;
583 port->dbl_quick =
TRUE;
585 port->dbl_quick =
FALSE;
587 for (i = 0; i < PORT_DOUBLE; i++) {
588 if (port->byte_order == ENDIAN_BIG)
591 port->dbl_cnvrt[i] =
dbl_cnvrt[PORT_DOUBLE - i - 1];
595 port->flt_quick =
TRUE;
597 port->flt_quick =
FALSE;
599 for (i = 0; i < PORT_FLOAT; i++) {
600 if (port->byte_order == ENDIAN_BIG)
603 port->flt_cnvrt[i] =
flt_cnvrt[PORT_FLOAT - i - 1];
607 port->lng_quick =
TRUE;
609 port->lng_quick =
FALSE;
611 for (i = 0; i < PORT_LONG; i++) {
612 if (port->byte_order == ENDIAN_BIG)
615 port->lng_cnvrt[i] =
lng_cnvrt[PORT_LONG - i - 1];
619 port->int_quick =
TRUE;
621 port->int_quick =
FALSE;
623 for (i = 0; i < PORT_INT; i++) {
624 if (port->byte_order == ENDIAN_BIG)
627 port->int_cnvrt[i] =
int_cnvrt[PORT_INT - i - 1];
631 port->shrt_quick =
TRUE;
633 port->shrt_quick =
FALSE;
635 for (i = 0; i < PORT_SHORT; i++) {
636 if (port->byte_order == ENDIAN_BIG)
639 port->shrt_cnvrt[i] =
shrt_cnvrt[PORT_SHORT - i - 1];
655 return (ENDIAN_LITTLE);