/* ********************************
 * *                              *
 * * Local Structures Definitions *
 * *                              *
 * ********************************
 */

/* Operation argument to main setup routines.
 */
#define OPER_CREATE     0
#define OPER_CALLBACK   1
#define OPER_MAX_WIDTH  2
#define OPER_LIST       3
#define OPER_TEST       4
#define OPER_REPAIR     5

#define WARN_MSG_TYPE_SAVE             1
#define WARN_MSG_TYPE_SAVE_NOT_ALLOWED 2
#define WARN_MSG_TYPE_ACK              3

/* Local widget information structure.  Contains auxiliary user data that
 * often needs to be associated with widgets.
 */
struct widget_info		/* Auxiliary information about a widget */
{
  SINT4 type ;			/* Type of the widget */
#define TYPE_TEXT         0
#define TYPE_NUMERIC      1
#define TYPE_LABEL        2
#define TYPE_BOOLEAN      3
#define TYPE_NUMERIC_HINT 4
#define TYPE_TEXT_HINT    5
#define TYPE_FRAME_HELP   6

  SINT4 frame_form_line ;	/* 8-bit frame, 12-bit form, 12-bit line */

  Widget *widget ;		/* ==> first (of possibly several) */

#define PRINTF_STR_LEN 80
  char printfstr1[PRINTF_STR_LEN] ;
  char printfstr2[PRINTF_STR_LEN] ;
};

struct labeldef			/* Used to define pulldown labels */
{
  char *text ;			/* ==> pulldown text */
  SINT4 value ;			/* Value associated with this choice */
} ;

struct menu_s {
  Widget  main;
  Widget  mainbar;
  Widget  filebtn;
  Widget  filepdw;
  Widget  helpbtn;
  Widget  helppdw;
  Widget  srlwin;
  Widget  rowcol;
};

/* ***********************************
 * *                                 *
 * * Display/Query Macro Definitions *
 * *                                 *
 * ***********************************
 */

/* ==================================================
 * Macro to display and query for a single numeric item.
 *
 *         ITEM : Name of the structure member.  Can be any size INT or FLT.
 *  DESCRIPTION : Text string describing the item.
 *    PRINTFSTR : String used to print the item's value.  Must contain a
 *                floating print designator.
 *        SCALE : Floating scale factor to convert to internal units.
 */
#define NUMERIC_ITEM( ITEM, DESCRIPTION, PRINTFSTR, SCALE ) \
switch (oper_a) \
  { \
    case OPER_CREATE : \
      { \
        struct widget_info *winfo = \
          make_simple_item( DESCRIPTION, width, local_cbf ); \
	winfo->type = TYPE_NUMERIC ; \
        winfo->frame_form_line = frame_form_line; \
        strncpy( winfo->printfstr1, PRINTFSTR, PRINTF_STR_LEN ) ; \
        winfo->printfstr1[ PRINTF_STR_LEN-1 ] = 0 ; \
        display_numeric_item( winfo->widget[1], ((FLT8)WVAL(ITEM))/(SCALE)); \
      } \
      break; \
      NUMERIC_TAIL( ITEM, DESCRIPTION, PRINTFSTR, SCALE ) ;

#define NUMERIC_HINT( ITEM, DESCRIPTION, PRINTFSTR, SCALE, HINTS ) \
switch (oper_a) \
  { \
    case OPER_CREATE : \
      { \
        int   II; \
        SINT4 nitems = sizeof(HINTS) / sizeof(char*) ; \
        struct widget_info **winfo = \
          make_simple_hint( DESCRIPTION, width, local_cbf, HINTS, nitems); \
        winfo[0]->type = TYPE_NUMERIC ; \
        winfo[1]->type = TYPE_NUMERIC_HINT ; \
        for(II = 0; II < 2; II++) \
        { \
          winfo[II]->frame_form_line = frame_form_line ; \
          strncpy( winfo[II]->printfstr1, PRINTFSTR, PRINTF_STR_LEN ) ; \
          winfo[II]->printfstr1[ PRINTF_STR_LEN-1 ] = 0 ; \
        } \
        display_numeric_item( winfo[0]->widget[1], ((FLT8)WVAL(ITEM))/(SCALE)); \
      } \
      break; \
      NUMERIC_TAIL( ITEM, DESCRIPTION, PRINTFSTR, SCALE ) ;

/* The assignment of a new value to an item detects whether the
 * FLT8 value becomes changed after the assignment.  Any change
 * is used as evidence that the item is an INT of some sort, and
 * the assignment is redone using NINT()
 */
#define NUMERIC_TAIL( ITEM, DESCRIPTION, PRINTFSTR, SCALE ) \
    case OPER_CALLBACK : \
      if (winfo_a->frame_form_line == frame_form_line) \
        { \
          if (cbd_a) \
          { \
            FLT8 fnew, fval = *(FLT8 *)cbd_a; \
            fval = MAX(fval, ((FLT8)setup_min_c.ITEM)/(SCALE)); \
            fval = MIN(fval, ((FLT8)setup_max_c.ITEM)/(SCALE)); \
            fnew = (SCALE) * fval ;  /* WVAL(ITEM) =      fnew  ;*/ \
            /* if( WVAL(ITEM) != fnew ) WVAL(ITEM) = NINT(fnew) ;*/ \
            AssignValue( &WVAL(ITEM), fnew ); \
          } \
          display_numeric_item( winfo_a->widget[1], ((FLT8)WVAL(ITEM))/(SCALE)); \
        } \
      break; \
    case OPER_MAX_WIDTH : \
      width = MAX(width, (int)strlen(DESCRIPTION)+1); \
      break;\
    case OPER_LIST : \
      if (list_frame && list_form) \
      { \
        FILE *stream = (FILE *)cbd_a; \
        list_numeric_item(stream, DESCRIPTION, descrip_fmtstr, \
          ((FLT8)WVAL(ITEM))/(SCALE), PRINTFSTR); \
      } \
      break;\
    case OPER_TEST : \
      if (list_frame && list_form) \
      { \
        if( (0 == MINV(ITEM)) && (0 == MAXV(ITEM)) ) \
          minmax_error( #ITEM, DESCRIPTION ) ; \
        if( (WVAL(ITEM) < MINV(ITEM)) || (WVAL(ITEM) > MAXV(ITEM)) ) \
          test_numeric_item(DESCRIPTION, WVAL(ITEM), \
            MINV(ITEM), MAXV(ITEM), SCALE, PRINTFSTR); \
      } \
      break;\
    case OPER_REPAIR : \
      if( (!lrepair_only_visible_c) || (list_frame && list_form) ) { \
        if ((WVAL(ITEM) < MINV(ITEM)) || (WVAL(ITEM) > MAXV(ITEM))) \
        { \
          FLT8 fval_old = WVAL(ITEM) ; WVAL(ITEM) = DEFV(ITEM) ; \
          if (list_frame && list_form) \
            repair_numeric_item(DESCRIPTION, WVAL(ITEM), fval_old, SCALE, PRINTFSTR); \
        } \
      } \
      break;\
  } \
frame_form_line++;

/* ==================================================
 * Macro to display and query for a single text field.
 *
 *         ITEM : Name of the structure member character string
 *  DESCRIPTION : Text string describing the item.
 *       LENGTH : Allocation length of the string.
 *     PADSTYLE : One of PAD_NULLTERM, PAD_SPACE, plus PAD_HIDDEN option
 */
#define PAD_NULLTERM 0x01
#define PAD_SPACE    0x02
#define PAD_HIDDEN   0x04

#define TEXT_ITEM( ITEM, DESCRIPTION, LENGTH, PADSTYLE ) \
switch (oper_a) \
  { \
    case OPER_CREATE : \
      { \
        struct widget_info *winfo = \
          make_simple_item( DESCRIPTION, width, local_cbf ); \
        winfo->type = TYPE_TEXT ; \
        winfo->frame_form_line = frame_form_line; \
        display_text_item( winfo->widget[1], WVAL(ITEM), LENGTH, PADSTYLE); \
      } \
      break; \
      TEXT_TAIL( ITEM, DESCRIPTION, LENGTH, PADSTYLE ) ;

#define TEXT_HINT( ITEM, DESCRIPTION, LENGTH, PADSTYLE, HINTS ) \
switch (oper_a) \
  { \
    case OPER_CREATE : \
      { \
        int II; \
        SINT4 nitems = sizeof(HINTS) / sizeof(char*) ; \
        struct widget_info **winfo = \
          make_simple_hint( DESCRIPTION, width, local_cbf, HINTS, nitems); \
        winfo[0]->type = TYPE_TEXT ; \
        winfo[1]->type = TYPE_TEXT_HINT ; \
        for(II = 0; II < 2; II++) \
           winfo[II]->frame_form_line = frame_form_line ; \
        display_text_item( winfo[0]->widget[1], WVAL(ITEM), LENGTH, PADSTYLE); \
      } \
      break; \
      TEXT_TAIL( ITEM, DESCRIPTION, LENGTH, PADSTYLE ) ;

#define TEXT_TAIL( ITEM, DESCRIPTION, LENGTH, PADSTYLE ) \
    case OPER_CALLBACK : \
      if (winfo_a->frame_form_line == frame_form_line) \
        { \
          extract_text_item( (char *)cbd_a,      WVAL(ITEM), LENGTH, PADSTYLE ); \
          display_text_item( winfo_a->widget[1], WVAL(ITEM), LENGTH, PADSTYLE ); \
        } \
      break; \
    case OPER_MAX_WIDTH : \
      width = MAX(width, (int)strlen(DESCRIPTION)+1); \
      break; \
    case OPER_LIST : \
      if (list_frame && list_form) \
      { \
        FILE *stream = (FILE *)cbd_a; \
        list_text_item(stream, DESCRIPTION, descrip_fmtstr, WVAL(ITEM), \
          LENGTH, PADSTYLE); \
      } \
      break;\
    case OPER_TEST : \
      if (strchr(WVAL(ITEM), '\0') == NULL)  \
      { \
        if (list_frame && list_form) \
          test_text_item(DESCRIPTION, WVAL(ITEM), LENGTH); \
      } \
      break;\
    case OPER_REPAIR : \
      if( (!lrepair_only_visible_c) || (list_frame && list_form) ) { \
        if (strchr(WVAL(ITEM), '\0') == NULL)  \
        { \
          WVAL(ITEM)[LENGTH - 1] = '\0'; \
          if (list_frame && list_form) \
           repair_text_item(DESCRIPTION, WVAL(ITEM)); \
        } \
      } \
      break;\
  } \
frame_form_line++;

/* ==================================================
 * Macro to display and query for a selection from a pulldown list
 *
 *         ITEM : Name of the structure member scalar item
 *  DESCRIPTION : Text string describing the item.
 *       LABELS : Array of labeldef structures defining the option menu
 */
#define LABEL_ITEM( ITEM, DESCRIPTION, LABELS ) \
switch (oper_a) \
  { \
    case OPER_CREATE : \
      { \
        SINT4 nitems = sizeof(LABELS) / sizeof(struct labeldef) ; \
        struct widget_info *winfo = make_label_item \
          ( DESCRIPTION, LABELS, nitems, width, local_cbf ); \
	winfo->type = TYPE_LABEL ; \
        winfo->frame_form_line = frame_form_line; \
        display_label_item( winfo->widget[1], WVAL(ITEM), LABELS, nitems); \
      } \
      break; \
    case OPER_CALLBACK : \
      if (winfo_a->frame_form_line == frame_form_line) \
        { \
          SINT4 nitems = sizeof(LABELS) / sizeof(struct labeldef) ; \
          WVAL(ITEM) = extract_label_item( (int)cbd_a, LABELS, nitems ); \
        } \
      break; \
    case OPER_MAX_WIDTH : \
      width = MAX(width, (int)strlen(DESCRIPTION)+1); \
      break; \
    case OPER_LIST : \
      if (list_frame && list_form) \
      { \
        FILE *stream = (FILE *)cbd_a; \
        SINT4 nitems = sizeof(LABELS) / sizeof(struct labeldef) ; \
        list_label_item(stream, DESCRIPTION, descrip_fmtstr, WVAL(ITEM), \
          LABELS, nitems); \
      } \
      break;\
    case OPER_TEST : \
      if (list_frame && list_form) \
        if( (0 == MINV(ITEM)) && (0 == MAXV(ITEM)) ) \
          minmax_error( #ITEM, DESCRIPTION ) ; \
    case OPER_REPAIR : \
      { \
        SINT4 item_idx; \
        SINT4 nitems = sizeof(LABELS) / sizeof(struct labeldef) ; \
        for (item_idx = 0; item_idx < nitems; item_idx++) \
         { \
           if (((SINT4)WVAL(ITEM)) == LABELS[item_idx].value) \
             break; \
         } \
         if (item_idx >= nitems) \
         { \
           if (oper_a == OPER_TEST) \
           { \
             if (list_frame && list_form) \
               test_label_item(DESCRIPTION); \
           } \
           else /* OPER_REPAIR */ \
           { \
             if( (!lrepair_only_visible_c) || (list_frame && list_form) ) { \
               WVAL(ITEM) = LABELS[0].value; \
               if (list_frame && list_form) \
                 repair_label_item(DESCRIPTION, LABELS[0].text); \
             } \
           } \
         } \
      } \
      break;\
  } \
frame_form_line++;

/* ==================================================
 * Macro to display boolean.
 *
 *         ITEM : Name of the structure member character string
 *  DESCRIPTION : Text string describing the item.
 */
#define BOOLEAN_ITEM( ITEM, DESCRIPTION, FALSE_STR, TRUE_STR ) \
switch (oper_a) \
  { \
    case OPER_CREATE : \
      { \
        struct widget_info *winfo = make_boolean_item( DESCRIPTION,  \
          FALSE_STR, TRUE_STR, width, local_cbf ); \
	winfo->type = TYPE_BOOLEAN ; \
        winfo->frame_form_line = frame_form_line; \
        XtVaSetValues( winfo->widget[1], XmNset, WVAL(ITEM), NULL) ; \
        display_boolean_item( winfo->widget[1], WVAL(ITEM)); \
      } \
      break; \
    case OPER_CALLBACK : \
      if (winfo_a->frame_form_line == frame_form_line) \
        { \
          UINT1  lset = *(UINT1 *)cbd_a; \
	  WVAL(ITEM) = lset ; \
          display_boolean_item( winfo_a->widget[1], WVAL(ITEM)); \
        } \
      break; \
    case OPER_MAX_WIDTH : \
      width = MAX(width, (int)strlen(DESCRIPTION)+1); \
      break; \
    case OPER_LIST : \
      if (list_frame && list_form) \
      { \
        FILE *stream = (FILE *)cbd_a; \
        list_boolean_item(stream, DESCRIPTION, descrip_fmtstr, WVAL(ITEM), \
          FALSE_STR, TRUE_STR ); \
      } \
      break;\
    case OPER_TEST : \
      if (list_frame && list_form) \
      { \
        if( (0 == MINV(ITEM)) && (0 == MAXV(ITEM)) ) \
          minmax_error( #ITEM, DESCRIPTION ) ; \
        if( (WVAL(ITEM) < MINV(ITEM)) || (WVAL(ITEM) > MAXV(ITEM)) ) \
          test_boolean_item(DESCRIPTION, WVAL(ITEM), MINV(ITEM), MAXV(ITEM)); \
      } \
      break;\
    case OPER_REPAIR : \
      if( (!lrepair_only_visible_c) || (list_frame && list_form) ) { \
        if ((WVAL(ITEM) < MINV(ITEM)) ||(WVAL(ITEM) > MAXV(ITEM))) \
        { \
          UINT1 lset_old = WVAL(ITEM); \
          WVAL(ITEM) = MAXV(ITEM); \
          if (list_frame && list_form) \
            repair_boolean_item(DESCRIPTION, WVAL(ITEM),  lset_old); \
        } \
      } \
      break;\
  } \
frame_form_line++;

/* ==================================================
 * Macro to display new frame, overriding the help string at OPER_CALLBACK time.
 *
 *  DESCRIPTION : Text string describing the current frame.
 *         COND : Conditional expression for visibility of the frame
 */
#define BEGIN_NEW_FRAME( DESCRIPTION, COND) \
frame_form_line += 0x01000000; /* Increment the frame number */ \
{ SINT4 framenum = frame_form_line >> 24 ; \
  switch (oper_a) \
    { \
      case OPER_CREATE : \
      { \
        struct widget_info *winfo; \
        struct menu_s *main_menu = (struct menu_s *)cbd_a; \
        frame_array = (Widget*)realloc( frame_array, (framenum+1)*sizeof(Widget) ) ; \
        winfo = make_new_frame( main_menu->rowcol, DESCRIPTION, local_cbf);\
	winfo->type = TYPE_FRAME_HELP ; \
        winfo->frame_form_line = frame_form_line; \
        strcpy(winfo->printfstr1, help_file); \
        frame_array[framenum] =  winfo->widget[0]; \
        if (COND) \
          XtManageChild(frame_array[framenum]); \
        else  \
          XtUnmanageChild(frame_array[framenum]); \
      } \
        break; \
      case OPER_CALLBACK : \
        if (winfo_a->frame_form_line == frame_form_line) \
             display_frame_help(winfo_a->printfstr1); \
        if (COND) \
          XtManageChild(frame_array[framenum]); \
        else \
          XtUnmanageChild(frame_array[framenum]); \
        break; \
      case OPER_LIST : \
      case OPER_TEST : \
      case OPER_REPAIR : \
        if (COND) \
        { \
           if (oper_a == OPER_LIST) \
           { \
             FILE *stream = (FILE *)cbd_a; \
             list_frame_title(stream, DESCRIPTION); \
           } \
           list_frame = TRUE; \
        } \
        else \
          list_frame = FALSE;\
        break; \
    }; \
}; \
BEGIN_OPTIONAL_LIST( TRUE ) ;

/* ==================================================
 * Macro to begin a group of optional questions.
 *
 *  COND : Conditional expression for visibility of the group.
 */
#define BEGIN_OPTIONAL_LIST( COND ) \
frame_form_line += 0x00001000; /* Increment the form number */ \
frame_form_line &= 0xFFFFF000; /* Zero the line number */ \
{ SINT4 formnum = (frame_form_line >> 12) & 0xFFF ; \
  switch( oper_a ) \
    { \
      case OPER_CREATE : \
        form_array = (Widget *)realloc( form_array, (formnum+1)*sizeof(Widget) ) ; \
        form_array[ formnum ] = make_optional_list() ; \
      case OPER_CALLBACK : \
        if (COND) \
          XtManageChild( form_array[ formnum ] ) ; \
        else \
          XtUnmanageChild( form_array[ formnum ] ); \
        break; \
      case OPER_LIST : \
      case OPER_TEST : \
      case OPER_REPAIR : \
        if (COND) \
          list_form = TRUE; \
        else \
          list_form = FALSE;\
        break; \
     } \
}

/* ==================================================
 * Macro to begin a group of optional questions.
 *
 *  COND : Conditional expression for visibility of the group.
 */
#define ADD_TITLE(TITLE) \
  switch( oper_a ) \
    { \
      case OPER_CREATE : \
      { \
        struct menu_s *main_menu = (struct menu_s *)cbd_a; \
        make_title_and_help(main_menu->main, main_menu->helppdw, TITLE, \
          help_file); \
      } \
      break; \
    case OPER_LIST : \
      { \
        FILE *stream = (FILE *)cbd_a; \
        list_title(stream, TITLE); \
      } \
      break; \
    case OPER_TEST : \
    case OPER_REPAIR : \
      { \
        test_title(TITLE); \
      } \
      break; \
    } 

/* ***********************
 * *                     *
 * * Function Prototypes *
 * *                     *
 * ***********************
 */

struct widget_info *make_simple_item
( char *description_a, int width_a, XtCallbackProc cbf_a ) ;

void display_numeric_item(Widget wgt_a, FLT8 fval_a) ;
void list_numeric_item(FILE *stream_a, char *descrip_a, char *descrip_fmtstr_a, 
  FLT8 fval_a, char *fval_fmtstr_a);
void test_numeric_item(char *descrip_a, FLT8 fval_a, FLT8 min_fval_a, 
  FLT8 max_fval_a, FLT8 scale_a, char *fmtstr_a );
void repair_numeric_item(char *descrip_a, FLT8 fval_a, FLT8 fval_old_a, FLT8 scale_a,
   char *fmtstr_a );

void display_text_item(Widget wgt_a,      char *item_a, int length_a, int padstyle_a) ;
void extract_text_item(const char *newstring_a, char *item_a, int length_a, int padstyle_a) ;
void list_text_item(FILE *stream_a, char *descrip_a, char *descrip_fmtstr_a, char *item_a,
   int length_a, int padstyle_a);
void test_text_item(char *descrip_a, char *item_a,  int length_a);
void repair_text_item(char *descrip_a, char *item_a);

struct widget_info **make_simple_hint
( char *description_a, int width_a, XtCallbackProc cbf_a, char *hints_a[], int nitems_a);


struct widget_info *make_label_item
( char *description_a, struct labeldef labels_a[], int nitems_a,
  int width_a, XtCallbackProc cbf_a ) ;

void display_label_item(Widget wgt_a, SINT4 item_a, struct labeldef labels_a[], int nitems_a);
SINT4 extract_label_item( int row_a, struct labeldef labels_a[], int nitems_a ) ;
void list_label_item(FILE *stream_a, char *descrip_a, char *descrip_fmtstr_a,
  SINT4 item_a, struct labeldef labels_a[], int nitems_a);
void test_label_item(char *descrip_a);
void repair_label_item(char *descrip_a, char *labelstr_a);

struct widget_info *make_boolean_item
( char *description_a, char *false_str_a, char *true_str_a,
  int width_a, XtCallbackProc cbf_a ) ;

void display_boolean_item(Widget wgt_a, UINT1 lset_a) ;
void list_boolean_item(FILE *stream,  char *descrip_a, char *descrip_fmtstr_a,
  UINT1 lset_a, char *false_str_a, char *true_str_a);
void test_boolean_item(char *descrip_a, UINT1 lset_a, UINT1 lfalse_a, UINT1 ltrue_a);
void repair_boolean_item(char *descrip_a, UINT1 lset_a, UINT1 lset_old_a);

void generic_cbf
(Widget wgt_a, XtPointer cbd_a, XtPointer cbs_a,
 void (*kernel)(int operation, struct widget_info *info, void *cbd)) ; 

struct widget_info *make_new_frame(Widget rowcol_a, char *frame_title_a,
   XtCallbackProc cbf_a );
void display_frame_help(char *help_str_a);
void list_frame_title(FILE *stream, char *descrip_a);

Widget make_optional_list( void ) ;

void make_title_and_help(Widget main_wgt_a, Widget pdw_wgt_a,
    char *dialog_title_a, char *help_file_a);
void list_title(FILE *stream, char *title_str_a);
void test_title(char *title_str_a);

void rcp_top_setup(int oper_a, struct widget_info *winfo_a, void *cbd_a ) ;
void rcp_top_setup_cbf (Widget wgt_a, XtPointer cbd_a, XtPointer cbs_a) ;

void dsp_top_setup(int oper_a, struct widget_info *winfo_a, void *cbd_a ) ;
void dsp_top_setup_cbf (Widget wgt_a, XtPointer cbd_a, XtPointer cbs_a) ;

void input_top_setup(int oper_a, struct widget_info *winfo_a, void *cbd_a ) ;
void input_top_setup_cbf (Widget wgt_a, XtPointer cbd_a, XtPointer cbs_a) ;

void output_top_setup(int oper_a, struct widget_info *winfo_a, void *cbd_a ) ;
void output_top_setup_cbf (Widget wgt_a, XtPointer cbd_a, XtPointer cbs_a) ;

void product_top_setup(int oper_a, struct widget_info *winfo_a, void *cbd_a ) ;
void product_top_setup_cbf (Widget wgt_a, XtPointer cbd_a, XtPointer cbs_a) ;

void ingest_top_setup(int oper_a, struct widget_info *winfo_a, void *cbd_a ) ;
void ingest_top_setup_cbf (Widget wgt_a, XtPointer cbd_a, XtPointer cbs_a) ;

void iris_top_setup(int oper_a, struct widget_info *winfo_a, void *cbd_a ) ;
void iris_top_setup_cbf (Widget wgt_a, XtPointer cbd_a, XtPointer cbs_a) ;

void input_top_setup(int oper_a, struct widget_info *winfo_a, void *cbd_a ) ;
void input_top_setup_cbf (Widget wgt_a, XtPointer cbd_a, XtPointer cbs_a) ;

void license_top_setup(int oper_a, struct widget_info *winfo_a, void *cbd_a ) ;
void license_top_setup_cbf (Widget wgt_a, XtPointer cbd_a, XtPointer cbs_a) ;

void web_top_setup(int oper_a, struct widget_info *winfo_a, void *cbd_a ) ;
void web_top_setup_cbf (Widget wgt_a, XtPointer cbd_a, XtPointer cbs_a) ;

void  load_checksum(void);
void  load_auxset_checksum(void);
UINT2 compare_checksum_equal(void);
FILE  *open_list_file(void);
void  setupload(void) ;
void  auxiliary_setup_info( UINT2 lentry_a ) ;
void  setupsave(void) ;
void  popupMinMaxErrors(void);
void minmax_error( char *item_a, char *desc_a ) ;
void setup_load_delayed(void);
void setup_desensitive_save_wgt(void);


void popup_warning_dialog(char *msg_sptr, 
       char *ok_sptr, char *cancel_sptr, UINT4 iwarning_type_a);
void popdown_warning_dialog(void);
void popup_loading_dialog(char *stxt_a);
void popup_loading_dialog_delay(char *stxt_a);
void popdown_loading_dialog(void);

void update_msg_loading_dialog(char *stxt_a); 
char *warning_message_save(void);
UINT2 lhas_same_iris_version(void);

/* ***************************************
 * *                                     *
 * * Static Shared Structure Allocations *
 * *                                     *
 * ***************************************
 */
#ifdef SETUP_ALLOCATE
#define EXTERN
#else
#define EXTERN extern
#endif

EXTERN XtAppContext app_context_c;
EXTERN char remoteHostData_c[MAXHOSTNAMELEN];
EXTERN char hostname_c[MAXHOSTNAMELEN];

#define VERSIONS_SAME           1
#define VERSIONS_DONT_MATCH     2
#define VERSIONS_ZERO           3
#define VERSIONS_UNKNOWN_HOST   4
EXTERN UINT2 lsame_iris_version;

/* Auxiliary SETUP variables that help with the user interface.
 */
struct auxset {
  SINT4 rcp_ilat, rcp_ilon ;	  /* Signed versions of latitude and longitude */
  UINT2 lstatus_product_gen ;     /* Status products are being generated */
  UINT2 lstatus_product_timeout ; /* Receive timeouts are enabled */
  UINT2 lnoise_az ;               /* Specific AZ is forced during noise sample */
  UINT2 lnoise_el ;               /* Minimum EL is forced during noise sample */
  UINT2 lingsim_radar ;		  /* Ingest simulation is at the radar */
  UINT2 lingsim_shearline ;	  /* Ingest simulation includes a shear line */
  UINT2 lingsim_fallspeed ;	  /* Ingest simulation includes fallspeed */
  UINT2 lingsim_windfield ;	  /* Ingest simulation includes overall windfield */
} ;

/* The following structure contains all of the setup structures that will
 * ever be accessed.  They are put together into one large collection so
 * that the interactive menus can freely cross between major divisions if
 * certain data happen to be grouped that way.
 */
struct allsetups {
  struct ant_manual_setup   rcp  ;
  struct iris_setup         iris ;
  struct license_setup      License ;
  struct rtdisp_setup       Rtdisp ;
  struct dsp_manual_setup   dsp  ;
  struct dsp_gain_cal       gain ;
  struct dsp_agc_cal        agc  ;
  struct auxset             auxset ;
} ;

EXTERN struct allsetups setup_min_c ;
EXTERN struct allsetups setup_max_c ;
EXTERN struct allsetups setup_def_c ;
EXTERN struct allsetups setup_work_c ;

#define MINV( ITEM ) (setup_min_c.ITEM)  /* Minimum value of an item */
#define MAXV( ITEM ) (setup_max_c.ITEM)  /* Maximum value of an item */
#define DEFV( ITEM ) (setup_def_c.ITEM)  /* Default value of an item */
#define WVAL( ITEM ) (setup_work_c.ITEM) /* Working value of an item */

EXTERN Widget setup_top_c;
EXTERN Display *main_display_c;
EXTERN Window  win_c;
EXTERN Pixmap hourglass_pointer;


/* The OPER_REPAIR function is affected by the following variable.  It
 * controls whether repairs are made to all elements of a structure,
 * or to just the ones that are visible in the current context.  This
 * distinction is important when discriminated unions are involved.
 */
EXTERN UINT2 lrepair_only_visible_c ;

EXTERN UINT2 liris_setup_c; 
EXTERN struct full_time_spec setup_time_c;

#undef EXTERN


