home *** CD-ROM | disk | FTP | other *** search
EPOC OPL Source | 1998-08-30 | 3.7 KB | 157 lines |
-
-
- Rem du, an addon command for Shell5
- Rem Display the usage of a filesystem by directory
- Rem
- Rem Copyright (C) 1998 Nick Murray
- Rem
- Rem This program is free software; you can redistribute it and/or
- Rem modify it under the terms of the GNU General Public License
- Rem as published by the Free Software Foundation; either version 2
- Rem of the License, or (at your option) any later version.
- Rem
- Rem This program is distributed in the hope that it will be useful,
- Rem but WITHOUT ANY WARRANTY; without even the implied warranty of
- Rem MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- Rem See the GNU General Public License for more details.
- Rem
- Rem You should have received a copy of the GNU General Public License
- Rem along with this program; if not, write to the Free Software Foundation,
- Rem Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- Rem
- PROC du%:(n%)
- GLOBAL du_bad_count%
- LOCAL i%,buf$(255),ret%,flag%,tot&
- ONERR ErrTrap::
- i%=2
- WHILE i%<=n%
- buf$=PEEK$(argv&(i%))
- IF buf$="-s"
- flag%=1
- ELSE
- BREAK
- ENDIF
- i%=i%+1
- ENDWH
- IF i%>n% Rem no directories given
- buf$=_cwd$
- ENDIF
- DO
- du_bad_count%=0
- ret%=Fparse%:(ADDR(buf$),buf$)
- IF ret%<0
- PRINT PrPath$:(buf$),"-",err$:(ret%)
- RETURN
- ELSEIF ret% AND 16
- tot&=_du&:(buf$,flag%)
- IF flag% Rem NOTE: this IS printed when ESC breaks the recursion
- fprint%:(NUM$(tot&,-9)+" "+PrPath$:(buf$))
- ENDIF
- ENDIF
- IOYIELD
- IF _stat%<>-46
- IF _key%(1)=27
- BREAK
- ELSE
- KEYA(_stat%,_key%())
- ENDIF
- ENDIF
- i%=i%+1
- IF i%<=n%
- buf$=PEEK$(argv&(i%))
- ENDIF
- IF du_bad_count%
- PRINT "Warning:",du_bad_count%,"files were open and aren't included in the total."
- ENDIF
- UNTIL i%>n%
- RETURN
- ErrTrap::
- ONERR off
- PRINT err$:(ERR)
- RETURN ERR
- ENDP
-
- PROC _du&:(d$,flag%)
- LOCAL i$(255),ret%,tot&,p&,base&,h%,Fsize&,q&
- Rem this must be redesigned for psion5 as we can't use IOOPEN/IOW to read
- Rem directories. Instead build a linked list of contents of the directory and then
- Rem parse one entry at a time - when DIR$ will be safe again
- ONERR ErrTrap::
- Rem MUST flag that an error has occured and unroll all alloc "further down"
- Rem PRINT "Called:",d$
- base&=ALLOC(16)
- Rem base&=ALLOC&:(16,"du1")
- IF base&=0
- RAISE -10 Rem must catch this as we "collapse" down
- ENDIF
- p&=base&
- POKEL p&,0
- i$=DIR$(d$)
- WHILE LEN(i$)
- POKEL p&,ALLOC((LEN(i$)+20) AND $FFF0)
- Rem POKEL p&,ALLOC&:((LEN(i$)+20) AND $FFF0,"du2")
- Rem LEN + 1 + 15 + space for pointer
- IF PEEKL(p&)=0
- RAISE -10
- ENDIF
- p&=PEEKL(p&)
- POKEL p&,0
- POKE$ p&+4,i$
- Rem PRINT "Storing",i$,p&
- i$=DIR$("")
- IOYIELD
- IF _stat%<>-46
- IF _key%(1)=27
- GOTO Cleanup::
- ELSE
- KEYA(_stat%,_key%())
- ENDIF
- ENDIF
- ENDWH
- p&=PEEKL(base&)
- WHILE p&
- ret%=IOOPEN(h%,PEEK$(p&+4),$0600) Rem read-only, shared, random access
- Rem PRINT PEEK$(p&+4),ret%
- IF ret%=0 Rem files
- Fsize&=0
- IOSEEK(h%,2,Fsize&)
- tot&=tot&+Fsize&
- IOCLOSE(h%)
- ELSEIF ret%=-9 Rem file open
- du_bad_count%=du_bad_count%+1
- ELSE Rem -33 is a directory in Z!!
- tot&=tot&+_du&:(PEEK$(p&+4)+"\",flag%)
- ENDIF
- p&=PEEKL(p&)
- IOYIELD
- IF _stat%<>-46
- IF _key%(1)=27
- GOTO Cleanup::
- ELSE
- KEYA(_stat%,_key%(1))
- ENDIF
- ENDIF
- ENDWH
- IF flag%=0
- fprint%:(NUM$(tot&,-9)+" "+PrPath$:(d$))
- ENDIF
- GOTO Cleanup::
- ErrTrap::
- ONERR off
- tot&=ERR Rem flag error (will be <0)
- Cleanup::
- p&=PEEKL(base&)
- WHILE p&
- Rem PRINT p&,"Freeing:",PEEK$(p&+4)
- q&=PEEKL(p&)
- FREEALLOC(p&)
- Rem FREEALLOC&:(p&)
- p&=q&
- ENDWH
- FREEALLOC(base&)
- Rem FREEALLOC&:(base&)
- RETURN tot&
- ENDP
-
-
-