Skip to content
Snippets Groups Projects
Commit 3d42bdfb authored by Jonathan Schöbel's avatar Jonathan Schöbel
Browse files

Attr: provided static internal methods

For every function there is also a static method/function which can
perform the same work, but doesn't rely on really having an struct Attr.
This is useful for example in an array to manipulate a single element
while still using the same code.
Also the orginal methods are implemented with the new internal ones
themselves.
parent 3e09a2ef
No related branches found
No related tags found
No related merge requests found
......@@ -28,7 +28,7 @@ long_line_behaviour=1
long_line_column=72
[files]
current_page=3
current_page=16
FILE_NAME_0=923;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fconfigure.ac;0;8
FILE_NAME_1=73;Make;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2FMakefile.am;0;8
FILE_NAME_2=1143;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Fmain.c;0;8
......@@ -43,9 +43,9 @@ FILE_NAME_10=2022;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fp
FILE_NAME_11=2558;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ffragment_class.c;0;8
FILE_NAME_12=2167;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fnode_fragment.c;0;8
FILE_NAME_13=5930;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fnode_fragment.h;0;8
FILE_NAME_14=5566;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr.c;0;8
FILE_NAME_14=1393;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr.c;0;8
FILE_NAME_15=2924;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr.h;0;8
FILE_NAME_16=1434;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr_static.c;0;8
FILE_NAME_16=2825;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr_static.c;0;8
FILE_NAME_17=1116;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr_data.h;0;8
FILE_NAME_18=25820;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ftext.c;0;8
FILE_NAME_19=904;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ftext.h;0;8
......
......@@ -45,39 +45,20 @@ SH_Attr_new (const char * name,
/*@modifies status@*/
{
struct SH_Attr * attr;
attr = malloc (sizeof (struct SH_Attr));
attr = malloc (sizeof (struct SH_Attr));
if (attr == NULL)
{
set_status (status, E_ALLOC, 4, "malloc failed");
return NULL;
}
attr->name = strdup (name);
if (NULL == attr->name)
if (!Attr_init (attr, name, value, status))
{
set_status (status, E_ALLOC, 2, "strdup failed");
free (attr);
return NULL;
}
if (NULL == value)
{
attr->value = NULL;
}
else
{
attr->value = strdup (value);
if (NULL == attr->value)
{
set_status (status, E_ALLOC, 2,
"strdup failed");
free (attr->name);
free (attr);
return NULL;
}
}
set_success (status);
return attr;
}
......@@ -93,16 +74,15 @@ SH_Attr_raw_new (/*@only@*/ char * name,
/*@modifies status@*/
{
struct SH_Attr * attr;
attr = malloc (sizeof (struct SH_Attr));
attr = malloc (sizeof (struct SH_Attr));
if (attr == NULL)
{
set_status (status, E_ALLOC, 4, "malloc failed");
return NULL;
}
attr->name = name;
attr->value = value;
Attr_raw_init (attr, name, value);
set_success (status);
return attr;
......@@ -118,39 +98,20 @@ SH_Attr_copy (const struct SH_Attr * attr,
/*@modifies status@*/
{
struct SH_Attr * copy;
copy = malloc (sizeof (struct SH_Attr));
copy = malloc (sizeof (struct SH_Attr));
if (copy == NULL)
{
set_status (status, E_ALLOC, 4, "malloc failed");
return NULL;
}
copy->name = strdup (attr->name);
if (NULL == copy->name)
if (!Attr_copy (copy, attr, status))
{
set_status (status, E_ALLOC, 2, "strdup failed");
free (copy);
return NULL;
}
if (NULL == attr->value)
{
copy->value = NULL;
}
else
{
copy->value = strdup (attr->value);
if (NULL == copy->value)
{
set_status (status, E_ALLOC, 2,
"strdup failed");
free (copy->name);
free (copy);
return NULL;
}
}
set_success (status);
return copy;
}
......@@ -162,10 +123,8 @@ SH_Attr_free (/*@only@*/ struct SH_Attr * attr)
/*@modifies attr@*/
/*@releases attr@*/
{
free (attr->name);
if (NULL != attr->value) free (attr->value);
Attr_free (attr);
free (attr);
return;
}
......
......@@ -32,6 +32,104 @@
#include "attr_data.h"
static inline
bool
Attr_init (struct SH_Attr * attr,
const char * name,
/*@null@*/ const char * value,
/*@null@*/ /*@out@*/ struct SH_Status * status)
/*@globals fileSystem@*/
/*@modifies fileSystem@*/
/*@modifies status@*/
{
attr->name = strdup (name);
if (NULL == attr->name)
{
set_status (status, E_ALLOC, 2, "strdup failed");
return FALSE;
}
if (NULL == value)
{
attr->value = NULL;
}
else
{
attr->value = strdup (value);
if (NULL == attr->value)
{
set_status (status, E_ALLOC, 2,
"strdup failed");
free (attr->name);
return FALSE;
}
}
return TRUE;
}
static inline
void
Attr_raw_init (struct SH_Attr * attr,
/*@only@*/ char * name,
/*@null@*/ /*@only@*/ char * value)
/*@globals fileSystem@*/
/*@modifies fileSystem@*/
/*@modifies status@*/
{
attr->name = name;
attr->value = value;
return;
}
static inline
bool
Attr_copy (struct SH_Attr * copy,
const struct SH_Attr * attr,
/*@null@*/ /*@out@*/ struct SH_Status * status)
/*@globals fileSystem@*/
/*@modifies fileSystem@*/
/*@modifies status@*/
{
copy->name = strdup (attr->name);
if (NULL == copy->name)
{
set_status (status, E_ALLOC, 2, "strdup failed");
return FALSE;
}
if (NULL == attr->value)
{
copy->value = NULL;
}
else
{
copy->value = strdup (attr->value);
if (NULL == copy->value)
{
set_status (status, E_ALLOC, 2,
"strdup failed");
free (copy->name);
return FALSE;
}
}
return TRUE;
}
static inline
void
Attr_free (struct SH_Attr * attr)
/*@modifies attr->name@*/
/*@modifies attr->value@*/
/*@releases attr->name@*/
/*@releases attr->value@*/
{
free (attr->name);
if (NULL != attr->value) free (attr->value);
return;
}
static inline
/*@observer@*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment