Changeset 27394 in project


Ignore:
Timestamp:
09/09/12 00:34:59 (8 years ago)
Author:
ecloud
Message:

removed trailing whitespace

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/4/endian-port/trunk/endian-port.scm

    r26451 r27394  
    1  
     1
    22;;
    33;; An I/O port that supports different endian formats.
     
    2222
    2323(module endian-port
    24         (make-endian-port 
     24        (make-endian-port
    2525         endian-port?
    26          endian-port-fileno 
    27          endian-port-filename 
     26         endian-port-fileno
     27         endian-port-filename
    2828         endian-port-byte-order
    2929         close-endian-port
    3030         open-endian-port
    31          port->endian-port 
    32          endian-port-set-bigendian! 
    33          endian-port-set-littlendian! 
     31         port->endian-port
     32         endian-port-set-bigendian!
     33         endian-port-set-littlendian!
    3434         endian-port-setpos
    35          endian-port-pos 
    36          endian-port-eof? 
     35         endian-port-pos
     36         endian-port-eof?
    3737         endian-port-read-int1
    3838         endian-port-read-int2
     
    4545         endian-port-read-bit-vector
    4646         endian-port-read-byte-vector
    47          endian-port-write-int1 
     47         endian-port-write-int1
    4848         endian-port-write-int2
    4949         endian-port-write-int4
    50          endian-port-write-uint1       
     50         endian-port-write-uint1
    5151         endian-port-write-uint2
    5252         endian-port-write-uint4
    53          endian-port-write-ieee-float32 
     53         endian-port-write-ieee-float32
    5454         endian-port-write-ieee-float64
    5555         endian-port-write-bit-vector
     
    6868;  * fileno:  file handle corresponding to the port
    6969;  * filename:  file name corresponding to the port
    70 ;  * byte-order: can be MSB or LSB (type defined in unit endian-blob) 
     70;  * byte-order: can be MSB or LSB (type defined in unit endian-blob)
    7171;
    7272
     
    8585
    8686
    87 ; Procedure: 
     87; Procedure:
    8888; close-endian-port:: ENDIAN-PORT -> UNDEFINED
    8989;
     
    9393  (file-close (endian-port-fileno eport)))
    9494
    95 ; Procedure: 
     95; Procedure:
    9696; open-endian-port MODE FILENAME -> ENDIAN-PORT
    9797;
     
    107107               (error 'endian-port  "unable to open file: " filename)
    108108               (make-endian-port fd filename MSB))))
    109         (else 
     109        (else
    110110         (let ((fd (file-open filename (bitwise-ior open/append open/creat open/binary))))
    111111           (if (< fd 0)
     
    113113               (make-endian-port fd filename MSB))))))
    114114
    115 ; Procedure: 
     115; Procedure:
    116116; port->endian-port:: PORT -> ENDIAN-PORT
    117117;
    118118; Creates an endian port to the file specified by the given port. The
    119 ; default endianness of the newly created endian port is MSB. 
     119; default endianness of the newly created endian port is MSB.
    120120;
    121121(define (port->endian-port port)
     
    152152                        (set-file-position! (endian-port-fileno eport) pos seek/set))
    153153                       (else (set-file-position! (endian-port-fileno eport) pos whence)))))
    154                        
     154
    155155
    156156; Procedure:
     
    162162(define (endian-port-pos eport)
    163163  (file-position  (endian-port-fileno eport)))
    164                        
     164
    165165
    166166; Procedure:
     
    173173  (zero? (- (file-size  (endian-port-fileno eport))
    174174            (file-position  (endian-port-fileno eport)))))
    175                        
     175
    176176
    177177; Procedure:
     
    181181; BYTE-ORDER is one of MSB or LSB. If byte order is not specified,
    182182; then use the byte order setting of the given endian port.
    183 ; 
     183;
    184184(define (endian-port-read-uint1 eport . rest)
    185185  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
    186186                (let* ( [buf (make-blob 1)]
    187187                        [ret (file-read (endian-port-fileno eport) 1 buf)])
    188                         (and (= (cadr ret) 1) (endian-blob->uint1 (byte-blob->endian-blob 
     188                        (and (= (cadr ret) 1) (endian-blob->uint1 (byte-blob->endian-blob
    189189                                        (blob->byte-blob (car ret)) byte-order) ) ))))
    190190
    191191
    192192; Procedure:
    193 ; endian-port-read-uint2:: EPORT [* BYTE-ORDER] -> UINTEGER. 
     193; endian-port-read-uint2:: EPORT [* BYTE-ORDER] -> UINTEGER.
    194194;
    195195; Reads an unsigned integer of size 2 bytes. Optional argument
    196196; BYTE-ORDER is one of MSB or LSB. If byte order is not specified,
    197197; then use the byte order setting of the given endian port.
    198 ; 
     198;
    199199(define (endian-port-read-uint2 eport . rest)
    200200  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
    201201                (let* ( [buf (make-blob 2)]
    202202                        [ret (file-read (endian-port-fileno eport) 2 buf)])
    203                         (and (= (cadr ret) 2) (endian-blob->uint2 (byte-blob->endian-blob 
     203                        (and (= (cadr ret) 2) (endian-blob->uint2 (byte-blob->endian-blob
    204204                                        (blob->byte-blob (car ret)) byte-order) ) ))))
    205205
     
    211211; BYTE-ORDER is one of MSB or LSB. If byte order is not specified,
    212212; then use the byte order setting of the given endian port.
    213 ; 
     213;
    214214(define (endian-port-read-uint4 eport . rest)
    215215  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
    216216                (let* ( [buf (make-blob 4)]
    217217                        [ret (file-read (endian-port-fileno eport) 4 buf)])
    218                         (and (= (cadr ret) 4) (endian-blob->uint4 (byte-blob->endian-blob 
     218                        (and (= (cadr ret) 4) (endian-blob->uint4 (byte-blob->endian-blob
    219219                                        (blob->byte-blob (car ret)) byte-order) ) ))))
    220220
     
    225225; BYTE-ORDER is one of MSB or LSB. If byte order is not specified,
    226226; then use the byte order setting of the given endian port.
    227 ; 
     227;
    228228(define (endian-port-read-int1 eport . rest)
    229229  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
    230230                (let* ( [buf (make-blob 1)]
    231231                        [ret (file-read (endian-port-fileno eport) 1 buf)])
    232                         (and (= (cadr ret) 1) (endian-blob->sint1 (byte-blob->endian-blob 
     232                        (and (= (cadr ret) 1) (endian-blob->sint1 (byte-blob->endian-blob
    233233                                        (blob->byte-blob (car ret)) byte-order) ) ))))
    234234
    235235
    236236; Procedure:
    237 ; endian-port-read-int2:: EPORT [* BYTE-ORDER] -> INTEGER. 
     237; endian-port-read-int2:: EPORT [* BYTE-ORDER] -> INTEGER.
    238238;
    239239; Reads a signed integer of size 2 bytes. Optional argument
    240240; BYTE-ORDER is one of MSB or LSB. If byte order is not specified,
    241241; then use the byte order setting of the given endian port.
    242 ; 
     242;
    243243(define (endian-port-read-int2 eport . rest)
    244244  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
    245245                (let* ( [buf (make-blob 2)]
    246246                        [ret (file-read (endian-port-fileno eport) 2 buf)])
    247                         (and (= (cadr ret) 2) (endian-blob->sint2 (byte-blob->endian-blob 
     247                        (and (= (cadr ret) 2) (endian-blob->sint2 (byte-blob->endian-blob
    248248                                        (blob->byte-blob (car ret)) byte-order) ) ))))
    249249
     
    255255; BYTE-ORDER is one of MSB or LSB. If byte order is not specified,
    256256; then use the byte order setting of the given endian port.
    257 ; 
     257;
    258258(define (endian-port-read-int4 eport . rest)
    259259  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
    260260                (let* ( [buf (make-blob 4)]
    261261                        [ret (file-read (endian-port-fileno eport) 4 buf)])
    262                         (and (= (cadr ret) 4) (endian-blob->sint4 (byte-blob->endian-blob 
     262                        (and (= (cadr ret) 4) (endian-blob->sint4 (byte-blob->endian-blob
    263263                                        (blob->byte-blob (car ret)) byte-order) ) ))))
    264264
    265 ; Procedure: 
     265; Procedure:
    266266;
    267267; endian-port-read-ieee-float32:: EPORT [* BYTE-ORDER] -> REAL
     
    270270; argument BYTE-ORDER is one of MSB or LSB. If byte order is not
    271271; specified, then use the byte order setting of the given endian port.
    272 ; 
     272;
    273273(define (endian-port-read-ieee-float32 eport . rest)
    274274  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
    275275                (let* ( [buf (make-blob 4)]
    276276                        [ret (file-read (endian-port-fileno eport) 4 buf)])
    277                         (and (= (cadr ret) 4) 
    278                              (endian-blob->ieee_float32 
    279                               (byte-blob->endian-blob 
     277                        (and (= (cadr ret) 4)
     278                             (endian-blob->ieee_float32
     279                              (byte-blob->endian-blob
    280280                               (blob->byte-blob (car ret)) byte-order) ) ))))
    281281
    282 ; Procedure: 
     282; Procedure:
    283283;
    284284; endian-port-read-ieee-float32:: EPORT [* BYTE-ORDER] -> REAL
     
    287287; argument BYTE-ORDER is one of MSB or LSB. If byte order is not
    288288; specified, then use the byte order setting of the given endian port.
    289 ; 
     289;
    290290(define (endian-port-read-ieee-float64 eport . rest)
    291291  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
    292292                 (let* ( [buf (make-blob 8)]
    293293                         [ret (file-read (endian-port-fileno eport) 8 buf)] )
    294                    (and (= (cadr ret) 8) 
     294                   (and (= (cadr ret) 8)
    295295                        (endian-blob->ieee_float64
    296296                         (byte-blob->endian-blob
     
    302302;
    303303; Helper function for endian-port-read-bit-vector below
    304 ; *  set len bits in vector bv starting at position pos, 
     304; *  set len bits in vector bv starting at position pos,
    305305;    according to the bits set in vector b
    306306;
     
    327327   (let ((nb  (inexact->exact (ceiling (/ size 8))))
    328328         (bv  (make-bit-vector size))
    329          (byte-order  (if byte-order byte-order (endian-port-byte-order eport)))) 
    330      (cond 
     329         (byte-order  (if byte-order byte-order (endian-port-byte-order eport))))
     330     (cond
    331331      ((eq? byte-order MSB)
    332332       ;; if big engian, we start with the most significant bit
     
    356356                     (- rem 8))))))))))
    357357
    358 ; Procedure: 
     358; Procedure:
    359359; endian-port-read-byte-vector:: PORT * SIZE [* BYTE-ORDER]  -> BYTE-VECTOR
    360360;
     
    385385; MSB or LSB. If byte order is not specified, then use the byte
    386386; order setting of the given endian port.
    387 ; 
     387;
    388388(define (endian-port-write-uint1 eport word . rest)
    389389  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
     
    398398; MSB or LSB. If byte order is not specified, then use the byte
    399399; order setting of the given endian port.
    400 ; 
     400;
    401401(define (endian-port-write-uint2 eport word . rest)
    402402  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
     
    411411; MSB or LSB. If byte order is not specified, then use the byte
    412412; order setting of the given endian port.
    413 ; 
     413;
    414414(define (endian-port-write-uint4 eport word . rest)
    415415  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
     
    425425; MSB or LSB. If byte order is not specified, then use the byte
    426426; order setting of the given endian port.
    427 ; 
     427;
    428428(define (endian-port-write-int1 eport word . rest)
    429429  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
     
    438438; MSB or LSB. If byte order is not specified, then use the byte
    439439; order setting of the given endian port.
    440 ; 
     440;
    441441(define (endian-port-write-int2 eport word . rest)
    442442  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
     
    451451; MSB or LSB. If byte order is not specified, then use the byte
    452452; order setting of the given endian port.
    453 ; 
     453;
    454454(define (endian-port-write-int4 eport word . rest)
    455455  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
     
    464464; is one of MSB or LSB. If byte order is not specified, then use
    465465; the byte order setting of the given endian port.
    466 ; 
     466;
    467467(define (endian-port-write-ieee-float32 eport word . rest)
    468468  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
     
    479479; is one of MSB or LSB. If byte order is not specified, then use
    480480; the byte order setting of the given endian port.
    481 ; 
     481;
    482482(define (endian-port-write-ieee-float64 eport word . rest)
    483483  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
    484484                (let* ( [buf (u8vector->blob (endian-blob->u8vector (ieee_float64->endian-blob word byte-order)))])
    485485;(printf "trying to write float ~a, but after conversions it turns out as ~a~%" word
    486 ;       (endian-blob->ieee_float64 (byte-blob->endian-blob (blob->byte-blob buf) byte-order) ) 
     486;       (endian-blob->ieee_float64 (byte-blob->endian-blob (blob->byte-blob buf) byte-order) )
    487487                        (file-write (endian-port-fileno eport) buf))))
    488488
     
    521521; module. Optional argument BIT-ORDER is one of MSB or LSB.  If
    522522; bit order is not specified, then use the byte order setting of the
    523 ; given endian port. 
     523; given endian port.
    524524;
    525525; Note that here the "byte order" type is interpreted as bit order:
Note: See TracChangeset for help on using the changeset viewer.