PROCEDURE define_timesharing  (
  status: (var) status = $optional
)

*IF $variable(wev$proc_doc,declared)<>'UNKNOWN'

"    This request defines the timesharing application.
"DEFINE_TIMESHARING is called by the DEFINE_NETWORK command.  The
"PROMPT_FOR_TIMESHARING_TITLES procedure call allows the site to
"define multiple titles.  PROMPT_FOR_TIMESHARING_TITLES calls
"PROCESS_TIMESHARING_TITLES which inturn calls the ADD_TITLES
"subcommand to actually set the title values.
*IFEND


    create_variable changes_accepted k=boolean
    create_variable defs_file k=string v='$local.'//$unique
    create_variable display_status k=status
    create_variable i k=integer
    create_variable ignore_status k=status
    create_variable last_line k=integer
    create_variable local_status k=status
    create_variable manna_file k=string v='$local.'//$unique
    create_variable max_titles k=integer v=25
    create_variable prompted k=string
    create_variable sub_utility_file k=string v='$local.'//$unique
    create_variable titles k=string d=max_titles v=''
    create_variable title_count k=integer v=0
    create_variable title_file k=string v='$local.'//$unique
    create_variable yes_response k=boolean


  collect_text o=$fname(manna_file) until='  end_collect'
    $system.osf$command_library.manage_network_applications
    manna_block: ..
      BLOCK
        display_server_attributes server=osa$timesharing o=$null status=display_status
        IF display_status.normal THEN
          collect_text o=$fname(sub_utility_file) until='          end_sub_utility_file'
          chas_block: ..
            BLOCK
              put_line ('1The Timesharing application is already defined.' ..
                        ' The following title(s) are from the current definition' ..
                        ' of Timesharing.')
              display_server_attributes server=osa$timesharing a=titles o=title_list
              $system.edit_file title_list o=$null
                position_cursor line=last
                last_line = $current_line
                position_cursor line=first
                position_cursor t='Titles:'
                title_count = last_line - $current_line + 1
                delete_lines lines=first..($current_line-1)
                write_file file=$output l=current..last
                replace_text 'Titles:' '' line=current
                replace_text ' ' '' lines=all
                position_cursor line=first
                IF $current_word <> 'None' THEN
                  FOR i = 1 TO title_count DO
                    titles(i) = $current_word
                    IF i <> title_count THEN
                      position_forwards
                    IFEND
                  FOREND
                IFEND
              end
              $system.osf$builtin_library.prompt_for_answer ..
                   'Do you want to add or delete Timesharing application titles?' yes_response
              IF NOT yes_response THEN
                EXIT chas_block
              IFEND
              change_server server=osa$timesharing
                $system.osf$builtin_library.prompt_for_timesharing_titles titles changes_accepted
                IF changes_accepted THEN
                  put_line 'end_change_server yes' o=$fname(defs_file)
                ELSE
                  put_line 'end_change_server no' o=$fname(defs_file)
                IFEND
              include_file $fname(defs_file)
            BLOCKEND chas_block
          end_sub_utility_file

        ELSE " Timesharing not defined.
          collect_text o=$fname(sub_utility_file) until='          end_sub_utility_file'
            define_server osa$timesharing protocol=cdna_virtual_terminal nam_initiated=true
              $system.osf$builtin_library.prompt_for_timesharing_titles titles changes_accepted
              IF changes_accepted THEN
                collect_text o=$fname(defs_file) until='                **'
                  change_maximum_connections maximum_connections=500
                  change_connection_priority connection_priority=6
                  change_client_validation capability=timesharing
                  change_server_validation capability=none ring=3 system_privilege=false
                  change_server_job $null validation_source=client maximum_connections=1
                  end_define_server
                **
              ELSE
                put_line 'end_define_server sd=false' o=$fname(defs_file)
              IFEND
            include_file $fname(defs_file)
            IF changes_accepted THEN
              activate_server osa$timesharing
              put_line ('0Timesharing application is defined.', '  ') o=$response
            IFEND
          end_sub_utility_file
        IFEND
        include_file $fname(sub_utility_file)
      BLOCKEND manna_block
    quit
  end_collect

  include_file $fname(manna_file) status=local_status
  detach_file $fname(manna_file) status=ignore_status
  detach_file $fname(title_file) status=ignore_status
  detach_file $fname(defs_file) status=ignore_status
  detach_file $fname(sub_utility_file) status=ignore_status

  IF NOT local_status.normal THEN
    put_line ('0Definition/modification of Timesharing application failed.', ..
              ' '//$strrep(local_status),'  ') o=$response
  IFEND

  accept_line prompted input p='Press NEXT:'

PROCEND define_timesharing
