mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 12:32:40 +03:00
"file" utility: use -b option if available.
* configure.ac: test if "file" utility has -b option. * (regex_check_type): don't compare file names if "file -b" is used. Reduce variable scope. Rename variable. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
0bb9c04720
commit
debabe561a
19
configure.ac
19
configure.ac
@ -126,7 +126,7 @@ fi
|
|||||||
AC_SUBST(MANDOC)
|
AC_SUBST(MANDOC)
|
||||||
AC_SUBST(MAN_FLAGS)
|
AC_SUBST(MAN_FLAGS)
|
||||||
|
|
||||||
dnl Check for -z, -L, and -S options to file
|
dnl Check for -z, -b, -L, and -S options to file
|
||||||
AC_CHECK_PROG(HAVE_FILECMD, file, true, false)
|
AC_CHECK_PROG(HAVE_FILECMD, file, true, false)
|
||||||
if $HAVE_FILECMD; then
|
if $HAVE_FILECMD; then
|
||||||
dnl Don't use the file command if it doesn't accept the -z option
|
dnl Don't use the file command if it doesn't accept the -z option
|
||||||
@ -148,7 +148,22 @@ if $HAVE_FILECMD; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if test x$mc_cv_file_z = xyes; then
|
if test x$mc_cv_file_z = xyes; then
|
||||||
dnl file is used; check -L and -S options
|
dnl file is used; check -b, -L and -S options
|
||||||
|
|
||||||
|
AC_MSG_CHECKING([for -b option to file command])
|
||||||
|
AC_CACHE_VAL(mc_cv_file_b, [
|
||||||
|
file -b . > /dev/null 2>&1
|
||||||
|
if test $? = 0; then
|
||||||
|
mc_cv_file_b=yes
|
||||||
|
else
|
||||||
|
mc_cv_file_b=no
|
||||||
|
fi
|
||||||
|
])
|
||||||
|
AC_MSG_RESULT([$mc_cv_file_b])
|
||||||
|
|
||||||
|
if test x$mc_cv_file_b = xyes; then
|
||||||
|
AC_DEFINE(FILE_B, "-b ", [Define if the file command accepts the -b option])
|
||||||
|
fi
|
||||||
|
|
||||||
AC_MSG_CHECKING([for -L option to file command])
|
AC_MSG_CHECKING([for -L option to file command])
|
||||||
AC_CACHE_VAL(mc_cv_file_L, [
|
AC_CACHE_VAL(mc_cv_file_L, [
|
||||||
|
@ -74,8 +74,12 @@
|
|||||||
/*** file scope macro definitions ****************************************************************/
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
#ifdef USE_FILE_CMD
|
#ifdef USE_FILE_CMD
|
||||||
|
#ifdef FILE_B
|
||||||
|
#define FILE_CMD "file -z " FILE_B FILE_S FILE_L
|
||||||
|
#else
|
||||||
#define FILE_CMD "file -z " FILE_S FILE_L
|
#define FILE_CMD "file -z " FILE_S FILE_L
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/*** file scope type declarations ****************************************************************/
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
@ -646,7 +650,6 @@ regex_check_type (const vfs_path_t * filename_vpath, const char *ptr, gboolean c
|
|||||||
if (!*have_type)
|
if (!*have_type)
|
||||||
{
|
{
|
||||||
vfs_path_t *localfile_vpath;
|
vfs_path_t *localfile_vpath;
|
||||||
const char *realname; /* name used with "file" */
|
|
||||||
|
|
||||||
#ifdef HAVE_CHARSET
|
#ifdef HAVE_CHARSET
|
||||||
static char encoding_id[21]; /* CSISO51INISCYRILLIC -- 20 */
|
static char encoding_id[21]; /* CSISO51INISCYRILLIC -- 20 */
|
||||||
@ -664,7 +667,6 @@ regex_check_type (const vfs_path_t * filename_vpath, const char *ptr, gboolean c
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
realname = vfs_path_get_last_path_str (localfile_vpath);
|
|
||||||
|
|
||||||
#ifdef HAVE_CHARSET
|
#ifdef HAVE_CHARSET
|
||||||
got_encoding_data = is_autodetect_codeset_enabled
|
got_encoding_data = is_autodetect_codeset_enabled
|
||||||
@ -694,26 +696,32 @@ regex_check_type (const vfs_path_t * filename_vpath, const char *ptr, gboolean c
|
|||||||
if (got_data > 0)
|
if (got_data > 0)
|
||||||
{
|
{
|
||||||
char *pp;
|
char *pp;
|
||||||
size_t real_len;
|
|
||||||
|
|
||||||
pp = strchr (content_string, '\n');
|
pp = strchr (content_string, '\n');
|
||||||
if (pp != NULL)
|
if (pp != NULL)
|
||||||
*pp = '\0';
|
*pp = '\0';
|
||||||
|
|
||||||
real_len = strlen (realname);
|
#ifndef FILE_B
|
||||||
|
|
||||||
if (strncmp (content_string, realname, real_len) == 0)
|
|
||||||
{
|
{
|
||||||
/* Skip "realname: " */
|
const char *real_name; /* name used with "file" */
|
||||||
content_shift = real_len;
|
size_t real_len;
|
||||||
if (content_string[content_shift] == ':')
|
|
||||||
|
real_name = vfs_path_get_last_path_str (localfile_vpath);
|
||||||
|
real_len = strlen (real_name);
|
||||||
|
|
||||||
|
if (strncmp (content_string, real_name, real_len) == 0)
|
||||||
{
|
{
|
||||||
|
/* Skip "real_name: " */
|
||||||
|
content_shift = real_len;
|
||||||
|
|
||||||
/* Solaris' file prints tab(s) after ':' */
|
/* Solaris' file prints tab(s) after ':' */
|
||||||
for (content_shift++; whitespace (content_string[content_shift]);
|
if (content_string[content_shift] == ':')
|
||||||
content_shift++)
|
for (content_shift++; whitespace (content_string[content_shift]);
|
||||||
;
|
content_shift++)
|
||||||
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif /* FILE_B */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user