* GETLIST
* GET.LIST command
* Copyright (c) 1994, 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:
*
*    GET.LIST [list.name] [TO list.number]
*
* list.name   = name from which to restore. Defaults to list.number
*
* list.number = list to restore. Defaults to 0.
*
* @SYSTEM.RETURN.CODE
*    +ve Successful - number of items restored
*    -ve Error code
*
* END-DESCRIPTION
*
* START-CODE


$internal
program $get.list
$catalog $getlist

$include err.h
$include keys.h

$include syscom.h
$include parser.h


   parser = "!PARSER"

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

* ---------------  Step 1 -  Parse the command

   list.no = 0
   list.name = ""

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

   * Get list name

   call @parser(parser$get.token, token.type, list.name, keyword)
   if (token.type = PARSER$END) or (keyword = KW$TO) then
      stop sysmsg(3273) ;* Saved select list name missing or invalid
   end

   * Get list number if present

   call @parser(parser$get.token, token.type, token, keyword)
   if keyword = KW$TO then
      call @parser(parser$get.token, token.type, token, keyword)
      if (token.type = PARSER$END) or not(num(token)) then
         stop sysmsg(3272) ;* Select list number missing or invalid
      end

      list.no = token + 0
      if list.no > HIGH.USER.SELECT then
         stop sysmsg(3272) ;* Select list number missing or invalid
      end

      call @parser(parser$get.token, token.type, token, keyword)
   end

   * Check no further information in command

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


* ---------------  Step 2 -  Open the save list file

   open "$SAVEDLISTS" to saved.lists.file else
      @system.return.code = -status()
      stop sysmsg(3248, status()) ;* Error xx opening $SAVEDLISTS
   end

* ---------------  Step 3 -  Fetch the select list

   read list.rec from saved.lists.file, list.name on error
      @system.return.code = -status()
      stop sysmsg(3259, status(), list.name) ;* Error xx reading list 'xx'
   end else
      @system.return.code = -status()
      stop sysmsg(3268, list.name) ;* Saved select list 'xx' not found
   end

   formlist list.rec to list.no
   @system.return.code = dcount(list.rec, @fm)
   display sysmsg(3261, @system.return.code, list.no) ;* xx records selected to select list xx

   return
end

* END-CODE
