added const qualifier for all the parsing

This commit is contained in:
David Parkhurst 2021-03-26 15:16:04 -06:00
parent 380a6eaf06
commit c748922b5e
22 changed files with 831 additions and 853 deletions

View File

@ -1472,7 +1472,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc)
for (int i = 0; i < (int)pSrc->elements.size(); i++) for (int i = 0; i < (int)pSrc->elements.size(); i++)
{ {
const char * ptr = string_hsave(pSrc->elements[i]->name); const char* ptr = string_hsave(pSrc->elements[i]->name);
struct element *elt_ptr = element_store(ptr); struct element *elt_ptr = element_store(ptr);
elt_ptr->gfw = pSrc->elements[i]->gfw; elt_ptr->gfw = pSrc->elements[i]->gfw;
} }
@ -1561,7 +1561,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc)
count_elts = 0; count_elts = 0;
paren_count = 0; paren_count = 0;
char * string = string_duplicate(s_ptr->mole_balance); char * string = string_duplicate(s_ptr->mole_balance);
char * ptr = string; const char* ptr = string;
get_secondary_in_species(&ptr, 1.0); get_secondary_in_species(&ptr, 1.0);
s_ptr->next_secondary = elt_list_save(); s_ptr->next_secondary = elt_list_save();
free_check_null(string); free_check_null(string);

View File

@ -560,7 +560,7 @@ public:
int clear(void); int clear(void);
int convert_units(cxxSolution* solution_ptr); int convert_units(cxxSolution* solution_ptr);
struct unknown* find_surface_charge_unknown(std::string& str_ptr, int plane); struct unknown* find_surface_charge_unknown(std::string& str_ptr, int plane);
std::vector<struct master*> get_list_master_ptrs(const char* ptr, struct master* master_ptr); std::vector<struct master*> get_list_master_ptrs(const char* cptr, struct master* master_ptr);
int inout(void); int inout(void);
int is_special(struct species* spec); int is_special(struct species* spec);
int mb_for_species_aq(int n); int mb_for_species_aq(int n);
@ -606,7 +606,7 @@ public:
int write_phase_sys_total(int n); int write_phase_sys_total(int n);
// print.cpp ------------------------------- // print.cpp -------------------------------
static char* sformatf(const char* format, ...); char* sformatf(const char* format, ...);
int array_print(LDBLE* array_l, int row_count, int column_count, int array_print(LDBLE* array_l, int row_count, int column_count,
int max_column_count); int max_column_count);
int set_pr_in_false(void); int set_pr_in_false(void);
@ -649,11 +649,11 @@ public:
int read_input(void); int read_input(void);
int* read_list_ints_range(const char** ptr, int* count_ints, int positive, int* read_list_ints_range(const char** ptr, int* count_ints, int positive,
int* int_list); int* int_list);
int read_log_k_only(const char* ptr, LDBLE* log_k); int read_log_k_only(const char* cptr, LDBLE* log_k);
int read_t_c_only(const char* ptr, LDBLE* t_c); int read_t_c_only(const char* cptr, LDBLE* t_c);
int read_p_c_only(const char* ptr, LDBLE* p_c); int read_p_c_only(const char* cptr, LDBLE* p_c);
int read_omega_only(const char* ptr, LDBLE* omega); int read_omega_only(const char* cptr, LDBLE* omega);
int read_number_description(const char* ptr, int* n_user, int* n_user_end, int read_number_description(const char* cptr, int* n_user, int* n_user_end,
char** description, int allow_negative = FALSE); char** description, int allow_negative = FALSE);
int check_key(const char* str); int check_key(const char* str);
int check_units(std::string& tot_units, bool alkalinity, bool check_compatibility, int check_units(std::string& tot_units, bool alkalinity, bool check_compatibility,
@ -665,19 +665,19 @@ public:
int add_psi_master_species(char* token); int add_psi_master_species(char* token);
int read_advection(void); int read_advection(void);
int read_analytical_expression_only(const char* ptr, LDBLE* log_k); int read_analytical_expression_only(const char* cptr, LDBLE* log_k);
/* VP: Density Start */ /* VP: Density Start */
int read_millero_abcdef(const char* ptr, LDBLE* abcdef); int read_millero_abcdef(const char* cptr, LDBLE* abcdef);
/* VP: Density End */ /* VP: Density End */
int read_viscosity_parms(const char* ptr, LDBLE* Jones_Dole); int read_viscosity_parms(const char* cptr, LDBLE* Jones_Dole);
int read_copy(void); int read_copy(void);
int read_debug(void); int read_debug(void);
int read_delta_h_only(const char* ptr, LDBLE* delta_h, int read_delta_h_only(const char* cptr, LDBLE* delta_h,
DELTA_H_UNIT* units); DELTA_H_UNIT* units);
int read_aq_species_vm_parms(const char* ptr, LDBLE* delta_v); int read_aq_species_vm_parms(const char* cptr, LDBLE* delta_v);
int read_vm_only(const char* ptr, LDBLE* delta_v, int read_vm_only(const char* cptr, LDBLE* delta_v,
DELTA_V_UNIT* units); DELTA_V_UNIT* units);
int read_phase_vm(const char* ptr, LDBLE* delta_v, int read_phase_vm(const char* cptr, LDBLE* delta_v,
DELTA_V_UNIT* units); DELTA_V_UNIT* units);
int read_llnl_aqueous_model_parameters(void); int read_llnl_aqueous_model_parameters(void);
int read_exchange(void); int read_exchange(void);
@ -687,7 +687,7 @@ public:
int read_incremental_reactions(void); int read_incremental_reactions(void);
int read_inverse(void); int read_inverse(void);
int read_inv_balances(struct inverse* inverse_ptr, const char* next_char); int read_inv_balances(struct inverse* inverse_ptr, const char* next_char);
int read_inv_isotopes(struct inverse* inverse_ptr, const char* ptr); int read_inv_isotopes(struct inverse* inverse_ptr, const char* cptr);
int read_inv_phases(struct inverse* inverse_ptr, const char* next_char); int read_inv_phases(struct inverse* inverse_ptr, const char* next_char);
int read_kinetics(void); int read_kinetics(void);
LDBLE* read_list_doubles(const char** ptr, int* count_doubles); LDBLE* read_list_doubles(const char** ptr, int* count_doubles);
@ -841,12 +841,12 @@ protected:
struct logk* logk_search(const char* name); struct logk* logk_search(const char* name);
struct master* master_alloc(void); struct master* master_alloc(void);
static int master_compare(const void* ptr1, const void* ptr2); static int master_compare(const void* ptr1, const void* ptr2);
int master_delete(const char* ptr); int master_delete(const char* cptr);
public: public:
struct master* master_bsearch(const char* ptr); struct master* master_bsearch(const char* cptr);
struct master* master_bsearch_primary(const char* ptr); struct master* master_bsearch_primary(const char* cptr);
struct master* master_bsearch_secondary(const char* ptr); struct master* master_bsearch_secondary(const char* cptr);
struct master* master_search(const char* ptr, int* n); struct master* master_search(const char* cptr, int* n);
struct pe_data* pe_data_alloc(void); struct pe_data* pe_data_alloc(void);
public: public:
struct pe_data* pe_data_dup(struct pe_data* pe_ptr_old); struct pe_data* pe_data_dup(struct pe_data* pe_ptr_old);
@ -854,13 +854,13 @@ public:
protected: protected:
int pe_data_store(struct pe_data** pe, const char* token); int pe_data_store(struct pe_data** pe, const char* token);
public: public:
struct phase* phase_bsearch(const char* ptr, int* j, int print); struct phase* phase_bsearch(const char* cptr, int* j, int print);
protected: protected:
static int phase_compare(const void* ptr1, const void* ptr2); static int phase_compare(const void* ptr1, const void* ptr2);
int phase_delete(int i); int phase_delete(int i);
struct phase* phase_store(const char* name); struct phase* phase_store(const char* name);
public: public:
struct rate* rate_bsearch(const char* ptr, int* j); struct rate* rate_bsearch(const char* cptr, int* j);
int rate_free(struct rate* rate_ptr); int rate_free(struct rate* rate_ptr);
struct rate* rate_copy(struct rate* rate_ptr); struct rate* rate_copy(struct rate* rate_ptr);
struct rate* rate_search(const char* name, int* n); struct rate* rate_search(const char* name, int* n);
@ -1054,7 +1054,7 @@ public:
#endif #endif
int copy_token(char* token_ptr, const char** ptr, int* length); int copy_token(char* token_ptr, const char** ptr, int* length);
int copy_token(std::string& token, const char** ptr); int copy_token(std::string& token, const char** ptr);
int dup_print(const char* ptr, int emphasis); int dup_print(const char* cptr, int emphasis);
int equal(LDBLE a, LDBLE b, LDBLE eps); int equal(LDBLE a, LDBLE b, LDBLE eps);
public: public:
void* free_check_null(void* ptr); void* free_check_null(void* ptr);
@ -1068,6 +1068,7 @@ protected:
int print_centered(const char* string); int print_centered(const char* string);
public: public:
static int replace(const char* str1, const char* str2, char* str); static int replace(const char* str1, const char* str2, char* str);
static void replace(std::string &stds, const char* str1, const char* str2);
static bool replace(const char* str1, const char* str2, std::string& str); static bool replace(const char* str1, const char* str2, std::string& str);
static int strcmp_nocase(const char* str1, const char* str2); static int strcmp_nocase(const char* str1, const char* str2);
static int strcmp_nocase_arg1(const char* str1, const char* str2); static int strcmp_nocase_arg1(const char* str1, const char* str2);
@ -1088,9 +1089,12 @@ public:
void strings_map_clear(); void strings_map_clear();
protected: protected:
char* string_pad(const char* str, int i); char* string_pad(const char* str, int i);
int string_trim(char* str); static int string_trim(char* str);
int string_trim_right(char* str); static int string_trim_right(char* str);
int string_trim_left(char* str); static int string_trim_left(char* str);
static void string_trim(std::string& str);
static void string_trim_left(std::string& str);
static void string_trim_right(std::string& str);
static LDBLE under(LDBLE xval); static LDBLE under(LDBLE xval);
int get_input_errors(void); int get_input_errors(void);
int isamong(char c, const char* s_l); int isamong(char c, const char* s_l);

View File

@ -814,7 +814,7 @@ calc_surface_charge(const char *surface_name)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
{ {
char token[MAX_LENGTH], token1[MAX_LENGTH]; char token[MAX_LENGTH], token1[MAX_LENGTH];
char *ptr; const char* cptr;
int i, j, k; int i, j, k;
LDBLE charge; LDBLE charge;
struct rxn_token_temp *token_ptr; struct rxn_token_temp *token_ptr;
@ -840,8 +840,8 @@ calc_surface_charge(const char *surface_name)
master_ptr = trxn.token[i].s->primary; master_ptr = trxn.token[i].s->primary;
strcpy(token, master_ptr->elt->name); strcpy(token, master_ptr->elt->name);
replace("_", " ", token); replace("_", " ", token);
ptr = token; cptr = token;
copy_token(token1, &ptr, &j); copy_token(token1, &cptr, &j);
if (strcmp(surface_name, token1) == 0) if (strcmp(surface_name, token1) == 0)
{ {
charge += s_x[k]->moles * s_x[k]->z; charge += s_x[k]->moles * s_x[k]->z;
@ -1966,7 +1966,7 @@ match_elts_in_species(const char *name, const char *mytemplate)
*/ */
int i, i1, l, case_no, match; int i, i1, l, case_no, match;
char c, c1; char c, c1;
char *ptr, *ptr1; const char* cptr, *ptr1;
LDBLE d; LDBLE d;
char element[MAX_LENGTH]; char element[MAX_LENGTH];
char token[MAX_LENGTH], equal_list[MAX_LENGTH]; char token[MAX_LENGTH], equal_list[MAX_LENGTH];
@ -1993,11 +1993,11 @@ match_elts_in_species(const char *name, const char *mytemplate)
replace("--", "-2", token); replace("--", "-2", token);
} }
ptr = token; cptr = token;
std::vector< std::pair<std::string, LDBLE> > match_vector; std::vector< std::pair<std::string, LDBLE> > match_vector;
while ((c = *ptr) != '\0') while ((c = *cptr) != '\0')
{ {
c1 = *(ptr + 1); c1 = *(cptr + 1);
str[0] = c; str[0] = c;
str[1] = '\0'; str[1] = '\0';
/* /*
@ -2008,11 +2008,11 @@ match_elts_in_species(const char *name, const char *mytemplate)
/* /*
* Get new element and subscript * Get new element and subscript
*/ */
if (get_elt(&ptr, element, &l) == ERROR) if (get_elt(&cptr, element, &l) == ERROR)
{ {
return (ERROR); return (ERROR);
} }
if (get_num(&ptr, &d) == ERROR) if (get_num(&cptr, &d) == ERROR)
{ {
return (ERROR); return (ERROR);
} }
@ -2023,7 +2023,7 @@ match_elts_in_species(const char *name, const char *mytemplate)
{ {
std::pair<std::string, LDBLE> pr(str, 1.0); std::pair<std::string, LDBLE> pr(str, 1.0);
match_vector.push_back(pr); match_vector.push_back(pr);
ptr += 1; cptr += 1;
} }
} }
/* /*
@ -2031,8 +2031,8 @@ match_elts_in_species(const char *name, const char *mytemplate)
*/ */
strcpy(template1, mytemplate); strcpy(template1, mytemplate);
squeeze_white(template1); squeeze_white(template1);
ptr = template1; cptr = template1;
while (extract_bracket(&ptr, equal_list) == TRUE) while (extract_bracket(&cptr, equal_list) == TRUE)
{ {
replace("{", "", equal_list); replace("{", "", equal_list);
replace("}", "", equal_list); replace("}", "", equal_list);
@ -2102,8 +2102,8 @@ match_elts_in_species(const char *name, const char *mytemplate)
*/ */
strcpy(template1, mytemplate); strcpy(template1, mytemplate);
squeeze_white(template1); squeeze_white(template1);
ptr = template1; cptr = template1;
while (extract_bracket(&ptr, equal_list) == TRUE) while (extract_bracket(&cptr, equal_list) == TRUE)
{ {
strcpy(equal_list1, equal_list); strcpy(equal_list1, equal_list);
replace("{", "", equal_list); replace("{", "", equal_list);
@ -2124,7 +2124,7 @@ match_elts_in_species(const char *name, const char *mytemplate)
} }
replace(equal_list1, elt_name.c_str(), template1); replace(equal_list1, elt_name.c_str(), template1);
squeeze_white(template1); squeeze_white(template1);
ptr = template1; cptr = template1;
} }
/* /*
* Compare string * Compare string
@ -2160,13 +2160,13 @@ match_elts_in_species(const char *name, const char *mytemplate)
break; break;
case 1: case 1:
/* leading wild card */ /* leading wild card */
if ((ptr = strstr(token, template1)) == NULL) if ((cptr = strstr(token, template1)) == NULL)
{ {
match = FALSE; match = FALSE;
} }
else else
{ {
if (strcmp(ptr, template1) == 0) if (strcmp(cptr, template1) == 0)
match = TRUE; match = TRUE;
} }
break; break;
@ -2186,14 +2186,15 @@ match_elts_in_species(const char *name, const char *mytemplate)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
int Phreeqc:: int Phreeqc::
extract_bracket(char **string, char *bracket_string) extract_bracket(const char **string, char *bracket_string)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
{ {
char *ptr, *ptr1; const char* cptr;
char *ptr1;
if ((ptr = strstr(*string, "{")) == NULL) if ((cptr = strstr(*string, "{")) == NULL)
return (FALSE); return (FALSE);
strcpy(bracket_string, ptr); strcpy(bracket_string, cptr);
if ((ptr1 = strstr(bracket_string, "}")) == NULL) if ((ptr1 = strstr(bracket_string, "}")) == NULL)
{ {
error_string = sformatf( error_string = sformatf(
@ -2272,8 +2273,8 @@ surf_total(const char *total_name, const char *surface_name)
//strcpy(token, s_x[j]->next_elt[i].elt->name); //strcpy(token, s_x[j]->next_elt[i].elt->name);
//replace("_", " ", token); //replace("_", " ", token);
//ptr = token; //cptr = token;
//copy_token(name, &ptr, &k); //copy_token(name, &cptr, &k);
token = s_x[j]->next_elt[i].elt->name; token = s_x[j]->next_elt[i].elt->name;
replace("_", " ", token); replace("_", " ", token);
std::string::iterator b = token.begin(); std::string::iterator b = token.begin();
@ -2360,7 +2361,7 @@ surf_total_no_redox(const char *total_name, const char *surface_name)
int i, j, k; int i, j, k;
char name[MAX_LENGTH], token[MAX_LENGTH]; char name[MAX_LENGTH], token[MAX_LENGTH];
char surface_name_local[MAX_LENGTH]; char surface_name_local[MAX_LENGTH];
char *ptr; const char* cptr;
if (use.Get_surface_ptr() == NULL) if (use.Get_surface_ptr() == NULL)
return (0); return (0);
@ -2374,8 +2375,8 @@ surf_total_no_redox(const char *total_name, const char *surface_name)
continue; continue;
strcpy(token, x[j]->master[0]->elt->name); strcpy(token, x[j]->master[0]->elt->name);
replace("_", " ", token); replace("_", " ", token);
ptr = token; cptr = token;
copy_token(name, &ptr, &k); copy_token(name, &cptr, &k);
if (surface_name != NULL) if (surface_name != NULL)
{ {
if (strcmp(name, surface_name) == 0) if (strcmp(name, surface_name) == 0)
@ -2404,8 +2405,8 @@ surf_total_no_redox(const char *total_name, const char *surface_name)
strcpy(token, s_x[j]->next_elt[i].elt->name); strcpy(token, s_x[j]->next_elt[i].elt->name);
replace("_", " ", token); replace("_", " ", token);
ptr = token; cptr = token;
copy_token(name, &ptr, &k); copy_token(name, &cptr, &k);
if (strcmp(name, surface_name_local) == 0) if (strcmp(name, surface_name_local) == 0)
{ {
/* /*
@ -2821,8 +2822,8 @@ kinetics_formula(std::string kin_name, cxxNameDouble &stoichiometry)
std::string name = it->first; std::string name = it->first;
LDBLE coef = it->second; LDBLE coef = it->second;
char * temp_name = string_duplicate(name.c_str()); char * temp_name = string_duplicate(name.c_str());
char *ptr = temp_name; const char* cptr = temp_name;
get_elts_in_species(&ptr, coef); get_elts_in_species(&cptr, coef);
free_check_null(temp_name); free_check_null(temp_name);
} }
} }

View File

@ -332,7 +332,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie,
char query[2 * MAX_LENGTH]; char query[2 * MAX_LENGTH];
char in_file[2 * MAX_LENGTH], out_file[2 * MAX_LENGTH], db_file[2 * MAX_LENGTH]; char in_file[2 * MAX_LENGTH], out_file[2 * MAX_LENGTH], db_file[2 * MAX_LENGTH];
char *env_ptr; char *env_ptr;
char *ptr; const char* cptr;
/* /*
* Prepare error handling * Prepare error handling
*/ */
@ -383,8 +383,8 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie,
* Open file for output * Open file for output
*/ */
strcpy(query, "Name of output file?"); strcpy(query, "Name of output file?");
ptr = default_name; cptr = default_name;
copy_token(token, &ptr, &l); copy_token(token, &cptr, &l);
strcpy(token, default_name); strcpy(token, default_name);
strcat(token, ".out"); strcat(token, ".out");
std::ofstream * local_output_stream = NULL; std::ofstream * local_output_stream = NULL;
@ -422,12 +422,12 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie,
phrq_io->push_istream(local_input_stream); phrq_io->push_istream(local_input_stream);
if (get_line() == KEYWORD) if (get_line() == KEYWORD)
{ {
ptr = line; cptr = line;
copy_token(token, &ptr, &l); copy_token(token, &cptr, &l);
if (strcmp_nocase(token, "database") == 0) if (strcmp_nocase(token, "database") == 0)
{ {
user_database = (char *) free_check_null(user_database); user_database = (char *) free_check_null(user_database);
user_database = string_duplicate(ptr); user_database = string_duplicate(cptr);
if (string_trim(user_database) == EMPTY) if (string_trim(user_database) == EMPTY)
{ {
warning_msg("DATABASE file name is missing; default database will be used."); warning_msg("DATABASE file name is missing; default database will be used.");
@ -529,7 +529,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie,
char query[2 * MAX_LENGTH]; char query[2 * MAX_LENGTH];
char in_file[2 * MAX_LENGTH], out_file[2 * MAX_LENGTH], db_file[2 * MAX_LENGTH]; char in_file[2 * MAX_LENGTH], out_file[2 * MAX_LENGTH], db_file[2 * MAX_LENGTH];
char *env_ptr; char *env_ptr;
char *ptr; const char* cptr;
/* /*
* Prepare error handling * Prepare error handling
*/ */
@ -580,8 +580,8 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie,
* Open file for output * Open file for output
*/ */
strcpy(query, "Name of output file?"); strcpy(query, "Name of output file?");
ptr = default_name; cptr = default_name;
copy_token(token, &ptr, &l); copy_token(token, &cptr, &l);
strcat(token, ".out"); strcat(token, ".out");
std::ofstream * local_output_stream; std::ofstream * local_output_stream;
if (argc <= 1) if (argc <= 1)
@ -618,12 +618,12 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie,
phrq_io->push_istream(local_input_stream); phrq_io->push_istream(local_input_stream);
if (get_line() == KEYWORD) if (get_line() == KEYWORD)
{ {
ptr = line; cptr = line;
copy_token(token, &ptr, &l); copy_token(token, &cptr, &l);
if (strcmp_nocase(token, "database") == 0) if (strcmp_nocase(token, "database") == 0)
{ {
user_database = (char *) free_check_null(user_database); user_database = (char *) free_check_null(user_database);
user_database = string_duplicate(ptr); user_database = string_duplicate(cptr);
if (string_trim(user_database) == EMPTY) if (string_trim(user_database) == EMPTY)
{ {
warning_msg("DATABASE file name is missing; default database will be used."); warning_msg("DATABASE file name is missing; default database will be used.");

View File

@ -4044,7 +4044,7 @@ dump_netpath(struct inverse *inverse_ptr)
{ {
int j; int j;
std::string string; std::string string;
char *ptr; const char* cptr;
if (inverse_ptr->netpath == NULL) if (inverse_ptr->netpath == NULL)
return; return;
@ -4079,8 +4079,8 @@ dump_netpath(struct inverse *inverse_ptr)
/* flags and description */ /* flags and description */
char * description = string_duplicate(it->second.Get_description().c_str()); char * description = string_duplicate(it->second.Get_description().c_str());
ptr = description; cptr = description;
j = copy_token(string, &ptr); j = copy_token(string, &cptr);
if (j != EMPTY) if (j != EMPTY)
{ {
string = sformatf("%s", description); string = sformatf("%s", description);
@ -4397,7 +4397,7 @@ dump_netpath_pat(struct inverse *inv_ptr)
cxxSolution *solution_ptr, *solution_ptr_orig; cxxSolution *solution_ptr, *solution_ptr_orig;
struct master *master_ptr; struct master *master_ptr;
LDBLE d1, d2, d3; LDBLE d1, d2, d3;
char *ptr; const char* cptr;
LDBLE sum, sum1, sum_iso, d; LDBLE sum, sum1, sum_iso, d;
std::vector<double> array_save, l_delta_save; std::vector<double> array_save, l_delta_save;
int count_unknowns_save, max_row_count_save, max_column_count_save, temp, int count_unknowns_save, max_row_count_save, max_column_count_save, temp,
@ -4517,9 +4517,9 @@ dump_netpath_pat(struct inverse *inv_ptr)
/* Header */ /* Header */
char * description = string_duplicate(solution_ptr_orig->Get_description().c_str()); char * description = string_duplicate(solution_ptr_orig->Get_description().c_str());
ptr = description; cptr = description;
std::string string; std::string string;
if (copy_token(string, &ptr) != EMPTY) if (copy_token(string, &cptr) != EMPTY)
{ {
fprintf(netpath_file, "%d. %s\n", count_inverse_models, fprintf(netpath_file, "%d. %s\n", count_inverse_models,
solution_ptr_orig->Get_description().c_str()); solution_ptr_orig->Get_description().c_str());

View File

@ -28,7 +28,7 @@ read_isotopes(void)
struct element *elt_ptr; struct element *elt_ptr;
int return_value, opt, opt_save; int return_value, opt, opt_save;
char *next_char; const char* next_char;
const char *opt_list[] = { const char *opt_list[] = {
"isotope", /* 0 */ "isotope", /* 0 */
"total_is_major" /* 1 */ "total_is_major" /* 1 */
@ -160,14 +160,14 @@ read_calculate_values(void)
* ERROR if error occurred reading data * ERROR if error occurred reading data
* *
*/ */
char *ptr; const char* cptr;
int l; int l;
int return_value, opt, opt_save; int return_value, opt, opt_save;
char token[MAX_LENGTH]; char token[MAX_LENGTH];
struct calculate_value *calculate_value_ptr; struct calculate_value *calculate_value_ptr;
char *description; char *description;
int n_user, n_user_end; int n_user, n_user_end;
char *next_char; const char* next_char;
const char *opt_list[] = { const char *opt_list[] = {
"start", /* 0 */ "start", /* 0 */
"end" /* 1 */ "end" /* 1 */
@ -176,8 +176,8 @@ read_calculate_values(void)
/* /*
* Read advection number (not currently used) * Read advection number (not currently used)
*/ */
ptr = line; cptr = line;
read_number_description(ptr, &n_user, &n_user_end, &description); read_number_description(cptr, &n_user, &n_user_end, &description);
description = (char *) free_check_null(description); description = (char *) free_check_null(description);
opt_save = OPTION_DEFAULT; opt_save = OPTION_DEFAULT;
/* /*
@ -276,14 +276,14 @@ read_isotope_ratios(void)
* ERROR if error occurred reading data * ERROR if error occurred reading data
* *
*/ */
char *ptr; const char* cptr;
int l; int l;
int return_value, opt, opt_save; int return_value, opt, opt_save;
char token[MAX_LENGTH]; char token[MAX_LENGTH];
struct isotope_ratio *isotope_ratio_ptr; struct isotope_ratio *isotope_ratio_ptr;
char *description; char *description;
int n_user, n_user_end; int n_user, n_user_end;
char *next_char; const char* next_char;
const char *opt_list[] = { const char *opt_list[] = {
"no_options" /* 0 */ "no_options" /* 0 */
}; };
@ -291,8 +291,8 @@ read_isotope_ratios(void)
/* /*
* Read number (not currently used) * Read number (not currently used)
*/ */
ptr = line; cptr = line;
read_number_description(ptr, &n_user, &n_user_end, &description); read_number_description(cptr, &n_user, &n_user_end, &description);
description = (char *) free_check_null(description); description = (char *) free_check_null(description);
opt_save = OPTION_DEFAULT; opt_save = OPTION_DEFAULT;
/* /*
@ -375,14 +375,14 @@ read_isotope_alphas(void)
* ERROR if error occurred reading data * ERROR if error occurred reading data
* *
*/ */
char *ptr; const char* cptr;
int l; int l;
int return_value, opt, opt_save; int return_value, opt, opt_save;
char token[MAX_LENGTH]; char token[MAX_LENGTH];
struct isotope_alpha *isotope_alpha_ptr; struct isotope_alpha *isotope_alpha_ptr;
char *description; char *description;
int n_user, n_user_end; int n_user, n_user_end;
char *next_char; const char* next_char;
const char *opt_list[] = { const char *opt_list[] = {
"no_options" /* 0 */ "no_options" /* 0 */
}; };
@ -390,8 +390,8 @@ read_isotope_alphas(void)
/* /*
* Read number (not currently used) * Read number (not currently used)
*/ */
ptr = line; cptr = line;
read_number_description(ptr, &n_user, &n_user_end, &description); read_number_description(cptr, &n_user, &n_user_end, &description);
description = (char *) free_check_null(description); description = (char *) free_check_null(description);
opt_save = OPTION_DEFAULT; opt_save = OPTION_DEFAULT;
/* /*

View File

@ -187,7 +187,7 @@ RESTART: // if limiting rates, jump to here
else else
{ {
char * temp_name = string_duplicate(name.c_str()); char * temp_name = string_duplicate(name.c_str());
char * ptr = temp_name; const char* ptr = temp_name;
if (get_elts_in_species(&ptr, coef * coef1) == ERROR) if (get_elts_in_species(&ptr, coef * coef1) == ERROR)
{ {
error_string = sformatf("Error in -formula: %s", temp_name); error_string = sformatf("Error in -formula: %s", temp_name);
@ -211,7 +211,7 @@ RESTART: // if limiting rates, jump to here
{ {
/* found kinetics component */ /* found kinetics component */
char * formula = string_duplicate(exchange_ptr->Get_exchange_comps()[j].Get_formula().c_str()); char * formula = string_duplicate(exchange_ptr->Get_exchange_comps()[j].Get_formula().c_str());
char * ptr = formula; const char* ptr = formula;
if (get_elts_in_species(&ptr, -coef*exchange_ptr->Get_exchange_comps()[j].Get_phase_proportion()) == ERROR) if (get_elts_in_species(&ptr, -coef*exchange_ptr->Get_exchange_comps()[j].Get_phase_proportion()) == ERROR)
{ {
error_string = sformatf("Error in -formula: %s", formula); error_string = sformatf("Error in -formula: %s", formula);
@ -236,7 +236,7 @@ RESTART: // if limiting rates, jump to here
{ {
/* found kinetics component */ /* found kinetics component */
char * temp_formula = string_duplicate(surface_comp_ptr->Get_formula().c_str()); char * temp_formula = string_duplicate(surface_comp_ptr->Get_formula().c_str());
char *ptr = temp_formula; const char* cptr = temp_formula;
/* Surface = 0 when m becomes low ... /* Surface = 0 when m becomes low ...
*/ */
if (0.9 * surface_comp_ptr->Get_phase_proportion() * if (0.9 * surface_comp_ptr->Get_phase_proportion() *
@ -251,7 +251,7 @@ RESTART: // if limiting rates, jump to here
} }
else else
{ {
if (get_elts_in_species(&ptr, -coef * surface_comp_ptr->Get_phase_proportion()) == ERROR) if (get_elts_in_species(&cptr, -coef * surface_comp_ptr->Get_phase_proportion()) == ERROR)
{ {
error_string = sformatf("Error in -formula: %s", temp_formula); error_string = sformatf("Error in -formula: %s", temp_formula);
error_msg(error_string, CONTINUE); error_msg(error_string, CONTINUE);

View File

@ -2233,8 +2233,11 @@ do_status(void)
} }
//pr.headings = TRUE; // set in class_main; not set for IPhreeqc //pr.headings = TRUE; // set in class_main; not set for IPhreeqc
LDBLE ext = (double) clock() / CLOCKS_PER_SEC; LDBLE ext = (double) clock() / CLOCKS_PER_SEC;
#define TESTING
#ifndef TESTING
dup_print(sformatf("End of Run after %g Seconds.", ext), TRUE); dup_print(sformatf("End of Run after %g Seconds.", ext), TRUE);
screen_msg(sformatf("\nEnd of Run after %g Seconds.\n", ext)); screen_msg(sformatf("\nEnd of Run after %g Seconds.\n", ext));
#endif
// appt this gives output when the charts are active... // appt this gives output when the charts are active...
phrq_io->output_flush(); phrq_io->output_flush();
phrq_io->error_flush(); phrq_io->error_flush();

View File

@ -26,7 +26,7 @@ parse_eq(char *eqn, struct elt_list **elt_ptr, int association)
int i; int i;
LDBLE coef, l_z; LDBLE coef, l_z;
char c; char c;
char *ptr; const char* cptr;
char token[MAX_LENGTH]; char token[MAX_LENGTH];
paren_count = 0; paren_count = 0;
@ -53,8 +53,8 @@ parse_eq(char *eqn, struct elt_list **elt_ptr, int association)
*/ */
count_trxn = 0; count_trxn = 0;
trxn.dz[0] = trxn.dz[1] = trxn.dz[2] = 0.0; trxn.dz[0] = trxn.dz[1] = trxn.dz[2] = 0.0;
ptr = eqn; cptr = eqn;
c = ptr[0]; c = cptr[0];
for (;;) for (;;)
{ {
if (c == '=') if (c == '=')
@ -65,11 +65,11 @@ parse_eq(char *eqn, struct elt_list **elt_ptr, int association)
error_msg(error_string, CONTINUE); error_msg(error_string, CONTINUE);
return (ERROR); return (ERROR);
} }
if (get_species(&ptr) == ERROR) if (get_species(&cptr) == ERROR)
{ {
return (ERROR); return (ERROR);
} }
c = ptr[0]; c = cptr[0];
if (association == FALSE) if (association == FALSE)
{ {
trxn.token[count_trxn].coef *= -1.0; trxn.token[count_trxn].coef *= -1.0;
@ -79,10 +79,10 @@ parse_eq(char *eqn, struct elt_list **elt_ptr, int association)
/* /*
* Get coefficient, name, and charge of species for dissociation reaction * Get coefficient, name, and charge of species for dissociation reaction
*/ */
ptr++; cptr++;
if (association == TRUE) if (association == TRUE)
{ {
if (get_species(&ptr) == ERROR) if (get_species(&cptr) == ERROR)
{ {
return (ERROR); return (ERROR);
} }
@ -102,16 +102,16 @@ parse_eq(char *eqn, struct elt_list **elt_ptr, int association)
/* /*
* Get reaction species from rhs of equation * Get reaction species from rhs of equation
*/ */
c = ptr[0]; c = cptr[0];
for (;;) for (;;)
{ {
if (c == '\0') if (c == '\0')
break; break;
if (get_species(&ptr) == ERROR) if (get_species(&cptr) == ERROR)
{ {
return (ERROR); return (ERROR);
} }
c = ptr[0]; c = cptr[0];
if (association == TRUE) if (association == TRUE)
{ {
trxn.token[count_trxn].coef *= -1.0; trxn.token[count_trxn].coef *= -1.0;
@ -131,7 +131,7 @@ parse_eq(char *eqn, struct elt_list **elt_ptr, int association)
replace("(S)", "", token); replace("(S)", "", token);
replace("(g)", "", token); replace("(g)", "", token);
replace("(G)", "", token); replace("(G)", "", token);
char *char_ptr = token; const char *char_ptr = token;
if (get_elts_in_species(&char_ptr, trxn.token[0].coef) == ERROR) if (get_elts_in_species(&char_ptr, trxn.token[0].coef) == ERROR)
{ {
@ -214,7 +214,7 @@ check_eqn(int association)
{ {
sumcharge += (trxn.token[i].coef) * (trxn.token[i].z); sumcharge += (trxn.token[i].coef) * (trxn.token[i].z);
char * temp_name = string_duplicate(trxn.token[i].name); char * temp_name = string_duplicate(trxn.token[i].name);
char *t_ptr = temp_name; const char *t_ptr = temp_name;
if (get_elts_in_species(&t_ptr, trxn.token[i].coef) == ERROR) if (get_elts_in_species(&t_ptr, trxn.token[i].coef) == ERROR)
{ {
free_check_null(temp_name); free_check_null(temp_name);
@ -283,7 +283,7 @@ get_charge(char *charge, LDBLE * l_z)
*/ */
{ {
int i; int i;
char *ptr; char* ptr;
char c, c1; char c, c1;
/* /*
* Charge is zero * Charge is zero
@ -333,6 +333,7 @@ get_charge(char *charge, LDBLE * l_z)
{ {
if (*ptr != '0') if (*ptr != '0')
{ {
char* ptr;
*l_z = strtod(charge, &ptr); *l_z = strtod(charge, &ptr);
return (OK); return (OK);
} }
@ -404,12 +405,14 @@ get_coef(LDBLE * coef, const char **eqnaddr)
{ {
int i; int i;
char c, c1; char c, c1;
char *ptr, *ptr1, *rest; const char* cptr;
const char* rest;
char* ptr1;
char token[MAX_LENGTH];; char token[MAX_LENGTH];;
rest = *eqnaddr; rest = *eqnaddr;
ptr = *eqnaddr; /* address of a position in eqn */ cptr = *eqnaddr; /* address of a position in eqn */
c = *ptr; /* character in eqn */ c = *cptr; /* character in eqn */
*coef = 0.0; *coef = 0.0;
/* /*
* No leading sign or number * No leading sign or number
@ -423,12 +426,12 @@ get_coef(LDBLE * coef, const char **eqnaddr)
/* /*
* Leading +, no digits * Leading +, no digits
*/ */
c1 = *(ptr + 1); c1 = *(cptr + 1);
if (c == '+' && if (c == '+' &&
(isalpha((int) c1) || (isalpha((int) c1) ||
(c1 == '(') || (c1 == ')') || (c1 == '[') || (c1 == ']'))) (c1 == '(') || (c1 == ')') || (c1 == '[') || (c1 == ']')))
{ {
*eqnaddr = ++ptr; *eqnaddr = ++cptr;
*coef = 1.0; *coef = 1.0;
return (OK); return (OK);
} }
@ -439,7 +442,7 @@ get_coef(LDBLE * coef, const char **eqnaddr)
(isalpha((int) c1) || (isalpha((int) c1) ||
(c1 == '(') || (c1 == ')') || (c1 == '[') || (c1 == ']'))) (c1 == '(') || (c1 == ')') || (c1 == '[') || (c1 == ']')))
{ {
*eqnaddr = ++ptr; *eqnaddr = ++cptr;
*coef = -1.0; *coef = -1.0;
return (OK); return (OK);
} }
@ -459,10 +462,10 @@ get_coef(LDBLE * coef, const char **eqnaddr)
error_msg(error_string, CONTINUE); error_msg(error_string, CONTINUE);
return (ERROR); return (ERROR);
} }
c = *(++ptr); c = *(++cptr);
} }
token[i] = '\0'; token[i] = '\0';
*eqnaddr = ptr; *eqnaddr = cptr;
errno = 0; errno = 0;
*coef = strtod(token, &ptr1); *coef = strtod(token, &ptr1);
if ((errno == ERANGE) || (*ptr1 != '\0')) if ((errno == ERANGE) || (*ptr1 != '\0'))
@ -575,7 +578,7 @@ get_elts_in_species(const char **t_ptr, LDBLE coef)
char c, c1; char c, c1;
LDBLE d; LDBLE d;
char element[MAX_LENGTH]; char element[MAX_LENGTH];
char** t_ptr_save = t_ptr; const char** t_ptr_save = t_ptr;
while (((c = **t_ptr) != '+') && (c != '-') && (c != '\0')) while (((c = **t_ptr) != '+') && (c != '-') && (c != '\0'))
{ {
/* close parenthesis */ /* close parenthesis */
@ -708,7 +711,7 @@ get_secondary(const char **t_ptr, char *element, int *i)
{ {
int j; int j;
char c; char c;
char *ptr; const char* cptr;
c = *(*t_ptr)++; c = *(*t_ptr)++;
if (c == '\0') if (c == '\0')
@ -766,7 +769,7 @@ get_secondary(const char **t_ptr, char *element, int *i)
* Check if secondary master species element * Check if secondary master species element
*/ */
j = *i; j = *i;
ptr = *t_ptr; cptr = *t_ptr;
if (c == '(') if (c == '(')
{ {
/* copy parenthesis */ /* copy parenthesis */
@ -796,7 +799,7 @@ get_secondary(const char **t_ptr, char *element, int *i)
if (c != ')') if (c != ')')
{ {
*i = j; *i = j;
*t_ptr = ptr; *t_ptr = cptr;
/* put in closing parenthesis */ /* put in closing parenthesis */
} }
else else
@ -830,7 +833,7 @@ get_secondary_in_species(const char **t_ptr, LDBLE coef)
char c, c1; char c, c1;
LDBLE d; LDBLE d;
char element[MAX_LENGTH]; char element[MAX_LENGTH];
char** t_ptr_save = t_ptr; const char** t_ptr_save = t_ptr;
while (((c = **t_ptr) != '+') && (c != '-') && (c != '\0')) while (((c = **t_ptr) != '+') && (c != '-') && (c != '\0'))
{ {
/* close parenthesis */ /* close parenthesis */
@ -962,7 +965,7 @@ get_num(const char **t_ptr, LDBLE * num)
{ {
int i, decimal; int i, decimal;
char c; char c;
char *ptr1; char* ptr1;
char token[MAX_LENGTH]; char token[MAX_LENGTH];
*num = 1.0; *num = 1.0;
@ -1005,7 +1008,7 @@ get_num(const char **t_ptr, LDBLE * num)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
int Phreeqc:: int Phreeqc::
get_species(const char **ptr) get_species(const char **cptr)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
{ {
/* Function reads next species out of the equation, including optional /* Function reads next species out of the equation, including optional
@ -1013,7 +1016,7 @@ get_species(const char **ptr)
* store in trxn.token[count]. * store in trxn.token[count].
* *
* Arguments: * Arguments:
* **ptr input, points to the position in the equation to pick up the species. * **cptr input, points to the position in the equation to pick up the species.
* output, points to the next character after the species charge. * output, points to the next character after the species charge.
* *
*/ */
@ -1023,12 +1026,12 @@ get_species(const char **ptr)
if ((size_t) count_trxn + 1 > trxn.token.size()) if ((size_t) count_trxn + 1 > trxn.token.size())
trxn.token.resize((size_t)count_trxn + 1); trxn.token.resize((size_t)count_trxn + 1);
/* coefficient */ /* coefficient */
if (get_coef(&(trxn.token[count_trxn].coef), ptr) == ERROR) if (get_coef(&(trxn.token[count_trxn].coef), cptr) == ERROR)
{ {
return (ERROR); return (ERROR);
} }
/* name and charge */ /* name and charge */
if (get_token(ptr, string, &trxn.token[count_trxn].z, &l) == ERROR) if (get_token(cptr, string, &trxn.token[count_trxn].z, &l) == ERROR)
{ {
return (ERROR); return (ERROR);
} }

View File

@ -571,7 +571,7 @@ read_pitzer(void)
pitz_param_type pzp_type; pitz_param_type pzp_type;
int return_value, opt, opt_save; int return_value, opt, opt_save;
char *next_char; const char* next_char;
const char *opt_list[] = { const char *opt_list[] = {
"b0", /* 0 */ "b0", /* 0 */
"b1", /* 1 */ "b1", /* 1 */

View File

@ -68,7 +68,7 @@ pitz_param_read(char *string, int n)
* *
*/ */
int l, i, j, k; int l, i, j, k;
char *ptr; const char* cptr;
char token[2 * MAX_LENGTH]; char token[2 * MAX_LENGTH];
struct pitz_param pzp, *pzp_ptr; struct pitz_param pzp, *pzp_ptr;
@ -78,13 +78,13 @@ pitz_param_read(char *string, int n)
return (NULL); return (NULL);
pitz_param_init(&pzp); pitz_param_init(&pzp);
ptr = string; cptr = string;
if (copy_token(token, &ptr, &l) == EMPTY) if (copy_token(token, &cptr, &l) == EMPTY)
return (NULL); return (NULL);
ptr = string; cptr = string;
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
int j = copy_token(token, &ptr, &l); int j = copy_token(token, &cptr, &l);
if (j == EMPTY) if (j == EMPTY)
return (NULL); return (NULL);
if (j != UPPER && token[0] != '(') if (j != UPPER && token[0] != '(')
@ -99,7 +99,7 @@ pitz_param_read(char *string, int n)
k = 0; k = 0;
for (i = 0; i < 6; i++) for (i = 0; i < 6; i++)
{ {
if (copy_token(token, &ptr, &l) == EMPTY) if (copy_token(token, &cptr, &l) == EMPTY)
break; break;
j = sscanf(token, SCANFORMAT, &pzp.a[i]); j = sscanf(token, SCANFORMAT, &pzp.a[i]);
if (j <= 0) if (j <= 0)

100
prep.cpp
View File

@ -309,9 +309,9 @@ quick_setup(void)
/* test that charge and surface match */ /* test that charge and surface match */
cxxSurfaceComp *comp_ptr = use.Get_surface_ptr()->Find_comp(x[i]->surface_comp); cxxSurfaceComp *comp_ptr = use.Get_surface_ptr()->Find_comp(x[i]->surface_comp);
char * temp_formula = string_duplicate(comp_ptr->Get_formula().c_str()); char * temp_formula = string_duplicate(comp_ptr->Get_formula().c_str());
char * ptr = temp_formula; const char* ptr = temp_formula;
copy_token(token, &ptr, &l); copy_token(token, &ptr, &l);
char * ptr1 = token; const char* ptr1 = token;
get_elt(&ptr1, name, &l); get_elt(&ptr1, name, &l);
ptr1 = strchr(name, '_'); ptr1 = strchr(name, '_');
if (ptr1 != NULL) if (ptr1 != NULL)
@ -656,7 +656,7 @@ build_ss_assemblage(void)
int row, col; int row, col;
struct master *master_ptr; struct master *master_ptr;
struct rxn_token *rxn_ptr; struct rxn_token *rxn_ptr;
char *ptr; const char* cptr;
if (ss_unknown == NULL) if (ss_unknown == NULL)
return (OK); return (OK);
@ -760,8 +760,8 @@ build_ss_assemblage(void)
count_elts = 0; count_elts = 0;
paren_count = 0; paren_count = 0;
char * token = string_duplicate(x[i]->phase->formula); char * token = string_duplicate(x[i]->phase->formula);
ptr = token; cptr = token;
get_elts_in_species(&ptr, 1.0); get_elts_in_species(&cptr, 1.0);
free_check_null(token); free_check_null(token);
/* /*
* Go through elements in phase * Go through elements in phase
@ -1373,7 +1373,7 @@ build_pure_phases(void)
*/ */
bool stop; bool stop;
std::string token; std::string token;
char *ptr; const char* cptr;
struct master *master_ptr; struct master *master_ptr;
struct rxn_token *rxn_ptr; struct rxn_token *rxn_ptr;
/* /*
@ -1439,15 +1439,15 @@ build_pure_phases(void)
if (comp_ptr->Get_add_formula().size() > 0) if (comp_ptr->Get_add_formula().size() > 0)
{ {
char * char_name = string_duplicate(comp_ptr->Get_add_formula().c_str()); char * char_name = string_duplicate(comp_ptr->Get_add_formula().c_str());
ptr = char_name; cptr = char_name;
get_elts_in_species(&ptr, 1.0); get_elts_in_species(&cptr, 1.0);
free_check_null(char_name); free_check_null(char_name);
} }
else else
{ {
char * char_name = string_duplicate(x[i]->phase->formula); char * char_name = string_duplicate(x[i]->phase->formula);
ptr = char_name; cptr = char_name;
get_elts_in_species(&ptr, 1.0); get_elts_in_species(&cptr, 1.0);
free_check_null(char_name); free_check_null(char_name);
} }
/* /*
@ -1889,8 +1889,8 @@ convert_units(cxxSolution *solution_ptr)
else else
{ {
char * temp_desc = string_duplicate(comp_ref.Get_description().c_str()); char * temp_desc = string_duplicate(comp_ref.Get_description().c_str());
char *ptr = temp_desc; const char* cptr = temp_desc;
copy_token(token, &ptr); copy_token(token, &cptr);
master_ptr = master_bsearch(token.c_str()); master_ptr = master_bsearch(token.c_str());
free_check_null(temp_desc); free_check_null(temp_desc);
if (master_ptr != NULL) if (master_ptr != NULL)
@ -1988,11 +1988,11 @@ convert_units(cxxSolution *solution_ptr)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
std::vector<struct master *> Phreeqc:: std::vector<struct master *> Phreeqc::
get_list_master_ptrs(char *ptr, struct master *master_ptr) get_list_master_ptrs(const char* cptr, struct master *master_ptr)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
{ {
/* /*
* Input: ptr contains a list of one or more master species names * Input: cptr contains a list of one or more master species names
* Output: space is allocated and a list of master species pointers is * Output: space is allocated and a list of master species pointers is
* returned. * returned.
*/ */
@ -2054,7 +2054,7 @@ get_list_master_ptrs(char *ptr, struct master *master_ptr)
* First in list is secondary species, Include all valences from input * First in list is secondary species, Include all valences from input
*/ */
master_ptr_list.push_back(master_ptr0); master_ptr_list.push_back(master_ptr0);
while (copy_token(token, &ptr, &l) != EMPTY) while (copy_token(token, &cptr, &l) != EMPTY)
{ {
master_ptr = master_bsearch(token); master_ptr = master_bsearch(token);
if (master_ptr != NULL) if (master_ptr != NULL)
@ -2947,7 +2947,7 @@ add_surface_charge_balance(void)
* Include charge balance in list for mass-balance equations * Include charge balance in list for mass-balance equations
*/ */
int i; int i;
char *ptr; const char* cptr;
std::string token; std::string token;
struct master *master_ptr; struct master *master_ptr;
@ -2999,8 +2999,8 @@ add_surface_charge_balance(void)
* Include charge balance in list for mass-balance equations * Include charge balance in list for mass-balance equations
*/ */
char * temp_name = string_duplicate(master_ptr->elt->name); char * temp_name = string_duplicate(master_ptr->elt->name);
ptr = temp_name; cptr = temp_name;
get_secondary_in_species(&ptr, 1.0); get_secondary_in_species(&cptr, 1.0);
free_check_null(temp_name); free_check_null(temp_name);
return (OK); return (OK);
@ -3062,8 +3062,8 @@ add_cd_music_charge_balances(int n)
*/ */
{ {
char * temp_name = string_duplicate( master_ptr->elt->name); char * temp_name = string_duplicate( master_ptr->elt->name);
char *ptr = temp_name; const char* cptr = temp_name;
get_secondary_in_species(&ptr, s[n]->dz[0]); get_secondary_in_species(&cptr, s[n]->dz[0]);
free_check_null(temp_name); free_check_null(temp_name);
} }
/* /*
@ -3077,8 +3077,8 @@ add_cd_music_charge_balances(int n)
*/ */
{ {
char * temp_name = string_duplicate( master_ptr->elt->name); char * temp_name = string_duplicate( master_ptr->elt->name);
char *ptr = temp_name; const char* cptr = temp_name;
get_secondary_in_species(&ptr, s[n]->dz[1]); get_secondary_in_species(&cptr, s[n]->dz[1]);
free_check_null(temp_name); free_check_null(temp_name);
} }
/* /*
@ -3092,8 +3092,8 @@ add_cd_music_charge_balances(int n)
*/ */
{ {
char * temp_name = string_duplicate(master_ptr->elt->name); char * temp_name = string_duplicate(master_ptr->elt->name);
char *ptr = temp_name; const char* cptr = temp_name;
get_secondary_in_species(&ptr, s[n]->dz[2]); get_secondary_in_species(&cptr, s[n]->dz[2]);
free_check_null(temp_name); free_check_null(temp_name);
} }
@ -4183,7 +4183,7 @@ setup_solution(void)
*/ */
struct master *master_ptr; struct master *master_ptr;
cxxSolution *solution_ptr; cxxSolution *solution_ptr;
char *ptr; const char* cptr;
std::string token; std::string token;
struct master_isotope *master_isotope_ptr; struct master_isotope *master_isotope_ptr;
struct phase *phase_ptr; struct phase *phase_ptr;
@ -4223,8 +4223,8 @@ setup_solution(void)
comp_ptr = &(comp_it->second); comp_ptr = &(comp_it->second);
} }
char * temp_desc = string_duplicate(it->first.c_str()); char * temp_desc = string_duplicate(it->first.c_str());
ptr = temp_desc; cptr = temp_desc;
copy_token(token, &ptr); copy_token(token, &cptr);
master_ptr = master_bsearch(token.c_str()); master_ptr = master_bsearch(token.c_str());
/* /*
* Check that total not <= zero * Check that total not <= zero
@ -4263,7 +4263,7 @@ setup_solution(void)
/* /*
* Store list of master species pointers, set master[i].in and master[i].rxn for list * Store list of master species pointers, set master[i].in and master[i].rxn for list
*/ */
x[count_unknowns]->master = get_list_master_ptrs(ptr, master_ptr); x[count_unknowns]->master = get_list_master_ptrs(cptr, master_ptr);
if (comp_ptr) if (comp_ptr)
{ {
setup_master_rxn(x[count_unknowns]->master, comp_ptr->Get_pe_reaction()); setup_master_rxn(x[count_unknowns]->master, comp_ptr->Get_pe_reaction());
@ -4288,8 +4288,8 @@ setup_solution(void)
*/ */
free_check_null(temp_desc); free_check_null(temp_desc);
temp_desc = string_duplicate(it->first.c_str()); temp_desc = string_duplicate(it->first.c_str());
ptr = temp_desc; cptr = temp_desc;
copy_token(token, &ptr); copy_token(token, &cptr);
Utilities::str_tolower(token); Utilities::str_tolower(token);
if (strstr(token.c_str(), "alk") != NULL) if (strstr(token.c_str(), "alk") != NULL)
{ {
@ -4347,8 +4347,8 @@ setup_solution(void)
if (comp_ptr && comp_ptr->Get_equation_name().size() > 0) if (comp_ptr && comp_ptr->Get_equation_name().size() > 0)
{ {
char * temp_eq_name = string_duplicate(comp_ptr->Get_equation_name().c_str()); char * temp_eq_name = string_duplicate(comp_ptr->Get_equation_name().c_str());
ptr = temp_eq_name; cptr = temp_eq_name;
copy_token(token, &ptr); copy_token(token, &cptr);
Utilities::str_tolower(token); Utilities::str_tolower(token);
if (strstr(token.c_str(), "charge") != NULL) if (strstr(token.c_str(), "charge") != NULL)
{ {
@ -5131,8 +5131,8 @@ write_mb_eqn_x(void)
{ {
j = count_elts; j = count_elts;
char * temp_name = string_duplicate(trxn.token[i].s->name); char * temp_name = string_duplicate(trxn.token[i].s->name);
char * ptr = temp_name; const char* cptr = temp_name;
get_elts_in_species(&ptr, trxn.token[i].coef); get_elts_in_species(&cptr, trxn.token[i].coef);
free_check_null(temp_name); free_check_null(temp_name);
for (k = j; k < count_elts; k++) for (k = j; k < count_elts; k++)
{ {
@ -5153,15 +5153,15 @@ write_mb_eqn_x(void)
if (trxn.token[i].s->secondary == NULL) if (trxn.token[i].s->secondary == NULL)
{ {
char * temp_name = string_duplicate(trxn.token[i].s->primary->elt->name); char * temp_name = string_duplicate(trxn.token[i].s->primary->elt->name);
char *ptr = temp_name; const char* cptr = temp_name;
get_secondary_in_species(&ptr, trxn.token[i].coef); get_secondary_in_species(&cptr, trxn.token[i].coef);
free_check_null(temp_name); free_check_null(temp_name);
} }
else else
{ {
char * temp_name = string_duplicate(trxn.token[i].s->secondary->elt->name); char * temp_name = string_duplicate(trxn.token[i].s->secondary->elt->name);
ptr = temp_name; cptr = temp_name;
get_secondary_in_species(&ptr, trxn.token[i].coef); get_secondary_in_species(&cptr, trxn.token[i].coef);
free_check_null(temp_name); free_check_null(temp_name);
} }
} }
@ -5194,15 +5194,15 @@ write_mb_for_species_list(int n)
if (trxn.token[i].s->secondary == NULL) if (trxn.token[i].s->secondary == NULL)
{ {
char * temp_name = string_duplicate(trxn.token[i].s->primary->elt->name); char * temp_name = string_duplicate(trxn.token[i].s->primary->elt->name);
char * ptr = temp_name; const char* cptr = temp_name;
get_secondary_in_species(&ptr, trxn.token[i].coef); get_secondary_in_species(&cptr, trxn.token[i].coef);
free_check_null(temp_name); free_check_null(temp_name);
} }
else else
{ {
char * temp_name = string_duplicate(trxn.token[i].s->secondary->elt->name); char * temp_name = string_duplicate(trxn.token[i].s->secondary->elt->name);
char * ptr = temp_name; const char* cptr = temp_name;
if (get_secondary_in_species(&ptr, trxn.token[i].coef) == ERROR) if (get_secondary_in_species(&cptr, trxn.token[i].coef) == ERROR)
{ {
input_error++; input_error++;
error_string = sformatf( "Error parsing %s.", trxn.token[i].s->secondary->elt->name); error_string = sformatf( "Error parsing %s.", trxn.token[i].s->secondary->elt->name);
@ -5256,15 +5256,15 @@ write_phase_sys_total(int n)
if (trxn.token[i].s->secondary == NULL) if (trxn.token[i].s->secondary == NULL)
{ {
char * temp_name = string_duplicate(trxn.token[i].s->primary->elt->name); char * temp_name = string_duplicate(trxn.token[i].s->primary->elt->name);
char *ptr = temp_name; const char* cptr = temp_name;
get_secondary_in_species(&ptr, trxn.token[i].coef); get_secondary_in_species(&cptr, trxn.token[i].coef);
free_check_null(temp_name); free_check_null(temp_name);
} }
else else
{ {
char * temp_name = string_duplicate(trxn.token[i].s->secondary->elt->name); char * temp_name = string_duplicate(trxn.token[i].s->secondary->elt->name);
char *ptr = temp_name; const char* cptr = temp_name;
get_secondary_in_species(&ptr, trxn.token[i].coef); get_secondary_in_species(&cptr, trxn.token[i].coef);
free_check_null(temp_name); free_check_null(temp_name);
} }
} }
@ -6053,8 +6053,8 @@ build_min_exch(void)
paren_count = 0; paren_count = 0;
{ {
char * formula = string_duplicate(comp_ref.Get_formula().c_str()); char * formula = string_duplicate(comp_ref.Get_formula().c_str());
char * ptr = formula; const char* cptr = formula;
get_elts_in_species(&ptr, 1.0); get_elts_in_species(&cptr, 1.0);
free_check_null(formula); free_check_null(formula);
} }
#ifdef COMBINE #ifdef COMBINE
@ -6187,8 +6187,8 @@ build_min_surface(void)
{ {
/* Add specified formula for all types of surfaces */ /* Add specified formula for all types of surfaces */
char * formula = string_duplicate(comp_ptr->Get_formula().c_str()); char * formula = string_duplicate(comp_ptr->Get_formula().c_str());
char *ptr1 = formula; const char* cptr1 = formula;
get_elts_in_species(&ptr1, 1.0); get_elts_in_species(&cptr1, 1.0);
free_check_null(formula); free_check_null(formula);
} }
#ifdef COMBINE #ifdef COMBINE

751
read.cpp

File diff suppressed because it is too large Load Diff

View File

@ -35,7 +35,7 @@ read_transport(void)
* ERROR if error occurred reading data * ERROR if error occurred reading data
* *
*/ */
char *ptr; const char* cptr;
int i, j, l; int i, j, l;
int count_length, count_disp, count_punch, count_print, count_por, count_same_model; int count_length, count_disp, count_punch, count_print, count_por, count_same_model;
int count_length_alloc, count_disp_alloc, count_por_alloc; int count_length_alloc, count_disp_alloc, count_por_alloc;
@ -45,8 +45,9 @@ read_transport(void)
LDBLE *length, *disp, *pors; LDBLE *length, *disp, *pors;
int *punch_temp, *print_temp, *same_model_temp; int *punch_temp, *print_temp, *same_model_temp;
int return_value, opt, opt_save; int return_value, opt, opt_save;
char *next_char, *next_char_save; const char* next_char;
char file_name[MAX_LENGTH]; //char file_name[MAX_LENGTH];
std::string file_name("phreeqc.dmp");
const char *opt_list[] = { const char *opt_list[] = {
"cells", /* 0 */ "cells", /* 0 */
@ -100,7 +101,6 @@ read_transport(void)
}; };
int count_opt_list = 48; int count_opt_list = 48;
strcpy(file_name, "phreeqc.dmp");
/* /*
* Initialize * Initialize
*/ */
@ -145,8 +145,8 @@ read_transport(void)
/* /*
* Read transport number (not currently used) * Read transport number (not currently used)
*/ */
ptr = line; cptr = line;
read_number_description(ptr, &n_user, &n_user_end, &description); read_number_description(cptr, &n_user, &n_user_end, &description);
description = (char *)free_check_null(description); description = (char *)free_check_null(description);
/* /*
* Set use data to last read * Set use data to last read
@ -442,17 +442,17 @@ read_transport(void)
opt_save = OPTION_DEFAULT; opt_save = OPTION_DEFAULT;
break; break;
case 26: /* dump */ case 26: /* dump */
{
dump_in = TRUE; dump_in = TRUE;
next_char_save = next_char; std::string temp_name(next_char);
if (copy_token(file_name, &next_char, &l) == EMPTY) string_trim(temp_name);
strcpy(file_name, "phreeqc.dmp"); if (temp_name.size() > 0)
else
{ {
string_trim(next_char_save); file_name = temp_name;
strcpy(file_name, next_char_save);
} }
opt_save = OPTION_DEFAULT; opt_save = OPTION_DEFAULT;
break; break;
}
case 27: /* output */ case 27: /* output */
case 28: /* output_frequency */ case 28: /* output_frequency */
case 34: /* print_frequency */ case 34: /* print_frequency */
@ -1150,7 +1150,7 @@ read_transport(void)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
int Phreeqc:: int Phreeqc::
read_line_LDBLEs(char *next_char, LDBLE ** d, int *count_d, int *count_alloc) read_line_LDBLEs(const char* next_char, LDBLE ** d, int *count_d, int *count_alloc)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
{ {
int i, j, l, n; int i, j, l, n;

View File

@ -177,7 +177,7 @@ read_sit(void)
pitz_param_type pzp_type; pitz_param_type pzp_type;
int return_value, opt, opt_save; int return_value, opt, opt_save;
char *next_char; const char* next_char;
const char *opt_list[] = { const char *opt_list[] = {
"epsilon", /* 0 */ "epsilon", /* 0 */
"epsilon1" /* 1 */ "epsilon1" /* 1 */

View File

@ -37,10 +37,10 @@ read_solution_spread(void)
struct spread_row *heading, *row_ptr, *units; struct spread_row *heading, *row_ptr, *units;
int count, strings, numbers; int count, strings, numbers;
int spread_lines; int spread_lines;
char *ptr; const char* cptr;
struct defaults soln_defaults; struct defaults soln_defaults;
int return_value, opt; int return_value, opt;
char *next_char; const char* next_char;
const char *opt_list[] = { const char *opt_list[] = {
"temp", /* 0 */ "temp", /* 0 */
"temperature", /* 1 */ "temperature", /* 1 */
@ -103,10 +103,10 @@ read_solution_spread(void)
if (spread_lines == 0 && opt != OPTION_DEFAULT) if (spread_lines == 0 && opt != OPTION_DEFAULT)
{ {
row_ptr = string_to_spread_row(line); row_ptr = string_to_spread_row(line);
ptr = line; cptr = line;
count = numbers = strings = 0; count = numbers = strings = 0;
int j; int j;
while (((j = copy_token(token, &ptr)) != EMPTY)) while (((j = copy_token(token, &cptr)) != EMPTY))
{ {
count++; count++;
if (j == UPPER || j == LOWER) if (j == UPPER || j == LOWER)
@ -117,14 +117,16 @@ read_solution_spread(void)
/* /*
* Is 2nd token all number * Is 2nd token all number
*/ */
ptr = line; cptr = line;
copy_token(token, &ptr); copy_token(token, &cptr);
j = copy_token(token, &ptr); j = copy_token(token, &cptr);
bool num = false; bool num = false;
if (j == DIGIT) if (j == DIGIT)
{ {
char* ptr;
strtod(token.c_str(), &ptr); strtod(token.c_str(), &ptr);
int j1 = copy_token(token1, &ptr); cptr = ptr;
int j1 = copy_token(token1, &cptr);
if (j1 != EMPTY) if (j1 != EMPTY)
{ {
num = FALSE; num = FALSE;
@ -134,12 +136,11 @@ read_solution_spread(void)
num = TRUE; num = TRUE;
} }
} }
/* /*
* Starts with hyphen * Starts with hyphen
*/ */
ptr = line; cptr = line;
copy_token(token, &ptr); copy_token(token, &cptr);
if (token[0] == '-') if (token[0] == '-')
{ {
/* opt = opt; */ /* opt = opt; */
@ -554,7 +555,7 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units,
CParser parser(this->phrq_io); CParser parser(this->phrq_io);
int return_value, opt; int return_value, opt;
char *next_char; const char* next_char;
const char *opt_list[] = { const char *opt_list[] = {
"temp", /* 0 */ "temp", /* 0 */
"temperature", /* 1 */ "temperature", /* 1 */
@ -884,10 +885,10 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units,
/* read and save element name */ /* read and save element name */
{ {
char *temp_iso_name = string_duplicate(token.c_str()); char *temp_iso_name = string_duplicate(token.c_str());
char *ptr1 = temp_iso_name; const char* cptr1 = temp_iso_name;
get_num(&ptr1, &dummy); get_num(&cptr1, &dummy);
temp_isotope.Set_isotope_number(dummy); temp_isotope.Set_isotope_number(dummy);
if (ptr1[0] == '\0' || isupper((int) ptr1[0]) == FALSE) if (cptr1[0] == '\0' || isupper((int)cptr1[0]) == FALSE)
{ {
error_msg("Expecting element name.", PHRQ_io::OT_CONTINUE); error_msg("Expecting element name.", PHRQ_io::OT_CONTINUE);
error_msg(line_save, PHRQ_io::OT_CONTINUE); error_msg(line_save, PHRQ_io::OT_CONTINUE);
@ -896,7 +897,7 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units,
char_string = (char*)free_check_null(char_string); char_string = (char*)free_check_null(char_string);
return (CParser::PARSER_ERROR); return (CParser::PARSER_ERROR);
} }
temp_isotope.Set_elt_name(ptr1); temp_isotope.Set_elt_name(cptr1);
temp_iso_name = (char*)free_check_null(temp_iso_name); temp_iso_name = (char*)free_check_null(temp_iso_name);
} }
/* read and store isotope ratio */ /* read and store isotope ratio */
@ -934,8 +935,6 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units,
break; break;
case 10: /* water */ case 10: /* water */
{ {
//next_char = char_string;
//int j = copy_token(token, &next_char); // read identifier "water"
int j = copy_token(token, &next_char); int j = copy_token(token, &next_char);
if (j == EMPTY) if (j == EMPTY)
{ {
@ -1061,7 +1060,7 @@ string_to_spread_row(char *string)
int j, l; int j, l;
/* possible memory error if length of line is smaller than previous line */ /* possible memory error if length of line is smaller than previous line */
char *token; char *token;
char *ptr; const char* cptr;
struct spread_row *spread_row_ptr = NULL; struct spread_row *spread_row_ptr = NULL;
/* /*
* Allocate space * Allocate space
@ -1104,7 +1103,7 @@ string_to_spread_row(char *string)
spread_row_ptr->empty = 0; spread_row_ptr->empty = 0;
spread_row_ptr->string = 0; spread_row_ptr->string = 0;
spread_row_ptr->number = 0; spread_row_ptr->number = 0;
ptr = string; cptr = string;
/* /*
* Split by tabs, reallocate space * Split by tabs, reallocate space
*/ */
@ -1141,7 +1140,7 @@ string_to_spread_row(char *string)
return spread_row_ptr; return spread_row_ptr;
} }
} }
j = copy_token_tab(token, &ptr, &l); j = copy_token_tab(token, &cptr, &l);
if (j == EOL) if (j == EOL)
break; break;
spread_row_ptr->char_vector[spread_row_ptr->count] = spread_row_ptr->char_vector[spread_row_ptr->count] =
@ -1240,16 +1239,16 @@ spread_row_free(struct spread_row *spread_row_ptr)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
int Phreeqc:: int Phreeqc::
copy_token_tab(char *token_ptr, char **ptr, int *length) copy_token_tab(char *token_ptr, const char **cptr, int *length)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
{ {
/* /*
* Copies from **ptr to *token_ptr until first tab is encountered. * Copies from **cptr to *token_ptr until first tab is encountered.
* *
* Arguments: * Arguments:
* *token_ptr output, place to store token * *token_ptr output, place to store token
* *
* **ptr input, character string to read token from * **cptr input, character string to read token from
* output, next position after token * output, next position after token
* *
* length output, length of token * length output, length of token
@ -1267,8 +1266,8 @@ copy_token_tab(char *token_ptr, char **ptr, int *length)
/* /*
* Strip leading spaces * Strip leading spaces
*/ */
while ((c = **ptr) == ' ') while ((c = **cptr) == ' ')
(*ptr)++; (*cptr)++;
/* /*
* Check what we have * Check what we have
*/ */
@ -1303,10 +1302,10 @@ copy_token_tab(char *token_ptr, char **ptr, int *length)
i = 0; i = 0;
for (;;) for (;;)
{ {
c = **ptr; c = **cptr;
if (c == '\t') if (c == '\t')
{ {
(*ptr)++; (*cptr)++;
break; break;
} }
else if (c == '\0') else if (c == '\0')
@ -1316,7 +1315,7 @@ copy_token_tab(char *token_ptr, char **ptr, int *length)
else else
{ {
token_ptr[i] = c; token_ptr[i] = c;
(*ptr)++; (*cptr)++;
i++; i++;
} }
} }
@ -1340,7 +1339,7 @@ copy_token_tab(char *token_ptr, char **ptr, int *length)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
int Phreeqc:: int Phreeqc::
get_option_string(const char **opt_list, int count_opt_list, char **next_char) get_option_string(const char **opt_list, int count_opt_list, const char **next_char)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
{ {
/* /*
@ -1348,7 +1347,7 @@ get_option_string(const char **opt_list, int count_opt_list, char **next_char)
*/ */
int j; int j;
int opt_l, opt; int opt_l, opt;
char *opt_ptr; const char *opt_ptr;
char option[MAX_LENGTH]; char option[MAX_LENGTH];
opt_ptr = *next_char; opt_ptr = *next_char;

View File

@ -663,7 +663,7 @@ add_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr)
int i; int i;
LDBLE amount_to_add, total; LDBLE amount_to_add, total;
char token[MAX_LENGTH]; char token[MAX_LENGTH];
char *ptr; const char* cptr;
struct master *master_ptr; struct master *master_ptr;
if (check_pp_assemblage(pp_assemblage_ptr) == OK) if (check_pp_assemblage(pp_assemblage_ptr) == OK)
@ -692,8 +692,8 @@ add_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr)
if (comp_ptr->Get_add_formula().size() > 0) if (comp_ptr->Get_add_formula().size() > 0)
{ {
strcpy(token, comp_ptr->Get_add_formula().c_str()); strcpy(token, comp_ptr->Get_add_formula().c_str());
ptr = &(token[0]); cptr = &(token[0]);
get_elts_in_species(&ptr, 1.0); get_elts_in_species(&cptr, 1.0);
} }
else else
{ {
@ -938,7 +938,7 @@ reaction_calc(cxxReaction *reaction_ptr)
*/ */
int return_value; int return_value;
LDBLE coef; LDBLE coef;
char *ptr; const char* cptr;
struct phase *phase_ptr; struct phase *phase_ptr;
/* /*
* Go through list and generate list of elements and * Go through list and generate list of elements and
@ -965,8 +965,8 @@ reaction_calc(cxxReaction *reaction_ptr)
else else
{ {
char * token = string_duplicate(it->first.c_str()); char * token = string_duplicate(it->first.c_str());
ptr = token; cptr = token;
get_elts_in_species(&ptr, coef); get_elts_in_species(&cptr, coef);
free_check_null(token); free_check_null(token);
} }
} }
@ -1064,7 +1064,7 @@ add_ss_assemblage(cxxSSassemblage *ss_assemblage_ptr)
int i, j, k; int i, j, k;
LDBLE amount_to_add, total; LDBLE amount_to_add, total;
struct master *master_ptr; struct master *master_ptr;
char *ptr; const char* cptr;
if (ss_assemblage_ptr == NULL) if (ss_assemblage_ptr == NULL)
return (OK); return (OK);
@ -1090,9 +1090,9 @@ add_ss_assemblage(cxxSSassemblage *ss_assemblage_ptr)
if (comp_ptr->Get_moles() > 0.0) if (comp_ptr->Get_moles() > 0.0)
{ {
char * token = string_duplicate(phase_ptr->formula); char * token = string_duplicate(phase_ptr->formula);
ptr = &(token[0]); cptr = &(token[0]);
count_elts = 0; // appt count_elts = 0; // appt
get_elts_in_species(&ptr, 1.0); get_elts_in_species(&cptr, 1.0);
free_check_null(token); free_check_null(token);
for (k = 0; k < count_elts; k++) for (k = 0; k < count_elts; k++)
{ {
@ -1270,7 +1270,7 @@ pp_assemblage_check(cxxPPassemblage *pp_assemblage_ptr)
* Check for missing elements * Check for missing elements
*/ */
std::string token; std::string token;
char *ptr; const char* cptr;
struct master *master_ptr; struct master *master_ptr;
if (check_pp_assemblage(pp_assemblage_ptr) == OK) if (check_pp_assemblage(pp_assemblage_ptr) == OK)
@ -1293,8 +1293,8 @@ pp_assemblage_check(cxxPPassemblage *pp_assemblage_ptr)
if (comp_ptr->Get_add_formula().size() > 0) if (comp_ptr->Get_add_formula().size() > 0)
{ {
token = comp_ptr->Get_add_formula(); token = comp_ptr->Get_add_formula();
ptr = &(token[0]); cptr = &(token[0]);
get_elts_in_species(&ptr, 1.0); get_elts_in_species(&cptr, 1.0);
} }
else else
{ {

View File

@ -834,7 +834,7 @@ master_alloc(void)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
int Phreeqc:: int Phreeqc::
master_delete(char *ptr) master_delete(const char* cptr)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
{ {
/* /*
@ -849,7 +849,7 @@ master_delete(char *ptr)
*/ */
int n; int n;
if (master_search(ptr, &n) == NULL) if (master_search(cptr, &n) == NULL)
return (FALSE); return (FALSE);
master_free(master[n]); master_free(master[n]);
master.erase(master.begin() + n); master.erase(master.begin() + n);
@ -875,29 +875,29 @@ master_free(struct master *master_ptr)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
struct master * Phreeqc:: struct master * Phreeqc::
master_bsearch(const char *ptr) master_bsearch(const char* cptr)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
{ {
/* /*
* Uses binary search. Assumes master is in sort order. * Uses binary search. Assumes master is in sort order.
* Find master species for string (*ptr) containing name of element or valence state. * Find master species for string (*cptr) containing name of element or valence state.
* *
* Input: ptr pointer to string containing element name * Input: cptr pointer to string containing element name
* *
* Return: pointer to master structure containing name ptr or NULL. * Return: pointer to master structure containing name cptr or NULL.
*/ */
void *void_ptr; void *void_ptr;
if (master.size() == 0) if (master.size() == 0)
{ {
return (NULL); return (NULL);
} }
void_ptr = bsearch((const char *) ptr, void_ptr = bsearch((const char *) cptr,
(char *) &master[0], (char *) &master[0],
master.size(), master.size(),
sizeof(struct master *), master_compare_string); sizeof(struct master *), master_compare_string);
if (void_ptr == NULL) if (void_ptr == NULL)
{ {
char * dup = string_duplicate(ptr); char * dup = string_duplicate(cptr);
replace("(+","(", dup); replace("(+","(", dup);
void_ptr = bsearch((const char *) dup, void_ptr = bsearch((const char *) dup,
(char*)&master[0], (char*)&master[0],
@ -941,23 +941,23 @@ master_compare(const void *ptr1, const void *ptr2)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
struct master * Phreeqc:: struct master * Phreeqc::
master_bsearch_primary(const char *ptr) master_bsearch_primary(const char* cptr)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
{ {
/* /*
* Find primary master species for first element in the string, ptr. * Find primary master species for first element in the string, cptr.
* Uses binary search. Assumes master is in sort order. * Uses binary search. Assumes master is in sort order.
*/ */
int l; int l;
char *ptr1; const char* cptr1;
char elt[MAX_LENGTH]; char elt[MAX_LENGTH];
struct master *master_ptr_primary; struct master *master_ptr_primary;
/* /*
* Find element name * Find element name
*/ */
char * temp_name = string_duplicate(ptr); char * temp_name = string_duplicate(cptr);
ptr1 = temp_name; cptr1 = temp_name;
get_elt(&ptr1, elt, &l); get_elt(&cptr1, elt, &l);
free_check_null(temp_name); free_check_null(temp_name);
/* /*
* Search master species list * Search master species list
@ -967,14 +967,14 @@ master_bsearch_primary(const char *ptr)
{ {
input_error++; input_error++;
error_string = sformatf( error_string = sformatf(
"Could not find primary master species for %s.", ptr); "Could not find primary master species for %s.", cptr);
error_msg(error_string, CONTINUE); error_msg(error_string, CONTINUE);
} }
return (master_ptr_primary); return (master_ptr_primary);
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
struct master * Phreeqc:: struct master * Phreeqc::
master_bsearch_secondary(char *ptr) master_bsearch_secondary(const char* cptr)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
{ {
/* /*
@ -982,15 +982,15 @@ master_bsearch_secondary(char *ptr)
* i.e. S(6) for S. * i.e. S(6) for S.
*/ */
int l; int l;
char *ptr1; const char* cptr1;
char elt[MAX_LENGTH]; char elt[MAX_LENGTH];
struct master *master_ptr_primary, *master_ptr=NULL, *master_ptr_secondary=NULL; struct master *master_ptr_primary, *master_ptr=NULL, *master_ptr_secondary=NULL;
int j; int j;
/* /*
* Find element name * Find element name
*/ */
ptr1 = ptr; cptr1 = cptr;
get_elt(&ptr1, elt, &l); get_elt(&cptr1, elt, &l);
/* /*
* Search master species list * Search master species list
*/ */
@ -999,7 +999,7 @@ master_bsearch_secondary(char *ptr)
{ {
input_error++; input_error++;
error_string = sformatf( error_string = sformatf(
"Could not find primary master species for %s.", ptr); "Could not find primary master species for %s.", cptr);
error_msg(error_string, CONTINUE); error_msg(error_string, CONTINUE);
} }
/* /*
@ -1035,7 +1035,7 @@ master_bsearch_secondary(char *ptr)
{ {
input_error++; input_error++;
error_string = sformatf( error_string = sformatf(
"Could not find secondary master species for %s.", ptr); "Could not find secondary master species for %s.", cptr);
error_msg(error_string, STOP); error_msg(error_string, STOP);
} }
@ -1044,11 +1044,11 @@ master_bsearch_secondary(char *ptr)
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
struct master * Phreeqc:: struct master * Phreeqc::
master_search(char *ptr, int *n) master_search(const char* cptr, int *n)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
{ {
/* /*
* Linear search of master to find master species in string, ptr. * Linear search of master to find master species in string, cptr.
* Returns pointer if found. n contains position in array master. * Returns pointer if found. n contains position in array master.
* Returns NULL if not found. * Returns NULL if not found.
*/ */
@ -1060,7 +1060,7 @@ master_search(char *ptr, int *n)
*n = -999; *n = -999;
for (i = 0; i < (int)master.size(); i++) for (i = 0; i < (int)master.size(); i++)
{ {
if (strcmp(ptr, master[i]->elt->name) == 0) if (strcmp(cptr, master[i]->elt->name) == 0)
{ {
*n = i; *n = i;
master_ptr = master[i]; master_ptr = master[i];
@ -1163,11 +1163,11 @@ phase_free(struct phase *phase_ptr)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
struct phase * Phreeqc:: struct phase * Phreeqc::
phase_bsearch(const char *ptr, int *j, int print) phase_bsearch(const char* cptr, int *j, int print)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
{ {
/* Binary search the structure array "phases" for a name that is equal to /* Binary search the structure array "phases" for a name that is equal to
* ptr. Assumes array phases is in sort order. * cptr. Assumes array phases is in sort order.
* *
* Arguments: * Arguments:
* name input, a character string to be located in phases. * name input, a character string to be located in phases.
@ -1184,14 +1184,14 @@ phase_bsearch(const char *ptr, int *j, int print)
if ((int)phases.size() > 0) if ((int)phases.size() > 0)
{ {
void_ptr = (void *) void_ptr = (void *)
bsearch((char *) ptr, bsearch((char *) cptr,
(char *) &phases[0], (char *) &phases[0],
phases.size(), phases.size(),
sizeof(struct phase *), phase_compare_string); sizeof(struct phase *), phase_compare_string);
} }
if (void_ptr == NULL && print == TRUE) if (void_ptr == NULL && print == TRUE)
{ {
error_string = sformatf( "Could not find phase in list, %s.", ptr); error_string = sformatf( "Could not find phase in list, %s.", cptr);
error_msg(error_string, CONTINUE); error_msg(error_string, CONTINUE);
} }
@ -1320,11 +1320,11 @@ phase_store(const char *name_in)
* ********************************************************************** */ * ********************************************************************** */
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
struct rate * Phreeqc:: struct rate * Phreeqc::
rate_bsearch(char *ptr, int *j) rate_bsearch(const char* cptr, int *j)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
{ {
/* Binary search the structure array "rates" for a name that is equal to /* Binary search the structure array "rates" for a name that is equal to
* ptr. Assumes array rates is in sort order. * cptr. Assumes array rates is in sort order.
* *
* Arguments: * Arguments:
* name input, a character string to be located in rates. * name input, a character string to be located in rates.
@ -1343,7 +1343,7 @@ rate_bsearch(char *ptr, int *j)
return (NULL); return (NULL);
} }
void_ptr = (void *) void_ptr = (void *)
bsearch((char *) ptr, bsearch((char *) cptr,
(char *) &rates[0], (char *) &rates[0],
rates.size(), rates.size(),
sizeof(struct rate *), rate_compare_string); sizeof(struct rate *), rate_compare_string);
@ -3256,13 +3256,13 @@ get_entity_enum(char *name)
* *
*/ */
int i; int i;
char *ptr; const char* cptr;
char token[MAX_LENGTH]; char token[MAX_LENGTH];
/* /*
* Read keyword * Read keyword
*/ */
ptr = name; cptr = name;
copy_token(token, &ptr, &i); copy_token(token, &cptr, &i);
check_key(token); check_key(token);
switch (next_keyword) switch (next_keyword)

View File

@ -416,7 +416,7 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer)
*/ */
int found; int found;
LDBLE moles; LDBLE moles;
//char *ptr; //const char* cptr;
/* /*
* Cycle through tally table columns * Cycle through tally table columns
*/ */
@ -792,7 +792,7 @@ build_tally_table(void)
int count_tt_pure_phase, count_tt_ss_phase, count_tt_kinetics; int count_tt_pure_phase, count_tt_ss_phase, count_tt_kinetics;
struct phase *phase_ptr; struct phase *phase_ptr;
char token[MAX_LENGTH]; char token[MAX_LENGTH];
char *ptr; const char* cptr;
/* /*
* make list of all elements in all entitites * make list of all elements in all entitites
* defines the number of rows in the table * defines the number of rows in the table
@ -906,8 +906,8 @@ build_tally_table(void)
if (comp_ptr->Get_add_formula().size() > 0) if (comp_ptr->Get_add_formula().size() > 0)
{ {
strcpy(token, comp_ptr->Get_add_formula().c_str()); strcpy(token, comp_ptr->Get_add_formula().c_str());
ptr = &(token[0]); cptr = &(token[0]);
get_elts_in_species(&ptr, 1.0); get_elts_in_species(&cptr, 1.0);
} }
else else
{ {
@ -1025,8 +1025,8 @@ build_tally_table(void)
std::string name = it->first; std::string name = it->first;
LDBLE coef = it->second; LDBLE coef = it->second;
char * temp_name = string_duplicate(name.c_str()); char * temp_name = string_duplicate(name.c_str());
ptr = temp_name; cptr = temp_name;
get_elts_in_species(&ptr, 1.0 * coef); get_elts_in_species(&cptr, 1.0 * coef);
free_check_null(temp_name); free_check_null(temp_name);
} }
} }
@ -1157,7 +1157,7 @@ calc_dummy_kinetic_reaction_tally(cxxKinetics *kinetics_ptr)
* Go through kinetic components and add positive amount of each reactant * Go through kinetic components and add positive amount of each reactant
*/ */
LDBLE coef; LDBLE coef;
char *ptr; const char* cptr;
struct phase *phase_ptr; struct phase *phase_ptr;
/* /*
* Go through list and generate list of elements and * Go through list and generate list of elements and
@ -1191,8 +1191,8 @@ calc_dummy_kinetic_reaction_tally(cxxKinetics *kinetics_ptr)
{ {
std::string name = it->first; std::string name = it->first;
char * temp_name = string_duplicate(name.c_str()); char * temp_name = string_duplicate(name.c_str());
ptr = temp_name; cptr = temp_name;
get_elts_in_species(&ptr, coef); get_elts_in_species(&cptr, coef);
free_check_null(temp_name); free_check_null(temp_name);
} }
} }

113
tidy.cpp
View File

@ -663,14 +663,14 @@ coef_in_master(struct master * master_ptr)
{ {
int l; int l;
LDBLE coef; LDBLE coef;
char *ptr; const char* cptr;
char elt_name[MAX_LENGTH]; char elt_name[MAX_LENGTH];
struct elt_list *next_elt; struct elt_list *next_elt;
coef = 0.0; coef = 0.0;
char * temp_name = string_duplicate(master_ptr->elt->name); char * temp_name = string_duplicate(master_ptr->elt->name);
ptr = temp_name; cptr = temp_name;
get_elt(&ptr, elt_name, &l); get_elt(&cptr, elt_name, &l);
free_check_null(temp_name); free_check_null(temp_name);
for (next_elt = master_ptr->s->next_elt; next_elt->elt != NULL; for (next_elt = master_ptr->s->next_elt; next_elt->elt != NULL;
next_elt++) next_elt++)
@ -1563,7 +1563,7 @@ tidy_pp_assemblage(void)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
{ {
LDBLE coef; LDBLE coef;
char *ptr; const char* cptr;
/* /*
* Find pointers for pure phases * Find pointers for pure phases
*/ */
@ -1616,8 +1616,8 @@ tidy_pp_assemblage(void)
} }
{ {
char * temp_add = string_duplicate(it->second.Get_add_formula().c_str()); char * temp_add = string_duplicate(it->second.Get_add_formula().c_str());
ptr = temp_add; cptr = temp_add;
get_elts_in_species(&ptr, coef); get_elts_in_species(&cptr, coef);
free_check_null(temp_add); free_check_null(temp_add);
} }
/* check that all elements are in the database */ /* check that all elements are in the database */
@ -2299,7 +2299,8 @@ tidy_species(void)
{ {
int i, j; int i, j;
struct master *master_ptr; struct master *master_ptr;
char c, *ptr; char c;
const char* cptr;
/* /*
* Make sure species pointers are ok * Make sure species pointers are ok
*/ */
@ -2331,10 +2332,10 @@ tidy_species(void)
for (i = 0; i < (int)master.size(); i++) for (i = 0; i < (int)master.size(); i++)
{ {
char * temp_name = string_duplicate(master[i]->elt->name); char * temp_name = string_duplicate(master[i]->elt->name);
ptr = temp_name; cptr = temp_name;
if (ptr[0] != '[') if (cptr[0] != '[')
{ {
while ((c = (int) *(++ptr)) != '\0') while ((c = (int) *(++cptr)) != '\0')
{ {
if (isupper((int) c)) if (isupper((int) c))
{ {
@ -2630,7 +2631,7 @@ tidy_surface(void)
* After all of data are read, fill in master species for surface comps * After all of data are read, fill in master species for surface comps
* Sort surface * Sort surface
*/ */
char *ptr1; const char* cptr1;
cxxSurface *surface_ptr; cxxSurface *surface_ptr;
//std::map<int, cxxSurface>::iterator kit; //std::map<int, cxxSurface>::iterator kit;
//for (kit = Rxn_surface_map.begin(); kit != Rxn_surface_map.end(); kit++) //for (kit = Rxn_surface_map.begin(); kit != Rxn_surface_map.end(); kit++)
@ -2715,8 +2716,8 @@ tidy_surface(void)
paren_count = 0; paren_count = 0;
{ {
char * temp_formula = string_duplicate(comp_ptr->Get_formula().c_str()); char * temp_formula = string_duplicate(comp_ptr->Get_formula().c_str());
ptr1 = temp_formula; cptr1 = temp_formula;
get_elts_in_species(&ptr1, comp_ptr->Get_moles()); get_elts_in_species(&cptr1, comp_ptr->Get_moles());
free_check_null(temp_formula); free_check_null(temp_formula);
} }
{ {
@ -2900,15 +2901,15 @@ phase_rxn_to_trxn(struct phase *phase_ptr, struct reaction *rxn_ptr)
* temp reaction structure. * temp reaction structure.
*/ */
int i, l; int i, l;
char *ptr; const char* cptr;
char token[MAX_LENGTH]; char token[MAX_LENGTH];
LDBLE l_z; LDBLE l_z;
trxn.token[0].name = phase_ptr->formula; trxn.token[0].name = phase_ptr->formula;
/* charge */ /* charge */
char * temp_formula = string_duplicate(phase_ptr->formula); char * temp_formula = string_duplicate(phase_ptr->formula);
ptr = temp_formula; cptr = temp_formula;
get_token(&ptr, token, &l_z, &l); get_token(&cptr, token, &l_z, &l);
free_check_null(temp_formula); free_check_null(temp_formula);
trxn.token[0].z = l_z; trxn.token[0].z = l_z;
trxn.token[0].s = NULL; trxn.token[0].s = NULL;
@ -3113,7 +3114,7 @@ tidy_kin_exchange(void)
*/ */
{ {
cxxKinetics *kinetics_ptr; cxxKinetics *kinetics_ptr;
char *ptr; const char* cptr;
LDBLE conc; LDBLE conc;
//std::map<int, cxxExchange>::iterator it = Rxn_exchange_map.begin(); //std::map<int, cxxExchange>::iterator it = Rxn_exchange_map.begin();
@ -3209,8 +3210,8 @@ tidy_kin_exchange(void)
paren_count = 0; paren_count = 0;
{ {
char * temp_formula = string_duplicate(comp_ref.Get_formula().c_str()); char * temp_formula = string_duplicate(comp_ref.Get_formula().c_str());
ptr = temp_formula; cptr = temp_formula;
get_elts_in_species(&ptr, conc); get_elts_in_species(&cptr, conc);
free_check_null(temp_formula); free_check_null(temp_formula);
} }
comp_ref.Set_totals(elt_list_NameDouble()); comp_ref.Set_totals(elt_list_NameDouble());
@ -3233,7 +3234,7 @@ update_kin_exchange(void)
*/ */
{ {
cxxKinetics* kinetics_ptr; cxxKinetics* kinetics_ptr;
char* ptr; const char* cptr;
LDBLE conc; LDBLE conc;
std::map<int, cxxExchange>::iterator it = Rxn_exchange_map.begin(); std::map<int, cxxExchange>::iterator it = Rxn_exchange_map.begin();
@ -3322,8 +3323,8 @@ update_kin_exchange(void)
paren_count = 0; paren_count = 0;
{ {
char* temp_formula = string_duplicate(comp_ref.Get_formula().c_str()); char* temp_formula = string_duplicate(comp_ref.Get_formula().c_str());
ptr = temp_formula; cptr = temp_formula;
get_elts_in_species(&ptr, 1.0); get_elts_in_species(&cptr, 1.0);
free_check_null(temp_formula); free_check_null(temp_formula);
} }
cxxNameDouble nd_formula = elt_list_NameDouble(); cxxNameDouble nd_formula = elt_list_NameDouble();
@ -3345,8 +3346,8 @@ update_kin_exchange(void)
paren_count = 0; paren_count = 0;
{ {
char* temp_formula = string_duplicate(comp_ref.Get_formula().c_str()); char* temp_formula = string_duplicate(comp_ref.Get_formula().c_str());
ptr = temp_formula; cptr = temp_formula;
get_elts_in_species(&ptr, conc); get_elts_in_species(&cptr, conc);
free_check_null(temp_formula); free_check_null(temp_formula);
} }
comp_ref.Set_totals(elt_list_NameDouble()); comp_ref.Set_totals(elt_list_NameDouble());
@ -3365,7 +3366,7 @@ tidy_min_exchange(void)
*/ */
{ {
int n, jj; int n, jj;
char *ptr; const char* cptr;
LDBLE conc; LDBLE conc;
//std::map<int, cxxExchange>::iterator it = Rxn_exchange_map.begin(); //std::map<int, cxxExchange>::iterator it = Rxn_exchange_map.begin();
@ -3461,8 +3462,8 @@ tidy_min_exchange(void)
paren_count = 0; paren_count = 0;
{ {
char * temp_formula = string_duplicate(comp_ref.Get_formula().c_str()); char * temp_formula = string_duplicate(comp_ref.Get_formula().c_str());
ptr = temp_formula; cptr = temp_formula;
get_elts_in_species(&ptr, conc); get_elts_in_species(&cptr, conc);
free_check_null(temp_formula); free_check_null(temp_formula);
} }
comp_ref.Set_totals(elt_list_NameDouble()); comp_ref.Set_totals(elt_list_NameDouble());
@ -3473,8 +3474,8 @@ tidy_min_exchange(void)
paren_count = 0; paren_count = 0;
{ {
char * temp_formula = string_duplicate(comp_ref.Get_formula().c_str()); char * temp_formula = string_duplicate(comp_ref.Get_formula().c_str());
ptr = temp_formula; cptr = temp_formula;
get_elts_in_species(&ptr, -comp_ref.Get_phase_proportion()); get_elts_in_species(&cptr, -comp_ref.Get_phase_proportion());
free_check_null(temp_formula); free_check_null(temp_formula);
} }
int l; int l;
@ -3482,8 +3483,8 @@ tidy_min_exchange(void)
if (phase_ptr != NULL) if (phase_ptr != NULL)
{ {
char * temp_formula = string_duplicate(phase_ptr->formula); char * temp_formula = string_duplicate(phase_ptr->formula);
ptr = temp_formula; cptr = temp_formula;
get_elts_in_species(&ptr, 1.0); get_elts_in_species(&cptr, 1.0);
free_check_null(temp_formula); free_check_null(temp_formula);
} }
else else
@ -3527,7 +3528,7 @@ update_min_exchange(void)
*/ */
{ {
int n, jj; int n, jj;
char* ptr; const char* cptr;
LDBLE conc; LDBLE conc;
std::map<int, cxxExchange>::iterator it = Rxn_exchange_map.begin(); std::map<int, cxxExchange>::iterator it = Rxn_exchange_map.begin();
@ -3616,8 +3617,8 @@ update_min_exchange(void)
paren_count = 0; paren_count = 0;
{ {
char* temp_formula = string_duplicate(comp_ref.Get_formula().c_str()); char* temp_formula = string_duplicate(comp_ref.Get_formula().c_str());
ptr = temp_formula; cptr = temp_formula;
get_elts_in_species(&ptr, 1.0); get_elts_in_species(&cptr, 1.0);
free_check_null(temp_formula); free_check_null(temp_formula);
} }
cxxNameDouble nd_formula = elt_list_NameDouble(); cxxNameDouble nd_formula = elt_list_NameDouble();
@ -3639,8 +3640,8 @@ update_min_exchange(void)
paren_count = 0; paren_count = 0;
{ {
char* temp_formula = string_duplicate(comp_ref.Get_formula().c_str()); char* temp_formula = string_duplicate(comp_ref.Get_formula().c_str());
ptr = temp_formula; cptr = temp_formula;
get_elts_in_species(&ptr, conc); get_elts_in_species(&cptr, conc);
free_check_null(temp_formula); free_check_null(temp_formula);
} }
comp_ref.Set_totals(elt_list_NameDouble()); comp_ref.Set_totals(elt_list_NameDouble());
@ -3651,8 +3652,8 @@ update_min_exchange(void)
paren_count = 0; paren_count = 0;
{ {
char* temp_formula = string_duplicate(comp_ref.Get_formula().c_str()); char* temp_formula = string_duplicate(comp_ref.Get_formula().c_str());
ptr = temp_formula; cptr = temp_formula;
get_elts_in_species(&ptr, -comp_ref.Get_phase_proportion()); get_elts_in_species(&cptr, -comp_ref.Get_phase_proportion());
free_check_null(temp_formula); free_check_null(temp_formula);
} }
int l; int l;
@ -3660,8 +3661,8 @@ update_min_exchange(void)
if (phase_ptr != NULL) if (phase_ptr != NULL)
{ {
char* temp_formula = string_duplicate(phase_ptr->formula); char* temp_formula = string_duplicate(phase_ptr->formula);
ptr = temp_formula; cptr = temp_formula;
get_elts_in_species(&ptr, 1.0); get_elts_in_species(&cptr, 1.0);
free_check_null(temp_formula); free_check_null(temp_formula);
} }
else else
@ -3810,10 +3811,10 @@ tidy_min_surface(void)
/* if (conc < MIN_RELATED_SURFACE) conc = 0.0; */ /* if (conc < MIN_RELATED_SURFACE) conc = 0.0; */
{ {
char * temp_formula = string_duplicate(surface_comp_ptr->Get_formula().c_str()); char * temp_formula = string_duplicate(surface_comp_ptr->Get_formula().c_str());
char *ptr = temp_formula; const char* cptr = temp_formula;
count_elts = 0; count_elts = 0;
paren_count = 0; paren_count = 0;
get_elts_in_species(&ptr, conc); get_elts_in_species(&cptr, conc);
free_check_null(temp_formula); free_check_null(temp_formula);
} }
{ {
@ -3841,8 +3842,8 @@ tidy_min_surface(void)
paren_count = 0; paren_count = 0;
{ {
char * temp_formula = string_duplicate(phase_ptr->formula); char * temp_formula = string_duplicate(phase_ptr->formula);
char * ptr = temp_formula; const char* cptr = temp_formula;
get_elts_in_species(&ptr, 1.0); get_elts_in_species(&cptr, 1.0);
free_check_null(temp_formula); free_check_null(temp_formula);
} }
// Revise logic for surface related to mineral // Revise logic for surface related to mineral
@ -3852,8 +3853,8 @@ tidy_min_surface(void)
// Use formula for all types of surfaces // Use formula for all types of surfaces
{ {
char * temp_formula = string_duplicate(comp_jj_ptr->Get_formula().c_str()); char * temp_formula = string_duplicate(comp_jj_ptr->Get_formula().c_str());
char *ptr = temp_formula; const char* cptr = temp_formula;
get_elts_in_species(&ptr, get_elts_in_species(&cptr,
-comp_jj_ptr->Get_phase_proportion()); -comp_jj_ptr->Get_phase_proportion());
if (surface_ptr->Get_type() != cxxSurface::CD_MUSIC) if (surface_ptr->Get_type() != cxxSurface::CD_MUSIC)
@ -4064,10 +4065,10 @@ update_min_surface(void)
else /* need to generate from scratch */ else /* need to generate from scratch */
{ {
char* temp_formula = string_duplicate(surface_comp_ptr->Get_formula().c_str()); char* temp_formula = string_duplicate(surface_comp_ptr->Get_formula().c_str());
char* ptr = temp_formula; const char* cptr = temp_formula;
count_elts = 0; count_elts = 0;
paren_count = 0; paren_count = 0;
get_elts_in_species(&ptr, conc); get_elts_in_species(&cptr, conc);
free_check_null(temp_formula); free_check_null(temp_formula);
cxxNameDouble nd = elt_list_NameDouble(); cxxNameDouble nd = elt_list_NameDouble();
@ -4197,10 +4198,10 @@ tidy_kin_surface(void)
/* if (conc < MIN_RELATED_SURFACE) conc = 0.0; */ /* if (conc < MIN_RELATED_SURFACE) conc = 0.0; */
{ {
char * temp_formula = string_duplicate(comp_ptr->Get_formula().c_str()); char * temp_formula = string_duplicate(comp_ptr->Get_formula().c_str());
char *ptr = temp_formula; const char* cptr = temp_formula;
count_elts = 0; count_elts = 0;
paren_count = 0; paren_count = 0;
get_elts_in_species(&ptr, conc); get_elts_in_species(&cptr, conc);
free_check_null(temp_formula); free_check_null(temp_formula);
} }
{ {
@ -4259,8 +4260,8 @@ tidy_kin_surface(void)
else else
{ {
char * temp_name = string_duplicate(name.c_str()); char * temp_name = string_duplicate(name.c_str());
char * ptr = temp_name; const char* cptr = temp_name;
get_elts_in_species(&ptr, coef); get_elts_in_species(&cptr, coef);
free_check_null(temp_name); free_check_null(temp_name);
} }
} }
@ -4287,8 +4288,8 @@ tidy_kin_surface(void)
kin_comp_ptr->Get_rate_name().c_str()) == 0) kin_comp_ptr->Get_rate_name().c_str()) == 0)
{ {
char * temp_formula = string_duplicate( comp_ptr->Get_formula().c_str()); char * temp_formula = string_duplicate( comp_ptr->Get_formula().c_str());
char *ptr = temp_formula; const char* cptr = temp_formula;
get_elts_in_species(&ptr, -1 * comp_ptr->Get_phase_proportion()); get_elts_in_species(&cptr, -1 * comp_ptr->Get_phase_proportion());
free_check_null(temp_formula); free_check_null(temp_formula);
} }
} }
@ -4477,10 +4478,10 @@ update_kin_surface(void)
else /* need to generate from scratch */ else /* need to generate from scratch */
{ {
char* temp_formula = string_duplicate(comp_ptr->Get_formula().c_str()); char* temp_formula = string_duplicate(comp_ptr->Get_formula().c_str());
char* ptr = temp_formula; const char* cptr = temp_formula;
count_elts = 0; count_elts = 0;
paren_count = 0; paren_count = 0;
get_elts_in_species(&ptr, conc); get_elts_in_species(&cptr, conc);
free_check_null(temp_formula); free_check_null(temp_formula);
cxxNameDouble nd = elt_list_NameDouble(); cxxNameDouble nd = elt_list_NameDouble();

View File

@ -1678,7 +1678,8 @@ set_initial_moles(int i)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
{ {
cxxKinetics *kinetics_ptr; cxxKinetics *kinetics_ptr;
char token[MAX_LENGTH], token1[MAX_LENGTH], *ptr; char token[MAX_LENGTH], token1[MAX_LENGTH];
const char* cptr;
int j, k, l; int j, k, l;
/* /*
* Pure phase assemblage * Pure phase assemblage
@ -1763,11 +1764,11 @@ set_initial_moles(int i)
count_elts = 0; count_elts = 0;
paren_count = 0; paren_count = 0;
strcpy(token, "X"); strcpy(token, "X");
ptr = token; cptr = token;
get_elts_in_species(&ptr, 2e-10); get_elts_in_species(&cptr, 2e-10);
ptr = token; cptr = token;
LDBLE z; LDBLE z;
get_token(&ptr, token1, &z, &l); get_token(&cptr, token1, &z, &l);
comp.Set_formula(token1); comp.Set_formula(token1);
comp.Set_formula_z(z); comp.Set_formula_z(z);
comp.Set_totals(elt_list_NameDouble()); comp.Set_totals(elt_list_NameDouble());
@ -2747,9 +2748,9 @@ diffuse_implicit(LDBLE DDt, int stagnant)
break; break;
} }
char * temp_name = string_duplicate(ct[1].J_ij[cp].name); char * temp_name = string_duplicate(ct[1].J_ij[cp].name);
char * ptr = temp_name; const char* cptr = temp_name;
count_elts = 0; count_elts = 0;
get_elts_in_species(&ptr, 1); get_elts_in_species(&cptr, 1);
free_check_null(temp_name); free_check_null(temp_name);
for (int k = 0; k < count_elts; k++) for (int k = 0; k < count_elts; k++)
{ {
@ -3589,15 +3590,15 @@ fill_m_s(struct J_ij *l_J_ij, int l_J_ij_count_spec, int icell, int stagnant)
*/ */
int j, k, l; int j, k, l;
LDBLE fraction; LDBLE fraction;
char *ptr; const char* cptr;
for (j = 0; j < l_J_ij_count_spec; j++) for (j = 0; j < l_J_ij_count_spec; j++)
{ {
{ {
char * temp_name = string_duplicate(l_J_ij[j].name); char * temp_name = string_duplicate(l_J_ij[j].name);
ptr = temp_name; cptr = temp_name;
count_elts = 0; count_elts = 0;
get_elts_in_species(&ptr, 1); get_elts_in_species(&cptr, 1);
free_check_null(temp_name); free_check_null(temp_name);
} }
if (implicit && stagnant < 2) if (implicit && stagnant < 2)

View File

@ -312,13 +312,13 @@ compute_gfw(const char *string, LDBLE * gfw)
int i; int i;
char token[MAX_LENGTH]; char token[MAX_LENGTH];
char *ptr; const char* cptr;
count_elts = 0; count_elts = 0;
paren_count = 0; paren_count = 0;
strcpy(token, string); strcpy(token, string);
ptr = token; cptr = token;
if (get_elts_in_species(&ptr, 1.0) == ERROR) if (get_elts_in_species(&cptr, 1.0) == ERROR)
{ {
return (ERROR); return (ERROR);
} }
@ -337,16 +337,16 @@ compute_gfw(const char *string, LDBLE * gfw)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
int Phreeqc:: int Phreeqc::
copy_token(char *token_ptr, const char **ptr, int *length) copy_token(char *token_ptr, const char **cptr, int *length)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
{ {
/* /*
* Copies from **ptr to *token_ptr until first space is encountered. * Copies from **cptr to *token_ptr until first space is encountered.
* *
* Arguments: * Arguments:
* *token_ptr output, place to store token * *token_ptr output, place to store token
* *
* **ptr input, character string to read token from * **cptr input, character string to read token from
* output, next position after token * output, next position after token
* *
* length output, length of token * length output, length of token
@ -364,8 +364,8 @@ copy_token(char *token_ptr, const char **ptr, int *length)
/* /*
* Read to end of whitespace * Read to end of whitespace
*/ */
while (isspace((int) (c = **ptr))) while (isspace((int) (c = **cptr)))
(*ptr)++; (*cptr)++;
/* /*
* Check what we have * Check what we have
*/ */
@ -393,12 +393,12 @@ copy_token(char *token_ptr, const char **ptr, int *length)
* Begin copying to token * Begin copying to token
*/ */
i = 0; i = 0;
while ((!isspace((int) (c = **ptr))) && while ((!isspace((int) (c = **cptr))) &&
/* c != ',' && */ /* c != ',' && */
c != ';' && c != '\0') c != ';' && c != '\0')
{ {
token_ptr[i] = c; token_ptr[i] = c;
(*ptr)++; (*cptr)++;
i++; i++;
} }
token_ptr[i] = '\0'; token_ptr[i] = '\0';
@ -407,16 +407,16 @@ copy_token(char *token_ptr, const char **ptr, int *length)
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
int Phreeqc:: int Phreeqc::
copy_token(std::string &token, const char **ptr) copy_token(std::string &token, const char **cptr)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
{ {
/* /*
* Copies from **ptr to *token until first space is encountered. * Copies from **cptr to *token until first space is encountered.
* *
* Arguments: * Arguments:
* &token_ptr output, place to store token * &token_ptr output, place to store token
* *
* **ptr input, character string to read token from * **cptr input, character string to read token from
* output, next position after token * output, next position after token
* *
* Returns: * Returns:
@ -433,8 +433,8 @@ copy_token(std::string &token, const char **ptr)
* Read to end of whitespace * Read to end of whitespace
*/ */
token.clear(); token.clear();
while (isspace((int) (c = **ptr))) while (isspace((int) (c = **cptr)))
(*ptr)++; (*cptr)++;
/* /*
* Check what we have * Check what we have
*/ */
@ -463,107 +463,19 @@ copy_token(std::string &token, const char **ptr)
*/ */
char c_char[2]; char c_char[2];
c_char[1] = '\0'; c_char[1] = '\0';
while ((!isspace((int) (c = **ptr))) && while ((!isspace((int) (c = **cptr))) &&
/* c != ',' && */ /* c != ',' && */
c != ';' && c != '\0') c != ';' && c != '\0')
{ {
c_char[0] = c; c_char[0] = c;
token.append(c_char); token.append(c_char);
(*ptr)++; (*cptr)++;
} }
return (return_value); return (return_value);
} }
#if defined PHREEQ98
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
int Phreeqc:: int Phreeqc::
copy_title(char *token_ptr, char **ptr, int *length) dup_print(const char* cptr, int emphasis)
/* ---------------------------------------------------------------------- */
{
/*
* Copies from **ptr to *token_ptr until first space or comma is encountered.
*
* Arguments:
* *token_ptr output, place to store token
*
* **ptr input, character string to read token from
* output, next position after token
*
* length output, length of token
*
* Returns:
* UPPER,
* LOWER,
* DIGIT,
* EMPTY,
* UNKNOWN.
*/
int i, return_value;
char c;
int Quote = FALSE;
/*
* Read to end of whitespace
*/
while (isspace((int) (c = **ptr)) || (c == ',') || (c == '"'))
{
if (c == '"')
Quote = TRUE;
(*ptr)++;
}
/*
* Check what we have
*/
if (isupper((int) c) || c == '[')
{
return_value = UPPER;
}
else if (islower((int) c))
{
return_value = LOWER;
}
else if (isdigit((int) c) || c == '.' || c == '-')
{
return_value = DIGIT;
}
else if (c == '\0')
{
return_value = EMPTY;
}
else
{
return_value = UNKNOWN;
}
/*
* Begin copying to token
*/
i = 0;
if (Quote == TRUE)
{
while (((int) (c = **ptr) != '"') && c != '\0')
{
token_ptr[i] = c;
(*ptr)++;
i++;
}
}
else
{
while ((!isspace((int) (c = **ptr))) &&
c != ',' && c != ';' && c != '\0')
{
token_ptr[i] = c;
(*ptr)++;
i++;
}
}
token_ptr[i] = '\0';
*length = i;
return (return_value);
}
#endif
/* ---------------------------------------------------------------------- */
int Phreeqc::
dup_print(const char *ptr, int emphasis)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
{ {
/* /*
@ -576,14 +488,14 @@ dup_print(const char *ptr, int emphasis)
if (pr.headings == FALSE) if (pr.headings == FALSE)
return (OK); return (OK);
std::string save_in(ptr); std::string save_in(cptr);
l = (int) strlen(ptr); l = (int) strlen(cptr);
if (emphasis == TRUE) if (emphasis == TRUE)
{ {
std::string dash; std::string dash;
dash.resize(l, '-'); dash.resize(l, '-');
output_msg(sformatf("%s\n%s\n%s\n\n", dash.c_str(), save_in.c_str(), dash)); output_msg(sformatf("%s\n%s\n%s\n\n", dash.c_str(), save_in.c_str(), dash.c_str()));
log_msg(sformatf("%s\n%s\n%s\n\n", dash.c_str(), save_in.c_str(), dash)); log_msg(sformatf("%s\n%s\n%s\n\n", dash.c_str(), save_in.c_str(), dash.c_str()));
} }
else else
{ {
@ -642,22 +554,22 @@ get_token(const char **eqnaddr, char *string, LDBLE * l_z, int *l)
int i, j; int i, j;
int ltoken, lcharge; int ltoken, lcharge;
char c; char c;
char *ptr, *ptr1, *rest; const char* cptr, *ptr1, *rest;
char charge[MAX_LENGTH]; char charge[MAX_LENGTH];
rest = *eqnaddr; rest = *eqnaddr;
ptr = *eqnaddr; cptr = *eqnaddr;
i = 0; i = 0;
/* /*
* Find end of token or begining of charge * Find end of token or begining of charge
*/ */
while (((c = *ptr) != '+') && (c != '-') && (c != '=') && (c != '\0')) while (((c = *cptr) != '+') && (c != '-') && (c != '=') && (c != '\0'))
{ {
string[i++] = c; string[i++] = c;
if (c == '[') if (c == '[')
{ {
ptr++; cptr++;
while ((c = *ptr) != ']') while ((c = *cptr) != ']')
{ {
if (c == '\0') if (c == '\0')
{ {
@ -675,7 +587,7 @@ get_token(const char **eqnaddr, char *string, LDBLE * l_z, int *l)
MAX_LENGTH, string)); MAX_LENGTH, string));
return (ERROR); return (ERROR);
} }
ptr++; cptr++;
} }
string[i++] = c; string[i++] = c;
} }
@ -688,7 +600,7 @@ get_token(const char **eqnaddr, char *string, LDBLE * l_z, int *l)
MAX_LENGTH, string)); MAX_LENGTH, string));
return (ERROR); return (ERROR);
} }
ptr++; cptr++;
} }
string[i] = '\0'; string[i] = '\0';
ltoken = i; ltoken = i;
@ -706,7 +618,7 @@ get_token(const char **eqnaddr, char *string, LDBLE * l_z, int *l)
*/ */
if (c == '=' || c == '\0') if (c == '=' || c == '\0')
{ {
*eqnaddr = ptr; *eqnaddr = cptr;
lcharge = 0; lcharge = 0;
*l_z = 0.0; *l_z = 0.0;
} }
@ -716,7 +628,7 @@ get_token(const char **eqnaddr, char *string, LDBLE * l_z, int *l)
* Copy characters into charge until next species or end is detected * Copy characters into charge until next species or end is detected
*/ */
j = 0; j = 0;
ptr1 = ptr; ptr1 = cptr;
while ((isalpha((int) (c = *ptr1)) == FALSE) && while ((isalpha((int) (c = *ptr1)) == FALSE) &&
(c != '(') && (c != '(') &&
(c != ')') && (c != ')') &&
@ -834,7 +746,7 @@ parse_couple(char *token)
* order. * order.
*/ */
int e1, e2, p1, p2; int e1, e2, p1, p2;
char *ptr; const char* cptr;
char elt1[MAX_LENGTH], elt2[MAX_LENGTH], paren1[MAX_LENGTH], char elt1[MAX_LENGTH], elt2[MAX_LENGTH], paren1[MAX_LENGTH],
paren2[MAX_LENGTH]; paren2[MAX_LENGTH];
@ -844,9 +756,9 @@ parse_couple(char *token)
return (OK); return (OK);
} }
while (replace("+", "", token) == TRUE); while (replace("+", "", token) == TRUE);
ptr = token; cptr = token;
get_elt(&ptr, elt1, &e1); get_elt(&cptr, elt1, &e1);
if (*ptr != '(') if (*cptr != '(')
{ {
error_string = sformatf( "Element name must be followed by " error_string = sformatf( "Element name must be followed by "
"parentheses in redox couple, %s.", token); "parentheses in redox couple, %s.", token);
@ -857,10 +769,10 @@ parse_couple(char *token)
paren_count = 1; paren_count = 1;
paren1[0] = '('; paren1[0] = '(';
p1 = 1; p1 = 1;
while (*ptr != '\0') while (*cptr != '\0')
{ {
ptr++; cptr++;
if (*ptr == '/' || *ptr == '\0') if (*cptr == '/' || *cptr == '\0')
{ {
error_string = sformatf( error_string = sformatf(
"End of line or " "/" "End of line or " "/"
@ -868,17 +780,17 @@ parse_couple(char *token)
error_msg(error_string, CONTINUE); error_msg(error_string, CONTINUE);
return (ERROR); return (ERROR);
} }
paren1[p1++] = *ptr; paren1[p1++] = *cptr;
if (*ptr == '(') if (*cptr == '(')
paren_count++; paren_count++;
if (*ptr == ')') if (*cptr == ')')
paren_count--; paren_count--;
if (paren_count == 0) if (paren_count == 0)
break; break;
} }
paren1[p1] = '\0'; paren1[p1] = '\0';
ptr++; cptr++;
if (*ptr != '/') if (*cptr != '/')
{ {
error_string = sformatf( " " "/" " must follow parentheses " error_string = sformatf( " " "/" " must follow parentheses "
"ending first half of redox couple, %s.", token); "ending first half of redox couple, %s.", token);
@ -886,8 +798,8 @@ parse_couple(char *token)
parse_error++; parse_error++;
return (ERROR); return (ERROR);
} }
ptr++; cptr++;
get_elt(&ptr, elt2, &e2); get_elt(&cptr, elt2, &e2);
if (strcmp(elt1, elt2) != 0) if (strcmp(elt1, elt2) != 0)
{ {
error_string = sformatf( "Redox couple must be two redox states " error_string = sformatf( "Redox couple must be two redox states "
@ -895,7 +807,7 @@ parse_couple(char *token)
error_msg(error_string, CONTINUE); error_msg(error_string, CONTINUE);
return (ERROR); return (ERROR);
} }
if (*ptr != '(') if (*cptr != '(')
{ {
error_string = sformatf( "Element name must be followed by " error_string = sformatf( "Element name must be followed by "
"parentheses in redox couple, %s.", token); "parentheses in redox couple, %s.", token);
@ -906,10 +818,10 @@ parse_couple(char *token)
paren2[0] = '('; paren2[0] = '(';
paren_count = 1; paren_count = 1;
p2 = 1; p2 = 1;
while (*ptr != '\0') while (*cptr != '\0')
{ {
ptr++; cptr++;
if (*ptr == '/' || *ptr == '\0') if (*cptr == '/' || *cptr == '\0')
{ {
error_string = sformatf( "End of line or " "/" " encountered" error_string = sformatf( "End of line or " "/" " encountered"
" before end of parentheses, %s.", token); " before end of parentheses, %s.", token);
@ -917,10 +829,10 @@ parse_couple(char *token)
return (ERROR); return (ERROR);
} }
paren2[p2++] = *ptr; paren2[p2++] = *cptr;
if (*ptr == '(') if (*cptr == '(')
paren_count++; paren_count++;
if (*ptr == ')') if (*cptr == ')')
paren_count--; paren_count--;
if (paren_count == 0) if (paren_count == 0)
break; break;
@ -1003,7 +915,7 @@ replace(const char *str1, const char *str2, char *str)
* FALSE if string was not replaced * FALSE if string was not replaced
*/ */
int l, l1, l2; int l, l1, l2;
char *ptr_start; char* ptr_start;
ptr_start = strstr(str, str1); ptr_start = strstr(str, str1);
/* /*
@ -1028,7 +940,14 @@ replace(const char *str1, const char *str2, char *str)
memcpy(ptr_start, str2, l2); memcpy(ptr_start, str2, l2);
return (TRUE); return (TRUE);
} }
void Phreeqc::
replace(std::string &stds, const char* str1, const char* str2)
{
size_t pos;
while ((pos = stds.find(str1)) != std::string::npos) {
stds.replace(pos, 1, str2);
}
}
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
void Phreeqc:: void Phreeqc::
space(void **ptr, int i, int *max, int struct_size) space(void **ptr, int i, int *max, int struct_size)
@ -1135,7 +1054,7 @@ str_tolower(char *str)
/* /*
* Replaces string, str, with same string, lower case * Replaces string, str, with same string, lower case
*/ */
char *ptr; char* ptr;
ptr = str; ptr = str;
while (*ptr != '\0') while (*ptr != '\0')
{ {
@ -1152,7 +1071,7 @@ str_toupper(char *str)
/* /*
* Replaces string, str, with same string, lower case * Replaces string, str, with same string, lower case
*/ */
char *ptr; char* ptr;
ptr = str; ptr = str;
while (*ptr != '\0') while (*ptr != '\0')
{ {
@ -1460,7 +1379,7 @@ string_trim(char *str)
* EMPTY if string is all whitespace * EMPTY if string is all whitespace
*/ */
int i, l, start, end, length; int i, l, start, end, length;
char *ptr_start; char* ptr_start;
l = (int) strlen(str); l = (int) strlen(str);
/* /*
@ -1494,6 +1413,22 @@ string_trim(char *str)
return (TRUE); return (TRUE);
} }
void Phreeqc::string_trim_left(std::string& str)
{
const std::string& chars = "\t\n ";
str.erase(0, str.find_first_not_of(chars));
}
void Phreeqc::string_trim_right(std::string& str)
{
const std::string& chars = "\t\n ";
str.erase(str.find_last_not_of(chars) + 1);
}
void Phreeqc::string_trim(std::string& str)
{
const std::string& chars = "\t\n ";
str.erase(0, str.find_first_not_of(chars));
str.erase(str.find_last_not_of(chars) + 1);
}
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
int Phreeqc:: int Phreeqc::
@ -1547,7 +1482,7 @@ string_trim_left(char *str)
* EMPTY if string is all whitespace * EMPTY if string is all whitespace
*/ */
int i, l, start, end, length; int i, l, start, end, length;
char *ptr_start; char* ptr_start;
l = (int) strlen(str); l = (int) strlen(str);
/* /*