'***************************************
'*                                     *
'* VerVerWal die Verzeichnisverwaltung *
'* ----------------------------------- *
'*                                     *
'* Autor  : Wolf-Gideon Bleek          *
'* Datum  : 11. Juli '88               *
'* Grueße : Frank Dz                   *
'* Version: 1.0                        *
'* Betriebssystem: V1.2 & V1.3         *
'*                                     *
'***************************************


LIBRARY ":bmaps/dos.library"

DECLARE FUNCTION Lock& LIBRARY
DECLARE FUNCTION Examine LIBRARY
DECLARE FUNCTION ExNext LIBRARY


LIBRARY ":bmaps/exec.library"

DECLARE FUNCTION AllocMem& LIBRARY

Info&    = 0

Typ&     = 2^16
Groesse& = 300

Suffix$  = "Keine Endung"

DIM Verz$(200), File$(200), Size$(200)

Info& = AllocMem&(Groesse&, Typ&)
OPEN "ram:temporary" FOR OUTPUT AS 255

OPEN "RAM:dir-list" FOR APPEND AS 1
CLOSE 1

MENU 1,0,1,"Daten    "
MENU 1,1,1,"Laden    "
MENU 1,2,1,"Speichern"
MENU 1,3,1,"ENDE     "

MENU 2,0,1,"Verzeichnis"
MENU 2,1,1,"Ergänzen   "
MENU 2,2,1,"Sortieren  "
MENU 2,3,1,"Auflisten  "
MENU 2,4,1,"Löschen    "

MENU 3,0,1,"Einstellungen"
MENU 3,1,1,"Endungen herausfiltern"


MENU 4,0,0,""

ON MENU GOSUB Auswahl
MENU ON

WHILE 1
    IF FileSpeicher& <> 0 THEN
    FreeMem(FileSpeicher&, Laenge&)
  END IF
  
SLEEP
WEND


Auswahl:
  HM = MENU(0)
  MP = MENU(1)
  
  FOR i = 1 TO 3
    MENU i, 0, 0
  NEXT i
  
  IF HM = 1 AND MP = 3 THEN
    MENU RESET
    CALL FreeMem(Info&, Groesse&)
    CLOSE 255
    LIBRARY CLOSE
    END      
  END IF
  
  IF HM = 1 AND MP = 1 THEN GOSUB Laden  
  IF HM = 1 AND MP = 2 THEN GOSUB Speichern
  
  IF HM = 2 AND MP = 1 THEN GOSUB GetVerz
  IF HM = 2 AND MP = 2 THEN GOSUB Sortieren
  IF HM = 2 AND MP = 3 THEN GOSUB Auflisten
  IF HM = 2 AND MP = 4 THEN GOSUB Loeschen
                                          
  IF HM = 3 AND MP = 1 THEN GOSUB NewSuffix
  
  
  PRINT
  PRINT "OK"
  PRINT
  
  FOR i = 1 TO 3
    MENU i,0,1
  NEXT i
    
  RETURN
  

Laden:
  PRINT "LADEN"
  PRINT
             
  PRINT "Bitte geben Sie den File-Namen ein!"
  PRINT
  INPUT "File-Name:";SourceFile$
                          
  IF SourceFile$ = "" THEN RETURN
  
  PRINT
  PRINT "File wird geladen ..."

  OPEN "RAM:dir-list" FOR OUTPUT AS 2
  OPEN SourceFile$ FOR INPUT AS 1
  
  WHILE(EOF(1)=0)
    
    INPUT#1, Verz$, File$, Size$
    PRINT#2, Verz$
    PRINT#2, File$
    PRINT#2, Size$
  
  WEND
  
  CLOSE 1
  CLOSE 2

  RETURN
  
  
Speichern:
  PRINT "SPEICHERN"
  PRINT
  
  PRINT "Bitte geben Sie den File-Namen ein!"
  PRINT
  INPUT "File-Name:";DestFile$
  
  IF DestFile$ = "" THEN RETURN
  
  PRINT
  PRINT "File wird gespeichert ..."

  OPEN "RAM:dir-list" FOR INPUT AS 1
  OPEN DestFile$ FOR OUTPUT AS 2
  
  WHILE(EOF(1)=0)
    
    INPUT#1, Verz$, File$, Size$
    PRINT#2, Verz$
    PRINT#2, File$
    PRINT#2, Size$
  
  WEND
  
  CLOSE 1
  CLOSE 2
  
  RETURN
  

GetVerz:
  PRINT "VERZEICHNIS DAZULADEN"
  PRINT
  
  PRINT "Bitte gben Sie den Pfade des Verzeichnisses ein!"
  PRINT
  INPUT "Verzeichnis-Name:";Verz$
  
  IF Verz$ = "" THEN RETURN

  PRINT
  PRINT "Verzeichnis wird eingelesen ..."
  PRINT
  
  Verz$  = Verz$ + CHR$(0)
  VerzL& = Lock&(SADD(Verz$), -2&)
  
  IF VerzL& <> 0 THEN
  
    OPEN "RAM:dir-list" FOR APPEND AS 1
    
    Status = Examine(VerzL&, Info&)
    PRINT "Verzeichnis: ";
    CALL Ausgabe(Info&, 255, "")
    Verzeichnis$ = File$
    
    Status = ExNext(VerzL&, Info&)
    
    WHILE(Status<>0)
    
      CALL Ausgabe(Info&, 1, Verzeichnis$)
      Status = ExNext(VerzL&, Info&)     
      
    WEND
  
    CLOSE 1
    
  ELSE
  
    PRINT "Verzeichnis nicht gefunden!"
    
  END IF
  
  RETURN


Sortieren:

  PRINT "VERZEICHNIS - Sortieren"
  PRINT
  
  OPEN "RAM:dir-list" FOR INPUT AS 1

  z = 0
  
  WHILE(EOF(1)=0)
    
    INPUT#1, Verz$(z), File$(z), Size$(z)
    z = z + 1
    
  WEND
  
  CLOSE 1
  
  FOR i = 0 TO z - 2
    k = i
    FOR j = i TO z - 1
      IF Verz$(j)+File$(j)<Verz$(k)+File$(k) THEN k = j
    NEXT j
    SWAP Verz$(i), Verz$(k)
    SWAP File$(i), File$(k)
    SWAP Size$(i), Size$(k)
  NEXT i
  
  OPEN "RAM:dir-LIST" FOR OUTPUT AS 1
  
  FOR i = 0 TO z - 1
    PRINT#1, Verz$(i)
    PRINT#1, File$(i)
    PRINT#1, Size$(i)
  NEXT i
  
  CLOSE 1
  
  RETURN


Auflisten:

  PRINT "VERZEICHNIS - LISTE AUSGEBEN"
  PRINT
  
  OPEN "RAM:dir-list" FOR INPUT AS 1

  WHILE(EOF(1)=0)
    
    INPUT#1, Verz$, File$, Size$
    PRINT Verz$;TAB(40);File$;TAB(70);Size$
  
  WEND
  
  CLOSE 1
  
  RETURN


Loeschen:
  
  PRINT "VERZEICHNIS - LÖSCHEN"
  PRINT
  PRINT "Wollen Sie wirklich alle Daten löschen?"
  
  INPUT "Antwort (J/N):";A$
  
  IF A$<>"J" THEN RETURN
  
  KILL "ram:dir-list"

  PRINT
  PRINT "Verzeichnis gelöscht!"

  OPEN "RAM:dir-list" FOR APPEND AS 1
  CLOSE 1
  
  RETURN
     

NewSuffix:

  PRINT "FILES mit ENDUNG AUSSCHLIEßEN"
  PRINT
  
  PRINT "Bitte geben Sie die Endung ein (";Suffix$;")"
  PRINT "oder tippen Sie RETURN für alle Files."
  PRINT
  
  INPUT "Suffix: ";Suffix$
  
  IF Suffix$ = "" THEN Suffix$ = "Keine Endung"
  
  RETURN
  
    
SUB Ausgabe(Mem&, Ch%, Verz$) STATIC
SHARED File$, Suffix$

  i = 8 : File$=""

  WHILE(PEEK(Mem&+i)<>0)
    File$ = File$ + CHR$(PEEK(Mem&+i))
    i = i + 1                       
    
  WEND
   
  IF RIGHT$(UCASE$(File$), LEN(Suffix$)) = UCASE$(Suffix$) THEN EXIT SUB
   
  PRINT File$;TAB(35);
  PRINT#Ch%, Verz$
  PRINT#Ch%, File$
          
  IF PEEKL(Mem&+4)<0 THEN
    PRINT PEEKL(Mem&+124);TAB(45);
    PRINT#Ch%, PEEKL(Mem&+124)
  ELSE
    PRINT " DIR";TAB(45);
    PRINT#Ch%, "DIR"
  END IF

  PRINT

END SUB
      
