home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d3xx / d325 / batchman.lha / Batchman / Code / DosStuff.mod < prev   
Text File  |  1990-02-27  |  3KB  |  135 lines

  1. (* Copyright 1988 Michal Todorovic *)
  2. (* For non-commercial use only.    *)
  3.  
  4. IMPLEMENTATION MODULE DosStuff;
  5.  
  6. FROM System        IMPORT argc, argv;
  7. FROM FileSystem    IMPORT ReadChar, Lookup, Close, File,
  8.                           done;
  9. FROM TermInOut     IMPORT WriteString;
  10.  
  11.  
  12.  
  13.  
  14. (**********************************************************)
  15. (* Gets the next string from the file.                    *)
  16. (**********************************************************)
  17. PROCEDURE GetNext(VAR InFile : File; 
  18.                   VAR Info   : ARRAY OF CHAR;
  19.                   Num        : CARDINAL) : BOOLEAN;
  20.  
  21. VAR
  22.   Counter  : CARDINAL;
  23.   C        : CHAR;
  24.   Done     : BOOLEAN;
  25.  
  26. BEGIN
  27.   Counter := 0;
  28.   Done    := TRUE;
  29.  
  30.   REPEAT
  31.     ReadChar(InFile, C)
  32.   UNTIL (((ORD(C) <> 10)AND(ORD(C) <> 32)) OR InFile.eof);
  33.  
  34.   IF InFile.eof THEN 
  35.     RETURN FALSE 
  36.   END;
  37.  
  38.   WHILE (NOT(InFile.eof) AND Done) DO
  39.     IF (ORD(C) = 10) OR (ORD(C) = 32) THEN
  40.       Done := FALSE
  41.     ELSE 
  42.       IF Counter < Num THEN
  43.         Info[Counter] := C;
  44.         INC(Counter);
  45.         ReadChar(InFile, C)
  46.       ELSE 
  47.         RETURN FALSE
  48.       END
  49.     END
  50.   END;
  51.   RETURN TRUE
  52. END GetNext;
  53.  
  54.  
  55.  
  56.  
  57.  
  58. (**********************************************************)
  59. (* Gets the single character 'C' or 'R' or 'Q' (upper or  *)
  60. (* lower case)                                            *)
  61. (**********************************************************)
  62. PROCEDURE GetNextChar (VAR InFile : File; VAR C : CHAR)
  63.                       : BOOLEAN;
  64.  
  65. BEGIN
  66.   REPEAT
  67.     ReadChar(InFile, C)
  68.   UNTIL (((ORD(C) <> 10)AND(ORD(C) <> 32)) OR InFile.eof); 
  69.   IF InFile.eof THEN 
  70.     RETURN FALSE 
  71.   END;
  72.   C := CAP(C);
  73.   RETURN ((C = 'C') OR (C = 'R') OR (C = 'Q'))
  74. END GetNextChar;
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81. (**********************************************************)
  82. (* Gets all the information from the configuration file.  *)
  83. (**********************************************************)
  84. PROCEDURE GetInfo(VAR Paths  : ARRAY OF LongString;
  85.                   VAR Name   : ARRAY OF ShortString;
  86.                   VAR Memory : ARRAY OF CHAR; 
  87.                   VAR Num    : CARDINAL) : BOOLEAN;
  88.  
  89. VAR 
  90.   Counter  : CARDINAL;
  91.   InFile   : File;
  92.   Check1,
  93.   Check2,
  94.   Check3   : BOOLEAN;
  95.  
  96. BEGIN
  97.   Check1  := TRUE;
  98.   Check2  := TRUE;
  99.   Check3  := TRUE;
  100.   Counter := 0;
  101.  
  102.   IF (argc > 1) THEN
  103.     (* Find user specified file *)
  104.     Lookup(InFile,argv^[1]^, FALSE)
  105.   ELSE
  106.     (* Find default file *)
  107.     Lookup(InFile,"S:Batchman.dat", FALSE)
  108.   END;
  109.  
  110.   IF (InFile.res = done) THEN
  111.     WHILE Check1 AND Check2 AND Check3
  112.                             AND (Counter <= MaxGadgets) DO
  113.       Check1 := GetNext(InFile, Paths[Counter], 100);
  114.       Check2 := GetNext(InFile, Name[Counter],  15);
  115.       Check3 := GetNextChar(InFile, Memory[Counter]);
  116.       INC(Counter)
  117.     END;
  118.  
  119.     Close(InFile);
  120.  
  121.     Num   := Counter - 1;
  122.     RETURN (Check1 = Check2) AND (Check1 = Check3)
  123.  
  124.   ELSE 
  125.     WriteString("\n\nI couldn't open your input file\n\n");
  126.     RETURN FALSE
  127.   END
  128. END GetInfo;
  129.   
  130.  
  131.  
  132.  
  133.  
  134. END DosStuff.
  135.