MT Swap characters : Source

Name:MT Swap characters
Event Class:XUVJ
Event ID:trpl
Resource:AEVTXUVJtrpl

Source

--- This source is written in HyperTalk for CompileIt!

global myType:OStype, mySize:longInt
global theAEEvent:R,theReply:R, handerRefCon:LongInt

codeResource "osax"

pascal function tblReplace:I theAEEvent:R, theReply:R, handerRefCon:L

  put NewPtr(28) into myWorkPtr

  put myWorkPtr into myStrDescPtr
  put myWorkPtr + 8 into myDescPtr
  put myWorkPtr + 16 into myDesc2Ptr
  put myWorkPtr + 24 into mysPtr
  put myWorkPtr + 26 into myrPtr


  put AEGetParamDesc(theAEEvent@,"----","TEXT",myStrDescPtr@) into err
  if err <> 0 then
    DisposPtr myWorkPtr
    return err
  end if

  put myStrDescPtr@.dataHandle into tStrHandle
  put GetHandleSize(tStrHandle) into tStrSize

  put tStrHandle into xStrHandle
  put HandToHand(xStrHandle) into err
  if err <> 0 then
    put AEDisposeDesc(myStrDescPtr@) into xerr
    DisposPtr myWorkPtr
    return err
  end if

  ----
  put AEGetParamDesc(theAEEvent@,"tbl1",typeAEList,myDescPtr@) into err
  if err <> 0 then
    DisposHandle xStrHandle
    DisposPtr myWorkPtr
    return err
  end if

  put AEGetParamDesc(theAEEvent@,"tbl2",typeAEList,myDesc2Ptr@) into err
  if err <> 0 then
    put AEDisposeDesc(myStrDescPtr@) into xerr
    put AEDisposeDesc(myDescPtr@) into xerr
    DisposHandle xStrHandle
    DisposPtr myWorkPtr
    return err
  end if

  ----
  put AECountItems(myDescPtr@,my1Size) into err
  put AECountItems(myDesc2Ptr@,my2Size) into err

  if my1Size <> my2Size or my1Size = 0 then
    put AEDisposeDesc(myDescPtr@) into xerr
    put AEDisposeDesc(myDesc2Ptr@) into xerr
    put AEDisposeDesc(myStrDescPtr@) into xerr
    DisposHandle xStrHandle
    DisposPtr myWorkPtr
    return -1708
  end if


  put tStrSize-1 into xLen

  repeat with x = 1 to my1Size

    put AEGetNthPtr(myDescPtr@,x,"TEXT",myKey,myType,mysPtr,1,mySize) into err
    if err <> 0 then
      put AEDisposeDesc(myDescPtr@) into xerr
      put AEDisposeDesc(myDesc2Ptr@) into xerr
      put AEDisposeDesc(myStrDescPtr@) into xerr
      DisposHandle xStrHandle
      DisposPtr myWorkPtr
      return err
    end if

    put AEGetNthPtr(myDesc2Ptr@,x,"TEXT",myKey,myType,myrPtr,1,mySize) into err
    if err <> 0 then
      put AEDisposeDesc(myDescPtr@) into xerr
      put AEDisposeDesc(myDesc2Ptr@) into xerr
      put AEDisposeDesc(myStrDescPtr@) into xerr
      DisposHandle xStrHandle
      DisposPtr myWorkPtr
      return err
    end if

    repeat with y=0 to xLen
      if CharToNum(xStrHandle@@.charType[y]) = CharToNum(mysPtr@.charType) then
        put myrPtr@.chartype into tStrHandle@@.charType[y]
      end if
    end repeat

  end repeat


  if theReply@.descriptorType <> typeNull then
    if theReply@.descriptorType <> typeNull then
      put AEPutParamDesc(theReply@, keyDirectObject,myStrDescPtr@) into err
    end if
  end if

  put AEDisposeDesc(myDescPtr@) into xerr
  put AEDisposeDesc(myDesc2Ptr@) into xerr
  put AEDisposeDesc(myStrDescPtr@) into xerr
  DisposHandle xStrHandle
  DisposPtr myWorkPtr

  return err


end tblReplace




Tanaka's osax : Source
Tanaka's osax