changeset 10843:2f2e5033b3bb

(tar-header-block-tokenize): Parse 32-bit modtime current-time compatible a list of 16-bit ints (HIGH LOW). (tar-parse-octal-integer): Write char-const '0' as ?0 instead of more obscure 48. (tar-parse-octal-long-integer): New function. (tar-clip-time-string): New function. (tar-header-block-summarize, tar-header-block-summarize): Insert mod-time into listing. (tar-next-line): Move goal column to new location of filenames. (tar-mode-show-date): New variable. (tar-header-block-summarize, tar-next-line): Obey it.
author Richard M. Stallman <rms@gnu.org>
date Sun, 26 Feb 1995 22:06:49 +0000
parents 076c2c2b4f06
children 06d6b2e17987
files lisp/tar-mode.el
diffstat 1 files changed, 33 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/tar-mode.el	Sun Feb 26 21:37:30 1995 +0000
+++ b/lisp/tar-mode.el	Sun Feb 26 22:06:49 1995 +0000
@@ -54,10 +54,6 @@
 ;;; o  It's not possible to add a NEW file to a tar archive; not that 
 ;;;    important, but still...
 ;;;
-;;; o  In the directory listing, we don't show creation times because I don't
-;;;    know how to print an arbitrary date, and I don't really want to have to
-;;;    implement decode-universal-time.
-;;;
 ;;; o  The code is less efficient that it could be - in a lot of places, I
 ;;;    pull a 512-character string out of the buffer and parse it, when I could
 ;;;    be parsing it in place, not garbaging a string.  Should redo that.
@@ -107,14 +103,18 @@
 how many null padding bytes go on the end of the tar file.")
 
 (defvar tar-update-datestamp nil
-  "*Whether tar-mode should play fast and loose with sub-file datestamps;
-if this is true, then editing and saving a tar file entry back into its
+  "*Non-nil means tar-mode should play fast and loose with sub-file datestamps.
+If this is true, then editing and saving a tar file entry back into its
 tar file will update its datestamp.  If false, the datestamp is unchanged.
 You may or may not want this - it is good in that you can tell when a file
 in a tar archive has been changed, but it is bad for the same reason that
 editing a file in the tar archive at all is bad - the changed version of 
 the file never exists on disk.")
 
+(defvar tar-mode-show-date nil
+  "*Non-nil means Tar mode should show the date/time of each subfile.
+This information is useful, but it takes screen space away from file names.")
+
 (defvar tar-parse-info nil)
 (defvar tar-header-offset nil)
 (defvar tar-superior-buffer nil)
@@ -248,7 +248,7 @@
 	     (tar-parse-octal-integer string tar-uid-offset (1- tar-gid-offset))
 	     (tar-parse-octal-integer string tar-gid-offset (1- tar-size-offset))
 	     (tar-parse-octal-integer string tar-size-offset (1- tar-time-offset))
-	     (tar-parse-octal-integer string tar-time-offset (1- tar-chk-offset))
+	     (tar-parse-octal-long-integer string tar-time-offset (1- tar-chk-offset))
 	     (tar-parse-octal-integer string tar-chk-offset (1- tar-linkp-offset))
 	     link-p
 	     (substring string tar-link-offset link-end)
@@ -269,10 +269,25 @@
     (let ((n 0))
       (while (< start end)
 	(setq n (if (< (aref string start) ?0) n
-		  (+ (* n 8) (- (aref string start) 48)))
+		  (+ (* n 8) (- (aref string start) ?0)))
 	      start (1+ start)))
       n)))
 
+(defun tar-parse-octal-long-integer (string &optional start end)
+  (if (null start) (setq start 0))
+  (if (null end) (setq end (length string)))
+  (if (= (aref string start) 0)
+      [0 0]
+    (let ((lo 0)
+	  (hi 0))
+      (while (< start end)
+	(if (>= (aref string start) ?0)
+	    (setq lo (+ (* lo 8) (- (aref string start) ?0))
+		  hi (+ (* hi 8) (ash lo -16))
+		  lo (logand lo 65535)))
+	(setq start (1+ start)))
+      (list hi lo))))
+
 (defun tar-parse-octal-integer-safe (string)
   (let ((L (length string)))
     (if (= L 0) (error "empty string"))
@@ -315,6 +330,9 @@
     (tar-dotimes (i l) (aset hblock (- 153 i) (aref chk-string (- l i 1)))))
   hblock)
 
+(defun tar-clip-time-string (time)
+  (let ((str (current-time-string time)))
+    (concat (substring str 4 16) (substring str 19 24))))
 
 (defun tar-grind-file-mode (mode string start)
   "Write a \"-rw--r--r-\" representing MODE into STRING beginning at START."
@@ -349,10 +367,11 @@
 	   (namew 8)
 	   (groupw 8)
 	   (sizew 8)
-	   (datew 2)
+	   (datew (if tar-mode-show-date 18 0))
 	   (slash (1- (+ left namew)))
 	   (lastdigit (+ slash groupw sizew))
-	   (namestart (+ lastdigit datew))
+	   (datestart (+ lastdigit 2))
+	   (namestart (+ datestart datew))
 	   (string (make-string (+ namestart (length name) (if link-p (+ 5 (length link-name)) 0)) 32))
 	   (type (tar-header-link-type tar-hblock)))
       (aset string 0 (if mod-p ?* ? ))
@@ -373,11 +392,13 @@
       (setq uid (if (= 0 (length uname)) (int-to-string uid) uname))
       (setq gid (if (= 0 (length gname)) (int-to-string gid) gname))
       (setq size (int-to-string size))
+      (setq time (tar-clip-time-string time))
       (tar-dotimes (i (min (1- namew) (length uid))) (aset string (- slash i) (aref uid (- (length uid) i 1))))
       (aset string (1+ slash) ?/)
       (tar-dotimes (i (min (1- groupw) (length gid))) (aset string (+ (+ slash 2) i) (aref gid i)))
       (tar-dotimes (i (min sizew (length size))) (aset string (- lastdigit i) (aref size (- (length size) i 1))))
-      ;; ## bloody hell, how do I print an arbitrary date??
+      (if tar-mode-show-date
+	  (tar-dotimes (i (length time)) (aset string (+ datestart i) (aref time i))))
       (tar-dotimes (i (length name)) (aset string (+ namestart i) (aref name i)))
       (if (or (eq link-p 1) (eq link-p 2))
 	  (progn
@@ -611,7 +632,7 @@
 (defun tar-next-line (p)
   (interactive "p")
   (forward-line p)
-  (if (eobp) nil (forward-char 36)))
+  (if (eobp) nil (forward-char (if tar-mode-show-date 54 36))))
 
 (defun tar-previous-line (p)
   (interactive "p")