Browse Source

Added boksi support. Updated documentation

master
dirkson 3 years ago
parent
commit
ad253519e5
  1. 20
      .lvimrc
  2. 78
      README.md
  3. 31
      build
  4. 6
      include/lob.h
  5. 4
      include/lob_basic.h
  6. 298
      include/tinyfiledialogs.h
  7. 5
      meson.build
  8. 6
      src/dependencies/README
  9. 5655
      src/dependencies/tinyfiledialogs.c
  10. 140
      src/lob.c

20
.lvimrc

@ -0,0 +1,20 @@
"Stuff you're more likely to edit goes near the top
let s:projstd = '-std=gnu89 -Wall'
let s:projinc = '-Iinclude -Isrc -Imeson/debug -Isrc/example -Isubprojects/boksi/include'
let s:projopt = ''
let g:ale_linters = {'c': ['clang', 'clangcheck']}
"let g:ale_linters = {'c': ['clang', 'clangtidy', 'clangd', 'cppcheck']}
"let g:ale_linters = {'c': ['clang', 'clangtidy', 'clangd', 'cppcheck','cquery', 'flawfinder', 'gcc']}
let s:projstrn = s:projstd.' '.s:projopt.' '.s:projinc
let g:ale_c_clang_options = s:projstrn
let g:ale_c_clangd_options = s:projstrn
let g:ale_c_clangformat_options = s:projstrn
let g:ale_c_clangcheck_options = s:projstrn
let g:ale_c_cppcheck_options = s:projstrn
let g:ale_c_gcc_options = s:projstrn
"Use build_dir instead
"let g:ale_c_clangtidy_options = projstrn
let g:ale_c_build_dir = 'meson/debug'

78
README.md

@ -3,58 +3,84 @@
Lob (or liblob) is a cross-platform, MIT-licensed, statically-compiled logging library written in C89.
It will display errors, warnings, and other messages via stdout, stderr, gui boxes, or direct writes to files. It's optionally thread safe, and optionally process-safe. All calls are blocking. It's designed to be minimal and only include the code *you* need. It prefers to log successfully over logging quickly, but it should still be quite fast. It should compile on Linux, OSX, and windows.
It will display errors, warnings, and other messages via stdout, stderr, gui boxes, or direct writes to files. It's optionally thread safe, and all calls are blocking. It's designed to be minimal and only include the code *you* need. It prefers to log successfully over logging quickly, but it should still be quite fast. It should compile on Linux, OSX, and windows.
It mostly exists because I noticed I kept copy/pasting a debug-output file to all my projects.
## Basic Use
## Documentation
To build, type 'make'. Output is lib/liblob.a , which should be usable in most C projects.
To build, type './build -r'. Output is lib/liblob.a , which should be usable in most C projects.
To build examples, type 'make examples'. Output is bin/test and bin/basic
The externally visible logging function is:
```
char lob(const unsigned char OutputFlags, const char Level, const char *Format, ...)
int lob(const lob_level Level, const char * const Format, ...)
```
OutputFlags can be any mixture of the following, bitwise-or'd together:
To include predefined levels, include "lob\_basic.h". It provides the follow levels:
```
LOB_STDOUT
LOB_FILE
LOB_GUIBOX
LOB_ERROR //Prints to stderr, log.txt, and creates a guibox
LOB_WARN //Prints to stdout and log.txt
LOB_INFO //Prints to stdout
LOB_DEBUG //Prints to stdout
LOB_TRACE //Prints to stdout
```
Level can be any of the following:
```
LOB_ERROR
LOB_WARN
LOB_INFO
LOB_DEBUG
```
Format is a printf-style formatted string, with a newline appended for you. It is followed by a list of variables, in the printf style.
lob()'s return value is determined by its level. The default levels provided by "lob\_basic.h" use 0 for LOB\_ERROR, and 1 for others.
Format is a printf-style formatted string. It is followed by a list of variables, in the printf style.
lob() returns whatever you passed as "Level". By default, this will be 'false'(0) for LOB\_ERROR, and 'true' for others.
The following example will print out its message in stdout and to a gui box, then return 0 from the parent function:
```
if (SomeCondition == Failure)
return lob(LOB_STDOUT | LOB_GUIBOX, LOB_ERROR, "Oops! This happened: %i", SomeCondition);
return lob(LOB_ERROR, "Oops! This happened: %i", SomeCondition);
```
## Available compile flags
Lob is designed to be statically compiled into whatever it's used in, and as such most configuration options are compile-time flags. This removes the unused feature from lob entirely in most cases.
You'll need to clean whenever cflags change: ./build -c
To use a flag, use this format
```
CFLAGS="-DLOB\_SOME_FLAG -DLOB\_SOME_OTHER_FLAG" ./build -r liblob.a
```
List of simple compile flags
```
LOB\_NO\_TIME //Disable timestamp
LOB\_NO\_SOURCE_FILE //Disable source file/line number
LOB\_NO\_FILE //Disable output to log files
LOB\_NO\_STDOUT //Disable output to stdout/err
LOB\_NO\_BOKSI //Disable Boksi gui boxes
LOB\_NO\_TINYFD //Disable tinyfiledialogs gui boxes. Automatically set if Boksi is enabled.
```
There are also a few more complicated flags.
Example usage:
```
CFLAGS="-DLOB\_TIME\_FORMAT=\"[%H:%M:%S] \" -DLOB\_BUFFER\_SIZE=1024" ./build -r liblob.a
```
List of more complicated flags
```
LOB\_TIME\_FORMAT //Default "[%H:%M:%S] " . Uses strftime format.
LOB\_RETURN\_TYPE //Default int . You cannot use lob_basic.h if you change this to char*.
LOB\_BUFFER\_SIZE //Default 1024 . ONLY valid for Boksi or tinyfiledialogs boxes right now. Any message longer than this will be safely truncated in its gui box.
## Advanced Use
Additional options are available at compile time. See lobtions.h
Define your own levels!
## TODO
+ Add loblvl() to allow users to change logging level at runtime.
+ Add some method to allow users to introduce their own callbacks.
+ Add some method of internet-capable logging.
+ Add logging to syslog.
+ Add LOB_PROCESS_SAFE
+ Switch to Boksi dialog box generation rather than tinyfiledialogs.
+ Add LOB\_PROCESS\_SAFE
## FAQ

31
build

@ -51,12 +51,14 @@ SCRIPTDIR=scripts
mesonbuild_help () {
echo "Usage: build -mode [target]"
echo "Mode is one of the following:"
echo "-d : debug"
echo "-r : release"
echo "-c : clean"
echo "-a : address sanitizer"
echo "-w : cross-compile for win32"
echo "-w64 : cross-compile for win64"
echo "-d : debug"
echo "-r : release"
echo "-c : clean"
echo "-fc : Fully clean - Removes dependencies too"
echo "-a : address sanitizer"
echo "-w : cross-compile for win32"
echo "-w64: cross-compile for win64"
echo "-o : cross-compile for OSX"
echo "Target will be passed to ninja directly"
}
mesonbuild_clean () {
@ -133,10 +135,19 @@ case "$1" in
exit 1
fi
mesonbuild_clean
rm -rf $DEPDIR
echo "Cleaned."
exit 0
;;
-fc)
if [ "$#" -ne 1 ]; then
echo "You passed additional arguments to clean. I have no idea what you want. Did not clean."
exit 1
fi
mesonbuild_clean
rm -rf $DEPDIR
echo "Fully cleaned."
exit 0
;;
*)
mesonbuild_help
err=1
@ -209,9 +220,12 @@ if [ -d "$SCRIPTDIR" ] && [ -e scripts/dependencies ]; then
cd ../
fi
#Set up basic directory structure, if needed
mkdir -p $BUILDDIR 2> /dev/null
#MESONOPTS=MESONOPTS:"-Dc_args=$3"
if [ ! -d "$BUILDDIR/$DIR" ]; then
export CC="$COMPILER"
#Run meson if required
@ -223,6 +237,9 @@ if [ ! -d "$BUILDDIR/$DIR" ]; then
mesonbuild_clean
exit 1
fi
#else
#May wish to look into this in the future
#meson configure $MESONOPTS
fi
#Actually build

6
include/lob.h

@ -13,9 +13,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#ifndef LOB_INCLUDED
#define LOB_INCLUDED
//Unimplemented items
#define LOB_NO_SYSLOG
#define LOB_NO_NET
#define LOB_NO_DATE
#define LOB_NO_TINYFD
//#define LOB_THREADSAFE
@ -27,6 +29,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#define LOB_TIME_FORMAT "[%H:%M:%S] "
#endif
#ifndef LOB_BUFFER_SIZE
#define LOB_BUFFER_SIZE 1024
#endif
//Colors
#define LOB_COLOR_NORMAL "\x1B[0m"
#define LOB_COLOR_RED "\x1B[31m"

4
include/lob_basic.h

@ -7,7 +7,7 @@
//This is an ugly way to define the levels.
//For a prettier method for your own code, see lob_level_init()
//ERROR
//ERROR
lob_level_t LOB_ERROR_DATA = {
//Return value
0
@ -41,7 +41,7 @@
#endif
};
//WARN
//WARN
lob_level_t LOB_WARN_DATA = {
//Return value
1

298
include/tinyfiledialogs.h

@ -1,298 +0,0 @@
/*
_________
/ \ tinyfiledialogs.h v2.7.2 [November 23, 2016] zlib licence
|tiny file| Unique header file of "tiny file dialogs" created [November 9, 2014]
| dialogs | Copyright (c) 2014 - 2016 Guillaume Vareille http://ysengrin.com
\____ ___/ http://tinyfiledialogs.sourceforge.net
\|
git://git.code.sf.net/p/tinyfiledialogs/code
_____________________________________________________
| |
| direct CONTACT: mailto:tinyfiledialogs@ysengrin.com |
|______________________________________________________|
A big thank you to Don Heyse http://ldglite.sf.net for
his code contributions, bug corrections & thorough testing!
git://git.code.sf.net/p/tinyfiledialogs/code
Please
1) let me know
- if you are including tiny file dialogs,
I'll be happy to add your link to the list of projects using it.
- If you are using it on different hardware / OS / compiler.
2) Be the first to leave a review on Sourceforge. Thanks.
tiny file dialogs (cross-platform C C++)
InputBox PasswordBox MessageBox ColorPicker
OpenFileDialog SaveFileDialog SelectFolderDialog
Native dialog library for WINDOWS MAC OSX GTK+ QT CONSOLE & more
A single C file (add it to your C or C++ project) with 6 boxes:
- message / question
- input / password
- save file
- open file & multiple files
- select folder
- color picker.
Complements OpenGL GLFW GLUT GLUI VTK SFML SDL Ogre Unity ION
CEGUI MathGL CPW GLOW IMGUI GLT NGL STB & GUI less programs
NO INIT
NO MAIN LOOP
The dialogs can be forced into console mode
Windows (XP to 10) [ASCII + MBCS + UTF-8 + UTF-16]
- native code & some vbs create the graphic dialogs
- enhanced console mode can use dialog.exe from
http://andrear.altervista.org/home/cdialog.php
- basic console input
Unix (command line call attempts) [ASCII + UTF-8]
- applescript
- zenity / matedialog
- kdialog
- Xdialog
- python2 tkinter
- dialog (opens a console if needed)
- basic console input
The same executable can run across desktops & distributions
tested with C & C++ compilers
on VisualStudio MinGW Mac Linux Bsd Solaris Minix Raspbian
using Gnome Kde Enlightenment Mate Cinnamon Unity
Lxde Lxqt Xfce WindowMaker IceWm Cde Jds OpenBox
bindings for LUA and C# dll
- License -
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef TINYFILEDIALOGS_H
#define TINYFILEDIALOGS_H
/* #define TINYFD_NOLIB */
/* On windows, define TINYFD_NOLIB here
if you don't want to include the code creating the graphic dialogs.
Then you won't need to link against Comdlg32.lib and Ole32.lib */
/* if tinydialogs.c is compiled with a C++ compiler rather than with a C compiler
(ie. you change the extension from .c to .cpp), you need to comment out:
extern "C" {
and the corresponding closing bracket near the end of this file:
}
*/
#ifdef __cplusplus
extern "C" {
#endif
extern char tinyfd_version[8]; /* contains tinyfd current version number */
#ifdef _WIN32
/* for UTF-16 use the functions at the end of this files */
extern int tinyfd_winUtf8; /* 0 (default) or 1 */
/* on windows string char can be 0:MBSC or 1:UTF-8
unless your code is really prepared for UTF-8 on windows, leave this on MBSC. */
#endif
extern int tinyfd_forceConsole ; /* 0 (default) or 1 */
/* for unix & windows: 0 (graphic mode) or 1 (console mode).
0: try to use a graphic solution, if it fails then it uses console mode.
1: forces all dialogs into console mode even when an X server is present,
if the package dialog (and a console is present) or dialog.exe is installed.
on windows it only make sense for console applications */
extern char tinyfd_response[1024];
/* if you pass "tinyfd_query" as aTitle,
the functions will not display the dialogs
but will return 0 for console mode, 1 for graphic mode.
tinyfd_response is then filled with the retain solution.
possible values for tinyfd_response are (all lowercase)
for the graphic mode:
windows applescript zenity zenity3 matedialog kdialog
xdialog tkinter gdialog gxmessage xmessage
for the console mode:
dialog whiptail basicinput */
int tinyfd_messageBox (
char const * const aTitle , /* "" */
char const * const aMessage , /* "" may contain \n \t */
char const * const aDialogType , /* "ok" "okcancel" "yesno" */
char const * const aIconType , /* "info" "warning" "error" "question" */
int const aDefaultButton ) ; /* 0 for cancel/no , 1 for ok/yes */
/* returns 0 for cancel/no , 1 for ok/yes */
char const * tinyfd_inputBox (
char const * const aTitle , /* "" */
char const * const aMessage , /* "" may NOT contain \n \t on windows */
char const * const aDefaultInput ) ; /* "" , if NULL it's a passwordBox */
/* returns NULL on cancel */
char const * tinyfd_saveFileDialog (
char const * const aTitle , /* "" */
char const * const aDefaultPathAndFile , /* "" */
int const aNumOfFilterPatterns , /* 0 */
char const * const * const aFilterPatterns , /* NULL | {"*.jpg","*.png"} */
char const * const aSingleFilterDescription ) ; /* NULL | "text files" */
/* returns NULL on cancel */
char const * tinyfd_openFileDialog (
char const * const aTitle , /* "" */
char const * const aDefaultPathAndFile , /* "" */
int const aNumOfFilterPatterns , /* 0 */
char const * const * const aFilterPatterns , /* NULL {"*.jpg","*.png"} */
char const * const aSingleFilterDescription , /* NULL | "image files" */
int const aAllowMultipleSelects ) ; /* 0 or 1 */
/* in case of multiple files, the separator is | */
/* returns NULL on cancel */
char const * tinyfd_selectFolderDialog (
char const * const aTitle , /* "" */
char const * const aDefaultPath ) ; /* "" */
/* returns NULL on cancel */
char const * tinyfd_colorChooser(
char const * const aTitle , /* "" */
char const * const aDefaultHexRGB , /* NULL or "#FF0000" */
unsigned char const aDefaultRGB[3] , /* { 0 , 255 , 255 } */
unsigned char aoResultRGB[3] ) ; /* { 0 , 0 , 0 } */
/* returns the hexcolor as a string "#FF0000" */
/* aoResultRGB also contains the result */
/* aDefaultRGB is used only if aDefaultHexRGB is NULL */
/* aDefaultRGB and aoResultRGB can be the same array */
/* returns NULL on cancel */
/************ NOT CROSS PLATFORM SECTION STARTS HERE ************************/
#ifdef _WIN32
#ifndef TINYFD_NOLIB
/* windows only - utf-16 version */
int tinyfd_messageBoxW(
wchar_t const * const aTitle ,
wchar_t const * const aMessage, /* "" may contain \n \t */
wchar_t const * const aDialogType, /* "ok" "okcancel" "yesno" */
wchar_t const * const aIconType, /* "info" "warning" "error" "question" */
int const aDefaultButton ); /* 0 for cancel/no , 1 for ok/yes */
/* returns 0 for cancel/no , 1 for ok/yes */
/* windows only - utf-16 version */
wchar_t const * tinyfd_saveFileDialogW(
wchar_t const * const aTitle, /* NULL or "" */
wchar_t const * const aDefaultPathAndFile, /* NULL or "" */
int const aNumOfFilterPatterns, /* 0 */
wchar_t const * const * const aFilterPatterns, /* NULL or {"*.jpg","*.png"} */
wchar_t const * const aSingleFilterDescription); /* NULL or "image files" */
/* returns NULL on cancel */
/* windows only - utf-16 version */
wchar_t const * tinyfd_openFileDialogW(
wchar_t const * const aTitle, /* "" */
wchar_t const * const aDefaultPathAndFile, /* "" */
int const aNumOfFilterPatterns , /* 0 */
wchar_t const * const * const aFilterPatterns, /* NULL {"*.jpg","*.png"} */
wchar_t const * const aSingleFilterDescription, /* NULL | "image files" */
int const aAllowMultipleSelects ) ; /* 0 or 1 */
/* in case of multiple files, the separator is | */
/* returns NULL on cancel */
/* windows only - utf-16 version */
wchar_t const * tinyfd_selectFolderDialogW(
wchar_t const * const aTitle, /* "" */
wchar_t const * const aDefaultPath); /* "" */
/* returns NULL on cancel */
/* windows only - utf-16 version */
wchar_t const * tinyfd_colorChooserW(
wchar_t const * const aTitle, /* "" */
wchar_t const * const aDefaultHexRGB, /* NULL or "#FF0000" */
unsigned char const aDefaultRGB[3] , /* { 0 , 255 , 255 } */
unsigned char aoResultRGB[3] ) ; /* { 0 , 0 , 0 } */
/* returns the hexcolor as a string "#FF0000" */
/* aoResultRGB also contains the result */
/* aDefaultRGB is used only if aDefaultHexRGB is NULL */
/* aDefaultRGB and aoResultRGB can be the same array */
/* returns NULL on cancel */
#endif /*TINYFD_NOLIB*/
#else /*_WIN32*/
/* unix zenity only */
char const * tinyfd_arrayDialog(
char const * const aTitle , /* "" */
int const aNumOfColumns , /* 2 */
char const * const * const aColumns, /* {"Column 1","Column 2"} */
int const aNumOfRows, /* 2*/
char const * const * const aCells);
/* {"Row1 Col1","Row1 Col2","Row2 Col1","Row2 Col2"} */
#endif /*_WIN32 */
#ifdef __cplusplus
}
#endif
#endif /* TINYFILEDIALOGS_H */
/*
- This is not for android nor ios.
- The code is pure C, perfectly compatible with C++.
- the utf-16 prototypes are in the header file
- The API is Fortran ISO_C_BINDING compliant
- C# via dll, see example file
- OSX supported from 10.4 to 10.11
- Avoid using " and ' in titles and messages.
- There's one file filter only, it may contain several patterns.
- If no filter description is provided,
the list of patterns will become the description.
- char const * filterPatterns[3] = { "*.obj" , "*.stl" , "*.dxf" } ;
- On windows link against Comdlg32.lib and Ole32.lib
This linking is not compulsary for console mode (see above).
- On unix: it tries command line calls, so no such need.
- On unix you need applescript, zenity, matedialog, kdialog, Xdialog,
python2/tkinter or dialog (will open a terminal if running without console).
- One of those is already included on most (if not all) desktops.
- In the absence of those it will use gdialog, gxmessage or whiptail
with a textinputbox.
- If nothing is found, it switches to basic console input,
it opens a console if needed.
- Use windows separators on windows and unix separators on unix.
- String memory is preallocated statically for all the returned values.
- File and path names are tested before return, they are valid.
- If you pass only a path instead of path + filename,
make sure it ends with a separator.
- tinyfd_forceConsole=1; at run time, forces dialogs into console mode.
- On windows, console mode only make sense for console applications.
- Mutiple selects are not allowed in console mode.
- The package dialog must be installed to run in enhanced console mode.
It is already installed on most unix systems.
- On osx, the package dialog can be installed via http://macports.org
- On windows, for enhanced console mode,
dialog.exe should be copied somewhere on your executable path.
It can be found at the bottom of the following page:
http://andrear.altervista.org/home/cdialog.php
- If dialog is missing, it will switch to basic console input.
- You can query the type of dialog that will be use.
- MinGW needs gcc >= v4.9 otherwise some headers are incomplete.
- The Hello World (and a bit more) is on the sourceforge site:
*/

5
meson.build

@ -11,12 +11,9 @@ if not depboksi.found()
add_project_arguments('-DLOB_NO_BOKSI', language : 'c')
endif
add_project_arguments('-DLOB_NO_BOKSI', language : 'c')
#Liblob library
#liblob = library('liblob', 'src/lob.c', include_directories : incdir, dependencies: deptinyfd)
liblob = library('liblob', 'src/lob.c', include_directories : incdir)
liblob = library('lob', 'src/lob.c', include_directories : incdir, dependencies: [ depboksi ])
lobdep = declare_dependency(link_with : liblob, include_directories : incdir)
#Basic test binary

6
src/dependencies/README

@ -1,6 +0,0 @@
tinyfiledialogs, by Guillaume Vareille, is used under a zlib licence
At the time of this writing, tinyfiledialogs is only available here:
https://sourceforge.net/projects/tinyfiledialogs/

5655
src/dependencies/tinyfiledialogs.c
File diff suppressed because it is too large
View File

140
src/lob.c

@ -10,12 +10,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
// ***Includes***
#include "lob.h"
//ONE of these must be defined
#if !defined(LOB_SINGLE_THREADED) && !defined(LOB_THREADSAFE) && !defined(LOB_PROCESS_SAFE)
#define LOB_SINGLE_THREADED
#endif
#include <stdarg.h>
#ifndef LOB_NO_TIME
@ -30,8 +24,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#endif
#ifndef LOB_NO_BOKSI
#include <boksi.h>
//#include <stdlib.h>
//#include "tinyfiledialogs.h"
#endif
#ifndef LOB_NO_TINYFD
#include <stdlib.h>
#include "tinyfiledialogs.h"
#endif
#ifndef LOB_NO_NET
#error Network logging is unimplemented. Sorry!
@ -43,10 +39,15 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#error Date is unimplemented. Sorry!
#endif
//ONE of these must be defined
#if !defined(LOB_SINGLE_THREADED) && !defined(LOB_THREADSAFE) && !defined(LOB_PROCESS_SAFE)
#error Well, that didn't work
#define LOB_SINGLE_THREADED
#endif
// ***Cross platform wrappers***
// File lockers
// Also locks stdout/err
// File lockers. Also locks stdout/err
#ifdef LOB_THREADSAFE
static inline void lob_flockfile(FILE *file)
{
@ -57,7 +58,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
flockfile(file);
#endif
}
static inline void lob_funlockfile(FILE *file)
{
#ifdef WIN32
@ -67,7 +67,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
funlockfile(file);
#endif
}
#endif
#ifdef LOB_PROCESS_SAFE
//TODO - Proccess-based file locking
//On non-windows, we use fcntl() for process-based file locking
//We do this because it works on linux, OSX, and BSD's,
@ -76,13 +78,13 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
//fcntl()
#endif
// ***Output Functions***
// They're void because, let's face it: If the error systems fails to error, what're we SUPPOSED to do?
#ifndef LOB_NO_STDOUT
#if !defined(LOB_NO_STDOUT) || !defined(LOB_NO_FILE)
//We reuse this for lob_out_file
static inline void lob_out_stdout(FILE *stdouterr, const char *const prefix, const char * const prefixColor, const char * const time, const char * const sourceFile, const int sourceLine, const char doColor, const char * const msg, va_list args)
{
{
#ifdef LOB_THREADSAFE
lob_flockfile(stdouterr);
#endif
@ -94,7 +96,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
fprintf(stdouterr, "%s", prefix);
#ifndef LOB_NO_COLOR
if (doColor)
fprintf(stdouterr, "%s", LOB_COLOR_NORMAL);
fprintf(stdouterr, "%s", LOB_COLOR_NORMAL);
#endif
#ifndef LOB_NO_TIME
#ifndef LOB_NO_COLOR
@ -132,7 +134,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
//In most situations, "\n" will flush. But just to be sure, we flush anyway.
fflush(stdout);
}
#endif
#endif
#ifndef LOB_NO_FILE
//On many platforms, writes to unclosed files may not show up.
@ -152,12 +154,27 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#endif
#ifndef LOB_NO_BOKSI
static inline void lob_out_msg(const char *prefix, const char level, char *buffer, const char *msg, va_list args)
static inline void lob_out_msg(const char * const prefix, const char * const msg, va_list args)
{
vsnprintf(buffer, LOB_MAX_BUFFER_SIZE, msg, args);
#ifdef LOB_GUIBOX_TINYFD
tinyfd_messageBox(LOB_GUIBOX_NAME, buffer, "ok", lob_get_prefix(level), 1);
#endif
char buffer[LOB_BUFFER_SIZE] = {0};
vsnprintf(buffer, LOB_BUFFER_SIZE, msg, args);
boksi_info binfo;
boksi_method bmethod[] = {
BOKSI_WIN,
BOKSI_OSX,
BOKSI_GTK3,
BOKSI_LIBUI,
BOKSI_NCURSES,
BOKSI_STDOUT,
BOKSI_GIVEUP};
boksi_set_info(&binfo, bmethod);
boksi_explicit(binfo, BOKSI_ERROR, prefix, "Ok", buffer);
//tinyfd_messageBox(LOB_GUIBOX_NAME, buffer, "ok", lob_get_prefix(level), 1);
}
#endif
@ -177,49 +194,6 @@ static inline void lob_out_syslog(const char *prefix, const char *msg, va_list a
// ***Internal Functions***
/*
static inline char* lob_get_prefix(const char level)
{
#ifdef LOB_PREFIX
switch(level)
{
#ifdef LOB_USE_ERROR
case LOB_ERROR:
return LOB_PREFIX_ERROR;
break;
#endif
#ifdef LOB_USE_WARN
case LOB_WARN:
return LOB_PREFIX_WARN;
break;
#endif
#ifdef LOB_USE_INFO
case LOB_INFO:
return LOB_PREFIX_INFO;
break;
#endif
#ifdef LOB_USE_DEBUG
case LOB_DEBUG:
return LOB_PREFIX_DEBUG;
break;
#endif
#ifdef LOB_USE_TRACE
case LOB_TRACE:
return LOB_PREFIX_TRACE;
break;
#endif
default:
//This should never happen. I hope.
return "Oops";
break;
}
#endif
return "";
}
*/
//Will not touch the string unless LOB_TIME is enabled
#ifndef LOB_NO_TIME
static inline void lob_get_time(char *timeString)
@ -244,16 +218,15 @@ extern LOB_RETURN_TYPE lob_internal(const char * const sourceFile, const int sou
char *time = NULL;
#endif
char *color;
#ifndef LOB_NO_COLOR
color = level->prefixColor;
#else
color = "";
#endif
va_list args;
#ifndef LOB_NO_STDOUT
char *color;
#ifndef LOB_NO_COLOR
color = level->prefixColor;
#else
color = "";
#endif
if (level->methods & LOB_METHOD_STDOUT)
{
va_start(args, msg);
@ -276,27 +249,14 @@ extern LOB_RETURN_TYPE lob_internal(const char * const sourceFile, const int sou
}
#endif
#ifndef LOB_NO_BOKSI
if (flags & LOB_GUIBOX)
{
//We use buffer as a quick shorthand, so we don't need to test both it AND the flags(again)
char *buffer = calloc(LOB_MAX_BUFFER_SIZE, sizeof(char));
if (buffer == NULL)
return level; //Couldn't allocate - Just give up.
va_start(args, msg);
lob_out_msg(prefix, level, buffer, msg, args);
va_end(args);
free(buffer);
}
if (level->methods & LOB_METHOD_BOKSI)
{
va_start(args, msg);
lob_out_msg(level->label, msg, args);
va_end(args);
}
#endif
return level->returnValue;
}
extern char loblvl(const char minLevel, const unsigned char flags, const char level, const char *msg, ...)
{
//if (minLevel >= level)
//return lob(flags, level, msg, ...);
return level;
}
Loading…
Cancel
Save