Path: utzoo!mnetor!uunet!husc6!purdue!i.cc.purdue.edu!j.cc.purdue.edu!ahh From: ahh@j.cc.purdue.edu (Brent L. Woods) Newsgroups: comp.sources.amiga Subject: foreach--executes commands multiply with wildcard expansion. 1 of 1. Message-ID: <6651@j.cc.purdue.edu> Date: 11 Mar 88 08:03:45 GMT Organization: Co-Moderators Unlimited. Lines: 129 Keywords: tested, shar file, part 1 of 1. Approved: ahh@j.cc.purdue.edu (Brent Woods) Program Name: foreach Submitted By: Jonas Flygare Summary: A program that allows multiple executions of a command with Amiga-style wildcards (even if the command doesn't support them). Poster Boy: Brent Woods (ahh@j.cc.purdue.edu) Tested. Part 1 of 1. NOTES: Brent Woods, Co-Moderator, comp.{sources,binaries}.amiga USENET: ...!j.cc.purdue.edu!ahh ARPANET: ahh@j.cc.purdue.edu BITNET: PODUM@PURCCVM PHONE: +1 (317) 743-8421 USNAIL: 320 Brown St., #406 / West Lafayette, IN 47906 ================================================================ # This is a shell archive. # Remove everything above and including the cut line. # Then run the rest of the file through sh. #----cut here-----cut here-----cut here-----cut here----# #!/bin/sh # shar: Shell Archiver # Run the following text with /bin/sh to create: # foreach.readme # foreach.c # This archive created: Wed Mar 9 15:42:58 1988 # By: Brent L. Woods (Co-Moderators Unlimited.) cat << \SHAR_EOF > foreach.readme (I would be surprised if this haven't been written already, it isn't that advanced, but I couldn't find it on my fishdisks.) Here is a small program I wrote in just about 1.5 hours, after being really fed up with having to do 15 compress just because compress won't accept wildcards. Argh! (I just got the sources, and have fixed that.. ;-) But, I found the program to be useful for other things, so I kept it around. It probably is full of bugs (it *is* short, but that never stopped me from writing buggy programs.. Try TECO if you want to produce more bugs with one line of code, than You thought was possible.. ) Anyway, You get the uuencoded executable, together with the source, and this file. That is just about all documentation You get. The program is called foreach, as in "foreach #?.c compress -v" which will run compress (with flag -v) on all files matching #?.c. It isn't blindingly fast, since I put a call to Execute in there. It isn't *that* slow either. Considering the time put into this You get it for free. (But when I write my *really* great program I'll have you pay through the nose to get it.. ;-) However.. If I should happen to recieve email regarding obvious bugs or great improvements, I would feel really happy. So please do. Here's how to reach me.. (first one preferred) jonasf@kuling.UUCP (domain: jonasf@kuling.uu.se) flax@suadb.UUCP (domain: flax@suadb.kth.se possibly .su.se) or: Jonas Flygare Vaktargatan 32 F:621 754 22 Uppsala SHAR_EOF cat << \SHAR_EOF > foreach.c #include #include #include #include /* Compiled with Lattice v4.0 */ void main(argc, argv) int argc; char **argv; { char *filestring; char *commandstring; int error; int i; struct FILEINFO info; int attr=0; /* One could really look more at the arguments more here... */ if (argc<3) { printf("Usage is %ls \n", argv[0]); exit(0); } /* Get filepattern and command to apply */ filestring=strdup(argv[1]); commandstring=strdup(argv[2]); /* Make sure command gets all the supplied args.. */ for(i=3;i