"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:
Andrew Borodin 2022-06-26 19:18:09 +03:00
parent 0bb9c04720
commit debabe561a
2 changed files with 37 additions and 14 deletions

View File

@ -126,7 +126,7 @@ fi
AC_SUBST(MANDOC)
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)
if $HAVE_FILECMD; then
dnl Don't use the file command if it doesn't accept the -z option
@ -148,7 +148,22 @@ if $HAVE_FILECMD; then
fi
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_CACHE_VAL(mc_cv_file_L, [

View File

@ -74,8 +74,12 @@
/*** file scope macro definitions ****************************************************************/
#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
#endif
#endif
/*** 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)
{
vfs_path_t *localfile_vpath;
const char *realname; /* name used with "file" */
#ifdef HAVE_CHARSET
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;
}
realname = vfs_path_get_last_path_str (localfile_vpath);
#ifdef HAVE_CHARSET
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)
{
char *pp;
size_t real_len;
pp = strchr (content_string, '\n');
if (pp != NULL)
*pp = '\0';
real_len = strlen (realname);
if (strncmp (content_string, realname, real_len) == 0)
#ifndef FILE_B
{
/* Skip "realname: " */
content_shift = real_len;
if (content_string[content_shift] == ':')
const char *real_name; /* name used with "file" */
size_t real_len;
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 ':' */
for (content_shift++; whitespace (content_string[content_shift]);
content_shift++)
;
if (content_string[content_shift] == ':')
for (content_shift++; whitespace (content_string[content_shift]);
content_shift++)
;
}
}
#endif /* FILE_B */
}
else
{