
PROC initialize_user_menu, inium (
  initial_call, ic     : boolean = false
  natural_language, nl : name = us_english
  status               : var of status = $optional
  )


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

"     The purpose of this command is to setup the user's environment to support
"activation of MENU/VE's user menu.  If ADMINISTER_USER does not define a user
"prolog, INITIALIZE_USER_MENU activates the user menu by calling SELECT_USER_MENU.
"If a user prolog is defined, execution is not done here.  When a user prolog is
"defined but does not exist, the prolog is created with a call to
"SELECT_USER_MENU.
"     Parameter INITIAL_CALL is declared for backward compatibility, the
"parameter is ignored.
"     The first section attempts to upgrade the user's environment from 1.2.2 to
"1.2.3 and beyond.  At 1.2.3 the catalog $USER.EUC$CYBER_MENU_SYSTEM is renamed
"$USER.CYBER_MENU_SYSTEM.  This is accomplished by backing up all files found in
"the old catalog and restoring them into the new catalog.  Finally, the old catalog
"is deleted.
"     In the 1.2.3 release, $USER.EUC$CYBER_MENU_SYSTEM  will be eliminated and
"MENU_VE attributes will be stored in the user's prolog per user's request.
*IFEND

  EXIT_PROC WHEN $job(mode) <> 'INTERACTIVE'

  create_variable admu_file k=string v='$local.'//$unique
  create_variable backup_file k=string v='$local.'//$unique
  create_variable catalog_status k=status
  create_variable commands k=string v='$local.'//$unique
  create_variable ignore_status k=status
  create_variable lines k=string d=10
  create_variable lines_returned k=integer v=0
  create_variable index k=integer v=1
  create_variable local_status k=status
  create_variable user_prolog k=string v=''


main_block: ..
  BLOCK

*IF $variable(euv$proc_doc,declared)<>'UNKNOWN'
" Following code is not needed for release 1.0 for there will be no new catalog and files created
"**      display_catalog c=$user.euc$cyber_menu_system o=$null status=catalog_status
"**      IF catalog_status.normal THEN
"**        display_catalog c=$user.cyber_menu_system o=$null status=catalog_status
"**        IF (NOT catalog_status.normal) AND ..    **"
"**              ($condition(catalog_status.condition) = 'PFE$UNKNOWN_LAST_SUBCATALOG') THEN
"**
"**  COLLECT_TEXT o=$fname(commands) until='END_COLLECT'
"**    BACKUP_PERMANENT_FILES bf=$fname(backup_file) l=$job_log
"**      backup_catalog c=$user.euc$cyber_menu_system
"**    QUIT
"**    RESTORE_PERMANENT_FILES l=$job_log
"**      restore_catalog c=$user.euc$cyber_menu_system bf=$fname(backup_file) ncn=$user.cyber_menu_system
"**    QUIT
"**    delete_file f=$fname(backup_file)
"**  END_COLLECT
"**
"**          include_file f=$fname(commands) status=local_status
"**          delete_file f=$fname(commands) status=ignore_status
"**          EXIT main_block WHEN NOT local_status.normal
"**          delete_catalog_contents c=$user.euc$cyber_menu_system status=ignore_status
"**          delete_catalog c=$user.euc$cyber_menu_system status=ignore_status
"**        IFEND
"**      IFEND
*IFEND


COLLECT_TEXT o=$fname(commands) until='END_COLLECT'
  ADMINISTER_VALIDATIONS
    display_user  do=user_prolog  o=$fname(admu_file)
  END_ADMINISTER_VALIDATIONS
END_COLLECT

    include_file $fname(commands) status=local_status
    delete_file $fname(commands) status=ignore_status
    EXIT main_block WHEN NOT local_status.normal

  EDIT_FILE file= $fname(admu_file) output=$null prolog=$null status= ignore_status
    locate_text 'Value:' status= ignore_status
    line_image= $trim($line_text)
    IF $substr(line_image,13,5) = '$NULL' THEN
      user_prolog= ''
    ELSE
      user_prolog= $substr(line_image,13,$strlen(line_image)-12)
    IFEND
  QUIT
  detach_file $fname(admu_file) status= ignore_status

    IF user_prolog = '' THEN

       user_prolog='$user.prolog'
COLLECT_TEXT o=$fname(commands)  until='END_COLLECT'  sm='?'
  ADMINISTER_VALIDATIONS
    CHANGE_USER  $name($job(user))
      change_user_prolog  $string(?user_prolog?)
    END_CHANGE_USER
  END_ADMINISTER_VALIDATIONS
END_COLLECT
    include_file $fname(commands) status=local_status
    delete_file $fname(commands) status=ignore_status
    EXIT main_block WHEN NOT local_status.normal

COLLECT_TEXT o=$fname(user_prolog//'.$eoi')  until='END_COLLECT'  sm='?'
" **MENU_VE USER'S MENU STARTUP CALL**
  SELECT_USER_MENU pc=true nl=?$string($value(natural_language))?  status=osv$status
" **END MENU_VE USER'S MENU VER 1.0**
END_COLLECT

    ELSEIF NOT $file($fname(user_prolog),permanent) THEN

COLLECT_TEXT o=$fname(user_prolog//'.$eoi') until='END_COLLECT' sm='?'
"**MENU_VE USER'S MENU STARTUP CALL**
  SELECT_USER_MENU pc=true nl=?$string($value(natural_language))?  status=osv$status
"**END MENU_VE USER'S MENU VER 1.0**
END_COLLECT

    IFEND

  BLOCKEND main_block

  EXIT_PROC WITH local_status WHEN NOT local_status.normal

PROCEND initialize_user_menu

