PROCEDURE process_timesharing_titles (
  input, i: string = $required
  processor, p: key delete, add, keyend = $required
  titles, t: (var) array of string = $required
  )


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

"    The purpose of this request is to add or delete titles from
"the timesharing application currently being defined.  This
"request is called by PROMPT_FOR_TIMESHARING_TITLES.  In this
"request the INPUT line is processed by excuting either of the
"DEFINE_SERVER subcommands, ADD_TITLES or DELETE_TITLES.  This is
"determined by the PROCESSOR value.  The TITLES array is finally
"updated.  The TITLES array is used by
"PROMPT_FOR_TIMESHARING_TITLES to setup the menu display.
*IFEND


   create_variable local_status k=status
   create_variable prompt k=string
   create_variable max_titles k=integer v=$upperbound(titles)
   create_variable local_titles k=string d=1..max_titles
   create_variable title_count k=integer v=0

  local_titles = titles
  processor = $string($value(processor))
  front = $scan_not_any(' ', $value(input))
  input = $trim($substr($value(input), front, ($strlen($value(input))-front+1)))//' '
  title_value = ''
  command_line = processor//'_titles ('
  input_length = $strlen(input)

  FOR i = 1 TO input_length DO
    char = $substr(input, i, 1)
    get_title: ..
      BLOCK
        IF char = ' ' THEN
          include_line 'x=$string($name(title_value))' status=local_status
          IF NOT local_status.normal THEN
            put_line '0Title '//title_value//' is not a name.' o=$response
            accept_line prompt input p='Press NEXT:'
            EXIT_PROC
          IFEND
          found = false
          IF processor = 'ADD' THEN
            FOR index = 1 TO max_titles DO
              IF $translate(ltu,local_titles(index))=$translate(ltu,title_value) THEN
                put_line '0Title '//title_value//' already exists.' o=$response
                put_line ' Title is being ignored' o=$response
                title_value = ''
                EXIT get_title
              IFEND
              found = (local_titles(index) = '')
              EXIT WHEN found
            FOREND
            IF found THEN
              local_titles(index) = title_value
            ELSE
              put_line '0Attempted title add will exceed maximum number of titles.' o=$response
              accept_line prompt input p='Press NEXT:'
              EXIT_PROC
            IFEND
          ELSE
            FOR index = 1 TO max_titles DO
              found = (local_titles(index) = title_value)
              EXIT WHEN found
            FOREND
            IF found THEN
              local_titles(index) = ''
            ELSE
              put_line '0Attempted to delete an unknown title.' o=$response
              accept_line prompt input p='Press NEXT:'
              EXIT_PROC
            IFEND
          IFEND
          command_line = command_line//' '''//title_value//''''
          title_count = title_count + 1
          title_value = ''
        ELSE
          title_value = title_value//char
        IFEND
      BLOCKEND get_title
  FOREND
  command_line = command_line//')'

  IF title_count>0 THEN
    include_command command_line status=local_status
    IF local_status.normal THEN
      titles = local_titles
    ELSE
      put_line ('0The following error occured during attempt to '//processor//' titles.', ..
                ' '//$strrep(local_status)) o=$response
      accept_line prompt input p='Press NEXT:'
      EXIT_PROC
    IFEND
  ELSE
    put_line '0No titles were added.' o=$response
    accept_line prompt input p='Press NEXT:'
  IFEND

PROCEND process_timesharing_titles
