Cleaning up include statements

Removing inclusion of malloc.h. Adding crtdbg.h
This commit is contained in:
Michael Tryby
2019-03-28 09:26:26 -04:00
parent 8574f52256
commit 1b167b5caf
28 changed files with 164 additions and 169 deletions

View File

@@ -10,13 +10,16 @@ License: see LICENSE
Last Updated: 03/17/2019
******************************************************************************
*/
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#endif
#include <math.h>
#include "types.h"
@@ -56,7 +59,7 @@ int netsize(Project *pr)
*/
{
Parser *parser = &pr->parser;
char line[MAXLINE + 1]; // Line from input data file
char *tok; // First token of line
int sect, newsect; // Input data sections
@@ -147,7 +150,7 @@ int readdata(Project *pr)
inperr, errsum; // Error code & total error count
// Allocate input buffer
parser->X = (double *)calloc(MAXTOKS, sizeof(double));
parser->X = (double *)calloc(MAXTOKS + 1, sizeof(double));
ERRCODE(MEMCHECK(parser->X));
if (errcode) return errcode;
@@ -175,7 +178,7 @@ int readdata(Project *pr)
while (fgets(line, MAXLINE, parser->InFile) != NULL)
{
// Make copy of line and scan for tokens
strcpy(wline, line);
strncpy(wline, line, MAXLINE);
parser->Ntokens = gettokens(wline, parser->Tok, MAXTOKS, parser->Comment);
// Skip blank lines and those filled with a comment
@@ -246,10 +249,10 @@ int readdata(Project *pr)
// Stop if reach end of file or max. error count
if (errsum == MAXERRS) break;
}
// Check for errors
if (errsum > 0) errcode = 200;
// Check for unlinked nodes
if (!errcode) errcode = unlinked(pr);
@@ -397,7 +400,7 @@ int updatepumpparams(Project *pr, int pumpindex)
curve->Type = PUMP_CURVE;
npts = curve->Npts;
// Generic power function curve
// Generic power function curve
if (npts == 1)
{
pump->Ptype = POWER_FUNC;
@@ -407,7 +410,7 @@ int updatepumpparams(Project *pr, int pumpindex)
q2 = 2.0 * q1;
h2 = 0.0;
}
// 3 point curve with shutoff head
else if (npts == 3 && curve->X[0] == 0.0)
{
@@ -418,7 +421,7 @@ int updatepumpparams(Project *pr, int pumpindex)
q2 = curve->X[2];
h2 = curve->Y[2];
}
// Custom pump curve
else
{
@@ -431,7 +434,7 @@ int updatepumpparams(Project *pr, int pumpindex)
pump->Q0 = (curve->X[0] + pump->Qmax) / 2.0;
pump->Hmax = curve->Y[0];
}
// Compute shape factors & limits of power function curves
if (pump->Ptype == POWER_FUNC)
{
@@ -461,7 +464,7 @@ int addnodeID(Network *net, int n, char *id)
**--------------------------------------------------------------
*/
{
if (findnode(net,id)) return 0;
if (findnode(net,id)) return 0;
strncpy(net->Node[n].ID, id, MAXID);
hashtable_insert(net->NodeHashTable, net->Node[n].ID, n);
return 1;
@@ -587,7 +590,7 @@ int unlinked(Project *pr)
Network *net = &pr->network;
int *marked;
int i, err, errcode;
errcode = 0;
err = 0;
@@ -596,19 +599,19 @@ int unlinked(Project *pr)
ERRCODE(MEMCHECK(marked));
if (errcode) return errcode;
memset(marked, 0, (net->Nnodes + 1) * sizeof(int));
// Mark end nodes of each link
for (i = 1; i <= net->Nlinks; i++)
{
marked[net->Link[i].N1]++;
marked[net->Link[i].N2]++;
}
// Check each junction
for (i = 1; i <= net->Njuncs; i++)
{
// If not marked then error
if (marked[i] == 0)
if (marked[i] == 0)
{
err++;
sprintf(pr->Msg, "Error 233: %s %s", geterrmsg(233, pr->Msg), net->Node[i].ID);
@@ -638,7 +641,7 @@ int getpatterns(Project *pr)
SFloatlist *f;
STmplist *tmppattern;
Spattern *pattern;
// Start at head of the list of patterns
tmppattern = parser->Patlist;
@@ -696,7 +699,7 @@ int getcurves(Project *pr)
{
Network *net = &pr->network;
Parser *parser = &pr->parser;
int i, j;
double x;
char errmsg[MAXMSG+1];
@@ -827,14 +830,14 @@ int gettokens(char *s, char** Tok, int maxToks, char *comment)
int m, n;
size_t len;
char *c, *c2;
// clear comment
comment[0] = '\0';
// Begin with no tokens
for (n=0; n<maxToks; n++) Tok[n] = NULL;
n = 0;
// Truncate s at start of comment
c = strchr(s,';');
if (c)
@@ -855,7 +858,7 @@ int gettokens(char *s, char** Tok, int maxToks, char *comment)
*c = '\0';
}
len = (int)strlen(s);
// Scan s for tokens until nothing left
while (len > 0 && n < MAXTOKS)
{
@@ -868,7 +871,7 @@ int gettokens(char *s, char** Tok, int maxToks, char *comment)
{
s++; // Start token after quote
m = (int)strcspn(s,"\"\n\r"); // Find end quote (or EOL)
}
}
s[m] = '\0'; // Null-terminate the token
Tok[n] = s; // Save pointer to token
n++; // Update token count
@@ -876,7 +879,7 @@ int gettokens(char *s, char** Tok, int maxToks, char *comment)
}
}
return n;
}
}
double hour(char *time, char *units)
/*
@@ -914,7 +917,7 @@ double hour(char *time, char *units)
if (match(units, w_DAYS)) return (y[0] * 24.0);
}
// Convert hh:mm:ss format to decimal hours
// Convert hh:mm:ss format to decimal hours
if (n > 1) y[0] = y[0] + y[1] / 60.0 + y[2] / 3600.0;
// If am/pm attached then adjust hour accordingly
@@ -933,7 +936,7 @@ double hour(char *time, char *units)
else return (y[0] + 12.0);
}
return -1.0;
}
}
int getfloat(char *s, double *y)
/*
@@ -979,14 +982,14 @@ void inperrmsg(Project *pr, int err, int sect, char *line)
*/
{
Parser *parser = &pr->parser;
char errStr[MAXMSG + 1] = "";
char tok[MAXMSG + 1];
// Get token associated with input error
if (parser->ErrTok >= 0) strcpy(tok, parser->Tok[parser->ErrTok]);
else strcpy(tok, "");
// write error message to report file
sprintf(pr->Msg, "Error %d: %s %s in %s section:",
err, geterrmsg(err, errStr), tok, SectTxt[sect]);