Commit 0c0a91b9 authored by Arnaud Blanchard's avatar Arnaud Blanchard
Browse files

Big improvement of documentation

parent 4b5f3763
......@@ -11,45 +11,30 @@
cmake_minimum_required(VERSION 2.6)
get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) #The name of the project is the basename of the directory
project(${PROJECT_NAME})
project(blc_core)
#source files
set(sources
src/blc_text.cpp
src/blc_tools.cpp
src/blc_mem.cpp
src/blc_array.cpp
src/blc_realtime.cpp
)
add_definitions(-Wall -Wno-multichar -pthread)
add_definitions(-Wno-multichar -pthread)
include_directories(include)
#shared lib
add_library(${PROJECT_NAME} SHARED ${sources})
if (UNIX AND NOT APPLE) #On MacOSX -pthread is included
target_link_libraries(${PROJECT_NAME} -pthread)
endif()
set(sources
src/blc_text.cpp
src/blc_tools.cpp
src/blc_mem.cpp
src/blc_array.cpp
src/blc_realtime.cpp)
#static lib
add_library(static_${PROJECT_NAME} STATIC ${sources})
#Both librairies have the same name only the extension will change.
set_target_properties(static_${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
#Add a target to generate documentation
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(${PROJECT_SOURCE_DIR}/doxyfile.in doxyfile.doxy) #Replace the CMAKE variables in the Doxyfile
add_custom_target(doc ${DOXYGEN_EXECUTABLE} doxyfile.doxy COMMENT "Generating API documentation for ${PROJECT_NAME}" VERBATIM)
else()
message("You need to install doxygen to generate the doc.")
add_library(blc_core SHARED ${sources})
add_library(static_blc_core STATIC ${sources})
if (UNIX AND NOT APPLE) #On MacOSX -pthread is included
target_link_libraries(blc_core -pthread)
endif()
#Both version of librairies will have the same name only the extension will change.
set_target_properties(static_blc_core PROPERTIES OUTPUT_NAME blc_core)
#Describe what will be to install or in the package by default the prefix (CMAKE_INSTALL_PREFIX) is '/usr/’
install(DIRECTORY include/ DESTINATION include/${PROJECT_NAME})
install(TARGETS ${PROJECT_NAME} static_${PROJECT_NAME} DESTINATION lib)
install(FILES ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}-config.cmake DESTINATION share/${PROJECT_NAME})
#Describe what will have to be installed or in the package by default the prefix (CMAKE_INSTALL_PREFIX) is '/usr/’ or '/usr/local' depending on your system
install(DIRECTORY include/ DESTINATION include/blc_core)
install(TARGETS ${PROJECT_NAME} static_blc_core DESTINATION lib)
install(FILES ${PROJECT_SOURCE_DIR}/blc_core-config.cmake DESTINATION share/blc_core)
#Package
set(CPACK_GENERATOR "DEB")
......
INSTALL
=======
You are advised to used standard [blaar install](https://framagit.org/blaar/blaar/wikis/INSTALL) but you are free to make a manual installation
Manual install with cmake
-------------------------
You need git, g++, cmake and doxygen for the documentation:
- Ubuntu:
```sh
sudo apt-get install git g++ cmake
```
- OSX with [homebrew](http://brew.sh) and any C++ compiler
```sh
brew install git cmake
```
You can copy past the following code:
```sh
git clone https://framagit.org/blaar/blc_core.git
cd blc_core
mkdir build
cd build
cmake ..
make
sudo make install
```
The created library `libblc_core.{so|dylib}` and `libblc_core.a` will be in `/usr/local/lib`. Includes in `/usr/local/include/blc_core` and a cmake config file in `/usr/local/share/blc_core`
You can create a debian package (.deb) with:
make package
Manual install with simple makefiles
====================================
All the sources are in src, includes in include and the previous lines allow you to create an adequate makefile
BLC core : Core of Basic Libraries for C/C++
BLC core : Core of Basic Libraries for C/C++
============================================
- Copyright : [ETIS](http://www.etis.ensea.fr/neurocyber) - ENSEA, University of Cergy-Pontoise, CNRS (2011-2016)
- Author : [Arnaud Blanchard](http://arnaudblanchard.thoughtsheet.com)
- Licence : [CeCILL v2.1](http://www.cecill.info/licences/Licence_CeCILL_V2-en.html)
Core functions used by almost all the projects of [BLAAR](https://framagit.org/blaar/blaar/wikis/home)
Core functions used by almost all the projects of [BLAAR](https://framagit.org/blaar/blaar)
It is composed of five main files (need a POSIX system), for Linux and OSX.
......@@ -17,7 +17,7 @@ It is composed of five main files (need a POSIX system), for Linux and OSX.
[Standard blaar install](https://framagit.org/blaar/blaar/wikis/install) automatically installs it.
However, independently of blaar, you can [manually build the library](Install)
However, independently of blaar, you can [manually build the library](https://framagit.org/blaar/blc_core/blob/master/INSTALL)
[More details and examples](https://framagit.org/blaar/blc_core/wikis/home)
PROJECT_NAME = ${PROJECT_NAME}
OUTPUT_DIRECTORY = ${PROJECT_SOURCE_DIR}
OPTIMIZE_OUTPUT_FOR_C = YES
EXTRACT_LOCAL_CLASSES = NO
HIDE_UNDOC_MEMBERS = YES
HIDE_UNDOC_CLASSES = YES
HIDE_FRIEND_COMPOUNDS = YES
HIDE_IN_BODY_DOCS = YES
CASE_SENSE_NAMES = NO
SORT_MEMBER_DOCS = NO
QUIET = YES
INPUT = ${PROJECT_SOURCE_DIR}
RECURSIVE = YES
USE_MDFILE_AS_MAINPAGE = ${PROJECT_SOURCE_DIR}/README.md
ALPHABETICAL_INDEX = NO
HTML_OUTPUT = .
GENERATE_LATEX = NO
MACRO_EXPANSION = YES
PREDEFINED = __cplusplus = 1
REPEAT_BRIEF = YES
SKIP_FUNCTION_MACROS = NO
CLASS_DIAGRAMS = NO
SHOW_FILES = NO
......@@ -14,101 +14,151 @@
 and, more generally, to use and operate it in the same conditions as regards security.
 The fact that you are presently reading this means that you have had knowledge of the CeCILL v2.1 license and that you accept its terms. */
/**
@date Apr 28, 2014
@author Arnaud Blanchard
@defgroup blc_array Blc mem more informations about type, format and dims of the data.
@{
This kind of functionnalities are more complete with the Standard Template Library (STL) but it much simpler here.
*/
#ifndef BLC_ARRAY_H
#define BLC_ARRAY_H
#include "blc_tools.h"
#include "blc_mem.h"
/**
@defgroup blc_array blc_array
@{
@brief blc_mem with more informations about type, format and structures (dimensions) of the data.
*/
/**Like EXIT_ON_ERROR but displays all the informations about the array on stderr before quitting. Useful to debug.*/
#define EXIT_ON_ARRAY_ERROR(array, ...) blc_array_fatal_error(array, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
///Description of a dimension properties of a blc_array.
typedef struct blc_dim {
size_t length;
size_t step;
size_t length; ///<number of element for the dimension
size_t step; ///< shift in bytes to do to pass from one element of this dimension to the next one
} blc_dim;
///Description of a n-dimensional array with type and format
typedef struct blc_array
#ifdef __cplusplus
:blc_mem {
/**Define an empty array*/
blc_array();
/**Define and allocates the array */
blc_array(uint32_t type, uint32_t format, int dims_nb, int length0, ...);
/**Free dims. The data is freed by ~blc_mem()*/
~blc_array();
/**def and does not allocate*/
/* Definiting the array without allocation. Useful when you want to use external buffer
====================================================================================*/
/**Defines the blc_array but does not allocate memory (data)*/
void vdef_array(uint32_t type, uint32_t format, int dims_nb, int length0, va_list arguments);
/**Defines the blc_array but does not allocate memory (data)*/
void def_array(uint32_t type, uint32_t format, int dims_nb, int length0, ...);
/**Defines the blc_array but does not allocate memory (data)*/
void def_array(uint32_t type, uint32_t format, int dims_nb, blc_dim *dims);
/**Defines the blc_array but does not allocate memory (data)*/
void def_array(uint32_t type, uint32_t format, char const *dims_string);
/*the name should be changed*/
/* Allocating the array
====================*/
/**Defines and allocates the blc_array with a string (i.e. "UIN8 RGB3 3x800x600")*/
void init(char const *properties);
/**Defines and allocates the blc_array */
void vinit(uint32_t type, uint32_t format, int dims_nb, int length, va_list arguments);
/**Defines and allocates the blc_array */
void init(uint32_t type, uint32_t format, int dims_nb, int length0, ...);
/* Printing informations about the blc_array
==========================================*/
/**Print the properties of the dims in a string (i.e. "3x800x600" )*/
int sprint_dims(char *string, int max_string_size);
/**Print the properties of the dims in a file or stderr by default (i.e. "3x800x600" )*/
int fprint_dims(FILE *file=stderr) const;
/**Print all the informations about the blc_array. Useful for debuging.*/
void fprint_debug(FILE *file=stderr) const;
/**Print all the properties of the array in a string (i.e. "UIN8 RGB3 3x800x600")*/
void sprint_properties(char *string, size_t max_string_size);
/**Print all the properties of the array in a file or stderr by default. (i.e. "UIN8 RGB3 3x800x600")*/
void fprint_properties(FILE *file=stderr);
/* Modifying the properties of the array
======================================*/
/**Add one dimention to the definition of the blc_array. You have to manage eventual **memory reallocation** yourself.*/
void add_dim(int length, int step);
/**Add one dimension ti the definition of the blc_array. The step is infered from the type of the data and the size of the previous dimension. You have to manage the eventual **memory reallocation** yourself.*/
void add_dim(int length);
/** Set all the dims of the array*/
void set_dims(int dims_nb, int length, ...);
int sprint_dims(char *string, int size);
int fprint_dims(FILE *file) const;
void fprint_debug(FILE *file) const;
/**Set all dims by reading the properties from the string (i.e. "3x800x600" ). You have to manage eventual **memory reallocation** yourself. */
int sscan_dims(char const* string);
/**Set all dims by reading the properties from the file (i.e. "3x800x600" ). You have to manage eventual **memory reallocation** yourself. */
void fscan_dims(FILE *file);
/**Set all properties by reading the properties from the string (i.e. "UIN8 RGB3 3x800x600" ). You have to manage eventual **memory reallocation** yourself. */
void sscan_properties(char const *string);
/**Set all properties by reading the properties from the file (i.e. "UIN8 RGB3 3x800x600" ). You have to manage eventual **memory reallocation** yourself. */
void fscan_properties(FILE *file);
// size_t get_minimum_size();
/*Reading data from files
======================*/
void sprint_properties(char *buffer, size_t buffer_size);
void fprint_properties(FILE *file);
///Scan and interpret the string as the description of the dimensions of a **blc_channel**. **Return** how many chars have been interpreted.
int sscan_dims(char const* string);
int get_type_size();
size_t get_minimum_size();
/**Defines the array without allocating the data by reading the file with .blc extension*/
void def_with_blc_file(char const *filename);
/**Defines and allocates the blc_array depending on the description of the blc file (with .blc extension) but does not update the data. This allow you to refresh data without reallocating memory.*/
void init_with_blc_file(char const *filename);
/**Update the content of the memory with the content of the blc file. The blc_array has to be properly defined and allocated before. .blc format is a specific format, whre de first line is the properties of the blc_array and them it is raw binary memory. It may be a problem with endianness */
void update_with_blc_file(char const *filename);
void save_blc_file(char const *filename);
void fprint_tsv(FILE *file);
/**Same as update_with_blc_file but this reas .tsv, tab separated values (i.e. 0.75 0.33 0.55 ). Typically used with excel and similar. You have to care yourself to define and allocate an appropriate blc_array.*/
void update_with_tsv_file(char const *filename);
void save_tsv_file(char const *filename);
/*Writing data in files
=====================*/
/**Create a .blc file with the content of the blc_array. This is meant to be used with init_with_blc_file, update_with_blc_file.*/
void save_blc_file(char const *filename);
/**Write the content of the blc_array as TSV (tab separated values) in a file. It can also be used to write on the terminal.*/
void fprint_tsv(FILE *file=stderr);
/**Comme fprint_tsv but automtically create the file. With filename which must have .tsv extension.*/
void save_tsv_file(char const *filename);
/**Print the blc_array as a text_graph surface. Only works with 2D blc_array of type 'UIN8'. It draws a matrix of values. If ansi terminal is 1, it draws colored valuse depending on the blc_uchar_color_scale.*/
void fprint_surface_uchars(FILE *file, int ansi_terminal=0);
/*miscellaneous
=============*/
/**Return the size in bytes of one element depending on the type of data of the blc_array*/
int get_type_size();
#else
{
blc_mem mem;
blc_mem mem; ///< raw memory of the array
#endif
blc_dim * dims;
int dims_nb;
uint32_t type, format;
size_t total_length;
blc_dim * dims; ///< array of dimentions of the blc_array
int dims_nb; ///< number of dimension of the blc_array
uint32_t type; ///< type of data in the memory as a unsigned int of 4 bytes. Possibilities are 'UIN8' uchar, 'INT8' char, 'UI16' uint16_t, 'IN16' int16_t, 'UI32' uint32_t, 'IN32' int32_t, 'FL32' float, 'FL64' double
uint32_t format; ///< describes how the data should be interpreted. 'NDEF' (no specification), 'TEXT' for strings, 'Y800' black and white image, 'RGB3' image in RGB, 'LPCM' sound in non compressed format, ...
size_t total_length; ///<Total number of elements in the array. This differ of size if an element is bigger than one byte.
} blc_array;
/*Plain C functions ( work also with C++)
===============================*********/
START_EXTERN_C
/**Define but does not allocate the blc_array.*/
void blc_array_def(blc_array *blc_array, uint32_t type, uint32_t format, int dims_nb, int length0, ...);
/**Define and allocate the blc_array*/
void blc_array_init(blc_array *blc_array, uint32_t type, uint32_t format, int dims_nb, int length0, ...);
/** like blc_fatal_error but add informations about the blc_array. You should not call it, it is called by EXIT_ON_ARRAY_ERROR*/
void blc_array_fatal_error(blc_array const *array, const char *name_of_file, const char* name_of_function, int numero_of_line, const char *message, ...);
/**Free the dims description and data if not null of the array*/
void blc_array_destroy(blc_array *array);
/**Display a 3D matrix ( tipically a image). The interface will change to be simplified*/
void fprint_3Dmatrix(FILE *file, blc_mem *mem, int offset, int step0, int length0, int step1, int width, int step2, int height, int ansi_terminal);
END_EXTERN_C
///@}
#endif
#ifndef BLC_CORE_H
#define BLC_CORE_H
#include "blc_array.h"
#include "blc_mem.h"
#include "blc_realtime.h"
#include "blc_text.h"
#include "blc_tools.h"
#include "blc_mem.h"
#include "blc_array.h"
#include "blc_realtime.h"
#endif
......@@ -14,30 +14,7 @@
 and, more generally, to use and operate it in the same conditions as regards security.
 The fact that you are presently reading this means that you have had knowledge of the CeCILL v2.1 license and that you accept its terms. */
/**
@date Apr 28, 2014
@author Arnaud Blanchard
@defgroup blc_mem blc_mem
@{
@brief Structure with a data pointer and a size. This kind of functionnalities are more complete with the Standard Template Library (STL) or boost, but it is much simpler here.
@code{.c}
typedef struct blc_mem {
//This union is a convenient shortcut for casting the data pointer.
union{
void *data;
char *chars;
uchar *uchars;
int16_t *ints16;
uint16_t *uints16;
int32_t *ints32;
uint32_t *uints32;
float *floats;
double *doubles;
};
size_t size;
}
@endcode
*/
#ifndef BLC_MEM_H
#define BLC_MEM_H
......@@ -45,8 +22,19 @@
#include "blc_tools.h"
#include <stdio.h>
/**
@defgroup blc_mem blc_mem
@{
@brief Provides simple tools to dynamically manipulate memory.
This kind of functionnalities are more complete with the Standard Template Library (https://en.wikipedia.org/wiki/Standard_Template_Library) but it much simpler here and works with plain C.
blc_mem is included in blc_array
*/
/** Description of a block of memory with a pointer and a size.*/
typedef struct blc_mem {
//We can use only one of this datatpe at a time
///The union is used to cast the pointer in whatever you want. It does NOT mean you allocate n pointers.
union{
void *data;
char *chars;
......@@ -58,9 +46,10 @@ typedef struct blc_mem {
float *floats;
double *doubles;
};
size_t size;
size_t size; ///<Size of the memory in bytes
#ifdef __cplusplus
/**Initiallize blc_mem with empty data and size*/
blc_mem();
/** Create and allocate memory of size size */
blc_mem(size_t size);
......@@ -83,17 +72,27 @@ typedef struct blc_mem {
/** Reset all the value to 'value'. */
void reset(int value=0);
void fprint_graph_uchars(FILE *file, char const *title, int height, int max, int min, char const* abscissa_name=NULL, char const* ordinate_name = NULL);
/** Draw text only the graph usually on a terminal based on the uchars data. If you want to draw more than one graph, use blc_mems_fprint_graph_uchars
@param file ouptut where to graph (usually stderr)
@param title title of the graph
@param height height of the text graph in lines of text
@param max top value drawn. It is in this order (max first) to avoid to set min when it is 0
@param min is the bottom value drawn
@param abscissa_name text displayed in the abscissa. It as to be the same for all graphs
@param ordinate_name text displayed in ordonate
*/
void fprint_graph_uchars(FILE *file, char const *title, int height, int max=255, int min=0, char const* abscissa_name=NULL, char const* ordinate_name = NULL);
#endif
}blc_mem;
#ifndef __cplusplus
#define BLC_MEM_INITIALIZER {.data=NULL, .size=0}
#endif
START_EXTERN_C
///Useful only on plain C. C++ initializes in the constructor
#define BLC_MEM_INITIALIZER {.data=NULL, .size=0}
/// Allocate or reallocate memory as needed but lose the content.
/// Allocate or reallocate memory as requested by **size** but lose the content.
void blc_mem_allocate(blc_mem *mem, size_t size);
/// Reallocate memory and keep the content.
void blc_mem_reallocate(blc_mem *mem, size_t size);
......@@ -101,11 +100,22 @@ void blc_mem_reallocate(blc_mem *mem, size_t size);
void blc_mem_replace(blc_mem *mem, char const* data, size_t size);
/// Increase the size and append the data at the end.
void blc_mem_append(blc_mem *mem, char const* data, size_t size);
/// Draw graphs based and blc_mems data
void blc_mems_fprint_graph_uchars(blc_mem *const *mems, int mems_nb, FILE *file, char const *const* title, int height, int max, int min, char const* abscissa_name, char const* ordinate_name );
/// Draw text graphs usually on the terminal based and blc_mems uchars.
/**
@param mems pointer to an array of blc_mem to graph
@param mems_nb number of blc_mems to graph
@param file ouptut where to graph (usually stderr)
@param titles array of graph titles
@param height height of the text graph in lines of text
@param max top value drawn. It is in this order (max first) to be consistent with c++ version
@param min is the bottom value drawn
@param abscissa_name text displayed in the abscissa. It as to be the same for all graphs
@param ordinate_name text displayed in ordonate
*/
void blc_mems_fprint_graph_uchars(blc_mem *const *mems, int mems_nb, FILE *file, char const *const* titles, int height, int max, int min, char const* abscissa_name, char const* ordinate_name );
END_EXTERN_C
///@}
//@}
#endif
......@@ -13,37 +13,41 @@
 and, more generally, to use and operate it in the same conditions as regards security.
 The fact that you are presently reading this means that you have had knowledge of the CeCILL v2.1 license and that you accept its terms. */
/**
@defgroup blc_realtime realtime
Few functions helping for pseudo realtime applications.
@{*/
#ifndef BLC_REALTIME_H
#define BLC_REALTIME_H
#include "blc_tools.h"
#include <semaphore.h>
#define EXIT_ON_PTHREAD_ERROR(pthread_error_id, ...) fatal_pthread_error(__FILE__, __FUNCTION__, __LINE__, pthread_error_id, NULL, __VA_ARGS__)
///Stop on pthread error and display the error message. Error is any int variable you need to provide to the macro.
/**
@defgroup blc_realtime blc_realtime
Few functions and shortcut helping for pseudo (standard unix is not realtime anyway) realtime applications
@{*/
///Maximum size of a semaphore name
#define BLC_SEM_NAME_LEN 31 // At least on OSX
/**Write the appropriate message error and exit the program for functions error returned by pthread_... functions. It is similar to EXIT_ON_SYSTEM_ERROR but for pthread_... functions*/
#define EXIT_ON_PTHREAD_ERROR(pthread_error_id, ...) fatal_pthread_error(__FILE__, __FUNCTION__, __LINE__, pthread_error_id, NULL, __VA_ARGS__)
/**Execute the command which should be something like 'pthread_...', check the return value and display the error message and exit on error. Error_variable is any int variable you need to provide to the macro. It will be set to 0 in case of success.
It is a good habit to always check the return value of this function. Exemple:
@code{.c}
int error_id;
pthread_t thread;
PTHREAD_CHECK(pthread_create(&thread, NULL, your_callback, your_callback_argument), error_id, "Failling creating thread ...");
@endcode
In case of error, you will know the line, the file, the command that was executed and the error in human readable form.*/
#define PTHREAD_CHECK(command, error_variable, ...) do{if (((error_variable)=(command))) fatal_pthread_error(__FILE__, __FUNCTION__, __LINE__, error_variable, STRINGIFY(command), __VA_ARGS__);}while(0)
START_EXTERN_C
///This is called by EXIT_ON_PTHREAD_ERROR and PTHREAD_CHECK, you should not need it directly.
void fatal_pthread_error(const char *name_of_file, const char* name_of_function, int numero_of_line, int error_id, const char *command, const char *message, ...);
/// Return the time difference between the timeval struct and the actual time. If time is empty, it is filled with the current time and 0 is returned.
///Return the time difference between the timeval struct and the actual time and set the time to the current time.
long us_time_diff(struct timeval *time);
///Check weather a semaphore is locked. You may use sem_getvalue instead but it does not exist on darwin (Mac OSX).
int sem_is_locked(sem_t *sem);
/**Try to lock the mutex in timeout micro seconds.
@return 1 in case of immediate success, -1 in case of succes after microseconds, 0 in case of failure */
int blc_mutex_trylock_in_time(pthread_mutex_t *mutex, uint32_t microseconds);
END_EXTERN_C
///@}
#endif
///@}
\ No newline at end of file
......@@ -15,29 +15,19 @@
 The fact that you are presently reading this means that you have had knowledge of the CeCILL v2.1 license and that you accept its terms.*/
/**
@defgroup blc_text Text_tools
@{
@brief Provide tools to manipulate text on files or on the terminal (color, formating, ...).
Consider using ncurses ( https://www.gnu.org/software/ncurses ) for more interactive tools with the terminal.
@code {.c}
#include "blc.h"
int main(int argc, char **argv){
int rows_nb, columns_nb;
float values[3]={1.3, 4.2, 5.5};
color_printf(BLC_BLUE, "\nJ'écris en bleu\n\n");
underline_printf('=', "J'écris souligné avec des '='");
fprint_tsv_floats(stdout, values, 3);
blc_terminal_get_size(&columns_nb, &rows_nb);
printf("\nTaille du terminal %dx%d\n", columns_nb, rows_nb);
fprint_human_size(stdout, 1000456670); //1Kb = 1024b
printf("\n");
@mainpage Summary
Blc core is composed of these five modules (one file each):
- @ref blc_text manipulates strings, text files and terminal interaction (colors, size, ...).
- @ref blc_tools various low level tools and shortcuts, error checks, simple memory management, ...
- @ref blc_realtime few functions to mesure time, manage pthreads and semaphores.
- @ref blc_mem manipulates simple blocks of memory with reallocations.
- @ref blc_array manipulates memory as n-dimentional arrays allowing to represent sound, images or anykind of data.
return EXIT_SUCCESS;
}
@endcode
*/
#ifndef BLC_TEXT_H
#define BLC_TEXT_H
......@@ -46,6 +36,15 @@
#include "blc_tools.h"
#include "blc_mem.h"
/**
@defgroup blc_text blc_text
@{
@brief Provide tools to manipulate text on files or on the terminal (color, formating, ...)
Consider using ncurses ( https://www.gnu.org/software/ncurses ) for more complex interactive tools with the terminal.
*/
#define MOVE_BEGIN_PREVIOUS_N_LINES "%dF"
#define DEL_END_SCREEN "0J"
......@@ -80,8 +79,7 @@ enum BLC_COLORS{
BLC_COLORS_NB
};
// eprint for info print (stderr) to oppose standard cursor (stdout) usually not used
///eprint for info print (stderr) to oppose standard cursor (stdout) usually not used
#define blc_eprint_cursor_position(row, column) eprintf_escape_command("%d;%dH", row, column);
#define blc_eprint_cursor_up(rows_nb) eprintf_escape_command("%dA", rows_nb);
#define blc_eprint_cursor_down(rows_nb) eprintf_escape_command("%dB", rows_nb);
......@@ -91,122 +89,95 @@ enum BLC_COLORS{
#define blc_eprint_del_end_screen() eprintf_escape_command("0J");
#define blc_fprint_del_end_line(file) fprintf_escape_command(file, "0K");
//Shortcut to escape directly on stdout
///Shortcut to escape directly on stdout
#define printf_escape_command( ...) if (blc_stdout_ansi) fprintf_escape_command(stdout, __VA_ARGS__)
//Shortcut to escape directly on stderr
///Shortcut to escape directly on stderr
#define eprintf_escape_command( ...) if (blc_stderr_ansi) fprintf_escape_command(stderr, __VA_ARGS__)
///Start a new color for the standart output.
#define print_start_color(color_id) fprint_start_color(stdout, color_id)
///Reset the default color for the standart output.
#define print_stop_color() fprint_stop_color(stdout)
///
///Shortcut to print directly on stdout with color only if stdout accept color
#define color_printf(color_id, ...) do{if(blc_stdout_ansi) color_fprintf(color_id, stdout, __VA_ARGS__); else fprintf(stderr, __VA_ARGS__);}while(0)
///
///Shortcut to print directly on stderr only if stderr accept colors
#define color_eprintf(color_id, ...) do{if(blc_stderr_ansi) color_fprintf(color_id, stderr, __VA_ARGS__); else fprintf(stderr, __VA_ARGS__);}while(0)
///Same as color_eprintf but take a va_list of arguments like vprintf
#define color_veprintf(color_id, ...) do{if(blc_stderr_ansi) color_vfprintf(color_id, stderr, __VA_ARGS__); else vfprintf(stderr, __VA_ARGS__);}while(0)