From efe04692ff6711c9fc9f71835decf6278a0b8269 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 19 Oct 2011 21:48:09 +0000 Subject: [PATCH] OUTPUT_SCREEN and OUTPUT_LOG are done. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5703 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_base.cxx | 2 - PHRQ_io.cpp | 154 ++++++++++++++++++++++++------------------------- PHRQ_io.h | 6 +- Phreeqc.h | 10 ++++ class_main.cpp | 26 ++++----- 5 files changed, 103 insertions(+), 95 deletions(-) diff --git a/PHRQ_base.cxx b/PHRQ_base.cxx index cb0b5ba5..4a973661 100644 --- a/PHRQ_base.cxx +++ b/PHRQ_base.cxx @@ -45,8 +45,6 @@ warning_msg(const std::string & stdstr) { if (this->io) { - //this->io->phreeqc_handler(PHRQ_io::ACTION_OUTPUT, PHRQ_io::OUTPUT_WARNING, stdstr.c_str(), false, "", NULL); - //this->io->output_string(PHRQ_io::OUTPUT_WARNING, stdstr); this->io->warning_msg(stdstr.c_str()); } else diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 261b6354..85554ce1 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -13,7 +13,7 @@ PHRQ_io(void) input_file = NULL; database_file = NULL; output_file = NULL; /* OUTPUT_MESSAGE */ - log_file = NULL; /* OUTPUT_LOG */ + log_file = NULL; punch_file = NULL; /* OUTPUT_PUNCH */ error_file = NULL; dump_file = NULL; @@ -85,9 +85,9 @@ output_open_temp(const char *file_name) safe_close(output_file); if ((output_file = fopen(file_name, "w")) == NULL) { - return true; // error + return false; // error } - return false; + return true; } /* ---------------------------------------------------------------------- */ void PHRQ_io:: @@ -147,9 +147,9 @@ log_open(const char *file_name) safe_close(log_file); if ((log_file = fopen(file_name, "w")) == NULL) { - return true; // error + return false; // error } - return false; + return true; } /* ---------------------------------------------------------------------- */ void PHRQ_io:: @@ -209,9 +209,9 @@ punch_open(const char *file_name) safe_close(punch_file); if ((punch_file = fopen(file_name, "w")) == NULL) { - return true; // error + return false; // error } - return false; + return true; } /* ---------------------------------------------------------------------- */ void PHRQ_io:: @@ -375,9 +375,9 @@ dump_open(const char *file_name) safe_close(dump_file); if ((dump_file = fopen(file_name, "w")) == NULL) { - return true; // error + return false; // error } - return false; + return true; } /* ---------------------------------------------------------------------- */ void PHRQ_io:: @@ -569,22 +569,22 @@ output_msg(int type, const char *format, va_list args) } } break; - case OUTPUT_LOG: - if (log_file != NULL && log_file_on) - { - vfprintf(log_file, format, args); - if (flush) - fflush(log_file); - } - break; - case OUTPUT_SCREEN: - if (error_file != NULL && error_file_on) - { - vfprintf(error_file, format, args); - if (flush) - fflush(error_file); - } - break; + //case OUTPUT_LOG: + // if (log_file != NULL && log_file_on) + // { + // vfprintf(log_file, format, args); + // if (flush) + // fflush(log_file); + // } + // break; + //case OUTPUT_SCREEN: + // if (error_file != NULL && error_file_on) + // { + // vfprintf(error_file, format, args); + // if (flush) + // fflush(error_file); + // } + // break; //case OUTPUT_DUMP: // if (dump_file != NULL && dump_file_on) @@ -661,19 +661,19 @@ output_string(const int type, std::string str) fprintf(punch_file, "%s", str.c_str()); } break; - case OUTPUT_LOG: - if (log_file != NULL && log_file_on) - { - fprintf(log_file, "%s", str.c_str()); - } - break; - case OUTPUT_SCREEN: - if (error_file != NULL && error_file_on) - { - fprintf(error_file, "%s", str.c_str()); - fflush(error_file); - } - break; + //case OUTPUT_LOG: + // if (log_file != NULL && log_file_on) + // { + // fprintf(log_file, "%s", str.c_str()); + // } + // break; + //case OUTPUT_SCREEN: + // if (error_file != NULL && error_file_on) + // { + // fprintf(error_file, "%s", str.c_str()); + // fflush(error_file); + // } + // break; //case OUTPUT_DUMP: // if (dump_file != NULL && dump_file_on) @@ -772,17 +772,17 @@ output_open(int type, const char *file_name) // error_file = stderr; // } // break; - case OUTPUT_LOG: - if (log_file != NULL) - { - safe_close(log_file); - log_file = NULL; - } - if ((log_file = fopen(file_name, "w")) == NULL) - { - return 0; - } - break; + //case OUTPUT_LOG: + // if (log_file != NULL) + // { + // safe_close(log_file); + // log_file = NULL; + // } + // if ((log_file = fopen(file_name, "w")) == NULL) + // { + // return 0; + // } + // break; default: assert(false); } @@ -808,12 +808,12 @@ output_isopen(const int type) case OUTPUT_PUNCH: return (punch_file != NULL); break; - case OUTPUT_SCREEN: - return (error_file != NULL); - break; - case OUTPUT_LOG: - return (log_file != NULL); - break; + //case OUTPUT_SCREEN: + // return (error_file != NULL); + // break; + //case OUTPUT_LOG: + // return (log_file != NULL); + // break; //case OUTPUT_DUMP: // return (dump_file != NULL); // break; @@ -855,15 +855,15 @@ output_fflush(const int type) fflush(punch_file); break; - case OUTPUT_SCREEN: - if (error_file) - fflush(error_file); - break; + //case OUTPUT_SCREEN: + // if (error_file) + // fflush(error_file); + // break; - case OUTPUT_LOG: - if (log_file) - fflush(log_file); - break; + //case OUTPUT_LOG: + // if (log_file) + // fflush(log_file); + // break; //case OUTPUT_DUMP: // if (dump_file) @@ -904,15 +904,15 @@ output_rewind(const int type) rewind(punch_file); break; - case OUTPUT_SCREEN: - if (error_file) - rewind(error_file); - break; + //case OUTPUT_SCREEN: + // if (error_file) + // rewind(error_file); + // break; - case OUTPUT_LOG: - if (log_file) - rewind(log_file); - break; + //case OUTPUT_LOG: + // if (log_file) + // rewind(log_file); + // break; //case OUTPUT_DUMP: // if (dump_file) @@ -948,13 +948,13 @@ output_close(const int type) safe_close(punch_file); break; - case OUTPUT_SCREEN: - safe_close(error_file); - break; + //case OUTPUT_SCREEN: + // safe_close(error_file); + // break; - case OUTPUT_LOG: - safe_close(log_file); - break; + //case OUTPUT_LOG: + // safe_close(log_file); + // break; //case OUTPUT_DUMP: // safe_close(dump_file); diff --git a/PHRQ_io.h b/PHRQ_io.h index e8f5c83e..7591adda 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -14,8 +14,8 @@ typedef enum //OUTPUT_WARNING, OUTPUT_MESSAGE, OUTPUT_PUNCH, - OUTPUT_SCREEN, - OUTPUT_LOG, + //OUTPUT_SCREEN, + //OUTPUT_LOG, OUTPUT_CHECKLINE, OUTPUT_GUI_ERROR, //OUTPUT_DUMP, @@ -123,7 +123,7 @@ protected: FILE *input_file; FILE *database_file; FILE *output_file; /* OUTPUT_MESSAGE */ - FILE *log_file; /* OUTPUT_LOG */ + FILE *log_file; FILE *punch_file; /* OUTPUT_PUNCH */ FILE *error_file; FILE *dump_file; diff --git a/Phreeqc.h b/Phreeqc.h index 2331be91..12deb808 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -281,6 +281,8 @@ int process_file_names(int argc, char *argv[], void **db_cookie, void **input_cookie, int log); /* PHRQ_io_output.cpp */ +void screen_msg(const char *err_str); + // dump_file bool dump_open(const char *file_name); void dump_fflush(void); @@ -289,6 +291,14 @@ void dump_rewind(void); bool dump_isopen(void); void dump_msg(const char * str); +// log_file +bool log_open(const char *file_name); +void log_fflush(void); +void log_close(void); +void log_rewind(void); +bool log_isopen(void); +void log_msg(const char * str); + // error_file bool error_open(const char *file_name); void error_fflush(void); diff --git a/class_main.cpp b/class_main.cpp index 5d69d605..e64a072b 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -186,38 +186,38 @@ write_banner(void) { char buffer[80]; int len, indent; - output_msg(OUTPUT_SCREEN, + screen_msg( " ÛßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßÛ\n"); - output_msg(OUTPUT_SCREEN, + screen_msg( " º º\n"); /* version */ len = sprintf(buffer, "* PHREEQC-%s *", "@VERSION@"); indent = (44 - len) / 2; - output_msg(OUTPUT_SCREEN, "%14cº%*c%s%*cº\n", ' ', indent, ' ', buffer, - 44 - indent - len, ' '); + screen_msg(sformatf("%14cº%*c%s%*cº\n", ' ', indent, ' ', buffer, + 44 - indent - len, ' ').c_str()); - output_msg(OUTPUT_SCREEN, + screen_msg( " º º\n"); - output_msg(OUTPUT_SCREEN, + screen_msg( " º A hydrogeochemical transport model º\n"); - output_msg(OUTPUT_SCREEN, + screen_msg( " º º\n"); - output_msg(OUTPUT_SCREEN, + screen_msg( " º by º\n"); - output_msg(OUTPUT_SCREEN, + screen_msg( " º D.L. Parkhurst and C.A.J. Appelo º\n"); - output_msg(OUTPUT_SCREEN, + screen_msg( " º º\n"); /* date */ len = sprintf(buffer, "%s", "@VER_DATE@"); indent = (44 - len) / 2; - output_msg(OUTPUT_SCREEN, "%14cº%*c%s%*cº\n", ' ', indent, ' ', buffer, - 44 - indent - len, ' '); + screen_msg(sformatf("%14cº%*c%s%*cº\n", ' ', indent, ' ', buffer, + 44 - indent - len, ' ').c_str()); - output_msg(OUTPUT_SCREEN, + screen_msg( " ÛÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÛ\n\n"); return 0;