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

Validator: added support for global attributes

Global attributes are represented by empty attributes. A global
attribute is an attribute, that is accepted for any tag.
It is refused to remove a specific tag for a global attribute, as this
would mean to "localize" the tag, thus making it not global anymore.
The method to do that and a predicate for globalness is missing yet.
parent 781488f2
No related branches found
No related tags found
No related merge requests found
......@@ -64,7 +64,7 @@ FILE_NAME_31=1303;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fp
FILE_NAME_32=10846;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_tag.c;0;8
FILE_NAME_33=1068;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_tag.h;0;8
FILE_NAME_34=1287;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_tag_data.h;0;8
FILE_NAME_35=15745;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_attr.c;0;8
FILE_NAME_35=23338;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_attr.c;0;8
FILE_NAME_36=1051;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_attr.h;0;8
FILE_NAME_37=1413;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_attr_data.h;0;8
FILE_NAME_38=924;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fstatus.h;0;8
......@@ -83,8 +83,8 @@ FILE_NAME_50=4221;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fp
FILE_NAME_51=994;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text_mark.c;0;8
FILE_NAME_52=2447;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator.c;0;8
FILE_NAME_53=9409;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator_tag.c;0;8
FILE_NAME_54=17869;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator_attr.c;0;8
FILE_NAME_55=547;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftodo.txt;0;8
FILE_NAME_54=45433;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator_attr.c;0;8
FILE_NAME_55=556;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftodo.txt;0;8
FILE_NAME_56=201;YAML;0;EUTF-8;0;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2F.gitlab-ci.yml;0;4
FILE_NAME_57=71;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fgitlab-ci%2Fupload.sh.in;0;8
FILE_NAME_58=806;Sh;0;EUTF-8;0;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fgitlab-ci%2Frelease.sh.in;0;4
......
......@@ -130,7 +130,7 @@ static inline
bool
add_attr (struct SH_Validator * validator,
const char * attr,
/*@dependent@*/ const char * tag,
/*@null@*/ /*@dependent@*/ const char * tag,
size_t index,
/*@null@*/ /*@out@*/ struct SH_Status * status)
/*@modifies validator->attrs@*/
......@@ -155,7 +155,7 @@ static inline
bool
attr_add_tag (struct attr_info * attr,
const size_t index,
/*@dependent@*/ const char * tag,
/*@null@*/ /*@dependent@*/ const char * tag,
/*@null@*/ /*@out@*/ struct SH_Status * status)
/*@modifies attr@*/
/*@globals fileSystem@*/
......@@ -241,6 +241,13 @@ init_attr_from_spec (/*@special@*/ struct SH_Validator * validator,
return FALSE;
}
if (0 == spec.tag_n)
{
attr_data->tags = NULL;
attr_data->tag_n = 0;
return TRUE;
}
if (spec.tag_n >= (SIZE_MAX / sizeof (struct attr_tag_info)))
{
set_status (status, E_DOMAIN, 2,
......@@ -356,6 +363,13 @@ init_attrs_from_spec (/*@special@*/ struct SH_Validator * validator,
attrs[position] = attr_data;
attr_n++;
}
else if ((0 == spec[index].tag_n)
&& (0 != attrs[position].tag_n))
{
free (attrs[position].tags);
attrs[position].tags = NULL;
attrs[position].tag_n = 0;
}
}
#undef attr_n
#undef attrs
......@@ -389,12 +403,20 @@ copy_attr (/*@special@*/ struct attr_info * copy,
return FALSE;
}
tags = malloc (sizeof (struct attr_tag_info) * attr->tag_n);
if (NULL == tags)
if (0 == attr->tag_n)
{
set_status (status, E_ALLOC, 3, "malloc failed");
free (name);
return FALSE;
tags = NULL;
}
else
{
tags = malloc (attr->tag_n
* sizeof (struct attr_tag_info));
if (NULL == tags)
{
set_status (status, E_ALLOC, 3, "malloc failed");
free (name);
return FALSE;
}
}
copy->name = name;
......@@ -458,7 +480,7 @@ free_attr (struct attr_info attr)
/*@releases attr.name@*/
{
free (attr.name);
free (attr.tags);
if (0 != attr.tag_n) free (attr.tags);
return;
}
......@@ -561,7 +583,7 @@ static inline
bool
add_attr (struct SH_Validator * validator,
const char * attr,
/*@dependent@*/ const char * tag,
/*@null@*/ /*@dependent@*/ const char * tag,
size_t index,
/*@null@*/ /*@out@*/ struct SH_Status * status)
/*@modifies validator->attrs@*/
......@@ -592,16 +614,24 @@ add_attr (struct SH_Validator * validator,
return FALSE;
}
attr_data.tags = malloc (sizeof (struct attr_tag_info));
if (NULL == attr_data.tags)
if (NULL == tag)
{
set_status (status, E_ALLOC, 3, "malloc failed");
free (attr_data.name);
return FALSE;
attr_data.tags = NULL;
attr_data.tag_n = 0;
}
else
{
attr_data.tags = malloc (sizeof (struct attr_tag_info));
if (NULL == attr_data.tags)
{
set_status (status, E_ALLOC, 3, "malloc failed");
free (attr_data.name);
return FALSE;
}
attr_data.tags[0].name = tag;
attr_data.tag_n = 1;
attr_data.tags[0].name = tag;
attr_data.tag_n = 1;
}
/* allocate new space */
/* The addition and the multiplication is save,
......@@ -690,7 +720,7 @@ static inline
bool
attr_add_tag (struct attr_info * attr,
const size_t index,
/*@dependent@*/ const char * tag,
/*@null@*/ /*@dependent@*/ const char * tag,
/*@null@*/ /*@out@*/ struct SH_Status * status)
/*@modifies attr@*/
/*@globals fileSystem@*/
......@@ -699,6 +729,22 @@ attr_add_tag (struct attr_info * attr,
{
struct attr_tag_info * new_tags;
if (0 == attr->tag_n)
{
set_success (status);
return TRUE;
}
if (NULL == tag)
{
free (attr->tags);
attr->tags = NULL;
attr->tag_n = 0;
set_success (status);
return TRUE;
}
if ((attr->tag_n == SIZE_MAX)
|| ((attr->tag_n + 1)
> (SIZE_MAX / sizeof (struct attr_tag_info))))
......@@ -840,6 +886,9 @@ SH_Validator_check_attr (struct SH_Validator * validator,
if (!find_tag (validator, tag, &index)) return FALSE;
tag = validator->tags[index].name;
/* global attr */
if (0 == attr->tag_n) return TRUE;
if (!find_attr_tag (attr, tag, &index)) return FALSE;
}
......@@ -848,7 +897,7 @@ SH_Validator_check_attr (struct SH_Validator * validator,
bool
SH_Validator_register_attr (struct SH_Validator * validator,
const char * tag,
/*@null@*/ const char * tag,
const char * attr,
/*@null@*/ /*@out@*/
struct SH_Status * status)
......@@ -861,13 +910,16 @@ SH_Validator_register_attr (struct SH_Validator * validator,
/* note, that index is used for three different arrays */
size_t index;
if ((!find_tag (validator, tag, &index))
&& (!add_tag (validator, tag, index, status)))
if (NULL != tag)
{
return FALSE;
}
if ((!find_tag (validator, tag, &index))
&& (!add_tag (validator, tag, index, status)))
{
return FALSE;
}
tag = validator->tags[index].name;
tag = validator->tags[index].name;
}
/* attr already registered */
if (find_attr (validator, attr, &index))
......@@ -875,6 +927,11 @@ SH_Validator_register_attr (struct SH_Validator * validator,
struct attr_info * attr;
attr = &validator->attrs[index];
if (NULL == tag)
{
return attr_add_tag (attr, 0, NULL, status);
}
if ((!find_attr_tag (attr, tag, &index))
&& (!attr_add_tag (attr, index, tag, status)))
{
......@@ -962,6 +1019,15 @@ SH_Validator_deregister_attr (struct SH_Validator * validator,
tag = validator->tags[index].name;
if (0 == attr->tag_n)
{
set_status (status, E_STATE, 2,
"can't remove specific tag "
"for global attribute, "
"please localize first");
return FALSE;
}
if (!find_attr_tag (attr, tag, &index))
{
/* TODO: define whether this is an error */
......
This diff is collapsed.
......@@ -2,13 +2,10 @@ create Logger
create Docs
dynamic Validator initialization
remove -Wno-nonnull from AM_CFLAGS
fix warnings for tests
rewrite validator test
restructure validator
Fragment:
- create html on single Text object
......@@ -22,6 +19,8 @@ Fragment:
- support for mapping special chars -> html entities
Validator:
- support for global attributes
- check for global attributes
- change global to local attribute
- add tag types
- fix cursed behaviour, when removing fails
- initialize from file
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