This commit is contained in:
michaeltryby
2019-04-22 13:36:44 -04:00
22 changed files with 243 additions and 276 deletions

View File

@@ -7,7 +7,7 @@
Authors: see AUTHORS
Copyright: see AUTHORS
License: see LICENSE
Last Updated: 04/03/2019
Last Updated: 04/20/2019
******************************************************************************
*/
@@ -819,7 +819,7 @@ void adjustpatterns(Network *network, int index)
Psource source;
// Adjust patterns used by junctions
for (j = 1; j <= network->Njuncs; j++)
for (j = 1; j <= network->Nnodes; j++)
{
// Adjust demand patterns
list_t *dlist = network->Node[j].D;
@@ -1003,6 +1003,18 @@ int setcomment(Network *network, int object, int index, const char *newcomment)
}
}
int namevalid(const char *name)
//----------------------------------------------------------------
// Input: name = name used to ID an object
// Output: returns TRUE if name is valid, FALSE if not
// Purpose: checks that an object's ID name is valid.
//----------------------------------------------------------------
{
size_t n = strlen(name);
if (n < 1 || n > MAXID || strpbrk(name, " ;") || name[0] == '"') return FALSE;
return TRUE;
}
char *getTmpName(char *fname)
//----------------------------------------------------------------
// Input: fname = file name string
@@ -1042,33 +1054,37 @@ char *xstrcpy(char **s1, const char *s2, const size_t n)
// n = maximum size of strings
// Output: none
// Purpose: like strcpy except for dynamic strings.
// Note: The calling program is responsible for ensuring that
// s1 points to a valid memory location or is NULL. E.g.,
// the following code will likely cause a segment fault:
// char *s;
// s = xstrcpy(s, "Some text");
// while this would work correctly:
// char *s = NULL;
// s = xstrcpy(s, "Some text");
//----------------------------------------------------------------
{
size_t n1 = 0, n2;
size_t n1 = 0, n2 = 0;
// Find size of source string
if (s2) n2 = strlen(s2);
if (n2 > n) n2 = n;
// Source string is empty -- free destination string
if (s2 == NULL || strlen(s2) == 0)
if (n2 == 0)
{
free(*s1);
*s1 = NULL;
return NULL;
}
// Source string not empty -- overwrite destination string
else
{
// See if size of destination string needs to grow
if (*s1) n1 = strlen(*s1);
if ((n2 = strlen(s2)) > n) n2 = n;
if (n2 > n1)
{
free(*s1);
*s1 = (char *)malloc((n2 + 1) * sizeof(char));
}
// See if size of destination string needs to grow
if (*s1) n1 = strlen(*s1);
if (n2 > n1) *s1 = realloc(*s1, (n2 + 1) * sizeof(char));
// Copy the new comment string into the existing one
if (*s1) strcpy(*s1, s2);
return *s1;
}
// Copy the source string into the destination string
strcpy(*s1, s2);
return *s1;
}
int strcomp(const char *s1, const char *s2)