Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Anime and Manga management

Name: Anonymous 2009-09-26 10:28

I'm searching for an easy way to organize your Anime and Manga collection. Something like this

./anime "The Melanch*" +
The Melancholy of Suzumiya Haruhi Episode 110 -> Episode 111

If it doesn't exist yet, code it for me, you are prog after all.

Name: Anonymous 2009-09-28 9:32

>>22 here, there's some progress with inotify but I'm too lazy to parse the inotify struct in memory (and cffi:mem-aref behaves silly IMHO), so here's what I wrote so far:


(cffi:defcenum inotify-mask
  (:IN_ACCESS #16r1)
  (:IN_MODIFY #16r2)
  (:IN_ATTRIB #16r4)
  (:IN_CLOSE_WRITE #16r8)
  (:IN_CLOSE_NOWRITE #16r10)
;  (:IN_CLOSE #16r18) ; 0x8 | 0x10
  (:IN_OPEN #16r20)
  (:IN_MOVED_FROM #16r40)
  (:IN_MOVED_TO #16r80)
;  (:IN_MOVE #16r40 #16r80) ; 0x40 | 0x80
  (:IN_CREATE #16r100)
  (:IN_DELETE #16r200)
  (:IN_DELETE_SELF #16r400)
  (:IN_MOVE_SELF #16r800)
  (:IN_UNMOUNT #16r2000)
  (:IN_Q_OVERFLOW #16r4000)
  (:IN_IGNORED #16r8000)
  (:IN_ONLY_DIR #16r1000000)
  (:IN_DONT_FOLLOW #16r2000000)
  (:IN_MASK_ADD #16r20000000)
  (:IN_ISDIR #16r40000000)
  (:IN_ONESHOT #16r80000000)
  (:IN_ALL_EVENTS #16rFFFFFFFF))


(cffi:defctype uint32_t :unsigned-int)

(cffi:defcfun "inotify_init1" :int
  (flags :int))

(cffi:defcfun "inotify_add_watch" :int
  (fd :int) (pathname :string) (mask inotify-mask))

(cffi:defcfun "inotify_rm_watch" :int
  (fd :int) (wd uint32_t))

(defconstant +INOTIFY-MEMORY+ 256)

(defclass inotify ()
  ((inotify-instance
    :initform (let ((x (inotify-init1 0)))
                (if (= x -1)
                    (error "inotify-init1")
                    x))
    :reader inotify-instance
    :documentation "Inotify instance file descriptor")
   (inotify-table
    :initform (make-hash-table)
    :initarg :table
    :reader inotify-table
    :documentation "Hash table that pathname->wd entries are stored")))

(defmacro with-inotify-instance ((name &optional (flags 0)) &body body)
  `(let ((,name (make-instance 'inotify)))
     (unwind-protect
          (progn ,@body)
       (cffi:foreign-funcall "close"
                             :int (inotify-instance ,name)))))

(defun inotify-add (inotify file-or-dir events)
  "Add or modify file-or-dir to watch list"
  (let ((watch-descriptor (inotify-add-watch (inotify-instance inotify)
                              file-or-dir events)))
    (setf (gethash file-or-dir (inotify-table inotify))
          watch-descriptor)))

(defun inotify-remove (inotify file-or-dir)
  (multiple-value-bind (watch-descriptor bool)
      (gethash file-or-dir
               (inotify-table inotify))
    (when bool
      (inotify-rm-watch (inotify-instance inotify)
                        watch-descriptor))))

(defun inotify-parse-event (event)
  "Parse event from foreign pointer to lisp data"
  (let* ((watch-descriptor (cffi:mem-aref event :int))
         (mask (cffi:mem-aref event :unsigned-int 1))
         (pointer-name (cffi:mem-aref event :pointer 4)))
    (list watch-descriptor mask pointer-name)))
 
(defun inotify-event (inotify)
  "Read event from inotify object"
  (cffi:with-foreign-pointer (pointer +INOTIFY-MEMORY+)
    (if (< 0 (cffi:foreign-funcall "read"
                                   :int (inotify-instance inotify)
                                   :pointer pointer
                                   :unsigned-int +INOTIFY-MEMORY+
                                   :int))
        (inotify-parse-event pointer))))

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List