File extension is in extensions list: Difference between revisions

Content added Content deleted
(Added 11l)
m (→‎{{header|REXX}}: changed some variable names and comments.)
Line 1,517: Line 1,517:
=={{header|REXX}}==
=={{header|REXX}}==
This REXX version handles the extra credit requirement.
This REXX version handles the extra credit requirement.
<lang rexx>/*REXX program displays if a filename has a known extension (as per a list of EXTs).*/
<lang rexx>/*REXX pgm displays if a filename has a known extension (as per a list of extensions). */
$= 'zip rar 7z gz archive A## tar.bz2'; upper $ /*a list of "allowable" file extensions*/
$= 'zip rar 7z gz archive A## tar.bz2'; upper $ /*a list of "allowable" file extensions*/
parse arg fn /*obtain optional argument from the CL.*/
parse arg fn /*obtain optional argument from the CL.*/
@.= /*define the default for the @. array.*/
@.= /*define the default for the @. array.*/
if fn\='' then @.1 = strip(fn) /*A filename specified? Then use it. */
if fn\='' then @.1 = strip(fn) /*A filename specified? Then use it. */
else do; @.1 = "MyData.a##" /* else use list*/
else do; @.1 = "MyData.a##" /*No " " Else use list*/
@.2 = "MyData.tar.Gz"
@.2 = "MyData.tar.Gz"
@.3 = "MyData.gzip"
@.3 = "MyData.gzip"
Line 1,531: Line 1,531:
@.8 = "MyData_v1.0.bz2"
@.8 = "MyData_v1.0.bz2"
end
end
#=words($)
#= words($)


do j=1 while @.j\=='' /*traipse through @ list of file exts.*/
do j=1 while @.j\==''; @@= @.j; upper @@ /*traipse through @ file extension list*/
file=@.j; upper file /*get a filename; and then uppercase it*/
do k=1 for # until right(@@, L)==x /*Search $ list, is extension in list? */
x= . || word($, k); L=length(x) /*construct the extension of the file. */

do k=1 for # until right(file, length(x) )==x /*Search $ list, is ext in list?*/
x=. || word($, k) /*construct the extension of the file. */
end /*k*/ /* [↓] display file, and a nay or yea.*/
end /*k*/ /* [↓] display file, and a nay or yea.*/
say right(@.j, 40) ' ' right( word( "false true", 1 + (k<=#) ), 5)

say right(@.j, 40) ' ' right( word( "false true", 1 + (k<=#) ), 5)
end /*j*/ /*stick a fork in it, we're all done. */</lang>
end /*j*/ /*stick a fork in it, we're all done. */</lang>
{{out|output|text=&nbsp; when using the default input:}}
{{out|output|text=&nbsp; when using the default input:}}