News:

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

parser

Started by ragdog, November 25, 2007, 02:31:29 PM

Previous topic - Next topic

ragdog

hi

i have problem with parsing from editbox line to line skip 0Dh,0Ah

print :
       MessageBox text1
       MessageBox text2
       MessageBox text3
       MessageBox text4
....
...
..

can your help please?

my code is Attached

greets
ragdog

ragdog

hi

i have solved my problem and have a another problem with print the last line



       invoke GetDlgItemText,hWnd,1002,addr hSrcBuffer,sizeof hSrcBuffer
          mov esi,offset hSrcBuffer
     
@Back:
          mov ah,byte ptr [esi]

          cmp ah,13
          je @NextLine
          cmp ah,10
          je @NextLine
     
          mov edx,1024
          mov edi,offset hDestBuffer
          mov ah,byte ptr [esi]

@1:
          mov byte ptr [edi],ah
          dec edx
           jz @ret
          inc   esi
          inc edi
          mov ah,byte ptr [esi]
          cmp ah,0Dh
          jne @1
          mov byte ptr [edi],0

        invoke MessageBox,hWnd,addr hDestBuffer,0,MB_OK
       
@NextLine:
           inc esi
          jmp @Back
@ret:


can your help fix this problem

thanks in forward

ragdog

[attachment deleted by admin]

Tedd

The last line ends with 0, so you need to check for that (as well as 13 and 10).
No snowflake in an avalanche feels responsible.

Mark Jones

Also you don't really need to check for both the CR and LF unless expecting to handle Macintosh-formatted text files; the LF is common to both PC and UNIX if my memory serves me correctly.

Have you single-stepped the code in Ollydbg yet? That's how I solve most of my "unintentional bugs." :lol
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Tedd

Windows/Dos: CR,LF
Linux: LF
Mac: LF

(Mac used to be CR, so it's often quoted as being so, but Mac is now based on BSD so it's LF)


ragdog's code needs to check for CR and LF (separately) as it first hits the CR, skips over it for the 'next' line but immediately meets the LF and so then skips over that for the (actual start of the) next line - this could be done in one, but it still works as is.
No snowflake in an avalanche feels responsible.

ragdog

#5
thanks for your reply


        invoke GetDlgItemText,hWnd,1002,addr hSrcBuffer,sizeof hSrcBuffer
           mov esi,offset hSrcBuffer
    @Back:
   mov ah,byte ptr [esi]
           mov edx,1024
   mov edi,offset hDestBuffer
   mov ah,byte ptr [esi]
       @@:
           mov byte ptr [edi],ah
           cmp ah,0
    je @F
   dec edx
    jz @ret
           inc  esi
           inc edi
           mov ah,byte ptr [esi]
           cmp ah,0Dh
   jne @B
   mov byte ptr [edi],0 
        invoke  MessageBox,hWnd,addr hDestBuffer,0,MB_OK
   inc esi; for 0Dh
   inc  esi; for 0Ah
   jmp @Back
    @@:
invoke   MessageBox,hWnd,addr hDestBuffer,0,MB_OK
  @ret:


best regards
ragdog

ragdog

hi  ::)

i have coded a parser sensless now
i wanted to show every line in the edit-box in one of the message-box
my edit-box breaks at the windowmargin if i write continouse with the parser
does it show me the interruped line
but i want it to have it single

could you help me?
i want to format every single line from the edit-box

like this format

<  text: line1                             >
<        line2                             >
<        line3                             >
<        line4                             >
...
..
.

here is the formatalgo for a single line:


.data
szformat db "<  text: *                                 >",0

.data?
szWord       dd ?                   ; pointer to entered word
szBuffer     db 64 dup(?)           ; ascii string buffer

.code

Format proc lpszSrc:DWORD,lpszDest:DWORD,lpszFrm:DWORD

    mov eax, lpszSrc
    mov szWord,eax                      ; save location of entered word
    mov eax,lpszFrm                     ; copy format to eax
    lea esi,[eax]                       ; load addresses of string locations
    lea edi,szBuffer                    ; into source and dest registers
    mov ecx,szWord                      ; szWord already a pointer, use as ecx
@@: movsb                               ; copy byte edi<--esi, inc both ++
    cmp byte ptr [esi],"*"              ; look for the asterisk
    jnz @B                              ; keep copying until found
@@: mov al,byte ptr [ecx]               ; fetch a byte of the new word
    cmp al,0                            ; are we at end of new word?
     jz @F                              ; if so, break out
    inc ecx                             ; else point to next byte of new word
    mov byte ptr [edi],al               ; put byte in the destination buffer
    inc esi                             ; and increment the
    inc edi                             ; other two pointers
    jmp @B                              ; and loop back
@@: movsb                               ; finish copying rest of string
    cmp byte ptr [edi-1],00             ; wait for ending null to be written
    jnz @B                              ; and loop
invoke lstrcpy,lpszDest ,addr szBuffer
invoke RtlZeroMemory,addr szBuffer ,sizeof szBuffer
ret
Format endp



thanks in forward sorry for my misunderstanding

ragdog

Tight_Coder_Ex

These are the changes I've made to get working what you require

lpFormat    db "test1",0Dh,0Ah
            db "test2",0Dh,0Ah
            db "test3",0Dh,0Ah
            db "test4",0Dh,0Ah
    db 0


        invoke GetDlgItemText,hWnd,1002,addr hSrcBuffer,sizeof hSrcBuffer

          mov edi,offset hSrcBuffer
  mov ecx, eax
  mov al, 10
   
    @@: cmp byte ptr [edi], 0
jz @F

      mov ebx, edi
repnz scasb
mov byte ptr [edi - 2], 0

        push ecx
push eax
invoke MessageBox,hWnd,ebx,0,MB_OK
pop eax
pop ecx
jmp @B
@@:

ragdog

thanks Tight_Coder_Ex  for the small parser code

i have a another problem


i want to format every single line from the edit-box

like this format

<  text: line1                             >
<        line2                             >
<        line3                             >
<        line4                             >
...
..
.


greets
ragdog

Tight_Coder_Ex

One way of doing it is statically like

lpFormat    db "text:  line1",0Dh,0Ah
            db "       line2",0Dh,0Ah
            db "       line3",0Dh,0Ah
            db "       line4",0Dh,0Ah
    db 0

or do you need to do it in code?

ragdog

no i mean get any text from multiline editbox and format this line to line



example from editbox :

Format proc                                                 
lpszSrc:DWORD,lpszDest:DWORD,lpszFrm:DWOR                   
D                                                           
                                                             
    mov eax, lpszSrc                                         
    mov szWord,eax                      ; save location of   
entered word             

                                   
to atached example

[attachment deleted by admin]

Tight_Coder_Ex

Maybe you could demonstrate pictorially what you mean.  The way I understand it is;

Text Box

This is going to be a sample demonstration


Output would be

         This
          is
          going
          to
          be
          a
          sample
          demonstration

ragdog

hi

does any have an idea to  solve my problem?  :'(

my current source is added


greets
ragdog

[attachment deleted by admin]

MichaelW

Among other problems your dialog window procedure and your format procedure are failing to preserve the values of EBX, ESI, and EDI. Hopefully, this code will do what you are asking for.

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    .data
      hInstance dd 0
      hWndEdit  dd 0
      hWndList  dd 0
      sz1       db 100 dup(0)
      sz2       db 100 dup(0)
    .code

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

DlgProc proc hDlg:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

    push ebx

    SWITCH uMsg

      CASE WM_INITDIALOG

        invoke GetDlgItem, hDlg, 101
        mov hWndEdit, eax
        invoke GetDlgItem, hDlg, 102
        mov hWndList, eax

      CASE WM_COMMAND

        SWITCH wParam

          CASE 103

            xor ebx, ebx
          @@:
            invoke RtlZeroMemory, ADDR sz1, 100
            mov WORD PTR sz1, 100
            invoke SendMessage, hWndEdit, EM_GETLINE, ebx, ADDR sz1
            test eax, eax
            jz @F
            invoke szTrim, ADDR sz1
            invoke RtlZeroMemory, ADDR sz2, 100
            invoke szMultiCat, 3, ADDR sz2, chr$("<"), ADDR sz1, chr$(">")
            invoke SendMessage, hWndList, LB_ADDSTRING, 0, ADDR sz2
            inc ebx
            jmp @B
          @@:

          CASE IDCANCEL

            invoke EndDialog, hDlg, NULL

        ENDSW


      CASE WM_CLOSE

        invoke EndDialog, hDlg, NULL

    ENDSW

    pop ebx
    return 0

DlgProc endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    invoke GetModuleHandle, NULL
    mov hInstance, eax

    Dialog "Test", \
           "Courier New",8, \
           WS_OVERLAPPED or WS_SYSMENU or DS_CENTER, \
           3,0,0,300,225,1024

    DlgEdit ES_MULTILINE or WS_VSCROLL or WS_HSCROLL or \
            ES_AUTOVSCROLL or ES_AUTOHSCROLL or \
            ES_WANTRETURN or WS_BORDER, \
            10,10,278,80,101

    DlgList WS_VSCROLL or WS_BORDER,10,100,278,80,102

    DlgButton "Format",0,125,180,50,15,103

    CallModalDialog hInstance,0,DlgProc,NULL

    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start
eschew obfuscation

ragdog

thanks MichaelW for you reply and code  :U i studdy this

best regards
ragdog

re:

this works perfect thank you  :U :U