UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
trans.h
1 /* trans.h */
2 /* trans.h,v 1.13 2001/09/27 17:03:48 ibadm Exp */
3 
4 /*********************************************************************
5  *
6  * UNIVERS
7  * (C) ООО "ГЕОВЕРС", 2001
8  *
9  * Все права защищены * * Использование, копирование или передача регулируются законами * Российской Федерации "Об авторском праве и смежных правах", "О * правовой охране программ для электронных вычислительных машин и баз * данных" * * Encoding: ISO-8859-5 (GOST) * *********************************************************************/ #ifndef __trans_h #define __trans_h /*********************************************************************** * * Module for data transformation between different computer * architectures. * ***********************************************************************/ #include <mix/Types.h> /* Supported architectures. */ typedef enum { /* MSB; SPARC, Power, MC680x0, Network Byte Order */ trans_big_endian, /* LSB; INTEL x86, VAX-11 */ trans_little_endian, /* MSB; IBM S/360 and clones */ trans_ibm_s360 } ByteOrder; /* String equivalents for ByteOrder. */ #define TRANS_BIG_ENDIAN "sparc,mc68k,power,bigend" #define TRANS_LITTLE_ENDIAN "intel86,vax11,litend" #define TRANS_IBM_S360 "ibm360" /* Supported text encodings. */ typedef enum { trans_enc_unknown, /* undefined encoding */ trans_ascii, /* 8-bits (7-bits informational) */ trans_ebcdic, /* 8-bits (equivalent to ASCII) */ trans_iso8859_5, /* 8-bits cyrillic ISO 8859-5 (GOST) */ trans_koi8r, /* 8-bits cyrillic KOI8-R (Internet) */ trans_cp866, /* 8-bits cyrillic CP 866 (alternative, DOS) */ trans_cp1251, /* 8-bits cyrillic CP 1251 (windows) */ trans_gb2312 /* 16-bits chinese + english + greek + cyrillic */ } TextEncoding; /*********************************************************************** * Floating point number Real4 representation for endian transformation. ***********************************************************************/ typedef union { UnsInt1 byte[sizeof(Real4)]; Real4 value; } endian_Real4; /*********************************************************************** * Floating point number Real4 description for IBM S/360. * unsigned sign:1; * unsigned exponent:7; 16**(e-64) * unsigned fraction2:8; * unsigned fraction1:8; * unsigned fraction0:8; * * Floating point number Real4 description by ANSI/IEEE 754-1985. * unsigned sign:1; * unsigned exponent:8; 2**(e-128) * unsigned fraction2:7; * unsigned fraction1:8; * unsigned fraction0:8; ***********************************************************************/ typedef struct { unsigned sign; /* 0 means +1; 1 means -1 */ unsigned exponent; unsigned fraction; } struct_Real4; /*********************************************************************** * Floating point number Real8 representation for endian transformation. ***********************************************************************/ typedef union { UnsInt1 byte[sizeof(Real8)]; Real8 value; } endian_Real8; /*********************************************************************** * Floating point number Real8 description for IBM S/360. * unsigned sign:1; * unsigned exponent:7; 16**(e-64) * unsigned fraction6:8; * unsigned fraction5:8; * unsigned fraction4:8; * unsigned fraction3:8; * unsigned fraction2:8; * unsigned fraction1:8; * unsigned fraction0:8; * * Floating point number Real8 description by ANSI/IEEE 754-1985. * unsigned sign:1; * unsigned exponent:11; 2**(e-1024) * unsigned fraction6:4; * unsigned fraction5:8; * unsigned fraction4:8; * unsigned fraction3:8; * unsigned fraction2:8; * unsigned fraction1:8; * unsigned fraction0:8; ***********************************************************************/ typedef struct { unsigned sign; /* 0 means +1; 1 means -1 */ unsigned exponent; unsigned fraction1; unsigned fraction0; } struct_Real8; #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /*********************************************************************** * Service functions. Pointer address alignment insensitive. ***********************************************************************/ /* Procedure to exchange 8 bytes MSB<->LSB at the pointer. */ void trans_endian_8b (void* pInPlace); /* Procedure to exchange 4 bytes MSB<->LSB at the pointer. */ void trans_endian_4b (void* pInPlace); /* Procedure to exchange 2 bytes MSB<->LSB at the pointer. */ void trans_endian_2b (void* pInPlace); /* Procedure to determine actual computer architecture. */ ByteOrder trans_smart (); /* Procedures for conversion ByteOrder id to string and vise versa. */ const char* trans_to_string (ByteOrder trans_type); ByteOrder string_to_trans (const char* str); /* Procedures for conversion text encoding id to string and vise versa. */ const char* textenc_to_label (TextEncoding textenc); const char* textenc_to_string (TextEncoding textenc); TextEncoding string_to_textenc (const char* str); /* Determine atom type for representing given text encoding. */ AtomType textenc_atom (TextEncoding textenc); /*********************************************************************** * Unified structured representation of float numbers. ***********************************************************************/ /* * REAL*4 */ /* Transform float of given endian and architecture (ANSI/IEEE 754-1985 or IBM S/360) to structured format. */ void trans_Real4_to_struct (const void* pValue, ByteOrder eFloatArch, struct_Real4* pStruct); /* Transform structured format to float of needed endian and architecture (ANSI/IEEE 754-1985 or IBM S/360). */ void trans_struct_to_Real4 (void* pValue, ByteOrder eFloatArch, const struct_Real4* pStruct); /* * REAL*8 */ /* Transform float of given endian and architecture (ANSI/IEEE 754-1985 or IBM S/360) to structured format. */ void trans_Real8_to_struct (const void* pValue, ByteOrder eFloatArch, struct_Real8* pStruct); /* Transform structured format to float of needed endian and architecture (ANSI/IEEE 754-1985 or IBM S/360). */ void trans_struct_to_Real8 (void* pValue, ByteOrder eFloatArch, const struct_Real8* pStruct); /*********************************************************************** * Language <-> encoding. * * Due to usual encoding supports few languages and each non-English * language has many different encodings, "favorite" term is set. * * For example, there are many cyrillic encodings: "koi8-r", "iso-8859-5", * "cp1251", "cp866" etc, but favorite text encoding for "ru" language is * "iso-8859-5" (inside UNIVERS package of course :-). * Each encoding contains latin chars, but favorite language for the * "iso-8859-5" encoding is "ru", because this language is target for it. * * Next two functions perform two way "favoritism": ***********************************************************************/ /* Get favorite text encoding for the given language */ TextEncoding lang_to_textenc (const char* lang); /* Return favorite language of this encoding */ const char* textenc_to_lang (TextEncoding textenc); /*********************************************************************** * Elementary transformation functions. * The pointer pInPlace must be aligned to 4-bytes (2-bytes for Int2) * boundary. Alignment for Char pointers isn't needed. ***********************************************************************/ /* Procedure of floating point Real4 number transformation. */ int trans_one_Real4 (ByteOrder trans_target, ByteOrder trans_source, void* pInPlace); /* Procedure of floating point Real8 number transformation. */ /* NOT TESTED! trans_ibm_s360<->trans_*_endian IEEE maybe BUGGY! */ int trans_one_Real8 (ByteOrder trans_target, ByteOrder trans_source, void* pInPlace); #ifdef CompilerIs64bitReady /* Procedure of signed integer Int8 number transformation. */ int trans_one_Int8 (ByteOrder trans_target, ByteOrder trans_source, void* pInPlace); #endif /* CompilerIs64bitReady */ /* Procedure of signed integer Int4 number transformation. */ int trans_one_Int4 (ByteOrder trans_target, ByteOrder trans_source, void* pInPlace); /* Procedure of signed integer Int2 number transformation. */ int trans_one_Int2 (ByteOrder trans_target, ByteOrder trans_source, void* pInPlace); /* Procedure of signed integer Int1 number transformation. */ int trans_one_Int1 (ByteOrder trans_target, ByteOrder trans_source, void* pInPlace); /* Procedure of character transformation. */ int trans_one_Char (TextEncoding trans_target, TextEncoding trans_source, void* pInPlace); /* Procedure of 2-byte character transformation. */ int trans_one_Char2 (ByteOrder trans_target, ByteOrder trans_source, void* pInPlace); /*********************************************************************** * Batch transformation functions. * Pointers pTarget and pSource must be aligned to 4-bytes (2-bytes for * Int2) boundary. Alignment for Char pointers isn't needed. ***********************************************************************/ /* Procedure of floating point Real4 number's array transformation. */ int trans_many_Real4 (ByteOrder trans_target, void* pTarget, ByteOrder trans_source, const void* pSource, unsigned long count); /* Procedure of floating point Real8 number's array transformation. */ /* NOT TESTED! trans_ibm_s360<->trans_*_endian IEEE maybe BUGGY! */ int trans_many_Real8 (ByteOrder trans_target, void* pTarget, ByteOrder trans_source, const void* pSource, unsigned long count); #ifdef CompilerIs64bitReady /* Procedure of signed integer Int8 number's array transformation. */ int trans_many_Int8 (ByteOrder trans_target, void* pTarget, ByteOrder trans_source, const void* pSource, unsigned long count); #endif /* CompilerIs64bitReady */ /* Procedure of signed integer Int4 number's array transformation. */ int trans_many_Int4 (ByteOrder trans_target, void* pTarget, ByteOrder trans_source, const void* pSource, unsigned long count); /* Procedure of signed integer Int2 number's array transformation. */ int trans_many_Int2 (ByteOrder trans_target, void* pTarget, ByteOrder trans_source, const void* pSource, unsigned long count); /* Procedure of signed integer Int1 number's array transformation. */ int trans_many_Int1 (ByteOrder trans_target, void* pTarget, ByteOrder trans_source, const void* pSource, unsigned long count); /* Procedure of 2-byte character's array transformation. */ int trans_many_Char2 (ByteOrder trans_target, void* pTarget, ByteOrder trans_source, const void* pSource, unsigned long count); /* Procedure of character's array transformation. */ int trans_many_Char (TextEncoding trans_target, void* pTarget, TextEncoding trans_source, const void* pSource, unsigned long count); /*********************************************************************** * Batch data transformation functions of given type. ***********************************************************************/ /* Procedure for given data type (numbers, Char2) array transformation. */ int trans_numbers (AtomType atom_type, ByteOrder trans_target, void* pTarget, ByteOrder trans_source, const void* pSource, unsigned long count); /* Procedure for given string (1-byte chars) transformation. */ int trans_string (TextEncoding trans_target, Char* szTarget, TextEncoding trans_source, const Char* szSource); /*********************************************************************** * Char2 <-> multibyte char string translations. * ASCII + something in second part of 8bits table (c2enc dependent). ***********************************************************************/ /* Translate multibyte string to one two-byte char */ int trans_get_Char2 (TextEncoding c2enc, Char2* c2symbol, const char* mbs); /* Translate multibyte string to one two-byte char */ int trans_put_Char2 (TextEncoding c2enc, Char* mbs, Char2 c2symbol); #ifdef __cplusplus }; #endif /* __cplusplus */ #endif /* trans.h */
10  *
11  * Использование, копирование или передача регулируются законами
12  * Российской Федерации "Об авторском праве и смежных правах", "О * правовой охране программ для электронных вычислительных машин и баз * данных" * * Encoding: ISO-8859-5 (GOST) * *********************************************************************/ #ifndef __trans_h #define __trans_h /*********************************************************************** * * Module for data transformation between different computer * architectures. * ***********************************************************************/ #include <mix/Types.h> /* Supported architectures. */ typedef enum { /* MSB; SPARC, Power, MC680x0, Network Byte Order */ trans_big_endian, /* LSB; INTEL x86, VAX-11 */ trans_little_endian, /* MSB; IBM S/360 and clones */ trans_ibm_s360 } ByteOrder; /* String equivalents for ByteOrder. */ #define TRANS_BIG_ENDIAN "sparc,mc68k,power,bigend" #define TRANS_LITTLE_ENDIAN "intel86,vax11,litend" #define TRANS_IBM_S360 "ibm360" /* Supported text encodings. */ typedef enum { trans_enc_unknown, /* undefined encoding */ trans_ascii, /* 8-bits (7-bits informational) */ trans_ebcdic, /* 8-bits (equivalent to ASCII) */ trans_iso8859_5, /* 8-bits cyrillic ISO 8859-5 (GOST) */ trans_koi8r, /* 8-bits cyrillic KOI8-R (Internet) */ trans_cp866, /* 8-bits cyrillic CP 866 (alternative, DOS) */ trans_cp1251, /* 8-bits cyrillic CP 1251 (windows) */ trans_gb2312 /* 16-bits chinese + english + greek + cyrillic */ } TextEncoding; /*********************************************************************** * Floating point number Real4 representation for endian transformation. ***********************************************************************/ typedef union { UnsInt1 byte[sizeof(Real4)]; Real4 value; } endian_Real4; /*********************************************************************** * Floating point number Real4 description for IBM S/360. * unsigned sign:1; * unsigned exponent:7; 16**(e-64) * unsigned fraction2:8; * unsigned fraction1:8; * unsigned fraction0:8; * * Floating point number Real4 description by ANSI/IEEE 754-1985. * unsigned sign:1; * unsigned exponent:8; 2**(e-128) * unsigned fraction2:7; * unsigned fraction1:8; * unsigned fraction0:8; ***********************************************************************/ typedef struct { unsigned sign; /* 0 means +1; 1 means -1 */ unsigned exponent; unsigned fraction; } struct_Real4; /*********************************************************************** * Floating point number Real8 representation for endian transformation. ***********************************************************************/ typedef union { UnsInt1 byte[sizeof(Real8)]; Real8 value; } endian_Real8; /*********************************************************************** * Floating point number Real8 description for IBM S/360. * unsigned sign:1; * unsigned exponent:7; 16**(e-64) * unsigned fraction6:8; * unsigned fraction5:8; * unsigned fraction4:8; * unsigned fraction3:8; * unsigned fraction2:8; * unsigned fraction1:8; * unsigned fraction0:8; * * Floating point number Real8 description by ANSI/IEEE 754-1985. * unsigned sign:1; * unsigned exponent:11; 2**(e-1024) * unsigned fraction6:4; * unsigned fraction5:8; * unsigned fraction4:8; * unsigned fraction3:8; * unsigned fraction2:8; * unsigned fraction1:8; * unsigned fraction0:8; ***********************************************************************/ typedef struct { unsigned sign; /* 0 means +1; 1 means -1 */ unsigned exponent; unsigned fraction1; unsigned fraction0; } struct_Real8; #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /*********************************************************************** * Service functions. Pointer address alignment insensitive. ***********************************************************************/ /* Procedure to exchange 8 bytes MSB<->LSB at the pointer. */ void trans_endian_8b (void* pInPlace); /* Procedure to exchange 4 bytes MSB<->LSB at the pointer. */ void trans_endian_4b (void* pInPlace); /* Procedure to exchange 2 bytes MSB<->LSB at the pointer. */ void trans_endian_2b (void* pInPlace); /* Procedure to determine actual computer architecture. */ ByteOrder trans_smart (); /* Procedures for conversion ByteOrder id to string and vise versa. */ const char* trans_to_string (ByteOrder trans_type); ByteOrder string_to_trans (const char* str); /* Procedures for conversion text encoding id to string and vise versa. */ const char* textenc_to_label (TextEncoding textenc); const char* textenc_to_string (TextEncoding textenc); TextEncoding string_to_textenc (const char* str); /* Determine atom type for representing given text encoding. */ AtomType textenc_atom (TextEncoding textenc); /*********************************************************************** * Unified structured representation of float numbers. ***********************************************************************/ /* * REAL*4 */ /* Transform float of given endian and architecture (ANSI/IEEE 754-1985 or IBM S/360) to structured format. */ void trans_Real4_to_struct (const void* pValue, ByteOrder eFloatArch, struct_Real4* pStruct); /* Transform structured format to float of needed endian and architecture (ANSI/IEEE 754-1985 or IBM S/360). */ void trans_struct_to_Real4 (void* pValue, ByteOrder eFloatArch, const struct_Real4* pStruct); /* * REAL*8 */ /* Transform float of given endian and architecture (ANSI/IEEE 754-1985 or IBM S/360) to structured format. */ void trans_Real8_to_struct (const void* pValue, ByteOrder eFloatArch, struct_Real8* pStruct); /* Transform structured format to float of needed endian and architecture (ANSI/IEEE 754-1985 or IBM S/360). */ void trans_struct_to_Real8 (void* pValue, ByteOrder eFloatArch, const struct_Real8* pStruct); /*********************************************************************** * Language <-> encoding. * * Due to usual encoding supports few languages and each non-English * language has many different encodings, "favorite" term is set. * * For example, there are many cyrillic encodings: "koi8-r", "iso-8859-5", * "cp1251", "cp866" etc, but favorite text encoding for "ru" language is * "iso-8859-5" (inside UNIVERS package of course :-). * Each encoding contains latin chars, but favorite language for the * "iso-8859-5" encoding is "ru", because this language is target for it. * * Next two functions perform two way "favoritism": ***********************************************************************/ /* Get favorite text encoding for the given language */ TextEncoding lang_to_textenc (const char* lang); /* Return favorite language of this encoding */ const char* textenc_to_lang (TextEncoding textenc); /*********************************************************************** * Elementary transformation functions. * The pointer pInPlace must be aligned to 4-bytes (2-bytes for Int2) * boundary. Alignment for Char pointers isn't needed. ***********************************************************************/ /* Procedure of floating point Real4 number transformation. */ int trans_one_Real4 (ByteOrder trans_target, ByteOrder trans_source, void* pInPlace); /* Procedure of floating point Real8 number transformation. */ /* NOT TESTED! trans_ibm_s360<->trans_*_endian IEEE maybe BUGGY! */ int trans_one_Real8 (ByteOrder trans_target, ByteOrder trans_source, void* pInPlace); #ifdef CompilerIs64bitReady /* Procedure of signed integer Int8 number transformation. */ int trans_one_Int8 (ByteOrder trans_target, ByteOrder trans_source, void* pInPlace); #endif /* CompilerIs64bitReady */ /* Procedure of signed integer Int4 number transformation. */ int trans_one_Int4 (ByteOrder trans_target, ByteOrder trans_source, void* pInPlace); /* Procedure of signed integer Int2 number transformation. */ int trans_one_Int2 (ByteOrder trans_target, ByteOrder trans_source, void* pInPlace); /* Procedure of signed integer Int1 number transformation. */ int trans_one_Int1 (ByteOrder trans_target, ByteOrder trans_source, void* pInPlace); /* Procedure of character transformation. */ int trans_one_Char (TextEncoding trans_target, TextEncoding trans_source, void* pInPlace); /* Procedure of 2-byte character transformation. */ int trans_one_Char2 (ByteOrder trans_target, ByteOrder trans_source, void* pInPlace); /*********************************************************************** * Batch transformation functions. * Pointers pTarget and pSource must be aligned to 4-bytes (2-bytes for * Int2) boundary. Alignment for Char pointers isn't needed. ***********************************************************************/ /* Procedure of floating point Real4 number's array transformation. */ int trans_many_Real4 (ByteOrder trans_target, void* pTarget, ByteOrder trans_source, const void* pSource, unsigned long count); /* Procedure of floating point Real8 number's array transformation. */ /* NOT TESTED! trans_ibm_s360<->trans_*_endian IEEE maybe BUGGY! */ int trans_many_Real8 (ByteOrder trans_target, void* pTarget, ByteOrder trans_source, const void* pSource, unsigned long count); #ifdef CompilerIs64bitReady /* Procedure of signed integer Int8 number's array transformation. */ int trans_many_Int8 (ByteOrder trans_target, void* pTarget, ByteOrder trans_source, const void* pSource, unsigned long count); #endif /* CompilerIs64bitReady */ /* Procedure of signed integer Int4 number's array transformation. */ int trans_many_Int4 (ByteOrder trans_target, void* pTarget, ByteOrder trans_source, const void* pSource, unsigned long count); /* Procedure of signed integer Int2 number's array transformation. */ int trans_many_Int2 (ByteOrder trans_target, void* pTarget, ByteOrder trans_source, const void* pSource, unsigned long count); /* Procedure of signed integer Int1 number's array transformation. */ int trans_many_Int1 (ByteOrder trans_target, void* pTarget, ByteOrder trans_source, const void* pSource, unsigned long count); /* Procedure of 2-byte character's array transformation. */ int trans_many_Char2 (ByteOrder trans_target, void* pTarget, ByteOrder trans_source, const void* pSource, unsigned long count); /* Procedure of character's array transformation. */ int trans_many_Char (TextEncoding trans_target, void* pTarget, TextEncoding trans_source, const void* pSource, unsigned long count); /*********************************************************************** * Batch data transformation functions of given type. ***********************************************************************/ /* Procedure for given data type (numbers, Char2) array transformation. */ int trans_numbers (AtomType atom_type, ByteOrder trans_target, void* pTarget, ByteOrder trans_source, const void* pSource, unsigned long count); /* Procedure for given string (1-byte chars) transformation. */ int trans_string (TextEncoding trans_target, Char* szTarget, TextEncoding trans_source, const Char* szSource); /*********************************************************************** * Char2 <-> multibyte char string translations. * ASCII + something in second part of 8bits table (c2enc dependent). ***********************************************************************/ /* Translate multibyte string to one two-byte char */ int trans_get_Char2 (TextEncoding c2enc, Char2* c2symbol, const char* mbs); /* Translate multibyte string to one two-byte char */ int trans_put_Char2 (TextEncoding c2enc, Char* mbs, Char2 c2symbol); #ifdef __cplusplus }; #endif /* __cplusplus */ #endif /* trans.h */
13  * правовой охране программ для электронных вычислительных машин и баз * данных" * * Encoding: ISO-8859-5 (GOST) * *********************************************************************/ #ifndef __trans_h #define __trans_h /*********************************************************************** * * Module for data transformation between different computer * architectures. * ***********************************************************************/ #include <mix/Types.h> /* Supported architectures. */ typedef enum { /* MSB; SPARC, Power, MC680x0, Network Byte Order */ trans_big_endian, /* LSB; INTEL x86, VAX-11 */ trans_little_endian, /* MSB; IBM S/360 and clones */ trans_ibm_s360 } ByteOrder; /* String equivalents for ByteOrder. */ #define TRANS_BIG_ENDIAN "sparc,mc68k,power,bigend" #define TRANS_LITTLE_ENDIAN "intel86,vax11,litend" #define TRANS_IBM_S360 "ibm360" /* Supported text encodings. */ typedef enum { trans_enc_unknown, /* undefined encoding */ trans_ascii, /* 8-bits (7-bits informational) */ trans_ebcdic, /* 8-bits (equivalent to ASCII) */ trans_iso8859_5, /* 8-bits cyrillic ISO 8859-5 (GOST) */ trans_koi8r, /* 8-bits cyrillic KOI8-R (Internet) */ trans_cp866, /* 8-bits cyrillic CP 866 (alternative, DOS) */ trans_cp1251, /* 8-bits cyrillic CP 1251 (windows) */ trans_gb2312 /* 16-bits chinese + english + greek + cyrillic */ } TextEncoding; /*********************************************************************** * Floating point number Real4 representation for endian transformation. ***********************************************************************/ typedef union { UnsInt1 byte[sizeof(Real4)]; Real4 value; } endian_Real4; /*********************************************************************** * Floating point number Real4 description for IBM S/360. * unsigned sign:1; * unsigned exponent:7; 16**(e-64) * unsigned fraction2:8; * unsigned fraction1:8; * unsigned fraction0:8; * * Floating point number Real4 description by ANSI/IEEE 754-1985. * unsigned sign:1; * unsigned exponent:8; 2**(e-128) * unsigned fraction2:7; * unsigned fraction1:8; * unsigned fraction0:8; ***********************************************************************/ typedef struct { unsigned sign; /* 0 means +1; 1 means -1 */ unsigned exponent; unsigned fraction; } struct_Real4; /*********************************************************************** * Floating point number Real8 representation for endian transformation. ***********************************************************************/ typedef union { UnsInt1 byte[sizeof(Real8)]; Real8 value; } endian_Real8; /*********************************************************************** * Floating point number Real8 description for IBM S/360. * unsigned sign:1; * unsigned exponent:7; 16**(e-64) * unsigned fraction6:8; * unsigned fraction5:8; * unsigned fraction4:8; * unsigned fraction3:8; * unsigned fraction2:8; * unsigned fraction1:8; * unsigned fraction0:8; * * Floating point number Real8 description by ANSI/IEEE 754-1985. * unsigned sign:1; * unsigned exponent:11; 2**(e-1024) * unsigned fraction6:4; * unsigned fraction5:8; * unsigned fraction4:8; * unsigned fraction3:8; * unsigned fraction2:8; * unsigned fraction1:8; * unsigned fraction0:8; ***********************************************************************/ typedef struct { unsigned sign; /* 0 means +1; 1 means -1 */ unsigned exponent; unsigned fraction1; unsigned fraction0; } struct_Real8; #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /*********************************************************************** * Service functions. Pointer address alignment insensitive. ***********************************************************************/ /* Procedure to exchange 8 bytes MSB<->LSB at the pointer. */ void trans_endian_8b (void* pInPlace); /* Procedure to exchange 4 bytes MSB<->LSB at the pointer. */ void trans_endian_4b (void* pInPlace); /* Procedure to exchange 2 bytes MSB<->LSB at the pointer. */ void trans_endian_2b (void* pInPlace); /* Procedure to determine actual computer architecture. */ ByteOrder trans_smart (); /* Procedures for conversion ByteOrder id to string and vise versa. */ const char* trans_to_string (ByteOrder trans_type); ByteOrder string_to_trans (const char* str); /* Procedures for conversion text encoding id to string and vise versa. */ const char* textenc_to_label (TextEncoding textenc); const char* textenc_to_string (TextEncoding textenc); TextEncoding string_to_textenc (const char* str); /* Determine atom type for representing given text encoding. */ AtomType textenc_atom (TextEncoding textenc); /*********************************************************************** * Unified structured representation of float numbers. ***********************************************************************/ /* * REAL*4 */ /* Transform float of given endian and architecture (ANSI/IEEE 754-1985 or IBM S/360) to structured format. */ void trans_Real4_to_struct (const void* pValue, ByteOrder eFloatArch, struct_Real4* pStruct); /* Transform structured format to float of needed endian and architecture (ANSI/IEEE 754-1985 or IBM S/360). */ void trans_struct_to_Real4 (void* pValue, ByteOrder eFloatArch, const struct_Real4* pStruct); /* * REAL*8 */ /* Transform float of given endian and architecture (ANSI/IEEE 754-1985 or IBM S/360) to structured format. */ void trans_Real8_to_struct (const void* pValue, ByteOrder eFloatArch, struct_Real8* pStruct); /* Transform structured format to float of needed endian and architecture (ANSI/IEEE 754-1985 or IBM S/360). */ void trans_struct_to_Real8 (void* pValue, ByteOrder eFloatArch, const struct_Real8* pStruct); /*********************************************************************** * Language <-> encoding. * * Due to usual encoding supports few languages and each non-English * language has many different encodings, "favorite" term is set. * * For example, there are many cyrillic encodings: "koi8-r", "iso-8859-5", * "cp1251", "cp866" etc, but favorite text encoding for "ru" language is * "iso-8859-5" (inside UNIVERS package of course :-). * Each encoding contains latin chars, but favorite language for the * "iso-8859-5" encoding is "ru", because this language is target for it. * * Next two functions perform two way "favoritism": ***********************************************************************/ /* Get favorite text encoding for the given language */ TextEncoding lang_to_textenc (const char* lang); /* Return favorite language of this encoding */ const char* textenc_to_lang (TextEncoding textenc); /*********************************************************************** * Elementary transformation functions. * The pointer pInPlace must be aligned to 4-bytes (2-bytes for Int2) * boundary. Alignment for Char pointers isn't needed. ***********************************************************************/ /* Procedure of floating point Real4 number transformation. */ int trans_one_Real4 (ByteOrder trans_target, ByteOrder trans_source, void* pInPlace); /* Procedure of floating point Real8 number transformation. */ /* NOT TESTED! trans_ibm_s360<->trans_*_endian IEEE maybe BUGGY! */ int trans_one_Real8 (ByteOrder trans_target, ByteOrder trans_source, void* pInPlace); #ifdef CompilerIs64bitReady /* Procedure of signed integer Int8 number transformation. */ int trans_one_Int8 (ByteOrder trans_target, ByteOrder trans_source, void* pInPlace); #endif /* CompilerIs64bitReady */ /* Procedure of signed integer Int4 number transformation. */ int trans_one_Int4 (ByteOrder trans_target, ByteOrder trans_source, void* pInPlace); /* Procedure of signed integer Int2 number transformation. */ int trans_one_Int2 (ByteOrder trans_target, ByteOrder trans_source, void* pInPlace); /* Procedure of signed integer Int1 number transformation. */ int trans_one_Int1 (ByteOrder trans_target, ByteOrder trans_source, void* pInPlace); /* Procedure of character transformation. */ int trans_one_Char (TextEncoding trans_target, TextEncoding trans_source, void* pInPlace); /* Procedure of 2-byte character transformation. */ int trans_one_Char2 (ByteOrder trans_target, ByteOrder trans_source, void* pInPlace); /*********************************************************************** * Batch transformation functions. * Pointers pTarget and pSource must be aligned to 4-bytes (2-bytes for * Int2) boundary. Alignment for Char pointers isn't needed. ***********************************************************************/ /* Procedure of floating point Real4 number's array transformation. */ int trans_many_Real4 (ByteOrder trans_target, void* pTarget, ByteOrder trans_source, const void* pSource, unsigned long count); /* Procedure of floating point Real8 number's array transformation. */ /* NOT TESTED! trans_ibm_s360<->trans_*_endian IEEE maybe BUGGY! */ int trans_many_Real8 (ByteOrder trans_target, void* pTarget, ByteOrder trans_source, const void* pSource, unsigned long count); #ifdef CompilerIs64bitReady /* Procedure of signed integer Int8 number's array transformation. */ int trans_many_Int8 (ByteOrder trans_target, void* pTarget, ByteOrder trans_source, const void* pSource, unsigned long count); #endif /* CompilerIs64bitReady */ /* Procedure of signed integer Int4 number's array transformation. */ int trans_many_Int4 (ByteOrder trans_target, void* pTarget, ByteOrder trans_source, const void* pSource, unsigned long count); /* Procedure of signed integer Int2 number's array transformation. */ int trans_many_Int2 (ByteOrder trans_target, void* pTarget, ByteOrder trans_source, const void* pSource, unsigned long count); /* Procedure of signed integer Int1 number's array transformation. */ int trans_many_Int1 (ByteOrder trans_target, void* pTarget, ByteOrder trans_source, const void* pSource, unsigned long count); /* Procedure of 2-byte character's array transformation. */ int trans_many_Char2 (ByteOrder trans_target, void* pTarget, ByteOrder trans_source, const void* pSource, unsigned long count); /* Procedure of character's array transformation. */ int trans_many_Char (TextEncoding trans_target, void* pTarget, TextEncoding trans_source, const void* pSource, unsigned long count); /*********************************************************************** * Batch data transformation functions of given type. ***********************************************************************/ /* Procedure for given data type (numbers, Char2) array transformation. */ int trans_numbers (AtomType atom_type, ByteOrder trans_target, void* pTarget, ByteOrder trans_source, const void* pSource, unsigned long count); /* Procedure for given string (1-byte chars) transformation. */ int trans_string (TextEncoding trans_target, Char* szTarget, TextEncoding trans_source, const Char* szSource); /*********************************************************************** * Char2 <-> multibyte char string translations. * ASCII + something in second part of 8bits table (c2enc dependent). ***********************************************************************/ /* Translate multibyte string to one two-byte char */ int trans_get_Char2 (TextEncoding c2enc, Char2* c2symbol, const char* mbs); /* Translate multibyte string to one two-byte char */ int trans_put_Char2 (TextEncoding c2enc, Char* mbs, Char2 c2symbol); #ifdef __cplusplus }; #endif /* __cplusplus */ #endif /* trans.h */
14  * данных"
15  *
16  * Encoding: ISO-8859-5 (GOST)
17  *
18  *********************************************************************/
19 
20 #ifndef __trans_h
21 #define __trans_h
22 
23 /***********************************************************************
24  *
25  * Module for data transformation between different computer
26  * architectures.
27  *
28  ***********************************************************************/
29 
30 #include <mix/Types.h>
31 
32 
33 /* Supported architectures. */
34 typedef enum
35 {
36  /* MSB; SPARC, Power, MC680x0, Network Byte Order */
37  trans_big_endian,
38  /* LSB; INTEL x86, VAX-11 */
39  trans_little_endian,
40  /* MSB; IBM S/360 and clones */
41  trans_ibm_s360
42 
43 } ByteOrder;
44 
45 
46 /* String equivalents for ByteOrder. */
47 #define TRANS_BIG_ENDIAN "sparc,mc68k,power,bigend"
48 #define TRANS_LITTLE_ENDIAN "intel86,vax11,litend"
49 #define TRANS_IBM_S360 "ibm360"
50 
51 
52 /* Supported text encodings. */
53 typedef enum
54 {
55  trans_enc_unknown, /* undefined encoding */
56  trans_ascii, /* 8-bits (7-bits informational) */
57  trans_ebcdic, /* 8-bits (equivalent to ASCII) */
58  trans_iso8859_5, /* 8-bits cyrillic ISO 8859-5 (GOST) */
59  trans_koi8r, /* 8-bits cyrillic KOI8-R (Internet) */
60  trans_cp866, /* 8-bits cyrillic CP 866 (alternative, DOS) */
61  trans_cp1251, /* 8-bits cyrillic CP 1251 (windows) */
62  trans_gb2312 /* 16-bits chinese + english + greek + cyrillic */
63 
64 } TextEncoding;
65 
66 
67 /***********************************************************************
68  * Floating point number Real4 representation for endian transformation.
69  ***********************************************************************/
70 typedef union
71 {
72  UnsInt1 byte[sizeof(Real4)];
73  Real4 value;
74 
75 } endian_Real4;
76 
77 
78 /***********************************************************************
79  * Floating point number Real4 description for IBM S/360.
80  * unsigned sign:1;
81  * unsigned exponent:7; 16**(e-64)
82  * unsigned fraction2:8;
83  * unsigned fraction1:8;
84  * unsigned fraction0:8;
85  *
86  * Floating point number Real4 description by ANSI/IEEE 754-1985.
87  * unsigned sign:1;
88  * unsigned exponent:8; 2**(e-128)
89  * unsigned fraction2:7;
90  * unsigned fraction1:8;
91  * unsigned fraction0:8;
92  ***********************************************************************/
93 typedef struct
94 {
95  unsigned sign; /* 0 means +1; 1 means -1 */
96  unsigned exponent;
97  unsigned fraction;
98 
99 } struct_Real4;
100 
101 
102 /***********************************************************************
103  * Floating point number Real8 representation for endian transformation.
104  ***********************************************************************/
105 typedef union
106 {
107  UnsInt1 byte[sizeof(Real8)];
108  Real8 value;
109 
110 } endian_Real8;
111 
112 
113 /***********************************************************************
114  * Floating point number Real8 description for IBM S/360.
115  * unsigned sign:1;
116  * unsigned exponent:7; 16**(e-64)
117  * unsigned fraction6:8;
118  * unsigned fraction5:8;
119  * unsigned fraction4:8;
120  * unsigned fraction3:8;
121  * unsigned fraction2:8;
122  * unsigned fraction1:8;
123  * unsigned fraction0:8;
124  *
125  * Floating point number Real8 description by ANSI/IEEE 754-1985.
126  * unsigned sign:1;
127  * unsigned exponent:11; 2**(e-1024)
128  * unsigned fraction6:4;
129  * unsigned fraction5:8;
130  * unsigned fraction4:8;
131  * unsigned fraction3:8;
132  * unsigned fraction2:8;
133  * unsigned fraction1:8;
134  * unsigned fraction0:8;
135  ***********************************************************************/
136 typedef struct
137 {
138  unsigned sign; /* 0 means +1; 1 means -1 */
139  unsigned exponent;
140  unsigned fraction1;
141  unsigned fraction0;
142 
143 } struct_Real8;
144 
145 
146 #ifdef __cplusplus
147 extern "C" {
148 #endif /* __cplusplus */
149 
150 
151 /***********************************************************************
152  * Service functions. Pointer address alignment insensitive.
153  ***********************************************************************/
154 
155 /* Procedure to exchange 8 bytes MSB<->LSB at the pointer. */
156 void trans_endian_8b (void* pInPlace);
157 
158 /* Procedure to exchange 4 bytes MSB<->LSB at the pointer. */
159 void trans_endian_4b (void* pInPlace);
160 
161 /* Procedure to exchange 2 bytes MSB<->LSB at the pointer. */
162 void trans_endian_2b (void* pInPlace);
163 
164 /* Procedure to determine actual computer architecture. */
165 ByteOrder trans_smart ();
166 
167 /* Procedures for conversion ByteOrder id to string and vise versa. */
168 const char* trans_to_string (ByteOrder trans_type);
169 ByteOrder string_to_trans (const char* str);
170 
171 /* Procedures for conversion text encoding id to string and vise versa. */
172 const char* textenc_to_label (TextEncoding textenc);
173 const char* textenc_to_string (TextEncoding textenc);
174 TextEncoding string_to_textenc (const char* str);
175 
176 /* Determine atom type for representing given text encoding. */
177 AtomType textenc_atom (TextEncoding textenc);
178 
179 
180 /***********************************************************************
181  * Unified structured representation of float numbers.
182  ***********************************************************************/
183 
184  /*
185  * REAL*4
186  */
187 
188 /* Transform float of given endian and architecture (ANSI/IEEE
189  754-1985 or IBM S/360) to structured format. */
190 void trans_Real4_to_struct (const void* pValue, ByteOrder eFloatArch,
191  struct_Real4* pStruct);
192 
193 /* Transform structured format to float of needed endian and
194  architecture (ANSI/IEEE 754-1985 or IBM S/360). */
195 void trans_struct_to_Real4 (void* pValue, ByteOrder eFloatArch,
196  const struct_Real4* pStruct);
197 
198 
199  /*
200  * REAL*8
201  */
202 
203 /* Transform float of given endian and architecture (ANSI/IEEE
204  754-1985 or IBM S/360) to structured format. */
205 void trans_Real8_to_struct (const void* pValue, ByteOrder eFloatArch,
206  struct_Real8* pStruct);
207 
208 /* Transform structured format to float of needed endian and
209  architecture (ANSI/IEEE 754-1985 or IBM S/360). */
210 void trans_struct_to_Real8 (void* pValue, ByteOrder eFloatArch,
211  const struct_Real8* pStruct);
212 
213 
214 /***********************************************************************
215  * Language <-> encoding.
216  *
217  * Due to usual encoding supports few languages and each non-English
218  * language has many different encodings, "favorite" term is set.
219  *
220  * For example, there are many cyrillic encodings: "koi8-r", "iso-8859-5",
221  * "cp1251", "cp866" etc, but favorite text encoding for "ru" language is
222  * "iso-8859-5" (inside UNIVERS package of course :-).
223  * Each encoding contains latin chars, but favorite language for the
224  * "iso-8859-5" encoding is "ru", because this language is target for it.
225  *
226  * Next two functions perform two way "favoritism":
227  ***********************************************************************/
228 
229 /* Get favorite text encoding for the given language */
230 TextEncoding lang_to_textenc (const char* lang);
231 
232 /* Return favorite language of this encoding */
233 const char* textenc_to_lang (TextEncoding textenc);
234 
235 
236 /***********************************************************************
237  * Elementary transformation functions.
238  * The pointer pInPlace must be aligned to 4-bytes (2-bytes for Int2)
239  * boundary. Alignment for Char pointers isn't needed.
240  ***********************************************************************/
241 
242 /* Procedure of floating point Real4 number transformation. */
243 int trans_one_Real4 (ByteOrder trans_target, ByteOrder trans_source,
244  void* pInPlace);
245 
246 /* Procedure of floating point Real8 number transformation. */
247 /* NOT TESTED! trans_ibm_s360<->trans_*_endian IEEE maybe BUGGY! */
248 int trans_one_Real8 (ByteOrder trans_target, ByteOrder trans_source,
249  void* pInPlace);
250 
251 #ifdef CompilerIs64bitReady
252 /* Procedure of signed integer Int8 number transformation. */
253 int trans_one_Int8 (ByteOrder trans_target, ByteOrder trans_source,
254  void* pInPlace);
255 #endif /* CompilerIs64bitReady */
256 
257 /* Procedure of signed integer Int4 number transformation. */
258 int trans_one_Int4 (ByteOrder trans_target, ByteOrder trans_source,
259  void* pInPlace);
260 
261 /* Procedure of signed integer Int2 number transformation. */
262 int trans_one_Int2 (ByteOrder trans_target, ByteOrder trans_source,
263  void* pInPlace);
264 
265 /* Procedure of signed integer Int1 number transformation. */
266 int trans_one_Int1 (ByteOrder trans_target, ByteOrder trans_source,
267  void* pInPlace);
268 
269 /* Procedure of character transformation. */
270 int trans_one_Char (TextEncoding trans_target, TextEncoding trans_source,
271  void* pInPlace);
272 
273 /* Procedure of 2-byte character transformation. */
274 int trans_one_Char2 (ByteOrder trans_target, ByteOrder trans_source,
275  void* pInPlace);
276 
277 
278 /***********************************************************************
279  * Batch transformation functions.
280  * Pointers pTarget and pSource must be aligned to 4-bytes (2-bytes for
281  * Int2) boundary. Alignment for Char pointers isn't needed.
282  ***********************************************************************/
283 
284 /* Procedure of floating point Real4 number's array transformation. */
285 int trans_many_Real4 (ByteOrder trans_target, void* pTarget,
286  ByteOrder trans_source, const void* pSource,
287  unsigned long count);
288 
289 /* Procedure of floating point Real8 number's array transformation. */
290  /* NOT TESTED! trans_ibm_s360<->trans_*_endian IEEE maybe BUGGY! */
291 int trans_many_Real8 (ByteOrder trans_target, void* pTarget,
292  ByteOrder trans_source, const void* pSource,
293  unsigned long count);
294 
295 #ifdef CompilerIs64bitReady
296 /* Procedure of signed integer Int8 number's array transformation. */
297 int trans_many_Int8 (ByteOrder trans_target, void* pTarget,
298  ByteOrder trans_source, const void* pSource,
299  unsigned long count);
300 #endif /* CompilerIs64bitReady */
301 
302 /* Procedure of signed integer Int4 number's array transformation. */
303 int trans_many_Int4 (ByteOrder trans_target, void* pTarget,
304  ByteOrder trans_source, const void* pSource,
305  unsigned long count);
306 
307 /* Procedure of signed integer Int2 number's array transformation. */
308 int trans_many_Int2 (ByteOrder trans_target, void* pTarget,
309  ByteOrder trans_source, const void* pSource,
310  unsigned long count);
311 
312 /* Procedure of signed integer Int1 number's array transformation. */
313 int trans_many_Int1 (ByteOrder trans_target, void* pTarget,
314  ByteOrder trans_source, const void* pSource,
315  unsigned long count);
316 
317 /* Procedure of 2-byte character's array transformation. */
318 int trans_many_Char2 (ByteOrder trans_target, void* pTarget,
319  ByteOrder trans_source, const void* pSource,
320  unsigned long count);
321 
322 /* Procedure of character's array transformation. */
323 int trans_many_Char (TextEncoding trans_target, void* pTarget,
324  TextEncoding trans_source, const void* pSource,
325  unsigned long count);
326 
327 
328 /***********************************************************************
329  * Batch data transformation functions of given type.
330  ***********************************************************************/
331 
332 /* Procedure for given data type (numbers, Char2) array transformation. */
333 int trans_numbers (AtomType atom_type,
334  ByteOrder trans_target, void* pTarget,
335  ByteOrder trans_source, const void* pSource,
336  unsigned long count);
337 
338 /* Procedure for given string (1-byte chars) transformation. */
339 int trans_string (TextEncoding trans_target, Char* szTarget,
340  TextEncoding trans_source, const Char* szSource);
341 
342 
343 /***********************************************************************
344  * Char2 <-> multibyte char string translations.
345  * ASCII + something in second part of 8bits table (c2enc dependent).
346  ***********************************************************************/
347 
348 /* Translate multibyte string to one two-byte char */
349 int trans_get_Char2 (TextEncoding c2enc, Char2* c2symbol,
350  const char* mbs);
351 
352 /* Translate multibyte string to one two-byte char */
353 int trans_put_Char2 (TextEncoding c2enc, Char* mbs,
354  Char2 c2symbol);
355 
356 
357 #ifdef __cplusplus
358 };
359 #endif /* __cplusplus */
360 
361 #endif /* trans.h */
Definition: trans.h:136
Definition: trans.h:70
Definition: trans.h:93
Definition: trans.h:105