Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 0.1.7 Add Region_List #7

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/stego.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ tests# tests folder name
0.1.3# update prev_offset on kls_push()
0.1.5# add kls_log(), fixes
0.1.6# functional Koliseo_Temp
0.1.7# add Region_List
4 changes: 4 additions & 0 deletions bin/v0.1.7/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#amboso compliant version folder, will ignore everything inside BUT the gitignore, to keep the clean dir
*
!.gitignore
!static
1 change: 1 addition & 0 deletions bin/v0.1.7/static
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Define the package name and version
AC_INIT([koliseo], [0.1.6], [jgabaut@github.com])
AC_INIT([koliseo], [0.1.7], [jgabaut@github.com])

# Verify automake version and enable foreign option
AM_INIT_AUTOMAKE([foreign -Wall])
Expand All @@ -24,7 +24,7 @@ fi
# Set a default version number if not specified externally
AC_ARG_VAR([VERSION], [Version number])
if test -z "$VERSION"; then
VERSION="0.1.6"
VERSION="0.1.7"
fi

# Output variables to the config.h header
Expand Down
2 changes: 1 addition & 1 deletion docs/koliseo.doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ PROJECT_NAME = "koliseo"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = "0.1.5"
PROJECT_NUMBER = "0.1.7"

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
299 changes: 299 additions & 0 deletions src/koliseo.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ Koliseo* kls_new(ptrdiff_t size) {
kls->size = size;
kls->offset = sizeof(*kls);
kls->prev_offset = kls->offset;
sprintf(msg,"Init of Region_List for kls.");
kls_log("KLS",msg);
Region* kls_header = (Region*) malloc(sizeof(Region));
kls_header->begin_offset = 0;
kls_header->end_offset = kls->offset;
strcpy(kls_header->name,"KLS Header");
strcpy(kls_header->desc,"Denotes Space occupied by the Koliseo header.");
Region_List reglist = kls_emptyList();
reglist = kls_cons(kls_header,reglist);
kls->regs = reglist;
if (kls->regs == NULL) {
fprintf(stderr,"[KLS] kls_new() failed to get a Region_List.\n");
abort();
}
} else {
fprintf(stderr,"[KLS] Failed kls_new() call.\n");
abort();
Expand Down Expand Up @@ -250,3 +264,288 @@ void kls_temp_end(Koliseo_Temp tmp_kls) {
sprintf(msg,"Ended Temp KLS.");
kls_log("KLS",msg);
}


Region_List kls_emptyList(void)
{
return NULL;
}
bool kls_empty(Region_List l) {
if (l==NULL)
{
return true;
}
else
{
return false;
}
}
element kls_head(Region_List l) {
if (kls_empty(l))
{
abort();
}
else
{
return l->value;
}
}
Region_List kls_tail(Region_List l) {
if (kls_empty(l))
{
abort();
}
else
{
return l->next;
}
}
Region_List kls_cons(element e, Region_List l) {
if (e == NULL) {
kls_log("KLS","kls_cons(): element was NULL");
}
Region_List t;
t = (Region_List)malloc(sizeof(region_list_item));
t->value = e;
t->next = l;
return t;
}

void kls_freeList(Region_List l) {
if (kls_empty(l))
{
return;
}
else
{
kls_freeList(kls_tail(l));
free(l);
}
return;
}

void kls_showList(Region_List l) {
char msg[1000];
printf("[");
while (!kls_empty(l))
{
printf("--BEGIN Region--\n\n");
printf("Begin [%li] End [%li]\n",kls_head(l)->begin_offset,kls_head(l)->end_offset);
printf("Name [%s] Desc [%s]",kls_head(l)->name,kls_head(l)->desc);
printf("\n\n--END Region--");
kls_log("KLS","--BEGIN Region--");
sprintf(msg,"Begin [%li] End [%li]",kls_head(l)->begin_offset,kls_head(l)->end_offset);
kls_log("KLS",msg);
sprintf(msg,"Name [%s] Desc [%s]",kls_head(l)->name,kls_head(l)->desc);
kls_log("KLS",msg);
kls_log("KLS","--END Region--");
kls_log("KLS",msg);
//TODO
//Print containing kls
//print_kls_2file(stdout,kls_head(l));
l = kls_tail(l);
if (!kls_empty(l))
{
printf(",\n");
}
}
printf("]\n");
}



bool kls_member(element el, Region_List l) {
if (kls_empty(l))
{
return false;
}
else
{
if (el == kls_head(l))
{
return true;
}
else
{
return kls_member(el, kls_tail(l));
}
}
}
int kls_lenght(Region_List l) {
if (kls_empty(l))
{
return 0;
}
else
{
return 1 + kls_lenght(kls_tail(l));
}
}
Region_List kls_append(Region_List l1, Region_List l2) {
if (kls_empty(l1))
{
return l2;
}
else
{
return kls_cons(kls_head(l1), kls_append(kls_tail(l1), l2));
}
}
Region_List kls_reverse(Region_List l) {
if (kls_empty(l))
{
return kls_emptyList();
}
else
{
return kls_append(kls_reverse(kls_tail(l)), kls_cons(kls_head(l), kls_emptyList()));
}
}
Region_List kls_copy(Region_List l) {
if (kls_empty(l))
{
return l;
}
else
{
return kls_cons(kls_head(l), kls_copy(kls_tail(l)));
}
}
Region_List kls_delet(element el, Region_List l) {
if (kls_empty(l))
{
return kls_emptyList();
}
else
{
if (el == kls_head(l))
{
return kls_tail(l);
}
else
{
return kls_cons(kls_head(l), kls_delet(el, kls_tail(l)));
}
}
}

Region_List kls_insord(element el, Region_List l) {
if (kls_empty(l))
{
return kls_cons(el, l);
}
else
{
if (el->begin_offset <= kls_head(l)->begin_offset)
{
return kls_cons(el, l);
}
else
{
return kls_cons(kls_head(l),kls_insord(el, kls_tail(l)));
}
}
}

Region_List kls_insord_p(element el, Region_List l) {
Region_List pprec, patt = l, paux;
bool found = false;
pprec = NULL;

while (patt != NULL && !found)
{
if (el < patt->value)
{
found = true;
}
else
{
pprec = patt; patt = patt->next;
}
}
paux = (Region_List) malloc(sizeof(region_list_item));
paux->value = el;
paux->next = patt;
if (patt == l)
{
return paux;
}
else
{
pprec->next = paux;
return l;
}
}
Region_List kls_mergeList(Region_List l1, Region_List l2) {
if (kls_empty(l1))
{
return l2;
}
else
{
if (kls_empty(l2))
{
return l1;
}
else
{
if (kls_isLess(kls_head(l1), kls_head(l2)))
{
return kls_cons(kls_head(l1), kls_mergeList(kls_tail(l1), l2));
}
else
{
if (kls_isEqual(kls_head(l1), kls_head(l2)))
{
return kls_cons(kls_head(l1), kls_mergeList(kls_tail(l1), kls_tail(l2)));
}
else
{
return kls_cons(kls_head(l2), kls_mergeList(l1, kls_tail(l2)));
}
}
}
}
}
Region_List kls_intersect(Region_List l1, Region_List l2) {
if (kls_empty(l1) || kls_empty(l2))
{
return kls_emptyList();
}

if (kls_member(kls_head(l1), l2) && !kls_member(kls_head(l1), kls_tail(l1)))
{
return kls_cons(kls_head(l1), kls_intersect(kls_tail(l1), l2));
}

else
{
return kls_intersect(kls_tail(l1), l2);
}
}
Region_List kls_diff(Region_List l1, Region_List l2) {
if (kls_empty(l1) || kls_empty(l2))
{
return l1;
}

else
{
if (!kls_member(kls_head(l1), l2) && !kls_member(kls_head(l1), kls_tail(l1)))
{
return kls_cons(kls_head(l1), kls_diff(kls_tail(l1), l2));
}
else
{
return kls_diff(kls_tail(l1), l2);
}
}
}

bool kls_isLess(Region* r1, Region* r2) {
return (r1->begin_offset < r2->begin_offset);
}

bool kls_isEqual(Region* r1, Region* r2) {
return (r1->begin_offset == r2->begin_offset);
}
Loading