* RELEASE
* RELEASE verb
* Copyright (c) 2005 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:
* 25 May 05  2.2-0 New module.
* 16 Sep 04  2.0-1 OpenQM launch. Earlier history details suppressed.
* END-HISTORY
*
* START-DESCRIPTION:
*
*    RELEASE filename id...
*    RELEASE FILELOCK filename
*
* END-DESCRIPTION
*
* START-CODE

$internal

program release
$catalog $RELEASE

$include parser.h

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

   parser = "!PARSER"

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

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

   call @parser(PARSER$MFILE, token.type, token, keyword)
   if keyword = KW$FILELOCK then   ;* Releasing file lock
      call @parser(PARSER$MFILE, token.type, token, keyword)
      gosub open.file
      release.lock file.id, @user.no
   end else                        ;* Releasing record lock(s)
      gosub open.file

      call @parser(PARSER$MFILE, token.type, token, keyword)
      if token.type = PARSER$END then stop sysmsg(1434) ;* Record id required

      loop
         release.lock file.id, @user.no, token
         call @parser(PARSER$GET.TOKEN, token.type, token, keyword)
      until token.type = PARSER$END
      repeat
   end

   @system.return.code = 0

   return

* ======================================================================

open.file:
   if token = 'DICT' then
      dict.flag = 'DICT'
      call @parser(PARSER$MFILE, token.type, token, keyword)
   end else
      dict.flag = ''
   end

   open dict.flag, token to fu else
      open dict.flag, upcase(token) to fu else
         @system.return.code = status()
         stop sysmsg(2021, trimf(dict.flag:' ':token)) ;* File %1 not found
      end
   end

   file.id = fileinfo(fu, FL$FILENO)

   return
end

* END-CODE
