Jump to content

Abbreviations, easy: Difference between revisions

→‎{{header|REXX}}: ooRRexx conformance and readable
imported>RegalCode
(→‎{{header|REXX}}: ooRRexx conformance and readable)
Line 3,218:
 
=={{header|REXX}}==
<syntaxhighlight lang="rexx">/*REXX program validates a user "word" words against a "command table" with abbreviations.*/
parse arg uw Parse Arg userwords /*obtain optional arguments from the CLcommand line */
ifIf uwuserwords='' Then then uw= 'riG rePEAT copies put mo rest/* nothing specified, use typesdefault list from fup.task 6 poweRin'*/
userwords= 'riG rePEAT copies put mo rest types fup. 6 poweRin'
saySay 'user words: ' uwuserwords
 
@keyws= 'Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy' ,
'COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find' ,
'NFind NFINDUp NFUp CFind FINdup FUp FOrward GET Help HEXType Input POWerinput' ,
'Join SPlit SPLTJOIN LOAD Locate CLocate LOWercase UPPercase LPrefix MACRO' ,
'MErge MOve MODify MSG Next Overlay PARSE PREServe PURge PUT PUTD Query QUIT' ,
'READ RECover REFRESH RENum REPeat Replace CReplace RESet RESTore RGTLEFT' ,
'RIght LEft SAVE SET SHift SI SORT SOS STAck STATus TOP TRAnsfer Type Up'
Say 'full words: ' validate(userwords) /*display the result(s) To the terminal*/
 
sayExit 'full words: ' validate(uw) /*displaystick thea result(s)fork in it, we're toall theDone. terminal*/
/*----------------------------------------------------------------------------------*/
exit /*stick a fork in it, we're all done. */
validate: Procedure Expose keyws
/*──────────────────────────────────────────────────────────────────────────────────────*/
validate: procedure exposeArg userwords @; arg x; upper @ /*ARG Arg = capitalizesParse allUpper theArg get Xuserwords in words.uppercase */
res='' $= /* initialize the return string To null /*initialize the return string to null.*/
Do j=1 To words(userwords) /* loop through userwords do j=1 to words(x); _=word(x, j) /*obtain a word from the X list. */
uword=word(userwords,j) /* get next userword do k=1 to words(@); a=word(@, k) /*get a legitimate command name from @.*/
Do k=1 To words(keyws) /* loop through all keywords */
L=verify(_, 'abcdefghijklmnopqrstuvwxyz', "M") /*maybe get abbrev's len.*/
keyw=word(keyws,k)
if L==0 then L=length(_) /*0? Command name can't be abbreviated*/
L=verify(_keyw, 'abcdefghijklmnopqrstuvwxyz', "'M"') /*maybe getpos. abbrev'sof len.first lowercase ch*/
if abbrev(a, _, L) then do; $=$ a; iterate j; end /*is valid abbrev?*/
If L==0 Then end /*k keyword is all uppercase */
L=length(keyw) $=$ '*error*' /* we need L characters for a match /*processed the whole list, not valid. */
end /*j*/Else
L=L-1 return strip($) /* number of uppercase characters /*elide the superfluous leading blank. */</syntaxhighlight>
If abbrev(translate(keyw),uword,L) Then Do /* uword is an abbreviation */
res=res keyw /* add the matching keyword To the result string */
iterate j /* and proceed with the next userword if any */
End
End
res=res '*error*' /* no match found. indicate error */
End
Return strip(res) /* get rid of leading böank */
syntaxhighlight>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
2,295

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.