Mercurial > emacs
comparison lisp/ls-lisp.el @ 24435:3b5ee0390edd
(ls-lisp-insert-directory): Protect the sum total of
the file sizes from overflowing.
(ls-lisp-format): If file size is a float, use %8.0f to print it.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Thu, 04 Mar 1999 11:30:27 +0000 |
parents | 40be509c47c2 |
children | e5af0407bcd6 |
comparison
equal
deleted
inserted
replaced
24434:3c42b33fb636 | 24435:3b5ee0390edd |
---|---|
136 short | 136 short |
137 (file-list (directory-files dir nil wildcard)) | 137 (file-list (directory-files dir nil wildcard)) |
138 file-alist | 138 file-alist |
139 (now (current-time)) | 139 (now (current-time)) |
140 ;; do all bindings here for speed | 140 ;; do all bindings here for speed |
141 file-size | |
141 fil attr) | 142 fil attr) |
142 (cond ((memq ?A switches) | 143 (cond ((memq ?A switches) |
143 (setq file-list | 144 (setq file-list |
144 (ls-lisp-delete-matching "^\\.\\.?$" file-list))) | 145 (ls-lisp-delete-matching "^\\.\\.?$" file-list))) |
145 ((not (memq ?a switches)) | 146 ((not (memq ?a switches)) |
166 (ls-lisp-handle-switches file-alist switches)) | 167 (ls-lisp-handle-switches file-alist switches)) |
167 (while file-alist | 168 (while file-alist |
168 (setq elt (car file-alist) | 169 (setq elt (car file-alist) |
169 file-alist (cdr file-alist) | 170 file-alist (cdr file-alist) |
170 short (car elt) | 171 short (car elt) |
171 attr (cdr elt)) | 172 attr (cdr elt) |
173 file-size (nth 7 attr)) | |
172 (and attr | 174 (and attr |
173 (setq sum (+ sum (nth 7 attr))) | 175 (setq sum |
174 (insert (ls-lisp-format short attr switches now)))) | 176 ;; Even if neither SUM nor file's size |
177 ;; overflow, their sum could. | |
178 (if (or (< sum (- 134217727 file-size)) | |
179 (floatp sum) | |
180 (floatp file-size)) | |
181 (+ sum file-size) | |
182 (+ (float sum) file-size))) | |
183 (insert (ls-lisp-format short attr file-size switches now)) | |
184 )) | |
175 ;; Fill in total size of all files: | 185 ;; Fill in total size of all files: |
176 (save-excursion | 186 (save-excursion |
177 (search-backward "total \007") | 187 (search-backward "total \007") |
178 (goto-char (match-end 0)) | 188 (goto-char (match-end 0)) |
179 (delete-char -1) | 189 (delete-char -1) |
180 (insert (format "%.0f" (fceiling (/ sum 1024.0)))))) | 190 (insert (format "%.0f" (fceiling (/ sum 1024.0)))))) |
181 ;; if not full-directory-p, FILE *must not* end in /, as | 191 ;; if not full-directory-p, FILE *must not* end in /, as |
182 ;; file-attributes will not recognize a symlink to a directory | 192 ;; file-attributes will not recognize a symlink to a directory |
183 ;; must make it a relative filename as ls does: | 193 ;; must make it a relative filename as ls does: |
184 (setq file (file-name-nondirectory file)) | 194 (setq file (file-name-nondirectory file)) |
185 (insert (ls-lisp-format file (file-attributes file) switches | 195 (insert (ls-lisp-format file (file-attributes file) |
196 (nth 7 (file-attributes file)) switches | |
186 (current-time))))))) | 197 (current-time))))))) |
187 | 198 |
188 (defun ls-lisp-delete-matching (regexp list) | 199 (defun ls-lisp-delete-matching (regexp list) |
189 ;; Delete all elements matching REGEXP from LIST, return new list. | 200 ;; Delete all elements matching REGEXP from LIST, return new list. |
190 ;; Should perhaps use setcdr for efficiency. | 201 ;; Should perhaps use setcdr for efficiency. |
238 (or (< hi0 hi1) | 249 (or (< hi0 hi1) |
239 (and (= hi0 hi1) | 250 (and (= hi0 hi1) |
240 (< lo0 lo1))))) | 251 (< lo0 lo1))))) |
241 | 252 |
242 | 253 |
243 (defun ls-lisp-format (file-name file-attr switches now) | 254 (defun ls-lisp-format (file-name file-attr file-size switches now) |
244 (let ((file-type (nth 0 file-attr))) | 255 (let ((file-type (nth 0 file-attr))) |
245 (concat (if (memq ?i switches) ; inode number | 256 (concat (if (memq ?i switches) ; inode number |
246 (format "%6d " (nth 10 file-attr))) | 257 (format "%6d " (nth 10 file-attr))) |
247 ;; nil is treated like "" in concat | 258 ;; nil is treated like "" in concat |
248 (if (memq ?s switches) ; size in K | 259 (if (memq ?s switches) ; size in K |
249 (format "%4d " (fceiling (/ (nth 7 file-attr) 1024.0)))) | 260 (format "%4d " (fceiling (/ file-size 1024.0)))) |
250 (nth 8 file-attr) ; permission bits | 261 (nth 8 file-attr) ; permission bits |
251 ;; numeric uid/gid are more confusing than helpful | 262 ;; numeric uid/gid are more confusing than helpful |
252 ;; Emacs should be able to make strings of them. | 263 ;; Emacs should be able to make strings of them. |
253 ;; user-login-name and user-full-name could take an | 264 ;; user-login-name and user-full-name could take an |
254 ;; optional arg. | 265 ;; optional arg. |
255 (format " %3d %-8s %-8s %8d " | 266 (format (if (floatp file-size) |
267 " %3d %-8s %-8s %8.0f " | |
268 " %3d %-8s %-8s %8d ") | |
256 (nth 1 file-attr) ; no. of links | 269 (nth 1 file-attr) ; no. of links |
257 (if (= (user-uid) (nth 2 file-attr)) | 270 (if (= (user-uid) (nth 2 file-attr)) |
258 (user-login-name) | 271 (user-login-name) |
259 (int-to-string (nth 2 file-attr))) ; uid | 272 (int-to-string (nth 2 file-attr))) ; uid |
260 (if (eq system-type 'ms-dos) | 273 (if (eq system-type 'ms-dos) |
261 "root" ; everything is root on MSDOS. | 274 "root" ; everything is root on MSDOS. |
262 (int-to-string (nth 3 file-attr))) ; gid | 275 (int-to-string (nth 3 file-attr))) ; gid |
263 (nth 7 file-attr) ; size in bytes | 276 file-size |
264 ) | 277 ) |
265 (ls-lisp-format-time file-attr switches now) | 278 (ls-lisp-format-time file-attr switches now) |
266 " " | 279 " " |
267 file-name | 280 file-name |
268 (if (stringp file-type) ; is a symbolic link | 281 (if (stringp file-type) ; is a symbolic link |