News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

masm32lib-readline fails ...

Started by denise_amiga, June 05, 2005, 07:07:25 AM

Previous topic - Next topic

denise_amiga

if the text contains tab´s the result is not correct.


    cmp al, 13                  ; test for ascii 13 and 0
    ja pre


hutch--

Thanks,

You are correct. I will have to set up a test piece but its a simple mod.


  pre:
    mov [edi+ecx], al           ; write BYTE to buffer
  ristart:
    add ecx, 1
    mov al, [edx+ecx]           ; read BYTE from source
    cmp al, 9
    je pre
    cmp al, 13                  ; test for ascii 13 and 0
    ja pre
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

denise_amiga

hi hutch--

in your new version, you are filtered, <tab>(9) and all below <cr>(13) what about with the range 13-32.
hi is my attempt



OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

align 4

readline proc source:DWORD,buffer:DWORD,spos:DWORD

comment * ------------------------------------------------------

        source  =   source memory to read line from
        buffer  =   buffer that line of text is written to
        spos    =   start position in buffer to write to

        readline copies a line of text from the source
        to the buffer starting from the offset set in "spos",
        updates the "spos" variable to the start of the following
        line of text and returns that variable in EAX.
        EAX returns ZERO if the end of the source is on the
        curent line.

        The length of the line not including ascii
        0 and 13 is returned in ECX. You should test
        the buffer if ZERO is returned in EAX as it may
        contain the last line of text that is zero terminated.

        Conditions to test for.
        1. End of source returns zero in EAX.
        2. blank line has 1st byte in buffer set to zero
           and a line length in ECX of ZERO.
        3. Line length is returned in ECX.

        ------------------------------------------------------ *

    push    edi

    mov     edx, [esp+2*4]          ; source address in EDX
    mov     edi, [esp+3*4]          ; buffer address in EDI
    add     edx, [esp+4*4]          ; add spos to source
    ;xor    eax, eax                ; clear EAX
    mov     ecx, -1                 ; set index and counter to -1
align 4
@@:
    add     ecx, 1
    movzx   eax, byte ptr [edx+ecx] ; read BYTE from source
    mov     [edi+ecx], al           ; write BYTE to buffer
    cmp     al, 13                  ; test for ascii 13
    je      @F

    cmp     al, 9                   ; tab is valid
    je      @B

    cmp     al, 31                  ; only ascii greater space
    ja      @B

@@:
    mov     byte ptr [edi+ecx], 0   ; write terminator to buffer
    test    al, al                  ; test for end of source
    jz      @liout                  ; return zero if end of source

    lea     eax, [ecx+2]            ; add counter + 2 to EAX
    add     eax, [esp+4*4]          ; return next spos in eax

@liout:
    pop     edi

    ret     3*4

readline endp

OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef