6 /* Returns its argument as a "modifiable" string. This function is
7 * intended to pass strings to legacy libraries that don't know yet
8 * about the "const" modifier. The return value of this function
9 * MUST NOT be modified. */
10 extern char *str_unconst (const char *);
12 /* String managing functions */
14 extern const char *cstrcasestr (const char *haystack
, const char *needle
);
15 extern const char *cstrstr (const char *haystack
, const char *needle
);
17 char *unescape_string ( const char * in
);
18 char *escape_string ( const char * in
);
19 void str_replace(char *s
, char from
, char to
);
20 int is_printable (int c
);
21 void msglen (const char *text
, /*@out@*/ int *lines
, /*@out@*/ int *columns
);
23 /* Copy from s to d, and trim the beginning if necessary, and prepend
24 * "..." in this case. The destination string can have at most len
25 * bytes, not counting trailing 0. */
26 char *trim (const char *s
, char *d
, int len
);
28 /* Quote the filename for the purpose of inserting it into the command
29 * line. If quote_percent is 1, replace "%" with "%%" - the percent is
30 * processed by the mc command line. */
31 char *name_quote (const char *c
, int quote_percent
);
33 /* returns a duplicate of c. */
34 char *fake_name_quote (const char *c
, int quote_percent
);
36 /* Remove the middle part of the string to fit given length.
37 * Use "~" to show where the string was truncated.
38 * Return static buffer, no need to free() it. */
39 const char *name_trunc (const char *txt
, int trunc_len
);
41 /* path_trunc() is the same as name_trunc() above but
42 * it deletes possible password from path for security
44 const char *path_trunc (const char *path
, int trunc_len
);
46 /* return a static string representing size, appending "K" or "M" for
48 * NOTE: uses the same static buffer as size_trunc_sep. */
49 const char *size_trunc (double size
);
51 /* return a static string representing size, appending "K" or "M" for
52 * big sizes. Separates every three digits by ",".
53 * NOTE: uses the same static buffer as size_trunc. */
54 const char *size_trunc_sep (double size
);
56 /* Print file SIZE to BUFFER, but don't exceed LEN characters,
57 * not including trailing 0. BUFFER should be at least LEN+1 long.
59 * Units: size units (0=bytes, 1=Kbytes, 2=Mbytes, etc.) */
60 void size_trunc_len (char *buffer
, int len
, off_t size
, int units
);
61 int is_exe (mode_t mode
);
62 const char *string_perm (mode_t mode_bits
);
64 /* @modifies path. @returns pointer into path. */
65 char *strip_password (char *path
, int has_prefix
);
67 /* @returns a pointer into a static buffer. */
68 const char *strip_home_and_password (const char *dir
);
70 const char *extension (const char *);
71 char *concat_dir_and_file (const char *dir
, const char *file
);
72 const char *unix_error_string (int error_num
);
73 const char *skip_separators (const char *s
);
74 const char *skip_numbers (const char *s
);
75 char *strip_ctrl_codes (char *s
);
77 /* Replaces "\\E" and "\\e" with "\033". Replaces "^" + [a-z] with
78 * ((char) 1 + (c - 'a')). The same goes for "^" + [A-Z].
79 * Returns a newly allocated string. */
80 char *convert_controls (const char *s
);
82 /* overwrites passwd with '\0's and frees it. */
83 void wipe_password (char *passwd
);
85 char *diff_two_paths (const char *first
, const char *second
);
87 /* Returns the basename of fname. The result is a pointer into fname. */
88 const char *x_basename (const char *fname
);
90 /* Profile managing functions */
91 int set_int (const char *, const char *, int);
92 int get_int (const char *, const char *, int);
93 extern char * get_config_string (const char *, const char *, const char *);
94 extern void set_config_string (const char *, const char *, const char *);
96 char *load_file (const char *filename
);
97 char *load_mc_home_file (const char *filename
, char ** allocated_filename
);
99 /* uid/gid managing */
100 void init_groups (void);
101 void destroy_groups (void);
102 int get_user_permissions (struct stat
*buf
);
104 void init_uid_gid_cache (void);
105 char *get_group (int);
106 char *get_owner (int);
108 #define MAX_I18NTIMELENGTH 14
109 #define MIN_I18NTIMELENGTH 10
110 #define STD_I18NTIMELENGTH 12
112 size_t i18n_checktimelength (void);
113 const char *file_date (time_t);
115 int exist_file (const char *name
);
117 /* Returns a copy of *s until a \n is found and is below top */
118 const char *extract_line (const char *s
, const char *top
);
119 const char *_icase_search (const char *text
, const char *data
, int *lng
);
120 #define icase_search(T,D) _icase_search((T), (D), NULL)
124 match_file
, /* match a filename, use easy_patterns */
125 match_normal
, /* match pattern, use easy_patterns */
126 match_regex
/* match pattern, force using regex */
129 extern int easy_patterns
;
130 char *convert_pattern (const char *pattern
, int match_type
, int do_group
);
131 int regexp_match (const char *pattern
, const char *string
, int match_type
);
134 void open_error_pipe (void);
135 void check_error_pipe (void);
136 int close_error_pipe (int error
, const char *text
);
138 /* Process spawning */
139 int my_system (int flags
, const char *shell
, const char *command
);
140 void save_stop_handler (void);
141 extern struct sigaction startup_handler
;
143 /* Tilde expansion */
144 char *tilde_expand (const char *);
146 /* Pathname canonicalization */
147 void canonicalize_pathname (char *);
149 /* Misc Unix functions */
150 char *get_current_wd (char *buffer
, int size
);
151 int my_mkdir (const char *s
, mode_t mode
);
152 int my_rmdir (const char *s
);
154 /* Rotating dash routines */
155 void use_dash (int flag
); /* Disable/Enable rotate_dash routines */
156 void rotate_dash (void);
158 /* Creating temporary files safely */
159 const char *mc_tmpdir (void);
160 int mc_mkstemps(char **pname
, const char *prefix
, const char *suffix
);
163 #ifdef _POSIX_VERSION
164 #define PATH_MAX _POSIX_PATH_MAX
167 #define PATH_MAX MAXPATHLEN
169 #define PATH_MAX 1024
175 #define MAXSYMLINKS 32
178 char *mc_realpath(const char *path
, char resolved_path
[]);
180 enum compression_type
{
187 /* Looks for ``magic'' bytes at the start of the VFS file to guess the
188 * compression type. Side effect: modifies the file position. */
189 enum compression_type
get_compression_type (int fd
);
190 const char *decompress_extension (int type
);
194 typedef struct hook
{
195 void (*hook_fn
)(void *);
200 void add_hook (Hook
**hook_list
, void (*hook_fn
)(void *), void *data
);
201 void execute_hooks (Hook
*hook_list
);
202 void delete_hook (Hook
**hook_list
, void (*hook_fn
)(void *));
203 int hook_present (Hook
*hook_list
, void (*hook_fn
)(void *));
205 GList
*list_append_unique (GList
*list
, char *text
);
207 /* Position saving and restoring */
209 /* file where positions are stored */
210 #define MC_FILEPOS ".mc/filepos"
212 #define MC_FILEPOS_TMP ".mc/filepos.tmp"
213 /* maximum entries in MC_FILEPOS */
214 #define MC_FILEPOS_ENTRIES 1024
215 /* Load position for the given filename */
216 void load_file_position (const char *filename
, long *line
, long *column
);
217 /* Save position for the given filename */
218 void save_file_position (const char *filename
, long line
, long column
);
221 /* OS specific defines */
223 #define PATH_SEP_STR "/"
224 #define PATH_ENV_SEP ':'
225 #define TMPDIR_DEFAULT "/tmp"
226 #define SCRIPT_SUFFIX ""
227 #define get_default_editor() "vi"
228 #define OS_SORT_CASE_SENSITIVE_DEFAULT 1
229 #define STRCOMP strcmp
230 #define STRNCOMP strncmp
231 #define MC_ARCH_FLAGS 0
233 /* taken from regex.c: */
234 /* Jim Meyering writes:
236 "... Some ctype macros are valid only for character codes that
237 isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
238 using /bin/cc or gcc but without giving an ansi option). So, all
239 ctype uses should be through macros like ISPRINT... If
240 STDC_HEADERS is defined, then autoconf has verified that the ctype
241 macros don't need to be guarded with references to isascii. ...
242 Defining isascii to 1 should let any compiler worth its salt
243 eliminate the && through constant folding." */
245 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
248 #define ISASCII(c) isascii(c)
251 /* usage: str_cmp ("foo", !=, "bar") */
252 #define str_cmp(a,rel,b) (strcmp ((a), (b)) rel 0)
254 /* if ch is in [A-Za-z], returns the corresponding control character,
255 * else returns the argument. */
256 extern int ascii_alpha_to_cntrl (int ch
);
259 const char *Q_ (const char *s
);