{
/* library of scripts called from Designer/2000 INS scripts */

/*
entry points:
 EXECUTE_SCRIPT == "START.INS"
 EXECUTE_SCRIPT == "INSTALL_DEPENDENCIES.INS"
 EXECUTE_SCRIPT == "INSTALL_CHILDREN.INS"
 EXECUTE_SCRIPT == "DES2_END_COPY.INS"
 EXECUTE_SCRIPT == "DES2_REF.INS"
 EXECUTE_SCRIPT == "INSPATCH.INS"
 EXECUTE_SCRIPT == "DES2_OLD.INS"
 EXECUTE_SCRIPT == "ADD_PATH.INS"
 EXECUTE_SCRIPT == "MODIFY_EXECUTE.INS"
 EXECUTE_SCRIPT == "MODIFY_FOR_FILE.INS"
 EXECUTE_SCRIPT == "MODIFY_BROADCAST.INS"
 EXECUTE_SCRIPT == "MODIFY_ADD.INS"
 EXECUTE_SCRIPT == "DES2_REGEDIT.INS"
 EXECUTE_SCRIPT == "DES2_OCXEDIT.INS"
 EXECUTE_SCRIPT == "END.INS"
 EXECUTE_SCRIPT == "DEPENDENCY_MSG.INS"

entry points found in des2k_72.cmn
 EXECUTE_SCRIPT == "MODIFY_VARIABLES.CMN"
 EXECUTE_SCRIPT == "TRANSLATE_VARIABLES.CMN"
 EXECUTE_SCRIPT == "DES2_BB.DIS"
 EXECUTE_SCRIPT == "DES2_BB.REM"

*/

/**************************************************************************
  Check that all variables we might use are instantiated
**************************************************************************/

  {filename = filename;} ['UNBOUND_VARIABLE: {filename = "unknown file";}]
  filename2 = first(reverse(explode(current_script,"\/")));  /* allow unix and dos/os2 seperators */
  filename2 = "%filename%->%filename2%";

/* ...
information_dialog("%filename2%
%EXECUTE_SCRIPT%");
... */

/**************************************************************************
  Values to signal script completion
**************************************************************************/

   script_completed     = "completed";
   script_failed        = "failed";
   script_return_value  = 0;
   return_at_end        = true;

      ins_script_ratchet = "7.2.96.5.6";

/**************************************************************************
  Start the different entry points
**************************************************************************/

if ((EXECUTE_SCRIPT == "MODIFY_VARIABLES.CMN") ||
    (EXECUTE_SCRIPT == "TRANSLATE_VARIABLES.CMN") ||
    (EXECUTE_SCRIPT == "DES2_BB.DIS") ||
    (EXECUTE_SCRIPT == "DES2_BB.REM"))
  {
    script_return_value = execute("%product_home%\des2k_72.cmn");
    if (return_at_end) return(script_return_value);
  }

if (EXECUTE_SCRIPT == "START.INS")
  {
    /* start.ins */
    /* start the ins script
    */

    /* inputs:
           start_ins_list       : product_script, product_debug (atom)
       outputs:
           filename             : string
       gobal:
       returns:
    */

    {
      filename = first(reverse(explode(first(start_ins_list),"\/")));  /* allow unix and dos/os2 seperators */
      filename2 = first(reverse(explode(current_script,"\/")));  /* allow unix and dos/os2 seperators */
      filename2 = "%filename%->%filename2%";

      {debug_list = debug_list;} ['UNBOUND_VARIABLE: debug_list = list();]
      debug_script = member(debug_list,'DEBUG_INS);
      debug_values = member(debug_list,first(rest(start_ins_list)));
      product_bitmap = first(rest(rest(start_ins_list)));

      if (debug_script) information_dialog("Starting %filename%...%carriage_return%doit = %doit%");

      set("run_configuration",TRUE,'GLOBAL);

      EXECUTE_SCRIPT = script_completed;
      script_return_value = 0;
      if (return_at_end) return(script_return_value);
    }
  }

if (EXECUTE_SCRIPT == "INSTALL_DEPENDENCIES.INS")
  {
    /* install_dependencies.ins */
    /* standard install script to install parent and dependent products
    */
    {
      execute("%installer_home%\%operating_system%.ins");

      ui_product(product_label);
      ui_action(instantiate(installing_product));

      /* install order parent - others - self - children */
      /* here install parents & others from the install list */

      copy_install_list = list();
      union(copy_install_list,install_list);
      while(not(empty(copy_install_list)))
        {
          next_product = first(copy_install_list);
          copy_install_list = rest(copy_install_list);

          install(next_product);

          ui_product(product_label);
          ui_action(instantiate(installing_product));
        }

      EXECUTE_SCRIPT = script_completed;
      script_return_value = 0;
      if (return_at_end) return(script_return_value);
    }
  }

if (EXECUTE_SCRIPT == "INSTALL_CHILDREN.INS")
  {
    /* install_children.ins */
    /* standard install script to install children
    */
    {
      ui_product(product_label);
      ui_action(instantiate(installing_product));

      /* install order parent - others - self - children */
      /* here install parents & others from the install list */

      copy_install_list = list();
      union(copy_install_list,children_install_list);
      while(not(empty(copy_install_list)))
        {
          next_product = first(copy_install_list);
          copy_install_list = rest(copy_install_list);

          install(next_product);

          ui_product(product_label);
          ui_action(instantiate(installing_product));
        }

      EXECUTE_SCRIPT = script_completed;
      script_return_value = 0;
      if (return_at_end) return(script_return_value);
    }
  }

if (EXECUTE_SCRIPT == "DES2_START_COPY.INS")
  {
    /* des2_end_copy.ins */
    /* standard install script to clear up after copying files
    */
    {

      /* set the retry flags */

      { save_permit_retry_operations   = permit_retry_operations; }
      ['UNBOUND_VARIABLE: save_permit_retry_operations = TRUE;]

      { save_permit_ignore_operations  = permit_ignore_operations; }
      ['UNBOUND_VARIABLE: save_permit_ignore_operations = TRUE;]

      { save_permit_process_operations = permit_process_operations; }
      ['UNBOUND_VARIABLE: save_permit_process_operations = TRUE;]

      permit_retry_operations = TRUE;
      permit_ignore_operations = TRUE;
      permit_process_operations = TRUE;

      EXECUTE_SCRIPT = script_completed;
      script_return_value = 0;
      if (return_at_end) return(script_return_value);
    }
  }

if (EXECUTE_SCRIPT == "DES2_END_COPY.INS")
  {
    /* des2_end_copy.ins */
    /* standard install script to clear up after copying files
    */
    {

      /* undo the retry flags */

      permit_retry_operations   = save_permit_retry_operations;
      permit_ignore_operations  = save_permit_ignore_operations;
      permit_process_operations = save_permit_process_operations;

      /* ...
      permit_retry_operations = FALSE;
      permit_ignore_operations = FALSE;
      permit_process_operations = FALSE;
      */

      EXECUTE_SCRIPT = script_completed;
      script_return_value = 0;
      if (return_at_end) return(script_return_value);
    }
  }

if (EXECUTE_SCRIPT == "DES2_REF.INS")
  {
    /* des2_ref.ins */
    /* standard install script to register self and reference referenced products
    */
    {
      /* store away who we are and what version number - although
         the info is technically obtainanble from the .rgs file
         The product_status (Production, Limited Production, Beta etc) set in
         user.avf but could be overwritten in each vrf file.
      */
      ini_section = product_filename(current_product);
      case_modify_list = list();
      add(case_modify_list,list("product_name",     product_interface_label(current_product), ora_config, ini_section));
      add(case_modify_list,list("product_version",  product_version(current_product),         ora_config, ini_section));
      add(case_modify_list,list("product_status",   product_status, ora_config, ini_section));
      EXECUTE_SCRIPT = "MODIFY_VARIABLES.CMN";
      execute("%product_home%\des2k_72.ins");

      /* for 32 bit OCSM */
      /* all registry variables were put under the product's subkey (with a
         few exceptions dealt with individually) so registering the lot is easy
      */
      ini_section = product_filename(current_product);
      modify_key = "HKEY_LOCAL_MACHINE";
      modify_subkey = "SOFTWARE\ORACLE\%ini_section%";

      win32_register_ocsm_product();

      win32_register_key(modify_key,modify_subkey);

      /* the map files mainly use these map variables (+oracle_home etc) */
      win32_register_map_variable(ini_section);

      if(member(case_map_variables,'DES2K_R61_GROUP))
      {
         win32_register_map_variable("DES2K_R61_GROUP");
      }
      [ 'UNBOUND_ENVIRONMENT_VARIABLE: continue();]

      if(member(case_map_variables,'DES2K_R61_BULLETINS))
      {
         win32_register_map_variable("DES2K_R61_BULLETINS");
      }
      [ 'UNBOUND_ENVIRONMENT_VARIABLE: continue();]

      if(member(case_map_variables,'DES2K_R61_TUTORIAL))
      {
         win32_register_map_variable("DES2K_R61_TUTORIAL");
      }
      [ 'UNBOUND_ENVIRONMENT_VARIABLE: continue();]

      if(member(case_map_variables,'ODD_R61_GROUP))
      {
         win32_register_map_variable("ODD_R61_GROUP");
      }
      [ 'UNBOUND_ENVIRONMENT_VARIABLE: continue();]

      if(member(case_map_variables,'ODD_R61_BULLETINS))
      {
         win32_register_map_variable("ODD_R61_BULLETINS");
      }
      [ 'UNBOUND_ENVIRONMENT_VARIABLE: continue();]

      if(member(case_map_variables,'ODD_R61_TUTORIAL))
      {
         win32_register_map_variable("ODD_R61_TUTORIAL");
      }
      [ 'UNBOUND_ENVIRONMENT_VARIABLE: continue();]

      if(member(case_map_variables,'REPOS_R10_GROUP))
      {
         win32_register_map_variable("REPOS_R10_GROUP");
      }
      [ 'UNBOUND_ENVIRONMENT_VARIABLE: continue();]

      if(member(case_map_variables,'REPOS_R10_BULLETINS))
      {
         win32_register_map_variable("REPOS_R10_BULLETINS");
      }
      [ 'UNBOUND_ENVIRONMENT_VARIABLE: continue();]

      if(member(case_map_variables,'REPOS_R10_TUTORIAL))
      {
         win32_register_map_variable("REPOS_R10_TUTORIAL");
      }
      [ 'UNBOUND_ENVIRONMENT_VARIABLE: continue();]

      if(member(case_map_variables,'OBM_R10_GROUP))
      {
         win32_register_map_variable("OBM_R10_GROUP");
      }
      [ 'UNBOUND_ENVIRONMENT_VARIABLE: continue();]

      if(member(case_map_variables,'OBM_R10_BULLETINS))
      {
         win32_register_map_variable("OBM_R10_BULLETINS");
      }
      [ 'UNBOUND_ENVIRONMENT_VARIABLE: continue();]

      if(member(case_map_variables,'OBM_R10_TUTORIAL))
      {
         win32_register_map_variable("OBM_R10_TUTORIAL");
      }
      [ 'UNBOUND_ENVIRONMENT_VARIABLE: continue();]


      /* undo the retry flags */

      /* register self */
      ui_action(instantiate(registering_product));

      /* the old method of install patches where patch list contains the patches */
      if (case_install_patch_files)
        {
          while (not(empty(patch_list)))
            {
              next_patch = first(patch_list);
              patch_list = rest(patch_list);

              next_patch_registry  = first(next_patch);
              next_patch_product   = first(rest(next_patch));
              next_patch_version   = first(rest(rest(next_patch)));
              patch_size           = first(rest(rest(rest(next_patch))));
              patch_group          = first(rest(rest(rest(rest(next_patch)))));

              {

                patch_number = product_number(next_patch_product);
                patch_label = product_interface_label(next_patch_product);
                patch_name = product_name(next_patch_product);
                patch_comment = registry_comment(next_patch_registry);
                patch_filename = product_filename(next_patch_product);
                patch_location = product_location(next_patch_product);
                parent_registry = registry_parent(next_patch_registry);
                patch_registry = make_registry(patch_name, patch_number, patch_filename,
                                               next_patch_version, patch_label,
                                               patch_size, patch_comment, parent_registry);
              }

              ['PARENT_NOT_FOUND:
                {
                  patch_registry = make_registry(patch_name, patch_number, patch_filename,
                                                 next_patch_version, patch_label,
                                                 patch_size, patch_comment);
                }
              ]

              register(patch_registry);


            } /* while not empty */
        }
      else
        {
          register(current_product);
        }

      /* install order is parents/others - self - children in install list */
      /* here install children (and anything else that is left) */

      while(not(empty(install_list)))
        {
          next_product = first(install_list);
          install_list = rest(install_list);
          install(next_product);

          ui_product(product_label);
          ui_action(instantiate(installing_product));
        }

      /* now that everything is installed and registered, reference it */

      /* Note that the parent product does not reference any of its
         child products as a child can be de-installed at any
         time without affecting the parent.
         Note also that the child products do not reference the parent
         (or parent's parent etc) as de-install ation of
         the parent involves ALWAYS de-installs child products.
         Note also that you should not reference or de-install the installer.
      */

      current_product_registry = registration(product_name(current_product));
      restrict_list = all_child_products(current_product);
      add(restrict_list,orainst_product);
      next_parent = current_product;
      {
        while (true)
        {
          next_parent = product_parent(next_parent);
          add(restrict_list,next_parent);
        }
      }
      ['PARENT_NOT_FOUND: continue();]

      reference_variable_list = list();

      while(not(empty(reference_list)))
        {
          next_product = first(reference_list);
          reference_list = rest(reference_list);
          if ((not(member(restrict_list,next_product))))
            {
              if (registered(product_name(next_product)))
                {
                  {
                    next_product_name = product_name(next_product);
                    next_product_registry = registration(next_product_name);
                    references_list = registry_references(next_product_registry);
                    if (not(member(references_list, current_product_registry)))
                      {
                        reference(next_product,current_product);
                      }
                    add(reference_variable_list,next_product_name);
                  }
                  ['UNREGISTERED_PRODUCT: continue();]
                }
              else
                {
                  if (debug_values)
                    {
                      information_dialog("%next_product% not registered. Can not reference from %current_product%");
                    }
                }
            }

          /* now store the reference list in the registry */
          ini_section = product_filename(current_product);
          {
            case_translate_list = list("REFERENCE_LIST", ora_config, ini_section);
            EXECUTE_SCRIPT = "TRANSLATE_VARIABLES.CMN";
            old_reference_string = execute("%installer_home%\des2k_72.dei");
          }
          ['UNBOUND_ENVIRONMENT_VARIABLE: old_reference_string = "";]
          old_reference_list = explode(old_reference_string,",");
          union(reference_variable_list,old_reference_list);
          sort(reference_variable_list,TRUE);
          reference_variable_string = implode(reference_variable_list,",");
          case_modify_list = list();
          add(case_modify_list,list("REFERENCE_LIST", reference_variable_string, ora_config, ini_section));
          EXECUTE_SCRIPT = "MODIFY_VARIABLES.CMN";
          execute("%product_home%\des2k_72.cmn");

        }

     /* finally, register self if not installed solely as a dependency */
     if ((not(internally_called)) || (member(selected_products,current_product)))
        {
          reference(current_product);
        }

      EXECUTE_SCRIPT = script_completed;
      script_return_value = 0;
      if (return_at_end) return(script_return_value);
    }
  }

if (EXECUTE_SCRIPT == "INSPATCH.INS")
  {
    /* inspatch.ins */
    /* copy patched files from patch group
    */
    {
      if (patch_installation)
        {
          {
          ui_action(instantiate(installing_patches));

          patch_list_copy = list();
          union(patch_list_copy,patch_list);

          while (not(empty(patch_list_copy)))
            {
              next_patch = first(patch_list_copy);
              patch_list_copy = rest(patch_list_copy);

              next_patch_registry = first(next_patch);
              patch_group = first(rest(rest(rest(rest(next_patch)))));
              copy(patch_group,"files");
            }

          }
          ['UNBOUND_VARIABLE: continue(); ]

        } /* if patch instalation */

      EXECUTE_SCRIPT = script_completed;
      script_return_value = 0;
      if (return_at_end) return(script_return_value);
    }
  }

if (EXECUTE_SCRIPT == "DES2_OLD.INS")
  {
    /* des2_old.ins */
    /* standard install script to remove old products
    */
    {
      /* see comment in des2_old2.ins procedure */
      /* Attempt to remove obsolete files even if not upgrading
         just in case they are lying around from an aborted de-installation.
      */

      /* removing files from a directory that does not exist (ie neither the
         directory nor the file were created because you are not upgrading)
         signals an OS_ERROR. You can't ignore just this type of error and
         let others (eg PERMISSION_DENIED) be handled by the
         permit_retry_operations.
         (An added complication arises when you try to remove icons from
         folders that do not exist - you get an asynchronous windows error)
         There are 3 ways of dealing with this:
         startegy 1) turn retry on and use the strategy with the 'OS_ERROR error
         strategy 2) remove file by file and direcrory by directory
                     (make sure the icons/folder exist (by creating them!))
         strategy 3) create the empty directories first
      */

      strategy = 'STRATEGY2;

      if (strategy == 'STRATEGY1)
      {
        /* strategy 1 */
        save_permit_retry_operations = permit_retry_operations;
        save_permit_retry_operations = TRUE;
        {remove(old);}
        ['UNBOUND_VARIABLE: continue();]
        permit_retry_operations = save_permit_retry_operations;
      }

      if (strategy == 'STRATEGY2)
      {
        /* strategy 2 */

        /*
        copy(old,"icon");
        information_dialog("icons created");
        */

        /* first check to see if there are any files with icons to delete */
        /* remember that the group_files function picks up files with empty subgroup as well as the subgroup specified */
        old_icon_files_list = group_files(old,"icon");
        old_files_list = group_files(old, "");
        subtract(old_icon_files_list,old_files_list);
        old_icon_files_exist = FALSE;
        {
          while (not(empty(old_icon_files_list)))
          {
            next_file = first(old_icon_files_list);
            old_icon_files_list = rest(old_icon_files_list);
            {
              if (exists(next_file))
              {
                old_icon_files_exist = TRUE;
              } /* if exists */
            }
            ['INVALID_FILE_NAME: {continue();}
             'PERMISSION_DENIED: {continue();}
             'OS_ERROR: {continue();}
            ]
          } /* while */
        }
        ['UNBOUND_VARIABLE: {continue();}]

        /* now remove the icons */
        if (old_icon_files_exist)
          {
            /* remember that the group_files function picks up files with empty subgroup as well as the subgroup specified */
            old_icon_files_list = group_files(old,"icon");
            old_files_list = group_files(old, "");
            subtract(old_icon_files_list,old_files_list);

            if (false)
            {

            /* some of the files to be removed have associated icons;
               make sure that the folder exists or you will get an
               error window.
               Easiest way to do this is create them !!
            */

            /* can not use copy as it will copy all files with empty sub group as well */
            /* copy(old,"icon"); */

            /* create (empty) files before creating icons */
            while (not(empty(old_icon_files_list)))
              {
                next_file = first(old_icon_files_list);
                old_icon_files_list = rest(old_icon_files_list);
                {
                  create_file(next_file);
                }
                ['INVALID_FILE_NAME: {continue();}
                 'PERMISSION_DENIED: {continue();}
                 'OS_ERROR: {continue();}
                 'WRITE_ERROR: {continue();}
                ]
              } /* while */
            /* create the folders - by creating the icons in them */
            windows_create_icons(old);

            } /* if true/false */

            /* now remove the icons (and the folder) */
            /* remove(old); */
            windows_delete_icons(old);
          }

        /* now remove the files */
        {

          files_list = group_files(old);
          while (not(empty(files_list)))
          {
            next_file = first(files_list);
            files_list = rest(files_list);
            {
              if (exists(next_file))
              {
                permit_retry_operations = false;
                {
                  remove(next_file);
                }
                ['OS_ERROR:
                  {continue();}
                 'DEFAULT:
                  {
                    /* try again but with user retries turned on */
                    permit_retry_operations = true;
                    remove_file(next_file);
                    files_deleted = TRUE;
                  }
                ]
              } /* if exists */
            }
            ['INVALID_FILE_NAME: {continue();}
             'PERMISSION_DENIED: {continue();}
             'OS_ERROR: {continue();}
            ]
          } /* while */
        }
        ['UNBOUND_VARIABLE: {continue();}]

        /* now remove directories */
        {
          directories_list = group_directories(old);
          while (not(empty(directories_list)))
          {
            next_directory = first(directories_list);
            directories_list = rest(directories_list);
            {
              if (exists(next_directory))
              {
                permit_retry_operations = false;
                {remove_directory(next_directory);}
                ['OS_ERROR:
                  {continue();}
                 'DEFAULT:
                  {
                    /* try again but with user retries turned on */
                    permit_retry_operations = true;
                    remove_directory(next_directory);
                  }
                ]
              } /* if exists */
            }
            ['INVALID_FILE_NAME: {continue();}
             'PERMISSION_DENIED: {continue();}
             'OS_ERROR: {continue();}
            ]
          } /* while */
        }
        ['UNBOUND_VARIABLE: continue();]
        permit_retry_operations = true;

      }

      if (strategy == 'STRATEGY3)
      {
        /* strategy 3 */
        {
        directories_list = group_directories(old);
        while (not(empty(directories_list)))
          {
          next_directory = first(directories_list);
          directories_list = rest(directories_list);
          make_directory(next_directory);
          }
        remove(old);
        }
        ['UNBOUND_VARIABLE: continue();]
      }

      EXECUTE_SCRIPT = script_completed;
      script_return_value = 0;
      if (return_at_end) return(script_return_value);
    }
  }

if (EXECUTE_SCRIPT == "DES2_OLD2.INS")
  {
    /* des2_old.ins */
    /* standard install script to remove old products
    */
    {
      /* this fancy bit of code is meant to determine which bundle you
         are upgrading from and remove only those files that were obsoleted
         from that bundle. The idea being that to get to the current state
         would already have removed files obsoleted in previous versions.
      */
      /* However, uprading by installing patches can change the bundle
         number without removing files because it has not been decided
         that they are obsolete at that stage - and there can always be
         another patch to up the number even more.
         So - rename this procedure out of the way and create a new
         simpler one.
      */

      if (version_status == 'upgrade)
        {
          if (registered(product_name(current_product)))
            {
              {
                registry = registration(product_name(current_product));
                current_version = product_version(current_product);
                installed_version = registry_version(registry);

                /* decide which version is installed */
                /* list must be in most_recent .. least recent order starting with current version */
                previous_bundles_list = list();
                add(previous_bundles_list,list("6.0.8.32.0","608320"));
                add(previous_bundles_list,list("6.0.8.2.0","60820"));
                add(previous_bundles_list,list("6.0.8.0.0","60800"));
                add(previous_bundles_list,list("6.0.7.26.0","607260"));
                add(previous_bundles_list,list("6.0.7.0.0","607260"));
                add(previous_bundles_list,list("6.0.6.2.0","607260"));

                /* the check is only made on the 3rd to 5th version digits */
                installed_version_list     = explode(installed_version,".");
                installed_upg_version_list = rest(rest(installed_version_list));
                installed_upg_version      = implode(installed_upg_version_list,".");

                {
                  while (not(empty(previous_bundles_list)))
                    {
                    bundle_pair = first(previous_bundles_list);
                    bundle_version = first(bundle_pair);
                    installed_bundle_id = first(rest(bundle_pair));
                    previous_bundles_list = rest(previous_bundles_list);

                    /* the check is only made on the 3rd to 5th version digits
                       which deote the bundle
                    */
                    bundle_version_list      = explode(bundle_version,".");
                    bundle_upg_version_list  = rest(rest(bundle_version_list));
                    bundle_upg_version       = implode(bundle_upg_version_list,".");

                    if ((same_version(installed_upg_version,bundle_upg_version)) ||
                        (later_version(installed_upg_version,bundle_upg_version)))
                      {
                      signal('INSTALLED_BUNDLE_FOUND);
                      }
                    }
                }
                ['INSTALLED_BUNDLE_FOUND: continue();]

                /* now remove the installed version */
                {
                  remove(old,installed_bundle_id);
                }
                ['UNBOUND_VARIABLE: continue();]

              }
              ['UNREGISTERED_PRODUCT: continue();]
            }

        }
      EXECUTE_SCRIPT = script_completed;
      script_return_value = 0;
      if (return_at_end) return(script_return_value);
    }
  }

if (EXECUTE_SCRIPT == "ADD_PATH.INS")
  {
    /* add_path.ins */
    /* standard install script to add a path to an oracle.ini variable
    */
    {
      next_add =  case_add_path_list;

      add_variable =    first(next_add);
      add_value =       first(rest(next_add));
      add_ini_file =    first(rest(rest(next_add)));
      add_ini_section = first(rest(rest(rest(next_add))));

      case_translate_list = list(add_variable,add_ini_file,add_ini_section);
      {
        EXECUTE_SCRIPT = "TRANSLATE_VARIABLES.CMN";
        add_variable_value = execute("%product_home%\des2k_72.cmn");
      }
      [ 'UNBOUND_ENVIRONMENT_VARIABLE: add_variable_value = ""; ]

      add_list = explode(add_variable_value,";");
      add(add_list,add_value);
      sort(add_list,true);

      add_variable_value = implode(add_list,";");
      case_modify_list = list(add_variable,add_variable_value,add_ini_file,add_ini_section);
      EXECUTE_SCRIPT = "MODIFY_VARIABLES.CMN";
      execute("%product_home%\des2k_72.cmn");

      EXECUTE_SCRIPT = script_completed;
      script_return_value = 0;
      if (return_at_end) return(script_return_value);
    }
  }

if (EXECUTE_SCRIPT == "MODIFY_EXECUTE.INS")
  {
    /* modify_execute.ins */
    /* standard install script to modify the EXECUTE_xxx ini variable pointing to an installed file
       inputs : case_execute_list                structured list
    */
    {
      repl_bin_list = list();           /* 16 bit OCSM */
      repl_variable_list = list();      /* 16 bit OCSM */
      repl_group_list = list();         /* 32 bit OCSM */
      case_modify_list = list();

      /* deal with the variables from the list set by the .ins script */

      while(not(empty(case_execute_list)))
        {
          next_execute = first(case_execute_list);
          case_execute_list = rest(case_execute_list);

          execute_variable =     first(next_execute);
          execute_id  =          first(rest(next_execute));
          execute_group =        first(rest(rest(next_execute)));
          execute_ini_file =     first(rest(rest(rest(next_execute))));
          execute_ini_section =  first(rest(rest(rest(rest(next_execute)))));
          execute_ini_location = rest(rest(rest(rest(rest(next_execute)))));

          /* the id and group are passed in as parameters */
          /* note that the group/id should only exist once, either as a
             directory or a file. Get the directories first because
             these should all have a "bin" (or another) tag specified to
             stop them getting picked up when a different tag is specified.
         */
          execute_list = list();
          execute_group_name = group_name(execute_group);
          union(execute_list,group_directories(execute_group,execute_id));
          union(execute_list,group_files(execute_group,execute_id));

          if (not(length(execute_list) == 1))
            {
            information_dialog(instantiate(reg_variable_not_set));
            execute_list = list("<enter value>");
            }

          if (not(empty(execute_list)))
            {
              execute_name = first(execute_list);
              this_execute = list(execute_variable,execute_name,execute_ini_file,execute_ini_section);
              union(this_execute, execute_ini_location);
              add(case_modify_list,this_execute);

              /* add the name to the repl_variable_list for processing later */
              union(repl_bin_list,list(execute_group_name));
              union(repl_group_list,list(execute_group));
              add(repl_variable_list,execute_variable);
            }
        }

      /* store the replicate variables */

      current_product_ini_section = product_filename(current_product);
      repl_bin = implode(repl_bin_list,",");
      repl_variables = implode(repl_variable_list,",");

      /* for 16 bit OCSM */
      /* the files in the groups listed in replicate_bin are replicated for a partial download */
      add(case_modify_list,list("REPLICATE_BIN",       "%repl_bin%",       ora_config, current_product_ini_section));
      add(case_modify_list,list("REPLICATE_VARIABLES", "%repl_variables%", ora_config, current_product_ini_section));

      /* for 32 bit OCSM */
      while (not(empty(repl_group_list)))
        {
          next_repl_group = first(repl_group_list);
          repl_group_list = rest(repl_group_list);
          win32_register_ocsm_group(next_repl_group,'MEDMODE);
        }

      /* now go and add the list to the registry */

      EXECUTE_SCRIPT = "MODIFY_VARIABLES.CMN";
      script_return_value = execute("%product_home%\des2k_72.cmn");
      if (return_at_end) return(script_return_value);
    }
  }

if (EXECUTE_SCRIPT == "MODIFY_BROADCAST.INS")
  {
    /* modify_broadcast.ins */
    /* standard install script to modify the broadcast_xxx ini variable
       inputs : case_broadcast_list                structured list
    */
    {
      case_modify_list = list();
      while(not(empty(case_broadcast_list)))
        {
          next_broadcast = first(case_broadcast_list);
          case_broadcast_list = rest(case_broadcast_list);

          broadcast_variable =     first(next_broadcast);
          broadcast_id  =          first(rest(next_broadcast));
          broadcast_value  =       first(rest(rest(next_broadcast)));
          broadcast_ini_file =     first(rest(rest(rest(next_broadcast))));
          broadcast_ini_section =  first(rest(rest(rest(rest(next_broadcast)))));
          broadcast_ini_location = rest(rest(rest(rest(rest(next_broadcast)))));

          /* the group file is always 'bin' */
          broadcast_list = group_files(bin,broadcast_id);

          if (not(length(broadcast_list) == 1))
            {
            information_dialog(instantiate(breg_variable_not_set));
            broadcast_list = list("<enter value>");
            }

          if (not(empty(broadcast_list)))
            {
              broadcast_name = first(broadcast_list);
              /* broadcast_name is the real name of the exe/dll.
                 We should extract the filename bit and prepend the
                 string BROADCAST_ to get the variable name.
                 To make life easy (for now) use the broadcast_variable
                 as given in the list
              */

              this_broadcast = list(broadcast_variable,broadcast_value,broadcast_ini_file,broadcast_ini_section);
              union(this_broadcast, broadcast_ini_location);
              add(case_modify_list,this_broadcast);
            }
        }

      EXECUTE_SCRIPT = "MODIFY_VARIABLES.CMN";
      script_return_value = execute("%product_home%\des2k_72.cmn");
      if (return_at_end) return(script_return_value);
    }
  }

if (EXECUTE_SCRIPT == "MODIFY_ADD.INS")
  {
    /* modify_add.ins */
    /* standard install script to modify a path style ini variable by adding a fully qualified directory entry
       inputs : case_add_list                structured list
    */
    {
      case_modify_list = list();
      while(not(empty(case_add_list)))
        {
          next_add = first(case_add_list);
          case_add_list = rest(case_add_list);

          add_variable =    first(next_add);
          add_value  =      first(rest(next_add));
          add_ini_file =    first(rest(rest(next_add)));
          add_ini_section = first(rest(rest(rest(next_add))));
          add_location =    rest(rest(rest(rest(next_add))));

          /* old way of doing it
          { add_variable_value = v7_translate(add_variable); }
          ['UNBOUND_ENVIRONMENT_VARIABLE:  { add_variable_value = "";  }]
          add_variable_list = explode(add_variable_value,";");
          add(add_variable_list_list,add_value);
          add_variable_value = implode(add_variable_list,";");
          modify(add_variable,add_variable_value,add_ini_file,add_ini_file_section);
          */

          /* see if we have already processed this */
          add_variable_value = "";
          temp_case_modify_list = list();
          union(temp_case_modify_list,case_modify_list);
          while(not(empty(temp_case_modify_list)))
            {
              next_in_modify_list = first(temp_case_modify_list);
              temp_case_modify_list = rest(temp_case_modify_list);
              next_add_variable = first(next_in_modify_list);
              if (next_add_variable == add_variable)
                {
                  add_variable_value = first(rest(next_in_modify_list));
                  extract(case_modify_list,next_in_modify_list);
                }
            }

          if (add_variable_value == "")
          {
            {
              case_translate_list = list(add_variable,add_ini_file,add_ini_section);
              union(case_translate_list,add_location);
              EXECUTE_SCRIPT = "TRANSLATE_VARIABLES.CMN";
              add_variable_value = execute("%product_home%\des2k_72.cmn");
            }
            ['UNBOUND_ENVIRONMENT_VARIABLE:  { add_variable_value = "";  }]
          }

          add_variable_list = explode(add_variable_value,";");

          /* add_value might be a semicolon seperated string list */
          /* if (not(member(add_variable_list,add_value))) add(add_variable_list,add_value); */
          add_value_list = explode(add_value,";");
          union(add_variable_list,add_value_list);

          add_variable_value = implode(add_variable_list,";");

          add_list = list(add_variable,add_variable_value,add_ini_file,add_ini_section);
          union(add_list,add_location);
          add(case_modify_list,add_list);
        }

      EXECUTE_SCRIPT = "MODIFY_VARIABLES.CMN";
      script_return_value = execute("%product_home%\des2k_72.cmn");
      if (return_at_end) return(script_return_value);
    }
  }

if (EXECUTE_SCRIPT == "DES2_REGEDIT.INS")
  {
    /* des2_regedit.ins */
    /* standard install script to spawn a regedit command
       inputs : case_regedit_list               list of registry input files
    */
    {
      /* the REGEXE variable should be set in user.avf */
      {EXECUTE_REGEDIT = REGEXE;}
      ['UNBOUND_VARIABLE:
        {
        spawn_dir    = windows_directory();
        spawn_dir2   = windows_system_directory();
        if (operating_system == "nt")
          {
          /* note that the registry editor is spawn_dir2\regedt32 under NT 3.51
             and spawn_dir\regedit under NT 4.0
             Under NT 3.51, however, it is ok to use spawn_dir\regedit (a 16 bit
             program) with the [regedit4] as the first line of the .reg file.
          */
          /* EXECUTE_REGEDIT = "%spawn_dir2%\regedt32"; */
          /* EXECUTE_REGEDIT = "%spawn_dir%\regedit"; */
          EXECUTE_REGEDIT = "regedit";
          }
        else if (operating_system == "win95")
          {
          /* EXECUTE_REGEDIT = "%spawn_dir%\regedit"; */
          EXECUTE_REGEDIT = "regedit";
          }
        else
          {
          /* a useful default */
          /* EXECUTE_REGEDIT = "%spawn_dir%\regedit"; */
          EXECUTE_REGEDIT = "regedit";
          }
        }
      ]

      while(not(empty(case_regedit_list)))
        {
          next_registry_file = first(case_regedit_list);
          case_regedit_list = rest(case_regedit_list);

          {win32_asynchronous_spawn("%EXECUTE_REGEDIT% /s %next_registry_file%");}
          ['NO_RESPONSE, 'FILE_NOT_FOUND, 'MEMORY_ERROR, 'OS_ERROR, 'INVALID_FILE_NAME:
           information_dialog("Failed to register %next_registry_file%");
          ]
        }

      EXECUTE_SCRIPT = script_completed;
      script_return_value = 0;
      if (return_at_end) return(script_return_value);
    }
  }

if (EXECUTE_SCRIPT == "DES2_OCXEDIT.INS")
  {
    /* des2_ocsedit.ins */
    /* standard install script to spawn a regsvr32 command to install an OCX
       inputs : case_regedit_list               list of ocs input files
    */
    {
      spawn_dir    = windows_directory();
      spawn_dir2   = windows_system_directory();
      EXECUTE_OCX = "regsvr32";

      while(not(empty(case_regedit_list)))
        {
          next_registry_file = first(case_regedit_list);
          case_regedit_list = rest(case_regedit_list);

          {win32_asynchronous_spawn("%EXECUTE_OCX% /s %next_registry_file%");}
          ['NO_RESPONSE, 'FILE_NOT_FOUND, 'MEMORY_ERROR, 'OS_ERROR, 'INVALID_FILE_NAME:
           information_dialog("Failed to register %next_registry_file%");
          ]
        }

      EXECUTE_SCRIPT = script_completed;
      script_return_value = 0;
      if (return_at_end) return(script_return_value);
    }
  }

if (EXECUTE_SCRIPT == "DEPENDENCY_MSG.INS")
  {
    /* dependency_msg.ins */
    /* create a message to (manually) install further dependent products
    */

    /* inputs:  dependency_msg_flag             true/false (ignored)
                dependency_msg_product_list     a list of product to be installed by user for required functionality
                dependency_msg_message          the message for the user
       outputs:
       gobal:
       returns:
    */

    {
      dependency_msg_flag =         first(case_dependency_msg_list);
      dependency_msg_product_list = first(rest(case_dependency_msg_list));
      dependency_msg_message =      first(rest(rest(case_dependency_msg_list)));

      /* the install flag is neaningless at present */
      /* if (not(dependency_msg_flag)) */
        {
          if (not(empty(dependency_msg_product_list)))
            {
               case_temp_dependency_list = list();
               case_temp_name_list = list();
               union(case_temp_dependency_list,dependency_msg_product_list);
               while (not(empty(case_temp_dependency_list)))
                 {
                   case_temp_product = first(case_temp_dependency_list);
                   case_temp_dependency_list = rest(case_temp_dependency_list);

                   case_temp_product_name = product_name(case_temp_product);
                   case_temp_label = product_interface_label(case_temp_product);
                   case_temp_version = product_version(case_temp_product);

                   if (registered(case_temp_product_name))
                     {
                     case_temp_registry = registration(case_temp_product_name);
                     case_temp_registry_version = registry_version(case_temp_registry);
                     if (earlier_version(case_temp_registry,case_temp_version,3))
                       {
                         add(case_temp_name_list,"%case_temp_label% %case_temp_version%");
                       }
                     }
                   else
                     {
                       add(case_temp_name_list,"%case_temp_label% %case_temp_version%");
                     }
                 }

               dependency_msg_product_string = implode(case_temp_name_list, ",");
               /* information_dialog(instantiate(dependency_msg_message)); */
               if (not(empty(case_temp_name_list)))
                 {
                   { add(case_remind_list,instantiate(dependency_msg_message)); }
                   ['UNBOUND_VARIABLE:
                     {
                       /* the case implementation of this has not been defined so use the global version instead */
                       add(remind_list,instantiate(dependency_msg_message));
                     }
                   ]
                 }
            }
        }

      EXECUTE_SCRIPT = script_completed;
      script_return_value = 0;
      if (return_at_end) return(script_return_value);
    }
  }


if (EXECUTE_SCRIPT == "END.INS")
  {
    /* end.ins */
    /* end the ins script
    */

    /* inputs:
       outputs:
       gobal:
       returns:
    */

    {
      if (debug_script) information_dialog("Ending %filename%...");

      EXECUTE_SCRIPT = script_completed;
      script_return_value = 0;
      if (return_at_end) return(script_return_value);
    }
  }

/**************************************************************************
  Check the completion status
**************************************************************************/

if (EXECUTE_SCRIPT == script_failed)
  {
  information_dialog("%filename2%
internal error: script incorrectly called. Processing will continue.");
  }
else if (not(EXECUTE_SCRIPT == script_completed))
  {
  information_dialog("%filename2%
internal error: script incorrectly called. Entry point %EXECUTE_SCRIPT% not found");
  }

  return(script_return_value);
}
