Ticket #2182 (fix incorrect tab size)

fixed incorrect tab size

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
Signed-off-by: Ilia Maslakov <il.smind@gmail.com>
This commit is contained in:
Ilia Maslakov 2010-05-08 05:59:17 +00:00
parent e14ddbd7a1
commit c94da73c54

View File

@ -86,19 +86,28 @@ do { \
#define HDIFF_MINCTX 5
#define HDIFF_DEPTH 10
#define TAB_SKIP(ts, pos) ((ts) - (pos) % (ts))
#define FILE_DIRTY(fs) \
do { \
(fs)->pos = 0; \
(fs)->len = 0; \
} while (0)
/*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
static inline int
TAB_SKIP (int ts, int pos)
{
if (ts > 0 && ts < 9)
return ts - pos % ts;
else
return 8 - pos % 8;
}
/* --------------------------------------------------------------------------------------------- */
@ -188,8 +197,7 @@ open_temp (void **name)
if (fd == -1)
{
message (D_ERROR, MSG_ERROR,
_(" Cannot create temporary diff file \n %s "),
unix_error_string (errno));
_(" Cannot create temporary diff file \n %s "), unix_error_string (errno));
return -1;
}
*name = diff_file_name;
@ -581,7 +589,7 @@ p_close (FBUF * fs)
*/
static int
dview_get_byte (char * str, gboolean * result)
dview_get_byte (char *str, gboolean * result)
{
if (str == NULL)
{
@ -602,7 +610,7 @@ dview_get_byte (char * str, gboolean * result)
*/
static int
dview_get_utf (char * str, int * char_width, gboolean * result)
dview_get_utf (char *str, int *char_width, gboolean * result)
{
int res = -1;
gunichar ch;
@ -1451,7 +1459,7 @@ cvt_mget (const char *src, size_t srcsize, char *dst, int dstsize, int skip, int
int w;
skip--;
utf_ch = dview_get_utf ((char *)src, &w, &res);
utf_ch = dview_get_utf ((char *) src, &w, &res);
if (w > 1)
skip += w - 1;
if (!g_unichar_isprint (utf_ch))
@ -1982,26 +1990,26 @@ static int
find_prev_hunk (const GArray * a, int pos)
{
#if 1
while (pos > 0 && ((DIFFLN *) &g_array_index (a, DIFFLN, pos))->ch != EQU_CH)
while (pos > 0 && ((DIFFLN *) & g_array_index (a, DIFFLN, pos))->ch != EQU_CH)
{
pos--;
}
while (pos > 0 && ((DIFFLN *) &g_array_index (a, DIFFLN, pos))->ch == EQU_CH)
while (pos > 0 && ((DIFFLN *) & g_array_index (a, DIFFLN, pos))->ch == EQU_CH)
{
pos--;
}
while (pos > 0 && ((DIFFLN *) &g_array_index (a, DIFFLN, pos))->ch != EQU_CH)
while (pos > 0 && ((DIFFLN *) & g_array_index (a, DIFFLN, pos))->ch != EQU_CH)
{
pos--;
}
if (pos > 0 && (size_t) pos < a->len)
pos++;
#else
while (pos > 0 && ((DIFFLN *) &g_array_index (a, DIFFLN, pos - 1))->ch == EQU_CH)
while (pos > 0 && ((DIFFLN *) & g_array_index (a, DIFFLN, pos - 1))->ch == EQU_CH)
{
pos--;
}
while (pos > 0 && ((DIFFLN *) &g_array_index (a, DIFFLN, pos - 1))->ch != EQU_CH)
while (pos > 0 && ((DIFFLN *) & g_array_index (a, DIFFLN, pos - 1))->ch != EQU_CH)
{
pos--;
}
@ -2015,11 +2023,11 @@ find_prev_hunk (const GArray * a, int pos)
static size_t
find_next_hunk (const GArray * a, size_t pos)
{
while (pos < a->len && ((DIFFLN *) &g_array_index (a, DIFFLN, pos))->ch != EQU_CH)
while (pos < a->len && ((DIFFLN *) & g_array_index (a, DIFFLN, pos))->ch != EQU_CH)
{
pos++;
}
while (pos < a->len && ((DIFFLN *) &g_array_index (a, DIFFLN, pos))->ch == EQU_CH)
while (pos < a->len && ((DIFFLN *) & g_array_index (a, DIFFLN, pos))->ch == EQU_CH)
{
pos++;
}
@ -2051,7 +2059,7 @@ get_current_hunk (WDiff * dview, int *start_line1, int *end_line1, int *start_li
*end_line2 = 1;
pos = dview->skip_rows;
ch = ((DIFFLN *) &g_array_index (a0, DIFFLN, pos))->ch;
ch = ((DIFFLN *) & g_array_index (a0, DIFFLN, pos))->ch;
if (ch != EQU_CH)
{
switch (ch)
@ -2066,21 +2074,21 @@ get_current_hunk (WDiff * dview, int *start_line1, int *end_line1, int *start_li
res = DIFF_CHG;
break;
}
while (pos > 0 && ((DIFFLN *) &g_array_index (a0, DIFFLN, pos))->ch != EQU_CH)
while (pos > 0 && ((DIFFLN *) & g_array_index (a0, DIFFLN, pos))->ch != EQU_CH)
{
pos--;
}
if (pos > 0)
{
*start_line1 = ((DIFFLN *) &g_array_index (a0, DIFFLN, pos))->line + 1;
*start_line2 = ((DIFFLN *) &g_array_index (a1, DIFFLN, pos))->line + 1;
*start_line1 = ((DIFFLN *) & g_array_index (a0, DIFFLN, pos))->line + 1;
*start_line2 = ((DIFFLN *) & g_array_index (a1, DIFFLN, pos))->line + 1;
}
pos = dview->skip_rows;
while (pos < a0->len && ((DIFFLN *) &g_array_index (a0, DIFFLN, pos))->ch != EQU_CH)
while (pos < a0->len && ((DIFFLN *) & g_array_index (a0, DIFFLN, pos))->ch != EQU_CH)
{
int l0, l1;
l0 = ((DIFFLN *) &g_array_index (a0, DIFFLN, pos))->line;
l1 = ((DIFFLN *) &g_array_index (a1, DIFFLN, pos))->line;
l0 = ((DIFFLN *) & g_array_index (a0, DIFFLN, pos))->line;
l1 = ((DIFFLN *) & g_array_index (a1, DIFFLN, pos))->line;
if (l0 > 0)
*end_line1 = max (*start_line1, l0);
if (l1 > 0)
@ -2337,8 +2345,8 @@ dview_init (WDiff * dview, const char *args, const char *file1, const char *file
dview->ord = 0;
dview->full = 0;
dview->search.handle=NULL;
dview->search.last_string=NULL;
dview->search.handle = NULL;
dview->search.last_string = NULL;
dview->search.last_found_line = -1;
dview->search.last_accessed_num_line = 0;
@ -2420,6 +2428,7 @@ dview_diff_options (WDiff * dview)
dview_reread (dview);
}
}
/* --------------------------------------------------------------------------------------------- */
static void
@ -2457,10 +2466,13 @@ dview_display_file (const WDiff * dview, int ord, int r, int c, int height, int
int display_symbols = dview->display_symbols;
int display_numbers = dview->display_numbers;
int show_cr = dview->show_cr;
int tab_size = dview->tab_size;
int tab_size = 8;
const DIFFLN *p;
int nwidth = display_numbers;
int xwidth = display_symbols + display_numbers;
if (dview->tab_size > 0 && dview->tab_size < 9)
tab_size = dview->tab_size;
if (xwidth)
{
if (xwidth > width && display_symbols)
@ -2495,7 +2507,7 @@ dview_display_file (const WDiff * dview, int ord, int r, int c, int height, int
{
int ch, next_ch, col;
size_t cnt;
p = (DIFFLN *) &g_array_index (dview->a[ord], DIFFLN, i);
p = (DIFFLN *) & g_array_index (dview->a[ord], DIFFLN, i);
ch = p->ch;
tty_setcolor (NORMAL_COLOR);
if (display_symbols)
@ -2556,12 +2568,18 @@ dview_display_file (const WDiff * dview, int ord, int r, int c, int height, int
{
tty_setcolor (att[cnt] ? DFF_CHH_COLOR : DFF_CHG_COLOR);
#ifdef HAVE_CHARSET
if (utf8_display) {
if (!dview->utf8) {
next_ch = convert_from_8bit_to_utf_c ((unsigned char) next_ch, dview->converter);
if (utf8_display)
{
if (!dview->utf8)
{
next_ch =
convert_from_8bit_to_utf_c ((unsigned char) next_ch,
dview->converter);
}
} else if (dview->utf8)
next_ch = convert_from_utf_to_current_c (next_ch, dview->converter);
}
else if (dview->utf8)
next_ch =
convert_from_utf_to_current_c (next_ch, dview->converter);
else
#endif
next_ch = convert_to_display_c (next_ch);
@ -2628,11 +2646,15 @@ dview_display_file (const WDiff * dview, int ord, int r, int c, int height, int
if (ch_res)
{
#ifdef HAVE_CHARSET
if (utf8_display) {
if (!dview->utf8) {
next_ch = convert_from_8bit_to_utf_c ((unsigned char) next_ch, dview->converter);
if (utf8_display)
{
if (!dview->utf8)
{
next_ch =
convert_from_8bit_to_utf_c ((unsigned char) next_ch, dview->converter);
}
} else if (dview->utf8)
}
else if (dview->utf8)
next_ch = convert_from_utf_to_current_c (next_ch, dview->converter);
else
#endif
@ -2869,6 +2891,7 @@ static void
dview_load_options (WDiff * dview)
{
gboolean show_numbers, show_symbols;
int tab_size;
show_symbols = mc_config_get_bool (mc_main_config, "DiffView", "show_symbols", FALSE);
if (show_symbols)
@ -2876,7 +2899,11 @@ dview_load_options (WDiff * dview)
show_numbers = mc_config_get_bool (mc_main_config, "DiffView", "show_numbers", FALSE);
if (show_numbers)
dview->display_numbers = calc_nwidth ((const GArray ** const) dview->a);
dview->tab_size = mc_config_get_int (mc_main_config, "DiffView", "tab_size", 8);
tab_size = mc_config_get_int (mc_main_config, "DiffView", "tab_size", 8);
if (tab_size > 0 && tab_size < 9)
dview->tab_size = tab_size;
else
dview->tab_size = 8;
dview->opt.quality = mc_config_get_int (mc_main_config, "DiffView", "diff_quality", 0);
@ -2905,7 +2932,8 @@ dview_ok_to_exit (WDiff * dview)
if (!dview->merged)
return res;
switch (query_dialog
(_("Quit"), _(" File was modified, Save with exit? "), D_NORMAL, 2, _("&Yes"), _("&No")))
(_("Quit"), _(" File was modified, Save with exit? "), D_NORMAL, 2, _("&Yes"),
_("&No")))
{
case -1:
res = FALSE;
@ -2987,10 +3015,12 @@ dview_execute_cmd (WDiff * dview, unsigned long command)
dview_redo (dview);
break;
case CK_DiffNextHunk:
dview->skip_rows = dview->search.last_accessed_num_line = find_next_hunk (dview->a[0], dview->skip_rows);
dview->skip_rows = dview->search.last_accessed_num_line =
find_next_hunk (dview->a[0], dview->skip_rows);
break;
case CK_DiffPrevHunk:
dview->skip_rows = dview->search.last_accessed_num_line = find_prev_hunk (dview->a[0], dview->skip_rows);
dview->skip_rows = dview->search.last_accessed_num_line =
find_prev_hunk (dview->a[0], dview->skip_rows);
break;
case CK_DiffGoto:
dview_goto_cmd (dview, TRUE);