home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
thinkref
/
archive
/
THINKPascalUH2.1.sea
/
MPW2TPas
next >
Wrap
Text File
|
1995-09-12
|
13KB
|
473 lines
##
## MPW2TPas
## Copyright ©1995, Symantec Corp.
## Written by Glenn L. Austin
## Symantec Macintosh Development Tools Technical Support
##
## MPW2TPas takes MPW header files and massages them for use with THINK Pascal.
## The acid test for this script was converting the MPW Universal Headers 2.1
## so that they can be used with THINK Pascal 4.0.2.
##
set exit 0
set me "{0}"
if "{1} " == " "
echo '## '"{me}"' - Copyright ©1995, Symantec Corp.'
echo '## Written by Glenn L. Austin'
echo '##'
echo '## Converts MPW Pascal headers for use within THINK Pascal'
echo '##'
echo '## Syntax: '"{me}"' file [file..]'
exit 0
else
## Handle my necessary recursive calls for:
## - calculating a constant value
## - computing the size of a variable type
## - getting the value of a constant
if "{1}" == "-calculate"
set s "{2}"
set f "{3}"
if "{s}" =~ /$[0-9A-F]+/
echo "{s}"
exit 0
end
if "{s}" =~ /[-0-9]+/
echo "{s}"
exit 0
end
loop
break if "{s}" !~ /≈sizeof∂([¬∂)]+∂)≈/
( evaluate "{s}" =~ /(≈)®1sizeof∂(([¬∂)]+)®2∂)(≈)®3/ ) ∑ Dev:Null
set s1 "{®1}"
set s2 "{®2}"
set s3 "{®3}"
unset ®1 ®2 ®3
set s2 "`"{me}" -sizeof "{s2}" "{f}"`"
set s "{s1}{s2}{s3}"
end
loop
break if "{s}" !~ /≈∂(≈∂)≈/
( evaluate "{s}" =~ /([¬∂(]*)®1∂((≈)®2∂)([¬∂)]*)®3/ ) ∑ Dev:Null
set s1 "{®1}"
set s2 "{®2}"
set s3 "{®3}"
unset ®1 ®2 ®3
set s2 "`"{me}" -calculate "{s2}" "{f}"`"
set s "{s1}{s2}{s3}"
end
set v ""
loop
break if "{s} " == " "
if ("{s}" =~ /≈[-+∂/∂*]≈/) && ("{s}" !~ /-[0-9]+/)
( evaluate "{s}" =~ /(?[¬-+ ∂t∂*∂/]*)®1[ ∂t]*([-+∂/∂*]+)®2[ ∂t]*(≈)®3/ ) ∑ Dev:Null
set s1 "{®1}"
set s2 "{®2}"
set s3 "{®3}"
unset ®1 ®2 ®3
if "{s1}" !~ /[-0-9$A-F]+/
set s1 "`"{me}" -valueof "{s1}" "{f}"`"
end
if "{s2}" == '/'
set s2 '÷'
else if "{s2}" == '**'
if "{s3}" !~ /[-0-9$A-F]+/
set s3 "`"{me} -calculate "{s3}" "{f}"`"
end
set s2 1
loop
break if {s3} == 0
( evaluate s3 -= 1 ) ∑ Dev:Null
( evaluate s2 = {s2} * {s1} ) ∑ Dev:Null
end
set s1 "`evaluate -h {s2}`"
( evaluate "{s1}" =~ /0x(≈)®1/ ) ∑ Dev:Null
set s1 `echo "00000000{®1}" | translate "a-f" "A-F"`
unset ®1
( evaluate "{s1}" =~ /≈([0-9a-fA-F]«8»)®1/ ) ∑ Dev:Null
set s1 "${®1}"
unset ®1
set s2 ""
set s3 ""
end
set v "{v}{s1}{s2}"
set s "{s3}"
else
if "{s}" !~ /[-0-9$A-F]+/
set s "`"{me}" -valueof "{s}" "{f}"`"
end
set v "{v}{s}"
break
end
end
if "{v}" =~ /≈$[0-9A-F]+≈/
( set v `evaluate -h {v}` ) ∑ Dev:Null
if "{v}" !~ /0x[0-9A-F]+/
set v "`"{me}" -calculate "{v}" "{f}"`"
end
set v `evaluate -h {v}`
( evaluate "{v}" =~ /0x(≈)®1/ ) ∑ Dev:Null
set v `echo "${®1}" | translate "a-f" "A-F"`
unset ®1
else
( set v `evaluate {v}` ) ∑ Dev:Null
if "{v}" !~ /[-0-9]+/
set v "`"{me}" -calculate "{v}" "{f}"`"
end
end
echo "{v}"
exit 0
else if "{1}" == "-sizeof"
set s "{2}"
set f "{3}"
set elemSize 0
if ("{s}" == "BYTE") || ("{s}" =~ /[SU]Int8/)
echo 1
exit 0
else if ("{s}" == "INTEGER") || ("{s}" =~ /[SU]Int16/)
echo 2
exit 0
else if ("{s}" == "LONGINT") || ("{s}" =~ /[SU]Int32/) || ("{s}" == "OSType") || ("{s}" == "ResType")
echo 4
exit 0
end
set filePos "`position -c "{f}"`"
( evaluate "{filePos}" =~ /([0-9]+)®1,([0-9]+)®2/ ) ∑ Dev:Null
set filePos 'Δ1!'{®1}':Δ1!'{®2}
find • "{f}"
find /•[ ∂t]+{s}[ ∂t]*∂=[ ∂t]*/ "{f}"
find §Δ "{f}"
find /[¬ ∂t∂n;]+/ "{f}"
set packed 0
if "`catenate "{f}".§`" == "PACKED"
set packed 1
find /[ ∂t∂n]+/Δ "{f}"
find /[¬ ∂t∂n]+/ "{f}"
end
set s1 "`catenate "{f}".§`"
if ("{s1}" == "BYTE") || ("{s1}" =~ /[SU]Int8/)
find {filePos} "{f}"
echo 1
exit 0
else if ("{s1}" == "INTEGER") || ("{s1}" =~ /[SU]Int16/)
find {filePos} "{f}"
echo 2
exit 0
else if ("{s}" == "LONGINT") || ("{s}" =~ /[SU]Int32/) || ("{s}" == "OSType") || ("{s}" == "ResType")
find {filePos} "{f}"
echo 4
exit 0
end
if "{s1}" == "RECORD"
find Δ!1:Δ/•[ ∂t]+END;/ "{f}"
set numLines `count -l "{f}".§`
find Δ§ "{f}"
loop
break if {numLines} == 0
( evaluate numLines -= 1 ) ∑ Dev:Null
find /:[ ∂t]*/Δ:Δ/;/ "{f}"
set s1 "`catenate "{f}".§`"
if "{s1}" =~ /(PACKED )«0,1»ARRAY ≈/
( evaluate "{s1}" =~ /≈ARRAY ∂[([¬∂.]+)®1∂.∂.([¬∂]]+)®2∂] OF (≈)®3/ ) ∑ Dev:Null
set lb "{®1}"
set hb "{®2}"
set sz "{®3}"
unset ®1 ®2 ®3
set sz "`"{me}" -sizeof "{sz}" "{f}"`"
#if ({sz} == 1) && !{packed} && ("{s1}" !~ /PACKED ≈/)
# set sz 2
#end
if "{lb}" !~ /[-0-9]+/
set lb "`"{me}" -calculate "{lb}" "{f}"`"
end
if "{hb}" !~ /[-0-9]+/
set hb "`"{me}" -calculate "{hb}" "{f}"`"
end
( evaluate sz = {sz} * (1 + {hb} - {lb}) ) ∑ Dev:Null
else
set sz "`"{me}" -sizeof "{s1}" "{f}"`"
end
if ({sz} != 1) && !{packed} && `evaluate {elemSize} MOD 2`
( evaluate elemSize += 1 ) ∑ Dev:Null
end
( evaluate elemSize += {sz} ) ∑ Dev:Null
find Δ!1 "{f}"
end
else if "{s1}" == "ARRAY"
find /∂[/Δ:Δ/∂.∂./ "{f}"
set lb "`catenate "{f}".§`"
find /∂.∂./Δ:Δ/∂]/ "{f}"
set hb "`catenate "{f}".§`"
find / OF /Δ:Δ/;/ "{f}"
set sz "`catenate "{f}".§`"
set sz `"{me}" -sizeof "{sz}" "{f}"`
if "{lb}" !~ /[-0-9]+/
set lb "`"{me}" -calculate "{lb}" "{f}"`"
end
if "{hb}" !~ /[-0-9]+/
set hb "`"{me}" -calculate "{hb}" "{f}"`"
end
if !{packed} && ({sz} == 1)
set sz 2
end
( evaluate elemSize = (1 + hb - lb) * sz ) ∑ Dev:Null
else
set elemSize "`"{me}" -sizeof "{s1}" "{f}"`"
end
find {filePos} "{f}"
if `evaluate {elemSize} MOD 2`
( evaluate elemSize += 1 ) ∑ Dev:Null
end
echo {elemSize}
exit 0
else if "{1}" == "-valueof"
set s "{2}"
set f "{3}"
set v 0
set filePos "`position -c "{f}"`"
( evaluate "{filePos}" =~ /([0-9]+)®1,([0-9]+)®2/ ) ∑ Dev:Null
set filePos 'Δ1!'{®1}':Δ1!'{®2}
find • "{f}"
find /•[ ∂t]*{s}[ ∂t]*∂=[ ∂t]*/Δ:Δ/;/ "{f}"
set v "`catenate "{f}".§`"
find {filePos} "{f}"
if "{v}" =~ /$[0-9A-F]+/
echo "{v}"
exit 0
end
if "{v}" != /[-0-9]+/
set v "`"{me}" -calculate "{v}" "{f}"`"
end
echo "{v}"
exit 0
else ## do file(s)
set filesToDo ""
loop
break if "{1} " == " "
set filesToDo "{filesToDo}{1} "
shift 1
end
end
end
for f in {filesToDo}
open "{f}"
find • "{f}"
replace -c ∞ /∂:= UsingIncludes∂}∂n∂{∂$SETC UsingIncludes ∂:= 1∂}∂n+/ "∂:= UsingIncludes∂}∂n∂{∂$SETC UsingIncludes ∂:= 1∂}∂n∂n USES∂n" "{f}"
replace -c ∞ /∂{∂$IFC UNDEFINED ≈∂}∂n∂{∂$I (∂$∂$SHELL∂([¬∂)]+∂))«0,1»([¬.]+)®1.p∂}∂n∂{∂$ENDC∂}∂n(∂{[ ∂t]+≈∂}∂n)*/ "®1," "{f}"
if {status}
replace \• USES∂n\ "∂n" "{f}"
else
replace -c 1 \,\ ";∂n" "{f}"
find \• USES∂n\Δ "{f}"
echo -n " " >"{f}".§
find §Δ:Δ/;/ "{f}"
set s "`catenate "{f}".§`"
echo -n "{s}" >"{f}".§
end
find • "{f}"
replace -c ∞ /•∂{∂$PUSH∂}/ "∂{ ∂$PUSH∂}" "{f}"
find • "{f}"
replace -c ∞ /•∂{∂$ALIGN (≈)®1∂}/ "∂{ ∂$ALIGN ®1∂}" "{f}"
find • "{f}"
replace -c ∞ /•∂{∂$LibExport∂+∂}/ "∂{ ∂$LibExport∂+∂}" "{f}"
find • "{f}"
find /• +USES∂n /Δ "{f}"
if !{status} && ("{f}" !~ /Types.p/)
echo -n "ConditionalMacros, Types, " >>"{f}".§
end
find §Δ "{f}"
find Δ\?\ "{f}"
find Δ\?\ "{f}"
find /, Types/ "{f}"
if !{status}
echo -n "" >"{f}".§
end
find \• +USES∂n\ "{f}"
find /, ConditionalMacros/ "{f}"
if !{status}
echo -n "" >"{f}".§
end
find • "{f}"
find /,∂{∂$/ "{f}"
if {status} == 0
find Δ§ "{f}"
replace -c 1 /∂{∂$[¬∂}]+∂} +/ " " "{f}"
replace -c 1 /;∂n∂{∂$ENDC *∂}/ ";" "{f}"
end
find • "{f}"
replace -c ∞ /•([ ∂t]*PROCEDURE[ ∂t][¬∂;]+;[ ∂n∂t]+C;)®1/ "∂{®1∂}" "{f}"
find • "{f}"
replace -c ∞ /•([ ∂t]*FUNCTION[ ∂t][¬∂;]+;[ ∂n∂t]+C;)®1/ "∂{®1∂}" "{f}"
find • "{f}"
replace -c ∞ /•([ ∂t]*PROCEDURE[ ∂t][¬∂(]+∂([¬∂)]+∂)[¬;]*;[ ∂n∂t]*C;)®1/ "∂{®1∂}" "{f}"
find • "{f}"
replace -c ∞ /•([ ∂t]*FUNCTION[ ∂t][¬∂(]+∂([¬∂)]+∂)[¬;]*;[ ∂n∂t]*C;)®1/ "∂{®1∂}" "{f}"
find • "{f}"
replace -c 1 /•∂{∂$POP∂}/ "∂{ ∂$POP∂}" "{f}"
replace -c ∞ /•∂{∂$IFC NOT UsingIncludes∂}∂n([ ∂t]*)®1END∂.∂n∂{∂$ENDC∂}/ "∂{∂$IFC NOT UsingIncludes∂}∂n®1IMPLEMENTATION∂n®1END∂.∂n∂{∂$ENDC∂}" "{f}"
find • "{f}"
replace -c ∞ /•∂{∂$IFC UNDEFINED UsingIncludes∂}∂n∂{∂$SETC UsingIncludes := 0∂}∂n∂{∂$ENDC∂}∂n+/ "" "{f}"
find • "{f}"
replace -c ∞ /•∂{∂$IFC NOT UsingIncludes∂}∂n([¬∂{]+)®1∂{∂$ENDC∂}/ "®1" "{f}"
find • "{f}"
replace -c ∞ /•∂{∂$I[-+]∂}∂n∂{∂$SETC [¬ :]+Includes := UsingIncludes∂}∂n∂{∂$SETC UsingIncludes := 1∂}∂n+/ "" "{f}"
find • "{f}"
replace -c ∞ /•∂{∂$SETC UsingIncludes := [¬∂}]+Includes∂}∂n+/ "" "{f}"
find • "{f}"
loop
find /[0-9]+∂*∂*∂([¬∂)]+∂)/ "{f}"
break if {status}
set s "`catenate "{f}".§`"
( evaluate "{s}" =~ /[¬∂(]*(∂(+)®1[¬∂(]*/ ) ∑ Dev:Null
set v `echo -n "{®1}" | count -c`
loop
( evaluate v -= 1 ) ∑ Dev:Null
break if {v} == 0
find §:/∂)/ "{f}"
end
set s "`catenate "{f}".§`"
mark § '--TEMP--' "{f}"
( evaluate "{s}" =~ /([0-9]+)®1∂*∂*∂((≈)®2∂)/ ) ∑ Dev:Null
set m "{®1}"
set c "{®2}"
unset ®1 ®2
if "{c}" !~ /[0-9]+/
set c "`"{me}" -calculate "{c}" "{f}"`"
end
set v 1
loop
break if {c} == 0
( evaluate c -= 1 ) ∑ Dev:Null
( evaluate v = {v} * {m} ) ∑ Dev:Null
end
set v "`evaluate -h {v}`"
( evaluate "{v}" =~ /0x(≈)®1/ ) ∑ Dev:Null
set v `echo "00000000{®1}" | translate "a-f" "A-F"`
unset ®1
( evaluate "{v}" =~ /≈([0-9a-fA-F]«8»)®1/ ) ∑ Dev:Null
set v "${®1}"
unset ®1
find '--TEMP--' "{f}"
unmark '--TEMP--' "{f}"
echo -n "{v}" >"{f}".§
end
find • "{f}"
loop
find /ARRAY ∂[/ "{f}"
break if {status}
loop
find §Δ:Δ/∂.∂./ "{f}"
if "`catenate "{f}".§`" !~ /[0-9]+/
set s "`catenate "{f}".§`"
set s "`"{me}" -calculate "{s}" "{f}"`"
echo -n "{s}" >"{f}".§
end
find /∂.∂./Δ:Δ/[,∂]]/ "{f}"
if "`catenate "{f}".§`" !~ /[0-9]+/
set s "`catenate "{f}".§`"
set s "`"{me}" -calculate "{s}" "{f}"`"
echo -n "{s}" >"{f}".§
end
find /?/ "{f}"
break if "`catenate "{f}".§`" == ']'
end
end
find • "{f}"
loop
find /[ ∂t]+=[ ∂t]+[¬-∂'∂"]≈[-+∂/∂*]≈;/ "{f}"
break if {status}
find \[ ∂t∂n]\Δ:Δ/[ ∂t=]/ "{f}"
find /=[ ∂t]*/Δ:Δ/;/ "{f}"
set s "`catenate "{f}".§`"
#set echo 1;" MPW2TPas" -calculate "{s}" "{f}";set echo 0
set v "`"{me}" -calculate "{s}" "{f}"`"
echo -n "{v}" >"{f}".§
end
find • "{f}"
replace -c ∞ /eventMask: EventMask/ "evtMask: EventMask" "{f}"
find • "{f}"
replace -c ∞ /recordID: RecordID/ "recID: RecordID" "{f}"
find • "{f}"
replace -c ∞ /attribute: Attribute/ "attrib: Attribute" "{f}"
find • "{f}"
replace -c ∞ /timeScale: TimeScale/ "time_Scale: TimeScale" "{f}"
find • "{f}"
replace -c ∞ /packedDSSpec: PackedDSSpec/ "packed_DSSpec: PackedDSSpec" "{f}"
find • "{f}"
replace -c ∞ /flatInstrument: FlatInstrument/ "flatInstr: FlatInstrument" "{f}"
find • "{f}"
replace -c ∞ /noteRequest: NoteRequest/ "noteReq: NoteRequest" "{f}"
find • "{f}"
replace -c ∞ /noteChannel: NoteChannel/ "noteChan: NoteChannel" "{f}"
find • "{f}"
replace -c ∞ /instrumentData: InstrumentData/ "instrData: InstrumentData" "{f}"
find • "{f}"
replace -c ∞ /vblTaskPtr: VBLTaskPtr/ "vblTaskP: VBLTaskPtr" "{f}"
find • "{f}"
replace -c ∞ /object: / "obj: " "{f}"
find • "{f}"
replace -c ∞ /threadStyle: ThreadStyle/ "thrdStyle: ThreadStyle" "{f}"
find • "{f}"
replace -c ∞ /threadState: ThreadState/ "thrdState: ThreadState" "{f}"
find • "{f}"
replace -c ∞ /tmTaskPtr: TMTaskPtr/ "tmTaskP: TMTaskPtr" "{f}"
find • "{f}"
replace -c ∞ /$0([A-F][0-9A-F]«3»)®1/ "$®1" "{f}"
find • "{f}"
replace -c ∞ /∂(∂*∂±/ "∂( ∂*∂±" "{f}"
find • "{f}"
replace -c ∞ /(typedef pascal [¬∂(]+)®1∂(∂*/ "®1∂( ∂*" "{f}"
find • "{f}"
replace -c ∞ /∂(∂*/ "∂{" "{f}"
find • "{f}"
replace -c ∞ /∂*∂)/ "∂}" "{f}"
find • "{f}"
set commentDepth 0
set needMultiLineCommenting 0
loop
find /[∂{∂}]/ "{f}"
break if {status}
if "`catenate "{f}".§`" == "∂{"
if {commentDepth}
echo -n '(*' >"{f}".§
set needMultiLineCommenting 1
end
( evaluate commentDepth = {commentDepth} + 1 ) ∑ Dev:Null
else
( evaluate commentDepth = {commentDepth} - 1 ) ∑ Dev:Null
if {commentDepth}
echo -n '* )' >"{f}".§
else
if {needMultiLineCommenting}
find \∂{\:/∂}/ "{f}"
set nLines `count -l "{f}".§`
( evaluate nLines = {nLines} - 1 ) ∑ Dev:Null
find Δ§ "{f}"
replace -c {nLines} /∂n/ "∂}∂n∂{" "{f}"
set needMultiLineCommenting 0
find /∂}/ "{f}"
end
end
end
end
find • "{f}"
replace -c ∞ /∂*∂)∂}/ "∂* ∂)∂}" "{f}"
find • "{f}"
replace -c ∞ /(typedef pascal [¬∂(]+)®1∂( ∂*/ "®1∂(∂*" "{f}"
find • "{f}"
replace -c ∞ /∂( ∂*∂±/ "∂(∂*∂±" "{f}"
find • "{f}"
replace -c ∞ /(∂{[¬∂}∂n]«250»)®1(≈)®2/ "®1∂}∂n∂{®2" "{f}"
find • "{f}"
echo "∂{ Converted with MPW2TPas `date` ∂}" >"{f}".§
find • "{f}"
close -y "{f}"
setfile -c 'PJMM' -t 'TEXT' "{f}"
end
exit 0