mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-04 04:06:06 -05:00
osc: use STRLEN() macro to make parse_rgb() more self-documenting
The empty literals in the macro are to ensure the argument itself is a string literal, so it can't be used on anything else.
This commit is contained in:
parent
6dfacb9c08
commit
2e87889279
3 changed files with 5 additions and 4 deletions
1
macros.h
1
macros.h
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#define PASTE(a, b) a##b
|
#define PASTE(a, b) a##b
|
||||||
#define XPASTE(a, b) PASTE(a, b)
|
#define XPASTE(a, b) PASTE(a, b)
|
||||||
|
#define STRLEN(str) (sizeof("" str "") - 1)
|
||||||
#define DO_PRAGMA(x) _Pragma(#x)
|
#define DO_PRAGMA(x) _Pragma(#x)
|
||||||
#define VERCMP(x, y, cx, cy) ((cx > x) || ((cx == x) && (cy >= y)))
|
#define VERCMP(x, y, cx, cy) ((cx > x) || ((cx == x) && (cy >= y)))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -158,6 +158,7 @@ vtlib = static_library(
|
||||||
'composed.c', 'composed.h',
|
'composed.c', 'composed.h',
|
||||||
'csi.c', 'csi.h',
|
'csi.c', 'csi.h',
|
||||||
'dcs.c', 'dcs.h',
|
'dcs.c', 'dcs.h',
|
||||||
|
'macros.h',
|
||||||
'osc.c', 'osc.h',
|
'osc.c', 'osc.h',
|
||||||
'sixel.c', 'sixel.h',
|
'sixel.c', 'sixel.h',
|
||||||
'vt.c', 'vt.h',
|
'vt.c', 'vt.h',
|
||||||
|
|
|
||||||
7
osc.c
7
osc.c
|
|
@ -11,6 +11,7 @@
|
||||||
#include "base64.h"
|
#include "base64.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "grid.h"
|
#include "grid.h"
|
||||||
|
#include "macros.h"
|
||||||
#include "notify.h"
|
#include "notify.h"
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
#include "selection.h"
|
#include "selection.h"
|
||||||
|
|
@ -341,12 +342,10 @@ parse_rgb(const char *string, uint32_t *color, bool *_have_alpha,
|
||||||
|
|
||||||
/* Verify we have the minimum required length (for "") */
|
/* Verify we have the minimum required length (for "") */
|
||||||
if (have_alpha) {
|
if (have_alpha) {
|
||||||
/* rgba:x/x/x/x */
|
if (len < STRLEN("rgba:x/x/x/x"))
|
||||||
if (len < 4 /* 'rgba' */ + 1 /* ':' */ + 3 /* '/' */ + 4 * 1 /* 4 * 'x' */)
|
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
/* rgb:x/x/x */
|
if (len < STRLEN("rgb:x/x/x"))
|
||||||
if (len < 3 /* 'rgb' */ + 1 /* ':' */ + 2 /* '/' */ + 3 * 1 /* 3 * 'x' */)
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue