Skip to content

Commit

Permalink
Improve the reference chapter
Browse files Browse the repository at this point in the history
  • Loading branch information
agagniere committed Sep 4, 2024
1 parent 08061b8 commit 093cfb3
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 43 deletions.
3 changes: 2 additions & 1 deletion book/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ man: $(SphinxMan) ## Generate and open the documentation in the terminal
man $<

pdf: $(SphinxPdf) ## Generate and open the documentation as a PDF
$(Open) $(SphinxFolder)/latex/blackmagic.pdf

doxygen_html html pdf:
doxygen_html html:
$(Open) $< 2>/dev/null

.PHONY: doxygen_html html man pdf
Expand Down
4 changes: 0 additions & 4 deletions book/pages/reference/arg_count.md

This file was deleted.

4 changes: 0 additions & 4 deletions book/pages/reference/fold.md

This file was deleted.

4 changes: 1 addition & 3 deletions book/pages/reference/index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Reference

:::{toctree}
token
arg_count
fold
internal
color
log
:::
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Token manipulation
# Macros for writing macros

## Create a string literal

Expand All @@ -13,3 +13,13 @@
:::
:::{doxygendefine} CONCAT
:::

## Count arguments

:::{doxygendefine} ARG_COUNT
:::

## Fold

:::{doxygenfile} fold.h
:::
1 change: 0 additions & 1 deletion include/blackmagic/arg_count.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/**
* @file
* Count the number of arguments of a variadic macro.
* @author Antoine GAGNIERE
*/

/** Returns the 78th argument */
Expand Down
14 changes: 9 additions & 5 deletions include/blackmagic/blackmagic.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
/**
* @file
* Include all blackmagic headers with a single include
* @author Antoine GAGNIERE
*/

#include "blockmagic/token.h"
#include "blockmagic/log.h"
#include "blockmagic/for.h"
#include "blockmagic/color.h"
#include "blockmagic/enum.h"
#include "blackmagic/token.h"
#include "blackmagic/log.h"
#include "blackmagic/for.h"
#include "blackmagic/color.h"
#include "blackmagic/enum.h"
#include "blackmagic/fold.h"

/**
Expand All @@ -19,15 +20,18 @@
* @code{.c}
* #include <blackmagic/foo.h>
* @endcode
* @author Antoine GAGNIERE
*/

/**
* @dir blackmagic
* This directory contains all blackmagic headers.
* Do not add it directly to the search path for headers, prefer instead the `include` directory
* @author Antoine GAGNIERE
*/

/**
* @mainpage
* Welcome to the documentation of black magic.
* @author Antoine GAGNIERE
*/
10 changes: 9 additions & 1 deletion include/blackmagic/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* @file
*
* Human readable ANSI escape code
*/

#include "blackmagic/token.h" // STRINGIZE
Expand Down Expand Up @@ -52,6 +52,14 @@

/**
* Expands to a string literal containig an escape code setting the terminal color.
* @section example Example
* @code{.c}
* COLOR(BOLD, ITALIC, UNDERLINED, BLUE)
* @endcode
* Evaluates to:
* @code{.c}
* "\e[1;3;4;34m"
* @endcode
* @since 0.1
*/
#define COLOR(...) STRINGIZE(\e[FOLD(COLOR_JOIN __VA_OPT__(,) __VA_ARGS__)m)
Expand Down
43 changes: 22 additions & 21 deletions include/blackmagic/fold.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/**
* @file
* Apply a binary macro on any number of argument
* @author Antoine GAGNIERE
*/

#include "blackmagic/arg_count.h" // ARG_COUNT
Expand All @@ -13,7 +12,7 @@
///@{
#ifndef FOLD
/** Default fold to use, can be overridden */
# define FOLD TREE_FOLD
# define FOLD TREE_FOLD
#endif
///@}

Expand Down Expand Up @@ -45,6 +44,7 @@
*/
#define FOLD_RIGHT(M, ...) CONCAT(FOLD_RIGHT_, ARG_COUNT(__VA_ARGS__))(M __VA_OPT__(,) __VA_ARGS__)

/// @cond
#define TREE_FOLD_0(M)
#define TREE_FOLD_1(M, A) A
#define TREE_FOLD_2(M, A, B) M(A, B)
Expand All @@ -68,23 +68,24 @@
#define TREE_FOLD_20(M, A, B, C, D, ...) M(M(M(A, B), M(C, D)), TREE_FOLD_16(M, __VA_ARGS__))

#define FOLD_RIGHT_0(M)
#define FOLD_RIGHT_1(M, A) A
#define FOLD_RIGHT_2(M, A, B) M(A, B)
#define FOLD_RIGHT_3(M, A, B, C) M(A, M(B, C))
#define FOLD_RIGHT_4(M, A, B, C, D) M(A, M(B, M(C, D)))
#define FOLD_RIGHT_1(M, A) A
#define FOLD_RIGHT_2(M, A, B) M(A, B)
#define FOLD_RIGHT_3(M, A, B, C) M(A, M(B, C))
#define FOLD_RIGHT_4(M, A, B, C, D) M(A, M(B, M(C, D)))
#define FOLD_RIGHT_5(M, A, B, C, D, E) M(A, M(B, M(C, M(D, E))))
#define FOLD_RIGHT_6(M, A, ...) M(A, FOLD_RIGHT_5(M, __VA_ARGS__))
#define FOLD_RIGHT_7(M, A, B, ...) M(A, M(B, FOLD_RIGHT_5(M, __VA_ARGS__)))
#define FOLD_RIGHT_8(M, A, B, C, ...) M(A, M(B, M(C, FOLD_RIGHT_5(M, __VA_ARGS__))))
#define FOLD_RIGHT_9(M, A, ...) M(A, FOLD_RIGHT_8(M, __VA_ARGS__))
#define FOLD_RIGHT_10(M, A, ...) M(A, FOLD_RIGHT_9(M, __VA_ARGS__))
#define FOLD_RIGHT_11(M, A, ...) M(A, FOLD_RIGHT_10(M, __VA_ARGS__))
#define FOLD_RIGHT_12(M, A, ...) M(A, FOLD_RIGHT_11(M, __VA_ARGS__))
#define FOLD_RIGHT_13(M, A, ...) M(A, FOLD_RIGHT_12(M, __VA_ARGS__))
#define FOLD_RIGHT_14(M, A, ...) M(A, FOLD_RIGHT_13(M, __VA_ARGS__))
#define FOLD_RIGHT_15(M, A, ...) M(A, FOLD_RIGHT_14(M, __VA_ARGS__))
#define FOLD_RIGHT_16(M, A, ...) M(A, FOLD_RIGHT_15(M, __VA_ARGS__))
#define FOLD_RIGHT_17(M, A, ...) M(A, FOLD_RIGHT_16(M, __VA_ARGS__))
#define FOLD_RIGHT_18(M, A, ...) M(A, FOLD_RIGHT_17(M, __VA_ARGS__))
#define FOLD_RIGHT_19(M, A, ...) M(A, FOLD_RIGHT_18(M, __VA_ARGS__))
#define FOLD_RIGHT_20(M, A, ...) M(A, FOLD_RIGHT_19(M, __VA_ARGS__))
#define FOLD_RIGHT_6(M, A, ...) M(A, FOLD_RIGHT_5(M, __VA_ARGS__))
#define FOLD_RIGHT_7(M, A, B, ...) M(A, M(B, FOLD_RIGHT_5(M, __VA_ARGS__)))
#define FOLD_RIGHT_8(M, A, B, C, ...) M(A, M(B, M(C, FOLD_RIGHT_5(M, __VA_ARGS__))))
#define FOLD_RIGHT_9(M, A, ...) M(A, FOLD_RIGHT_8(M, __VA_ARGS__))
#define FOLD_RIGHT_10(M, A, ...) M(A, FOLD_RIGHT_9(M, __VA_ARGS__))
#define FOLD_RIGHT_11(M, A, ...) M(A, FOLD_RIGHT_10(M, __VA_ARGS__))
#define FOLD_RIGHT_12(M, A, ...) M(A, FOLD_RIGHT_11(M, __VA_ARGS__))
#define FOLD_RIGHT_13(M, A, ...) M(A, FOLD_RIGHT_12(M, __VA_ARGS__))
#define FOLD_RIGHT_14(M, A, ...) M(A, FOLD_RIGHT_13(M, __VA_ARGS__))
#define FOLD_RIGHT_15(M, A, ...) M(A, FOLD_RIGHT_14(M, __VA_ARGS__))
#define FOLD_RIGHT_16(M, A, ...) M(A, FOLD_RIGHT_15(M, __VA_ARGS__))
#define FOLD_RIGHT_17(M, A, ...) M(A, FOLD_RIGHT_16(M, __VA_ARGS__))
#define FOLD_RIGHT_18(M, A, ...) M(A, FOLD_RIGHT_17(M, __VA_ARGS__))
#define FOLD_RIGHT_19(M, A, ...) M(A, FOLD_RIGHT_18(M, __VA_ARGS__))
#define FOLD_RIGHT_20(M, A, ...) M(A, FOLD_RIGHT_19(M, __VA_ARGS__))
///@endcond
1 change: 0 additions & 1 deletion include/blackmagic/for.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/**
* @file
* Generate code by calling a macro repeatedly
* @author Antoine GAGNIERE
*/

/** To be used with @ref FOR */
Expand Down
2 changes: 2 additions & 0 deletions include/blackmagic/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
# define log_header() /**< Place this macro once before any log */
#endif

///@cond
#if LOG_FORMAT == LOG_FORMAT_CONSOLE
# define log_log(LEVEL, IGNORED, MESSAGE, ...) \
fprintf(LOG_FILE, "[%5s " __FILE__ ":%s:" STRINGIZE(__LINE__) "] " MESSAGE "\n", LEVEL, __func__ __VA_OPT__(, ) __VA_ARGS__)
Expand All @@ -96,6 +97,7 @@
#else
# define log_log(L, C, M, ...) /* Logs are disabled */
#endif
///@endcond

#if LOG_LEVEL >= LOG_LEVEL_FATAL
/** Report a condition that forces to program to terminate */
Expand Down
1 change: 0 additions & 1 deletion include/blackmagic/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/**
* @file
* Token manipulation.
* @author Antoine GAGNIERE
*/

/**
Expand Down

0 comments on commit 093cfb3

Please sign in to comment.