WinAsm Studio, The Assembly IDE - Free Downloads, Source Code
Sponsors
Articles
Programming Quick Start
32-bit Assembler is Easy
Porting Iczelion tutorials
What is FASM
Hard Drive Recovery
Wiring your own LAN
Personal menu
Welcome Guest
User:
Pass:
Register!
Resend Validation Email
 
Forum
 

wtok issues, wtok seems to have dissapearing values returned

yguy
Quote Post


New Member
*

Group: Members
Posts: 6
Member No.: 28293
Joined: 30-October 09


Hi all, new here. 1st post (easy on me). Here's the code...


LOCAL pTokens :DWORD
LOCAL hFile :DWORD
LOCAL pread :DWORD
LOCAL pwrite :DWORD
LOCAL pfile :DWORD
LOCAL ptank :DWORD
LOCAL pbuffer :DWORD
LOCAL fsz :DWORD
LOCAL max :DWORD

mov pfile,InputFile("qdos.asm")
mov fsz, ecx
push edi
mov edi, rv(lfcnt,pfile)
add edi, 1
mov max, edi
mov pbuffer, alloc(fsz)
mov ptank, alloc(180)
mov pread, 0
mov pwrite, 0

@@:
mov pread, linein$(pfile,ptank,pread)
invoke decomment,ptank
mov ptank, remove$(ptank, ";")
test tstline$(ptank), eax
jz skip_blank_lines
mov pwrite, lineout$(ptank,pbuffer,pwrite,0)
skip_blank_lines:
sub edi, 1
jnz @B
free ptank
free pfile

mov edi,rv(wtok,pbuffer,addr pTokens)
free pbuffer
mov hFile,fcreate("tester.txt")
push esi
mov esi, pTokens

@@:
fprint hFile,[esi]
add esi, 4
sub edi, 1
jnz @B

fclose hFile
free pTokens

pop esi
pop edi



The source file is this...


include \masm32\include\qdos.inc
.data
userstring db "testing 1, 2, 3...",0

runDos
lea eax, userstring
mov eax, remove$(eax, "testing ") ; eax gets the address of the altered string as the return value
println eax ; println addr userstring

println
exitDos


And the wtok output of my code is this...


\masm32\include\qdos.inc
.data
userstring
db
"testing 1, 2, 3..."
0
runDos
lea
eax,
userstring
mov
eax,
remove$(eax,
"testing "
println
eax
println
exitDos


The string "include" is missing from the top of the output, as are all left parentheses ')'. I've tested all of the variables up to the wtok call, and the strings exists up to when the call is made; they're missing afterwards.

btw - disregard the runDos, println, and exitDos in the above code. They're custom macros.

If you have any ideas, I'd sure appreciate hearing them. Thanks in advance!
yguy
PMEmail Poster
Top
yguy
Quote Post


New Member
*

Group: Members
Posts: 6
Member No.: 28293
Joined: 30-October 09


I figured out how to get the output that I wanted (I'll bet I recreated the wheel, though). Here's my updated code...
CODE

.486
.MODEL flat, stdcall
OPTION casemap :none

include \masm32\include\windows.inc
include \masm32\include\masm32.inc
include \masm32\include\kernel32.inc
include \masm32\include\oleaut32.inc
include \masm32\macros\macros.asm
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\oleaut32.lib

.DATA?
pSource  DWORD ?
pDest  DWORD ?
pTemp  DWORD ?
pTokens DWORD ?
.DATA
szSource DWORD 0
bFlag  DWORD 0
rPos  DWORD 0
wPos  DWORD 0
hFile  DWORD 0
.CODE
start:
; Load the source file
mov  pSource, InputFile("C:\masm32\Projects\qdos\qdos.asm")
mov szSource,ecx

; Create a destination buffer to hold the processed text
lea eax,[ecx*2]
mov pDest,alloc$(eax)

; Remove certain characters in the pSource and replace them with #32,
; unless they're within quoted text
mov edi,szSource
mov esi,pSource
mov bFlag,0

@@:
 cmp BYTE PTR[esi],'"'
 je __trip_flag
 cmp BYTE PTR[esi],','
 je __do_something
 cmp BYTE PTR[esi],'('
 je __do_something
 cmp BYTE PTR[esi],')'
 je __do_something
 cmp BYTE PTR[esi],'{'
 je __do_something
 cmp BYTE PTR[esi],'}'
 je __do_something
 cmp BYTE PTR[esi],'['
 je __do_something
 cmp BYTE PTR[esi],']'
 je __do_something
 jmp __do_nothing
__trip_flag:
 not bFlag
 jmp __do_nothing
__do_something:
 cmp bFlag,0
 jne __do_nothing
 mov BYTE PTR[esi],32
__do_nothing:
 inc esi
 dec edi
jnz @B

; Create a buffer to process individual text lines
mov pTemp,alloc$(16000)
mov edi,rv(lfcnt,pSource)
mov rPos,0
mov wPos,0

@@:
; Strip blank lines, comments, and padding from text line
 mov eax,pTemp
 mov eax,[eax]
 mov eax,0
 mov rPos,linein$(pSource,pTemp,rPos)
 invoke szMonoSpace,pTemp
 invoke decomment,pTemp
 mov pTemp,remove$(pTemp,";")
 test tstline$(pTemp),eax
 jz __ender
 
; Append the carriage return, line feed, and 0 termination...
 mov esi,pTemp
 mov eax,len(pTemp)
 mov WORD PTR[esi+eax],0D0Ah
 add eax,2
 mov BYTE PTR[esi+eax],0
 mov wPos,lineout$(pTemp,pDest,wPos,1)
__ender:
 dec edi
jnz @B

; Create tokenized text lines, and write them to file
free$ pTemp
mov edi,rv(wtok,pDest,addr pTokens)
free$ pDest
mov esi,pTokens
mov hFile,fcreate("tester.txt")

@@:
 fprint hFile,[esi]
 add esi,4
 dec edi
jnz @B

fclose hFile
free pTokens
free pSource

ret
END start


And here's the output that it produces; this is what I was trying
to figure out in my 1st post...


include
\masm32\include\qdos.inc
.data
userstring
db
"testing 1, 2, 3..."
0
runDos
lea
eax
userstring
mov
eax
remove$
eax
"testing "
println
eax
println
exitDos


Is there a more efficient way to do this type of parsing, or am I on the right track? Any input would be appreciated.
PMEmail Poster
Top
GRINcoide
Quote Post


New Member
*

Group: Members
Posts: 1
Member No.: 29860
Joined: 10-December 09


This phrase, is matchless)))
PMEmail PosterUsers WebsiteICQAOLYahooMSN
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

Topic Options Reply to this topicStart new topicStart Poll

 

Sponsors
Computer Science

Internet
C/C++
Hardware & PC maintenance

HiEditor

General Discussions
Suggestions/Bug Reports
WinAsm Studio

General Discussions
Suggestions/Bug Reports
WinAsm Studio FAQ
Multilingual User Interface
Add-Ins
Assembly Programming

Main
Newbies
Projects
Custom Controls
Snippets
Announcements & Rules

Announcements

General

Online Degrees - Distance Learning
The Heap
Russian
Google