home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / CodeWarrior Lite / Metrowerks C⁄C++ Lite / Libraries / MacOS 68K / MacOS Files / CGlue.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-12  |  27.0 KB  |  1,203 lines  |  [TEXT/MMCC]

  1. /*
  2.     File:        CGlue.c
  3.  
  4.     Contains:    Sources for C glue to toolbox routines.
  5.                 These functions use C calling conventions and need to be 
  6.                 recompiled for each compiler.  
  7.  
  8.     Written by:    Nick Kledzik
  9.  
  10.     Copyright:    © 1993-1994 by Apple Computer, Inc., all rights reserved.
  11.  
  12.     Change History (most recent first):
  13.  
  14.          <2>     8/28/94    ngk        Fix warning in SC.
  15.          <1>     8/28/94    ngk        Test C<->Pascal string routines.
  16.                                      Fix misuses of 'const'.
  17.          <0>      7/5/94    ngk        factored out from glue sources.
  18.  
  19. */ 
  20.  
  21.  
  22. #if __MWERKS__
  23. #pragma pointers_in_D0        //    required for c-style toolbox glue function: c2pstr and p2cstr
  24.                             //    the inverse operation (pointers_in_A0) is performed at the end ...
  25. #endif
  26.  
  27. //    Generate this as near code calls ...
  28. #pragma near_code
  29.  
  30. // were defining the C glue here, so we need to force it to be in the headers
  31. #define CGLUESUPPORTED 1
  32.  
  33. /*******************************  Strings ******************************/
  34.  
  35. #include <Strings.h>
  36.  
  37. char *p2cstr(StringPtr aStr)
  38. {
  39.     return (char *) P2CStr(aStr);
  40. }
  41.  
  42. StringPtr c2pstr(char *aStr)
  43. {
  44.      return C2PStr((Ptr)aStr);
  45. }
  46.  
  47. #include <Types.h>
  48.  
  49. //
  50. //    CopyPascalStringToC converts the source pascal string to a destination
  51. //    C string as it copies. 
  52. //
  53. static void CopyPascalStringToC(ConstStr255Param src, char* dst)
  54. {
  55.     if ( src != NULL )
  56.     {
  57.         short   length  = *src++;
  58.     
  59.         while ( length > 0 ) 
  60.         {
  61.             *dst++ = *(char*)src++;
  62.             --length;
  63.         }
  64.     }
  65.     *dst = '\0';
  66. }
  67.  
  68.  
  69. //
  70. //    CopyCStringToPascal converts the source C string to a destination
  71. //    pascal string as it copies. The dest string will
  72. //    be truncated to fit into an Str255 if necessary.
  73. //  If the C String pointer is NULL, the pascal string's length is set to zero
  74. //
  75. static void CopyCStringToPascal(const char* src, Str255 dst)
  76. {
  77.     short     length  = 0;
  78.     
  79.     // handle case of overlapping strings
  80.     if ( (void*)src == (void*)dst )
  81.     {
  82.         unsigned char*        curdst = &dst[1];
  83.         unsigned char        thisChar;
  84.                 
  85.         thisChar = *(const unsigned char*)src++;
  86.         while ( thisChar != '\0' ) 
  87.         {
  88.             unsigned char    nextChar;
  89.             
  90.             // use nextChar so we don't overwrite what we are about to read
  91.             nextChar = *(const unsigned char*)src++;
  92.             *curdst++ = thisChar;
  93.             thisChar = nextChar;
  94.             
  95.             if ( ++length >= 255 )
  96.                 break;
  97.         }
  98.     }
  99.     else if ( src != NULL )
  100.     {
  101.         unsigned char*        curdst = &dst[1];
  102.         short                 overflow = 255;        // count down so test it loop is faster
  103.         register char        temp;
  104.     
  105.         // Can't do the K&R C thing of “while (*s++ = *t++)” because it will copy trailing zero
  106.         // which might overrun pascal buffer.  Instead we use a temp variable.
  107.         while ( (temp = *src++) != 0 ) 
  108.         {
  109.             *(char*)curdst++ = temp;
  110.                 
  111.             if ( --overflow <= 0 )
  112.                 break;
  113.         }
  114.         length = 255 - overflow;
  115.     }
  116.     dst[0] = length;
  117. }
  118.  
  119.  
  120. //
  121. // StrLen is only used in this file and is not exported. It provides the
  122. //    same functionality of strlen in the standard C library, but we do not
  123. //    want to have to depend on the StdCLib for linking
  124. //
  125. static unsigned short StrLen(const char* str)
  126. {
  127.     unsigned short count = 0;
  128.     
  129.     while (*str++) count++;
  130.     return count;
  131. }
  132.  
  133.  
  134. /*******************************  Controls ****************************/
  135.  
  136. #include <Controls.h>
  137.  
  138.  
  139. ControlHandle newcontrol(WindowPtr theWindow, const Rect* boundsRect, const char* title,
  140.                          Boolean visible, short value, short min, short max, short procID, long refCon)
  141. {
  142.     Str255 pString;
  143.     
  144.     CopyCStringToPascal(title, pString);
  145.     return NewControl(theWindow, (Rect*)boundsRect, pString, 
  146.             visible, value, min, max, procID, refCon);
  147. }
  148.  
  149. void setcontroltitle(ControlHandle theControl, const char* title)
  150. {
  151.     Str255 pString;
  152.  
  153.     CopyCStringToPascal(title, pString);
  154.     SetControlTitle(theControl, pString);
  155. }
  156.  
  157. void getcontroltitle(ControlHandle theControl, char* title)
  158. {
  159.     Str255 pString;
  160.  
  161.     GetControlTitle(theControl, pString);
  162.     CopyPascalStringToC(pString, title);
  163. }
  164.  
  165. short testcontrol(ControlHandle theControl, Point *thePt)
  166. {
  167.     return TestControl(theControl, *thePt);
  168. }
  169.  
  170. short findcontrol(Point *thePoint, WindowPtr theWindow, ControlHandle *theControl)
  171. {
  172.     return FindControl(*thePoint, theWindow, theControl);
  173. }
  174.  
  175. short trackcontrol(ControlHandle theControl, Point *thePoint, ControlActionUPP action)
  176. {
  177.     return TrackControl(theControl, *thePoint, action);
  178. }
  179.  
  180. void dragcontrol(ControlHandle theControl, Point *startPt, const Rect* limitRect,
  181.                  const Rect* slopRect, short axis)
  182. {
  183.     DragControl(theControl, *startPt, limitRect, slopRect, axis);
  184. }
  185.  
  186.  
  187. /*******************************  Devices ****************************/
  188.  
  189. #include <Devices.h>
  190.  
  191. OSErr opendriver(const char* driverName, short *refNum)
  192. {
  193.     Str255 pString;
  194.  
  195.     CopyCStringToPascal(driverName, pString);
  196.     return OpenDriver(pString, refNum);
  197. }
  198.  
  199. short opendeskacc(const char* deskAccName)
  200. {
  201.     Str255 pString;
  202.     
  203.     CopyCStringToPascal(deskAccName, pString);
  204.     return OpenDeskAcc(pString);
  205. }
  206.  
  207.  
  208.  
  209. /*******************************  Dialogs ****************************/
  210.  
  211. #include <Dialogs.h>
  212.  
  213. DialogPtr newdialog(void *wStorage, const Rect *boundsRect, const char *title, Boolean visible,
  214.                      short procID, WindowPtr behind, Boolean goAwayFlag, long refCon, Handle itmLstHndl)
  215. {
  216.     Str255 pString;
  217.  
  218.     CopyCStringToPascal(title, pString);
  219.     return NewDialog(wStorage, boundsRect, pString, visible,
  220.             procID, behind, goAwayFlag, refCon, itmLstHndl);
  221. }
  222.  
  223. DialogPtr newcolordialog(void *dStorage, const Rect *boundsRect, const char* title,
  224.                          Boolean visible, short procID, WindowPtr behind, 
  225.                         Boolean goAwayFlag, long refCon, Handle items)
  226. {
  227.     Str255 pString;
  228.  
  229.     CopyCStringToPascal(title, pString);
  230.     return NewColorDialog(dStorage, boundsRect, pString, visible,
  231.             procID, behind, goAwayFlag, refCon, items);
  232. }
  233.  
  234. void paramtext(const char* param0, const char* param1, const char* param2, const char* param3)
  235. {
  236.     Str255 pString0, pString1, pString2, pString3;
  237.     
  238.     CopyCStringToPascal(param0, pString0);
  239.     CopyCStringToPascal(param1, pString1);
  240.     CopyCStringToPascal(param2, pString2);
  241.     CopyCStringToPascal(param3, pString3);
  242.     ParamText(pString0, pString1, pString2, pString3);
  243. }
  244.  
  245. void getdialogitemtext(Handle item, char *text)
  246. {
  247.     Str255 pString;
  248.  
  249.     GetDialogItemText(item, pString);
  250.     CopyPascalStringToC(pString, text);
  251. }
  252.  
  253. void setdialogitemtext(Handle item, const char* text)
  254. {
  255.     Str255 pString;
  256.  
  257.     CopyCStringToPascal(text, pString);
  258.     SetDialogItemText(item, pString);
  259. }
  260.  
  261. short finddialogitem(DialogPtr theDialog, Point *thePt)
  262. {
  263.     return FindDialogItem(theDialog, *thePt);
  264. }
  265.  
  266.  
  267. /*******************************  DiskInit ****************************/
  268.  
  269. #include <DiskInit.h>
  270.  
  271. OSErr dibadmount(Point *where, long evtMessage)
  272. {
  273.     return DIBadMount(*where, evtMessage);
  274. }
  275.  
  276. OSErr dizero(short drvnum, const char* volName)
  277. {
  278.     Str255 pString;
  279.  
  280.     CopyCStringToPascal(volName, pString);
  281.     return DIZero(drvnum, pString);
  282. }
  283.  
  284.  
  285.  
  286. /*******************************  Files ****************************/
  287.  
  288. #include <Files.h>
  289.  
  290. OSErr getvinfo(short drvNum, char* volName, short *vRefNum, long *freeBytes)
  291. {
  292.     if ( volName == NULL ) 
  293.     {
  294.         // I don't know if it is legal for volName to be NULL, but if it is don't use CopyCStringToPascal
  295.         return GetVInfo(drvNum, NULL, vRefNum, freeBytes);
  296.     }
  297.     else
  298.     {
  299.         OSErr     result;
  300.         Str255    pString;
  301.         
  302.         result =  GetVInfo(drvNum, pString, vRefNum, freeBytes);
  303.         CopyPascalStringToC(pString, volName);
  304.  
  305.         return result;
  306.     }
  307. }
  308.  
  309. OSErr fsopen(const char* fileName, short vRefNum, short *refNum)
  310. {
  311.     if ( fileName == NULL)
  312.     {
  313.         // I don't know if it is legal for filename to be NULL, but if it is don't use CopyCStringToPascal
  314.         return FSOpen(NULL, vRefNum, refNum);        
  315.     }
  316.     else
  317.     {
  318.         Str255 pString;
  319.     
  320.         CopyCStringToPascal(fileName, pString);
  321.         return FSOpen(pString, vRefNum, refNum);
  322.     }
  323. }
  324.  
  325. OSErr getfinfo(const char* fileName, short vRefNum, FInfo *fndrInfo)
  326. {
  327.     if ( fileName == NULL)
  328.     {
  329.         // I don't know if it is legal for filename to be NULL, but if it is don't use CopyCStringToPascal
  330.         return GetFInfo(NULL, vRefNum, fndrInfo);        
  331.     }
  332.     else
  333.     {
  334.         Str255 pString;
  335.     
  336.         CopyCStringToPascal(fileName, pString);
  337.         return GetFInfo(pString, vRefNum, fndrInfo);
  338.     }
  339. }
  340.  
  341. OSErr getvol(char* volName, short *vRefNum)
  342. {
  343.     if ( volName == NULL)
  344.     {
  345.         // I don't know if it is legal for volName to be NULL, but if it is don't use CopyCStringToPascal
  346.         return GetVol(NULL, vRefNum);        
  347.     }
  348.     else
  349.     {
  350.         Str255 pString;
  351.         OSErr result;
  352.     
  353.         result = GetVol(pString, vRefNum);
  354.         CopyPascalStringToC(pString, volName);
  355.         return result;
  356.     }
  357. }
  358.  
  359. OSErr setvol(const char* volName, short vRefNum)
  360. {
  361.     if ( volName == NULL)
  362.     {
  363.         // set by vRefNum
  364.         return SetVol(NULL, vRefNum);        
  365.     }
  366.     else
  367.     {
  368.         Str255 pString;
  369.     
  370.         // set by name
  371.         CopyCStringToPascal(volName, pString);
  372.         return SetVol(pString, vRefNum);
  373.     }
  374. }
  375.  
  376. OSErr unmountvol(const char* volName, short vRefNum)
  377. {
  378.     if ( volName == NULL)
  379.     {
  380.         // unmount by vRefNum
  381.         return UnmountVol(NULL, vRefNum);        
  382.     }
  383.     else
  384.     {
  385.         Str255 pString;
  386.  
  387.         // Note: at one time this function would see if the volName was a zero length string.
  388.         // If so, it would cast away the const and return the volName returned by UnmountVol
  389.         CopyCStringToPascal(volName, pString);
  390.         return UnmountVol(pString, vRefNum);
  391.     }
  392. }
  393.  
  394. OSErr eject(const char* volName, short vRefNum)
  395. {
  396.     if ( volName == NULL)
  397.     {
  398.         // unmount by vRefNum
  399.         return Eject(NULL, vRefNum);        
  400.     }
  401.     else
  402.     {
  403.         Str255 pString;
  404.  
  405.         // Note: at one time this function would see if the volName was a zero length string.
  406.         // If so, it would cast away the const and return the volName returned by Eject
  407.         CopyCStringToPascal(volName, pString);
  408.         return Eject(pString, vRefNum);
  409.     }
  410. }
  411.  
  412. OSErr flushvol(const char* volName, short vRefNum)
  413. {
  414.     if ( volName == NULL)
  415.     {
  416.         // I don't know if it is legal for volName to be NULL, but if it is don't use CopyCStringToPascal
  417.         return FlushVol(NULL, vRefNum);        
  418.     }
  419.     else
  420.     {
  421.         Str255 pString;
  422.     
  423.         CopyCStringToPascal(volName, pString);
  424.         return FlushVol(pString, vRefNum);
  425.     }
  426. }
  427.  
  428. OSErr create(const char* fileName, short vRefNum, OSType creator, OSType fileType)
  429. {
  430.     if ( fileName == NULL)
  431.     {
  432.         // I don't know if it is legal for fileName to be NULL, but if it is don't use CopyCStringToPascal
  433.         return Create(NULL, vRefNum, creator, fileType);
  434.     }
  435.     else
  436.     {
  437.         Str255 pString;
  438.     
  439.         CopyCStringToPascal(fileName, pString);
  440.         return Create(pString, vRefNum, creator, fileType);
  441.     }
  442. }
  443.  
  444. OSErr fsdelete(const char* fileName, short vRefNum)
  445. {
  446.     if ( fileName == NULL)
  447.     {
  448.         // I don't know if it is legal for fileName to be NULL, but if it is don't use CopyCStringToPascal
  449.         return FSDelete(NULL, vRefNum);
  450.     }
  451.     else
  452.     {
  453.         Str255 pString;
  454.     
  455.         CopyCStringToPascal(fileName, pString);
  456.         return FSDelete(pString, vRefNum);
  457.     }
  458. }
  459.  
  460. OSErr openrf(const char* fileName, short vRefNum, short *refNum)
  461. {
  462.     if ( fileName == NULL)
  463.     {
  464.         // I don't know if it is legal for fileName to be NULL, but if it is don't use CopyCStringToPascal
  465.         return OpenRF(NULL, vRefNum, refNum);
  466.     }
  467.     else
  468.     {
  469.         Str255 pString;
  470.     
  471.         CopyCStringToPascal(fileName, pString);
  472.         return OpenRF(pString, vRefNum, refNum);
  473.     }
  474. }
  475.  
  476. OSErr fsrename(const char* oldName, short vRefNum, const char* newName)
  477. {
  478.     Str255 pString1, pString2;
  479.     StringPtr oldPtr = pString1;
  480.     StringPtr newPtr = pString2;
  481.     
  482.     if ( oldName == NULL )                        
  483.         oldPtr = NULL;
  484.     else 
  485.         CopyCStringToPascal(oldName, pString1);
  486.     
  487.     if ( newName == NULL )        
  488.         newPtr = NULL;
  489.     else 
  490.         CopyCStringToPascal(newName, pString2);
  491.     
  492.     return Rename(oldPtr, vRefNum, newPtr);
  493. }
  494.  
  495. OSErr setfinfo(const char* fileName, short vRefNum, const FInfo *fndrInfo)
  496. {
  497.     if ( fileName == NULL)
  498.     {
  499.         // I don't know if it is legal for fileName to be NULL, but if it is don't use CopyCStringToPascal
  500.         return SetFInfo(NULL, vRefNum, fndrInfo);
  501.     }
  502.     else
  503.     {
  504.         Str255 pString;
  505.     
  506.         CopyCStringToPascal(fileName, pString);
  507.         return SetFInfo(pString, vRefNum, fndrInfo);
  508.     }
  509. }
  510.  
  511. OSErr setflock(const char* fileName, short vRefNum)
  512. {
  513.     if ( fileName == NULL)
  514.     {
  515.         // I don't know if it is legal for fileName to be NULL, but if it is don't use CopyCStringToPascal
  516.         return SetFLock(NULL, vRefNum);
  517.     }
  518.     else
  519.     {
  520.         Str255 pString;
  521.     
  522.         CopyCStringToPascal(fileName, pString);
  523.         return SetFLock(pString, vRefNum);
  524.     }
  525. }
  526.  
  527. OSErr rstflock(const char* fileName, short vRefNum)
  528. {
  529.     if ( fileName == NULL)
  530.     {
  531.         // I don't know if it is legal for fileName to be NULL, but if it is don't use CopyCStringToPascal
  532.         return RstFLock(NULL, vRefNum);
  533.     }
  534.     else
  535.     {
  536.         Str255 pString;
  537.     
  538.         CopyCStringToPascal(fileName, pString);
  539.         return RstFLock(pString, vRefNum);
  540.     }
  541. }
  542.  
  543.  
  544.  
  545. /*******************************  Fonts ****************************/
  546.  
  547. #include <Fonts.h>
  548.  
  549. void getfnum(const char* theName, short *familyID)
  550. {
  551.     Str255 pString;
  552.     
  553.     CopyCStringToPascal(theName, pString);
  554.     GetFNum(pString, familyID);
  555. }
  556.  
  557. void getfontname(short familyID, char *theName)
  558. {
  559.     Str255 pString;
  560.     
  561.     GetFontName(familyID, pString);
  562.     CopyPascalStringToC(pString, theName);
  563. }
  564.  
  565.  
  566.  
  567. /*******************************  Lists ****************************/
  568.  
  569. #include <Lists.h>
  570.  
  571. void laddtocell(const Ptr dataPtr, short dataLen, Cell *theCell, ListHandle lHandle)
  572. {
  573.     LAddToCell(dataPtr, dataLen, *theCell, lHandle);
  574. }
  575.  
  576. void lcellsize(Point *cSize, ListHandle lHandle)
  577. {
  578.     LCellSize(*cSize, lHandle);
  579. }
  580.  
  581. Boolean lclick(Point *pt, short modifiers, ListHandle lHandle)
  582. {
  583.     return LClick(*pt, modifiers, lHandle);
  584. }
  585.  
  586. void lclrcell(Cell *theCell, ListHandle lHandle)
  587. {
  588.      LClrCell(*theCell, lHandle);
  589. }
  590.  
  591. void ldraw(Cell *theCell, ListHandle lHandle)
  592. {
  593.     LDraw(*theCell, lHandle);
  594. }
  595.  
  596. void lgetcelldatalocation(short *offset, short *len, Cell *theCell, ListHandle lHandle)
  597. {
  598.     LGetCellDataLocation( offset, len, *theCell, lHandle);
  599. }
  600.  
  601. void lgetcell(Ptr dataPtr, short *dataLen, Cell *theCell, ListHandle lHandle)
  602. {
  603.     LGetCell(dataPtr,  dataLen, *theCell, lHandle);
  604. }
  605.  
  606. ListHandle  lnew(Rect *rView, Rect *dataBounds, Point *cSize, short theProc, 
  607.     WindowPtr theWindow, Boolean drawIt, Boolean HasGrow, Boolean ScrollHoriz, 
  608.     Boolean ScrollVert)
  609. {
  610.     return LNew(rView, dataBounds, *cSize, theProc, theWindow, drawIt, HasGrow, ScrollHoriz, ScrollVert);
  611. }
  612.  
  613. void lrect(Rect *cellRect, Cell *theCell, ListHandle lHandle)
  614. {
  615.     LRect( cellRect, *theCell, lHandle);
  616. }
  617.  
  618. void lsetcell(const Ptr dataPtr, short dataLen, Cell *theCell, ListHandle lHandle)
  619. {
  620.     LSetCell(dataPtr, dataLen, *theCell, lHandle);
  621. }
  622.  
  623. void lsetselect(Boolean setIt, Cell *theCell, ListHandle lHandle)
  624. {
  625.     LSetSelect(setIt, *theCell, lHandle);
  626. }
  627.  
  628. /*******************************  Menus ****************************/
  629.  
  630. #include <Menus.h>
  631.  
  632. MenuHandle newmenu(short menuID, const char *menuTitle)
  633. {
  634.     Str255 pString;
  635.  
  636.     CopyCStringToPascal(menuTitle, pString);
  637.     return NewMenu(menuID, pString);
  638. }
  639.  
  640. void getmenuitemtext(MenuHandle menu, short item, char *itemString)
  641. {    
  642.     Str255 pString;
  643.  
  644.     GetMenuItemText(menu, item, pString);
  645.     CopyPascalStringToC(pString, itemString);
  646. }
  647.  
  648. void appendmenu(MenuHandle menu, const char *data)
  649. {
  650.     Str255 pString;
  651.  
  652.     CopyCStringToPascal(data, pString);
  653.     AppendMenu(menu, pString);
  654. }
  655.  
  656. void insertmenuitem(MenuHandle theMenu, const char *itemString, short afterItem)
  657. {
  658.     Str255 pString;
  659.  
  660.     CopyCStringToPascal(itemString, pString);
  661.     InsertMenuItem(theMenu, pString, afterItem);
  662. }
  663.  
  664. long menuselect(const Point *startPt)
  665. {
  666.     return MenuSelect(*startPt);
  667. }
  668.  
  669. void setmenuitemtext(MenuHandle menu, short item, const char *itemString)
  670. {
  671.     Str255 pString;
  672.  
  673.     CopyCStringToPascal(itemString, pString);
  674.     SetMenuItemText(menu, item, pString);
  675. }
  676.  
  677.  
  678. /*******************************  Quickdraw ****************************/
  679.  
  680. #include <Quickdraw.h>
  681.  
  682. void drawstring(const char* s)
  683. {
  684.     Str255 pString;
  685.     
  686.     CopyCStringToPascal(s, pString);
  687.     DrawString(pString);
  688. }
  689.  
  690. short stringwidth(const char* s)
  691. {
  692.     Str255 pString;
  693.     
  694.     CopyCStringToPascal(s, pString);
  695.     return StringWidth(pString);
  696. }
  697.  
  698. Boolean ptinrect(const Point *pt, const Rect *r)
  699. {
  700.     return PtInRect(*pt, r);        
  701. }
  702.  
  703. void pt2rect(const Point *pt1, const Point *pt2, Rect *destRect)
  704. {
  705.     Pt2Rect(*pt1, *pt2, (Rect*)destRect);        
  706. }
  707.  
  708. void pttoangle(const Rect *r, const Point *pt, short *angle)
  709. {
  710.     PtToAngle(r, *pt, angle);                         
  711. }
  712.  
  713. Boolean ptinrgn(const Point *pt, RgnHandle rgn)
  714. {
  715.     return PtInRgn(*pt, rgn);
  716. }
  717.  
  718. void addpt(const Point *src, Point *dst)
  719. {
  720.     AddPt(*src, dst);
  721. }
  722.  
  723. void subpt(const Point *src, Point *dst)
  724. {
  725.     SubPt(*src, dst);
  726. }
  727.  
  728. Boolean equalpt(const Point *pt1, const Point *pt2)
  729. {
  730.     return EqualPt(*pt1, *pt2);
  731. }
  732.  
  733. void stuffhex(void* thingPtr, const char* s)
  734. {
  735.     Str255 pString;
  736.     
  737.     CopyCStringToPascal(s, pString);
  738.     StuffHex(thingPtr, pString);
  739. }
  740.  
  741. void stdtext(short count, const void *textAddr, const Point *number, const Point *denom)
  742. {
  743.     StdText(count, (Ptr)textAddr, *number, *denom);
  744. }
  745.  
  746. void stdline(const Point *newPt)
  747. {
  748.     StdLine(*newPt);
  749. }
  750.  
  751.  
  752. /*******************************  Resources ****************************/
  753.  
  754. #include <Resources.h>
  755.  
  756. short openrfperm(const char* fileName, short vRefNum, char permission)
  757. {
  758.     Str255 pString;
  759.     
  760.     CopyCStringToPascal(fileName, pString);
  761.     return OpenRFPerm(pString, vRefNum, permission);
  762. }
  763.  
  764. short openresfile(const char* fileName)
  765. {
  766.     Str255 pString;
  767.     
  768.     CopyCStringToPascal(fileName, pString);
  769.     return OpenResFile(pString);
  770. }
  771.  
  772. void createresfile(const char* fileName)
  773. {
  774.     Str255 pString;
  775.     
  776.     CopyCStringToPascal(fileName, pString);
  777.     CreateResFile(pString);
  778. }
  779.  
  780. void getresinfo(Handle theResource, short *theID, ResType *theType, char *name)
  781. {
  782.     Str255    pString;
  783.     
  784.     GetResInfo(theResource, theID, theType, pString);
  785.     CopyPascalStringToC(pString, name);
  786. }
  787.  
  788. void setresinfo(Handle theResource, short theID, const char* name)
  789. {
  790.     Str255 pString;
  791.     
  792.     CopyCStringToPascal(name, pString);
  793.     SetResInfo(theResource, theID, pString);
  794. }
  795.  
  796. void addresource(Handle theResource, ResType theType, short theID, const char* name)
  797. {
  798.     Str255 pString;
  799.     
  800.     CopyCStringToPascal(name, pString);
  801.     AddResource(theResource, theType, theID, pString);
  802. }
  803.  
  804. Handle getnamedresource(ResType theType, const char* name)
  805. {
  806.     Str255 pString;
  807.     
  808.     CopyCStringToPascal(name, pString);
  809.     return GetNamedResource(theType, pString);
  810. }
  811.  
  812. Handle get1namedresource(ResType theType, const char* name)
  813. {
  814.     Str255 pString;
  815.     
  816.     CopyCStringToPascal(name, pString);
  817.     return GetNamedResource(theType, pString);
  818. }
  819.  
  820. /*******************************  StandardFile ****************************/
  821.  
  822. #include <StandardFile.h>
  823.  
  824. void sfpputfile(Point *where, const char* prompt, const char* origName, DlgHookUPP dlgHook,
  825.                 SFReply *reply, short dlgID, ModalFilterUPP filterProc)
  826. {
  827.     Str255 pString1, pString2;
  828.  
  829.     CopyCStringToPascal(prompt, pString1);
  830.     CopyCStringToPascal(origName, pString2);
  831.     SFPPutFile(*where, pString1, pString2, dlgHook, reply, dlgID, filterProc);
  832. }
  833.  
  834. void sfgetfile(Point *where, const char* prompt, FileFilterUPP fileFilter,
  835.             short numTypes, ConstSFTypeListPtr typeList, DlgHookUPP dlgHook, SFReply *reply)
  836. {
  837.     Str255 pString;
  838.  
  839.     CopyCStringToPascal(prompt, pString);
  840.     SFGetFile(*where, pString, fileFilter, numTypes, typeList, dlgHook, reply);
  841. }
  842.  
  843. void sfpgetfile(Point *where, const char* prompt, FileFilterUPP fileFilter,
  844.                 short numTypes, ConstSFTypeListPtr typeList, DlgHookUPP dlgHook, SFReply *reply,
  845.                 short dlgID, ModalFilterUPP filterProc)
  846. {
  847.     Str255 pString;
  848.  
  849.     CopyCStringToPascal(prompt, pString);
  850.     SFPGetFile(*where, pString, fileFilter, numTypes, typeList, 
  851.             dlgHook, reply, dlgID, filterProc);
  852. }
  853.  
  854. void sfputfile(Point *where, const char* prompt, const char* origName, DlgHookUPP dlgHook, 
  855.                 SFReply *reply)
  856. {
  857.     Str255 pString1, pString2;
  858.     
  859.     CopyCStringToPascal(prompt, pString1);
  860.     CopyCStringToPascal(origName, pString2);
  861.     SFPutFile(*where, pString1, pString2, dlgHook, reply);
  862. }
  863.  
  864.  
  865. /*******************************  TextEdit ****************************/
  866.  
  867. #include <TextEdit.h>
  868.  
  869. void teclick(Point *pt, Boolean fExtend, TEHandle h)
  870. {
  871.     TEClick(*pt, fExtend, h);
  872. }
  873.  
  874.  
  875. /*******************************  TextUtils ****************************/
  876.  
  877. #include <TextUtils.h>
  878. #include <Traps.h>
  879.  
  880. #if !CFMSYSTEMCALLS 
  881.  
  882. #pragma parameter __D0 Trap0xA03C(__A0, __A1, __D0)
  883. pascal long Trap0xA03C(const void* text1, const void* text2, long lengths)
  884.  = 0xA03C;
  885.  
  886. #pragma parameter __D0 Trap0xA23C(__A0, __A1, __D0)
  887. pascal long Trap0xA23C(const void* text1, const void* text2, long lengths)
  888.  = 0xA03C;
  889.  
  890. #pragma parameter __D0 Trap0xA43C(__A0, __A1, __D0)
  891. pascal long Trap0xA43C(const void* text1, const void* text2, long lengths)
  892.  = 0xA03C;
  893.  
  894. #pragma parameter __D0 Trap0xA63C(__A0, __A1, __D0)
  895. pascal long Trap0xA63C(const void* text1, const void* text2, long lengths)
  896.  = 0xA03C;
  897.  
  898.  
  899. #pragma parameter __D0 Trap0xA050(__A0, __A1, __D0)
  900. pascal short Trap0xA050(const void* text1, const void* text2, long lengths)
  901.  = 0xA050;
  902.  
  903. #pragma parameter __D0 Trap0xA250(__A0, __A1, __D0)
  904. pascal short Trap0xA250(const void* text1, const void* text2, long lengths)
  905.  = 0xA050;
  906.  
  907. #pragma parameter __D0 Trap0xA450(__A0, __A1, __D0)
  908. pascal short Trap0xA450(const void* text1, const void* text2, long lengths)
  909.  = 0xA050;
  910.  
  911. #pragma parameter __D0 Trap0xA650(__A0, __A1, __D0)
  912. pascal short Trap0xA650(const void* text1, const void* text2, long lengths)
  913.  = 0xA050;
  914.  
  915.  
  916. #pragma parameter Trap0xA054(__A0, __D0)
  917. pascal void Trap0xA054(const void* text, short length)
  918.  = 0xA054;
  919.  
  920. #pragma parameter Trap0xA254(__A0, __D0)
  921. pascal void Trap0xA254(const void* text, short length)
  922.  = 0xA254;
  923.  
  924. #endif
  925.  
  926. Boolean equalstring(const char* text1, const char* text2, Boolean caseSens, Boolean diacSens)
  927. {
  928.     unsigned short            trapWord    = _CmpString;
  929.     long                    lengths    = ((unsigned long)(StrLen(text1) & 0x0000FFFF) << 16) | 
  930.                                         (StrLen(text2) & 0x0000FFFF);
  931.     
  932.     if (!diacSens)
  933.         trapWord |= 0x0200;    /* set bit 9 to ignore diacritical marks */
  934.     if (caseSens)
  935.         trapWord |= 0x0400; /* set bit 10 to indicate case sensitivity */
  936.  
  937.     {
  938.         long    result;
  939.         
  940.         switch ( trapWord )
  941.         {
  942.         case 0xA03C:
  943.             result = Trap0xA03C(text1, text2, lengths);
  944.             break;
  945.         case 0xA23C:
  946.             result = Trap0xA23C(text1, text2, lengths);
  947.             break;
  948.         case 0xA43C:
  949.             result = Trap0xA43C(text1, text2, lengths);
  950.             break;
  951.         case 0xA63C:
  952.             result = Trap0xA63C(text1, text2, lengths);
  953.             break;
  954.         }
  955.         return ( ! result );
  956.     }
  957. }
  958.  
  959.  
  960. void upperstring(char* text, Boolean diacSens)
  961. {
  962.     unsigned short trapWord = _UprString;
  963.     unsigned short length    = StrLen(text);
  964.     
  965.     if (!diacSens)
  966.         trapWord |= 0x0200;    /* set bit 9 to ignore diacritical marks */
  967.  
  968.     if ( trapWord == 0xA054 )
  969.         Trap0xA054(text, length);
  970.     else
  971.         Trap0xA254(text, length);
  972. }
  973.  
  974.  
  975. short relstring(const char* text1, const char* text2, Boolean caseSens, Boolean diacSens)
  976. {
  977.     unsigned short     trapWord    = _RelString;
  978.     short            result;
  979.     long            lengths        = ((unsigned long)(StrLen(text1) & 0x0000FFFF) << 16) | 
  980.                                     (StrLen(text2) & 0x0000FFFF);
  981.     
  982.     if (!diacSens)
  983.         trapWord |= 0x0200;    /* set bit 9 to ignore diacritical marks */
  984.     if (caseSens)
  985.         trapWord |= 0x0400; /* set bit 10 to indicate case sensitivity */
  986.  
  987.     switch ( trapWord )
  988.     {
  989.     case 0xA050:
  990.         result = Trap0xA050(text1, text2, lengths);
  991.         break;
  992.     case 0xA250:
  993.         result = Trap0xA250(text1, text2, lengths);
  994.         break;
  995.     case 0xA450:
  996.         result = Trap0xA450(text1, text2, lengths);
  997.         break;
  998.     case 0xA650:
  999.         result = Trap0xA650(text1, text2, lengths);
  1000.         break;
  1001.     }
  1002.     return result;
  1003. }
  1004.  
  1005. void setstring(StringHandle theString, const char* strNew)
  1006. {
  1007.     Str255 pString;
  1008.     
  1009.     CopyCStringToPascal(strNew, pString);
  1010.     SetString(theString, pString);
  1011. }
  1012.  
  1013. StringHandle newstring(const char* theString)
  1014. {
  1015.     Str255 pString;
  1016.     
  1017.     CopyCStringToPascal(theString, pString);
  1018.     return NewString(pString);
  1019. }
  1020.  
  1021. void getindstring(char *theString, short strListID, short index)
  1022. {
  1023.     Str255 pString;
  1024.  
  1025.     GetIndString(pString, strListID, index);
  1026.     CopyPascalStringToC(pString, theString);
  1027. }
  1028.  
  1029. short iucompstring(const char* aStr, const char* bStr)
  1030. {
  1031.     return CompareText(aStr, bStr, StrLen(aStr), StrLen(bStr), NULL);
  1032. }
  1033.  
  1034.  
  1035. short iuequalstring(const char* aStr, const char* bStr)
  1036. {
  1037.     return IdenticalText(aStr, bStr, StrLen(aStr), StrLen(bStr), NULL);
  1038. }
  1039.  
  1040. short iucomppstring(const char* aStr, const char* bStr, Handle intlHandle)
  1041. {
  1042.     return CompareText(aStr, bStr, StrLen(aStr), StrLen(bStr), intlHandle);
  1043. }
  1044.  
  1045. short iuequalpstring(const char* aStr, const char* bStr, Handle intlHandle)
  1046. {
  1047.     return IdenticalText(aStr, bStr, StrLen(aStr), StrLen(bStr), intlHandle);
  1048. }
  1049.  
  1050. short iustringorder(const char* aStr, const char* bStr, 
  1051.                     ScriptCode aScript, ScriptCode bScript,
  1052.                      LangCode aLang, LangCode bLang)
  1053. {
  1054.     return TextOrder(aStr, bStr, StrLen(aStr), StrLen(bStr), aScript, bScript, aLang, bLang);
  1055. }
  1056.  
  1057. void stringtonum(const char* theString, long *theNum)
  1058. {
  1059.     Str255 pString;
  1060.     
  1061.     CopyCStringToPascal(theString, pString);
  1062.     StringToNum(pString, theNum);
  1063. }
  1064.  
  1065. void numtostring(long theNum, char *theString)
  1066. {
  1067.     Str255    pString;    
  1068.     
  1069.     NumToString(theNum, pString);
  1070.     CopyPascalStringToC(pString, theString);
  1071. }
  1072.  
  1073. void iudatestring(long dateTime, DateForm longFlag, char *result)
  1074. {
  1075.     Str255    pString;
  1076.     
  1077.     DateString(dateTime, longFlag, pString, NULL);
  1078.     CopyPascalStringToC(pString, result);
  1079. }
  1080.  
  1081. void iudatepstring(long dateTime, DateForm longFlag, char *result, Handle intlHandle)
  1082. {
  1083.     Str255    pString;    
  1084.     
  1085.     DateString(dateTime, longFlag, pString, intlHandle);
  1086.     CopyPascalStringToC(pString, result);
  1087. }
  1088.  
  1089. void iutimestring(long dateTime, Boolean wantSeconds, char *result)
  1090. {
  1091.     Str255    pString;    
  1092.     
  1093.     TimeString(dateTime, wantSeconds, pString, NULL);
  1094.     CopyPascalStringToC(pString, result);
  1095. }
  1096.  
  1097. void iutimepstring(long dateTime, Boolean wantSeconds, char *result, Handle intlHandle)
  1098. {
  1099.     Str255    pString;    
  1100.     
  1101.     TimeString(dateTime, wantSeconds, pString, intlHandle);
  1102.     CopyPascalStringToC(pString, result);
  1103. }
  1104.  
  1105. void iuldatestring(LongDateTime *dateTime, DateForm longFlag, char *result, Handle intlHandle)
  1106. {
  1107.     Str255    pString;    
  1108.     
  1109.     LongDateString(dateTime, longFlag, pString, intlHandle);
  1110.     CopyPascalStringToC(pString, result);
  1111. }
  1112.  
  1113. void iultimestring(LongDateTime *dateTime, Boolean wantSeconds, char *result, Handle intlHandle)
  1114. {
  1115.     Str255    pString;
  1116.     
  1117.     LongTimeString(dateTime, wantSeconds, pString, intlHandle);
  1118.     CopyPascalStringToC(pString, result);
  1119. }
  1120.  
  1121.  
  1122. /*******************************  Windows ****************************/
  1123.  
  1124. #include <Windows.h>
  1125.  
  1126. void setwtitle(WindowPtr theWindow, const char* title)
  1127. {
  1128.     Str255 pString;
  1129.     
  1130.     CopyCStringToPascal(title, pString);
  1131.     SetWTitle(theWindow, pString);
  1132. }
  1133.  
  1134. Boolean trackgoaway(WindowPtr theWindow, Point *thePt)
  1135. {
  1136.     return TrackGoAway(theWindow, *thePt);
  1137. }
  1138.  
  1139. short findwindow(Point *thePoint, WindowPtr *theWindow)
  1140. {
  1141.     return FindWindow(*thePoint, theWindow);
  1142. }
  1143.  
  1144. void getwtitle(WindowPtr theWindow, char *title)
  1145. {
  1146.     Str255 pString;
  1147.  
  1148.     GetWTitle(theWindow, pString);
  1149.     CopyPascalStringToC(pString, title);
  1150. }
  1151.  
  1152. long growwindow(WindowPtr theWindow, Point *startPt, const Rect *bBox)
  1153. {
  1154.     return GrowWindow(theWindow, *startPt, bBox);
  1155. }
  1156.  
  1157. WindowPtr newwindow(void *wStorage, const Rect *boundsRect, const char* title, Boolean visible,
  1158.                      short theProc, WindowPtr behind, Boolean goAwayFlag, long refCon)
  1159. {
  1160.     Str255 pString;
  1161.     
  1162.     CopyCStringToPascal(title, pString);
  1163.     return NewWindow(wStorage, boundsRect, pString, visible, theProc,
  1164.                         behind, goAwayFlag, refCon);
  1165. }
  1166.  
  1167. WindowPtr newcwindow(void *wStorage, const Rect *boundsRect, const char *title,
  1168.                      Boolean visible, short procID, WindowPtr behind, Boolean goAwayFlag, long refCon)
  1169. {
  1170.     Str255 pString;
  1171.     
  1172.     CopyCStringToPascal(title, pString);
  1173.     return NewCWindow(wStorage, boundsRect, pString, visible, procID,
  1174.                         behind, goAwayFlag, refCon);
  1175. }
  1176.  
  1177. long pinrect(const Rect *theRect, Point *thePt)
  1178. {
  1179.     return PinRect(theRect, *thePt);    
  1180. }
  1181.  
  1182. Boolean trackbox(WindowPtr theWindow, Point *thePt, short partCode)
  1183. {
  1184.     return TrackBox(theWindow, *thePt, partCode);
  1185. }
  1186.  
  1187. long draggrayrgn(RgnHandle theRgn, Point *startPt, const Rect *boundsRect,
  1188.                  const Rect *slopRect, short axis, DragGrayRgnUPP actionProc)
  1189. {
  1190.     return DragGrayRgn(theRgn, *startPt, boundsRect, slopRect, axis, actionProc);
  1191. }
  1192.  
  1193. void dragwindow(WindowPtr theWindow, Point *startPt, const Rect *boundsRect)
  1194. {
  1195.     DragWindow(theWindow, *startPt, boundsRect);
  1196. }
  1197.  
  1198. #if __MWERKS__
  1199. #pragma pointers_in_A0        //    required for c-style toolbox glue function: c2pstr and p2cstr
  1200.                             //    the inverse operation (pointers_in_A0) is performed at the end ...
  1201. #endif
  1202.  
  1203.