#
# d32trans - options processing, running d32cpp
#
Set Exit 0
Set CaseSensitive 0
#
Set TransOptions ""
Set CppOptions ""
set ErrlogFile Dev:StdErr
set TempDir "{DSP3210_Temp}"
Set progress 0
Set RunCpp 1

If "{DSP3210_AsmPP}" == ""
	set DSP3210_AsmPP "d32cpp"
End

Loop
	Break If {#} == 0
	If "{1}" =~ /-p/
		set TransOptions "{TransOptions} -p"
		Set progress 1
		shift 1
		continue
	Else If "{1}" =~ /-a/
		set RunCpp 0
		shift 1
		continue
	Else If "{1}" =~ /-e/ || "{1}" =~ /-errlog/
		set ErrlogFile "{2}"
		shift 2
		continue
	Else If "{1}" =~ /-c/
		set TransOptions "{TransOptions} -c"
		shift 1
		continue
	Else If "{1}" =~ /-w/
		set TransOptions "{TransOptions} -w"
		shift 1
		continue
	Else If "{1}"  =~ /-y/
		set TransOptions "{TransOptions} {1} '{2}'"
		If "{1}" !~ /≈:∞/
			Set TempDir "{1}:"
		Else
			Set TempDir "{1}"
		End
		shift 2
		continue
	Else If "{1}" =~ /-d/ || "{1}" =~ /-define/
		Set defines "{2}"
		Loop
			Break If "{defines}" !~ /([¬,]*)®1,[ ∂t]*(≈)®2/
			Set CppOptions "{CppOptions} -D'{®1}'"
			Set defines "{®2}"
		End
		Set CppOptions "{CppOptions} -D'{defines}'"
		shift 2
		continue
	Else If "{1}" =~ /-u/ || "{1}" =~ /-undef/
		Set undefines "{2}"
		Loop
			Break If "{undefines}" !~ /([¬,]*)®1,[ ∂t]*(≈)®2/
			Set CppOptions "{CppOptions} -U'{®1}'"
			Set undefines "{®2}"
		End
		Set CppOptions "{CppOptions} -U'{undefines}'"
		shift 2
		continue
	Else If "{1}" =~ /-i/ || "{1}" =~ /-include/
		Set includes "{2}"
		Loop
			Break If "{includes}" !~ /([¬,]*)®1,[ ∂t]*(≈)®2/
			Set CppOptions "{CppOptions} -I'{®1}'"
			Set includes "{®2}"
		End
		Set CppOptions "{CppOptions} -I'{includes}'"
		shift 2
		continue
	Else If "{1}" =~ /-use/
		d32trans_mac -use
		exit 0
	Else If "{1}" =~ /-≈/
		echo "{0}: Illegal option. Usage:" >Dev:StdErr
		d32trans_mac -use
		exit 1
    Else if "{infilename}" == ""
		set infilename "{1}"
		shift 1
		continue
	Else If "{outfilename}" == ""
		set outfilename "{1}"
		shift 1
		continue
	Else
		echo "{0}: too many filename arguments" > Dev:StdErr
		d32trans_mac -use
		exit 1
	End
End

If "{infilename}" == ""
	set infilename Dev:StdIn
	set outfilename Dev:StdOut
Else If "{outfilename}" == ""
	set outfilename "{infilename}.cvt"
End

If {RunCpp}
	If {progress}
		Echo "{DSP3210_AsmPP}{CppOptions} {infilename} > {TempDir}'d32trans.tmp' ≥ {ErrlogFile}"
	End
	{DSP3210_AsmPP} {CppOptions} {infilename} > {TempDir}'d32trans.tmp' ≥ {ErrlogFile}
	If {Status} > 0
		exit 1
	End
	if {progress}
		Echo "d32trans_mac {TransOptions} {TempDir}'d32trans.tmp' {outfilename} ≥≥ {ErrlogFile}"
    End
	d32trans_mac {TransOptions} {TempDir}'d32trans.tmp' {outfilename} ≥≥ {ErrlogFile}
	Set stat {Status}
	If {progress}
		echo "Delete {TempDir}'d32trans.tmp' ≥≥ {ErrlogFile}"
	End
    Delete {TempDir}'d32trans.tmp' ≥≥ {ErrlogFile}
	Exit {stat}
Else
	if {progress}
		Echo "d32trans_mac {TransOptions} {infilename} {outfilename} ≥≥ {ErrlogFile}"
    End
	d32trans_mac {TransOptions} {infilename} {outfilename} ≥≥ {ErrlogFile}
    Exit {Status}
End
Exit 0

