mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
Improve file position handling on Big Engian machines
Added swap_HALFs(dest, src, len) function to byteswap.c. Calc can now handle Big Engian file position sizes that are a multiple of BASEB bits in length. Before handle Big Engian file positions could only be 32 and 64 bits in length. This will allow, for example, a Big Engian file position size of 128 (assuming that 128/BASEB is is an integer).
This commit is contained in:
8
CHANGES
8
CHANGES
@@ -27,6 +27,14 @@ The following are the changes from calc version 2.14.1.2 to date:
|
|||||||
to CALC_HAVE_FGETSETPOS_H. The make install and the olduninstall
|
to CALC_HAVE_FGETSETPOS_H. The make install and the olduninstall
|
||||||
rules remove the any old have_fpos.h that was previously installed.
|
rules remove the any old have_fpos.h that was previously installed.
|
||||||
|
|
||||||
|
Added swap_HALFs(dest, src, len) function to byteswap.c.
|
||||||
|
|
||||||
|
Calc can now handle Big Engian file position sizes that are a
|
||||||
|
multiple of BASEB bits in length. Before handle Big Engian file
|
||||||
|
positions could only be 32 and 64 bits in length. This will allow,
|
||||||
|
for example, a Big Engian file position size of 128 (assuming that
|
||||||
|
128/BASEB is is an integer).
|
||||||
|
|
||||||
|
|
||||||
The following are the changes from calc version 2.14.1.1 to 2.14.1.1:
|
The following are the changes from calc version 2.14.1.1 to 2.14.1.1:
|
||||||
|
|
||||||
|
48
byteswap.c
48
byteswap.c
@@ -40,7 +40,7 @@
|
|||||||
* dest - pointer to where the swapped src will be put or
|
* dest - pointer to where the swapped src will be put or
|
||||||
* NULL to allocate the storage
|
* NULL to allocate the storage
|
||||||
* src - pointer to a HALF array to swap
|
* src - pointer to a HALF array to swap
|
||||||
* len - length of the src HALF array
|
* len - length of the src HALF array in HALFs
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
* pointer to where the swapped src has been put
|
* pointer to where the swapped src has been put
|
||||||
@@ -276,7 +276,7 @@ swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
|
|||||||
* dest - pointer to where the swapped src will be put or
|
* dest - pointer to where the swapped src will be put or
|
||||||
* NULL to allocate the storage
|
* NULL to allocate the storage
|
||||||
* src - pointer to a HALF array to swap
|
* src - pointer to a HALF array to swap
|
||||||
* len - length of the src HALF array
|
* len - length of the src HALF array in HALFs
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
* pointer to where the swapped src has been put
|
* pointer to where the swapped src has been put
|
||||||
@@ -309,6 +309,50 @@ swap_b16_in_HALFs(HALF *dest, HALF *src, LEN len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* swap_HALFs - swap HALFs in an array of HALFs
|
||||||
|
*
|
||||||
|
* given:
|
||||||
|
* dest - pointer to where the swapped src will be put or
|
||||||
|
* NULL to allocate the storage
|
||||||
|
* src - pointer to a HALF array to swap
|
||||||
|
* len - length of the src HALF array in HALFs
|
||||||
|
*
|
||||||
|
* returns:
|
||||||
|
* pointer to where the swapped src has been put
|
||||||
|
*/
|
||||||
|
HALF *
|
||||||
|
swap_HALFs(HALF *dest, HALF *src, LEN len)
|
||||||
|
{
|
||||||
|
HALF *s; /* src swap pointer */
|
||||||
|
HALF *d; /* dest swap pointer */
|
||||||
|
HALF *ret;
|
||||||
|
LEN i;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* allocate storage if needed
|
||||||
|
*/
|
||||||
|
if (dest == NULL) {
|
||||||
|
dest = alloc(len);
|
||||||
|
}
|
||||||
|
ret = dest;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* swap HALFs in the array
|
||||||
|
*/
|
||||||
|
s = src;
|
||||||
|
d = &dest[len-1];
|
||||||
|
for (i=0; i < len; ++i, --d, ++s) {
|
||||||
|
*d = *s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* return the result
|
||||||
|
*/
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* swap_b16_in_ZVALUE - swap 16 bits in a ZVALUE
|
* swap_b16_in_ZVALUE - swap 16 bits in a ZVALUE
|
||||||
*
|
*
|
||||||
|
@@ -96,7 +96,7 @@ main(int UNUSED(argc), char **argv)
|
|||||||
/*
|
/*
|
||||||
* print the file position information
|
* print the file position information
|
||||||
*/
|
*/
|
||||||
#if defined(HAVE_FPOS_POS)
|
#if defined(HAVE_FPOS_POS) && defined(FPOS_POS_BITS)
|
||||||
fileposlen = FPOS_POS_BITS;
|
fileposlen = FPOS_POS_BITS;
|
||||||
#else /* ! HAVE_FPOS_POS */
|
#else /* ! HAVE_FPOS_POS */
|
||||||
# if defined(FPOS_BITS)
|
# if defined(FPOS_BITS)
|
||||||
@@ -119,8 +119,12 @@ main(int UNUSED(argc), char **argv)
|
|||||||
} else if (fileposlen == 32) {
|
} else if (fileposlen == 32) {
|
||||||
printf("#define SWAP_HALF_IN_FILEPOS(dest, src)\t\t%s\n",
|
printf("#define SWAP_HALF_IN_FILEPOS(dest, src)\t\t%s\n",
|
||||||
"SWAP_HALF_IN_B32(dest, src)");
|
"SWAP_HALF_IN_B32(dest, src)");
|
||||||
|
} else if (fileposlen%BASEB == 0) {
|
||||||
|
printf("#define SWAP_HALF_IN_FILEPOS(dest, src)\t\t"
|
||||||
|
"swap_HALFs((HALF *)dest, (HALF *)src, (LEN)%d)\n",
|
||||||
|
fileposlen/BASEB);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "%s: unexpected FILEPOS bit size: %d\n",
|
fprintf(stderr, "%s: unexpected BIG_ENDIAN FILEPOS bit size: %d\n",
|
||||||
program, fileposlen);
|
program, fileposlen);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
1
zmath.h
1
zmath.h
@@ -643,6 +643,7 @@ E_FUNC void math_error(char *, ...) \
|
|||||||
E_FUNC HALF *swap_b8_in_HALFs(HALF *dest, HALF *src, LEN len);
|
E_FUNC HALF *swap_b8_in_HALFs(HALF *dest, HALF *src, LEN len);
|
||||||
E_FUNC ZVALUE *swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all);
|
E_FUNC ZVALUE *swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all);
|
||||||
E_FUNC HALF *swap_b16_in_HALFs(HALF *dest, HALF *src, LEN len);
|
E_FUNC HALF *swap_b16_in_HALFs(HALF *dest, HALF *src, LEN len);
|
||||||
|
E_FUNC HALF *swap_HALFs(HALF *dest, HALF *src, LEN len);
|
||||||
E_FUNC ZVALUE *swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all);
|
E_FUNC ZVALUE *swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all);
|
||||||
E_FUNC ZVALUE *swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all);
|
E_FUNC ZVALUE *swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user