//  ERRMSG.C
//  Miscellaneous error messages
//  © 2021 Peter J. Meyer

#include "iss.h"

//  Error codes from ARRAYS.H

#define NO_ERROR                     0
#define ZERO_ARRAY_SIZE             -5      
#define ZERO_ELEMENT_SIZE           -6
#define INVALID_DIMENSIONALITY     -11
#define NULL_POINTER               -14
#define INSUFFICIENT_MEMORY        -15
#define REQUEST_EXCEEDS_60MB       -16     
#define SIZE_NOT_MULT_4            -29

static char *array_name[] = { "sites", "bonds", "v_bonds", 
    "initial_sites", "cluster_numbers", "spin_distances", "precomp_nn_sites" };

void query_re_display_input_data_format(void);

/*--------------------------------------*/
void missing_code(char *file, int linenum)
{
printf("\nCode for %dd case missing in file %s at line %d.\n",
    dimensionality,file,linenum);
exit(1);
}

/*--------------------------------------------*/
void display_file_error_message(char *operation, 
                                char *file_type, 
                                char *filename)
{
printf("\nCannot %s %s file %s.\n",operation,file_type,filename);
exit(1);
}


/*------------------------------------------*/
void display_input_data_error(char *parameter)
{
printf("\nError in specification of %s in input file %s.\n",parameter,input_filepath);
query_re_display_input_data_format();
}

/*----------------------------------------------*/
void display_missing_data_message(char *parameter)
{
printf("\nIn input data file %s, %s is not specified.\n",input_filepath,parameter);
query_re_display_input_data_format();
}

/*-----------------------------------------*/
void query_re_display_input_data_format(void)
{
int ch;

printf("\nPress spacebar for input data format, Escape to quit.  ");
ch = getch();
printf("\n");
if ( ch == SPACE )
    display_input_data_format();        //  Does not return;
exit(1);
}

/*------------------------------------------*/
void display_array_allocation_error(int errno, 
                                    int err_flag)
{
printf("\nError %d when allocating %dd array %s%d (size = %d).",
    err_flag,dimensionality,array_name[errno],dimensionality,size);

switch ( err_flag )
    {
    case ZERO_ARRAY_SIZE:
    printf("\nZero array size.\n");
    break;
     
    case ZERO_ELEMENT_SIZE:
    printf("\nZero element size.\n");
    break;
     
    case INVALID_DIMENSIONALITY:
    printf("\nInvalid dimensionality.\n");
    break;
     
    case NULL_POINTER:
    printf("\nNull pointer.\n");
    break;
     
    case INSUFFICIENT_MEMORY:
    printf("\nInsufficient memory.\n");
    break;
     
    case REQUEST_EXCEEDS_60MB:
    printf("\nRequest exceeds 60MB.\n");
    break;
     
    case SIZE_NOT_MULT_4:
    printf("\nSize not a multiple of 4.\n");
    break;
     
    default:
    printf("\nUnknown error.\n");
    }

exit(1);
}

/*------------------------------------*/
void display_array_free_error(int errno)
{
printf("\nError when freeing array %s%d.\n",array_name[errno],dimensionality);
}