Skip to content

Commit

Permalink
Merge branch '3972_fix_illumos'
Browse files Browse the repository at this point in the history
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
  • Loading branch information
zyv committed Oct 5, 2024
2 parents 6dd05af + 8f723b8 commit a24d45f
Show file tree
Hide file tree
Showing 24 changed files with 204 additions and 152 deletions.
14 changes: 9 additions & 5 deletions autogen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ cd "$srcdir"
${AUTORECONF:-autoreconf} --verbose --install --force -I m4 ${AUTORECONF_FLAGS}

# Customize the INSTALL file
rm -f INSTALL && ln -s doc/INSTALL
rm -f INSTALL && ln -s doc/INSTALL .

# Generate po/POTFILES.in
${XGETTEXT:-xgettext} --keyword=_ --keyword=N_ --keyword=Q_ --output=- \
if ! xgettext -h 2>&1 | grep -e '--keyword=' >/dev/null ; then
echo "gettext is unable to extract translations, set XGETTEXT to GNU gettext!" >&2
else
${XGETTEXT:-xgettext} --keyword=_ --keyword=N_ --keyword=Q_ --output=- \
`find . -name '*.[ch]'` | ${SED-sed} -ne '/^#:/{s/#://;s/:[0-9]*/\
/g;s/ //g;p;}' | \
grep -v '^$' | sort | uniq >po/POTFILES.in
fi

$srcdir/version.sh "$srcdir"
"$srcdir/version.sh" "$srcdir"

if test -x $srcdir/configure.mc; then
$srcdir/configure.mc "$@"
if test -x "$srcdir/configure.mc"; then
"$srcdir/configure.mc" "$@"
fi
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ tests/lib/mcconfig/Makefile
tests/lib/search/Makefile
tests/lib/strutil/Makefile
tests/lib/vfs/Makefile
tests/lib/vfs/mc.charsets
tests/lib/widget/Makefile
tests/src/Makefile
tests/src/filemanager/Makefile
Expand Down
21 changes: 12 additions & 9 deletions lib/charsets.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,17 +267,16 @@ get_codepage_index (const char *id)
gboolean
is_supported_encoding (const char *encoding)
{
gboolean result = FALSE;
guint t;
GIConv coder;
gboolean result;

for (t = 0; t < codepages->len; t++)
{
const char *id;

id = ((codepage_desc *) g_ptr_array_index (codepages, t))->id;
result |= (g_ascii_strncasecmp (encoding, id, strlen (id)) == 0);
}
if (encoding == NULL)
return FALSE;

coder = str_crt_conv_from (encoding);
result = coder != INVALID_CONV;
if (result)
str_close_conv (coder);
return result;
}

Expand Down Expand Up @@ -364,6 +363,8 @@ str_nconvert_to_display (const char *str, int len)
return g_string_new (str);

conv = str_crt_conv_from (cp_source);
if (conv == INVALID_CONV)
return g_string_new (str);

buff = g_string_new ("");
str_nconvert (conv, str, len, buff);
Expand Down Expand Up @@ -396,6 +397,8 @@ str_nconvert_to_input (const char *str, int len)
return g_string_new (str);

conv = str_crt_conv_to (cp_source);
if (conv == INVALID_CONV)
return g_string_new (str);

buff = g_string_new ("");
str_nconvert (conv, str, len, buff);
Expand Down
12 changes: 5 additions & 7 deletions lib/strutil/strutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,16 @@ static const char *const str_utf8_encodings[] = {

/* standard 8bit encodings, no wide or multibytes characters */
static const char *const str_8bit_encodings[] = {
/* Solaris has different names of Windows 1251 encoding */
#ifdef __sun
"ansi-1251",
"ansi1251",
#else
"cp-1251",
"cp1251",
#endif
/* solaris */
"ansi-1251",
"ansi1251",
"cp-1250",
"cp1250",
"cp-866",
"cp866",
/* glibc */
"ibm-866",
"ibm866",
"cp-850",
Expand Down Expand Up @@ -274,7 +272,7 @@ str_crt_conv_from (const char *from_enc)
void
str_close_conv (GIConv conv)
{
if (conv != str_cnv_not_convert)
if (conv != INVALID_CONV && conv != str_cnv_not_convert)
g_iconv_close (conv);
}

Expand Down
32 changes: 26 additions & 6 deletions lib/utilunix.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,10 +920,20 @@ canonicalize_pathname_custom (char *path, canon_path_flags_t flags)
{
/* "token/../foo" -> "foo" */
#ifdef HAVE_CHARSET
if ((strncmp (s, VFS_ENCODING_PREFIX, enc_prefix_len) == 0)
&& (is_supported_encoding (s + enc_prefix_len)))
/* special case: remove encoding */
str_move (s, p + 1);
if (strncmp (s, VFS_ENCODING_PREFIX, enc_prefix_len) == 0)
{
char *enc;

enc = vfs_get_encoding (s, -1);

if (is_supported_encoding (enc))
/* special case: remove encoding */
str_move (s, p + 1);
else
str_move (s, p + 4);

g_free (enc);
}
else
#endif /* HAVE_CHARSET */
str_move (s, p + 4);
Expand All @@ -947,9 +957,18 @@ canonicalize_pathname_custom (char *path, canon_path_flags_t flags)
if (s == lpath + 1)
s[0] = '\0';
#ifdef HAVE_CHARSET
else if ((strncmp (s, VFS_ENCODING_PREFIX, enc_prefix_len) == 0)
&& (is_supported_encoding (s + enc_prefix_len)))
else if (strncmp (s, VFS_ENCODING_PREFIX, enc_prefix_len) == 0)
{
char *enc;
gboolean ok;

enc = vfs_get_encoding (s, -1);
ok = is_supported_encoding (enc);
g_free (enc);

if (!ok)
goto last;

/* special case: remove encoding */
s[0] = '.';
s[1] = '.';
Expand All @@ -966,6 +985,7 @@ canonicalize_pathname_custom (char *path, canon_path_flags_t flags)
#endif /* HAVE_CHARSET */
else
{
last:
if (s >= lpath + url_delim_len
&& strncmp (s - url_delim_len, VFS_PATH_URL_DELIMITER, url_delim_len) == 0)
*s = '\0';
Expand Down
73 changes: 35 additions & 38 deletions lib/vfs/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,42 +182,6 @@ vfs_canon (const char *path)
return result;
}

/* --------------------------------------------------------------------------------------------- */

#ifdef HAVE_CHARSET
/** get encoding after last #enc: or NULL, if part does not contain #enc:
*
* @param path null-terminated string
* @param len the maximum length of path, where #enc: should be searched
*
* @return newly allocated string.
*/

static char *
vfs_get_encoding (const char *path, ssize_t len)
{
char *semi;

/* try found #enc: */
semi = g_strrstr_len (path, len, VFS_ENCODING_PREFIX);
if (semi == NULL)
return NULL;

if (semi == path || IS_PATH_SEP (semi[-1]))
{
char *slash;

semi += strlen (VFS_ENCODING_PREFIX); /* skip "#enc:" */
slash = strchr (semi, PATH_SEP);
if (slash != NULL)
return g_strndup (semi, slash - semi);
return g_strdup (semi);
}

return vfs_get_encoding (path, semi - path);
}
#endif

/* --------------------------------------------------------------------------------------------- */
/** Extract the hostname and username from the path
*
Expand Down Expand Up @@ -896,8 +860,8 @@ vfs_path_element_clone (const vfs_path_element_t *element)
new_element->vfs_prefix = g_strdup (element->vfs_prefix);
#ifdef HAVE_CHARSET
new_element->encoding = g_strdup (element->encoding);
if (vfs_path_element_need_cleanup_converter (element) && new_element->encoding != NULL)
new_element->dir.converter = str_crt_conv_from (new_element->encoding);
if (vfs_path_element_need_cleanup_converter (element) && element->encoding != NULL)
new_element->dir.converter = str_crt_conv_from (element->encoding);
else
new_element->dir.converter = element->dir.converter;
#endif
Expand Down Expand Up @@ -1071,6 +1035,39 @@ vfs_prefix_to_class (const char *prefix)

#ifdef HAVE_CHARSET

/** get encoding after last #enc: or NULL, if part does not contain #enc:
*
* @param path null-terminated string
* @param len the maximum length of path, where #enc: should be searched
*
* @return newly allocated string.
*/

char *
vfs_get_encoding (const char *path, ssize_t len)
{
char *semi;

/* try found #enc: */
semi = g_strrstr_len (path, len, VFS_ENCODING_PREFIX);
if (semi == NULL)
return NULL;

if (semi == path || IS_PATH_SEP (semi[-1]))
{
char *slash;

semi += strlen (VFS_ENCODING_PREFIX); /* skip "#enc:" */
slash = strchr (semi, PATH_SEP);
if (slash != NULL)
return g_strndup (semi, slash - semi);
return g_strdup (semi);
}

return vfs_get_encoding (path, semi - path);
}

/* --------------------------------------------------------------------------------------------- */
/**
* Check if need cleanup charset converter for vfs_path_element_t
*
Expand Down
1 change: 1 addition & 0 deletions lib/vfs/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ void vfs_path_element_free (vfs_path_element_t * element);
struct vfs_class *vfs_prefix_to_class (const char *prefix);

#ifdef HAVE_CHARSET
char *vfs_get_encoding(const char *path, ssize_t len);
gboolean vfs_path_element_need_cleanup_converter (const vfs_path_element_t * element);
vfs_path_t *vfs_path_change_encoding (vfs_path_t * vpath, const char *encoding);
#endif
Expand Down
17 changes: 14 additions & 3 deletions m4.include/mc-i18n.m4
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,27 @@ AC_DEFUN([mc_I18N],[
have_charset=yes
charset_msg="yes"
AC_CHECK_HEADERS([gnu/libc-version.h])
dnl Solaris has different name of Windows 1251 encoding
case $host_os in
solaris*)
CP1251="ANSI-1251"
ENCODING_CP1251="ANSI-1251"
;;
*)
CP1251="CP1251"
ENCODING_CP1251="CP1251"
;;
esac
AC_SUBST(CP1251)
if test "x$ac_cv_header_gnu_libc_version_h" != "xno"; then
ENCODING_CP866="IBM866"
ENCODING_ISO8859="ISO-8859"
else
ENCODING_CP866="CP866"
ENCODING_ISO8859="ISO8859"
fi
AC_SUBST(ENCODING_CP1251)
AC_SUBST(ENCODING_CP866)
fi
])
10 changes: 5 additions & 5 deletions misc/mc.charsets.in
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
ASCII 7-bit ASCII
ISO-8859-1 ISO 8859-1
ISO-8859-2 ISO 8859-2
ISO-8859-5 ISO 8859-5
@ENCODING_ISO8859@-1 ISO 8859-1
@ENCODING_ISO8859@-2 ISO 8859-2
@ENCODING_ISO8859@-5 ISO 8859-5
CP1250 Windows 1250
@CP1251@ Windows 1251
@ENCODING_CP1251@ Windows 1251
CP437 CP 437
CP850 CP 850
CP852 CP 852
IBM866 CP 866
@ENCODING_CP866@ CP 866
KOI8-R KOI8-R
KOI8-U KOI8-U
UTF-8 UTF-8
2 changes: 1 addition & 1 deletion src/diffviewer/ydiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ dview_get_utf (const char *str, int *ch, int *ch_length)
}
else
{
char *next_ch;
const char *next_ch;

/* Calculate UTF-8 char length */
next_ch = g_utf8_next_char (str);
Expand Down
35 changes: 16 additions & 19 deletions src/editor/editdraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ edit_draw_this_line (WEdit *edit, off_t b, long row, long start_col, long end_co
unsigned int c;
gboolean wide_width_char = FALSE;
gboolean control_char = FALSE;
gboolean printable;

p->ch = 0;
p->style = q == edit->buffer.curs1 ? MOD_CURSOR : 0;
Expand Down Expand Up @@ -759,34 +760,30 @@ edit_draw_this_line (WEdit *edit, off_t b, long row, long start_col, long end_co
control_char = TRUE;
break;
}

#ifdef HAVE_CHARSET
if (edit->utf8)
{
if (g_unichar_isprint (c))
p->ch = c;
if (mc_global.utf8_display)
/* c is gunichar */
printable = g_unichar_isprint (c);
else
{
p->ch = '.';
p->style = abn_style;
}
p++;
/* c was gunichar; now c is 8-bit char converted from gunichar */
printable = is_printable (c);
}
else
#endif
/* c is 8-bit char */
printable = is_printable (c);

if (printable)
p->ch = c;
else
{
if ((mc_global.utf8_display && g_unichar_isprint (c)) ||
(!mc_global.utf8_display && is_printable (c)))
{
p->ch = c;
p++;
}
else
{
p->ch = '.';
p->style = abn_style;
p++;
}
p->ch = '.';
p->style = abn_style;
}
p++;
col++;
break;
} /* case */
Expand Down
Loading

0 comments on commit a24d45f

Please sign in to comment.