Richard Lowe Jr
Richard Lowe Jr Home

College: STRTRK Program

Prev

Next

This program opened my eyes to a whole new level of programming: interfacing with the operating system itself.
1   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    !!                                                                   !!
    !!   DISK CLEANUP AND MAINTENANCE PROGRAM                            !!
    !!                                                                   !!
    !!     A PROGRAM WHICH REMOVES UNWANTED FILES FROM A SYSTEM DISK     !!
    !!                                                                   !!
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1

 
10	Extend\

 	On Error Goto 9000
15	U1$="\                  \     ######(#####)    \        \"
20	Dim Ex.acct$(20%), D.file$(20%), Ex.file$(25%)

 
22	Dim A%(30%),F1%(20%),F2%(20%)
26	C.total%=0% ! Deleted filesize accumulator

 
28  !

     !   PROGRAM FUNCTIONS: FNS.tand$, FNC.mp%, FNE$, FNA.num$

     !
30 ! Function to pack filname string into standard form for comparison
32	Def FNS.tand$(F.ilnam$)
34	    Q$=SYS(CHR$(6%)+CHR$(-10%)+F.ilnam$)\

 	    Change Q$ to A%
36	    P.roj%=A%(6%)\

 	    P.rog%=A%(5%)
38	    If P.roj%=0% AND P.rog%=0% Then 

 	       P$=MID(SYS(CHR$(6%)+CHR$(14%)),7%,2%)\

 	       P.roj%=ASCII(RIGHT(P$,2%))\

 	       P.rog%=ASCII(P$)
40	    If P.roj%=255% Then 

 	       P.j$="???"

 	    Else

 	       T$=NUM1$(P.roj%)\

 	       L5%=LEN(T$)\

 	       P.j$=RIGHT(("   "+T$),(L5%+1%))
42	    If P.rog%=255% Then 

 	       P.g$="???"

 	    Else

 	       T$=NUM1$(P.rog%)\

 	       P.g$=RIGHT(("   "+T$),(LEN(T$)+1%))
44	    F.name$=RAD$(A%(7%)+SWAP%(A%(8%)))+RAD$(A%(9%)+SWAP%(A%(10%)))
46	    E.xt$=RAD$(A%(11%)+SWAP%(A%(12%)))
48	    FNS.tand$=CHR$(91%)+P.j$+CHR$(44%)+P.g$+CHR$(93%)+

 	     F.name$+CHR$(46%)+E.xt$\

 	FNend
49  !

 
50 ! Function to compare two filname strings as prepared by above routine

 
52	Def FNC.mp%(F1$,F2$)\

 	    FNC.mp%=-1%
54	    Change F1$ to F1%\

 	    Change F2$ to F2%
56	    For C%=1% to 19%
58	        If F1%(C%)=63% OR F2%(C%)=63% Then 62

 	            ! Is either character a wild card
60	        If F1%(C%)<>F2%(C%) Then 

 	           FNC.mp%= 0%\

 	           Goto 64
62	    Next C%
64	FNend

 
70 ! Function to write error text

 
72	Def FNE$(E5%)=RIGHT(SYS(CHR$(6%)+CHR$(9%)+CHR$(E5%)),4%)

 
80 !  Function to get next sequential account from MFD

    !    Returns two character string of which ASCII values are the 

    !    Programmer-Project numbers.
82	DEF FNA.num$
83	    If I.x%>30% Then

 	       Get #2\

 	       I.x%=-1%
84	    I.x%=I.x%+1%\

 	    Field #2, (I.x%*16%+2%) as F.x$,8% as A.x$, (502%-I.x%*16%) as F.x2$
86	    Change A.x$ to A.x%
88	    If A.x%(7%)<>112% AND A.x%(8%)<>60% Then 83
90	    FNA.num$=LEFT(A.x$,2%)\

 	FNend
92 !

 
100 !

     !  Get information and set up the work arrays

     !
102	Print "DKCLN     "+RIGHT(SYS(CHR$(6%)+CHR$(9%)),3%)+"   "+DATE$(0%)+

 			"   "+TIME$(0%)\

 		Print
105	E%=1%
110	Print "Begin at Account";\

 	Input Line A$\

 	A$=LEFT(FNS.tand$(CVT$$(A$,38%)),9%)\

 	B1%=VAL(MID(A$,2%,3%))\

 	B2%=VAL(MID(A$,6%,3%))

 
115	E%=2%
120	Print "      to Account";\

 	Input Line A$\

 	A$=LEFT(FNS.tand$(CVT$$(A$,38%)),9%)\

 	F1%=VAL(MID(A$,2%,3%))\

 	F2%=VAL(MID(A$,6%,3%))
123 !

     !  Build work array for accounts to be skipped

     !
125	E%=3%
130	A$=""\

 	Print "Except Accounts";
140	Input Line A1$\

 	A$=A$+CVT$$(A1$,102%)
150	If RIGHT(A1$,(LEN(A1$)-1%))<>CHR$(13%)+CHR$(10%) Then 140

 	    !Allows multiple line entry until terminated by carriage return
160 !  Break string into working array
170	Ex.acct%=0%\

 	P1%=1%
180	P1%=INSTR(P1%,A$,"(")\

 	P2%=INSTR(P1%,A$,")")
190	If P1%=0% Then 250
200	If P2%=0% Then 

 	   Print "Unbalanced Parentheses in Command String"\

 	   Print "Try Again."\

 	   Goto 130
210	Ex.acct%=Ex.acct%+1%\

 	Ex.acct$(Ex.acct%)=LEFT(FNS.tand$(MID(A$,P1%,(P2%-P1%+1%))),9%)\

 	P1%=P2%+1%
220	If Ex.acct%<20% Then 180
230	Print "***Too many Accounts Entered--Truncated: "+RIGHT(A$,P1%)

 
250 !
255	E%=4%
260	A$=""\

 	Print "Delete Files";
270	Input Line A1$\

 	A$=A$+CVT$$(A1$,102%)+"," ! Delimiter added at end of each line
280	If RIGHT(A1$,(LEN(A1$)-1%)) <> CHR$(13%)+CHR$(10%) Then 270

 
300! Break it up
310	D.file%=0%
320	L%,C%=1% !Pointers in string
330	P1%=INSTR(C%,A$,"(")\

 	P2%=INSTR(C%,A$,")")\

 	C1%=INSTR(C%,A$,",")
340	If C1%=0% Then 400
350	If C1%=L% Then 

 	   L%,C%=L%+1%\

 	   Goto 330 !Double comma trap
360	If C1%>P1% AND C1%<P2% Then 

 	   C%=P2%+1%\

 	   Goto 330

 	    ! Check if comma between parentheses
370	D.file%=D.file%+1%\

 	D.file$(D.file%)=FNS.tand$(MID(A$,L%,(C1%-L%)))\

 	L%,C%=C1%+1%
380	If D.file%<20% Then 330
390	Print "Too many files--Truncated: "+RIGHT(A$,L%)

 
400 !

     ! Build work array for files to be passed over

     !
405	E%=5%
410	A$=""\

 	Print "Except files";
420	Input Line A1$\

 	A$=A$+CVT$$(A1$,102%)+","
430	If RIGHT(A1$,(LEN(A1$)-1%))<>CHR$(13%)+CHR$(10%) Then 420

 
450 ! Break it up
460	Ex.file$(1%)=FNS.tand$("[*,*]*.TMP")\

 	Ex.file$(2%)=FNS.tand$("[*,*]*.WRK")\

 	Ex.file$(3%)=FNS.tand$("[*,*]*.LOG")\

 	Ex.file$(4%)=FNS.tand$("[*,*]*.QUE")\

 	Ex.file$(5%)=FNS.tand$("[*,*]*.SYS")\

 	Ex.file%=5%

 	 ! Let's leave these alone, always
480	L%,C%=1%
490	P1%=INSTR(C%,A$,"(")\

 	P2%=INSTR(C%,A$,")")\

 	C1%=INSTR(C%,A$,",")
500	If C1%=0% Then 560
510	If C1%=L% Then 

 	   L%,C%=L%+1%\

 	   Goto 490
520	IF C1%>P1% AND C1%<P2% Then 

 	   C%=P2%+1%\

 	   Goto 490
530	Ex.file%=Ex.file%+1%\

 	Ex.file$(Ex.file%)=FNS.tand$(MID(A$,L%,(C1%-L%)))
540	L%,C%=C1%+1%\

 	If Ex.file%<25% Then 490
550	Print "***Too many files--Truncated: "+RIGHT(A$,L%)

 
555	E%=0%
558 !

     ! Options to delete zero length files

     !
560	Input "Delete Zero Length Files <Yes>"; A$\

 	A$=LEFT(CVT$$(A$,38%),1%)\

 	If A$="" OR A$="Y" Then 

 	   Z%=-1%

 	Else

 	   Z%=0%

 
562	Print "Listing to";\

 	Input Line L$\

 	L$=CVT$$(L$,102%)\

 	Open L$ as file #5

 	  !  Get listing file and open it

 
565 !

     ! Inspection option

     !
570	Input "Inspection <Yes>"; A$\

 	A$=LEFT(CVT$$(A$,38%),1%)\

 	If A$<>"N" Then 

 	   I.ns%=-1%

 	Else

 	   I.ns%=0%
572 !

     !  Option to detach job if inspection not being used.

     !
575	   F.det%=0%

 	      ! Flag to set when detached
580	   If NOT I.ns% Then

 	      Input "Detach <Yes>"; A$\

 	      If LEFT(CVT$$(A$,38%),1%)<>"N" Then

 	         F.det%=-1%\

 	         Print\

 	         Print "DETACHING. . ."\

 	         Q$=SYS(CHR$(6%)+CHR$(7%))

 
600 !

     ! Set up listing file and print headings

     !
620	Print #5, CHR$(12%)\

 	Print #5, STRING$(78%,42%)\

 	Print #5, "     Disk File Cleanup    "+DATE$(0%)+"     "+TIME$(0%)\

 	Print #5\

 	Print #5, "Starting Account: ["+NUM1$(B1%)+","+NUM1$(B2%)+"]"\

 	Print #5, "      to Account: ["+NUM1$(F1%)+","+NUM1$(F2%)+"]"
622	Print #5, "Except Accounts: "+Ex.acct$(1%);\

 	If Ex.acct%<2% Then

 	   Goto 625
623	For I%=2% to Ex.acct%\

 	    If POS(5%)<60% Then

 	       Print #5, ", ";

 	    Else

 	       Print #5\

 	       Print #5, TAB(18%);
624	    Print #5, Ex.acct$(I%);\

 	Next I%
625	Print #5\

 	Print #5\

 	Print #5, "Delete Files: "+D.file$(1%);\

 	If D.file%<2% Then

 	   Goto 629
626	For I%=2% to D.file%\

 	    If POS(5%)<60% Then

 	       Print #5, ", ";

 	    Else

 	       Print #5\

 	       Print #5, TAB(15%);
628	    Print #5, D.file$(I%);\

 	Next I%
629	Print #5\

 	Print #5
630	Print #5, "Except files: "+Ex.file$(1%);\

 	If Ex.file%<2% Then

 	   Goto 634
631	For I%=2% to Ex.file%\

 	    If POS(5%)<60% Then

 	       Print #5, ", ";

 	    Else

 	       Print #5\

 	       Print #5, TAB(15%);
632	    Print #5, Ex.file$(I%);\

 	Next I%
634	Print #5\

 	Print #5
636	If Z% Then 

 	   Print #5, "ZERO LENGTH Files to be deleted."\

 	   Print #5
640	Print #5, "Inspection Option is ";\

 	If Z% Then 

 	   Print #5, "Set"

 	Else

 	   Print #5, "Not Set"
645	Print #5\

 	Print #5, "Listing to: "; L$\

 	Print #5\

 	Print #5, STRING$(78%,42%)\

 	Print #5\

 	Print #5
700 !

     !  Account Search

     !
705	Open "SY:[1,1]" as file #2\

 	I.x%=10% ! Open MFD, Index set to skip [0,1],[1,1],[1,2],[1,3]
707	Get #2
710	Until 1<>1\

 	    A1$=FNA.num$\

 	    P1%=ASCII(RIGHT(A1$,2%))\

 	    P2%=ASCII(A1$)
720	    If P1%<B1% OR (P1%=B1% AND P2%<B2%) Then 900
730	    If P1%>F1% OR (P1%=F1% AND P2%>F2%) Then 1000
745	    A1$=LEFT(FNS.TAND$("("+NUM1$(P1%)+","+NUM1$(P2%)+")"),9%)
750	    If Ex.acct%=0% Then 770
760	    For I%=1% to Ex.acct%\

 	        If FNC.mp%(A1$,Ex.acct$(I%)) Then 900
765	    Next I%
770!

 
775 ! File Search

 
780	    FOR N2%=0% Until 1<>1\

 	        Q$=SYS(CHR$(6%)+CHR$(15%)+CHR$(N2%)+CHR$(SWAP%(N2%))+

 	         CHR$(P2%)+CHR$(P1%))\

 	        Change Q$ to A%\

 	        F3$=RAD$(A%(7%)+SWAP%(A%(8%)))+RAD$(A%(9%)+SWAP%(A%(10%)))\

 	        E3$=RAD$(A%(11%)+SWAP%(A%(12%)))\

 	        L%=A%(13%)+SWAP%(A%(14%))\

 	        DA%=A%(17%)+SWAP%(A%(18%))\

 	        F.Test$=FNS.tand$(A1$+F3$+"."+E3$)
782	        If A%(30%) Then 850
785	        If L%=0% Then 

 	           C.size%=4%\

 	           If Z% Then 800
787	        If L%>0% Then 

 	           C.size%=((L%-1%)/4%+1%)*4%
790	        For I%=1% to D.file%\

 	            If FNC.mp%(F.test$,D.file$(I%)) Then 800
792	        Next I%\

 	        Goto 850
800	        For I%=1% to Ex.file%\

 	            If FNC.mp%(F.test$,Ex.file$(I%)) Then 850
805	        Next I%
810	        If NOT(I.ns%) Then 830
815	        Print Using U1$, F.test$,L%,C.size%,DATE$(DA%);\

 	        Input A$\

 	        A$=LEFT(CVT$$(A$,38%),1%)
820	        If A$="C" Then 

 	           Print #5%, "*** CHECK ***  ";\

 	           Print #5%, Using U1$, F.test$,L%,C.size%,DATE$(DA%)\

 	           Goto 850
825	        If NOT(A$="Y" OR A$="K") Then 850
830	        KILL F.test$
835	        C.total%=C.total%+C.size%
840	        Print #5, Using U1$, F.test$,L%,C.size%,DATE$(DA%);\

 	        Print #5%, "  DELETED"
850	    Next N2%
900	Next
910 !

 
1000 !

      ! Print total line to listing file

      !
1010	Print #5\

 	Print #5\

 	Print #5, "Total of";C.total%;"Blocks freed."\

 	Print #5, CHR$(12%)
1050	Close I% For I%=1% to 12%
1055	If ((PEEK(PEEK(PEEK(PEEK(520%)))+2%) AND 255%)=(PEEK(518%) and 255%)

 	     AND

 	     (PEEK(PEEK(PEEK(PEEK(520%)))+6%) AND 8192%)=8192%)

 	       Then Goto 32767

 	       Else Q$=SYS(CHR$(6%)+CHR$(5%))

 	          !  Log out if job is running detached

 
1060	Goto 32767
1070 !

 
9000 !

      ! ERROR Handler

      !
9020	If ERL=610 Then 

 	   Print FNE$(ERR);"-- ";L$\

 	   Resume 610
9025	If ERR=11 AND ERL=86 Then 

 	   Resume 1000
9030	IF ERR=5 Then 

 	   If ERL=710 Then 

 	      Resume 1000

 	   Else

 	      If ERL=780 Then 

 	         Resume 900
9040	If ERR=2% AND ERL=34 Then 

 	   Print FNE$(2%);"-- ";F.ilnam$\

 	   If E%=1% Then 

 	      Resume 110

 	   Else

 	      If E%=2% Then 

 	         Resume 120

 	      Else

 	         If E%=3% Then 

 	            Resume 130

 	         Else

 	            If E%=4% Then 

 	               Resume 260

 	            Else

 	               If E%=5% Then 

 	                  Resume 410
9045	If ERR=52 Then 

 	   Print FNE$(52);"-- ";A$\

 	   Resume
9050	Print FNE$(ERR);" at line";ERL;"--Fatal"
9060	Print\

 	Resume 1050
32767	END

Unless otherwise noted, all photos and text is Copyright © Richard G Lowe, Jr.