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 #define ARRAY_FOR_EACH(_arr, _elem) \ 32 for (size_t _i = 0; _i < ARRAY_LENGTH(_arr) && (_elem = &_arr[_i]); _i++) 33 34 #define min(a, b) (((a) < (b)) ? (a) : (b)) 35 #define max(a, b) (((a) > (b)) ? (a) : (b)) 36 37 #define ANSI_HIGHLIGHT "\x1B[0;1;39m" 38 #define ANSI_RED "\x1B[0;31m" 39 #define ANSI_GREEN "\x1B[0;32m" 40 #define ANSI_YELLOW "\x1B[0;33m" 41 #define ANSI_BLUE "\x1B[0;34m" 42 #define ANSI_MAGENTA "\x1B[0;35m" 43 #define ANSI_CYAN "\x1B[0;36m" 44 #define ANSI_BRIGHT_RED "\x1B[0;31;1m" 45 #define ANSI_BRIGHT_GREEN "\x1B[0;32;1m" 46 #define ANSI_BRIGHT_YELLOW "\x1B[0;33;1m" 47 #define ANSI_BRIGHT_BLUE "\x1B[0;34;1m" 48 #define ANSI_BRIGHT_MAGENTA "\x1B[0;35;1m" 49 #define ANSI_BRIGHT_CYAN "\x1B[0;36;1m" 50 #define ANSI_NORMAL "\x1B[0m" 51 52 53 #define ANSI_UP "\x1B[%dA" 54 #define ANSI_DOWN "\x1B[%dB" 55 #define ANSI_RIGHT "\x1B[%dC" 56 #define ANSI_LEFT "\x1B[%dD" 57 58 59 #define CASE_RETURN_STRING(a) case a: return #a 60