This is the CodeGen part of QuickRez. This is the template source file used
by QuickRez. We were hoping to release a BP 7 and C++ TVision version, but 
due to lack of demand and $$ they have been delayed. We need your help and 
registrations to help us keep the development effort alive. We are releasing
the CodeGen module to perhaps stimulate a few users to enhance it and perhaps
offer suggestions. 

Note : This code is provided as is. Use and/or modify at your own risk. Any 
improvements or enhancements are welcome so long as you also indicate that you
are deriving from this work. The authors at Tri-Power would also like a copy of your
works. You can send them via Compuserve to 72451,622 or mail them to :

Tri-Power Consultants
3149 Casa De Campo #F306
San Mateo CA  94403-2155


CG Engine:
----------
Current KeyWord List:
 %xxxx           - Parameter number, passed in
 DateTime        - Date and time stamp
 Message         - Message to Screen (User notification)
 DefineOutput    - Define an output file.
 IfDef           - If String (Type) is defined...
   Else
   EndIf
 USES            - Execute Uses Statement
 Repeat          - Looping Construct (for particular types of resources)
 AppStatus       - Application Status Bar (Generate)
 AppMenuBar      - Application Menu Bar (Generate)
 ObjStringList   - Generate string lists
 ObjRegNumber    - Generate ObjType registration number
 SubViewNumber   - Current sub-view (tab ordered)
 ClearSubNumber  - Clear the current sub vew number
 ObjCode         - Go to Sub Topic TType of the current object (using obj name)
 Fields          - Generate Default View Fields
 ObjFields       - Generate Object Special fields
 SetFields       - Setup View Fields (which to write out)
 RezList         - Generate INTERNAL Resource list of type X
 RezCount        - Get the Count from that Internal List
 SubViews        - Process all subviews within the current object
 ForAll          - Looping Construct
   EndFor
 Var             - Reference a literal variable.
 CycleSubViews   - Loop through sub-views of a resource.
   EndCycle
 Call            - Call a USER DEFINED sub-topic.
 IfCompare       - Compare two quoted values for conditional parsing.
 ExpandFields    - Used to EXPAND FLAG VALUES Into Program Statements.
 Count           - Return a count of the given type(s) of resources.
 CycleStringList - Loop through all the strings in a TStrList.
 ReportObjects   - List out the list of User ID's in report style format.
 CycleMainMenus  - Cycle through the MAIN MENUS of a menu bar.
 CycleSubMenus   - Cycle through ONE SUB LEVEL of the current menu object.
 Replicate       - Create a repeated string of a single character.
 LoadObj         - Force a LOAD of a user object for work.
 FreeObj         - Free the object from a forced load.


FILE FORMAT:
------------

  o Keywords are indicated by: << keyword [ parameter ] >>

  o Source File is encrypted.  Each string is XOR'd with two bytes.

  o If A strings first character = #0 then that entire line is nothing
     but a keyword and parameters.  No Output is generated for that line.

  o Keywords are surrounded by #255 (keyword & Params) #254
    Keyword Format:
            $ff mm xx yy.....yyy $fe

    Where: mm xx = keyword Number
           mm xx <  $8000 then internal keyword reference
           mm xx >= $8000 then External Keyword Reference
           mm xx =  $0000 then the following word is a %Var reference.
           yy.yy =  Parameter Reference

    If mm xx = $8000 then ERROR (kw not defined)

  o Parameters are stored as LITERAL ASCII Strings, separated by commas.
    Format:
           $ff mm xx 1,"this is a string",bb zz yy,"Next Param" $fe

    Where: mm xx = Keyword
           bb    = $0  then zz yy = Percent Parameter "%xxxx"
           bb    = $1  then zz yy = Lookup to Internal Variable.
           bb    = $2  then zz yy = Lookup EXTERNAL Variable.
           bb ord $80 + above value = enquote result string.

    If a %xxxx parameter is referenced, and the literal is a double quoted
    string then if the symbol is NOT $%xxxx then the double quotes are
    removed AFTER resolution of %xxxx.  Passing a % symbol MUST indicate
    a DOUBLE QUOTE if passing a string!!

  o String literals are Double Quoted.

  o keywords: IF, ELSE, and ENDIF are to be contained on their own separate
      line.  They cannot be matched with other keywords on the same line.

New Constraints:
----------------

Keyword(s):  IfDef[xxxx] ... { Else } .... Endif

   If the operational constant symbol "xxxxx" is defined, then do the
   following... else do .... endif.

   Internal xxxx symbols used:
   ---------------------------
   CPP            - Yes, C++ code has been choosen.
   TP             - Yes, Turbo Pascal code has been choosen.
   Date           - Date stamp.
   Time           - Time Stamp.
   BuildName      - Name of the Build Program
   ProgName       - Name of the Program
   DialogName     - Name of the Dialog File
   MenuBarName    - Name of the Menu Bar File.
   StatusName     - Name of the Status Line File.
   StringListName - Name of the String List File.
   SubViewName    - Name of the sub view file.
   ReportName     - Name of the Report File.
   ObjName        - Name of the current Object (User ID)
   ProgNameH      - Name of the program with extension ".H"
   BuildNameH     - Name of the Build Program w/extension ".H"
   DialogNameH    - Name of the Dialog file w/extension ".H"
   MenuBarNameH   - Name of the Menu bar file w/extension ".H"
   StatusNameH    - Name of the status Line File w/extension ".H"
   StringNameH    - Name of the String List FIle w/extension ".H"
   SubViewNameH   - Name of the sub view file w/extension ".H"

   DialogObjects  - Full list of all editable dialog object user id's.
   StatusObjects  - Full list of all editable status line object user id's.
   MenuBarObjects - Full list of all editable menu bar object user id's.
   StringObjects  - Full list of all editable string list object user id's.
   SubViewObjects - Full list of all editable subv view object user id's.
   NonStdObjects  - Full list of all non-editable object user id's.

   CRLF           - produce a CRLF in the output file.
   MethodCalls    - Returns TRUE if method calls have been chosen for defn.
   ObjRegNumber   - Base: 1000->  Used in Registration Records as ObjType.
   CompilerObjName- Normalized Object User ID for compiler acceptable use.

   These refer to the actual loaded object in memory.  These MUST BE USED
   WITHIN AN OBJECT/SUBVIEW LOOP.
   ObjHelpCtx     - The View's Help CTX number.
   ObjOptions     - Produces the Objects Current OPTIONS.
   ObjState       - Produces the Objects Current STATE.
   ObjEventMask   - Produces the Objects Current EVENT MASK.
   ObjDragMode    - Produces the Objects Current DRAG MODE.
   ObjGrowMode    - Produces the Objects Current GROW MODE.

   These refer to DEFAULTS for that object which are looked up.
   OptionFlags    : All these are the same as the above, but will provide
   EventMask      : the respected objects DEFAULT settings for these flags.
   StateFlags
   DragMode
   GrowMode

   Field Values = These refer to The CURRENT OBJECTS LOCATIONAL FIELDS.
   ObjOrigin      - Produces: x,y
   ObjOrigin.X    - Produces: x
   ObjOrigin.Y    - Produces: y
   ObjCursor      - Produces: x,y
   ObjCursor.X    - Produces: x
   ObjCursor.Y    : etc...Items refering to a TPOINT type will produce comma
   ObjSize        : separated items.
   ObjSize.X
   ObjSize.Y
   ObjBounds      - Produces: x1,y1,x2,y2

   ObjTypeName     - Produces the TYPE NAME for the current object loaded.
   ObjTypeNumber   - Produces the TYPE (REGISTRATION) # for the obj. Loaded.

   SubViewNumber   - SUBVIEW NUMBER (RECORD SETUPS) Incremental Reference
   AppMenuBar      - Produces ID of the app menubar (1st in list)
   AppStatusLine   - Produces ID of the app Status Line (1st in list)

   Used in string lists. These reference an individual string w/in the loop.
   StrID           - Current string ID
   ObjString       - Current QUOTED STRING (ready for CODE)

   ObjUses         - Defines Unit Names in USES form.

   Defined Variables to use. Grabs the current Menu/Status Definitions
   ObjMenuBar
   ObjStatusDef

   The Following Variables are used when the following TTypes of objects are
   currently loaded.
   //TButton, TDialog, TLabel, TParamText, TStaticText
   ObjText          - The TEXT
   ObjCommand       - The COMMAND
   ObjFlags         - The FLAG VALUE (IN DECIMAL)

   //InputLine, NumericInput, StringInput
   ObjMaxLen        - Maximum Set length for the input line
   ObjData          - Pre-set data for the input lines.
   ObjMax           - Max Value for the numeric input line.
   ObjMin           - Min Value for the Numeric Input Line.
   ObjCtrlOk        - Ctrl Chars for the String Input Line.
   ObjMinLen        - Min Entry Length required.

   //CheckBox,RadioButtons
   ObjStringItems   - Items used in the list.

   //History, Label
   ObjLink          - NIL if not linked.
   ObjHistoryID     - History ID

   //ListBox, ListViewer, SortedListBox
   ObjNumCols
   ObjScrollBar
   ObjHScrollBar
   ObjVScrollBar
   ObjList

   //PParamText
   ObjParamCount

   //Objectives
   CObjList        - Returns NIL if list = NIL or List.count = zero
   ConstNIL        - Returns NULL for C++, and NIL for Pascal CodeGen.


----------------
KeyWord(s):  Message[#,"this is my string"]

   Place a message "xxxx" on line # of the message dialog on the screen.
   The line number can range from 1 - 4.  The string is LIMITED to
   45 characters.

   Example: <<Message[1, "Now generating C++ Code"]>>

----------------
KeyWord(s):  DefineOutput[ {$xxxx} or "xxxxxxxx", EXT]

   Define the destination of the current text output.  If prefixed by a
   "$" symbol, then it will reference one of the FILE NAMES input into
   the dialog, presented in IFDEF Internal symbols.
   If placed in Double Quotes, it will be considered a hardcoded file
   name.  (Internal symbols will add correct extensions).

   If provided, an EXTension to the file name will be appended.

   Example:  <<DefineOutput[ DialogName, ".PAS"]>>

----------------
KeyWord(s):  IfDef[ xxxxx ]

   Where xxxxx is an Internal Symbol.  If it is defined as TRUE or NOT BLANK
   (for strings) then the following code will execute until an ELSE or an
   ENDIF is reached.  Nesting IS allowed.

----------------
Keyword(s):  Else

   Where IfDef MUST be previously defined.

----------------
Keyword(s):  EndIf

   Ends one level of IfDef nesting.

   Example:
      <<IfDef[ DialogName ]>>
         <<Message[1, "Generating Dialog Code"]>>
      <<Else>>
         <<Message[2, "No Dialog code to generate"]>>
      <<Endif>>

----------------
Keyword(s):  Var[ xxxx... ]

   Where xxxxx is an internal variable symbol.  If preceeded by $ the
   symbol will be quoted, otherwise direct text will be returned.

   The VAR keyword is a way to write direct text to the output file by
   referencing specific internal variables (Those that return strings).

   Example: <<Var[ "This is the dialog File:", DialogName, %1, CRLF]>>

----------------
Keyword(s): ForAll[ param ]

   This keyword sets up a list of user ID's according to the PARAM given.
   It will iterate for all user ID's until that list is exhausted.  Nesting
   of this keyword is also permitted.

   Legal values for PARAM are:
      DialogObjects  StatusObjects   MenuBarObjects
      StringObjects  SubViewObjects  NonStdObjects

----------------
Keyword(s): EndFor

   This keyword ends one iteration of a list.  If all values in the current
   list are exhausted the list is thrown out, and the Engine continues.
   Otherwise, the iteration begins for the new object at the line below
   the FORALL keyword.

   Example:
      <<ForAll[ DialogObjects ]>>
          <<Var[ ObjName, " - Dialog Type", CRLF]>>
          <<PasObjCode[ Define ]>>
      <<EndFor>>

----------------
Keyword(s): DateTime[ date, time ]

   This keyword allows you to place a date and time stamp into the output
   file.  The order of the parameters may be switched if you wish, or
   you may specify only one or the other.

   Example:  <<DateTime[ time ]>>
             <<DateTime[ date ]>>
             <<DateTime[ time, date ]>>

----------------
Keyword(s): CycleSubViews

   This keyword has no parameters.  However, this keyword should only be
   specified inside of a ForAll Loop of dialogs.  The reason is it directly
   iterates over each sub-view contained within the given Object (Current
   dialog).  If a current object is not availble this keyword could cause
   erroneous results.

   Example:  <<ForAll[ Dialogs ]>>
                T<<Var[ ObjName ]>> = Record
                <<CycleSubViews>>
                   <<PasObjCode[ defineType ]>>;
                <<EndCycle>>
              <<EndFor>>

----------------
Keyword(s): EndCycle

   This keyword will cease the iteration of sub-views after all sub-views
   have been exhausted.  See Example Above.

-----------------
Keyword(s): ObjCode[ prfx, subcall, subparams ]

   This keyword allows for an indirect call to a prfx<objname> record.
   This keyword also needs to be contained within a FORALL loop in order
   to reference the current object. Where prfx = some set of letters for
   a prefix, and sub-params are the next parameters necessary to pass into
   the routine.  Subcall is the routine within the keyword which you wish
   to execute.

   Example:  <<ObjCode[ "PT", defineit ]>>

   If the current object is an input line this would result in a call to
   <<PTInputLine>>.  Then it would search through the code until it found
   **DefineIt, then it would run the subroutine.

-----------------
Keyword(s): Call[ MainItem, subcall, subparams]

   If MainItem = "FILE" then the call goes outside to another supporting
   library.  (Not yet implemented).  MainItem should indicate the MAIN ID
   of the string list you wish to reference.  SUBCALL should be the subset
   of strings you wish to execute.

   Currently, the keyword CALL is a special case.  The MainItem will not
   be checked for (as a keyword) until RUNTIME.  Also, SubCall will not
   be checked for until RUNTIME.  The release version of CGCOMP will resolve
   these references BEFORE runtime, producing output for both the display
   and error checking.  This means that this version will NOT have error
   checking for the above reasons, so be careful when implementing CALL.

   Parameter %1 will reference the first in the sequence of SUBPARAMS.  it
   will NOT reference MAINITEM.

-----------------
Keyword(s): IfCompare[ Value, sign, Value ]

   Allows for integrated comparision during SCRIPT EXECUTION.  It provides
   for a dynamic method of Script Code Selection during generation.  The
   VALUEs in the statement can be any of the MARKED variable references.
   See VARIABLES & LEGEND for what can be used.

   VALUE can also be replaced by a LITERAL, which MUST be enclosed in
   DOUBLE QUOTES: I.E.

      IfCompare[ ObjHelpCTX, "=", "0"]

   SIGN can be defined as follows:

      "="    - Compares for EQUAL values.
      "<>"   - Compares for NOT EQUAL values.
      "<"    - Compares Value 1 < Value 2
      ">"    - Compares Value 1 > Value 2

-----------------
Keyword(s):  ExpandFields[ value ]

-----------------
Keyword(s):  Count[ types ]

   Provide a COUNT of a given TYPE of resource.  The TYPE can take on
   the following variables:

      DialogObjects
      MenuObjects
      StatusObjects
      StringObjects
      SubViewObjects
      NonStdObjects
      AllObjects

   Use of any other variable will be ignored and return a count of ZERO.

-----------------
Keyword(s):  CycleStringList

   Prep's and LOADS the current Object as a STRING LIST object type.  This
   keyword ASSUMES that the current object is a TStringList.  If the object
   is NOT it may cause CodeGen to HANG, so be careful.

   From here, you can print individual strings in a loop through the use
   of the ObjStrID, and ObjString variables.

   ENDCYCLE keyword also ends this loop.

-----------------
Keyword(s):  ReportObjects

   This is a unique loop keyword.  It will load a comprehensive listing of
   all the objects in the resource file preceeded by the resource type name.
   It will then SORT by TypeName, ID (respectively) and print the results
   to your output file.  SEE "REPORT" in the SCRIPT for an example of use.
