Changeset 18824 in project


Ignore:
Timestamp:
07/14/10 20:44:04 (10 years ago)
Author:
ecloud
Message:

endian-port-read-intx and write-intx use signed ints; added read-uintx and write-uintx variants for unsigned ints

File:
1 edited

Legend:

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

    r18795 r18824  
    3838         endian-port-read-int2
    3939         endian-port-read-int4
     40         endian-port-read-uint1
     41         endian-port-read-uint2
     42         endian-port-read-uint4
    4043         endian-port-read-ieee-float32
    4144         endian-port-read-ieee-float64
     
    4548         endian-port-write-int2
    4649         endian-port-write-int4
     50         endian-port-write-uint1       
     51         endian-port-write-uint2
     52         endian-port-write-uint4
    4753         endian-port-write-ieee-float32
    4854         endian-port-write-ieee-float64
     
    170176
    171177; Procedure:
    172 ; endian-port-read-int1:: EPORT [* BYTE-ORDER] -> UINTEGER
     178; endian-port-read-uint1:: EPORT [* BYTE-ORDER] -> UINTEGER
    173179;
    174180; Reads an unsigned integer of size 1 byte. Optional argument
     
    176182; then use the byte order setting of the given endian port.
    177183;
    178 (define (endian-port-read-int1 eport . rest)
     184(define (endian-port-read-uint1 eport . rest)
     185  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
    179186                (let* ( [buf (make-blob 1)]
    180187                                [ret (file-read (endian-port-fileno eport) 1 buf)])
    181                         (and (eq? (cadr ret) 1) (u8vector-ref (blob->u8vector/shared (car ret)) 0)) ))
    182 
    183 
    184 ; Procedure:
    185 ; endian-port-read-int2:: EPORT [* BYTE-ORDER] -> UINTEGER.
     188                        (and (eq? (cadr ret) 1) (endian-blob->uint1 (byte-blob->endian-blob
     189                                        (blob->byte-blob (car ret)) byte-order) ) ))))
     190
     191
     192; Procedure:
     193; endian-port-read-uint2:: EPORT [* BYTE-ORDER] -> UINTEGER.
    186194;
    187195; Reads an unsigned integer of size 2 bytes. Optional argument
     
    189197; then use the byte order setting of the given endian port.
    190198;
    191 (define (endian-port-read-int2 eport . rest)
     199(define (endian-port-read-uint2 eport . rest)
    192200  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
    193201                (let* ( [buf (make-blob 2)]
     
    198206
    199207; Procedure:
    200 ; endian-port-read-int4:: EPORT [* BYTE-ORDER] -> UINTEGER
     208; endian-port-read-uint4:: EPORT [* BYTE-ORDER] -> UINTEGER
    201209;
    202210; Reads an unsigned integer of size 4 bytes. Optional argument
     
    204212; then use the byte order setting of the given endian port.
    205213;
    206 (define (endian-port-read-int4 eport . rest)
     214(define (endian-port-read-uint4 eport . rest)
    207215  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
    208216                (let* ( [buf (make-blob 4)]
    209217                                [ret (file-read (endian-port-fileno eport) 4 buf)])
    210218                        (and (eq? (cadr ret) 4) (endian-blob->uint4 (byte-blob->endian-blob
     219                                        (blob->byte-blob (car ret)) byte-order) ) ))))
     220
     221; Procedure:
     222; endian-port-read-int1:: EPORT [* BYTE-ORDER] -> INTEGER
     223;
     224; Reads a signed integer of size 1 byte. Optional argument
     225; BYTE-ORDER is one of MSB or LSB. If byte order is not specified,
     226; then use the byte order setting of the given endian port.
     227;
     228(define (endian-port-read-int1 eport . rest)
     229  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
     230                (let* ( [buf (make-blob 1)]
     231                                [ret (file-read (endian-port-fileno eport) 1 buf)])
     232                        (and (eq? (cadr ret) 1) (endian-blob->sint1 (byte-blob->endian-blob
     233                                        (blob->byte-blob (car ret)) byte-order) ) ))))
     234
     235
     236; Procedure:
     237; endian-port-read-int2:: EPORT [* BYTE-ORDER] -> INTEGER.
     238;
     239; Reads a signed integer of size 2 bytes. Optional argument
     240; BYTE-ORDER is one of MSB or LSB. If byte order is not specified,
     241; then use the byte order setting of the given endian port.
     242;
     243(define (endian-port-read-int2 eport . rest)
     244  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
     245                (let* ( [buf (make-blob 2)]
     246                                [ret (file-read (endian-port-fileno eport) 2 buf)])
     247                        (and (eq? (cadr ret) 2) (endian-blob->sint2 (byte-blob->endian-blob
     248                                        (blob->byte-blob (car ret)) byte-order) ) ))))
     249
     250
     251; Procedure:
     252; endian-port-read-int4:: EPORT [* BYTE-ORDER] -> INTEGER
     253;
     254; Reads a signed integer of size 4 bytes. Optional argument
     255; BYTE-ORDER is one of MSB or LSB. If byte order is not specified,
     256; then use the byte order setting of the given endian port.
     257;
     258(define (endian-port-read-int4 eport . rest)
     259  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
     260                (let* ( [buf (make-blob 4)]
     261                                [ret (file-read (endian-port-fileno eport) 4 buf)])
     262                        (and (eq? (cadr ret) 4) (endian-blob->sint4 (byte-blob->endian-blob
    211263                                        (blob->byte-blob (car ret)) byte-order) ) ))))
    212264
     
    303355; endian-port-read-byte-vector:: PORT * SIZE [* BYTE-ORDER]  -> BYTE-VECTOR
    304356;
    305 ; Reads a byte vector of the specified size and returns a Scheme byte
     357; Reads an unsigned byte vector of the specified size and returns a Scheme byte
    306358; vector. Optional argument BYTE-ORDER is one of MSB or LSB. If
    307359; byte order is not specified, then use the byte order setting of the
     
    323375
    324376; Procedure:
    325 ; endian-port-write-int1:: EPORT * WORD [* BYTE-ORDER] -> UINTEGER
     377; endian-port-write-uint1:: EPORT * WORD [* BYTE-ORDER] -> UINTEGER
    326378;
    327379; Writes an unsigned integer of size 1 byte. Returns the number of
     
    330382; order setting of the given endian port.
    331383;
    332 (define (endian-port-write-int1 eport word . rest)
     384(define (endian-port-write-uint1 eport word . rest)
    333385  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
    334386                (let* ( [buf (u8vector->blob (endian-blob->u8vector (uint1->endian-blob word byte-order)))])
     
    336388
    337389; Procedure:
    338 ; endian-port-write-int2:: EPORT * WORD [* BYTE-ORDER] -> UINTEGER
     390; endian-port-write-uint2:: EPORT * WORD [* BYTE-ORDER] -> UINTEGER
    339391;
    340392; Writes an unsigned integer of size 2 bytes. Returns the number of
     
    343395; order setting of the given endian port.
    344396;
    345 (define (endian-port-write-int2 eport word . rest)
     397(define (endian-port-write-uint2 eport word . rest)
    346398  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
    347399                (let* ( [buf (u8vector->blob (endian-blob->u8vector (uint2->endian-blob word byte-order)))])
     
    349401
    350402; Procedure:
    351 ; endian-port-write-int4:: EPORT * WORD [* BYTE-ORDER] -> UINTEGER
     403; endian-port-write-uint4:: EPORT * WORD [* BYTE-ORDER] -> UINTEGER
    352404;
    353405; Writes an unsigned integer of size 4 bytes. Returns the number of
     
    356408; order setting of the given endian port.
    357409;
     410(define (endian-port-write-uint4 eport word . rest)
     411  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
     412                (let* ( [buf (u8vector->blob (endian-blob->u8vector (uint4->endian-blob word byte-order)))])
     413                        (file-write (endian-port-fileno eport) buf))))
     414
     415; Procedure:
     416; Procedure:
     417; endian-port-write-int1:: EPORT * WORD [* BYTE-ORDER] -> INTEGER
     418;
     419; Writes a signed integer of size 1 byte. Returns the number of
     420; bytes written (always 1). Optional argument BYTE-ORDER is one of
     421; MSB or LSB. If byte order is not specified, then use the byte
     422; order setting of the given endian port.
     423;
     424(define (endian-port-write-int1 eport word . rest)
     425  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
     426                (let* ( [buf (u8vector->blob (endian-blob->u8vector (sint1->endian-blob word byte-order)))])
     427                        (file-write (endian-port-fileno eport) buf))))
     428
     429; Procedure:
     430; endian-port-write-int2:: EPORT * WORD [* BYTE-ORDER] -> INTEGER
     431;
     432; Writes a signed integer of size 2 bytes. Returns the number of
     433; bytes written (always 2). Optional argument BYTE-ORDER is one of
     434; MSB or LSB. If byte order is not specified, then use the byte
     435; order setting of the given endian port.
     436;
     437(define (endian-port-write-int2 eport word . rest)
     438  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
     439                (let* ( [buf (u8vector->blob (endian-blob->u8vector (sint2->endian-blob word byte-order)))])
     440                        (file-write (endian-port-fileno eport) buf))))
     441
     442; Procedure:
     443; endian-port-write-int4:: EPORT * WORD [* BYTE-ORDER] -> INTEGER
     444;
     445; Writes a signed integer of size 4 bytes. Returns the number of
     446; bytes written (always 4). Optional argument BYTE-ORDER is one of
     447; MSB or LSB. If byte order is not specified, then use the byte
     448; order setting of the given endian port.
     449;
    358450(define (endian-port-write-int4 eport word . rest)
    359451  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
    360                 (let* ( [buf (u8vector->blob (endian-blob->u8vector (uint4->endian-blob word byte-order)))])
     452                (let* ( [buf (u8vector->blob (endian-blob->u8vector (sint4->endian-blob word byte-order)))])
    361453                        (file-write (endian-port-fileno eport) buf))))
    362454
     
    372464  (let-optionals rest ([byte-order (endian-port-byte-order eport)])
    373465                (let* ( [buf (u8vector->blob (endian-blob->u8vector (ieee_float32->endian-blob word byte-order)))])
    374 (printf "trying to write float ~a, but after conversions it turns out as ~a~%" word
    375         (endian-blob->ieee_float32 (byte-blob->endian-blob (blob->byte-blob buf) byte-order) ) )
     466;(let ([testval (endian-blob->ieee_float32 (byte-blob->endian-blob (blob->byte-blob buf) byte-order)) ])
     467;       (unless (eq? testval word) (printf "trying to write float ~a, but after conversions it turns out as ~a~%" word testval) ) )
    376468                        (file-write (endian-port-fileno eport) buf))))
    377469
     
    394486; endian-port-write-byte-vector:: PORT * BYTE-VECTOR [* BYTE-ORDER] -> UINTEGER
    395487;
    396 ; Writes the given byte vector and returns the number of bytes
     488; Writes the given unsigned byte vector and returns the number of bytes
    397489; written. The argument must be a byte vector object. Optional
    398490; argument BYTE-ORDER is one of MSB or LSB. If byte order is not
Note: See TracChangeset for help on using the changeset viewer.