/*====================================================================*\
FILE	: TestRunMode.c
PURPOSE	: Utilities for determining the current run mode of regression tests.

HISTORY..
DATE		AUTHOR		MODIFICATIONS
25 Jan 96	Alistair	$$1 Based on Pro/DEVELOP equivalent.
04 Mar 96	Michael		$$2 Added TestError.h include
06 Mar 96	Igor		$$3 Fix bug
04-Nov-97 H-03-29 Pavel         $$4 Added statisctic mode
20-Jan-98 H-03-37 aab           $$5 Fixed some bugs for c++ compiler
03-Jul-98 H-03-49 Misha         $$6 add UtilString.h
26-Nov-98 I-01-27 Pavel         $$7 Updated fro crash_rep mode
15-Dec-98 I-01-28 Pavel         $$8 Check R_PRODEV_REGRESS
\*====================================================================*/

/*--------------------------------------------------------------------*\
Pro/TOOLKIT includes
\*--------------------------------------------------------------------*/
#include        "ProToolkit.h"	 /* Needed for standard C includes */

/*--------------------------------------------------------------------*\
Application includes
\*--------------------------------------------------------------------*/
#include "TestError.h"
#include "UtilString.h"

#include <stdlib.h>

/*--------------------------------------------------------------------*\
Application global/external data
\*--------------------------------------------------------------------*/
static int user_run_mode = TEST_RUN_MODE_SILENT;/*  Initialize to be silent  */
static int user_is_run_mode_set = 0;		/*  Is the run mode set yet? */

/*====================================================================*\
    FUNCTION :	ProTestRunmodeGet()
    PURPOSE  :	To check status of user_run_mode
	Determined by the value of the environment variable
	"PROTOOL_DEBUG" :
	    "silent" or not set		- run silently (take no action
					    over error statuses)
	    "crash"			- report error in log file,
					    then crash
	    "stat"                      - statistic
	    "report" or any other value	- report error only
\*====================================================================*/
int ProTestRunmodeGet()
{
    char *p_env;

/*--------------------------------------------------------------------*\
    If the run mode is already set,  just return it
\*--------------------------------------------------------------------*/
    if(user_is_run_mode_set)
	return(user_run_mode);

/*=====================================================================*\
|   Check for "R_PRODEV_REGRESS", to run from auto
\*=====================================================================*/
    if( (p_env = getenv("R_PRODEV_REGRESS")) != NULL)
    {	/*  Check for regression mode  */
        if(!strcmp(p_env,"no_crash"))
            /*  Report errors, no abort  */
	    user_run_mode = TEST_RUN_MODE_REPORT;	
	else
	    user_run_mode = TEST_RUN_MODE_CRASH;
    } 
    else 
    {
/*--------------------------------------------------------------------*\
    Read the value of PROTOOL_DEBUG
\*--------------------------------------------------------------------*/
        p_env = getenv("PROTOOL_DEBUG");

/*--------------------------------------------------------------------*\
    Is it SILENT?
\*--------------------------------------------------------------------*/
        if(p_env == NULL ||
        !ProUtilStrcmp(p_env, "silent"))
        {
	    user_run_mode = TEST_RUN_MODE_SILENT;
	    printf("\n   Pro/TOOLKIT Run Mode SILENT\n\n");
        }
/*--------------------------------------------------------------------*\
    Are we to CRASH?
\*--------------------------------------------------------------------*/
        else if(!ProUtilStrcmp(p_env, "crash"))
        {
	    user_run_mode = TEST_RUN_MODE_CRASH;
	    printf("\n   Pro/TOOLKIT Run Mode CRASH\n\n");
        }
/*--------------------------------------------------------------------*\
    Are we to statistic ?
\*--------------------------------------------------------------------*/
        else if (!ProUtilStrcmp(p_env, "stat"))
        {
            user_run_mode = TEST_RUN_MODE_STAT;
            printf ("\n   Pro/TOOLKIT Run Mode STATISTIC\n\n");
        }
/*--------------------------------------------------------------------*\
    Are we to potential crash report only ?
\*--------------------------------------------------------------------*/
        else if (!ProUtilStrcmp(p_env, "crash_rep"))
        {
            user_run_mode = TEST_RUN_MODE_CRASH_REP;
            printf ("\n   Pro/TOOLKIT Run Mode CRASH_REPORT\n\n");
        }
/*--------------------------------------------------------------------*\
    Then just REPORT.
\*--------------------------------------------------------------------*/
        else
        {
	    user_run_mode = TEST_RUN_MODE_REPORT;
	    printf("\n   Pro/TOOLKIT Run Mode REPORT\n\n");
        }
    }
/*--------------------------------------------------------------------*\
    Run mode is now set
\*--------------------------------------------------------------------*/
    user_is_run_mode_set = 1;

/*--------------------------------------------------------------------*\
    Return run mode
\*--------------------------------------------------------------------*/
    return(user_run_mode);
}
