home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Interfaces&Libraries / Universal / Interfaces / CIncludes / TextUtils.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-17  |  10.7 KB  |  395 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        TextUtils.h
  3.  
  4.      Contains:    Text Utilities Interfaces.
  5.  
  6.      Version:    Technology:    System 7.5+
  7.                  Release:    Universal Interfaces 3.2
  8.  
  9.      Copyright:    © 1985-1998 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __TEXTUTILS__
  18. #define __TEXTUTILS__
  19.  
  20. #ifndef __MACTYPES__
  21. #include <MacTypes.h>
  22. #endif
  23. #ifndef __NUMBERFORMATTING__
  24. #include <NumberFormatting.h>
  25. #endif
  26. #ifndef __STRINGCOMPARE__
  27. #include <StringCompare.h>
  28. #endif
  29. #ifndef __DATETIMEUTILS__
  30. #include <DateTimeUtils.h>
  31. #endif
  32.  
  33.  
  34.  
  35. #if PRAGMA_ONCE
  36. #pragma once
  37. #endif
  38.  
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42.  
  43. #if PRAGMA_IMPORT
  44. #pragma import on
  45. #endif
  46.  
  47. #if PRAGMA_STRUCT_ALIGN
  48.     #pragma options align=mac68k
  49. #elif PRAGMA_STRUCT_PACKPUSH
  50.     #pragma pack(push, 2)
  51. #elif PRAGMA_STRUCT_PACK
  52.     #pragma pack(2)
  53. #endif
  54.  
  55. /*
  56.  
  57.     Here are the current System 7 routine names and the translations to the older forms.
  58.     Please use the newer forms in all new code and migrate the older names out of existing
  59.     code as maintainance permits.
  60.     
  61.     NEW NAME                    OLD NAMEs                    OBSOLETE FORM (no script code)
  62.  
  63.     FindScriptRun
  64.     FindWordBreaks                                            NFindWord, FindWord
  65.     GetIndString            
  66.     GetString
  67.     Munger
  68.     NewString                
  69.     SetString                
  70.     StyledLineBreak
  71.     TruncString
  72.     TruncText
  73.  
  74.     UpperString ($A054)            UprString, UprText
  75.     UppercaseText                SCUpperText (a only)        UpperText ($A456)
  76.     LowercaseText                                            LwrString, LowerText, LwrText ($A056)
  77.     StripDiacritics                                            StripText ($A256)
  78.     UppercaseStripDiacritics                                StripUpperText ($A656)
  79.  
  80.  
  81. */
  82.  
  83. /* Type for truncWhere parameter in TruncString, TruncText */
  84. typedef short                             TruncCode;
  85.  
  86. enum {
  87.                                                                 /* Constants for truncWhere argument in TruncString and TruncText */
  88.     truncEnd                    = 0,                            /* Truncate at end */
  89.     truncMiddle                    = 0x4000,                        /* Truncate in middle */
  90.     smTruncEnd                    = 0,                            /* Truncate at end - obsolete */
  91.     smTruncMiddle                = 0x4000                        /* Truncate in middle - obsolete */
  92. };
  93.  
  94.  
  95. enum {
  96.                                                                 /* Constants for TruncString and TruncText results */
  97.     notTruncated                = 0,                            /* No truncation was necessary */
  98.     truncated                    = 1,                            /* Truncation performed */
  99.     truncErr                    = -1,                            /* General error */
  100.     smNotTruncated                = 0,                            /* No truncation was necessary - obsolete */
  101.     smTruncated                    = 1,                            /* Truncation performed    - obsolete */
  102.     smTruncErr                    = -1                            /* General error - obsolete */
  103. };
  104.  
  105. typedef SInt8                             StyledLineBreakCode;
  106.  
  107. enum {
  108.     smBreakWord                    = 0,
  109.     smBreakChar                    = 1,
  110.     smBreakOverflow                = 2
  111. };
  112.  
  113.  
  114. struct ScriptRunStatus {
  115.     SInt8                             script;
  116.     SInt8                             runVariant;
  117. };
  118. typedef struct ScriptRunStatus            ScriptRunStatus;
  119.  
  120. struct BreakTable {
  121.     char                             charTypes[256];
  122.     short                             tripleLength;
  123.     short                             triples[1];
  124. };
  125. typedef struct BreakTable                BreakTable;
  126. typedef BreakTable *                    BreakTablePtr;
  127.  
  128. struct NBreakTable {
  129.     SInt8                             flags1;
  130.     SInt8                             flags2;
  131.     short                             version;
  132.     short                             classTableOff;
  133.     short                             auxCTableOff;
  134.     short                             backwdTableOff;
  135.     short                             forwdTableOff;
  136.     short                             doBackup;
  137.     short                             length;                        /* length of NBreakTable */
  138.     char                             charTypes[256];
  139.     short                             tables[1];
  140. };
  141. typedef struct NBreakTable                NBreakTable;
  142. typedef NBreakTable *                    NBreakTablePtr;
  143. /* The following functions are new names that work on 68k and PowerPC*/
  144. EXTERN_API( long )
  145. Munger                            (Handle                 h,
  146.                                  long                     offset,
  147.                                  const void *            ptr1,
  148.                                  long                     len1,
  149.                                  const void *            ptr2,
  150.                                  long                     len2)                                ONEWORDINLINE(0xA9E0);
  151.  
  152. EXTERN_API( StringHandle )
  153. NewString                        (ConstStr255Param         theString)                            ONEWORDINLINE(0xA906);
  154.  
  155. EXTERN_API( void )
  156. SetString                        (StringHandle             theString,
  157.                                  ConstStr255Param         strNew)                                ONEWORDINLINE(0xA907);
  158.  
  159. EXTERN_API( StringHandle )
  160. GetString                        (short                     stringID)                            ONEWORDINLINE(0xA9BA);
  161.  
  162. EXTERN_API( void )
  163. GetIndString                    (Str255                 theString,
  164.                                  short                     strListID,
  165.                                  short                     index);
  166.  
  167. #if CGLUESUPPORTED
  168. EXTERN_API_C( void )
  169. setstring                        (StringHandle             theString,
  170.                                  const char *            strNew);
  171.  
  172. EXTERN_API_C( StringHandle )
  173. newstring                        (const char *            theString);
  174.  
  175. EXTERN_API_C( void )
  176. getindstring                    (char *                    theString,
  177.                                  short                     strListID,
  178.                                  short                     index);
  179.  
  180. #endif  /* CGLUESUPPORTED */
  181.  
  182. EXTERN_API( StyledLineBreakCode )
  183. StyledLineBreak                    (Ptr                     textPtr,
  184.                                  long                     textLen,
  185.                                  long                     textStart,
  186.                                  long                     textEnd,
  187.                                  long                     flags,
  188.                                  Fixed *                textWidth,
  189.                                  long *                    textOffset)                            FOURWORDINLINE(0x2F3C, 0x821C, 0xFFFE, 0xA8B5);
  190.  
  191. EXTERN_API( short )
  192. TruncString                        (short                     width,
  193.                                  Str255                 theString,
  194.                                  TruncCode                 truncWhere)                            FOURWORDINLINE(0x2F3C, 0x8208, 0xFFE0, 0xA8B5);
  195.  
  196. EXTERN_API( short )
  197. TruncText                        (short                     width,
  198.                                  Ptr                     textPtr,
  199.                                  short *                length,
  200.                                  TruncCode                 truncWhere)                            FOURWORDINLINE(0x2F3C, 0x820C, 0xFFDE, 0xA8B5);
  201.  
  202. EXTERN_API( void )
  203. FindWordBreaks                    (Ptr                     textPtr,
  204.                                  short                     textLength,
  205.                                  short                     offset,
  206.                                  Boolean                 leadingEdge,
  207.                                  BreakTablePtr             breaks,
  208.                                  OffsetTable             offsets,
  209.                                  ScriptCode             script)                                FOURWORDINLINE(0x2F3C, 0xC012, 0x001A, 0xA8B5);
  210.  
  211. EXTERN_API( void )
  212. LowercaseText                    (Ptr                     textPtr,
  213.                                  short                     len,
  214.                                  ScriptCode             script)                                SIXWORDINLINE(0x3F3C, 0x0000, 0x2F3C, 0x800A, 0xFFB6, 0xA8B5);
  215.  
  216. EXTERN_API( void )
  217. UppercaseText                    (Ptr                     textPtr,
  218.                                  short                     len,
  219.                                  ScriptCode             script)                                SIXWORDINLINE(0x3F3C, 0x0400, 0x2F3C, 0x800A, 0xFFB6, 0xA8B5);
  220.  
  221. EXTERN_API( void )
  222. StripDiacritics                    (Ptr                     textPtr,
  223.                                  short                     len,
  224.                                  ScriptCode             script)                                SIXWORDINLINE(0x3F3C, 0x0200, 0x2F3C, 0x800A, 0xFFB6, 0xA8B5);
  225.  
  226. EXTERN_API( void )
  227. UppercaseStripDiacritics        (Ptr                     textPtr,
  228.                                  short                     len,
  229.                                  ScriptCode             script)                                SIXWORDINLINE(0x3F3C, 0x0600, 0x2F3C, 0x800A, 0xFFB6, 0xA8B5);
  230.  
  231. EXTERN_API( ScriptRunStatus )
  232. FindScriptRun                    (Ptr                     textPtr,
  233.                                  long                     textLen,
  234.                                  long *                    lenUsed)                            FOURWORDINLINE(0x2F3C, 0x820C, 0x0026, 0xA8B5);
  235.  
  236. /*
  237.       The following functions are old names, but are required for PowerPC builds
  238.       because InterfaceLib exports these names, instead of the new ones.
  239. */
  240.  
  241. EXTERN_API( void )
  242. FindWord                        (Ptr                     textPtr,
  243.                                  short                     textLength,
  244.                                  short                     offset,
  245.                                  Boolean                 leadingEdge,
  246.                                  BreakTablePtr             breaks,
  247.                                  OffsetTable             offsets)                            FOURWORDINLINE(0x2F3C, 0x8012, 0x001A, 0xA8B5);
  248.  
  249. EXTERN_API( void )
  250. NFindWord                        (Ptr                     textPtr,
  251.                                  short                     textLength,
  252.                                  short                     offset,
  253.                                  Boolean                 leadingEdge,
  254.                                  NBreakTablePtr         nbreaks,
  255.                                  OffsetTable             offsets)                            FOURWORDINLINE(0x2F3C, 0x8012, 0xFFE2, 0xA8B5);
  256.  
  257. /*
  258.    On 68K machines, LwrText, LowerText, StripText, UpperText and StripUpperText
  259.    return an error code in register D0, but System 7 PowerMacs do not emulate
  260.    this properly, so checking D0 is unreliable.
  261. */
  262.  
  263.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  264.                                                                                             #pragma parameter LwrText(__A0, __D0)
  265.                                                                                             #endif
  266. EXTERN_API( void )
  267. LwrText                            (Ptr                     textPtr,
  268.                                  short                     len)                                ONEWORDINLINE(0xA056);
  269.  
  270.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  271.                                                                                             #pragma parameter LowerText(__A0, __D0)
  272.                                                                                             #endif
  273. EXTERN_API( void )
  274. LowerText                        (Ptr                     textPtr,
  275.                                  short                     len)                                ONEWORDINLINE(0xA056);
  276.  
  277.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  278.                                                                                             #pragma parameter StripText(__A0, __D0)
  279.                                                                                             #endif
  280. EXTERN_API( void )
  281. StripText                        (Ptr                     textPtr,
  282.                                  short                     len)                                ONEWORDINLINE(0xA256);
  283.  
  284.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  285.                                                                                             #pragma parameter UpperText(__A0, __D0)
  286.                                                                                             #endif
  287. EXTERN_API( void )
  288. UpperText                        (Ptr                     textPtr,
  289.                                  short                     len)                                ONEWORDINLINE(0xA456);
  290.  
  291.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  292.                                                                                             #pragma parameter StripUpperText(__A0, __D0)
  293.                                                                                             #endif
  294. EXTERN_API( void )
  295. StripUpperText                    (Ptr                     textPtr,
  296.                                  short                     len)                                ONEWORDINLINE(0xA656);
  297.  
  298.  
  299. /* The following are new names which are exported by InterfaceLib*/
  300.  
  301. EXTERN_API( void )
  302. UpperString                        (Str255                 theString,
  303.                                  Boolean                 diacSensitive);
  304.  
  305. #if CGLUESUPPORTED
  306. EXTERN_API_C( void )
  307. upperstring                        (char *                    theString,
  308.                                  Boolean                 diacSensitive);
  309.  
  310. #endif  /* CGLUESUPPORTED */
  311.  
  312. /* The following are macros which map old names to the names exported by InterfaceLib*/
  313. #if OLDROUTINENAMES
  314. #define UprString(theString, diacSensitive)  \
  315.          UpperString(theString, diacSensitive)
  316. #if CGLUESUPPORTED
  317. #define uprstring(theString, diacSensitive) upperstring(theString, diacSensitive)
  318. #endif  /* CGLUESUPPORTED */
  319.  
  320. #endif  /* OLDROUTINENAMES */
  321.  
  322. /* Old routine name but no new names are mapped to it:*/
  323.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  324.                                                                                             #pragma parameter UprText(__A0, __D0)
  325.                                                                                             #endif
  326. EXTERN_API( void )
  327. UprText                            (Ptr                     textPtr,
  328.                                  short                     len)                                ONEWORDINLINE(0xA054);
  329.  
  330. /*
  331.  
  332.     Functions for converting between C and Pascal Strings
  333.     (Previously in Strings.h)
  334.     
  335. */
  336. EXTERN_API_C( StringPtr )
  337. c2pstr                            (char *                    aStr);
  338.  
  339. EXTERN_API( StringPtr )
  340. C2PStr                            (Ptr                     cString);
  341.  
  342. EXTERN_API_C( char *)
  343. p2cstr                            (StringPtr                 aStr);
  344.  
  345. EXTERN_API( Ptr )
  346. P2CStr                            (StringPtr                 pString);
  347.  
  348. EXTERN_API_C( void )
  349. c2pstrcpy                        (Str255                 dst,
  350.                                  const char *            src);
  351.  
  352. EXTERN_API_C( void )
  353. p2cstrcpy                        (char *                    dst,
  354.                                  ConstStr255Param         src);
  355.  
  356. EXTERN_API_C( void )
  357. CopyPascalStringToC                (ConstStr255Param         src,
  358.                                  char *                    dst);
  359.  
  360. EXTERN_API_C( void )
  361. CopyCStringToPascal                (const char *            src,
  362.                                  Str255                 dst);
  363.  
  364.  
  365. #if !TARGET_OS_MAC
  366.     /* Added for QuickTime 3.0 */
  367.     #define C2PStr(a)        (StringPtr)c2pstr((Ptr)(a))
  368.     #define P2CStr(a)        (Ptr)p2cstr(a)
  369.  
  370.     #define CopyPascalStringToC(src,dst) p2cstrcpy(dst,src)
  371.     #define CopyCStringToPascal(src,dst) c2pstrcpy(dst,src)
  372. #endif
  373.  
  374.  
  375. #if PRAGMA_STRUCT_ALIGN
  376.     #pragma options align=reset
  377. #elif PRAGMA_STRUCT_PACKPUSH
  378.     #pragma pack(pop)
  379. #elif PRAGMA_STRUCT_PACK
  380.     #pragma pack()
  381. #endif
  382.  
  383. #ifdef PRAGMA_IMPORT_OFF
  384. #pragma import off
  385. #elif PRAGMA_IMPORT
  386. #pragma import reset
  387. #endif
  388.  
  389. #ifdef __cplusplus
  390. }
  391. #endif
  392.  
  393. #endif /* __TEXTUTILS__ */
  394.  
  395.