page%swap@Sun.COM (Bob Page) (11/13/89)
Submitted-by: utoddl@uncecs.edu (Todd M. Lewis) Posting-number: Volume 89, Issue 202 Archive-name: dos/fs/sweep.1 SWEEP takes CLI commands and executes them in the current directory and in all directories below the current directory. * The directory tree can be traversed top-down or bottom-up. * Multiple commands can be issued. * I/O streams can be redirected for SWEEP and the executed commands. [uuencoded executable included. ..bob] # This is a shell archive. # Remove anything above and including the cut line. # Then run the rest of the file through 'sh'. # Unpacked files will be owned by you and have default permissions. #----cut here-----cut here-----cut here-----cut here----# #!/bin/sh # shar: SHell ARchive # Run the following text through 'sh' to create: # makefile # sweep.c # sweep.doc # sweep.uu # This is archive 1 of a 1-part kit. # This archive created: Sun Nov 12 17:49:40 1989 echo "extracting makefile" sed 's/^X//' << \SHAR_EOF > makefile Xsweep: sweep.o X ln sweep.o -lc X Xsweep.o: sweep.c X cc sweep.c X SHAR_EOF echo "extracting sweep.c" sed 's/^X//' << \SHAR_EOF > sweep.c X#include <stdio.h> X#include <exec/memory.h> X#include <functions.h> X#include <libraries/dos.h> X#include <libraries/dosextens.h> X X#define MAXCMDLEN 1024L X Xint cmdTooLong; Xchar cmdstr[MAXCMDLEN+1]; /* This is where we put the command string. */ Xchar firstchar; /* '-' Do a pre-order tree traversal. */ X /* '+' Do a post-order tree traversal. (default) */ X /* '?' Show command usage. */ X /* Otherwise, it is part of the command string. */ X X/* NOTE: dos.library is openned by the compiler startup code. X * _cli_parse() is called during program startup to parse the command line. X * We don't really want the command line parsed, so we replace it with our own X * parser. This works with Manx C. I don't know what you would do to X * make it work with Lattice. X */ X Xvoid _cli_parse( pp, alen, aptr ) X struct Process *pp; /* Program's process structure */ X long alen; /* Length of the command string */ X char *aptr; /* The command string itself */ X { X long i, j; X char *p; X X p = aptr; X firstchar = *p; X j = alen; X X switch (*p) { X case '-' : X case '+' : X case '?' : p += 1; j -= 1; break; X default : ; X } X X if ( alen < MAXCMDLEN ) { X cmdTooLong = 0; X for( i=0; i<j; i++) /* Copy the pertinent parts of the command */ X cmdstr[i] = p[i]; /* string to our buffer. Make sure it fits. */ X cmdstr[i] = '\0'; /* Tack on a null char, just to be safe. */ X } X else X cmdTooLong = 1; X X } X X/* X * _wb_parse() is called by Manx startup. Since we are only running from X * the CLI, we can stub this out and reduce our program size. X */ X Xvoid _wb_parse() { } X X Xvoid Syntax() X{ X printf("Sweep: Execute CLI command(s) in current directory and all\n" X " subdirectories. tml 11/89\n\n"); X printf("USAGE: SWEEP [+|-|?] cmd [ + \n cmd... ]\n\n" X " '+' Do a post-order (bottom up) tree traversal. (default)\n" X " '-' Do a pre-order (top down) tree traversal.\n"); X printf(" '?' Show command usage. (this display)\n" X " cmd Command(s) you want executed in each directory.\n" X " Multiple commands can be issued as with the RUN command.\n"); X } X Xmain() X{ X X if (firstchar == '?') { X Syntax(); X exit(); X } X X doDir( "\0" ); X } X XdoDir( topDirName ) X char *topDirName; X { X struct FileLock *topLock, *tmpLock; X struct FileInfoBlock *fib; X X X /* Get a lock on the Current Directory */ X topLock = Lock( topDirName, ACCESS_READ ); X X if (topLock == NULL) { X return(); X } X X tmpLock = CurrentDir( topLock ); X X if (firstchar == '-') /* Do a pre-order traversal. */ X Execute( cmdstr , 0L, Output() ); X X /* The FileInfoBlock structure has to be long-word alligned, so */ X /* we should use AllocMem to insure this condition is met. */ X X fib = AllocMem( (long) sizeof( struct FileInfoBlock ), MEMF_PUBLIC ); X X if ( Examine( topLock, fib ) ) /* We know this is our mother dir, so */ X /* don't recurse on this one. */ X while ( ExNext( topLock, fib) ) { X if ( fib->fib_DirEntryType > 0 ) { /* It's a directory */ X doDir( fib->fib_FileName); X } X }; X X if (firstchar != '-') /* Do a Post-order traversal. */ X Execute( cmdstr , 0L, Output() ); X X FreeMem( fib, ( long ) sizeof ( struct FileInfoBlock ) ); X X topLock = CurrentDir( tmpLock ); X X UnLock( topLock ); X } X SHAR_EOF echo "extracting sweep.doc" sed 's/^X//' << \SHAR_EOF > sweep.doc XSWEEP is a CLI program which takes CLI commands and executes them in the Xcurrent directory and in all directories below the current directory. X X * The directory tree can be traversed in a pre-order (top down) fashion, X or in a post-order (bottom up) fashion. The latter is the default. X * Multiple commands can be issued in the same manner as with the RUN X command. X * Input and output can be redirected for SWEEP as well as for the X commands it executes. X XThe command syntax is: X SWEEP [+|-|?] cmd [+ <return> cmd] ... X X + As the first character, '+' forces the directory tree to be X traversed in a post-order (bottom up) fashion. This is the X default behavior, thus this parameter is useless. In this mode, X the command(s) will be executed in the lowest-level directories X first. X X - forces the directory tree to be traversed in a pre-order (top down) X fashion. In this mode, the command(s) will be executed in the X current directory first, then in the lower-level subdirectories. X X ? Causes the command syntax to be displayed. In this case, any X command is ignored. X XSome examples are in order. X X Assume we have a disk with the following directory structure: X Volume Name: MyDisk X (root) X / \ X Test Real X / \ / \ X A Q S T X / \ X / \ X B F X / | \ / \ X C D E G H X XSWEEP list Assuming our current directory is A, the list X command will be executed in the following X directories: C D E B G H F A X XSWEEP -list Assuming our current directory is A, the list X command will be executed in the following X directories: A B C D E F G H X XSWEEP s:spat protect #? -wed X This command would execute the spat script in all X the directories, making all the files and X directories read-only. X XSWEEP delete #? With A as our current directory, this will delete X all the files in C, then in D, then E, then X go to B and delete all B's files, including X the now-empty directories C, D, and E. It X then cleans out G, H, F (getting rid of the empty X G and H directories there) and finally back X to A to delete A's files and the two empty X directories B and F. Use with care! X XSWEEP -delete #? This command is just like the last one, but it X would not delete the directories that were X not empty from the start. This is because the X directory tree is traversed top-down. The delete X command in the A directory would remove all of A's X files, but because neither B nor F is empty, those X directories will remain. All the files in and below X A, however, would be deleted, just like the last X example. X XSWEEP >ram:EditMe -echo "*N" + Xcd + Xlist X Assume the F directory is our current directory. X This command would execute the echo, cd, and X list commands in each directory from the current X directory on down, in top-down fashon, producing a X file on RAM: called "EditMe" which could be printed X to provide a reference of what was on the disk. X It would look like this: X XMyDisk:Test/A/F X.info 76 ----rwed 30-Oct-89 21:12:37 XG Dir ----rwed 15-Jul-89 15:27:56 XH Dir ----rwed 24-Oct-88 19:04:37 XSomeFile 894 ----rwed 13-Aug-88 18:11:51 XAnotherFile 370 ----rwed 13-Aug-88 18:11:55 XSomeFile.info 894 ----rwed 13-Aug-88 18:12:05 X6 files - 2 directories - 9 blocks used X X XMyDisk:Test/A/F/G X.info 16 ----rwed 24-Oct-88 19:48:47 X1 file - 2 blocks used X X XMyDisk:Test/A/F/H XDirectory "current directory" is empty X X X X SHAR_EOF echo "extracting sweep.uu" sed 's/^X//' << \SHAR_EOF > sweep.uu X Xbegin 644 sweep XM```#\P`````````#``````````(```13```!J@````$```/I```$4T[Z`WI.4 XM5?_T*VT`$/_T(&W_]!E0AF$K;0`,__@@;?_T$!!(@$C`8`Q2K?_T4ZW_^&`8+ XM8!:0O````"MG[%6`9^B0O````!)GX&#H#*T```0```QL/$)L@EY"K?_\8!H@4 XM+?_\(&W_]"(M__Q#[()@$[`(`!@`4JW__"`M__RPK?_X;=P@+?_\0>R"8$(P. XM"`!@!CE\``&"7DY=3G5.50``3EU.=4Y5``!(>@`@3KH$@EA/2'H`CDZZ!'A8I XM3TAZ`1U.N@1N6$].74YU4W=E97`Z($5X96-U=&4@0TQ)(&-O;6UA;F0H<RD@* XM:6X@8W5R<F5N="!D:7)E8W1O<GD@86YD(&%L;`H@("`@("`@<W5B9&ER96-T* XM;W)I97,N("`@("`@("`@("`@("`@("`@("`@("`@("`@=&UL(#$Q+S@Y"@H`S XM55-!1T4Z(%-71450(%LK?"U\/UT@8VUD(%L@*R`*(&-M9"XN+B!="@H@)RLG& XM("!$;R!A('!O<W0M;W)D97(@*&)O='1O;2!U<"D@=')E92!T<F%V97)S86PN@ XM("`H9&5F875L="D*("<M)R`@1&\@82!P<F4M;W)D97(@("AT;W`@(&1O=VXI; XM('1R964@=')A=F5R<V%L+@H`("<_)R`@4VAO=R!C;VUM86YD('5S86=E+B`@L XM*'1H:7,@9&ES<&QA>2D*(&-M9"`@0V]M;6%N9"AS*2!Y;W4@=V%N="!E>&5C< XM=71E9"!I;B!E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HPB;P`$+&R&9D[N_H9,[P`#``0L;(9F3N[^C XMSB!O``0L;(9F3N[^@````^P````!`````0```_`````````#\@```^H```"6[ XM,#$R,S0U-C<X.6%B8V1E9@```"`@("`@("`@(#`P,#`P("`@("`@("`@("`@R XM("`@("`@D$!`0$!`0$!`0$!`0$!`0`P,#`P,#`P,#`Q`0$!`0$!`"0D)"0D)^ XM`0$!`0$!`0$!`0$!`0$!`0$!`0%`0$!`0$`*"@H*"@H"`@("`@("`@("`@("J XM`@("`@("`D!`0$`@``````````````````$``````0``````````````````P XM```!`0````$``````````````````````0(````!````````````````````' XM````````````````````````````````````````````````````````````` XM````````````````````````````````````````````````````````````` XM````````````````````````````````````````````````````````````` XM````````````````````````````````````````````````````````````` XM````````````````````````````````````````````````````````````` XM````````````````````````````````````````````````````````````` XM````````````````````````````````````````````````````````````` XM````````````````````````````````````````````````````````````` X?`````!0````````````````#\@```^L````!```#\@``M X`` Xend Xsize 5116 SHAR_EOF echo "End of archive 1 (of 1)" # if you want to concatenate archives, remove anything after this line exit