// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD
#include "color.h"
#include "alloc.h"
#include "bfstd.h"
#include "bftw.h"
#include "config.h"
#include "diag.h"
#include "dir.h"
#include "dstring.h"
#include "expr.h"
#include "fsade.h"
#include "stat.h"
#include "trie.h"
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
/**
* An escape sequence, which may contain embedded NUL bytes.
*/
struct esc_seq {
/** The length of the escape sequence. */
size_t len;
/** The escape sequence iteself, without a terminating NUL. */
char seq[];
};
/**
* A colored file extension, like `*.tar=01;31`.
*/
struct ext_color {
/** Priority, to disambiguate case-sensitive and insensitive matches. */
size_t priority;
/** The escape sequence associated with this extension. */
struct esc_seq *esc;
/** The length of the extension to match. */
size_t len;
/** Whether the comparison should be case-sensitive. */
bool case_sensitive;
/** The extension to match (NUL-terminated). */
char ext[];
};
struct colors {
/** esc_seq allocator. */
struct varena esc_arena;
/** ext_color allocator. */
struct varena ext_arena;
// Known dircolors keys
struct esc_seq *reset;
struct esc_seq *leftcode;
struct esc_seq *rightcode;
struct esc_seq *endcode;
struct esc_seq *clear_to_eol;
struct esc_seq *bold;
struct esc_seq *gray;
struct esc_seq *red;
struct esc_seq *green;
struct esc_seq *yellow;
struct esc_seq *blue;
struct esc_seq *magenta;
struct esc_seq *cyan;
struct esc_seq *white;
struct esc_seq *warning;
struct esc_seq *