* Proposal: cpio-mode
@ 2015-04-16 19:08 Douglas Lewan
2015-04-16 20:42 ` Stefan Monnier
0 siblings, 1 reply; 3+ messages in thread
From: Douglas Lewan @ 2015-04-16 19:08 UTC (permalink / raw)
To: emacs-devel@gnu.org
[-- Attachment #1: Type: text/plain, Size: 268 bytes --]
All,
A cpio mode has been in the emacs TODO file for as long as I've looked there.
I'd like to write that. Is there really still interest?
Thanks.
,DougDouglas Lewan(908) 720-7908
My problem lies in reconciling my gross habits with my net income. -- Errol Flynn
[-- Attachment #2: Type: text/html, Size: 1251 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Proposal: cpio-mode
2015-04-16 19:08 Proposal: cpio-mode Douglas Lewan
@ 2015-04-16 20:42 ` Stefan Monnier
2016-10-20 11:02 ` Lars Brinkhoff
0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2015-04-16 20:42 UTC (permalink / raw)
To: Douglas Lewan; +Cc: emacs-devel@gnu.org
> A cpio mode has been in the emacs TODO file for as long as I've looked there.
> I'd like to write that. Is there really still interest?
It'd fit very nicely in GNU ELPA, I think, yes. Of course, the fact
that noone wrote one up might indicate that the demand is not very high,
but I for one would enjoy easier access to the initramfs files, for example.
Stefan
PS: For what it's worth, here's my earlier attempt at such a thing.
Obviously I stopped before getting to the meat of it.
PPS: Also, there are various possible options in terms of UI: you could
integrate cpio support into arc-mode.el, or you could "do it by hand"
along the lines of tar-mode.el, or you make a magic file-name handler
(and rely on dired for the UI).
;;; cpio-mode.el --- View/edit cpio archives
;; Copyright (C) 2012 Stefan Monnier
;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
;; Keywords:
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
;; The format supported is the "New ASCII Format" as documented in
;; http://people.freebsd.org/~kientzle/libarchive/man/cpio.5.txt.
(eval-when-compile (require 'cl))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.cpio\\'" . cpio-mode))
;;;###autoload
(when (boundp 'inhibit-local-variables-regexps)
(add-to-list 'inhibit-local-variables-regexps "\\.cpio\\'"))
;;;###autoload
(define-derived-mode cpio-mode special-mode "CPIO"
"View/edit cpio archives."
(add-hook 'change-major-mode-hook
(lambda () (with-silent-modifications
(save-restriction
(widen)
(remove-text-properties (point-min) (point-max)
'(display nil invisible nil))))))
(cpio--parse-buffer))
(defun cpio--parse-mode (mode)
(string
(case (logand #o170000 mode)
(#o140000 ?s)
(#o120000 ?l)
(#o100000 ?-)
(#o060000 ?b)
(#o040000 ?d)
(#o020000 ?c)
(#o010000 ?p)
(t (error "Unknown mode %S" mode)))
(if (zerop (logand #o400 mode)) ?- ?r)
(if (zerop (logand #o200 mode)) ?- ?w)
(if (zerop (logand #o100 mode))
(if (zerop (logand #o4000 mode)) ?- ?S)
(if (zerop (logand #o4000 mode)) ?x ?s))
(if (zerop (logand #o040 mode)) ?- ?r)
(if (zerop (logand #o020 mode)) ?- ?w)
(if (zerop (logand #o010 mode))
(if (zerop (logand #o2000 mode)) ?- ?S)
(if (zerop (logand #o2000 mode)) ?x ?s))
(if (zerop (logand #o004 mode)) ?- ?r)
(if (zerop (logand #o002 mode)) ?- ?w)
(if (zerop (logand #o001 mode)) ?- ?x)))
(defun cpio--parse-buffer ()
(save-excursion
(save-restriction
(widen)
(goto-char (point-min))
(with-silent-modifications
(while (not (eobp))
(assert (zerop (mod (- (point) (point-min)) 4)))
(cond
((not (looking-at "07070[12]\\([[:xdigit:]]\\{8\\}\\)\\([[:xdigit:]]\\{8\\}\\)\\([[:xdigit:]]\\{8\\}\\)\\([[:xdigit:]]\\{8\\}\\)\\([[:xdigit:]]\\{8\\}\\)\\([[:xdigit:]]\\{8\\}\\)\\([[:xdigit:]]\\{8\\}\\)\\([[:xdigit:]]\\{8\\}\\)\\([[:xdigit:]]\\{8\\}\\)\\([[:xdigit:]]\\{8\\}\\)\\([[:xdigit:]]\\{8\\}\\)\\([[:xdigit:]]\\{8\\}\\)[[:xdigit:]]\\{8\\}\\|\0+\\'"))
(error "Unrecognized cpio header format"))
((not (match-beginning 1))
;; Reached the trailing padding, just skip it.
(put-text-property (point) (point-max) 'invisible t)
(goto-char (match-end 0)))
(t
(let* ((ino (string-to-number (match-string 1) 16))
(mode (string-to-number (match-string 2) 16))
(uid (string-to-number (match-string 3) 16))
(gid (string-to-number (match-string 4) 16))
(nlink (string-to-number (match-string 5) 16))
(mtime (string-to-number (match-string 6) 16))
(filesize (string-to-number (match-string 7) 16))
(devmajor (string-to-number (match-string 8) 16))
(devminor (string-to-number (match-string 9) 16))
(rdevmajor (string-to-number (match-string 10) 16))
(rdevminor (string-to-number (match-string 11) 16))
(namesize (string-to-number (match-string 12) 16))
(namebeg (match-end 0))
(name (buffer-substring namebeg (+ namebeg namesize -1)))
(filebeg (+ (match-end 0) 2 (* (/ (+ namesize 1) 4) 4)))
(next (+ filebeg (* (/ (+ filesize 3) 4) 4))))
(if (and (zerop ino) (zerop mode) (zerop filesize)
(equal name "TRAILER!!!"))
(put-text-property (match-beginning 0) next
'display "\n<trailer>")
(if (bobp)
(put-text-property (point) (match-end 1) 'invisible t)
(put-text-property (point) (match-end 1) 'display "\n"))
(put-text-property (match-beginning 2) (match-end 2)
'display (cpio--parse-mode mode))
(put-text-property (match-beginning 3) (match-end 3)
'display (format "%10d" uid))
(put-text-property (match-beginning 4) (match-end 4)
'display (format "/%-10d" gid))
(put-text-property (match-beginning 5) ;; (match-end 6)
;; 'invisible t)
;; (put-text-property (match-beginning 7)
(match-end 7)
'display (format "%10d" filesize))
(put-text-property (match-beginning 8) namebeg
'display " ")
(if (= (logand #o170000 mode) #o120000) ;Symlink
(progn
(put-text-property (+ namebeg namesize -1) filebeg
'display " -> ")
(put-text-property (+ filebeg filesize) next
'invisible t))
(put-text-property (+ namebeg namesize -1) next
'invisible t))
(message "Parsed %S of size %d" name filesize))
(goto-char next)))))))))
(provide 'cpio-mode)
;;; cpio-mode.el ends here
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Proposal: cpio-mode
2015-04-16 20:42 ` Stefan Monnier
@ 2016-10-20 11:02 ` Lars Brinkhoff
0 siblings, 0 replies; 3+ messages in thread
From: Lars Brinkhoff @ 2016-10-20 11:02 UTC (permalink / raw)
To: emacs-devel
Stefan Monnier wrote:
> Douglas Lewan wrote:
>> A cpio mode has been in the emacs TODO file for as long as I've
>> looked there. I'd like to write that. Is there really still
>> interest?
>
> It'd fit very nicely in GNU ELPA, I think, yes. Of course, the fact
> that noone wrote one up might indicate that the demand is not very
> high, but I for one would enjoy easier access to the initramfs files,
> for example.
I just now wanted to open an rpm file like I would a tar file. I
understand rpm files are mostly compressed cpio files.
So, +1 on cpio-mode.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-10-20 11:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-16 19:08 Proposal: cpio-mode Douglas Lewan
2015-04-16 20:42 ` Stefan Monnier
2016-10-20 11:02 ` Lars Brinkhoff
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.