2 Copyright (C) 2007, 2010 Free Software Foundation, Inc.
4 2007 Daniel Borca <dborca@yahoo.com>
6 2010 Slava Zanko <slavazanko@gmail.com>
7 2010 Andrew Borodin <aborodin@vmail.ru>
8 2010 Ilia Maslakov <il.smind@gmail.com>
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
33 #include <sys/types.h>
36 #include "lib/global.h"
37 #include "lib/tty/tty.h"
38 #include "lib/tty/color.h"
39 #include "lib/tty/key.h"
40 #include "lib/skin.h" /* EDITOR_NORMAL_COLOR */
41 #include "lib/vfs/vfs.h" /* mc_opendir, mc_readdir, mc_closedir, */
43 #include "lib/widget.h"
44 #include "lib/charsets.h"
45 #include "lib/event.h" /* mc_event_raise() */
47 #include "src/filemanager/cmd.h"
48 #include "src/filemanager/midnight.h" /* Needed for current_panel and other_panel */
49 #include "src/filemanager/layout.h" /* Needed for get_current_index and get_other_panel */
51 #include "src/keybind-defaults.h"
52 #include "src/history.h"
53 #include "src/selcodepage.h"
58 /*** global variables ****************************************************************************/
60 /*** file scope macro definitions ****************************************************************/
62 #define g_array_foreach(a, TP, cbf) \
64 size_t g_array_foreach_i;\
65 TP *g_array_foreach_var=NULL; \
66 for (g_array_foreach_i=0;g_array_foreach_i < a->len; g_array_foreach_i++) \
68 g_array_foreach_var = &g_array_index(a,TP,g_array_foreach_i); \
69 (*cbf) (g_array_foreach_var); \
73 #define FILE_READ_BUF 4096
74 #define FILE_FLAG_TEMP (1 << 0)
84 #define HDIFF_ENABLE 1
85 #define HDIFF_MINCTX 5
86 #define HDIFF_DEPTH 10
88 #define FILE_DIRTY(fs) \
96 /*** file scope type declarations ****************************************************************/
98 /*** file scope variables ************************************************************************/
100 /*** file scope functions ************************************************************************/
101 /* --------------------------------------------------------------------------------------------- */
104 TAB_SKIP (int ts
, int pos
)
106 if (ts
> 0 && ts
< 9)
107 return ts
- pos
% ts
;
112 /* --------------------------------------------------------------------------------------------- */
115 dview_set_codeset (WDiff
* dview
)
118 const char *encoding_id
= NULL
;
122 get_codepage_id (mc_global
.source_codepage
>=
123 0 ? mc_global
.source_codepage
: mc_global
.display_codepage
);
124 if (encoding_id
!= NULL
)
127 conv
= str_crt_conv_from (encoding_id
);
128 if (conv
!= INVALID_CONV
)
130 if (dview
->converter
!= str_cnv_from_term
)
131 str_close_conv (dview
->converter
);
132 dview
->converter
= conv
;
134 dview
->utf8
= (gboolean
) str_isutf8 (encoding_id
);
141 /* --------------------------------------------------------------------------------------------- */
144 dview_select_encoding (WDiff
* dview
)
147 if (do_select_codepage ())
148 dview_set_codeset (dview
);
156 rewrite_backup_content (const char *from_file_name
, const char *to_file_name
)
162 if (!g_file_get_contents (from_file_name
, &contents
, &length
, NULL
))
165 backup_fd
= fopen (to_file_name
, "w");
166 if (backup_fd
== NULL
)
172 length
= fwrite ((const void *) contents
, length
, 1, backup_fd
);
180 /* buffered I/O ************************************************************* */
183 * Try to open a temporary file.
185 * \param[out] name address of a pointer to store the temporary name
187 * \return file descriptor on success, negative on error
189 * \note the name is not altered if this function fails
193 open_temp (void **name
)
196 char *diff_file_name
= NULL
;
198 fd
= mc_mkstemps (&diff_file_name
, "mcdiff", NULL
);
201 message (D_ERROR
, MSG_ERROR
,
202 _("Cannot create temporary diff file\n%s"), unix_error_string (errno
));
205 *name
= diff_file_name
;
209 /* --------------------------------------------------------------------------------------------- */
212 * Alocate file structure and associate file descriptor to it.
214 * \param fd file descriptor
216 * \return file structure
226 fs
= g_try_malloc (sizeof (FBUF
));
230 fs
->buf
= g_try_malloc (FILE_READ_BUF
);
245 /* --------------------------------------------------------------------------------------------- */
248 * Free file structure without closing the file.
250 * \param fs file structure
252 * \return 0 on success, non-zero on error
258 if (fs
->flags
& FILE_FLAG_TEMP
)
260 rv
= unlink (fs
->data
);
269 /* --------------------------------------------------------------------------------------------- */
272 * Open a binary temporary file in R/W mode.
274 * \return file structure
276 * \note the file will be deleted when closed
290 fd
= open_temp (&fs
->data
);
298 fs
->flags
= FILE_FLAG_TEMP
;
302 /* --------------------------------------------------------------------------------------------- */
305 * Open a binary file in specified mode.
307 * \param filename file name
308 * \param flags open mode, a combination of O_RDONLY, O_WRONLY, O_RDWR
310 * \return file structure
313 f_open (const char *filename
, int flags
)
324 fd
= open (filename
, flags
);
335 /* --------------------------------------------------------------------------------------------- */
338 * Read a line of bytes from file until newline or EOF.
340 * \param buf destination buffer
341 * \param size size of buffer
342 * \param fs file structure
344 * \return number of bytes read
346 * \note does not stop on null-byte
347 * \note buf will not be null-terminated
350 f_gets (char *buf
, size_t size
, FBUF
* fs
)
359 for (i
= fs
->pos
; j
< size
&& i
< fs
->len
&& !stop
; i
++, j
++)
369 if (j
== size
|| stop
)
375 fs
->len
= read (fs
->fd
, fs
->buf
, FILE_READ_BUF
);
382 /* --------------------------------------------------------------------------------------------- */
387 * \param fs file structure
389 * \param whence seek directive: SEEK_SET, SEEK_CUR or SEEK_END
391 * \return position in file, starting from begginning
393 * \note avoids thrashing read cache when possible
396 f_seek (FBUF
* fs
, off_t off
, int whence
)
400 if (fs
->len
&& whence
!= SEEK_END
)
402 rv
= lseek (fs
->fd
, 0, SEEK_CUR
);
405 if (whence
== SEEK_CUR
)
408 off
+= rv
- fs
->len
+ fs
->pos
;
410 if (off
- rv
>= -fs
->len
&& off
- rv
<= 0)
412 fs
->pos
= fs
->len
+ off
- rv
;
418 rv
= lseek (fs
->fd
, off
, whence
);
426 /* --------------------------------------------------------------------------------------------- */
429 * Seek to the beginning of file, thrashing read cache.
431 * \param fs file structure
433 * \return 0 if success, non-zero on error
438 off_t rv
= lseek (fs
->fd
, 0, SEEK_SET
);
446 /* --------------------------------------------------------------------------------------------- */
449 * Write bytes to file.
451 * \param fs file structure
452 * \param buf source buffer
453 * \param size size of buffer
455 * \return number of written bytes, -1 on error
457 * \note thrashes read cache
460 f_write (FBUF
* fs
, const char *buf
, size_t size
)
462 ssize_t rv
= write (fs
->fd
, buf
, size
);
470 /* --------------------------------------------------------------------------------------------- */
473 * Truncate file to the current position.
475 * \param fs file structure
477 * \return current file size on success, negative on error
479 * \note thrashes read cache
484 off_t off
= lseek (fs
->fd
, 0, SEEK_CUR
);
487 int rv
= ftruncate (fs
->fd
, off
);
500 /* --------------------------------------------------------------------------------------------- */
505 * \param fs file structure
507 * \return 0 on success, non-zero on error
509 * \note if this is temporary file, it is deleted
514 int rv
= close (fs
->fd
);
519 /* --------------------------------------------------------------------------------------------- */
522 * Create pipe stream to process.
524 * \param cmd shell command line
525 * \param flags open mode, either O_RDONLY or O_WRONLY
527 * \return file structure
530 p_open (const char *cmd
, int flags
)
534 const char *type
= NULL
;
536 if (flags
== O_RDONLY
)
540 if (flags
== O_WRONLY
)
556 f
= popen (cmd
, type
);
568 /* --------------------------------------------------------------------------------------------- */
573 * \param fs structure
575 * \return 0 on success, non-zero on error
580 int rv
= pclose (fs
->data
);
586 * Get one char (byte) from string
588 * \param char * str, gboolean * result
590 * \return int as character or 0 and result == FALSE if fail
594 dview_get_byte (char *str
, gboolean
* result
)
602 return (unsigned char) *str
;
607 * Get utf multibyte char from string
609 * \param char * str, int * char_width, gboolean * result
611 * \return int as utf character or 0 and result == FALSE if fail
615 dview_get_utf (char *str
, int *char_width
, gboolean
* result
)
619 gchar
*next_ch
= NULL
;
631 res
= g_utf8_get_char_validated (str
, -1);
641 /* Calculate UTF-8 char width */
642 next_ch
= g_utf8_next_char (str
);
645 width
= next_ch
- str
;
658 dview_str_utf8_offset_to_pos (const char *text
, size_t length
)
661 if (text
== NULL
|| text
[0] == '\0')
663 if (g_utf8_validate (text
, -1, NULL
))
665 result
= g_utf8_offset_to_pointer (text
, length
) - text
;
670 char *tmpbuf
, *buffer
;
671 buffer
= tmpbuf
= g_strdup (text
);
672 while (tmpbuf
[0] != '\0')
674 uni
= g_utf8_get_char_validated (tmpbuf
, -1);
675 if ((uni
!= (gunichar
) (-1)) && (uni
!= (gunichar
) (-2)))
677 tmpbuf
= g_utf8_next_char (tmpbuf
);
686 result
= g_utf8_offset_to_pointer (tmpbuf
, length
) - tmpbuf
;
689 return max (length
, (size_t) result
);
693 /* --------------------------------------------------------------------------------------------- */
694 /* diff parse *************************************************************** */
697 * Read decimal number from string.
699 * \param[in,out] str string to parse
700 * \param[out] n extracted number
702 * \return 0 if success, otherwise non-zero
705 scan_deci (const char **str
, int *n
)
707 const char *p
= *str
;
710 *n
= strtol (p
, &q
, 10);
719 /* --------------------------------------------------------------------------------------------- */
722 * Parse line for diff statement.
724 * \param p string to parse
725 * \param ops list of diff statements
727 * \return 0 if success, otherwise non-zero
730 scan_line (const char *p
, GArray
* ops
)
740 /* handle the following cases:
742 * NUM[,NUM]cNUM[,NUM]
744 * where NUM is a positive integer
747 if (scan_deci (&p
, &f1
) != 0 || f1
< 0)
756 if (scan_deci (&p
, &f2
) != 0 || f2
< f1
)
771 else if (cmd
!= 'c' && cmd
!= 'd')
776 if (scan_deci (&p
, &t1
) != 0 || t1
< 0)
785 if (scan_deci (&p
, &t2
) != 0 || t2
< t1
)
805 g_array_append_val (ops
, op
);
809 /* --------------------------------------------------------------------------------------------- */
812 * Parse diff output and extract diff statements.
814 * \param f stream to read from
815 * \param ops list of diff statements to fill
817 * \return positive number indicating number of hunks, otherwise negative
820 scan_diff (FBUF
* f
, GArray
* ops
)
825 while ((sz
= f_gets (buf
, sizeof (buf
) - 1, f
)))
827 if (isdigit (buf
[0]))
829 if (buf
[sz
- 1] != '\n')
834 if (scan_line (buf
, ops
) != 0)
840 while (buf
[sz
- 1] != '\n' && (sz
= f_gets (buf
, sizeof (buf
), f
)) != 0)
848 /* --------------------------------------------------------------------------------------------- */
851 * Invoke diff and extract diff statements.
853 * \param args extra arguments to be passed to diff
854 * \param extra more arguments to be passed to diff
855 * \param file1 first file to compare
856 * \param file2 second file to compare
857 * \param ops list of diff statements to fill
859 * \return positive number indicating number of hunks, otherwise negative
862 dff_execute (const char *args
, const char *extra
, const char *file1
, const char *file2
,
865 static const char *opt
=
866 " --old-group-format='%df%(f=l?:,%dl)d%dE\n'"
867 " --new-group-format='%dea%dF%(F=L?:,%dL)\n'"
868 " --changed-group-format='%df%(f=l?:,%dl)c%dF%(F=L?:,%dL)\n'"
869 " --unchanged-group-format=''";
876 cmd
= g_strdup_printf ("diff %s %s %s \"%s\" \"%s\"", args
, extra
, opt
, file1
, file2
);
880 f
= p_open (cmd
, O_RDONLY
);
886 rv
= scan_diff (f
, ops
);
889 if (rv
< 0 || code
== -1 || !WIFEXITED (code
) || WEXITSTATUS (code
) == 2)
895 /* --------------------------------------------------------------------------------------------- */
898 * Reparse and display file according to diff statements.
900 * \param ord 0 if displaying first file, 1 if displaying 2nd file
901 * \param filename file name to display
902 * \param ops list of diff statements
903 * \param printer printf-like function to be used for displaying
904 * \param ctx printer context
906 * \return 0 if success, otherwise non-zero
909 dff_reparse (int ord
, const char *filename
, const GArray
* ops
, DFUNC printer
, void *ctx
)
922 f
= f_open (filename
, O_RDONLY
);
940 #define T1 a[ ord^1 ][0]
941 #define T2 a[ ord^1 ][1]
942 for (i
= 0; i
< ops
->len
; i
++)
945 op
= &g_array_index (ops
, DIFFCMD
, i
);
946 n
= op
->F1
- (op
->cmd
!= add_cmd
);
947 while (line
< n
&& (sz
= f_gets (buf
, sizeof (buf
), f
)) != 0)
950 printer (ctx
, EQU_CH
, line
, off
, sz
, buf
);
952 while (buf
[sz
- 1] != '\n')
954 sz
= f_gets (buf
, sizeof (buf
), f
);
957 printer (ctx
, 0, 0, 0, 1, "\n");
960 printer (ctx
, 0, 0, 0, sz
, buf
);
969 if (op
->cmd
== add_cmd
)
971 n
= op
->T2
- op
->T1
+ 1;
974 printer (ctx
, DEL_CH
, 0, 0, 1, "\n");
978 if (op
->cmd
== del_cmd
)
980 n
= op
->F2
- op
->F1
+ 1;
981 while (n
!= 0 && (sz
= f_gets (buf
, sizeof (buf
), f
)) != 0)
984 printer (ctx
, ADD_CH
, line
, off
, sz
, buf
);
986 while (buf
[sz
- 1] != '\n')
988 sz
= f_gets (buf
, sizeof (buf
), f
);
991 printer (ctx
, 0, 0, 0, 1, "\n");
994 printer (ctx
, 0, 0, 0, sz
, buf
);
1006 n
= op
->F2
- op
->F1
+ 1;
1007 while (n
!= 0 && (sz
= f_gets (buf
, sizeof (buf
), f
)) != 0)
1010 printer (ctx
, CHG_CH
, line
, off
, sz
, buf
);
1012 while (buf
[sz
- 1] != '\n')
1014 sz
= f_gets (buf
, sizeof (buf
), f
);
1017 printer (ctx
, 0, 0, 0, 1, "\n");
1020 printer (ctx
, 0, 0, 0, sz
, buf
);
1029 n
= op
->T2
- op
->T1
- (op
->F2
- op
->F1
);
1032 printer (ctx
, CHG_CH
, 0, 0, 1, "\n");
1042 while ((sz
= f_gets (buf
, sizeof (buf
), f
)) != 0)
1045 printer (ctx
, EQU_CH
, line
, off
, sz
, buf
);
1047 while (buf
[sz
- 1] != '\n')
1049 sz
= f_gets (buf
, sizeof (buf
), f
);
1052 printer (ctx
, 0, 0, 0, 1, "\n");
1055 printer (ctx
, 0, 0, 0, sz
, buf
);
1068 /* --------------------------------------------------------------------------------------------- */
1069 /* horizontal diff ********************************************************** */
1072 * Longest common substring.
1074 * \param s first string
1075 * \param m length of first string
1076 * \param t second string
1077 * \param n length of second string
1078 * \param ret list of offsets for longest common substrings inside each string
1079 * \param min minimum length of common substrings
1081 * \return 0 if success, nonzero otherwise
1084 lcsubstr (const char *s
, int m
, const char *t
, int n
, GArray
* ret
, int min
)
1092 if (m
< min
|| n
< min
)
1094 /* XXX early culling */
1098 Lprev
= g_new0 (int, n
+ 1);
1099 Lcurr
= g_new0 (int, n
+ 1);
1101 if (Lprev
== NULL
|| Lcurr
== NULL
)
1108 for (i
= 0; i
< m
; i
++)
1113 #ifdef USE_MEMSET_IN_LCS
1114 memset (Lcurr
, 0, (n
+ 1) * sizeof (int));
1116 for (j
= 0; j
< n
; j
++)
1118 #ifndef USE_MEMSET_IN_LCS
1123 int v
= Lprev
[j
] + 1;
1128 g_array_set_size (ret
, 0);
1130 if (z
== v
&& z
>= min
)
1132 int off0
= i
- z
+ 1;
1133 int off1
= j
- z
+ 1;
1135 for (k
= 0; k
< ret
->len
; k
++)
1137 PAIR
*p
= (PAIR
*) g_array_index (ret
, PAIR
, k
);
1138 if ((*p
)[0] == off0
)
1142 if ((*p
)[1] >= off1
)
1152 g_array_append_val (ret
, p2
);
1168 /* --------------------------------------------------------------------------------------------- */
1171 * Scan recursively for common substrings and build ranges.
1173 * \param s first string
1174 * \param t second string
1175 * \param bracket current limits for both of the strings
1176 * \param min minimum length of common substrings
1177 * \param hdiff list of horizontal diff ranges to fill
1178 * \param depth recursion depth
1180 * \return 0 if success, nonzero otherwise
1183 hdiff_multi (const char *s
, const char *t
, const BRACKET bracket
, int min
, GArray
* hdiff
,
1193 ret
= g_array_new (FALSE
, TRUE
, sizeof (PAIR
));
1197 len
= lcsubstr (s
+ bracket
[0].off
, bracket
[0].len
,
1198 t
+ bracket
[1].off
, bracket
[1].len
, ret
, min
);
1202 const PAIR
*data
= (const PAIR
*) &g_array_index (ret
, PAIR
, 0);
1205 b
[0].off
= bracket
[0].off
;
1206 b
[0].len
= (*data
)[0];
1207 b
[1].off
= bracket
[1].off
;
1208 b
[1].len
= (*data
)[1];
1209 if (!hdiff_multi (s
, t
, b
, min
, hdiff
, depth
))
1212 for (k
= 0; k
< ret
->len
- 1; k
++)
1214 data
= (const PAIR
*) &g_array_index (ret
, PAIR
, k
);
1215 data2
= (const PAIR
*) &g_array_index (ret
, PAIR
, k
+ 1);
1216 b
[0].off
= bracket
[0].off
+ (*data
)[0] + len
;
1217 b
[0].len
= (*data2
)[0] - (*data
)[0] - len
;
1218 b
[1].off
= bracket
[1].off
+ (*data
)[1] + len
;
1219 b
[1].len
= (*data2
)[1] - (*data
)[1] - len
;
1220 if (!hdiff_multi (s
, t
, b
, min
, hdiff
, depth
))
1223 data
= (const PAIR
*) &g_array_index (ret
, PAIR
, k
);
1224 b
[0].off
= bracket
[0].off
+ (*data
)[0] + len
;
1225 b
[0].len
= bracket
[0].len
- (*data
)[0] - len
;
1226 b
[1].off
= bracket
[1].off
+ (*data
)[1] + len
;
1227 b
[1].len
= bracket
[1].len
- (*data
)[1] - len
;
1228 if (!hdiff_multi (s
, t
, b
, min
, hdiff
, depth
))
1231 g_array_free (ret
, TRUE
);
1236 p
[0].off
= bracket
[0].off
;
1237 p
[0].len
= bracket
[0].len
;
1238 p
[1].off
= bracket
[1].off
;
1239 p
[1].len
= bracket
[1].len
;
1240 g_array_append_val (hdiff
, p
);
1245 /* --------------------------------------------------------------------------------------------- */
1248 * Build list of horizontal diff ranges.
1250 * \param s first string
1251 * \param m length of first string
1252 * \param t second string
1253 * \param n length of second string
1254 * \param min minimum length of common substrings
1255 * \param hdiff list of horizontal diff ranges to fill
1256 * \param depth recursion depth
1258 * \return 0 if success, nonzero otherwise
1261 hdiff_scan (const char *s
, int m
, const char *t
, int n
, int min
, GArray
* hdiff
, unsigned int depth
)
1266 /* dumbscan (single horizontal diff) -- does not compress whitespace */
1267 for (i
= 0; i
< m
&& i
< n
&& s
[i
] == t
[i
]; i
++)
1269 for (; m
> i
&& n
> i
&& s
[m
- 1] == t
[n
- 1]; m
--, n
--)
1277 /* smartscan (multiple horizontal diff) */
1278 return hdiff_multi (s
, t
, b
, min
, hdiff
, depth
);
1281 /* --------------------------------------------------------------------------------------------- */
1282 /* read line **************************************************************** */
1285 * Check if character is inside horizontal diff limits.
1287 * \param k rank of character inside line
1288 * \param hdiff horizontal diff structure
1289 * \param ord 0 if reading from first file, 1 if reading from 2nd file
1291 * \return TRUE if inside hdiff limits, FALSE otherwise
1294 is_inside (int k
, GArray
* hdiff
, int ord
)
1298 for (i
= 0; i
< hdiff
->len
; i
++)
1301 b
= &g_array_index (hdiff
, BRACKET
, i
);
1303 start
= (*b
)[ord
].off
;
1304 end
= start
+ (*b
)[ord
].len
;
1305 if (k
>= start
&& k
< end
)
1313 /* --------------------------------------------------------------------------------------------- */
1316 * Copy `src' to `dst' expanding tabs.
1318 * \param dst destination buffer
1319 * \param src source buffer
1320 * \param srcsize size of src buffer
1321 * \param base virtual base of this string, needed to calculate tabs
1322 * \param ts tab size
1324 * \return new virtual base
1326 * \note The procedure returns when all bytes are consumed from `src'
1329 cvt_cpy (char *dst
, const char *src
, size_t srcsize
, int base
, int ts
)
1332 for (i
= 0; srcsize
!= 0; i
++, src
++, dst
++, srcsize
--)
1337 int j
= TAB_SKIP (ts
, i
+ base
);
1349 /* --------------------------------------------------------------------------------------------- */
1352 * Copy `src' to `dst' expanding tabs.
1354 * \param dst destination buffer
1355 * \param dstsize size of dst buffer
1356 * \param[in,out] _src source buffer
1357 * \param srcsize size of src buffer
1358 * \param base virtual base of this string, needed to calculate tabs
1359 * \param ts tab size
1361 * \return new virtual base
1363 * \note The procedure returns when all bytes are consumed from `src'
1364 * or `dstsize' bytes are written to `dst'
1365 * \note Upon return, `src' points to the first unwritten character in source
1368 cvt_ncpy (char *dst
, int dstsize
, const char **_src
, size_t srcsize
, int base
, int ts
)
1371 const char *src
= *_src
;
1372 for (i
= 0; i
< dstsize
&& srcsize
!= 0; i
++, src
++, dst
++, srcsize
--)
1377 int j
= TAB_SKIP (ts
, i
+ base
);
1378 if (j
> dstsize
- i
)
1394 /* --------------------------------------------------------------------------------------------- */
1397 * Read line from memory, converting tabs to spaces and padding with spaces.
1399 * \param src buffer to read from
1400 * \param srcsize size of src buffer
1401 * \param dst buffer to read to
1402 * \param dstsize size of dst buffer, excluding trailing null
1403 * \param skip number of characters to skip
1404 * \param ts tab size
1405 * \param show_cr show trailing carriage return as ^M
1407 * \return negative on error, otherwise number of bytes except padding
1410 cvt_mget (const char *src
, size_t srcsize
, char *dst
, int dstsize
, int skip
, int ts
, int show_cr
)
1418 for (i
= 0; dstsize
!= 0 && srcsize
!= 0 && *src
!= '\n'; i
++, src
++, srcsize
--)
1422 int j
= TAB_SKIP (ts
, i
+ base
);
1430 else if (dstsize
!= 0)
1437 else if (src
[0] == '\r' && (srcsize
== 1 || src
[1] == '\n'))
1439 if (skip
== 0 && show_cr
)
1464 utf_ch
= dview_get_utf ((char *) src
, &w
, &res
);
1467 if (!g_unichar_isprint (utf_ch
))
1479 while (dstsize
!= 0)
1488 /* --------------------------------------------------------------------------------------------- */
1491 * Read line from memory and build attribute array.
1493 * \param src buffer to read from
1494 * \param srcsize size of src buffer
1495 * \param dst buffer to read to
1496 * \param dstsize size of dst buffer, excluding trailing null
1497 * \param skip number of characters to skip
1498 * \param ts tab size
1499 * \param show_cr show trailing carriage return as ^M
1500 * \param hdiff horizontal diff structure
1501 * \param ord 0 if reading from first file, 1 if reading from 2nd file
1502 * \param att buffer of attributes
1504 * \return negative on error, otherwise number of bytes except padding
1507 cvt_mgeta (const char *src
, size_t srcsize
, char *dst
, int dstsize
, int skip
, int ts
, int show_cr
,
1508 GArray
* hdiff
, int ord
, char *att
)
1516 for (i
= 0, k
= 0; dstsize
!= 0 && srcsize
!= 0 && *src
!= '\n'; i
++, k
++, src
++, srcsize
--)
1520 int j
= TAB_SKIP (ts
, i
+ base
);
1528 else if (dstsize
!= 0)
1531 *att
++ = is_inside (k
, hdiff
, ord
);
1536 else if (src
[0] == '\r' && (srcsize
== 1 || src
[1] == '\n'))
1538 if (skip
== 0 && show_cr
)
1543 *att
++ = is_inside (k
, hdiff
, ord
);
1545 *att
++ = is_inside (k
, hdiff
, ord
);
1551 *att
++ = is_inside (k
, hdiff
, ord
);
1566 utf_ch
= dview_get_utf ((char *) src
, &w
, &res
);
1569 if (!g_unichar_isprint (utf_ch
))
1575 *att
++ = is_inside (k
, hdiff
, ord
);
1582 while (dstsize
!= 0)
1592 /* --------------------------------------------------------------------------------------------- */
1595 * Read line from file, converting tabs to spaces and padding with spaces.
1597 * \param f file stream to read from
1598 * \param off offset of line inside file
1599 * \param dst buffer to read to
1600 * \param dstsize size of dst buffer, excluding trailing null
1601 * \param skip number of characters to skip
1602 * \param ts tab size
1603 * \param show_cr show trailing carriage return as ^M
1605 * \return negative on error, otherwise number of bytes except padding
1608 cvt_fget (FBUF
* f
, off_t off
, char *dst
, size_t dstsize
, int skip
, int ts
, int show_cr
)
1611 int old_base
= base
;
1612 const int amount
= dstsize
;
1614 size_t useful
, offset
;
1621 const char *q
= NULL
;
1622 char tmp
[BUFSIZ
]; /* XXX capacity must be >= max{dstsize + 1, amount} */
1623 char cvt
[BUFSIZ
]; /* XXX capacity must be >= MAX_TAB_WIDTH * amount */
1625 if ((int) sizeof (tmp
) < amount
|| (int) sizeof (tmp
) <= dstsize
1626 || (int) sizeof (cvt
) < 8 * amount
)
1628 /* abnormal, but avoid buffer overflow */
1629 memset (dst
, ' ', dstsize
);
1630 dst
[dstsize
] = '\0';
1634 f_seek (f
, off
, SEEK_SET
);
1639 sz
= f_gets (tmp
, amount
, f
);
1643 base
= cvt_cpy (cvt
, tmp
, sz
, old_base
, ts
);
1644 if (cvt
[base
- old_base
- 1] == '\n')
1646 q
= &cvt
[base
- old_base
- 1];
1647 base
= old_base
+ q
- cvt
+ 1;
1654 memset (dst
, ' ', dstsize
);
1655 dst
[dstsize
] = '\0';
1659 useful
= base
- skip
;
1660 offset
= skip
- old_base
;
1662 if (useful
<= dstsize
)
1665 memmove (dst
, cvt
+ offset
, useful
);
1669 sz
= f_gets (tmp
, dstsize
- useful
+ 1, f
);
1672 const char *ptr
= tmp
;
1673 useful
+= cvt_ncpy (dst
+ useful
, dstsize
- useful
, &ptr
, sz
, base
, ts
) - base
;
1682 memmove (dst
, cvt
+ offset
, dstsize
);
1684 lastch
= cvt
[offset
+ dstsize
];
1688 for (i
= 0; i
< sz
&& dst
[i
] != '\n'; i
++)
1690 if (dst
[i
] == '\r' && dst
[i
+ 1] == '\n')
1694 if (i
+ 1 < dstsize
)
1707 for (; i
< dstsize
; i
++)
1715 /* --------------------------------------------------------------------------------------------- */
1716 /* diff printers et al ****************************************************** */
1719 cc_free_elt (void *elt
)
1728 /* --------------------------------------------------------------------------------------------- */
1731 printer (void *ctx
, int ch
, int line
, off_t off
, size_t sz
, const char *str
)
1733 GArray
*a
= ((PRINTER_CTX
*) ctx
)->a
;
1734 DSRC dsrc
= ((PRINTER_CTX
*) ctx
)->dsrc
;
1742 if (dsrc
== DATA_SRC_MEM
&& line
!= 0)
1744 if (sz
!= 0 && str
[sz
- 1] == '\n')
1749 p
.p
= g_strndup (str
, sz
);
1752 g_array_append_val (a
, p
);
1754 else if (dsrc
== DATA_SRC_MEM
)
1757 p
= &g_array_index (a
, DIFFLN
, a
->len
- 1);
1758 if (sz
!= 0 && str
[sz
- 1] == '\n')
1764 size_t new_size
= p
->u
.len
+ sz
;
1765 char *q
= g_realloc (p
->p
, new_size
);
1766 memcpy (q
+ p
->u
.len
, str
, sz
);
1771 if (dsrc
== DATA_SRC_TMP
&& (line
!= 0 || ch
== 0))
1773 FBUF
*f
= ((PRINTER_CTX
*) ctx
)->f
;
1774 f_write (f
, str
, sz
);
1779 /* --------------------------------------------------------------------------------------------- */
1782 redo_diff (WDiff
* dview
)
1784 FBUF
*const *f
= dview
->f
;
1794 if (dview
->opt
.quality
== 2)
1796 strcat (extra
, " -d");
1798 if (dview
->opt
.quality
== 1)
1800 strcat (extra
, " --speed-large-files");
1802 if (dview
->opt
.strip_trailing_cr
)
1804 strcat (extra
, " --strip-trailing-cr");
1806 if (dview
->opt
.ignore_tab_expansion
)
1808 strcat (extra
, " -E");
1810 if (dview
->opt
.ignore_space_change
)
1812 strcat (extra
, " -b");
1814 if (dview
->opt
.ignore_all_space
)
1816 strcat (extra
, " -w");
1818 if (dview
->opt
.ignore_case
)
1820 strcat (extra
, " -i");
1823 if (dview
->dsrc
!= DATA_SRC_MEM
)
1829 ops
= g_array_new (FALSE
, FALSE
, sizeof (DIFFCMD
));
1830 ndiff
= dff_execute (dview
->args
, extra
, dview
->file
[0], dview
->file
[1], ops
);
1834 g_array_free (ops
, TRUE
);
1838 ctx
.dsrc
= dview
->dsrc
;
1841 ctx
.a
= dview
->a
[0];
1843 rv
|= dff_reparse (0, dview
->file
[0], ops
, printer
, &ctx
);
1845 ctx
.a
= dview
->a
[1];
1847 rv
|= dff_reparse (1, dview
->file
[1], ops
, printer
, &ctx
);
1850 g_array_free (ops
, TRUE
);
1852 if (rv
!= 0 || dview
->a
[0]->len
!= dview
->a
[1]->len
)
1855 if (dview
->dsrc
== DATA_SRC_TMP
)
1861 if (dview
->dsrc
== DATA_SRC_MEM
&& HDIFF_ENABLE
)
1863 dview
->hdiff
= g_ptr_array_new ();
1864 if (dview
->hdiff
!= NULL
)
1869 for (i
= 0; i
< dview
->a
[0]->len
; i
++)
1872 p
= &g_array_index (dview
->a
[0], DIFFLN
, i
);
1873 q
= &g_array_index (dview
->a
[1], DIFFLN
, i
);
1874 if (p
->line
&& q
->line
&& p
->ch
== CHG_CH
)
1876 h
= g_array_new (FALSE
, FALSE
, sizeof (BRACKET
));
1879 gboolean runresult
=
1880 hdiff_scan (p
->p
, p
->u
.len
, q
->p
, q
->u
.len
, HDIFF_MINCTX
, h
,
1884 g_array_free (h
, TRUE
);
1889 g_ptr_array_add (dview
->hdiff
, h
);
1896 /* --------------------------------------------------------------------------------------------- */
1899 destroy_hdiff (WDiff
* dview
)
1901 if (dview
->hdiff
!= NULL
)
1904 int len
= dview
->a
[0]->len
;
1905 for (i
= 0; i
< len
; i
++)
1907 GArray
*h
= (GArray
*) g_ptr_array_index (dview
->hdiff
, i
);
1909 g_array_free (h
, TRUE
);
1911 g_ptr_array_free (dview
->hdiff
, TRUE
);
1912 dview
->hdiff
= NULL
;
1915 mc_search_free (dview
->search
.handle
);
1916 dview
->search
.handle
= NULL
;
1917 g_free (dview
->search
.last_string
);
1918 dview
->search
.last_string
= NULL
;
1921 /* --------------------------------------------------------------------------------------------- */
1922 /* stuff ******************************************************************** */
1925 get_digits (unsigned int n
)
1935 /* --------------------------------------------------------------------------------------------- */
1938 get_line_numbers (const GArray
* a
, size_t pos
, int *linenum
, int *lineofs
)
1952 p
= &g_array_index (a
, DIFFLN
, pos
);
1957 for (n
= pos
; n
> 0; n
--)
1965 *lineofs
= pos
- n
+ 1;
1973 /* --------------------------------------------------------------------------------------------- */
1976 calc_nwidth (const GArray
** const a
)
1980 get_line_numbers (a
[0], a
[0]->len
- 1, &l1
, &o1
);
1981 get_line_numbers (a
[1], a
[1]->len
- 1, &l2
, &o2
);
1986 return get_digits (l1
);
1989 /* --------------------------------------------------------------------------------------------- */
1992 find_prev_hunk (const GArray
* a
, int pos
)
1995 while (pos
> 0 && ((DIFFLN
*) & g_array_index (a
, DIFFLN
, pos
))->ch
!= EQU_CH
)
1999 while (pos
> 0 && ((DIFFLN
*) & g_array_index (a
, DIFFLN
, pos
))->ch
== EQU_CH
)
2003 while (pos
> 0 && ((DIFFLN
*) & g_array_index (a
, DIFFLN
, pos
))->ch
!= EQU_CH
)
2007 if (pos
> 0 && (size_t) pos
< a
->len
)
2010 while (pos
> 0 && ((DIFFLN
*) & g_array_index (a
, DIFFLN
, pos
- 1))->ch
== EQU_CH
)
2014 while (pos
> 0 && ((DIFFLN
*) & g_array_index (a
, DIFFLN
, pos
- 1))->ch
!= EQU_CH
)
2023 /* --------------------------------------------------------------------------------------------- */
2026 find_next_hunk (const GArray
* a
, size_t pos
)
2028 while (pos
< a
->len
&& ((DIFFLN
*) & g_array_index (a
, DIFFLN
, pos
))->ch
!= EQU_CH
)
2032 while (pos
< a
->len
&& ((DIFFLN
*) & g_array_index (a
, DIFFLN
, pos
))->ch
== EQU_CH
)
2040 * Find start and end lines of the current hunk.
2042 * \param dview - widget WDiff
2043 * \return boolean and
2044 * start_line1 first line of current hunk (file[0])
2045 * end_line1 last line of current hunk (file[0])
2046 * start_line1 first line of current hunk (file[0])
2047 * end_line1 last line of current hunk (file[0])
2050 get_current_hunk (WDiff
* dview
, int *start_line1
, int *end_line1
, int *start_line2
, int *end_line2
)
2052 const GArray
*a0
= dview
->a
[0];
2053 const GArray
*a1
= dview
->a
[1];
2063 pos
= dview
->skip_rows
;
2064 ch
= ((DIFFLN
*) & g_array_index (a0
, DIFFLN
, pos
))->ch
;
2079 while (pos
> 0 && ((DIFFLN
*) & g_array_index (a0
, DIFFLN
, pos
))->ch
!= EQU_CH
)
2085 *start_line1
= ((DIFFLN
*) & g_array_index (a0
, DIFFLN
, pos
))->line
+ 1;
2086 *start_line2
= ((DIFFLN
*) & g_array_index (a1
, DIFFLN
, pos
))->line
+ 1;
2088 pos
= dview
->skip_rows
;
2089 while (pos
< a0
->len
&& ((DIFFLN
*) & g_array_index (a0
, DIFFLN
, pos
))->ch
!= EQU_CH
)
2092 l0
= ((DIFFLN
*) & g_array_index (a0
, DIFFLN
, pos
))->line
;
2093 l1
= ((DIFFLN
*) & g_array_index (a1
, DIFFLN
, pos
))->line
;
2095 *end_line1
= max (*start_line1
, l0
);
2097 *end_line2
= max (*start_line2
, l1
);
2105 dview_remove_hunk (WDiff
* dview
, FILE * merge_file
, int from1
, int to1
)
2110 f0
= fopen (dview
->file
[0], "r");
2112 while (fgets (buf
, sizeof (buf
), f0
) != NULL
&& line
< from1
- 1)
2115 fputs (buf
, merge_file
);
2117 while (fgets (buf
, sizeof (buf
), f0
) != NULL
)
2121 fputs (buf
, merge_file
);
2127 dview_add_hunk (WDiff
* dview
, FILE * merge_file
, int from1
, int from2
, int to2
)
2133 f0
= fopen (dview
->file
[0], "r");
2134 f1
= fopen (dview
->file
[1], "r");
2136 while (fgets (buf
, sizeof (buf
), f0
) != NULL
&& line
< from1
- 1)
2139 fputs (buf
, merge_file
);
2142 while (fgets (buf
, sizeof (buf
), f1
) != NULL
&& line
<= to2
)
2146 fputs (buf
, merge_file
);
2148 while (fgets (buf
, sizeof (buf
), f0
) != NULL
)
2150 fputs (buf
, merge_file
);
2157 dview_replace_hunk (WDiff
* dview
, FILE * merge_file
, int from1
, int to1
, int from2
, int to2
)
2163 f0
= fopen (dview
->file
[0], "r");
2164 f1
= fopen (dview
->file
[1], "r");
2166 while (fgets (buf
, sizeof (buf
), f0
) != NULL
&& line1
< from1
- 1)
2169 fputs (buf
, merge_file
);
2172 while (fgets (buf
, sizeof (buf
), f1
) != NULL
&& line2
<= to2
)
2176 fputs (buf
, merge_file
);
2178 while (fgets (buf
, sizeof (buf
), f0
) != NULL
)
2182 fputs (buf
, merge_file
);
2189 do_merge_hunk (WDiff
* dview
)
2191 int from1
, to1
, from2
, to2
;
2195 hunk
= get_current_hunk (dview
, &from1
, &to1
, &from2
, &to2
);
2200 char *merge_file_name
= NULL
;
2204 dview
->merged
= mc_util_make_backup_if_possible (dview
->file
[0], "~~~");
2207 message (D_ERROR
, MSG_ERROR
,
2208 _("Cannot create backup file\n%s%s\n%s"),
2209 dview
->file
[0], "~~~", unix_error_string (errno
));
2215 merge_file_fd
= mc_mkstemps (&merge_file_name
, "mcmerge", NULL
);
2216 if (merge_file_fd
== -1)
2218 message (D_ERROR
, MSG_ERROR
, _("Cannot create temporary merge file\n%s"),
2219 unix_error_string (errno
));
2223 merge_file
= fdopen (merge_file_fd
, "w");
2228 dview_remove_hunk (dview
, merge_file
, from1
, to1
);
2231 dview_add_hunk (dview
, merge_file
, from1
, from2
, to2
);
2234 dview_replace_hunk (dview
, merge_file
, from1
, to1
, from2
, to2
);
2237 fflush (merge_file
);
2238 fclose (merge_file
);
2239 res
= rewrite_backup_content (merge_file_name
, dview
->file
[0]);
2240 unlink (merge_file_name
);
2241 g_free (merge_file_name
);
2245 /* --------------------------------------------------------------------------------------------- */
2246 /* view routines and callbacks ********************************************** */
2249 dview_compute_split (WDiff
* dview
, int i
)
2252 if (dview
->bias
< 2 - dview
->half1
)
2254 dview
->bias
= 2 - dview
->half1
;
2256 if (dview
->bias
> dview
->half2
- 2)
2258 dview
->bias
= dview
->half2
- 2;
2262 /* --------------------------------------------------------------------------------------------- */
2265 dview_compute_areas (WDiff
* dview
)
2267 dview
->height
= LINES
- 2;
2268 dview
->half1
= COLS
/ 2;
2269 dview
->half2
= COLS
- dview
->half1
;
2271 dview_compute_split (dview
, 0);
2274 /* --------------------------------------------------------------------------------------------- */
2277 dview_init (WDiff
* dview
, const char *args
, const char *file1
, const char *file2
,
2278 const char *label1
, const char *label2
, DSRC dsrc
)
2286 if (dsrc
== DATA_SRC_TMP
)
2299 else if (dsrc
== DATA_SRC_ORG
)
2301 f
[0] = f_open (file1
, O_RDONLY
);
2305 f
[1] = f_open (file2
, O_RDONLY
);
2314 dview
->file
[0] = file1
;
2315 dview
->file
[1] = file2
;
2316 dview
->label
[0] = g_strdup (label1
);
2317 dview
->label
[1] = g_strdup (label2
);
2320 dview
->hdiff
= NULL
;
2322 dview
->converter
= str_cnv_from_term
;
2323 dview_set_codeset (dview
);
2325 dview
->a
[0] = g_array_new (FALSE
, FALSE
, sizeof (DIFFLN
));
2326 dview
->a
[1] = g_array_new (FALSE
, FALSE
, sizeof (DIFFLN
));
2328 ndiff
= redo_diff (dview
);
2331 /* goto WIDGET_DESTROY stage: dview_fini() */
2335 dview
->ndiff
= ndiff
;
2337 dview
->view_quit
= 0;
2340 dview
->new_frame
= 1;
2341 dview
->skip_rows
= 0;
2342 dview
->skip_cols
= 0;
2343 dview
->display_symbols
= 0;
2344 dview
->display_numbers
= 0;
2346 dview
->tab_size
= 8;
2350 dview
->search
.handle
= NULL
;
2351 dview
->search
.last_string
= NULL
;
2352 dview
->search
.last_found_line
= -1;
2353 dview
->search
.last_accessed_num_line
= -1;
2355 dview
->opt
.quality
= 0;
2356 dview
->opt
.strip_trailing_cr
= 0;
2357 dview
->opt
.ignore_tab_expansion
= 0;
2358 dview
->opt
.ignore_space_change
= 0;
2359 dview
->opt
.ignore_all_space
= 0;
2360 dview
->opt
.ignore_case
= 0;
2362 dview_compute_areas (dview
);
2367 /* --------------------------------------------------------------------------------------------- */
2370 dview_reread (WDiff
* dview
)
2372 int ndiff
= dview
->ndiff
;
2374 destroy_hdiff (dview
);
2375 if (dview
->a
[0] != NULL
)
2377 g_array_foreach (dview
->a
[0], DIFFLN
, cc_free_elt
);
2378 g_array_free (dview
->a
[0], TRUE
);
2380 if (dview
->a
[1] != NULL
)
2382 g_array_foreach (dview
->a
[1], DIFFLN
, cc_free_elt
);
2383 g_array_free (dview
->a
[1], TRUE
);
2386 dview
->a
[0] = g_array_new (FALSE
, FALSE
, sizeof (DIFFLN
));
2387 dview
->a
[1] = g_array_new (FALSE
, FALSE
, sizeof (DIFFLN
));
2389 ndiff
= redo_diff (dview
);
2391 dview
->ndiff
= ndiff
;
2394 /* --------------------------------------------------------------------------------------------- */
2396 dview_diff_options (WDiff
* dview
)
2398 const char *quality_str
[] = {
2400 N_("&Fastest (Assume large files)"),
2401 N_("&Minimal (Find a smaller set of change)")
2404 QuickWidget diffopt_widgets
[] = {
2405 QUICK_BUTTON (6, 10, 14, OPTY
, N_("&Cancel"), B_CANCEL
, NULL
),
2406 QUICK_BUTTON (2, 10, 14, OPTY
, N_("&OK"), B_ENTER
, NULL
),
2408 QUICK_CHECKBOX (3, OPTX
, 12, OPTY
,
2409 N_("Strip &trailing carriage return"), &dview
->opt
.strip_trailing_cr
),
2410 QUICK_CHECKBOX (3, OPTX
, 11, OPTY
,
2411 N_("Ignore all &whitespace"), &dview
->opt
.ignore_all_space
),
2412 QUICK_CHECKBOX (3, OPTX
, 10, OPTY
,
2413 N_("Ignore &space change"), &dview
->opt
.ignore_space_change
),
2414 QUICK_CHECKBOX (3, OPTX
, 9, OPTY
,
2415 N_("Ignore tab &expansion"), &dview
->opt
.ignore_tab_expansion
),
2416 QUICK_CHECKBOX (3, OPTX
, 8, OPTY
,
2417 N_("&Ignore case"), &dview
->opt
.ignore_case
),
2418 QUICK_LABEL (3, OPTX
, 7, OPTY
, N_("Diff extra options")),
2419 QUICK_RADIO (3, OPTX
, 3, OPTY
,
2420 3, (const char **) quality_str
, (int *) &dview
->opt
.quality
),
2421 QUICK_LABEL (3, OPTX
, 2, OPTY
, N_("Diff algorithm")),
2426 QuickDialog diffopt
= {
2428 N_("Diff Options"), "[Diff Options]",
2429 diffopt_widgets
, NULL
, FALSE
2432 if (quick_dialog (&diffopt
) != B_CANCEL
)
2434 dview_reread (dview
);
2438 /* --------------------------------------------------------------------------------------------- */
2441 dview_fini (WDiff
* dview
)
2443 if (dview
->dsrc
!= DATA_SRC_MEM
)
2445 f_close (dview
->f
[1]);
2446 f_close (dview
->f
[0]);
2449 if (dview
->converter
!= str_cnv_from_term
)
2450 str_close_conv (dview
->converter
);
2452 destroy_hdiff (dview
);
2453 if (dview
->a
[0] != NULL
)
2455 g_array_foreach (dview
->a
[0], DIFFLN
, cc_free_elt
);
2456 g_array_free (dview
->a
[0], TRUE
);
2459 if (dview
->a
[1] != NULL
)
2461 g_array_foreach (dview
->a
[1], DIFFLN
, cc_free_elt
);
2462 g_array_free (dview
->a
[1], TRUE
);
2466 g_free (dview
->label
[0]);
2467 g_free (dview
->label
[1]);
2471 /* --------------------------------------------------------------------------------------------- */
2474 dview_display_file (const WDiff
* dview
, int ord
, int r
, int c
, int height
, int width
)
2479 FBUF
*f
= dview
->f
[ord
];
2480 int skip
= dview
->skip_cols
;
2481 int display_symbols
= dview
->display_symbols
;
2482 int display_numbers
= dview
->display_numbers
;
2483 int show_cr
= dview
->show_cr
;
2486 int nwidth
= display_numbers
;
2487 int xwidth
= display_symbols
+ display_numbers
;
2488 if (dview
->tab_size
> 0 && dview
->tab_size
< 9)
2489 tab_size
= dview
->tab_size
;
2493 if (xwidth
> width
&& display_symbols
)
2496 display_symbols
= 0;
2498 if (xwidth
> width
&& display_numbers
)
2501 display_numbers
= width
;
2515 if ((int) sizeof (buf
) <= width
|| (int) sizeof (buf
) <= nwidth
)
2517 /* abnormal, but avoid buffer overflow */
2521 for (i
= dview
->skip_rows
, j
= 0; i
< dview
->a
[ord
]->len
&& j
< height
; j
++, i
++)
2523 int ch
, next_ch
, col
;
2525 p
= (DIFFLN
*) & g_array_index (dview
->a
[ord
], DIFFLN
, i
);
2527 tty_setcolor (NORMAL_COLOR
);
2528 if (display_symbols
)
2530 tty_gotoyx (r
+ j
, c
- 2);
2531 tty_print_char (ch
);
2535 if (display_numbers
)
2537 tty_gotoyx (r
+ j
, c
- xwidth
);
2538 g_snprintf (buf
, display_numbers
+ 1, "%*d", nwidth
, p
->line
);
2539 tty_print_string (str_fit_to_term (buf
, nwidth
, J_LEFT_FIT
));
2543 tty_setcolor (DFF_ADD_COLOR
);
2547 tty_setcolor (DFF_CHG_COLOR
);
2551 if (i
== (size_t) dview
->search
.last_found_line
)
2553 tty_setcolor (MARKED_SELECTED_COLOR
);
2557 if (dview
->hdiff
!= NULL
&& g_ptr_array_index (dview
->hdiff
, i
) != NULL
)
2561 k
= dview_str_utf8_offset_to_pos (p
->p
, width
);
2564 cvt_mgeta (p
->p
, p
->u
.len
, buf
, k
, skip
, tab_size
, show_cr
,
2565 g_ptr_array_index (dview
->hdiff
, i
), ord
, att
);
2566 tty_gotoyx (r
+ j
, c
);
2568 for (cnt
= 0; cnt
< strlen (buf
) && col
< width
; cnt
++)
2574 next_ch
= dview_get_utf (buf
+ cnt
, &w
, &ch_res
);
2577 if (!g_unichar_isprint (next_ch
))
2581 next_ch
= dview_get_byte (buf
+ cnt
, &ch_res
);
2584 tty_setcolor (att
[cnt
] ? DFF_CHH_COLOR
: DFF_CHG_COLOR
);
2586 if (mc_global
.utf8_display
)
2591 convert_from_8bit_to_utf_c ((unsigned char) next_ch
,
2595 else if (dview
->utf8
)
2597 convert_from_utf_to_current_c (next_ch
, dview
->converter
);
2600 next_ch
= convert_to_display_c (next_ch
);
2602 tty_print_anychar (next_ch
);
2608 else if (ch
== CHG_CH
)
2610 tty_setcolor (DFF_CHH_COLOR
);
2614 k
= dview_str_utf8_offset_to_pos (p
->p
, width
);
2617 cvt_mget (p
->p
, p
->u
.len
, buf
, k
, skip
, tab_size
, show_cr
);
2621 cvt_fget (f
, p
->u
.off
, buf
, width
, skip
, tab_size
, show_cr
);
2626 if (display_numbers
)
2628 tty_gotoyx (r
+ j
, c
- xwidth
);
2629 memset (buf
, ' ', display_numbers
);
2630 buf
[display_numbers
] = '\0';
2631 tty_print_string (buf
);
2635 tty_setcolor (DFF_DEL_COLOR
);
2639 tty_setcolor (DFF_CHD_COLOR
);
2641 memset (buf
, ' ', width
);
2644 tty_gotoyx (r
+ j
, c
);
2645 /* tty_print_nstring (buf, width); */
2647 for (cnt
= 0; cnt
< strlen (buf
) && col
< width
; cnt
++)
2653 next_ch
= dview_get_utf (buf
+ cnt
, &w
, &ch_res
);
2656 if (!g_unichar_isprint (next_ch
))
2660 next_ch
= dview_get_byte (buf
+ cnt
, &ch_res
);
2664 if (mc_global
.utf8_display
)
2669 convert_from_8bit_to_utf_c ((unsigned char) next_ch
, dview
->converter
);
2672 else if (dview
->utf8
)
2673 next_ch
= convert_from_utf_to_current_c (next_ch
, dview
->converter
);
2676 next_ch
= convert_to_display_c (next_ch
);
2678 tty_print_anychar (next_ch
);
2684 tty_setcolor (NORMAL_COLOR
);
2686 if (width
< xwidth
- 1)
2690 memset (buf
, ' ', k
);
2692 for (; j
< height
; j
++)
2696 tty_gotoyx (r
+ j
, c
- xwidth
);
2697 /* tty_print_nstring (buf, xwidth - 1); */
2698 tty_print_string (str_fit_to_term (buf
, xwidth
- 1, J_LEFT_FIT
));
2700 tty_gotoyx (r
+ j
, c
);
2701 /* tty_print_nstring (buf, width); */
2702 tty_print_string (str_fit_to_term (buf
, width
, J_LEFT_FIT
));
2708 /* --------------------------------------------------------------------------------------------- */
2711 dview_status (const WDiff
* dview
, int ord
, int width
, int c
)
2715 int linenum
, lineofs
;
2717 tty_setcolor (STATUSBAR_COLOR
);
2720 get_line_numbers (dview
->a
[ord
], dview
->skip_rows
, &linenum
, &lineofs
);
2722 filename_width
= width
- 22;
2723 if (filename_width
< 8)
2726 buf
= str_term_trim (strip_home_and_password (dview
->label
[ord
]), filename_width
);
2728 tty_printf ("%-*s %6d+%-4d Col %-4d ", filename_width
, buf
, linenum
, lineofs
,
2731 tty_printf ("%-*s %6d+%-4d Dif %-4d ", filename_width
, buf
, linenum
, lineofs
, dview
->ndiff
);
2734 /* --------------------------------------------------------------------------------------------- */
2737 dview_redo (WDiff
* dview
)
2739 if (dview
->display_numbers
)
2741 int old
= dview
->display_numbers
;
2742 dview
->display_numbers
= calc_nwidth ((const GArray
**) dview
->a
);
2743 dview
->new_frame
= (old
!= dview
->display_numbers
);
2745 dview_reread (dview
);
2748 /* --------------------------------------------------------------------------------------------- */
2751 dview_edit (WDiff
* dview
, int ord
)
2755 int linenum
, lineofs
;
2757 if (dview
->dsrc
== DATA_SRC_TMP
)
2759 error_dialog (_("Edit"), _("Edit is disabled"));
2763 h
= ((Widget
*) dview
)->owner
;
2766 get_line_numbers (dview
->a
[ord
], dview
->skip_rows
, &linenum
, &lineofs
);
2767 h
->modal
= TRUE
; /* not allow edit file in several editors */
2768 do_edit_at_line (dview
->file
[ord
], use_internal_edit
, linenum
);
2771 dview_update (dview
);
2774 /* --------------------------------------------------------------------------------------------- */
2777 dview_goto_cmd (WDiff
* dview
, int ord
)
2779 static const char *title
[2] = { N_("Goto line (left)"), N_("Goto line (right)") };
2780 static char prev
[256];
2781 /* XXX some statics here, to be remembered between runs */
2786 input
= input_dialog (_(title
[ord
]), _("Enter line:"), MC_HISTORY_YDIFF_GOTO_LINE
, prev
);
2789 const char *s
= input
;
2790 if (scan_deci (&s
, &newline
) == 0 && *s
== '\0')
2796 for (; i
< dview
->a
[ord
]->len
; i
++)
2798 p
= &g_array_index (dview
->a
[ord
], DIFFLN
, i
);
2799 if (p
->line
== newline
)
2805 dview
->skip_rows
= dview
->search
.last_accessed_num_line
= (ssize_t
) i
;
2806 g_snprintf (prev
, sizeof (prev
), "%d", newline
);
2812 /* --------------------------------------------------------------------------------------------- */
2815 dview_labels (WDiff
* dview
)
2817 Dlg_head
*h
= dview
->widget
.owner
;
2818 WButtonBar
*b
= find_buttonbar (h
);
2820 buttonbar_set_label (b
, 1, Q_ ("ButtonBar|Help"), diff_map
, (Widget
*) dview
);
2821 buttonbar_set_label (b
, 2, Q_ ("ButtonBar|Save"), diff_map
, (Widget
*) dview
);
2822 buttonbar_set_label (b
, 4, Q_ ("ButtonBar|Edit"), diff_map
, (Widget
*) dview
);
2823 buttonbar_set_label (b
, 5, Q_ ("ButtonBar|Merge"), diff_map
, (Widget
*) dview
);
2824 buttonbar_set_label (b
, 7, Q_ ("ButtonBar|Search"), diff_map
, (Widget
*) dview
);
2825 buttonbar_set_label (b
, 9, Q_ ("ButtonBar|Options"), diff_map
, (Widget
*) dview
);
2826 buttonbar_set_label (b
, 10, Q_ ("ButtonBar|Quit"), diff_map
, (Widget
*) dview
);
2830 /* --------------------------------------------------------------------------------------------- */
2833 dview_event (Gpm_Event
* event
, void *x
)
2835 WDiff
*dview
= (WDiff
*) x
;
2836 int result
= MOU_NORMAL
;
2838 /* We are not interested in the release events */
2839 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
)) == 0)
2845 if ((event
->buttons
& GPM_B_UP
) != 0 && (event
->type
& GPM_DOWN
) != 0)
2847 dview
->skip_rows
-= 2;
2848 dview
->search
.last_accessed_num_line
= dview
->skip_rows
;
2849 dview_update (dview
);
2851 else if ((event
->buttons
& GPM_B_DOWN
) != 0 && (event
->type
& GPM_DOWN
) != 0)
2853 dview
->skip_rows
+= 2;
2854 dview
->search
.last_accessed_num_line
= dview
->skip_rows
;
2855 dview_update (dview
);
2862 dview_save (WDiff
* dview
)
2864 gboolean res
= TRUE
;
2867 res
= mc_util_unlink_backup_if_possible (dview
->file
[0], "~~~");
2868 dview
->merged
= !res
;
2873 dview_do_save (WDiff
* dview
)
2875 (void) dview_save (dview
);
2879 dview_save_options (WDiff
* dview
)
2881 mc_config_set_bool (mc_main_config
, "DiffView", "show_symbols",
2882 dview
->display_symbols
!= 0 ? TRUE
: FALSE
);
2883 mc_config_set_bool (mc_main_config
, "DiffView", "show_numbers",
2884 dview
->display_numbers
!= 0 ? TRUE
: FALSE
);
2885 mc_config_set_int (mc_main_config
, "DiffView", "tab_size", dview
->tab_size
);
2887 mc_config_set_int (mc_main_config
, "DiffView", "diff_quality", dview
->opt
.quality
);
2889 mc_config_set_bool (mc_main_config
, "DiffView", "diff_ignore_tws",
2890 dview
->opt
.strip_trailing_cr
);
2891 mc_config_set_bool (mc_main_config
, "DiffView", "diff_ignore_all_space",
2892 dview
->opt
.ignore_all_space
);
2893 mc_config_set_bool (mc_main_config
, "DiffView", "diff_ignore_space_change",
2894 dview
->opt
.ignore_space_change
);
2895 mc_config_set_bool (mc_main_config
, "DiffView", "diff_tab_expansion",
2896 dview
->opt
.ignore_tab_expansion
);
2897 mc_config_set_bool (mc_main_config
, "DiffView", "diff_ignore_case", dview
->opt
.ignore_case
);
2901 dview_load_options (WDiff
* dview
)
2903 gboolean show_numbers
, show_symbols
;
2906 show_symbols
= mc_config_get_bool (mc_main_config
, "DiffView", "show_symbols", FALSE
);
2908 dview
->display_symbols
= 1;
2909 show_numbers
= mc_config_get_bool (mc_main_config
, "DiffView", "show_numbers", FALSE
);
2911 dview
->display_numbers
= calc_nwidth ((const GArray
** const) dview
->a
);
2912 tab_size
= mc_config_get_int (mc_main_config
, "DiffView", "tab_size", 8);
2913 if (tab_size
> 0 && tab_size
< 9)
2914 dview
->tab_size
= tab_size
;
2916 dview
->tab_size
= 8;
2918 dview
->opt
.quality
= mc_config_get_int (mc_main_config
, "DiffView", "diff_quality", 0);
2920 dview
->opt
.strip_trailing_cr
=
2921 mc_config_get_bool (mc_main_config
, "DiffView", "diff_ignore_tws", FALSE
);
2922 dview
->opt
.ignore_all_space
=
2923 mc_config_get_bool (mc_main_config
, "DiffView", "diff_ignore_all_space", FALSE
);
2924 dview
->opt
.ignore_space_change
=
2925 mc_config_get_bool (mc_main_config
, "DiffView", "diff_ignore_space_change", FALSE
);
2926 dview
->opt
.ignore_tab_expansion
=
2927 mc_config_get_bool (mc_main_config
, "DiffView", "diff_tab_expansion", FALSE
);
2928 dview
->opt
.ignore_case
=
2929 mc_config_get_bool (mc_main_config
, "DiffView", "diff_ignore_case", FALSE
);
2931 dview
->new_frame
= 1;
2935 * Check if it's OK to close the diff viewer. If there are unsaved changes,
2939 dview_ok_to_exit (WDiff
* dview
)
2941 gboolean res
= TRUE
;
2947 act
= query_dialog (_("Quit"), !mc_global
.widget
.midnight_shutdown
?
2948 _("File was modified. Save with exit?") :
2949 _("Midnight Commander is being shut down.\nSave modified file?"),
2950 D_NORMAL
, 2, _("&Yes"), _("&No"));
2953 if (mc_global
.widget
.midnight_shutdown
|| (act
== -1))
2962 (void) dview_save (dview
);
2966 if (mc_util_restore_from_backup_if_possible (dview
->file
[0], "~~~"))
2967 res
= mc_util_unlink_backup_if_possible (dview
->file
[0], "~~~");
2976 /* --------------------------------------------------------------------------------------------- */
2979 dview_execute_cmd (WDiff
* dview
, unsigned long command
)
2981 cb_ret_t res
= MSG_HANDLED
;
2984 case CK_ShowSymbols
:
2985 dview
->display_symbols
^= 1;
2986 dview
->new_frame
= 1;
2988 case CK_ShowNumbers
:
2989 dview
->display_numbers
^= calc_nwidth ((const GArray
** const) dview
->a
);
2990 dview
->new_frame
= 1;
2994 dview
->new_frame
= 1;
3000 dview
->new_frame
= 1;
3006 dview_compute_split (dview
, 1);
3007 dview
->new_frame
= 1;
3014 dview_compute_split (dview
, -1);
3015 dview
->new_frame
= 1;
3019 dview
->tab_size
= 2;
3022 dview
->tab_size
= 3;
3025 dview
->tab_size
= 4;
3028 dview
->tab_size
= 8;
3037 dview
->skip_rows
= dview
->search
.last_accessed_num_line
=
3038 find_next_hunk (dview
->a
[0], dview
->skip_rows
);
3041 dview
->skip_rows
= dview
->search
.last_accessed_num_line
=
3042 find_prev_hunk (dview
->a
[0], dview
->skip_rows
);
3045 dview_goto_cmd (dview
, TRUE
);
3048 dview_edit (dview
, dview
->ord
);
3051 do_merge_hunk (dview
);
3055 dview_edit (dview
, dview
->ord
^ 1);
3058 dview_search_cmd (dview
);
3060 case CK_SearchContinue
:
3061 dview_continue_search_cmd (dview
);
3064 dview
->skip_rows
= dview
->search
.last_accessed_num_line
= 0;
3067 dview
->skip_rows
= dview
->search
.last_accessed_num_line
= dview
->a
[0]->len
- 1;
3070 if (dview
->skip_rows
> 0)
3073 dview
->search
.last_accessed_num_line
= dview
->skip_rows
;
3078 dview
->search
.last_accessed_num_line
= dview
->skip_rows
;
3081 if (dview
->height
> 2)
3083 dview
->skip_rows
+= dview
->height
- 2;
3084 dview
->search
.last_accessed_num_line
= dview
->skip_rows
;
3088 if (dview
->height
> 2)
3090 dview
->skip_rows
-= dview
->height
- 2;
3091 dview
->search
.last_accessed_num_line
= dview
->skip_rows
;
3101 dview
->skip_cols
-= 8;
3104 dview
->skip_cols
+= 8;
3107 dview
->skip_cols
= 0;
3113 dview
->view_quit
= 1;
3116 dview_do_save (dview
);
3119 dview_diff_options (dview
);
3122 case CK_SelectCodepage
:
3123 dview_select_encoding (dview
);
3124 dview_reread (dview
);
3125 tty_touch_screen ();
3130 /* don't close diffviewer due to SIGINT */
3133 res
= MSG_NOT_HANDLED
;
3138 /* --------------------------------------------------------------------------------------------- */
3141 dview_handle_key (WDiff
* dview
, int key
)
3143 unsigned long command
;
3145 key
= convert_from_input_c (key
);
3147 command
= keybind_lookup_keymap_command (diff_map
, key
);
3148 if ((command
!= CK_IgnoreKey
) && (dview_execute_cmd (dview
, command
) == MSG_HANDLED
))
3152 return MSG_NOT_HANDLED
;
3155 /* --------------------------------------------------------------------------------------------- */
3158 dview_callback (Widget
* w
, widget_msg_t msg
, int parm
)
3160 WDiff
*dview
= (WDiff
*) w
;
3161 Dlg_head
*h
= dview
->widget
.owner
;
3167 dview_labels (dview
);
3168 dview_load_options (dview
);
3169 dview_update (dview
);
3173 dview
->new_frame
= 1;
3174 dview_update (dview
);
3178 i
= dview_handle_key (dview
, parm
);
3179 if (dview
->view_quit
)
3182 dview_update (dview
);
3185 case WIDGET_COMMAND
:
3186 i
= dview_execute_cmd (dview
, parm
);
3187 if (dview
->view_quit
)
3190 dview_update (dview
);
3193 case WIDGET_DESTROY
:
3194 dview_save_options (dview
);
3199 return default_proc (msg
, parm
);
3203 /* --------------------------------------------------------------------------------------------- */
3206 dview_adjust_size (Dlg_head
* h
)
3211 /* Look up the viewer and the buttonbar, we assume only two widgets here */
3212 dview
= (WDiff
*) find_widget_type (h
, dview_callback
);
3213 bar
= find_buttonbar (h
);
3214 widget_set_size (&dview
->widget
, 0, 0, LINES
- 1, COLS
);
3215 widget_set_size ((Widget
*) bar
, LINES
- 1, 0, 1, COLS
);
3217 dview_compute_areas (dview
);
3220 /* --------------------------------------------------------------------------------------------- */
3223 dview_dialog_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
3225 WDiff
*dview
= (WDiff
*) data
;
3230 dview_adjust_size (h
);
3236 return dview_execute_cmd (NULL
, parm
);
3237 /* message from buttonbar */
3238 if (sender
== (Widget
*) find_buttonbar (h
))
3241 return send_message ((Widget
*) data
, WIDGET_COMMAND
, parm
);
3243 dview
= (WDiff
*) find_widget_type (h
, dview_callback
);
3244 return dview_execute_cmd (dview
, parm
);
3246 return MSG_NOT_HANDLED
;
3249 dview
= (WDiff
*) find_widget_type (h
, dview_callback
);
3250 h
->state
= DLG_ACTIVE
; /* don't stop the dialog before final decision */
3251 if (dview_ok_to_exit (dview
))
3252 h
->state
= DLG_CLOSED
;
3256 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
3260 /* --------------------------------------------------------------------------------------------- */
3263 dview_get_title (const Dlg_head
* h
, size_t len
)
3265 const WDiff
*dview
= (const WDiff
*) find_widget_type (h
, dview_callback
);
3266 const char *modified
= dview
->merged
? " (*) " : " ";
3270 len1
= (len
- str_term_width1 (_("Diff:")) - strlen (modified
) - 3) / 2;
3272 title
= g_string_sized_new (len
);
3273 g_string_append (title
, _("Diff:"));
3274 g_string_append (title
, modified
);
3275 g_string_append (title
, str_term_trim (dview
->label
[0], len1
));
3276 g_string_append (title
, " | ");
3277 g_string_append (title
, str_term_trim (dview
->label
[1], len1
));
3279 return g_string_free (title
, FALSE
);
3282 /*** public functions ****************************************************************************/
3283 /* --------------------------------------------------------------------------------------------- */
3286 diff_view (const char *file1
, const char *file2
, const char *label1
, const char *label2
)
3290 Dlg_head
*dview_dlg
;
3292 /* Create dialog and widgets, put them on the dialog */
3294 create_dlg (FALSE
, 0, 0, LINES
, COLS
, NULL
, dview_dialog_callback
,
3295 "[Diff Viewer]", NULL
, DLG_WANT_TAB
);
3297 dview
= g_new0 (WDiff
, 1);
3299 init_widget (&dview
->widget
, 0, 0, LINES
- 1, COLS
,
3300 (callback_fn
) dview_callback
, (mouse_h
) dview_event
);
3302 widget_want_cursor (dview
->widget
, 0);
3304 add_widget (dview_dlg
, dview
);
3305 add_widget (dview_dlg
, buttonbar_new (TRUE
));
3307 dview_dlg
->get_title
= dview_get_title
;
3309 error
= dview_init (dview
, "-a", file1
, file2
, label1
, label2
, DATA_SRC_MEM
); /* XXX binary diff? */
3311 /* Please note that if you add another widget,
3312 * you have to modify dview_adjust_size to
3316 run_dlg (dview_dlg
);
3318 if ((error
!= 0) || (dview_dlg
->state
== DLG_CLOSED
))
3319 destroy_dlg (dview_dlg
);
3324 /* --------------------------------------------------------------------------------------------- */
3326 #define GET_FILE_AND_STAMP(n) \
3329 vfs_path_t *vpath = vfs_path_from_str(file##n); \
3331 real_file##n = file##n; \
3332 if (!vfs_file_is_local (vpath)) \
3334 real_file##n = mc_getlocalcopy (file##n); \
3335 if (real_file##n != NULL) \
3338 if (mc_stat (real_file##n, &st##n) != 0) \
3342 vfs_path_free(vpath); \
3346 #define UNGET_FILE(n) \
3352 if (use_copy##n > 0) \
3355 mtime = st##n.st_mtime; \
3356 if (mc_stat (real_file##n, &st##n) == 0) \
3357 changed = (mtime != st##n.st_mtime); \
3359 mc_ungetlocalcopy (file##n, real_file##n, changed); \
3360 g_free (real_file##n); \
3366 dview_diff_cmd (void)
3374 if (mc_global
.mc_run_mode
== MC_RUN_FULL
)
3376 const WPanel
*panel0
= current_panel
;
3377 const WPanel
*panel1
= other_panel
;
3378 if (get_current_index ())
3380 panel0
= other_panel
;
3381 panel1
= current_panel
;
3383 file0
= concat_dir_and_file (panel0
->cwd
, selection (panel0
)->fname
);
3384 file1
= concat_dir_and_file (panel1
->cwd
, selection (panel1
)->fname
);
3385 is_dir0
= S_ISDIR (selection (panel0
)->st
.st_mode
);
3386 is_dir1
= S_ISDIR (selection (panel1
)->st
.st_mode
);
3392 if (file0
!= NULL
&& !is_dir0
&& file1
!= NULL
&& !is_dir1
)
3400 GET_FILE_AND_STAMP (0);
3401 GET_FILE_AND_STAMP (1);
3402 if (real_file0
!= NULL
&& real_file1
!= NULL
)
3404 rv
= diff_view (real_file0
, real_file1
, file0
, file1
);
3415 message (1, MSG_ERROR
, _("Two files are needed to compare"));
3418 /* --------------------------------------------------------------------------------------------- */
3421 dview_update (WDiff
* dview
)
3423 int height
= dview
->height
;
3427 int last
= dview
->a
[0]->len
- 1;
3429 if (dview
->skip_rows
> last
)
3431 dview
->skip_rows
= dview
->search
.last_accessed_num_line
= last
;
3433 if (dview
->skip_rows
< 0)
3435 dview
->skip_rows
= dview
->search
.last_accessed_num_line
= 0;
3437 if (dview
->skip_cols
< 0)
3439 dview
->skip_cols
= 0;
3447 width1
= dview
->half1
+ dview
->bias
;
3448 width2
= dview
->half2
- dview
->bias
;
3455 if (dview
->new_frame
)
3457 int xwidth
= dview
->display_symbols
+ dview
->display_numbers
;
3459 tty_setcolor (NORMAL_COLOR
);
3462 tty_draw_box (1, 0, height
, width1
, FALSE
);
3466 tty_draw_box (1, width1
, height
, width2
, FALSE
);
3472 if (xwidth
< width1
- 1)
3474 tty_gotoyx (1, xwidth
);
3475 tty_print_alt_char (mc_tty_frm
[MC_TTY_FRM_DTOPMIDDLE
], FALSE
);
3476 tty_gotoyx (height
, xwidth
);
3477 tty_print_alt_char (mc_tty_frm
[MC_TTY_FRM_DBOTTOMMIDDLE
], FALSE
);
3478 tty_draw_vline (2, xwidth
, mc_tty_frm
[MC_TTY_FRM_VERT
], height
- 2);
3480 if (xwidth
< width2
- 1)
3482 tty_gotoyx (1, width1
+ xwidth
);
3483 tty_print_alt_char (mc_tty_frm
[MC_TTY_FRM_DTOPMIDDLE
], FALSE
);
3484 tty_gotoyx (height
, width1
+ xwidth
);
3485 tty_print_alt_char (mc_tty_frm
[MC_TTY_FRM_DBOTTOMMIDDLE
], FALSE
);
3486 tty_draw_vline (2, width1
+ xwidth
, mc_tty_frm
[MC_TTY_FRM_VERT
], height
- 2);
3489 dview
->new_frame
= 0;
3494 dview_status (dview
, dview
->ord
, width1
, 0);
3495 dview_display_file (dview
, dview
->ord
, 2, 1, height
- 2, width1
- 2);
3499 dview_status (dview
, dview
->ord
^ 1, width2
, width1
);
3500 dview_display_file (dview
, dview
->ord
^ 1, 2, width1
+ 1, height
- 2, width2
- 2);
3504 /* --------------------------------------------------------------------------------------------- */