Merge branch '1743_mcedit_file_size'

* 1743_mcedit_file_size: (25 commits)
  Refresh po/*.po files.
  Indentation.
  Add threshold for file size.
  Drop limit of edited file size.
  Add functions to transform string to unsigned integer:
  Refactoring of functions that operate with editor buffer.
  Refactoring: rename functions of getting BOL and EOFL:
  Refactoring: move members from WEdit to edit_buffer_t and rename related functions:
  (get_paragraph): refactoring.
  A lot of type accuracies.
  (edit_indent_width, edit_insert_indent): move to wordproc.c and make static.
  Rename edit_buffer_t members.
  Use GPtrArray to store editor buffers.
  (edit_cursor_move): refactoring using editor buffer API.
  New editor buffer API to delete character at cursor position.
  New editor buffer API to insert character at cursor position.
  (edit_buffer_write_file): refactoring: return number of written bytes.
  (edit_buffer_write_file): new editor buffer API.
  (edit_buffer_read_file): refactoring: return number of read bytes.
  (edit_buffer_read_file): new editor buffer API.
  ...
This commit is contained in:
Andrew Borodin 2013-07-05 09:20:58 +04:00
commit 2b0c66bc1f
70 changed files with 2608 additions and 1608 deletions

View File

@ -4,6 +4,7 @@
#include "lib/global.h" /* include glib.h */
#include <sys/types.h>
#include <inttypes.h>
#include <string.h>
#ifdef HAVE_ASSERT_H
#include <assert.h> /* assert() */
@ -86,6 +87,20 @@ typedef enum
J_CENTER_LEFT_FIT = 0x14
} align_crt_t;
/* string-to-integer parsing results
*/
typedef enum
{
LONGINT_OK = 0,
/* These two values can be ORed together, to indicate that both errors occurred. */
LONGINT_OVERFLOW = 1,
LONGINT_INVALID_SUFFIX_CHAR = 2,
LONGINT_INVALID_SUFFIX_CHAR_WITH_OVERFLOW = (LONGINT_INVALID_SUFFIX_CHAR | LONGINT_OVERFLOW),
LONGINT_INVALID = 4
} strtol_error_t;
/*** structures declarations (and typedefs of structures)*****************************************/
/* all functions in str_class must be defined for every encoding */
@ -540,7 +555,13 @@ char *strrstr_skip_count (const char *haystack, const char *needle, size_t skip_
char *str_replace_all (const char *haystack, const char *needle, const char *replacement);
strtol_error_t xstrtoumax (const char *s, char **ptr, int base, uintmax_t * val,
const char *valid_suffixes);
uintmax_t parse_integer (const char *str, gboolean * invalid);
/* --------------------------------------------------------------------------------------------- */
/*** inline functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
static inline void
str_replace (char *s, char from, char to)
@ -552,6 +573,7 @@ str_replace (char *s, char from, char to)
}
}
/* --------------------------------------------------------------------------------------------- */
/*
* strcpy is unsafe on overlapping memory areas, so define memmove-alike
* string function.
@ -584,4 +606,6 @@ str_move (char *dest, const char *src)
return (char *) memmove (dest, src, n);
}
/* --------------------------------------------------------------------------------------------- */
#endif /* MC_STRUTIL_H */

View File

@ -7,6 +7,7 @@ libmcstrutil_la_SOURCES = \
strutilascii.c \
strutil.c \
strutilutf8.c \
strverscmp.c
strverscmp.c \
xstrtol.c
AM_CPPFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir)

View File

@ -832,3 +832,42 @@ strrstr_skip_count (const char *haystack, const char *needle, size_t skip_count)
}
/* --------------------------------------------------------------------------------------------- */
/* Interprete string as a non-negative decimal integer, optionally multiplied by various values.
*
* @param str input value
* @param invalid set to TRUE if "str" does not represent a number in this format
*
* @return non-integer representation of "str", 0 in case of error.
*/
uintmax_t
parse_integer (const char *str, gboolean * invalid)
{
uintmax_t n;
char *suffix;
strtol_error_t e;
e = xstrtoumax (str, &suffix, 10, &n, "bcEGkKMPTwYZ0");
if (e == LONGINT_INVALID_SUFFIX_CHAR && *suffix == 'x')
{
uintmax_t multiplier;
multiplier = parse_integer (suffix + 1, invalid);
if (multiplier != 0 && n * multiplier / multiplier != n)
{
*invalid = TRUE;
return 0;
}
n *= multiplier;
}
else if (e != LONGINT_OK)
{
*invalid = TRUE;
n = 0;
}
return n;
}
/* --------------------------------------------------------------------------------------------- */

238
lib/strutil/xstrtol.c Normal file
View File

@ -0,0 +1,238 @@
/* A more useful interface to strtol.
Copyright (C) 1995-1996, 1998-2001, 2003-2007, 2009-2012 Free Software
Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Jim Meyering. */
#include <config.h>
/* Some pre-ANSI implementations (e.g. SunOS 4)
need stderr defined if assertion checking is enabled. */
#include <stdio.h>
#ifdef HAVE_ASSERT_H
#include <assert.h>
#endif
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include "lib/strutil.h"
/*** global variables ****************************************************************************/
/*** file scope macro definitions ****************************************************************/
/*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
static strtol_error_t
bkm_scale (uintmax_t * x, int scale_factor)
{
if (UINTMAX_MAX / scale_factor < *x)
{
*x = UINTMAX_MAX;
return LONGINT_OVERFLOW;
}
*x *= scale_factor;
return LONGINT_OK;
}
/* --------------------------------------------------------------------------------------------- */
static strtol_error_t
bkm_scale_by_power (uintmax_t * x, int base, int power)
{
strtol_error_t err = LONGINT_OK;
while (power-- != 0)
err |= bkm_scale (x, base);
return err;
}
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
strtol_error_t
xstrtoumax (const char *s, char **ptr, int base, uintmax_t * val, const char *valid_suffixes)
{
char *t_ptr;
char **p;
uintmax_t tmp;
strtol_error_t err = LONGINT_OK;
#ifdef HAVE_ASSERT_H
assert (0 <= base && base <= 36);
#endif
p = (ptr != NULL ? ptr : &t_ptr);
{
const char *q = s;
unsigned char ch = *q;
while (isspace (ch))
ch = *++q;
if (ch == '-')
return LONGINT_INVALID;
}
errno = 0;
tmp = strtol (s, p, base);
if (*p == s)
{
/* If there is no number but there is a valid suffix, assume the
number is 1. The string is invalid otherwise. */
if (valid_suffixes != NULL && **p != '\0' && strchr (valid_suffixes, **p) != NULL)
tmp = 1;
else
return LONGINT_INVALID;
}
else if (errno != 0)
{
if (errno != ERANGE)
return LONGINT_INVALID;
err = LONGINT_OVERFLOW;
}
/* Let valid_suffixes == NULL mean "allow any suffix". */
/* FIXME: update all callers except the ones that allow suffixes
after the number, changing last parameter NULL to "". */
if (valid_suffixes == NULL)
{
*val = tmp;
return err;
}
if (**p != '\0')
{
int suffixes = 1;
strtol_error_t overflow;
if (strchr (valid_suffixes, **p) == NULL)
{
*val = tmp;
return err | LONGINT_INVALID_SUFFIX_CHAR;
}
base = 1024;
if (strchr (valid_suffixes, '0') != NULL)
{
/* The "valid suffix" '0' is a special flag meaning that
an optional second suffix is allowed, which can change
the base. A suffix "B" (e.g. "100MB") stands for a power
of 1000, whereas a suffix "iB" (e.g. "100MiB") stands for
a power of 1024. If no suffix (e.g. "100M"), assume
power-of-1024. */
switch (p[0][1])
{
case 'i':
if (p[0][2] == 'B')
suffixes += 2;
break;
case 'B':
case 'D': /* 'D' is obsolescent */
base = 1000;
suffixes++;
break;
}
}
switch (**p)
{
case 'b':
overflow = bkm_scale (&tmp, 512);
break;
case 'B':
overflow = bkm_scale (&tmp, 1024);
break;
case 'c':
overflow = 0;
break;
case 'E': /* exa or exbi */
overflow = bkm_scale_by_power (&tmp, base, 6);
break;
case 'G': /* giga or gibi */
case 'g': /* 'g' is undocumented; for compatibility only */
overflow = bkm_scale_by_power (&tmp, base, 3);
break;
case 'k': /* kilo */
case 'K': /* kibi */
overflow = bkm_scale_by_power (&tmp, base, 1);
break;
case 'M': /* mega or mebi */
case 'm': /* 'm' is undocumented; for compatibility only */
overflow = bkm_scale_by_power (&tmp, base, 2);
break;
case 'P': /* peta or pebi */
overflow = bkm_scale_by_power (&tmp, base, 5);
break;
case 'T': /* tera or tebi */
case 't': /* 't' is undocumented; for compatibility only */
overflow = bkm_scale_by_power (&tmp, base, 4);
break;
case 'w':
overflow = bkm_scale (&tmp, 2);
break;
case 'Y': /* yotta or 2**80 */
overflow = bkm_scale_by_power (&tmp, base, 8);
break;
case 'Z': /* zetta or 2**70 */
overflow = bkm_scale_by_power (&tmp, base, 7);
break;
default:
*val = tmp;
return err | LONGINT_INVALID_SUFFIX_CHAR;
}
err |= overflow;
*p += suffixes;
if (**p != '\0')
err |= LONGINT_INVALID_SUFFIX_CHAR;
}
*val = tmp;
return err;
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Slava Zanko <slavazanko@gmail.com>\n"
"Language-Team: Azerbaijani (http://www.transifex.com/projects/p/mc/language/"
@ -860,7 +860,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Павал Шаламіцкі <yehekim@gmail.com>\n"
"Language-Team: Belarusian (http://www.transifex.com/projects/p/mc/language/"
@ -924,8 +924,10 @@ msgstr "Немагчыма атрымаць памер або дазволы ф
msgid "\"%s\" is not a regular file"
msgstr "«%s» ня ёсьць звычайным файлам"
#, c-format
msgid "File \"%s\" is too large"
#, fuzzy, c-format
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr "Файл «%s» — завялікі"
#, c-format

View File

@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Yasen Pramatarov <yasen@lindeas.com>\n"
"Language-Team: Bulgarian (http://www.transifex.com/projects/p/mc/language/"
@ -860,8 +860,10 @@ msgstr ""
msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
#, fuzzy, c-format
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr "Файлът \"%s\" е твърде голям"
#, c-format

View File

@ -11,7 +11,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Daniel <danicases@gmail.com>\n"
"Language-Team: Catalan (http://www.transifex.com/projects/p/mc/language/"
@ -865,8 +865,10 @@ msgstr ""
msgid "\"%s\" is not a regular file"
msgstr "\"%s\" no és un fitxer estàndard"
#, c-format
msgid "File \"%s\" is too large"
#, fuzzy, c-format
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr "El fitxer \"%s\" és massa gran"
#, c-format

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Slava Zanko <slavazanko@gmail.com>\n"
"Language-Team: Czech (http://www.transifex.com/projects/p/mc/language/cs/)\n"
@ -880,8 +880,10 @@ msgstr "Nelze zjistit velikost/práva k souboru %s"
msgid "\"%s\" is not a regular file"
msgstr "„%s“ není normální soubor"
#, c-format
msgid "File \"%s\" is too large"
#, fuzzy, c-format
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr "Soubor „%s“ je příliš velký"
#, c-format

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Slava Zanko <slavazanko@gmail.com>\n"
"Language-Team: Danish (http://www.transifex.com/projects/p/mc/language/da/)\n"
@ -880,8 +880,10 @@ msgstr "Kan ikke indhente størrelse/tilladelser for %s"
msgid "\"%s\" is not a regular file"
msgstr "»%s« er ikke en regulær fil"
#, c-format
msgid "File \"%s\" is too large"
#, fuzzy, c-format
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr "Fil »%s« er for stor"
#, c-format

View File

@ -10,7 +10,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-17 11:42+0000\n"
"Last-Translator: Fabian Affolter <fab@fedoraproject.org>\n"
"Language-Team: German (http://www.transifex.com/projects/p/mc/language/de/)\n"
@ -902,8 +902,10 @@ msgstr "Kann Größe/Zugriffsrechte der Datei \"%s\" nicht ermitteln"
msgid "\"%s\" is not a regular file"
msgstr "\"%s\" ist keine normale Datei"
#, c-format
msgid "File \"%s\" is too large"
#, fuzzy, c-format
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr "Die Datei \"%s\" ist zu groß"
#, c-format

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Slava Zanko <slavazanko@gmail.com>\n"
"Language-Team: German (Switzerland) (http://www.transifex.com/projects/p/mc/"
@ -857,7 +857,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Panos Bouklis <panos@echidna-band.com>\n"
"Language-Team: Greek (http://www.transifex.com/projects/p/mc/language/el/)\n"
@ -883,8 +883,10 @@ msgstr "Αδυναμία λήψης του μεγέθους/αδειών για
msgid "\"%s\" is not a regular file"
msgstr "Το \"%s\" δεν είναι συνηθισμένο αρχείο"
#, c-format
msgid "File \"%s\" is too large"
#, fuzzy, c-format
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr "Το αρχείο \"%s\" είναι πολύ μεγάλο"
#, c-format

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 13:34+0000\n"
"Last-Translator: Keith Bowes <zooplah@gmail.com>\n"
"Language-Team: Esperanto (http://www.transifex.com/projects/p/mc/language/"
@ -919,8 +919,10 @@ msgstr "Ne eblas akiri grandon/permesojn por %s"
msgid "\"%s\" is not a regular file"
msgstr "\"%s\" estas ne normala dosiero"
#, c-format
msgid "File \"%s\" is too large"
#, fuzzy, c-format
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr "Dosiero \"%s\" estas tro granda"
#, c-format

View File

@ -12,7 +12,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: David Martin <david.martin@telefonica.net>\n"
"Language-Team: Spanish (http://www.transifex.com/projects/p/mc/language/"
@ -929,8 +929,10 @@ msgstr "Imposible obtener tamaño/permisos para %s"
msgid "\"%s\" is not a regular file"
msgstr "«%s» no es un archivo ordinario"
#, c-format
msgid "File \"%s\" is too large"
#, fuzzy, c-format
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr "El archivo «%s» es demasiado grande"
#, c-format

View File

@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2011-07-11 17:34+0000\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -855,7 +855,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Slava Zanko <slavazanko@gmail.com>\n"
"Language-Team: Basque (http://www.transifex.com/projects/p/mc/language/eu/)\n"
@ -901,8 +901,10 @@ msgstr "%s-ren neurria/baimenak ezin eskuratu"
msgid "\"%s\" is not a regular file"
msgstr "\"%s\" ez da fitxategi arrunta"
#, c-format
msgid "File \"%s\" is too large"
#, fuzzy, c-format
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr "\"%s\" fitxategia handiegia da"
#, c-format

View File

@ -11,7 +11,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Sina Saharkhiz <sinas1991@gmail.com>\n"
"Language-Team: Persian (http://www.transifex.com/projects/p/mc/language/"
@ -860,8 +860,10 @@ msgstr ""
msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
#, fuzzy, c-format
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr "فایل \"%s\" بیش از حد بزرگ است"
#, c-format

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Slava Zanko <slavazanko@gmail.com>\n"
"Language-Team: Finnish (http://www.transifex.com/projects/p/mc/language/"
@ -858,7 +858,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Slava Zanko <slavazanko@gmail.com>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -866,7 +866,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Stéphane Aulery <lkppo@free.fr>\n"
"Language-Team: French (http://www.transifex.com/projects/p/mc/language/fr/)\n"
@ -877,8 +877,10 @@ msgstr "Impossible d'obtenir la taille ou les permissions de %s"
msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
#, fuzzy, c-format
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr "Le fichier \"%s\" est trop grand"
#, c-format

View File

@ -12,7 +12,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-26 10:28+0000\n"
"Last-Translator: mbouzada <mbouzada@gmail.com>\n"
"Language-Team: Galician (http://www.transifex.com/projects/p/mc/language/"
@ -927,8 +927,10 @@ msgstr "Non é posíbel obter tamaño/permisos do ficheiro: %s"
msgid "\"%s\" is not a regular file"
msgstr "«%s» non é un ficheiro regular"
#, c-format
msgid "File \"%s\" is too large"
#, fuzzy, c-format
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr "O ficheiro «%s» é demasiado grande"
#, c-format

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2010-12-29 10:19+0000\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: Croatian (http://www.transifex.com/projects/p/mc/language/"
@ -858,7 +858,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Rezső Páder <rezso@rezso.net>\n"
"Language-Team: Hungarian (http://www.transifex.com/projects/p/mc/language/"
@ -927,8 +927,10 @@ msgstr "Méret/hozzáférés lekérdezése nem sikerült: %s"
msgid "\"%s\" is not a regular file"
msgstr "\"%s\": speciális fájl"
#, c-format
msgid "File \"%s\" is too large"
#, fuzzy, c-format
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr "A(z) \"%s\" fájl túl nagy"
#, c-format

View File

@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Martijn Dekker <mcdutchie@hotmail.com>\n"
"Language-Team: Interlingua (http://www.transifex.com/projects/p/mc/language/"
@ -880,8 +880,10 @@ msgstr "Impossibile obtener dimension/permissiones pro %s"
msgid "\"%s\" is not a regular file"
msgstr "\"%s\" non es un file regular"
#, c-format
msgid "File \"%s\" is too large"
#, fuzzy, c-format
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr "Le file \"%s\" es multo grande"
#, c-format

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Andika Triwidada <andika@gmail.com>\n"
"Language-Team: Indonesian (http://www.transifex.com/projects/p/mc/language/"
@ -867,7 +867,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -11,7 +11,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-05-03 00:01+0200\n"
"Last-Translator: Marco Ciampa <ciampix@libero.it>\n"
"Language-Team: Italian (http://www.transifex.com/projects/p/mc/language/"
@ -925,8 +925,10 @@ msgstr "Impossibile ottenere dimensioni/permessi per %s"
msgid "\"%s\" is not a regular file"
msgstr "\"%s\" non è un file normale"
#, c-format
msgid "File \"%s\" is too large"
#, fuzzy, c-format
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr "Il file \"%s\" è troppo grande"
#, c-format

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2011-12-07 11:21+0000\n"
"Last-Translator: slavazanko <slavazanko@gmail.com>\n"
"Language-Team: Italian (Italy) (http://www.transifex.net/projects/p/mc/team/"
@ -857,7 +857,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -11,7 +11,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Slava Zanko <slavazanko@gmail.com>\n"
"Language-Team: Japanese (http://www.transifex.com/projects/p/mc/language/"
@ -870,7 +870,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: George Machitidze <giomac@gmail.com>\n"
"Language-Team: Georgian (http://www.transifex.com/projects/p/mc/language/"
@ -858,7 +858,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Slava Zanko <slavazanko@gmail.com>\n"
"Language-Team: Korean (http://www.transifex.com/projects/p/mc/language/ko/)\n"
@ -863,7 +863,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Slava Zanko <slavazanko@gmail.com>\n"
"Language-Team: Lithuanian (http://www.transifex.com/projects/p/mc/language/"
@ -862,7 +862,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Slava Zanko <slavazanko@gmail.com>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -860,7 +860,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

577
po/mc.pot

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Slava Zanko <slavazanko@gmail.com>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -859,7 +859,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Slava Zanko <slavazanko@gmail.com>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -859,7 +859,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -13,7 +13,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-31 16:08+0000\n"
"Last-Translator: Richard E. van der Luit <nippur@fedoraproject.org>\n"
"Language-Team: Dutch (http://www.transifex.com/projects/p/mc/language/nl/)\n"
@ -920,8 +920,10 @@ msgstr "Kan geen grootte-/rechteninformatie verkrijgen voor %s"
msgid "\"%s\" is not a regular file"
msgstr "\"%s\" is geen normaal bestand"
#, c-format
msgid "File \"%s\" is too large"
#, fuzzy, c-format
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr "Bestand \"%s\" is te groot"
#, c-format

View File

@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 18:27+0000\n"
"Last-Translator: Piotr Drąg <piotrdrag@gmail.com>\n"
"Language-Team: Polish (http://www.transifex.com/projects/p/mc/language/pl/)\n"
@ -925,8 +925,10 @@ msgstr "Nie można uzyskać rozmiaru/uprawnień dla %s"
msgid "\"%s\" is not a regular file"
msgstr "\"%s\" nie jest zwykłym plikiem"
#, c-format
msgid "File \"%s\" is too large"
#, fuzzy, c-format
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr "Plik \"%s\" jest za duży"
#, c-format

View File

@ -10,7 +10,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Gilberto J <gmj125@gmail.com>\n"
"Language-Team: Portuguese (http://www.transifex.com/projects/p/mc/language/"
@ -925,8 +925,10 @@ msgstr "Não é possível obter tamanho/permissões para %s"
msgid "\"%s\" is not a regular file"
msgstr "\"%s\" não é um ficheiro regular"
#, c-format
msgid "File \"%s\" is too large"
#, fuzzy, c-format
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr "Ficheiro \"%s\" é demasiado grande"
#, c-format

View File

@ -11,7 +11,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Enrico Nicoletto <enrico.BR@gmx.co.uk>\n"
"Language-Team: Portuguese (Brazil) (http://www.transifex.com/projects/p/mc/"
@ -883,8 +883,10 @@ msgstr "Não foi possível obter tamanho/permissões para %s"
msgid "\"%s\" is not a regular file"
msgstr "\"%s\" não é um arquivo regular"
#, c-format
msgid "File \"%s\" is too large"
#, fuzzy, c-format
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr "Arquivo \"%s\" é muito grande"
#, c-format

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Slava Zanko <slavazanko@gmail.com>\n"
"Language-Team: Romanian (http://www.transifex.com/projects/p/mc/language/"
@ -861,7 +861,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -18,17 +18,15 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"PO-Revision-Date: 2013-06-16 08:43+0000\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-07-05 09:15+0300\n"
"Last-Translator: Andrew Borodin <aborodin@vmail.ru>\n"
"Language-Team: Russian (http://www.transifex.com/projects/p/mc/language/"
"ru/)\n"
"Language-Team: Russian (http://www.transifex.com/projects/p/mc/language/ru/)\n"
"Language: ru\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
msgid "Warning: cannot load codepages list"
msgstr "Внимание: невозможно загрузить список кодировок"
@ -117,8 +115,7 @@ msgid "Not implemented yet"
msgstr "Пока не реализовано"
msgid "Num of replace tokens not equal to num of found tokens"
msgstr ""
"Количество шаблонных полей не соответствует количеству полей для замены"
msgstr "Количество шаблонных полей не соответствует количеству полей для замены"
#, c-format
msgid "Invalid token number %d"
@ -616,8 +613,7 @@ msgid "Load definitions of key bindings from specified file"
msgstr "Чтение определений привязок клавиш из указанного файла"
msgid "Don't load definitions of key bindings from file, use defaults"
msgstr ""
"Не загружать привязки клавиш из файла, использовать привязки по умолчанию"
msgstr "Не загружать привязки клавиш из файла, использовать привязки по умолчанию"
msgid "Requests to run in black and white"
msgstr "Принудительно установить черно-белый режим"
@ -654,26 +650,22 @@ msgid ""
msgstr ""
"--colors КЛЮЧЕВОЕ_СЛОВО={ТЕКСТ},{ФОН},{АТРИБУТ}:КЛЮЧЕВОЕ_СЛОВО2=...\n"
"\n"
"{ТЕКСТ}, {ФОН} и {АТРИБУТ} можно опустить, чтобы использовать значения по "
"умолчанию\n"
"{ТЕКСТ}, {ФОН} и {АТРИБУТ} можно опустить, чтобы использовать значения по умолчанию\n"
"\n"
"Ключевые слова:\n"
" Общие: errors, disabled, reverse, gauge, header\n"
" input, inputmark, inputunchanged, commandlinemark\n"
" bbarhotkey, bbarbutton, statusbar\n"
" Отображение файлов: normal, selected, marked, markselect\n"
" Диалоги: dnormal, dfocus, dhotnormal, dhotfocus, "
"errdhotnormal,\n"
" Диалоги: dnormal, dfocus, dhotnormal, dhotfocus, errdhotnormal,\n"
" errdhotfocus\n"
" Меню: menunormal, menuhot, menusel, menuhotsel, "
"menuinactive\n"
" Меню: menunormal, menuhot, menusel, menuhotsel, menuinactive\n"
" Всплывающие меню: pmenunormal, pmenusel, pmenutitle\n"
" Редактор: editnormal, editbold, editmarked, editwhitespace,\n"
" editlinestate, editbg, editframe, editframeactive\n"
" editframedrag\n"
" Просмотрщик: viewbold, viewunderline, viewselected\n"
" Справка: helpnormal, helpitalic, helpbold, helplink, "
"helpslink\n"
" Справка: helpnormal, helpitalic, helpbold, helplink, helpslink\n"
#. TRANSLATORS: don't translate color names and attributes
msgid ""
@ -697,8 +689,7 @@ msgstr ""
" от color16 до color255 или от rgb000 до rgb555 и от gray0 до gray23\n"
"\n"
"Атрибуты:\n"
" bold, underline, reverse, blink; несколько атрибутов объединяются знаком "
"\"+\"\n"
" bold, underline, reverse, blink; несколько атрибутов объединяются знаком \"+\"\n"
msgid "Color options"
msgstr "Цветовые настройки"
@ -938,8 +929,12 @@ msgid "\"%s\" is not a regular file"
msgstr "\"%s\" не является обычным файлом"
#, c-format
msgid "File \"%s\" is too large"
msgstr "Файл \"%s\" слишком большой"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
"Файл \"%s\" слишком большой.\n"
"Всё равно открыть?"
#, c-format
msgid "Error reading from pipe: %s"
@ -2244,25 +2239,16 @@ msgid " %s%s file error"
msgstr "ошибка файла %s%s"
#, c-format
msgid ""
"The format of the %smc.ext file has changed with version 3.0. It seems that "
"the installation failed. Please fetch a fresh copy from the Midnight "
"Commander package."
msgstr ""
"Формат %smc.ext изменён с версии 3.0. Возможно, произошёл сбой при "
"установке. Пожалуйста, возьмите свежую копию из пакета Midnight Commander."
msgid "The format of the %smc.ext file has changed with version 3.0. It seems that the installation failed. Please fetch a fresh copy from the Midnight Commander package."
msgstr "Формат %smc.ext изменён с версии 3.0. Возможно, произошёл сбой при установке. Пожалуйста, возьмите свежую копию из пакета Midnight Commander."
#, c-format
msgid "%s file error"
msgstr "ошибка файла %s"
#, c-format
msgid ""
"The format of the %s file has changed with version 3.0. You may either want "
"to copy it from %smc.ext or use that file as an example of how to write it."
msgstr ""
"Формат файла %s изменён с версии 3.0. Вы можете либо скопировать его с %s/mc."
"ext, либо использовать этот файл как пример и написать свой."
msgid "The format of the %s file has changed with version 3.0. You may either want to copy it from %smc.ext or use that file as an example of how to write it."
msgstr "Формат файла %s изменён с версии 3.0. Вы можете либо скопировать его с %s/mc.ext, либо использовать этот файл как пример и написать свой."
msgid "DialogTitle|Copy"
msgstr "Копирование"
@ -2332,8 +2318,7 @@ msgid ""
"\n"
"Option Stable Symlinks will be disabled"
msgstr ""
"Невозможно создать устойчивые симв. ссылки через нелокальные файловые "
"системы:\n"
"Невозможно создать устойчивые симв. ссылки через нелокальные файловые системы:\n"
"\n"
"Опция \"Устойчивые символические ссылки\" будет отменена"
@ -4289,12 +4274,12 @@ msgstr ""
msgid "Cannot view: not a regular file"
msgstr "Просмотр невозможен: необычный файл"
#, fuzzy, c-format
#, c-format
msgid ""
"Cannot open \"%s\" in parse mode\n"
"%s"
msgstr ""
"Невозможно открыть \"%s\"\n"
"Невозможно открыть \"%s\" в режиме фильтра\n"
"%s"
msgid "Seeking to search result"
@ -4308,3 +4293,4 @@ msgstr "Продолжить с начала?"
msgid "Cannot fetch a local copy of /ftp://some.host/editme.txt"
msgstr "Невозможно получить локальную копию /ftp://some.host/editme.txt"

View File

@ -11,7 +11,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Jose Riha <jose1711@gmail.com>\n"
"Language-Team: Slovak (http://www.transifex.com/projects/p/mc/language/sk/)\n"
@ -870,7 +870,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -10,7 +10,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Slava Zanko <slavazanko@gmail.com>\n"
"Language-Team: Slovenian (http://www.transifex.com/projects/p/mc/language/"
@ -870,7 +870,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Slava Zanko <slavazanko@gmail.com>\n"
"Language-Team: Serbian (http://www.transifex.com/projects/p/mc/language/"
@ -861,7 +861,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Cybjit <cybjit@gmail.com>\n"
"Language-Team: Swedish (http://www.transifex.com/projects/p/mc/language/"
@ -861,7 +861,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2011-12-07 11:21+0000\n"
"Last-Translator: slavazanko <slavazanko@gmail.com>\n"
"Language-Team: Swedish (Sweden) (http://www.transifex.net/projects/p/mc/team/"
@ -857,7 +857,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Slava Zanko <slavazanko@gmail.com>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -857,7 +857,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Slava Zanko <slavazanko@gmail.com>\n"
"Language-Team: Turkish (http://www.transifex.com/projects/p/mc/language/"
@ -860,7 +860,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -10,7 +10,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: peinguin <pingvein@gmail.com>\n"
"Language-Team: Ukrainian (http://www.transifex.com/projects/p/mc/language/"
@ -924,8 +924,10 @@ msgstr "Не вдалося отримати розмір/права досту
msgid "\"%s\" is not a regular file"
msgstr "«%s» не є звичайним файлом"
#, c-format
msgid "File \"%s\" is too large"
#, fuzzy, c-format
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr "Файл «%s» завеликий"
#, c-format

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Slava Zanko <slavazanko@gmail.com>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -859,7 +859,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Slava Zanko <slavazanko@gmail.com>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -857,7 +857,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -10,7 +10,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Slava Zanko <slavazanko@gmail.com>\n"
"Language-Team: Chinese (China) (http://www.transifex.com/projects/p/mc/"
@ -902,8 +902,10 @@ msgstr "无法获取文件%s的大小和权限信息"
msgid "\"%s\" is not a regular file"
msgstr "\"%s\"不是一个常规文件"
#, c-format
msgid "File \"%s\" is too large"
#, fuzzy, c-format
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr "文件\"%s\"太大"
#, c-format

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Midnight Commander\n"
"Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
"POT-Creation-Date: 2013-06-27 16:02+0400\n"
"POT-Creation-Date: 2013-07-05 09:13+0400\n"
"PO-Revision-Date: 2013-03-13 08:51+0000\n"
"Last-Translator: Slava Zanko <slavazanko@gmail.com>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -859,7 +859,9 @@ msgid "\"%s\" is not a regular file"
msgstr ""
#, c-format
msgid "File \"%s\" is too large"
msgid ""
"File \"%s\" is too large.\n"
"Open it anyway?"
msgstr ""
#, c-format

View File

@ -9,8 +9,9 @@ endif
libedit_la_SOURCES = \
bookmark.c \
choosesyntax.c \
edit.c edit.h \
edit-impl.h \
edit.c edit.h \
editbuffer.c editbuffer.h \
editcmd.c \
editcmd_dialogs.c editcmd_dialogs.h \
editdraw.c \

View File

@ -39,33 +39,6 @@
#define EDIT_TOP_EXTREME option_edit_top_extreme
#define EDIT_BOTTOM_EXTREME option_edit_bottom_extreme
/*
* The editor keeps data in two arrays of buffers.
* All buffers have the same size, which must be a power of 2.
*/
/* Configurable: log2 of the buffer size in bytes */
#ifndef S_EDIT_BUF_SIZE
#define S_EDIT_BUF_SIZE 16
#endif
/* Size of the buffer */
#define EDIT_BUF_SIZE (((off_t) 1) << S_EDIT_BUF_SIZE)
/* Buffer mask (used to find cursor position relative to the buffer) */
#define M_EDIT_BUF_SIZE (EDIT_BUF_SIZE - 1)
/*
* Configurable: Maximal allowed number of buffers in each buffer array.
* This number can be increased for systems with enough physical memory.
*/
#ifndef MAXBUFF
#define MAXBUFF 1024
#endif
/* Maximal length of file that can be opened */
#define SIZE_LIMIT (EDIT_BUF_SIZE * (MAXBUFF - 2))
/* Initial size of the undo stack, in bytes */
#define START_STACK_SIZE 32
@ -180,12 +153,7 @@ void edit_menu_cmd (WDialog * h);
void user_menu (WEdit * edit, const char *menu_file, int selected_entry);
void edit_init_menu (struct WMenuBar *menubar);
void edit_save_mode_cmd (void);
int edit_get_byte (const WEdit * edit, off_t byte_index);
int edit_get_utf (const WEdit * edit, off_t byte_index, int *char_width);
long edit_count_lines (const WEdit * edit, off_t current, off_t upto);
off_t edit_move_forward (const WEdit * edit, off_t current, long lines, off_t upto);
off_t edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto);
off_t edit_move_backward (const WEdit * edit, off_t current, long lines);
void edit_scroll_screen_over_cursor (WEdit * edit);
void edit_render_keypress (WEdit * edit);
void edit_scroll_upward (WEdit * edit, long i);
@ -196,8 +164,6 @@ void edit_move_up (WEdit * edit, long i, gboolean do_scroll);
void edit_move_down (WEdit * edit, long i, gboolean do_scroll);
void edit_move_to_prev_col (WEdit * edit, off_t p);
long edit_get_col (const WEdit * edit);
off_t edit_bol (const WEdit * edit, off_t current);
off_t edit_eol (const WEdit * edit, off_t current);
void edit_update_curs_row (WEdit * edit);
void edit_update_curs_col (WEdit * edit);
void edit_find_bracket (WEdit * edit);
@ -253,9 +219,7 @@ gboolean edit_save_block (WEdit * edit, const char *filename, off_t start, off_t
gboolean edit_save_block_cmd (WEdit * edit);
gboolean edit_insert_file_cmd (WEdit * edit);
char *edit_get_word_from_pos (const WEdit * edit, off_t start_pos, off_t * start, gsize * len,
gsize * cut);
long edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath);
off_t edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath);
gboolean edit_load_back_cmd (WEdit * edit);
gboolean edit_load_forward_cmd (WEdit * edit);
void edit_block_process_cmd (WEdit * edit, int macro_number);
@ -314,12 +278,10 @@ void book_mark_restore (WEdit * edit, int color);
gboolean edit_line_is_blank (WEdit * edit, long line);
gboolean is_break_char (char c);
long edit_indent_width (const WEdit * edit, off_t p);
void edit_insert_indent (WEdit * edit, int indent);
void edit_options_dialog (WDialog * h);
void edit_syntax_dialog (WEdit * edit);
void edit_mail_dialog (WEdit * edit);
void format_paragraph (WEdit * edit, int force);
void format_paragraph (WEdit * edit, gboolean force);
/* either command or char_for_insertion must be passed as -1 */
void edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion);

File diff suppressed because it is too large Load Diff

View File

@ -47,6 +47,7 @@ extern int option_save_position;
extern int option_syntax_highlighting;
extern int option_group_undo;
extern char *option_backup_ext;
extern char *option_filesize_threshold;
extern int edit_confirm_save;

767
src/editor/editbuffer.c Normal file
View File

@ -0,0 +1,767 @@
/*
Editor text keep buffer.
Copyright (C) 2013
The Free Software Foundation, Inc.
Written by:
Andrew Borodin <aborodin@vmail.ru> 2013
This file is part of the Midnight Commander.
The Midnight Commander is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
The Midnight Commander is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file
* \brief Source: editor text keep buffer.
* \author Andrew Borodin
* \date 2013
*/
#include <config.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "lib/global.h"
#include "lib/vfs/vfs.h"
#include "edit-impl.h"
#include "editbuffer.h"
/* --------------------------------------------------------------------------------------------- */
/*-
*
* here's a quick sketch of the layout: (don't run this through indent.)
*
* |
* \0\0\0\0\0m e _ f i l e . \nf i n . \n|T h i s _ i s _ s o\0\0\0\0\0\0\0\0\0
* ______________________________________|______________________________________
* |
* ... | b2[2] | b2[1] | b2[0] | b1[0] | b1[1] | b1[2] | ...
* |-> |-> |-> |-> |-> |-> |
* |
* _<------------------------->|<----------------->_
* curs2 | curs1
* ^ | ^
* | ^|^ |
* cursor ||| cursor
* |||
* file end|||file beginning
* |
* |
*
* _
* This_is_some_file
* fin.
*
*
* This is called a "gab buffer".
* See also:
* http://en.wikipedia.org/wiki/Gap_buffer
* http://stackoverflow.com/questions/4199694/data-structure-for-text-editor
*/
/*** global variables ****************************************************************************/
/*** file scope macro definitions ****************************************************************/
/*
* The editor keeps data in two arrays of buffers.
* All buffers have the same size, which must be a power of 2.
*/
/* Configurable: log2 of the buffer size in bytes */
#ifndef S_EDIT_BUF_SIZE
#define S_EDIT_BUF_SIZE 16
#endif
/* Size of the buffer */
#define EDIT_BUF_SIZE (((off_t) 1) << S_EDIT_BUF_SIZE)
/* Buffer mask (used to find cursor position relative to the buffer) */
#define M_EDIT_BUF_SIZE (EDIT_BUF_SIZE - 1)
/*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/**
* Get pointer to byte at specified index
*
* @param buf pointer to editor buffer
* @param byte_index byte index
*
* @return NULL if byte_index is negative or larger than file size; pointer to byte otherwise.
*/
static char *
edit_buffer_get_byte_ptr (const edit_buffer_t * buf, off_t byte_index)
{
void *b;
if (byte_index >= (buf->curs1 + buf->curs2) || byte_index < 0)
return NULL;
if (byte_index >= buf->curs1)
{
off_t p;
p = buf->curs1 + buf->curs2 - byte_index - 1;
b = g_ptr_array_index (buf->b2, p >> S_EDIT_BUF_SIZE);
return (char *) b + EDIT_BUF_SIZE - 1 - (p & M_EDIT_BUF_SIZE);
}
b = g_ptr_array_index (buf->b1, byte_index >> S_EDIT_BUF_SIZE);
return (char *) b + (byte_index & M_EDIT_BUF_SIZE);
}
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/**
* Initialize editor buffers.
*
* @param buf pointer to editor buffer
*/
void
edit_buffer_init (edit_buffer_t * buf, off_t size)
{
buf->b1 = g_ptr_array_sized_new (32);
buf->b2 = g_ptr_array_sized_new (32);
buf->curs1 = 0;
buf->curs2 = 0;
buf->size = size;
buf->lines = 0;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Clean editor buffers.
*
* @param buf pointer to editor buffer
*/
void
edit_buffer_clean (edit_buffer_t * buf)
{
if (buf->b1 != NULL)
{
g_ptr_array_foreach (buf->b1, (GFunc) g_free, NULL);
g_ptr_array_free (buf->b1, TRUE);
}
if (buf->b2 != NULL)
{
g_ptr_array_foreach (buf->b2, (GFunc) g_free, NULL);
g_ptr_array_free (buf->b2, TRUE);
}
}
/* --------------------------------------------------------------------------------------------- */
/**
* Get byte at specified index
*
* @param buf pointer to editor buffer
* @param byte_index byte index
*
* @return '\n' if byte_index is negative or larger than file size; byte at byte_index otherwise.
*/
int
edit_buffer_get_byte (const edit_buffer_t * buf, off_t byte_index)
{
char *p;
p = edit_buffer_get_byte_ptr (buf, byte_index);
return (p != NULL) ? *(unsigned char *) p : '\n';
}
/* --------------------------------------------------------------------------------------------- */
#ifdef HAVE_CHARSET
/**
* Get utf-8 symbol at specified index
*
* @param buf pointer to editor buffer
* @param byte_index byte index
* @param char_width width of returned symbol
*
* @return '\n' if byte_index is negative or larger than file size;
* 0 if utf-8 symbol at specified index is invalid;
* utf-8 symbol otherwise
*/
int
edit_buffer_get_utf (const edit_buffer_t * buf, off_t byte_index, int *char_width)
{
gchar *str = NULL;
gunichar res;
gunichar ch;
gchar *next_ch = NULL;
if (byte_index >= (buf->curs1 + buf->curs2) || byte_index < 0)
{
*char_width = 0;
return '\n';
}
str = edit_buffer_get_byte_ptr (buf, byte_index);
if (str == NULL)
{
*char_width = 0;
return 0;
}
res = g_utf8_get_char_validated (str, -1);
if (res == (gunichar) (-2) || res == (gunichar) (-1))
{
/* Retry with explicit bytes to make sure it's not a buffer boundary */
size_t i;
gchar utf8_buf[UTF8_CHAR_LEN + 1];
for (i = 0; i < UTF8_CHAR_LEN; i++)
utf8_buf[i] = edit_buffer_get_byte (buf, byte_index + i);
utf8_buf[i] = '\0';
res = g_utf8_get_char_validated (utf8_buf, -1);
}
if (res == (gunichar) (-2) || res == (gunichar) (-1))
{
ch = *str;
*char_width = 0;
}
else
{
ch = res;
/* Calculate UTF-8 char width */
next_ch = g_utf8_next_char (str);
if (next_ch != NULL)
*char_width = next_ch - str;
else
{
ch = 0;
*char_width = 0;
}
}
return (int) ch;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Get utf-8 symbol before specified index
*
* @param buf pointer to editor buffer
* @param byte_index byte index
* @param char_width width of returned symbol
*
* @return 0 if byte_index is negative or larger than file size;
* 1-byte value before specified index if utf-8 symbol before specified index is invalid;
* utf-8 symbol otherwise
*/
int
edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int *char_width)
{
size_t i;
gchar utf8_buf[3 * UTF8_CHAR_LEN + 1];
gchar *str;
gchar *cursor_buf_ptr;
gunichar res;
if (byte_index > (buf->curs1 + buf->curs2) || byte_index <= 0)
{
*char_width = 0;
return 0;
}
for (i = 0; i < (3 * UTF8_CHAR_LEN); i++)
utf8_buf[i] = edit_buffer_get_byte (buf, byte_index + i - (2 * UTF8_CHAR_LEN));
utf8_buf[i] = '\0';
cursor_buf_ptr = utf8_buf + (2 * UTF8_CHAR_LEN);
str = g_utf8_find_prev_char (utf8_buf, cursor_buf_ptr);
if (str == NULL || g_utf8_next_char (str) != cursor_buf_ptr)
{
*char_width = 1;
return *(cursor_buf_ptr - 1);
}
res = g_utf8_get_char_validated (str, -1);
if (res == (gunichar) (-2) || res == (gunichar) (-1))
{
*char_width = 1;
return *(cursor_buf_ptr - 1);
}
*char_width = cursor_buf_ptr - str;
return (int) res;
}
#endif /* HAVE_CHARSET */
/* --------------------------------------------------------------------------------------------- */
/**
* Count lines in editor buffer.
*
* @param buf editor buffer
* @param first start byte offset
* @param last finish byte offset
*
* @return line numbers between "first" and "last" bytes
*/
long
edit_buffer_count_lines (const edit_buffer_t * buf, off_t first, off_t last)
{
long lines = 0;
first = max (first, 0);
last = min (last, buf->size);
while (first < last)
if (edit_buffer_get_byte (buf, first++) == '\n')
lines++;
return lines;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Get "begin-of-line" offset of line contained specified byte offset
*
* @param buf editor buffer
* @param current byte offset
*
* @return index of first char of line
*/
off_t
edit_buffer_get_bol (const edit_buffer_t * buf, off_t current)
{
if (current <= 0)
return 0;
for (; edit_buffer_get_byte (buf, current - 1) != '\n'; current--)
;
return current;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Get "end-of-line" offset of line contained specified byte offset
*
* @param buf editor buffer
* @param current byte offset
*
* @return index of last char of line + 1
*/
off_t
edit_buffer_get_eol (const edit_buffer_t * buf, off_t current)
{
if (current >= buf->size)
return buf->size;
for (; edit_buffer_get_byte (buf, current) != '\n'; current++)
;
return current;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Get word from specified offset.
*
* @param buf editor buffer
* @param current start_pos offset
* @param start actual start word ofset
* @param cut
*
* @return word as newly allocated object
*/
GString *
edit_buffer_get_word_from_pos (const edit_buffer_t * buf, off_t start_pos, off_t * start,
gsize * cut)
{
off_t word_start;
long cut_len = 0;
GString *match_expr;
int c1, c2;
for (word_start = start_pos; word_start != 0; word_start--, cut_len++)
{
c1 = edit_buffer_get_byte (buf, word_start);
c2 = edit_buffer_get_byte (buf, word_start - 1);
if (is_break_char (c1) != is_break_char (c2) || c1 == '\n' || c2 == '\n')
break;
}
match_expr = g_string_sized_new (16);
do
{
c1 = edit_buffer_get_byte (buf, word_start + match_expr->len);
c2 = edit_buffer_get_byte (buf, word_start + match_expr->len + 1);
g_string_append_c (match_expr, c1);
}
while (!(is_break_char (c1) != is_break_char (c2) || c1 == '\n' || c2 == '\n'));
*start = word_start;
*cut = cut_len;
return match_expr;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Basic low level single character buffer alterations and movements at the cursor: insert character
* at the cursor position and move right.
*
* @param buf pointer to editor buffer
* @param c character to insert
*/
void
edit_buffer_insert (edit_buffer_t * buf, int c)
{
void *b;
off_t i;
i = buf->curs1 & M_EDIT_BUF_SIZE;
/* add a new buffer if we've reached the end of the last one */
if (i == 0)
g_ptr_array_add (buf->b1, g_malloc0 (EDIT_BUF_SIZE));
/* perform the insertion */
b = g_ptr_array_index (buf->b1, buf->curs1 >> S_EDIT_BUF_SIZE);
*((unsigned char *) b + i) = (unsigned char) c;
/* update cursor position */
buf->curs1++;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Basic low level single character buffer alterations and movements at the cursor: insert character
* at the cursor position and move left.
*
* @param buf pointer to editor buffer
* @param c character to insert
*/
void
edit_buffer_insert_ahead (edit_buffer_t * buf, int c)
{
void *b;
off_t i;
i = buf->curs2 & M_EDIT_BUF_SIZE;
/* add a new buffer if we've reached the end of the last one */
if (i == 0)
g_ptr_array_add (buf->b2, g_malloc0 (EDIT_BUF_SIZE));
/* perform the insertion */
b = g_ptr_array_index (buf->b2, buf->curs2 >> S_EDIT_BUF_SIZE);
*((unsigned char *) b + EDIT_BUF_SIZE - 1 - i) = (unsigned char) c;
/* update cursor position */
buf->curs2++;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Basic low level single character buffer alterations and movements at the cursor: delete character
* at the cursor position.
*
* @param buf pointer to editor buffer
* @param c character to insert
*/
int
edit_buffer_delete (edit_buffer_t * buf)
{
void *b;
unsigned char c;
off_t prev;
off_t i;
prev = buf->curs2 - 1;
b = g_ptr_array_index (buf->b2, prev >> S_EDIT_BUF_SIZE);
i = prev & M_EDIT_BUF_SIZE;
c = *((unsigned char *) b + EDIT_BUF_SIZE - 1 - i);
if (i == 0)
{
i = buf->b2->len - 1;
b = g_ptr_array_index (buf->b2, i);
g_ptr_array_remove_index (buf->b2, i);
g_free (b);
}
buf->curs2 = prev;
return c;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Basic low level single character buffer alterations and movements at the cursor: delete character
* before the cursor position and move left.
*
* @param buf pointer to editor buffer
* @param c character to insert
*/
int
edit_buffer_backspace (edit_buffer_t * buf)
{
void *b;
unsigned char c;
off_t prev;
off_t i;
prev = buf->curs1 - 1;
b = g_ptr_array_index (buf->b1, prev >> S_EDIT_BUF_SIZE);
i = prev & M_EDIT_BUF_SIZE;
c = *((unsigned char *) b + i);
if (i == 0)
{
i = buf->b1->len - 1;
b = g_ptr_array_index (buf->b1, i);
g_ptr_array_remove_index (buf->b1, i);
g_free (b);
}
buf->curs1 = prev;
return c;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Calculate forward offset with specified number of lines.
*
* @param buf editor buffer
* @param current current offset
* @param lines number of lines to move forward
* @param upto offset to count lines between current and upto.
*
* @return If lines is zero returns the count of lines from current to upto.
* If upto is zero returns offset of lines forward current.
* Else returns forward offset with specified number of lines
*/
off_t
edit_buffer_move_forward (const edit_buffer_t * buf, off_t current, long lines, off_t upto)
{
long next;
if (upto != 0)
return (off_t) edit_buffer_count_lines (buf, current, upto);
lines = max (lines, 0);
while (lines-- != 0)
{
next = edit_buffer_get_eol (buf, current) + 1;
if (next > buf->size)
break;
current = next;
}
return current;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Calculate backward offset with specified number of lines.
*
* @param buf editor buffer
* @param current current offset
* @param lines number of lines to move bacward
*
* @return backward offset with specified number of lines.
*/
off_t
edit_buffer_move_backward (const edit_buffer_t * buf, off_t current, long lines)
{
lines = max (lines, 0);
current = edit_buffer_get_bol (buf, current);
while (lines-- != 0 && current != 0)
current = edit_buffer_get_bol (buf, current - 1);
return current;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Load file into editor buffer
*
* @param buf pointer to editor buffer
* @param fd file descriptor
* @param size file size
*
* @return number of read bytes
*/
off_t
edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size)
{
off_t ret = 0;
off_t i;
off_t data_size;
void *b;
buf->curs2 = size;
i = buf->curs2 >> S_EDIT_BUF_SIZE;
/* fill last part of b2 */
data_size = buf->curs2 & M_EDIT_BUF_SIZE;
if (data_size != 0)
{
b = g_malloc0 (EDIT_BUF_SIZE);
g_ptr_array_add (buf->b2, b);
ret = mc_read (fd, (char *) b + EDIT_BUF_SIZE - data_size, data_size);
if (ret < 0 || ret != data_size)
return ret;
}
/* fullfill other parts of b2 from end to begin */
data_size = EDIT_BUF_SIZE;
for (--i; i >= 0; i--)
{
off_t sz;
b = g_malloc0 (data_size);
g_ptr_array_add (buf->b2, b);
sz = mc_read (fd, b, data_size);
if (sz >= 0)
ret += sz;
if (sz != data_size)
break;
}
/* reverse buffer */
for (i = 0; i < buf->b2->len / 2; i++)
{
void **b1, **b2;
b1 = &g_ptr_array_index (buf->b2, i);
b2 = &g_ptr_array_index (buf->b2, buf->b2->len - 1 - i);
b = *b1;
*b1 = *b2;
*b2 = b;
}
return ret;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Write editor buffer content to file
*
* @param buf pointer to editor buffer
* @param fd file descriptor
*
* @return number of written bytes
*/
off_t
edit_buffer_write_file (edit_buffer_t * buf, int fd)
{
off_t ret = 0;
off_t i;
off_t data_size, sz;
void *b;
/* write all fullfilled parts of b1 from begin to end */
if (buf->b1->len != 0)
{
data_size = EDIT_BUF_SIZE;
for (i = 0; i < (off_t) buf->b1->len - 1; i++)
{
b = g_ptr_array_index (buf->b1, i);
sz = mc_write (fd, b, data_size);
if (sz >= 0)
ret += sz;
else if (i == 0)
ret = sz;
if (sz != data_size)
return ret;
}
/* write last partially filled part of b1 */
data_size = ((buf->curs1 - 1) & M_EDIT_BUF_SIZE) + 1;
b = g_ptr_array_index (buf->b1, i);
sz = mc_write (fd, b, data_size);
if (sz >= 0)
ret += sz;
if (sz != data_size)
return ret;
}
/* write b2 from end to begin, if b2 contains some data */
if (buf->b2->len != 0)
{
/* write last partially filled part of b2 */
i = buf->b2->len - 1;
b = g_ptr_array_index (buf->b2, i);
data_size = ((buf->curs2 - 1) & M_EDIT_BUF_SIZE) + 1;
sz = mc_write (fd, (char *) b + EDIT_BUF_SIZE - data_size, data_size);
if (sz >= 0)
ret += sz;
if (sz == data_size)
{
/* write other fullfilled parts of b2 from end to begin */
data_size = EDIT_BUF_SIZE;
while (--i >= 0)
{
b = g_ptr_array_index (buf->b2, i);
sz = mc_write (fd, b, data_size);
if (sz >= 0)
ret += sz;
if (sz != data_size)
break;
}
}
}
return ret;
}
/* --------------------------------------------------------------------------------------------- */

102
src/editor/editbuffer.h Normal file
View File

@ -0,0 +1,102 @@
/** \file
* \brief Header: text keep buffer for WEdit
*/
#ifndef MC__EDIT_BUFFER_H
#define MC__EDIT_BUFFER_H
/*** typedefs(not structures) and defined constants **********************************************/
/*** enums ***************************************************************************************/
/*** structures declarations (and typedefs of structures)*****************************************/
typedef struct edit_buffer_struct
{
off_t curs1; /* position of the cursor from the beginning of the file. */
off_t curs2; /* position from the end of the file */
GPtrArray *b1; /* all data up to curs1 */
GPtrArray *b2; /* all data from end of file down to curs2 */
off_t size; /* file size */
long lines; /* total lines in the file */
long curs_line; /* line number of the cursor. */
} edit_buffer_t;
/*** global variables defined in .c file *********************************************************/
/*** declarations of public functions ************************************************************/
void edit_buffer_init (edit_buffer_t * buf, off_t size);
void edit_buffer_clean (edit_buffer_t * buf);
int edit_buffer_get_byte (const edit_buffer_t * buf, off_t byte_index);
#ifdef HAVE_CHARSET
int edit_buffer_get_utf (const edit_buffer_t * buf, off_t byte_index, int *char_width);
int edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int *char_width);
#endif
long edit_buffer_count_lines (const edit_buffer_t * buf, off_t first, off_t last);
off_t edit_buffer_get_bol (const edit_buffer_t * buf, off_t current);
off_t edit_buffer_get_eol (const edit_buffer_t * buf, off_t current);
GString *edit_buffer_get_word_from_pos (const edit_buffer_t * buf, off_t start_pos, off_t * start,
gsize * cut);
void edit_buffer_insert (edit_buffer_t * buf, int c);
void edit_buffer_insert_ahead (edit_buffer_t * buf, int c);
int edit_buffer_delete (edit_buffer_t * buf);
int edit_buffer_backspace (edit_buffer_t * buf);
off_t edit_buffer_move_forward (const edit_buffer_t * buf, off_t current, long lines, off_t upto);
off_t edit_buffer_move_backward (const edit_buffer_t * buf, off_t current, long lines);
off_t edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size);
off_t edit_buffer_write_file (edit_buffer_t * buf, int fd);
/*** inline functions ****************************************************************************/
static inline int
edit_buffer_get_current_byte (const edit_buffer_t * buf)
{
return edit_buffer_get_byte (buf, buf->curs1);
}
/* --------------------------------------------------------------------------------------------- */
static inline int
edit_buffer_get_previous_byte (const edit_buffer_t * buf)
{
return edit_buffer_get_byte (buf, buf->curs1 - 1);
}
/* --------------------------------------------------------------------------------------------- */
/**
* Get "begin-of-line" offset of current line
*
* @param buf editor buffer
*
* @return index of first char of current line
*/
static inline off_t
edit_buffer_get_current_bol (const edit_buffer_t * buf)
{
return edit_buffer_get_bol (buf, buf->curs1);
}
/* --------------------------------------------------------------------------------------------- */
/**
* Get "end-of-line" offset of current line
*
* @param buf editor buffer
*
* @return index of first char of current line + 1
*/
static inline off_t
edit_buffer_get_current_eol (const edit_buffer_t * buf)
{
return edit_buffer_get_eol (buf, buf->curs1);
}
/* --------------------------------------------------------------------------------------------- */
#endif /* MC__EDIT_BUFFER_H */

View File

@ -309,52 +309,15 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath)
}
else if (edit->lb == LB_ASIS)
{ /* do not change line breaks */
off_t buf;
buf = 0;
filelen = edit->last_byte;
while (buf <= (edit->curs1 >> S_EDIT_BUF_SIZE) - 1)
{
if (mc_write (fd, (char *) edit->buffers1[buf], EDIT_BUF_SIZE) != EDIT_BUF_SIZE)
{
mc_close (fd);
goto error_save;
}
buf++;
}
if (mc_write
(fd, (char *) edit->buffers1[buf],
edit->curs1 & M_EDIT_BUF_SIZE) != (edit->curs1 & M_EDIT_BUF_SIZE))
{
filelen = -1;
}
else if (edit->curs2)
{
edit->curs2--;
buf = (edit->curs2 >> S_EDIT_BUF_SIZE);
if (mc_write
(fd,
(char *) edit->buffers2[buf] + EDIT_BUF_SIZE -
(edit->curs2 & M_EDIT_BUF_SIZE) - 1,
1 + (edit->curs2 & M_EDIT_BUF_SIZE)) != 1 + (edit->curs2 & M_EDIT_BUF_SIZE))
{
filelen = -1;
}
else
{
while (--buf >= 0)
{
if (mc_write (fd, (char *) edit->buffers2[buf], EDIT_BUF_SIZE) != EDIT_BUF_SIZE)
{
filelen = -1;
break;
}
}
}
edit->curs2++;
}
if (mc_close (fd))
goto error_save;
filelen = edit_buffer_write_file (&edit->buffer, fd);
if (filelen != edit->buffer.size)
{
mc_close (fd);
goto error_save;
}
if (mc_close (fd) != 0)
goto error_save;
/* Update the file information, especially the mtime. */
if (mc_stat (savename_vpath, &edit->stat1) == -1)
goto error_save;
@ -384,7 +347,7 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath)
}
}
if (filelen != edit->last_byte)
if (filelen != edit->buffer.size)
goto error_save;
if (this_save_mode == EDIT_DO_BACKUP)
@ -430,13 +393,13 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath)
/* --------------------------------------------------------------------------------------------- */
static gboolean
edit_check_newline (WEdit * edit)
edit_check_newline (const edit_buffer_t * buf)
{
return !(option_check_nl_at_eof && edit->last_byte > 0
&& edit_get_byte (edit, edit->last_byte - 1) != '\n'
return !(option_check_nl_at_eof && buf->size > 0
&& edit_buffer_get_byte (buf, buf->size - 1) != '\n'
&& edit_query_dialog2 (_("Warning"),
_("The file you are saving is not finished with a newline"),
_("C&ontinue"), _("&Cancel")));
_("C&ontinue"), _("&Cancel")) != 0);
}
/* --------------------------------------------------------------------------------------------- */
@ -548,32 +511,34 @@ edit_delete_column_of_text (WEdit * edit)
long b, c, d;
eval_marks (edit, &m1, &m2);
n = edit_move_forward (edit, m1, 0, m2) + 1;
c = (long) edit_move_forward3 (edit, edit_bol (edit, m1), 0, m1);
d = (long) edit_move_forward3 (edit, edit_bol (edit, m2), 0, m2);
n = edit_buffer_move_forward (&edit->buffer, m1, 0, m2) + 1;
c = (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, m1), 0, m1);
d = (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, m2), 0, m2);
b = max (min (c, d), min (edit->column1, edit->column2));
c = max (c, max (edit->column1, edit->column2));
while (n--)
{
r = edit_bol (edit, edit->curs1);
r = edit_buffer_get_current_bol (&edit->buffer);
p = edit_move_forward3 (edit, r, b, 0);
q = edit_move_forward3 (edit, r, c, 0);
if (p < m1)
p = m1;
if (q > m2)
q = m2;
edit_cursor_move (edit, p - edit->curs1);
edit_cursor_move (edit, p - edit->buffer.curs1);
while (q > p)
{
/* delete line between margins */
if (edit_get_byte (edit, edit->curs1) != '\n')
if (edit_buffer_get_current_byte (&edit->buffer) != '\n')
edit_delete (edit, TRUE);
q--;
}
if (n)
/* move to next line except on the last delete */
edit_cursor_move (edit, edit_move_forward (edit, edit->curs1, 1, 0) - edit->curs1);
edit_cursor_move (edit,
edit_buffer_move_forward (&edit->buffer, edit->buffer.curs1, 1,
0) - edit->buffer.curs1);
}
}
@ -610,12 +575,12 @@ edit_block_delete (WEdit * edit)
edit_push_markers (edit);
curs_line = edit->curs_line;
curs_line = edit->buffer.curs_line;
curs_pos = edit->curs_col + edit->over_col;
/* move cursor to start of selection */
edit_cursor_move (edit, start_mark - edit->curs1);
edit_cursor_move (edit, start_mark - edit->buffer.curs1);
edit_scroll_screen_over_cursor (edit);
if (start_mark < end_mark)
@ -630,8 +595,8 @@ edit_block_delete (WEdit * edit)
/* move cursor to the saved position */
edit_move_to_line (edit, curs_line);
/* calculate line width and cursor position before cut */
line_width = edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0,
edit_eol (edit, edit->curs1));
line_width = edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 0,
edit_buffer_get_current_eol (&edit->buffer));
if (option_cursor_beyond_eol && curs_pos > line_width)
edit->over_col = curs_pos - line_width;
}
@ -696,7 +661,7 @@ edit_get_search_line_type (mc_search_t * search)
/**
* Calculating the start position of next line.
*
* @param edit editor object
* @param buf editor buffer object
* @param current_pos current position
* @param max_pos max position
* @param end_string_symbol end of line symbol
@ -704,7 +669,7 @@ edit_get_search_line_type (mc_search_t * search)
*/
static off_t
edit_calculate_start_of_next_line (WEdit * edit, off_t current_pos, off_t max_pos,
edit_calculate_start_of_next_line (const edit_buffer_t * buf, off_t current_pos, off_t max_pos,
char end_string_symbol)
{
off_t i;
@ -712,7 +677,7 @@ edit_calculate_start_of_next_line (WEdit * edit, off_t current_pos, off_t max_po
for (i = current_pos; i < max_pos; i++)
{
current_pos++;
if (edit_get_byte (edit, i) == end_string_symbol)
if (edit_buffer_get_byte (buf, i) == end_string_symbol)
break;
}
@ -723,19 +688,20 @@ edit_calculate_start_of_next_line (WEdit * edit, off_t current_pos, off_t max_po
/**
* Calculating the end position of previous line.
*
* @param edit editor object
* @param buf editor buffer object
* @param current_pos current position
* @param end_string_symbol end of line symbol
* @return end position of previous line
*/
static off_t
edit_calculate_end_of_previous_line (WEdit * edit, off_t current_pos, char end_string_symbol)
edit_calculate_end_of_previous_line (const edit_buffer_t * buf, off_t current_pos,
char end_string_symbol)
{
off_t i;
for (i = current_pos - 1; i >= 0; i--)
if (edit_get_byte (edit, i) == end_string_symbol)
if (edit_buffer_get_byte (buf, i) == end_string_symbol)
break;
return i;
@ -745,17 +711,18 @@ edit_calculate_end_of_previous_line (WEdit * edit, off_t current_pos, char end_s
/**
* Calculating the start position of previous line.
*
* @param edit editor object
* @param buf editor buffer object
* @param current_pos current position
* @param end_string_symbol end of line symbol
* @return start position of previous line
*/
static inline off_t
edit_calculate_start_of_previous_line (WEdit * edit, off_t current_pos, char end_string_symbol)
edit_calculate_start_of_previous_line (const edit_buffer_t * buf, off_t current_pos,
char end_string_symbol)
{
current_pos = edit_calculate_end_of_previous_line (edit, current_pos, end_string_symbol);
current_pos = edit_calculate_end_of_previous_line (edit, current_pos, end_string_symbol);
current_pos = edit_calculate_end_of_previous_line (buf, current_pos, end_string_symbol);
current_pos = edit_calculate_end_of_previous_line (buf, current_pos, end_string_symbol);
return (current_pos + 1);
}
@ -764,16 +731,17 @@ edit_calculate_start_of_previous_line (WEdit * edit, off_t current_pos, char end
/**
* Calculating the start position of current line.
*
* @param edit editor object
* @param buf editor buffer object
* @param current_pos current position
* @param end_string_symbol end of line symbol
* @return start position of current line
*/
static inline off_t
edit_calculate_start_of_current_line (WEdit * edit, off_t current_pos, char end_string_symbol)
edit_calculate_start_of_current_line (const edit_buffer_t * buf, off_t current_pos,
char end_string_symbol)
{
current_pos = edit_calculate_end_of_previous_line (edit, current_pos, end_string_symbol);
current_pos = edit_calculate_end_of_previous_line (buf, current_pos, end_string_symbol);
return (current_pos + 1);
}
@ -817,7 +785,7 @@ editcmd_find (WEdit * edit, gsize * len)
off_t search_start = edit->search_start;
off_t search_end;
off_t start_mark = 0;
off_t end_mark = edit->last_byte;
off_t end_mark = edit->buffer.size;
int mark_res = 0;
char end_string_symbol;
@ -836,18 +804,18 @@ editcmd_find (WEdit * edit, gsize * len)
/* fix the start and the end of search block positions */
if ((edit->search_line_type & AT_START_LINE) != 0
&& (start_mark != 0 || edit_get_byte (edit, start_mark - 1) != end_string_symbol))
&& (start_mark != 0
|| edit_buffer_get_byte (&edit->buffer, start_mark - 1) != end_string_symbol))
{
start_mark =
edit_calculate_start_of_next_line (edit, start_mark, edit->last_byte,
edit_calculate_start_of_next_line (&edit->buffer, start_mark, edit->buffer.size,
end_string_symbol);
}
if ((edit->search_line_type & AT_END_LINE) != 0
&& (end_mark - 1 != edit->last_byte
|| edit_get_byte (edit, end_mark) != end_string_symbol))
{
end_mark = edit_calculate_end_of_previous_line (edit, end_mark, end_string_symbol);
}
&& (end_mark - 1 != edit->buffer.size
|| edit_buffer_get_byte (&edit->buffer, end_mark) != end_string_symbol))
end_mark =
edit_calculate_end_of_previous_line (&edit->buffer, end_mark, end_string_symbol);
if (start_mark >= end_mark)
{
edit->search->error = MC_SEARCH_E_NOTFOUND;
@ -858,7 +826,7 @@ editcmd_find (WEdit * edit, gsize * len)
else
{
if (edit_search_options.backwards)
end_mark = max (1, edit->curs1) - 1;
end_mark = max (1, edit->buffer.curs1) - 1;
}
/* search */
@ -869,7 +837,8 @@ editcmd_find (WEdit * edit, gsize * len)
if ((edit->search_line_type & AT_START_LINE) != 0)
search_start =
edit_calculate_start_of_current_line (edit, search_start, end_string_symbol);
edit_calculate_start_of_current_line (&edit->buffer, search_start,
end_string_symbol);
while (search_start >= start_mark)
{
@ -887,7 +856,8 @@ editcmd_find (WEdit * edit, gsize * len)
if ((edit->search_line_type & AT_START_LINE) != 0)
search_start =
edit_calculate_start_of_previous_line (edit, search_start, end_string_symbol);
edit_calculate_start_of_previous_line (&edit->buffer, search_start,
end_string_symbol);
else
search_start--;
}
@ -898,7 +868,8 @@ editcmd_find (WEdit * edit, gsize * len)
/* forward search */
if ((edit->search_line_type & AT_START_LINE) != 0 && search_start != start_mark)
search_start =
edit_calculate_start_of_next_line (edit, search_start, end_mark, end_string_symbol);
edit_calculate_start_of_next_line (&edit->buffer, search_start, end_mark,
end_string_symbol);
return mc_search_run (edit->search, (void *) edit, search_start, end_mark, len);
}
return FALSE;
@ -950,7 +921,7 @@ edit_do_search (WEdit * edit)
gsize len = 0;
if (edit->search == NULL)
edit->search_start = edit->curs1;
edit->search_start = edit->buffer.curs1;
edit_push_undo_action (edit, KEY_PRESS + edit->start_display);
@ -963,12 +934,12 @@ edit_do_search (WEdit * edit)
search_create_bookmark = FALSE;
book_mark_flush (edit, -1);
while (mc_search_run (edit->search, (void *) edit, q, edit->last_byte, &len))
while (mc_search_run (edit->search, (void *) edit, q, edit->buffer.size, &len))
{
if (found == 0)
edit->search_start = edit->search->normal_offset;
found++;
l += edit_count_lines (edit, q, edit->search->normal_offset);
l += edit_buffer_count_lines (&edit->buffer, q, edit->search->normal_offset);
if (l != l_last)
{
book_mark_insert (edit, l, BOOK_MARK_FOUND_COLOR);
@ -981,7 +952,7 @@ edit_do_search (WEdit * edit)
if (found == 0)
edit_error_dialog (_("Search"), _("Search string not found"));
else
edit_cursor_move (edit, edit->search_start - edit->curs1);
edit_cursor_move (edit, edit->search_start - edit->buffer.curs1);
}
else
{
@ -998,7 +969,7 @@ edit_do_search (WEdit * edit)
edit->found_start = edit->search_start = edit->search->normal_offset;
edit->found_len = len;
edit->over_col = 0;
edit_cursor_move (edit, edit->search_start - edit->curs1);
edit_cursor_move (edit, edit->search_start - edit->buffer.curs1);
edit_scroll_screen_over_cursor (edit);
if (edit_search_options.backwards)
edit->search_start--;
@ -1007,7 +978,7 @@ edit_do_search (WEdit * edit)
}
else
{
edit->search_start = edit->curs1;
edit->search_start = edit->buffer.curs1;
if (edit->search->error_str != NULL)
edit_error_dialog (_("Search"), edit->search->error_str);
}
@ -1048,8 +1019,8 @@ edit_get_block (WEdit * edit, off_t start, off_t finish, off_t * l)
int c;
off_t x;
x = edit_move_forward3 (edit, edit_bol (edit, start), 0, start);
c = edit_get_byte (edit, start);
x = edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, start), 0, start);
c = edit_buffer_get_byte (&edit->buffer, start);
if ((x >= edit->column1 && x < edit->column2)
|| (x >= edit->column2 && x < edit->column1) || c == '\n')
{
@ -1063,7 +1034,7 @@ edit_get_block (WEdit * edit, off_t start, off_t finish, off_t * l)
{
*l = finish - start;
while (start < finish)
*s++ = edit_get_byte (edit, start++);
*s++ = edit_buffer_get_byte (&edit->buffer, start++);
}
*s = '\0';
return r;
@ -1087,7 +1058,7 @@ edit_save_block_to_clip_file (WEdit * edit, off_t start, off_t finish)
/* --------------------------------------------------------------------------------------------- */
static void
pipe_mail (WEdit * edit, char *to, char *subject, char *cc)
pipe_mail (const edit_buffer_t * buf, char *to, char *subject, char *cc)
{
FILE *p = 0;
char *s;
@ -1100,17 +1071,18 @@ pipe_mail (WEdit * edit, char *to, char *subject, char *cc)
g_free (subject);
g_free (cc);
if (s)
if (s != NULL)
{
p = popen (s, "w");
g_free (s);
}
if (p)
if (p != NULL)
{
off_t i;
for (i = 0; i < edit->last_byte; i++)
fputc (edit_get_byte (edit, i), p);
for (i = 0; i < buf->size; i++)
fputc (edit_buffer_get_byte (buf, i), p);
pclose (p);
}
}
@ -1119,16 +1091,16 @@ pipe_mail (WEdit * edit, char *to, char *subject, char *cc)
/** find first character of current word */
static gboolean
edit_find_word_start (WEdit * edit, off_t * word_start, gsize * word_len)
edit_find_word_start (const edit_buffer_t * buf, off_t * word_start, gsize * word_len)
{
int c, last;
off_t i;
/* return if at begin of file */
if (edit->curs1 <= 0)
if (buf->curs1 <= 0)
return FALSE;
c = edit_get_byte (edit, edit->curs1 - 1);
c = edit_buffer_get_previous_byte (buf);
/* return if not at end or in word */
if (is_break_char (c))
return FALSE;
@ -1137,11 +1109,11 @@ edit_find_word_start (WEdit * edit, off_t * word_start, gsize * word_len)
for (i = 2;; i++)
{
/* return if at begin of file */
if (edit->curs1 < i)
if (buf->curs1 < i)
return FALSE;
last = c;
c = edit_get_byte (edit, edit->curs1 - i);
c = edit_buffer_get_byte (buf, buf->curs1 - i);
if (is_break_char (c))
{
@ -1149,7 +1121,7 @@ edit_find_word_start (WEdit * edit, off_t * word_start, gsize * word_len)
if (isdigit (last))
return FALSE;
*word_start = edit->curs1 - (i - 1); /* start found */
*word_start = buf->curs1 - (i - 1); /* start found */
*word_len = (gsize) (i - 1);
break;
}
@ -1176,7 +1148,7 @@ edit_collect_completions_get_current_word (WEdit * edit, mc_search_t * srch, off
off_t i;
GString *temp;
if (!mc_search_run (srch, (void *) edit, word_start, edit->last_byte, &len))
if (!mc_search_run (srch, (void *) edit, word_start, edit->buffer.size, &len))
return NULL;
temp = g_string_sized_new (len);
@ -1185,7 +1157,7 @@ edit_collect_completions_get_current_word (WEdit * edit, mc_search_t * srch, off
{
int chr;
chr = edit_get_byte (edit, word_start + i);
chr = edit_buffer_get_byte (&edit->buffer, word_start + i);
if (!isspace (chr))
g_string_append_c (temp, chr);
}
@ -1216,7 +1188,7 @@ edit_collect_completions (WEdit * edit, off_t word_start, gsize word_len,
if (mc_config_get_bool
(mc_main_config, CONFIG_APP_SECTION, "editor_wordcompletion_collect_entire_file", 0))
{
last_byte = edit->last_byte;
last_byte = edit->buffer.size;
}
else
{
@ -1240,7 +1212,7 @@ edit_collect_completions (WEdit * edit, off_t word_start, gsize word_len,
/* add matched completion if not yet added */
for (i = 0; i < len; i++)
{
skip = edit_get_byte (edit, start + i);
skip = edit_buffer_get_byte (&edit->buffer, start + i);
if (isspace (skip))
continue;
@ -1318,7 +1290,7 @@ edit_insert_column_of_text (WEdit * edit, unsigned char *data, off_t size, long
off_t i, cursor;
long col;
cursor = edit->curs1;
cursor = edit->buffer.curs1;
col = edit_get_col (edit);
for (i = 0; i < size; i++)
@ -1330,27 +1302,27 @@ edit_insert_column_of_text (WEdit * edit, unsigned char *data, off_t size, long
long l;
off_t p;
if (edit_get_byte (edit, edit->curs1) != '\n')
if (edit_buffer_get_current_byte (&edit->buffer) != '\n')
{
for (l = width - (edit_get_col (edit) - col); l > 0; l -= space_width)
edit_insert (edit, ' ');
}
for (p = edit->curs1;; p++)
for (p = edit->buffer.curs1;; p++)
{
if (p == edit->last_byte)
if (p == edit->buffer.size)
{
edit_cursor_move (edit, edit->last_byte - edit->curs1);
edit_cursor_move (edit, edit->buffer.size - edit->buffer.curs1);
edit_insert_ahead (edit, '\n');
p++;
break;
}
if (edit_get_byte (edit, p) == '\n')
if (edit_buffer_get_byte (&edit->buffer, p) == '\n')
{
p++;
break;
}
}
edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0) - edit->curs1);
edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0) - edit->buffer.curs1);
for (l = col - edit_get_col (edit); l >= space_width; l -= space_width)
edit_insert (edit, ' ');
@ -1360,8 +1332,8 @@ edit_insert_column_of_text (WEdit * edit, unsigned char *data, off_t size, long
*col1 = col;
*col2 = col + width;
*start_pos = cursor;
*end_pos = edit->curs1;
edit_cursor_move (edit, cursor - edit->curs1);
*end_pos = edit->buffer.curs1;
edit_cursor_move (edit, cursor - edit->buffer.curs1);
}
/* --------------------------------------------------------------------------------------------- */
@ -1664,7 +1636,7 @@ edit_save_as_cmd (WEdit * edit)
int save_lock = 0;
int different_filename = 0;
if (!edit_check_newline (edit))
if (!edit_check_newline (&edit->buffer))
return FALSE;
exp_vpath = edit_get_save_file_as (edit);
@ -2046,7 +2018,7 @@ edit_save_confirm_cmd (WEdit * edit)
if (edit->filename_vpath == NULL)
return edit_save_as_cmd (edit);
if (!edit_check_newline (edit))
if (!edit_check_newline (&edit->buffer))
return FALSE;
if (edit_confirm_save)
@ -2259,7 +2231,7 @@ eval_marks (WEdit * edit, off_t * start_mark, off_t * end_mark)
long end_mark_curs;
if (edit->end_mark_curs < 0)
end_mark_curs = edit->curs1;
end_mark_curs = edit->buffer.curs1;
else
end_mark_curs = edit->end_mark_curs;
@ -2279,10 +2251,10 @@ eval_marks (WEdit * edit, off_t * start_mark, off_t * end_mark)
&& (((edit->mark1 > end_mark_curs) && (edit->column1 < edit->column2))
|| ((edit->mark1 < end_mark_curs) && (edit->column1 > edit->column2))))
{
start_bol = edit_bol (edit, *start_mark);
start_eol = edit_eol (edit, start_bol - 1) + 1;
end_bol = edit_bol (edit, *end_mark);
end_eol = edit_eol (edit, *end_mark);
start_bol = edit_buffer_get_bol (&edit->buffer, *start_mark);
start_eol = edit_buffer_get_eol (&edit->buffer, start_bol - 1) + 1;
end_bol = edit_buffer_get_bol (&edit->buffer, *end_mark);
end_eol = edit_buffer_get_eol (&edit->buffer, *end_mark);
col1 = min (edit->column1, edit->column2);
col2 = max (edit->column1, edit->column2);
@ -2311,7 +2283,7 @@ eval_marks (WEdit * edit, off_t * start_mark, off_t * end_mark)
void
edit_block_copy_cmd (WEdit * edit)
{
off_t start_mark, end_mark, current = edit->curs1;
off_t start_mark, end_mark, current = edit->buffer.curs1;
long col_delta = 0;
off_t mark1, mark2;
long c1, c2;
@ -2349,7 +2321,7 @@ edit_block_copy_cmd (WEdit * edit)
edit_scroll_screen_over_cursor (edit);
if (edit->column_highlight)
edit_set_markers (edit, edit->curs1, mark2, c1, c2);
edit_set_markers (edit, edit->buffer.curs1, mark2, c1, c2);
else if (start_mark < current && end_mark > current)
edit_set_markers (edit, start_mark, end_mark + end_mark - start_mark, 0, 0);
@ -2369,7 +2341,7 @@ edit_block_move_cmd (WEdit * edit)
if (eval_marks (edit, &start_mark, &end_mark))
return;
if (!edit->column_highlight && edit->curs1 > start_mark && edit->curs1 < end_mark)
if (!edit->column_highlight && edit->buffer.curs1 > start_mark && edit->buffer.curs1 < end_mark)
return;
if (edit->mark2 < 0)
@ -2393,10 +2365,12 @@ edit_block_move_cmd (WEdit * edit)
x2 = x + edit->over_col;
/* do nothing when cursor inside first line of selected area */
if ((edit_eol (edit, edit->curs1) == edit_eol (edit, start_mark)) && x2 > c1 && x2 <= c2)
if ((edit_buffer_get_eol (&edit->buffer, edit->buffer.curs1) ==
edit_buffer_get_eol (&edit->buffer, start_mark)) && x2 > c1 && x2 <= c2)
return;
if (edit->curs1 > start_mark && edit->curs1 < edit_eol (edit, end_mark))
if (edit->buffer.curs1 > start_mark
&& edit->buffer.curs1 < edit_buffer_get_eol (&edit->buffer, end_mark))
{
if (x > c2)
x -= b_width;
@ -2411,8 +2385,8 @@ edit_block_move_cmd (WEdit * edit)
edit->over_col = max (0, edit->over_col - b_width);
/* calculate the cursor pos after delete block */
current = edit_move_forward3 (edit, edit_bol (edit, edit->curs1), x, 0);
edit_cursor_move (edit, current - edit->curs1);
current = edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), x, 0);
edit_cursor_move (edit, current - edit->buffer.curs1);
edit_scroll_screen_over_cursor (edit);
/* add TWS if need before block insertion */
@ -2426,9 +2400,9 @@ edit_block_move_cmd (WEdit * edit)
{
off_t count, count_orig;
current = edit->curs1;
current = edit->buffer.curs1;
copy_buf = g_malloc0 (end_mark - start_mark);
edit_cursor_move (edit, start_mark - edit->curs1);
edit_cursor_move (edit, start_mark - edit->buffer.curs1);
edit_scroll_screen_over_cursor (edit);
for (count = start_mark; count < end_mark; count++)
@ -2436,14 +2410,15 @@ edit_block_move_cmd (WEdit * edit)
edit_scroll_screen_over_cursor (edit);
edit_cursor_move (edit,
current - edit->curs1 -
(((current - edit->curs1) > 0) ? end_mark - start_mark : 0));
current - edit->buffer.curs1 -
(((current - edit->buffer.curs1) > 0) ? end_mark - start_mark : 0));
edit_scroll_screen_over_cursor (edit);
count_orig = count;
while (count-- > start_mark)
edit_insert_ahead (edit, copy_buf[end_mark - count - 1]);
edit_set_markers (edit, edit->curs1, edit->curs1 + end_mark - start_mark, 0, 0);
edit_set_markers (edit, edit->buffer.curs1, edit->buffer.curs1 + end_mark - start_mark, 0,
0);
/* Place cursor at the end of text selection */
if (option_cursor_after_inserted_block)
@ -2545,7 +2520,7 @@ edit_replace_cmd (WEdit * edit, int again)
edit->search = mc_search_new (input1, -1);
if (edit->search == NULL)
{
edit->search_start = edit->curs1;
edit->search_start = edit->buffer.curs1;
goto cleanup;
}
edit->search->search_type = edit_search_options.type;
@ -2583,7 +2558,7 @@ edit_replace_cmd (WEdit * edit, int again)
edit->search_start = edit->search->normal_offset;
/*returns negative on not found or error in pattern */
if ((edit->search_start >= 0) && (edit->search_start < edit->last_byte))
if ((edit->search_start >= 0) && (edit->search_start < edit->buffer.size))
{
gsize i;
GString *repl_str;
@ -2591,7 +2566,7 @@ edit_replace_cmd (WEdit * edit, int again)
edit->found_start = edit->search_start;
i = edit->found_len = len;
edit_cursor_move (edit, edit->search_start - edit->curs1);
edit_cursor_move (edit, edit->search_start - edit->buffer.curs1);
edit_scroll_screen_over_cursor (edit);
if (edit->replace_mode == 0)
@ -2664,7 +2639,7 @@ edit_replace_cmd (WEdit * edit, int again)
{
edit->search_start += edit->found_len + (len == 0 ? 1 : 0);
if (edit->search_start >= edit->last_byte)
if (edit->search_start >= edit->buffer.size)
break;
}
@ -2673,7 +2648,7 @@ edit_replace_cmd (WEdit * edit, int again)
else
{
/* try and find from right here for next search */
edit->search_start = edit->curs1;
edit->search_start = edit->buffer.curs1;
edit_update_curs_col (edit);
edit->force |= REDRAW_PAGE;
@ -2705,7 +2680,7 @@ edit_replace_cmd (WEdit * edit, int again)
mc_search_cbret_t
edit_search_cmd_callback (const void *user_data, gsize char_offset, int *current_char)
{
*current_char = edit_get_byte ((WEdit *) user_data, (off_t) char_offset);
*current_char = edit_buffer_get_byte (&((WEdit *) user_data)->buffer, (off_t) char_offset);
return MC_SEARCH_CB_OK;
}
@ -2795,7 +2770,7 @@ edit_ok_to_exit (WEdit * edit)
if (!mc_global.midnight_shutdown)
{
if (!edit_check_newline (edit))
if (!edit_check_newline (&edit->buffer))
{
g_free (fname);
return FALSE;
@ -2888,7 +2863,7 @@ edit_save_block (WEdit * edit, const char *filename, off_t start, off_t finish)
{
end = min (finish, start + TEMP_BUF_LEN);
for (; i < end; i++)
buf[i - start] = edit_get_byte (edit, i);
buf[i - start] = edit_buffer_get_byte (&edit->buffer, i);
len -= mc_write (file, (char *) buf, end - start);
start = end;
}
@ -3004,7 +2979,7 @@ edit_goto_cmd (WEdit * edit)
line = l;
if (l < 0)
l = edit->total_lines + l + 2;
l = edit->buffer.lines + l + 2;
edit_move_display (edit, l - WIDGET (edit)->lines / 2 - 1);
edit_move_to_line (edit, l - 1);
edit->force |= REDRAW_COMPLETELY;
@ -3265,7 +3240,7 @@ edit_mail_dialog (WEdit * edit)
mail_cc_last = tmail_cc;
mail_subject_last = tmail_subject;
mail_to_last = tmail_to;
pipe_mail (edit, mail_to_last, mail_subject_last, mail_cc_last);
pipe_mail (&edit->buffer, mail_to_last, mail_subject_last, mail_cc_last);
}
}
@ -3289,14 +3264,14 @@ edit_complete_word_cmd (WEdit * edit)
GString *compl[MAX_WORD_COMPLETIONS]; /* completions */
/* search start of word to be completed */
if (!edit_find_word_start (edit, &word_start, &word_len))
if (!edit_find_word_start (&edit->buffer, &word_start, &word_len))
return;
/* prepare match expression */
/* match_expr = g_strdup_printf ("\\b%.*s[a-zA-Z_0-9]+", word_len, bufpos); */
match_expr = g_string_new ("(^|\\s+|\\b)");
for (i = 0; i < word_len; i++)
g_string_append_c (match_expr, edit_get_byte (edit, word_start + i));
g_string_append_c (match_expr, edit_buffer_get_byte (&edit->buffer, word_start + i));
g_string_append (match_expr,
"[^\\s\\.=\\+\\[\\]\\(\\)\\,\\;\\:\\\"\\'\\-\\?\\/\\|\\\\\\{\\}\\*\\&\\^\\%%\\$#@\\!]+");
@ -3469,13 +3444,13 @@ edit_get_match_keyword_cmd (WEdit * edit)
}
/* search start of word to be completed */
if (!edit_find_word_start (edit, &word_start, &word_len))
if (!edit_find_word_start (&edit->buffer, &word_start, &word_len))
return;
/* prepare match expression */
match_expr = g_string_sized_new (word_len);
for (i = 0; i < word_len; i++)
g_string_append_c (match_expr, edit_get_byte (edit, word_start + i));
g_string_append_c (match_expr, edit_buffer_get_byte (&edit->buffer, word_start + i));
ptr = g_get_current_dir ();
path = g_strconcat (ptr, G_DIR_SEPARATOR_S, (char *) NULL);
@ -3522,29 +3497,31 @@ edit_suggest_current_word (WEdit * edit)
gsize word_len = 0;
off_t word_start = 0;
int retval = B_SKIP_WORD;
char *match_word;
GString *match_word;
/* search start of word to spell check */
match_word = edit_get_word_from_pos (edit, edit->curs1, &word_start, &word_len, &cut_len);
match_word = edit_buffer_get_word_from_pos (&edit->buffer, edit->buffer.curs1, &word_start,
&cut_len);
word_len = match_word->len;
#ifdef HAVE_CHARSET
if (mc_global.source_codepage >= 0 && (mc_global.source_codepage != mc_global.display_codepage))
{
GString *tmp_word;
tmp_word = str_convert_to_display (match_word);
g_free (match_word);
match_word = g_string_free (tmp_word, FALSE);
tmp_word = str_convert_to_display (match_word->str);
g_string_free (match_word, TRUE);
match_word = tmp_word;
}
#endif
if (!aspell_check (match_word, (int) word_len))
if (!aspell_check (match_word->str, (int) word_len))
{
GArray *suggest;
unsigned int res;
suggest = g_array_new (TRUE, FALSE, sizeof (char *));
res = aspell_suggest (suggest, match_word, (int) word_len);
res = aspell_suggest (suggest, match_word->str, (int) word_len);
if (res != 0)
{
char *new_word = NULL;
@ -3555,7 +3532,7 @@ edit_suggest_current_word (WEdit * edit)
edit_scroll_screen_over_cursor (edit);
edit_render_keypress (edit);
retval = spell_dialog_spell_suggest_show (edit, match_word, &new_word, suggest);
retval = spell_dialog_spell_suggest_show (edit, match_word->str, &new_word, suggest);
edit_cursor_move (edit, word_len - cut_len);
if (retval == B_ENTER && new_word != NULL)
@ -3582,14 +3559,14 @@ edit_suggest_current_word (WEdit * edit)
g_free (cp_word);
}
else if (retval == B_ADD_WORD && match_word != NULL)
aspell_add_to_dict (match_word, (int) word_len);
aspell_add_to_dict (match_word->str, (int) word_len);
}
g_array_free (suggest, TRUE);
edit->found_start = 0;
edit->found_len = 0;
}
g_free (match_word);
g_string_free (match_word, TRUE);
return retval;
}
@ -3598,9 +3575,9 @@ edit_suggest_current_word (WEdit * edit)
void
edit_spellcheck_file (WEdit * edit)
{
if (edit->curs_line > 0)
if (edit->buffer.curs_line > 0)
{
edit_cursor_move (edit, -edit->curs1);
edit_cursor_move (edit, -edit->buffer.curs1);
edit_move_to_prev_col (edit, 0);
edit_update_curs_row (edit);
}
@ -3609,16 +3586,16 @@ edit_spellcheck_file (WEdit * edit)
{
int c1, c2;
c2 = edit_get_byte (edit, edit->curs1);
c2 = edit_buffer_get_current_byte (&edit->buffer);
do
{
if (edit->curs1 >= edit->last_byte)
if (edit->buffer.curs1 >= edit->buffer.size)
return;
c1 = c2;
edit_cursor_move (edit, 1);
c2 = edit_get_byte (edit, edit->curs1);
c2 = edit_buffer_get_current_byte (&edit->buffer);
}
while (is_break_char (c1) || is_break_char (c2));
}

View File

@ -7,7 +7,7 @@
Written by:
Paul Sheer, 1996, 1997
Andrew Borodin <aborodin@vmail.ru> 2012
Andrew Borodin <aborodin@vmail.ru> 2012, 2013
Slava Zanko <slavazanko@gmail.com>, 2013
This file is part of the Midnight Commander.
@ -114,7 +114,7 @@ status_string (WEdit * edit, char *s, int w)
* otherwise print the current character as is (if printable),
* as decimal and as hex.
*/
if (edit->curs1 < edit->last_byte)
if (edit->buffer.curs1 < edit->buffer.size)
{
#ifdef HAVE_CHARSET
if (edit->utf8)
@ -122,7 +122,7 @@ status_string (WEdit * edit, char *s, int w)
unsigned int cur_utf = 0;
int cw = 1;
cur_utf = edit_get_utf (edit, edit->curs1, &cw);
cur_utf = edit_buffer_get_utf (&edit->buffer, edit->buffer.curs1, &cw);
if (cw > 0)
{
g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X",
@ -130,7 +130,7 @@ status_string (WEdit * edit, char *s, int w)
}
else
{
cur_utf = edit_get_byte (edit, edit->curs1);
cur_utf = edit_buffer_get_current_byte (&edit->buffer);
g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X",
(int) cur_utf, (unsigned) cur_utf);
}
@ -140,7 +140,7 @@ status_string (WEdit * edit, char *s, int w)
{
unsigned char cur_byte = 0;
cur_byte = edit_get_byte (edit, edit->curs1);
cur_byte = edit_buffer_get_current_byte (&edit->buffer);
g_snprintf (byte_str, sizeof (byte_str), "%4d 0x%03X",
(int) cur_byte, (unsigned) cur_byte);
}
@ -159,8 +159,9 @@ status_string (WEdit * edit, char *s, int w)
macro_index < 0 ? '-' : 'R',
edit->overwrite == 0 ? '-' : 'O',
edit->curs_col + edit->over_col,
edit->curs_line + 1,
edit->total_lines + 1, (long) edit->curs1, (long) edit->last_byte, byte_str,
edit->buffer.curs_line + 1,
edit->buffer.lines + 1, (long) edit->buffer.curs1, (long) edit->buffer.size,
byte_str,
#ifdef HAVE_CHARSET
mc_global.source_codepage >= 0 ? get_codepage_id (mc_global.source_codepage) :
#endif
@ -175,8 +176,9 @@ status_string (WEdit * edit, char *s, int w)
edit->curs_col + edit->over_col,
edit->start_line + 1,
edit->curs_row,
edit->curs_line + 1,
edit->total_lines + 1, (long) edit->curs1, (long) edit->last_byte, byte_str,
edit->buffer.curs_line + 1,
edit->buffer.lines + 1, (long) edit->buffer.curs1, (long) edit->buffer.size,
byte_str,
#ifdef HAVE_CHARSET
mc_global.source_codepage >= 0 ? get_codepage_id (mc_global.source_codepage) :
#endif
@ -233,8 +235,8 @@ edit_status_fullscreen (WEdit * edit, int color)
{
size_t percent = 100;
if (edit->total_lines + 1 != 0)
percent = (edit->curs_line + 1) * 100 / (edit->total_lines + 1);
if (edit->buffer.lines + 1 != 0)
percent = (edit->buffer.curs_line + 1) * 100 / (edit->buffer.lines + 1);
widget_move (h, 0, w - 6 - 6);
tty_printf (" %3d%%", percent);
}
@ -292,7 +294,8 @@ edit_status_window (WEdit * edit)
edit_move (2, w->lines - 1);
tty_printf ("%3ld %5ld/%ld %6ld/%ld",
edit->curs_col + edit->over_col,
edit->curs_line + 1, edit->total_lines + 1, edit->curs1, edit->last_byte);
edit->buffer.curs_line + 1, edit->buffer.lines + 1, edit->buffer.curs1,
edit->buffer.size);
}
/*
@ -303,7 +306,7 @@ edit_status_window (WEdit * edit)
if (cols > 46)
{
edit_move (32, w->lines - 1);
if (edit->curs1 >= edit->last_byte)
if (edit->buffer.curs1 >= edit->buffer.size)
tty_print_string ("[<EOF> ]");
#ifdef HAVE_CHARSET
else if (edit->utf8)
@ -311,9 +314,9 @@ edit_status_window (WEdit * edit)
unsigned int cur_utf;
int cw = 1;
cur_utf = edit_get_utf (edit, edit->curs1, &cw);
cur_utf = edit_buffer_get_utf (&edit->buffer, edit->buffer.curs1, &cw);
if (cw <= 0)
cur_utf = edit_get_byte (edit, edit->curs1);
cur_utf = edit_buffer_get_current_byte (&edit->buffer);
tty_printf ("[%05d 0x%04X]", cur_utf, cur_utf);
}
#endif
@ -321,7 +324,7 @@ edit_status_window (WEdit * edit)
{
unsigned char cur_byte;
cur_byte = edit_get_byte (edit, edit->curs1);
cur_byte = edit_buffer_get_current_byte (&edit->buffer);
tty_printf ("[%05d 0x%04X]", (unsigned int) cur_byte, (unsigned int) cur_byte);
}
}
@ -545,7 +548,7 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
if (option_line_state)
{
cur_line = edit->start_line + row;
if (cur_line <= (unsigned int) edit->total_lines)
if (cur_line <= (unsigned int) edit->buffer.lines)
{
g_snprintf (line_stat, LINE_STATE_WIDTH + 1, "%7i ", cur_line + 1);
}
@ -564,13 +567,14 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
{
eval_marks (edit, &m1, &m2);
if (row <= edit->total_lines - edit->start_line)
if (row <= edit->buffer.lines - edit->start_line)
{
off_t tws = 0;
if (tty_use_colors () && visible_tws)
{
tws = edit_eol (edit, b);
while (tws > b && ((c = edit_get_byte (edit, tws - 1)) == ' ' || c == '\t'))
tws = edit_buffer_get_eol (&edit->buffer, b);
while (tws > b
&& ((c = edit_buffer_get_byte (&edit->buffer, tws - 1)) == ' ' || c == '\t'))
tws--;
}
@ -583,7 +587,7 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
p->ch = 0;
p->style = 0;
if (q == edit->curs1)
if (q == edit->buffer.curs1)
p->style |= MOD_CURSOR;
if (q >= m1 && q < m2)
{
@ -607,14 +611,11 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
#ifdef HAVE_CHARSET
if (edit->utf8)
{
c = edit_get_utf (edit, q, &cw);
}
c = edit_buffer_get_utf (&edit->buffer, q, &cw);
else
#endif
{
c = edit_get_byte (edit, q);
}
c = edit_buffer_get_byte (&edit->buffer, q);
/* we don't use bg for mc - fg contains both */
if (book_mark)
{
@ -829,7 +830,7 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
static inline void
edit_draw_this_char (WEdit * edit, off_t curs, long row, long start_column, long end_column)
{
off_t b = edit_bol (edit, curs);
off_t b = edit_buffer_get_bol (&edit->buffer, curs);
edit_draw_this_line (edit, b, row, start_column, end_column);
}
@ -905,13 +906,13 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
if ((force & REDRAW_PAGE) != 0)
{
row = start_row;
b = edit_move_forward (edit, edit->start_display, start_row, 0);
b = edit_buffer_move_forward (&edit->buffer, edit->start_display, start_row, 0);
while (row <= end_row)
{
if (key_pending (edit))
return;
edit_draw_this_line (edit, b, row, start_column, end_column);
b = edit_move_forward (edit, b, 1, 0);
b = edit_buffer_move_forward (&edit->buffer, b, 1, 0);
row++;
}
}
@ -930,12 +931,12 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
if (key_pending (edit))
return;
edit_draw_this_line (edit, b, row, start_column, end_column);
b = edit_move_forward (edit, b, 1, 0);
b = edit_buffer_move_forward (&edit->buffer, b, 1, 0);
}
}
/* if (force & REDRAW_LINE) ---> default */
b = edit_bol (edit, edit->curs1);
b = edit_buffer_get_current_bol (&edit->buffer);
if (curs_row >= start_row && curs_row <= end_row)
{
if (key_pending (edit))
@ -946,13 +947,13 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
if ((force & REDRAW_AFTER_CURSOR) != 0 && end_row > curs_row)
{
row = curs_row + 1 < start_row ? start_row : curs_row + 1;
b = edit_move_forward (edit, b, 1, 0);
b = edit_buffer_move_forward (&edit->buffer, b, 1, 0);
while (row <= end_row)
{
if (key_pending (edit))
return;
edit_draw_this_line (edit, b, row, start_column, end_column);
b = edit_move_forward (edit, b, 1, 0);
b = edit_buffer_move_forward (&edit->buffer, b, 1, 0);
row++;
}
}
@ -960,7 +961,8 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
if ((force & REDRAW_LINE_ABOVE) != 0 && curs_row >= 1)
{
row = curs_row - 1;
b = edit_move_backward (edit, edit_bol (edit, edit->curs1), 1);
b = edit_buffer_move_backward (&edit->buffer,
edit_buffer_get_current_bol (&edit->buffer), 1);
if (row >= start_row && row <= end_row)
{
if (key_pending (edit))
@ -972,8 +974,8 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
if ((force & REDRAW_LINE_BELOW) != 0 && row < w->lines - 1)
{
row = curs_row + 1;
b = edit_bol (edit, edit->curs1);
b = edit_move_forward (edit, b, 1, 0);
b = edit_buffer_get_current_bol (&edit->buffer);
b = edit_buffer_move_forward (&edit->buffer, b, 1, 0);
if (row >= start_row && row <= end_row)
{
if (key_pending (edit))
@ -987,18 +989,18 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
{
/* with the new text highlighting, we must draw from the top down */
edit_draw_this_char (edit, prev_curs, prev_curs_row, start_column, end_column);
edit_draw_this_char (edit, edit->curs1, edit->curs_row, start_column, end_column);
edit_draw_this_char (edit, edit->buffer.curs1, edit->curs_row, start_column, end_column);
}
else
{
edit_draw_this_char (edit, edit->curs1, edit->curs_row, start_column, end_column);
edit_draw_this_char (edit, edit->buffer.curs1, edit->curs_row, start_column, end_column);
edit_draw_this_char (edit, prev_curs, prev_curs_row, start_column, end_column);
}
edit->force = 0;
prev_curs_row = edit->curs_row;
prev_curs = edit->curs1;
prev_curs = edit->buffer.curs1;
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -529,8 +529,10 @@ edit_event (Gpm_Event * event, void *data)
edit->prev_col = local.x - edit->start_col - option_line_state_width - 1;
else
{
long line_len = edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0,
edit_eol (edit, edit->curs1));
long line_len;
line_len = edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 0,
edit_buffer_get_current_eol (&edit->buffer));
if (local.x > line_len)
{
@ -552,7 +554,7 @@ edit_event (Gpm_Event * event, void *data)
else if (local.y < (edit->curs_row + 1))
edit_move_up (edit, (edit->curs_row + 1) - local.y, 0);
else
edit_move_to_prev_col (edit, edit_bol (edit, edit->curs1));
edit_move_to_prev_col (edit, edit_buffer_get_current_bol (&edit->buffer));
if ((local.type & GPM_DOWN) != 0)
{

View File

@ -9,6 +9,7 @@
#include "lib/widget.h" /* Widget */
#include "edit-impl.h"
#include "editbuffer.h"
/*** typedefs(not structures) and defined constants **********************************************/
@ -74,10 +75,7 @@ struct WEdit
vfs_path_t *dir_vpath; /* NULL if filename is absolute */
/* dynamic buffers and cursor position for editor: */
off_t curs1; /* position of the cursor from the beginning of the file. */
off_t curs2; /* position from the end of the file */
unsigned char *buffers1[MAXBUFF + 1]; /* all data up to curs1 */
unsigned char *buffers2[MAXBUFF + 1]; /* all data from end of file down to curs2 */
edit_buffer_t buffer;
#ifdef HAVE_CHARSET
/* multibyte support */
@ -99,7 +97,6 @@ struct WEdit
off_t found_start; /* the found word from a search - start position */
/* display information */
off_t last_byte; /* Last byte of file */
long start_display; /* First char displayed */
long start_col; /* First displayed column, negative */
long max_column; /* The maximum cursor position ever reached used to calc hori scroll bar */
@ -117,11 +114,9 @@ struct WEdit
unsigned int fullscreen:1; /* Is window fullscreen or not */
long prev_col; /* recent column position of the cursor - used when moving
up or down past lines that are shorter than the current line */
long curs_line; /* line number of the cursor. */
long start_line; /* line number of the top of the page */
/* file info */
long total_lines; /* total lines in the file */
off_t mark1; /* position of highlight start */
off_t mark2; /* position of highlight end */
off_t end_mark_curs; /* position of cursor after end of highlighting */

View File

@ -9,6 +9,7 @@
Paul Sheer, 1998
Egmont Koblinger <egmont@gmail.com>, 2010
Slava Zanko <slavazanko@gmail.com>, 2013
Andrew Borodin <aborodin@vmail.ru>, 2013
This file is part of the Midnight Commander.
@ -221,7 +222,7 @@ compare_word_to_right (const WEdit * edit, off_t i, const char *text,
if (*text == '\0')
return -1;
c = xx_tolower (edit, edit_get_byte (edit, i - 1));
c = xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i - 1));
if ((line_start != 0 && c != '\n') || (whole_left != NULL && strchr (whole_left, c) != NULL))
return -1;
@ -234,7 +235,7 @@ compare_word_to_right (const WEdit * edit, off_t i, const char *text,
return -1;
while (TRUE)
{
c = xx_tolower (edit, edit_get_byte (edit, i));
c = xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i));
if (*p == '\0' && whole_right != NULL && strchr (whole_right, c) == NULL)
break;
if (c == *p)
@ -250,7 +251,7 @@ compare_word_to_right (const WEdit * edit, off_t i, const char *text,
j = 0;
while (TRUE)
{
c = xx_tolower (edit, edit_get_byte (edit, i));
c = xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i));
if (c == *p)
{
j = i;
@ -282,7 +283,7 @@ compare_word_to_right (const WEdit * edit, off_t i, const char *text,
while (TRUE)
{
d = c;
c = xx_tolower (edit, edit_get_byte (edit, i));
c = xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i));
for (j = 0; p[j] != SYNTAX_TOKEN_BRACKET && p[j]; j++)
if (c == p[j])
goto found_char2;
@ -301,7 +302,7 @@ compare_word_to_right (const WEdit * edit, off_t i, const char *text,
case SYNTAX_TOKEN_BRACE:
if (++p > q)
return -1;
c = xx_tolower (edit, edit_get_byte (edit, i));
c = xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i));
for (; *p != SYNTAX_TOKEN_BRACE && *p; p++)
if (c == *p)
goto found_char3;
@ -311,12 +312,13 @@ compare_word_to_right (const WEdit * edit, off_t i, const char *text,
p++;
break;
default:
if (*p != xx_tolower (edit, edit_get_byte (edit, i)))
if (*p != xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i)))
return -1;
}
}
return (whole_right != NULL &&
strchr (whole_right, xx_tolower (edit, edit_get_byte (edit, i))) != NULL) ? -1 : i;
strchr (whole_right,
xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i))) != NULL) ? -1 : i;
}
/* --------------------------------------------------------------------------------------------- */
@ -344,7 +346,7 @@ apply_rules_going_right (WEdit * edit, off_t i)
off_t end = 0;
edit_syntax_rule_t _rule = edit->rule;
c = xx_tolower (edit, edit_get_byte (edit, i));
c = xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i));
if (c == 0)
return;
@ -353,7 +355,7 @@ apply_rules_going_right (WEdit * edit, off_t i)
/* check to turn off a keyword */
if (_rule.keyword != 0)
{
if (edit_get_byte (edit, i - 1) == '\n')
if (edit_buffer_get_byte (&edit->buffer, i - 1) == '\n')
_rule.keyword = 0;
if (is_end)
{
@ -1374,7 +1376,7 @@ get_first_editor_line (WEdit * edit)
for (i = 0; i < sizeof (s) - 1; i++)
{
s[i] = edit_get_byte (edit, i);
s[i] = edit_buffer_get_byte (&edit->buffer, i);
if (s[i] == '\n')
{
s[i] = '\0';
@ -1398,7 +1400,7 @@ edit_get_syntax_color (WEdit * edit, off_t byte_index)
if (!tty_use_colors ())
return 0;
if (edit->rules != NULL && byte_index < edit->last_byte && option_syntax_highlighting)
if (edit->rules != NULL && byte_index < edit->buffer.size && option_syntax_highlighting)
{
edit_get_rule (edit, byte_index);
return translate_rule_to_color (edit, &edit->rule);

View File

@ -2,13 +2,14 @@
Word-processor mode for the editor: does dynamic
paragraph formatting.
Copyright (C) 2011
Copyright (C) 2011, 2013
The Free Software Foundation, Inc.
Copyright (C) 1996 Paul Sheer
Writen by:
Paul Sheer, 1996
Andrew Borodin <aborodin@vmail.ru>, 2013
This file is part of the Midnight Commander.
@ -30,6 +31,8 @@
* \brief Source: word-processor mode for the editor: does dynamic paragraph formatting
* \author Paul Sheer
* \date 1996
* \author Andrew Borodin
* \date 2013
*/
#include <config.h>
@ -68,50 +71,48 @@
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
static long
line_start (WEdit * edit, long line)
static off_t
line_start (const edit_buffer_t * buf, long line)
{
off_t p;
long l;
l = edit->curs_line;
p = edit->curs1;
l = buf->curs_line;
p = buf->curs1;
if (line < l)
p = edit_move_backward (edit, p, l - line);
p = edit_buffer_move_backward (buf, p, l - line);
else if (line > l)
p = edit_move_forward (edit, p, line - l, 0);
p = edit_buffer_move_forward (buf, p, line - l, 0);
p = edit_bol (edit, p);
while (strchr ("\t ", edit_get_byte (edit, p)))
p = edit_buffer_get_bol (buf, p);
while (strchr ("\t ", edit_buffer_get_byte (buf, p)) != NULL)
p++;
return p;
}
/* --------------------------------------------------------------------------------------------- */
static int
bad_line_start (WEdit * edit, off_t p)
static gboolean
bad_line_start (const edit_buffer_t * buf, off_t p)
{
int c;
c = edit_get_byte (edit, p);
c = edit_buffer_get_byte (buf, p);
if (c == '.')
{ /* '...' is acceptable */
if (edit_get_byte (edit, p + 1) == '.')
if (edit_get_byte (edit, p + 2) == '.')
return 0;
return 1;
{
/* `...' is acceptable */
return !(edit_buffer_get_byte (buf, p + 1) == '.'
&& edit_buffer_get_byte (buf, p + 2) == '.');
}
if (c == '-')
{
if (edit_get_byte (edit, p + 1) == '-')
if (edit_get_byte (edit, p + 2) == '-')
return 0; /* '---' is acceptable */
return 1;
/* `---' is acceptable */
return !(edit_buffer_get_byte (buf, p + 1) == '-'
&& edit_buffer_get_byte (buf, p + 2) == '-');
}
if (strchr (NO_FORMAT_CHARS_START, c))
return 1;
return 0;
return (strchr (NO_FORMAT_CHARS_START, c) != NULL);
}
/* --------------------------------------------------------------------------------------------- */
@ -120,27 +121,21 @@ bad_line_start (WEdit * edit, off_t p)
* Return position in the file.
*/
static long
begin_paragraph (WEdit * edit, int force)
static off_t
begin_paragraph (WEdit * edit, gboolean force)
{
long i;
for (i = edit->curs_line - 1; i >= 0; i--)
{
if (edit_line_is_blank (edit, i))
for (i = edit->buffer.curs_line - 1; i >= 0; i--)
if (edit_line_is_blank (edit, i) ||
(force && bad_line_start (&edit->buffer, line_start (&edit->buffer, i))))
{
i++;
break;
}
if (force)
{
if (bad_line_start (edit, line_start (edit, i)))
{
i++;
break;
}
}
}
return edit_move_backward (edit, edit_bol (edit, edit->curs1), edit->curs_line - i);
return edit_buffer_move_backward (&edit->buffer, edit_buffer_get_current_bol (&edit->buffer),
edit->buffer.curs_line - i);
}
/* --------------------------------------------------------------------------------------------- */
@ -149,68 +144,59 @@ begin_paragraph (WEdit * edit, int force)
* Return position in the file.
*/
static long
end_paragraph (WEdit * edit, int force)
static off_t
end_paragraph (WEdit * edit, gboolean force)
{
long i;
for (i = edit->curs_line + 1; i <= edit->total_lines; i++)
{
if (edit_line_is_blank (edit, i))
for (i = edit->buffer.curs_line + 1; i <= edit->buffer.lines; i++)
if (edit_line_is_blank (edit, i) ||
(force && bad_line_start (&edit->buffer, line_start (&edit->buffer, i))))
{
i--;
break;
}
if (force)
if (bad_line_start (edit, line_start (edit, i)))
{
i--;
break;
}
}
return edit_eol (edit,
edit_move_forward (edit, edit_bol (edit, edit->curs1),
i - edit->curs_line, 0));
return edit_buffer_get_eol (&edit->buffer,
edit_buffer_move_forward (&edit->buffer,
edit_buffer_get_current_bol
(&edit->buffer),
i - edit->buffer.curs_line, 0));
}
/* --------------------------------------------------------------------------------------------- */
static unsigned char *
get_paragraph (WEdit * edit, off_t p, off_t q, int indent, int *size)
static GString *
get_paragraph (const edit_buffer_t * buf, off_t p, off_t q, gboolean indent)
{
unsigned char *s, *t;
#if 0
t = g_try_malloc ((q - p) + 2 * (q - p) / option_word_wrap_line_length + 10);
#else
t = g_try_malloc (2 * (q - p) + 100);
#endif
if (t == NULL)
return NULL;
for (s = t; p < q; p++, s++)
GString *t;
t = g_string_sized_new (128);
for (; p < q; p++)
{
if (indent)
if (edit_get_byte (edit, p - 1) == '\n')
while (strchr ("\t ", edit_get_byte (edit, p)))
p++;
*s = edit_get_byte (edit, p);
if (indent && edit_buffer_get_byte (buf, p - 1) == '\n')
while (strchr ("\t ", edit_buffer_get_byte (buf, p)) != NULL)
p++;
g_string_append_c (t, edit_buffer_get_byte (buf, p));
}
*size = (unsigned long) (s - t);
/* FIXME: all variables related to 'size' should be fixed */
t[*size] = '\n';
g_string_append_c (t, '\n');
return t;
}
/* --------------------------------------------------------------------------------------------- */
static inline void
strip_newlines (unsigned char *t, int size)
strip_newlines (unsigned char *t, off_t size)
{
unsigned char *p = t;
while (size-- != 0)
{
unsigned char *p;
for (p = t; size-- != 0; p++)
if (*p == '\n')
*p = ' ';
p++;
}
}
/* --------------------------------------------------------------------------------------------- */
@ -218,23 +204,23 @@ strip_newlines (unsigned char *t, int size)
This function calculates the number of chars in a line specified to length l in pixels
*/
static inline int
next_tab_pos (int x)
static inline off_t
next_tab_pos (off_t x)
{
return x += tab_width - x % tab_width;
x += tab_width - x % tab_width;
return x;
}
/* --------------------------------------------------------------------------------------------- */
static inline int
line_pixel_length (unsigned char *t, long b, int l)
static inline off_t
line_pixel_length (unsigned char *t, off_t b, off_t l)
{
int x = 0, c, xn = 0;
off_t x = 0, xn = 0;
while (TRUE)
{
c = t[b];
switch (c)
switch (t[b])
{
case '\n':
return b;
@ -255,11 +241,11 @@ line_pixel_length (unsigned char *t, long b, int l)
/* --------------------------------------------------------------------------------------------- */
static int
next_word_start (unsigned char *t, int q, int size)
static off_t
next_word_start (unsigned char *t, off_t q, off_t size)
{
int i;
int saw_ws = 0;
off_t i;
gboolean saw_ws = FALSE;
for (i = q; i < size; i++)
{
@ -269,37 +255,37 @@ next_word_start (unsigned char *t, int q, int size)
return -1;
case '\t':
case ' ':
saw_ws = 1;
saw_ws = TRUE;
break;
default:
if (saw_ws != 0)
if (saw_ws)
return i;
break;
}
}
return -1;
return (-1);
}
/* --------------------------------------------------------------------------------------------- */
/** find the start of a word */
static inline int
word_start (unsigned char *t, int q, int size)
word_start (unsigned char *t, off_t q, off_t size)
{
int i = q;
off_t i;
if (t[q] == ' ' || t[q] == '\t')
return next_word_start (t, q, size);
while (TRUE)
for (i = q;; i--)
{
int c;
unsigned char c;
if (i == 0)
return -1;
return (-1);
c = t[i - 1];
if (c == '\n')
return -1;
return (-1);
if (c == ' ' || c == '\t')
return i;
i--;
@ -310,17 +296,18 @@ word_start (unsigned char *t, int q, int size)
/** replaces ' ' with '\n' to properly format a paragraph */
static inline void
format_this (unsigned char *t, int size, int indent)
format_this (unsigned char *t, off_t size, long indent)
{
int q = 0, ww;
off_t q = 0, ww;
strip_newlines (t, size);
ww = option_word_wrap_line_length * FONT_MEAN_WIDTH - indent;
if (ww < FONT_MEAN_WIDTH * 2)
ww = FONT_MEAN_WIDTH * 2;
while (TRUE)
{
int p;
off_t p;
q = line_pixel_length (t, q, ww);
if (q > size)
@ -344,79 +331,113 @@ format_this (unsigned char *t, int size, int indent)
/* --------------------------------------------------------------------------------------------- */
static inline void
replace_at (WEdit * edit, long q, int c)
replace_at (WEdit * edit, off_t q, int c)
{
edit_cursor_move (edit, q - edit->curs1);
edit_cursor_move (edit, q - edit->buffer.curs1);
edit_delete (edit, TRUE);
edit_insert_ahead (edit, c);
}
/* --------------------------------------------------------------------------------------------- */
static long
edit_indent_width (const WEdit * edit, off_t p)
{
off_t q = p;
/* move to the end of the leading whitespace of the line */
while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, q)) != NULL
&& q < edit->buffer.size - 1)
q++;
/* count the number of columns of indentation */
return (long) edit_move_forward3 (edit, p, 0, q);
}
/* --------------------------------------------------------------------------------------------- */
static void
edit_insert_indent (WEdit * edit, long indent)
{
if (!option_fill_tabs_with_spaces)
while (indent >= TAB_SIZE)
{
edit_insert (edit, '\t');
indent -= TAB_SIZE;
}
while (indent-- > 0)
edit_insert (edit, ' ');
}
/* --------------------------------------------------------------------------------------------- */
/** replaces a block of text */
static inline void
put_paragraph (WEdit * edit, unsigned char *t, off_t p, int indent, int size)
put_paragraph (WEdit * edit, unsigned char *t, off_t p, long indent, off_t size)
{
long cursor;
int i, c = 0;
off_t cursor;
off_t i;
int c = '\0';
cursor = edit->curs1;
if (indent)
while (strchr ("\t ", edit_get_byte (edit, p)))
cursor = edit->buffer.curs1;
if (indent != 0)
while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, p)) != NULL)
p++;
for (i = 0; i < size; i++, p++)
{
if (i && indent)
if (i != 0 && indent != 0)
{
if (t[i - 1] == '\n' && c == '\n')
{
while (strchr ("\t ", edit_get_byte (edit, p)))
while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, p)) != NULL)
p++;
}
else if (t[i - 1] == '\n')
{
off_t curs;
edit_cursor_move (edit, p - edit->curs1);
curs = edit->curs1;
edit_cursor_move (edit, p - edit->buffer.curs1);
curs = edit->buffer.curs1;
edit_insert_indent (edit, indent);
if (cursor >= curs)
cursor += edit->curs1 - p;
p = edit->curs1;
cursor += edit->buffer.curs1 - p;
p = edit->buffer.curs1;
}
else if (c == '\n')
{
edit_cursor_move (edit, p - edit->curs1);
while (strchr ("\t ", edit_get_byte (edit, p)))
edit_cursor_move (edit, p - edit->buffer.curs1);
while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, p)) != NULL)
{
edit_delete (edit, TRUE);
if (cursor > edit->curs1)
if (cursor > edit->buffer.curs1)
cursor--;
}
p = edit->curs1;
p = edit->buffer.curs1;
}
}
c = edit_get_byte (edit, p);
c = edit_buffer_get_byte (&edit->buffer, p);
if (c != t[i])
replace_at (edit, p, t[i]);
}
edit_cursor_move (edit, cursor - edit->curs1); /* restore cursor position */
edit_cursor_move (edit, cursor - edit->buffer.curs1); /* restore cursor position */
}
/* --------------------------------------------------------------------------------------------- */
static inline int
static inline long
test_indent (const WEdit * edit, off_t p, off_t q)
{
int indent;
long indent;
indent = edit_indent_width (edit, p++);
if (indent == 0)
return 0;
for (; p < q; p++)
if (edit_get_byte (edit, p - 1) == '\n')
if (indent != edit_indent_width (edit, p))
return 0;
if (edit_buffer_get_byte (&edit->buffer, p - 1) == '\n'
&& indent != edit_indent_width (edit, p))
return 0;
return indent;
}
@ -425,45 +446,44 @@ test_indent (const WEdit * edit, off_t p, off_t q)
/* --------------------------------------------------------------------------------------------- */
void
format_paragraph (WEdit * edit, int force)
format_paragraph (WEdit * edit, gboolean force)
{
long p, q;
int size;
unsigned char *t;
int indent = 0;
off_t p, q;
off_t size;
GString *t;
long indent;
unsigned char *t2;
if (option_word_wrap_line_length < 2)
return;
if (edit_line_is_blank (edit, edit->curs_line))
if (edit_line_is_blank (edit, edit->buffer.curs_line))
return;
p = begin_paragraph (edit, force);
q = end_paragraph (edit, force);
indent = test_indent (edit, p, q);
t = get_paragraph (edit, p, q, indent, &size);
if (!t)
return;
t = get_paragraph (&edit->buffer, p, q, indent != 0);
size = t->len - 1;
if (!force)
{
int i;
if (strchr (NO_FORMAT_CHARS_START, *t))
{
g_free (t);
return;
}
for (i = 0; i < size - 1; i++)
{
if (t[i] == '\n')
{
if (strchr (NO_FORMAT_CHARS_START "\t ", t[i + 1]))
{
g_free (t);
return;
}
}
}
off_t i;
if (strchr (NO_FORMAT_CHARS_START, t->str[0]) == NULL)
for (i = 0; i < size - 1; i++)
if (t->str[i] == '\n'
&& strchr (NO_FORMAT_CHARS_START "\t ", t->str[i + 1]) != NULL)
break;
g_string_free (t, TRUE);
return;
}
format_this (t, q - p, indent);
put_paragraph (edit, t, p, indent, size);
g_free (t);
t2 = (unsigned char *) g_string_free (t, FALSE);
format_this (t2, q - p, indent);
put_paragraph (edit, t2, p, indent, size);
g_free (t2);
/* Scroll left as much as possible to show the formatted paragraph */
edit_scroll_left (edit, -edit->start_col);

View File

@ -373,6 +373,7 @@ static const struct
} str_options[] = {
#ifdef USE_INTERNAL_EDIT
{ "editor_backup_extension", &option_backup_ext, "~" },
{ "editor_filesize_threshold", &option_filesize_threshold, "64M" },
#endif
{ "mcview_eof", &mcview_show_eof, "" },
{ NULL, NULL, NULL }

View File

@ -8,9 +8,13 @@ AM_CPPFLAGS = \
LIBS = @CHECK_LIBS@ $(top_builddir)/lib/libmc.la
TESTS = \
replace__str_replace_all
replace__str_replace_all \
parse_integer
check_PROGRAMS = $(TESTS)
replace__str_replace_all_SOURCES = \
replace__str_replace_all.c
parse_integer_SOURCES = \
parse_integer.c

View File

@ -0,0 +1,168 @@
/*
lib/strutil - tests for lib/strutil/parse_integer function.
Copyright (C) 2013
The Free Software Foundation, Inc.
Written by:
Andrew Borodin <aborodin@vmail.ru>, 2013
This file is part of the Midnight Commander.
The Midnight Commander is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
The Midnight Commander is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define TEST_SUITE_NAME "/lib/strutil"
#include "tests/mctest.h"
#include <inttypes.h>
#include "lib/strutil.h"
/* --------------------------------------------------------------------------------------------- */
/* @Before */
static void
setup (void)
{
}
/* --------------------------------------------------------------------------------------------- */
/* @After */
static void
teardown (void)
{
}
/* --------------------------------------------------------------------------------------------- */
/* @DataSource("str_replace_all_test_ds") */
/* *INDENT-OFF* */
static const struct parse_integer_test_ds
{
const char *haystack;
uintmax_t expected_result;
gboolean invalid;
} parse_integer_test_ds[] =
{
{
/* too big */
"99999999999999999999999999999999999999999999999999999999999999999999",
0,
TRUE
},
{
"x",
0,
TRUE
},
{
"9x",
0,
TRUE
},
{
"1",
1,
FALSE
},
{
"-1",
0,
TRUE
},
{
"1k",
1024,
FALSE
},
{
"1K",
1024,
FALSE
},
{
"1M",
1024 * 1024,
FALSE
},
{
"1m",
0,
TRUE
},
{
"64M",
64 * 1024 * 1024,
FALSE
},
{
"1G",
1 * 1024 * 1024 * 1024,
FALSE
}
};
/* *INDENT-ON* */
/* @Test(dataSource = "str_replace_all_test_ds") */
/* *INDENT-OFF* */
START_TEST (parse_integer_test)
/* *INDENT-ON* */
{
/* given */
uintmax_t actual_result;
gboolean invalid = FALSE;
const struct parse_integer_test_ds *data = &parse_integer_test_ds[_i];
/* when */
actual_result = parse_integer (data->haystack, &invalid);
/* then */
fail_unless (invalid == data->invalid && actual_result == data->expected_result,
"actial ( %" PRIuMAX ") not equal to\nexpected (%" PRIuMAX ")",
actual_result, data->expected_result);
}
/* *INDENT-OFF* */
END_TEST
/* *INDENT-ON* */
/* --------------------------------------------------------------------------------------------- */
int
main (void)
{
int number_failed;
Suite *s = suite_create (TEST_SUITE_NAME);
TCase *tc_core = tcase_create ("Core");
SRunner *sr;
tcase_add_checked_fixture (tc_core, setup, teardown);
/* Add new tests here: *************** */
tcase_add_loop_test (tc_core, parse_integer_test, 0, G_N_ELEMENTS (parse_integer_test_ds));
/* *********************************** */
suite_add_tcase (s, tc_core);
sr = srunner_create (s);
srunner_set_log (sr, "parse_integer.log");
srunner_run_all (sr, CK_NOFORK);
number_failed = srunner_ntests_failed (sr);
srunner_free (sr);
return (number_failed == 0) ? 0 : 1;
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -155,6 +155,8 @@ my_setup (void)
load_codepages_list ();
#endif /* HAVE_CHARSET */
option_filesize_threshold = (char *) "64M";
test_edit = edit_init (NULL, 0, 0, 24, 80, vfs_path_from_str ("test-data.txt"), 1);
editcmd_dialog_completion_show__init ();
}
@ -264,7 +266,9 @@ START_PARAMETRIZED_TEST (test_autocomplete, test_autocomplete_ds)
{
int chr;
chr = edit_get_byte (test_edit, data->input_completed_word_start_pos + i++);
chr =
edit_buffer_get_byte (&test_edit->buffer,
data->input_completed_word_start_pos + i++);
if (isspace (chr))
break;
g_string_append_c (actual_completed_str, chr);
@ -336,7 +340,9 @@ START_PARAMETRIZED_TEST (test_autocomplete_single, test_autocomplete_single_ds)
{
int chr;
chr = edit_get_byte (test_edit, data->input_completed_word_start_pos + i++);
chr =
edit_buffer_get_byte (&test_edit->buffer,
data->input_completed_word_start_pos + i++);
if (isspace (chr))
break;
g_string_append_c (actual_completed_str, chr);