MODULE ram$externalize_share_mode;
?? RIGHT := 110 ??

?? PUSH (LISTEXT := ON) ??
*copyc rac$max_permit_option_index
*copyc clt$value
*copyc pft$permit_options
*copyc pft$share_selections
*copyc rat$table_entry_name
?? POP ??
*copyc clp$create_variable
*copyc clp$read_variable
*copyc clp$write_variable
*copyc pmp$get_unique_name
*copyc rap$line_length
*copyc rav$share_keys
*copyc i#move

*copyc rah$externalize_share_mode

  PROCEDURE [XDCL, #GATE] rap$externalize_share_mode
    (    share_mode: pft$share_selections;
     VAR value: clt$value;
     VAR status: ost$status);

    VAR
      empty_set: [STATIC] pft$share_selections := [],
      i: pft$permit_options,
      number_in_list: 0 .. rac$max_permit_option_index,
      selection_list: array [1 .. rac$max_permit_option_index] of rat$table_entry_name,
      string_value: ^array [1 .. * ] of cell,
      unique_name: ost$name,
      variable: clt$variable_reference,
      variable_scope: [STATIC, READ] clt$variable_scope := [clc$local_variable];


    status.normal := TRUE;

    IF share_mode = empty_set THEN
      number_in_list := 1;
      selection_list [number_in_list].value := 'NONE';
      selection_list [number_in_list].size := 4;
    ELSE
      number_in_list := 0;
      FOR i := LOWERBOUND (rav$share_keys) TO UPPERBOUND (rav$share_keys) DO
        IF i IN share_mode THEN
          number_in_list := number_in_list + 1;
          selection_list [number_in_list].value := rav$share_keys [i];
          selection_list [number_in_list].size := rap$line_length (rav$share_keys [i]);
        IFEND;
      FOREND;
    IFEND;


    pmp$get_unique_name (unique_name, status);
    IF NOT status.normal THEN
      RETURN; {----->
    IFEND;

    unique_name (1) := '#';

    clp$create_variable (unique_name, clc$string_value, osc$max_name_size, 1, number_in_list, variable_scope,
          variable, status);
    IF NOT status.normal THEN
      RETURN; {----->
    IFEND;

    value.descriptor := 'VARIABLE';
    value.kind := clc$variable_reference;
    value.var_ref := variable;

    PUSH string_value: [1 .. (#SIZE (rat$table_entry_name) * number_in_list)];
    i#move (^selection_list, string_value, (#SIZE (rat$table_entry_name) * number_in_list));
    variable.value.string_value := string_value;

    clp$write_variable (unique_name, variable.value, status);
    IF NOT status.normal THEN
      RETURN; {----->
    IFEND;

    clp$read_variable (unique_name, value.var_ref, status);
    IF NOT status.normal THEN
      RETURN; {----->
    IFEND;

  PROCEND rap$externalize_share_mode;
MODEND ram$externalize_share_mode
