Skip to content

Commit

Permalink
feat: 0.1.12 - Define int API level, vargs log (#13)
Browse files Browse the repository at this point in the history
* feat: kls_log() vargs

* feat: drop sprintf(msg) for logs

* feat: define int API level

* chore: bump doxyfile

* chore: bump stego.lock
  • Loading branch information
jgabaut authored Sep 1, 2023
1 parent 7d13e69 commit 63273c1
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 76 deletions.
1 change: 1 addition & 0 deletions bin/stego.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ tests# tests folder name
0.1.9# add kls_usageReport()
0.1.10# add ncurses debug functions
0.1.11# add kls_formatSize()
0.1.12# add int API lvl, vargs log
4 changes: 4 additions & 0 deletions bin/v0.1.12/.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.12/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.11], [[email protected]])
AC_INIT([koliseo], [0.1.12], [[email protected]])

# 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.11"
VERSION="0.1.12"
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.11"
PROJECT_NUMBER = "0.1.12"

# 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
112 changes: 50 additions & 62 deletions src/koliseo.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ FILE* KOLISEO_DEBUG_FP = NULL;
const char* string_koliseo_version(void) {
return KOLISEO_API_VERSION_STRING;
}
/**
* Returns the constant int representing current version for Koliseo.
* @return A constant int in numeric format for current Koliseo version.
*/
const int int_koliseo_version(void) {
return KOLISEO_API_VERSION_INT;
}

/**
* Returns the current offset (position of pointer bumper) for the passed Koliseo.
Expand All @@ -24,10 +31,12 @@ ptrdiff_t kls_get_pos(Koliseo* kls) {
/**
* 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.
* @param format The message format string.
*/
void kls_log(const char* tag, const char* msg) {
void kls_log(const char* tag, const char* format, ...) {
if (KOLISEO_DEBUG == 1) {
va_list args;
va_start(args, format);
if (KOLISEO_DEBUG_FP == NULL) {
fprintf(stderr,"[KLS] kls_log(): Failed opening KOLISEO_DEBUG_FP to print logs.\n");
} else {
Expand All @@ -36,9 +45,12 @@ void kls_log(const char* tag, const char* msg) {
char timeheader[500];
if ( strftime(timeheader, sizeof timeheader, "%X", mytime) )
{
fprintf(KOLISEO_DEBUG_FP,"[%-10.10s] [%s] [%s]\n", tag, timeheader, msg);
fprintf(KOLISEO_DEBUG_FP,"[%-10.10s] [%s] [", tag, timeheader);
vfprintf(KOLISEO_DEBUG_FP, format, args);
fprintf(KOLISEO_DEBUG_FP,"]\n");
}
}
va_end(args);
}
}

Expand All @@ -56,21 +68,18 @@ 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);
char h_size[200];
kls_formatSize(size,h_size,sizeof(h_size));
sprintf(msg,"Allocated (%s) for new KLS.",h_size);
kls_log("KLS",msg);
kls_log("KLS","Allocated (%s) for new KLS.",h_size);
Koliseo* kls = p;
kls->data = p;
kls->size = size;
kls->offset = sizeof(*kls);
kls->prev_offset = kls->offset;
if (KOLISEO_AUTOSET_REGIONS == 1) {
sprintf(msg,"Init of Region_List for kls.");
kls_log("KLS",msg);
kls_log("KLS","Init of Region_List for kls.");
Region* kls_header = (Region*) malloc(sizeof(Region));
kls_header->begin_offset = 0;
kls_header->end_offset = kls->offset;
Expand Down Expand Up @@ -111,9 +120,7 @@ void* kls_pop(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count) {
char* p = kls->data + kls->offset - padding - size*count;
kls->prev_offset = kls->offset;
kls->offset -= padding + size*count;
char msg[500];
sprintf(msg,"Popped (%li) for KLS.",size);
kls_log("KLS",msg);
kls_log("KLS","Popped (%li) for KLS.",size);
if (KOLISEO_DEBUG == 1) {
print_kls_2file(KOLISEO_DEBUG_FP,kls);
}
Expand Down Expand Up @@ -144,13 +151,11 @@ 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];
char h_size[200];
kls_formatSize(size,h_size,sizeof(h_size));
//sprintf(msg,"Pushed size (%li) for KLS.",size);
//kls_log("KLS",msg);
sprintf(msg,"Pushed size (%s) for KLS.",h_size);
kls_log("KLS",msg);
kls_log("KLS","Pushed size (%s) for KLS.",h_size);
if (KOLISEO_DEBUG == 1) {
print_kls_2file(KOLISEO_DEBUG_FP,kls);
}
Expand Down Expand Up @@ -195,13 +200,11 @@ void* kls_push_zero(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t cou
kls->regs = kls_append(reglist, kls->regs);
}

char msg[500];
char h_size[200];
kls_formatSize(size,h_size,sizeof(h_size));
//sprintf(msg,"Pushed zeroes, size (%li) for KLS.",size);
//kls_log("KLS",msg);
sprintf(msg,"Pushed zeroes, size (%s) for KLS.",h_size);
kls_log("KLS",msg);
kls_log("KLS","Pushed zeroes, size (%s) for KLS.",h_size);
if (KOLISEO_DEBUG == 1) {
print_kls_2file(KOLISEO_DEBUG_FP,kls);
}
Expand Down Expand Up @@ -245,13 +248,11 @@ void* kls_push_zero_named(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff
reglist = kls_cons(reg,reglist);
kls->regs = kls_append(reglist, kls->regs);

char msg[500];
char h_size[200];
kls_formatSize(size,h_size,sizeof(h_size));
//sprintf(msg,"Pushed zeroes, size (%li) for KLS.",size);
//kls_log("KLS",msg);
sprintf(msg,"Pushed zeroes, size (%s) for KLS.",h_size);
kls_log("KLS",msg);
kls_log("KLS","Pushed zeroes, size (%s) for KLS.",h_size);
if (KOLISEO_DEBUG == 1) {
print_kls_2file(KOLISEO_DEBUG_FP,kls);
}
Expand All @@ -270,15 +271,15 @@ void print_kls_2file(FILE* fp, Koliseo* kls) {
if (kls == NULL) {
fprintf(fp,"[KLS] kls was NULL.");
} else {
fprintf(fp,"\n[KLS] Size: [%li]\n", kls->size);
fprintf(fp,"\n[KLS] Size: { %li }\n", kls->size);
char human_size[200];
char curr_size[200];
kls_formatSize(kls->size,human_size,sizeof(human_size));
fprintf(fp,"[KLS] Human: [%s]\n", human_size);
fprintf(fp,"[KLS] Human: { %s }\n", human_size);
kls_formatSize(kls->offset,curr_size,sizeof(curr_size));
fprintf(fp,"[KLS] Used (Human): [%s]\n", curr_size);
fprintf(fp,"[KLS] Offset: [%li]\n", kls->offset);
fprintf(fp,"[KLS] Prev_Offset: [%li]\n\n", kls->prev_offset);
fprintf(fp,"[KLS] Used (Human): { %s }\n", curr_size);
fprintf(fp,"[KLS] Offset: { %li }\n", kls->offset);
fprintf(fp,"[KLS] Prev_Offset: { %li }\n\n", kls->prev_offset);
}
}

Expand Down Expand Up @@ -333,17 +334,17 @@ void kls_show_toWin(Koliseo* kls, WINDOW* win) {
int y = 2;
int x = 2;
mvwprintw(win, y++, x, "Koliseo data:");
mvwprintw(win, y++, x, "Size: [%li]", kls->size);
mvwprintw(win, y++, x, "Size: { %li }", kls->size);
char h_size[200];
kls_formatSize(kls->size,h_size,sizeof(h_size));
mvwprintw(win, y++, x, "Human size: [%s]", h_size);
mvwprintw(win, y++, x, "Human size: { %s }", h_size);
char curr_size[200];
kls_formatSize(kls->offset,curr_size,sizeof(curr_size));
mvwprintw(win, y++, x, "Used (Human): [%s]\n", curr_size);
mvwprintw(win, y++, x, "Offset: [%li]", kls->offset);
mvwprintw(win, y++, x, "Prev_Offset: [%li]", kls->prev_offset);
mvwprintw(win, y++, x, "Region_List len: [%i]", kls_length(kls->regs));
mvwprintw(win, y++, x, "Current usage: [%.3f%%]", (kls->offset * 100.0 ) / kls->size );
mvwprintw(win, y++, x, "Used (Human): { %s }\n", curr_size);
mvwprintw(win, y++, x, "Offset: { %li }", kls->offset);
mvwprintw(win, y++, x, "Prev_Offset: { %li }", kls->prev_offset);
mvwprintw(win, y++, x, "Region_List len: { %i }", kls_length(kls->regs));
mvwprintw(win, y++, x, "Current usage: { %.3f%% }", (kls->offset * 100.0 ) / kls->size );
mvwprintw(win, y++, x, "%s","");
mvwprintw(win, y++, x, "q or Enter to quit.");
/*
Expand Down Expand Up @@ -397,16 +398,15 @@ void kls_showList_toWin(Koliseo* kls, WINDOW* win) {
wclear(win);
y = 3;
element e = kls_head(rl);
mvwprintw(win, y++, x, "Name: [%s]", e->name);
mvwprintw(win, y++, x, "Desc: [%s]", e->desc);
mvwprintw(win, y++, x, "Begin_Offset: [%li]", e->begin_offset);
mvwprintw(win, y++, x, "End_Offset: [%li]", e->end_offset);
mvwprintw(win, y++, x, "Region_List len: [%i]", kls_length(kls->regs));
mvwprintw(win, y++, x, "Current usage: [%.3f%%]", kls_usageShare(e,kls));
mvwprintw(win, y++, x, "Name: { %s }", e->name);
mvwprintw(win, y++, x, "Desc: { %s }", e->desc);
mvwprintw(win, y++, x, "Offsets: { %li } -> { %li }", e->begin_offset, e->end_offset);
mvwprintw(win, y++, x, "Region_List len: { %i }", kls_length(kls->regs));
mvwprintw(win, y++, x, "Current usage: { %.3f%% }", kls_usageShare(e,kls));
char h_size[200];
ptrdiff_t reg_size = e->end_offset - e->begin_offset;
kls_formatSize(reg_size,h_size,sizeof(h_size));
mvwprintw(win, y++, x, "Human size: [%s]", h_size);
mvwprintw(win, y++, x, "Human size: { %s }", h_size);
mvwprintw(win, y++, x, "%s","");
mvwprintw(win, y++, x, "q to quit, Right arrow to go forward.");
/*
Expand Down Expand Up @@ -452,9 +452,7 @@ 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);
kls_log("KLS","Cleared offsets for KLS.");
}

/**
Expand All @@ -466,9 +464,7 @@ void kls_free(Koliseo* kls) {
kls_clear(kls);
kls_freeList(kls->regs);
free(kls);
char msg[500];
sprintf(msg,"Freed KLS.");
kls_log("KLS",msg);
kls_log("KLS","Freed KLS.");
}

/**
Expand All @@ -483,9 +479,7 @@ 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);
kls_log("KLS","Prepared new Temp KLS.");
return tmp;
}

Expand All @@ -497,9 +491,7 @@ Koliseo_Temp kls_temp_start(Koliseo* kls) {
void kls_temp_end(Koliseo_Temp tmp_kls) {
tmp_kls.kls->prev_offset = tmp_kls.prev_offset;
tmp_kls.kls->offset = tmp_kls.offset;
char msg[500];
sprintf(msg,"Ended Temp KLS.");
kls_log("KLS",msg);
kls_log("KLS","Ended Temp KLS.");
}


Expand Down Expand Up @@ -569,23 +561,19 @@ void kls_showList_toFile(Region_List l, FILE* fp) {
fprintf(stderr,"[KLS] kls_showList_toFile(): passed file was NULL.\n");
abort();
}
char msg[1000];
fprintf(fp,"{");
while (!kls_empty(l))
{
fprintf(fp,"\n[%s], [%s] ",kls_head(l)->name,kls_head(l)->desc);
fprintf(fp,"[%li]->[%li]",kls_head(l)->begin_offset,kls_head(l)->end_offset);
kls_log("KLS","--BEGIN Region--");
sprintf(msg,"[%s], [%s]",kls_head(l)->name,kls_head(l)->desc);
kls_log("KLS",msg);
fprintf(fp,"\n{ %s }, { %s } ",kls_head(l)->name,kls_head(l)->desc);
fprintf(fp,"{ %li } -> { %li }",kls_head(l)->begin_offset,kls_head(l)->end_offset);
kls_log("KLS-Region"," Region {");
kls_log("KLS-Region","{ %s }, { %s }",kls_head(l)->name,kls_head(l)->desc);
char h_size[200];
ptrdiff_t r_size = kls_head(l)->end_offset - kls_head(l)->begin_offset;
kls_formatSize(r_size,h_size,sizeof(h_size));
sprintf(msg,"[%s]",h_size);
kls_log("KLS",msg);
sprintf(msg,"[%li]->[%li]",kls_head(l)->begin_offset,kls_head(l)->end_offset);
kls_log("KLS",msg);
kls_log("KLS","--END Region--");
kls_log("KLS-Region","{ %s }",h_size);
kls_log("KLS-Region","{ %li } -> { %li }",kls_head(l)->begin_offset,kls_head(l)->end_offset);
kls_log("KLS-Region"," }");

l = kls_tail(l);
if (!kls_empty(l))
Expand Down
22 changes: 13 additions & 9 deletions src/koliseo.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#ifndef KOLISEO_H
#define KOLISEO_H
#ifndef KOLISEO_H_
#define KOLISEO_H_
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdarg.h>
#include <assert.h>
#include <string.h>
#include <time.h>

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

/**
* Global variable for debug flag.
Expand All @@ -26,11 +27,14 @@ extern int KOLISEO_AUTOSET_REGIONS;
*/
extern FILE* KOLISEO_DEBUG_FP;

static const char KOLISEO_API_VERSION_STRING[] = "0.1.11"; /**< Represents current version with MAJOR.MINOR.PATCH format.*/
static const int KOLISEO_API_VERSION_INT = (KLS_MAJOR*3+KLS_MINOR*2+KLS_PATCH); /**< Represents current version with numeric format.*/
static const char KOLISEO_API_VERSION_STRING[] = "0.1.12"; /**< Represents current version with MAJOR.MINOR.PATCH format.*/

const char* string_koliseo_version(void);

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

void kls_log(const char* tag, const char* format, ...);

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

Expand All @@ -54,8 +58,8 @@ typedef struct Region {
static const char KOLISEO_DEFAULT_REGION_NAME[] = "No Name"; /**< Represents default Region name, used for kls_push_zero().*/
static const char KOLISEO_DEFAULT_REGION_DESC[] = "No Desc"; /**< Represents default Region desc, used for kls_push_zero().*/

#ifndef KOLISEO_LIST_H
#define KOLISEO_LIST_H
#ifndef KOLISEO_LIST_H_
#define KOLISEO_LIST_H_
#include "stdbool.h"

typedef Region* element;
Expand Down Expand Up @@ -119,8 +123,8 @@ void print_dbg_kls(Koliseo* kls);
void kls_formatSize(ptrdiff_t size, char* outputBuffer, size_t bufferSize);

#ifdef KOLISEO_HAS_CURSES
#ifndef KOLISEO_CURSES_H
#define KOLISEO_CURSES_H
#ifndef KOLISEO_CURSES_H_
#define KOLISEO_CURSES_H_
#include "ncurses.h"
void kls_show_toWin(Koliseo* kls, WINDOW* win);
void kls_showList_toWin(Koliseo* kls, WINDOW* win);
Expand Down
4 changes: 2 additions & 2 deletions static/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
int main(void) {
KOLISEO_DEBUG = 1;
KOLISEO_AUTOSET_REGIONS = 1;
printf("Demo for Koliseo, using API version %s\n", string_koliseo_version());
printf("Demo for Koliseo, using API lvl [%i], version %s \n", int_koliseo_version(), string_koliseo_version());
printf("Supporting Amboso API version %s\n\n", getAmbosoVersion());
printf("KOLISEO_DEBUG is [%i]\n\n", KOLISEO_DEBUG);
printf("KOLISEO_AUTOSET_REGIONS is [%i]\n\n", KOLISEO_AUTOSET_REGIONS);
Expand Down Expand Up @@ -122,7 +122,7 @@ int main(void) {
kls_free(kls);

printf("[End of demo]\n");
printf("[End of demo for Koliseo v%s]\n", string_koliseo_version());
printf("[End of demo for Koliseo, API lvl [%i] v%s ]\n", int_koliseo_version(), string_koliseo_version());
if (KOLISEO_DEBUG == 1) {
fclose(KOLISEO_DEBUG_FP);
}
Expand Down

0 comments on commit 63273c1

Please sign in to comment.