* DELUSER
* DELETE.USER verb
* Copyright (c) 2002 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:
* 13 Oct 04  2.0-5 Use message handler.
* 16 Sep 04  2.0-1 OpenQM launch. Earlier history details suppressed.
* END-HISTORY
*
* START-DESCRIPTION:
*
* DELETE.USER username
*
* END-DESCRIPTION
*
* START-CODE

$internal
$flags trusted
program $delete.user
$catalog $DELUSER

$include int$keys.h
$include parser.h
$include err.h

   prompt ''

   parser = "!PARSER"

   @system.return.code = -ER$ARGS     ;* Preset for argument errors


   if not(kernel(K$ADMINISTRATOR,-1)) then
      stop sysmsg(2001) ;* Command requires administrator privileges
   end

   openpath @qmsys:@ds:'$LOGINS' to lgn.f else
      @system.return.code = -status()
      stop sysmsg(6050) ;* Cannot open $LOGINS register in QMSYS account
   end

   call @parser(parser$reset, 0, @sentence, 0)
   call @parser(parser$get.token, token.type, token, keyword) ;* Verb

   * Get and process user name

   call @parser(parser$get.token, token.type, username, keyword)
   if token.type = PARSER$END then
      display sysmsg(6051) :  ;* User name:
      input username
      username = trim(username)
      if username = '' then stop
   end

   * Check for unwanted command arguments

   call @parser(parser$get.token, token.type, token, keyword)
   if token.type # PARSER$END then
      stop sysmsg(2018) ;* Unexpected token (xx)
   end

   * Check user exists in $LOGINS file.

   if system(91) then username = upcase(username)
   if username = '' then stop sysmsg(6052) ;* User name is invalid
   readu lgn.rec from lgn.f, username else stop sysmsg(6057) ;* User is not in register

   * Delete $LOGINS entry

   delete lgn.f, username
   close lgn.f

   display sysmsg(6058, username) ;* User xx deleted

   @system.return.code = 0
   return

   * Avoid compiler warnings
   lgn.rec = lgn.rec
end

* END-CODE
