xref: /third_party/libinput/src/util-macros.h (revision a46c0ec8)
1/*
2 * Copyright © 2008-2011 Kristian Høgsberg
3 * Copyright © 2011 Intel Corporation
4 * Copyright © 2013-2015 Red Hat, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 */
25
26#pragma once
27
28#include "config.h"
29
30#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
31/**
32 * Iterate through the array _arr, assigning the variable elem to each
33 * element. elem only exists within the loop.
34 */
35#define ARRAY_FOR_EACH(_arr, _elem) \
36	for (__typeof__((_arr)[0]) *_elem = _arr; \
37	     _elem < (_arr) + ARRAY_LENGTH(_arr); \
38	     _elem++)
39
40#define min(a, b) (((a) < (b)) ? (a) : (b))
41#define max(a, b) (((a) > (b)) ? (a) : (b))
42
43#define ANSI_HIGHLIGHT		"\x1B[0;1;39m"
44#define ANSI_RED		"\x1B[0;31m"
45#define ANSI_GREEN		"\x1B[0;32m"
46#define ANSI_YELLOW		"\x1B[0;33m"
47#define ANSI_BLUE		"\x1B[0;34m"
48#define ANSI_MAGENTA		"\x1B[0;35m"
49#define ANSI_CYAN		"\x1B[0;36m"
50#define ANSI_BRIGHT_RED		"\x1B[0;31;1m"
51#define ANSI_BRIGHT_GREEN	"\x1B[0;32;1m"
52#define ANSI_BRIGHT_YELLOW	"\x1B[0;33;1m"
53#define ANSI_BRIGHT_BLUE	"\x1B[0;34;1m"
54#define ANSI_BRIGHT_MAGENTA	"\x1B[0;35;1m"
55#define ANSI_BRIGHT_CYAN	"\x1B[0;36;1m"
56#define ANSI_NORMAL		"\x1B[0m"
57
58#define ANSI_UP			"\x1B[%dA"
59#define ANSI_DOWN		"\x1B[%dB"
60#define ANSI_RIGHT		"\x1B[%dC"
61#define ANSI_LEFT		"\x1B[%dD"
62
63#define CASE_RETURN_STRING(a) case a: return #a
64
65#define _fallthrough_ __attribute__((fallthrough))
66