17 #include <sys/types.h> 38 extern unsigned char dbl_cnvrt[
sizeof(double)];
39 extern unsigned char flt_cnvrt[
sizeof(float)];
41 extern unsigned char lng_cnvrt[
sizeof(long)];
42 extern unsigned char int_cnvrt[
sizeof(int)];
43 extern unsigned char shrt_cnvrt[
sizeof(short)];
47 static char *buffer =
NULL;
48 static int buf_alloced = 0;
50 static int buf_alloc(
int needed)
55 if (needed <= buf_alloced)
83 unsigned char *c1, *c2;
93 ret =
dig_fread(buffer, PORT_DOUBLE, cnt, fp);
97 c1 = (
unsigned char *)buffer;
98 c2 = (
unsigned char *)buf;
99 for (i = 0; i < cnt; i++) {
104 c2 +=
sizeof(double);
127 unsigned char *c1, *c2;
131 if (ret != (
int) cnt)
137 ret =
dig_fread(buffer, PORT_FLOAT, cnt, fp);
138 if (ret != (
int) cnt)
141 c1 = (
unsigned char *)buffer;
142 c2 = (
unsigned char *)buf;
143 for (i = 0; i < cnt; i++) {
171 unsigned char *c1, *c2;
175 ret =
dig_fread(buf, port_off_t_size, cnt, fp);
176 if (ret != (
int) cnt)
181 buf_alloc(cnt * port_off_t_size);
182 ret =
dig_fread(buffer, port_off_t_size, cnt, fp);
183 if (ret != (
int) cnt)
186 memset(buf, 0, cnt *
sizeof(off_t));
188 c1 = (
unsigned char *)buffer;
189 c2 = (
unsigned char *)buf;
190 for (i = 0; i < cnt; i++) {
193 if (c1[port_off_t_size - 1] & 0x80)
194 memset(c2, 0xff,
sizeof(off_t));
195 memcpy(c2, c1, port_off_t_size);
199 memset(c2, 0xff,
sizeof(off_t));
200 memcpy(c2 +
nat_off_t - port_off_t_size, c1, port_off_t_size);
202 c1 += port_off_t_size;
214 buf_alloc(cnt * port_off_t_size);
215 ret =
dig_fread(buffer, port_off_t_size, cnt, fp);
216 if (ret != (
int) cnt)
219 memset(buf, 0, cnt *
sizeof(off_t));
221 c1 = (
unsigned char *)buffer;
222 c2 = (
unsigned char *)buf;
223 for (i = 0; i < cnt; i++) {
226 if (c1[port_off_t_size - 1] & 0x80)
227 memset(c2, 0xff,
sizeof(off_t));
231 memset(c2, 0xff,
sizeof(off_t));
233 for (j = 0; j < port_off_t_size; j++)
235 c1 += port_off_t_size;
264 unsigned char *c1, *c2;
269 if (ret != (
int) cnt)
275 ret =
dig_fread(buffer, PORT_LONG, cnt, fp);
276 if (ret != (
int) cnt)
279 memset(buf, 0, cnt *
sizeof(
long));
281 c1 = (
unsigned char *)buffer;
282 c2 = (
unsigned char *)buf;
283 for (i = 0; i < cnt; i++) {
286 if (c1[PORT_LONG - 1] & 0x80)
287 memset(c2, 0xff,
sizeof(
long));
288 memcpy(c2, c1, PORT_LONG);
292 memset(c2, 0xff,
sizeof(
long));
293 memcpy(c2 +
nat_lng - PORT_LONG, c1, PORT_LONG);
303 ret =
dig_fread(buffer, PORT_LONG, cnt, fp);
304 if (ret != (
int) cnt)
307 memset(buf, 0, cnt *
sizeof(
long));
309 c1 = (
unsigned char *)buffer;
310 c2 = (
unsigned char *)buf;
311 for (i = 0; i < cnt; i++) {
314 if (c1[PORT_LONG - 1] & 0x80)
315 memset(c2, 0xff,
sizeof(
long));
319 memset(c2, 0xff,
sizeof(
long));
347 unsigned char *c1, *c2;
352 if (ret != (
int) cnt)
358 ret =
dig_fread(buffer, PORT_INT, cnt, fp);
359 if (ret != (
int) cnt)
362 memset(buf, 0, cnt *
sizeof(
int));
364 c1 = (
unsigned char *)buffer;
365 c2 = (
unsigned char *)buf;
366 for (i = 0; i < cnt; i++) {
369 if (c1[PORT_INT - 1] & 0x80)
370 memset(c2, 0xff,
sizeof(
int));
371 memcpy(c2, c1, PORT_INT);
375 memset(c2, 0xff,
sizeof(
int));
376 memcpy(c2 +
nat_int - PORT_INT, c1, PORT_INT);
386 ret =
dig_fread(buffer, PORT_INT, cnt, fp);
387 if (ret != (
int) cnt)
390 memset(buf, 0, cnt *
sizeof(
int));
392 c1 = (
unsigned char *)buffer;
393 c2 = (
unsigned char *)buf;
394 for (i = 0; i < cnt; i++) {
397 if (c1[PORT_INT - 1] & 0x80)
398 memset(c2, 0xff,
sizeof(
int));
402 memset(c2, 0xff,
sizeof(
int));
430 unsigned char *c1, *c2;
435 if (ret != (
int) cnt)
441 if (0 >= (ret =
dig_fread(buffer, PORT_SHORT, cnt, fp)))
442 if (ret != (
int) cnt)
445 memset(buf, 0, cnt *
sizeof(
short));
447 c1 = (
unsigned char *)buffer;
448 c2 = (
unsigned char *)buf;
449 for (i = 0; i < cnt; i++) {
452 if (c1[PORT_SHORT - 1] & 0x80)
453 memset(c2, 0xff,
sizeof(
short));
454 memcpy(c2, c1, PORT_SHORT);
458 memset(c2, 0xff,
sizeof(
short));
459 memcpy(c2 +
nat_shrt - PORT_SHORT, c1, PORT_SHORT);
469 ret =
dig_fread(buffer, PORT_SHORT, cnt, fp);
470 if (ret != (
int) cnt)
473 memset(buf, 0, cnt *
sizeof(
short));
475 c1 = (
unsigned char *)buffer;
476 c2 = (
unsigned char *)buf;
477 for (i = 0; i < cnt; i++) {
480 if (c1[PORT_SHORT - 1] & 0x80)
481 memset(c2, 0xff,
sizeof(
short));
485 memset(c2, 0xff,
sizeof(
short));
514 if (ret != (
int) cnt)
558 size_t cnt,
struct gvfile * fp)
561 unsigned char *c1, *c2;
569 c1 = (
unsigned char *)buf;
570 c2 = (
unsigned char *)buffer;
571 for (i = 0; i < cnt; i++) {
574 c1 +=
sizeof(
double);
577 if (
dig_fwrite(buffer, PORT_DOUBLE, cnt, fp) == cnt)
597 size_t cnt,
struct gvfile * fp)
600 unsigned char *c1, *c2;
608 c1 = (
unsigned char *)buf;
609 c2 = (
unsigned char *)buffer;
610 for (i = 0; i < cnt; i++) {
616 if (
dig_fwrite(buffer, PORT_FLOAT, cnt, fp) == cnt)
637 size_t cnt,
struct gvfile * fp,
size_t port_off_t_size)
640 unsigned char *c1, *c2;
644 if (
dig_fwrite(buf, port_off_t_size, cnt, fp) == cnt)
648 buf_alloc(cnt * port_off_t_size);
649 c1 = (
unsigned char *)buf;
650 c2 = (
unsigned char *)buffer;
651 for (i = 0; i < cnt; i++) {
653 memcpy(c2, c1, port_off_t_size);
655 memcpy(c2, c1 +
nat_off_t - port_off_t_size, port_off_t_size);
657 c2 += port_off_t_size;
659 if (
dig_fwrite(buffer, port_off_t_size, cnt, fp) == cnt)
669 buf_alloc(cnt * port_off_t_size);
670 c1 = (
unsigned char *)buf;
671 c2 = (
unsigned char *)buffer;
672 for (i = 0; i < cnt; i++) {
673 for (j = 0; j < port_off_t_size; j++)
676 c2 += port_off_t_size;
678 if (
dig_fwrite(buffer, port_off_t_size, cnt, fp) == cnt)
703 size_t cnt,
struct gvfile * fp)
706 unsigned char *c1, *c2;
715 c1 = (
unsigned char *)buf;
716 c2 = (
unsigned char *)buffer;
717 for (i = 0; i < cnt; i++) {
719 memcpy(c2, c1, PORT_LONG);
721 memcpy(c2, c1 +
nat_lng - PORT_LONG, PORT_LONG);
725 if (
dig_fwrite(buffer, PORT_LONG, cnt, fp) == cnt)
731 c1 = (
unsigned char *)buf;
732 c2 = (
unsigned char *)buffer;
733 for (i = 0; i < cnt; i++) {
739 if (
dig_fwrite(buffer, PORT_LONG, cnt, fp) == cnt)
759 size_t cnt,
struct gvfile * fp)
762 unsigned char *c1, *c2;
771 c1 = (
unsigned char *)buf;
772 c2 = (
unsigned char *)buffer;
773 for (i = 0; i < cnt; i++) {
775 memcpy(c2, c1, PORT_INT);
777 memcpy(c2, c1 +
nat_int - PORT_INT, PORT_INT);
781 if (
dig_fwrite(buffer, PORT_INT, cnt, fp) == cnt)
787 c1 = (
unsigned char *)buf;
788 c2 = (
unsigned char *)buffer;
789 for (i = 0; i < cnt; i++) {
795 if (
dig_fwrite(buffer, PORT_INT, cnt, fp) == cnt)
815 size_t cnt,
struct gvfile * fp)
818 unsigned char *c1, *c2;
827 c1 = (
unsigned char *)buf;
828 c2 = (
unsigned char *)buffer;
829 for (i = 0; i < cnt; i++) {
831 memcpy(c2, c1, PORT_SHORT);
833 memcpy(c2, c1 +
nat_shrt - PORT_SHORT, PORT_SHORT);
837 if (
dig_fwrite(buffer, PORT_SHORT, cnt, fp) == cnt)
843 c1 = (
unsigned char *)buf;
844 c2 = (
unsigned char *)buffer;
845 for (i = 0; i < cnt; i++) {
851 if (
dig_fwrite(buffer, PORT_SHORT, cnt, fp) == cnt)
872 size_t cnt,
struct gvfile * fp)
891 size_t cnt,
struct gvfile * fp)
int dig__fread_port_I(int *buf, size_t cnt, struct gvfile *fp)
Read integers from the Portable Vector Format.
#define ENDIAN_LITTLE
Endian check.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
int flt_quick
Quick reading flag for float.
unsigned char dbl_cnvrt[PORT_DOUBLE]
Conversion matrices between file and native byte order (double)
int dig__fwrite_port_S(const short *buf, size_t cnt, struct gvfile *fp)
Write shorts to the Portable Vector Format.
int dig_set_cur_port(struct Port_info *port)
Set current Port_info structure.
size_t dig_fwrite(const void *ptr, size_t size, size_t nmemb, struct gvfile *file)
Write struct gvfile.
int dbl_quick
Quick reading flag for double.
unsigned char flt_cnvrt[PORT_FLOAT]
Conversion matrices between file and native byte order (float)
int dig__fwrite_port_O(const off_t *buf, size_t cnt, struct gvfile *fp, size_t port_off_t_size)
Write off_ts to the Portable Vector Format.
unsigned char shrt_cnvrt[PORT_SHORT]
Conversion matrices between file and native byte order (short)
int shrt_quick
Quick reading flag for short.
unsigned char shrt_cnvrt[sizeof(short)]
int dig_out_of_memory(void)
For now just print message and return error code.
void dig_init_portable(struct Port_info *port, int byte_order)
Set Port_info structure to byte order of file.
int int_quick
Quick reading flag for int.
size_t dig_fread(void *ptr, size_t size, size_t nmemb, struct gvfile *file)
Read struct gvfile.
#define PORT_DOUBLE
Sizes of types used in portable format (different names used in Vlib/ and diglib/ for the same thing)...
int dig__fread_port_C(char *buf, size_t cnt, struct gvfile *fp)
Read chars from the Portable Vector Format.
unsigned char dbl_cnvrt[sizeof(double)]
int dig__fwrite_port_L(const long *buf, size_t cnt, struct gvfile *fp)
Write longs to the Portable Vector Format.
unsigned char int_cnvrt[PORT_INT]
Conversion matrices between file and native byte order (int)
void port_init(void)
Initialize Port_info structures.
unsigned char lng_cnvrt[PORT_LONG]
Conversion matrices between file and native byte order (long)
struct Port_info * Cur_Head
int off_t_quick
Quick reading flag for off_t.
void * dig__alloc_space(int, int *, int, void *, int)
int dig__fread_port_F(float *buf, size_t cnt, struct gvfile *fp)
Read floats from the Portable Vector Format.
unsigned char int_cnvrt[sizeof(int)]
int byte_order
File byte order.
unsigned char off_t_cnvrt[PORT_OFF_T]
Conversion matrices between file and native byte order (off_t)
unsigned char flt_cnvrt[sizeof(float)]
int dig__fread_port_P(plus_t *buf, size_t cnt, struct gvfile *fp)
Read plus_t from the Portable Vector Format.
int dig__fread_port_S(short *buf, size_t cnt, struct gvfile *fp)
Read shorts from the Portable Vector Format.
int dig__fread_port_D(double *buf, size_t cnt, struct gvfile *fp)
Read doubles from the Portable Vector Format.
int dig__byte_order_out()
Get byte order.
int dig__fwrite_port_C(const char *buf, size_t cnt, struct gvfile *fp)
Write chars to the Portable Vector Format.
int dig__fwrite_port_F(const float *buf, size_t cnt, struct gvfile *fp)
Write floats to the Portable Vector Format.
int dig__fwrite_port_P(const plus_t *buf, size_t cnt, struct gvfile *fp)
Write plus_t to the Portable Vector Format.
int dig__fwrite_port_D(const double *buf, size_t cnt, struct gvfile *fp)
Write doubles to the Portable Vector Format.
int dig__fread_port_L(long *buf, size_t cnt, struct gvfile *fp)
Read longs from the Portable Vector Format.
int lng_quick
Quick reading flag for long.
int dig__fread_port_O(off_t *buf, size_t cnt, struct gvfile *fp, size_t port_off_t_size)
Read off_ts from the Portable Vector Format.
unsigned char off_t_cnvrt[sizeof(off_t)]
unsigned char lng_cnvrt[sizeof(long)]
int dig__fwrite_port_I(const int *buf, size_t cnt, struct gvfile *fp)
Write integers to the Portable Vector Format.