/* ***********************************************************
 * *                                                         *
 * *   IRIS MENU I/O related routines, for POM menu          *
 * *                                                         *
 * ***********************************************************
 * File: libs/config/menu_load.c
 *
 *                     COPYRIGHT (c) 2003  BY
 *         SIGMET INCORPORATED, WESTFORD MASSACHUSETTS, U.S.A.
 * 
 * THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
 * ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
 * INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
 * COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
 * OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
 * TRANSFERED.
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "sigtypes.h"
#include "headers.h"
#include "product.h"
#define LIM_DEFINITIONS
#define LIM_KERNEL menu_limits_kernel
#include "config_lib.h"
#include "user_lib.h"

static MESSAGE menu_limits
( const char *sname_a,		/* Name of structure */
  volatile void *item_a,	/* Pointer to structure */
  SINT4 ioper_a,		/* Operation to perform */
  void *file_a );		/* Diagnostic messages, or NULL */

static MESSAGE LIM_KERNEL
( const char *sname_a,		/* Name of structure */
  void *item_a,			/* Pointer to structure */
  SINT4 ioper_a,		/* Operation to perform */
  const char *spath_a,		/* Full path name of fields */
  void *ioarg_a ) ;		/* Diagnostic messages, or NULL */


/* =================================================================== 
 * This subroutine reads the saved values from the setup file.
 */
MESSAGE menu_load_pom_headers
( const char *sName_a,                     /* File name to load */
  struct pom_save_sends_list *pPomHeaders_a )
{
  char sName[FILENAME_SIZE];

  strncpy( sName, sName_a, FILENAME_SIZE-20 );
  sName[FILENAME_SIZE-20]=0;
  strcat( sName, ".pom_headers" );
  memset( pPomHeaders_a, 0, sizeof(struct pom_save_sends_list) ) ;

  return( lim_loadFileDir( NULL, "IRIS_MENU", sName, "pom_save_sends_list",
			   pPomHeaders_a, menu_limits ) ) ;
}

/* =================================================================== 
 * This subroutine writes new values to the dsp file. 
 */
MESSAGE menu_save_pom_headers
( const char *sName_a,                    /* File name to load */
  const struct pom_save_sends_list *pPomHeaders_a )
{
  char sName[FILENAME_SIZE];
  strncpy( sName, sName_a, FILENAME_SIZE-20 );
  sName[FILENAME_SIZE-20]=0;
  strcat( sName, ".pom_headers" );

  return( lim_saveFileDir( NULL, "IRIS_MENU", sName, "pom_save_sends_list",
			pPomHeaders_a, menu_limits ) ) ;
}

/* ======================================================================
 * Check limits on menu structures.
 */
static MESSAGE menu_limits
( const char *sname_a,		/* Name of structure */
  volatile void *item_a,	/* Pointer to structure */
  SINT4 ioper_a,		/* Operation to perform */
  void *file_a )		/* Diagnostic messages, or NULL */
{
  return( lim_toplevel( sname_a, item_a, ioper_a, file_a, LIM_KERNEL ) ) ;
}

/* ======================================================================
 * Internal routine to recursively descend the menu structures.
 */
static MESSAGE LIM_KERNEL
( const char *sname_a,		/* Name of structure */
  void *item_a,			/* Pointer to structure */
  SINT4 ioper_a,		/* Operation to perform */
  const char *spath_a,		/* Full path name of fields */
  void *ioarg_a )		/* Diagnostic messages, or NULL */
{
  char spath[PATHNAME_SIZE], *sItem ; struct lim_inLine **pLine ;
  SINT4 idim1=0, idim2=0 ; MESSAGE istatus = SS_NORMAL ;
  UINT1 lActualSizes = USEACTUALSIZES( ioper_a ) ;

  /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  if( 0 == strcmp( "pom_save_sends_list", sname_a ) )
    {
      struct pom_save_sends_list *item = item_a ;
      
      SUBSTRUCTURE_1D( pom_save_sends, Sends, MAX_POM_SENDS_SAVED ) ;
    }
  /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  else if( 0 == strcmp( "pom_save_sends", sname_a ) ) 
    {
      struct pom_save_sends *item = item_a ;
      
      if( (!lActualSizes) || item->iPType )
	{
	  SCALAR   (     iPType,    0, NUM_DEFINED_PRODUCTS,    0 ) ;
	  STRING   (     sPName,   "" ) ;
	  SCALAR_1D(    iOutput,    0,           0xffffffff,    0, MAX_OUT_DEVICES ) ;
	  SCALAR_1D( iHeadFlags,    0,                    1,    0, MAX_OUT_DEVICES ) ;
	}
    }
  /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  else
    istatus = iMessageMod_va( CONFIG_LIM_BADSTRUCT, 1, sname_a ) ;

  return( istatus ) ;
}

