1 /* helpers.h -- main header file */
2 
3 /*
4  * This file is part of CliFM
5  *
6  * Copyright (C) 2016-2021, L. Abramovich <johndoe.arch@outlook.com>
7  * All rights reserved.
8 
9  * CliFM is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * CliFM is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22  * MA 02110-1301, USA.
23 */
24 
25 #ifndef HELPERS_H
26 #define HELPERS_H
27 
28 #if defined(__linux__) && !defined(_BE_POSIX)
29 #define _GNU_SOURCE
30 #else
31 #define _POSIX_C_SOURCE 200809L
32 #define _DEFAULT_SOURCE
33 #define _XOPEN_SOURCE /* wcwidth() */
34 #if defined(__FreeBSD__)
35 #define __XSI_VISIBLE 700
36 #define __BSD_VISIBLE 1
37 #endif
38 #ifdef __NetBSD__
39 #define _NETBSD_SOURCE
40 #endif
41 #ifdef __OpenBSD__
42 #define _BSD_SOURCE
43 #endif
44 #endif
45 
46 /* Setting GLOB_BRACE to ZERO disables support for GLOB_BRACE if not
47  * available on current platform */
48 #if !defined(__TINYC__) && !defined(GLOB_BRACE)
49 #define GLOB_BRACE 0
50 #endif
51 
52 /* Support large files on ARM or 32-bit machines */
53 #if defined(__arm__) || defined(__i386__)
54 #define _FILE_OFFSET_BITS 64
55 #endif
56 
57 #include <libintl.h>
58 #include <regex.h>
59 #include <stddef.h>
60 #include <stdlib.h>
61 
62 #if defined(__linux__)
63 #include <linux/version.h>
64 #include <sys/inotify.h>
65 #include <sys/types.h>
66 #define LINUX_INOTIFY
67 #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
68 #include <sys/types.h>
69 #include <sys/event.h>
70 #include <sys/time.h>
71 #define BSD_KQUEUE
72 #endif /* __linux__ */
73 
74 #include "init.h"
75 #include "strings.h"
76 #include "messages.h"
77 #include "settings.h"
78 
79 #if __TINYC__
80 void *__dso_handle;
81 #endif
82 
83 #define EXIT_SUCCESS 0
84 #define EXIT_FAILURE 1
85 
86 #ifndef PATH_MAX
87 #define PATH_MAX 4096
88 #endif
89 
90 #ifndef HOST_NAME_MAX
91 #define HOST_NAME_MAX 64
92 #endif
93 
94 #ifndef NAME_MAX
95 #define NAME_MAX 255
96 #endif
97 
98 /* _GNU_SOURCE is only defined if __linux__ is defined and _BE_POSIX
99  * is not defined */
100 #ifdef _GNU_SOURCE
101 #if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 28))
102 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
103 #define _STATX
104 #endif /* LINUX_VERSION (4.11) */
105 #endif /* __GLIBC__ */
106 #endif /* _GNU_SOURCE */
107 
108 /* Because capability.h is deprecated in BSD */
109 #if __linux__
110 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
111 #define _LINUX_CAP
112 #endif /* LINUX_VERSION (2.6.24)*/
113 #endif /* __linux__ */
114 
115 /* Define our own boolean type
116 #undef bool
117 #define bool signed char
118 #undef TRUE
119 #undef FALSE
120 #define TRUE 1
121 #define FALSE 0 */
122 
123 /* Event handling */
124 #ifdef LINUX_INOTIFY
125 #define NUM_EVENT_SLOTS 32 /* Make room for 32 events */
126 #define EVENT_SIZE (sizeof(struct inotify_event))
127 #define EVENT_BUF_LEN (EVENT_SIZE * NUM_EVENT_SLOTS)
128 extern int inotify_fd, inotify_wd;
129 extern unsigned int INOTIFY_MASK;
130 #elif defined(BSD_KQUEUE)
131 #define NUM_EVENT_SLOTS 10
132 #define NUM_EVENT_FDS 10
133 extern int kq, event_fd;
134 extern struct kevent events_to_monitor[];
135 extern unsigned int KQUEUE_FFLAGS;
136 extern struct timespec timeout;
137 #endif /* LINUX_INOTIFY */
138 extern int watch;
139 
140 #define PROGRAM_NAME "CliFM"
141 #define PNL "clifm" /* Program name lowercase */
142 #define PROGRAM_DESC "The command line file manager"
143 #ifndef __HAIKU__
144 #define CLEAR if (write(STDOUT_FILENO, "\033c", 2) <= 0) {}
145 #else
146 #define CLEAR fputs("\x1b[H\x1b[2J", stdout);
147 #endif
148 #define VERSION "1.3"
149 #define AUTHOR "L. Abramovich"
150 #define CONTACT "johndoe.arch@outlook.com"
151 #define WEBSITE "https://github.com/leo-arch/clifm"
152 #define DATE "Oct 3, 2021"
153 #define LICENSE "GPL2+"
154 
155 /* Options flags */
156 #define FOLDERS_FIRST (1 << 1)
157 #define HELP          (1 << 2)
158 #define HIDDEN        (1 << 3)
159 #define AUTOLS        (1 << 4)
160 #define SPLASH        (1 << 5)
161 #define CASE_SENS     (1 << 6)
162 #define START_PATH    (1 << 7)
163 #define PRINT_VERSION (1 << 8)
164 #define ALT_PROFILE   (1 << 9)
165 
166 /* File ownership flags */
167 #define R_USR (1 << 1)
168 #define X_USR (1 << 2)
169 #define R_GRP (1 << 3)
170 #define X_GRP (1 << 4)
171 #define R_OTH (1 << 5)
172 #define X_OTH (1 << 6)
173 
174 /* Internal flags */
175 #define ROOT_USR      (1 << 10)
176 #define EXT_HELP      (1 << 11)
177 //#define FILE_CMD_OK (1 << 12)
178 #define GUI           (1 << 13)
179 #define IS_USRVAR_DEF (1 << 14)
180 
181 /* Used by log_msg() to know wether to tell prompt() to print messages or
182  * not */
183 #define PRINT_PROMPT   1
184 #define NOPRINT_PROMPT 0
185 
186 /* Macros for xchdir (for setting term title or not) */
187 #define SET_TITLE 1
188 #define NO_TITLE  0
189 
190 /* Macros for cd_function */
191 #define CD_PRINT_ERROR    1
192 #define CD_NO_PRINT_ERROR 0
193 
194 /* Macros for the count_dir function. CPOP tells the function to only
195  * check if a given directory is populated (it has at least 3 files) */
196 #define CPOP    1
197 #define NO_CPOP 0
198 
199 /* Error codes, used by the launch_exec functions */
200 #define EXNULLERR  79
201 #define EXFORKERR  81
202 #define EXCRASHERR 82
203 
204 #define BACKGROUND 1
205 #define FOREGROUND 0
206 
207 /* A few colors */
208 #define GRAY   "\x1b[1;30m"
209 #define _RED   "\x1b[1;31m"
210 #define _GREEN "\x1b[0;32m"
211 #define D_CYAN "\x1b[0;36m"
212 #define BOLD   "\x1b[1m"
213 #define NC     "\x1b[0m"
214 
215 #define COLORS_REPO "https://github.com/leo-arch/clifm-colors"
216 
217 /* Colors for the prompt: */
218 /* \001 and \002 tell readline that color codes between them are
219  * non-printing chars. This is specially useful for the prompt, i.e.,
220  * when passing color codes to readline */
221 #define RL_NC    "\001\x1b[0m\002"
222 #define DLFC     "\x1b[0K"         /* Delete line from cursor */
223 #define CNL      "\x1b[1E"         /* Move the cursor to beginning next line*/
224 #define DLFC_LEN 4                 /* Length of the above escape codes */
225 
226 #define UNSET -1
227 
228 /* Macros for the cp and mv cmds */
229 #define CP_CP    0
230 #define CP_ADVCP 1
231 #define CP_WCP   2
232 #define MV_MV    0
233 #define MV_ADVMV 1
234 
235 /* Sort macros */
236 #define SNONE      0
237 #define SNAME      1
238 #define SSIZE      2
239 #define SATIME     3
240 #define SBTIME     4
241 #define SCTIME     5
242 #define SMTIME     6
243 #define SVER       7
244 #define SEXT       8
245 #define SINO       9
246 #define SOWN       10
247 #define SGRP       11
248 #define SORT_TYPES 11
249 
250 /* Macros for the colors_list function */
251 #define NO_ELN        0
252 #define NO_NEWLINE    0
253 #define NO_PAD        0
254 #define PRINT_NEWLINE 1
255 
256 /* A few key macros used by the auto-suggestions system */
257 #define _ESC   27
258 #define _TAB   9
259 #define BS     8
260 #define DELETE 127
261 #define ENTER  13
262 /* #define OP_BRACKET 91
263 #define UC_O 79
264 #define SPACE 32 */
265 
266 /* Macros to specify suggestions type */
267 #define NO_SUG         0
268 #define HIST_SUG       1
269 #define FILE_SUG       2
270 #define CMD_SUG        3
271 #define INT_CMD        4
272 #define COMP_SUG       5
273 #define BOOKMARK_SUG   6
274 #define ALIAS_SUG      7
275 #define ELN_SUG        8
276 #define FIRST_WORD     9
277 #define JCMD_SUG       10
278 #define JCMD_SUG_NOACD 11 /* No auto-cd */
279 #define VAR_SUG	       12
280 #define SEL_SUG	       13
281 
282 /* 46 == \x1b[00;38;02;000;000;000;00;48;02;000;000;000m\0 (24bit, RGB
283  * true color format including foreground and background colors, the SGR
284  * (Select Graphic Rendition) parameter, and, of course, the terminating
285  * null byte. */
286 #define MAX_COLOR 46
287 
288 /* Macros to control file descriptors in exec functions */
289 #define E_NOFLAG   0
290 #define E_NOSTDIN  (1 << 1)
291 #define E_NOSTDOUT (1 << 2)
292 #define E_NOSTDERR (1 << 3)
293 #define E_MUTE     (E_NOSTDOUT | E_NOSTDERR)
294 
295 /* Macros for ELN padding */
296 #define NOPAD         0
297 #define ZEROPAD       1
298 #define LEFTSPACEPAD  2
299 #define RIGHTSPACEPAD 3
300 
301 /* Macros for the clear_suggestion function */
302 #define CS_FREEBUF 1
303 #define CS_KEEPBUF 0
304 
305 /* Macros for the xmagic function */
306 #define MIME_TYPE 1
307 #define TEXT_DESC 0
308 
309 /* Max length of the properties string in long view mode */
310 #define MAX_PROP_STR 55
311 
312 /* Macros for the prompt style */
313 #define DEF_PROMPT_STYLE    0
314 #define CUSTOM_PROMPT_STYLE 1
315 
316 /* Macros for the dirjump function */
317 #define SUG_JUMP    0
318 #define NO_SUG_JUMP 1
319 
320 /* Macros for the media_menu function */
321 #define MEDIA_LIST 	0
322 #define MEDIA_MOUNT	1
323 
324 /* Macros for the rl_highlight function */
325 #define SET_COLOR    1
326 #define INFORM_COLOR 0
327 
328 #define MB_LEN_MAX 16
329 
330 #define TMP_FILENAME ".clifmXXXXXX"
331 
332 #ifndef P_tmpdir
333 #define P_tmpdir "/tmp"
334 #endif
335 
336 #define itoa xitoa /* itoa does not exist in some OS's */
337 //#define atoi xatoi
338 
339 #ifndef _NO_GETTEXT
340 #define _(String) gettext(String)
341 #else
342 #define _(String) String
343 #endif /* _GETTEXT */
344 
345 #define strlen(s) xstrnlen(s)
346 
347 #define ENTRY_N 64
348 
349 #define UNUSED(x) (void)x /* Just silence the compiler's warning */
350 #define TOUPPER(ch) (((ch) >= 'a' && (ch) <= 'z') ? ((ch) - 'a' + 'A') : (ch))
351 #define DIGINUM(n) (((n) < 10) ? 1 \
352 		: ((n) < 100)        ? 2 \
353 		: ((n) < 1000)       ? 3 \
354 		: ((n) < 10000)      ? 4 \
355 		: ((n) < 100000)     ? 5 \
356 		: ((n) < 1000000)    ? 6 \
357 		: ((n) < 10000000)   ? 7 \
358 		: ((n) < 100000000)  ? 8 \
359 		: ((n) < 1000000000) ? 9 \
360 				      : 10)
361 #define _ISDIGIT(n) ((unsigned int)(n) - '0' <= 9)
362 #define _ISALPHA(n) ((unsigned int)(n) >= 'a' && (unsigned int)(n) <= 'z')
363 #define SELFORPARENT(n) (*(n) == '.' && (!(n)[1] || ((n)[1] == '.' && !(n)[2])))
364 
365 /* dirjump macros for calculating directories rank extra points */
366 #define BASENAME_BONUS 	300
367 #define BOOKMARK_BONUS 	500
368 #define PINNED_BONUS    1000
369 #define WORKSPACE_BONUS 300
370 /* Last directory access */
371 #define JHOUR(n)  ((n) *= 4) /* Within last hour */
372 #define JDAY(n)   ((n) *= 2) /* Within last day */
373 #define JWEEK(n)  ((n) / 2)  /* Within last week */
374 #define JOLDER(n) ((n) / 4)  /* More than a week */
375 
376 #if defined(__HAIKU__)
377 # define DT_UNKNOWN 0
378 # define DT_FIFO    1
379 # define DT_CHR     2
380 # define DT_DIR     4
381 # define DT_BLK     6
382 # define DT_REG     8
383 # define DT_LNK     10
384 # define DT_SOCK    12
385 #endif
386 
387 #define DT_NONE     14
388 
389 /* Macros for the get_sys_shell function */
390 #define SHELL_NONE 0
391 #define SHELL_BASH 1
392 #define SHELL_DASH 2
393 #define SHELL_FISH 3
394 #define SHELL_KSH  4
395 #define SHELL_TCSH 5
396 #define SHELL_ZSH  6
397 
398 #define BELL_NONE          0
399 #define BELL_AUDIBLE       1
400 #define BELL_VISIBLE       2
401 #define VISIBLE_BELL_DELAY 30
402 #define DEF_BELL_STYLE     BELL_VISIBLE
403 
404 				/** #########################
405 				 *  #    GLOBAL VARIABLES   #
406 				 *  ######################### */
407 
408 /* Struct to store information about current user */
409 struct user_t {
410 	char *home;
411 	char *name;
412 	char *shell;
413 	size_t home_len;
414 	uid_t uid;
415 	gid_t gid;
416 };
417 
418 extern struct user_t user;
419 
420 /* Struct to store user defined variables */
421 struct usrvar_t {
422 	char *name;
423 	char *value;
424 };
425 
426 extern struct usrvar_t *usr_var;
427 
428 /* Struct to store user defined actions */
429 struct actions_t {
430 	char *name;
431 	char *value;
432 };
433 
434 extern struct actions_t *usr_actions;
435 
436 /* Workspaces information */
437 struct ws_t {
438 	char *path;
439 	int num;
440 	int pad;
441 };
442 
443 extern struct ws_t *ws;
444 
445 /* Struct to store user defined keybindings */
446 struct kbinds_t {
447 	char *function;
448 	char *key;
449 };
450 
451 extern struct kbinds_t *kbinds;
452 
453 /* Struct to store the dirjump database values */
454 struct jump_t {
455 	char *path;
456 	int keep;
457 	int rank;
458 	size_t visits;
459 	time_t first_visit;
460 	time_t last_visit;
461 };
462 
463 extern struct jump_t *jump_db;
464 
465 /* Struct to store bookmarks */
466 struct bookmarks_t {
467 	char *shortcut;
468 	char *name;
469 	char *path;
470 };
471 
472 extern struct bookmarks_t *bookmarks;
473 
474 struct alias_t {
475 	char *name;
476 	char *cmd;
477 };
478 
479 extern struct alias_t *aliases;
480 
481 /* Struct to store file information */
482 struct fileinfo {
483 	char *color;
484 	char *ext_color;
485 #ifndef _NO_ICONS
486 	char *icon;
487 	char *icon_color;
488 #endif
489 	char *name;
490 	int dir;
491 	int eln_n;
492 	int exec;
493 	int filesn; /* Number of files in subdir */
494 	int ruser; /* User read permission for dir */
495 	int symlink;
496 	int sel;
497 	int pad;
498 	size_t len;
499 	mode_t mode; /* Store st_mode (for long view mode) */
500 	mode_t type; /* Store d_type value */
501 	ino_t inode;
502 	off_t size;
503 	uid_t uid;
504 	gid_t gid;
505 	nlink_t linkn;
506 	time_t ltime; /* For long view mode */
507 	time_t time;
508 };
509 
510 extern struct fileinfo *file_info;
511 
512 struct devino_t {
513 	dev_t dev;
514 	ino_t ino;
515 	char pad1;
516 	char pad2;
517 	char pad3;
518 	char pad4;
519 	char pad5;
520 	char pad6;
521 	char pad7;
522 	char mark;
523 };
524 
525 extern struct devino_t *sel_devino;
526 
527 struct autocmds_t {
528 	char *pattern;
529 	char *color_scheme;
530 	char *cmd;
531 	int long_view;
532 	int light_mode;
533 	int files_counter;
534 	int max_files;
535 	int max_name_len;
536 	int show_hidden;
537 	int sort;
538 	int sort_reverse;
539 	int pager;
540 	int pad;
541 };
542 
543 extern struct autocmds_t *autocmds;
544 
545 struct opts_t {
546 	char *color_scheme;
547 	int long_view;
548 	int light_mode;
549 	int files_counter;
550 	int max_files;
551 	int max_name_len;
552 	int show_hidden;
553 	int sort;
554 	int sort_reverse;
555 	int pager;
556 	int pad;
557 };
558 
559 extern struct opts_t opts;
560 
561 /* Struct to specify which parameters have been set from the command
562  * line, to avoid overriding them with init_config(). While no command
563  * line parameter will be overriden, the user still can modifiy on the
564  * fly (editing the config file) any option not specified in the command
565  * line */
566 struct param {
567 	int auto_open;
568 	int autocd;
569 	int autojump;
570 	int autols;
571 	int bm_file;
572 	int case_sens_dirjump;
573 	int case_sens_path_comp;
574 	int clear_screen;
575 	int colorize;
576 	int columns;
577 	int config;
578 	int cwd_in_title;
579 	int dirmap;
580 	int disk_usage;
581 	int cd_on_quit;
582 	int check_cap;
583 	int check_ext;
584 	int classify;
585 	int color_scheme;
586 	int control_d_exits;
587 	int expand_bookmarks;
588 	int ext;
589 	int ffirst;
590 	int files_counter;
591 	int follow_symlinks;
592 #ifndef _NO_FZF
593 	int fzftab;
594 #endif
595 	int hidden;
596 #ifndef _NO_HIGHLIGHT
597 	int highlight;
598 #endif
599 	int horizontal_list;
600 #ifndef _NO_ICONS
601 	int icons;
602 #endif
603 	int icons_use_file_color;
604 	int int_vars;
605 	int list_and_quit;
606 	int light;
607 	int logs;
608 	int longview;
609 	int max_dirhist;
610 	int max_files;
611 	int max_path;
612 	int mount_cmd;
613 	int no_dirjump;
614 	int noeln;
615 	int only_dirs;
616 	int pager;
617 	int path;
618 	int printsel;
619 	int restore_last_path;
620 	int rl_vi_mode;
621 	int sensitive;
622 	int share_selbox;
623 	int sort;
624 	int sort_reverse;
625 	int splash;
626 //	int stderr;
627 	int stealth_mode;
628 #ifndef _NO_SUGGESTIONS
629 	int suggestions;
630 #endif
631 	int tips;
632 #ifndef _NO_TRASH
633 	int trasrm;
634 #endif
635 	int unicode;
636 	int welcome_message;
637 	int warning_prompt;
638 };
639 
640 extern struct param xargs;
641 
642 /* Struct to store remotes information */
643 struct remote_t {
644 	char *desc;
645 	char *name;
646 	char *mount_cmd;
647 	char *mountpoint;
648 	char *unmount_cmd;
649 	int auto_mount;
650 	int auto_unmount;
651 	int mounted;
652 	int padding;
653 };
654 
655 extern struct remote_t *remotes;
656 
657 struct suggestions_t {
658 	int filetype;
659     int printed;
660 	int type;
661     int offset;
662 	char *color;
663 	size_t full_line_len;
664 	size_t nlines;
665 };
666 
667 extern struct suggestions_t suggestion;
668 
669 /* A list of possible program messages. Each value tells the prompt what
670  * to do with error messages: either to print an E, W, or N char at the
671  * beginning of the prompt, or nothing (nomsg) */
672 enum prog_msg {
673 	NOMSG = 	0,
674 	ERROR = 	1,
675 	WARNING = 	2,
676 	NOTICE = 	4
677 };
678 
679 /* pmsg holds the current program message type */
680 extern enum prog_msg pmsg;
681 
682 /* Enumeration for the dirjump function options */
683 enum jump {
684 	NONE = 		0,
685 	JPARENT =	1,
686 	JCHILD =	2,
687 	JORDER =	4,
688 	JLIST =		8
689 };
690 
691 enum comp_type {
692 	TCMP_BOOKMARK =	0,
693 	TCMP_CMD =		1,
694 	TCMP_CSCHEME = 	2,
695 	TCMP_DESEL = 	3,
696 	TCMP_ELN =		4,
697 	TCMP_HIST = 	5,
698 	TCMP_JUMP = 	6,
699 	TCMP_NET =		7,
700 	TCMP_NONE = 	8,
701 	TCMP_OPENWITH = 9,
702 	TCMP_PATH = 	10,
703 	TCMP_PROF = 	11,
704 	TCMP_RANGES = 	12,
705 	TCMP_SEL =		13,
706 	TCMP_SORT = 	14,
707 	TCMP_TRASHDEL=	15,
708 	TCMP_UNTRASH=	16
709 };
710 
711 extern enum comp_type cur_comp_type;
712 
713 extern struct termios orig_termios;
714 
715 extern int
716 	curcol,
717 	currow,
718 	flags;
719 
720 extern int
721 	auto_open,
722 	autocd,
723 	autocmd_set,
724 	autojump,
725 	autols,
726 	bell,
727 	bg_proc,
728 	case_sensitive,
729 	case_sens_dirjump,
730 	case_sens_path_comp,
731 	case_sens_search,
732 	cd_on_quit,
733 	check_cap,
734 	check_ext,
735 	classify,
736 	clear_screen,
737 	cmdhist_flag,
738 	colorize,
739 	columned,
740 	config_ok,
741 	control_d_exits,
742 	copy_n_rename,
743 	cp_cmd,
744 	cur_ws,
745 	dequoted,
746 	dir_changed, /* flag to know is dir was changed: used by autocmds */
747 	dirhist_map,
748 	disk_usage,
749 	elnpad,
750 	expand_bookmarks,
751 	ext_cmd_ok,
752 	files_counter,
753 	filter_rev,
754 	follow_symlinks,
755 #ifndef _NO_FZF
756 	fzftab,
757 #endif
758 #ifndef _NO_HIGHLIGHT
759 	highlight,
760 #endif
761 	home_ok,
762 #ifndef _NO_ICONS
763 	icons,
764 #endif
765 	int_vars,
766 	internal_cmd,
767 	is_sel,
768 	kb_shortcut,
769 	kbind_busy,
770 	light_mode,
771 	list_folders_first,
772 	listing_mode,
773 	logs_enabled,
774 	long_view,
775 	max_name_len,
776 	mime_match,
777 	min_name_trim,
778 	mv_cmd,
779 	no_eln,
780 	no_log,
781 	only_dirs,
782 	open_in_foreground, /* Override mimelist file: used by mime_open */
783 	pager,
784 	print_msg,
785 	print_selfiles,
786 	prompt_offset,
787 	prompt_style,
788 	recur_perm_error_flag,
789 	restore_last_path,
790 	rl_last_word_start,
791 	rl_nohist,
792 	rl_notab,
793 	sel_is_last,
794 	selfile_ok,
795 	share_selbox,
796 	shell,
797 	shell_terminal,
798 	show_hidden,
799 	sort,
800 	sort_reverse,
801 	sort_switch,
802 	splash_screen,
803 	suggest_filetype_color,
804 	suggestions,
805 	switch_cscheme,
806 	tips,
807 #ifndef _NO_TRASH
808 	tr_as_rm,
809 	trash_ok,
810 #endif
811 	unicode,
812 	warning_prompt,
813 	welcome_message,
814 	_xrename,
815 	xrename; /* We're running a secondary prompt for the rename function */
816 
817 //#ifndef _NO_HIGHLIGHT
818 extern int wrong_cmd;
819 extern int wrong_cmd_line;
820 //#endif
821 
822 extern int
823 	argc_bk,
824 	dirhist_cur_index,
825 	dirhist_total_index,
826 	exit_code,
827 	jump_total_rank,
828 	max_dirhist,
829 	max_files,
830 	max_hist,
831 	max_jump_total_rank,
832 	max_log,
833 	max_path,
834 	max_printselfiles,
835 	min_jump_rank,
836 	trash_n,
837 	shell_is_interactive,
838 	*eln_as_file;
839 
840 extern unsigned short term_cols, term_rows;
841 
842 extern size_t
843 	actions_n,
844 	aliases_n,
845 	args_n,
846 	autocmds_n,
847 	bm_n,
848 	cdpath_n,
849 	cschemes_n,
850 	current_hist_n,
851 	curhistindex,
852 	eln_as_file_n,
853 	ext_colors_n,
854 	files,
855 	jump_n,
856 	kbinds_n,
857 	longest,
858 	msgs_n,
859 	P_tmpdir_len,
860 	path_n,
861 	path_progsn,
862 	prompt_cmds_n,
863 	remotes_n,
864 	sel_n,
865 	tab_offset,
866 	user_home_len,
867 	usrvar_n,
868 	nwords;
869 
870 extern struct termios shell_tmodes;
871 extern off_t total_sel_size;
872 extern pid_t own_pid;
873 
874 extern char
875 	div_line_char[NAME_MAX],
876 	hostname[HOST_NAME_MAX],
877 
878 	*actions_file,
879 	*alt_config_dir,
880 	*alt_bm_file,
881 	*alt_config_file,
882 	*alt_kbinds_file,
883 	*alt_profile,
884 	*bm_file,
885 	*colors_dir,
886 	*config_dir,
887 	*config_dir_gral,
888 	*config_file,
889 	*cur_color,
890 	*data_dir,
891 	*cur_cscheme,
892 	*dirhist_file,
893 	*encoded_prompt,
894 	*file_cmd_path,
895 	*_filter,
896 	*fzftab_options,
897 	*hist_file,
898 	*kbinds_file,
899 	*jump_suggestion,
900 	*last_cmd,
901 	*log_file,
902 	*ls_colors_bk,
903 	*mime_file,
904 	*msg_log_file,
905 	*opener,
906 	*pinned_dir,
907 	*plugins_dir,
908 	*profile_file,
909 	*qc,
910 	*remotes_file,
911 	*sel_file,
912 	*stdin_tmp_dir,
913 #ifndef _NO_SUGGESTIONS
914 	*suggestion_buf,
915 	*suggestion_strategy,
916 #endif
917 	*term,
918 //	*term_bgcolor,
919 	*tmp_dir,
920 #ifndef _NO_TRASH
921 	*trash_dir,
922 	*trash_files_dir,
923 	*trash_info_dir,
924 #endif
925 	*usr_cscheme,
926 	*user_home,
927 	*wprompt_str,
928 
929 	**argv_bk,
930 	**bin_commands,
931 	**bookmark_names,
932 	**cdpaths,
933 	**color_schemes,
934 	**ext_colors,
935 	**history,
936 	**messages,
937 	**old_pwd,
938 	**paths,
939 	**profile_names,
940 	**prompt_cmds,
941 	**sel_elements;
942 
943 extern const char
944 	*internal_cmds[],
945 	*param_str[];
946 
947 extern regex_t regex_exp;
948 extern size_t *ext_colors_len;
949 extern char **environ;
950 
951 /* To store all the 39 color variables I use, with 46 bytes each, I need
952  * a total of 1,8Kb. It's not much but it could be less if I'd use
953  * dynamically allocated arrays for them (which, on the other side,
954  * would make the whole thing slower and more tedious) */
955 
956 /* Colors */
957 extern char
958 	/* File types */
959 	bd_c[MAX_COLOR],	/* Block device */
960 	ca_c[MAX_COLOR],	/* Cap file */
961 	cd_c[MAX_COLOR],	/* Char device */
962 	ee_c[MAX_COLOR],	/* Empty executable */
963 	ex_c[MAX_COLOR],	/* Executable */
964 	ef_c[MAX_COLOR],	/* Empty reg file */
965 	ed_c[MAX_COLOR],	/* Empty dir */
966 	fi_c[MAX_COLOR],	/* Reg file */
967 	di_c[MAX_COLOR],	/* Directory */
968 	ln_c[MAX_COLOR],	/* Symlink */
969 	mh_c[MAX_COLOR],	/* Multi-hardlink file */
970 	nd_c[MAX_COLOR],	/* No read directory */
971 	ne_c[MAX_COLOR],	/* No read empty dir */
972 	nf_c[MAX_COLOR],	/* No read file */
973 	no_c[MAX_COLOR],	/* Unknown */
974 	or_c[MAX_COLOR],	/* Broken symlink */
975 	ow_c[MAX_COLOR],	/* Other writable */
976 	pi_c[MAX_COLOR],	/* FIFO, pipe */
977 	sg_c[MAX_COLOR],	/* SGID file */
978 	so_c[MAX_COLOR],	/* Socket */
979 	st_c[MAX_COLOR],	/* Sticky (not ow)*/
980 	su_c[MAX_COLOR],	/* SUID file */
981 	tw_c[MAX_COLOR],	/* Sticky other writable */
982 	uf_c[MAX_COLOR],	/* Non-'stat'able file */
983 
984 	/* Interface */
985 	bm_c[MAX_COLOR],	/* Bookmarked directory */
986 	dc_c[MAX_COLOR],	/* Files counter */
987 	df_c[MAX_COLOR],	/* Default color */
988 	dh_c[MAX_COLOR],	/* Dirhist index */
989 	dl_c[MAX_COLOR],	/* Dividing line */
990 	el_c[MAX_COLOR],	/* ELN color */
991 	mi_c[MAX_COLOR],	/* Misc indicators */
992 	ts_c[MAX_COLOR],	/* TAB completion suffix */
993 	wc_c[MAX_COLOR],	/* Welcome message */
994 	wp_c[MAX_COLOR],	/* Warning prompt */
995 
996 	/* Suggestions */
997 	sb_c[MAX_COLOR],	/* Auto-suggestions: shell builtins */
998 	sc_c[MAX_COLOR],	/* Auto-suggestions: external commands */
999 	sf_c[MAX_COLOR],	/* Auto-suggestions: filenames */
1000 	sh_c[MAX_COLOR],	/* Auto-suggestions: history */
1001 	sx_c[MAX_COLOR],	/* Auto-suggestions: internal commands and params */
1002 	sp_c[MAX_COLOR],	/* Auto-suggestions: suggestions pointer */
1003 
1004 #ifndef _NO_ICONS
1005     dir_ico_c[MAX_COLOR], /* Directories icon color */
1006 #endif
1007 
1008 	/* Syntax highlighting */
1009 	hb_c[MAX_COLOR],	/* Brackets () [] {} */
1010 	hc_c[MAX_COLOR],	/* Comments */
1011 	hd_c[MAX_COLOR],	/* Paths (slashes) */
1012 	he_c[MAX_COLOR],	/* Expansion operators: * ~ */
1013 	hn_c[MAX_COLOR],	/* Numbers */
1014 	hp_c[MAX_COLOR],	/* Parameters: - */
1015 	hq_c[MAX_COLOR],	/* Quoted strings */
1016 	hr_c[MAX_COLOR],	/* Redirection > */
1017 	hs_c[MAX_COLOR],	/* Process separators | & ; */
1018 	hv_c[MAX_COLOR],	/* Variables $ */
1019 	hw_c[MAX_COLOR],	/* Wrong, non-existent command name $ */
1020 
1021     /* Colors used in the prompt, so that \001 and \002 needs to
1022 	 * be added. This is why MAX_COLOR + 2 */
1023 	/* Workspaces */
1024 	ws1_c[MAX_COLOR + 2],
1025 	ws2_c[MAX_COLOR + 2],
1026 	ws3_c[MAX_COLOR + 2],
1027 	ws4_c[MAX_COLOR + 2],
1028 	ws5_c[MAX_COLOR + 2],
1029 	ws6_c[MAX_COLOR + 2],
1030 	ws7_c[MAX_COLOR + 2],
1031 	ws8_c[MAX_COLOR + 2],
1032 
1033 	em_c[MAX_COLOR + 2], /* Error msg color */
1034 	li_c[MAX_COLOR + 2], /* Sel indicator color */
1035 	li_cb[MAX_COLOR], /* Sel indicator color (for the files list) */
1036 	nm_c[MAX_COLOR + 2], /* Notice msg color */
1037 	ti_c[MAX_COLOR + 2], /* Trash indicator color */
1038 	tx_c[MAX_COLOR + 2], /* Text color */
1039 	si_c[MAX_COLOR + 2], /* stealth indicator color */
1040 	wm_c[MAX_COLOR + 2]; /* Warning msg color */
1041 
1042 #endif /* HELPERS_H */
1043