Updated italian translation
[midnight-commander.git] / src / util.h
blob8587754139fbb7c846ae8f40a4a2f17a0860a6e6
1 #ifndef MC_UTIL_H
2 #define MC_UTIL_H
4 #include <sys/types.h>
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 #ifdef INLINE_STR_UNCONST
11 static inline char *str_unconst_inlined (const char *s)
13 return (char *) s;
15 #define str_unconst(s) str_unconst_inlined(s)
16 #else
17 extern char *str_unconst (const char *);
18 #endif
20 /* String managing functions */
22 extern const char *cstrcasestr (const char *haystack, const char *needle);
23 extern const char *cstrstr (const char *haystack, const char *needle);
25 void str_replace(char *s, char from, char to);
26 int is_printable (int c);
27 void msglen (const char *text, /*@out@*/ int *lines, /*@out@*/ int *columns);
29 /* Copy from s to d, and trim the beginning if necessary, and prepend
30 * "..." in this case. The destination string can have at most len
31 * bytes, not counting trailing 0. */
32 char *trim (const char *s, char *d, int len);
34 /* Quote the filename for the purpose of inserting it into the command
35 * line. If quote_percent is 1, replace "%" with "%%" - the percent is
36 * processed by the mc command line. */
37 char *name_quote (const char *c, int quote_percent);
39 /* returns a duplicate of c. */
40 char *fake_name_quote (const char *c, int quote_percent);
42 /* Remove the middle part of the string to fit given length.
43 * Use "~" to show where the string was truncated.
44 * Return static buffer, no need to free() it. */
45 const char *name_trunc (const char *txt, int trunc_len);
47 /* path_trunc() is the same as name_trunc() above but
48 * it deletes possible password from path for security
49 * reasons. */
50 const char *path_trunc (const char *path, int trunc_len);
52 /* return a static string representing size, appending "K" or "M" for
53 * big sizes.
54 * NOTE: uses the same static buffer as size_trunc_sep. */
55 const char *size_trunc (double size);
57 /* return a static string representing size, appending "K" or "M" for
58 * big sizes. Separates every three digits by ",".
59 * NOTE: uses the same static buffer as size_trunc. */
60 const char *size_trunc_sep (double size);
62 /* Print file SIZE to BUFFER, but don't exceed LEN characters,
63 * not including trailing 0. BUFFER should be at least LEN+1 long.
65 * Units: size units (0=bytes, 1=Kbytes, 2=Mbytes, etc.) */
66 void size_trunc_len (char *buffer, int len, off_t size, int units);
67 int is_exe (mode_t mode);
68 const char *string_perm (mode_t mode_bits);
70 /* @modifies path. @returns pointer into path. */
71 char *strip_password (char *path, int has_prefix);
73 /* @returns a pointer into a static buffer. */
74 const char *strip_home_and_password (const char *dir);
76 const char *extension (const char *);
77 char *concat_dir_and_file (const char *dir, const char *file);
78 const char *unix_error_string (int error_num);
79 const char *skip_separators (const char *s);
80 const char *skip_numbers (const char *s);
81 char *strip_ctrl_codes (char *s);
83 /* Replaces "\\E" and "\\e" with "\033". Replaces "^" + [a-z] with
84 * ((char) 1 + (c - 'a')). The same goes for "^" + [A-Z].
85 * Returns a newly allocated string. */
86 char *convert_controls (const char *s);
88 /* overwrites passwd with '\0's and frees it. */
89 void wipe_password (char *passwd);
91 char *diff_two_paths (const char *first, const char *second);
93 /* Returns the basename of fname. The result is a pointer into fname. */
94 const char *x_basename (const char *fname);
96 /* Profile managing functions */
97 int set_int (const char *, const char *, int);
98 int get_int (const char *, const char *, int);
99 extern char * get_config_string (const char *, const char *, const char *);
100 extern void set_config_string (const char *, const char *, const char *);
102 char *load_file (const char *filename);
103 char *load_mc_home_file (const char *filename, char ** allocated_filename);
105 /* uid/gid managing */
106 void init_groups (void);
107 void destroy_groups (void);
108 int get_user_permissions (struct stat *buf);
110 void init_uid_gid_cache (void);
111 char *get_group (int);
112 char *get_owner (int);
114 #define MAX_I18NTIMELENGTH 14
115 #define MIN_I18NTIMELENGTH 10
116 #define STD_I18NTIMELENGTH 12
118 size_t i18n_checktimelength (void);
119 const char *file_date (time_t);
121 int exist_file (const char *name);
123 /* Returns a copy of *s until a \n is found and is below top */
124 const char *extract_line (const char *s, const char *top);
125 const char *_icase_search (const char *text, const char *data, int *lng);
126 #define icase_search(T,D) _icase_search((T), (D), NULL)
128 /* Matching */
129 enum {
130 match_file, /* match a filename, use easy_patterns */
131 match_normal, /* match pattern, use easy_patterns */
132 match_regex /* match pattern, force using regex */
135 extern int easy_patterns;
136 char *convert_pattern (const char *pattern, int match_type, int do_group);
137 int regexp_match (const char *pattern, const char *string, int match_type);
139 /* Error pipes */
140 void open_error_pipe (void);
141 void check_error_pipe (void);
142 int close_error_pipe (int error, const char *text);
144 /* Process spawning */
145 int my_system (int flags, const char *shell, const char *command);
146 void save_stop_handler (void);
147 extern struct sigaction startup_handler;
149 /* Tilde expansion */
150 char *tilde_expand (const char *);
152 /* Pathname canonicalization */
153 void canonicalize_pathname (char *);
155 /* Misc Unix functions */
156 char *get_current_wd (char *buffer, int size);
157 int my_mkdir (const char *s, mode_t mode);
158 int my_rmdir (const char *s);
160 /* Rotating dash routines */
161 void use_dash (int flag); /* Disable/Enable rotate_dash routines */
162 void rotate_dash (void);
164 /* Creating temporary files safely */
165 const char *mc_tmpdir (void);
166 int mc_mkstemps(char **pname, const char *prefix, const char *suffix);
168 #ifndef PATH_MAX
169 #ifdef _POSIX_VERSION
170 #define PATH_MAX _POSIX_PATH_MAX
171 #else
172 #ifdef MAXPATHLEN
173 #define PATH_MAX MAXPATHLEN
174 #else
175 #define PATH_MAX 1024
176 #endif
177 #endif
178 #endif
180 #ifndef MAXSYMLINKS
181 #define MAXSYMLINKS 32
182 #endif
184 char *mc_realpath(const char *path, char resolved_path[]);
186 enum compression_type {
187 COMPRESSION_NONE,
188 COMPRESSION_GZIP,
189 COMPRESSION_BZIP,
190 COMPRESSION_BZIP2
193 /* Looks for ``magic'' bytes at the start of the VFS file to guess the
194 * compression type. Side effect: modifies the file position. */
195 enum compression_type get_compression_type (int fd);
196 const char *decompress_extension (int type);
198 /* Hook functions */
200 typedef struct hook {
201 void (*hook_fn)(void *);
202 void *hook_data;
203 struct hook *next;
204 } Hook;
206 void add_hook (Hook **hook_list, void (*hook_fn)(void *), void *data);
207 void execute_hooks (Hook *hook_list);
208 void delete_hook (Hook **hook_list, void (*hook_fn)(void *));
209 int hook_present (Hook *hook_list, void (*hook_fn)(void *));
211 GList *list_append_unique (GList *list, char *text);
213 /* Position saving and restoring */
215 /* file where positions are stored */
216 #define MC_FILEPOS ".mc/filepos"
217 /* temporary file */
218 #define MC_FILEPOS_TMP ".mc/filepos.tmp"
219 /* maximum entries in MC_FILEPOS */
220 #define MC_FILEPOS_ENTRIES 1024
221 /* Load position for the given filename */
222 void load_file_position (const char *filename, long *line, long *column);
223 /* Save position for the given filename */
224 void save_file_position (const char *filename, long line, long column);
227 /* OS specific defines */
228 #define PATH_SEP '/'
229 #define PATH_SEP_STR "/"
230 #define PATH_ENV_SEP ':'
231 #define TMPDIR_DEFAULT "/tmp"
232 #define SCRIPT_SUFFIX ""
233 #define get_default_editor() "vi"
234 #define OS_SORT_CASE_SENSITIVE_DEFAULT 1
235 #define STRCOMP strcmp
236 #define STRNCOMP strncmp
237 #define MC_ARCH_FLAGS 0
239 /* taken from regex.c: */
240 /* Jim Meyering writes:
242 "... Some ctype macros are valid only for character codes that
243 isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
244 using /bin/cc or gcc but without giving an ansi option). So, all
245 ctype uses should be through macros like ISPRINT... If
246 STDC_HEADERS is defined, then autoconf has verified that the ctype
247 macros don't need to be guarded with references to isascii. ...
248 Defining isascii to 1 should let any compiler worth its salt
249 eliminate the && through constant folding." */
251 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
252 #define ISASCII(c) 1
253 #else
254 #define ISASCII(c) isascii(c)
255 #endif
257 /* usage: str_cmp ("foo", !=, "bar") */
258 #define str_cmp(a,rel,b) (strcmp ((a), (b)) rel 0)
260 /* if ch is in [A-Za-z], returns the corresponding control character,
261 * else returns the argument. */
262 extern int ascii_alpha_to_cntrl (int ch);
264 /* translates the string and returns the part after the first occurence
265 * of the ``|'' character. */
266 extern const char *gettext_ui (const char *);
268 #endif