abcio.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. #ifndef _abcio_h_
  2. #define _abcio_h_
  3. /* abcio.h
  4. *
  5. * Copyright (C) 1992-2011,2015,2017,2018 Paul Boersma
  6. *
  7. * This code is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * This code is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /* Numeric text input and output. */
  21. int texgeti8 (MelderReadText text);
  22. int16 texgeti16 (MelderReadText text);
  23. int32 texgeti32 (MelderReadText text);
  24. integer texgetinteger (MelderReadText text);
  25. #define texgetinteger16BE texgetinteger
  26. #define texgetinteger32BE texgetinteger
  27. unsigned int texgetu8 (MelderReadText text);
  28. uint16 texgetu16 (MelderReadText text);
  29. uint32 texgetu32 (MelderReadText text);
  30. double texgetr32 (MelderReadText text);
  31. double texgetr64 (MelderReadText text);
  32. double texgetr80 (MelderReadText text);
  33. dcomplex texgetc64 (MelderReadText text);
  34. dcomplex texgetc128 (MelderReadText text);
  35. int texgete8 (MelderReadText text, enum_generic_getValue getValue);
  36. int texgete16 (MelderReadText text, enum_generic_getValue getValue);
  37. bool texgeteb (MelderReadText text);
  38. bool texgeteq (MelderReadText text);
  39. bool texgetex (MelderReadText text);
  40. autostring8 texgets16 (MelderReadText text);
  41. autostring8 texgets32 (MelderReadText text);
  42. autostring32 texgetw16 (MelderReadText text);
  43. autostring32 texgetw32 (MelderReadText text);
  44. void texindent (MelderFile file);
  45. void texexdent (MelderFile file);
  46. void texresetindent (MelderFile file);
  47. #define texput_UP_TO_SIX_NULLABLE_STRINGS \
  48. conststring32 s1 = nullptr, conststring32 s2 = nullptr, conststring32 s3 = nullptr, \
  49. conststring32 s4 = nullptr, conststring32 s5 = nullptr, conststring32 s6 = nullptr
  50. void texputintro (MelderFile file, texput_UP_TO_SIX_NULLABLE_STRINGS);
  51. void texputi8 (MelderFile file, int i, texput_UP_TO_SIX_NULLABLE_STRINGS);
  52. void texputi16 (MelderFile file, int i, texput_UP_TO_SIX_NULLABLE_STRINGS);
  53. void texputi32 (MelderFile file, long i, texput_UP_TO_SIX_NULLABLE_STRINGS);
  54. void texputinteger (MelderFile file, integer i, texput_UP_TO_SIX_NULLABLE_STRINGS);
  55. #define texputinteger16BE texputinteger
  56. #define texputinteger32BE texputinteger
  57. void texputu8 (MelderFile file, unsigned int u, texput_UP_TO_SIX_NULLABLE_STRINGS);
  58. void texputu16 (MelderFile file, unsigned int u, texput_UP_TO_SIX_NULLABLE_STRINGS);
  59. void texputu32 (MelderFile file, unsigned long u, texput_UP_TO_SIX_NULLABLE_STRINGS);
  60. void texputr32 (MelderFile file, double x, texput_UP_TO_SIX_NULLABLE_STRINGS);
  61. void texputr64 (MelderFile file, double x, texput_UP_TO_SIX_NULLABLE_STRINGS);
  62. void texputc64 (MelderFile file, dcomplex z, texput_UP_TO_SIX_NULLABLE_STRINGS);
  63. void texputc128 (MelderFile file, dcomplex z, texput_UP_TO_SIX_NULLABLE_STRINGS);
  64. void texpute8 (MelderFile file, int i, conststring32 (*getText) (int), texput_UP_TO_SIX_NULLABLE_STRINGS);
  65. void texpute16 (MelderFile file, int i, conststring32 (*getText) (int), texput_UP_TO_SIX_NULLABLE_STRINGS);
  66. void texputeb (MelderFile file, bool i, texput_UP_TO_SIX_NULLABLE_STRINGS);
  67. void texputeq (MelderFile file, bool i, texput_UP_TO_SIX_NULLABLE_STRINGS);
  68. void texputex (MelderFile file, bool i, texput_UP_TO_SIX_NULLABLE_STRINGS);
  69. void texputs8 (MelderFile file, conststring8 s, texput_UP_TO_SIX_NULLABLE_STRINGS);
  70. void texputs16 (MelderFile file, conststring8 s, texput_UP_TO_SIX_NULLABLE_STRINGS);
  71. void texputs32 (MelderFile file, conststring8 s, texput_UP_TO_SIX_NULLABLE_STRINGS);
  72. void texputw16 (MelderFile file, conststring32 s, texput_UP_TO_SIX_NULLABLE_STRINGS);
  73. void texputw32 (MelderFile file, conststring32 s, texput_UP_TO_SIX_NULLABLE_STRINGS);
  74. /* Portable device-independent binary input and output. */
  75. /* Works on all machines with 8-bit bytes and chars, and 2's complement integers. */
  76. /* Works independent of byte order or floating-point implementations. */
  77. /*
  78. The 42 routines are analogous to fgetc and fputc, who read or write one character:
  79. int fgetc (FILE *f); int fputc (int c, FILE *f); // 0..255
  80. */
  81. unsigned int bingetu8 (FILE *f); void binputu8 (unsigned int i, FILE *f); // 0..255
  82. uint16 bingetu16 (FILE *f); void binputu16 (uint16 i, FILE *f); // 0..65535
  83. uint32 bingetu32 (FILE *f); void binputu32 (uint32 i, FILE *f); // 0..4294967295
  84. int bingeti8 (FILE *f); void binputi8 (int i, FILE *f); /* -128..127 */
  85. int16 bingeti16 (FILE *f); void binputi16 (int16 i, FILE *f); // -32768..32767
  86. int32 bingeti24 (FILE *f); void binputi24 (int32 i, FILE *f); // -8388608..8388607
  87. int32 bingeti32 (FILE *f); void binputi32 (int32 i, FILE *f); // -2147483648..2147483647
  88. integer bingetinteger32BE (FILE *f); void binputinteger32BE (integer i, FILE *f);
  89. integer bingetinteger16BE (FILE *f); void binputinteger16BE (integer i, FILE *f);
  90. /*
  91. Read or write signed or unsigned integers from or to 2 or 4 bytes in the stream 'f',
  92. in big-endian byte order (most significant byte first).
  93. This is the native integer format on Macintosh and Silicon Graphics Iris.
  94. */
  95. int16 bingeti16LE (FILE *f); void binputi16LE (int16 i, FILE *f); // -32768..32767
  96. int32 bingeti24LE (FILE *f); void binputi24LE (int32 i, FILE *f); // -8388608..8388607
  97. int32 bingeti32LE (FILE *f); void binputi32LE (int32 i, FILE *f); // -2147483648..2147483647
  98. uint16 bingetu16LE (FILE *f); void binputu16LE (uint16 i, FILE *f); // 0..65535
  99. uint32 bingetu32LE (FILE *f); void binputu32LE (uint32 i, FILE *f); // 0..4294967295
  100. /*
  101. Read or write signed or unsigned integers from or to 2 or 4 bytes in the stream 'f',
  102. in little-endian byte order (least significant byte first).
  103. This is the native integer format on Vax and IBM PC.
  104. */
  105. unsigned int bingetb1 (FILE *f); void binputb1 (unsigned int value, FILE *f); // 0..1
  106. unsigned int bingetb2 (FILE *f); void binputb2 (unsigned int value, FILE *f); // 0..3
  107. unsigned int bingetb3 (FILE *f); void binputb3 (unsigned int value, FILE *f); // 0..7
  108. unsigned int bingetb4 (FILE *f); void binputb4 (unsigned int value, FILE *f); // 0..15
  109. unsigned int bingetb5 (FILE *f); void binputb5 (unsigned int value, FILE *f); // 0..31
  110. unsigned int bingetb6 (FILE *f); void binputb6 (unsigned int value, FILE *f); // 0..63
  111. unsigned int bingetb7 (FILE *f); void binputb7 (unsigned int value, FILE *f); // 0..127
  112. void bingetb (FILE *f); void binputb (FILE *f);
  113. /*
  114. Read or write an unsigned integer from or to a number of bits in the stream 'f'.
  115. After an uninterrupted sequence of bingetbxxx or binputbxxx, call bingetb or binputb.
  116. Not reentrant: uses a static one-byte buffer. Do not call from interrupt routines.
  117. Example 1:
  118. int hasTitle = bingetb1 (f); // one bit
  119. int category = bingetb3 (f); // a number in the range 0..7
  120. int sense = bingetb2 (f); // a number in the range 0..3
  121. bingetb (f);
  122. Example 2:
  123. binputb1 (hasTitle, f); // one bit
  124. binputb3 (category, f); // a number in the range 0..7
  125. binputb2 (sense, f); // a number in the range 0..3
  126. binputb (f);
  127. */
  128. int bingete8 (FILE *f, int min, int max, conststring32 type);
  129. int bingete16 (FILE *f, int min, int max, conststring32 type);
  130. bool bingetbool8 (FILE *f);
  131. #define bingeteb bingetbool8
  132. #define bingeteq bingetbool8
  133. #define bingetex bingetbool8
  134. void binpute8 (int value, FILE *f);
  135. void binpute16 (int value, FILE *f);
  136. void binputbool8 (bool value, FILE *f);
  137. #define binputeb binputbool8
  138. #define binputeq binputbool8
  139. #define binputex binputbool8
  140. double bingetr32 (FILE *f); void binputr32 (double x, FILE *f);
  141. /*
  142. Read or write a real number from or to 4 bytes in the stream `f`,
  143. in IEEE single-precision binary real format, with the most significant bit first.
  144. NaN's (Not-a-Numbers) and infinities get the value HUGE, which equals infinity on IEEE machines.
  145. Absolute values of normalized numbers (23 bits precision): 1.2e-38 .. 3.4e38.
  146. Denormalized: from 1.4e-45.
  147. This is the native format of a `float` on Macintosh and Silicon Graphics Iris.
  148. */
  149. double bingetr32LE (FILE *f); void binputr32LE (double x, FILE *f); // least significant bit first
  150. double bingetr64 (FILE *f); void binputr64 (double x, FILE *f);
  151. /*
  152. Read or write a real number from or to 8 bytes in the stream `f`,
  153. in IEEE double-precision binary real format, with the most significant bit first.
  154. NaN's (Not-a-Numbers) and infinities get the value HUGE, which equals infinity on IEEE machines.
  155. Absolute values of normalized numbers (52 bits precision): 2.2e-308 .. 1.8e308.
  156. Denormalized: from 4.9e-324.
  157. This is the native format of a `double` on Silicon Graphics Iris and PowerMac.
  158. */
  159. double bingetr80 (FILE *f); void binputr80 (double x, FILE *f);
  160. /*
  161. Read or write a real number from or to 10 bytes in the stream `f`,
  162. in IEEE extended-precision binary real format, with the most significant bit first,
  163. as implemented in Motorola's MC68881 floating-point coprocessor.
  164. NaN's (Not-a-Numbers) and infinities get the value HUGE, which equals infinity on IEEE machines.
  165. Absolute values of normalized numbers (63 bits precision): 8e-4933 .. 6e4931.
  166. Denormalized: from 9e-4952.
  167. This format is used to encode the sampling rate in AIFF (Audio Interchange File Format) files,
  168. and is the native format of a `double` on 68k Macintosh.
  169. */
  170. dcomplex bingetc64 (FILE *f);
  171. dcomplex bingetc128 (FILE *f);
  172. void binputc64 (dcomplex z, FILE *f);
  173. void binputc128 (dcomplex z, FILE *f);
  174. autostring8 bingets8 (FILE *f); void binputs8 (const char *s, FILE *f); // 0..255 characters
  175. autostring8 bingets16 (FILE *f); void binputs16 (const char *s, FILE *f); // 0..65535 characters
  176. autostring8 bingets32 (FILE *f); void binputs32 (const char *s, FILE *f); // 0..4294967295 characters
  177. /*
  178. Read or write a string from or to `str32len(s)` UTF-16LE or ASCII characters plus 1, 2, or 4 bytes in the stream `f`,
  179. in a Pascal-style format: first the length, then the characters, without a trailing null byte.
  180. bingetsxxx returns a new 'malloc'ed null-terminated C string (for the caller to `free` it).
  181. Fail if out of memory.
  182. binputsxxx expects a null-terminated C string whose `str32len` fits in 1, 2, or 4 bytes.
  183. */
  184. autostring32 bingetw8 (FILE *f); void binputw8 (conststring32 s, FILE *f);
  185. autostring32 bingetw16 (FILE *f); void binputw16 (conststring32 s, FILE *f);
  186. autostring32 bingetw32 (FILE *f); void binputw32 (conststring32 s, FILE *f);
  187. /* End of file abcio.h */
  188. #endif