WILDCARD.DEF 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. (* ========================================================= *)
  2. (* Preliminary library module for Gardens Point Modula *)
  3. (* This module is part of the gpm-pc distribution. It is *)
  4. (* required because the DOS shell does not expand wildcards. *)
  5. (* ========================================================= *)
  6. FOREIGN DEFINITION MODULE Wildcards;
  7. IMPORT IMPLEMENTATION FROM "wildcard.obj";
  8. IMPORT Types, UxFiles;
  9. TYPE FileAttrib = UxFiles.FileAttrib;
  10. (* rdOnly,hidden,system,volId,subDir,archive *)
  11. FileAttSet = UxFiles.FileAttSet;
  12. (* SET OF FilePermissionBits *)
  13. TYPE FfBlk = RECORD
  14. reserved : ARRAY [0 .. 21] OF CHAR;
  15. fftime : Types.Int16;
  16. ffdate : Types.Int16;
  17. ffsize : CARDINAL;
  18. ffname : ARRAY [0 .. 12] OF CHAR;
  19. END;
  20. PROCEDURE FileAttOf(ffBlk : FfBlk) : FileAttSet;
  21. (* extracts attribute set from the given FfBlk *)
  22. PROCEDURE FindFirst(pathNm : ARRAY OF CHAR;
  23. attrib : FileAttSet;
  24. VAR ffBlk : FfBlk;
  25. VAR found : BOOLEAN);
  26. PROCEDURE FindNext (VAR ffBlk : FfBlk;
  27. VAR found : BOOLEAN);
  28. END Wildcards.
  29. (* Examples of use:
  30. Here is a simple program which demonstrates usage of the WildCards library. It
  31. accepts arguments from the command line, and then finds any files that match
  32. these patterns in the current directory. A more complex example on the
  33. distribution is the source code for the compiler driver program gpd.mod}. This
  34. file demonstrates the use of both the WildCards and PcProcesses libraries.
  35. MODULE WildTest; (* demonstrates the Wildcards library *)
  36. FROM ProgArgs IMPORT ArgNumber, GetArg;
  37. FROM InOut IMPORT WriteString, WriteLn;
  38. FROM Wildcards IMPORT
  39. FileAttOf, FindFirst, FindNext, FileAttrib, FileAttSet, FfBlk;
  40. VAR ffblk : FfBlk;
  41. found : BOOLEAN;
  42. count : CARDINAL;
  43. VAR cArg : ARRAY [0 .. 79] OF CHAR;
  44. BEGIN
  45. FOR count := 1 TO ArgNumber() - 1 DO
  46. GetArg(count,cArg);
  47. WriteLn;
  48. WriteString("Command line arg -- ");
  49. WriteString(cArg);
  50. WriteLn;
  51. FindFirst(cArg, FileAttSet{direc}, ffblk, found);
  52. WHILE found DO
  53. WriteString(ffblk.ffname);
  54. IF subDir IN FileAttOf(ffblk) THEN WriteString(" <dir>") END;
  55. WriteLn;
  56. FindNext(ffblk,found);
  57. END; (* while *)
  58. END;
  59. END WildTest.
  60. The second example program uses the FileMode type of the DOS version of
  61. UxFiles to print information regarding the mode of named files. The program
  62. interactively accepts filenames from the user, looks up the files, displaying
  63. their attributes if found.
  64. The program displays the characters "r a s h" to indicate if the file has the
  65. read-only, archive, system, and hidden attributes. It is a simple exercise to
  66. combine the ideas of the two demonstration programs to print the attributes of
  67. files found as a result of wildcard lookups.
  68. MODULE ModeTest;
  69. IMPORT InOut, UxFiles;
  70. FROM InOut IMPORT Write;
  71. VAR str : ARRAY [0 .. 127] OF CHAR;
  72. ok : BOOLEAN;
  73. mod : UxFiles.FileMode;
  74. index : CARDINAL;
  75. BEGIN
  76. InOut.WriteString("File mode-test : type a filename, ^C to exit");
  77. InOut.WriteLn;
  78. LOOP
  79. InOut.WriteString(">> ");
  80. InOut.ReadString(str);
  81. UxFiles.GetMode(str,mod,ok);
  82. IF ok THEN
  83. IF UxFiles.subDir IN mod THEN
  84. InOut.WriteString("directory");
  85. ELSIF UxFiles.volId IN mod THEN
  86. InOut.WriteString("volume-ID");
  87. ELSE
  88. IF UxFiles.rdOnly IN mod THEN Write("r") ELSE Write(".") END;
  89. IF UxFiles.archive IN mod THEN Write("a") ELSE Write(".") END;
  90. IF UxFiles.system IN mod THEN Write("s") ELSE Write(".") END;
  91. IF UxFiles.hidden IN mod THEN Write("h") ELSE Write(".") END;
  92. END;
  93. ELSE InOut.WriteString("ModeTest: file not found");
  94. END;
  95. InOut.WriteLn;
  96. END;
  97. END ModeTest.
  98. *)