* FORMLST
* FORM.LIST command
* 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:
* 28 Mar 05  2.1-11 Use PARSER$MFILE.
* 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:
*
*    FORM.LIST {DICT} file.name list.name
*
* END-DESCRIPTION
*
* START-CODE


$internal
program $form.list
$catalog $formlst

$include err.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 = ""
   dict.flag = ''

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

   * Get file name

   call @parser(PARSER$MFILE, token.type, file.name, keyword)
   if keyword = KW$DICT then
      dict.flag = 'DICT'
      call @parser(PARSER$MFILE, token.type, file.name, keyword)
   end
   if token.type = PARSER$END then stop "File name missing in FORM.LIST"

   * Get list name

   call @parser(PARSER$GET.TOKEN, token.type, list.name, keyword)
   if token.type = PARSER$END then stop sysmsg(2102) ;* File name required

   * Check no further information in command

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


* ---------------  Step 2 -  Open the file

   open dict.flag, file.name to list.file else
      open dict.flag, upcase(file.name) to list.file else
         @system.return.code = -status()
         stop sysmsg(1430, status(), trimf(dict.flag : ' ')) ;* Error xx opening xx
      end
   end

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

   read list.rec from list.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
