s/msgid "%s: %s: %s %3d%% (%ld bytes transfered)"/msgid "%s: %s: %s %3d%% (%lu bytes...
[midnight-commander.git] / src / util.h
blob302f0bb65f0a271df092e704c142ab16b89626a9
1 #ifndef __UTIL_H
2 #define __UTIL_H
5 #include <sys/types.h>
7 /* String managing functions */
9 #if defined(SCO_FLAVOR) && defined(__GNUC__)
10 extern char*g_strdup (const char*);
11 #endif
13 int is_printable (int c);
14 int msglen (char *text, int *lines);
15 char *trim (char *s, char *d, int len);
16 char *name_quote (const char *c, int quote_percent);
17 char *fake_name_quote (const char *c, int quote_percent);
18 char *name_trunc (char *txt, int trunc_len);
19 char *size_trunc (double size);
20 char *size_trunc_sep (double size);
21 void size_trunc_len (char *buffer, int len, off_t size, int units);
22 int is_exe (mode_t mode);
23 char *string_perm (mode_t mode_bits);
24 char *strip_password (char *path, int has_prefix);
25 char *strip_home_and_password(char *dir);
26 char *extension (char *);
27 char *concat_dir_and_file (const char *dir, const char *file);
28 char *unix_error_string (int error_num);
29 char *skip_separators (char *s);
30 char *skip_numbers (char *s);
31 char *strip_ctrl_codes (char *s);
32 char *convert_controls (char *s);
33 void wipe_password (char *passwd);
34 char *reverse_string (char *string);
35 char *resolve_symlinks (char *path);
36 char *diff_two_paths (char *first, char *second);
37 int set_nonblocking (int fd);
39 char *x_basename (char *s);
40 char *g_readlink (char *path);
42 /* Profile managing functions */
43 int set_int (char *, char *, int);
44 int get_int (char *, char *, int);
46 char *load_file (char *filename);
47 char *load_mc_home_file (const char *filename, char ** allocated_filename);
49 /* uid/gid managing */
50 void init_groups (void);
51 void destroy_groups (void);
52 int get_user_permissions (struct stat *buf);
54 void init_uid_gid_cache (void);
55 char *get_group (int);
56 char *get_owner (int);
58 #define MAX_I18NTIMELENGTH 14
59 #define MIN_I18NTIMELENGTH 10
60 #define STD_I18NTIMELENGTH 12
62 size_t i18n_checktimelength (void);
63 char *file_date (time_t);
65 char *file_date_pck (time_t);
66 int exist_file (char *name);
68 /* Returns a copy of *s until a \n is found and is below top */
69 char *extract_line (char *s, char *top);
70 char *_icase_search (char *text, char *data, int *lng);
71 #define icase_search(T,D) _icase_search((T), (D), NULL)
73 /* Matching */
74 enum { match_file, match_normal };
75 extern int easy_patterns;
76 char *convert_pattern (char *pattern, int match_type, int do_group);
77 int regexp_match (char *pattern, char *string, int match_type);
79 /* Error pipes */
80 void open_error_pipe (void);
81 void check_error_pipe (void);
82 int close_error_pipe (int error, char *text);
84 /* Process spawning */
85 void my_putenv (char*, char*);
86 #define EXECUTE_INTERNAL 1
87 #define EXECUTE_TEMPFILE 2
88 #define EXECUTE_AS_SHELL 4
89 #define EXECUTE_SETUID 8
90 #define EXECUTE_WAIT 16
91 int my_system (int flags, const char *shell, const char *command);
92 int my_system_get_child_pid (int flags, const char *shell, const char *command, pid_t *pid);
93 void save_stop_handler (void);
94 extern struct sigaction startup_handler;
96 /* Tilde expansion */
97 char *tilde_expand (const char *);
99 /* Pathname canonicalization */
100 char *canonicalize_pathname (char *);
102 /* Misc Unix functions */
103 long blocks2kilos (int blocks, int bsize);
104 char *get_current_wd (char *buffer, int size);
105 int my_mkdir (char *s, mode_t mode);
106 int my_rmdir (char *s);
108 /* Rotating dash routines */
109 void use_dash (int flag); /* Disable/Enable rotate_dash routines */
110 void rotate_dash (void);
111 void remove_dash (void);
113 extern char app_text [];
115 /* Creating temporary files safely */
116 void init_tmpdir(void);
117 int mc_mkstemps(char **pname, const char *prefix, const char *suffix);
119 enum {
120 ISGUNZIPABLE_GUNZIP,
121 ISGUNZIPABLE_BZIP,
122 ISGUNZIPABLE_BZIP2
125 long int is_gunzipable (int fd, int *type);
126 char *decompress_command (int type);
127 char *decompress_extension (int type);
128 void decompress_command_and_arg (int type, char **cmd, char **flags);
130 int mc_doublepopen (int inhandle, int inlen, pid_t *tp, char *command, ...);
131 int mc_doublepclose (int pipehandle, pid_t pid);
133 /* Hook functions */
135 typedef struct hook {
136 void (*hook_fn)(void *);
137 void *hook_data;
138 struct hook *next;
139 } Hook;
141 void add_hook (Hook **hook_list, void (*hook_fn)(void *), void *data);
142 void execute_hooks (Hook *hook_list);
143 void delete_hook (Hook **hook_list, void (*hook_fn)(void *));
144 int hook_present (Hook *hook_list, void (*hook_fn)(void *));
146 int max_open_files (void);
148 #ifdef OS2_NT
149 # define PATH_SEP '\\'
150 # define PATH_SEP_STR "\\"
151 # define PATH_ENV_SEP ';'
152 # define TMPDIR_DEFAULT "c:\\temp"
153 # define SCRIPT_SUFFIX ".cmd"
154 # define OS_SORT_CASE_SENSITIVE_DEFAULT 0
155 # define STRCOMP stricmp
156 # define STRNCOMP strnicmp
157 # define MC_ARCH_FLAGS REG_ICASE
158 char *get_default_shell (void);
159 char *get_default_editor (void);
160 int lstat (const char* pathname, struct stat *buffer);
161 #else
162 # define PATH_SEP '/'
163 # define PATH_SEP_STR "/"
164 # define PATH_ENV_SEP ':'
165 # define TMPDIR_DEFAULT "/tmp"
166 # define SCRIPT_SUFFIX ""
167 # define get_default_editor() "vi"
168 # define OS_SORT_CASE_SENSITIVE_DEFAULT 1
169 # define STRCOMP strcmp
170 # define STRNCOMP strncmp
171 # define MC_ARCH_FLAGS 0
172 #endif
174 #include "i18n.h"
176 /* taken from regex.c: */
177 /* Jim Meyering writes:
179 "... Some ctype macros are valid only for character codes that
180 isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
181 using /bin/cc or gcc but without giving an ansi option). So, all
182 ctype uses should be through macros like ISPRINT... If
183 STDC_HEADERS is defined, then autoconf has verified that the ctype
184 macros don't need to be guarded with references to isascii. ...
185 Defining isascii to 1 should let any compiler worth its salt
186 eliminate the && through constant folding." */
188 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
189 #define ISASCII(c) 1
190 #else
191 #define ISASCII(c) isascii(c)
192 #endif
194 #endif