undone Warnflag declaration due to cl.exe incompatibilities , now Warnflag is retuned with errorcode

This commit is contained in:
mauriziocingi
2015-11-20 13:35:40 +01:00
parent 3151805675
commit ea08fb9da1
4 changed files with 62 additions and 30 deletions

View File

@@ -52,7 +52,7 @@ epanet_heads=enumstxt.h funcs.h hash.h mempool.h text.h types.h vars.h epanet2.h
# Epanet main program
epanet_main=main
# Epanet main program header files
epanet_main_heads=epanet2.h text.h
epanet_main_heads=epanet2.h
.PHONY: all
all: $(libname) $(exename)

View File

@@ -36,7 +36,6 @@
// --- define DLLEXPORT
#ifndef DLLEXPORT
#ifdef WINDOWS
#define DLLDATA __declspec(dllexport)
#ifdef __cplusplus
#define DLLEXPORT extern "C" __declspec(dllexport)
#else
@@ -54,9 +53,6 @@
#define DLLEXPORT
#endif
#endif
#ifndef DLLDATA
#define DLLDATA
#endif
// --- Define the EPANET toolkit constants
@@ -287,7 +283,6 @@ extern "C" {
int DLLEXPORT ENsetcurvevalue(int index, int pnt, EN_API_FLOAT_TYPE x, EN_API_FLOAT_TYPE y);
int DLLEXPORT ENsetcurve(int index, EN_API_FLOAT_TYPE *x, EN_API_FLOAT_TYPE *y, int len);
int DLLEXPORT ENaddcurve(char *id);
char DLLDATA Warnflag;
#if defined(__cplusplus)
}

View File

@@ -1,10 +1,17 @@
#include <stdio.h>
#include <string.h>
#include "epanet2.h"
#include "text.h"
/* text copied here, no more need of include "text.h" */
#define FMT01 "\n... EPANET Version %d.%d.%d\n"
#define FMT03 "\n Correct syntax is:\n epanet <input file> <output file>\n"
#define FMT09 "\n... EPANET completed.\n"
#define FMT10 "\n... EPANET completed. There are warnings."
#define FMT11 "\n... EPANET completed. There are errors."
void writeConsole(char *s);
extern char Warnflag;
/*
----------------------------------------------------------------
@@ -23,40 +30,70 @@ int main(int argc, char *argv[])
** Command line for stand-alone operation is:
** progname f1 f2 f3
** where progname = name of executable this code was compiled to,
** f1 = name of input file, f2 = name of report file, and
** f3 = name of binary output file (optional).
** f1 = name of input file,
** f2 = name of report file (optional, stdout if left blank)
** f3 = name of binary output file (optional, nullfile if left blank).
**--------------------------------------------------------------
*/
{
char *f1,*f2,*f3;
char blank[] = "";
char errmsg[40];
int errcode;
int version;
char s[25];
/* Check for proper number of command line arguments */
if (argc < 3) {
if (argc < 2) {
writeConsole(FMT03);
}
else {
/* Call the main control function */
f1 = argv[1];
f2 = argv[2];
if (argc > 2) {
f2 = argv[2];
}
else {
f2 = blank;
}
if (argc > 3) {
f3 = argv[3];
}
else {
f3 = blank;
}
writeConsole(FMT01);
errcode = ENepanet(f1,f2,f3,NULL);
if (errcode > 0) {
writeConsole(FMT11);
}
else if (Warnflag > 0) {
writeConsole(FMT10);
}
else {
writeConsole(FMT09);
}
}
/* get version from DLL and trasform in Major.Minor.Patch format
instead of hardcoded version */
ENgetversion(&version);
int major= version/10000;
int minor= (version%10000)/100;
int patch= version%100;
sprintf(s,FMT01, major , minor, patch);
writeConsole(s);
if (strlen(f2)> 0) {
/* use stdout for progress messages */
errcode = ENepanet(f1,f2,f3,writeConsole);
}
else {
/* use stdout for reporting, no progress messages */
errcode = ENepanet(f1,f2,f3,NULL);
}
/* Error/Warning check */
if (errcode == 0) writeConsole(FMT09);
else {
if (errcode > 100) {
writeConsole(FMT11);
}
else {
writeConsole(FMT10);
}
ENgeterror(errcode, errmsg, 40);
writeConsole(errmsg);
}
return(0);
} /* End of main */
@@ -70,6 +107,8 @@ void writeConsole(char *s)
**----------------------------------------------------------------
*/
{
fprintf(stdout,"%s",s);
fprintf(stdout,"%s\n",s);
fflush(stdout);
}

View File

@@ -180,7 +180,7 @@ int DLLEXPORT ENepanet(char *f1, char *f2, char *f3, void (*pviewprog) (char *))
ERRCODE(ENsolveQ());
ERRCODE(ENreport());
ENclose();
return(errcode);
return(MAX(errcode, Warnflag) );
}
@@ -290,7 +290,7 @@ int DLLEXPORT ENclose()
} //(2.00.12 - LR)
if (InFile != NULL) { fclose(InFile); InFile=NULL; }
if (RptFile != NULL) { fclose(RptFile); RptFile=NULL; }
if (RptFile != NULL && RptFile != stdout) { fclose(RptFile); RptFile=NULL; }
if (HydFile != NULL) { fclose(HydFile); HydFile=NULL; }
if (OutFile != NULL) { fclose(OutFile); OutFile=NULL; }
@@ -3499,8 +3499,8 @@ void writecon(char *s)
*/
{
//(2.00.11 - LR)
fprintf(stdout,s);
fflush(stdout);
//fprintf(stdout,s);
//fflush(stdout);
}
@@ -3514,14 +3514,12 @@ void writewin(char *s)
**----------------------------------------------------------------
*/
{
#ifdef DLL
char progmsg[MAXMSG+1];
if (viewprog != NULL)
{
strncpy(progmsg,s,MAXMSG);
viewprog(progmsg);
}
#endif
}