Skip to content

Commit

Permalink
feat: 0.1.4 add kls_log(), update demo (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgabaut authored Aug 21, 2023
1 parent a30aa8d commit b4436b9
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ amboso_cfg.dot
#Ignore docs pdf
docs/docs.pdf

# ignore debug log file
debug_log.txt

#Ignore doxygen dir
doxygen/

Expand Down
1 change: 1 addition & 0 deletions bin/stego.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ tests# tests folder name
0.1.1# abort() on failed operations
0.1.2# print_kls_2file()
0.1.3# update prev_offset on kls_push()
0.1.4# add kls_log()
4 changes: 4 additions & 0 deletions bin/v0.1.4/.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.4/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.3], [jgabaut@github.com])
AC_INIT([koliseo], [0.1.4], [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.3"
VERSION="0.1.4"
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.3"
PROJECT_NUMBER = "0.1.4"

# 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
43 changes: 43 additions & 0 deletions src/koliseo.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "koliseo.h"
int KOLISEO_DEBUG = 0;
FILE* KOLISEO_DEBUG_FP = NULL;

/**
* Returns the constant string representing current version for Koliseo.
Expand All @@ -17,6 +19,22 @@ ptrdiff_t kls_get_pos(Koliseo* kls) {
return kls->offset;
}

/**
* When KOLISEO_DEBUG is 1, logs a message to the defined KOLISEO_DEBUG_FP.
* @param tag Tag for a message.
* @param msg The actual message.
*/
void kls_log(const char* tag, const char* msg) {
if (KOLISEO_DEBUG == 1) {
if (KOLISEO_DEBUG_FP == NULL) {
fprintf(stderr,"[KLS] kls_log(): Failed opening KOLISEO_DEBUG_FP to print logs.\n");
} else {
fprintf(KOLISEO_DEBUG_FP,"[%s] %s\n", tag, msg);
}
}
}


/**
* Takes a ptrdiff_t size and allocates the backing memory for a Koliseo. Sets the fields with appropriate values if memory allocation was successful, goes to abort() otherwise.
* @param size The size for Koliseo data field.
Expand All @@ -30,6 +48,9 @@ Koliseo* kls_new(ptrdiff_t size) {
assert(size >= (ptrdiff_t)sizeof(Koliseo));
void *p = malloc(size);
if (p) {
char msg[500];
sprintf(msg,"Allocated (%li) for new KLS.",size);
kls_log("KLS",msg);
Koliseo* kls = p;
kls->data = p;
kls->size = size;
Expand Down Expand Up @@ -58,6 +79,10 @@ void* kls_pop(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count) {
}
char* p = kls->data + kls->offset - padding - size*count;
kls->offset -= padding + size*count;
char msg[500];
sprintf(msg,"Popped (%li) for KLS.",size);
kls_log("KLS",msg);

return p;
}

Expand Down Expand Up @@ -85,6 +110,9 @@ void* kls_push(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count) {
char* p = kls->data + kls->offset + padding;
kls->prev_offset = kls->offset;
kls->offset += padding + size*count;
char msg[500];
sprintf(msg,"Pushed (%li) for KLS.",size);
kls_log("KLS",msg);
return p;
}

Expand Down Expand Up @@ -115,6 +143,9 @@ void* kls_push_zero(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t cou
memset(p, 0, size*count);
kls->prev_offset = kls->offset;
kls->offset += padding + size*count;
char msg[500];
sprintf(msg,"Pushed zeroes, size (%li) for KLS.",size);
kls_log("KLS",msg);
return p;
}

Expand Down Expand Up @@ -153,6 +184,9 @@ void kls_clear(Koliseo* kls) {
//Reset pointer
kls->prev_offset = kls->offset;
kls->offset = sizeof(*kls);
char msg[500];
sprintf(msg,"Cleared offsets for KLS.");
kls_log("KLS",msg);
}

/**
Expand All @@ -163,6 +197,9 @@ void kls_clear(Koliseo* kls) {
void kls_free(Koliseo* kls) {
kls_clear(kls);
free(kls);
char msg[500];
sprintf(msg,"Freed KLS.");
kls_log("KLS",msg);
}

/**
Expand All @@ -177,6 +214,9 @@ Koliseo_Temp kls_temp_start(Koliseo* kls) {
tmp.kls = kls;
tmp.prev_offset = kls->prev_offset;
tmp.offset = kls->offset;
char msg[500];
sprintf(msg,"Prepared new Temp KLS.");
kls_log("KLS",msg);
return tmp;
}

Expand All @@ -188,4 +228,7 @@ Koliseo_Temp kls_temp_start(Koliseo* kls) {
void kls_temp_end(Koliseo_Temp tmp_kls) {
tmp_kls.prev_offset = tmp_kls.prev_offset;
tmp_kls.offset = tmp_kls.offset;
char msg[500];
sprintf(msg,"Ended Temp KLS.");
kls_log("KLS",msg);
}
16 changes: 14 additions & 2 deletions src/koliseo.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,24 @@

#define KLS_MAJOR 0 /**< Represents current major release.*/
#define KLS_MINOR 1 /**< Represents current minor release.*/
#define KLS_PATCH 3 /**< Represents current patch release.*/
#define KLS_PATCH 4 /**< Represents current patch release.*/

static const char KOLISEO_API_VERSION_STRING[] = "0.1.3"; /**< Represents current version with MAJOR.MINOR.PATCH format.*/
/**
* Global variable for debug flag.
*/
extern int KOLISEO_DEBUG;

/**
* Global variable for debug file pointer.
*/
extern FILE* KOLISEO_DEBUG_FP;

static const char KOLISEO_API_VERSION_STRING[] = "0.1.4"; /**< Represents current version with MAJOR.MINOR.PATCH format.*/

const char* string_koliseo_version(void);

void kls_log(const char* tag, const char* msg);

#define KLS_DEFAULT_SIZE (16*1024) /**< Represents a simple default size for demo purposes.*/

#ifndef KLS_DEFAULT_ALIGNMENT
Expand Down
26 changes: 26 additions & 0 deletions static/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,29 @@
#include "amboso.h"

int main(void) {
KOLISEO_DEBUG = 1;
printf("Demo for Koliseo, using API version %s\n", string_koliseo_version());
printf("Supporting Amboso API version %s\n\n", getAmbosoVersion());
printf("KOLISEO_DEBUG is [%i]\n\n", KOLISEO_DEBUG);
//Reset debug log file
if (KOLISEO_DEBUG == 1) {
KOLISEO_DEBUG_FP = fopen("./static/debug_log.txt","w");
if (KOLISEO_DEBUG_FP == NULL) {
fprintf(stderr,"[KLS] Failed to open debug logfile.\n");
exit(EXIT_FAILURE);
}
kls_log("KLS-DEMO","New demo run.");
}
if (KOLISEO_DEBUG == 1) {
fclose(KOLISEO_DEBUG_FP);
}
if (KOLISEO_DEBUG == 1) {
KOLISEO_DEBUG_FP = fopen("./static/debug_log.txt","a");
if (KOLISEO_DEBUG_FP == NULL) {
fprintf(stderr,"[KLS] Failed to open debug logfile.\n");
exit(EXIT_FAILURE);
}
}

printf("[Init Koliseo] [size: %i]\n",KLS_DEFAULT_SIZE);
Koliseo* kls = kls_new(KLS_DEFAULT_SIZE);
Expand All @@ -31,6 +52,7 @@ int main(void) {
printf("[KLS_POP a int from Koliseo] [size: %li]\n",sizeof(int));
z = KLS_POP(kls, int, 1);


printf("\n*z is [%i] after KLS_POP\n",*z);
printf("[Current position in Koliseo] [pos: %li]\n",kls_get_pos(kls));

Expand All @@ -44,5 +66,9 @@ int main(void) {
kls_free(kls);

printf("[End of demo]\n");
if (KOLISEO_DEBUG == 1) {
fclose(KOLISEO_DEBUG_FP);
}

return 0;
}

0 comments on commit b4436b9

Please sign in to comment.