Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

680 lines
17 KiB

  1. /*
  2. File: TextUtils.h
  3. Contains: Text Utilities Interfaces.
  4. Version: QuickTime 7.3
  5. Copyright: (c) 2007 (c) 1985-2001 by Apple Computer, Inc., all rights reserved.
  6. Bugs?: For bug reports, consult the following page on
  7. the World Wide Web:
  8. http://developer.apple.com/bugreporter/
  9. */
  10. #ifndef __TEXTUTILS__
  11. #define __TEXTUTILS__
  12. #ifndef __MACTYPES__
  13. #include <MacTypes.h>
  14. #endif
  15. #ifndef __NUMBERFORMATTING__
  16. #include <NumberFormatting.h>
  17. #endif
  18. #ifndef __STRINGCOMPARE__
  19. #include <StringCompare.h>
  20. #endif
  21. #ifndef __DATETIMEUTILS__
  22. #include <DateTimeUtils.h>
  23. #endif
  24. #if PRAGMA_ONCE
  25. #pragma once
  26. #endif
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. #if PRAGMA_IMPORT
  31. #pragma import on
  32. #endif
  33. #if PRAGMA_STRUCT_ALIGN
  34. #pragma options align=mac68k
  35. #elif PRAGMA_STRUCT_PACKPUSH
  36. #pragma pack(push, 2)
  37. #elif PRAGMA_STRUCT_PACK
  38. #pragma pack(2)
  39. #endif
  40. /*
  41. Here are the current System 7 routine names and the translations to the older forms.
  42. Please use the newer forms in all new code and migrate the older names out of existing
  43. code as maintainance permits.
  44. NEW NAME OLD NAMEs OBSOLETE FORM (no script code)
  45. FindScriptRun
  46. FindWordBreaks NFindWord, FindWord
  47. GetIndString
  48. GetString
  49. Munger
  50. NewString
  51. SetString
  52. StyledLineBreak
  53. TruncString
  54. TruncText
  55. UpperString ($A054) UprString, UprText
  56. UppercaseText SCUpperText (a only) UpperText ($A456)
  57. LowercaseText LwrString, LowerText, LwrText ($A056)
  58. StripDiacritics StripText ($A256)
  59. UppercaseStripDiacritics StripUpperText ($A656)
  60. */
  61. /* TruncCode, StyledLineBreakCode, and truncation constants moved to QuickDrawText.i */
  62. struct ScriptRunStatus {
  63. SInt8 script;
  64. SInt8 runVariant;
  65. };
  66. typedef struct ScriptRunStatus ScriptRunStatus;
  67. struct BreakTable {
  68. char charTypes[256];
  69. short tripleLength;
  70. short triples[1];
  71. };
  72. typedef struct BreakTable BreakTable;
  73. typedef BreakTable * BreakTablePtr;
  74. struct NBreakTable {
  75. SInt8 flags1;
  76. SInt8 flags2;
  77. short version;
  78. short classTableOff;
  79. short auxCTableOff;
  80. short backwdTableOff;
  81. short forwdTableOff;
  82. short doBackup;
  83. short length; /* length of NBreakTable */
  84. char charTypes[256];
  85. short tables[1];
  86. };
  87. typedef struct NBreakTable NBreakTable;
  88. typedef NBreakTable * NBreakTablePtr;
  89. /* The following functions are new names that work on 68k and PowerPC*/
  90. /*
  91. * Munger()
  92. *
  93. * Availability:
  94. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  95. * CarbonLib: in CarbonLib 1.0 and later
  96. * Mac OS X: in version 10.0 and later
  97. */
  98. EXTERN_API( long )
  99. Munger(
  100. Handle h,
  101. long offset,
  102. const void * ptr1,
  103. long len1,
  104. const void * ptr2,
  105. long len2) ONEWORDINLINE(0xA9E0);
  106. /*
  107. * NewString()
  108. *
  109. * Availability:
  110. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  111. * CarbonLib: in CarbonLib 1.0 and later
  112. * Mac OS X: in version 10.0 and later
  113. */
  114. EXTERN_API( StringHandle )
  115. NewString(ConstStr255Param theString) ONEWORDINLINE(0xA906);
  116. /*
  117. * SetString()
  118. *
  119. * Availability:
  120. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  121. * CarbonLib: in CarbonLib 1.0 and later
  122. * Mac OS X: in version 10.0 and later
  123. */
  124. EXTERN_API( void )
  125. SetString(
  126. StringHandle theString,
  127. ConstStr255Param strNew) ONEWORDINLINE(0xA907);
  128. /*
  129. * GetString()
  130. *
  131. * Availability:
  132. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  133. * CarbonLib: in CarbonLib 1.0 and later
  134. * Mac OS X: in version 10.0 and later
  135. */
  136. EXTERN_API( StringHandle )
  137. GetString(short stringID) ONEWORDINLINE(0xA9BA);
  138. /*
  139. * GetIndString()
  140. *
  141. * Availability:
  142. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  143. * CarbonLib: in CarbonLib 1.0 and later
  144. * Mac OS X: in version 10.0 and later
  145. */
  146. EXTERN_API( void )
  147. GetIndString(
  148. Str255 theString,
  149. short strListID,
  150. short index);
  151. #if CALL_NOT_IN_CARBON
  152. /*
  153. * setstring()
  154. *
  155. * Availability:
  156. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  157. * CarbonLib: not available
  158. * Mac OS X: not available
  159. */
  160. EXTERN_API_C( void )
  161. setstring(
  162. StringHandle theString,
  163. const char * strNew);
  164. /*
  165. * newstring()
  166. *
  167. * Availability:
  168. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  169. * CarbonLib: not available
  170. * Mac OS X: not available
  171. */
  172. EXTERN_API_C( StringHandle )
  173. newstring(const char * theString);
  174. /*
  175. * getindstring()
  176. *
  177. * Availability:
  178. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  179. * CarbonLib: not available
  180. * Mac OS X: not available
  181. */
  182. EXTERN_API_C( void )
  183. getindstring(
  184. char * theString,
  185. short strListID,
  186. short index);
  187. #endif /* CALL_NOT_IN_CARBON */
  188. /*
  189. * FindWordBreaks()
  190. *
  191. * Availability:
  192. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  193. * CarbonLib: in CarbonLib 1.0 and later
  194. * Mac OS X: in version 10.0 and later
  195. */
  196. EXTERN_API( void )
  197. FindWordBreaks(
  198. Ptr textPtr,
  199. short textLength,
  200. short offset,
  201. Boolean leadingEdge,
  202. BreakTablePtr breaks,
  203. OffsetTable offsets,
  204. ScriptCode script) FOURWORDINLINE(0x2F3C, 0xC012, 0x001A, 0xA8B5);
  205. /*
  206. * LowercaseText()
  207. *
  208. * Availability:
  209. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  210. * CarbonLib: in CarbonLib 1.0 and later
  211. * Mac OS X: in version 10.0 and later
  212. */
  213. EXTERN_API( void )
  214. LowercaseText(
  215. Ptr textPtr,
  216. short len,
  217. ScriptCode script) SIXWORDINLINE(0x3F3C, 0x0000, 0x2F3C, 0x800A, 0xFFB6, 0xA8B5);
  218. /*
  219. * UppercaseText()
  220. *
  221. * Availability:
  222. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  223. * CarbonLib: in CarbonLib 1.0 and later
  224. * Mac OS X: in version 10.0 and later
  225. */
  226. EXTERN_API( void )
  227. UppercaseText(
  228. Ptr textPtr,
  229. short len,
  230. ScriptCode script) SIXWORDINLINE(0x3F3C, 0x0400, 0x2F3C, 0x800A, 0xFFB6, 0xA8B5);
  231. /*
  232. * StripDiacritics()
  233. *
  234. * Availability:
  235. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  236. * CarbonLib: in CarbonLib 1.0 and later
  237. * Mac OS X: in version 10.0 and later
  238. */
  239. EXTERN_API( void )
  240. StripDiacritics(
  241. Ptr textPtr,
  242. short len,
  243. ScriptCode script) SIXWORDINLINE(0x3F3C, 0x0200, 0x2F3C, 0x800A, 0xFFB6, 0xA8B5);
  244. /*
  245. * UppercaseStripDiacritics()
  246. *
  247. * Availability:
  248. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  249. * CarbonLib: in CarbonLib 1.0 and later
  250. * Mac OS X: in version 10.0 and later
  251. */
  252. EXTERN_API( void )
  253. UppercaseStripDiacritics(
  254. Ptr textPtr,
  255. short len,
  256. ScriptCode script) SIXWORDINLINE(0x3F3C, 0x0600, 0x2F3C, 0x800A, 0xFFB6, 0xA8B5);
  257. /*
  258. * FindScriptRun()
  259. *
  260. * Availability:
  261. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  262. * CarbonLib: in CarbonLib 1.0 and later
  263. * Mac OS X: in version 10.0 and later
  264. */
  265. EXTERN_API( ScriptRunStatus )
  266. FindScriptRun(
  267. Ptr textPtr,
  268. long textLen,
  269. long * lenUsed) FOURWORDINLINE(0x2F3C, 0x820C, 0x0026, 0xA8B5);
  270. /*
  271. The following functions are old names, but are required for PowerPC builds
  272. because InterfaceLib exports these names, instead of the new ones.
  273. */
  274. #if CALL_NOT_IN_CARBON
  275. /*
  276. * FindWord()
  277. *
  278. * Availability:
  279. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  280. * CarbonLib: not available
  281. * Mac OS X: not available
  282. */
  283. EXTERN_API( void )
  284. FindWord(
  285. Ptr textPtr,
  286. short textLength,
  287. short offset,
  288. Boolean leadingEdge,
  289. BreakTablePtr breaks,
  290. OffsetTable offsets) FOURWORDINLINE(0x2F3C, 0x8012, 0x001A, 0xA8B5);
  291. /*
  292. * NFindWord()
  293. *
  294. * Availability:
  295. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  296. * CarbonLib: not available
  297. * Mac OS X: not available
  298. */
  299. EXTERN_API( void )
  300. NFindWord(
  301. Ptr textPtr,
  302. short textLength,
  303. short offset,
  304. Boolean leadingEdge,
  305. NBreakTablePtr nbreaks,
  306. OffsetTable offsets) FOURWORDINLINE(0x2F3C, 0x8012, 0xFFE2, 0xA8B5);
  307. /*
  308. On 68K machines, LwrText, LowerText, StripText, UpperText and StripUpperText
  309. return an error code in register D0, but System 7 PowerMacs do not emulate
  310. this properly, so checking D0 is unreliable.
  311. */
  312. /*
  313. * LwrText()
  314. *
  315. * Availability:
  316. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  317. * CarbonLib: not available
  318. * Mac OS X: not available
  319. */
  320. #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  321. #pragma parameter LwrText(__A0, __D0)
  322. #endif
  323. EXTERN_API( void )
  324. LwrText(
  325. Ptr textPtr,
  326. short len) ONEWORDINLINE(0xA056);
  327. /*
  328. * LowerText()
  329. *
  330. * Availability:
  331. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  332. * CarbonLib: not available
  333. * Mac OS X: not available
  334. */
  335. #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  336. #pragma parameter LowerText(__A0, __D0)
  337. #endif
  338. EXTERN_API( void )
  339. LowerText(
  340. Ptr textPtr,
  341. short len) ONEWORDINLINE(0xA056);
  342. /*
  343. * StripText()
  344. *
  345. * Availability:
  346. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  347. * CarbonLib: not available
  348. * Mac OS X: not available
  349. */
  350. #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  351. #pragma parameter StripText(__A0, __D0)
  352. #endif
  353. EXTERN_API( void )
  354. StripText(
  355. Ptr textPtr,
  356. short len) ONEWORDINLINE(0xA256);
  357. /*
  358. * UpperText()
  359. *
  360. * Availability:
  361. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  362. * CarbonLib: not available
  363. * Mac OS X: not available
  364. */
  365. #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  366. #pragma parameter UpperText(__A0, __D0)
  367. #endif
  368. EXTERN_API( void )
  369. UpperText(
  370. Ptr textPtr,
  371. short len) ONEWORDINLINE(0xA456);
  372. /*
  373. * StripUpperText()
  374. *
  375. * Availability:
  376. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  377. * CarbonLib: not available
  378. * Mac OS X: not available
  379. */
  380. #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  381. #pragma parameter StripUpperText(__A0, __D0)
  382. #endif
  383. EXTERN_API( void )
  384. StripUpperText(
  385. Ptr textPtr,
  386. short len) ONEWORDINLINE(0xA656);
  387. /* The following are new names which are exported by InterfaceLib*/
  388. #endif /* CALL_NOT_IN_CARBON */
  389. /*
  390. * UpperString()
  391. *
  392. * Availability:
  393. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  394. * CarbonLib: in CarbonLib 1.0 and later
  395. * Mac OS X: in version 10.0 and later
  396. */
  397. EXTERN_API( void )
  398. UpperString(
  399. Str255 theString,
  400. Boolean diacSensitive);
  401. /*
  402. * upperstring()
  403. *
  404. * Availability:
  405. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  406. * CarbonLib: in CarbonLib 1.0 and later
  407. * Mac OS X: in version 10.0 and later
  408. */
  409. EXTERN_API_C( void )
  410. upperstring(
  411. char * theString,
  412. Boolean diacSensitive);
  413. /* The following are macros which map old names to the names exported by InterfaceLib*/
  414. #if OLDROUTINENAMES
  415. #define UprString(theString, diacSensitive) \
  416. UpperString(theString, diacSensitive)
  417. #endif /* OLDROUTINENAMES */
  418. /* Old routine name but no new names are mapped to it:*/
  419. #if CALL_NOT_IN_CARBON
  420. /*
  421. * UprText()
  422. *
  423. * Availability:
  424. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  425. * CarbonLib: not available
  426. * Mac OS X: not available
  427. */
  428. #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  429. #pragma parameter UprText(__A0, __D0)
  430. #endif
  431. EXTERN_API( void )
  432. UprText(
  433. Ptr textPtr,
  434. short len) ONEWORDINLINE(0xA054);
  435. #endif /* CALL_NOT_IN_CARBON */
  436. /*
  437. Functions for converting between C and Pascal Strings
  438. (Previously in Strings.h)
  439. Note: CopyPascalStringToC, CopyCStringToPascal, c2pstrcpy, and p2cstrcpy
  440. are written to allow inplace conversion. That is, the src and dst
  441. parameters can point to the memory location. These functions
  442. are available in CarbonLib and CarbonAccessors.o.
  443. Note: c2pstr, C2PStr, p2cstr, and P2CStr are all deprecated. These functions
  444. only do inplace conversion and often require casts to call them. This can
  445. cause bugs because you can easily cast away a const and change the
  446. contents of a read-only buffer. These functions are available
  447. in InterfaceLib, or when building for Carbon if you #define OLDP2C,
  448. then they are available as a macro.
  449. */
  450. /*
  451. * c2pstrcpy()
  452. *
  453. * Availability:
  454. * Non-Carbon CFM: in CarbonAccessors.o 1.0.2 and later
  455. * CarbonLib: in CarbonLib 1.0 and later
  456. * Mac OS X: in version 10.0 and later
  457. */
  458. EXTERN_API_C( void )
  459. c2pstrcpy(
  460. Str255 dst,
  461. const char * src);
  462. /*
  463. * p2cstrcpy()
  464. *
  465. * Availability:
  466. * Non-Carbon CFM: in CarbonAccessors.o 1.0.2 and later
  467. * CarbonLib: in CarbonLib 1.0 and later
  468. * Mac OS X: in version 10.0 and later
  469. */
  470. EXTERN_API_C( void )
  471. p2cstrcpy(
  472. char * dst,
  473. ConstStr255Param src);
  474. /*
  475. * CopyPascalStringToC()
  476. *
  477. * Availability:
  478. * Non-Carbon CFM: in CarbonAccessors.o 1.0.2 and later
  479. * CarbonLib: in CarbonLib 1.0 and later
  480. * Mac OS X: in version 10.0 and later
  481. */
  482. EXTERN_API_C( void )
  483. CopyPascalStringToC(
  484. ConstStr255Param src,
  485. char * dst);
  486. /*
  487. * CopyCStringToPascal()
  488. *
  489. * Availability:
  490. * Non-Carbon CFM: in CarbonAccessors.o 1.0.2 and later
  491. * CarbonLib: in CarbonLib 1.0 and later
  492. * Mac OS X: in version 10.0 and later
  493. */
  494. EXTERN_API_C( void )
  495. CopyCStringToPascal(
  496. const char * src,
  497. Str255 dst);
  498. #if CALL_NOT_IN_CARBON
  499. /*
  500. * c2pstr()
  501. *
  502. * Availability:
  503. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  504. * CarbonLib: not available
  505. * Mac OS X: not available
  506. */
  507. EXTERN_API_C( StringPtr )
  508. c2pstr(char * aStr);
  509. /*
  510. * C2PStr()
  511. *
  512. * Availability:
  513. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  514. * CarbonLib: not available
  515. * Mac OS X: not available
  516. */
  517. EXTERN_API( StringPtr )
  518. C2PStr(Ptr cString);
  519. /*
  520. * p2cstr()
  521. *
  522. * Availability:
  523. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  524. * CarbonLib: not available
  525. * Mac OS X: not available
  526. */
  527. EXTERN_API_C( char * )
  528. p2cstr(StringPtr aStr);
  529. /*
  530. * P2CStr()
  531. *
  532. * Availability:
  533. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  534. * CarbonLib: not available
  535. * Mac OS X: not available
  536. */
  537. EXTERN_API( Ptr )
  538. P2CStr(StringPtr pString);
  539. #endif /* CALL_NOT_IN_CARBON */
  540. #if !TARGET_OS_MAC
  541. /* Added for QuickTime 3.0 */
  542. #define C2PStr(a) (StringPtr)c2pstr((Ptr)(a))
  543. #define P2CStr(a) (Ptr)p2cstr(a)
  544. #define CopyPascalStringToC(src,dst) p2cstrcpy(dst,src)
  545. #define CopyCStringToPascal(src,dst) c2pstrcpy(dst,src)
  546. #endif
  547. #if TARGET_OS_MAC && TARGET_API_MAC_CARBON && OLDP2C
  548. /* macros to help source code that uses deprecated inplace */
  549. /* conversion routines to compiler for carbon */
  550. #define p2cstr(aStr) (p2cstrcpy((char *) aStr, aStr) , (char *) aStr)
  551. #define c2pstr(aStr) (c2pstrcpy((StringPtr)aStr, aStr) , (StringPtr) aStr)
  552. #define C2PStr(a) (StringPtr)c2pstr((Ptr)(a))
  553. #define P2CStr(a) (Ptr)p2cstr(a)
  554. #endif
  555. #if PRAGMA_STRUCT_ALIGN
  556. #pragma options align=reset
  557. #elif PRAGMA_STRUCT_PACKPUSH
  558. #pragma pack(pop)
  559. #elif PRAGMA_STRUCT_PACK
  560. #pragma pack()
  561. #endif
  562. #ifdef PRAGMA_IMPORT_OFF
  563. #pragma import off
  564. #elif PRAGMA_IMPORT
  565. #pragma import reset
  566. #endif
  567. #ifdef __cplusplus
  568. }
  569. #endif
  570. #endif /* __TEXTUTILS__ */