diff --git a/include/epanet2.h b/include/epanet2.h index ec32e67..36a1f0f 100644 --- a/include/epanet2.h +++ b/include/epanet2.h @@ -75,11 +75,11 @@ extern "C" { int DLLEXPORT ENgettitle(char *line1, char *line2, char *line3); - int DLLEXPORT ENsettitle(char *line1, char *line2, char *line3); + int DLLEXPORT ENsettitle(const char *line1, const char *line2, const char *line3); int DLLEXPORT ENgetcomment(int object, int index, char *comment); - int DLLEXPORT ENsetcomment(int object, int index, char *comment); + int DLLEXPORT ENsetcomment(int object, int index, const char *comment); int DLLEXPORT ENgetcount(int object, int *count); @@ -107,9 +107,9 @@ extern "C" { int DLLEXPORT ENcloseH(); - int DLLEXPORT ENsavehydfile(char *filename); + int DLLEXPORT ENsavehydfile(const char *filename); - int DLLEXPORT ENusehydfile(char *filename); + int DLLEXPORT ENusehydfile(const char *filename); /******************************************************************** @@ -137,17 +137,17 @@ extern "C" { ********************************************************************/ - int DLLEXPORT ENwriteline(char *line); + int DLLEXPORT ENwriteline(const char *line); int DLLEXPORT ENreport(); - int DLLEXPORT ENcopyreport(char *filename); + int DLLEXPORT ENcopyreport(const char *filename); int DLLEXPORT ENclearreport(); int DLLEXPORT ENresetreport(); - int DLLEXPORT ENsetreport(char *format); + int DLLEXPORT ENsetreport(const char *format); int DLLEXPORT ENsetstatusreport(int level); @@ -161,7 +161,7 @@ extern "C" { int DLLEXPORT ENtimetonextevent(int *eventType, long *duration, int *elementIndex); - int DLLEXPORT ENsetreportcallback(void (*callback)(void *userData, void *EN_projectHandle, char*)); + int DLLEXPORT ENsetreportcallback(void (*callback)(void *userData, void *EN_projectHandle, const char*)); int DLLEXPORT ENsetreportcallbackuserdata(void *userData); @@ -188,8 +188,8 @@ extern "C" { int DLLEXPORT ENgetqualtype(int *qualType, int *traceNode); - int DLLEXPORT ENsetqualtype(int qualType, char *chemName, char *chemUnits, - char *traceNode); + int DLLEXPORT ENsetqualtype(int qualType, const char *chemName, + const char *chemUnits, const char *traceNode); /******************************************************************** @@ -197,15 +197,15 @@ extern "C" { ********************************************************************/ - int DLLEXPORT ENaddnode(char *id, int nodeType, int *index); + int DLLEXPORT ENaddnode(const char *id, int nodeType, int *index); int DLLEXPORT ENdeletenode(int index, int actionCode); - int DLLEXPORT ENgetnodeindex(char *id, int *index); + int DLLEXPORT ENgetnodeindex(const char *id, int *index); int DLLEXPORT ENgetnodeid(int index, char *id); - int DLLEXPORT ENsetnodeid(int index, char *newid); + int DLLEXPORT ENsetnodeid(int index, const char *newid); int DLLEXPORT ENgetnodetype(int index, int *nodeType); @@ -214,12 +214,12 @@ extern "C" { int DLLEXPORT ENsetnodevalue(int index, int property, EN_API_FLOAT_TYPE value); int DLLEXPORT ENsetjuncdata(int index, EN_API_FLOAT_TYPE elev, - EN_API_FLOAT_TYPE dmnd, char *dmndpat); + EN_API_FLOAT_TYPE dmnd, const char *dmndpat); int DLLEXPORT ENsettankdata(int index, EN_API_FLOAT_TYPE elev, EN_API_FLOAT_TYPE initlvl, EN_API_FLOAT_TYPE minlvl, EN_API_FLOAT_TYPE maxlvl, EN_API_FLOAT_TYPE diam, - EN_API_FLOAT_TYPE minvol, char *volcurve); + EN_API_FLOAT_TYPE minvol, const char *volcurve); int DLLEXPORT ENgetcoord(int index, double *x, double *y); @@ -238,13 +238,14 @@ extern "C" { EN_API_FLOAT_TYPE preq, EN_API_FLOAT_TYPE pexp); int DLLEXPORT ENadddemand(int nodeIndex, EN_API_FLOAT_TYPE baseDemand, - char *demandPattern, char *demandName); + const char *demandPattern, const char *demandName); int DLLEXPORT ENdeletedemand(int nodeIndex, int demandIndex); int DLLEXPORT ENgetnumdemands(int nodeIndex, int *numDemands); - int DLLEXPORT ENgetdemandindex(int nodeIndex, char *demandName, int *demandIndex); + int DLLEXPORT ENgetdemandindex(int nodeIndex, const char *demandName, + int *demandIndex); int DLLEXPORT ENgetbasedemand(int nodeIndex, int demandIndex, EN_API_FLOAT_TYPE *baseDemand); @@ -258,7 +259,7 @@ extern "C" { int DLLEXPORT ENgetdemandname(int nodeIndex, int demandIndex, char *demandName); - int DLLEXPORT ENsetdemandname(int nodeIndex, int demandIndex, char *demandName); + int DLLEXPORT ENsetdemandname(int nodeIndex, int demandIndex, const char *demandName); /******************************************************************** @@ -266,15 +267,16 @@ extern "C" { ********************************************************************/ - int DLLEXPORT ENaddlink(char *id, int linkType, char *fromNode, char *toNode, int *index); + int DLLEXPORT ENaddlink(const char *id, int linkType, const char *fromNode, + const char *toNode, int *index); int DLLEXPORT ENdeletelink(int index, int actionCode); - int DLLEXPORT ENgetlinkindex(char *id, int *index); + int DLLEXPORT ENgetlinkindex(const char *id, int *index); int DLLEXPORT ENgetlinkid(int index, char *id); - int DLLEXPORT ENsetlinkid(int index, char *newid); + int DLLEXPORT ENsetlinkid(int index, const char *newid); int DLLEXPORT ENgetlinktype(int index, int *linkType); @@ -318,15 +320,15 @@ extern "C" { ********************************************************************/ - int DLLEXPORT ENaddpattern(char *id); + int DLLEXPORT ENaddpattern(const char *id); int DLLEXPORT ENdeletepattern(int index); - int DLLEXPORT ENgetpatternindex(char *id, int *index); + int DLLEXPORT ENgetpatternindex(const char *id, int *index); int DLLEXPORT ENgetpatternid(int index, char *id); - int DLLEXPORT ENsetpatternid(int index, char *id); + int DLLEXPORT ENsetpatternid(int index, const char *id); int DLLEXPORT ENgetpatternlen(int index, int *len); @@ -344,15 +346,15 @@ extern "C" { ********************************************************************/ - int DLLEXPORT ENaddcurve(char *id); + int DLLEXPORT ENaddcurve(const char *id); int DLLEXPORT ENdeletecurve(int index); - int DLLEXPORT ENgetcurveindex(char *id, int *index); + int DLLEXPORT ENgetcurveindex(const char *id, int *index); int DLLEXPORT ENgetcurveid(int index, char *id); - int DLLEXPORT ENsetcurveid(int index, char *id); + int DLLEXPORT ENsetcurveid(int index, const char *id); int DLLEXPORT ENgetcurvelen(int index, int *len); diff --git a/include/epanet2_2.h b/include/epanet2_2.h index 76dea18..62e3d1a 100644 --- a/include/epanet2_2.h +++ b/include/epanet2_2.h @@ -144,7 +144,8 @@ typedef struct Project *EN_Project; @param line3 third title line @return an error code */ - int DLLEXPORT EN_settitle(EN_Project ph, char *line1, char *line2, char *line3); + int DLLEXPORT EN_settitle(EN_Project ph, const char *line1, const char *line2, + const char *line3); /** @brief Retrieves a descriptive comment assigned to a Node, Link, Pattern or Curve. @@ -164,7 +165,8 @@ typedef struct Project *EN_Project; @param comment the comment string assigned to the object @return an error code */ - int DLLEXPORT EN_setcomment(EN_Project ph, int object, int index, char *comment); + int DLLEXPORT EN_setcomment(EN_Project ph, int object, int index, + const char *comment); /** @brief Retrieves the number of objects of a given type in a project. @@ -526,7 +528,7 @@ typedef struct Project *EN_Project; use the userData parameter to pass any client context necessary (a context pointer or wrapper object perhaps). Leave un-set or set the report callback to NULL to revert to EPANET's default behavior. **/ - int DLLEXPORT EN_setreportcallback(EN_Project ph, void (*callback)(void *userData, void *EN_projectHandle, char*)); + int DLLEXPORT EN_setreportcallback(EN_Project ph, void (*callback)(void *userData, void *EN_projectHandle, const char*)); int DLLEXPORT EN_setreportcallbackuserdata(EN_Project ph, void *userData); /** @@ -535,7 +537,7 @@ typedef struct Project *EN_Project; @param line a text string to write. @return an error code. */ - int DLLEXPORT EN_writeline(EN_Project ph, char *line); + int DLLEXPORT EN_writeline(EN_Project ph, const char *line); /** @brief Writes simulation results in a tabular format to a project's report file. @@ -560,7 +562,7 @@ typedef struct Project *EN_Project; This function allows toolkit clients to retrieve the contents of a project's report file while the project is still open. */ - int DLLEXPORT EN_copyreport(EN_Project ph, char *filename); + int DLLEXPORT EN_copyreport(EN_Project ph, const char *filename); /** @brief Clears the contents of a project's report file. @@ -598,7 +600,7 @@ typedef struct Project *EN_Project; Formatted results of a simulation can be written to a project's report file using the ::EN_report function. */ - int DLLEXPORT EN_setreport(EN_Project ph, char *format); + int DLLEXPORT EN_setreport(EN_Project ph, const char *format); /** @brief Sets the level of hydraulic status reporting. @@ -637,7 +639,7 @@ typedef struct Project *EN_Project; @param maxLen maximum number of characters that errmsg can hold @return an error code - Error message strings should be at least @ref EN_SizeLimits "EN_MAXMSG" characters in length. + Error message strings should be greater than @ref EN_SizeLimits "EN_MAXMSG" characters in length. */ int DLLEXPORT EN_geterror(int errcode, char *out_errmsg, int maxLen); @@ -776,8 +778,8 @@ typedef struct Project *EN_Project; Note that the trace node is specified by ID name and not by index. */ - int DLLEXPORT EN_setqualtype(EN_Project ph, int qualType, char *chemName, - char *chemUnits, char *traceNode); + int DLLEXPORT EN_setqualtype(EN_Project ph, int qualType, const char *chemName, + const char *chemUnits, const char *traceNode); /******************************************************************** @@ -795,7 +797,7 @@ typedef struct Project *EN_Project; When a new node is created all of its properties (see @ref EN_NodeProperty) are set to 0. */ - int DLLEXPORT EN_addnode(EN_Project ph, char *id, int nodeType, int *out_index); + int DLLEXPORT EN_addnode(EN_Project ph, const char *id, int nodeType, int *out_index); /** @brief Deletes a node from a project. @@ -819,7 +821,7 @@ typedef struct Project *EN_Project; @param[out] index the node's index (starting from 1). @return an error code */ - int DLLEXPORT EN_getnodeindex(EN_Project ph, char *id, int *out_index); + int DLLEXPORT EN_getnodeindex(EN_Project ph, const char *id, int *out_index); /** @brief Gets the ID name of a node given its index. @@ -828,7 +830,7 @@ typedef struct Project *EN_Project; @param[out] out_id the node's ID name. @return an error code - The ID name must be sized to hold at least @ref EN_SizeLimits "EN_MAXID" characters. + The ID name must be sized to hold at least @ref EN_SizeLimits "EN_MAXID+1" characters. */ int DLLEXPORT EN_getnodeid(EN_Project ph, int index, char *out_id); @@ -841,7 +843,7 @@ typedef struct Project *EN_Project; The ID name must not be longer than @ref EN_SizeLimits "EN_MAXID" characters. */ - int DLLEXPORT EN_setnodeid(EN_Project ph, int index, char *newid); + int DLLEXPORT EN_setnodeid(EN_Project ph, int index, const char *newid); /** @brief Retrieves a node's type given its index. @@ -889,7 +891,7 @@ typedef struct Project *EN_Project; These properties have units that depend on the units used for flow rate (see @ref Units). */ int DLLEXPORT EN_setjuncdata(EN_Project ph, int index, double elev, double dmnd, - char *dmndpat); + const char *dmndpat); /** @brief Sets a group of properties for a tank node. @@ -907,7 +909,7 @@ typedef struct Project *EN_Project; These properties have units that depend on the units used for flow rate (see @ref Units). */ int DLLEXPORT EN_settankdata(EN_Project ph, int index, double elev, double initlvl, - double minlvl, double maxlvl, double diam, double minvol, char *volcurve); + double minlvl, double maxlvl, double diam, double minvol, const char *volcurve); /** @brief Gets the (x,y) coordinates of a node. @@ -985,7 +987,7 @@ typedef struct Project *EN_Project; that no time pattern or category name is associated with the demand. */ int DLLEXPORT EN_adddemand(EN_Project ph, int nodeIndex, double baseDemand, - char *demandPattern, char *demandName); + const char *demandPattern, const char *demandName); /** @brief deletes a demand from a junction node. @@ -1004,7 +1006,7 @@ typedef struct Project *EN_Project; @param[out] demandIndex the index of the demand being sought @return an error code */ - int DLLEXPORT EN_getdemandindex(EN_Project ph, int nodeIndex, char *demandName, + int DLLEXPORT EN_getdemandindex(EN_Project ph, int nodeIndex, const char *demandName, int *out_demandIndex); /** @@ -1073,7 +1075,7 @@ typedef struct Project *EN_Project; @param[out] out_demandName The name of the selected category. @return an error code. - \b demandName must be sized to contain at least @ref EN_SizeLimits "EN_MAXID" characters. + \b demandName must be sized to contain at least @ref EN_SizeLimits "EN_MAXID+1" characters. */ int DLLEXPORT EN_getdemandname(EN_Project ph, int nodeIndex, int demandIndex, char *out_demandName); @@ -1087,7 +1089,8 @@ typedef struct Project *EN_Project; The category name must contain no more than @ref EN_SizeLimits "EN_MAXID" characters. */ - int DLLEXPORT EN_setdemandname(EN_Project ph, int nodeIndex, int demandIdx, char *demandName); + int DLLEXPORT EN_setdemandname(EN_Project ph, int nodeIndex, int demandIdx, + const char *demandName); /******************************************************************** @@ -1120,8 +1123,8 @@ typedef struct Project *EN_Project; See @ref EN_LinkProperty. */ - int DLLEXPORT EN_addlink(EN_Project ph, char *id, int linkType, char *fromNode, - char *toNode, int *out_index); + int DLLEXPORT EN_addlink(EN_Project ph, const char *id, int linkType, const char *fromNode, + const char *toNode, int *out_index); /** @brief Deletes a link from the project. @@ -1143,7 +1146,7 @@ typedef struct Project *EN_Project; @param[out] index the link's index (starting from 1). @return an error code. */ - int DLLEXPORT EN_getlinkindex(EN_Project ph, char *id, int *out_index); + int DLLEXPORT EN_getlinkindex(EN_Project ph, const char *id, int *out_index); /** @brief Gets the ID name of a link given its index. @@ -1152,7 +1155,7 @@ typedef struct Project *EN_Project; @param[out] out_id The link's ID name. @return an error code. - The ID name must be sized to hold at least @ref EN_SizeLimits "EN_MAXID" characters. + The ID name must be sized to hold at least @ref EN_SizeLimits "EN_MAXID+1" characters. */ int DLLEXPORT EN_getlinkid(EN_Project ph, int index, char *out_id); @@ -1165,7 +1168,7 @@ typedef struct Project *EN_Project; The ID name must not be longer than @ref EN_SizeLimits "EN_MAXID" characters. */ - int DLLEXPORT EN_setlinkid(EN_Project ph, int index, char *newid); + int DLLEXPORT EN_setlinkid(EN_Project ph, int index, const char *newid); /** @brief Retrieves a link's type. @@ -1341,7 +1344,7 @@ typedef struct Project *EN_Project; The new pattern contains a single time period whose factor is 1.0. */ - int DLLEXPORT EN_addpattern(EN_Project ph, char *id); + int DLLEXPORT EN_addpattern(EN_Project ph, const char *id); /** @brief Deletes a time pattern from a project. @@ -1358,7 +1361,7 @@ typedef struct Project *EN_Project; @param[out] index the time pattern's index (starting from 1). @return an error code. */ - int DLLEXPORT EN_getpatternindex(EN_Project ph, char *id, int *out_index); + int DLLEXPORT EN_getpatternindex(EN_Project ph, const char *id, int *out_index); /** @brief Retrieves the ID name of a time pattern given its index. @@ -1367,7 +1370,7 @@ typedef struct Project *EN_Project; @param[out] out_id the time pattern's ID name. @return an error code. - The ID name must be sized to hold at least @ref EN_SizeLimits "EN_MAXID" characters. + The ID name must be sized to hold at least @ref EN_SizeLimits "EN_MAXID+1" characters. */ int DLLEXPORT EN_getpatternid(EN_Project ph, int index, char *out_id); @@ -1380,7 +1383,7 @@ typedef struct Project *EN_Project; The new ID name must not exceed @ref EN_SizeLimits "EN_MAXID" characters. */ - int DLLEXPORT EN_setpatternid(EN_Project ph, int index, char *id); + int DLLEXPORT EN_setpatternid(EN_Project ph, int index, const char *id); /** @brief Retrieves the number of time periods in a time pattern. @@ -1449,7 +1452,7 @@ typedef struct Project *EN_Project; The new curve contains a single data point (1.0, 1.0). */ - int DLLEXPORT EN_addcurve(EN_Project ph, char *id); + int DLLEXPORT EN_addcurve(EN_Project ph, const char *id); /** @brief Deletes a data curve from a project. @@ -1466,7 +1469,7 @@ typedef struct Project *EN_Project; @param[out] index The curve's index (starting from 1). @return an error code. */ - int DLLEXPORT EN_getcurveindex(EN_Project ph, char *id, int *out_index); + int DLLEXPORT EN_getcurveindex(EN_Project ph, const char *id, int *out_index); /** @brief Retrieves the ID name of a curve given its index. @@ -1475,7 +1478,7 @@ typedef struct Project *EN_Project; @param[out] out_id the curve's ID name. @return an error code. - The ID name must be sized to hold at least @ref EN_SizeLimits "EN_MAXID" characters. + The ID name must be sized to hold at least @ref EN_SizeLimits "EN_MAXID+1" characters. */ int DLLEXPORT EN_getcurveid(EN_Project ph, int index, char *out_id); @@ -1488,7 +1491,7 @@ typedef struct Project *EN_Project; The new ID name must not exceed @ref EN_SizeLimits "EN_MAXID" characters. */ - int DLLEXPORT EN_setcurveid(EN_Project ph, int index, char *id); + int DLLEXPORT EN_setcurveid(EN_Project ph, int index, const char *id); /** @brief Retrieves the number of points in a curve. @@ -1553,7 +1556,7 @@ typedef struct Project *EN_Project; The calling program is responsible for making `xValues` and `yValues` large enough to hold `nPoints` number of data points and for sizing `id` to hold at least - @ref EN_SizeLimits "EN_MAXID" characters. + @ref EN_SizeLimits "EN_MAXID+1" characters. */ int DLLEXPORT EN_getcurve(EN_Project ph, int index, char *out_id, int *out_nPoints, double *out_xValues, double *out_yValues); @@ -1683,7 +1686,7 @@ typedef struct Project *EN_Project; @param[out] out_id the rule's ID name. @return Error code. - The ID name must be sized to hold at least @ref EN_SizeLimits "EN_MAXID" characters. + The ID name must be sized to hold at least @ref EN_SizeLimits "EN_MAXID+1" characters. */ int DLLEXPORT EN_getruleID(EN_Project ph, int index, char *out_id); diff --git a/src/epanet.c b/src/epanet.c index 6516f7a..d9e0280 100644 --- a/src/epanet.c +++ b/src/epanet.c @@ -251,7 +251,8 @@ int DLLEXPORT EN_gettitle(EN_Project p, char *line1, char *line2, char *line3) return 0; } -int DLLEXPORT EN_settitle(EN_Project p, char *line1, char *line2, char *line3) +int DLLEXPORT EN_settitle(EN_Project p, const char *line1, + const char *line2, const char *line3) /*---------------------------------------------------------------- ** Input: line1, line2, line3 = project's title lines ** Returns: error code @@ -279,7 +280,8 @@ int DLLEXPORT EN_getcomment(EN_Project p, int object, int index, char *comment) return getcomment(&p->network, object, index, comment); } -int DLLEXPORT EN_setcomment(EN_Project p, int object, int index, char *comment) +int DLLEXPORT EN_setcomment(EN_Project p, int object, int index, + const char *comment) /*---------------------------------------------------------------- ** Input: object = a type of object (see EN_ObjectType) ** index = the object's index @@ -842,7 +844,7 @@ int DLLEXPORT EN_closeQ(EN_Project p) ********************************************************************/ - int DLLEXPORT EN_setreportcallback(EN_Project p, void (*callback)(void*,void*,char*)) + int DLLEXPORT EN_setreportcallback(EN_Project p, void (*callback)(void*,void*,const char*)) { p->report.reportCallback = callback; return 0; @@ -854,7 +856,7 @@ int DLLEXPORT EN_closeQ(EN_Project p) return 0; } -int DLLEXPORT EN_writeline(EN_Project p, char *line) +int DLLEXPORT EN_writeline(EN_Project p, const char *line) /*---------------------------------------------------------------- ** Input: line = line of text ** Output: none @@ -890,7 +892,7 @@ int DLLEXPORT EN_report(EN_Project p) return errcode; } -int DLLEXPORT EN_copyreport(EN_Project p, char *filename) +int DLLEXPORT EN_copyreport(EN_Project p, const char *filename) /*---------------------------------------------------------------- ** Input: filename = name of file to receive copy of report ** Output: none @@ -939,7 +941,7 @@ int DLLEXPORT EN_resetreport(EN_Project p) return 0; } -int DLLEXPORT EN_setreport(EN_Project p, char *format) +int DLLEXPORT EN_setreport(EN_Project p, const char *format) /*---------------------------------------------------------------- ** Input: format = a report formatting command ** Output: none @@ -1714,8 +1716,8 @@ int DLLEXPORT EN_getqualtype(EN_Project p, int *qualType, int *traceNode) return 0; } -int DLLEXPORT EN_setqualtype(EN_Project p, int qualType, char *chemName, - char *chemUnits, char *traceNode) +int DLLEXPORT EN_setqualtype(EN_Project p, int qualType, const char *chemName, + const char *chemUnits, const char *traceNode) /*---------------------------------------------------------------- ** Input: qualType = type of quality analysis to run (see EN_QualityType) ** chemname = name of chemical constituent @@ -1794,7 +1796,7 @@ int DLLEXPORT EN_setqualtype(EN_Project p, int qualType, char *chemName, ********************************************************************/ -int DLLEXPORT EN_addnode(EN_Project p, char *id, int nodeType, int *index) +int DLLEXPORT EN_addnode(EN_Project p, const char *id, int nodeType, int *index) /*---------------------------------------------------------------- ** Input: id = node ID name ** nodeType = type of node (see EN_NodeType) @@ -2043,7 +2045,7 @@ int DLLEXPORT EN_deletenode(EN_Project p, int index, int actionCode) return 0; } -int DLLEXPORT EN_getnodeindex(EN_Project p, char *id, int *index) +int DLLEXPORT EN_getnodeindex(EN_Project p, const char *id, int *index) /*---------------------------------------------------------------- ** Input: id = node ID name ** Output: index = node index @@ -2075,7 +2077,7 @@ int DLLEXPORT EN_getnodeid(EN_Project p, int index, char *id) return 0; } -int DLLEXPORT EN_setnodeid(EN_Project p, int index, char *newid) +int DLLEXPORT EN_setnodeid(EN_Project p, int index, const char *newid) /*---------------------------------------------------------------- ** Input: index = node index ** newid = new node ID name @@ -2618,7 +2620,7 @@ int DLLEXPORT EN_setnodevalue(EN_Project p, int index, int property, double valu } int DLLEXPORT EN_setjuncdata(EN_Project p, int index, double elev, - double dmnd, char *dmndpat) + double dmnd, const char *dmndpat) /*---------------------------------------------------------------- ** Input: index = junction node index ** elev = junction elevation @@ -2663,7 +2665,7 @@ int DLLEXPORT EN_setjuncdata(EN_Project p, int index, double elev, int DLLEXPORT EN_settankdata(EN_Project p, int index, double elev, double initlvl, double minlvl, double maxlvl, double diam, - double minvol, char *volcurve) + double minvol, const char *volcurve) /*---------------------------------------------------------------- ** Input: index = tank node index ** elev = tank bottom elevation @@ -2839,7 +2841,7 @@ int DLLEXPORT EN_setdemandmodel(EN_Project p, int model, double pmin, } int DLLEXPORT EN_adddemand(EN_Project p, int nodeIndex, double baseDemand, - char *demandPattern, char *demandName) + const char *demandPattern, const char *demandName) /*---------------------------------------------------------------- ** Input: nodeIndex = node index ** baseDemand = baseline demand value @@ -2926,7 +2928,7 @@ int DLLEXPORT EN_deletedemand(EN_Project p, int nodeIndex, int demandIndex) return 0; } -int DLLEXPORT EN_getdemandindex(EN_Project p, int nodeIndex, char *demandName, +int DLLEXPORT EN_getdemandindex(EN_Project p, int nodeIndex, const char *demandName, int *demandIndex) /*---------------------------------------------------------------- ** Input: nodeIndex = node index @@ -3075,7 +3077,7 @@ int DLLEXPORT EN_getdemandname(EN_Project p, int nodeIndex, int demandIndex, } int DLLEXPORT EN_setdemandname(EN_Project p, int nodeIndex, int demandIndex, - char *demandName) + const char *demandName) /*---------------------------------------------------------------- ** Input: nodeIndex = node index ** demandIndex = demand category index @@ -3165,8 +3167,8 @@ int DLLEXPORT EN_setdemandpattern(EN_Project p, int nodeIndex, int demandIndex, ********************************************************************/ -int DLLEXPORT EN_addlink(EN_Project p, char *id, int linkType, - char *fromNode, char *toNode, int *index) +int DLLEXPORT EN_addlink(EN_Project p, const char *id, int linkType, + const char *fromNode, const char *toNode, int *index) /*---------------------------------------------------------------- ** Input: id = link ID name ** type = link type (see EN_LinkType) @@ -3416,7 +3418,7 @@ int DLLEXPORT EN_deletelink(EN_Project p, int index, int actionCode) return 0; } -int DLLEXPORT EN_getlinkindex(EN_Project p, char *id, int *index) +int DLLEXPORT EN_getlinkindex(EN_Project p, const char *id, int *index) /*---------------------------------------------------------------- ** Input: id = link ID name ** Output: index = link index @@ -3448,7 +3450,7 @@ int DLLEXPORT EN_getlinkid(EN_Project p, int index, char *id) return 0; } -int DLLEXPORT EN_setlinkid(EN_Project p, int index, char *newid) +int DLLEXPORT EN_setlinkid(EN_Project p, int index, const char *newid) /*---------------------------------------------------------------- ** Input: index = link index ** id = link ID name @@ -4376,7 +4378,7 @@ int DLLEXPORT EN_setheadcurveindex(EN_Project p, int linkIndex, int curveIndex) ********************************************************************/ -int DLLEXPORT EN_addpattern(EN_Project p, char *id) +int DLLEXPORT EN_addpattern(EN_Project p, const char *id) /*---------------------------------------------------------------- ** Input: id = time pattern ID name ** Output: none @@ -4468,7 +4470,7 @@ int DLLEXPORT EN_deletepattern(EN_Project p, int index) return 0; } -int DLLEXPORT EN_getpatternindex(EN_Project p, char *id, int *index) +int DLLEXPORT EN_getpatternindex(EN_Project p, const char *id, int *index) /*---------------------------------------------------------------- ** Input: id = time pattern name ** Output: index = time pattern index @@ -4509,7 +4511,7 @@ int DLLEXPORT EN_getpatternid(EN_Project p, int index, char *id) return 0; } -int DLLEXPORT EN_setpatternid(EN_Project p, int index, char *id) +int DLLEXPORT EN_setpatternid(EN_Project p, int index, const char *id) /*---------------------------------------------------------------- ** Input: index = time pattern index ** id = time pattern ID name @@ -4653,7 +4655,7 @@ int DLLEXPORT EN_setpattern(EN_Project p, int index, double *values, int len) ********************************************************************/ -int DLLEXPORT EN_addcurve(EN_Project p, char *id) +int DLLEXPORT EN_addcurve(EN_Project p, const char *id) /*---------------------------------------------------------------- ** Input: id = data curve ID name ** Output: none @@ -4745,7 +4747,7 @@ int DLLEXPORT EN_deletecurve(EN_Project p, int index) return 0; } -int DLLEXPORT EN_getcurveindex(EN_Project p, char *id, int *index) +int DLLEXPORT EN_getcurveindex(EN_Project p, const char *id, int *index) /*---------------------------------------------------------------- ** Input: id = data curve name ** Output: index = data curve index @@ -4777,7 +4779,7 @@ int DLLEXPORT EN_getcurveid(EN_Project p, int index, char *id) return 0; } -int DLLEXPORT EN_setcurveid(EN_Project p, int index, char *id) +int DLLEXPORT EN_setcurveid(EN_Project p, int index, const char *id) /*---------------------------------------------------------------- ** Input: index = data curve index ** id = data curve ID name diff --git a/src/epanet2.c b/src/epanet2.c index be16f6a..53d1732 100644 --- a/src/epanet2.c +++ b/src/epanet2.c @@ -104,7 +104,7 @@ int DLLEXPORT ENgettitle(char *line1, char *line2, char *line3) return EN_gettitle(_defaultProject, line1, line2, line3) ; } -int DLLEXPORT ENsettitle(char *line1, char *line2, char *line3) +int DLLEXPORT ENsettitle(const char *line1, const char *line2, const char *line3) { return EN_settitle(_defaultProject, line1, line2, line3) ; } @@ -114,7 +114,7 @@ int DLLEXPORT ENgetcomment(int object, int index, char *comment) return EN_getcomment(_defaultProject, object, index, comment); } -int DLLEXPORT ENsetcomment(int object, int index, char *comment) +int DLLEXPORT ENsetcomment(int object, int index, const char *comment) { return EN_setcomment(_defaultProject, object, index, comment); } @@ -156,12 +156,12 @@ int DLLEXPORT ENnextH(long *tStep) { return EN_nextH(_defaultProject, tStep); } int DLLEXPORT ENcloseH() { return EN_closeH(_defaultProject); } -int DLLEXPORT ENsavehydfile(char *filename) +int DLLEXPORT ENsavehydfile(const char *filename) { return EN_savehydfile(_defaultProject, filename); } -int DLLEXPORT ENusehydfile(char *filename) +int DLLEXPORT ENusehydfile(const char *filename) { return EN_usehydfile(_defaultProject, filename); } @@ -192,11 +192,11 @@ int DLLEXPORT ENcloseQ() { return EN_closeQ(_defaultProject); } ********************************************************************/ -int DLLEXPORT ENwriteline(char *line) { return EN_writeline(_defaultProject, line); } +int DLLEXPORT ENwriteline(const char *line) { return EN_writeline(_defaultProject, line); } int DLLEXPORT ENreport() { return EN_report(_defaultProject); } -int DLLEXPORT ENcopyreport(char *filename) +int DLLEXPORT ENcopyreport(const char *filename) { return EN_copyreport(_defaultProject, filename); } @@ -205,14 +205,14 @@ int DLLEXPORT ENclearreport() { return EN_clearreport(_defaultProject); } int DLLEXPORT ENresetreport() { return EN_resetreport(_defaultProject); } -int DLLEXPORT ENsetreport(char *format) { return EN_setreport(_defaultProject, format); } +int DLLEXPORT ENsetreport(const char *format) { return EN_setreport(_defaultProject, format); } int DLLEXPORT ENsetstatusreport(int level) { return EN_setstatusreport(_defaultProject, level); } -int DLLEXPORT ENsetreportcallback(void (*callback)(void *userData, void *EN_projectHandle, char*)) +int DLLEXPORT ENsetreportcallback(void (*callback)(void *userData, void *EN_projectHandle, const char*)) { return EN_setreportcallback(_defaultProject, callback); } @@ -297,8 +297,8 @@ int DLLEXPORT ENgetqualtype(int *qualType, int *traceNode) return EN_getqualtype(_defaultProject, qualType, traceNode); } -int DLLEXPORT ENsetqualtype(int qualType, char *chemName, char *chemUnits, - char *traceNode) +int DLLEXPORT ENsetqualtype(int qualType, const char *chemName, + const char *chemUnits, const char *traceNode) { return EN_setqualtype(_defaultProject, qualType, chemName, chemUnits, traceNode); } @@ -309,7 +309,7 @@ int DLLEXPORT ENsetqualtype(int qualType, char *chemName, char *chemUnits, ********************************************************************/ -int DLLEXPORT ENaddnode(char *id, int nodeType, int *index) +int DLLEXPORT ENaddnode(const char *id, int nodeType, int *index) { return EN_addnode(_defaultProject, id, nodeType, index); } @@ -319,7 +319,7 @@ int DLLEXPORT ENdeletenode(int index, int actionCode) return EN_deletenode(_defaultProject, index, actionCode); } -int DLLEXPORT ENgetnodeindex(char *id, int *index) +int DLLEXPORT ENgetnodeindex(const char *id, int *index) { return EN_getnodeindex(_defaultProject, id, index); } @@ -329,7 +329,7 @@ int DLLEXPORT ENgetnodeid(int index, char *id) return EN_getnodeid(_defaultProject, index, id); } -int DLLEXPORT ENsetnodeid(int index, char *newid) +int DLLEXPORT ENsetnodeid(int index, const char *newid) { return EN_setnodeid(_defaultProject, index, newid); } @@ -353,7 +353,7 @@ int DLLEXPORT ENsetnodevalue(int index, int property, EN_API_FLOAT_TYPE value) } int DLLEXPORT ENsetjuncdata(int index, EN_API_FLOAT_TYPE elev, EN_API_FLOAT_TYPE dmnd, - char *dmndpat) + const char *dmndpat) { return EN_setjuncdata(_defaultProject, index, elev, dmnd, dmndpat); } @@ -361,7 +361,7 @@ int DLLEXPORT ENsetjuncdata(int index, EN_API_FLOAT_TYPE elev, EN_API_FLOAT_TYPE int DLLEXPORT ENsettankdata(int index, EN_API_FLOAT_TYPE elev, EN_API_FLOAT_TYPE initlvl, EN_API_FLOAT_TYPE minlvl, EN_API_FLOAT_TYPE maxlvl, EN_API_FLOAT_TYPE diam, - EN_API_FLOAT_TYPE minvol, char *volcurve) + EN_API_FLOAT_TYPE minvol, const char *volcurve) { return EN_settankdata(_defaultProject, index, elev, initlvl, minlvl, maxlvl, diam, minvol, volcurve); @@ -401,7 +401,7 @@ int DLLEXPORT ENsetdemandmodel(int model, EN_API_FLOAT_TYPE pmin, } int DLLEXPORT ENadddemand(int nodeIndex, EN_API_FLOAT_TYPE baseDemand, - char *demandPattern, char *demandName) + const char *demandPattern, const char *demandName) { return EN_adddemand(_defaultProject, nodeIndex, baseDemand, demandPattern, demandName); } @@ -411,7 +411,7 @@ int DLLEXPORT ENdeletedemand(int nodeIndex, int demandIndex) return EN_deletedemand(_defaultProject, nodeIndex, demandIndex); } -int DLLEXPORT ENgetdemandindex(int nodeIndex, char *demandName, int *demandIndex) +int DLLEXPORT ENgetdemandindex(int nodeIndex, const char *demandName, int *demandIndex) { return EN_getdemandindex(_defaultProject, nodeIndex, demandName, demandIndex); } @@ -451,7 +451,7 @@ int DLLEXPORT ENgetdemandname(int nodeIndex, int demandIndex, char *demandName) return EN_getdemandname(_defaultProject, nodeIndex, demandIndex, demandName); } -int DLLEXPORT ENsetdemandname(int nodeIndex, int demandIndex, char *demandName) +int DLLEXPORT ENsetdemandname(int nodeIndex, int demandIndex, const char *demandName) { return EN_setdemandname(_defaultProject, nodeIndex, demandIndex, demandName); } @@ -462,7 +462,8 @@ int DLLEXPORT ENsetdemandname(int nodeIndex, int demandIndex, char *demandName) ********************************************************************/ -int DLLEXPORT ENaddlink(char *id, int linkType, char *fromNode, char *toNode, int *index) +int DLLEXPORT ENaddlink(const char *id, int linkType, const char *fromNode, + const char *toNode, int *index) { return EN_addlink(_defaultProject, id, linkType, fromNode, toNode, index); } @@ -472,7 +473,7 @@ int DLLEXPORT ENdeletelink(int index, int actionCode) return EN_deletelink(_defaultProject, index, actionCode); } -int DLLEXPORT ENgetlinkindex(char *id, int *index) +int DLLEXPORT ENgetlinkindex(const char *id, int *index) { return EN_getlinkindex(_defaultProject, id, index); } @@ -482,7 +483,7 @@ int DLLEXPORT ENgetlinkid(int index, char *id) return EN_getlinkid(_defaultProject, index, id); } -int DLLEXPORT ENsetlinkid(int index, char *newid) +int DLLEXPORT ENsetlinkid(int index, const char *newid) { return EN_setlinkid(_defaultProject, index, newid); } @@ -573,7 +574,7 @@ int DLLEXPORT ENsetheadcurveindex(int linkIndex, int curveIndex) ********************************************************************/ -int DLLEXPORT ENaddpattern(char *id) +int DLLEXPORT ENaddpattern(const char *id) { return EN_addpattern(_defaultProject, id); } @@ -583,7 +584,7 @@ int DLLEXPORT ENdeletepattern(int index) return EN_deletepattern(_defaultProject, index); } -int DLLEXPORT ENgetpatternindex(char *id, int *index) +int DLLEXPORT ENgetpatternindex(const char *id, int *index) { return EN_getpatternindex(_defaultProject, id, index); } @@ -593,7 +594,7 @@ int DLLEXPORT ENgetpatternid(int index, char *id) return EN_getpatternid(_defaultProject, index, id); } -int DLLEXPORT ENsetpatternid(int index, char *id) +int DLLEXPORT ENsetpatternid(int index, const char *id) { return EN_setpatternid(_defaultProject, index, id); } @@ -646,7 +647,7 @@ int DLLEXPORT ENsetpattern(int index, EN_API_FLOAT_TYPE *values, int len) ********************************************************************/ -int DLLEXPORT ENaddcurve(char *id) +int DLLEXPORT ENaddcurve(const char *id) { return EN_addcurve(_defaultProject, id); } @@ -656,7 +657,7 @@ int DLLEXPORT ENdeletecurve(int index) return EN_deletecurve(_defaultProject, index); } -int DLLEXPORT ENgetcurveindex(char *id, int *index) +int DLLEXPORT ENgetcurveindex(const char *id, int *index) { return EN_getcurveindex(_defaultProject, id, index); } @@ -666,7 +667,7 @@ int DLLEXPORT ENgetcurveid(int index, char *id) return EN_getcurveid(_defaultProject, index, id); } -int DLLEXPORT ENsetcurveid(int index, char *id) +int DLLEXPORT ENsetcurveid(int index, const char *id) { return EN_setcurveid(_defaultProject, index, id); } diff --git a/src/funcs.h b/src/funcs.h index 69d3f81..2391477 100755 --- a/src/funcs.h +++ b/src/funcs.h @@ -31,16 +31,16 @@ int incontrols(Project *, int, int); int valvecheck(Project *, int, int, int, int); int unlinked(Project *); -int findnode(Network *, char *); -int findlink(Network *, char *); +int findnode(Network *, const char *); +int findlink(Network *, const char *); int findtank(Network *, int); int findvalve(Network *, int); int findpump(Network *, int); -int findpattern(Network *, char *); -int findcurve(Network *, char *); +int findpattern(Network *, const char *); +int findcurve(Network *, const char *); Pdemand finddemand(Pdemand, int); -int adddemand(Snode *, double, int, char *); +int adddemand(Snode *, double, int, const char *); void freedemands(Snode *); int addlinkvertex(Slink *, double, double); @@ -128,13 +128,13 @@ int checkrules(Project *, long); // ------- REPORT.C ----------------- int clearreport(Project *); -int copyreport(Project *, char *); +int copyreport(Project *, const char *); int writereport(Project *); void writelogo(Project *); void writesummary(Project *); void writehydstat(Project *, int, double); void writeheader(Project *, int,int); -void writeline(Project *, char *); +void writeline(Project *, const char *); void writerelerr(Project *, int, double); void writestatchange(Project *, int,char,char); void writecontrolaction(Project *, int, int); diff --git a/src/hash.c b/src/hash.c index 4e0099b..411c8ed 100755 --- a/src/hash.c +++ b/src/hash.c @@ -26,7 +26,7 @@ typedef struct DataEntryStruct } DataEntry; // Hash a string to an integer -unsigned int gethash(char *str) +unsigned int gethash(const char *str) { unsigned int hash = 5381; unsigned int retHash; @@ -61,7 +61,7 @@ HashTable *hashtable_create() } // Insert an entry into the hash table -int hashtable_insert(HashTable *ht, char *key, int data) +int hashtable_insert(HashTable *ht, const char *key, int data) { unsigned int i = gethash(key); DataEntry *entry; @@ -76,7 +76,7 @@ int hashtable_insert(HashTable *ht, char *key, int data) } // Change the hash table's data entry for a particular key -int hashtable_update(HashTable *ht, char *key, int new_data) +int hashtable_update(HashTable *ht, const char *key, int new_data) { unsigned int i = gethash(key); DataEntry *entry; @@ -96,7 +96,7 @@ int hashtable_update(HashTable *ht, char *key, int new_data) } // Delete an entry in the hash table -int hashtable_delete(HashTable *ht, char *key) +int hashtable_delete(HashTable *ht, const char *key) { unsigned int i = gethash(key); DataEntry *entry, *preventry; @@ -122,7 +122,7 @@ int hashtable_delete(HashTable *ht, char *key) } // Find the data for a particular key -int hashtable_find(HashTable *ht, char *key) +int hashtable_find(HashTable *ht, const char *key) { unsigned int i = gethash(key); DataEntry *entry; @@ -141,7 +141,7 @@ int hashtable_find(HashTable *ht, char *key) } // Find a particular key in the hash table -char *hashtable_findkey(HashTable *ht, char *key) +char *hashtable_findkey(HashTable *ht, const char *key) { unsigned int i = gethash(key); DataEntry *entry; diff --git a/src/hash.h b/src/hash.h index c847e00..feec4d0 100755 --- a/src/hash.h +++ b/src/hash.h @@ -18,11 +18,11 @@ typedef struct DataEntryStruct *HashTable; HashTable *hashtable_create(void); -int hashtable_insert(HashTable *, char *, int); -int hashtable_find(HashTable *, char *); -char *hashtable_findkey(HashTable *, char *); +int hashtable_insert(HashTable *, const char *, int); +int hashtable_find(HashTable *, const char *); +char *hashtable_findkey(HashTable *, const char *); void hashtable_free(HashTable *); -int hashtable_update(HashTable *ht, char *key, int new_data); -int hashtable_delete(HashTable *ht, char *key); +int hashtable_update(HashTable *ht, const char *key, int new_data); +int hashtable_delete(HashTable *ht, const char *key); #endif diff --git a/src/project.c b/src/project.c index 2aefa21..d5eee6c 100644 --- a/src/project.c +++ b/src/project.c @@ -492,7 +492,7 @@ Pdemand finddemand(Pdemand d, int index) return d; } -int adddemand(Snode *node, double dbase, int dpat, char *dname) +int adddemand(Snode *node, double dbase, int dpat, const char *dname) /*---------------------------------------------------------------- ** Input: node = a network junction node ** dbase = base demand value @@ -834,7 +834,7 @@ int unlinked(Project *pr) return 0; } -int findnode(Network *network, char *id) +int findnode(Network *network, const char *id) /*---------------------------------------------------------------- ** Input: id = node ID ** Output: none @@ -846,7 +846,7 @@ int findnode(Network *network, char *id) return (hashtable_find(network->NodeHashTable, id)); } -int findlink(Network *network, char *id) +int findlink(Network *network, const char *id) /*---------------------------------------------------------------- ** Input: id = link ID ** Output: none @@ -909,7 +909,7 @@ int findvalve(Network *network, int index) return NOTFOUND; } -int findpattern(Network *network, char *id) +int findpattern(Network *network, const char *id) /*---------------------------------------------------------------- ** Input: id = time pattern ID ** Output: none @@ -928,7 +928,7 @@ int findpattern(Network *network, char *id) return -1; } -int findcurve(Network *network, char *id) +int findcurve(Network *network, const char *id) /*---------------------------------------------------------------- ** Input: id = data curve ID ** Output: none diff --git a/src/report.c b/src/report.c index ae675da..14f55cf 100644 --- a/src/report.c +++ b/src/report.c @@ -67,7 +67,7 @@ int clearreport(Project *pr) return 0; } -int copyreport(Project* pr, char *filename) +int copyreport(Project* pr, const char *filename) /* **------------------------------------------------------ ** Input: filename = name of file to copy to @@ -876,7 +876,7 @@ void writeheader(Project *pr, int type, int contin) } } -void writeline(Project *pr, char *s) +void writeline(Project *pr, const char *s) /* **-------------------------------------------------------------- ** Input: *s = text string diff --git a/src/types.h b/src/types.h index e719c6b..02634e7 100755 --- a/src/types.h +++ b/src/types.h @@ -634,7 +634,7 @@ typedef struct { SField Field[MAXVAR]; // Output reporting fields - void (*reportCallback)(void*,void*,char*); // user-supplied reporting callback + void (*reportCallback)(void*,void*,const char*); // user-supplied reporting callback void *reportCallbackUserData; // user-supplied reporting context } Report;