1*56bb7041Schristos /* `dir', `vdir' and `ls' directory listing programs for GNU.
2*56bb7041Schristos 
3*56bb7041Schristos    Modified by Chet Ramey for Readline.
4*56bb7041Schristos 
5*56bb7041Schristos    Copyright (C) 1985, 1988, 1990-1991, 1995-2010, 2012, 2015
6*56bb7041Schristos    Free Software Foundation, Inc.
7*56bb7041Schristos 
8*56bb7041Schristos    This program is free software: you can redistribute it and/or modify
9*56bb7041Schristos    it under the terms of the GNU General Public License as published by
10*56bb7041Schristos    the Free Software Foundation, either version 3 of the License, or
11*56bb7041Schristos    (at your option) any later version.
12*56bb7041Schristos 
13*56bb7041Schristos    This program is distributed in the hope that it will be useful,
14*56bb7041Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
15*56bb7041Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*56bb7041Schristos    GNU General Public License for more details.
17*56bb7041Schristos 
18*56bb7041Schristos    You should have received a copy of the GNU General Public License
19*56bb7041Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
20*56bb7041Schristos 
21*56bb7041Schristos /* Written by Richard Stallman and David MacKenzie.  */
22*56bb7041Schristos 
23*56bb7041Schristos /* Color support by Peter Anvin <Peter.Anvin@linux.org> and Dennis
24*56bb7041Schristos    Flaherty <dennisf@denix.elk.miles.com> based on original patches by
25*56bb7041Schristos    Greg Lee <lee@uhunix.uhcc.hawaii.edu>.  */
26*56bb7041Schristos 
27*56bb7041Schristos #ifndef _COLORS_H_
28*56bb7041Schristos #define _COLORS_H_
29*56bb7041Schristos 
30*56bb7041Schristos #include <stdio.h> // size_t
31*56bb7041Schristos 
32*56bb7041Schristos #if defined(__TANDEM) && defined(HAVE_STDBOOL_H) && (__STDC_VERSION__ < 199901L)
33*56bb7041Schristos typedef int _Bool;
34*56bb7041Schristos #endif
35*56bb7041Schristos 
36*56bb7041Schristos #if defined (HAVE_STDBOOL_H)
37*56bb7041Schristos #  include <stdbool.h> // bool
38*56bb7041Schristos #else
39*56bb7041Schristos typedef int _rl_bool_t;
40*56bb7041Schristos 
41*56bb7041Schristos #ifdef bool
42*56bb7041Schristos #  undef bool
43*56bb7041Schristos #endif
44*56bb7041Schristos #define bool _rl_bool_t
45*56bb7041Schristos 
46*56bb7041Schristos #ifndef true
47*56bb7041Schristos #  define true 1
48*56bb7041Schristos #  define false 0
49*56bb7041Schristos #endif
50*56bb7041Schristos 
51*56bb7041Schristos #endif /* !HAVE_STDBOOL_H */
52*56bb7041Schristos 
53*56bb7041Schristos /* Null is a valid character in a color indicator (think about Epson
54*56bb7041Schristos    printers, for example) so we have to use a length/buffer string
55*56bb7041Schristos    type. */
56*56bb7041Schristos struct bin_str
57*56bb7041Schristos   {
58*56bb7041Schristos     size_t len;
59*56bb7041Schristos     const char *string;
60*56bb7041Schristos   };
61*56bb7041Schristos 
62*56bb7041Schristos /* file type indicators (dir, sock, fifo, ...)
63*56bb7041Schristos    Default value is initialized in parse-colors.c.
64*56bb7041Schristos    It is then modified from the values of $LS_COLORS. */
65*56bb7041Schristos extern struct bin_str _rl_color_indicator[];
66*56bb7041Schristos 
67*56bb7041Schristos /* The LS_COLORS variable is in a termcap-like format. */
68*56bb7041Schristos typedef struct _color_ext_type
69*56bb7041Schristos   {
70*56bb7041Schristos     struct bin_str ext;         	/* The extension we're looking for */
71*56bb7041Schristos     struct bin_str seq;         	/* The sequence to output when we do */
72*56bb7041Schristos     struct _color_ext_type *next;	/* Next in list */
73*56bb7041Schristos   } COLOR_EXT_TYPE;
74*56bb7041Schristos 
75*56bb7041Schristos /* file extensions indicators (.txt, .log, .jpg, ...)
76*56bb7041Schristos    Values are taken from $LS_COLORS in rl_parse_colors(). */
77*56bb7041Schristos extern COLOR_EXT_TYPE *_rl_color_ext_list;
78*56bb7041Schristos 
79*56bb7041Schristos #define FILETYPE_INDICATORS				\
80*56bb7041Schristos   {							\
81*56bb7041Schristos     C_ORPHAN, C_FIFO, C_CHR, C_DIR, C_BLK, C_FILE,	\
82*56bb7041Schristos     C_LINK, C_SOCK, C_FILE, C_DIR			\
83*56bb7041Schristos   }
84*56bb7041Schristos 
85*56bb7041Schristos /* Whether we used any colors in the output so far.  If so, we will
86*56bb7041Schristos    need to restore the default color later.  If not, we will need to
87*56bb7041Schristos    call prep_non_filename_text before using color for the first time. */
88*56bb7041Schristos 
89*56bb7041Schristos enum indicator_no
90*56bb7041Schristos   {
91*56bb7041Schristos     C_LEFT, C_RIGHT, C_END, C_RESET, C_NORM, C_FILE, C_DIR, C_LINK,
92*56bb7041Schristos     C_FIFO, C_SOCK,
93*56bb7041Schristos     C_BLK, C_CHR, C_MISSING, C_ORPHAN, C_EXEC, C_DOOR, C_SETUID, C_SETGID,
94*56bb7041Schristos     C_STICKY, C_OTHER_WRITABLE, C_STICKY_OTHER_WRITABLE, C_CAP, C_MULTIHARDLINK,
95*56bb7041Schristos     C_CLR_TO_EOL
96*56bb7041Schristos   };
97*56bb7041Schristos 
98*56bb7041Schristos 
99*56bb7041Schristos #if !S_IXUGO
100*56bb7041Schristos # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
101*56bb7041Schristos #endif
102*56bb7041Schristos 
103*56bb7041Schristos enum filetype
104*56bb7041Schristos   {
105*56bb7041Schristos     unknown,
106*56bb7041Schristos     fifo,
107*56bb7041Schristos     chardev,
108*56bb7041Schristos     directory,
109*56bb7041Schristos     blockdev,
110*56bb7041Schristos     normal,
111*56bb7041Schristos     symbolic_link,
112*56bb7041Schristos     sock,
113*56bb7041Schristos     whiteout,
114*56bb7041Schristos     arg_directory
115*56bb7041Schristos   };
116*56bb7041Schristos 
117*56bb7041Schristos /* Prefix color, currently same as socket */
118*56bb7041Schristos #define C_PREFIX	C_SOCK
119*56bb7041Schristos 
120*56bb7041Schristos extern void _rl_put_indicator (const struct bin_str *ind);
121*56bb7041Schristos extern void _rl_set_normal_color (void);
122*56bb7041Schristos extern bool _rl_print_prefix_color (void);
123*56bb7041Schristos extern bool _rl_print_color_indicator (const char *f);
124*56bb7041Schristos extern void _rl_prep_non_filename_text (void);
125*56bb7041Schristos 
126*56bb7041Schristos #endif /* !_COLORS_H_ */
127