Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Simple Sample

To declare a method, test, add it to a gmSL block:

Code Block
<gmSL namespace="gmSL" class="gm"><[CDATA[[
void test(string arg1)
{
        System.LogMessage("Here i am: " + arg1);
}
]]></gmsl>

To run a method, invoke it with a RunCommand statement, using a gm. prefix. For example:

Code Block
<RunCommand id="test" Prams="Mark" />

...

Custom Source Inspection

Another example – pre-inspection of a file:

 

 

Code Block
   <Load Project="%SrcPath%" SourceCode="on" />
   
   <gmSL namespace="gmSL" class="gm"><[CDATA[[
   void InspectCode()
   {
      int       levels(19);
      int       iRoot;
      tInfoFile formFile;
      Text      textStream;
      int       nRecord;
      int       curRecord;
      int       length = 0;
      int       rai = 0;
      string    record;
      string    token;
      int       lexeme;

      for(iRoot = Store.FindFirstChild(levels,0); iRoot != 0; iRoot = Store.FindNextChild(levels))
      {         
         if(Store.GetObjectType(iRoot) != ObjectType.FormFile) continue;
         string name = Symbol.FullName(iRoot,0);
         System.LogMessage("name=" + name);
         
         formFile = Store.GetVector(iRoot);
         if(formFile.textBase == 0) continue;
         System.LogMessage("formFile.textBase=" + formFile.textBase);
         
         textStream = Text.Open(Store.GetHandle(),formFile.textBase);
         System.LogMessage("textStream=" + textStream);

         nRecord = Text.Maximum(textStream);
         curRecord = 0;
         while(curRecord < nRecord)
         {
            curRecord = curRecord + 1;
            Text.Position(textStream,curRecord);
            record = Text.Access(textStream, length, rai, 0);
            if(length < 10) continue;
            Parser.SetStatement(record);
            token = Parser.GetToken(lexeme);
            if(token == "Attribute") break;
            if(token != "Begin") continue;
            token = Parser.GetToken(lexeme);
            if(token != "MSComctlLib") continue;
            System.LogMessage("record=" + record);
            while(lexeme>0)
            {
               System.LogMessage("  token=[" + token + "] lexeme=" + lexeme);
               token = Parser.GetToken(lexeme);
            }   
         }
         Text.Close(textStream);
      }
   }
]]></gmsl>
   <RunCommand id="InspectCode"  />
 
	<Compile...>
No Format
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Translation Log: C:\gmSamples\NewSamples\FileExplorerAPI\proj_csh\log\FileExplorer_csh-FileExplorer-gms-csh.TRAN.log
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Basic Processor V30.76(07/18/18) System Build(07/18/18 5:26:53)
Processing file: C:\gmSamples\NewSamples\FileExplorerAPI\src\FileExplorer.vbp
Reprocessing file: gm.cls
Reprocessing file: gm.cls
name=frmExploreLite.frm
formFile.textBase=3838
textStream=4
record=   Begin MSComctlLib.Toolbar Toolbar1
  token=[MSComctlLib] lexeme=2
  token=[.] lexeme=1
  token=[Toolbar] lexeme=2
  token=[Toolbar1] lexeme=2
record=   Begin MSComctlLib.ImageList ilSmall
  token=[MSComctlLib] lexeme=2
  token=[.] lexeme=1
  token=[ImageList] lexeme=2
  token=[ilSmall] lexeme=2
record=   Begin MSComctlLib.ImageList ilMain
  token=[MSComctlLib] lexeme=2
  token=[.] lexeme=1
  token=[ImageList] lexeme=2
  token=[ilMain] lexeme=2
record=   Begin MSComctlLib.ListView lvListView
  token=[MSComctlLib] lexeme=2
  token=[.] lexeme=1
  token=[ListView] lexeme=2
  token=[lvListView] lexeme=2
record=   Begin MSComctlLib.TreeView tvTreeView
  token=[MSComctlLib] lexeme=2
  token=[.] lexeme=1
  token=[TreeView] lexeme=2
  token=[tvTreeView] lexeme=2
record=   Begin MSComctlLib.StatusBar sbStatusBar
  token=[MSComctlLib] lexeme=2
  token=[.] lexeme=1
  token=[StatusBar] lexeme=2
  token=[sbStatusBar] lexeme=2
...
Translation Time (sec) = 0.25

 

 

...

Custom Source Edit

Here is an example that edits files: adding a comment to lines in form files ending with ':'

Code Block
<ScriptRules>
<ScriptRule id="PreEditor" Condition="%TaskTag% AND %SrcName%=='upg AND FileExplorer'">
<Option>
   <Load Project="%SrcPath%" SourceCode="on" />
    
   <gmSL namespace="gmSL" class="gm"><[CDATA[[
   void InspectCode()
   {
      int       levels(19);
      int       iRoot;
      tInfoFile formFile;
      Text      textStream;
      int       nRecord;
      int       curRecord;
      int       length = 0;
      int       rai = 0;
      string    record;
      string    token;
      int       lexeme;
 
      for(iRoot = Store.FindFirstChild(levels,0); iRoot != 0; iRoot = Store.FindNextChild(levels))
      {        
         if(Store.GetObjectType(iRoot) != ObjectType.FormFile) continue;
         string name = Symbol.FullName(iRoot,0);
         System.LogMessage("name=" + name);
          
         formFile = Store.GetVector(iRoot);
         if(formFile.textBase == 0) continue;
         System.LogMessage("formFile.textBase=" + formFile.textBase);
          
         textStream = Text.Open(Store.GetHandle(),formFile.textBase);
         System.LogMessage("textStream=" + textStream);
 
         // sample code changes lines ending with ":" to lines ending with ": 'TEST"
         nRecord = Text.Maximum(textStream);
         curRecord = 0;
         while(curRecord < nRecord)
         {
            curRecord = curRecord + 1;
            Text.Position(textStream,curRecord);
            record = Text.Access(textStream, length, rai, 0);
            
            if(length < 2) continue;
            string last = Character.SubStr(record,length-1,1);
            string colon = ":"; // if statement has issues with ":"
            if (last==colon) 
            {
               // Inserts a record after the current record and sets Position to new record
               Text.Insert(textStream,record + " ' TEST");
               // reset position to original record
               Text.Position(textStream,curRecord);
               // delete original record
               Text.Delete(textStream,curRecord);
               continue;
            }
         }
         Text.Close(textStream);
      }
   }
   ]]></gmsl>
 
   <RunCommand id="InspectCode"  />
</Option>
</ScriptRule>
</ScriptRules>

add to script with

   <ScriptRule id="PreEditor" fileName="PreEditor.Rules.xml" />
   
   <Compile Resx="%ResxFolder%" />




Table of Contents