directory.sl 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. %
  2. % Directory.SL - File Directory and related file primitives
  3. %
  4. % Author: Alan Snyder
  5. % Hewlett-Packard/CRC
  6. % Date: 13 July 1982
  7. %
  8. % *** THIS FILE IS TOPS-20 SPECIFIC ***
  9. %
  10. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  11. (BothTimes (load common jsys useful))
  12. (de find-matching-files (filename include-deleted-files)
  13. % Return a list describing all files that match the specified filename. The
  14. % filename may specify a directory and/or may contain wildcard characters.
  15. % Each element of the returned list corresponds to one matching file. The
  16. % format of each list element is:
  17. % (file-name full file name string
  18. % deleted-flag T or NIL
  19. % file-size integer count of pages in file
  20. % write-date integer representing date/time of last write
  21. % read-date integer representing date/time of last read
  22. % )
  23. (setf filename (fixup-directory-name filename))
  24. (let (jfn-word jfn file-name deleted-flag file-size write-date read-date)
  25. (cond
  26. ((and (stringp filename) (listp (setf jfn-word (ErrorSet
  27. (list 'jsys1
  28. (if include-deleted-files
  29. #.(bits 2 8 11 13 17)
  30. #.(bits 2 11 13 17))
  31. filename 0 0 (const jsGTJFN)) nil nil))))
  32. (setf jfn-word (first jfn-word))
  33. (for*
  34. (while (>= jfn-word 0))
  35. (do (setf jfn (lowhalfword jfn-word))
  36. (setf file-name (MkString 100 (char space)))
  37. (jsys1 file-name jfn
  38. #.(bits 2 5 8 11 14 35) 0 (const jsJFNS))
  39. (setf file-name (recopystringtonull file-name))
  40. (setf deleted-flag (jfn-deleted? jfn))
  41. (setf file-size (jfn-page-count jfn))
  42. (setf write-date (jfn-write-date jfn))
  43. (setf read-date (jfn-read-date jfn))
  44. )
  45. (collect (list
  46. file-name
  47. deleted-flag
  48. file-size
  49. write-date
  50. read-date
  51. ))
  52. (do (if (FixP (ErrorSet
  53. (list 'jsys1 jfn-word 0 0 0 (const jsGNJFN))
  54. NIL NIL)) (setf jfn-word -1)))
  55. ))
  56. )))
  57. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  58. % File Functions:
  59. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  60. (de file-deleted-status (file-name)
  61. % Return either: EXISTS, DELETED, NIL
  62. (let ((jfn (ErrorSet (list 'jsys1 #.(bits 2 8 17)
  63. file-name 0 0 (const jsGTJFN)) nil nil)
  64. ))
  65. (cond
  66. ((listp jfn)
  67. (setf jfn (car jfn))
  68. (prog1 (if (jfn-deleted? jfn) 'deleted 'exists)
  69. (jsys0 jfn 0 0 0 (const jsRLJFN))
  70. )
  71. )
  72. )))
  73. (de file-delete (file-name)
  74. (let ((jfn (ErrorSet (list 'jsys1 #.(bits 2 17)
  75. file-name 0 0 (const jsGTJFN)) nil nil)
  76. ))
  77. (cond
  78. ((listp jfn)
  79. (setf jfn (car jfn))
  80. (jsys0 jfn 0 0 0 (const jsDELF))
  81. )
  82. )))
  83. (de file-undelete (file-name)
  84. (let ((jfn (ErrorSet (list 'jsys1 #.(bits 2 8 17)
  85. file-name 0 0 (const jsGTJFN)) nil nil)
  86. ))
  87. (cond
  88. ((listp jfn)
  89. (setf jfn (car jfn))
  90. (jsys0 (xword 1 jfn) #.(bits 3) 0 0 (const jsCHFDB))
  91. (jsys0 jfn 0 0 0 (const jsRLJFN))
  92. )
  93. )))
  94. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  95. % JFN Functions:
  96. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  97. (de jfn-deleted? (jfn)
  98. (not (= (LAnd (Jsys4 jfn #.(xword 1 1) 4 0 (const jsGTFDB))
  99. (bits 3)) 0)))
  100. (de jfn-write-date (jfn)
  101. (Jsys4 jfn #.(xword 1 8#14) 4 0 (const jsGTFDB)))
  102. (de jfn-read-date (jfn)
  103. (Jsys4 jfn #.(xword 1 8#15) 4 0 (const jsGTFDB)))
  104. (de jfn-byte-count (jfn)
  105. (Jsys4 jfn #.(xword 1 8#12) 4 0 (const jsGTFDB)))
  106. (de jfn-page-count (jfn)
  107. (lowhalfword (Jsys4 jfn #.(xword 1 8#11) 4 0 (const jsGTFDB))))
  108. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  109. % Auxiliary Functions:
  110. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  111. (de file-date-to-string (fdate)
  112. % Convert a file date as returned by find-matching-files to a meaningful
  113. % string. Note that 0 is converted to the string "Never". All returned
  114. % strings are 18 characters long, right justified.
  115. (if (= fdate 0)
  116. " Never"
  117. (let ((buf (MkString 30 (char space))))
  118. (Jsys0 buf fdate 0 0 (const jsODTIM))
  119. (recopystringtonull buf))))
  120. (de fixup-directory-name (name)
  121. % If NAME is an unadorned directory or device name, append wild cards to it
  122. % so that it will match all files in the specified directory or directories.
  123. (let ((n (add1 (size name))))
  124. (cond ((or (= n 0)
  125. (= (indx name (- n 1)) (char :))
  126. (= (indx name (- n 1)) (char >))
  127. )
  128. (concat name "*.*.*"))
  129. (t name))))
  130. (de fixup-file-name (name)
  131. % Make the specified file name nice to print.
  132. % Remove any control characters (especially ^V).
  133. (for (in ch (String2List name))
  134. (with the-list)
  135. (when (GraphicP ch))
  136. (collect ch the-list)
  137. (returns (List2String the-list))
  138. ))
  139. (de trim-filename-to-prefix (s)
  140. % Remove trailing characters until the string ends with
  141. % a device or directory prefix.
  142. (for* (from i (size s) 0 -1)
  143. (for ch (indx s i) (indx s i))
  144. (until (or (= ch (char !:)) (= ch (char !>))))
  145. (returns (sub s 0 i))
  146. ))