Browse Source

Added vlob

master
dirkson 3 years ago
parent
commit
2324622230
  1. 2
      README.md
  2. 6
      include/lob.h
  3. 8
      meson.build
  4. 23
      src/lob.c

2
README.md

@ -82,6 +82,8 @@ LOB_BUFFER_SIZE //Default 256 . ONLY valid for Boksi or tinyfiledialogs boxes
Define your own levels! See include/lob_basic.h
If you need to pass in a va_list, you can call "vlob" rather than plain "lob". It takes all the same arguments, with the exception of a va_list instead of a list of arguments.
## TODO
+ Add some method to allow users to introduce their own callbacks.

6
include/lob.h

@ -19,6 +19,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#define LOB_NO_DATE
#define LOB_NO_TINYFD
#include <stdarg.h>
//#define LOB_THREADSAFE
#ifndef LOB_RETURN_TYPE
@ -119,13 +121,17 @@ typedef lob_level_t* lob_level;
//They do not change the external calling of lob
#ifndef LOB_NO_SOURCE_FILE
#define lob(...) lob_internal(__FILE__, __LINE__, __VA_ARGS__)
#define vlob(...) vlob_internal(__FILE__, __LINE__, __VA_ARGS__)
#else
#define lob(...) lob_internal(NULL, 0, __VA_ARGS__)
#define vlob(...) vlob_internal(NULL, 0, __VA_ARGS__)
#endif
//This should be considered the 'lob' definition, outside of
//the first two arguments provided by the preprocessor macro
extern LOB_RETURN_TYPE lob_internal(const char * const, const int, const lob_level, const char * const, ...);
extern LOB_RETURN_TYPE vlob_internal(const char * const, const int, const lob_level, const char * const, va_list);
// ***Include guards***

8
meson.build

@ -11,14 +11,6 @@ if not depboksi.found()
add_project_arguments('-DLOB_NO_BOKSI', language : 'c')
endif
#cc = meson.get_compiler('c')
#depm = cc.find_library('m', required : false)
#if not depm.found()
#add_project_arguments('-DLOB_NO_ALLOCATE', language : 'c')
#endif
#Liblob library
#liblob = library('liblob', 'src/lob.c', include_directories : incdir, dependencies: deptinyfd)
liblob = library('lob', 'src/lob.c', include_directories : incdir, dependencies: [ depboksi ])
lob_dep = declare_dependency(link_with : liblob, include_directories : incdir)

23
src/lob.c

@ -293,18 +293,15 @@ static inline void lob_get_time(char *timeString)
// ***External Functions***
extern LOB_RETURN_TYPE lob_internal(const char * const sourceFile, const int sourceLine, const lob_level level, const char * const msg, ...)
extern LOB_RETURN_TYPE vlob_internal(const char * const sourceFile, const int sourceLine, const lob_level level, const char * const msg, va_list args)
{
#ifndef LOB_NO_TIME
char time[LOB_TIME_STRINGLEN] = "";
// if (level->options & LOB_OPTION_TIME)
lob_get_time(time);
#else
char *time = NULL;
#endif
va_list args;
#ifndef LOB_NO_STDOUT
char *color;
#ifndef LOB_NO_COLOR
@ -314,34 +311,36 @@ extern LOB_RETURN_TYPE lob_internal(const char * const sourceFile, const int sou
#endif
if (level->methods & LOB_METHOD_STDOUT)
{
va_start(args, msg);
lob_out_generic(stdout, level->txtFormat, level->label, color, time, sourceFile, sourceLine, 1, msg, args);
va_end(args);
}
if (level->methods & LOB_METHOD_STDERR)
{
va_start(args, msg);
lob_out_generic(stderr, level->txtFormat, level->label, color, time, sourceFile, sourceLine, 1, msg, args);
va_end(args);
}
#endif
#ifndef LOB_NO_FILE
if (level->methods & LOB_METHOD_FILE)
{
va_start(args, msg);
lob_out_file(level->file, level->txtFormat, level->label, time, sourceFile, sourceLine, msg, args);
va_end(args);
}
#endif
#ifndef LOB_NO_BOKSI
if (level->methods & LOB_METHOD_BOKSI)
{
va_start(args, msg);
lob_out_boksi(level->label, level->guiFormat, msg, args);
va_end(args);
}
#endif
return level->returnValue;
}
extern LOB_RETURN_TYPE lob_internal(const char * const sourceFile, const int sourceLine, const lob_level level, const char * const msg, ...)
{
va_list args;
va_start(args, msg);
LOB_RETURN_TYPE ret = vlob_internal(sourceFile, sourceLine, level, msg, args);
va_end(args);
return ret;
}
Loading…
Cancel
Save