NumberFormatting.pas 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. {
  2. File: NumberFormatting.p
  3. Contains: Utilites for formatting numbers
  4. Version: Universal Interfaces 3.4.2
  5. Copyright: © 1996-2002 by Apple Computer, Inc., all rights reserved.
  6. Bugs?: For bug reports, consult the following page on
  7. the World Wide Web:
  8. http://www.freepascal.org/bugs.html
  9. }
  10. {
  11. Modified for use with Free Pascal
  12. Version 200
  13. Please report any bugs to <[email protected]>
  14. }
  15. {$mode macpas}
  16. {$packenum 1}
  17. {$macro on}
  18. {$inline on}
  19. {$CALLING MWPASCAL}
  20. unit NumberFormatting;
  21. interface
  22. {$setc UNIVERSAL_INTERFACES_VERSION := $0342}
  23. {$setc GAP_INTERFACES_VERSION := $0200}
  24. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  25. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  26. {$endc}
  27. {$ifc defined CPUPOWERPC and defined CPUI386}
  28. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  29. {$endc}
  30. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  31. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  32. {$endc}
  33. {$ifc not defined __ppc__ and defined CPUPOWERPC}
  34. {$setc __ppc__ := 1}
  35. {$elsec}
  36. {$setc __ppc__ := 0}
  37. {$endc}
  38. {$ifc not defined __i386__ and defined CPUI386}
  39. {$setc __i386__ := 1}
  40. {$elsec}
  41. {$setc __i386__ := 0}
  42. {$endc}
  43. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  44. {$error Conflicting definitions for __ppc__ and __i386__}
  45. {$endc}
  46. {$ifc defined __ppc__ and __ppc__}
  47. {$setc TARGET_CPU_PPC := TRUE}
  48. {$setc TARGET_CPU_X86 := FALSE}
  49. {$elifc defined __i386__ and __i386__}
  50. {$setc TARGET_CPU_PPC := FALSE}
  51. {$setc TARGET_CPU_X86 := TRUE}
  52. {$elsec}
  53. {$error Neither __ppc__ nor __i386__ is defined.}
  54. {$endc}
  55. {$setc TARGET_CPU_PPC_64 := FALSE}
  56. {$ifc defined FPC_BIG_ENDIAN}
  57. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  58. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  59. {$elifc defined FPC_LITTLE_ENDIAN}
  60. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  61. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  62. {$elsec}
  63. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  64. {$endc}
  65. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  66. {$setc CALL_NOT_IN_CARBON := FALSE}
  67. {$setc OLDROUTINENAMES := FALSE}
  68. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  69. {$setc OPAQUE_UPP_TYPES := TRUE}
  70. {$setc OTCARBONAPPLICATION := TRUE}
  71. {$setc OTKERNEL := FALSE}
  72. {$setc PM_USE_SESSION_APIS := TRUE}
  73. {$setc TARGET_API_MAC_CARBON := TRUE}
  74. {$setc TARGET_API_MAC_OS8 := FALSE}
  75. {$setc TARGET_API_MAC_OSX := TRUE}
  76. {$setc TARGET_CARBON := TRUE}
  77. {$setc TARGET_CPU_68K := FALSE}
  78. {$setc TARGET_CPU_MIPS := FALSE}
  79. {$setc TARGET_CPU_SPARC := FALSE}
  80. {$setc TARGET_OS_MAC := TRUE}
  81. {$setc TARGET_OS_UNIX := FALSE}
  82. {$setc TARGET_OS_WIN32 := FALSE}
  83. {$setc TARGET_RT_MAC_68881 := FALSE}
  84. {$setc TARGET_RT_MAC_CFM := FALSE}
  85. {$setc TARGET_RT_MAC_MACHO := TRUE}
  86. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  87. {$setc TYPE_BOOL := FALSE}
  88. {$setc TYPE_EXTENDED := FALSE}
  89. {$setc TYPE_LONGLONG := TRUE}
  90. uses MacTypes,ConditionalMacros,IntlResources;
  91. {$ALIGN MAC68K}
  92. {
  93. Here are the current System 7 routine names and the translations to the older forms.
  94. Please use the newer forms in all new code and migrate the older names out of existing
  95. code as maintainance permits.
  96. New Name Old Name(s)
  97. ExtendedToString FormatX2Str
  98. FormatRecToString Format2Str
  99. NumToString
  100. StringToExtended FormatStr2X
  101. StringToFormatRec Str2Format
  102. StringToNum
  103. }
  104. type
  105. NumFormatStringPtr = ^NumFormatString;
  106. NumFormatString = packed record
  107. fLength: UInt8;
  108. fVersion: UInt8;
  109. data: packed array [0..253] of char; { private data }
  110. end;
  111. NumFormatStringRec = NumFormatString;
  112. NumFormatStringRecPtr = ^NumFormatStringRec;
  113. FormatStatus = SInt16;
  114. const
  115. fVNumber = 0; { first version of NumFormatString }
  116. type
  117. FormatClass = SInt8;
  118. const
  119. fPositive = 0;
  120. fNegative = 1;
  121. fZero = 2;
  122. type
  123. FormatResultType = SInt8;
  124. const
  125. fFormatOK = 0;
  126. fBestGuess = 1;
  127. fOutOfSynch = 2;
  128. fSpuriousChars = 3;
  129. fMissingDelimiter = 4;
  130. fExtraDecimal = 5;
  131. fMissingLiteral = 6;
  132. fExtraExp = 7;
  133. fFormatOverflow = 8;
  134. fFormStrIsNAN = 9;
  135. fBadPartsTable = 10;
  136. fExtraPercent = 11;
  137. fExtraSeparator = 12;
  138. fEmptyFormatString = 13;
  139. type
  140. FVectorPtr = ^FVector;
  141. FVector = record
  142. start: SInt16;
  143. length: SInt16;
  144. end;
  145. { index by [fPositive..fZero] }
  146. TripleInt = array [0..2] of FVector;
  147. {
  148. * StringToNum()
  149. *
  150. * Availability:
  151. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  152. * CarbonLib: in CarbonLib 1.0 and later
  153. * Mac OS X: in version 10.0 and later
  154. }
  155. procedure StringToNum(const (*var*) theString: Str255; var theNum: SInt32); external name '_StringToNum';
  156. {
  157. * NumToString()
  158. *
  159. * Availability:
  160. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  161. * CarbonLib: in CarbonLib 1.0 and later
  162. * Mac OS X: in version 10.0 and later
  163. }
  164. procedure NumToString(theNum: SInt32; var theString: Str255); external name '_NumToString';
  165. {
  166. * ExtendedToString()
  167. *
  168. * Availability:
  169. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  170. * CarbonLib: in CarbonLib 1.0 and later
  171. * Mac OS X: in version 10.0 and later
  172. }
  173. function ExtendedToString(const (*var*) x: extended80; const (*var*) myCanonical: NumFormatString; const (*var*) partsTable: NumberParts; var outString: Str255): FormatStatus; external name '_ExtendedToString';
  174. {
  175. * StringToExtended()
  176. *
  177. * Availability:
  178. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  179. * CarbonLib: in CarbonLib 1.0 and later
  180. * Mac OS X: in version 10.0 and later
  181. }
  182. function StringToExtended(const (*var*) source: Str255; const (*var*) myCanonical: NumFormatString; const (*var*) partsTable: NumberParts; var x: extended80): FormatStatus; external name '_StringToExtended';
  183. {
  184. * StringToFormatRec()
  185. *
  186. * Availability:
  187. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  188. * CarbonLib: in CarbonLib 1.0 and later
  189. * Mac OS X: in version 10.0 and later
  190. }
  191. function StringToFormatRec(const (*var*) inString: Str255; const (*var*) partsTable: NumberParts; var outString: NumFormatString): FormatStatus; external name '_StringToFormatRec';
  192. {
  193. * FormatRecToString()
  194. *
  195. * Availability:
  196. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  197. * CarbonLib: in CarbonLib 1.0 and later
  198. * Mac OS X: in version 10.0 and later
  199. }
  200. function FormatRecToString(const (*var*) myCanonical: NumFormatString; const (*var*) partsTable: NumberParts; var outString: Str255; var positions: TripleInt): FormatStatus; external name '_FormatRecToString';
  201. {$ifc OLDROUTINENAMES}
  202. {$endc} {OLDROUTINENAMES}
  203. {$ALIGN MAC68K}
  204. end.