home *** CD-ROM | disk | FTP | other *** search
/ AppleScript - The Beta Release / AppleScript - The Beta Release.iso / Documentation / develop / Apple Event Objects and You / Apple Event Objects (code) / string_util.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-08  |  2.0 KB  |  63 lines  |  [TEXT/KAHL]

  1. #include <string.h>
  2. #include "ScriptScrap.h"
  3. #include "Prototypes.h"
  4.  
  5.  
  6. /*****************************************************************/
  7. /*   P S T R I N G   T O   T E X T   -   convert a Pascal-style
  8. /*                                          string into a handle to a
  9. /*                                         block of text.
  10. /*****************************************************************/
  11. void PstringToText(const char *pstring, Handle *textBlock)
  12. {
  13.     *textBlock = NewHandle(pstring[0]);
  14.     if (*textBlock != NULL)
  15.         BlockMove(&(pstring[1]), **textBlock, (long)(pstring[0]));
  16. } /* PstringToText */
  17.  
  18.  
  19. /*****************************************************************/
  20. /*   C S T R I N G   T O   T E X T   -   convert a C-style
  21. /*                                          string into a handle to a
  22. /*                                         block of text.
  23. /*****************************************************************/
  24. void CstringToText(const char *cstring, Handle *textBlock)
  25. {
  26.     long    numBytes = strlen(cstring);
  27.  
  28.     *textBlock = NewHandle(numBytes);
  29.     if (*textBlock != NULL)
  30.         BlockMove(cstring, **textBlock, numBytes);
  31. } /* CstringToText */
  32.  
  33.  
  34. /*****************************************************************/
  35. /*   T E X T   T O   P S T R I N G  -   convert a handle to a
  36. /*                                         block of text into a
  37. /*                                        Pascal-style string.
  38. /*****************************************************************/
  39. void TextToPstring(const Handle textBlock, char *pstring)
  40. {
  41.     long numBytes = GetHandleSize(textBlock);
  42.  
  43.     if (numBytes > 255) numBytes = 255;
  44.     pstring[0] = (char)numBytes;
  45.     BlockMove(*textBlock, &(pstring[1]), numBytes);
  46. } /* TextToPstring */
  47.  
  48.  
  49. /*****************************************************************/
  50. /*   T E X T   T O   C S T R I N G  -   convert a handle to a
  51. /*                                         block of text into a
  52. /*                                        C-style string.
  53. /*****************************************************************/
  54. void TextToCstring(const Handle textBlock, char *cstring)
  55. {
  56.     long numBytes = GetHandleSize(textBlock);
  57.  
  58.     if (numBytes > 255) numBytes = 255;
  59.     BlockMove(*textBlock, cstring, numBytes);
  60.     cstring[numBytes] = '\0';
  61. } /* TextToCstring */
  62.  
  63.