WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Syntax Checker

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Quote and Parenthesis Checker

Keywords:    Quote and Parenthesis checker syntax

I wrote a very simple winbatch program that searches my source code for two common errors that I sometimes make.

1. odd number of ( ) backets

2. unmatched " quotes.


;Written by Myles
CurrentDir=FilePath(IntControl(1004,0,0,0,0))

:top
file=AskFileName("Pick a winbatch file to check", CurrentDir, "*.wbt", "*.wbt", 1)
hdl = FileOpen(file, "READ")
linenum=1 
bad=0
while @TRUE
      line = FileRead(hdl)
      gosub read_line
      linenum=linenum+1
      If line == "*EOF*" Then Break
endwhile

message("Done","Processed %linenum% line(s) and found %bad% bad lines(s) ")
goto top

:read_line
c=0
s=1
while s > 0
   s=StrIndexNc (line,"(", s,@FWDSCAN )
   if s == 0 then break
   if s > 0
      s=s+1
      c=c+1
   endif
endwhile

d=0
s=1
while s > 0
   s=StrIndexNc (line,")", s,@FWDSCAN )
   if s == 0 then break
   if s > 0
      s=s+1
      d=d+1
   endif
endwhile

if c <> d 
   message("Bad line found",StrCat("Bad coding on line: %linenum%      Missing bracket ( or )",@crlf,@crlf,@crlf,line,@crlf,@crlf,@crlf))
   bad=bad+1 
endif

e=0
s=1
while s > 0
   s=StrIndexNc (line,'"', s,@FWDSCAN )
   if s == 0 then break
   if s > 0
      s=s+1
      e=e+1
   endif
endwhile

t = e mod 2
if t <> 0
   message("Bad line found",StrCat('Bad coding on line: %linenum%     Odd number of " ',@crlf,@crlf,@crlf,line,@crlf,@crlf,@crlf))
   bad=bad+1    
endif

return

Article ID:   W15294
File Created: 2002:09:05:13:51:06
Last Updated: 2002:09:05:13:51:06