Skip to content

Commit 6c4e687

Browse files
committed
Merge branch '4633_cleanup'
* 4633_cleanup: (47 commits) Update po/*.po files. (tar_short_read): fix undefined behaviour. Fix usage of g_file_test(). (do_link): fix typo in error message string diffviewer: refactoring. (edit_draw_this_line): use different variable for char attributes. tar (keyword_item_run): fix restoring extended attributes from global PAX headers. filemanager/chown: refactoring. filemanager/chattr: refactoring. filemanager/achown: refactoring. filemanager/chmod: refactoring. (init_learn): use button_get_width() to calculate button x-position. Rename variables and struct members that store return value of button_get_width(). (button_get_width): rename from button_get_len(). (query_dialog): refactoring. src/main.c: remove unused includes. (codepage_desc): move struct definition to c-file. (get_codepage_name): new function. Use get_codepage_id() instead of direct access to codepage_desc::id. lib/charsets.[ch]: cleanup. ...
2 parents 595fef4 + 32b9983 commit 6c4e687

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+2221
-2157
lines changed

lib/charsets.c

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <config.h>
3131

32+
#include <limits.h> // MB_LEN_MAX
3233
#include <stdio.h>
3334
#include <stdlib.h>
3435
#include <string.h>
@@ -52,15 +53,22 @@ const char *cp_source = NULL;
5253

5354
/*** file scope macro definitions ****************************************************************/
5455

55-
#define UNKNCHAR '\001'
56-
#define NO_TRANSLATION "No translation"
56+
#define UNKNCHAR '\001'
5757

5858
/*** file scope type declarations ****************************************************************/
5959

60+
typedef struct
61+
{
62+
char *id;
63+
char *name;
64+
} codepage_desc;
65+
6066
/*** forward declarations (file scope functions) *************************************************/
6167

6268
/*** file scope variables ************************************************************************/
6369

70+
static const char NO_TRANSLATION[] = N_ ("No translation");
71+
6472
/* --------------------------------------------------------------------------------------------- */
6573
/*** file scope functions ************************************************************************/
6674
/* --------------------------------------------------------------------------------------------- */
@@ -242,6 +250,15 @@ get_codepage_id (const int n)
242250

243251
/* --------------------------------------------------------------------------------------------- */
244252

253+
const char *
254+
get_codepage_name (const int n)
255+
{
256+
return (n < 0) ? _ (NO_TRANSLATION)
257+
: ((codepage_desc *) g_ptr_array_index (codepages, n))->name;
258+
}
259+
260+
/* --------------------------------------------------------------------------------------------- */
261+
245262
int
246263
get_codepage_index (const char *id)
247264
{
@@ -250,7 +267,7 @@ get_codepage_index (const char *id)
250267
if (strcmp (id, NO_TRANSLATION) == 0)
251268
return -1;
252269
for (guint i = 0; i < codepages->len; i++)
253-
if (strcmp (id, ((codepage_desc *) g_ptr_array_index (codepages, i))->id) == 0)
270+
if (strcmp (id, get_codepage_id (i)) == 0)
254271
return (int) i;
255272
return -1;
256273
}
@@ -303,10 +320,11 @@ init_translation_table (int cpsource, int cpdisplay)
303320
conv_displ[i] = i;
304321
conv_input[i] = i;
305322
}
306-
cp_source = ((codepage_desc *) g_ptr_array_index (codepages, cpsource))->id;
307-
cp_display = ((codepage_desc *) g_ptr_array_index (codepages, cpdisplay))->id;
308323

309-
// display <- inpit table
324+
cp_source = get_codepage_id (cpsource);
325+
cp_display = get_codepage_id (cpdisplay);
326+
327+
// display <- input table
310328

311329
cd = g_iconv_open (cp_display, cp_source);
312330
if (cd == INVALID_CONV)
@@ -317,7 +335,7 @@ init_translation_table (int cpsource, int cpdisplay)
317335

318336
g_iconv_close (cd);
319337

320-
// inpit <- display table
338+
// input <- display table
321339

322340
cd = g_iconv_open (cp_source, cp_display);
323341
if (cd == INVALID_CONV)
@@ -337,16 +355,6 @@ init_translation_table (int cpsource, int cpdisplay)
337355

338356
/* --------------------------------------------------------------------------------------------- */
339357

340-
void
341-
convert_to_display (char *str)
342-
{
343-
if (str != NULL)
344-
for (; *str != '\0'; str++)
345-
*str = conv_displ[(unsigned char) *str];
346-
}
347-
348-
/* --------------------------------------------------------------------------------------------- */
349-
350358
GString *
351359
str_nconvert_to_display (const char *str, int len)
352360
{
@@ -371,16 +379,6 @@ str_nconvert_to_display (const char *str, int len)
371379

372380
/* --------------------------------------------------------------------------------------------- */
373381

374-
void
375-
convert_from_input (char *str)
376-
{
377-
if (str != NULL)
378-
for (; *str != '\0'; str++)
379-
*str = conv_input[(unsigned char) *str];
380-
}
381-
382-
/* --------------------------------------------------------------------------------------------- */
383-
384382
GString *
385383
str_nconvert_to_input (const char *str, int len)
386384
{
@@ -408,7 +406,7 @@ str_nconvert_to_input (const char *str, int len)
408406
unsigned char
409407
convert_from_utf_to_current (const char *str)
410408
{
411-
unsigned char buf_ch[UTF8_CHAR_LEN + 1];
409+
unsigned char buf_ch[MB_LEN_MAX + 1];
412410
unsigned char ch = '.';
413411
GIConv conv;
414412
const char *cp_to;
@@ -444,8 +442,8 @@ convert_from_utf_to_current (const char *str)
444442
unsigned char
445443
convert_from_utf_to_current_c (int input_char, GIConv conv)
446444
{
447-
unsigned char str[UTF8_CHAR_LEN + 1];
448-
unsigned char buf_ch[UTF8_CHAR_LEN + 1];
445+
unsigned char str[MB_LEN_MAX + 1];
446+
unsigned char buf_ch[MB_LEN_MAX + 1];
449447
unsigned char ch = '.';
450448
int res;
451449

@@ -477,7 +475,7 @@ int
477475
convert_from_8bit_to_utf_c (char input_char, GIConv conv)
478476
{
479477
unsigned char str[2];
480-
unsigned char buf_ch[UTF8_CHAR_LEN + 1];
478+
unsigned char buf_ch[MB_LEN_MAX + 1];
481479
int ch;
482480

483481
str[0] = (unsigned char) input_char;

lib/charsets.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111

1212
/*** structures declarations (and typedefs of structures)*****************************************/
1313

14-
typedef struct
15-
{
16-
char *id;
17-
char *name;
18-
} codepage_desc;
19-
2014
/*** global variables defined in .c file *********************************************************/
2115

2216
extern unsigned char conv_displ[256];
@@ -29,14 +23,12 @@ extern GPtrArray *codepages;
2923
/*** declarations of public functions ************************************************************/
3024

3125
const char *get_codepage_id (const int n);
26+
const char *get_codepage_name (const int n);
3227
int get_codepage_index (const char *id);
3328
void load_codepages_list (void);
3429
void free_codepages_list (void);
3530
gboolean is_supported_encoding (const char *encoding);
3631
char *init_translation_table (int cpsource, int cpdisplay);
37-
void convert_to_display (char *str);
38-
void convert_from_input (char *str);
39-
void convert_string (unsigned char *str);
4032

4133
/*
4234
* Converter from utf to selected codepage

lib/global.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,16 @@
7373
#endif
7474

7575
/* Just for keeping Your's brains from invention a proper size of the buffer :-) */
76-
#define BUF_10K 10240L
77-
#define BUF_8K 8192L
78-
#define BUF_4K 4096L
79-
#define BUF_2K 2048L
80-
#define BUF_1K 1024L
81-
82-
#define BUF_LARGE BUF_1K
83-
#define BUF_MEDIUM 512
84-
#define BUF_SMALL 128
85-
#define BUF_TINY 64
86-
87-
#define UTF8_CHAR_LEN 6
76+
#define BUF_10K 10240L
77+
#define BUF_8K 8192L
78+
#define BUF_4K 4096L
79+
#define BUF_2K 2048L
80+
#define BUF_1K 1024L
81+
82+
#define BUF_LARGE BUF_1K
83+
#define BUF_MEDIUM 512
84+
#define BUF_SMALL 128
85+
#define BUF_TINY 64
8886

8987
/* Used to distinguish between a normal MC termination and */
9088
/* one caused by typing 'exit' or 'logout' in the subshell */

lib/mcconfig/paths.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ mc_config_mkdir (const char *directory_name, GError **mcerror)
107107
{
108108
mc_return_if_error (mcerror);
109109

110-
if ((!g_file_test (directory_name, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
111-
&& (g_mkdir_with_parents (directory_name, 0700) != 0))
110+
if (!(g_file_test (directory_name, G_FILE_TEST_EXISTS)
111+
&& g_file_test (directory_name, G_FILE_TEST_IS_DIR))
112+
&& g_mkdir_with_parents (directory_name, 0700) != 0)
112113
mc_propagate_error (mcerror, 0, _ ("Cannot create %s directory"), directory_name);
113114
}
114115

lib/search/search.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,8 @@ mc_search_prepare (mc_search_t *lc_mc_search)
203203

204204
for (loop1 = 0; loop1 < codepages->len; loop1++)
205205
{
206-
const char *id;
206+
const char *id = get_codepage_id (loop1);
207207

208-
id = ((codepage_desc *) g_ptr_array_index (codepages, loop1))->id;
209208
if (g_ascii_strcasecmp (id, lc_mc_search->original.charset) == 0)
210209
g_ptr_array_add (ret,
211210
mc_search__cond_struct_new (lc_mc_search,

lib/strutil/replace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ str_replace_all (const char *haystack, const char *needle, const char *replaceme
9292
if (*haystack != '\0')
9393
{
9494
if (return_str == NULL)
95-
return strdup (haystack);
95+
return g_strdup (haystack);
9696

9797
g_string_append (return_str, haystack);
9898
}

lib/strutil/strescape.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ str_escape (const char *src, const ssize_t src_len, const char *escaped_chars,
6262
return NULL;
6363

6464
if (*src == '\0')
65-
return strdup ("");
65+
return g_strdup ("");
6666

6767
ret = g_string_new ("");
6868

@@ -112,7 +112,7 @@ str_unescape (const char *src, const ssize_t src_len, const char *unescaped_char
112112
return NULL;
113113

114114
if (*src == '\0')
115-
return strdup ("");
115+
return g_strdup ("");
116116

117117
ret = g_string_sized_new (16);
118118

lib/terminal.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,19 @@
7373
* final-byte = [\x40-\x7e] # one of "@A–Z[\]^_`a–z{|}~"
7474
*/
7575
gboolean
76-
parse_csi (struct csi_command_t *out, const char **sptr, const char *end)
76+
parse_csi (csi_command_t *out, const char **sptr, const char *end)
7777
{
7878
gboolean ok = FALSE;
79+
char c;
80+
char private_mode = '\0';
81+
// parameter bytes
82+
size_t param_count = 0;
7983

8084
const char *s = *sptr;
8185
if (s == end)
8286
goto invalid_sequence;
8387

84-
char c = *s;
88+
c = *s;
8589

8690
#define NEXT_CHAR \
8791
do \
@@ -90,34 +94,29 @@ parse_csi (struct csi_command_t *out, const char **sptr, const char *end)
9094
goto invalid_sequence; \
9195
c = *s; \
9296
} \
93-
while (0)
94-
95-
char private_mode = '\0';
97+
while (FALSE)
9698

9799
if (c >= '<' && c <= '?') // "<=>?"
98100
{
99101
private_mode = c;
100102
NEXT_CHAR;
101103
}
102104

103-
// parameter bytes
104-
size_t param_count = 0;
105-
106105
if (private_mode != '\0')
107106
{
108107
while (c >= 0x30 && c <= 0x3F)
109108
NEXT_CHAR;
110109
}
111110
else
112111
{
112+
uint32_t tmp = 0;
113+
size_t sub_index = 0;
114+
113115
if (out != NULL)
114116
// N.B. empty parameter strings are allowed. For our current use,
115117
// treating them as zeroes happens to work.
116118
memset (out->params, 0, sizeof (out->params));
117119

118-
uint32_t tmp = 0;
119-
size_t sub_index = 0;
120-
121120
while (c >= 0x30 && c <= 0x3F)
122121
{
123122
if (c >= '0' && c <= '9')
@@ -207,9 +206,7 @@ strip_ctrl_codes (char *s)
207206
* OSC P s ; P t ST
208207
* OSC P s ; P t BEL
209208
*/
210-
const char *new_r;
211-
212-
for (new_r = r; *new_r != '\0'; new_r++)
209+
for (const char *new_r = r; *new_r != '\0'; new_r++)
213210
{
214211
switch (*new_r)
215212
{
@@ -241,9 +238,8 @@ strip_ctrl_codes (char *s)
241238
}
242239
else
243240
{
244-
const char *n;
241+
const char *n = str_cget_next_char (r);
245242

246-
n = str_cget_next_char (r);
247243
if (str_isprint (r))
248244
{
249245
memmove (w, r, n - r);

lib/terminal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616

1717
/*** structures declarations (and typedefs of structures)*****************************************/
1818

19-
struct csi_command_t
19+
typedef struct
2020
{
2121
char private_mode;
2222
uint32_t params[16][4];
2323
size_t param_count;
24-
};
24+
} csi_command_t;
2525

2626
/*** global variables defined in .c file *********************************************************/
2727

2828
/*** declarations of public functions ************************************************************/
2929

30-
gboolean parse_csi (struct csi_command_t *out, const char **sptr, const char *end);
30+
gboolean parse_csi (csi_command_t *out, const char **sptr, const char *end);
3131

3232
char *strip_ctrl_codes (char *s);
3333

lib/tty/key.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,7 @@ lookup_keyname (const char *name, int *idx)
12791279
/* --------------------------------------------------------------------------------------------- */
12801280

12811281
static gboolean
1282-
lookup_keycode (const long code, int *idx)
1282+
lookup_keycode (const int code, int *idx)
12831283
{
12841284
if (code != 0)
12851285
{

0 commit comments

Comments
 (0)