* _INDICES
* Recursive code to perform two argument variant on INDICES()
* Copyright (c) 2006 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:
* 15 May 06  2.4-4 Added return of case insensitivity flag.
* 14 Dec 05  2.3-2 Added collation map data.
* 18 Nov 05  2.2-17 0433 indices(f,x)<1,4> was inverted.
* 14 Nov 05  2.2-16 Added index sort reporting (Field 1, value 6).
* 16 Sep 04  2.0-1 OpenQM launch. Earlier history details suppressed.
* END-HISTORY
*
* START-DESCRIPTION:
*
*   INDICES(ak.data, akno)
*
*      ak.data : AK data structure (matrix)
*      akno    : AK number (from 1, not from 0 as use internally)
*
* END-DESCRIPTION
*
* START-CODE

$internal
$no.symbols
$no.xref
$recursive

subroutine indices(mat ak.data, akno)
   dim ak.data(1,1)

$include ak_info.h
$include dictdict.h


   result = ''
   if ak.data(akno, AKD$NAME) # '' then
      flags = ak.data(akno, AKD$FLGS)

      result = ak.data(akno, AKD$OBJ)
      type = result[1,1]
      if type = '' then
         type = 'D'   ;* For backward compatibility
         result<1> = type
      end

      fno = ak.data(akno, AKD$FNO)
      if (fno >= 0) then result<DICT.LOC> = fno  ;* Update field number

      * Value 2  -  1 if needs build, else null

      * Value 3  -  1 if NO.NULLS, else null

      if not(bitand(flags, AK$NULLS)) then result<1,3> = '1'

      * Value 4  -  1 if updates enabled, else null

      if bitand(flags, AK$ENABLED)then
         result<1,4> = '1'       ;* 0433 Updates enabled
      end else
         result<1,2> = '1'       ;* Needs build
      end

      * Value 5  -  Internal AK number

      result<1,5> = akno - 1

      * Value 6  -  Sort mode (L or R, blank for old indices)

      begin case
         case bitand(flags, AK$LSORT) ; result<1,6> = 'L'
         case bitand(flags, AK$RSORT) ; result<1,6> = 'R'
      end case

      * Value 7  -  Collation map name

      result<1,7> = ak.data(akno, AKD$MAPNAME)

      if type = 'A' or type = 'S' then
         result<DICT.A.JUSTIFY> = if bitand(flags, AK$RIGHT) then 'R' else 'L'
      end else
         result<DICT.FORMAT> = if bitand(flags, AK$RIGHT) then 'R' else 'L'
         result<DICT.S.M> = if bitand(flags, AK$MV) then 'M' else 'S'
      end

      * Value 8  -  Case insensitive?

      if bitand(flags, AK$NOCASE) then result<1,8> = '1'


   end

   return value result
end

* END-CODE
