Mercurial > emacs
comparison lisp/emacs-lisp/bindat.el @ 70853:993df0652ff7
Refill; nfc.
author | Thien-Thi Nguyen <ttn@gnuvola.org> |
---|---|
date | Tue, 23 May 2006 08:04:25 +0000 |
parents | 067115a6e738 |
children | c77bf4eed67a |
comparison
equal
deleted
inserted
replaced
70852:426725b2ce9a | 70853:993df0652ff7 |
---|---|
169 | 169 |
170 ;; ARG ::= ( eval EXPR ) -- interpret result as ARG | 170 ;; ARG ::= ( eval EXPR ) -- interpret result as ARG |
171 ;; | INTEGER_CONSTANT | 171 ;; | INTEGER_CONSTANT |
172 ;; | DEREF | 172 ;; | DEREF |
173 | 173 |
174 ;; DEREF ::= ( [NAME | INTEGER]... ) -- Field NAME or Array index relative to | 174 ;; DEREF ::= ( [NAME | INTEGER]... ) -- Field NAME or Array index relative |
175 ;; current structure spec. | 175 ;; to current structure spec. |
176 ;; -- see bindat-get-field | 176 ;; -- see bindat-get-field |
177 | 177 |
178 ;; A `union' specification | 178 ;; A `union' specification |
179 ;; ([FIELD] union TAG_VAL (TAG SPEC) ... [(t SPEC)]) | 179 ;; ([FIELD] union TAG_VAL (TAG SPEC) ... [(t SPEC)]) |
180 ;; is interpreted by evalling TAG_VAL and then comparing that to | 180 ;; is interpreted by evalling TAG_VAL and then comparing that to |
413 (bindat--length-group | 413 (bindat--length-group |
414 (if field (bindat-get-field struct field) struct) (eval len))) | 414 (if field (bindat-get-field struct field) struct) (eval len))) |
415 ((eq type 'repeat) | 415 ((eq type 'repeat) |
416 (let ((index 0)) | 416 (let ((index 0)) |
417 (while (< index len) | 417 (while (< index len) |
418 (bindat--length-group (nth index (bindat-get-field struct field)) (nthcdr tail item)) | 418 (bindat--length-group |
419 (nth index (bindat-get-field struct field)) | |
420 (nthcdr tail item)) | |
419 (setq index (1+ index))))) | 421 (setq index (1+ index))))) |
420 ((eq type 'union) | 422 ((eq type 'union) |
421 (let ((tag len) (cases (nthcdr tail item)) case cc) | 423 (let ((tag len) (cases (nthcdr tail item)) case cc) |
422 (while cases | 424 (while cases |
423 (setq case (car cases) | 425 (setq case (car cases) |
434 (if field | 436 (if field |
435 (setq last (bindat-get-field struct field))) | 437 (setq last (bindat-get-field struct field))) |
436 (setq pos (+ pos len)))))))) | 438 (setq pos (+ pos len)))))))) |
437 | 439 |
438 (defun bindat-length (spec struct) | 440 (defun bindat-length (spec struct) |
439 "Calculate raw-data length for STRUCT according to bindat specification SPEC." | 441 "Calculate raw-data length for STRUCT according to bindat SPEC." |
440 (let ((pos 0)) | 442 (let ((pos 0)) |
441 (bindat--length-group struct spec) | 443 (bindat--length-group struct spec) |
442 pos)) | 444 pos)) |
443 | 445 |
444 | 446 |
555 (bindat--pack-group | 557 (bindat--pack-group |
556 (if field (bindat-get-field struct field) struct) (eval len))) | 558 (if field (bindat-get-field struct field) struct) (eval len))) |
557 ((eq type 'repeat) | 559 ((eq type 'repeat) |
558 (let ((index 0)) | 560 (let ((index 0)) |
559 (while (< index len) | 561 (while (< index len) |
560 (bindat--pack-group (nth index (bindat-get-field struct field)) (nthcdr tail item)) | 562 (bindat--pack-group |
563 (nth index (bindat-get-field struct field)) | |
564 (nthcdr tail item)) | |
561 (setq index (1+ index))))) | 565 (setq index (1+ index))))) |
562 ((eq type 'union) | 566 ((eq type 'union) |
563 (let ((tag len) (cases (nthcdr tail item)) case cc) | 567 (let ((tag len) (cases (nthcdr tail item)) case cc) |
564 (while cases | 568 (while cases |
565 (setq case (car cases) | 569 (setq case (car cases) |
581 Optional fourth arg POS is the starting offset into RAW-DATA. | 585 Optional fourth arg POS is the starting offset into RAW-DATA. |
582 Note: The result is a multibyte string; use `string-make-unibyte' on it | 586 Note: The result is a multibyte string; use `string-make-unibyte' on it |
583 to make it unibyte if necessary." | 587 to make it unibyte if necessary." |
584 (let ((no-return raw-data)) | 588 (let ((no-return raw-data)) |
585 (unless pos (setq pos 0)) | 589 (unless pos (setq pos 0)) |
586 (unless raw-data (setq raw-data (make-vector (+ pos (bindat-length spec struct)) 0))) | 590 (unless raw-data |
591 (setq raw-data (make-vector (+ pos (bindat-length spec struct)) 0))) | |
587 (bindat--pack-group struct spec) | 592 (bindat--pack-group struct spec) |
588 (if no-return nil (concat raw-data)))) | 593 (if no-return nil (concat raw-data)))) |
589 | 594 |
590 | 595 |
591 ;; Misc. format conversions | 596 ;; Misc. format conversions |