107 lines
3.7 KiB
Plaintext
107 lines
3.7 KiB
Plaintext
_window = 1
|
|
begin enum 1
|
|
_userStringFld
|
|
_validateBtn
|
|
_resultsStringFld
|
|
end enum
|
|
|
|
void local fn BuildWindow
|
|
window _window, @"Abbreviations, simple", (0,0,600,268)
|
|
WindowSetContentMinSize( _window, fn CGSizeMake( 200, 268 ) )
|
|
WindowSetContentMaxSize( _window, fn CGSizeMake( 10000, 268 ) )
|
|
|
|
textfield _userStringFld,, @"riG rePEAT copies put mo rest types fup. 6 poweRin", (20,152,560,96)
|
|
TextFieldSetPlaceholderString( _userStringFld, @"Enter commands" )
|
|
ViewSetAutoresizingMask( _userStringFld, NSViewWidthSizable )
|
|
|
|
button _validateBtn,,, @"Validate", (259,117,83,32)
|
|
ViewSetAutoresizingMask( _validateBtn, NSViewMinXMargin + NSViewMaxXMargin )
|
|
|
|
textfield _resultsStringFld,,, (20,20,560,96)
|
|
TextFieldSetEditable( _resultsStringFld, NO )
|
|
TextFieldSetSelectable( _resultsStringFld, YES )
|
|
ViewSetAutoresizingMask( _resultsStringFld, NSViewWidthSizable )
|
|
end fn
|
|
|
|
local fn Commands as CFArrayRef
|
|
CFStringRef cmd, string
|
|
long abbrLen
|
|
CFMutableArrayRef commands = fn MutableArrayNew
|
|
ScannerRef scanner
|
|
|
|
string = @" add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 Schange Cinsert 2 Clast 3"
|
|
string = concat( string, @" compress 4 copy 2 count 3 Coverlay 3 cursor 3 delete 3 Cdelete 2 down 1 duplicate" )
|
|
string = concat( string, @" 3 xEdit 1 expand 3 extract 3 find 1 Nfind 2 Nfindup 6 NfUP 3 Cfind 2 findUP 3 fUP 2" )
|
|
string = concat( string, @" forward 2 get help 1 hexType 4 input 1 powerInput 3 join 1 split 2 spltJOIN load" )
|
|
string = concat( string, @" locate 1 Clocate 2 lowerCase 3 upperCase 3 Lprefix 2 macro merge 2 modify 3 move 2" )
|
|
string = concat( string, @" msg next 1 overlay 1 parse preserve 4 purge 3 put putD query 1 quit read recover 3" )
|
|
string = concat( string, @" refresh renum 3 repeat 3 replace 1 Creplace 2 reset 3 restore 4 rgtLEFT right 2 left" )
|
|
string = concat( string, @" 2 save set shift 2 si sort sos stack 3 status 4 top transfer 3 type 1 up 1" )
|
|
|
|
scanner = fn ScannerWithString( string )
|
|
while ( fn ScannerIsAtEnd( scanner ) == NO )
|
|
if ( fn ScannerScanUpToCharactersFromSet( scanner, fn CharacterSetWhitespaceAndNewlineSet, @cmd ) )
|
|
abbrLen = 0
|
|
fn ScannerScanInteger( scanner, @abbrLen )
|
|
MutableArrayAddObject( commands, @{@"cmd":cmd,@"len":@(abbrLen)} )
|
|
end if
|
|
wend
|
|
end fn = commands
|
|
|
|
void local fn Validate
|
|
CFArrayRef commands, words
|
|
CFStringRef userString, result, wd, cmd
|
|
long wordCount, i, wordLen, abbrLen
|
|
CFMutableStringRef results
|
|
CFDictionaryRef dict
|
|
BOOL found
|
|
|
|
commands = fn Commands
|
|
userString = fn ControlStringValue( _userStringFld )
|
|
words = fn StringComponentsSeparatedByCharactersInSet( userString, fn CharacterSetWhitespaceAndNewlineSet )
|
|
results = fn MutableStringNew
|
|
wordCount = len( words )
|
|
|
|
for i = 0 to wordCount - 1
|
|
found = NO
|
|
result = @"*error* "
|
|
wd = words[i]
|
|
wordLen = len( wd )
|
|
if ( wordLen )
|
|
|
|
for dict in commands
|
|
cmd = dict[@"cmd"]
|
|
abbrLen = fn NumberIntegerValue(dict[@"len"])
|
|
|
|
if ( abbrLen != 0 and wordLen >= abbrLen )
|
|
found = fn StringHasPrefix( lcase( cmd ), lcase( wd ) )
|
|
else
|
|
found = fn StringIsEqual( lcase( cmd ), lcase( wd ) )
|
|
end if
|
|
|
|
if ( found )
|
|
result = fn StringWithFormat( @"%@ ",ucase( cmd ) )
|
|
break
|
|
end if
|
|
next
|
|
|
|
MutableStringAppendString( results, result )
|
|
end if
|
|
next
|
|
|
|
ControlSetStringValue( _resultsStringFld, results )
|
|
end fn
|
|
|
|
void local fn DoDialog( ev as long, tag as long )
|
|
select ( ev )
|
|
case _btnClick : fn Validate
|
|
end select
|
|
end fn
|
|
|
|
editmenu 1
|
|
fn BuildWindow
|
|
|
|
on dialog fn DoDialog
|
|
|
|
HandleEvents
|