Sync to Wine-0_9_5:
[reactos.git] / rosapps / mc / src / util.h
1 #ifndef __UTIL_H
2 #define __UTIL_H
3
4
5 #include <sys/types.h>
6
7 /* String managing functions */
8
9 #if defined(SCO_FLAVOR) && defined(__GNUC__)
10 extern char* strdup(const char*);
11 #endif
12
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 (long int size);
20 char *size_trunc_sep (long int size);
21 int is_exe (mode_t mode);
22 char *string_perm (mode_t mode_bits);
23 char *strip_home_and_password(char *dir);
24 char *extension (char *);
25 char *split_extension (char *, int pad);
26 char *get_full_name (char *dir, char *file);
27 char *copy_strings (const char *first, ...);
28 char *concat_dir_and_file (const char *dir, const char *file);
29 char *unix_error_string (int error_num);
30 char *skip_separators (char *s);
31 char *skip_numbers (char *s);
32 char *strip_ctrl_codes (char *s);
33 char *convert_controls (char *s);
34 void wipe_password (char *passwd);
35 char *reverse_string (char *string);
36 char *resolve_symlinks (char *path);
37 char *diff_two_paths (char *first, char *second);
38 int set_nonblocking (int fd);
39
40 #ifndef HAVE_STRCASECMP
41 int strcasecmp (const char *s, const char *d);
42 #endif
43
44 char *x_basename (char *s);
45
46 extern int align_extensions;
47 #ifndef HAVE_MAD
48 void *do_xmalloc (int);
49 #define xmalloc(a,b) do_xmalloc (a)
50 #endif
51
52 /* Profile managing functions */
53 int set_int (char *, char *, int);
54 int get_int (char *, char *, int);
55
56 char *load_file (char *filename);
57
58 #include "fs.h"
59 #ifndef S_ISLNK
60 # define S_ISLNK(x) (((x) & S_IFLNK) == S_IFLNK)
61 #endif
62
63 #ifndef S_ISSOCK
64 # ifdef S_IFSOCK
65 # define S_ISSOCK(x) (((x) & S_IFSOCK) == S_IFSOCK)
66 # else
67 # define S_ISSOCK(x) 0
68 # endif
69 #endif
70
71 /* uid/gid managing */
72 typedef struct user_in_groups{
73 struct user_in_groups *next;
74 int gid;
75 } user_in_groups;
76
77 void init_groups (void);
78 void delete_groups (void);
79 int get_user_rights (struct stat *buf);
80
81 void init_uid_gid_cache (void);
82 char *get_group (int);
83 char *get_owner (int);
84
85 char *file_date (time_t);
86 char *file_date_pck (time_t);
87 int exist_file (char *name);
88
89 /* Returns a copy of *s until a \n is found and is below top */
90 char *extract_line (char *s, char *top);
91 char *_icase_search (char *text, char *data, int *lng);
92 #define icase_search(T,D) _icase_search((T), (D), NULL)
93
94 /* Matching */
95 enum { match_file, match_normal };
96 extern int easy_patterns;
97 char *convert_pattern (char *pattern, int match_type, int do_group);
98 int regexp_match (char *pattern, char *string, int match_type);
99
100 /* Error pipes */
101 void open_error_pipe (void);
102 void check_error_pipe (void);
103 void close_error_pipe (int error, char *text);
104
105 /* Process spawning */
106 void my_putenv (char*, char*);
107 #define EXECUTE_INTERNAL 1
108 #define EXECUTE_TEMPFILE 2
109 #define EXECUTE_AS_SHELL 4
110 int my_system (int flags, const char *shell, const char *command);
111 int my_system_get_child_pid (int flags, const char *shell, const char *command, pid_t *pid);
112 void save_stop_handler (void);
113 extern struct sigaction startup_handler;
114
115 /* Tilde expansion */
116 char *tilde_expand (char *);
117
118 /* Pathname canonicalization */
119 char *canonicalize_pathname (char *);
120
121 /* Misc Unix functions */
122 long blocks2kilos (int blocks, int bsize);
123 char *get_current_wd (char *buffer, int size);
124 int my_mkdir (char *s, mode_t mode);
125 int my_rmdir (char *s);
126
127 /* Filesystem status */
128 struct my_statfs {
129 int type;
130 char *typename;
131 char *mpoint;
132 char *device;
133 unsigned int avail;
134 unsigned int total;
135 unsigned int nfree;
136 unsigned int nodes;
137 };
138
139 void init_my_statfs (void);
140 void my_statfs (struct my_statfs *myfs_stats, char *path);
141
142 /* Rotating dash routines */
143 void use_dash (int flag); /* Disable/Enable rotate_dash routines */
144 void rotate_dash (void);
145 void remove_dash (void);
146
147 extern char app_text [];
148
149 enum {
150 ISGUNZIPABLE_GUNZIP,
151 ISGUNZIPABLE_BZIP,
152 ISGUNZIPABLE_BZIP2
153 };
154
155 long int is_gunzipable (int fd, int *type);
156 char *decompress_command (int type);
157 void decompress_command_and_arg (int type, char **cmd, char **flags);
158
159 int mc_doublepopen (int inhandle, int inlen, pid_t *tp, char *command, ...);
160 int mc_doublepclose (int pipehandle, pid_t pid);
161
162 /* Hook functions */
163
164 typedef struct hook {
165 void (*hook_fn)(void *);
166 void *hook_data;
167 struct hook *next;
168 } Hook;
169
170 void add_hook (Hook **hook_list, void (*hook_fn)(void *), void *data);
171 void execute_hooks (Hook *hook_list);
172 void delete_hook (Hook **hook_list, void (*hook_fn)(void *));
173 int hook_present (Hook *hook_list, void (*hook_fn)(void *));
174
175 /* message stubs: used by those routines that may output something during the panel_operate process */
176 void message_1s (int flags, char *title, char *str1);
177 void message_2s (int flags, char *title, char *str1, char *str2);
178 void message_3s (int flags, char *title, char *str1, char *str2, const char *str3);
179 void message_1s1d (int flags, char *title, char *str, int d);
180 void tell_parent (int msg);
181 int max_open_files (void);
182
183 #ifdef OS2_NT
184 # define PATH_SEP '\\'
185 # define PATH_SEP_STR "\\"
186 # define PATH_ENV_SEP ';'
187 # define OS_SORT_CASE_SENSITIVE_DEFAULT 0
188 # define STRCOMP stricmp
189 # define STRNCOMP strnicmp
190 # define MC_ARCH_FLAGS REG_ICASE
191 char *get_default_shell (void);
192 char *get_default_editor (void);
193 int lstat (const char* pathname, struct stat *buffer);
194 #else
195 # define PATH_SEP '/'
196 # define PATH_SEP_STR "/"
197 # define PATH_ENV_SEP ':'
198 # define get_default_editor() "vi"
199 # define OS_SORT_CASE_SENSITIVE_DEFAULT 1
200 # define STRCOMP strcmp
201 # define STRNCOMP strncmp
202 # define MC_ARCH_FLAGS 0
203 #endif
204
205 #include "i18n.h"
206
207 /* taken from regex.c: */
208 /* Jim Meyering writes:
209
210 "... Some ctype macros are valid only for character codes that
211 isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
212 using /bin/cc or gcc but without giving an ansi option). So, all
213 ctype uses should be through macros like ISPRINT... If
214 STDC_HEADERS is defined, then autoconf has verified that the ctype
215 macros don't need to be guarded with references to isascii. ...
216 Defining isascii to 1 should let any compiler worth its salt
217 eliminate the && through constant folding." */
218
219 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
220 #define ISASCII(c) 1
221 #else
222 #define ISASCII(c) isascii(c)
223 #endif
224
225 #endif