<diagram id="ch53fig26" title="MAGEC Insertion Point Processing Flow" chapter="gen" filename="ch53fig26.png">

  <description>
    Flowchart showing the logic MAGEC Generator follows when a percent (%) marker (Insertion Point) is encountered during code generation.
  </description>

  <nodes>
    <node id="START" type="start" label="Percent marker is encountered"/>

    <node id="CUSTOM_CHECK" type="decision" label="Custom code on file?">
      <yes label="Yes" target="CUSTOM_INSERT"/>
      <no label="No" target="DEFAULT_CHECK"/>
    </node>

    <node id="CUSTOM_INSERT" type="action" label="Insert the Custom Code from the Library for this Insertion Point for this Mask #"/>

    <node id="DEFAULT_CHECK" type="decision" label="Default code on file?">
      <yes label="Yes" target="DEFAULT_INSERT"/>
      <no label="No" target="COMMENT_INSERT"/>
    </node>

    <node id="DEFAULT_INSERT" type="action" label="Insert the Default Code from the Library for this Insertion Point"/>

    <node id="COMMENT_INSERT" type="action" label="Insert a COMMENT to show what was done here"/>
  </nodes>

  <flows>
    <flow from="START" to="CUSTOM_CHECK" type="down"/>
    <flow from="CUSTOM_CHECK" to="CUSTOM_INSERT" type="yes" color="magenta"/>
    <flow from="CUSTOM_CHECK" to="DEFAULT_CHECK" type="no"/>
    <flow from="DEFAULT_CHECK" to="DEFAULT_INSERT" type="yes" color="magenta"/>
    <flow from="DEFAULT_CHECK" to="COMMENT_INSERT" type="no"/>
    <flow from="CUSTOM_INSERT" to="END" type="join"/>
    <flow from="DEFAULT_INSERT" to="END" type="join"/>
    <flow from="COMMENT_INSERT" to="END" type="join"/>
  </flows>

  <notes>
    <note>Priority order: Custom Code (highest) → Default Code → Comment (fallback).</note>
    <note>This logic applies to every Insertion Point (%%xxxx) during screen, report, or program generation.</note>
    <note>Custom code is stored per Mask # and Insertion Point in the MAGEC library.</note>
  </notes>

</diagram>