updated the .TP cleanup for coherency in the key description pages.
[midnight-commander.git] / src / util.h
blob5594e527092c6d08fb0b3a37c1c31d333e74f39f
1 #ifndef __UTIL_H
2 #define __UTIL_H
5 #include <sys/types.h>
7 /* String managing functions */
9 int is_printable (int c);
10 int msglen (char *text, int *lines);
11 char *trim (char *s, char *d, int len);
12 char *name_quote (const char *c, int quote_percent);
13 char *fake_name_quote (const char *c, int quote_percent);
14 char *name_trunc (const char *txt, int trunc_len);
15 char *size_trunc (double size);
16 char *size_trunc_sep (double size);
17 void size_trunc_len (char *buffer, int len, off_t size, int units);
18 int is_exe (mode_t mode);
19 char *string_perm (mode_t mode_bits);
20 char *strip_password (char *path, int has_prefix);
21 char *strip_home_and_password(char *dir);
22 char *extension (char *);
23 char *concat_dir_and_file (const char *dir, const char *file);
24 char *unix_error_string (int error_num);
25 char *skip_separators (char *s);
26 char *skip_numbers (char *s);
27 char *strip_ctrl_codes (char *s);
28 char *convert_controls (char *s);
29 void wipe_password (char *passwd);
30 char *reverse_string (char *string);
31 char *diff_two_paths (char *first, char *second);
33 char *x_basename (char *s);
35 /* Profile managing functions */
36 int set_int (char *, char *, int);
37 int get_int (char *, char *, int);
39 char *load_file (char *filename);
40 char *load_mc_home_file (const char *filename, char ** allocated_filename);
42 /* uid/gid managing */
43 void init_groups (void);
44 void destroy_groups (void);
45 int get_user_permissions (struct stat *buf);
47 void init_uid_gid_cache (void);
48 char *get_group (int);
49 char *get_owner (int);
51 #define MAX_I18NTIMELENGTH 14
52 #define MIN_I18NTIMELENGTH 10
53 #define STD_I18NTIMELENGTH 12
55 size_t i18n_checktimelength (void);
56 char *file_date (time_t);
58 int exist_file (char *name);
60 /* Returns a copy of *s until a \n is found and is below top */
61 char *extract_line (char *s, char *top);
62 char *_icase_search (char *text, char *data, int *lng);
63 #define icase_search(T,D) _icase_search((T), (D), NULL)
65 /* Matching */
66 enum { match_file, match_normal };
67 extern int easy_patterns;
68 char *convert_pattern (char *pattern, int match_type, int do_group);
69 int regexp_match (char *pattern, char *string, int match_type);
71 /* Error pipes */
72 void open_error_pipe (void);
73 void check_error_pipe (void);
74 int close_error_pipe (int error, char *text);
76 /* Process spawning */
77 #define EXECUTE_INTERNAL 1
78 #define EXECUTE_AS_SHELL 4
79 int my_system (int flags, const char *shell, const char *command);
80 void save_stop_handler (void);
81 extern struct sigaction startup_handler;
83 /* Tilde expansion */
84 char *tilde_expand (const char *);
86 /* Pathname canonicalization */
87 char *canonicalize_pathname (char *);
89 /* Misc Unix functions */
90 char *get_current_wd (char *buffer, int size);
91 const char *mc_tmpdir (void);
92 int my_mkdir (char *s, mode_t mode);
93 int my_rmdir (char *s);
95 /* Rotating dash routines */
96 void use_dash (int flag); /* Disable/Enable rotate_dash routines */
97 void rotate_dash (void);
98 void remove_dash (void);
100 extern const char app_text [];
102 /* Creating temporary files safely */
103 void init_tmpdir(void);
104 int mc_mkstemps(char **pname, const char *prefix, const char *suffix);
106 enum {
107 COMPRESSION_NONE,
108 COMPRESSION_GZIP,
109 COMPRESSION_BZIP,
110 COMPRESSION_BZIP2
113 int get_compression_type (int fd);
114 char *decompress_extension (int type);
116 int mc_doublepopen (int inhandle, int inlen, pid_t *tp, char *command, ...);
117 int mc_doublepclose (int pipehandle, pid_t pid);
119 /* Hook functions */
121 typedef struct hook {
122 void (*hook_fn)(void *);
123 void *hook_data;
124 struct hook *next;
125 } Hook;
127 void add_hook (Hook **hook_list, void (*hook_fn)(void *), void *data);
128 void execute_hooks (Hook *hook_list);
129 void delete_hook (Hook **hook_list, void (*hook_fn)(void *));
130 int hook_present (Hook *hook_list, void (*hook_fn)(void *));
132 #ifdef NATIVE_WIN32
133 # define PATH_SEP '\\'
134 # define PATH_SEP_STR "\\"
135 # define PATH_ENV_SEP ';'
136 # define TMPDIR_DEFAULT "c:\\temp"
137 # define SCRIPT_SUFFIX ".cmd"
138 # define OS_SORT_CASE_SENSITIVE_DEFAULT 0
139 # define STRCOMP stricmp
140 # define STRNCOMP strnicmp
141 # define MC_ARCH_FLAGS REG_ICASE
142 char *get_default_shell (void);
143 char *get_default_editor (void);
144 int lstat (const char* pathname, struct stat *buffer);
145 #else
146 # define PATH_SEP '/'
147 # define PATH_SEP_STR "/"
148 # define PATH_ENV_SEP ':'
149 # define TMPDIR_DEFAULT "/tmp"
150 # define SCRIPT_SUFFIX ""
151 # define get_default_editor() "vi"
152 # define OS_SORT_CASE_SENSITIVE_DEFAULT 1
153 # define STRCOMP strcmp
154 # define STRNCOMP strncmp
155 # define MC_ARCH_FLAGS 0
156 #endif
158 #include "i18n.h"
160 /* taken from regex.c: */
161 /* Jim Meyering writes:
163 "... Some ctype macros are valid only for character codes that
164 isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
165 using /bin/cc or gcc but without giving an ansi option). So, all
166 ctype uses should be through macros like ISPRINT... If
167 STDC_HEADERS is defined, then autoconf has verified that the ctype
168 macros don't need to be guarded with references to isascii. ...
169 Defining isascii to 1 should let any compiler worth its salt
170 eliminate the && through constant folding." */
172 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
173 #define ISASCII(c) 1
174 #else
175 #define ISASCII(c) isascii(c)
176 #endif
178 #endif