MT Convert W code : Source

Name:MT Convert W code
Event Class:XUVJ
Event ID:Wcov
Resource:AEVTXUVJWcov

Source

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

global theAEEvent:R,theReply:R, handerRefCon:LongInt
global tgLen:LongInt, tgHandleLen:LongInt, myLen:LongInt
global my8tFlg:Boolean, myDscd:Integer, mySrcd:Integer

codeResource "osax"

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

  put NewPtrClear(8) into myDescPtr

  ------
  put AEGetParamDesc(theAEEvent@,"dscd","enum",myDescPtr@) into err

  if myDescPtr@.descriptorType = typeNull then
    DisposPtr myDescPtr
    return err
  else
    put CharToNum(myDescPtr@.dataHandle@@.charType) into myDscd
  end if

  if myDscd = 160 then put 77 into myDscd

  put AEDisposeDesc(myDescPtr@) into xerr

  -----
  put AEGetParamDesc(theAEEvent@,"srcd","enum",myDescPtr@) into err

  if myDescPtr@.descriptorType = typeNull then
    DisposPtr myDescPtr
    return err
  else
    put CharToNum(myDescPtr@.dataHandle@@.charType) into mySrcd
  end if

  if mySrcd = 160 then put 77 into mySrcd

  put AEDisposeDesc(myDescPtr@) into xerr
  ---
  put AEGetParamDesc(theAEEvent@,"8thr","bool",myDescPtr@) into err

  if myDescPtr@.descriptorType = typeNull then
    put false into my8tFlg
  else
    put myDescPtr@.dataHandle@@.BooleanType into my8tFlg
    put AEDisposeDesc(myDescPtr@) into xerr
  end if
  ---
  put AESizeOfParam(theAEEvent@,keyDirectObject,myType,mySize) into err
  if err <> 0 then
    DisposPtr myDescPtr
    return err
  end if

  if (myType = "list") then

    put AEGetParamDesc(theAEEvent@,keyDirectObject,typeAEList,myDescPtr@) into err
    if err <> 0 then
      DisposPtr myDescPtr
      return err
    end if

    put 0 into mySize
    put AECountItems(myDescPtr@,mySize) into err
    if err <> 0 then
      put AEDisposeDesc(myDescPtr@) into xErr
      DisposPtr myDescPtr
      return err
    end if

    if mySize > 0 then

      put NewPtrClear(8) into myLIPtr

      repeat with x = 1 to mySize

        put AEGetNthDesc(myDescPtr@,x,"TEXT",myKey,myLIPtr@) into err
        if err = 0 then

          put myLIPtr@.dataHandle into myStrHandle

          put GetHandleSize(myStrHandle) into tgLen

          if tgLen > 0 then
            put myConverter(myStrHandle) into err
            if err < 0 then
              put AEDisposeDesc(myDescPtr@) into xerr
              put AEDisposeDesc(myLIPtr@) into xErr
              DisposPtr myDescPtr
              DisposPtr myLIPtr
              return err
            end if
          end if

          put AEPutDesc(myDescPtr@,x,myLIPtr@) into err
          put AEDisposeDesc(myLIPtr@) into xErr
          if err <> 0 then
            put AEDisposeDesc(myDescPtr@) into xerr
            DisposPtr myDescPtr
            DisposPtr myLIPtr
            return err
          end if
        end if

      end repeat

      DisposPtr myLIPtr


    end if

  else
    --- String

    put AEGetParamDesc(theAEEvent@,keyDirectObject,typeChar,myDescPtr@) into err
    if err <> 0 then
      DisposPtr myDescPtr
      return err
    end if

    put myDescPtr@.dataHandle into myStrHandle

    put GetHandleSize(myStrHandle) into tgLen

    if tgLen > 0 then
      put myConverter(myStrHandle) into err
      if err < 0 then
        put AEDisposeDesc(myDescPtr@) into xerr
        DisposPtr myDescPtr
        return tgLen
      end if
    end if

  end if

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

  put AEDisposeDesc(myDescPtr@) into xerr
  DisposPtr myDescPtr
  return 0

end Wcov


function myConverter myStrHandle

  put GetHandleSize(myStrHandle) into tgLen

  if mySrcd = myDscd then return 0

  if mySrcd = 77 then
    if myDscd = 76 then
      return Mac2L1(myStrHandle)
    else if myDscd = 72 then
      return Mac2HTML(myStrHandle)
    end if

  else if mySrcd = 76 then
    if myDscd = 77 then
      return L12Mac(myStrHandle)
    else if myDscd = 72 then
      return L12HTML(myStrHandle)
    end if

  else if mySrcd = 72 then
    if myDscd = 77 then
      return HTML2Mac(myStrHandle)
    else if myDscd = 76 then
      return HTML2L1(myStrHandle)
    end if

  end if
end myConverter

--- XUVJ_8857_L1_table

function HTML2L1 tgHandle
  put GetNamedResource("tble","XUVJ_8857_L1_table") into myResHandle

  if myResHandle = nil then
    put ResError() into err
    return err
  end if

  put GetHandleSize(myResHandle) into myTableSize
  put (myTableSize div 10)-1 into dy

  Hlock myResHandle

  repeat with x = 0 to dy
    put CharToNum(myResHandle@@.charType[x*10+1]) into htmlLen

    put myResHandle@ + (x*10) into macrPtr
    put myResHandle@ + (x*10+2) into htmlPtr

    put 0 into baseOff
    repeat until baseOff < 0
      put Munger(tgHandle,baseOff,htmlPtr,htmlLen,macrPtr,1) into baseOff
    end repeat

  end repeat

  HUnlock myResHandle
  ReleaseResource myResHandle


  return 0

end HTML2L1


function HTML2Mac tgHandle
  put GetNamedResource("tble","XUVJ_8857_table") into myResHandle

  if myResHandle = nil then
    put ResError() into err
    return err
  end if

  put GetHandleSize(myResHandle) into myTableSize
  put (myTableSize div 10)-1 into dy

  Hlock myResHandle

  repeat with x = 0 to dy
    put CharToNum(myResHandle@@.charType[x*10+1]) into htmlLen

    put myResHandle@ + (x*10) into macrPtr
    put myResHandle@ + (x*10+2) into htmlPtr

    put 0 into baseOff
    repeat until baseOff < 0
      put Munger(tgHandle,baseOff,htmlPtr,htmlLen,macrPtr,1) into baseOff
    end repeat

  end repeat

  HUnlock myResHandle
  ReleaseResource myResHandle

  return 0

end HTML2Mac


function L12Mac tgHandle

  put GetResource("tble",1001) into myRsrcHandle

  if myRsrcHandle = nil then
    put ResError() into err
    return err
  end if

  put GetHandleSize(tgHandle) into tgHandleLen
  put tgHandleLen-1 into myLen

  repeat with x = 0 to myLen
    put charToNum(tgHandle@@.charType[x]) into dx
    put myRsrcHandle@@.charType[dx] into tgHandle@@.charType[x]
  end repeat

  ReleaseResource myRsrcHandle

  return 0

end L12Mac


function Mac2L1 tgHandle
  put GetResource("tble",1002) into myRsrcHandle

  if myRsrcHandle = nil then
    put ResError() into err
    return err
  end if

  put GetHandleSize(tgHandle) into tgHandleLen
  put tgHandleLen-1 into myLen

  repeat with x = 0 to myLen
    put charToNum(tgHandle@@.charType[x]) into dx
    put myRsrcHandle@@.charType[dx] into tgHandle@@.charType[x]
  end repeat

  ReleaseResource myRsrcHandle

  return 0

end Mac2L1



function L12HTML tgHandle

  put GetNamedResource("tble","XUVJ_8857_L1_table") into myResHandle

  if myResHandle = nil then
    put ResError() into err
    return err
  end if

  put GetHandleSize(myResHandle) into myTableSize
  if my8tFlg then
    put 3 into dy
  else
    put (myTableSize div 10)-1 into dy
  end if

  Hlock myResHandle

  repeat with x = 0 to dy

    put CharToNum(myResHandle@@.charType[x*10+1]) into htmlLen

    put myResHandle@ + (x*10) into macrPtr
    put myResHandle@ + (x*10+2) into htmlPtr

    put 0 into baseOff
    repeat until baseOff < 0
      put Munger(tgHandle,baseOff,macrPtr,1,htmlPtr,htmlLen) into baseOff
    end repeat

  end repeat

  HUnlock myResHandle
  ReleaseResource myResHandle

  return 0

end L12HTML



function Mac2HTML tgHandle
  put GetNamedResource("tble","XUVJ_8857_table") into myResHandle

  if myResHandle = nil then
    put ResError() into err
    return err
  end if

  put GetHandleSize(myResHandle) into myTableSize

  if my8tFlg then
    put 3 into dy
  else
    put (myTableSize div 10)-1 into dy
  end if

  Hlock myResHandle

  repeat with x = 0 to dy

    put CharToNum(myResHandle@@.charType[x*10+1]) into htmlLen

    put myResHandle@ + (x*10) into macrPtr
    put myResHandle@ + (x*10+2) into htmlPtr

    put 0 into baseOff
    repeat until baseOff < 0
      put Munger(tgHandle,baseOff,macrPtr,1,htmlPtr,htmlLen) into baseOff
    end repeat

  end repeat

  HUnlock myResHandle
  ReleaseResource myResHandle


  return 0

end Mac2HTML

Tanaka's osax : Source
Tanaka's osax