[comp.sys.amiga] Pattern-matching/Scripts

rouaix@inria.UUCP (05/26/87)

Here comes a new kind of scripts implementing pattern-matching for some
simple AmigaDOS commands.
You may have noticed that commands like TYPE do not support pattern-matching
in the file argument.
I would like to do: << type #?.c  >> for example.
As a replacement, I can now use:
	execute do type p #?.c
or 	execute do type DEVEL:foo/src/ p #?.(c|asm)
Syntax is:
execute do <CMD> [<DIR>] [p <PATTERN>]
which applies the command <CMD> (that has only one argument) to every file
matching the pattern <PATTERN> in the directory <DIR>.

Notes:
1) this is going to be slow unless you have the major commands on ram-disk.
2) you need EDIT. (I suppose many of you removed it due to lack of space 
	on the system disk)
3) if you give a directory name, it must end with a ":" or a "/" i.e
	ram: or sys:s/
4) the pattern is the same you would have used in << list p <PATTERN> >>

5) it is no fun designing command files for EDIT, but since it is
the only stream editor with this feature, I am forced to use it.
You can easily modify the script to allow commands with more than one
argument, or enhance it following your inspiration.

6) <CMD> may be "execute another_script". Try to write a Unix-like "mv" this 
way.

No Copyright, feel free to distribute .
Bugs/comments/flames -> rouaix@inria.inria.fr


Final note : use only original AmigaDOS commands for ECHO and CD in scripts.

This is it:
.key fun/a,direct,p/k
failat 20
if "<p>" eq ""
   list > ram:_d <direct> quick
else
   list > ram:_d <direct> p <p> quick
endif

if "<direct>" eq ""
echo  > ram:_f  "M**;P;D;W"
else
echo  > ram:_f  "D;=1;M**;P;D;W"
endif

echo > ram:_ed "0(A //echo ************File:/;from /ram:_c2/;N;A ,,<fun> <direct>,;from;N)"

edit from ram:_d to ram:_c with ram:_f ver ram:_v opt p300
if ERROR
skip abort
endif
copy ram:_c to ram:_c2
edit from ram:_c to ram:_ex with ram:_ed ver nil: opt p300
execute ram:_ex
skip done
lab abort
echo "No files"
lab done
delete > nil: ram:_#?

leivian@dover.UUCP (06/05/87)

In article <470@inria.UUCP> rouaix@inria.UUCP (Francois Rouaix) writes:
>You may have noticed that commands like TYPE do not support pattern-matching
>in the file argument.
>I would like to do: << type #?.c  >> for example.
just as a note, "less" from fish #74 allows you to do this one command
very nicely i.e. << less *.c >>, the rest of the comments on the general
case still apply --- less is "more" -- Bob L
-- 
Bob Leivian         Motorola, Dover Shores (CAD Support)  602-994-6778
 ...{mcdsun, sun}!sunburn!dover!leivian                   Mesa, AZ