1998-02-27 07:54:42 +03:00
|
|
|
#ifndef __UTIL_H
|
|
|
|
#define __UTIL_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
/* String managing functions */
|
|
|
|
|
1998-03-18 09:24:20 +03:00
|
|
|
int is_printable (int c);
|
|
|
|
int msglen (char *text, int *lines);
|
1998-02-27 07:54:42 +03:00
|
|
|
char *trim (char *s, char *d, int len);
|
|
|
|
char *name_quote (const char *c, int quote_percent);
|
|
|
|
char *fake_name_quote (const char *c, int quote_percent);
|
2002-08-19 02:01:51 +04:00
|
|
|
char *name_trunc (const char *txt, int trunc_len);
|
2000-06-15 11:03:49 +04:00
|
|
|
char *size_trunc (double size);
|
|
|
|
char *size_trunc_sep (double size);
|
2001-08-30 20:41:08 +04:00
|
|
|
void size_trunc_len (char *buffer, int len, off_t size, int units);
|
1998-03-18 09:24:20 +03:00
|
|
|
int is_exe (mode_t mode);
|
1998-02-27 07:54:42 +03:00
|
|
|
char *string_perm (mode_t mode_bits);
|
1999-02-04 02:19:40 +03:00
|
|
|
char *strip_password (char *path, int has_prefix);
|
2002-11-12 14:20:08 +03:00
|
|
|
char *strip_home_and_password (const char *dir);
|
1998-02-27 07:54:42 +03:00
|
|
|
char *extension (char *);
|
|
|
|
char *concat_dir_and_file (const char *dir, const char *file);
|
|
|
|
char *unix_error_string (int error_num);
|
|
|
|
char *skip_separators (char *s);
|
|
|
|
char *skip_numbers (char *s);
|
|
|
|
char *strip_ctrl_codes (char *s);
|
|
|
|
char *convert_controls (char *s);
|
|
|
|
void wipe_password (char *passwd);
|
|
|
|
char *diff_two_paths (char *first, char *second);
|
|
|
|
|
|
|
|
char *x_basename (char *s);
|
|
|
|
|
|
|
|
/* Profile managing functions */
|
|
|
|
int set_int (char *, char *, int);
|
|
|
|
int get_int (char *, char *, int);
|
|
|
|
|
|
|
|
char *load_file (char *filename);
|
2001-06-09 11:13:46 +04:00
|
|
|
char *load_mc_home_file (const char *filename, char ** allocated_filename);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* uid/gid managing */
|
|
|
|
void init_groups (void);
|
2001-09-01 17:47:34 +04:00
|
|
|
void destroy_groups (void);
|
|
|
|
int get_user_permissions (struct stat *buf);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
void init_uid_gid_cache (void);
|
|
|
|
char *get_group (int);
|
|
|
|
char *get_owner (int);
|
|
|
|
|
1999-08-06 23:24:04 +04:00
|
|
|
#define MAX_I18NTIMELENGTH 14
|
|
|
|
#define MIN_I18NTIMELENGTH 10
|
|
|
|
#define STD_I18NTIMELENGTH 12
|
|
|
|
|
1999-04-30 16:41:41 +04:00
|
|
|
size_t i18n_checktimelength (void);
|
1998-02-27 07:54:42 +03:00
|
|
|
char *file_date (time_t);
|
1999-08-06 23:24:04 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
int exist_file (char *name);
|
|
|
|
|
|
|
|
/* Returns a copy of *s until a \n is found and is below top */
|
|
|
|
char *extract_line (char *s, char *top);
|
|
|
|
char *_icase_search (char *text, char *data, int *lng);
|
|
|
|
#define icase_search(T,D) _icase_search((T), (D), NULL)
|
|
|
|
|
|
|
|
/* Matching */
|
|
|
|
enum { match_file, match_normal };
|
|
|
|
extern int easy_patterns;
|
|
|
|
char *convert_pattern (char *pattern, int match_type, int do_group);
|
|
|
|
int regexp_match (char *pattern, char *string, int match_type);
|
|
|
|
|
|
|
|
/* Error pipes */
|
|
|
|
void open_error_pipe (void);
|
|
|
|
void check_error_pipe (void);
|
1999-03-18 21:43:52 +03:00
|
|
|
int close_error_pipe (int error, char *text);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* Process spawning */
|
1998-04-24 05:08:06 +04:00
|
|
|
#define EXECUTE_INTERNAL 1
|
|
|
|
#define EXECUTE_AS_SHELL 4
|
|
|
|
int my_system (int flags, const char *shell, const char *command);
|
1998-02-27 07:54:42 +03:00
|
|
|
void save_stop_handler (void);
|
|
|
|
extern struct sigaction startup_handler;
|
|
|
|
|
|
|
|
/* Tilde expansion */
|
2000-04-18 12:58:42 +04:00
|
|
|
char *tilde_expand (const char *);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* Pathname canonicalization */
|
|
|
|
char *canonicalize_pathname (char *);
|
|
|
|
|
|
|
|
/* Misc Unix functions */
|
|
|
|
char *get_current_wd (char *buffer, int size);
|
|
|
|
int my_mkdir (char *s, mode_t mode);
|
|
|
|
int my_rmdir (char *s);
|
|
|
|
|
|
|
|
/* Rotating dash routines */
|
|
|
|
void use_dash (int flag); /* Disable/Enable rotate_dash routines */
|
|
|
|
void rotate_dash (void);
|
|
|
|
void remove_dash (void);
|
|
|
|
|
2001-05-21 20:21:07 +04:00
|
|
|
/* Creating temporary files safely */
|
2002-12-26 14:38:34 +03:00
|
|
|
const char *mc_tmpdir (void);
|
2001-05-21 20:21:07 +04:00
|
|
|
int mc_mkstemps(char **pname, const char *prefix, const char *suffix);
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
enum {
|
2002-07-03 01:09:25 +04:00
|
|
|
COMPRESSION_NONE,
|
|
|
|
COMPRESSION_GZIP,
|
|
|
|
COMPRESSION_BZIP,
|
|
|
|
COMPRESSION_BZIP2
|
1998-02-27 07:54:42 +03:00
|
|
|
};
|
|
|
|
|
2002-07-03 01:09:25 +04:00
|
|
|
int get_compression_type (int fd);
|
2002-11-12 14:20:08 +03:00
|
|
|
const char *decompress_extension (int type);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
int mc_doublepopen (int inhandle, int inlen, pid_t *tp, char *command, ...);
|
|
|
|
int mc_doublepclose (int pipehandle, pid_t pid);
|
|
|
|
|
|
|
|
/* Hook functions */
|
|
|
|
|
|
|
|
typedef struct hook {
|
|
|
|
void (*hook_fn)(void *);
|
|
|
|
void *hook_data;
|
|
|
|
struct hook *next;
|
|
|
|
} Hook;
|
|
|
|
|
|
|
|
void add_hook (Hook **hook_list, void (*hook_fn)(void *), void *data);
|
|
|
|
void execute_hooks (Hook *hook_list);
|
|
|
|
void delete_hook (Hook **hook_list, void (*hook_fn)(void *));
|
|
|
|
int hook_present (Hook *hook_list, void (*hook_fn)(void *));
|
|
|
|
|
2002-12-08 09:51:22 +03:00
|
|
|
|
|
|
|
/* Position saving and restoring */
|
|
|
|
|
|
|
|
/* file where positions are stored */
|
|
|
|
#define MC_FILEPOS ".mc/filepos"
|
|
|
|
/* temporary file */
|
|
|
|
#define MC_FILEPOS_TMP ".mc/filepos.tmp"
|
|
|
|
/* maximum entries in MC_FILEPOS */
|
|
|
|
#define MC_FILEPOS_ENTRIES 1024
|
|
|
|
/* Load position for the given filename */
|
|
|
|
void load_file_position (char *filename, long *line, long *column);
|
|
|
|
/* Save position for the given filename */
|
|
|
|
void save_file_position (char *filename, long line, long column);
|
|
|
|
|
|
|
|
|
|
|
|
/* OS specific defines */
|
|
|
|
|
2002-09-11 02:04:11 +04:00
|
|
|
#ifdef NATIVE_WIN32
|
1998-02-27 07:54:42 +03:00
|
|
|
# define PATH_SEP '\\'
|
|
|
|
# define PATH_SEP_STR "\\"
|
|
|
|
# define PATH_ENV_SEP ';'
|
2001-05-21 20:21:07 +04:00
|
|
|
# define TMPDIR_DEFAULT "c:\\temp"
|
|
|
|
# define SCRIPT_SUFFIX ".cmd"
|
1998-02-27 07:54:42 +03:00
|
|
|
# define OS_SORT_CASE_SENSITIVE_DEFAULT 0
|
1998-03-07 23:27:44 +03:00
|
|
|
# define STRCOMP stricmp
|
1998-03-23 08:27:15 +03:00
|
|
|
# define STRNCOMP strnicmp
|
1998-03-07 23:27:44 +03:00
|
|
|
# define MC_ARCH_FLAGS REG_ICASE
|
1998-02-27 07:54:42 +03:00
|
|
|
char *get_default_shell (void);
|
|
|
|
char *get_default_editor (void);
|
|
|
|
int lstat (const char* pathname, struct stat *buffer);
|
|
|
|
#else
|
|
|
|
# define PATH_SEP '/'
|
|
|
|
# define PATH_SEP_STR "/"
|
|
|
|
# define PATH_ENV_SEP ':'
|
2001-05-21 20:21:07 +04:00
|
|
|
# define TMPDIR_DEFAULT "/tmp"
|
|
|
|
# define SCRIPT_SUFFIX ""
|
1998-02-27 07:54:42 +03:00
|
|
|
# define get_default_editor() "vi"
|
|
|
|
# define OS_SORT_CASE_SENSITIVE_DEFAULT 1
|
1998-03-07 23:27:44 +03:00
|
|
|
# define STRCOMP strcmp
|
1998-03-23 08:27:15 +03:00
|
|
|
# define STRNCOMP strncmp
|
1998-03-07 23:27:44 +03:00
|
|
|
# define MC_ARCH_FLAGS 0
|
1998-02-27 07:54:42 +03:00
|
|
|
#endif
|
|
|
|
|
1998-03-25 08:16:00 +03:00
|
|
|
#include "i18n.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* taken from regex.c: */
|
|
|
|
/* Jim Meyering writes:
|
|
|
|
|
|
|
|
"... Some ctype macros are valid only for character codes that
|
|
|
|
isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
|
|
|
|
using /bin/cc or gcc but without giving an ansi option). So, all
|
|
|
|
ctype uses should be through macros like ISPRINT... If
|
|
|
|
STDC_HEADERS is defined, then autoconf has verified that the ctype
|
|
|
|
macros don't need to be guarded with references to isascii. ...
|
|
|
|
Defining isascii to 1 should let any compiler worth its salt
|
|
|
|
eliminate the && through constant folding." */
|
|
|
|
|
|
|
|
#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
|
|
|
|
#define ISASCII(c) 1
|
|
|
|
#else
|
|
|
|
#define ISASCII(c) isascii(c)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|