home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / m2t-2.zip / BAKLIST.MOD < prev    next >
Text File  |  1989-01-18  |  9KB  |  275 lines

  1. MODULE BakList;
  2.  
  3. (* This program is used to generate a list of all files in all     *)
  4. (* subdirectories except for the DOS files and the list file which *)
  5. (* this program generates.  The file FULLDISK.LST is created and   *)
  6. (* filled in the root directory of the default drive containing    *)
  7. (* the entire tree from the default subdirectory to all end points.*)
  8. (* If this program is called from the root directory, the tree for *)
  9. (* the entire default directory will be listed.  The resulting file*)
  10. (* can then be edited with any text editor to allow copying of all *)
  11. (* files or only selected files.                                   *)
  12. (*                                                                 *)
  13. (*         Copywrite (c) 1987, 1989 - Coronado Enterprises         *)
  14.  
  15.  
  16. FROM InOut         IMPORT WriteString,WriteCard,Write,WriteLn;
  17. FROM RealInOut     IMPORT WriteReal;
  18. FROM Real2Fil      IMPORT WriteStringFile,WriteLnFile;
  19. FROM DiskDirectory IMPORT CurrentDrive,CurrentDirectory;
  20. FROM Strings       IMPORT Concat,Copy,Length,Insert,CompareStr,
  21.                           Delete;
  22. FROM FileSystem    IMPORT Lookup,Close,File,Response;
  23. FROM SYSTEM        IMPORT AX,BX,CX,DX,SI,DI,ES,DS,CS,SS,SIZE,TSIZE,
  24.                           ADR,ADDRESS,GETREG,SETREG,SWI;
  25. FROM Storage       IMPORT ALLOCATE,DEALLOCATE;
  26. FROM DirHelps      IMPORT ReadFileStats,FileDataPointer,FileData;
  27.  
  28. VAR Drive        : CHAR;
  29.     StartingPath : ARRAY[0..64] OF CHAR;
  30.     FileList     : File;
  31.     DiskTransAdr : ARRAY[1..43] OF CHAR;
  32.  
  33.  
  34.  
  35.  
  36. (* This procedure selects the current drive and directory and opens*)
  37. (* the file named FULLDISK.LST to be used for recording all sub-   *)
  38. (* directories and filenames.                                      *)
  39.  
  40. PROCEDURE Initialize() : BOOLEAN;
  41. VAR StorageFile : ARRAY[0..20] OF CHAR;
  42. BEGIN
  43.    CurrentDrive(Drive);                 (* This generates the path *)
  44.    CurrentDirectory(Drive,StartingPath);(* used for the start of   *)
  45.    Insert(Drive,StartingPath,0);        (* the search.  It uses    *)
  46.    Insert(':',StartingPath,1);          (* the current drive and   *)
  47.    IF StartingPath[2] <> 000C THEN      (* path.                   *)
  48.       Insert('\',StartingPath,2);
  49.    END;
  50.  
  51.    StorageFile := ":\FULLDISK.LST";     (* This opens the file used*)
  52.    Insert(Drive,StorageFile,0);         (* to store the file-list. *)
  53.    Lookup(FileList,StorageFile,TRUE);   (* It is forced into the   *)
  54.    IF FileList.res = done THEN          (* root of the current     *)
  55.       RETURN(TRUE);                     (* directory.              *)
  56.    ELSE
  57.       RETURN(FALSE);
  58.    END;
  59. END Initialize;
  60.  
  61.  
  62.  
  63.  
  64. (* This procedure is used to store all of the data found into a    *)
  65. (* B-tree structure to be used in sorting the files and subdirec-  *)
  66. (* tories alphabetically.                                          *)
  67.  
  68. PROCEDURE StoreData(NewData         : FileDataPointer;
  69.                     VAR Files       : FileDataPointer;
  70.                     VAR Directories : FileDataPointer);
  71.      PROCEDURE AddToTree(VAR RootOfTree : FileDataPointer;
  72.                          VAR NewNode    : FileDataPointer);
  73.      VAR Result : INTEGER;
  74.      BEGIN
  75.         Result := CompareStr(RootOfTree^.Name,NewNode^.Name);
  76.         IF Result = 1 THEN
  77.            IF RootOfTree^.Left = NIL THEN
  78.               RootOfTree^.Left := NewNode;
  79.            ELSE
  80.               AddToTree(RootOfTree^.Left,NewNode);
  81.            END;
  82.         ELSE
  83.            IF RootOfTree^.Right = NIL THEN
  84.               RootOfTree^.Right := NewNode;
  85.            ELSE
  86.               AddToTree(RootOfTree^.Right,NewNode);
  87.            END;
  88.         END;
  89.      END AddToTree;
  90.  
  91.      PROCEDURE GoodFile(FileName : ARRAY OF CHAR) : BOOLEAN;
  92.      BEGIN
  93.         IF    CompareStr(FileName,"COMMAND.COM ") = 0 THEN
  94.            RETURN(FALSE);
  95.         ELSIF CompareStr(FileName,"IBMBIO.COM  ") = 0 THEN
  96.            RETURN(FALSE);
  97.         ELSIF CompareStr(FileName,"IBMDOS.COM  ") = 0 THEN
  98.            RETURN(FALSE);
  99.         ELSIF CompareStr(FileName,"FULLDISK.LST") = 0 THEN
  100.            RETURN(FALSE);
  101.         ELSE
  102.            RETURN(TRUE);
  103.         END;
  104.      END GoodFile;
  105.  
  106. VAR  Index   : CARDINAL;
  107. BEGIN
  108.    IF NewData^.Attr = 010H THEN         (* Attr = 10 for directory *)
  109.       IF NewData^.Name[0] <> "." THEN
  110.          IF Directories = NIL THEN
  111.             Directories := NewData;
  112.          ELSE
  113.             AddToTree(Directories,NewData);
  114.          END;
  115.       END;
  116.    ELSE                                    (* Otherwise a filename *)
  117.       IF GoodFile(NewData^.Name) THEN
  118.          IF Files = NIL THEN
  119.             Files := NewData;
  120.          ELSE
  121.             AddToTree(Files,NewData);
  122.          END;
  123.       ELSE
  124.          WriteString("File ignored here --->");
  125.          WriteString(NewData^.Name);
  126.          WriteLn;
  127.       END;
  128.    END;
  129. END StoreData;
  130.  
  131.  
  132.  
  133.  
  134. (* This procedure reads the file statistics from DOS and stores the*)
  135. (* data in a record for further use.                               *)
  136.  
  137. PROCEDURE ReadFileStatistics(VAR Files : FileDataPointer;
  138.                              VAR Directories : FileDataPointer;
  139.                              PathToFiles : ARRAY OF CHAR);
  140. TYPE MaskStore = ARRAY[0..70] OF CHAR;
  141. VAR SmallMask   : MaskStore;  (* Used for Directory output to file *)
  142.     MaskAndFile : MaskStore;          (* Used for file search name *)
  143.     MaskAddr    : ADDRESS;
  144.     Error       : BOOLEAN;
  145.     Index       : CARDINAL;
  146.     NewData     : FileDataPointer;
  147.     FirstFile   : BOOLEAN;
  148. BEGIN
  149.    WriteString(PathToFiles);
  150.    WriteLn;
  151.    Copy(PathToFiles,0,SIZE(PathToFiles),SmallMask);
  152.    Delete(SmallMask,0,2);
  153.    WriteStringFile(FileList,SmallMask);
  154.    WriteLnFile(FileList);
  155.    ALLOCATE(NewData,TSIZE(FileData));
  156.    FirstFile := TRUE;
  157.    Concat(PathToFiles,"/*.*",MaskAndFile);
  158.    ReadFileStats(MaskAndFile,FirstFile,NewData,Error);
  159.    IF NOT Error THEN
  160.       StoreData(NewData,Files,Directories);
  161.    END;
  162.  
  163.    REPEAT
  164.       ALLOCATE(NewData,TSIZE(FileData));
  165.       FirstFile := FALSE;
  166.       ReadFileStats(MaskAndFile,FirstFile,NewData,Error);
  167.       IF NOT Error THEN
  168.          StoreData(NewData,Files,Directories);
  169.       END;
  170.    UNTIL Error;
  171.  
  172. END ReadFileStatistics;
  173.  
  174.  
  175.  
  176.  
  177. (* This procedure lists all of the filenames alphabetically by     *)
  178. (* recursively tracing the B-tree described above.                 *)
  179.  
  180. PROCEDURE ListAllFiles(Files : FileDataPointer);
  181. VAR TempString : ARRAY[0..5] OF CHAR;
  182. BEGIN
  183.    IF Files <> NIL THEN
  184.       IF Files^.Left <> NIL THEN
  185.          ListAllFiles(Files^.Left);
  186.       END;
  187.          TempString := " ";
  188.          WriteStringFile(FileList,TempString);
  189.          WriteStringFile(FileList,Files^.Name);
  190.          WriteLnFile(FileList);
  191.       IF Files^.Right <> NIL THEN
  192.          ListAllFiles(Files^.Right);
  193.       END;
  194.    END;
  195. END ListAllFiles;
  196.  
  197.  
  198.  
  199.  
  200. (* This procedure searches all Subdirectory names found in a       *)
  201. (* search of a subdirectory for additional files and subdirector-  *)
  202. (* ies.  The search is recursive.                                  *)
  203.  
  204. PROCEDURE DoAllSubdirectories(StartPath : ARRAY OF CHAR;
  205.                               Directories : FileDataPointer);
  206. VAR NewPath : ARRAY[0..64] OF CHAR;
  207.     Index   : CARDINAL;
  208. BEGIN
  209.    IF Directories <> NIL THEN
  210.       IF Directories^.Left <> NIL THEN
  211.          DoAllSubdirectories(StartPath,Directories^.Left);
  212.       END;
  213.       IF Directories^.Name[0] <> '.' THEN
  214.          Copy(StartPath,0,64,NewPath);
  215.          Insert('\',NewPath,Length(NewPath));
  216.          Concat(NewPath,Directories^.Name,NewPath);
  217.          FOR Index := (SIZE(NewPath)-1) TO 1 BY -1 DO
  218.             IF NewPath[Index] = ' ' THEN
  219.                NewPath[Index] := 000C;
  220.             END;
  221.          END;
  222.          GetAllFilesAndDirectories(NewPath);
  223.       END;
  224.       IF Directories^.Right <> NIL THEN
  225.          DoAllSubdirectories(StartPath,Directories^.Right);
  226.       END;
  227.    END;
  228. END DoAllSubdirectories;
  229.  
  230.  
  231.  
  232. (* This procedure deletes a tree after it has completed its task   *)
  233. (* and is no longer of any use.                                    *)
  234.  
  235. PROCEDURE DeleteTree(Point : FileDataPointer);
  236. BEGIN
  237.    IF Point <> NIL THEN
  238.       DeleteTree(Point^.Left);
  239.       DeleteTree(Point^.Right);
  240.       DEALLOCATE(Point,TSIZE(FileData));
  241.    END;
  242. END DeleteTree;
  243.  
  244.  
  245.  
  246. (* This procedure searches a subdirectory for all files names and  *)
  247. (* additional subdirectories.                                      *)
  248.  
  249. PROCEDURE GetAllFilesAndDirectories(ThisPath : ARRAY OF CHAR);
  250. VAR DirExists   : BOOLEAN;           (* Temporary - use logic later*)
  251.     Files       : FileDataPointer;   (* Point to root of File tree *)
  252.     Directories : FileDataPointer;   (* Point to root of Dir tree  *)
  253. BEGIN
  254.    Files := NIL;
  255.    Directories := NIL;
  256.    ReadFileStatistics(Files,Directories,ThisPath);
  257.    ListAllFiles(Files);           (* List to a file for later use. *)
  258.    DoAllSubdirectories(ThisPath,Directories);
  259.    DeleteTree(Files);
  260.    DeleteTree(Directories);
  261. END GetAllFilesAndDirectories;
  262.  
  263.  
  264.  
  265.  
  266. BEGIN   (* Main program - BakList, Backup list *)
  267.    IF Initialize() THEN
  268.       GetAllFilesAndDirectories(StartingPath);
  269.       Close(FileList);
  270.    ELSE
  271.       WriteString("File named FULLDISK.LST cannot be opened");
  272.       WriteLn;
  273.    END;
  274. END BakList.
  275.