Skip to content

Commit

Permalink
Added the ability to specify the list of structures to process, as we…
Browse files Browse the repository at this point in the history
…ll as any alias and file overrides to be used with those structures, via a structure input file.
  • Loading branch information
SteveIves committed Nov 20, 2021
1 parent 051b1dc commit 41524e4
Show file tree
Hide file tree
Showing 134 changed files with 1,354 additions and 1,152 deletions.
103 changes: 103 additions & 0 deletions CodeGen/CodeGen.dbl
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,97 @@ proc
ok = false
exitCode = 1
end
(1),
begin
;If the single parameter is a file spec then it is a JSON file containing
;the definitions of structures to process, as well as an optional alias and
;file override for each. If not specified, aliases and file overrides
;default to the name of the structure

if (File.Exists(ClValues[0])) then
begin
;;The one parameter after -s is a valid file spec.
;;We will open the file and read structure names from it.
data jsonData, string

try
begin
jsonData = File.ReadAllText(ClValues[0])
end
catch (e, @Exception)
begin
Console.WriteLine("Failed to read structure list from {0}",ClValues[0])
ok = false
exitCode = 1
end
endtry

;Parse the extensions file

data structureDefs, [#]@StructureDefinition

if (ok)
begin
try
begin
structureDefs = JsonConvert.DeserializeObject<[#]@StructureDefinition>(jsonData)
end
catch (e, @Exception)
begin
Console.WriteLine("Failed to parse structure list from {0}",ClValues[0])
ok = false
exitCode = 1
end
endtry
end

;Load the structures, aliases and file overrides

if (ok)
begin
data structureDef, @StructureDefinition
foreach structureDef in structureDefs
begin
;Structure

structureDef.Structure = structureDef.Structure.Trim().ToUpper()
task.Structures.Add(structureDef.Structure)

;Alias

if (String.IsNullOrWhiteSpace(structureDef.Alias)) then
begin
structureDef.Alias = structureDef.Structure
end
else
begin
structureDef.Alias = structureDef.Alias.Trim().ToUpper()
end

task.Aliases.Add(structureDef.Alias)

;File override

if (String.IsNullOrWhiteSpace(structureDef.File)) then
begin
structureDef.File = structureDef.Structure
end
else
begin
structureDef.File = structureDef.File.Trim().ToUpper()
end

task.FileOverrides.Add(structureDef.File)

end
end
end
else
begin
;Single parameter is not a file spec, it's a single structure name
task.Structures.Add(ClValues[0].ToUpper())
end
end
(),
begin
data strName, String
Expand Down Expand Up @@ -1655,6 +1746,12 @@ proc
ok = false
exitCode = 1
end
else if (task.Aliases.Count > 0) then
begin
Console.WriteLine("ERROR: Option -a may not be used with a structure definitions input file. Define aliases in that file!")
ok = false
exitCode = 1
end
else
begin
using ClValues.Count select
Expand Down Expand Up @@ -1756,6 +1853,12 @@ proc
ok = false
exitCode = 1
end
else if (task.FileOverrides.Count > 0) then
begin
Console.WriteLine("ERROR: Option -fo may not be used with a structure definitions input file. Define file overrides in that file!")
ok = false
exitCode = 1
end
else
begin
using ClValues.Count select
Expand Down
1 change: 1 addition & 0 deletions CodeGen/CodeGen.synproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CodeGen.dbl" />
<Compile Include="StructureDefinition.dbl" />
<Compile Include="Documentation.dbl" />
<Compile Include="UpdateManager.dbl" />
<Compile Include="Properties\AssemblyInfo.dbl" />
Expand Down
59 changes: 59 additions & 0 deletions CodeGen/StructureDefinition.dbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
;;*****************************************************************************
;;
;; Title: StructureDefinition.dbl
;;
;; Type: Class
;;
;; Description: Represents the definition of a structure in a structure list
;; input file
;;
;; Date: 19th November 2021
;;
;; Author: Steve Ives, Synergex Professional Services Group
;; http://www.synergex.com
;;
;;*****************************************************************************
;;
;; Copyright (c) 2021, Synergex International, Inc.
;; All rights reserved.
;;
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions are met:
;;
;; * Redistributions of source code must retain the above copyright notice,
;; this list of conditions and the following disclaimer.
;;
;; * Redistributions in binary form must reproduce the above copyright notice,
;; this list of conditions and the following disclaimer in the documentation
;; and/or other materials provided with the distribution.
;;
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
;; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
;; POSSIBILITY OF SUCH DAMAGE.
;;
;;*****************************************************************************

import Newtonsoft.Json

namespace CodeGen

public class StructureDefinition

{JsonProperty(Required=Required.Always)}
public readwrite property Structure, string

public readwrite property Alias, string

public readwrite property File, string

endclass

endnamespace
11 changes: 11 additions & 0 deletions CodeGen/Usage.dbl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ proc
Console.WriteLine(" possible to generate a 'pseudo structure' based on the fields within")
Console.WriteLine(" an implicit group within a structure.")
Console.WriteLine("")
Console.WriteLine(" If you need to process a large number of structures you can use the")
Console.WriteLine(" -s option to specify a single structure list input file that defines")
Console.WriteLine(" structure names, and also optionally structure alias names and file")
Console.WriteLine(" override names.")
Console.WriteLine("")

;;Limit for text -------------------------------------------------------------------------------
Console.WriteLine(" -t [*]template [...]")
Expand Down Expand Up @@ -96,6 +101,9 @@ proc
Console.WriteLine(" separated by spaces, up to but not exceeding the number of structure")
Console.WriteLine(" names that have been specified via the -s option.")
Console.WriteLine("")
Console.WriteLine(" If you are using a structure list input file then structure aliases")
Console.WriteLine(" must be specified via that file.")
Console.WriteLine("")

;;Limit for text -------------------------------------------------------------------------------
Console.WriteLine(" -af")
Expand Down Expand Up @@ -247,6 +255,9 @@ proc
Console.WriteLine(" overrides for multiple structures, up to but not exceeding the number")
Console.WriteLine(" of structures specified via the -s option.")
Console.WriteLine("")
Console.WriteLine(" If you are using a structure list input file then file overrides")
Console.WriteLine(" must be specified via that file.")
Console.WriteLine("")

;;Limit for text -------------------------------------------------------------------------------
Console.WriteLine(" -g f|r|i")
Expand Down
Binary file modified Documentation/CodeGen.chm
Binary file not shown.
Binary file modified Documentation/CodeGen.hsm
Binary file not shown.

0 comments on commit 41524e4

Please sign in to comment.