Skip to content

Commit

Permalink
feat: 0.1.10 add ncurses function
Browse files Browse the repository at this point in the history
The ncurses dependency is guarded by compiler macro KOLISEO_HAS_CURSES.
You should add -DKOLISEO_HAS_CURSES to your compiler flags when you need
the ncurses-depended functions.
  • Loading branch information
jgabaut committed Aug 25, 2023
1 parent 6728597 commit ef45cd1
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ PACK_NAME = $(TARGET)-$(VERSION)-$(OS)-$(MACHINE)
koliseo_SOURCES = src/koliseo.c static/amboso.c static/demo.c

# Linking rule
LDADD = $(KOLISEO_LDFLAGS)
LDADD = $(KOLISEO_LDFLAGS) -lncurses

# Linker flag to strip symbols
AM_LDFLAGS = -s

# Compiler flags
AM_CFLAGS = $(KOLISEO_CFLAGS) -O2 -Werror -Wpedantic -Wall
AM_CFLAGS = $(KOLISEO_CFLAGS) -O2 -Werror -Wpedantic -Wall -DKOLISEO_HAS_CURSES

# Build rule for object files
%.o: %.c
Expand Down
1 change: 1 addition & 0 deletions bin/stego.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ tests# tests folder name
0.1.7# add Region_List
0.1.8# improved Region API
0.1.9# add kls_usageReport()
0.1.10# add ncurses debug functions
4 changes: 4 additions & 0 deletions bin/v0.1.10/.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.10/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.9], [jgabaut@github.com])
AC_INIT([koliseo], [0.1.10], [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.9"
VERSION="0.1.10"
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.9"
PROJECT_NUMBER = "0.1.10"

# 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
119 changes: 119 additions & 0 deletions src/koliseo.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,125 @@ void print_dbg_kls(Koliseo* kls) {
print_kls_2file(stderr,kls);
}

#ifdef KOLISEO_HAS_CURSES
/**
* Prints fields and eventually Region_List from the passed Koliseo pointer, to the passed WINDOW pointer.
* @param kls The Koliseo at hand.
* @param win The Window at hand.
*/
void kls_show_toWin(Koliseo* kls, WINDOW* win) {
if (win == NULL) {
kls_log("ERROR","kls_show_toWin(): passed WINDOW was null.");
abort();
}
if (kls == NULL) {
kls_log("ERROR","kls_show_toWin(): passed Koliseo was null.");
abort();
}
wclear(win);
box(win,0,0);
wrefresh(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, "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, "q or Enter to quit.");
/*
Region_List rl = kls_copy(kls->regs);
while (!kls_empty(rl)) {
mvwprintw(win, y, x, "Prev_Offset: [%i]",kls->prev_offset);
}
*/
wrefresh(win);
int ch = '?';
int quit = -1;
do {
quit = 0;
ch = wgetch(win);
switch (ch) {
case 10: case 'q': {
quit = 1;
}
break;
default: {
quit = 0;
}
break;
}
} while (!quit);
}

/**
* Displays a slideshow of Region_List from passed Koliseo, to the passed WINDOW pointer.
* @param kls The Koliseo at hand.
* @param win The Window at hand.
*/
void kls_showList_toWin(Koliseo* kls, WINDOW* win) {
if (win == NULL) {
kls_log("ERROR","kls_show_toWin(): passed WINDOW was null.");
abort();
}
if (kls == NULL) {
kls_log("ERROR","kls_show_toWin(): passed Koliseo was null.");
abort();
}
wclear(win);
box(win,0,0);
wrefresh(win);
int y = 2;
int x = 2;
int quit = 0;
mvwprintw(win, y++, x, "Region_List data:");
Region_List rl = kls_copy(kls->regs);
do {
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, "q to quit, Right arrow to go forward.");
/*
Region_List rl = kls_copy(kls->regs);
while (!kls_empty(rl)) {
mvwprintw(win, y, x, "Prev_Offset: [%i]",kls->prev_offset);
}
*/
box(win,0,0);
wrefresh(win);
int ch = '?';
int picked = -1;
do {
picked = 0;
ch = wgetch(win);
switch (ch) {
case KEY_RIGHT: {
rl = kls_tail(rl);
picked = 1;
}
break;
case 'q': {
quit = 1;
picked = 1;
}
break;
default: {
picked = 0;
}
break;
}
} while (!quit && !picked);
} while (!quit && !kls_empty(rl));
}
#endif

/**
* Resets the offset field for the passed Koliseo pointer.
* Notably, it sets the prev_offset field to the previous offset, thus remembering where last allocation was before the clear.
Expand Down
13 changes: 11 additions & 2 deletions src/koliseo.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

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

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

const char* string_koliseo_version(void);

Expand Down Expand Up @@ -117,6 +117,15 @@ void kls_free(Koliseo* kls);
void print_kls_2file(FILE* fp, Koliseo* kls);
void print_dbg_kls(Koliseo* kls);

#ifdef KOLISEO_HAS_CURSES
#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);
#endif
#endif

Koliseo_Temp kls_temp_start(Koliseo* kls);
void kls_temp_end(Koliseo_Temp tmp_kls);

Expand Down
21 changes: 21 additions & 0 deletions static/demo.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdio.h>
#include <locale.h>
#include "../src/koliseo.h"
#include "amboso.h"

Expand Down Expand Up @@ -76,6 +77,26 @@ int main(void) {
printf("[Usage report for Koliseo]\n");
kls_usageReport(kls);

WINDOW* win = NULL;
/* Initialize curses */
setlocale(LC_ALL, "");
initscr();
clear();
refresh();
start_color();
cbreak();
noecho();
keypad(stdscr, TRUE);
win = newwin(20, 60, 1, 2);
keypad(win, TRUE);
wclear(win);
wrefresh(win);
kls_show_toWin(kls,win);
refresh();
kls_showList_toWin(kls,win);
delwin(win);
endwin();

int* z = &minusone;
printf("\n*z is [%i] before KLS_POP\n",*z);

Expand Down

0 comments on commit ef45cd1

Please sign in to comment.