iphreeqc/module_files.c
Scott R Charlton e180be69b0 Rearranging IPhreeqc
git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/trunk@4106 1feff8c3-07ed-0310-ac33-dd36852eb9cd
2010-02-23 05:04:35 +00:00

90 lines
1.6 KiB
C

#include "module_files.h"
#if defined(R_SO)
#include "phreeqc_files.inl"
#else
#include "phreeqcpp/phreeqc/phreeqc_files.c"
#endif
static int module_isopen_handler(const int type);
static int module_open_handler(const int type, const char *file_name);
int
module_handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args)
{
switch (action) {
case ACTION_OPEN:
return module_open_handler(type, err_str);
break;
case ACTION_ISOPEN:
return module_isopen_handler(type);
break;
default:
return phreeqc_handler(action, type, err_str, stop, cookie, format, args);
break;
}
return ERROR;
}
static int
module_isopen_handler(const int type)
{
switch (type)
{
case OUTPUT_PUNCH:
if (punch_file) return 1;
break;
default:
assert(0);
}
return 0;
}
static int
module_open_handler(const int type, const char *file_name)
{
assert(file_name && strlen(file_name));
switch (type)
{
case OUTPUT_MESSAGE:
if (output != NULL)
{
fclose(output);
output = NULL;
}
if ( (output = fopen(file_name, "w")) == NULL)
{
return ERROR;
}
break;
case OUTPUT_ERROR:
assert(error_file != stderr);
if (error_file != NULL)
{
fclose(error_file);
error_file = NULL;
}
if ( (error_file = fopen(file_name, "w")) == NULL)
{
return ERROR;
}
break;
case OUTPUT_LOG:
if (log_file != NULL)
{
fclose(log_file);
log_file = NULL;
}
if ( (log_file = fopen(file_name, "w")) == NULL)
{
return ERROR;
}
break;
default:
return open_handler(type, file_name);
break;
}
return(OK);
}