mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-18 09:19:24 +03:00
lib/charsets.c: fix coding style, trivial optimizations.
This commit is contained in:
parent
c04f8776de
commit
c2e2a33358
@ -106,12 +106,14 @@ load_codepages_list_from_file (GPtrArray ** list, const char *fname)
|
|||||||
{
|
{
|
||||||
/* split string into id and cpname */
|
/* split string into id and cpname */
|
||||||
char *p = buf;
|
char *p = buf;
|
||||||
size_t buflen = strlen (buf);
|
size_t buflen;
|
||||||
|
|
||||||
if (*p == '\n' || *p == '\0' || *p == '#')
|
if (*p == '\n' || *p == '\0' || *p == '#')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (buflen > 0 && buf[buflen - 1] == '\n')
|
buflen = strlen (buf);
|
||||||
|
|
||||||
|
if (buflen != 0 && buf[buflen - 1] == '\n')
|
||||||
buf[buflen - 1] = '\0';
|
buf[buflen - 1] = '\0';
|
||||||
while (*p != '\0' && !whitespace (*p))
|
while (*p != '\0' && !whitespace (*p))
|
||||||
++p;
|
++p;
|
||||||
@ -181,11 +183,10 @@ translate_character (GIConv cd, char c)
|
|||||||
gsize bytes_read, bytes_written = 0;
|
gsize bytes_read, bytes_written = 0;
|
||||||
const char *ibuf = &c;
|
const char *ibuf = &c;
|
||||||
char ch = UNKNCHAR;
|
char ch = UNKNCHAR;
|
||||||
|
|
||||||
int ibuflen = 1;
|
int ibuflen = 1;
|
||||||
|
|
||||||
tmp_buff = g_convert_with_iconv (ibuf, ibuflen, cd, &bytes_read, &bytes_written, NULL);
|
tmp_buff = g_convert_with_iconv (ibuf, ibuflen, cd, &bytes_read, &bytes_written, NULL);
|
||||||
if (tmp_buff)
|
if (tmp_buff != NULL)
|
||||||
ch = tmp_buff[0];
|
ch = tmp_buff[0];
|
||||||
g_free (tmp_buff);
|
g_free (tmp_buff);
|
||||||
return ch;
|
return ch;
|
||||||
@ -270,7 +271,9 @@ is_supported_encoding (const char *encoding)
|
|||||||
|
|
||||||
for (t = 0; t < codepages->len; t++)
|
for (t = 0; t < codepages->len; t++)
|
||||||
{
|
{
|
||||||
const char *id = ((codepage_desc *) g_ptr_array_index (codepages, t))->id;
|
const char *id;
|
||||||
|
|
||||||
|
id = ((codepage_desc *) g_ptr_array_index (codepages, t))->id;
|
||||||
result |= (g_ascii_strncasecmp (encoding, id, strlen (id)) == 0);
|
result |= (g_ascii_strncasecmp (encoding, id, strlen (id)) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -340,14 +343,9 @@ init_translation_table (int cpsource, int cpdisplay)
|
|||||||
void
|
void
|
||||||
convert_to_display (char *str)
|
convert_to_display (char *str)
|
||||||
{
|
{
|
||||||
if (!str)
|
if (str != NULL)
|
||||||
return;
|
for (; *str != '\0'; str++)
|
||||||
|
*str = conv_displ[(unsigned char) *str];
|
||||||
while (*str)
|
|
||||||
{
|
|
||||||
*str = conv_displ[(unsigned char) *str];
|
|
||||||
str++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
@ -356,7 +354,6 @@ GString *
|
|||||||
str_convert_to_display (const char *str)
|
str_convert_to_display (const char *str)
|
||||||
{
|
{
|
||||||
return str_nconvert_to_display (str, -1);
|
return str_nconvert_to_display (str, -1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
@ -367,7 +364,7 @@ str_nconvert_to_display (const char *str, int len)
|
|||||||
GString *buff;
|
GString *buff;
|
||||||
GIConv conv;
|
GIConv conv;
|
||||||
|
|
||||||
if (!str)
|
if (str == NULL)
|
||||||
return g_string_new ("");
|
return g_string_new ("");
|
||||||
|
|
||||||
if (cp_display == cp_source)
|
if (cp_display == cp_source)
|
||||||
@ -386,14 +383,9 @@ str_nconvert_to_display (const char *str, int len)
|
|||||||
void
|
void
|
||||||
convert_from_input (char *str)
|
convert_from_input (char *str)
|
||||||
{
|
{
|
||||||
if (!str)
|
if (str != NULL)
|
||||||
return;
|
for (; *str != '\0'; str++)
|
||||||
|
*str = conv_input[(unsigned char) *str];
|
||||||
while (*str)
|
|
||||||
{
|
|
||||||
*str = conv_input[(unsigned char) *str];
|
|
||||||
str++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
@ -412,7 +404,7 @@ str_nconvert_to_input (const char *str, int len)
|
|||||||
GString *buff;
|
GString *buff;
|
||||||
GIConv conv;
|
GIConv conv;
|
||||||
|
|
||||||
if (!str)
|
if (str == NULL)
|
||||||
return g_string_new ("");
|
return g_string_new ("");
|
||||||
|
|
||||||
if (cp_display == cp_source)
|
if (cp_display == cp_source)
|
||||||
|
Loading…
Reference in New Issue
Block a user