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

Samples from Users
plus

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

Capitialize Function Names


Question:

I hate to bring this up, as it shows how obsessive-compulsive I can be at times, but one thing that bothers me no end is the formatting of code samples from this board. There are so many good pieces of code on this board that I can't help but save lots of them, but everyone has their own peculiarities when it comes to whitespace in code, capitalization, etc., and it disturbs me when code looks different, so I often go through and change the code I find on this board to my own idea of right... So what I'm wondering is if anyone has written a WB Studio add-in to search for WinBatch functions and set the case on them--i.e.:
if Somefunction
anotherfunction
endif
would become:
If SomeFunction
AnotherFunction
EndIf

Answer:

I think for "Right Casing" functions you might have to do something like load WIL.CLR into an array or LAFFDB table then figure out a way to identify a function name in the program, search for it in the list of functions and replace what you found in the program with what you found in the list of functions, be it array or otherwise.

Here is some sample code. It needs the xCAM array extender to run.

Note: When using this utility in WinBatch Studio, the array extender and the CAM array will never be unloaded while WBStudio is up.

You might make some enhancements to the proposal. For example, load the CAM array from ready made dump file, so that it must not created each time when it is first time invoked. Or let it loop to make pretty a complete line or whatever else.

Overall it is a good demonstration for the usage of the xCAM lookup array mechanism.


;==========================================================================================================================================
; MakePretty.wbt
;------------------------------------------------------------------------------------------------------------------------------------------
; This script tries to replace the word under the cursor with the same word,
; accordingly good looking and proper cased, as it is defined in the WIL.CLR file.
; Use this script only in WinBatch Studio Editor.
;
; Insert following two lines into your personal WSP-USER.MNU file at appropriate place.
; This will let you invoke the script by pressing [Ctrl+F6].
;
;    MakePrettyKeyword   \ ^{F6}
;       Call("G:\TEMP\WBT\MakePretty.wbt","") ; <== Change path to your needs.
;
;------------------------------------------------------------------------------------------------------------------------------------------
; Detlev Dalitz.20031023
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
sFileExtCAM = "D:\Programme\WinBatch\System\XCAM34I.DLL" ; <== Change path to your needs.
sFileCLR    = "D:\Programme\WinBatch\System\WIL.CLR"     ; <== Change path to your needs.
;------------------------------------------------------------------------------------------------------------------------------------------
If !IsDefined(aCAMKeyword)
   Display(2,"WSP-USER.MNU","Loading MakePrettyKeyword ...") ; This message is displayed only once when creating the CAM.
   AddExtender(sFileExtCAM)

   ; This implements a fast read routine for reading large section from an inifile.
   ; All lines of inifile must be terminated by @CRLF sequence.

   ; Read the CLR file completely into a string.
   ; Insert one helper @LF at the beginning of the stream, and one helper @CR at end of stream.
   sIni = StrCat(@LF,FileGet(sFileCLR),@CR)

   ; Remove empty lines.
   sSearch = StrCat(@LF,@CR)
   sReplace = ""
   While (StrIndex(sIni,sSearch,1,@FWDSCAN))
      sIni = StrReplace(sIni,sSearch,sReplace)
   EndWhile

   ; For sure, remove leading blanks.
   sSearch = StrCat(@LF," ")
   sReplace = @LF
   While (StrIndex(sIni,sSearch,1,@FWDSCAN))
      sIni = StrReplace(sIni,sSearch,sReplace)
   EndWhile

   ; Find the proper section and skip over section header line.
   iScan = StrIndexNC(sIni,"[keywords]",1,@FWDSCAN)
   If !iScan
      sTermTitle = "Error"
      sTermText  = StrCat("Inifile is damaged:",@LF,"{1}")
      sTermText  = StrReplace (sTermText,"{1}",sFileWilClr)
      Terminate(iTermBool,sTermTitle,sTermText)
   EndIf
   iScan = StrIndex(sIni,@LF,iScan,@FWDSCAN)
   If !iScan
      sTermTitle = "Error"
      sTermText  = StrCat("Inifile is damaged:",@LF,"{1}")
      sTermText  = StrReplace (sTermText,"{1}",sFileWilClr)
      Terminate(iTermBool,sTermTitle,sTermText)
   EndIf
   iSection = iScan

   ; Find end of section.
   iScan = StrIndex(sIni,StrCat(@LF,"["),iScan,@FWDSCAN)
   If iScan
      sIni = StrSub(sIni,iSection,iScan-iStart+1)
   Else
      sIni = StrSub(sIni,iSection,-1)
   EndIf

   ; Delete comment lines.
   sSearch = StrCat(@LF,";")
   sSearchWild = StrCat(@LF,";*",@CR)
   iScan = 0
   While @TRUE
      iScan = StrIndex(sIni,sSearch,iScan,@FWDSCAN)
      If !iScan Then Break
      sWild = StrSubWild(sIni,sSearchWild,iScan)
      sIni = StrReplace(sIni,sWild,"")
   EndWhile

   ; Remove all @CR.
   sIni = StrReplace(sIni,@CR,"")

   ; Remove leading blanks.
   sSearch = "= "
   sReplace = "="
   While (StrIndex(sIni,sSearch,1,@FWDSCAN))
      sIni = StrReplace(sIni,sSearch,sReplace)
   EndWhile

   ;Create CAM array.
   aCAMKeyword = camCAMFromArray(camArrayFromList(StrSub(sIni,2,-1),StrCat(@LF,"="),0),0,0)

EndIf
Drop(iScan,iSection,sFileCAM,sFileCLR,sFileExtCAM,sIni,sReplace,sSearch,sSearchWild,sTermText,sTermTitle,sWild)
;------------------------------------------------------------------------------------------------------------------------------------------
sUgly = wGetWord()
sPretty = camGet(aCAMKeyword,sUgly)
If (sPretty !="*EOF*CAM*")
   wWordLeft()
   iStrLen = StrLen(sUgly)
   For ii=1 To iStrLen
      wDelete()
   Next
   wInsString(sPretty)
EndIf
Drop(ii,iStrLen,sPretty,sUgly)
Exit
;==========================================================================================================================================

Article ID:   W16265
File Created: 2004:03:30:15:43:40
Last Updated: 2004:03:30:15:43:40