01-06-2009, 01:55 PM
This macro converts recorded mou commands to editable format.
Macro
Trigger @11
(can be any trigger)
Function ConvertRecordedMouString
Macro
Trigger @11

;Select recorded mou "..." command in QM editor, and run this macro.
;It replaces the selection to multiple mou- x y commands.
;Can be selected more than one line. Can contain other commands. For example you can select whole macro.
str s1.getsel s2 so
ARRAY(str) a
int r
foreach s2 s1
,if(findrx(s2 "^([[9],]*)mou ''(.+?)''$" 0 0 a)>=0)
,,ConvertRecordedMouString a[2] so a[1]; err mes- "failed to convert" "" "x"
,,r=1
,else
,,so.addline(s2)
if(r) so.setsel
else mes- "There are no mou ''...'' commands in the selected text." "" "!"
Function ConvertRecordedMouString
;/
function $s str&so [$prefix]
;Converts recorded mou command, where it is in format mou "...", to multiple mou- x y commands.
;s - input string.
;so - output string.
;prefix - a string to prepend to each line.
int i j x y isy c w; str ss
for j 0 1000000
,c=s[0]
,;out s
,sel c
,,case 0 break
,,
,,case ['+','-']
,,for isy 0 2
,,,s+1
,,,for(i 0 100) if(!isdigit(s[i])) break
,,,if(i=0) end ES_BADARG
,,,y=val(ss.left(s i)); if(s[-1]=='-') y=-y
,,,if(!isy) x=y; if(s[i]!='+' && s[i]!='-') end ES_BADARG
,,,s+i
,,s-1
,,so.formata("%smou- %i %i[]" prefix x y)
,,
,,case ['w','f'] ;;wait, factor
,,if(!isdigit(s[1])) goto g1
,,s+1
,,for(i 1 100) if(!isdigit(s[i])) break
,,w=val(ss.left(s i))
,,if(w) so.formata("%s%g%s[]" prefix w*0.001 iif(s[-1]='f' "*F" ""))
,,s+i-1
,,
,,case else
,,;g1
,,if(c!='@' and !isalpha(c)) end ES_BADARG
,,x=iif(c<=90 (c-64) -(c-96)); s+1; c=s[0]
,,y=iif(c<=90 (c-64) -(c-96))
,,so.formata("%smou- %i %i[]" prefix x y)
,
,s+1