2 Copyright (C) 2007, 2010, 2011
3 The Free Software Foundation, Inc.
6 Daniel Borca <dborca@yahoo.com>, 2007
7 Slava Zanko <slavazanko@gmail.com>, 2010
8 Andrew Borodin <aborodin@vmail.ru>, 2010
9 Ilia Maslakov <il.smind@gmail.com>, 2010
11 This file is part of the Midnight Commander.
13 The Midnight Commander is free software: you can redistribute it
14 and/or modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation, either version 3 of the License,
16 or (at your option) any later version.
18 The Midnight Commander is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
34 #include <sys/types.h>
37 #include "lib/global.h"
38 #include "lib/tty/tty.h"
39 #include "lib/tty/color.h"
40 #include "lib/tty/key.h"
41 #include "lib/skin.h" /* EDITOR_NORMAL_COLOR */
42 #include "lib/vfs/vfs.h" /* mc_opendir, mc_readdir, mc_closedir, */
44 #include "lib/widget.h"
45 #include "lib/charsets.h"
46 #include "lib/event.h" /* mc_event_raise() */
48 #include "src/filemanager/cmd.h"
49 #include "src/filemanager/midnight.h" /* Needed for current_panel and other_panel */
50 #include "src/filemanager/layout.h" /* Needed for get_current_index and get_other_panel */
52 #include "src/keybind-defaults.h"
53 #include "src/history.h"
54 #include "src/selcodepage.h"
59 /*** global variables ****************************************************************************/
61 /*** file scope macro definitions ****************************************************************/
63 #define g_array_foreach(a, TP, cbf) \
65 size_t g_array_foreach_i;\
66 TP *g_array_foreach_var=NULL; \
67 for (g_array_foreach_i=0;g_array_foreach_i < a->len; g_array_foreach_i++) \
69 g_array_foreach_var = &g_array_index(a,TP,g_array_foreach_i); \
70 (*cbf) (g_array_foreach_var); \
74 #define FILE_READ_BUF 4096
75 #define FILE_FLAG_TEMP (1 << 0)
85 #define HDIFF_ENABLE 1
86 #define HDIFF_MINCTX 5
87 #define HDIFF_DEPTH 10
89 #define FILE_DIRTY(fs) \
97 /*** file scope type declarations ****************************************************************/
99 /*** file scope variables ************************************************************************/
101 /*** file scope functions ************************************************************************/
102 /* --------------------------------------------------------------------------------------------- */
105 TAB_SKIP (int ts
, int pos
)
107 if (ts
> 0 && ts
< 9)
108 return ts
- pos
% ts
;
113 /* --------------------------------------------------------------------------------------------- */
116 dview_set_codeset (WDiff
* dview
)
119 const char *encoding_id
= NULL
;
123 get_codepage_id (mc_global
.source_codepage
>=
124 0 ? mc_global
.source_codepage
: mc_global
.display_codepage
);
125 if (encoding_id
!= NULL
)
128 conv
= str_crt_conv_from (encoding_id
);
129 if (conv
!= INVALID_CONV
)
131 if (dview
->converter
!= str_cnv_from_term
)
132 str_close_conv (dview
->converter
);
133 dview
->converter
= conv
;
135 dview
->utf8
= (gboolean
) str_isutf8 (encoding_id
);
142 /* --------------------------------------------------------------------------------------------- */
145 dview_select_encoding (WDiff
* dview
)
148 if (do_select_codepage ())
149 dview_set_codeset (dview
);
157 rewrite_backup_content (const char *from_file_name
, const char *to_file_name
)
163 if (!g_file_get_contents (from_file_name
, &contents
, &length
, NULL
))
166 backup_fd
= fopen (to_file_name
, "w");
167 if (backup_fd
== NULL
)
173 length
= fwrite ((const void *) contents
, length
, 1, backup_fd
);
181 /* buffered I/O ************************************************************* */
184 * Try to open a temporary file.
186 * \param[out] name address of a pointer to store the temporary name
188 * \return file descriptor on success, negative on error
190 * \note the name is not altered if this function fails
194 open_temp (void **name
)
197 char *diff_file_name
= NULL
;
199 fd
= mc_mkstemps (&diff_file_name
, "mcdiff", NULL
);
202 message (D_ERROR
, MSG_ERROR
,
203 _("Cannot create temporary diff file\n%s"), unix_error_string (errno
));
206 *name
= diff_file_name
;
210 /* --------------------------------------------------------------------------------------------- */
213 * Alocate file structure and associate file descriptor to it.
215 * \param fd file descriptor
217 * \return file structure
227 fs
= g_try_malloc (sizeof (FBUF
));
231 fs
->buf
= g_try_malloc (FILE_READ_BUF
);
246 /* --------------------------------------------------------------------------------------------- */
249 * Free file structure without closing the file.
251 * \param fs file structure
253 * \return 0 on success, non-zero on error
259 if (fs
->flags
& FILE_FLAG_TEMP
)
261 rv
= unlink (fs
->data
);
270 /* --------------------------------------------------------------------------------------------- */
273 * Open a binary temporary file in R/W mode.
275 * \return file structure
277 * \note the file will be deleted when closed
291 fd
= open_temp (&fs
->data
);
299 fs
->flags
= FILE_FLAG_TEMP
;
303 /* --------------------------------------------------------------------------------------------- */
306 * Open a binary file in specified mode.
308 * \param filename file name
309 * \param flags open mode, a combination of O_RDONLY, O_WRONLY, O_RDWR
311 * \return file structure
314 f_open (const char *filename
, int flags
)
325 fd
= open (filename
, flags
);
336 /* --------------------------------------------------------------------------------------------- */
339 * Read a line of bytes from file until newline or EOF.
341 * \param buf destination buffer
342 * \param size size of buffer
343 * \param fs file structure
345 * \return number of bytes read
347 * \note does not stop on null-byte
348 * \note buf will not be null-terminated
351 f_gets (char *buf
, size_t size
, FBUF
* fs
)
360 for (i
= fs
->pos
; j
< size
&& i
< fs
->len
&& !stop
; i
++, j
++)
370 if (j
== size
|| stop
)
376 fs
->len
= read (fs
->fd
, fs
->buf
, FILE_READ_BUF
);
383 /* --------------------------------------------------------------------------------------------- */
388 * \param fs file structure
390 * \param whence seek directive: SEEK_SET, SEEK_CUR or SEEK_END
392 * \return position in file, starting from begginning
394 * \note avoids thrashing read cache when possible
397 f_seek (FBUF
* fs
, off_t off
, int whence
)
401 if (fs
->len
&& whence
!= SEEK_END
)
403 rv
= lseek (fs
->fd
, 0, SEEK_CUR
);
406 if (whence
== SEEK_CUR
)
409 off
+= rv
- fs
->len
+ fs
->pos
;
411 if (off
- rv
>= -fs
->len
&& off
- rv
<= 0)
413 fs
->pos
= fs
->len
+ off
- rv
;
419 rv
= lseek (fs
->fd
, off
, whence
);
427 /* --------------------------------------------------------------------------------------------- */
430 * Seek to the beginning of file, thrashing read cache.
432 * \param fs file structure
434 * \return 0 if success, non-zero on error
439 off_t rv
= lseek (fs
->fd
, 0, SEEK_SET
);
447 /* --------------------------------------------------------------------------------------------- */
450 * Write bytes to file.
452 * \param fs file structure
453 * \param buf source buffer
454 * \param size size of buffer
456 * \return number of written bytes, -1 on error
458 * \note thrashes read cache
461 f_write (FBUF
* fs
, const char *buf
, size_t size
)
463 ssize_t rv
= write (fs
->fd
, buf
, size
);
471 /* --------------------------------------------------------------------------------------------- */
474 * Truncate file to the current position.
476 * \param fs file structure
478 * \return current file size on success, negative on error
480 * \note thrashes read cache
485 off_t off
= lseek (fs
->fd
, 0, SEEK_CUR
);
488 int rv
= ftruncate (fs
->fd
, off
);
501 /* --------------------------------------------------------------------------------------------- */
506 * \param fs file structure
508 * \return 0 on success, non-zero on error
510 * \note if this is temporary file, it is deleted
515 int rv
= close (fs
->fd
);
520 /* --------------------------------------------------------------------------------------------- */
523 * Create pipe stream to process.
525 * \param cmd shell command line
526 * \param flags open mode, either O_RDONLY or O_WRONLY
528 * \return file structure
531 p_open (const char *cmd
, int flags
)
535 const char *type
= NULL
;
537 if (flags
== O_RDONLY
)
541 if (flags
== O_WRONLY
)
557 f
= popen (cmd
, type
);
569 /* --------------------------------------------------------------------------------------------- */
574 * \param fs structure
576 * \return 0 on success, non-zero on error
581 int rv
= pclose (fs
->data
);
587 * Get one char (byte) from string
589 * \param char * str, gboolean * result
591 * \return int as character or 0 and result == FALSE if fail
595 dview_get_byte (char *str
, gboolean
* result
)
603 return (unsigned char) *str
;
608 * Get utf multibyte char from string
610 * \param char * str, int * char_width, gboolean * result
612 * \return int as utf character or 0 and result == FALSE if fail
616 dview_get_utf (char *str
, int *char_width
, gboolean
* result
)
620 gchar
*next_ch
= NULL
;
632 res
= g_utf8_get_char_validated (str
, -1);
642 /* Calculate UTF-8 char width */
643 next_ch
= g_utf8_next_char (str
);
646 width
= next_ch
- str
;
659 dview_str_utf8_offset_to_pos (const char *text
, size_t length
)
662 if (text
== NULL
|| text
[0] == '\0')
664 if (g_utf8_validate (text
, -1, NULL
))
666 result
= g_utf8_offset_to_pointer (text
, length
) - text
;
671 char *tmpbuf
, *buffer
;
672 buffer
= tmpbuf
= g_strdup (text
);
673 while (tmpbuf
[0] != '\0')
675 uni
= g_utf8_get_char_validated (tmpbuf
, -1);
676 if ((uni
!= (gunichar
) (-1)) && (uni
!= (gunichar
) (-2)))
678 tmpbuf
= g_utf8_next_char (tmpbuf
);
687 result
= g_utf8_offset_to_pointer (tmpbuf
, length
) - tmpbuf
;
690 return max (length
, (size_t) result
);
694 /* --------------------------------------------------------------------------------------------- */
695 /* diff parse *************************************************************** */
698 * Read decimal number from string.
700 * \param[in,out] str string to parse
701 * \param[out] n extracted number
703 * \return 0 if success, otherwise non-zero
706 scan_deci (const char **str
, int *n
)
708 const char *p
= *str
;
711 *n
= strtol (p
, &q
, 10);
720 /* --------------------------------------------------------------------------------------------- */
723 * Parse line for diff statement.
725 * \param p string to parse
726 * \param ops list of diff statements
728 * \return 0 if success, otherwise non-zero
731 scan_line (const char *p
, GArray
* ops
)
741 /* handle the following cases:
743 * NUM[,NUM]cNUM[,NUM]
745 * where NUM is a positive integer
748 if (scan_deci (&p
, &f1
) != 0 || f1
< 0)
757 if (scan_deci (&p
, &f2
) != 0 || f2
< f1
)
772 else if (cmd
!= 'c' && cmd
!= 'd')
777 if (scan_deci (&p
, &t1
) != 0 || t1
< 0)
786 if (scan_deci (&p
, &t2
) != 0 || t2
< t1
)
806 g_array_append_val (ops
, op
);
810 /* --------------------------------------------------------------------------------------------- */
813 * Parse diff output and extract diff statements.
815 * \param f stream to read from
816 * \param ops list of diff statements to fill
818 * \return positive number indicating number of hunks, otherwise negative
821 scan_diff (FBUF
* f
, GArray
* ops
)
826 while ((sz
= f_gets (buf
, sizeof (buf
) - 1, f
)))
828 if (isdigit (buf
[0]))
830 if (buf
[sz
- 1] != '\n')
835 if (scan_line (buf
, ops
) != 0)
841 while (buf
[sz
- 1] != '\n' && (sz
= f_gets (buf
, sizeof (buf
), f
)) != 0)
849 /* --------------------------------------------------------------------------------------------- */
852 * Invoke diff and extract diff statements.
854 * \param args extra arguments to be passed to diff
855 * \param extra more arguments to be passed to diff
856 * \param file1 first file to compare
857 * \param file2 second file to compare
858 * \param ops list of diff statements to fill
860 * \return positive number indicating number of hunks, otherwise negative
863 dff_execute (const char *args
, const char *extra
, const char *file1
, const char *file2
,
866 static const char *opt
=
867 " --old-group-format='%df%(f=l?:,%dl)d%dE\n'"
868 " --new-group-format='%dea%dF%(F=L?:,%dL)\n'"
869 " --changed-group-format='%df%(f=l?:,%dl)c%dF%(F=L?:,%dL)\n'"
870 " --unchanged-group-format=''";
877 cmd
= g_strdup_printf ("diff %s %s %s \"%s\" \"%s\"", args
, extra
, opt
, file1
, file2
);
881 f
= p_open (cmd
, O_RDONLY
);
887 rv
= scan_diff (f
, ops
);
890 if (rv
< 0 || code
== -1 || !WIFEXITED (code
) || WEXITSTATUS (code
) == 2)
896 /* --------------------------------------------------------------------------------------------- */
899 * Reparse and display file according to diff statements.
901 * \param ord 0 if displaying first file, 1 if displaying 2nd file
902 * \param filename file name to display
903 * \param ops list of diff statements
904 * \param printer printf-like function to be used for displaying
905 * \param ctx printer context
907 * \return 0 if success, otherwise non-zero
910 dff_reparse (int ord
, const char *filename
, const GArray
* ops
, DFUNC printer
, void *ctx
)
923 f
= f_open (filename
, O_RDONLY
);
941 #define T1 a[ ord^1 ][0]
942 #define T2 a[ ord^1 ][1]
943 for (i
= 0; i
< ops
->len
; i
++)
946 op
= &g_array_index (ops
, DIFFCMD
, i
);
947 n
= op
->F1
- (op
->cmd
!= add_cmd
);
948 while (line
< n
&& (sz
= f_gets (buf
, sizeof (buf
), f
)) != 0)
951 printer (ctx
, EQU_CH
, line
, off
, sz
, buf
);
953 while (buf
[sz
- 1] != '\n')
955 sz
= f_gets (buf
, sizeof (buf
), f
);
958 printer (ctx
, 0, 0, 0, 1, "\n");
961 printer (ctx
, 0, 0, 0, sz
, buf
);
970 if (op
->cmd
== add_cmd
)
972 n
= op
->T2
- op
->T1
+ 1;
975 printer (ctx
, DEL_CH
, 0, 0, 1, "\n");
979 if (op
->cmd
== del_cmd
)
981 n
= op
->F2
- op
->F1
+ 1;
982 while (n
!= 0 && (sz
= f_gets (buf
, sizeof (buf
), f
)) != 0)
985 printer (ctx
, ADD_CH
, line
, off
, sz
, buf
);
987 while (buf
[sz
- 1] != '\n')
989 sz
= f_gets (buf
, sizeof (buf
), f
);
992 printer (ctx
, 0, 0, 0, 1, "\n");
995 printer (ctx
, 0, 0, 0, sz
, buf
);
1007 n
= op
->F2
- op
->F1
+ 1;
1008 while (n
!= 0 && (sz
= f_gets (buf
, sizeof (buf
), f
)) != 0)
1011 printer (ctx
, CHG_CH
, line
, off
, sz
, buf
);
1013 while (buf
[sz
- 1] != '\n')
1015 sz
= f_gets (buf
, sizeof (buf
), f
);
1018 printer (ctx
, 0, 0, 0, 1, "\n");
1021 printer (ctx
, 0, 0, 0, sz
, buf
);
1030 n
= op
->T2
- op
->T1
- (op
->F2
- op
->F1
);
1033 printer (ctx
, CHG_CH
, 0, 0, 1, "\n");
1043 while ((sz
= f_gets (buf
, sizeof (buf
), f
)) != 0)
1046 printer (ctx
, EQU_CH
, line
, off
, sz
, buf
);
1048 while (buf
[sz
- 1] != '\n')
1050 sz
= f_gets (buf
, sizeof (buf
), f
);
1053 printer (ctx
, 0, 0, 0, 1, "\n");
1056 printer (ctx
, 0, 0, 0, sz
, buf
);
1069 /* --------------------------------------------------------------------------------------------- */
1070 /* horizontal diff ********************************************************** */
1073 * Longest common substring.
1075 * \param s first string
1076 * \param m length of first string
1077 * \param t second string
1078 * \param n length of second string
1079 * \param ret list of offsets for longest common substrings inside each string
1080 * \param min minimum length of common substrings
1082 * \return 0 if success, nonzero otherwise
1085 lcsubstr (const char *s
, int m
, const char *t
, int n
, GArray
* ret
, int min
)
1093 if (m
< min
|| n
< min
)
1095 /* XXX early culling */
1099 Lprev
= g_new0 (int, n
+ 1);
1100 Lcurr
= g_new0 (int, n
+ 1);
1102 if (Lprev
== NULL
|| Lcurr
== NULL
)
1109 for (i
= 0; i
< m
; i
++)
1114 #ifdef USE_MEMSET_IN_LCS
1115 memset (Lcurr
, 0, (n
+ 1) * sizeof (int));
1117 for (j
= 0; j
< n
; j
++)
1119 #ifndef USE_MEMSET_IN_LCS
1124 int v
= Lprev
[j
] + 1;
1129 g_array_set_size (ret
, 0);
1131 if (z
== v
&& z
>= min
)
1133 int off0
= i
- z
+ 1;
1134 int off1
= j
- z
+ 1;
1136 for (k
= 0; k
< ret
->len
; k
++)
1138 PAIR
*p
= (PAIR
*) g_array_index (ret
, PAIR
, k
);
1139 if ((*p
)[0] == off0
)
1143 if ((*p
)[1] >= off1
)
1153 g_array_append_val (ret
, p2
);
1169 /* --------------------------------------------------------------------------------------------- */
1172 * Scan recursively for common substrings and build ranges.
1174 * \param s first string
1175 * \param t second string
1176 * \param bracket current limits for both of the strings
1177 * \param min minimum length of common substrings
1178 * \param hdiff list of horizontal diff ranges to fill
1179 * \param depth recursion depth
1181 * \return 0 if success, nonzero otherwise
1184 hdiff_multi (const char *s
, const char *t
, const BRACKET bracket
, int min
, GArray
* hdiff
,
1194 ret
= g_array_new (FALSE
, TRUE
, sizeof (PAIR
));
1198 len
= lcsubstr (s
+ bracket
[0].off
, bracket
[0].len
,
1199 t
+ bracket
[1].off
, bracket
[1].len
, ret
, min
);
1203 const PAIR
*data
= (const PAIR
*) &g_array_index (ret
, PAIR
, 0);
1206 b
[0].off
= bracket
[0].off
;
1207 b
[0].len
= (*data
)[0];
1208 b
[1].off
= bracket
[1].off
;
1209 b
[1].len
= (*data
)[1];
1210 if (!hdiff_multi (s
, t
, b
, min
, hdiff
, depth
))
1213 for (k
= 0; k
< ret
->len
- 1; k
++)
1215 data
= (const PAIR
*) &g_array_index (ret
, PAIR
, k
);
1216 data2
= (const PAIR
*) &g_array_index (ret
, PAIR
, k
+ 1);
1217 b
[0].off
= bracket
[0].off
+ (*data
)[0] + len
;
1218 b
[0].len
= (*data2
)[0] - (*data
)[0] - len
;
1219 b
[1].off
= bracket
[1].off
+ (*data
)[1] + len
;
1220 b
[1].len
= (*data2
)[1] - (*data
)[1] - len
;
1221 if (!hdiff_multi (s
, t
, b
, min
, hdiff
, depth
))
1224 data
= (const PAIR
*) &g_array_index (ret
, PAIR
, k
);
1225 b
[0].off
= bracket
[0].off
+ (*data
)[0] + len
;
1226 b
[0].len
= bracket
[0].len
- (*data
)[0] - len
;
1227 b
[1].off
= bracket
[1].off
+ (*data
)[1] + len
;
1228 b
[1].len
= bracket
[1].len
- (*data
)[1] - len
;
1229 if (!hdiff_multi (s
, t
, b
, min
, hdiff
, depth
))
1232 g_array_free (ret
, TRUE
);
1237 p
[0].off
= bracket
[0].off
;
1238 p
[0].len
= bracket
[0].len
;
1239 p
[1].off
= bracket
[1].off
;
1240 p
[1].len
= bracket
[1].len
;
1241 g_array_append_val (hdiff
, p
);
1246 /* --------------------------------------------------------------------------------------------- */
1249 * Build list of horizontal diff ranges.
1251 * \param s first string
1252 * \param m length of first string
1253 * \param t second string
1254 * \param n length of second string
1255 * \param min minimum length of common substrings
1256 * \param hdiff list of horizontal diff ranges to fill
1257 * \param depth recursion depth
1259 * \return 0 if success, nonzero otherwise
1262 hdiff_scan (const char *s
, int m
, const char *t
, int n
, int min
, GArray
* hdiff
, unsigned int depth
)
1267 /* dumbscan (single horizontal diff) -- does not compress whitespace */
1268 for (i
= 0; i
< m
&& i
< n
&& s
[i
] == t
[i
]; i
++)
1270 for (; m
> i
&& n
> i
&& s
[m
- 1] == t
[n
- 1]; m
--, n
--)
1278 /* smartscan (multiple horizontal diff) */
1279 return hdiff_multi (s
, t
, b
, min
, hdiff
, depth
);
1282 /* --------------------------------------------------------------------------------------------- */
1283 /* read line **************************************************************** */
1286 * Check if character is inside horizontal diff limits.
1288 * \param k rank of character inside line
1289 * \param hdiff horizontal diff structure
1290 * \param ord 0 if reading from first file, 1 if reading from 2nd file
1292 * \return TRUE if inside hdiff limits, FALSE otherwise
1295 is_inside (int k
, GArray
* hdiff
, int ord
)
1299 for (i
= 0; i
< hdiff
->len
; i
++)
1302 b
= &g_array_index (hdiff
, BRACKET
, i
);
1304 start
= (*b
)[ord
].off
;
1305 end
= start
+ (*b
)[ord
].len
;
1306 if (k
>= start
&& k
< end
)
1314 /* --------------------------------------------------------------------------------------------- */
1317 * Copy `src' to `dst' expanding tabs.
1319 * \param dst destination buffer
1320 * \param src source buffer
1321 * \param srcsize size of src buffer
1322 * \param base virtual base of this string, needed to calculate tabs
1323 * \param ts tab size
1325 * \return new virtual base
1327 * \note The procedure returns when all bytes are consumed from `src'
1330 cvt_cpy (char *dst
, const char *src
, size_t srcsize
, int base
, int ts
)
1333 for (i
= 0; srcsize
!= 0; i
++, src
++, dst
++, srcsize
--)
1338 int j
= TAB_SKIP (ts
, i
+ base
);
1350 /* --------------------------------------------------------------------------------------------- */
1353 * Copy `src' to `dst' expanding tabs.
1355 * \param dst destination buffer
1356 * \param dstsize size of dst buffer
1357 * \param[in,out] _src source buffer
1358 * \param srcsize size of src buffer
1359 * \param base virtual base of this string, needed to calculate tabs
1360 * \param ts tab size
1362 * \return new virtual base
1364 * \note The procedure returns when all bytes are consumed from `src'
1365 * or `dstsize' bytes are written to `dst'
1366 * \note Upon return, `src' points to the first unwritten character in source
1369 cvt_ncpy (char *dst
, int dstsize
, const char **_src
, size_t srcsize
, int base
, int ts
)
1372 const char *src
= *_src
;
1373 for (i
= 0; i
< dstsize
&& srcsize
!= 0; i
++, src
++, dst
++, srcsize
--)
1378 int j
= TAB_SKIP (ts
, i
+ base
);
1379 if (j
> dstsize
- i
)
1395 /* --------------------------------------------------------------------------------------------- */
1398 * Read line from memory, converting tabs to spaces and padding with spaces.
1400 * \param src buffer to read from
1401 * \param srcsize size of src buffer
1402 * \param dst buffer to read to
1403 * \param dstsize size of dst buffer, excluding trailing null
1404 * \param skip number of characters to skip
1405 * \param ts tab size
1406 * \param show_cr show trailing carriage return as ^M
1408 * \return negative on error, otherwise number of bytes except padding
1411 cvt_mget (const char *src
, size_t srcsize
, char *dst
, int dstsize
, int skip
, int ts
, int show_cr
)
1419 for (i
= 0; dstsize
!= 0 && srcsize
!= 0 && *src
!= '\n'; i
++, src
++, srcsize
--)
1423 int j
= TAB_SKIP (ts
, i
+ base
);
1431 else if (dstsize
!= 0)
1438 else if (src
[0] == '\r' && (srcsize
== 1 || src
[1] == '\n'))
1440 if (skip
== 0 && show_cr
)
1465 utf_ch
= dview_get_utf ((char *) src
, &w
, &res
);
1468 if (!g_unichar_isprint (utf_ch
))
1480 while (dstsize
!= 0)
1489 /* --------------------------------------------------------------------------------------------- */
1492 * Read line from memory and build attribute array.
1494 * \param src buffer to read from
1495 * \param srcsize size of src buffer
1496 * \param dst buffer to read to
1497 * \param dstsize size of dst buffer, excluding trailing null
1498 * \param skip number of characters to skip
1499 * \param ts tab size
1500 * \param show_cr show trailing carriage return as ^M
1501 * \param hdiff horizontal diff structure
1502 * \param ord 0 if reading from first file, 1 if reading from 2nd file
1503 * \param att buffer of attributes
1505 * \return negative on error, otherwise number of bytes except padding
1508 cvt_mgeta (const char *src
, size_t srcsize
, char *dst
, int dstsize
, int skip
, int ts
, int show_cr
,
1509 GArray
* hdiff
, int ord
, char *att
)
1517 for (i
= 0, k
= 0; dstsize
!= 0 && srcsize
!= 0 && *src
!= '\n'; i
++, k
++, src
++, srcsize
--)
1521 int j
= TAB_SKIP (ts
, i
+ base
);
1529 else if (dstsize
!= 0)
1532 *att
++ = is_inside (k
, hdiff
, ord
);
1537 else if (src
[0] == '\r' && (srcsize
== 1 || src
[1] == '\n'))
1539 if (skip
== 0 && show_cr
)
1544 *att
++ = is_inside (k
, hdiff
, ord
);
1546 *att
++ = is_inside (k
, hdiff
, ord
);
1552 *att
++ = is_inside (k
, hdiff
, ord
);
1567 utf_ch
= dview_get_utf ((char *) src
, &w
, &res
);
1570 if (!g_unichar_isprint (utf_ch
))
1576 *att
++ = is_inside (k
, hdiff
, ord
);
1583 while (dstsize
!= 0)
1593 /* --------------------------------------------------------------------------------------------- */
1596 * Read line from file, converting tabs to spaces and padding with spaces.
1598 * \param f file stream to read from
1599 * \param off offset of line inside file
1600 * \param dst buffer to read to
1601 * \param dstsize size of dst buffer, excluding trailing null
1602 * \param skip number of characters to skip
1603 * \param ts tab size
1604 * \param show_cr show trailing carriage return as ^M
1606 * \return negative on error, otherwise number of bytes except padding
1609 cvt_fget (FBUF
* f
, off_t off
, char *dst
, size_t dstsize
, int skip
, int ts
, int show_cr
)
1612 int old_base
= base
;
1613 const int amount
= dstsize
;
1615 size_t useful
, offset
;
1622 const char *q
= NULL
;
1623 char tmp
[BUFSIZ
]; /* XXX capacity must be >= max{dstsize + 1, amount} */
1624 char cvt
[BUFSIZ
]; /* XXX capacity must be >= MAX_TAB_WIDTH * amount */
1626 if ((int) sizeof (tmp
) < amount
|| (int) sizeof (tmp
) <= dstsize
1627 || (int) sizeof (cvt
) < 8 * amount
)
1629 /* abnormal, but avoid buffer overflow */
1630 memset (dst
, ' ', dstsize
);
1631 dst
[dstsize
] = '\0';
1635 f_seek (f
, off
, SEEK_SET
);
1640 sz
= f_gets (tmp
, amount
, f
);
1644 base
= cvt_cpy (cvt
, tmp
, sz
, old_base
, ts
);
1645 if (cvt
[base
- old_base
- 1] == '\n')
1647 q
= &cvt
[base
- old_base
- 1];
1648 base
= old_base
+ q
- cvt
+ 1;
1655 memset (dst
, ' ', dstsize
);
1656 dst
[dstsize
] = '\0';
1660 useful
= base
- skip
;
1661 offset
= skip
- old_base
;
1663 if (useful
<= dstsize
)
1666 memmove (dst
, cvt
+ offset
, useful
);
1670 sz
= f_gets (tmp
, dstsize
- useful
+ 1, f
);
1673 const char *ptr
= tmp
;
1674 useful
+= cvt_ncpy (dst
+ useful
, dstsize
- useful
, &ptr
, sz
, base
, ts
) - base
;
1683 memmove (dst
, cvt
+ offset
, dstsize
);
1685 lastch
= cvt
[offset
+ dstsize
];
1689 for (i
= 0; i
< sz
&& dst
[i
] != '\n'; i
++)
1691 if (dst
[i
] == '\r' && dst
[i
+ 1] == '\n')
1695 if (i
+ 1 < dstsize
)
1708 for (; i
< dstsize
; i
++)
1716 /* --------------------------------------------------------------------------------------------- */
1717 /* diff printers et al ****************************************************** */
1720 cc_free_elt (void *elt
)
1729 /* --------------------------------------------------------------------------------------------- */
1732 printer (void *ctx
, int ch
, int line
, off_t off
, size_t sz
, const char *str
)
1734 GArray
*a
= ((PRINTER_CTX
*) ctx
)->a
;
1735 DSRC dsrc
= ((PRINTER_CTX
*) ctx
)->dsrc
;
1743 if (dsrc
== DATA_SRC_MEM
&& line
!= 0)
1745 if (sz
!= 0 && str
[sz
- 1] == '\n')
1750 p
.p
= g_strndup (str
, sz
);
1753 g_array_append_val (a
, p
);
1755 else if (dsrc
== DATA_SRC_MEM
)
1758 p
= &g_array_index (a
, DIFFLN
, a
->len
- 1);
1759 if (sz
!= 0 && str
[sz
- 1] == '\n')
1765 size_t new_size
= p
->u
.len
+ sz
;
1766 char *q
= g_realloc (p
->p
, new_size
);
1767 memcpy (q
+ p
->u
.len
, str
, sz
);
1772 if (dsrc
== DATA_SRC_TMP
&& (line
!= 0 || ch
== 0))
1774 FBUF
*f
= ((PRINTER_CTX
*) ctx
)->f
;
1775 f_write (f
, str
, sz
);
1780 /* --------------------------------------------------------------------------------------------- */
1783 redo_diff (WDiff
* dview
)
1785 FBUF
*const *f
= dview
->f
;
1795 if (dview
->opt
.quality
== 2)
1797 strcat (extra
, " -d");
1799 if (dview
->opt
.quality
== 1)
1801 strcat (extra
, " --speed-large-files");
1803 if (dview
->opt
.strip_trailing_cr
)
1805 strcat (extra
, " --strip-trailing-cr");
1807 if (dview
->opt
.ignore_tab_expansion
)
1809 strcat (extra
, " -E");
1811 if (dview
->opt
.ignore_space_change
)
1813 strcat (extra
, " -b");
1815 if (dview
->opt
.ignore_all_space
)
1817 strcat (extra
, " -w");
1819 if (dview
->opt
.ignore_case
)
1821 strcat (extra
, " -i");
1824 if (dview
->dsrc
!= DATA_SRC_MEM
)
1830 ops
= g_array_new (FALSE
, FALSE
, sizeof (DIFFCMD
));
1831 ndiff
= dff_execute (dview
->args
, extra
, dview
->file
[0], dview
->file
[1], ops
);
1835 g_array_free (ops
, TRUE
);
1839 ctx
.dsrc
= dview
->dsrc
;
1842 ctx
.a
= dview
->a
[0];
1844 rv
|= dff_reparse (0, dview
->file
[0], ops
, printer
, &ctx
);
1846 ctx
.a
= dview
->a
[1];
1848 rv
|= dff_reparse (1, dview
->file
[1], ops
, printer
, &ctx
);
1851 g_array_free (ops
, TRUE
);
1853 if (rv
!= 0 || dview
->a
[0]->len
!= dview
->a
[1]->len
)
1856 if (dview
->dsrc
== DATA_SRC_TMP
)
1862 if (dview
->dsrc
== DATA_SRC_MEM
&& HDIFF_ENABLE
)
1864 dview
->hdiff
= g_ptr_array_new ();
1865 if (dview
->hdiff
!= NULL
)
1870 for (i
= 0; i
< dview
->a
[0]->len
; i
++)
1873 p
= &g_array_index (dview
->a
[0], DIFFLN
, i
);
1874 q
= &g_array_index (dview
->a
[1], DIFFLN
, i
);
1875 if (p
->line
&& q
->line
&& p
->ch
== CHG_CH
)
1877 h
= g_array_new (FALSE
, FALSE
, sizeof (BRACKET
));
1880 gboolean runresult
=
1881 hdiff_scan (p
->p
, p
->u
.len
, q
->p
, q
->u
.len
, HDIFF_MINCTX
, h
,
1885 g_array_free (h
, TRUE
);
1890 g_ptr_array_add (dview
->hdiff
, h
);
1897 /* --------------------------------------------------------------------------------------------- */
1900 destroy_hdiff (WDiff
* dview
)
1902 if (dview
->hdiff
!= NULL
)
1905 int len
= dview
->a
[0]->len
;
1906 for (i
= 0; i
< len
; i
++)
1908 GArray
*h
= (GArray
*) g_ptr_array_index (dview
->hdiff
, i
);
1910 g_array_free (h
, TRUE
);
1912 g_ptr_array_free (dview
->hdiff
, TRUE
);
1913 dview
->hdiff
= NULL
;
1916 mc_search_free (dview
->search
.handle
);
1917 dview
->search
.handle
= NULL
;
1918 g_free (dview
->search
.last_string
);
1919 dview
->search
.last_string
= NULL
;
1922 /* --------------------------------------------------------------------------------------------- */
1923 /* stuff ******************************************************************** */
1926 get_digits (unsigned int n
)
1936 /* --------------------------------------------------------------------------------------------- */
1939 get_line_numbers (const GArray
* a
, size_t pos
, int *linenum
, int *lineofs
)
1953 p
= &g_array_index (a
, DIFFLN
, pos
);
1958 for (n
= pos
; n
> 0; n
--)
1966 *lineofs
= pos
- n
+ 1;
1974 /* --------------------------------------------------------------------------------------------- */
1977 calc_nwidth (const GArray
** const a
)
1981 get_line_numbers (a
[0], a
[0]->len
- 1, &l1
, &o1
);
1982 get_line_numbers (a
[1], a
[1]->len
- 1, &l2
, &o2
);
1987 return get_digits (l1
);
1990 /* --------------------------------------------------------------------------------------------- */
1993 find_prev_hunk (const GArray
* a
, int pos
)
1996 while (pos
> 0 && ((DIFFLN
*) & g_array_index (a
, DIFFLN
, pos
))->ch
!= EQU_CH
)
2000 while (pos
> 0 && ((DIFFLN
*) & g_array_index (a
, DIFFLN
, pos
))->ch
== EQU_CH
)
2004 while (pos
> 0 && ((DIFFLN
*) & g_array_index (a
, DIFFLN
, pos
))->ch
!= EQU_CH
)
2008 if (pos
> 0 && (size_t) pos
< a
->len
)
2011 while (pos
> 0 && ((DIFFLN
*) & g_array_index (a
, DIFFLN
, pos
- 1))->ch
== EQU_CH
)
2015 while (pos
> 0 && ((DIFFLN
*) & g_array_index (a
, DIFFLN
, pos
- 1))->ch
!= EQU_CH
)
2024 /* --------------------------------------------------------------------------------------------- */
2027 find_next_hunk (const GArray
* a
, size_t pos
)
2029 while (pos
< a
->len
&& ((DIFFLN
*) & g_array_index (a
, DIFFLN
, pos
))->ch
!= EQU_CH
)
2033 while (pos
< a
->len
&& ((DIFFLN
*) & g_array_index (a
, DIFFLN
, pos
))->ch
== EQU_CH
)
2041 * Find start and end lines of the current hunk.
2043 * \param dview - widget WDiff
2044 * \return boolean and
2045 * start_line1 first line of current hunk (file[0])
2046 * end_line1 last line of current hunk (file[0])
2047 * start_line1 first line of current hunk (file[0])
2048 * end_line1 last line of current hunk (file[0])
2051 get_current_hunk (WDiff
* dview
, int *start_line1
, int *end_line1
, int *start_line2
, int *end_line2
)
2053 const GArray
*a0
= dview
->a
[0];
2054 const GArray
*a1
= dview
->a
[1];
2064 pos
= dview
->skip_rows
;
2065 ch
= ((DIFFLN
*) & g_array_index (a0
, DIFFLN
, pos
))->ch
;
2080 while (pos
> 0 && ((DIFFLN
*) & g_array_index (a0
, DIFFLN
, pos
))->ch
!= EQU_CH
)
2086 *start_line1
= ((DIFFLN
*) & g_array_index (a0
, DIFFLN
, pos
))->line
+ 1;
2087 *start_line2
= ((DIFFLN
*) & g_array_index (a1
, DIFFLN
, pos
))->line
+ 1;
2089 pos
= dview
->skip_rows
;
2090 while (pos
< a0
->len
&& ((DIFFLN
*) & g_array_index (a0
, DIFFLN
, pos
))->ch
!= EQU_CH
)
2093 l0
= ((DIFFLN
*) & g_array_index (a0
, DIFFLN
, pos
))->line
;
2094 l1
= ((DIFFLN
*) & g_array_index (a1
, DIFFLN
, pos
))->line
;
2096 *end_line1
= max (*start_line1
, l0
);
2098 *end_line2
= max (*start_line2
, l1
);
2106 dview_remove_hunk (WDiff
* dview
, FILE * merge_file
, int from1
, int to1
)
2111 f0
= fopen (dview
->file
[0], "r");
2113 while (fgets (buf
, sizeof (buf
), f0
) != NULL
&& line
< from1
- 1)
2116 fputs (buf
, merge_file
);
2118 while (fgets (buf
, sizeof (buf
), f0
) != NULL
)
2122 fputs (buf
, merge_file
);
2128 dview_add_hunk (WDiff
* dview
, FILE * merge_file
, int from1
, int from2
, int to2
)
2134 f0
= fopen (dview
->file
[0], "r");
2135 f1
= fopen (dview
->file
[1], "r");
2137 while (fgets (buf
, sizeof (buf
), f0
) != NULL
&& line
< from1
- 1)
2140 fputs (buf
, merge_file
);
2143 while (fgets (buf
, sizeof (buf
), f1
) != NULL
&& line
<= to2
)
2147 fputs (buf
, merge_file
);
2149 while (fgets (buf
, sizeof (buf
), f0
) != NULL
)
2151 fputs (buf
, merge_file
);
2158 dview_replace_hunk (WDiff
* dview
, FILE * merge_file
, int from1
, int to1
, int from2
, int to2
)
2164 f0
= fopen (dview
->file
[0], "r");
2165 f1
= fopen (dview
->file
[1], "r");
2167 while (fgets (buf
, sizeof (buf
), f0
) != NULL
&& line1
< from1
- 1)
2170 fputs (buf
, merge_file
);
2173 while (fgets (buf
, sizeof (buf
), f1
) != NULL
&& line2
<= to2
)
2177 fputs (buf
, merge_file
);
2179 while (fgets (buf
, sizeof (buf
), f0
) != NULL
)
2183 fputs (buf
, merge_file
);
2190 do_merge_hunk (WDiff
* dview
)
2192 int from1
, to1
, from2
, to2
;
2196 hunk
= get_current_hunk (dview
, &from1
, &to1
, &from2
, &to2
);
2201 char *merge_file_name
= NULL
;
2205 dview
->merged
= mc_util_make_backup_if_possible (dview
->file
[0], "~~~");
2208 message (D_ERROR
, MSG_ERROR
,
2209 _("Cannot create backup file\n%s%s\n%s"),
2210 dview
->file
[0], "~~~", unix_error_string (errno
));
2216 merge_file_fd
= mc_mkstemps (&merge_file_name
, "mcmerge", NULL
);
2217 if (merge_file_fd
== -1)
2219 message (D_ERROR
, MSG_ERROR
, _("Cannot create temporary merge file\n%s"),
2220 unix_error_string (errno
));
2224 merge_file
= fdopen (merge_file_fd
, "w");
2229 dview_remove_hunk (dview
, merge_file
, from1
, to1
);
2232 dview_add_hunk (dview
, merge_file
, from1
, from2
, to2
);
2235 dview_replace_hunk (dview
, merge_file
, from1
, to1
, from2
, to2
);
2238 fflush (merge_file
);
2239 fclose (merge_file
);
2240 res
= rewrite_backup_content (merge_file_name
, dview
->file
[0]);
2241 unlink (merge_file_name
);
2242 g_free (merge_file_name
);
2246 /* --------------------------------------------------------------------------------------------- */
2247 /* view routines and callbacks ********************************************** */
2250 dview_compute_split (WDiff
* dview
, int i
)
2253 if (dview
->bias
< 2 - dview
->half1
)
2255 dview
->bias
= 2 - dview
->half1
;
2257 if (dview
->bias
> dview
->half2
- 2)
2259 dview
->bias
= dview
->half2
- 2;
2263 /* --------------------------------------------------------------------------------------------- */
2266 dview_compute_areas (WDiff
* dview
)
2268 dview
->height
= LINES
- 2;
2269 dview
->half1
= COLS
/ 2;
2270 dview
->half2
= COLS
- dview
->half1
;
2272 dview_compute_split (dview
, 0);
2275 /* --------------------------------------------------------------------------------------------- */
2278 dview_init (WDiff
* dview
, const char *args
, const char *file1
, const char *file2
,
2279 const char *label1
, const char *label2
, DSRC dsrc
)
2287 if (dsrc
== DATA_SRC_TMP
)
2300 else if (dsrc
== DATA_SRC_ORG
)
2302 f
[0] = f_open (file1
, O_RDONLY
);
2306 f
[1] = f_open (file2
, O_RDONLY
);
2315 dview
->file
[0] = file1
;
2316 dview
->file
[1] = file2
;
2317 dview
->label
[0] = g_strdup (label1
);
2318 dview
->label
[1] = g_strdup (label2
);
2321 dview
->hdiff
= NULL
;
2323 dview
->converter
= str_cnv_from_term
;
2324 dview_set_codeset (dview
);
2326 dview
->a
[0] = g_array_new (FALSE
, FALSE
, sizeof (DIFFLN
));
2327 dview
->a
[1] = g_array_new (FALSE
, FALSE
, sizeof (DIFFLN
));
2329 ndiff
= redo_diff (dview
);
2332 /* goto WIDGET_DESTROY stage: dview_fini() */
2336 dview
->ndiff
= ndiff
;
2338 dview
->view_quit
= 0;
2341 dview
->new_frame
= 1;
2342 dview
->skip_rows
= 0;
2343 dview
->skip_cols
= 0;
2344 dview
->display_symbols
= 0;
2345 dview
->display_numbers
= 0;
2347 dview
->tab_size
= 8;
2351 dview
->search
.handle
= NULL
;
2352 dview
->search
.last_string
= NULL
;
2353 dview
->search
.last_found_line
= -1;
2354 dview
->search
.last_accessed_num_line
= -1;
2356 dview
->opt
.quality
= 0;
2357 dview
->opt
.strip_trailing_cr
= 0;
2358 dview
->opt
.ignore_tab_expansion
= 0;
2359 dview
->opt
.ignore_space_change
= 0;
2360 dview
->opt
.ignore_all_space
= 0;
2361 dview
->opt
.ignore_case
= 0;
2363 dview_compute_areas (dview
);
2368 /* --------------------------------------------------------------------------------------------- */
2371 dview_reread (WDiff
* dview
)
2373 int ndiff
= dview
->ndiff
;
2375 destroy_hdiff (dview
);
2376 if (dview
->a
[0] != NULL
)
2378 g_array_foreach (dview
->a
[0], DIFFLN
, cc_free_elt
);
2379 g_array_free (dview
->a
[0], TRUE
);
2381 if (dview
->a
[1] != NULL
)
2383 g_array_foreach (dview
->a
[1], DIFFLN
, cc_free_elt
);
2384 g_array_free (dview
->a
[1], TRUE
);
2387 dview
->a
[0] = g_array_new (FALSE
, FALSE
, sizeof (DIFFLN
));
2388 dview
->a
[1] = g_array_new (FALSE
, FALSE
, sizeof (DIFFLN
));
2390 ndiff
= redo_diff (dview
);
2392 dview
->ndiff
= ndiff
;
2395 /* --------------------------------------------------------------------------------------------- */
2397 dview_diff_options (WDiff
* dview
)
2399 const char *quality_str
[] = {
2401 N_("&Fastest (Assume large files)"),
2402 N_("&Minimal (Find a smaller set of change)")
2405 QuickWidget diffopt_widgets
[] = {
2406 QUICK_BUTTON (6, 10, 14, OPTY
, N_("&Cancel"), B_CANCEL
, NULL
),
2407 QUICK_BUTTON (2, 10, 14, OPTY
, N_("&OK"), B_ENTER
, NULL
),
2409 QUICK_CHECKBOX (3, OPTX
, 12, OPTY
,
2410 N_("Strip &trailing carriage return"), &dview
->opt
.strip_trailing_cr
),
2411 QUICK_CHECKBOX (3, OPTX
, 11, OPTY
,
2412 N_("Ignore all &whitespace"), &dview
->opt
.ignore_all_space
),
2413 QUICK_CHECKBOX (3, OPTX
, 10, OPTY
,
2414 N_("Ignore &space change"), &dview
->opt
.ignore_space_change
),
2415 QUICK_CHECKBOX (3, OPTX
, 9, OPTY
,
2416 N_("Ignore tab &expansion"), &dview
->opt
.ignore_tab_expansion
),
2417 QUICK_CHECKBOX (3, OPTX
, 8, OPTY
,
2418 N_("&Ignore case"), &dview
->opt
.ignore_case
),
2419 QUICK_LABEL (3, OPTX
, 7, OPTY
, N_("Diff extra options")),
2420 QUICK_RADIO (3, OPTX
, 3, OPTY
,
2421 3, (const char **) quality_str
, (int *) &dview
->opt
.quality
),
2422 QUICK_LABEL (3, OPTX
, 2, OPTY
, N_("Diff algorithm")),
2427 QuickDialog diffopt
= {
2429 N_("Diff Options"), "[Diff Options]",
2430 diffopt_widgets
, NULL
, FALSE
2433 if (quick_dialog (&diffopt
) != B_CANCEL
)
2435 dview_reread (dview
);
2439 /* --------------------------------------------------------------------------------------------- */
2442 dview_fini (WDiff
* dview
)
2444 if (dview
->dsrc
!= DATA_SRC_MEM
)
2446 f_close (dview
->f
[1]);
2447 f_close (dview
->f
[0]);
2450 if (dview
->converter
!= str_cnv_from_term
)
2451 str_close_conv (dview
->converter
);
2453 destroy_hdiff (dview
);
2454 if (dview
->a
[0] != NULL
)
2456 g_array_foreach (dview
->a
[0], DIFFLN
, cc_free_elt
);
2457 g_array_free (dview
->a
[0], TRUE
);
2460 if (dview
->a
[1] != NULL
)
2462 g_array_foreach (dview
->a
[1], DIFFLN
, cc_free_elt
);
2463 g_array_free (dview
->a
[1], TRUE
);
2467 g_free (dview
->label
[0]);
2468 g_free (dview
->label
[1]);
2472 /* --------------------------------------------------------------------------------------------- */
2475 dview_display_file (const WDiff
* dview
, int ord
, int r
, int c
, int height
, int width
)
2480 FBUF
*f
= dview
->f
[ord
];
2481 int skip
= dview
->skip_cols
;
2482 int display_symbols
= dview
->display_symbols
;
2483 int display_numbers
= dview
->display_numbers
;
2484 int show_cr
= dview
->show_cr
;
2487 int nwidth
= display_numbers
;
2488 int xwidth
= display_symbols
+ display_numbers
;
2489 if (dview
->tab_size
> 0 && dview
->tab_size
< 9)
2490 tab_size
= dview
->tab_size
;
2494 if (xwidth
> width
&& display_symbols
)
2497 display_symbols
= 0;
2499 if (xwidth
> width
&& display_numbers
)
2502 display_numbers
= width
;
2516 if ((int) sizeof (buf
) <= width
|| (int) sizeof (buf
) <= nwidth
)
2518 /* abnormal, but avoid buffer overflow */
2522 for (i
= dview
->skip_rows
, j
= 0; i
< dview
->a
[ord
]->len
&& j
< height
; j
++, i
++)
2524 int ch
, next_ch
, col
;
2526 p
= (DIFFLN
*) & g_array_index (dview
->a
[ord
], DIFFLN
, i
);
2528 tty_setcolor (NORMAL_COLOR
);
2529 if (display_symbols
)
2531 tty_gotoyx (r
+ j
, c
- 2);
2532 tty_print_char (ch
);
2536 if (display_numbers
)
2538 tty_gotoyx (r
+ j
, c
- xwidth
);
2539 g_snprintf (buf
, display_numbers
+ 1, "%*d", nwidth
, p
->line
);
2540 tty_print_string (str_fit_to_term (buf
, nwidth
, J_LEFT_FIT
));
2544 tty_setcolor (DFF_ADD_COLOR
);
2548 tty_setcolor (DFF_CHG_COLOR
);
2552 if (i
== (size_t) dview
->search
.last_found_line
)
2554 tty_setcolor (MARKED_SELECTED_COLOR
);
2558 if (dview
->hdiff
!= NULL
&& g_ptr_array_index (dview
->hdiff
, i
) != NULL
)
2562 k
= dview_str_utf8_offset_to_pos (p
->p
, width
);
2565 cvt_mgeta (p
->p
, p
->u
.len
, buf
, k
, skip
, tab_size
, show_cr
,
2566 g_ptr_array_index (dview
->hdiff
, i
), ord
, att
);
2567 tty_gotoyx (r
+ j
, c
);
2569 for (cnt
= 0; cnt
< strlen (buf
) && col
< width
; cnt
++)
2575 next_ch
= dview_get_utf (buf
+ cnt
, &w
, &ch_res
);
2578 if (!g_unichar_isprint (next_ch
))
2582 next_ch
= dview_get_byte (buf
+ cnt
, &ch_res
);
2585 tty_setcolor (att
[cnt
] ? DFF_CHH_COLOR
: DFF_CHG_COLOR
);
2587 if (mc_global
.utf8_display
)
2592 convert_from_8bit_to_utf_c ((unsigned char) next_ch
,
2596 else if (dview
->utf8
)
2598 convert_from_utf_to_current_c (next_ch
, dview
->converter
);
2601 next_ch
= convert_to_display_c (next_ch
);
2603 tty_print_anychar (next_ch
);
2609 else if (ch
== CHG_CH
)
2611 tty_setcolor (DFF_CHH_COLOR
);
2615 k
= dview_str_utf8_offset_to_pos (p
->p
, width
);
2618 cvt_mget (p
->p
, p
->u
.len
, buf
, k
, skip
, tab_size
, show_cr
);
2622 cvt_fget (f
, p
->u
.off
, buf
, width
, skip
, tab_size
, show_cr
);
2627 if (display_numbers
)
2629 tty_gotoyx (r
+ j
, c
- xwidth
);
2630 memset (buf
, ' ', display_numbers
);
2631 buf
[display_numbers
] = '\0';
2632 tty_print_string (buf
);
2636 tty_setcolor (DFF_DEL_COLOR
);
2640 tty_setcolor (DFF_CHD_COLOR
);
2642 memset (buf
, ' ', width
);
2645 tty_gotoyx (r
+ j
, c
);
2646 /* tty_print_nstring (buf, width); */
2648 for (cnt
= 0; cnt
< strlen (buf
) && col
< width
; cnt
++)
2654 next_ch
= dview_get_utf (buf
+ cnt
, &w
, &ch_res
);
2657 if (!g_unichar_isprint (next_ch
))
2661 next_ch
= dview_get_byte (buf
+ cnt
, &ch_res
);
2665 if (mc_global
.utf8_display
)
2670 convert_from_8bit_to_utf_c ((unsigned char) next_ch
, dview
->converter
);
2673 else if (dview
->utf8
)
2674 next_ch
= convert_from_utf_to_current_c (next_ch
, dview
->converter
);
2677 next_ch
= convert_to_display_c (next_ch
);
2679 tty_print_anychar (next_ch
);
2685 tty_setcolor (NORMAL_COLOR
);
2687 if (width
< xwidth
- 1)
2691 memset (buf
, ' ', k
);
2693 for (; j
< height
; j
++)
2697 tty_gotoyx (r
+ j
, c
- xwidth
);
2698 /* tty_print_nstring (buf, xwidth - 1); */
2699 tty_print_string (str_fit_to_term (buf
, xwidth
- 1, J_LEFT_FIT
));
2701 tty_gotoyx (r
+ j
, c
);
2702 /* tty_print_nstring (buf, width); */
2703 tty_print_string (str_fit_to_term (buf
, width
, J_LEFT_FIT
));
2709 /* --------------------------------------------------------------------------------------------- */
2712 dview_status (const WDiff
* dview
, int ord
, int width
, int c
)
2716 int linenum
, lineofs
;
2718 tty_setcolor (STATUSBAR_COLOR
);
2721 get_line_numbers (dview
->a
[ord
], dview
->skip_rows
, &linenum
, &lineofs
);
2723 filename_width
= width
- 22;
2724 if (filename_width
< 8)
2727 buf
= str_term_trim (strip_home_and_password (dview
->label
[ord
]), filename_width
);
2729 tty_printf ("%-*s %6d+%-4d Col %-4d ", filename_width
, buf
, linenum
, lineofs
,
2732 tty_printf ("%-*s %6d+%-4d Dif %-4d ", filename_width
, buf
, linenum
, lineofs
, dview
->ndiff
);
2735 /* --------------------------------------------------------------------------------------------- */
2738 dview_redo (WDiff
* dview
)
2740 if (dview
->display_numbers
)
2742 int old
= dview
->display_numbers
;
2743 dview
->display_numbers
= calc_nwidth ((const GArray
**) dview
->a
);
2744 dview
->new_frame
= (old
!= dview
->display_numbers
);
2746 dview_reread (dview
);
2749 /* --------------------------------------------------------------------------------------------- */
2752 dview_edit (WDiff
* dview
, int ord
)
2756 int linenum
, lineofs
;
2758 if (dview
->dsrc
== DATA_SRC_TMP
)
2760 error_dialog (_("Edit"), _("Edit is disabled"));
2764 h
= ((Widget
*) dview
)->owner
;
2767 get_line_numbers (dview
->a
[ord
], dview
->skip_rows
, &linenum
, &lineofs
);
2768 h
->modal
= TRUE
; /* not allow edit file in several editors */
2769 do_edit_at_line (dview
->file
[ord
], use_internal_edit
, linenum
);
2772 dview_update (dview
);
2775 /* --------------------------------------------------------------------------------------------- */
2778 dview_goto_cmd (WDiff
* dview
, int ord
)
2780 static const char *title
[2] = { N_("Goto line (left)"), N_("Goto line (right)") };
2781 static char prev
[256];
2782 /* XXX some statics here, to be remembered between runs */
2787 input
= input_dialog (_(title
[ord
]), _("Enter line:"), MC_HISTORY_YDIFF_GOTO_LINE
, prev
);
2790 const char *s
= input
;
2791 if (scan_deci (&s
, &newline
) == 0 && *s
== '\0')
2797 for (; i
< dview
->a
[ord
]->len
; i
++)
2799 p
= &g_array_index (dview
->a
[ord
], DIFFLN
, i
);
2800 if (p
->line
== newline
)
2806 dview
->skip_rows
= dview
->search
.last_accessed_num_line
= (ssize_t
) i
;
2807 g_snprintf (prev
, sizeof (prev
), "%d", newline
);
2813 /* --------------------------------------------------------------------------------------------- */
2816 dview_labels (WDiff
* dview
)
2818 Dlg_head
*h
= dview
->widget
.owner
;
2819 WButtonBar
*b
= find_buttonbar (h
);
2821 buttonbar_set_label (b
, 1, Q_ ("ButtonBar|Help"), diff_map
, (Widget
*) dview
);
2822 buttonbar_set_label (b
, 2, Q_ ("ButtonBar|Save"), diff_map
, (Widget
*) dview
);
2823 buttonbar_set_label (b
, 4, Q_ ("ButtonBar|Edit"), diff_map
, (Widget
*) dview
);
2824 buttonbar_set_label (b
, 5, Q_ ("ButtonBar|Merge"), diff_map
, (Widget
*) dview
);
2825 buttonbar_set_label (b
, 7, Q_ ("ButtonBar|Search"), diff_map
, (Widget
*) dview
);
2826 buttonbar_set_label (b
, 9, Q_ ("ButtonBar|Options"), diff_map
, (Widget
*) dview
);
2827 buttonbar_set_label (b
, 10, Q_ ("ButtonBar|Quit"), diff_map
, (Widget
*) dview
);
2831 /* --------------------------------------------------------------------------------------------- */
2834 dview_event (Gpm_Event
* event
, void *x
)
2836 WDiff
*dview
= (WDiff
*) x
;
2837 int result
= MOU_NORMAL
;
2839 /* We are not interested in the release events */
2840 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
)) == 0)
2846 if ((event
->buttons
& GPM_B_UP
) != 0 && (event
->type
& GPM_DOWN
) != 0)
2848 dview
->skip_rows
-= 2;
2849 dview
->search
.last_accessed_num_line
= dview
->skip_rows
;
2850 dview_update (dview
);
2852 else if ((event
->buttons
& GPM_B_DOWN
) != 0 && (event
->type
& GPM_DOWN
) != 0)
2854 dview
->skip_rows
+= 2;
2855 dview
->search
.last_accessed_num_line
= dview
->skip_rows
;
2856 dview_update (dview
);
2863 dview_save (WDiff
* dview
)
2865 gboolean res
= TRUE
;
2868 res
= mc_util_unlink_backup_if_possible (dview
->file
[0], "~~~");
2869 dview
->merged
= !res
;
2874 dview_do_save (WDiff
* dview
)
2876 (void) dview_save (dview
);
2880 dview_save_options (WDiff
* dview
)
2882 mc_config_set_bool (mc_main_config
, "DiffView", "show_symbols",
2883 dview
->display_symbols
!= 0 ? TRUE
: FALSE
);
2884 mc_config_set_bool (mc_main_config
, "DiffView", "show_numbers",
2885 dview
->display_numbers
!= 0 ? TRUE
: FALSE
);
2886 mc_config_set_int (mc_main_config
, "DiffView", "tab_size", dview
->tab_size
);
2888 mc_config_set_int (mc_main_config
, "DiffView", "diff_quality", dview
->opt
.quality
);
2890 mc_config_set_bool (mc_main_config
, "DiffView", "diff_ignore_tws",
2891 dview
->opt
.strip_trailing_cr
);
2892 mc_config_set_bool (mc_main_config
, "DiffView", "diff_ignore_all_space",
2893 dview
->opt
.ignore_all_space
);
2894 mc_config_set_bool (mc_main_config
, "DiffView", "diff_ignore_space_change",
2895 dview
->opt
.ignore_space_change
);
2896 mc_config_set_bool (mc_main_config
, "DiffView", "diff_tab_expansion",
2897 dview
->opt
.ignore_tab_expansion
);
2898 mc_config_set_bool (mc_main_config
, "DiffView", "diff_ignore_case", dview
->opt
.ignore_case
);
2902 dview_load_options (WDiff
* dview
)
2904 gboolean show_numbers
, show_symbols
;
2907 show_symbols
= mc_config_get_bool (mc_main_config
, "DiffView", "show_symbols", FALSE
);
2909 dview
->display_symbols
= 1;
2910 show_numbers
= mc_config_get_bool (mc_main_config
, "DiffView", "show_numbers", FALSE
);
2912 dview
->display_numbers
= calc_nwidth ((const GArray
** const) dview
->a
);
2913 tab_size
= mc_config_get_int (mc_main_config
, "DiffView", "tab_size", 8);
2914 if (tab_size
> 0 && tab_size
< 9)
2915 dview
->tab_size
= tab_size
;
2917 dview
->tab_size
= 8;
2919 dview
->opt
.quality
= mc_config_get_int (mc_main_config
, "DiffView", "diff_quality", 0);
2921 dview
->opt
.strip_trailing_cr
=
2922 mc_config_get_bool (mc_main_config
, "DiffView", "diff_ignore_tws", FALSE
);
2923 dview
->opt
.ignore_all_space
=
2924 mc_config_get_bool (mc_main_config
, "DiffView", "diff_ignore_all_space", FALSE
);
2925 dview
->opt
.ignore_space_change
=
2926 mc_config_get_bool (mc_main_config
, "DiffView", "diff_ignore_space_change", FALSE
);
2927 dview
->opt
.ignore_tab_expansion
=
2928 mc_config_get_bool (mc_main_config
, "DiffView", "diff_tab_expansion", FALSE
);
2929 dview
->opt
.ignore_case
=
2930 mc_config_get_bool (mc_main_config
, "DiffView", "diff_ignore_case", FALSE
);
2932 dview
->new_frame
= 1;
2936 * Check if it's OK to close the diff viewer. If there are unsaved changes,
2940 dview_ok_to_exit (WDiff
* dview
)
2942 gboolean res
= TRUE
;
2948 act
= query_dialog (_("Quit"), !mc_global
.widget
.midnight_shutdown
?
2949 _("File was modified. Save with exit?") :
2950 _("Midnight Commander is being shut down.\nSave modified file?"),
2951 D_NORMAL
, 2, _("&Yes"), _("&No"));
2954 if (mc_global
.widget
.midnight_shutdown
|| (act
== -1))
2963 (void) dview_save (dview
);
2967 if (mc_util_restore_from_backup_if_possible (dview
->file
[0], "~~~"))
2968 res
= mc_util_unlink_backup_if_possible (dview
->file
[0], "~~~");
2977 /* --------------------------------------------------------------------------------------------- */
2980 dview_execute_cmd (WDiff
* dview
, unsigned long command
)
2982 cb_ret_t res
= MSG_HANDLED
;
2985 case CK_ShowSymbols
:
2986 dview
->display_symbols
^= 1;
2987 dview
->new_frame
= 1;
2989 case CK_ShowNumbers
:
2990 dview
->display_numbers
^= calc_nwidth ((const GArray
** const) dview
->a
);
2991 dview
->new_frame
= 1;
2995 dview
->new_frame
= 1;
3001 dview
->new_frame
= 1;
3007 dview_compute_split (dview
, 1);
3008 dview
->new_frame
= 1;
3015 dview_compute_split (dview
, -1);
3016 dview
->new_frame
= 1;
3020 dview
->tab_size
= 2;
3023 dview
->tab_size
= 3;
3026 dview
->tab_size
= 4;
3029 dview
->tab_size
= 8;
3038 dview
->skip_rows
= dview
->search
.last_accessed_num_line
=
3039 find_next_hunk (dview
->a
[0], dview
->skip_rows
);
3042 dview
->skip_rows
= dview
->search
.last_accessed_num_line
=
3043 find_prev_hunk (dview
->a
[0], dview
->skip_rows
);
3046 dview_goto_cmd (dview
, TRUE
);
3049 dview_edit (dview
, dview
->ord
);
3052 do_merge_hunk (dview
);
3056 dview_edit (dview
, dview
->ord
^ 1);
3059 dview_search_cmd (dview
);
3061 case CK_SearchContinue
:
3062 dview_continue_search_cmd (dview
);
3065 dview
->skip_rows
= dview
->search
.last_accessed_num_line
= 0;
3068 dview
->skip_rows
= dview
->search
.last_accessed_num_line
= dview
->a
[0]->len
- 1;
3071 if (dview
->skip_rows
> 0)
3074 dview
->search
.last_accessed_num_line
= dview
->skip_rows
;
3079 dview
->search
.last_accessed_num_line
= dview
->skip_rows
;
3082 if (dview
->height
> 2)
3084 dview
->skip_rows
+= dview
->height
- 2;
3085 dview
->search
.last_accessed_num_line
= dview
->skip_rows
;
3089 if (dview
->height
> 2)
3091 dview
->skip_rows
-= dview
->height
- 2;
3092 dview
->search
.last_accessed_num_line
= dview
->skip_rows
;
3102 dview
->skip_cols
-= 8;
3105 dview
->skip_cols
+= 8;
3108 dview
->skip_cols
= 0;
3114 dview
->view_quit
= 1;
3117 dview_do_save (dview
);
3120 dview_diff_options (dview
);
3123 case CK_SelectCodepage
:
3124 dview_select_encoding (dview
);
3125 dview_reread (dview
);
3126 tty_touch_screen ();
3131 /* don't close diffviewer due to SIGINT */
3134 res
= MSG_NOT_HANDLED
;
3139 /* --------------------------------------------------------------------------------------------- */
3142 dview_handle_key (WDiff
* dview
, int key
)
3144 unsigned long command
;
3146 key
= convert_from_input_c (key
);
3148 command
= keybind_lookup_keymap_command (diff_map
, key
);
3149 if ((command
!= CK_IgnoreKey
) && (dview_execute_cmd (dview
, command
) == MSG_HANDLED
))
3153 return MSG_NOT_HANDLED
;
3156 /* --------------------------------------------------------------------------------------------- */
3159 dview_callback (Widget
* w
, widget_msg_t msg
, int parm
)
3161 WDiff
*dview
= (WDiff
*) w
;
3162 Dlg_head
*h
= dview
->widget
.owner
;
3168 dview_labels (dview
);
3169 dview_load_options (dview
);
3170 dview_update (dview
);
3174 dview
->new_frame
= 1;
3175 dview_update (dview
);
3179 i
= dview_handle_key (dview
, parm
);
3180 if (dview
->view_quit
)
3183 dview_update (dview
);
3186 case WIDGET_COMMAND
:
3187 i
= dview_execute_cmd (dview
, parm
);
3188 if (dview
->view_quit
)
3191 dview_update (dview
);
3194 case WIDGET_DESTROY
:
3195 dview_save_options (dview
);
3200 return default_proc (msg
, parm
);
3204 /* --------------------------------------------------------------------------------------------- */
3207 dview_adjust_size (Dlg_head
* h
)
3212 /* Look up the viewer and the buttonbar, we assume only two widgets here */
3213 dview
= (WDiff
*) find_widget_type (h
, dview_callback
);
3214 bar
= find_buttonbar (h
);
3215 widget_set_size (&dview
->widget
, 0, 0, LINES
- 1, COLS
);
3216 widget_set_size ((Widget
*) bar
, LINES
- 1, 0, 1, COLS
);
3218 dview_compute_areas (dview
);
3221 /* --------------------------------------------------------------------------------------------- */
3224 dview_dialog_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
3226 WDiff
*dview
= (WDiff
*) data
;
3231 dview_adjust_size (h
);
3237 return dview_execute_cmd (NULL
, parm
);
3238 /* message from buttonbar */
3239 if (sender
== (Widget
*) find_buttonbar (h
))
3242 return send_message ((Widget
*) data
, WIDGET_COMMAND
, parm
);
3244 dview
= (WDiff
*) find_widget_type (h
, dview_callback
);
3245 return dview_execute_cmd (dview
, parm
);
3247 return MSG_NOT_HANDLED
;
3250 dview
= (WDiff
*) find_widget_type (h
, dview_callback
);
3251 h
->state
= DLG_ACTIVE
; /* don't stop the dialog before final decision */
3252 if (dview_ok_to_exit (dview
))
3253 h
->state
= DLG_CLOSED
;
3257 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
3261 /* --------------------------------------------------------------------------------------------- */
3264 dview_get_title (const Dlg_head
* h
, size_t len
)
3266 const WDiff
*dview
= (const WDiff
*) find_widget_type (h
, dview_callback
);
3267 const char *modified
= dview
->merged
? " (*) " : " ";
3271 len1
= (len
- str_term_width1 (_("Diff:")) - strlen (modified
) - 3) / 2;
3273 title
= g_string_sized_new (len
);
3274 g_string_append (title
, _("Diff:"));
3275 g_string_append (title
, modified
);
3276 g_string_append (title
, str_term_trim (dview
->label
[0], len1
));
3277 g_string_append (title
, " | ");
3278 g_string_append (title
, str_term_trim (dview
->label
[1], len1
));
3280 return g_string_free (title
, FALSE
);
3283 /*** public functions ****************************************************************************/
3284 /* --------------------------------------------------------------------------------------------- */
3287 diff_view (const char *file1
, const char *file2
, const char *label1
, const char *label2
)
3291 Dlg_head
*dview_dlg
;
3293 /* Create dialog and widgets, put them on the dialog */
3295 create_dlg (FALSE
, 0, 0, LINES
, COLS
, NULL
, dview_dialog_callback
,
3296 "[Diff Viewer]", NULL
, DLG_WANT_TAB
);
3298 dview
= g_new0 (WDiff
, 1);
3300 init_widget (&dview
->widget
, 0, 0, LINES
- 1, COLS
,
3301 (callback_fn
) dview_callback
, (mouse_h
) dview_event
);
3303 widget_want_cursor (dview
->widget
, 0);
3305 add_widget (dview_dlg
, dview
);
3306 add_widget (dview_dlg
, buttonbar_new (TRUE
));
3308 dview_dlg
->get_title
= dview_get_title
;
3310 error
= dview_init (dview
, "-a", file1
, file2
, label1
, label2
, DATA_SRC_MEM
); /* XXX binary diff? */
3312 /* Please note that if you add another widget,
3313 * you have to modify dview_adjust_size to
3317 run_dlg (dview_dlg
);
3319 if ((error
!= 0) || (dview_dlg
->state
== DLG_CLOSED
))
3320 destroy_dlg (dview_dlg
);
3325 /* --------------------------------------------------------------------------------------------- */
3327 #define GET_FILE_AND_STAMP(n) \
3330 vfs_path_t *vpath = vfs_path_from_str(file##n); \
3332 real_file##n = file##n; \
3333 if (!vfs_file_is_local (vpath)) \
3335 real_file##n = mc_getlocalcopy (file##n); \
3336 if (real_file##n != NULL) \
3339 if (mc_stat (real_file##n, &st##n) != 0) \
3343 vfs_path_free(vpath); \
3347 #define UNGET_FILE(n) \
3353 if (use_copy##n > 0) \
3356 mtime = st##n.st_mtime; \
3357 if (mc_stat (real_file##n, &st##n) == 0) \
3358 changed = (mtime != st##n.st_mtime); \
3360 mc_ungetlocalcopy (file##n, real_file##n, changed); \
3361 g_free (real_file##n); \
3367 dview_diff_cmd (void)
3375 if (mc_global
.mc_run_mode
== MC_RUN_FULL
)
3377 const WPanel
*panel0
= current_panel
;
3378 const WPanel
*panel1
= other_panel
;
3379 if (get_current_index ())
3381 panel0
= other_panel
;
3382 panel1
= current_panel
;
3384 file0
= concat_dir_and_file (panel0
->cwd
, selection (panel0
)->fname
);
3385 file1
= concat_dir_and_file (panel1
->cwd
, selection (panel1
)->fname
);
3386 is_dir0
= S_ISDIR (selection (panel0
)->st
.st_mode
);
3387 is_dir1
= S_ISDIR (selection (panel1
)->st
.st_mode
);
3393 if (file0
!= NULL
&& !is_dir0
&& file1
!= NULL
&& !is_dir1
)
3401 GET_FILE_AND_STAMP (0);
3402 GET_FILE_AND_STAMP (1);
3403 if (real_file0
!= NULL
&& real_file1
!= NULL
)
3405 rv
= diff_view (real_file0
, real_file1
, file0
, file1
);
3416 message (1, MSG_ERROR
, _("Two files are needed to compare"));
3419 /* --------------------------------------------------------------------------------------------- */
3422 dview_update (WDiff
* dview
)
3424 int height
= dview
->height
;
3428 int last
= dview
->a
[0]->len
- 1;
3430 if (dview
->skip_rows
> last
)
3432 dview
->skip_rows
= dview
->search
.last_accessed_num_line
= last
;
3434 if (dview
->skip_rows
< 0)
3436 dview
->skip_rows
= dview
->search
.last_accessed_num_line
= 0;
3438 if (dview
->skip_cols
< 0)
3440 dview
->skip_cols
= 0;
3448 width1
= dview
->half1
+ dview
->bias
;
3449 width2
= dview
->half2
- dview
->bias
;
3456 if (dview
->new_frame
)
3458 int xwidth
= dview
->display_symbols
+ dview
->display_numbers
;
3460 tty_setcolor (NORMAL_COLOR
);
3463 tty_draw_box (1, 0, height
, width1
, FALSE
);
3467 tty_draw_box (1, width1
, height
, width2
, FALSE
);
3473 if (xwidth
< width1
- 1)
3475 tty_gotoyx (1, xwidth
);
3476 tty_print_alt_char (mc_tty_frm
[MC_TTY_FRM_DTOPMIDDLE
], FALSE
);
3477 tty_gotoyx (height
, xwidth
);
3478 tty_print_alt_char (mc_tty_frm
[MC_TTY_FRM_DBOTTOMMIDDLE
], FALSE
);
3479 tty_draw_vline (2, xwidth
, mc_tty_frm
[MC_TTY_FRM_VERT
], height
- 2);
3481 if (xwidth
< width2
- 1)
3483 tty_gotoyx (1, width1
+ xwidth
);
3484 tty_print_alt_char (mc_tty_frm
[MC_TTY_FRM_DTOPMIDDLE
], FALSE
);
3485 tty_gotoyx (height
, width1
+ xwidth
);
3486 tty_print_alt_char (mc_tty_frm
[MC_TTY_FRM_DBOTTOMMIDDLE
], FALSE
);
3487 tty_draw_vline (2, width1
+ xwidth
, mc_tty_frm
[MC_TTY_FRM_VERT
], height
- 2);
3490 dview
->new_frame
= 0;
3495 dview_status (dview
, dview
->ord
, width1
, 0);
3496 dview_display_file (dview
, dview
->ord
, 2, 1, height
- 2, width1
- 2);
3500 dview_status (dview
, dview
->ord
^ 1, width2
, width1
);
3501 dview_display_file (dview
, dview
->ord
^ 1, 2, width1
+ 1, height
- 2, width2
- 2);
3505 /* --------------------------------------------------------------------------------------------- */