* ALIAS
* ALIAS verb.
* Copyright (c) 2004 Ladybridge Systems, All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* 
* Ladybridge Systems can be contacted via the www.openqm.com web site.
* 
* START-HISTORY:
* 18 Oct 04  2.0-5 Use message handler.
* 09 Oct 04  2.0-5 New module.
* 16 Sep 04  2.0-1 OpenQM launch. Earlier history details suppressed.
* END-HISTORY
*
* START-DESCRIPTION:
*
* ALIAS command target         Make "command" execute as "target"
* ALIAS command                Remove alias for "command"
* ALIAS                        Display alias list
*
* END-DESCRIPTION
*
* START-CODE

$internal
program alias
$catalogue $ALIAS

$include parser.h
$include syscom.h

   parser = '!PARSER'
   call @parser(PARSER$RESET, 0, @sentence, 0)
   call @parser(PARSER$GET.TOKEN, token.type, token, keyword) ;* Verb

   * Get command

   call @parser(PARSER$GET.TOKEN, token.type, cmd, keyword)

   if token.type = PARSER$END then          ;* Display aliases
      n = dcount(aliased.commands, @fm)
      if n = 0 then
         display sysmsg(3010) ;* There are no aliased commands
      end else
         for i = 1 to n
            display aliased.commands<i>: ' -> ' : alias.targets<i>
         next i
      end
   end else
      cmd = upcase(cmd)   ;* Aliased commands are effectively case insensitive

      * Get alias

      call @parser(PARSER$GET.TOKEN, token.type, alias, keyword)
      if token.type = PARSER$END then
         locate cmd in aliased.commands<1> by 'AL' setting i then
            del aliased.commands<i>
            del alias.targets<i>
         end
      end else
         locate cmd in aliased.commands<1> by 'AL' setting i then
            alias.targets<i> = alias
         end else
            ins cmd before aliased.commands<i>
            ins alias before alias.targets<i>
         end
      end
   end

   return
end

* END-CODE
