WBStudio.WspopupMnu.SpellCheck
Download: WinBatch WBStudio Wspopup.mnu spell checker database (20110205).
;==========================================================================================================================================
; WBStudio Utility for use within WinBatch Studio debug mode.
;==========================================================================================================================================
;
; "Spell Check" for WSPOPUP.MNU - Read/Write -
;
; This script does a spellcheck on Item1 and Item2 of special menu title lines of wspopup.mnu
; by lookup into a keyword database with proper spell checked words.
;
; It works directly on the file wspopup.mnu - virtually in WBStudio editor -
; but user must decide to save changes afterwards.
;
;..........................................................................................................................................
;
; >>> The running script can be terminated by pressing the Shift key. <<<
;
; Adapt the filepathes to your environment (see "Options - Tweak Section")
; for the Wspop.mnu file and the keyword database textfile.
;
;..........................................................................................................................................
; Version History:
; 20090711. Changed StrCat() to colon ":" concatenator and beautified the code.
; 20051215. Initial version.
;
; Detlev Dalitz.20051215.
;==========================================================================================================================================

;------------------------------------------------------------------------------------------------------------------------------------------
Terminate (RtStatus () != 10, IntControl (1004, 0, 0, 0, 0), "Terminated. Script runs only in WinBatch Studio debug mode.")
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
; ****** Options - Tweak Section ****** adapt it to your environment ******
;
;
sWorkFile = DirHome () : "Wspopup.mnu"
sLookupFile = "W:\WINBATCH\WBSTUDIO\WBStudio.WspopupMnu.SpellCheck.txt"
;
;
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
; Set Editor AutoIndent OFF.
iAutoIndent = RegQueryDword (@REGCURRENT, "Software\Wilson WindowWare\WinBatch Studio\Settings\File types\WIL Files[Autoindent]")
If iAutoIndent
   SendKey ("!vo!a~") ; Function wViewOptions() does not fit in this case.
   TimeDelay (1)
   iAutoIndent = RegQueryDword (@REGCURRENT, "Software\Wilson WindowWare\WinBatch Studio\Settings\File types\WIL Files[Autoindent]")
   Terminate (iAutoIndent, IntControl (1004, 0, 0, 0, 0), "Terminated. Cannot set registry value [Autoindent]=off.")
EndIf
;------------------------------------------------------------------------------------------------------------------------------------------
wFileOpen (sWorkFile)
wTopOfFile ()
iLineCount = wLineCount ()
;------------------------------------------------------------------------------------------------------------------------------------------
wFileOpen (sLookupFile)
wTopOfFile ()
;------------------------------------------------------------------------------------------------------------------------------------------
SendKey ("!wh") ; Tile horizontal MDI windows in WBStudio editor. ; Function wWinTile() does not fit in this case.
;------------------------------------------------------------------------------------------------------------------------------------------
sHeader = TimeYmdHms () : " - WSPOPUP.MNU - SpellCheck Reserved Words" : @LF
sExitMsg = "Ready."
;------------------------------------------------------------------------------------------------------------------------------------------
iCountTouched = 0
iCountChangedItem1 = 0
iCountChangedItem2 = 0
iCountNotChanged = 0
iCountDBError = 0
sOut = ""
While @TRUE
   wFileOpen (sWorkFile)
   wClearSel ()
   ; Search within WSPOPUP.MNU for menu title lines.
   wf_sPattern = "^.+\^.+\^.*\^.*$" ; Pattern for menu title lines.
   wf_iForward = @TRUE
   wf_iMatchCase = @TRUE
   wf_iRegExp = @TRUE
   wf_iWrap = @FALSE

   wf_iResult = wFind (wf_sPattern, wf_iForward, wf_iMatchCase, wf_iRegExp, wf_iWrap)
   If !wf_iResult Then Break

   ; Fill selection buffer with hit line from wspopup.mnu.
   sPopLine = wGetWord ()

   iLine = wGetLineNo ()
   sLineNum = StrFixLeft (iLine, " ", 6)

   ;..........................................................................................................................................
   ; Work on Item2
   ;..........................................................................................................................................
   ; Fetch Item2 Keyword from selection buffer.
   sPopLine2 = ItemExtract (2, sPopLine, "^")

   If StrIndex (sPopLine2, ".", 1, @FWDSCAN) Then Continue ; If special "long.text.line" menu title then Continue.

   ;..........................................................................................................................................
   ; Work on Lookup
   ;..........................................................................................................................................
   wFileOpen (sLookupFile)
   wClearSel ()
   ; Search within lookup file.
   wf_sPattern = "^" : sPopLine2 : "="
   wf_iForward = @TRUE
   wf_iMatchCase = @FALSE
   wf_iRegExp = @TRUE
   wf_iWrap = @TRUE

   wf_iResult = wFind (wf_sPattern, wf_iForward, wf_iMatchCase, wf_iRegExp, wf_iWrap)
   If !wf_iResult
      sMsg = "??? Not found: '" : sPopLine2 : "'"
      ;sMsg = StrCat("`",sMsg,"`")  ; "Literal Red Tag in Studio"
      sMsg = sLineNum : "  |" : sMsg
      sOut = ItemInsert (sMsg, -1, sOut, @LF)
      sPopLine = sLineNum : "  |" : sPopLine
      sOut = ItemInsert (sPopLine, -1, sOut, @LF)
      iCountDBError = iCountDBError + 1
      Continue
   EndIf

   sPopLookup = wGetWord ()
   sPopLookup = ItemExtract (1, sPopLookup, "=")

   ;..........................................................................................................................................
   ; Work on Item2
   ;..........................................................................................................................................
   sPopLine2 = sPopLookup

   ; Store back Item2 into selection buffer.
   sPopLine = ItemReplace (sPopLine2, 2, sPopLine, "^")

   ; Report.
   If (StrCmp (sPopLine2, sPopLookup) != 0)
      sMsg = "--- Item2 changed from: '" : sPopLine2 : "' to: '" : sPopLookup : "'"
      ;sMsg = StrCat("`",sMsg,"`")  ; "Literal Red Tag in Studio"
      sMsg = sLineNum : "  |" : sMsg
      sOut = ItemInsert (sMsg, -1, sOut, @LF)
      iCountChangedItem2 = iCountChangedItem2 + 1
   EndIf

   ;..........................................................................................................................................
   ; Work on Item1
   ;..........................................................................................................................................
   ; Fetch Item1 Menu title from selection buffer.
   sPopLine1 = ItemExtract (1, sPopLine, "^")

   iWild = StrIndexWild (sPopLine1, sPopLookup, 1)
   If iWild
      sWild = StrSubWild (sPopLine1, sPopLookup, iWild)
      If (StrCmp (sWild, sPopLookup) != 0)
         sPopLine1 = StrReplace (sPopLine1, sWild, sPopLookup)

         ; Store back Item1 into selection buffer.
         sPopLine = ItemReplace (sPopLine1, 1, sPopLine, "^")

         ; Report.
         sMsg = "--- Item1 changed from: '" : sWild : "' to: '" : sPopLookup : "'"
         ;sMsg = StrCat("`",sMsg,"`")  ; "Literal Red Tag in Studio"
         sMsg = sLineNum : "  |" : sMsg
         sOut = ItemInsert (sMsg, -1, sOut, @LF)
         iCountChangedItem1 = iCountChangedItem1 + 1
      EndIf
   Else
      ; Report.
      sMsg = "### Item1 cannot be changed by automatic. Need review."
      ;sMsg = StrCat("`",sMsg,"`")  ; "Literal Red Tag in Studio"
      sMsg = sLineNum : "  |" : sMsg
      sOut = ItemInsert (sMsg, -1, sOut, @LF)
      iCountNotChanged = iCountNotChanged + 1
   EndIf

   ;..........................................................................................................................................
   ; Write back.
   ;..........................................................................................................................................
   ; Write back selection buffer into the file.
   wFileOpen (sWorkFile)
   wInsString (sPopLine)

   iCountTouched = iCountTouched + 1

   sLineNum = StrFixLeft (iLine, " ", 6)
   sPopLine = sLineNum : "  |" : sPopLine
   sOut = ItemInsert (sPopLine, -1, sOut, @LF)

   sStatusMsg = iLineCount : "/" : sPopLine
   wStatusMsg (sStatusMsg)

   If IsKeyDown (@SHIFT)
      sExitMsg = "*** Aborted. ***"
      Break
   EndIf
EndWhile

wFileOpen (sLookupFile)
wWinClose ()

wFileOpen (sWorkFile)
wClearSel ()
wTopOfFile ()
;------------------------------------------------------------------------------------------------------------------------------------------
If sOut != ""
   sOut = ItemInsert ("", -1, sOut, @LF)
   sOut = ItemInsert (TimeYmdHms () : " - Line " : iLineCount : "/" : iLine, -1, sOut, @LF)
   sOut = ItemInsert (" - Lines touched ..: " : iCountTouched, -1, sOut, @LF)
   sOut = ItemInsert (" - Item1 changed ..: " : iCountChangedItem1, -1, sOut, @LF)
   sOut = ItemInsert (" - Item2 changed ..: " : iCountChangedItem2, -1, sOut, @LF)
   sOut = ItemInsert (" - Not changed ....: " : iCountNotChanged, -1, sOut, @LF)
   sOut = ItemInsert (" - DB Lookup Error : " : iCountDBError, -1, sOut, @LF)
   sOut = ItemInsert (sExitMsg, -1, sOut, @LF) ; Add Footer.
   sOut = ItemInsert (sHeader, 0, sOut, @LF) ; Add Header.
   sOut = StrReplace (sOut, @LF, @CRLF)
EndIf
;------------------------------------------------------------------------------------------------------------------------------------------

;------------------------------------------------------------------------------------------------------------------------------------------
:CANCEL
RegSetDword (@REGCURRENT, "Software\Wilson WindowWare\WinBatch Studio\Settings\File types\WIL Files[Autoindent]", iAutoIndent)
;------------------------------------------------------------------------------------------------------------------------------------------
wWinMaximize ()  ; SendKey("!-x") ; Maximize MDI window in WBStudio editor.
;------------------------------------------------------------------------------------------------------------------------------------------
If sOut == "" Then sOut = "*** No output. ***"
ClipPut (sOut)
wFileNew ()
wPaste ()
Exit
;------------------------------------------------------------------------------------------------------------------------------------------